Combining ExperimentData objects

The previous sections demonstrate how we can add data from an ODEProblem, FMU or a Dataset source in order to produce an ExperimentData object that would be used to train a DigitalEcho. In some scenarios, the complete data can come from multiple sources such as a combination of a Dataset and simulations from either ODEProblem or FMUs. In such a scenario, we would want to combine both the sources into a single ExperimentData object.

For this demonstration, we will use the dataset from the Including Data from a Dataset manual and combine it with simulations from an ODEProblem source.

using JuliaHub, JLSO, DataGeneration
using OrdinaryDiffEq

We start by downloading the dataset, and loading it into an ExperimentData.

train_dataset_name = "robertson"
path_to_dataset = JuliaHub.download_dataset(("juliasimtutorials", train_dataset_name), "path to save");
train_data = JLSO.load(path_to_dataset)[:result]
ed_dataset = ExperimentData(train_data)
 Number of Trajectories in ExperimentData: 100 
  Basic Statistics for Given Dynamical System's Specifications 
  Number of u0s in the ExperimentData: 3 
  Number of ps in the ExperimentData: 3 
 ╭─────────┬──────────────────────────────────────────────────────────────────...
────╮...
│  Field  │...
         │...
├─────────┼──────────────────────────────────────────────────────────────────...
────┤...
│         │    ╭────────────┬──────────────┬──────────────┬────────┬─────────...
│         │    │   Labels   │  LowerBound  │  UpperBound  │  Mean  │  StdDev...
│         │    ├────────────┼──────────────┼──────────────┼────────┼─────────...
│         │    │  states_1  │     1.0      │     1.0      │  1.0   │   0.0...
│   u0s   │    ├────────────┼──────────────┼──────────────┼────────┼─────────...
│         │    │     ⋮      │      ⋮       │      ⋮       │   ⋮    │...
│         │    │     ⋮      │      ⋮       │      ⋮       │   ⋮    │...
│         │    ├────────────┼──────────────┼──────────────┼────────┼─────────...
│         │    │  states_3  │     0.0      │     0.0      │  0.0   │   0.0...
│         │    ╰────────────┴──────────────┴──────────────┴────────┴─────────...
├─────────┼──────────────────────────────────────────────────────────────────...
────┤...
│         │  ╭──────────┬──────────────┬──────────────┬─────────────┬────────...
│         │  │  Labels  │  LowerBound  │  UpperBound  │    Mean     │  StdDev...
│         │  ├──────────┼──────────────┼──────────────┼─────────────┼────────...
│         │  │   p_1    │    0.036     │    0.044     │    0.04     │...
│   ps    │  ├──────────┼──────────────┼──────────────┼─────────────┼────────...
│         │  │    ⋮     │      ⋮       │      ⋮       │      ⋮      │...
│         │  │    ⋮     │      ⋮       │      ⋮       │      ⋮      │...
│         │  ├──────────┼──────────────┼──────────────┼─────────────┼────────...
│         │  │   p_3    │   9015.625   │  10992.188   │  10007.188  │  581.41...
│         │  ╰──────────┴──────────────┴──────────────┴─────────────┴────────...
╰─────────┴──────────────────────────────────────────────────────────────────...
────╯...
 Basic Statistics for Given Dynamical System's Continuous Fields 
  Number of states in the ExperimentData: 3 
 ╭──────────┬─────────────────────────────────────────────────────────────────...
──╮...
│  Field   │...
       │...
├──────────┼─────────────────────────────────────────────────────────────────...
──┤...
│          │  ╭────────────┬──────────────┬──────────────┬─────────┬─────────...
│          │  │   Labels   │  LowerBound  │  UpperBound  │  Mean   │  StdDev...
│          │  ├────────────┼──────────────┼──────────────┼─────────┼─────────...
│          │  │  states_1  │    0.081     │     1.0      │  0.587  │  0.299...
│  states  │  ├────────────┼──────────────┼──────────────┼─────────┼─────────...
│          │  │     ⋮      │      ⋮       │      ⋮       │    ⋮    │...
│          │  │     ⋮      │      ⋮       │      ⋮       │    ⋮    │...
│          │  ├────────────┼──────────────┼──────────────┼─────────┼─────────...
│          │  │  states_3  │     0.0      │    0.919     │  0.413  │  0.299...
│          │  ╰────────────┴──────────────┴──────────────┴─────────┴─────────...
╰──────────┴─────────────────────────────────────────────────────────────────...
──╯...

Now we simulate the Robertson model using an ODEProblem.

function rober(u, p, t)
    y₁, y₂, y₃ = u
    k₁, k₂, k₃ = p
    [-k₁ * y₁ + k₃ * y₂ * y₃;
        k₁ * y₁ - k₂ * y₂^2 - k₃ * y₂ * y₃;
        k₂ * y₂^2]
    # nothing
end
u0 = [1.0, 0.0, 0.0]
tspan = (0.0, 1e4)

rober_prob = ODEProblem{false}(rober, u0, tspan)
ODEProblem with uType Vector{Float64} and tType Float64. In-place: false
timespan: (0.0, 10000.0)
u0: 3-element Vector{Float64}:
 1.0
 0.0
 0.0

Note that we use the same labels for parameters, that have been used by the dataset.

params_labels = train_data["params_labels"]
3-element Vector{String}:
 "p_1"
 "p_2"
 "p_3"
p_lb = [0.036, 2.7e7, 0.9e4]
p_ub = [0.044, 3.3e7, 1.1e4]
nsamples = 50
param_space = ParameterSpace(p_lb, p_ub, nsamples; labels = params_labels)
 3 dimensional ParameterSpace with 50 samples 
 ╭──────────────────┬──────────────────────────────────────────────┬──────────...
─────────╮...
│    Space Type    │                  Statistics                  │  Number...
of Samples  │...
├──────────────────┼──────────────────────────────────────────────┼──────────...
─────────┤...
│                  │  ╭──────────┬──────────────┬──────────────╮  │...
│                  │  │  Labels  │  LowerBound  │  UpperBound  │  │...
│                  │  ├──────────┼──────────────┼──────────────┤  │...
│                  │  │   p_1    │    0.036     │    0.044     │  │...
│  ParameterSpace  │  ├──────────┼──────────────┼──────────────┤  │...
│                  │  │    ⋮     │      ⋮       │      ⋮       │  │...
│                  │  │    ⋮     │      ⋮       │      ⋮       │  │...
│                  │  ├──────────┼──────────────┼──────────────┤  │...
│                  │  │   p_3    │    9000.0    │   11000.0    │  │...
│                  │  ╰──────────┴──────────────┴──────────────╯  │...
╰──────────────────┴──────────────────────────────────────────────┴──────────...
─────────╯...

Now we define the SimulatorConfig and call it on the rober_prob.

sim_config = SimulatorConfig(param_space)
ed_ode = sim_config(rober_prob; alg = Rosenbrock23())
 Number of Trajectories in ExperimentData: 50 
  Basic Statistics for Given Dynamical System's Specifications 
  Number of u0s in the ExperimentData: 3 
  Number of ps in the ExperimentData: 3 
 ╭─────────┬──────────────────────────────────────────────────────────────────...
───╮...
│  Field  │...
        │...
├─────────┼──────────────────────────────────────────────────────────────────...
───┤...
│         │   ╭────────────┬──────────────┬──────────────┬────────┬──────────...
│         │   │   Labels   │  LowerBound  │  UpperBound  │  Mean  │  StdDev...
│         │   ├────────────┼──────────────┼──────────────┼────────┼──────────...
│         │   │  states_1  │     1.0      │     1.0      │  1.0   │   0.0...
│   u0s   │   ├────────────┼──────────────┼──────────────┼────────┼──────────...
│         │   │     ⋮      │      ⋮       │      ⋮       │   ⋮    │    ⋮...
│         │   │     ⋮      │      ⋮       │      ⋮       │   ⋮    │    ⋮...
│         │   ├────────────┼──────────────┼──────────────┼────────┼──────────...
│         │   │  states_3  │     0.0      │     0.0      │  0.0   │   0.0...
│         │   ╰────────────┴──────────────┴──────────────┴────────┴──────────...
├─────────┼──────────────────────────────────────────────────────────────────...
───┤...
│         │  ╭──────────┬──────────────┬──────────────┬────────────┬─────────...
│         │  │  Labels  │  LowerBound  │  UpperBound  │    Mean    │  StdDev...
│         │  ├──────────┼──────────────┼──────────────┼────────────┼─────────...
│         │  │   p_1    │    0.036     │    0.044     │    0.04    │   0.002...
│   ps    │  ├──────────┼──────────────┼──────────────┼────────────┼─────────...
│         │  │    ⋮     │      ⋮       │      ⋮       │     ⋮      │...
│         │  │    ⋮     │      ⋮       │      ⋮       │     ⋮      │...
│         │  ├──────────┼──────────────┼──────────────┼────────────┼─────────...
│         │  │   p_3    │   9015.625   │   10968.75   │  9978.125  │  580.975...
│         │  ╰──────────┴──────────────┴──────────────┴────────────┴─────────...
╰─────────┴──────────────────────────────────────────────────────────────────...
───╯...
 Basic Statistics for Given Dynamical System's Continuous Fields 
  Number of states in the ExperimentData: 3 
 ╭──────────┬─────────────────────────────────────────────────────────────────...
──╮...
│  Field   │...
       │...
├──────────┼─────────────────────────────────────────────────────────────────...
──┤...
│          │  ╭────────────┬──────────────┬──────────────┬─────────┬─────────...
│          │  │   Labels   │  LowerBound  │  UpperBound  │  Mean   │  StdDev...
│          │  ├────────────┼──────────────┼──────────────┼─────────┼─────────...
│          │  │  states_1  │    0.082     │     1.0      │  0.703  │  0.317...
│  states  │  ├────────────┼──────────────┼──────────────┼─────────┼─────────...
│          │  │     ⋮      │      ⋮       │      ⋮       │    ⋮    │...
│          │  │     ⋮      │      ⋮       │      ⋮       │    ⋮    │...
│          │  ├────────────┼──────────────┼──────────────┼─────────┼─────────...
│          │  │  states_3  │     0.0      │    0.918     │  0.297  │  0.317...
│          │  ╰────────────┴──────────────┴──────────────┴─────────┴─────────...
╰──────────┴─────────────────────────────────────────────────────────────────...
──╯...

Now we have two different ExperimentData objects: ed_dataset and ed_ode. We can combine them using combine:

ed = combine(ed_ode, ed_dataset)
 Number of Trajectories in ExperimentData: 150 
  Basic Statistics for Given Dynamical System's Specifications 
  Number of u0s in the ExperimentData: 3 
  Number of ps in the ExperimentData: 3 
 ╭─────────┬──────────────────────────────────────────────────────────────────...
─╮...
│  Field  │...
      │...
├─────────┼──────────────────────────────────────────────────────────────────...
─┤...
│         │  ╭────────────┬──────────────┬──────────────┬────────┬──────────╮...
│         │  │   Labels   │  LowerBound  │  UpperBound  │  Mean  │  StdDev...
│         │  ├────────────┼──────────────┼──────────────┼────────┼──────────┤...
│         │  │  states_1  │     1.0      │     1.0      │  1.0   │   0.0...
│   u0s   │  ├────────────┼──────────────┼──────────────┼────────┼──────────┤...
│         │  │     ⋮      │      ⋮       │      ⋮       │   ⋮    │    ⋮...
│         │  │     ⋮      │      ⋮       │      ⋮       │   ⋮    │    ⋮...
│         │  ├────────────┼──────────────┼──────────────┼────────┼──────────┤...
│         │  │  states_3  │     0.0      │     0.0      │  0.0   │   0.0...
│         │  ╰────────────┴──────────────┴──────────────┴────────┴──────────╯...
├─────────┼──────────────────────────────────────────────────────────────────...
─┤...
│         │  ╭──────────┬──────────────┬──────────────┬──────────┬───────────...
│         │  │  Labels  │  LowerBound  │  UpperBound  │   Mean   │  StdDev...
│         │  ├──────────┼──────────────┼──────────────┼──────────┼───────────...
│         │  │   p_1    │    0.036     │    0.044     │   0.04   │   0.002...
│   ps    │  ├──────────┼──────────────┼──────────────┼──────────┼───────────...
│         │  │    ⋮     │      ⋮       │      ⋮       │    ⋮     │     ⋮...
│         │  │    ⋮     │      ⋮       │      ⋮       │    ⋮     │     ⋮...
│         │  ├──────────┼──────────────┼──────────────┼──────────┼───────────...
│         │  │   p_3    │   9015.625   │  10992.188   │  9997.5  │  579.476...
│         │  ╰──────────┴──────────────┴──────────────┴──────────┴───────────...
╰─────────┴──────────────────────────────────────────────────────────────────...
─╯...
 Basic Statistics for Given Dynamical System's Continuous Fields 
  Number of states in the ExperimentData: 3 
 ╭──────────┬─────────────────────────────────────────────────────────────────...
──╮...
│  Field   │...
       │...
├──────────┼─────────────────────────────────────────────────────────────────...
──┤...
│          │  ╭────────────┬──────────────┬──────────────┬─────────┬─────────...
│          │  │   Labels   │  LowerBound  │  UpperBound  │  Mean   │  StdDev...
│          │  ├────────────┼──────────────┼──────────────┼─────────┼─────────...
│          │  │  states_1  │    0.081     │     1.0      │  0.587  │  0.299...
│  states  │  ├────────────┼──────────────┼──────────────┼─────────┼─────────...
│          │  │     ⋮      │      ⋮       │      ⋮       │    ⋮    │...
│          │  │     ⋮      │      ⋮       │      ⋮       │    ⋮    │...
│          │  ├────────────┼──────────────┼──────────────┼─────────┼─────────...
│          │  │  states_3  │     0.0      │    0.919     │  0.413  │  0.299...
│          │  ╰────────────┴──────────────┴──────────────┴─────────┴─────────...
╰──────────┴─────────────────────────────────────────────────────────────────...
──╯...

Notice, that the number of trajectories is 150. So it takes 100 trajectories from ed_dataset and 50 trajectories from ed_ode.