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

Using real data for estimating diffeq #368

Open
LorenzoBottaccioli opened this issue Jul 8, 2022 · 2 comments
Open

Using real data for estimating diffeq #368

LorenzoBottaccioli opened this issue Jul 8, 2022 · 2 comments

Comments

@LorenzoBottaccioli
Copy link

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
Copy link
Member

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
Copy link
Collaborator

AlCap23 commented Jul 12, 2022

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.

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

3 participants