⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 netloader.cpp

📁 amygdata的神经网络算法源代码
💻 CPP
📖 第 1 页 / 共 2 页
字号:
/***************************************************************************                          netloader.cpp  -  description                             -------------------    begin                : Mon Apr 29 2002    copyright            : (C) 2002 by Rudiger Koch    email                : rkoch@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.                                   * *                                                                         * ***************************************************************************/#include "amygdala/netloader.h"#include "amygdala/synapse.h"#include "amygdala/synapseproperties.h"#include "amygdala/neuron.h"#include "amygdala/inputneuron.h"#include "amygdala/basicneuron.h"#include "amygdala/utilities.h"#include "amygdala/axon.h"#include "amygdala/axonnode.h"#include "amygdala/physicalproperties.h"#include "amygdala/spikeinput.h"#include "amygdala/spikeoutput.h"#include "amygdala/outputmanager.h"#include "amygdala/nconnector.h"#include <stdexcept>#include <iostream>#include <libxml/parser.h>#include <libxml/parserInternals.h>using namespace std;using namespace Amygdala;extern "C" {    void __SAXStartElement1(NetLoader *netLoader, const char *name, const char **attrs){        netLoader->SAXStartElement1(name, attrs);    }    void __SAXEndElement1(NetLoader *netLoader, const char *name){        netLoader->SAXEndElement1(name);    }    void __SAXStartElement2(NetLoader *netLoader, const char *name, const char **attrs){        netLoader->SAXStartElement2(name, attrs);    }    void __SAXEndElement2(NetLoader *netLoader, const char *name){        netLoader->SAXEndElement2(name);    }    void __SAXError(NetLoader *netLoader, const char *msg, ...){        cerr << msg << endl;        netLoader->SAXError();    }} // extern "C"NetLoader::NetLoader(){}NetLoader::~NetLoader(){}void NetLoader::SAXError(){    saxErrors++;}void NetLoader::SAXStartElement1(string name, const char **attrs){    if(name == "synapse"){        return;    } else if(name == "property"){        if(attrs == NULL) return;        ParseProperties(attrs);        return;    } else if(name == "neuron"){        if(attrs == NULL) return;        ParseNeuron(attrs);        return;    } else if(name == "topology"){        if(attrs == NULL) return;        ParseTopology(attrs);        return;    } else if(name == "network"){        return;    }}void NetLoader::SAXEndElement1(string name){    if(name == "synapse"){        sProps = NULL;    }    else if(name == "neuron"){        NFactory * nf =  dynamic_cast<NFactory*> (FactoryBase::GetRegistry().GetFactory(currNType));        if (nf == NULL) throw runtime_error("No neuron type " + currNType + " registered!");        nf->MakeNeuron(currNId, nProps, currTop);        currNId = 0;        nProps = NULL;    }    else if(name == "topology"){        currTop = NULL;    }}void NetLoader::SAXEndElement2(string name){    if(name == "neuron") {        currNId = 0;        currNType.clear();        nProps = NULL;    }else if(name == "synapse"){        SpikingNeuron * post = dynamic_cast <SpikingNeuron * > (Network::GetNetworkRef()->GetNeuron(postNId));        connector->Connect(currNeuron, post, *sProps);        sProps = NULL;    } else if(name == "outputgroup"){        outputGroup = 0;    } else if(name == "spikeinput"){        spikeInput = NULL;    } else if(name == "spikeoutput"){        spikeOutput = NULL;    }}void NetLoader::SAXStartElement2(string name, const char **attrs){    if(name == "synapse"){        if(attrs == NULL) return;        ParseSynapse(attrs);        return;    } else if(name == "property"){        if(attrs == NULL) return;        ParseProperties(attrs);        return;    } else if(name == "neuron"){        if(attrs == NULL) return;        ParseNeuron(attrs);        return;    } else if(name == "topology"){        if(attrs == NULL) return;        ParseTopology(attrs);        return;    } else if(name == "outputgroup"){        if(attrs == NULL) return;        ParseOutputGroup(attrs);        return;    } else if(name == "spikeoutput"){        if(attrs == NULL) return;        ParseSpikeOutput(attrs);        return;    } else if(name == "spikeinput"){        if(attrs == NULL) return;        ParseSpikeInput(attrs);        return;    }}void NetLoader::ParseSpikeInput(const char **attrs){    string siName;    string siType;    for (unsigned int i = 0; attrs[i] != NULL; i++) {        string name(attrs[i]);        string value(attrs[++i]);        if ( name == "type" ) {            siType = value;        } else if ( name == "name" ) {            siName = value;        }    }    SIFactory * sif =  dynamic_cast<SIFactory*> (FactoryBase::GetRegistry().GetFactory(siType));    if (sif == NULL) throw runtime_error("No SpikeInput type " + siType + " registered!");    spikeInput = sif->MakeSpikeInput(siName);}void NetLoader::ParseSpikeOutput(const char **attrs){    string soName;    string soType;    for (unsigned int i = 0; attrs[i] != NULL; i++) {        string name(attrs[i]);        string value(attrs[++i]);        if ( name == "type" ) {            soType = value;        } else if ( name == "name" ) {            soName = value;        }    }    SOFactory * sof =  dynamic_cast<SOFactory*> (FactoryBase::GetRegistry().GetFactory(soType));    if (sof == NULL) throw runtime_error("No SpikeOutput type " + soType + " registered!");    spikeOutput = sof->MakeSpikeOutput(soName);}void NetLoader::ParseOutputGroup(const char **attrs){    unsigned int enabled=0;    for (unsigned int i = 0; attrs[i] != NULL; i++) {        string name(attrs[i]);        string value(attrs[++i]);        if ( name == "id" ) {            outputGroup = atoi(value.c_str());        } else if ( name == "enabled" ) {            enabled = atoi(value.c_str());        }    }    OutputManager::EnableOutput(enabled, outputGroup);}void NetLoader::ParseSynapse(const char **attrs){    string sType;    AmTimeInt delay=0;    for (unsigned int i = 0; attrs[i] != NULL; i++) {        string name(attrs[i]);        string value(attrs[++i]);        if ( name == "postneuron" ){            postNId = atoi(value.c_str());        } else if ( name == "type" ) {            sType = value;        } else if ( name == "delay" ) {            delay = atoi(value.c_str());        }    }    ConnectorRegistry & cr = ConnectorRegistry::GetRegistry();    connector = cr.GetConnector(sType);    sProps = connector->GetDefaultProperties();    sProps->SetDelay(delay);}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -