Ce serveur Gitlab sera éteint le 30 juin 2020, pensez à migrer vos projets vers les serveurs gitlab-research.centralesupelec.fr et gitlab-student.centralesupelec.fr !

Commit 11168278 authored by Ngocson's avatar Ngocson

soutenance

parent 081f11bc
......@@ -11,10 +11,37 @@ from Reservoir import *
import numpy as np
import matplotlib.pyplot as plt
from random import *
global V
n_train, n_test, d_train, d_test = 2000,1000,200,202
V = []
with open('ActivationFunction.csv') as csv_file:
csv_reader = csv.reader(csv_file, delimiter=';')
for row in csv_reader:
L = []
for value in row:
L.append(float(value))
V.append(L)
def approx_lin(x,vr=0.3,a=1.4,s=1.0):
global V
fi = min(max(100*(vr+1)/11,0.0),99.0)
if not fi.is_integer():
i = int(fi)
f = V[i]
else:
f = V[int(fi)]
fx = min(max(1000.0*(x+5)*s,0.0),24999.0)
if not fx.is_integer():
x = int(fx)
return a*((x+1-fx)*(f[x]-f[x+1])+f[x+1])
else:
return a*f[int(fx)]
n_train, n_test, d_train, d_test = 4000,1000,400,402
Nessais = 10
Ntrain = 50
Ntrain = 5
sp = 0.8
......@@ -23,14 +50,14 @@ TrainError = []
TestError = []
for i in range(Ntrain):
R = Reservoir(N = 100,
p = 0.05,
R = Reservoir(N = 200,
p = 0.1,
sp = sp,
outputScaling = sp*0.5,
outputScaling = 1,
v = 0.0001,
Activation = np.tanh,
Activation = np.vectorize(approx_lin),
Feedback = False,
inputScaling = 0.1
inputScaling = 5
)
for j in range(Nessais):
Narma10Generator.reset(np.zeros(10),np.zeros(10))
......@@ -44,7 +71,7 @@ for i in range(Ntrain):
epsi = R.fit(Y = Y_train[d_train:],
U = U_train[d_train:],
Forced = True,
Show = (i*Ntrain+j)%40==0
Show = (j)%5==0
)
......
......@@ -29,7 +29,7 @@ santa_fe = santa_fe/santa_fe.max()
X = santa_fe[:-1]
Y = santa_fe[1:]
def approx_lin(x,vr=0.8,a=1.0,s=1.0):
def approx_lin(x,vr=0.18,a=1.0,s=1.0):
global V
fi = min(max(100*(vr+1)/11,0.0),99.0)
if not fi.is_integer():
......@@ -50,59 +50,60 @@ nmos_training_error = []
nmos_testing_error = []
tanh_training_error = []
tanh_testing_error = []
Ns = range(50,800,5)
for N in Ns:
R_nmos = Reservoir.Reservoir(N = N,
p = 0.05,
sp = 0.9,
outputScaling = 1,
v = 0.0001,
Activation = np.vectorize(approx_lin),
Feedback = False,
inputScaling = 10,
damping = False
)
R_tanh = Reservoir.Reservoir(N = N,
p = 0.05,
sp = 0.9,
outputScaling = 1,
v = 0.0001,
Activation = np.tanh,
Feedback = False,
inputScaling = 10,
damping = False
)
n_init = 800
n_train = 6000
R_nmos.steps(X[:n_init])
R_tanh.steps(X[:n_init])
NRMSE_nmos = R_nmos.fit(Y[n_init:n_train],X[n_init:n_train])
NRMSE_tanh = R_tanh.fit(Y[n_init:n_train],X[n_init:n_train])
print(N,": Nmos NRMSE:",NRMSE_nmos," / ",20*np.log(NRMSE_nmos),"db ; ","Tanh NRMSE:",NRMSE_tanh," / ",20*np.log(NRMSE_tanh),"db ; ")
R_nmos.reset()
R_tanh.reset()
Ytanh_ = R_tanh.steps(X)
Ynmos_ = R_nmos.steps(X)
nmos_training_error.append(NRMSE_nmos)
nmos_testing_error.append(np.sqrt(np.linalg.norm(Ynmos_[n_init:]-Y[n_init:])/Ynmos_[n_init:].std()))
tanh_training_error.append(NRMSE_tanh)
tanh_testing_error.append(np.sqrt(np.linalg.norm(Ytanh_[n_init:]-Y[n_init:])/Ytanh_[n_init:].std()))
'''
plt.figure()
plt.plot(Y[-1000:],'r-',label="Teacher")
plt.plot(Ytanh_[-1000:],'b-',label="Tanh reservoir output")
plt.plot(Ynmos_[-1000:],'g-',label="Nmos reservoir output")
plt.legend()
plt.show()
'''
Vr = np.linspace(0.1,2.5,30)
Ns = range(1000,6000,100)
N = 450
n_train = 4000
n_init = 2*N
R_tanh = Reservoir.Reservoir(N = N,
p = 0.05,
sp = 0.9,
outputScaling = 1,
v = 0.0001,
Activation = np.tanh,
Feedback = False,
inputScaling = 10,
damping = False
)
R_tanh.steps(X[:n_init])
NRMSE_tanh = R_tanh.fit(Y[n_init:n_train],X[n_init:n_train])
R_tanh.reset()
Ytanh_ = R_tanh.steps(X)
tanh_training_error.append(NRMSE_tanh)
tanh_testing_error.append(np.sqrt(np.linalg.norm(Ytanh_[n_init:]-Y[n_init:])/Ytanh_[n_init:].std()))
vr =0.3
R_nmos = Reservoir.Reservoir(N = N,
p = 0.05,
sp = 0.9,
outputScaling = 1,
v = 0.0001,
Activation = np.vectorize(lambda x: approx_lin(x,vr)),
Feedback = False,
inputScaling = 10,
damping = False,
Verbose = False
)
R_nmos.steps(X[:n_init])
NRMSE_nmos = R_nmos.fit(Y[n_init:n_train],X[n_init:n_train])
R_nmos.reset()
Ynmos_ = R_nmos.steps(X)
print(" ",n_train,": Nmos NRMSE:",NRMSE_nmos," / ",20*np.log(NRMSE_nmos),"db ; ","Tanh NRMSE:",NRMSE_tanh," / ",20*np.log(NRMSE_tanh),"db ; ")
nmos_training_error.append(NRMSE_nmos)
nmos_testing_error.append(np.sqrt(np.linalg.norm(Ynmos_[n_init:]-Y[n_init:])/Ynmos_[n_init:].std()))
plt.figure()
plt.plot(Y[-200:],'r-.',label="Teacher")
plt.plot(Ytanh_[-200:],'b-',label="Tanh reservoir output")
plt.plot(Ynmos_[-200:],'g-',label="Nmos reservoir output")
plt.legend()
plt.show()
'''
plt.figure()
plt.title('Number of points used for fitting')
plt.plot(Ns,nmos_training_error,'r-',label='nmos training error')
......@@ -110,4 +111,9 @@ plt.plot(Ns,nmos_testing_error,'b-',label='nmos testing error')
plt.plot(Ns,tanh_training_error,'y-',label='tanh training error')
plt.plot(Ns,tanh_testing_error,'g-',label='tanh testing error')
plt.legend()
plt.show()
\ No newline at end of file
plt.show()
plt.figure()
plt.plot(n_train,[Vr[np.argmax(i)] for i in nmos_testing_error])
plt.show()
'''
\ No newline at end of file
# -*- coding: utf-8 -*-
"""
Created on Tue Apr 23 20:21:40 2019
@author: Ngocson
"""
import fpaa_reservoir
import csv
import numpy as np
import matplotlib.pyplot as plt
with open('santa_fe.txt') as sftr_file:
sftr_reader = csv.reader(sftr_file, delimiter=';')
santa_fe = np.array(next(sftr_reader)).astype(np.float)
santa_fe = santa_fe/santa_fe.max()
N = 450
verbose = True
n_init = 2*N
X = santa_fe[:-1]
Y = santa_fe[1:]
s = fpaa_reservoir.reservoirNMOS(N=N,
p = 0.011,
vr = 0.8,
tc = 10e-11,
te = 10e-9,
a_max = 1,
a_min = 1,
b_max = 0.0,
input_scalling=10.0,
s_min = 0.0,
s_max = 1,
verbose=verbose)
###################### LET THE FUN BEGIN ##################
training_error = []
testing_error = []
Ns = []
n_train = 2000
Ns.append(n_train)
s.steps(X[:n_init])
NRMSEtr = s.fit(Y[n_init:n_init+n_train],X[n_init:n_init+n_train],
0.0001,
verbose=verbose)
s.reset(True)
Y_ = s.steps(X)
NRMSEts = (np.sqrt(np.linalg.norm(Y_[n_init:]-Y[n_init:])/Y_[n_init:].std()))
training_error.append(NRMSEtr)
testing_error.append(NRMSEts)
print("Test:",testing_error," | Train", training_error)
'''
plt.figure()
plt.title('After training')
plt.plot(Y[n_init:],'r-',label='teacher')
plt.plot(Y_[n_init:],'b-',label='outp')
plt.legend()
plt.show()
plt.figure()
s.reset(True)
plt.figure()
plt.title('Testing')
plt.plot(Y[-1000:],'r.-',label='teacher')
plt.plot(Y_[-1000:],'b.-',label='outp')
plt.legend()
plt.show()
s.responses_NODE(X[:500],range(N))
plt.figure()
plt.title('Number of points used for fitting')
plt.plot(Ns,training_error,'r-',label='training error')
plt.plot(Ns,testing_error,'b-',label='testing error')
plt.legend()
plt.show()
'''
\ No newline at end of file
......@@ -12,12 +12,10 @@ with open('santa_fe.txt') as sftr_file:
sftr_reader = csv.reader(sftr_file, delimiter=';')
santa_fe = np.array(next(sftr_reader)).astype(np.float)
santa_fe = santa_fe/santa_fe.max()
N = 40
N = 300
verbose = False
n_init = 2*N
n_tot = 3000
X = santa_fe[:-1]
Y = santa_fe[1:]
......@@ -37,7 +35,7 @@ s = reservoirNMOS(N=N,
training_error = []
testing_error = []
Ns = []
for n in np.linspace(10*N,6000,50):
for n in np.linspace(5*N,3000,100):
n_tot = int(n)
print(n_tot)
Ns.append(n_tot)
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment