System data
- class deepSI.system_data.System_data(u=None, y=None, x=None, cheat_n=0, normed=False, dt=None)
System Data to be used
- u
The u input signal, first dimension is time.
- Type:
array
- y
The y output signal, first dimension is time. It can be not present.
- Type:
array or None
- x
The x internal state signal, first dimension is time. (often unused)
- Type:
array or None
- nu
Number of input dimensions. None -> self.u.shape == (N) Number -> self.u.shape == (N,nu) Tuple -> self.u.shape == (N,…)
- Type:
None, Number, Tuple
- ny
Number of input dimensions. None -> self.u.shape == (N) Tuple -> self.y.shape == (N,…)
- Type:
None, Number, Tuple
- cheat_n
Number of samples copied when simulation was applied. This number of samples will not be used to calculate RMS and such.
- Type:
int
- multi_u
Check for multi dimensional u, used to check SISO.
- Type:
bool
- multi_y
Check for multi dimensional y, used to check SISO.
- Type:
bool
- normed
Check if this data set is normed (i.e. was used as norm.transform(sys_data)) mostly used for debugging.
- Type:
bool
- __init__(u=None, y=None, x=None, cheat_n=0, normed=False, dt=None)
Create System data to be used in fitting, plotted and
- Parameters:
u (array or list or None) – Input signal with an array where the first dimension is time
y (array or list or None) – output signal with an array where the first dimension is time
x (array or list or None) – internal state signal with an array where the first dimension is time
cheat_n (int) – Number of samples copied when simulation was applied. This number of samples will not be used to calculate RMS and such.
normed (bool) – Check if this data set is normed (i.e. was used as norm.transform(sys_data)) mostly used for debugging.
- property N_samples
- property ny
Number of output dimensions. None or number or tuple
- property nu
Number of input dimensions. None or number or tuple
- property nx
Number of internal states. None or number or tuple
- flatten()
Flatten both u and y to (N,nu) and (N,ny) returns a new System_data
- reshape_as(other)
Inverse of .flatten and will reshape both u and y to (N,) + other.u.shape[1:] and (N,) + other.y.shape[1:]
- to_IO_data(na=10, nb=10, stride=1, online_construct=False, feedthrough=False)
Transforms the system data to Input-Output structure (hist,Y) with y length of na, and u length of nb
- Parameters:
na (int) – y history considered
nb (int) – u history considered
- Returns:
hist (ndarray of (Samples, na*ny + nb*nu)) – array of combination of historical inputs and output as [u[k-nb:k].flat,y[k-na:k].flat] for many k
Y (ndarray (Samples, features) or (Samples)) – array of single step ahead [y]
- to_hist_future_data(na=10, nb=10, nf=5, na_right=0, nb_right=0, stride=1, force_multi_u=False, force_multi_y=False, online_construct=False)
Transforms the system data to encoder structure as structure (uhist,yhist,ufuture,yfuture) of
Made for simulation error and multi step error methods
- Parameters:
na (int) – y history considered
nb (int) – u history considered
nf (int) – future inputs considered
- Returns:
uhist (ndarray (samples, nb, nu) or (sample, nb) if nu=None) – array of [u[k-nb],….,u[k - 1 + nb_right]]
yhist (ndarray (samples, na, ny) or (sample, na) if ny=None) – array of [y[k-na],….,y[k - 1 + na_right]]
ufuture (ndarray (samples, nf, nu) or (sample, nf) if nu=None) – array of [u[k],….,u[k+nf-1]]
yfuture (ndarray (samples, nf, ny) or (sample, nf) if ny=None) – array of [y[k],….,y[k+nf-1]]
- to_ss_data(nf=20, stride=1, force_multi_u=False, force_multi_y=False, online_construct=False)
- to_encoder_data(na=10, nb=10, nf=5, stride=1, force_multi_u=False, force_multi_y=False, online_construct=False)
Transforms the system data to encoder structure as structure (hist,ufuture,yfuture) of
- Parameters:
na (int) – y history considered
nb (int) – u history considered
nf (int) – future inputs considered
stride (int) – skipping data for smaller data set.
force_multi_u (bool) – converts to ufuture to #(samples, time_seq, nu) always
force_multi_y (bool) – converts to yfuture to #(samples, time_seq, ny) always
- Returns:
hist (ndarray (samples, ny*na + nu*nb)) – array of concat of u[k-nb-nf:k-nf].flat and y[k-na-nf:k-nf].flat
ufuture (ndarray (samples, nf, nu) or (sample, nf) if nu=None) – array of [u[k],….,u[k+nf-1]]
yfuture (ndarray (samples, nf, ny) or (sample, nf) if ny=None) – array of [y[k],….,y[k+nf-1]]
- to_video(file_name='video.mp4', scale_factor=10, vmin=0, vmax=1, fps=60)
Used cv2 to create a video from y of shape y.shape = (frames, ny1, ny2)
- plot_state_space_3d(nmax=2000, kernal=None, interpol_n=10)
- save(file)
Saves data with savez, see also load_system_data
- plot(show=False)
Very simple plotting function
- BFR(real, multi_average=True)
Best Fit Rate in percent i.e. 100*(1 - np.sum((y-yhat)**2)**0.5/np.std(y)) (100 = best possible fit)
- NRMS(real, multi_average=True, per_channel=True)
Normalized root mean square i.e. np.sum((y-yhat)**2)**0.5/np.std(y) (0 = best fit possible)
- NRMS_per_channel(real, multi_average=True)
Normalized root mean square i.e. np.sum((y-yhat)**2)**0.5/np.std(y) (0 = best fit possible)
- NRMS_mean_channels(real, multi_average=True)
Normalized root mean square i.e. np.sum((y-yhat)**2)**0.5/np.std(y) (0 = best fit possible)
- RMS(real, multi_average=True)
Root mean square error
- MSE(real, multi_average=True)
mean square error
- MAE(real, multi_average=True)
mean absolute error
- VAF(real, multi_average=True)
Variance accounted also known as R^2
calculated as 100*(1 - np.mean((y-yhat)**2)/np.std(y)**2) (100 = best possible fit)
- __sub__(other)
Calculate the difference between y two System_data a number or array
- train_test_split(split_fraction=0.25)
returns 2 data sets of length n*(1-split_fraction) and n*split_fraction respectively (left, right) split
- __getitem__(arg)
Slice the System_data in time index
- __len__()
Number of samples len(system_data) = self.N_samples
- down_sample_by_average(factor)
Down sample method
- Parameters:
factor (int) – length will be (original length)/factor
- down_sample_by_decimate(factor)
Down sample method :param factor: length will be (original length)/factor :type factor: int
- down_sample_by_MIMO(factor)
Down sample method
- Parameters:
factor (int) – length will be (original length)/factor
- __annotations__ = {}
- __module__ = 'deepSI.system_data.system_data'
- class deepSI.system_data.System_data_list(sys_data_list=None)
A list of System_data, has most methods of System_data in a list form with only some exceptions listed below
- sdl
- Type:
list of System_data
- y
concatenated y of system_data contained in sdl
- Type:
array
- u
concatenated u of system_data contained in sdl
- Type:
array
- append(System_data) adds element to sdl
- extend(list) adds elements to sdl
- __getitem__(number) get (ith system data, time slice)
- __init__(sys_data_list=None)
- sanity_check()
- property normed
- property N_samples
- property ny
- property nu
- property y
- property u
- property n_cheat
- property dt
- flatten()
- reshape_as(other)
Inverse of .flatten and will reshape both u and y to (N,) + other.u.shape[1:] and (N,) + other.y.shape[1:]
- to_IO_data(na=10, nb=10, stride=1, online_construct=False, feedthrough=False)
- to_hist_future_data(na=10, nb=10, na_right=0, nb_right=0, nf=5, stride=1, force_multi_u=False, force_multi_y=False, online_construct=False)
- to_ss_data(nf=20, stride=1, force_multi_u=False, force_multi_y=False, online_construct=False)
- to_encoder_data(na=10, nb=10, nf=5, stride=1, force_multi_u=False, force_multi_y=False, online_construct=False)
- save(file)
Saves data
- plot(show=False)
Very simple plotting function
- weighted_mean(vals)
- RMS(real, multi_average=True)
- MSE(real, multi_average=True)
- MAE(real, multi_average=True)
- __sub__(other)
- train_test_split(split_fraction=0.25)
return 2 data sets of length n*(1-split_fraction) and n*split_fraction respectively (left, right) split
- __getitem__(arg)
get (ith system data, time slice)
- __len__()
- append(other)
- extend(other)
- down_sample_by_average(factor)
Down sample method
- Parameters:
factor (int) – length will be (original length)/factor
- down_sample_by_decimate(factor)
Down sample method
- Parameters:
factor (int) – length will be (original length)/factor
- down_sample_by_MIMO(factor)
Down sample method
- Parameters:
factor (int) – length will be (original length)/factor
- __annotations__ = {}
- __module__ = 'deepSI.system_data.system_data'
- class deepSI.system_data.System_data_norm(u0=0, ustd=1, y0=0, ystd=1)
A utility to normalize system_data before fitting or usage
- u0
average u to be subtracted
- Type:
float or array
- ustd
standard divination of u to be divided by
- Type:
float or array
- y0
average y to be subtracted
- Type:
float or array
- ystd
standard divination of y to be divided by
- Type:
float or array
- __init__(u0=0, ustd=1, y0=0, ystd=1)
- property is_id
- make_training_data(sys_data)
- fit(sys_data)
set the values of u0, ustd, y0 and ystd using sys_data (can be a list) given
- transform(sys_data)
- Transform the data by
u <- (sys_data.u-self.u0)/self.ustd y <- (sys_data.y-self.y0)/self.ystd
- Parameters:
sys_data (System_data) – sys_data to be transformed
- Return type:
System_data or System_data_list if a list was given
- inverse_transform(sys_data)
- Inverse Transform the data by
u <- sys_data.u*self.ustd+self.u0 y <- sys_data.y*self.ystd+self.y0
- Parameters:
sys_data (System_data) –
- Return type:
System_data or System_data_list if a list was given
- __module__ = 'deepSI.system_data.system_data'
- deepSI.system_data.load_system_data(file)
Load System_data from .npz file