Пример #1
0
    def __init__(self):
        self.results = results[results[0] == 4]
        self.bds_stats = np.array(self.results[2][1:])
        self.pvalues = np.array(self.results[3][1:])

        self.data = data[3][data[3].notnull()]
        self.res = bds(self.data, 5)
Пример #2
0
    def __init__(self):
        self.results = results[results[0] == 4]
        self.bds_stats = np.array(self.results[2][1:])
        self.pvalues = np.array(self.results[3][1:])

        self.data = data[3][data[3].notnull()]
        self.res = bds(self.data, 5)
Пример #3
0
    def setup_class(cls):
        cls.results = results[results[0] == 3]
        cls.bds_stats = np.array(cls.results[2].iloc[1:])
        cls.pvalues = np.array(cls.results[3].iloc[1:])

        cls.data = data[2][data[2].notnull()]
        cls.res = bds(cls.data, 5)
Пример #4
0
    def setup_class(cls):
        cls.results = results[results[0] == 3]
        cls.bds_stats = np.array(cls.results[2][1:])
        cls.pvalues = np.array(cls.results[3][1:])

        cls.data = data[2][data[2].notnull()]
        cls.res = bds(cls.data, 5)
def independence(
    other_args: List[str],
    residuals: List[float],
):
    """Tests independent and identically distributed (i.i.d.) time series (BDS)

    Parameters
    ----------
    other_args : str
        Command line arguments to be processed with argparse
    residuals : List[float]
        Residuals data
    """
    parser = argparse.ArgumentParser(
        add_help=False,
        prog="independence",
        description="""
            Tests independent and identically distributed (i.i.d.) time series (BDS)
        """,
    )
    try:
        ns_parser = parse_known_args_and_warn(parser, other_args)
        if not ns_parser:
            return

        result = bds(residuals, max_dim=6)
        print("BDS Test")
        print("Dim 2: z-static {:.4f} Prob {:.4f}".format(
            result[0][0], result[1][0]))
        print("Dim 3: z-static {:.4f} Prob {:.4f}".format(
            result[0][1], result[1][1]))
        print("Dim 4: z-static {:.4f} Prob {:.4f}".format(
            result[0][2], result[1][2]))
        print("Dim 5: z-static {:.4f} Prob {:.4f}".format(
            result[0][3], result[1][3]))
        print("Dim 6: z-static {:.4f} Prob {:.4f}".format(
            result[0][4], result[1][4]))

        print("")

    except Exception as e:
        print(e, "\n")
        return
Пример #6
0
from statsmodels.tsa.stattools import bds
from rcnn.dataloader import CNNDataLoader
import warnings

warnings.filterwarnings("ignore")

if __name__ == '__main__':
    regression_datasets = [
        "BenzeneConcentration", "HouseholdPowerConsumption1",
        "NewsHeadlineSentiment", "BIDMC32HR", "LiveFuelMoistureContent",
        "IEEEPPG", "PPGDalia"
    ]

    for name in regression_datasets:
        print(name)
        dataloader = CNNDataLoader(
            path_to_file="/path/to/Monash_UEA_UCR_Regression_Archive/"
            f"{name}/{name}_TEST.ts",
            img_size=4)
        residuals = dataloader.get_residuals()
        for i in range(residuals.shape[0]):
            _, pval = bds(residuals[i])
            print(pval)
    #obtain final residual series by refitting the model with best parameter combination:
    am = arch_model(u_hat,
                    mean='Zero',
                    vol='GARCH',
                    p=garch_order[0],
                    q=garch_order[1],
                    rescale=False).fit(disp='off')

    u_hat_std = u_hat / np.sqrt(am.conditional_volatility)

    #BDS Test, epsilon is chosen according to

    epsilon = 0.5 * np.std(u_hat_std)
    max_dim = 5
    bdsstat = bds(np.log(u_hat_std**2), max_dim=max_dim, epsilon=epsilon)[1]

    df = pd.DataFrame()
    df['m'] = [str(i) for i in range(2, max_dim + 1)]
    df['p-value'] = bdsstat

    caption = 'BDS Test Results'

    df_str = df.T.to_latex(caption=caption, header=False)

    #split latex string and insert reference
    str_tmp = re.split(r'(aption{' + caption + r'})', df_str)

    str_out = str_tmp[0] + str_tmp[
        1] + '\n' + r'\label{tab:' + 'bds' + r'}' + str_tmp[2]
Пример #8
0
 def bds(self):
     result = stattools.bds(self.timeseries)
     BdsResult = namedtuple('BdsResult', 'statistic pvalue')
     return BdsResult(result[0], result[1])
Пример #9
0
                file.write("mean: " + str(numpy.mean(array)) + "\n")
                file.write("variance: " + str(numpy.var(array)) + "\n")
                file.write("standard deviation: " +
                           str(statistics.stdev(array)) + "\n")

                kpss_stat, p_value, lags, crit = stat.kpss(
                    array
                )  # https://www.statsmodels.org/dev/generated/statsmodels.tsa.stattools.kpss.html
                file.write("KPSS: " + str(kpss_stat) + "\n")

                start = 0
                end = 200
                max_bds = 0
                while (end <= len(array)
                       ):  # sliding window with fixed size (200 elements)
                    bds_stat, pvalue = stat.bds(
                        array[start:end]
                    )  # https://www.statsmodels.org/dev/generated/statsmodels.tsa.stattools.bds.html
                    if (bds_stat > max_bds):
                        max_bds = bds_stat
                    start += 1
                    end += 1
                file.write("BDS: " + str(max_bds) + "\n")

                H, c, data = compute_Hc(
                    array, kind='change',
                    simplified=True)  # https://pypi.org/project/hurst/
                file.write("Hurst Exponent: " + str(H) + "\n")

file.close()
Пример #10
0
def conv_to_float(n):
    if type(n) == int or type(n) == float:
        return float(n)
    l = n.split('.')
    if (len(l) == 1):
        return float(l[0])
    m = l[1] + "." + l[-2]
    return float(m)


df = pd.read_csv("merge_oil.csv")

#BDS Test over columns
us_price = [conv_to_float(i) for i in list(df["US_Price"])]

print(stattools.bds(us_price, max_dim=2, epsilon=None, distance=1.5))

dollar_eq = [conv_to_float(i) for i in list(df["Dollar_eq"])]
print("Dollar_eq")
print(stattools.bds(dollar_eq, max_dim=2, epsilon=None, distance=1.5))

price = [float(i) for i in df["Price"]]
print("Price")
print(stattools.bds(price, max_dim=2, epsilon=None, distance=1.5))

Open = [float(i) for i in df["Open"]]
print("Open")
print(stattools.bds(Open, max_dim=2, epsilon=None, distance=1.5))

high = [float(i) for i in df["High"]]
print("High")