public CommonSlice(int numberOfNeurons) { for (var i = 0; i < numberOfNeurons; i++) { Neurons.Add(new CommonBiasNeuron()); } }
public void InitDelta(List <double> idealOutput) { foreach (var(neuron, output) in Neurons.Cast <OutputNeuron>().Zip(idealOutput, (neuron, output) => (neuron, output))) { neuron.InitDelta(output); } }
static void Main() { //given const int stringLength = 32; //Input : N numbers , while NOT negative List <string> inputStrings = new List <string>(); long toAdd; while (true) { toAdd = long.Parse(Console.ReadLine()); if (toAdd < 0) { break; } inputStrings.Add(Convert.ToString(toAdd, 2).PadLeft(stringLength, '0')); } //Create Neurons Grid Neurons[,] neuronGrid = new Neurons[inputStrings.Count, stringLength]; //check each bit for (int currRow = 0; currRow < inputStrings.Count; currRow++) { for (int currCol = 0; currCol < stringLength; currCol++) { bool boundRight = false; bool boundTop = false; bool boundBot = false; } } }
public void AddLink(CPPNNetworkNeuron from, CPPNNetworkNeuron to, Complex weight) { if (Neurons.Contains(from) && Neurons.Contains(to)) { (to as CPPNOutputNeuron).AddChild(from, weight); } }
public override void InitNetwork() { // Creating neurons for (int ii = 0; ii < NeuronCount; ii++) { Neurons.Add(new Neuron(ii)); } // Adding link btween neurons int jj = 0; // input to hidden layer for (int kk = 0; kk < HIDDEN_NEURON_COUNT; kk++) { CreateSynapse(Neurons[0], Neurons[2 + kk], jj++); } for (int kk = 0; kk < HIDDEN_NEURON_COUNT; kk++) { CreateSynapse(Neurons[1], Neurons[2 + kk], jj++); } // reccurant links for (int kk = 0; kk < HIDDEN_NEURON_COUNT; kk++) { CreateSynapse(Neurons[2 + kk], Neurons[2 + kk], jj++); } // hidden layer to input for (int kk = 0; kk < HIDDEN_NEURON_COUNT; kk++) { CreateSynapse(Neurons[2 + kk], Neurons[NeuronCount - 2], jj++); } for (int kk = 0; kk < HIDDEN_NEURON_COUNT; kk++) { CreateSynapse(Neurons[2 + kk], Neurons[NeuronCount - 1], jj++); } }
public void Calculate() { for (int layer = 0; layer < TotalLayers; layer++) { Neurons.FindAll(n => n.NetworkLevel == layer).ForEach(n => n.Calculate()); } }
public NeuronLayer Clone() { return(new NeuronLayer { Neurons = Neurons.Select(n => n.Clone()).ToList() }); }
private void setBravery(Neurons n) { //Neurons n = victim.GetComponent ("Neurons") as Neurons; int bravery = (level * 10); n.setBravery(bravery); }
public double[] Activate(double[] inputs) { if (inputs.Length != Inputs) { throw new System.IndexOutOfRangeException("Input length invalid, should be: " + Inputs.ToString()); } Neurons.Sort(new Node.NodeSorter()); for (int i = 0; i < Inputs; i++) { Neurons[i].AddValue(inputs[i]); } foreach (Node n in Neurons) { n.Fire(); } var output = new double[Outputs]; for (int o = 0; o < Outputs; o++) { output[o] = Neurons[o + Inputs].GetValue(); } return(output); }
public void damage(GameObject Player) { health -= 50; if (isMonster && health <= 100) { loseForm(); } Neurons n = gameObject.GetComponent("Neurons") as Neurons; if (!isPlayer) { Brain b = gameObject.GetComponent("Brain") as Brain; Neurons neuron = gameObject.GetComponent("Neurons") as Neurons; GameObject canSee = b.visiblePlayer(); if (canSee == null && neuron.canBeStealthKilled()) { health -= 50; } } if (health < 0) { health = 0; } checkLife(); if (n != null) { n.seePlayer(Player); } }
/// <summary> /// Randomly mutates the neural network by changing weights, adding connections, and/or adding neurons. /// </summary> public void RandomMutation() { double connectionWeightsMutation = rand.NextDouble(); double connectionMutation = rand.NextDouble(); double NeuronMutation = rand.NextDouble(); if (connectionWeightsMutation < connectionWeightsMutationChance) { for (int outputNeuronIdx = NumInputs; outputNeuronIdx < NumInputs + NumOutputs; outputNeuronIdx++) { Neurons.TryGetValue(outputNeuronIdx, out Neuron outputNeuron); MutateConnections(outputNeuron); } } if (connectionMutation < connectionMutationChance) { MutateLink(); } if (NeuronMutation < NeuronMutationChance) { MutateNeuron(); } }
internal void Add(NeuronTypes type) { int arrayIndex = 0; for (int i = 0; i < NeuronsInfo.Count; i++) { arrayIndex += Convert.ToInt32(type == NeuronsInfo[i].neuronType); } NeuronsInfo.Add(new NeuronInfo(arrayIndex, type)); switch (type) { case NeuronTypes.feedForward: Neurons.Add(new Neuron(previousLayerLenght)); break; case NeuronTypes.lSTM: LSTMCells.Add(new LSTMCell(previousLayerLenght)); break; case NeuronTypes.recurrent: RecurrentNeurons.Add(new RecurrentNeuron(previousLayerLenght)); break; default: throw new NotImplementedException(); } }
public void FeedForward(double[] input) { foreach (Neuron n in Neurons) { n.Net = input[Neurons.IndexOf(n)]; } if (LayerAfter != null) { double[] newInput = new double[LayerAfter.Neurons.Count]; foreach (Neuron n in LayerAfter.Neurons) { double netSum = 0; foreach (Connection c in n.Connections) { double neuronValue = c.FromNeuron.Out; netSum += c.Weight * neuronValue; } newInput[LayerAfter.Neurons.IndexOf(n)] = netSum; } LayerAfter.FeedForward(newInput); } }
public void ResetNeuronsOfLayer(double minWeight, double maxWeight) { for (int neuronNo = 0; neuronNo < Neurons.Count; neuronNo++) { Neurons.ElementAt(neuronNo).ResetNeuron(); } }
public void ResetNeuronsOfLayer() { for (int neuronNo = 0; neuronNo < Neurons.Count; neuronNo++) { Neurons.ElementAt(neuronNo).ResetNeuron(); } }
/// <summary> /// Makes the initial connections frome every inout to every output with random weights. /// </summary> public void InitializeRandom() { for (int i = NumInputs; i < NumInputs + NumOutputs; i++) { Neurons.TryGetValue(i, out Neuron outputNeuron); for (int j = 1; j < NumInputs; j++) { Neurons.TryGetValue(j, out Neuron inputNeuron); Tuple <int, int> fromToPair = new Tuple <int, int>(inputNeuron.ID, outputNeuron.ID); Connection conn; if (InnovationNumbers.ContainsKey(fromToPair)) { lock (InnovationNumbers) { InnovationNumbers.TryGetValue(fromToPair, out int innoNumber); conn = new Connection(innoNumber, inputNeuron, rand.NextDouble() * 4 - 2); } } else { lock (InnovationNumbers) { conn = new Connection(InnovationNumbers.Count(), inputNeuron, rand.NextDouble() * 4 - 2); InnovationNumbers.Add(new Tuple <int, int>(inputNeuron.ID, outputNeuron.ID), InnovationNumbers.Count()); } } Connections.Add(fromToPair); outputNeuron.AddConnection(conn.ID, conn); } } }
/// <summary> /// Сгенерировать нейроны сети. /// </summary> /// <param name="attributes">Количество параметров входящего вектора.</param> /// <param name="neuronsCount">Количество нейронов.</param> public void GenerateNeurons(List <NetworkAttribute> attributes, int neuronsCount) { Neurons.Clear(); Weights.Clear(); InputAttributes.Clear(); InputAttributes.AddRange(attributes.Select(a => new InputAttributeBase { InputAttributeNumber = a.OrderNumber, Name = a.Name }) .ToList()); for (int i = 0; i < neuronsCount; i++) { Neurons.Add(new NeuronBase { NeuronNumber = i }); } foreach (var inputAttribute in InputAttributes) { foreach (var neuron in Neurons) { var randomWeight = NormalizationType.GetNeuronWeight(attributes.Count); Weights.Add(new WeightBase { InputAttributeNumber = inputAttribute.InputAttributeNumber, NeuronNumber = neuron.NeuronNumber, Value = randomWeight }); } } }
public InputLayer(int numberOfNeurons, IActivationFunction activationFunction, IInputFunction inputFunction) { for (int i = 0; i < numberOfNeurons; i++) { Neurons.Add(new InputNeuron(activationFunction, inputFunction)); } }
public void FillLayer() { for (var i = 0; i < Size; i++) { Neurons.Add(new Neuron(Index, i)); } }
public void AssignInput(List <double> input) { foreach (var(neuron, d) in Neurons.Zip(input, (neuron, d) => (neuron, d))) { neuron.Value = d; } }
/// <summary> /// mutates a random link in the neural network /// </summary> public void MutateNeuron() { while (true) { int neuronId = rand.Next(NumInputs, NumInputs + NumOutputs); if (Neurons.TryGetValue(neuronId, out Neuron farNeuron) && farNeuron.Connections.Count > 0) { Connection conn; int connectionId; do { connectionId = rand.Next(farNeuron.Connections.Count()); conn = farNeuron.Connections.Values.ElementAt(connectionId); } while (conn.From.ID == 0); Neuron newNeuron = new Neuron(Neurons.Count); Tuple <int, int> nearToMidTuple = new Tuple <int, int>(conn.From.ID, newNeuron.ID); Connection nearToMid; lock (InnovationNumbers) { if (InnovationNumbers.TryGetValue(nearToMidTuple, out int innoNumber)) { nearToMid = new Connection(innoNumber, conn.From, 1); } else { nearToMid = new Connection(InnovationNumbers.Count(), conn.From, 1); InnovationNumbers.Add(nearToMidTuple, InnovationNumbers.Count()); } } Connection midToFar; Tuple <int, int> midToFarTuple = new Tuple <int, int>(newNeuron.ID, farNeuron.ID); lock (InnovationNumbers) { if (InnovationNumbers.TryGetValue(midToFarTuple, out int innoNumber2)) { midToFar = new Connection(innoNumber2, newNeuron, conn.Weight); } else { midToFar = new Connection(InnovationNumbers.Count(), newNeuron, conn.Weight); InnovationNumbers.Add(midToFarTuple, InnovationNumbers.Count()); } } Neurons.Add(newNeuron.ID, newNeuron); newNeuron.AddConnection(nearToMid.ID, nearToMid); Connection oldConnection = farNeuron.Connections.Values.ElementAt(connectionId); conn.EnableDisable(); Connections.Add(nearToMidTuple); Connections.Add(midToFarTuple); farNeuron.AddConnection(midToFar.ID, midToFar); NumNeurons++; return; } } }
public override void Forward(bool isTraining) { Neurons.ForEach((N, i) => { N.InVal = N.InSynapses[0].InNeuron.OutVal; N.OutVal = N.InVal; }); }
public void copyTo(Network n1) { for (int layer = Synapsis.Length; layer-- > 0;) { Synapsis[layer].CopyTo(n1.Synapsis[layer], 0); } Neurons.CopyTo(n1.Neurons, 0); }
public Neuron GetWinner(Vector <double> input) { return(Neurons .Select((n, i) => new { neuron = n, value = DistanceCalculator.CalculateDistance(n.CurrentWeights, input) }) .OrderBy(item => item.value) .First().neuron); }
public Matrix[] Compute(Matrix[] input) { var outputs = Neurons.AsParallel().Select(n => n.Compute(input)).ToArray(); Outputs = outputs; return(outputs); }
public void Run() { Neurons.ForEach(x => x.Run()); if (NextLayer != null) { NextLayer.Run(); } }
public double[] Compute(double[] inputs) { var outputs = Neurons.AsParallel().Select(n => n.Compute(inputs)).ToArray(); Outputs = outputs; return(outputs); }
public void Optimize(double delta) { Weight += LearningRate * delta; Debug.WriteLine($"LR = {LearningRate} Delta = {delta} Weight = {Weight}"); Neurons.ToList().ForEach(x => x.UpdateWeights(Weight)); }
public NeuralLayer(int neuronCount, double initialWeight, string name) { Weight = initialWeight; Name = name; Enumerable.Range(0, neuronCount).ToList() .ForEach(elem => Neurons.Add(new Neuron())); }
public void Populate(int size, AbstractInputFunction inputFunction = null, AbstractActivationFunction activationFunction = null) { for (int toFill = size - Neurons.Count(); toFill > 0; toFill--) { Neurons.Add(new Neuron(inputFunction, activationFunction)); } Size = Neurons.Count(); }
public Network(int inputsCount, int layersCount, List<int> neuronsCountInHiddenLayers, Functions.IActivationFunction function, Neurons.INeuronInitilizer initializer ) { NetworkInit(inputsCount, layersCount); if (neuronsCountInHiddenLayers.Count != layersCount) throw new ApplicationException("Number of layers and provided layer's neuron count do not match!"); layers[0] = new Layer(inputsCount, inputsCount, function, initializer); for(int i = 1; i < layers.Length; i++) layers[i] = new Layer(neuronsCountInHiddenLayers[i-1], neuronsCountInHiddenLayers[i], function, initializer); }