diff --git a/build/lib/sorn/__init__.py b/build/lib/sorn/__init__.py index 754bb77..a0274ad 100644 --- a/build/lib/sorn/__init__.py +++ b/build/lib/sorn/__init__.py @@ -3,6 +3,6 @@ from .utils import * __author__ = "Saranraj Nambusubramaniyan" -__version__ = "0.5.8" +__version__ = "0.6.1" logging.basicConfig(level=logging.INFO) diff --git a/build/lib/sorn/sorn.py b/build/lib/sorn/sorn.py index 3b941c9..c23eafc 100644 --- a/build/lib/sorn/sorn.py +++ b/build/lib/sorn/sorn.py @@ -12,51 +12,7 @@ class Sorn(object): - """ This class wraps initialization of the network and its parameters - - Args: - nu (int): Number of input units. Defaults to 10 - - ne (int): Number of excitatory units. Defaults to 200 - - eta_stdp (float): STDP plasticity Learning rate constant; SORN1 and SORN2. Defaults to 0.004 - - eta_ip (float): Intrinsic plasticity learning rate constant; SORN1 and SORN2. Defaults to 0.001 - - eta_inhib (float): Intrinsic plasticity learning rate constant; SORN2 only. Defaults to 0.01 - - h_ip (float): Target firing rate. Defaults to 2 * nu / ne - - mu_ip (float): Mean target firing rate. Defaults to 0.1 - - sigma_ip (float): Variance of target firing rate. Defaults to 0.0 - - ni (int): Number of inhibitory units in the network. Defaults to int(0.2*ne) - - time_steps (float): Total time steps of simulation - - te_min (float): Excitatory minimum Threshold. Defaults to 0.0 - - te_max (float): Excitatory maximum Threshold. Defaults to 1.0 - - ti_min (float): Inhibitory minimum Threshold. Defaults to 0.0 - - ti_max (float): Inhibitory maximum Threshold. Defaults to 0.5 - - network_type_ee (str): Dense or Sparse. Defaults to Sparse - - network_type_ei (str): Dense or Sparse. Defaults to Sparse - - network_type_ie (str): Dense or Sparse. Defaults to Dense - - lambda_ee (int): Number of connections to and from a single excitatory unit to another at initialization. Defaults to 20 - - lambda_ei (int): Number of connections to and from a single inhibitory unit to exitatory unit at initialization. Defaults to 40 - - lambda_ie (int): Number of connections to and from a single excitatory unit to inhibitory unit at initialization. Defaults to 100""" - - def __init__(self): - pass + """ This class wraps initialization of the network and its parameters""" nu = 10 ne = 200 @@ -76,16 +32,21 @@ def __init__(self): lambda_ee = 20 lambda_ei = 40 lambda_ie = 100 + @staticmethod - def initialize_weight_matrix( - network_type: str, synaptic_connection: str, self_connection: str, lambd_w: int + def initialize_weight_matrix(network_type: str, synaptic_connection: str, self_connection: str, lambd_w: int ): """Wrapper for initializing the weight matrices for SORN + Args: network_type (str): Spare or Dense + synaptic_connection (str): EE,EI,IE. Note that Spare connection is defined only for EE connections + self_connection (str): True or False: Synaptic delay or time delay + lambd_w (int): Average number of incoming and outgoing connections per neuron + Returns: weight_matrix (array): Array of connection strengths """ @@ -108,15 +69,15 @@ def initialize_weight_matrix( return weight_matrix @staticmethod - def initialize_threshold_matrix( - te_min: float, te_max: float, ti_min: float, ti_max: float - ): + def initialize_threshold_matrix(te_min: float, te_max: float, ti_min: float, ti_max: float): """Initialize the threshold for excitatory and inhibitory neurons + Args: te_min (float): Min threshold value for excitatory units te_max (float): Min threshold value for inhibitory units ti_min (float): Max threshold value for excitatory units ti_max (float): Max threshold value for inhibitory units + Returns: te (array): Threshold values for excitatory units ti (array): Threshold values for inhibitory units @@ -130,9 +91,11 @@ def initialize_threshold_matrix( @staticmethod def initialize_activity_vector(ne: int, ni: int): """Initialize the activity vectors X and Y for excitatory and inhibitory neurons + Args: ne (int): Number of excitatory neurons ni (int): Number of inhibitory neurons + Returns: x (array): Array of activity vectors of excitatory population y (array): Array of activity vectors of inhibitory population""" @@ -145,21 +108,6 @@ def initialize_activity_vector(ne: int, ni: int): class Plasticity(Sorn): """Instance of class Sorn. Inherits the variables and functions defined in class Sorn. It encapsulates all plasticity mechanisms mentioned in the article. Inherits all attributed from parent class Sorn - Args: - nu (int): Number of input units. Defaults to 10 - ne (int): Sorn.ne # Number of excitatory units. Defaults to 200 - eta_stdp (float): STDP plasticity Learning rate constant; SORN1 and SORN2. Defaults to 0.004 - eta_ip (float): Intrinsic plasticity learning rate constant; SORN1 and SORN2. Defaults to 0.001 - eta_inhib (float): Intrinsic plasticity learning rate constant; SORN2 only. Defaults to 0.01 - h_ip (float): Target firing rate. Defaults to 2 * Sorn.nu / Sorn.ne - mu_ip (float): Mean target firing rate. Defaults to 0.1 - sigma_ip (float): Variance of target firing rate. Defaults to 0.0 - ni (int): Number of inhibitory units in the network. Defaults to int(0.2 * Sorn.ne) - time_steps (float): Total time steps of simulation - te_min (float): Excitatory minimum Threshold. Defaults to 0.0 - te_max (float): Excitatory maximum Threshold. Defaults to 1.0 - ti_min (float): Inhibitory minimum Threshold. Defaults to 0.0 - ti_max (float): Inhibitory maximum Threshold. Defaults to 0.5 """ def __init__(self): @@ -186,10 +134,14 @@ def __init__(self): def stdp(self, wee: np.array, x: np.array, cutoff_weights: list): """Apply STDP rule : Regulates synaptic strength between the pre(Xj) and post(Xi) synaptic neurons + Args: wee (array): Weight matrix + x (array): Excitatory network activity + cutoff_weights (list): Maximum and minimum weight ranges + Returns: wee (array): Weight matrix """ @@ -227,9 +179,12 @@ def stdp(self, wee: np.array, x: np.array, cutoff_weights: list): def ip(self, te: np.array, x: np.array): """Intrinsic Plasiticity mechanism + Args: te (array): Threshold vector of excitatory units + x (array): Excitatory network activity + Returns: te (array): Threshold vector of excitatory units """ @@ -252,8 +207,10 @@ def ip(self, te: np.array, x: np.array): @staticmethod def ss(wee: np.array): """Synaptic Scaling or Synaptic Normalization + Args: wee (array): Weight matrix + Returns: wee (array): Scaled Weight matrix """ @@ -262,11 +219,16 @@ def ss(wee: np.array): def istdp(self, wei: np.array, x: np.array, y: np.array, cutoff_weights: list): """Apply iSTDP rule, which regulates synaptic strength between the pre inhibitory(Xj) and post Excitatory(Xi) synaptic neurons + Args: wei (array): Synaptic strengths from inhibitory to excitatory + x (array): Excitatory network activity + y (array): Inhibitory network activity + cutoff_weights (list): Maximum and minimum weight ranges + Returns: wei (array): Synaptic strengths from inhibitory to excitatory""" @@ -310,8 +272,10 @@ def istdp(self, wei: np.array, x: np.array, y: np.array, cutoff_weights: list): @staticmethod def structural_plasticity(wee: np.array): """Add new connection value to the smallest weight between excitatory units randomly + Args: wee (array): Weight matrix + Returns: wee (array): Weight matrix""" @@ -336,8 +300,10 @@ def structural_plasticity(wee: np.array): @staticmethod def initialize_plasticity(): """Initialize weight matrices for plasticity phase based on network configuration + Args: kwargs (self.__dict__): All arguments are inherited from Sorn attributes + Returns: tuple(array): Weight matrices WEI, WEE, WIE and threshold matrices Te, Ti and Initial state vectors X,Y """ @@ -404,9 +370,12 @@ def initialize_plasticity(): class MatrixCollection(Sorn): """Collect all matrices initialized and updated during simulation (plasiticity and training phases) + Args: phase (str): Training or Plasticity phase + matrices (dict): Network activity, threshold and connection matrices + Returns: MatrixCollection instance""" @@ -483,10 +452,14 @@ def __init__(self, phase: str, matrices: dict = None): def weight_matrix(self, wee: np.array, wei: np.array, wie: np.array, i: int): """Update weight matrices + Args: wee (array): Excitatory-Excitatory weight matrix + wei (array): Inhibitory-Excitatory weight matrix + wie (array): Excitatory-Inhibitory weight matrix + i (int): Time step Returns: tuple (array): Weight Matrices Wee, Wei, Wie""" @@ -499,10 +472,14 @@ def weight_matrix(self, wee: np.array, wei: np.array, wie: np.array, i: int): def threshold_matrix(self, te: np.array, ti: np.array, i: int): """Update threshold matrices + Args: te (array): Excitatory threshold + ti (array): Inhibitory threshold + i (int): Time step + Returns: tuple (array): Threshold Matrices Te and Ti""" @@ -514,10 +491,14 @@ def network_activity_t( self, excitatory_net: np.array, inhibitory_net: np.array, i: int ): """Network state at current time step + Args: excitatory_net (array): Excitatory network activity + inhibitory_net (array): Inhibitory network activity + i (int): Time step + Returns: tuple (array): Updated Excitatory and Inhibitory states """ @@ -529,10 +510,14 @@ def network_activity_t( def network_activity_t_1(self, x: np.array, y: np.array, i: int): """Network activity at previous time step + Args: x (array): Excitatory network activity + y (array): Inhibitory network activity + i (int): Time step + Returns: tuple (array): Previous Excitatory and Inhibitory states """ @@ -546,8 +531,10 @@ def network_activity_t_1(self, x: np.array, y: np.array, i: int): class NetworkState(Plasticity): """The evolution of network states + Args: v_t (array): External input/stimuli + Returns: instance (object): NetworkState instance""" @@ -565,9 +552,12 @@ def __init__(self, v_t: np.array): def incoming_drive(self, weights: np.array, activity_vector: np.array): """Excitatory Post synaptic potential towards neurons in the reservoir in the absence of external input + Args: weights (array): Synaptic strengths + activity_vector (list): Acitivity of inhibitory or Excitatory neurons + Returns: incoming (array): Excitatory Post synaptic potential towards neurons """ @@ -585,13 +575,20 @@ def excitatory_network_state( white_noise_e: np.array, ): """Activity of Excitatory neurons in the network + Args: wee (array): Excitatory-Excitatory weight matrix + wei (array): Inhibitory-Excitatory weight matrix + te (array): Excitatory threshold + x (array): Excitatory network activity + y (array): Inhibitory network activity + white_noise_e (array): Gaussian noise + Returns: x (array): Current Excitatory network activity """ @@ -623,12 +620,18 @@ def inhibitory_network_state( self, wie: np.array, ti: np.array, y: np.array, white_noise_i: np.array ): """Activity of Excitatory neurons in the network + Args: wee (array): Excitatory-Excitatory weight matrix + wie (array): Excitatory-Inhibitory weight matrix + ti (array): Inhibitory threshold + y (array): Inhibitory network activity + white_noise_i (array): Gaussian noise + Returns: y (array): Current Inhibitory network activity""" @@ -656,13 +659,21 @@ def recurrent_drive( white_noise_e: np.array, ): """Network state due to recurrent drive received by the each unit at time t+1. Activity of Excitatory neurons without external stimuli + Args: + wee (array): Excitatory-Excitatory weight matrix + wei (array): Inhibitory-Excitatory weight matrix + te (array): Excitatory threshold + x (array): Excitatory network activity + y (array): Inhibitory network activity + white_noise_e (array): Gaussian noise + Returns: xt (array): Recurrent network state """ @@ -690,17 +701,27 @@ def recurrent_drive( class Simulator_(Sorn): """Simulate SORN using external input/noise using the fresh or pretrained matrices + Args: inputs (np.array, optional): External stimuli. Defaults to None. + phase (str, optional): Plasticity phase. Defaults to "plasticity". + matrices (dict, optional): Network states, connections and threshold matrices. Defaults to None. + time_steps (int, optional): Total number of time steps to simulate the network. Defaults to 1. + noise (bool, optional): If True, noise will be added. Defaults to True. + Returns: plastic_matrices (dict): Network states, connections and threshold matrices + X_all (array): Excitatory network activity collected during entire simulation steps + Y_all (array): Inhibitory network activity collected during entire simulation steps + R_all (array): Recurrent network activity collected during entire simulation steps + frac_pos_active_conn (list): Number of positive connection strengths in the network at each time step during simulation""" def __init__(self): @@ -718,18 +739,29 @@ def simulate_sorn( **kwargs ): """Simulation/Plasticity phase + Args: inputs (np.array, optional): External stimuli. Defaults to None. + phase (str, optional): Plasticity phase. Defaults to "plasticity" + matrices (dict, optional): Network states, connections and threshold matrices. Defaults to None. + time_steps (int, optional): Total number of time steps to simulate the network. Defaults to 1. + noise (bool, optional): If True, noise will be added. Defaults to True. + freeze (list, optional): List of synaptic plasticity mechanisms which will be turned off during simulation. Defaults to None. + Returns: plastic_matrices (dict): Network states, connections and threshold matrices + X_all (array): Excitatory network activity collected during entire simulation steps + Y_all (array): Inhibitory network activity collected during entire simulation steps + R_all (array): Recurrent network activity collected during entire simulation steps + frac_pos_active_conn (list): Number of positive connection strengths in the network at each time step during simulation""" assert ( @@ -888,18 +920,29 @@ def simulate_sorn( class Trainer_(Sorn): """Train the network with the fresh or pretrained network matrices and external stimuli + Args: inputs (np.array, optional): External stimuli. Defaults to None. + phase (str, optional): Training phase. Defaults to "training". + matrices (dict, optional): Network states, connections and threshold matrices. Defaults to None. + time_steps (int, optional): Total number of time steps to simulate the network. Defaults to 1. + noise (bool, optional): If True, noise will be added. Defaults to True. + freeze (list, optional): List of synaptic plasticity mechanisms which will be turned off during simulation. Defaults to None. + Returns: plastic_matrices (dict): Network states, connections and threshold matrices + X_all (array): Excitatory network activity collected during entire simulation steps + Y_all (array): Inhibitory network activity collected during entire simulation steps + R_all (array): Recurrent network activity collected during entire simulation steps + frac_pos_active_conn (list): Number of positive connection strengths in the network at each time step during simulation""" def __init__(self): @@ -917,17 +960,28 @@ def train_sorn( **kwargs ): """Train the network with the fresh or pretrained network matrices and external stimuli + Args: inputs (np.array, optional): External stimuli. Defaults to None. + phase (str, optional): Training phase. Defaults to "training". + matrices (dict, optional): Network states, connections and threshold matrices. Defaults to None. + time_steps (int, optional): Total number of time steps to simulate the network. Defaults to 1. + noise (bool, optional): If True, noise will be added. Defaults to True. + Returns: + plastic_matrices (dict): Network states, connections and threshold matrices + X_all (array): Excitatory network activity collected during entire simulation steps + Y_all (array): Inhibitory network activity collected during entire simulation steps + R_all (array): Recurrent network activity collected during entire simulation steps + frac_pos_active_conn (list): Number of positive connection strengths in the network at each time step during simulation""" assert ( diff --git a/dist/sorn-0.5.8-py3-none-any.whl b/dist/sorn-0.5.8-py3-none-any.whl deleted file mode 100644 index bf6b0b5..0000000 Binary files a/dist/sorn-0.5.8-py3-none-any.whl and /dev/null differ diff --git a/dist/sorn-0.5.8.tar.gz b/dist/sorn-0.5.8.tar.gz deleted file mode 100644 index b1c9172..0000000 Binary files a/dist/sorn-0.5.8.tar.gz and /dev/null differ diff --git a/dist/sorn-0.6.1-py3-none-any.whl b/dist/sorn-0.6.1-py3-none-any.whl new file mode 100644 index 0000000..1457eda Binary files /dev/null and b/dist/sorn-0.6.1-py3-none-any.whl differ diff --git a/dist/sorn-0.6.1.tar.gz b/dist/sorn-0.6.1.tar.gz new file mode 100644 index 0000000..edb583a Binary files /dev/null and b/dist/sorn-0.6.1.tar.gz differ diff --git a/setup.py b/setup.py index 87ba88d..86a3591 100644 --- a/setup.py +++ b/setup.py @@ -10,7 +10,7 @@ def read(fname): setup( name="sorn", - version="0.5.8", + version="0.6.1", author="Saranraj Nambusubramaniyan", author_email="saran_nns@hotmail.com", description="Self-Organizing Recurrent Neural Networks", diff --git a/sorn.egg-info/PKG-INFO b/sorn.egg-info/PKG-INFO index deeadf8..8cb50fc 100644 --- a/sorn.egg-info/PKG-INFO +++ b/sorn.egg-info/PKG-INFO @@ -1,6 +1,6 @@ Metadata-Version: 2.1 Name: sorn -Version: 0.5.8 +Version: 0.6.1 Summary: Self-Organizing Recurrent Neural Networks Home-page: https://github.com/Saran-nns/sorn Author: Saranraj Nambusubramaniyan diff --git a/sorn/__init__.py b/sorn/__init__.py index 754bb77..a0274ad 100644 --- a/sorn/__init__.py +++ b/sorn/__init__.py @@ -3,6 +3,6 @@ from .utils import * __author__ = "Saranraj Nambusubramaniyan" -__version__ = "0.5.8" +__version__ = "0.6.1" logging.basicConfig(level=logging.INFO)