def test_check_model(data, ss): reg = Regressor(ss=ss) summary, corr = reg.fit(df=data, outputs='T_int', inputs=['T_ext', 'P_hea']) assert not check_model(reg, summary, corr, verbose=True)
dict(name="sigw_w", value=0.1, transform="log"), dict(name="sigw_i", value=1e-8, transform="fixed"), dict(name="sigv", value=0.1, transform="log"), dict(name="x0_w", value=0.28, transform="log"), dict(name="x0_i", value=y0, transform="fixed"), dict(name="sigx0_w", value=1.0, transform="fixed"), dict(name="sigx0_i", value=1.0, transform="fixed") ] reg = Regressor(TwTi_RoRiAwAi(parameters, hold_order='foh')) inputs = [ 'Ambient temperature', 'Solar radiation: global horizontal', 'south_H' ] outputs = 'south_T' out = reg.fit(df=df[start_fit:stop_fit], inputs=inputs, outputs=outputs) # compute log-likelihood on validation dataset x, P = reg.estimate_states(df=df[start_fit:stop_fit], inputs=inputs, outputs=outputs) x0v = x[-1, :, :] P0v = np.linalg.cholesky(P[-1, :, :]).T reg.eval_log_likelihood(df=df[start_valid:stop_valid], inputs=inputs, outputs=outputs, x0=x0v, P0=P0v)
transform="lowup", bounds=(1e-10, 1.0)) reg.ss.parameters.set_parameter("sigw_i", value=0.1, transform="lowup", bounds=(1e-10, 1.0)) reg.ss.parameters.set_parameter("sigv", value=0.1, transform="lowup", bounds=(1e-10, 1.0)) reg.ss.parameters.set_parameter("x0_w", value=0.28, transform="lowup", bounds=(1e-7, 0.6)) reg.ss.parameters.set_parameter("x0_i", value=y0, transform="fixed") reg.ss.parameters.set_parameter("sigx0_w", value=1.0, transform="fixed") reg.ss.parameters.set_parameter("sigx0_i", value=1.0, transform="fixed") out = reg.fit(t, y, u, 'foh') # compute log-likelihood on validation dataset yp = df['south_T'][start_valid:stop_valid].values[np.newaxis, :] y0p = y[0, -1] / 100 tp = np.arange(0, dt * yp.shape[1], dt) reg.ss.parameters.set_parameter("x0_i", value=y0p, transform="fixed") up = df[['Ambient temperature', 'north_T', 'Solar radiation: global horizontal', 'south_H', 'vent2_H']][start_valid:stop_valid].values.T reg.eval_log_likelihood(tp, yp, up, 'foh') reg.ss.parameters.set_parameter("x0_i", value=y0, transform="fixed")
parameters = [ dict(name="Ro", value=0.1, transform="log"), dict(name="Ri", value=0.01, transform="log"), dict(name="Cw", value=0.1, transform="log"), dict(name="Ci", value=0.01, transform="log"), dict(name="sigw_w", value=0.01, transform="log"), dict(name="sigw_i", value=0.0, transform="fixed"), dict(name="sigv", value=0.01, transform="log"), dict(name="x0_w", value=0.25, transform="log"), dict(name="x0_i", value=y0, transform="fixed"), dict(name="sigx0_w", value=1.0, transform="fixed"), dict(name="sigx0_i", value=1.0, transform="fixed") ] reg = Regressor(TwTi_RoRi(parameters, hold_order='foh')) out = reg.fit(df=df, inputs=['T_ext', 'P_hea'], outputs='T_int') dt = 60 tnew = np.arange(df.index[0], df.index[-1] + dt, dt) y_mean_f, y_std_f = reg.predict(df=df, inputs=['T_ext', 'P_hea'], tpred=tnew) y_mean_s, y_std_s = reg.predict(df=df, outputs='T_int', inputs=['T_ext', 'P_hea'], tpred=tnew, smooth=True) # plot filtered and smoothed output plt.close("all") fig, axes = plt.subplots(nrows=1, ncols=1, sharex=True, sharey=True) fig.suptitle("filtered vs. smoothed state ")
df = pd.DataFrame(index=t, data=y, columns=['y']) parameters = [ dict(name="mscale", value=0.5, transform="log"), dict(name="lscale", value=0.5, transform="log"), dict(name="sigv", value=0.1, transform="log") ] reg12 = Regressor(Matern12(parameters)) reg32 = Regressor(Matern32(parameters)) reg52 = Regressor(Matern52(parameters)) # fit print("\nMatérn(1/2)") print("-" * 11) reg12.fit(df=df, outputs='y') print("\nMatérn(3/2)") print("-" * 11) reg32.fit(df=df, outputs='y') print("\nMatérn(5/2)") print("-" * 11) reg52.fit(df=df, outputs='y') # new data Nnew = 500 tnew = np.linspace(-0.1, 1.1, Nnew) # interpolate ym12, yd12 = reg12.predict(df=df, outputs='y', tpred=tnew, smooth=True)
df = pd.read_csv('../data/armadillo/armadillo_data_H2.csv').set_index('Time') y0 = 0.2670106194217502 parameters = [ dict(name="Ro", value=0.1, bounds=(1e-6, 0.3), prior=Normal(0.1, 0.04)), dict(name="Ri", value=0.01, bounds=(1e-6, 0.3), prior=Normal(0.05, 0.02)), dict(name="Cw", value=0.1, bounds=(1e-6, 0.3), prior=Normal(0.1, 0.04)), dict(name="Ci", value=0.01, bounds=(1e-6, 0.3), prior=Normal(0.05, 0.02)), dict(name="sigw_w", value=0.01, bounds=(1e-6, 0.3), prior=Normal(0.05, 0.02)), dict(name="sigw_i", value=0.0, transform="fixed"), dict(name="sigv", value=0.01, bounds=(1e-6, 0.3), prior=Normal(0.05, 0.02)), dict(name="x0_w", value=0.25, bounds=(0.1, 0.5), prior=Normal(0.25, 0.07)), dict(name="x0_i", value=y0, transform="fixed"), dict(name="sigx0_w", value=1.0, transform="fixed"), dict(name="sigx0_i", value=1.0, transform="fixed") ] reg = Regressor(TwTi_RoRi(parameters, hold_order='foh')) mh = reg.fit(df=df, inputs=['T_ext', 'P_hea'], outputs='T_int', options={ 'method': 'sMMALA', 'n_chains': 6, 'n_samples': 2000 })
N = 20 t = np.sort(np.random.rand(1, N), axis=1).flatten() y = np.sin(12 * t) + 0.66 * np.cos(25 * t) + np.random.randn(1, N) * 0.01 y = y.flatten() df = pd.DataFrame(index=t, data=y, columns=['y']) # Set Matern(3/2) parameters = [ dict(name="mscale", value=0.5, transform="log"), dict(name="lscale", value=0.5, transform="log"), dict(name="sigv", value=0.1, transform="log") ] reg = Regressor(Matern32(parameters)) results = reg.fit(df=df, outputs='y') # new data Nnew = 500 tnew = np.linspace(-0.1, 1.1, Nnew) ym_f, ys_f = reg.predict(df=df, outputs='y', tpred=tnew, smooth=False) ym_s, ys_s = reg.predict(df=df, outputs='y', tpred=tnew, smooth=True) # plot filtered and smoothed output plt.close("all") fig, axes = plt.subplots(nrows=2, ncols=1, sharex=True, sharey=True) fig.suptitle("filtered vs. smoothed state ") plt.xlim(-0.1, 1.1) axes[0].set_title("filtered") axes[0].plot(t, y, 'kx', mew=2)
dict(name="period", value=1.5, transform="log"), dict(name="mscale", value=1.0, transform="log"), dict(name="lscale", value=1.0, transform="log"), dict(name="sigv", value=0.1, transform="log") ] par_Matern12 = [ dict(name="mscale", value=1.0, transform="log"), dict(name="lscale", value=10.0, transform="log"), dict(name="sigv", value=0.1, transform="log") ] quasi_periodic = GPProduct(Periodic(par_Periodic), Matern12(par_Matern12)) reg = Regressor(quasi_periodic) results = reg.fit(df=data, outputs='y') Nnew = 500 tnew = np.linspace(xlim[0], xlim[1] + 3, Nnew) y_mean_f, y_std_f = reg.predict(df=data, outputs='y', tpred=tnew, smooth=False) y_mean_s, y_std_s = reg.predict(df=data, outputs='y', tpred=tnew, smooth=True) # plot filtered and smoothed output plt.close("all") fig, axes = plt.subplots(nrows=2, ncols=1, sharex=True, sharey=False) fig.suptitle("filtered vs. smoothed state ") axes[0].set_title("filtered") axes[0].plot(t, y, 'kx', mew=2) axes[0].plot(tnew, y_mean_f, 'C0', lw=2) axes[0].fill_between(tnew,