<commit_before>from __future__ import absolute_import, print_function

import numpy as np
from numpy.testing import assert_, assert_allclose

import statsmodels.datasets.interest_inflation.data as e6
from .results_JMulTi.parse_jmulti_output import load_results_jmulti
from .results_JMulTi.parse_jmulti_output import dt_s_tup_to_string
from statsmodels.tsa.vecm.vecm import VECM
from statsmodels.tsa.vector_ar.var_model import VARProcess

atol = 0.001  # absolute tolerance
rtol = 0.01  # relative tolerance
datasets = []
data = {}
results_ref = {}
results_sm = {}
coint_rank = 1

debug_mode = False
dont_test_se_t_p = False
deterministic_terms_list = ["nc", "co", "colo", "ci", "cili"]
seasonal_list = [0, 4]
dt_s_list = [(det, s) for det in deterministic_terms_list
             for s in seasonal_list]
all_tests = ["Gamma", "alpha", "beta", "C", "det_coint", "Sigma_u",
             "VAR repr. A", "VAR to VEC representation", "log_like"]
to_test = all_tests  # ["beta"]


def load_data(dataset, data_dict):
    dtset = dataset.load()
    # works for datasets with time-related first 2 names (e.g. year, quarter)
    variables = list(dtset.names[2:])
    loaded = dtset.data[variables].view(float, type=np.ndarray)
    data_dict[dataset] = loaded.reshape((-1, len(variables)))


def load_results_statsmodels(dataset):
    results_per_deterministic_terms = dict.fromkeys(dt_s_list)
    for dt_s_tup in dt_s_list:
        model = VECM(data[dataset], diff_lags=3,
                     deterministic=dt_s_tup[0], seasons=dt_s_tup[1])
        # print("\n\n\nDETERMINISTIC TERMS: " + deterministic_terms)
        results_per_deterministic_terms[dt_s_tup] = model.fit(
                method="ml", coint_rank=coint_rank)
    return results_per_deterministic_terms


def build_err_msg(ds, dt_s, parameter_str):
    dt = dt_s_tup_to_string(dt_s)
    seasons = dt_s[1]
    err_msg = "Error in " + parameter_str + " for:\n"
    err_msg += "- Dataset: " + ds.__str__() + "\n"
    err_msg += "- Deterministic terms: "
    err_msg += (dt_s[0] if dt != "nc" else "no det. terms")
    if seasons > 0:
        err_msg += ", seasons: " + str(seasons)
    return err_msg


def test_ml_gamma():
    if debug_mode:
        if "Gamma" not in to_test:<commit_msg>add file forgotten in last commit.<commit_after>from __future__ import absolute_import, print_function

import numpy as np
from numpy.testing import assert_, assert_allclose

import statsmodels.datasets.interest_inflation.data as e6
from .JMulTi_results.parse_jmulti_output import load_results_jmulti
from .JMulTi_results.parse_jmulti_output import dt_s_tup_to_string
from statsmodels.tsa.vecm.vecm import VECM
from statsmodels.tsa.vector_ar.var_model import VARProcess

atol = 0.001  # absolute tolerance
rtol = 0.01  # relative tolerance
datasets = []
data = {}
results_ref = {}
results_sm = {}
coint_rank = 1

debug_mode = False
dont_test_se_t_p = False
deterministic_terms_list = ["nc", "co", "colo", "ci", "cili"]
seasonal_list = [0, 4]
dt_s_list = [(det, s) for det in deterministic_terms_list
             for s in seasonal_list]
all_tests = ["Gamma", "alpha", "beta", "C", "det_coint", "Sigma_u",
             "VAR repr. A", "VAR to VEC representation", "log_like"]
to_test = all_tests  # ["beta"]


def load_data(dataset, data_dict):
    dtset = dataset.load()
    variables = dataset.variable_names
    loaded = dtset.data[variables].view(float, type=np.ndarray)
    data_dict[dataset] = loaded.reshape((-1, len(variables)))


def load_results_statsmodels(dataset):
    results_per_deterministic_terms = dict.fromkeys(dt_s_list)
    for dt_s_tup in dt_s_list:
        model = VECM(data[dataset], diff_lags=3,
                     deterministic=dt_s_tup[0], seasons=dt_s_tup[1])
        # print("\n\n\nDETERMINISTIC TERMS: " + deterministic_terms)
        results_per_deterministic_terms[dt_s_tup] = model.fit(
                method="ml", coint_rank=coint_rank)
    return results_per_deterministic_terms


def build_err_msg(ds, dt_s, parameter_str):
    dt = dt_s_tup_to_string(dt_s)
    seasons = dt_s[1]
    err_msg = "Error in " + parameter_str + " for:\n"
    err_msg += "- Dataset: " + ds.__str__() + "\n"
    err_msg += "- Deterministic terms: "
    err_msg += (dt_s[0] if dt != "nc" else "no det. terms")
    if seasons > 0:
        err_msg += ", seasons: " + str(seasons)
    return err_msg


def test_ml_gamma():
    if debug_mode:
        if "Gamma" not in to_test:
{'fraction_non_alphanumeric': 0.11585365853658537, 'fraction_numerical': 0.008581752484191508, 'mean_word_length': 3.8885209713024285, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 5, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '1675629', 'n_tokens_mistral': 1636, 'n_tokens_neox': 1570, 'n_words': 357}