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

GP Discrete Time State Space Models #15

Open
sumedhs-1995 opened this issue Feb 18, 2023 · 3 comments
Open

GP Discrete Time State Space Models #15

sumedhs-1995 opened this issue Feb 18, 2023 · 3 comments
Assignees
Labels
documentation Improvements or additions to documentation

Comments

@sumedhs-1995
Copy link

sumedhs-1995 commented Feb 18, 2023

@brunomorampc I am trying to use a GP Model in an MPC setting where I am trying to write the state-space equations as

x1(t+1) = gp1(x(t), u(t))
x2(t+1) = gp2(x(t),u(t)),

where x = [x1;x2], u = [u1;u2]

I have currently written code as follows. However I am still stuck at writing the correct syntax for writing gp into the equation. I would really appreciate some help with this.

Thank you in advance!

Create GP Prediction Model

gp_model = Model(plot_backend='bokeh', name='GP_Model', discrete=True)

Set states and inputs

s = gp_model.set_dynamical_states(['x1','x2'])
u = gp_model.set_inputs(['u1','u2'])
gp_model.set_measurement_equations([s[0], s[1]])

x1 = s[0]
x2 = s[1]

u1 = u[0]
u2 = u[1]

x_next = gp1.predict([x1,x2,u1,u2])
y_next = gp2.predict([x1,x2,u1,u2])

gp_model.set_dynamical_equations(['x1', 'x2' ])

Set up the model

gp_model.setup(dt=0.01)

Set initial conditions

x0_GP = [1, 1]
gp_model.set_initial_conditions(x0=x0_GP)

@sumedhs-1995 sumedhs-1995 changed the title ]GP Discrete Time State Space Models GP Discrete Time State Space Models Feb 18, 2023
@brunomorampc brunomorampc self-assigned this Feb 19, 2023
@brunomorampc brunomorampc added the documentation Improvements or additions to documentation label Feb 19, 2023
@jpohlodek jpohlodek self-assigned this Feb 20, 2023
@jpohlodek
Copy link
Contributor

Hi there,

I think the file gp_nmpc_cstr_output_feedback.py from the example repository contains what you are looking for.

At the moment you can set the dynamical equations as gp_model.set_dynamical_equations(['0', '0']) and then gp_model += [gp1, gp2] should do the trick. Now you can set up the model.

Hope this helps you.

@sumedhs-1995
Copy link
Author

sumedhs-1995 commented Mar 2, 2023

@jpohlodek Thank you for your response. I had referred to the example you pointed out and that was how I had setup initially. But the results I get from simulating the model don't seem to be correct. Because when I predict using:

gp_1_mean, _ = gp1.predict(train_in)
gp_2_mean, _ = gp2.predict(train_in)
gp_3_mean, _ = gp3.predict(train_in)

I get the following results:

image

But when I formulate a model using GPs as you've shown and simulate the model as shown below, the results are different and not consistent with what the gaussian processes should have predicted with the same time step.

image

The code can be found here

@jpohlodek
Copy link
Contributor

Hi @sumedhs-1995,

sorry for the late reply. Looking over your code, I found one problem where you generate your features and labels. You create the labels by downsampling the state solution and applying the shift afterwards. Hence, you train the features of one time step (t) with the labels from 50 time steps (t+50) later. In other words you are predicting with a step size of 50, but in the prediction you want a step size of 1.

In order to run it in a closed loop with the same sampling time as the original system, you need the labels from the next time (t+1) step. So it's better to create the labels first by shifting the state solution and then downsample to the desired size of the training data set.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
documentation Improvements or additions to documentation
Projects
None yet
Development

No branches or pull requests

3 participants