-
Notifications
You must be signed in to change notification settings - Fork 117
/
pca_tests.py
63 lines (52 loc) · 1.84 KB
/
pca_tests.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
# -*- coding: utf-8 -*-
#
# File : examples/timeserie_prediction/switch_attractor_esn
# Description : NARMA 30 prediction with ESN.
# Date : 26th of January, 2018
#
# This file is part of EchoTorch. EchoTorch is free software: you can
# redistribute it and/or modify it under the terms of the GNU General Public
# License as published by the Free Software Foundation, version 2.
#
# This program is distributed in the hope that it will be useful, but WITHOUT
# ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
# FOR A PARTICULAR PURPOSE. See the GNU General Public License for more
# details.
#
# You should have received a copy of the GNU General Public License along with
# 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
import torch
import echotorch.nn as etnn
from torch.autograd import Variable
import mdp
# Settings
input_dim = 10
output_dim = 3
tlen = 500
# Generate
training_samples = torch.randn(1, tlen, input_dim)
test_samples = torch.randn(1, tlen, input_dim)
# Generate
training_samples_np = training_samples[0].numpy()
test_samples_np = test_samples[0].numpy()
# Show
print(("Training samples : {}".format(training_samples_np)))
print(("Test samples : {}".format(test_samples_np)))
# PCA node
mdp_pca_node = mdp.Flow([mdp.nodes.PCANode(input_dim=input_dim, output_dim=output_dim)])
mdp_pca_node.train(training_samples_np)
pca_reduced = mdp_pca_node(test_samples_np)
# Show
print(("PCA reduced : {}".format(pca_reduced)))
# EchoTorch PCA node
et_pca_node = etnn.PCACell(input_dim=input_dim, output_dim=output_dim)
et_pca_node(Variable(training_samples))
et_pca_node.finalize()
et_reduced = et_pca_node(Variable(test_samples))
# Show
print("Reduced with EchoTorch/PCA :")
print(et_reduced)