当前位置: 首页>>代码示例>>C++>>正文


C++ Network::addNode方法代码示例

本文整理汇总了C++中Network::addNode方法的典型用法代码示例。如果您正苦于以下问题:C++ Network::addNode方法的具体用法?C++ Network::addNode怎么用?C++ Network::addNode使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在Network的用法示例。


在下文中一共展示了Network::addNode方法的6个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。

示例1: Network

Network *PerceptronModel::createNetwork(Episode *first_episode) const
{
    Network *network = new Network(first_episode->encodedStateSize());

    Dense *hidden = new Dense(_hidden_neurons, 1e-2);
    TanhActivation *hidden_activation = new TanhActivation;
    Dense *dense2 = new Dense(first_episode->valueSize(), 1e-2);

    hidden->setInput(network->inputPort());
    hidden_activation->setInput(hidden->output());
    dense2->setInput(hidden_activation->output());

    network->addNode(hidden);
    network->addNode(hidden_activation);
    network->addNode(dense2);

    return network;
}
开发者ID:ctguxp,项目名称:rlcpp,代码行数:18,代码来源:perceptronmodel.cpp

示例2: route_edges


//.........这里部分代码省略.........
      int minidx;
      int lastidx=-1;
      bool first=true;
      int gl=gs.size();
      VI used(gl,0);
      while (first || curidx!=iclosest){
         ParamEdge &cur=gs[curidx].line;
         double minc=DBL_MAX;
         for (j=0;j<gl;j++){ // find the nearest crosspoint of one of all voronoi lines; searching to the left from last cross point
            if (j==curidx) continue;
            if (used[j]) continue;
            if (j==lastidx) continue; // finds the last voronoi line again; should not happen as this line should be in used[] already; except for iclosest
            double c=cur.cross_param(gs[j].line);
            if (c==0) { // special case, check whether new line points inwards
               Point ctr90=to_left(Point(x,y)-cur.p(c),PI);
               Point cln90=to_left(cur.unit(),PI);
               Point dirj=gs[j].line.unit();
               if (!((scalar(ctr90,dirj)<0) && (scalar(cln90,dirj)>0))){ // new line not between center line and current line
                  continue;
               }
            }
            if (c>=0 && c<minc){
               minc=c;
               minidx=j;
               //if (i==iter) debugpoint(cur.p(c),state.avgsize/10,0,0,255);
            }
         }
         used[minidx]=1;
         Point cp=cur.cross_point(gs[minidx].line);
         //if (i==iter) debugpoint(cp,state.avgsize/10,0,255,0);
         gs[minidx].line.re_ref(cp); // setting ref point of next line to the current cross point
         //if (i==iter) debugline(gs[minidx].line.from(),gs[minidx].line.p(state.avgsize),255,0,255);
         int newnode=nv.nodes.size(); 
         nv.addNode(newnode,other,"",1,1,cp.x,cp.y,0);
         edge_crossings[min(i,gs[curidx].node)][max(i,gs[curidx].node)].push_back(newnode); // add the new node to the two veronoi lines it belongs to
         edge_crossings[min(i,gs[minidx].node)][max(i,gs[minidx].node)].push_back(newnode);
         //nodemap[i].push_back(newnode);
         lastidx=curidx;
         curidx=minidx;
         first=false;
         //if (i==iter) debugline(cur.from(),cp,0,0,0);
      }
   }
   printf("finding relevant cross points on seperator lines and building network\n");
   
   // go through all voronoi lines and connect all registered cross points
   CmpCrossPoints ccp(nv);
   for (i=0;i<n+4;i++){ // includes 4 virtual nodes
      for (j=i+1;j<n+4;j++){
         if (edge_crossings[i][j].size() ==0 ) continue;
         sort(edge_crossings[i][j].begin(),edge_crossings[i][j].end(),ccp); // sort cross points on line
         for (k=0;k<(int)edge_crossings[i][j].size();k++){
            int n1=edge_crossings[i][j][k];
            if (i<n) nodemap[i].push_back(n1); // register voronoi node to be adjacent to original node i (if not virtual node)
            if (j<n) nodemap[j].push_back(n1);
            if (k==((int)edge_crossings[i][j].size())-1) break; // for the last crosspoint we do not create an edge
            int n2=edge_crossings[i][j][k+1];
            nv.addEdge(n1,n2,undirected);
            if (iter<=1) debugline(nv.nodes[n1].x,nv.nodes[n1].y,nv.nodes[n2].x,nv.nodes[n2].y,0,0,0,true);
         }
      }
   }
   printf("finding shortest path through network for each original edge\n");
   if (iter>=1){ // this is just for showing 1 step show only veronoi lines, 2nd show splines
      nv.calcEdgeLengths();
      int m=state.nw.edges.size();
开发者ID:fugufisch,项目名称:biographer,代码行数:67,代码来源:edgerouting.cpp

示例3: main

int main (int argc, char** argv) {
    //srand(time(NULL));

    //manual config...
    //------------- output layer
    OutputNode output;
    output._name = "f";
    
    Sigmoid sigmoid;
    output._activationFunc = &sigmoid;

    SquaredError squaredError;
    output._criterion = &squaredError;

    //------------- interal layer 1
    InternalNode internal_1, internal_2;
    internal_1._name = "i1";
    internal_2._name = "i2";

    Sigmoid sigmoid_i1, sigmoid_i2;
    internal_1._activationFunc = &sigmoid_i1;
    internal_2._activationFunc = &sigmoid_i2;
   
    //------------- input layer
    InputNode input_1, input_2, input_3;
    input_1._name = "a";
    input_2._name = "b";
    input_3._name = "c";

    Constant input_1_value, input_2_value, input_3_value;
    input_1._activationFunc = &input_1_value;
    input_2._activationFunc = &input_2_value;
    input_3._activationFunc = &input_3_value;

    //------------- make connections
    output.addInput(&internal_1);
    output.addInput(&internal_2);

    internal_1.addInput(&input_1);
    internal_1.addInput(&input_2);
    internal_1.addInput(&input_3);

    internal_2.addInput(&input_1);
    internal_2.addInput(&input_2);
    internal_2.addInput(&input_3);

    Network network;
    network.addNode(&output);
    network.addNode(&input_1);
    network.addNode(&input_2);
    network.addNode(&input_3);
    network.addNode(&internal_1);
    network.addNode(&internal_2);

    //--- training    

    float a[NUM_TRAINING_SAMPLE] = {0.5, 0.3, 1, 0.25, 0.9, 0.5, 0.41, 0.6, 0.3, 0.7};
    float b[NUM_TRAINING_SAMPLE] = {0.3, 0.5, 0.2, 0.1, 0.8, 0.5, 0.4, 0.61, 0.31, 0.6};
    float targetValue[NUM_TRAINING_SAMPLE] = {1, 0, 1, 1, 1, 0, 1, 0, 0, 1};

    ForwardPass forwardPass;
    BackwardPropagation backPropagation;
    UpdateWeights updateWeights;
    updateWeights._learningRate = 0.75;

    for (size_t epoch=0; epoch<1000; ++epoch) {
        for (size_t i=0; i<NUM_TRAINING_SAMPLE; ++i) {
            input_1_value._value = a[i];
            input_2_value._value = b[i];
            input_3_value._value = -0.5;
            output._criterion->_targetValue = targetValue[i];

            forwardPass(&network);

            backPropagation(&network);

            updateWeights(&network);
        }
    }

    //--- testing
    
    float test_a[NUM_TESTING_SAMPLE] = {0.5, 0.3, 1, 0.2, 0.9, 0.5, 0.51, 0.61, 0.2, 0.4};
    float test_b[NUM_TESTING_SAMPLE] = {0.3, 0.5, 0.2, 1, 0.8, 0.5, 0.5, 0.60, 0.1, 0.5};
    float test_targetValue[NUM_TESTING_SAMPLE] = {1, 0, 1, 0, 1, 0, 1, 1, 1, 0};

    int numCorrect = 0;

    for (size_t i=0; i<NUM_TESTING_SAMPLE; ++i) {
        input_1_value._value = test_a[i];
        input_2_value._value = test_b[i];
        input_3_value._value = -0.5;
        output._criterion->_targetValue = test_targetValue[i];
        forwardPass(&network);        

        if (    output.getValue() > 0.5
            &&  static_cast<int>(test_targetValue[i]) == 1) {
            ++numCorrect;
        }
        else if (    output.getValue() <= 0.5
//.........这里部分代码省略.........
开发者ID:tklam,项目名称:KissNN,代码行数:101,代码来源:main.cpp

示例4: main

int main(){

	cout << "Demonstrating Omurtag et al. (2000)" << endl;
	Number    n_bins = 500;
	Potential V_min  = 0.0;

	NeuronParameter
		par_neuron
		(
			1.0,
			0.0,
			0.0,
			0.0,
			50e-3
		);

	OdeParameter
		par_ode
		(
			n_bins,
			V_min,
			par_neuron,
			InitialDensityParameter(0.0,0.0)
		);

	double min_bin = 0.01;
	LifNeuralDynamics dyn(par_ode,min_bin);
	LeakingOdeSystem sys(dyn);
	GeomParameter par_geom(sys);
	GeomDelayAlg alg(par_geom);

	Rate rate_ext = 800.0;
	RateAlgorithm<MPILib::DelayedConnection> alg_ext(rate_ext);

	Network network;

	NodeId id_rate = network.addNode(alg_ext,EXCITATORY_DIRECT);
	NodeId id_alg  = network.addNode(alg,    EXCITATORY_DIRECT);

	MPILib::DelayedConnection con(1,0.03,0.0);
	network.makeFirstInputOfSecond(id_rate,id_alg,con);

	MPILib::report::handler::RootReportHandler handler("singlepoptest", true, true);
	handler.addNodeToCanvas(id_alg);

	const SimulationRunParameter
		par_run
		(
			handler,
			10000000,
			0.0,
			0.5,
			1e-3,
			1e-4,
			"singlepoptest.log"
		);

	network.configureSimulation(par_run);
	network.evolve();

	return 0;
}
开发者ID:MartinPerez,项目名称:miind,代码行数:62,代码来源:LifOneCanvas.cpp

示例5: main

int main(){
  
  Rate rate_ext = 0;

  RateFunctor<double> input(Inp);
  RateFunctor<double> openlock(Opl);

  RateAlgorithm<double> alg_ext(rate_ext);

	WilsonCowanParameter par_wc;
	par_wc._f_bias        = 0;
	par_wc._f_noise       = 1.0;
	par_wc._rate_maximum  = 50;
	par_wc._time_membrane = 50e-3;
  

	WilsonCowanAlgorithm alg(par_wc);

	Network network;

	NodeId id_input = network.addNode(input, EXCITATORY_DIRECT);
	NodeId id_gate = network.addNode(alg, EXCITATORY_DIRECT);
	NodeId id_output = network.addNode(alg, EXCITATORY_DIRECT);
	NodeId id_lock = network.addNode(alg, INHIBITORY_DIRECT);
	NodeId id_openlock = network.addNode(openlock ,INHIBITORY_DIRECT);

	double weight = 1.0;

	network.makeFirstInputOfSecond(id_input, id_gate, weight);
	network.makeFirstInputOfSecond(id_input, id_lock, weight);
	network.makeFirstInputOfSecond(id_gate, id_output, weight);
	network.makeFirstInputOfSecond(id_lock, id_gate, -1*weight);
	network.makeFirstInputOfSecond(id_openlock, id_lock, -2*weight);

	MPILib::CanvasParameter par_canvas;
	par_canvas._state_min     = -0.020;
	par_canvas._state_max     = 0.020;
	par_canvas._t_min         = 0.0;
	par_canvas._t_max         = 2.0;
	par_canvas._f_min         = 0.0;
	par_canvas._f_max         = 50.0;
	par_canvas._dense_min     = 0.0;
	par_canvas._dense_max     = 200.0;



	MPILib::report::handler::RootReportHandler handler("singlepoptest", true, true, par_canvas );

	handler.addNodeToCanvas(id_input);
	handler.addNodeToCanvas(id_gate);
	handler.addNodeToCanvas(id_output);
	handler.addNodeToCanvas(id_lock);
	handler.addNodeToCanvas(id_openlock);

	const SimulationRunParameter
		par_run
		(
		  handler,
		  10000000,
		  0.0,
		  2.0,
	          1e-3,
		  1e-3,
		   "wilsom.log"
		);

	network.configureSimulation(par_run);
	network.evolve();

	return 0;
}
开发者ID:MartinPerez,项目名称:miind,代码行数:71,代码来源:population-example.cpp

示例6: main

int main(){

	cout << "Demonstrating Quadratic-Integrate-and-Fire under jump response" << endl;
	Number    n_bins = 1000;
	Potential V_min  = -10.0;

	NeuronParameter
		par_neuron
		(
			10.0,
			-10.0,
			-10.0,
			0.0,
			10e-3
		);

	OdeParameter
		par_ode
		(
			n_bins,
			V_min,
			par_neuron,
			InitialDensityParameter(0.0,0.0)
		);


	GeomLib::QifParameter
	  par_qif
	  (
	    0.5, // 
	    0.5  // default gamma sys
	  );

	DiffusionParameter par_diffusion(0.03,0.03);
	CurrentCompensationParameter par_current(0.0,0.0);
	SpikingQifNeuralDynamics dyn(par_ode,par_qif);
	QifOdeSystem sys(dyn);
	GeomDelayAlg alg_qif(GeomParameter(sys,  par_diffusion, par_current));
      


	// Reproduce mu = 0.6, sigma = 0.7       
	Rate rate_ext = 6000;
	Efficacy h    = -8e-3;

	RateAlgorithm<MPILib::DelayedConnection> alg_ext(rate_ext);

	Network network;

	NodeId id_rate = network.addNode(alg_ext, MPILib::INHIBITORY_GAUSSIAN);
	NodeId id_alg  = network.addNode(alg_qif, MPILib::EXCITATORY_GAUSSIAN);

	MPILib::DelayedConnection con(1,h,0.0);
	network.makeFirstInputOfSecond(id_rate,id_alg,con);


	MPILib::CanvasParameter par_canvas;
	par_canvas._state_min     = -10.0;
	par_canvas._state_max     =  10.0;
	par_canvas._t_min         = 0.0;
	par_canvas._t_max         = 0.5;
	par_canvas._f_min         = 0.0;
	par_canvas._f_max         = 10.0;
	par_canvas._dense_min     = 0.0;
	par_canvas._dense_max     = 5.0;


	MPILib::report::handler::RootReportHandler handler("twopopcanvas.root", true, true, par_canvas);
	handler.addNodeToCanvas(id_alg);

      

	const SimulationRunParameter
		par_run
		(
			handler,
			10000000,
			0.0,
			0.5,
			2e-3,
			1e-4,
			"singlepoptest.log"
		);

	network.configureSimulation(par_run);
	network.evolve();

	return 0;
}
开发者ID:SamDBrown,项目名称:miind,代码行数:89,代码来源:QifJumpPoisson.cpp


注:本文中的Network::addNode方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。