internal BackwardConnectionEntry(ConnectionIndex index, IBackwardConnection connection) { Contract.Requires(connection != null); Index = index; Connection = connection; }
internal BackwardConnectionEntry(ConnectionIndex index, IBackwardConnection connection) { Contract.Requires(connection != null); Index = index; Connection = connection; bwValues = connection.BackwardValues; lastBwValue = bwValues.Last; }
public NeuralNetwork(int numOfInputs, int numOfOutputs, int[] numOfHiddens) : base() { this.numOfHiddens = numOfHiddens; this.numOfInputs = numOfInputs; this.numOfOutputs = numOfOutputs; numOfLayers = this.numOfHiddens.Length + 1; layers = new PreceptorLayer[numOfLayers]; int prevNumOfPreceptors = this.numOfInputs; for (int i = 0; i < numOfLayers; i++) { int numOfPreceptors = i < (numOfLayers - 1) ? this.numOfHiddens[i] : this.numOfOutputs; Neuron.NormalizedMethod method = i == (numOfLayers - 1) ? Neuron.NormalizedMethod.SigmoidZeroTo1 : Neuron.NormalizedMethod.HyperTan; layers[i] = new PreceptorLayer(numOfPreceptors, prevNumOfPreceptors, method); numOfFeatures += numOfPreceptors; numOfConnections += prevNumOfPreceptors * numOfPreceptors; prevNumOfPreceptors = numOfPreceptors; } int idx = 0; featureIndex = new FeatureIndex[numOfFeatures]; for (int i = 0; i < numOfLayers; i++) { for (int j = 0; j < layers[i].numOfPreceptors; j++) { featureIndex[idx] = new FeatureIndex(i, j); idx += 1; } } idx = 0; connectionIndex = new ConnectionIndex[numOfConnections]; for (int i = 0; i < numOfLayers; i++) { for (int j = 0; j < layers[i].numOfPreceptors; j++) { for (int w = 0; w < layers[i].preceptors[j].GetNumWeights(); w++) { connectionIndex[idx] = new ConnectionIndex(i, j, w); idx += 1; } } } }
internal static LogicalNetwork CreateNetwork(LogicalNetworkFactory factory, IEnumerable<LogicalNetworkGene> geneSequence) { int nodeIndex = 0; int lastNodeIndex = -1; var uppers = new List<LogicalConnectionGene>(); var lowers = new List<LogicalConnectionGene>(); foreach (var gene in geneSequence) { var connGene = gene as LogicalConnectionGene; if (connGene != null) { if (connGene.IsUpper) uppers.Add(connGene); else lowers.Add(connGene); } else { var nodeGene = (LogicalNodeGene)gene; nodeIndex = nodeGene.Index; foreach (var ucg in uppers) { int uni = nodeIndex + ucg.Index; if (uni >= 0) { var connIndex = new ConnectionIndex(uni, nodeIndex); factory.TryAddConnectionFactory(connIndex, new Factory<ComputationalConnection<bool>>(ucg.CreateConnection)); } } if (lastNodeIndex != -1) { foreach (var lcg in lowers) { int lni = lastNodeIndex + lcg.Index; if (lni >= 0) { var connIndex = new ConnectionIndex(lastNodeIndex, lni); factory.TryAddConnectionFactory(connIndex, new Factory<ComputationalConnection<bool>>(lcg.CreateConnection)); } } } factory.TryAddNodeFactory(nodeIndex, new Factory<ComputationalNode<bool>>(nodeGene.CreateNode)); lastNodeIndex = nodeIndex; uppers.Clear(); lowers.Clear(); } } var network = new LogicalNetwork(factory); return network; }
/// <summary> /// Reverses the connection index. /// </summary> /// <returns>The reversed connection index.</returns> /// <param name="index">Index to reverse.</param> public static int ReverseConnectionIndex (ConnectionIndex index) { return ReverseConnectionIndex((int)index); }
/// <summary> /// Returns the vector from the center of the hex tile to the edge shared by the hex tile in the specified direction. /// </summary> public static Vector3 GetDirectionVector (ConnectionIndex direction) { return _linkDirections[(int)direction]; }
/// <summary> /// Returns the edge perpendicular to the specified connection as a list of two vectors (the positions of the two corners connection by that edge). /// </summary> public static List<Vector3> GetEdgeAsVectorList (ConnectionIndex direction) { List<Vector3> pointList = new List<Vector3>(); pointList.Add(edges[(int)direction].point1); pointList.Add(edges[(int)direction].point2); return pointList; }
/// <summary> /// Returns the edge perpendicular to the specified connection. /// </summary> public static Edge GetEdge (ConnectionIndex direction) { return new Edge(_edges[(int)direction]); }