Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fail to estimate a simple linear system identification (the result is sensitive to discretization freq) #2

Open
utotch opened this issue Apr 19, 2023 · 0 comments

Comments

@utotch
Copy link

utotch commented Apr 19, 2023

I tried to solve a simplest (linear grey-box system) problem to check nlgreyfast but it produced an incorrect result, which was unexpected.

Problem setting:
linear continuous-time grey-box system
#parameter = 1
#state = 2
#input = 1

I expected nlgreyfast solve this easily if I discretized the system with enough frequency, but it estimated the wrong value even though I chose enough freq.

I'm not sure it's my setting problem or inherent difficulty, but I'd be glad if you comment something to this.

code

% nlgreyfast sample
% dx/dt = [0 1; 0 theta]*[x1; x2] + [0; 1]*u1
% estimate theta
x1 = casadi.MX.sym('x1');
x2 = casadi.MX.sym('x2');
u1 = casadi.MX.sym('u1');
theta = casadi.MX.sym('theta');
n_param = 1;
Ac = [0 1; 0 theta];
Bc = [0; 1];
rhs = Ac*[x1; x2] + Bc*u1;
ode = casadi.Function('ode', {[x1; x2], u1, theta}, {rhs});
sample_freq = 20.0; % [Hz]: estimate value is very sensitive to this
num_sample_sim = 100;
num_steps_per_sample = 10;
[model, all_samples] = nlsim(ode, sample_freq, num_sample_sim, num_steps_per_sample);
fopts = struct;
fopts.scale_v       = ones(n_param,1);
fopts.param_guess_v = 1.0;
fopts.param_lb_v    = -20;
fopts.param_ub_v    =  20;
fopts.x0_v          = [0; 0];
fopts.x0_free_v     = [false; false];
fopts.y_states_v    = [1];
fopts.X_guess_H     = 'guess_mechatronic';
fopts.N_group_size  = 1;

% dataset(train)
dt = 0.1;
ts = (0:dt:100)';
us = sawtooth(ts);
theta_true = -2.0;
sysc = ss([0 1; 0 theta_true], Bc, [1 0], 0);
x0 = [0;0];
[ys, ts_, xs] = lsim(sysc, us, ts, x0);
data_train = iddata(ys, us, dt);
plot(data_train);
model_est = nlgreyfast(data_train, model, fopts);
fprintf(2,'[theta(true)    ]%f\n', theta_true);
fprintf(2,'[theta(estimate)]%f\n', model_est.param_est_v);
fprintf(2,'[x0(true)       ][%f;%f]\n',  x0(1), x0(2));
fprintf(2,'[x0(estimate)   ][%f;%f]\n',  model_est.x0_est_v(1), model_est.x0_est_v(2));

result

[theta(true)    ]-2.000000
[theta(estimate)]-1.000812
[x0(true)       ][0.000000;0.000000]
[x0(estimate)   ][0.000000;0.000000]
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant