?? layer.h
字號:
/*************************************************************************** layer.h - description ------------------- begin : Wed Apr 11 2001 copyright : (C) 2001 by Matt Grover email : mgrover@amygdala.org ***************************************************************************//*************************************************************************** * * * This program is free software; you can redistribute it and/or modify * * it under the terms of the GNU General Public License as published by * * the Free Software Foundation; either version 2 of the License, or * * (at your option) any later version. * * * ***************************************************************************/#ifndef LAYER_H#define LAYER_Husing namespace std;#include <vector>#include <string>#include <amygdala/neuron.h>#include <amygdala/network.h>#include <amygdala/types.h>class Network;class Neuron;/** @class Layer layer.h amygdala/layer.h * @brief Layer groups a number of Neurons for convenience. Layer is not needed to * operate the network. * * The only limitation currently is that unlayered Networks * cannot be loaded or saved. This limitation should be addressed in 0.3. * @see Neuron, Network, NetLoader *@author Matt Grover */class Layer {public: Layer(); ~Layer(); friend class Network; /** Add a pre instantiated Neuron to the Layer. This doesn't affect the * ownership of the Neuron until the Layer is added to a Network. At that * point, the Network will assume ownership of the pointer. Neurons that * are added to layers do not need to be added to a Network separately. * @param nrn Pointer to a Neuron object that will be added to the Layer. * @see Network::AddLayer() */ void AddNeuron(Neuron* nrn); /** Add pre instantiated Neuron objects to the Layer. This doesn't affect the * ownership of the Neuron until the Layer is added to a Network. At that * point, the Network will assume ownership of the pointer. Neurons that * are added to layers do not need to be added to a Network separately. * @param nrnVec Vector of pointers to Neuron objects that will be * added to the Layer. * @see Network::AddLayer() */ void AddNeuronVector(vector<Neuron*> nrnVec); /** Set the name of the Layer. This is optional, * but it can be useful after reloading a Network from * a file. * @param name Name of the Layer. */ void LayerName(string name) { layerName = name; } /** Retrieve the name of the Layer, * @returns Layer name. */ string LayerName() { return layerName; } /** Set the unique numeric ID for the Layer. * @param id Numeric id. */ void SetLayerId(unsigned int id) { layerId = id; } /** Get the numeric ID of the Layer. * @returns Numeric ID. */ unsigned int LayerId() { return layerId; } /** Designate what kind of layer this is * @parap ltype layer type. */ void SetLayerType(LayerType ltype) { layerType = ltype; } /** Get the layer type * @returns layer type */ LayerType GetLayerType() { return layerType; } /** Set the percentage of neurons that should be inhibitory * in the layer. This value can be overridden if it is * also set in ConnectLayers if Neuron::EnforceSign() has not * been called. * @param percent Percentage of neurons that are inhibitory (0 - 100.0) * @see Neuron::EnforceSign() */ void SetPercentInhibitory( float percent ); /** Connect this layer to to another layer. * @param output Layer that will receive input from this * layer. * @param parms Uniform connection parameters. Layers * connected with this parameter type will have weights * set from a uniform random distribution. * @param pctInhibitory If Neuron::EnforceSign() has not been set * prior to connecting the layers, then this can be used to set the number of * connections to output that will have a negative weight. * pctInhibitory will be ignored if sign enforcement has been * turned on and must be in the range 0 -> 100.0. * @see Node::ConnectLayers() */ bool ConnectLayers(Layer* output, UniConnectType parms, float pctInhibitory = 0.0); /** Connect this layer to to another layer. * @param output Layer that will receive input from this * layer. * @param parms Gaussian connection parameters. Layers * connected with this parameter type will have weights * set from a random Gaussian distribution. * @param pctInhibitory If Neuron::EnforceSign() has not been set * prior to connecting the layers, then this can be used to set the number of * connections to output that will have a negative weight. * pctInhibitory will be ignored if sign enforcement has been * turned on and must be in the range 0 -> 100.0. * @see Node::ConnectLayers() */ bool ConnectLayers(Layer* output, GaussConnectType parms, float pctInhibitory = 0.0); /** Set constants that should be common to all neurons * in a layer, such as time constants and learning constants. * This is optional and layers can be constructed without requiring * that all member Neurons have the constants. * @param lconst Layer constant structure. * @see GetLayerConstants() */ bool SetLayerConstants(LayerConstants lconst); /** Retrieve the set of constants that are common to * all Neurons in a layer if they have been previously set. * @returns LayerConstants struct. * @see SetLayerConstants() */ LayerConstants GetLayerConstants(); /** Set the default spike transmission delay. * @param delay The value of the delay in microseconds (us). */ void SetSynapticDelay(AmTimeInt delay) { synapticDelay = delay; } /** Get the default spike transmission delay. * @returns The value of the delay in microseconds (us). */ AmTimeInt GetSynapticDelay() const { return synapticDelay; } /* * Types and members refering to vector */ /** @returns The size of the layer. */ unsigned int size() { return nrnLayer.size(); } typedef vector<Neuron*>::iterator iterator; typedef vector<Neuron*>::const_iterator const_iterator; typedef vector<Neuron*>::reverse_iterator reverse_iterator; typedef vector<Neuron*>::const_reverse_iterator const_reverse_iterator; /** @returns An iterator (vector<Neuron*>) pointing to the first neuron in the layer. */ iterator begin() { return nrnLayer.begin(); } /** @returns An iterator (vector<Neuron*>) pointing to the last neuron in the layer. */ iterator end() { return nrnLayer.end(); } /** @returns An iterator (vector<Neuron*>) pointing to the first neuron in the layer. */ const_iterator begin() const { return nrnLayer.begin(); } /** @returns An iterator (vector<Neuron*>) pointing to the last neuron in the layer. */ const_iterator end() const { return nrnLayer.end(); } /** @returns A reverse iterator (vector<Neuron*>) pointing to the first neuron in the layer. */ reverse_iterator rbegin() { return nrnLayer.rbegin(); } /** @returns A reverse iterator (vector<Neuron*>) pointing to the last neuron in the layer. */ reverse_iterator rend() { return nrnLayer.rend(); } /** @returns A reverse iterator (vector<Neuron*>) pointing to the first neuron in the layer. */ const_reverse_iterator rbegin() const { return nrnLayer.rbegin(); } /** @returns A reverse iterator (vector<Neuron*>) pointing to the last neuron in the layer. */ const_reverse_iterator rend() const { return nrnLayer.rend(); } /** @returns A pointer to a member Neuron. The index is not related * to the NeuronID. */ Neuron* operator[](unsigned int& index) { return nrnLayer[index]; } protected: void SetLayerParent(Network* parent); inline bool ConnectionInhibitory(float& pctInhibitory); vector<Neuron*> nrnLayer; Network* parentNet; string layerName; LayerType layerType; unsigned int layerId; // Defaults for member neurons float learningConst; float memTimeConst; float synTimeConst; float restPtnl; float thresholdPtnl; bool constantsSet; float percentInhib; AmTimeInt synapticDelay;};#endif
?? 快捷鍵說明
復制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號
Ctrl + =
減小字號
Ctrl + -