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


C++ Neuron类代码示例

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


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

示例1: transferNeuronActivationToOutput

	void DynamicsPlotterUtil::transferNeuronActivationToOutput(const QList<Neuron*> neurons) {

		//Set the output of every neuron to the transferred activation
		for(QListIterator<Neuron*> i(neurons); i.hasNext();) {
			Neuron *neuron = i.next();
			neuron->getOutputActivationValue().set(
				neuron->getTransferFunction()->transferActivation(
					neuron->getActivationValue().get(), neuron));
		}
	}
开发者ID:nerd-toolkit,项目名称:nerd,代码行数:10,代码来源:DynamicsPlotterUtil.cpp

示例2: Neuron

void Neuron::makeSynapses(void){
   Neuron* n = new Neuron(4345);
   cout << "index of postSyn is: " << n->getIndex() << endl;
   
   Synapse syn1(1, n);
   axons.push_back(syn1);
   Synapse syn2(2, n);
   axons.push_back(syn2);
   Synapse syn3(3, n);
   axons.push_back(syn3);
   return;
}
开发者ID:julianborrey,项目名称:Angelica,代码行数:12,代码来源:netCoreNeuronTestingDecay.cpp

示例3: neuron_output

    Value NeuralNet::neuron_output(const Neuron& n, const ValueListPtr v) const
    {
        Neuron::const_iterator it;
        ValueList::const_iterator vit;
        Value retval = 0.0f;

        for(it = n.begin(), vit = v->begin(); it != n.end() && vit != v->end(); it++, vit++)
        {
            retval += (*it) * (*vit);
        }
        // std::cout << retval << std::endl;
        return retval;
    }
开发者ID:anttisalonen,项目名称:freekick,代码行数:13,代码来源:NeuralNet.cpp

示例4: sigmoid

// Back propagate the errors to update the weights.
void NeuralNet::backPropagate(vector<double>* outputs, int teacher) {
  Layer *outputLayer = (*layers)[numHiddenLayers + 1];
  for (int i = 0; i < outputs->size(); i++) {
    Neuron *n = outputLayer->getNeuron(i);
    double adjusted = -n->getValue();
    if (i == teacher) {
      adjusted += 1;
    }
    n->setDelta(sigmoidPrime(n->getActivation()) * adjusted);
  }

  // Propagate deltas backward from output layer to input layer.
  for (int l = numHiddenLayers; l >= 0; l--) {
    Layer *curr = (*layers)[l], *downstream = (*layers)[l+1];

    for (int i = 0; i < curr->neuronCount(); i++) {
      double sum = 0;
      Neuron *n = curr->getNeuron(i);
      for (int j = 0; j < downstream->neuronCount(); j++) {
        sum += downstream->getNeuron(j)->getWeight(i)
            * downstream->getNeuron(j)->getDelta();
      }
      n->setDelta(sigmoidPrime(n->getActivation()) * sum);
      for (int j = 0; j < downstream->neuronCount(); j++) {
        downstream->getNeuron(j)->updateWeight(i,
            learningRate * sigmoid(n->getActivation())
            * downstream->getNeuron(j)->getDelta());
      }
    }
  }
}
开发者ID:Amos-zq,项目名称:neural-ocr,代码行数:32,代码来源:NeuralNet.cpp

示例5: while

/**
 * Returns the strength of the owner synapse.
 * 
 * @param owner the owner of this SynapseFunction.
 * @return the strength of the owner.
 */
double ExampleSynapseFunction::calculate(Synapse *owner) {
	if(owner == 0) {
		return 0.0;
	}
	
	//Search for target neuron (if existing)
	Neuron *target = dynamic_cast<Neuron*>(owner->getTarget());
	if(target == 0) {
		return owner->getStrengthValue().get();
	}
	
	//Update history
	mHistory.enqueue(target->getLastActivation());
	while(!mHistory.empty() && mHistory.size() > mHistorySize->get()) {
		mHistory.dequeue();
	}
	
	
	//Calcualte average
	double activationSum = 0.0;
	double average = 0.0;
	for(QListIterator<double> i(mHistory); i.hasNext();) {
		activationSum += i.next();
	}
	if(mHistory.size() > 0) {
		average = (activationSum / ((double) mHistory.size()));
	}
	else {
		average = 0.0;
	}
	mCurrentAverage->set(average);
	
	//Adapt synapse if required.
	Neuron *source = owner->getSource();
	if(source != 0) {
		double output = source->getLastOutputActivation();
		if(output != 0) {
			double change = 0.0;
			if(average > mDesiredActivationRange->getMax()) {
				change = (average - mDesiredActivationRange->getMax()) * output * -1.0;
			}
			else if(average < mDesiredActivationRange->getMin()) {
				change = (mDesiredActivationRange->getMin() - average) * output;
			}
			owner->getStrengthValue().set(owner->getStrengthValue().get() + (change * mChangeRate->get()));
		}
	}
	
	return owner->getStrengthValue().get();
}
开发者ID:nerd-toolkit,项目名称:nerd,代码行数:56,代码来源:ExampleSynapseFunction.cpp

示例6: testCopy

void testCopy()
{
#ifdef USE_MATRIX
  RNN_MATRIX(rnnOrig);
  RNN_VECTOR(rnnCopy);
#endif
#ifdef USE_VECTOR
  RNN_MATRIX(rnnOrig);
  RNN_VECTOR(rnnCopy);
#endif
  for(int i = 0; i < 1000; i++)
  {
    Neuron *n = rnnOrig->createNeuron();
    if(drand48() < 0.5)
    {
      n->setTransferfunction(transferfunction_tanh);
    }
    else
    {
      n->setTransferfunction(transferfunction_id);
    }
  }
  for(int j = 0; j < 999; j++) // connect every neuron to neuron 0
  {
    __REAL w = ((drand48() < 0.5)?-1:1) * (10 * drand48() + 0.1);
    rnnOrig->createSynapse(rnnOrig->getNeuron(j), rnnOrig->getNeuron(j+1), w);
  }
  for(int j = 0; j < 10000; j++) // random synapses
  {
    __REAL w = ((drand48() < 0.5)?-1:1) * (10 * drand48() + 0.1);
    int source = (int)(drand48() * 100 + 0.5);
    int destination = (int)(drand48() * 100 + 0.5);
    // TODO: check why this is required for the test not to fail
    while(source != destination - 1)
    {
      source = (int)(drand48() * 100 + 0.5);
      destination = (int)(drand48() * 100 + 0.5);
    }
    rnnOrig->createSynapse(rnnOrig->getNeuron(source),
        rnnOrig->getNeuron(destination),
        w);
  }
  startTiming();
  rnnCopy->copy(rnnOrig);
  unsigned long time = stopTiming();
  cout << "RecurrentNeuralNetwork copy:\t\t\t\t\t";
  printTime(time);
  delete rnnOrig;
  delete rnnCopy;
}
开发者ID:kzahedi,项目名称:librnn,代码行数:50,代码来源:librnnRuntimeTestMain.cpp

示例7: calcMeanMembranePotential

void RungeKutta::calcMeanMembranePotential(Neuron& n_old, Neuron& n_new, double time, double timestep) {
    if (n_old.getType() == BRAINSTEM) return;
    
    double m = n_old.getM();
    double tau = n_old.getWeights()[0];
    double sigma = addWeightedNeighbors(n_old);
    double k1 = calcDerivative(time, m, sigma, tau);
    double k2 = calcDerivative(time + .5*timestep, m + (timestep/2)*k1, sigma, tau);
    double k3 = calcDerivative(time + .5*timestep, m + (timestep/2)*k2, sigma, tau);
    double k4 = calcDerivative(time + timestep, m + timestep*k3, sigma, tau);
    
    double newVal = m + (1.0/6)*timestep*(k1 + 2*k2 + 2*k3 + k4);
    n_new.setM(newVal);
    
}
开发者ID:jshin92,项目名称:Central-Pattern-Generator,代码行数:15,代码来源:RungeKutta.cpp

示例8: main

int main() {
  ScopedPass pass("Evolver [single-bit adder]");
  
  Network network;
  Evolver evolver(network);
  Neuron * input0 = new OrNeuron();
  Neuron * input1 = new OrNeuron();
  Neuron * output = new OrNeuron();
  network.AddNeuron(*input0);
  network.AddNeuron(*input1);
  network.AddNeuron(*output);
  
  while (true) {
    bool flag0 = RandomBool();
    bool flag1 = RandomBool();
    if (flag0) input0->Fire();
    else input0->Inhibit();
    if (flag1) input1->Fire();
    else input1->Inhibit();
    bool gotResponse = false;
    bool expectingResponse = (flag0 && !flag1) || (flag1 && !flag0);
    // Give it ten cycles to respond with the answer
    for (int i = 0; i < 10; ++i) {
      network.Cycle();
      if (output->IsFiring()) {
        gotResponse = true;
      }
      evolver.Prune();
      evolver.Grow();
    }
    if (gotResponse != expectingResponse) {
      std::cout << "wrong!" << std::endl;
      network.UpdateLivesWithPain(0.5);
    } else {
      std::cout << "right!" << std::endl;
    }
    // Give the network some time to flush out its activity
    for (int i = 0; i < 5; ++i) {
      network.Cycle();
      evolver.Prune();
      evolver.Grow();
    }
  }
  
  return 0;
}
开发者ID:unixpickle,项目名称:AI-attempts,代码行数:46,代码来源:test-evolutionary-adder.cpp

示例9: AreNeuronsConnected

bool NeuralNetwork::AreNeuronsConnected(const Neuron& lhs,const Neuron & rhs) const {
	for (auto& connection : rhs.GetConnections()) {
		if (!connection.outGoing && &lhs == connection.neuron) {
			return true;
		}
	}
	return false;
}
开发者ID:STJEREM,项目名称:TicTacToe,代码行数:8,代码来源:neural_network.cpp

示例10: train_one_sample

float RecSOM::train_one_sample(vector<float> sample, int nf) {
	Neuron*		w     = NULL;
  float     qerr  = 0.0;

	input_layer = &sample[0];

	w = activate_find_winner(output_layer);
	qerr = w->recursive_distance(alpha, beta, input_layer, context_layer);

	for(int i = 0; i < map_dim_x*map_dim_y; i++) {
		map_layer[i]->update_weights(gama, w, input_layer, context_layer, sigma, nf);
	}
  
  update_context(output_layer);

	return qerr;
}
开发者ID:Iskandor,项目名称:ymir-rte,代码行数:17,代码来源:RecSOM.cpp

示例11: getBMU

void SelfOrganizingMaps::evaluateIndependentVector(vector<double> inputVector){
	Neuron *bmu = getBMU(inputVector);
	_matrix->getNeuron(bmu->getX(), bmu->getY())->setNeuronColor(0,0,0);
/*
	cout << "A _bmuTestCases size = " << _bmuTestCases.size() << endl;
	_bmuTestCases.insert ( pair<Neuron *,Neuron *>(getBMU(inputVector),getBMU(inputVector)));
	cout << "B _bmuTestCases size = " << _bmuTestCases.size() << endl;
	cout << "Input Vector:" << endl;
	cout << inputVector[0] << " " << inputVector[1] << " " << inputVector[2] << endl;
	cout << "BMU:" << endl;
	bmu->info();
	
	double distanceToBMU = bmu->distanceToInputVector(inputVector);
	cout << "BMU distance to input vector: " << distanceToBMU << endl;
	int bmuX = bmu->getX();
	int bmuY = bmu->getY();

	if(((bmuX + 1 < _size) && (bmuX - 1 >= 0)) && ((bmuY + 1 < _size) && (bmuY - 1 >= 0))){
		Neuron *upLeft = _matrix->getNeuron(bmuX - 1, bmuY - 1);
		Neuron *up = _matrix->getNeuron(bmuX, bmuY - 1);
		Neuron *upRight = _matrix->getNeuron(bmuX + 1, bmuY - 1);
		Neuron *left = _matrix->getNeuron(bmuX - 1, bmuY);
		Neuron *right = _matrix->getNeuron(bmuX + 1, bmuY);
		Neuron *downLeft = _matrix->getNeuron(bmuX - 1, bmuY + 1);
		Neuron *down = _matrix->getNeuron(bmuX, bmuY + 1);
		Neuron *downRight = _matrix->getNeuron(bmuX + 1, bmuY + 1);

		double distUpLeft =  upLeft->distanceToInputVector(inputVector);
		double distUp = up->distanceToInputVector(inputVector);
		double distUpRight = upRight->distanceToInputVector(inputVector);
		double distLeft = left->distanceToInputVector(inputVector);
		double distRight = right->distanceToInputVector(inputVector);
		double distDownLeft = downLeft->distanceToInputVector(inputVector);
		double distDown = down->distanceToInputVector(inputVector);
		double distDownRight = downRight->distanceToInputVector(inputVector);

		cout << "Distances to side Neurons of the BMU" << endl;
		cout << distUpLeft << " " << distUp << " " << distUpRight << endl;
		cout << distLeft << "--" << distanceToBMU << "-- " << distRight << endl;
		cout << distDownLeft << " " << distDown << " " << distDownRight << endl; 
	}else{
		cout << "The BMU is in the borders" << endl;
	}
*/
}
开发者ID:VictorCruzIsc,项目名称:MachineLearningAlgorithms,代码行数:45,代码来源:SelfOrganizingMaps.cpp

示例12: main

int main(int argc, char **argv) {

  struct arguments args;
  /* Default values. */
  // arguments.flag = true;
  // arguments.value = 0;

  argp_parse (&argp, argc, argv, 0, 0, &args);

  Neuron* neuronita = new Neuron(args.args[0]);

  for(int i = 0; i < neuronita->axon.size(); i++)
    flattenNeuronSegment(neuronita->axon[i]);
  for(int i = 0; i < neuronita->dendrites.size(); i++)
    flattenNeuronSegment(neuronita->dendrites[i]);

  neuronita->save(args.args[1]);
}
开发者ID:contaconta,项目名称:neurons,代码行数:18,代码来源:neuronFlat.cpp

示例13: collectInputs

void Neuron :: collectInputs() {
	double collectedOut=0;
	vector<Edge*> input = getInputEdges();
	for(int i=0; i<input.size(); i++) {
        Neuron* start = input[i]->getStart();
		if(start == NULL){
            double w = input[i]->getWeight();
            collectedOut+=-1*w;
        }
        else{
            double w = input[i]->getWeight();
            double out = start->getOutput();
            collectedOut+=w*out;
        }
	}

	output = collectedOut;
    updateOutput();
}
开发者ID:nileshkulkarni,项目名称:AI_lab,代码行数:19,代码来源:neuron.cpp

示例14: while

vector<double> NeuralNetwork::get_output(vector<double> input) {
    queue<Neuron*> open_queue;
    set<Neuron*> closed_set;
    
    for (int i = 0; i < input_neurons_.size(); i++) {
        input_neurons_[i].output_ = input[i];
        
        for (int j = 0; j < input_neurons_[i].outputs_.size(); j++) {
            open_queue.push(input_neurons_[i].outputs_[j]);
            closed_set.insert(input_neurons_[i].outputs_[j]);
        }
    }
    
    for (int i = 0; i < output_neurons_.size(); i++) {
        closed_set.insert(&output_neurons_[i]);
    
        output_neurons_[i].output_ = 0.0;
    }
    
    while (!open_queue.empty()) {
        Neuron* neuron = open_queue.front();
        
        open_queue.pop();
        
        neuron->get_output();
        
        for (int i = 0; i < neuron->outputs_.size(); i++) {
            if (closed_set.find(neuron->outputs_[i]) == closed_set.end()) {
                open_queue.push(neuron->outputs_[i]);
                closed_set.insert(neuron->outputs_[i]);
            }
        }
    }
    
    vector<double> output(output_neurons_.size());
    for (int i = 0; i < output.size(); i++) {
        output_neurons_[i].get_output();
    
        output[i] = output_neurons_[i].output_;
    }
    
    return output;
}
开发者ID:imclab,项目名称:brains,代码行数:43,代码来源:NeuralNetwork.cpp

示例15: main

int main(int argc, char *argv[]) {

    if(argc < 1) {
        cout << "Usage: ./lab6 <epoch cnt> <inFile>" << endl;
        return 0;
    }
    //Read iris data into 2D vector
    vector <vector <string> > dataSet;
    ifstream inFile;
    inFile.open(argv[1]);
    while(inFile) {
        string temp;
        if(!getline( inFile, temp)) break; //error
        istringstream ss( temp );
        vector<string> tmp;
        while( ss ) {
            string s;
            if(!getline( ss, s, ',' )) break; //error
            tmp.push_back(s);
        }
        dataSet.push_back(tmp);
    }
    inFile.close();
    //Convert 2D string vector into doubles, split off the Yd
    vector< vector<double> > input(dataSet.size());
    vector<double> Yd;
    for( int i = 0; i < dataSet.size(); i++) {
        Yd.push_back(stod(dataSet[i][dataSet[i].size()-1]));
        for( int j = 0; j < dataSet[i].size()-1; j++) {
            input[i].push_back(stod(dataSet[i][j]));
        }
    }

    //Create neuron, test initial weights, train, test again
    Neuron* myNeuron = new Neuron();
    myNeuron->initializeWeights(4);
    test(myNeuron, input, Yd);
    train(myNeuron, input, Yd);
    test(myNeuron, input, Yd);

    return 0;
}
开发者ID:PoloMelendez,项目名称:CSUB,代码行数:42,代码来源:lab6.cpp


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