Systems

class deepSI.systems.System(action_space=None, observation_space=None)

The base System class

action_space

the input shape of input u. (None is a single unbounded float)

Type:

gym.space or None

observation_space

The input shape of output y. (None is a single unbounded float)

Type:

gym.space or None

norm

Used in most fittable systems to normalize the input output.

Type:

instance of System_data_norm

fitted
Type:

Boole

unique_code

Some random unique 4 digit code (can be used for saving/loading)

Type:

str

name

concatenation of the the class name and the unique code

Type:

str

use_norm
Type:

bool

seed

random seed

Type:

int

random

unique random generated initialized with seed (only created ones called)

Type:

np.random.RandomState

__init__(action_space=None, observation_space=None)

Create a System

Parameters:
  • action_space (gym.space or None) – the input shape of input u. (None is a single unbounded float)

  • observation_space (gym.space or None) – The input shape of output y. (None is a single unbounded float)

exists(name)
check_valid_system()
property name
property random
property act_measure_sys
property dt
get_state()

state of the system (not the parameters)

Returns:

state

Return type:

the user defined state

apply_experiment(sys_data, save_state=False, init_state=True)

Does an experiment (i.e. applying an input series u sequentionally to a system) with for a given system data (fixed u)

Parameters:
  • sys_data (System_data or System_data_list (or list or tuple)) – The experiment which should be applied

  • save_state (boole) – A flag to indicate that the state provided by self.get_state should be saved on the variable of the resulting Sysdata of .x

  • init_state (boole) – A flag to indicate that the all initalization should be skipped and the current state set before calling apply_experiment should be used. This can be used to manually set a initial state.

Notes

This will initialize the state using self.init_state if sys_data.y (and u) is not None and skip the appropriate number of steps associated with it. If either is missing than self.reset_state() is used to initialize the state. Afterwards this state is advanced using sys_data.u and the output is saved at each step. Lastly, the number of skipped/copied steps in init_state is saved as sys_data.cheat_n such that it can be accounted for later.

measure_act(action)
  1. Measure giving the current state and action

  2. advance state using action

calls measure_act_multi if (measure_act_multi or act_measure_multi is overwritten) was overwritten

measure_act_multi(actions)

calls act_measure if it was overwritten otherwise will throw an error

act_measure(action)
act_measure_multi(actions)
reset_state()

Should reset the internal state

if the system is act_measure it will call reset_state_and_measure and save the current output.

reset_state_and_measure()

Should reset the internal state and return the current measurement

init_state(sys_data)

initalizes the interal state using the sys_data and returns the number of steps used in the initilization

Returns:

k0 – number of steps that have been skipped

Return type:

int

Notes

Example: x[k0] = encoder(u[t-k0:k0],yhist[t-k0:k0]), and k0 This function is often overwritten in child. As default it will call self.reset and return 0

init_state_multi(sys_data, nf=None, stride=1)
init_state_and_measure(sys_data)
init_state_and_measure_multi(sys_data, nf=None, stride=1)
multi_step_ahead(sys_data, nf, full=False)

calculates the n-step precition

Parameters:
  • sys_data (System_data) –

  • n (int) –

  • full (boole) – if full not only the final n step prediction will be return but also the steps inbetween

one_step_ahead(sys_data)

One step ahead prediction

n_step_error(sys_data, nf=100, stride=1, mode='NRMS', mean_channels=True)

Calculate the expected error after taking n=1…nf steps.

Parameters:
  • sys_data (System_data) –

  • nf (int) – upper bound of n.

  • stride (int) – passed to init_state_multi to reduce memory cost.

  • mode (str or System_data_norm) – ‘NRMS’, ‘RMS’, ‘NRMS_sys_norm’ or a System_data_norm for norm obtained from the sys_data, no norm norm obtained from the provided data, given norm

  • mean_channels (boole) – return (nf) shape if true and (nf,ny) alike if false.

n_step_error_plot(sys_data, nf=100, stride=1, mode='NRMS', mean_channels=True, show=True)
save_system(file)

Save the system using pickle

Notes

This can be quite unstable for long term storage or switching between versions of this and other modules. Consider manually creating a save_system function for a long term solution.

sample_system(N_sampes=10000)

Mostly used for testing purposes it, will apply random actions on the system

__module__ = 'deepSI.systems.system'
class deepSI.systems.System_gym(env, env_kwargs={}, n=None)

docstring for System_gym

__init__(env, env_kwargs={}, n=None)
reset_state_and_measure()
act_measure(action)

Applies the action to the systems and returns the new observation

__module__ = 'deepSI.systems.system'
class deepSI.systems.System_ss(nx, nu=None, ny=None)

Derived state-space system with continues u, x, y vectors or scalars

__init__(nx, nu=None, ny=None)
reset_state()
measure_act(action)
f(x, u)

x[k+1] = f(x[k],u[k])

h(x, u)

y[k] = h(x[k],u[k])

get_state()
__module__ = 'deepSI.systems.system'
class deepSI.systems.System_io(na, nb, nu=None, ny=None, feedthrough=False)
__init__(na, nb, nu=None, ny=None, feedthrough=False)
reset_state()
property k0
init_state(sys_data)
init_state_multi(sys_data, nf=100, stride=1)
measure_act(action)
measure_act_multi(actions)
io_step(uy)
__module__ = 'deepSI.systems.system'
multi_io_step(uy)
get_state()
deepSI.systems.load_system(file)

This is not a safe function, only use on trusted files

class deepSI.systems.System_deriv(dt=None, nx=None, nu=None, ny=None, method='RK4')

ZOH integration for datageneration

__init__(dt=None, nx=None, nu=None, ny=None, method='RK4')
f(x, u)
deriv(x, u)
__module__ = 'deepSI.systems.system'
class deepSI.systems.Test_ss_linear1

docstring for Test_ss_linear1

__init__()

Noise, system setting and x0 settings

f(x, u)
h(x, u)
__module__ = 'deepSI.systems.test_systems'
class deepSI.systems.Test_ss_linear2

xk+1 = [[0.7,0.8],[0,0.1]] xk + [-1,0.1]*uk + nuk yk = xk[0] + wk nuk = N(0,0.5) x 2 wk = N(0,1)

__init__()

Noise, system setting and x0 settings

f(x, u)
h(x, u)
__module__ = 'deepSI.systems.test_systems'
class deepSI.systems.Double_bath(k1=0.5, k2=0.4, k3=0.2, k4=0.3, sigmaw=0.0, sigmav=0.0)
__init__(k1=0.5, k2=0.4, k3=0.2, k4=0.3, sigmaw=0.0, sigmav=0.0)
f(x, u)
h(x, u)
get_train_data(seed=None)
get_test_data(seed=None)
__module__ = 'deepSI.systems.double_bath'
class deepSI.systems.Cascaded_tanks_continuous(k1=0.5, k2=0.4, k3=0.2, k4=0.3, sigmav=0.0, dt=2, x1overflow=8, x2overflow=25)
__init__(k1=0.5, k2=0.4, k3=0.2, k4=0.3, sigmav=0.0, dt=2, x1overflow=8, x2overflow=25)
f(x, u)
h(x, u)
deriv(x, u)
__module__ = 'deepSI.systems.double_bath'
class deepSI.systems.Pendulum(dt=None, omega0=1, Fc=0.1, lin=False)

docstring for Pendulum

th,omega = x dth/dt = omega domega/dt = Tau / I - Fomega Tau = sum(r x F) = u - L m g sin(th) I = m L^2, domega/dt = u - g/L sin(th) - Fc omega

__init__(dt=None, omega0=1, Fc=0.1, lin=False)

Noise, system setting and x0 settings

deriv(x, u)
h(x, u)
__module__ = 'deepSI.systems.pendulum'
class deepSI.systems.NarendraLiBenchmark

docstring for NarendraLiBenchmark

__init__()

Noise, system setting and x0 settings

f(x, u)
h(x, u)
get_train_data()
get_test_data()
__module__ = 'deepSI.systems.narendra_li_benchmark'
class deepSI.systems.Nonlin_io_normals
__init__()
io_step(uy)
__module__ = 'deepSI.systems.classical_literature'
class deepSI.systems.Hammerstein_sysid_book
__init__()
io_step(uy)
__module__ = 'deepSI.systems.classical_literature'
class deepSI.systems.Wiener_sysid_book
__init__()
io_step(uy)
__module__ = 'deepSI.systems.classical_literature'
class deepSI.systems.Wiener2_sysid_book
__init__()
io_step(uy)
__module__ = 'deepSI.systems.classical_literature'
class deepSI.systems.NDE_squared_sysid_book
__init__()
io_step(uy)
__module__ = 'deepSI.systems.classical_literature'
class deepSI.systems.Dynamic_nonlin_sysid_book
__init__()
io_step(uy)
__module__ = 'deepSI.systems.classical_literature'
class deepSI.systems.Nonlin_io_example_2
__init__()
io_step(uy)
__module__ = 'deepSI.systems.classical_literature'
class deepSI.systems.Nonlinear_rlc

docstring for nonlinear_RLC

th,omega = x dth/dt = omega domega/dt = Tau / I - Fomega Tau = sum(r x F) = u - L m g sin(th) I = m L^2, domega/dt = u - g/L sin(th) - Fc omega

__init__()

Noise, system setting and x0 settings

deriv(x, u)
h(x, u)
get_train_data(N=4000)
get_test_data(N=4000)
__module__ = 'deepSI.systems.nonlinear_rlc'
class deepSI.systems.Nonlin_drag(dt=1, Fdrag=<function Nonlin_drag.<lambda>>)
__init__(dt=1, Fdrag=<function Nonlin_drag.<lambda>>)
deriv(x, u)
h(x, u)
get_train_data()
get_test_data()
__module__ = 'deepSI.systems.nonlin_drag'
class deepSI.systems.Coupled_electric_drive
__init__()
h(x, u)
__module__ = 'deepSI.systems.nonlin_drag'
class deepSI.systems.Lorenz_attractor(sigma=10, beta=2.6666666666666665, rho=28)
Description:

lorenz attractor learning envoriement x’ = sigma*(y-x) + a y’ = x*(rho-z) - y z’ = x*y - beta*z with as goal maximizing the number of x-crossings with the control a with as constraint that |a|<=1

Source:

Gerben Beintema from TU/e

Observation:

Type: Box(3,) Num Observation Min Max 0 current x -30 30 1 current y -40 40 2 current z 0 70

Actions:

Type: Discrete(3) or continues Box(1,) (min=-1, max=1) If Discrate(3):

action = 0 -> a = -1 action = 1 -> a = 0 action = 2 -> a = 1

if continues ie Box(1,):

a = action (with -1<=action<=1)

Reward:

1 for every crossing of the x-axis else 0

Starting State:

random position on the uncontrolled lorenz attractor (done by taking 500 steps)

Episode Termination:

1000 cycles

__init__(sigma=10, beta=2.6666666666666665, rho=28)

Noise, system setting and x0 settings

reset_state()
h(x, u)
deriv(x, u)

x’ = sigma*(y-x) + a y’ = x*(rho-z) - y (+ b) z’ = x*y - beta*z

__module__ = 'deepSI.systems.lorenz_attractor'
class deepSI.systems.Lorenz_attractor_sincos(sigma=10, beta=2.6666666666666665, rho=28)
h(x, u)
__module__ = 'deepSI.systems.lorenz_attractor'
class deepSI.systems.Van_der_pol_oscillator(dt=0.2, mu=2.5)

docstring for Van_der_pol_oscillator

__init__(dt=0.2, mu=2.5)
reset_state()
h(x, u)
deriv(state, u)
__module__ = 'deepSI.systems.van_der_pol_oscillator'
class deepSI.systems.Double_potential_well(a=1, Fmax=0.25, Nresist=0.7)

docstring for Double_potential_well

V(x) = 1/2*min((x-a)**2,(x+a)**2) v’ = -(x-a) if x>0 else (x+a) + u #+ resistance x’ = v Fmax < a Fmin > -a

__init__(a=1, Fmax=0.25, Nresist=0.7)

Noise, system setting and x0 settings

reset_state()
deriv(x, u)
h(x, u)
__module__ = 'deepSI.systems.double_well'
class deepSI.systems.Double_potential_well_video(a=1, Fmax=0.25, Nresist=0.7)

docstring for Double_potential_well_video

V(x) = 1/2*min((x-a)**2,(x+a)**2) v’ = -(x-a) if x>0 else (x+a) + u #+ resistance x’ = v Fmax < a Fmin > -a

__init__(a=1, Fmax=0.25, Nresist=0.7)
h(x, u)
__module__ = 'deepSI.systems.double_well'
class deepSI.systems.Ball_in_box(Fmax=0.25, Nresist=0.7)

docstring for double_well_system

dvxdt = (1/x**2-1/(1-x)**2)/200+ux-self.gamma*vx dvydt = (1/y**2-1/(1-y)**2)/200+uy-self.gamma*vy

__init__(Fmax=0.25, Nresist=0.7)

Noise, system setting and x0 settings

reset_state()
deriv(x, u)
h(x, u)
__module__ = 'deepSI.systems.ball_in_box'
class deepSI.systems.Ball_in_box_video(Fmax=0.25, image_height=25, image_width=25)

docstring for double_well_system

V(x) = 1/2*min((x-a)**2,(x+a)**2) v’ = -(x-a) if x>0 else (x+a) + u #+ resistance x’ = v Fmax < a Fmin > -a

__init__(Fmax=0.25, image_height=25, image_width=25)
h(x, u)
__module__ = 'deepSI.systems.ball_in_box'
class deepSI.systems.Bouc_wen(seed=None, dt=0.0013333333333333333, integration_factor=20)
__init__(seed=None, dt=0.0013333333333333333, integration_factor=20)
deriv(x, u)
h(x, u)
get_train_data()
get_test_data()
apply_experiment(exp)
__module__ = 'deepSI.systems.boucwen'