In [1]:
# 0. Preliminares
%matplotlib inline
import sys
sys.path.append('../') # needed to run the examples from within the package folder
import numpy as np
import matplotlib.pyplot as plt
import mpld3
mpld3.enable_notebook()
from pygrfnn.network import Model, make_connections
from pygrfnn.oscillator import Zparam
from pygrfnn.grfnn import GrFNN
from pygrfnn.vis import plot_connections
from pygrfnn.vis import tf_detail
In [2]:
# GrFNN parameters
params = Zparam( 1, -1, -1000, 0, 0, 1) # Limit Cycle
# Parameter sets for Hebbian plasiticity
w = .05;
# lambda = -.1; mu1 = 0; mu2 = 0; ceps = 4, kappa = 1; % Linear learning rule
# lambda = 0; mu1 = -1; mu2 = -50; ceps = 4, kappa = 1; % Critical learning rule
# lambda = 0; mu1 = -1; mu2 = -50; ceps = 16, kappa = 1; % Critical, stronger nonlinearity
lambda = .001; mu1 = -1; mu2 = -50; ceps = 16, kappa = 1; % Supercritical learning rule
# no stimulus
# 2. Create a GrFNN layer
layer = GrFNN(params,
fc=1,
octaves_per_side=1,
oscs_per_octave=99.5)
# 3. Create connection
n = connectAdd(n, n, [], 'weight', w, 'type', 'all2freq', ...
'learn', lambda, mu1, mu2, ceps, kappa, ...
'display', 10, 'save', 500);
# 4. Create the model and add the layer
model = Model()
model.add_layer(layer, None) # on external input
%% Run the network
tic
model = odeRK4fs(model);
toc
In [29]:
f1 = 1*np.logspace(-1, 1, 10, base=2)
f2 = 1*np.logspace(-2, 2, 20, base=2)
# M = np.ones((10,5))
# print(M.dot(f2))
# print(f1.dot(M))
F1 = np.tile(f1, (len(f2), 1)).T
F2 = np.tile(f2, (len(f1), 1))
F = (2*F1*F2)/(F1+F2)
# print(F1)
# print(F2)
# print(F)
# print(F1.shape)
# print(F2.shape)
# print(F.shape)
fig, (ax1, ax2, ax3) = plt.subplots(1, 3, sharex=True, sharey=True)
fig.set_size_inches(12, 3)
ax1.pcolormesh(f2, f1, F1)
ax2.pcolormesh(f2, f1, F2)
fa = ax3.pcolormesh(f2, f1, F)
ax1.set_title('F1')
ax2.set_title('F2')
ax3.set_title('F')
ax1.set_ylabel('f1')
ax2.set_xlabel('f2')
# cbar_ax = fig.add_axes([0.95, 0.15, 0.02, 0.7])
# fig.colorbar(fa, cax=cbar_ax)
fig.subplots_adjust(hspace=0)
In [ ]: