SciML / DataDrivenDiffEq.jl

Data driven modeling and automated discovery of dynamical systems for the SciML Scientific Machine Learning organization
https://docs.sciml.ai/DataDrivenDiffEq/stable/
MIT License
402 stars 56 forks source link

Using real data for estimating diffeq #368

Open LorenzoBottaccioli opened 2 years ago

LorenzoBottaccioli commented 2 years ago

Hi,

I'm quite new to Julia and the SciML packages I have looked at the examples and searched on the web but I did not find an answer to my question. I will like to use this library to identify the model behind some data that I have. My problem can be formulated as dx/dt= A * x + B * u where x is the state vector u is a time-varying input vector and A and B are constant matrix. For a more realistic case example imagine an RC circuit where you impose with the u vector an electric current and an electric charge. This data might be stored in a csv file having in the columns the different measurements (states and control inputs) and in the row the measured values for each time stamp. How do I build the pipe line?

I have taken a look at https://datadriven.sciml.ai/dev/examples/3_linear_continuous_system_controls/ but I don't understand how to pass as control an input that changes over time reading it from data.

Tnx

ChrisRackauckas commented 2 years ago

If you use a spline over the data using https://github.com/PumasAI/DataInterpolations.jl then you have a continuous function that can be passed as the control input.

AlCap23 commented 2 years ago

You probably want to load the csv file using DataFrames.jl and CSV.jl, select the corresponding columns ( for states, timestamps and control signal ) and pass them into the DataDrivenProblem. A simple example would be:

using DataFrames
using CSV
using LinearAlgebra
using DataDrivenDiffEq
# Create some random data, placeholder for CSV.File("...") |> DataFrame

times = 0:0.1:1.0
x1 = randn(length(times))
x2 = randn(length(times))
u = sin.(times)

df = DataFrame(
    t = 0:0.1:1.0, x1 = x1, x2 = x2, u = u
)

# Load the signals
t = df[!, :t]
X = permutedims(hcat(df[!, :x1], df[!, :x2]))
U = permutedims(df[!, :u])

prob = ContinuousDataDrivenProblem(X, t, U = U)

Note that we assume that time corresponds to columns, so we need to permute the arrays.