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


C++ NeuralNetwork::getSynapses方法代码示例

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


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

示例1: calculate

	/**
	 * Returns the strength of the owner synapse.
	 * 
	 * @param owner the owner of this SynapseFunction.
	 * @return the strength of the owner.
	 */
	double CloneSimpleSynapseFunction::calculate(Synapse *owner) {
		SimpleSynapseFunction::calculate(owner);
		if(owner == 0) {
			return 0.0;
		}
		if(mTargetId->get() == 0) {
			//per default set the id to the own synapse.
			mTargetId->set(owner->getId());
		}
		if(mLastKnownTargetId != mTargetId->get()) {
			mTargetSynapse = 0;
		}
		mLastKnownTargetId = mTargetId->get();
		if(mTargetId->get() == owner->getId()) {
			mTargetSynapse = owner;
		}
		else {
			Neuron *neuron = owner->getSource();
			QList<Synapse*> synapses;
			if(neuron != 0) {
				NeuralNetwork *network = neuron->getOwnerNetwork();
				if(network != 0) {
					synapses = network->getSynapses();
				}
			}
			if(mTargetSynapse == 0) {
				mTargetSynapse = NeuralNetwork::selectSynapseById(mTargetId->get(), synapses);
			}
			if(mTargetSynapse != 0) {
				if(!synapses.contains(mTargetSynapse)) {
					mTargetSynapse = 0;
				}
			}
			if(mTargetSynapse != 0) {
				owner->getStrengthValue().set(mTargetSynapse->getStrengthValue().get());
			}
		}
		
		return SimpleSynapseFunction::calculate(owner);
	}
开发者ID:nerd-toolkit,项目名称:nerd,代码行数:46,代码来源:CloneSimpleSynapseFunction.cpp

示例2: testDuplicationAndEquals

// Chris
void TestNeuralNetwork::testDuplicationAndEquals() {
	TransferFunctionAdapter tfa("TFA", -0.5, 0.5);
	ActivationFunctionAdapter afa("AFA");
	SynapseFunctionAdapter sfa("SFA");

	NeuralNetwork *net = new NeuralNetwork(afa, tfa, sfa);

	ControlInterfaceAdapter controlInterface;
	net->setControlInterface(&controlInterface);

	QVERIFY(net->getControlInterface() == &controlInterface);

	Neuron *neuron1 = new Neuron("Neuron1", tfa, afa, 2001);
	Neuron *neuron2 = new Neuron("Neuron1", tfa, afa, 2002);
	Neuron *neuron3 = new Neuron("Neuron1", tfa, afa, 2003);

	neuron1->setProperty(Neuron::NEURON_TYPE_INPUT);
	neuron3->setProperty(Neuron::NEURON_TYPE_OUTPUT);

	Synapse *synapse1 = Synapse::createSynapse(neuron1, neuron2, 0.5, sfa, 3001);
	Synapse *synapse2 = Synapse::createSynapse(neuron2, neuron3, 1.5, sfa, 3002);
	Synapse *synapse3 = Synapse::createSynapse(neuron3, synapse1, 0.1, sfa, 3003);

	net->addNeuron(neuron1);
	net->addNeuron(neuron2);
	net->addNeuron(neuron3);

	QCOMPARE(net->getNeurons().size(), 3);
	QVERIFY(net->getNeurons().contains(neuron1));
	QVERIFY(net->getNeurons().contains(neuron2));
	QVERIFY(net->getNeurons().contains(neuron3));

	QCOMPARE(net->getSynapses().size(), 3);
	QVERIFY(net->getSynapses().contains(synapse1));
	QVERIFY(net->getSynapses().contains(synapse2));
	QVERIFY(net->getSynapses().contains(synapse3));
	
	
	NeuralNetwork *copy = net->createCopy();

	//control interface is NOT copied.
	QVERIFY(copy->getControlInterface() == 0);

	QCOMPARE(copy->getNeurons().size(), 3);
	QVERIFY(!copy->getNeurons().contains(neuron1));
	QVERIFY(!copy->getNeurons().contains(neuron2));
	QVERIFY(!copy->getNeurons().contains(neuron3));

	QCOMPARE(copy->getSynapses().size(), 3);
	QVERIFY(!copy->getSynapses().contains(synapse1));
	QVERIFY(!copy->getSynapses().contains(synapse2));
	QVERIFY(!copy->getSynapses().contains(synapse3));

	Neuron *cNeuron1 = NeuralNetwork::selectNeuronById(neuron1->getId(), copy->getNeurons());
	Neuron *cNeuron2 = NeuralNetwork::selectNeuronById(neuron2->getId(), copy->getNeurons());
	Neuron *cNeuron3 = NeuralNetwork::selectNeuronById(neuron3->getId(), copy->getNeurons());

	Synapse *cSynapse1 = NeuralNetwork::selectSynapseById(synapse1->getId(), copy->getSynapses());
	Synapse *cSynapse2 = NeuralNetwork::selectSynapseById(synapse2->getId(), copy->getSynapses());
	Synapse *cSynapse3 = NeuralNetwork::selectSynapseById(synapse3->getId(), copy->getSynapses());
	
	QVERIFY(cNeuron1 != 0);
	QVERIFY(cNeuron2 != 0);
	QVERIFY(cNeuron3 != 0);

	QVERIFY(cNeuron1->equals(neuron1));
	QVERIFY(cNeuron2->equals(neuron2));
	QVERIFY(cNeuron3->equals(neuron3));

	QCOMPARE(cNeuron1->getId(), (qulonglong) 2001);
	QCOMPARE(cNeuron2->getId(), (qulonglong) 2002);
	QCOMPARE(cNeuron3->getId(), (qulonglong) 2003);

	QVERIFY(net->getInputNeurons().size() == 1);
	QVERIFY(copy->getInputNeurons().size() == 1);
	QVERIFY(net->getInputNeurons().at(0) == neuron1);
	QVERIFY(copy->getInputNeurons().at(0) == cNeuron1);
	QVERIFY(net->getOutputNeurons().size() == 1);
	QVERIFY(copy->getOutputNeurons().size() == 1);
	QVERIFY(net->getOutputNeurons().at(0) == neuron3);
	QVERIFY(copy->getOutputNeurons().at(0) == cNeuron3);

	QVERIFY(cSynapse1 != 0);
	QVERIFY(cSynapse2 != 0);
	QVERIFY(cSynapse3 != 0);

	QVERIFY(cSynapse1->equals(synapse1));
	QVERIFY(cSynapse2->equals(synapse2));
	QVERIFY(cSynapse3->equals(synapse3));

	QCOMPARE(cSynapse1->getId(), (qulonglong) 3001);
	QCOMPARE(cSynapse2->getId(), (qulonglong) 3002);
	QCOMPARE(cSynapse3->getId(), (qulonglong) 3003);

	QVERIFY(cSynapse1->getSource() == cNeuron1);
	QVERIFY(cSynapse2->getSource() == cNeuron2);
	QVERIFY(cSynapse3->getSource() == cNeuron3);
	QVERIFY(cSynapse1->getTarget() == cNeuron2);
	QVERIFY(cSynapse2->getTarget() == cNeuron3);
//.........这里部分代码省略.........
开发者ID:nerd-toolkit,项目名称:nerd,代码行数:101,代码来源:TestNeuralNetwork.cpp

示例3: calculateDegreesOfFreedom

void NetworkDegreeOfFreedomCalculator::calculateDegreesOfFreedom() {

	QList<NeuralNetwork*> networks = Neuro::getNeuralNetworkManager()->getNeuralNetworks();

	if(networks.empty()) {
		mDOFAll->set(0);
		mDOFMain->set(0);
		mDOFBiasTerms->set(0);
		mDOFSynapseWeights->set(0);
		mDOFTransferFunctions->set(0);
		mDOFActivationFunctions->set(0);
		mDOFSynapseFunctions->set(0);
		return;
	}

	NeuralNetwork *network = networks.at(0);
	if(network == 0) {
		Core::log("NetworkDegreeOfFreedomCalculator: Could not find a network...");
		return;
	}

	int dofBias = 0;
	int dofWeights = 0;
	int dofTF = 0;
	int dofAF = 0;
	int dofSF = 0;
	
	
	QList<Neuron*> neurons = network->getNeurons();
	
	for(QListIterator<Neuron*> i(neurons); i.hasNext();) {
		Neuron *neuron = i.next();
		
		bool bias = true;
		bool tf = true;
		bool af = true;
		
		if(neuron->hasProperty(NeuralNetworkConstants::TAG_ELEMENT_PROTECTED)) {
			bias = false;
			tf = false;
			af = false;
		}
		else {
			QString reducedDOFs = neuron->getProperty(
					NeuralNetworkConstants::TAG_ELEMENT_REDUCED_DEGREES_OF_FREEDOM);
			if(reducedDOFs != "") {
				if(reducedDOFs.contains("B")) {
					bias = false;
				}
				if(reducedDOFs.contains("A")) {
					af = false;
				}
				if(reducedDOFs.contains("T")) {
					tf = false;
				}
			}
			//Count bias only as degree of freedom, if there is one set.
			if(neuron->getBiasValue().get() == 0.0
				|| neuron->hasProperty(NeuralNetworkConstants::TAG_NEURON_PROTECT_BIAS)) 
			{
				bias = false;
			}
		}
		if(bias) { ++dofBias; }
		if(tf) { ++dofTF; }
		if(af) { ++dofAF; }
	}
	
	QList<Synapse*> synapses = network->getSynapses();	
	for(QListIterator<Synapse*> i(synapses); i.hasNext();) {
		Synapse *synapse = i.next();
		
		bool weight = true;
		bool sf = true;
		
		if(synapse->hasProperty(NeuralNetworkConstants::TAG_ELEMENT_PROTECTED)) {
			weight = false;
			sf = false;
		}
		else {
			QString reducedDOFs = synapse->getProperty(
					NeuralNetworkConstants::TAG_ELEMENT_REDUCED_DEGREES_OF_FREEDOM);
			if(reducedDOFs != "") {
				if(reducedDOFs.contains("W")) {
					weight = false;
				}
				if(reducedDOFs.contains("S")) {
					sf = false;
				}
			}
			if(synapse->hasProperty(NeuralNetworkConstants::TAG_SYNAPSE_PROTECT_STRENGTH)) {
				weight = false;
			}
		}
		if(weight) { ++dofWeights; }
		if(sf) { ++dofSF; }
	}

	
	mDOFAll->set(dofBias + dofWeights + dofTF + dofAF + dofSF);
//.........这里部分代码省略.........
开发者ID:nerd-toolkit,项目名称:nerd,代码行数:101,代码来源:NetworkDegreeOfFreedomCalculator.cpp


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