# Path: echotorch/datasets/SwitchAttractorDataset.py
# class SwitchAttractorDataset(Dataset):
#     """
#     Generate a dataset where the reservoir must switch
#     between two attractors.
#     """
# 
#     # Constructor
#     def __init__(self, sample_len, n_samples, seed=None):
#         """
#         Constructor
#         :param sample_len: Length of the time-series in time steps.
#         :param n_samples: Number of samples to generate.
#         :param system_order: th order NARMA
#         :param seed: Seed of random number generator.
#         """
#         # Properties
#         self.sample_len = sample_len
#         self.n_samples = n_samples
# 
#         # Init seed if needed
#         if seed is not None:
#             torch.manual_seed(seed)
#         # end if
# 
#         # Generate data set
#         self.inputs, 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.inputs[idx], self.outputs[idx]
#     # end __getitem__
# 
#     ##############################################
#     # PRIVATE
#     ##############################################
# 
#     # Generate
#     def _generate(self):
#         """
#         Generate dataset
#         :return:
#         """
#         inputs = list()
#         outputs = list()
# 
#         # Generate each sample
#         for i in range(self.n_samples):
#             # Start end stop
#             start = np.random.randint(0, self.sample_len)
#             stop = np.random.randint(start, start + self.sample_len / 2)
# 
#             # Limits
#             if stop >= self.sample_len:
#                 stop = self.sample_len - 1
#             # end if
# 
#             # Sample tensor
#             inp = torch.zeros(self.sample_len, 1)
#             out = torch.zeros(self.sample_len)
# 
#             # Set inputs
#             inp[start, 0] = 1.0
#             inp[stop] = 1.0
# 
#             # Set outputs
#             out[start:stop] = 1.0
# 
#             # Add
#             inputs.append(inp)
#             outputs.append(out)
#         # end for
# 
#         return inputs, outputs
#     # end _generate


import torch
import echotorch.nn as etnn
import echotorch.utils
import numpy as np
import mdp
import matplotlib.pyplot as plt
from echotorch.datasets.SwitchAttractorDataset import SwitchAttractorDataset
from torch.autograd import Variable
from torch.utils.data.dataloader import DataLoader
# this program; if not, write to the Free Software Foundation, Inc., 51
# Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
#
# Copyright Nils Schaetti <nils.schaetti@unine.ch>


# Imports

# Dataset params
train_sample_length = 1000
test_sample_length = 1000
n_train_samples = 40
n_test_samples = 10
batch_size = 1
spectral_radius = 0.9
leaky_rate = 1.0
input_dim = 1
n_hidden = 100

# Use CUDA?
use_cuda = False
use_cuda = torch.cuda.is_available() if use_cuda else False

# Manual seed
mdp.numx.random.seed(1)
np.random.seed(2)
torch.manual_seed(1)

# Switch attractor dataset
switch_train_dataset = SwitchAttractorDataset(train_sample_length, n_train_samples, seed=1)

# Path: echotorch/datasets/SwitchAttractorDataset.py
# class SwitchAttractorDataset(Dataset):
#     """
#     Generate a dataset where the reservoir must switch
#     between two attractors.
#     """
# 
#     # Constructor
#     def __init__(self, sample_len, n_samples, seed=None):
#         """
#         Constructor
#         :param sample_len: Length of the time-series in time steps.
#         :param n_samples: Number of samples to generate.
#         :param system_order: th order NARMA
#         :param seed: Seed of random number generator.
#         """
#         # Properties
#         self.sample_len = sample_len
#         self.n_samples = n_samples
# 
#         # Init seed if needed
#         if seed is not None:
#             torch.manual_seed(seed)
#         # end if
# 
#         # Generate data set
#         self.inputs, 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.inputs[idx], self.outputs[idx]
#     # end __getitem__
# 
#     ##############################################
#     # PRIVATE
#     ##############################################
# 
#     # Generate
#     def _generate(self):
#         """
#         Generate dataset
#         :return:
#         """
#         inputs = list()
#         outputs = list()
# 
#         # Generate each sample
#         for i in range(self.n_samples):
#             # Start end stop
#             start = np.random.randint(0, self.sample_len)
#             stop = np.random.randint(start, start + self.sample_len / 2)
# 
#             # Limits
#             if stop >= self.sample_len:
#                 stop = self.sample_len - 1
#             # end if
# 
#             # Sample tensor
#             inp = torch.zeros(self.sample_len, 1)
#             out = torch.zeros(self.sample_len)
# 
#             # Set inputs
#             inp[start, 0] = 1.0
#             inp[stop] = 1.0
# 
#             # Set outputs
#             out[start:stop] = 1.0
# 
#             # Add
#             inputs.append(inp)
#             outputs.append(out)
#         # end for
# 
#         return inputs, outputs
#     # end _generate


# Path: examples/switch_attractor/switch_attractor_esn.py
import torch
import echotorch.nn as etnn
import echotorch.utils
import numpy as np
import mdp
import matplotlib.pyplot as plt
from echotorch.datasets.SwitchAttractorDataset import SwitchAttractorDataset
from torch.autograd import Variable
from torch.utils.data.dataloader import DataLoader

# this program; if not, write to the Free Software Foundation, Inc., 51
# Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
#
# Copyright Nils Schaetti <nils.schaetti@unine.ch>


# Imports

# Dataset params
train_sample_length = 1000
test_sample_length = 1000
n_train_samples = 40
n_test_samples = 10
batch_size = 1
spectral_radius = 0.9
leaky_rate = 1.0
input_dim = 1
n_hidden = 100

# Use CUDA?
use_cuda = False
use_cuda = torch.cuda.is_available() if use_cuda else False

# Manual seed
mdp.numx.random.seed(1)
np.random.seed(2)
torch.manual_seed(1)

# Switch attractor dataset
switch_train_dataset = SwitchAttractorDataset(train_sample_length, n_train_samples, seed=1)

switch_test_dataset = SwitchAttractorDataset(test_sample_length, n_test_samples, seed=10)