📄 netloader.h
字号:
/*************************************************************************** netloader.h - description ------------------- begin : Mon Apr 29 2002 copyright : (C) 2002 by R黡iger Koch email : rkoch@rkoch.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 NETLOADER_H#define NETLOADER_Husing namespace std;#include <amygdala/types.h>#if GCC_VERSION >= 30000 #include <ext/hash_map>#else #include <hash_map>#endif#include <string>#include <strings.h>#include <stdio.h>#include <amygdala/neuron.h>class Layer;class NeuronFactoryBase {public: NeuronFactoryBase() {} virtual Neuron * NewNeuron(AmIdInt id) = 0; virtual string GetType() = 0;};/** @class NeuronFactory netloader.h amygdala/netloader.h * create Neuron instances of class <neuron>. When users want to write their * own neuron types they can instantiale a NeuronFactory for it and register * it. * @see NetLoader::RegisterNeuronClass() * @author R黡iger Koch */template<class neuron>class NeuronFactory : public NeuronFactoryBase {public: NeuronFactory(){ } virtual ~NeuronFactory(){} virtual Neuron * NewNeuron(AmIdInt id){ neuron *n = new neuron(id); return n; } /** Return the Type of the Neuron class */ virtual string GetType() { // We instantiate a dummy neuron here so we can call the virtual // function. neuron n(0); return n.ClassId(); }};/**@class NetLoader netloader.h amygdala/netloader.h *load and save Network instances. This class can be used with MP, but each NetLoader *instance is attached to the Network instance it is managing. If you want to use this *class in an SMP environmant with 20 Network instances you will need 20 associated *NetLoader instances *@author R黡iger Koch *@author Matt Grover *@see Node */class NetLoader {public: NetLoader(Network *_net); ~NetLoader(); /** Register a new NeuronFactory */ void RegisterNeuronClass(NeuronFactoryBase *factory); /** Load a Network from a file * @param filename */ void LoadXML(const char *filename); /** save a single Network Instance to a file. * @param filename the file to save the Network */ void SaveXML(string filename); /** Build a Layer that is composed of one particular Neuron type */ Layer* BuildLayer(int size, int startNrnId, LayerConstants layerConst, string neuronType); /** a SAX callback - don't use this function */ void SAXStartElement1(const char *name, const char **attrs); /** a SAX callback - don't use this function */ void SAXEndElement1(const char *name); /** a SAX callback - don't use this function */ void SAXStartElement2(const char *name, const char **attrs); /** a SAX callback - don't use this function */ void SAXEndElement2(const char *name); /** handles all SAX errors - don't use this function */ void SAXError();protected: // Protected attributes struct eqstr { bool operator()(const char* s1, const char* s2) const { return strcmp(s1, s2) == 0; } }; /** all known NeuronFactorys get registered here. The registry can hold * unknown factories regiestered by the user's application */ hash_map <const char*, NeuronFactoryBase*, hash<const char*>, eqstr > registry; /** The network object we're working on */ Network* net; Layer *currLayer; AmIdInt currNeuron; unsigned int saxErrors;private: // Private methods /** prevent users from instantiate empty NetLoaders */ NetLoader();protected: // Protected methods /** put the weights into the DOM tree */ void WriteSynapses(FILE *netFile, Neuron* preNrn); /** Put all layers into the DOM tree */ void SaveLayers(FILE *netFile); /** @return a string identifying the layer given by IType */ string LayerTypeStr(LayerType lType); /** Loading is done in 2 passes: in the first pass we * instantiate all layers and neurons. In the second we connect them. */ void SAXPass(const char* filename, int pass); void ParseLayerConstants(LayerConstants *layerConst, char **name, const char **attrs);};#endif
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -