📄 main.cpp
字号:
using namespace std;#include <amygdala/layer.h>#include <amygdala/netloader.h>#include <amygdala/network.h>#include <amygdala/node.h>//#include "../utilities/topology.h"#include <stdexcept>#include <iostream>// this function creates a Network for us we can then load and save.// It's an arbitrary neural network doing nothing usefulvoid mknet(NetLoader *nl){ Layer *layer1, *layer2, *layer3; LayerConstants layerConst; layerConst.learningConst = 1e-3; layerConst.membraneTimeConst = 7.0; layerConst.synapticTimeConst = 2.0; layerConst.restPtnl = 0.0; layerConst.thresholdPtnl = 5.0; try { layerConst.type = INPUTLAYER; layerConst.layerId = 123; // any integer will do as long as it's unique within a _Network_ layer1 = nl->BuildLayer(10, 1, layerConst, "AlphaNeuron"); layer1->LayerName("Input"); layerConst.type = HIDDENLAYER; layerConst.layerId = 287; layer2 = nl->BuildLayer(10, 20, layerConst, "FastNeuron"); layer2->LayerName("Hidden"); layerConst.type = OUTPUTLAYER; layerConst.layerId = 125; layer3 = nl->BuildLayer(10, 50, layerConst, "FastNeuron"); layer3->LayerName("Output"); } catch (string e) { cout << e << endl; exit (-1); } GaussConnectType conParms; conParms.meanWeight = 0.8; conParms.stdDev = 0.01; conParms.pctConnect = 100.0; // Fully connected layer1->ConnectLayers(layer2, conParms); layer2->ConnectLayers(layer3, conParms);}// make a simple (i.e. no SMP) Network, save it to a file and load it againvoid simple(){ Network *network = new Network(); NetLoader *nl = new NetLoader(network); try { mknet(nl); nl->SaveXML("simple.xml.gz"); // kill the network.... delete nl; delete network; // ... and make a fresh network network = new Network(); nl = new NetLoader(network); nl->LoadXML("simple.xml.gz"); //Topology top; // print out the network connections //top.TracePath(network); } catch (string e){ cout << e << endl; } delete nl; delete network;}// make a SMP net with 3 Network instances (partitions),// save them to a file and load them again. Such a net is suitable to// run on a system with 2 CPUsvoid smp(){ Node *theNode = Node::GetNodeRef(); Network *network1 = theNode->MakeNetwork(1); NetLoader *nl1 = new NetLoader(network1); mknet(nl1); Network *network2 = theNode->MakeNetwork(2); NetLoader *nl2 = new NetLoader(network2); mknet(nl2); Network *network3 = theNode->MakeNetwork(3); NetLoader *nl3 = new NetLoader(network3); mknet(nl3); delete nl1; delete nl2; delete nl3; try { theNode->Save("smp.amg"); theNode->Load("smp.amg"); } catch (runtime_error e) { cout << e.what() << endl; } catch (string e) { cout << e << endl; exit (-1); }}int main(int argc, char *argv[]){ if(argc > 1) { if(string("smp") == argv[1]){ smp(); } else { cout << "Usage: " << argv[0] << " [smp]" << endl; } } else { simple(); } return 0;}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -