Skip to content

Tutorials

Single component example

Here is an example of interpolating a simple quadratic function.

amisc.examples.tutorial.py
from amisc.rv import UniformRV
from amisc.system import ComponentSpec, SystemSurrogate

def fun(x):
    return dict(y=x ** 2)

x = UniformRV(-1, 1)
y = UniformRV(0, 1)
component = ComponentSpec(fun)
system = SystemSurrogate([component], x, y)

system.fit()
system.predict(0.5)  # 0.25

Two component system

Here is a simple example of a two-component multidisciplinary system.

amisc.examples.tutorial.py
import numpy as np

from amisc.rv import UniformRV
from amisc.system import ComponentSpec, SystemSurrogate

def fun1(x):
    return dict(y=x * np.sin(np.pi * x))

def fun2(x):
    return dict(y=1 / (1 + 25 * x ** 2))

x = UniformRV(0, 1, 'x')
y = UniformRV(0, 1, 'y')
z = UniformRV(0, 1, 'z')
model1 = ComponentSpec(fun1, exo_in=x, coupling_out=y)
model2 = ComponentSpec(fun2, coupling_in=y, coupling_out=z)

inputs = x
outputs = [y, z]
system = SystemSurrogate([model1, model2], inputs, outputs)
system.fit()

x_test = system.sample_inputs(10)
y_test = system.predict(x_test)
The first component computes \(y=x\sin(\pi x)\). The second component takes the output of the first and computes \(z=1 / (1 + 25y^2)\). The system-level input is \(x\) and the system-level outputs are \(y\) and \(z\).

Note

Each component always locally returns a dictionary with the output saved as y=value. This is not to be confused with the system-level y variable in this example.

Fire detection satellite

Here is an example of a three-component fire detection satellite system from Chauduri (2018).

amisc.examples.tutorial.py
import numpy as np

from amisc.examples.models import fire_sat_system

system = fire_sat_system()

xtest = system.sample_inputs(100, use_pdf=True)     # --> (100, xdim)
ytest = system(xtest, use_model='best')             # --> (100, ydim)
use_idx = ~np.any(np.isnan(ytest), axis=-1)
xtest = xtest[use_idx, :]
ytest = ytest[use_idx, :]
test_set = {'xt': xtest, 'yt': ytest}

system.fit(max_iter=10, test_set=test_set, n_jobs=-1, num_refine=1000)

print(f'Inputs: {system.exo_vars}')
print(f'Outputs: {system.coupling_vars}')

# Plots
input_vars = ['H', 'Po']
output_vars = ['Vsat', 'Asa']
system.plot_allocation()
system.plot_slice(input_vars, output_vars, show_model=['best', 'worst'], random_walk=True, N=10)
We first generate a test set using the ground truth model predictions (and filter any bad values out). Then we train the surrogate in 10 iterations, and finally plot some results. Here is the output of plot_slice(): Fire satellite system results