In [1]:
import pandas as pd
import numpy as np
import math
import random
%matplotlib inline
In [2]:
# 乱数シードを固定する
random.seed(0)
In [3]:
# 乱数の係数
random_factor = 0.05
# サイクルあたりのステップ数
steps_per_cycle = 50
# 生成するサイクル数
number_of_cycles = 100
In [4]:
df = pd.DataFrame(np.arange(steps_per_cycle * number_of_cycles + 1), columns=["t"])
df.head()
Out[4]:
In [5]:
random.uniform(-1.0, +1.0) * random_factor
Out[5]:
In [6]:
df["sin_t"] = df.t.apply(lambda x: math.sin(x * (2 * math.pi / steps_per_cycle) + random.uniform(-1.0, +1.0) * random_factor))
In [7]:
df[["sin_t"]].plot()
Out[7]:
In [8]:
df[["sin_t"]].head(steps_per_cycle * 2).plot()
Out[8]:
In [9]:
df["sin_t+1"] = df["sin_t"].shift(-1)
In [10]:
df.tail()
Out[10]:
In [11]:
df.dropna(inplace=True)
df.tail()
Out[11]:
In [12]:
df[["sin_t", "sin_t+1"]].head(steps_per_cycle).plot()
Out[12]:
In [13]:
matrix = df[["sin_t", "sin_t+1"]].as_matrix()
matrix
Out[13]:
In [14]:
np.save("noised.npy", matrix)
In [ ]: