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

Introducing time-varying independent variables into the neural ordinary differential equation #14

Open
zykhoo opened this issue Dec 28, 2021 · 1 comment

Comments

@zykhoo
Copy link

zykhoo commented Dec 28, 2021

Hello thank you for implementing this library!

I have a variable that depends on the time step, called aircon_power. It should take in the time step that the ode is currently at, and return the respective aircon_power.

def aircon_power(tstep):
    if tstep<0:
        return 0
    elif tstep>len(merged_dataset["temp_1"].values):
        return 544.9
    else:
        spl = interp1d(range(len(x)), x, kind = 'cubic')
        return spl(tstep)

I intend to then embed the aircon_power within the ordinary differential equations.

dT1 = - n_out[0, 0] * aircon_power(t) + (T1)*n_out[0, 1]

However, this returns an error because t is a symbolic Tensor.

NotImplementedError: Cannot convert a symbolic Tensor (tstep:0) to a numpy array.

Do you have any alternative method to introduce such a variable?

Thank you!

@cschempp
Copy link

I think the error comes from using interp1d, which expects numpy array.
For example, this works:

def aircon_power(self,tstep):
    if tstep<0:
        return 0
    elif tstep>1.5:
        return 544.9
    else:
        return 42

then call it inside your model class:

@tf.function
def call(self, t, y):
    x1, x2 = tf.unstack(y)    # state  variables
    acp = self.aircon_power(t)

    # ODEs

    return tf.stack([dx1_dT, dx2_dT])

I hope this helps.

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

2 participants