Open
Description
Hi @hrayrhar !
Amazing algorithm, I am trying to use it on a basic two dimesnaional dataset.
Please see my attempt below -
from __future__ import print_function
from __future__ import absolute_import
from tcorex.experiments.data import load_modular_sudden_change
from tcorex.experiments import baselines
from tcorex import base
from tcorex import TCorex
from tcorex import covariance as cov_utils
import numpy as np
import matplotlib
matplotlib.use('agg')
from matplotlib import pyplot as plt
import yfinance as yf
data = yf.download("SPY GOOGL", start="2014-01-01", end="2019-04-30")
data
return_target=data['Close'].pct_change().dropna()
nv = 2 # number of observed variables
m = 1 # number of hidden variables
nt = 10 # number of time periods
train_cnt = 16 # number of training samples for each time period
val_cnt = 4 # number of validation samples for each time period
# Generate some data with a sudden change in the middle.
#data, ground_truth_sigma = load_modular_sudden_change(nv=nv, m=m, nt=nt, ns=(train_cnt + val_cnt))
data =return_target.values
# Split it into train and validation.
#train_data = [X[:train_cnt] for X in data]
train_data=data
#val_data = [X[train_cnt:] for X in data]
# NOTE: the load_modular_sudden_change function above creates data where the time axis
# is already divided into time periods. If your data is not divided into time periods
# you can use the following procedure to do that:
# bucketed_data, index_to_bucket = make_buckets(data, window=train_cnt + val_cnt, stride='full')
# where the make_buckets function can be found at tcorex.experiments.data
# The core method we have is the tcorex.TCorex class.
tc = TCorex(nt=nt,
nv=nv,
n_hidden=m,
max_iter=500,
device='cpu', # for GPU set 'cuda',
l1=0.3, # coefficient of temporal regularization term
gamma=0.3, # parameter that controls sample weights
verbose=1, # 0, 1, 2
)
# # Fit the parameters of T-CorEx.
tc.fit(train_data)
Metadata
Metadata
Assignees
Labels
No labels