本文整理汇总了C++中NeuralNetwork::addNeuron方法的典型用法代码示例。如果您正苦于以下问题:C++ NeuralNetwork::addNeuron方法的具体用法?C++ NeuralNetwork::addNeuron怎么用?C++ NeuralNetwork::addNeuron使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类NeuralNetwork
的用法示例。
在下文中一共展示了NeuralNetwork::addNeuron方法的4个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: testFreeElements
void TestNeuralNetwork::testFreeElements() {
bool destroyedNeuron1 = false;
bool destroyedNeuron2 = false;
NeuronAdapter *neuron1 = new NeuronAdapter("Neuron1", TransferFunctionAdapter("TF1", 0.0, 1.0),
ActivationFunctionAdapter("AF1"), &destroyedNeuron1);
NeuronAdapter *neuron2 = new NeuronAdapter("Neuron2", TransferFunctionAdapter("TF1", 0.0, 1.0),
ActivationFunctionAdapter("AF1"), &destroyedNeuron2);
NeuralNetwork *net = new NeuralNetwork();
InterfaceValue *inputValue = new InterfaceValue("/", "Test1");
InterfaceValue *outputValue = new InterfaceValue("/", "Test1");
ControlInterfaceAdapter *controller = new ControlInterfaceAdapter();
controller->mInputValues.append(inputValue);
controller->mOutputValues.append(outputValue);
//free elements(false)
QVERIFY(net->addNeuron(neuron1) == true);
QVERIFY(net->addNeuron(neuron2) == true);
net->setControlInterface(controller);
QCOMPARE(net->getNeurons().size(), 2);
QVERIFY(net->getNeurons().contains(neuron1));
QVERIFY(net->getNeurons().contains(neuron2));
net->freeElements(false);
QCOMPARE(net->getNeurons().size(), 0);
QVERIFY(destroyedNeuron1 == false);
QVERIFY(destroyedNeuron2 == false);
//free elements(true)
QVERIFY(net->addNeuron(neuron1) == true);
QVERIFY(net->addNeuron(neuron2) == true);
net->setControlInterface(controller);
QCOMPARE(net->getNeurons().size(), 2);
QVERIFY(net->getNeurons().contains(neuron1));
QVERIFY(net->getNeurons().contains(neuron2));
net->freeElements(true);
QCOMPARE(net->getNeurons().size(), 0);
QVERIFY(destroyedNeuron1 == true);
QVERIFY(destroyedNeuron2 == true);
}
示例2: main
int main()
{
NeuralNetwork nn;
InputNeuron *in1 = new InputNeuron(2);
InputNeuron *in2 = new InputNeuron(3);
OutputNeuron *out1 = new OutputNeuron(1);
nn.addNeuron(in1);
nn.addNeuron(in2);
nn.addOutputNeuron(out1);
out1->setExpectedOutput(1);
if(nn.connectNeurons(0, 2) && nn.connectNeurons(1, 2))
{
nn.optimize();
std::cout << out1->evaluate() << std::endl;
}
return 0;
}
示例3: 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);
//.........这里部分代码省略.........
示例4: connectNetworksToInterfaces
void NetworkAgentControlParser::connectNetworksToInterfaces() {
NeuralNetworkManager *nnm = Neuro::getNeuralNetworkManager();
bool addedNetwork = false;
QStringList params = mNetLoaderArgument->getParameters();
int numberOfEntries = mNetLoaderArgument->getNumberOfEntries();
for(int i = 0; i < numberOfEntries; ++i) {
QStringList paramSet;
if(params.size() > i) {
paramSet = params.at(i).split(" ");
}
if(paramSet.size() > 2) {
Core::log("NetworkAgentControlParser: Could not interpret command line argument. ");
continue;
}
QString agentName = "";
QString networkFile = "";
if(paramSet.size() > 0) {
if(paramSet.at(0).trimmed() == "c") {
networkFile = "c";
}
else {
agentName = paramSet.at(0);
}
}
if(paramSet.size() > 1) {
networkFile = paramSet.at(1);
}
if(networkFile.trimmed() == "c") {
networkFile = "";
//use most recent network from the editor for this agent.
QString filePrefix = Core::getInstance()->getConfigDirectoryPath() + "/properties";
QFile file(filePrefix + "/recentNetworks.txt");
if(file.open(QIODevice::ReadOnly | QIODevice::Text)) {
QTextStream input(&file);
if(!input.atEnd()) {
networkFile = input.readLine();
}
}
file.close();
}
PhysicsManager *pm = Physics::getPhysicsManager();
SimObjectGroup *agent = 0;
if(agentName == "" && !pm->getSimObjectGroups().empty()) {
agent = pm->getSimObjectGroups().at(0);
}
else {
agent = pm->getSimObjectGroup(agentName);
}
if(agent == 0) {
Core::log(QString("NetworkAgentControlParser: Could not find an agent with name [")
.append(agentName).append("]! [Skipping]"));
continue;
}
QString errorMessage;
QList<QString> messages;
NeuralNetwork *net = 0;
//check if there is already a network that can be reused.
QList<NeuralNetwork*> networks = nnm->getNeuralNetworks();
if(networks.size() > i) {
net = networks.at(i);
}
if(net == 0) {
if(networkFile == "") {
//create standard network with matching number of input/output neurons.
net = new ModularNeuralNetwork();
int numberOfInputs = agent->getOutputValues().size();
int numberOfOutputs = agent->getInputValues().size();
for(int i = 0; i < numberOfInputs; ++i) {
Neuron *neuron = new Neuron("Neuron" + QString::number(i),
*net->getDefaultTransferFunction(),
*net->getDefaultActivationFunction());
neuron->setProperty(Neuron::NEURON_TYPE_INPUT);
net->addNeuron(neuron);
}
for(int i = 0; i < numberOfOutputs; ++i) {
Neuron *neuron = new Neuron("Neuron" + QString::number(i),
*net->getDefaultTransferFunction(),
*net->getDefaultActivationFunction());
neuron->setProperty(Neuron::NEURON_TYPE_OUTPUT);
net->addNeuron(neuron);
}
}
else {
net = NeuralNetworkIO::createNetworkFromFile(
//.........这里部分代码省略.........