<jupyter_start><jupyter_text>A minimal example with BatchLinearDyBM- Author: <NAME>, <NAME>- Date: Jul. 18, 2017- (C) Copyright IBM Corp. 2016Here we provide an example of how to train a DyBM in a batch manner and how to give prediction with that DyBM. We train the simplest batch version of DyBM, BatchLinearDyBM, with a one-dimensional time-series of noisy sine wave. After we train the DyBM using the time-series in batch manner, we let the DyBM predict one-step-ahead of a noise-less sine wave. In the end, we plot the noise-less sine wave and the corresponding predictions.<jupyter_code>%matplotlib inline
import matplotlib.pyplot as plt
import numpy as np
from pydybm.time_series.batch_dybm import BatchLinearDyBM
from pydybm.base.generator import NoisySin

# Prepare a generator of time-series
# In this example, we generate a noisy sine wave
length = 300 # length of the time-series
period = 60  # period of the sine wave
std = 0.1   # standard deviation of the noise
dim = 1      # dimension of the time-series
data = NoisySin(length,period,std,dim)
npData = np.array(data.to_list())     #  get sequence of data because batch cannot learn from generator 

# Create a DyBM
# In this example, we use a Linear DyBM
dybm = BatchLinearDyBM(dim, delay=2)

# Learn the time-series
dybm.fit(npData)

# Predict against noise-less sine wave
dybm.init_state()
test_gen = NoisySin(period*2, period, std=0, dim=dim)
result = dybm.predict(test_gen)

# Plot the time-series and prediction
test_data = test_gen.to_list()
plt.plot([x[0] for x in test_data],label="target")
plt.plot([x[0] for x in result],label="prediction")
plt.legend()<jupyter_output><empty_output>
{'fraction_non_alphanumeric': 0.08257986738999397, 'fraction_numerical': 0.013863773357444244, 'mean_word_length': 4.743944636678201, 'pattern_counts': {'":': 0, '<': 7, '<?xml version=': 0, '>': 7, '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}}
{'chain_length': '1', 'dir': 'jupyter-structured-clean-dedup', 'id': '254270', 'license': 'Apache-2.0', 'n_tokens_mistral': 557, 'n_tokens_neox': 516, 'n_words': 212, 'path': 'examples/time_series/BatchLinearDyBMDemo.ipynb', 'repo_name': 'ibm-research-tokyo/dybm', 'size': '1675'}