Skip to content

Commit

Permalink
Sinusoidal timeseries dataset
Browse files Browse the repository at this point in the history
  • Loading branch information
nschaetti committed Jan 25, 2019
1 parent 750e20e commit e7d40db
Showing 1 changed file with 124 additions and 0 deletions.
124 changes: 124 additions & 0 deletions echotorch/datasets/SinusoidalTimeseries.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,124 @@
# -*- coding: utf-8 -*-
#

# Imports
import torch
from torch.utils.data.dataset import Dataset
import math
from random import shuffle
import numpy as np


# Sinusoidal Timeseries
class SinusoidalTimeseries(Dataset):
"""
The Rössler attractor is the attractor for the Rössler system, a system of three non-linear ordinary differential
equations originally studied by Otto Rössler. These differential equations define a continuous-time dynamical
system that exhibits chaotic dynamics associated with the fractal properties of the attractor.
"""

# Constructor
def __init__(self, sample_len, n_samples, w, a=1, seed=None):
"""
Constructor
:param sample_len: Length of the time-series in time steps.
:param n_samples: Number of samples to generate.
:param a:
:param b:
:param c:
"""
# Properties
self.sample_len = sample_len
self.n_samples = n_samples
self.w = w
self.a = a

# Seed
if seed is not None:
np.random.seed(seed)
# end if

# Generate data set
self.outputs = self._generate()
# end __init__

#############################################
# OVERRIDE
#############################################

# Length
def __len__(self):
"""
Length
:return:
"""
return self.n_samples
# end __len__

# Get item
def __getitem__(self, idx):
"""
Get item
:param idx:
:return:
"""
return self.outputs[idx]
# end __getitem__

##############################################
# PUBLIC
##############################################

# Regenerate
def regenerate(self):
"""
Regenerate
:return:
"""
# Generate data set
self.outputs = self._generate()
# end regenerate

##############################################
# PRIVATE
##############################################

# Random initial points
def random_initial_points(self):
"""
Random initial points
:return:
"""
# Set
return np.random.random() * (math.pi * 2.0)
# end random_initial_points

# Generate
def _generate(self):
"""
Generate dataset
:return:
"""
# List of samples
samples = list()

# For each sample
for i in range(self.n_samples):
# Tensor
sample = torch.zeros(self.sample_len, 1)

# Init
init_g = self.random_initial_points()

for t in range(0, self.sample_len):
sample[t, 0] = self.a * math.sin(self.w * t + init_g)
# end for

# Append
samples.append(sample)
# end for

return samples
# end _generate

# end SinusoidalTimeseries

0 comments on commit e7d40db

Please sign in to comment.