Git Product home page Git Product logo

Comments (3)

kmkolasinski avatar kmkolasinski commented on June 28, 2024

Hi, could you provide me example ODE you would like to implement ?

from deep-learning-notes.

jzuhone avatar jzuhone commented on June 28, 2024

So, the example we are dealing with has a lot of pieces.

I am working for a spacecraft and we need to predict the temperature of various components as a function of time due to various forcings.

These include:

• solar heating, which depends on spacecraft attitude, position and distance from the sun
• passive cooling out to space
• heating from nearby electronics boxes

Our approach for a number of years has been to assume functional forms for each of these forcings with unknown constants, and then fit to historical temperature data using chi-squared fitting. This has worked very well, but there are some behaviors which our models cannot capture, presumably not due to unknown inputs but the fact that our functional forms are too simple or incomplete. We have all of the features we think we need, the question is how does the rate of change of temperature depend on them?

I realize this is a large jump in complexity from the models you laid out in this source code.

Thanks!

from deep-learning-notes.

kmkolasinski avatar kmkolasinski commented on June 28, 2024

Hi, is this toy example what you want to obtain ?

import numpy as np
import numpy.random as npr
import tensorflow as tf
from tqdm import tqdm
import matplotlib.pyplot as plt
import tensorflow.contrib.eager as tfe

keras = tf.keras
tf.enable_eager_execution()
import neural_ode as node

class NNModule(tf.keras.Model):
    def __init__(self, num_filters):
        super(NNModule, self).__init__(name="Module")
        self.dense_1 = keras.layers.Dense(num_filters, activation="tanh")        
        self.t_dense_1 = keras.layers.Dense(num_filters, activation=lambda x: tf.sin(x))

    def call(self, inputs, **kwargs):
        # x = [batch_size, 3]
        # t = [1]
        t, x = inputs
                
        # t = [batch_size, 1]
        t = tf.tile(tf.reshape(t, [1, 1]), [12, 1])        
        # t1 = [batch_size, num_filters]
        t1 = self.t_dense_1(t)        
        # h = [batch_size, num_filters]
        h = self.dense_1(x) + t1
        return h

# create model and ode solver
model = NNModule(num_filters=3)
ode = node.NeuralODE(
    model, t=np.linspace(0, 1.0, 20),
    solver=neural_ode.rk4_step
)

x0 = tf.random_normal(shape=[12, 3])

with tf.GradientTape() as g:
    g.watch(x0)
    xN = ode.forward(x0)
    # some loss function here e.g. L2
    loss = xN ** 2

# reverse mode with adjoint method
dLoss = g.gradient(loss, xN)
x0_rec, dLdx0, dLdW = ode.backward(xN, dLoss)

It solves following ODE:

dx / dt = tanh( Wx * x + bx ) + cos( Wt * t + bt)

Note: please note that my implementation maybe not the efficient one, I think the pytorch solver should be more reliable.

from deep-learning-notes.

Related Issues (13)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.