roahmlab / koopman-realizations

Codebase for generating linear/bilinear/nonlinear Koopman model realizations from data and constructing MPC controllers.
MIT License
17 stars 4 forks source link

Creating data file for code. #2

Open ajaigit opened 2 years ago

ajaigit commented 2 years ago

Dear Dr. Dan,

I read your Ph.D. thesis “Towards a Universal Modeling and Control Framework for Soft Robots”, inspired by your work and podcast “ How to do grad school”, I wanted to do similar work for my better understanding of Koopman Operator and how to implement the algorithms you have mentioned in your thesis for system identification.

I am using data from a soft robot and the data file looks similar to your “arm-3link-markers-noload-50trials_train-10_val-5.mat” file but the issue I am running into is the model prediction is not accurate. So I was wondering what possibly could I be doing wrong.

Given below is the structure of my data file: Training data:

X = [ x( : , : ) , y( : , :) , z( : , : ) ] % x,y,z coordinates of points along the robots body

Y = [ x( : , end ) , y( : , end ) , z( : , end ) ] % trying to track the tip of the robot.

U = all the torques that are acting on the robot ( torques are constant during the simulation for different points )

T = time .

Similarly, I create a data set for validation using new data the model was not trained before. I am not sure where I am going wrong?

Also when I identify the linear system by setting a delay of 1, I get ud1 , ud2 , ud3 ..... as the basis function. During the simulation of the identified linear model, what will be the initial condition corresponding to these delay input functions ? Given below are the setup parameters that I am using :

Ksysid = Ksysid( data4sysid ,... 'model_type' , 'linear' ,... % model type (linear, bilinear, or nonlinear) 'time_type' , 'discrete' , ... % 'discrete' or 'continuous' 'obs_type' , { 'poly' } ,... % type of basis functions 'obs_degree' , [1] ,... % "degree" of basis functions 'snapshots' , Inf ,... % Number of snapshot pairs 'lasso' , [ Inf ] ,... % L1 regularization term (Inf for least-squares sol.) 'delays' , 1 ,... % Numer of state/input delays 'loaded' , false ,... % Does system include external loads? 'dim_red' , false); % Should dimensional reduction be performed?

bruderd commented 2 years ago

Hello,

Thank you for your question and apologies for my delayed response.

The only variables from the training data file that are used to identify the Koopman model are 'u' (input) and 'y' (output), and possibly 't' (I would have to double check that). The rest of the fields in “arm-3link-markers-noload-50trials_train-10_val-5.mat” are just included for visualization purposes. With the data file you've provided, the Koopman model is trying to characterize the behavior of the end effector using only the coordinates of the end effector, which may not be enough information to build a suitable model.

I think you should define 'y' the way you are currently defining 'x': y = [ x( : , : ) , y( : , :) , z( : , : ) ] % x,y,z coordinates of points along the robots body

The resulting Koopman model will then describe the dynamics of all the points along the body, but you can just focus on the components that describe the trajectory of the end effector in your validation experiments or controller.

For your other questions about the input delays, in the built in function used for validating identified models, "Ksysid.val_model", the simulation begins one time step later than the number of delays. In other words, if delays = 1, then the model will be simulated starting from the 2nd time-step of the validation data, and 'ud' will be set to the value of 'u' at the 1st time step in of the validation data. You can see how this is done at Line 1629 of "Ksysid.m"

I hope this will be helpful, please let me know if you have any further questions.

Best, Dan

ajaigit commented 2 years ago

Thank you for the response, Dr. Dan. Your suggestions were very helpful and they did improve the accuracy of the model a lot. Can you please confirm if the variable z0 at line no. 1666 of Ksysid.m is the initial condition for the identified linear model and can be used when as an initial condition when simulating the identified linear model ?

bruderd commented 2 years ago

Yes z0 should be the initial condition for the system in the lifted space.

Best, Dan

ajaigit commented 2 years ago

Thank you for the confirmation Dr. Dan