def test_fit_predict_normalize(): '''Tests with dataset''' D = tsio.from_id_row_mat(YOUTUBE_1K, add_eps=1e-2) ssm = SSM(False, False, 1, normalize_err=True) Y = ssm.fit_predict(D) assert Y.any()
def test_fit_predict2(): ''' Tests the fit and predict methods for the state space models. Period Only ''' D = tsio.from_id_row_mat(YOUTUBE_1K, add_eps=1e-2).np_like_firstn() D = D[: 50] ssm = SSM(False, True, 50) X_train = D[:, :50] X_test = D[:, 50:] Y = ssm.fit_predict(X_train) err = ((X_test - Y) ** 2).mean() assert_equal((50, 50), Y.shape) assert err > 0
def test_fit_predict(): ''' Tests the fit and predict methods for the state space models. Trend + period ''' D = tsio.from_id_row_mat(YOUTUBE_1K, add_eps=1e-2).np_like_firstn() D = D[: 50] ssm = SSM(True, True, 50) D = (D.T / D.sum(axis=1)).T X_train = D[:, :50] X_test = D[:, 50:] Y = ssm.fit_predict(X_train) err = ((X_test - Y) ** 2).mean() assert_equal((50, 50), Y.shape) print(err) assert err > 0
def real_fit(args): obj_key, pop_series = args try: model = models.WavePhoenixR() model.fit(pop_series) params = model.parameters phoenix_model = model(pop_series.shape[0]) ssm1 = SSM(True, True, steps_ahead=0) ssm1_model = ssm1.fit_predict(pop_series[None], True)[0] ssm2 = SSM(True, False, steps_ahead=0) ssm2_model = ssm2.fit_predict(pop_series[None], True)[0] ssm3 = SSM(False, True, steps_ahead=0) ssm3_model = ssm3.fit_predict(pop_series[None], True)[0] ssm4 = SSM(False, False, steps_ahead=0) ssm4_model = ssm4.fit_predict(pop_series[None], True)[0] out = StringIO.StringIO() print(obj_key, file=out) print(dict((k, v.value) for k, v in params.items()), file=out) print(rmsqerr(pop_series, phoenix_model), \ bic(pop_series, phoenix_model, model.num_params), end=' ', file=out) print(rmsqerr(pop_series, ssm1_model), \ bic(pop_series, ssm1_model, 7), end=' ', file=out) print(rmsqerr(pop_series, ssm2_model), \ bic(pop_series, ssm2_model, 5), end=' ', file=out) print(rmsqerr(pop_series, ssm3_model), bic(pop_series, ssm3_model, 5), end=' ', file=out) print(rmsqerr(pop_series, ssm4_model), bic(pop_series, ssm4_model, 3), end=' ', file=out) return out.getvalue() except Exception as e: import traceback print('err at key', obj_key, file=sys.stderr) traceback.print_exc(e, file=sys.stderr) return None