예제 #1
0
from grey_box_modeling import batch_partition
from grey_box_modeling import build_training_model
from grey_box_modeling import build_inference_model
import tensorflow as tf
from matio import loadmat
import numpy as np
import matplotlib.pyplot as plt

# Full information problem first
# This case is just straight-up grey-box ID
Nopt = 10
Nx = 2
Na = 4
Naux = 4
# Load a dataset
data = loadmat('simple_data_summer.mat')

pars_scaled = data['pars_scaled']

# Construct model
model, aux_reshapor, uss_reshapor, grey_box_layer, LSTM_cell, densor = build_training_model(
    Nx=Nx, lstm=True, Nt=Nopt, Na=Na, Naux=Naux, custom_init=pars_scaled)

opt = tf.keras.optimizers.Adam(lr=1e-8, beta_1=0.9, beta_2=0.999, decay=0.01)

model.compile(optimizer=opt, loss='mse')

# Outputs
x = data['x']

# Inputs
예제 #2
0
                                    sigma_change=1,
                                    seed=seed + 1)
    disturbances[0:tsteps_steady, :] = np.zeros((tsteps_steady, Np))

    # Compile into a list of scenarios.
    scenarios = [(setpoints.copy(), disturbances)]

    # Return the set-points and the disturbances.
    return scenarios


if __name__ == "__main__":
    # Load the unscaled model, and the input and the output constraints.
    dist_indices = (0, 6, 23, 30, 31)
    dist_scaling = np.array([[5., 20., 20., 20., 20.]])
    model = matio.loadmat('CDU_Model.mat', squeeze=False)
    # Get the plant.
    (cdu, uscale, yscale, lb, ub) = _get_cdu_plant(model, dist_indices,
                                                   dist_scaling)
    cdu_mpc_controller = _get_cdu_mpc_controller(cdu, lb, ub)
    cdu_satdlqr_controller = _get_satdlqr_controller(cdu_mpc_controller)
    cdu_us_controller = _get_us_controller(cdu_mpc_controller)
    cdu_sh_controller = _get_short_horizon_controller(cdu_mpc_controller, N=3)
    cdu_offline_simulator = _get_cdu_offline_simulator(cdu_mpc_controller,
                                                       dist_indices,
                                                       dist_scaling,
                                                       lb,
                                                       ub,
                                                       Nsim=357600,
                                                       num_data_gen_task=int(
                                                           sys.argv[1]),
    Nx, Nt = series.shape

    num_batches = int(np.floor(Nt / Tx))
    batches = np.zeros((num_batches, Tx, Nx))

    for batch in range(0, num_batches):
        batches[batch, :, :] = np.transpose(series[:, Tx * batch:Tx *
                                                   (batch + 1)])

    return batches


# Load data
# First test my LSTM function again on Qother
data = loadmat('simple_data.mat')
Qother = data['Qother'].reshape(1, len(data['Qother']))

Nhorizon = 10
Nd = 1
Naux = 31
Qx = batch_partition(Qother, Nhorizon)
num_batches = Qx.shape[0]
HoD = batch_partition(data['HoD'], Nhorizon)
DoW = batch_partition(data['DoW'], Nhorizon)
Qy = batch_partition(Qother[0, 1:].reshape(1, Qother.shape[1] - 1), Nhorizon)
Qy = Qy.reshape(Nhorizon, num_batches, Nd)

## Some use case classes
reshapor = tf.keras.layers.Reshape((1, Nd + Naux))
Na = 12  # Number of outputs of the LSTM
예제 #4
0
# Partition data into batches for tf.keras
def batch_partition(series, Tx):
    
    Nx, Nt = series.shape
    
    num_batches = int(np.floor(Nt/Tx))
    batches = np.zeros((num_batches, Tx, Nx))
    
    for batch in range(0, num_batches):
        batches[batch, :, :] = np.transpose(series[:, Tx*batch:Tx*(batch+1)])
    
    return batches

# Load data
# First test my LSTM function again on Qother
data = loadmat('hvacid.mat')
iddata = loadmat('simple_data.mat')
yres = data['yres'].reshape(1, len(data['yres']))

yres_mean = np.mean(yres, axis = 1)
yres_std = np.std(yres, axis = 1)

#Scale the data
yres = (yres - yres_mean)/yres_std

Nhorizon = 10
Nd = 1
Naux = 31
Qx = batch_partition(yres, Nhorizon)
num_batches = Qx.shape[0]
HoD = batch_partition(iddata['HoD'], Nhorizon)