Last active
January 4, 2016 04:19
-
-
Save Uiuran/8567499 to your computer and use it in GitHub Desktop.
This code is to simulate a multi-topology network with homeostatic individuals that are influential on their neighbors. The code is not perfect yet, mnet_pack are networkx, numpy and other necessaries packages to come...
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
from mnet_pack import * | |
# Multi topologies network and cyclic Kinouchi-Copelli like automatas | |
# Copyleft (AA) 2014 ooOOOoooOOOoo8OOOooooOOOOooo8ooOO69 | |
# This program is free software: you can redistribute it and/or modify | |
# it under the terms of the GNU Affero General Public License as | |
# published by the Free Software Foundation, either version 3 of the | |
# License, or (at your option) any later version. | |
# 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 Affero General Public License for more details. | |
# You should have received a copy of the GNU Affero General Public LicenseT | |
# along with this program. If not, see <http://www.gnu.org/licenses/>. | |
class Multi: | |
''' Multi(num_nodes = 100, num_net = 2, net_type = {0:'er',1:'ws'}, interconnection = {'random': {0 : connex_tax, 1 : 'non-neighbour'}}) | |
Returns the matrix of network weight list that encompass all the weights of the multi-network, including the interconnection weights, the lists has a weight for each net-type of the multi-net. One must specify a dictionarie 'net_type' with network types (erdois-renyie 'er', watts-strogatz 'ws', ...) and a dictionarie with a interconnection strategy, where the key is the name of the strategy and the value is dictionarie with the arguments of the strategy. The implemented strategies are: | |
'random' - generate a int(connex_tax*num_nodes) number of links between different network types. Argument 0 is connex_tax, argument 1 is 'neighbour' for neighbouring net-types connection or 'non-neighbour' for all-to-all connection between net-types. ''' | |
def __init__(self, num_nos = 100, multi_redes = {0:{0:'er', 1:0.5},1: { 0:'ws', 1:4, 2:0.35}, 2:{ 0:'sf', 1:0.41, 2:0.54, 3: 0.05}}, inter_conexoes = {0:{ 1:{'weight':0.5}, 2:{'weight':0.25} }, 1:{ 0:{'weight':0.5}, 2:{'weight':0.3} }, 2:{ 0:{'weight':0.25}, 1:{'weight':0.3} } }, is_multiplex = True ): | |
# Do all the topologies of the multinetwork; | |
self.arquitetura_de_redes = []; | |
for rede in multi_redes: | |
# Check the type of the network and and build its architecture | |
self.faz_rede(rede, num_nos, multi_redes); | |
self.arquitetura_multi_redes = inter_conexoes; | |
def faz_rede(self, topologia, numero_nos, multi_redes): | |
tipo_da_rede = multi_redes[topologia][0]; # argumento 0 de cada topologia eh o nome daquele tipo | |
if tipo_da_rede == 'er': | |
self.arquitetura_de_redes.append(nx.generators.erdos_renyi_graph(numero_nos, multi_redes[topologia][1]) | |
elif tipo_da_rede == 'sw': | |
self.arquitetura_de_redes.append(nx.generators.connected_watts_strogatz_graph(numero_nos, multi_redes[topologia][1], multi_redes[topologia][2])); | |
elif tipo_da_rede == 'sf': | |
self.arquitetura_de_redes.append(nx.generators.scale_free_graph(numero_nos, multi_redes[topologia][0],multi_redes[topologia][1],multi_redes[topologia][2]); | |
class KinouchiCopelli: | |
''' Kinouchi Copelli model with support for a multi-level network dynamics. Each node has m states s = 0,1,2,...,m, where 2 to m are refractory states, 0 is a resting state and 1 is a excited state.''' | |
def __init__(self, multi_redes, unidades_de_entrada, estados = 2, tax_ramifica = 0.5, taxa_de_entrada = 2.0): | |
if estados < 2: | |
self.state_space = 2; | |
else: | |
self.state_space = estados; | |
self.neurons_de_entrada = unidades_de_entrada; | |
E_k = np.array( [ np.mean(nx.degree(multi_redes[i]).values()) for i in range(len(multi_redes)) ] ); | |
self.redes = ( multi_redes.arquitetura_de_redes, multi_redes.arquitetura_multi_redes); | |
if tax_ramifica < txmax: | |
self.p_max = np.array( [ 2.0*np.random.uniform(0,1)/E_k[i] for i in range(len(multi_redes)) ] ); | |
else: | |
self.p_max = np.array( [ 2.0*np.random.uniform(0,1)/E_k[i] for i in range(len(multi_redes)) ] ); | |
generateTransitionsP(); | |
def generateTransitionsP(): | |
if len(self.redes[1]) == 0: | |
for edge in self.redes[0][0].edge: | |
for a in self.redes[0][0].edge[edge].items(): | |
if a[0] == (edge-1): | |
self.redes[0][0].edge[edge][a[0]]['P'] = g.edge[edge-1][edge]['P']; | |
else: | |
self.redes[0][0].edge[edge][a[0]]['P'] = np.random.uniform(0,self.pmax[0]); | |
else: | |
for net in range(len(self.redes[0])): | |
for edge in self.redes[0][net].edge: | |
for a in self.redes[0][net].edge[edge].items(): | |
if a[0] == (edge-1): | |
self.redes[0][net].edge[edge][a[0]]['P'] = g.edge[edge-1][edge]['P']; | |
else: | |
self.redes[0][net].edge[edge][a[0]]['P'] = np.random.uniform(0,self.pmax[net]); | |
def setPmax(self, probabilidade_maxima): | |
self.p_max = probabilidade_maxima; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment