Skip to content

Commit

Permalink
Final part full-differetial representation of the LEGION network; Exa…
Browse files Browse the repository at this point in the history
…mples have been added
  • Loading branch information
U-DeBug010-PC\DeBug010 authored and U-DeBug010-PC\DeBug010 committed May 2, 2014
1 parent 39d3dfd commit fa8c7e3
Show file tree
Hide file tree
Showing 2 changed files with 77 additions and 25 deletions.
67 changes: 42 additions & 25 deletions nnet/legion/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@

from scipy.integrate import odeint;


class legion_parameters:
eps = 0.02;
alpha = 0.005;
Expand Down Expand Up @@ -64,31 +63,46 @@ def __init__(self, num_osc, stimulus = None, parameters = None, type_conn = conn
self._buffer_coupling_term = [0] * self._num_osc;

# set stimulus
self.__create_stimulus(stimulus);

# calculate dynamic weights
self.__create_dynamic_connections();

# generate first noises
self._noise = [random.random() * -self._params.ro for i in range(self._num_osc)];

def __create_stimulus(self, stimulus):
if (stimulus is None):
self._stimulus = [0] * self._num_osc;
else:
if (len(stimulus) != num_osc):
if (len(stimulus) != self._num_osc):
raise NameError("Number of stimulus should be equal number of oscillators in the network");
else:
self._stimulus = stimulus;

def __create_dynamic_connections(self):
if (self._stimulus is None):
raise NameError("Stimulus should initialed before creation of the dynamic connections in the network");

self._dynamic_coupling = [ [0] * self._num_osc for i in range(self._num_osc)];

# calculate dynamic weights
self._dynamic_coupling = [0] * self._num_osc;
for i in range(self._num_osc):
neighbors = self.get_neighbors(i);

if (len(neighbors) > 0):
self._dynamic_coupling[i] = (self._params.Wt * self._params.T) / len(neighbors);
else:
self._dynamic_coupling[i] = 0;

# generate first noises
self._noise = [random.random() * self._params.ro for i in range(self._num_osc)];

def simulate(self, steps, time, solution = solve_type.FAST, collect_dynamic = True):
if ( (len(neighbors) > 0) and (self._stimulus[i] > 0) ):
number_stimulated_neighbors = 0;
for j in neighbors:
if (self._stimulus[j] > 0):
number_stimulated_neighbors += 1;

dynamic_weight = self._params.Wt / number_stimulated_neighbors;
for j in neighbors:
self._dynamic_coupling[i][j] = dynamic_weight;

def simulate(self, steps, time, solution = solve_type.ODEINT, collect_dynamic = True):
return self.simulate_static(steps, time, solution, collect_dynamic);

def simulate_static(self, steps, time, solution = solve_type.FAST, collect_dynamic = False):
def simulate_static(self, steps, time, solution = solve_type.ODEINT, collect_dynamic = False):
dyn_exc = None;
dyn_time = None;

Expand Down Expand Up @@ -123,10 +137,11 @@ def _calculate_states(self, solution, t, step, int_step):
# Update states of oscillators
for index in range (0, self._num_osc, 1):
if (solution == solve_type.FAST):
[ next_excitatory[index], next_inhibitory[index], next_potential[index] ] = self.legion_state([self._excitatory[index], self._inhibitory[index], self._potential[index]], 0, index);
next_excitatory[index] += self._excitatory[index];
next_inhibitory[index] += self._inhibitory[index];
next_potential[index] += self._potential[index];
assert 0;
#[ next_excitatory[index], next_inhibitory[index], next_potential[index] ] = self.legion_state([self._excitatory[index], self._inhibitory[index], self._potential[index]], 0, index);
#next_excitatory[index] += self._excitatory[index];
#next_inhibitory[index] += self._inhibitory[index];
#next_potential[index] += self._potential[index];

elif (solution == solve_type.ODEINT):
result = odeint(self.legion_state, [self._excitatory[index], self._inhibitory[index], self._potential[index]], numpy.arange(t - step, t, int_step), (index , ));
Expand All @@ -137,10 +152,12 @@ def _calculate_states(self, solution, t, step, int_step):

# Update state of global inhibitory
if (solution == solve_type.FAST):
z = self._global_inhibitor + self.global_inhibitor_state(self._global_inhibitor, t, None);
assert 0;
# z = self._global_inhibitor + self.global_inhibitor_state(self._global_inhibitor, t, None);

elif (solution == solve_type.ODEINT):
result = odeint(self.global_inhibitor_state, self._global_inhibitor, numpy.arange(t - step, t, int_step), (None, ));
self._global_inhibitor = result[len(result) - 1][0];

else:
assert 0;
Expand Down Expand Up @@ -182,15 +199,15 @@ def legion_state(self, inputs, t, argv):

coupling = 0
for index_neighbor in neighbors:
coupling += self._dynamic_coupling[index_neighbor] * heaviside(self._excitatory[index_neighbor] - self._params.teta_x);
coupling += self._dynamic_coupling[index][index_neighbor] * heaviside(self._excitatory[index_neighbor] - self._params.teta_x);

self._buffer_coupling_term[index] = coupling - self._params.Wz * heaviside(self._global_inhibitor - self._params.teta_xz);

return [dx, dy, dp];


from support import draw_dynamics;

net = legion_network(1);
(t, x) = net.simulate(1000, 500, solve_type.ODEINT, collect_dynamic = True);
draw_dynamics(t, x, x_title = "Time", y_title = "x(t)");
# from support import draw_dynamics;
#
# net = legion_network(5, [0.2, 0.2, 0.2, 0.2, 0.2], type_conn = conn_type.LIST_BIDIR);
# (t, x) = net.simulate(1000, 500, solution = solve_type.ODEINT, collect_dynamic = True);
# draw_dynamics(t, x, x_title = "Time", y_title = "x(t)");
35 changes: 35 additions & 0 deletions nnet/legion/examples.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
from support import draw_dynamics;

from nnet.legion import legion_network;
from nnet import *;

def template_dynamic_legion(num_osc, steps, time, conn_type = conn_type.NONE, stimulus = None, params = None):
net = legion_network(num_osc, stimulus, type_conn = conn_type);
(t, x) = net.simulate(steps, time);

draw_dynamics(t, x, x_title = "Time", y_title = "x(t)");

def one_oscillator_unstimulated():
template_dynamic_legion(1, 2000, 200);

def one_oscillator_stimulated():
template_dynamic_legion(1, 2000, 200, stimulus = [1]);

def three_oscillator_unstimulated_list():
template_dynamic_legion(3, 2000, 200, conn_type = conn_type.LIST_BIDIR);

def three_oscillator_stimulated_list():
template_dynamic_legion(3, 1000, 500, conn_type = conn_type.LIST_BIDIR, stimulus = [1, 1, 1]);

def ten_oscillator_stimulated_list():
template_dynamic_legion(10, 1000, 750, conn_type = conn_type.LIST_BIDIR, stimulus = [1] * 10);

def ten_oscillator_mix_stimulated_list():
template_dynamic_legion(10, 1500, 1500, conn_type = conn_type.LIST_BIDIR, stimulus = [1, 1, 1, 0, 0, 0, 0, 1, 1, 1]);

one_oscillator_unstimulated();
one_oscillator_stimulated();
three_oscillator_unstimulated_list();
three_oscillator_stimulated_list();
ten_oscillator_stimulated_list();
ten_oscillator_mix_stimulated_list();

0 comments on commit fa8c7e3

Please sign in to comment.