titu1994 / tfdiffeq

Tensorflow implementation of Ordinary Differential Equation Solvers with full GPU support
MIT License
213 stars 52 forks source link

Example ode_demo using y**3? #11

Open pswpswpsw opened 3 years ago

pswpswpsw commented 3 years ago

This example ode_demo.py under Example is considering a NN with input cubic nonlinearity. Since the original dynamics is y**3 so it seems a bit weird. This implies that as long as the NN is learning the linear matrix mapping, it will work.

class ODEFunc(tf.keras.Model):
    def __init__(self, **kwargs):
        super(ODEFunc, self).__init__(**kwargs)

        self.x = tf.keras.layers.Dense(50, activation='tanh',
                                   kernel_initializer=tf.keras.initializers.TruncatedNormal(stddev=0.1))
        self.y = tf.keras.layers.Dense(2,
                                   kernel_initializer=tf.keras.initializers.TruncatedNormal(stddev=0.1))

    def call(self, t, y):
        y = tf.cast(y, tf.float32)
        x = self.x(y ** 3)
        y = self.y(x)
        return y

Question

When I turned it back to y, so using NN to fully learning the dynamics, (see below) it doesn't converge and seems stuck at somewhere. Does anyone have success in using NODE for this simple example?

098