Skip to content

Can't process 1-dimension state system #3

@utotch

Description

@utotch

I found nlgreyfast can't process "1D-state" system when I solve my problem.

When I code both "fopts.x0_free_v = false" and "fopts.x0_free_v = true", nlgreyfast can't proceed.
I think it is caused that nlgreyfast expects over 2D state system.

But I have a practical 1D state nonlinear system problem, and I believe 1D state system should not be ignored to solve.

I show the code:

% nlgreyfast sample
% dx/dt = theta*x + u
% estimate theta
x = casadi.MX.sym('x');
u = casadi.MX.sym('u');
theta = casadi.MX.sym('theta');
n_param = 1;
rhs = theta*x + u;
ode = casadi.Function('ode', {x, u, theta}, {rhs});
sample_freq = 20.0;
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    = -10;
fopts.param_ub_v    =  10;
fopts.x0_v          = 0.5;
fopts.x0_free_v     = false; % both [true] and [false] causes problem
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(theta_true, 1, 1, 0);
x0 = 0.5;
[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\n',  x0);
fprintf(2,'[x0(estimate)   ]%f\n',  model_est.x0_est_v);

"fopts.x0_free_v = false" case

Error using casadi.MX/paren_asgn
.../casadi/core/mx.cpp:330: Dimension mismatch. lhs is [0,0], while rhs is [0,1]

Error in indexing (line 42)
        paren_asgn(self, v, s.subs{:});

Error in nlidcomb (line 56)
x0_sym_v(x0_free_indexes_v) = x0_decvars_v;

Error in nlgreyfast (line 69)
    [estmodel.param_est_v, estmodel.x0_est_v, estmodel.diag_data ] = nlidcomb(plant_next, fs, u_data_V, y_data_V, ...

Error in nlgreyfast_sample_1d (line 35)
model_est = nlgreyfast(data_train, model, fopts);

"fopts.x0_free_v = true" case

Error using assert
Assertion failed.

Error in nlidcomb (line 269)
assert(all(size(X_guess_H)==size(X_simstart_without_x0_H)));

Error in nlgreyfast (line 69)
    [estmodel.param_est_v, estmodel.x0_est_v, estmodel.diag_data ] = nlidcomb(plant_next, fs, u_data_V, y_data_V, ...

Error in nlgreyfast_sample_1d (line 35)
model_est = nlgreyfast(data_train, model, fopts);

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions