本文整理汇总了C#中Network.addOutput方法的典型用法代码示例。如果您正苦于以下问题:C# Network.addOutput方法的具体用法?C# Network.addOutput怎么用?C# Network.addOutput使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Network
的用法示例。
在下文中一共展示了Network.addOutput方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: breed
private static Network breed(int parentA, int parentB)
{
List<Edge> childEdges = new List<Edge> ();
int AIndex = 0;
int BIndex = 0;
//merge genomes
while (AIndex < networks[parentA].edges.Count && BIndex < networks[parentB].edges.Count) {
if (networks [parentA].edges [AIndex].innovation == networks [parentB].edges [BIndex].innovation) {
if (rand.Next (0, 2) == 0) {
Edge e = new Edge(networks[parentA].edges[AIndex].inNeuron,networks[parentA].edges[AIndex].outNeuron,networks[parentA].edges[AIndex].weight, networks[parentA].edges[AIndex].isEnabled,networks[parentA].edges[AIndex].innovation);
childEdges.Add (e);
} else {
Edge e = new Edge(networks[parentB].edges[BIndex].inNeuron,networks[parentB].edges[BIndex].outNeuron,networks[parentB].edges[BIndex].weight, networks[parentB].edges[BIndex].isEnabled,networks[parentB].edges[BIndex].innovation);
childEdges.Add (e);
}
AIndex++;
BIndex++;
} else if (networks [parentA].edges [AIndex].innovation > networks [parentB].edges [BIndex].innovation) {
BIndex++;
} else {
Edge e = new Edge(networks[parentA].edges[AIndex].inNeuron,networks[parentA].edges[AIndex].outNeuron,networks[parentA].edges[AIndex].weight, networks[parentA].edges[AIndex].isEnabled,networks[parentA].edges[AIndex].innovation);
childEdges.Add (e);
AIndex++;
}
}
//excess edges left over from dominant parent
if (BIndex == networks [parentB].edges.Count) {
for (int i=AIndex; i<networks[parentA].edges.Count; i++) {
Edge e = new Edge(networks[parentA].edges[i].inNeuron,networks[parentA].edges[i].outNeuron,networks[parentA].edges[i].weight, networks[parentA].edges[i].isEnabled,networks[parentA].edges[i].innovation);
childEdges.Add (e);
}
}
//perturb it
double rand01 = rand.NextDouble ();
if (rand01 < perturbChance) {
double perturbAmount = (rand.NextDouble () * perturbPercent * 2.0 - perturbPercent);
for (int i=0; i<childEdges.Count; i++) {
//perturb it! sore aru
if(rand.NextDouble() < 0.9){
childEdges [i].weight = childEdges [i].weight + perturbAmount;
}
else{
//give weight a new value;
childEdges [i].weight = randomEdgeWeight();
}
if (!childEdges [i].isEnabled) {
rand01 = rand.NextDouble ();
if (rand01 < enableMutationChance) {
childEdges [i].isEnabled = true;
}
}
}
}
//create the child network
Network net = new Network ();
//add inputs
for(int j=0;j<inputN;j++){
Neuron n = new Neuron();
net.addNeuron(n);
net.addInput(j);
}
//add outputs
for(int j=0;j<outputN;j++){
Neuron n = new Neuron();
net.addNeuron(n);
net.addOutput(inputN + j);
}
for (int j=0; j<(neuronN - inputN - outputN); j++) {
Neuron n = new Neuron ();
net.addNeuron (n);
}
for(int i=0;i<childEdges.Count;i++){
bool flag = net.addEdge(childEdges[i].inNeuron, childEdges[i].outNeuron, childEdges[i].weight, childEdges[i].innovation);
if(flag==false){
//Console.WriteLine("wtf add edge failed");
}
}
//new links
double rand2 = rand.NextDouble();
if (rand2 < linkMutationChance) {
int tCount = 0;
while(tCount <30){
int inputNode = rand.Next(0,neuronN - outputN);
if(inputNode >= inputN){
inputNode += outputN;
}
int outputNode = rand.Next (inputN, neuronN);
if(net.checkEdge(inputNode, outputNode)){
//add edge if the edge is connected to the input.
if(net.neurons[inputNode].inputEdges.Count > 0 || inputNode < inputN){
bool tb = net.addEdge(inputNode, outputNode, randomEdgeWeight(), getInnovation(inputNode, outputNode));
if(tb){
tCount = 20;
//.........这里部分代码省略.........
示例2: populationSetup
public static void populationSetup()
{
finished = 0;
networks = new List<Network> ();
innovationInputs = new List<int> ();
innovationOutputs = new List<int> ();
for(int i=0;i<populationSize;i++){
Network net = new Network();
//add xorFitnessinputs
for(int j=0;j<inputN;j++){
Neuron n = new Neuron();
net.addNeuron(n);
net.addInput(j);
}
//add outputs
for(int j=0;j<outputN;j++){
Neuron n = new Neuron();
net.addNeuron(n);
net.addOutput(inputN + j);
}
neuronN = inputN + outputN;
//add edges to outputs
for(int j=0;j<inputN;j++){
for(int k=0;k<outputN;k++){
//add a random weight between -2 and 2
bool temp = net.addEdge(j, k+inputN, randomEdgeWeight(), getInnovation(j, k+inputN));
}
}
networks.Add(net);
}
startingIndexOfNewGenomes = 0;
//initialize species
species = new List<List<int>> ();
speciesLastMaxFitness = new List<double> ();
speciesLastFitnessImprovement = new List<int> ();
}