internal NeuronGene AdjustAxonTerminalsOfNeuronGene(NeuronGene gene, int desiredNumberOfTerminals) { NeuronGene toReturn = new NeuronGene { Axon = new AxonGene(), Soma = new SomaGene() }; toReturn.Axon.ActivationFunction = gene.Axon.ActivationFunction; toReturn.Axon.Weights = new List <double>(); toReturn.Soma.SummationFunction = gene.Soma.SummationFunction; toReturn.Soma.Bias = gene.Soma.Bias; if (desiredNumberOfTerminals > gene.Axon.Weights.Count) { for (int i = 0; i < gene.Axon.Weights.Count; i++) { toReturn.Axon.Weights.Add(gene.Axon.Weights[i]); } int delta = desiredNumberOfTerminals - gene.Axon.Weights.Count; for (int j = 0; j < delta; j++) { toReturn.Axon.Weights.Add(_weightInitializer.InitializeWeight()); } } else { for (int i = 0; i < desiredNumberOfTerminals; i++) { toReturn.Axon.Weights.Add(gene.Axon.Weights[i]); } } return(toReturn); }
public Synapse Create() { return(new Synapse { Axon = _axonFactory.Create(), Weight = _weightInitializer.InitializeWeight() }); }
internal INeuron CreateNeuron(Dictionary <int, Dictionary <int, IList <Synapse> > > mapping, int layerIndex, int neuronIndex) { var dendrites = (layerIndex > 0) ? getDendritesForSoma(layerIndex, neuronIndex, mapping) : mapping[layerIndex][neuronIndex]; var soma = _somaFactory.Create(dendrites, _biasInitiliazer.InitializeWeight()); var terminals = mapping[layerIndex + 1][neuronIndex]; var axon = _axonFactory.Create(terminals); return(_neuronFactory.Create(soma, axon)); }
internal NeuralNetworkGene TryAddLayerToNetwork(NeuralNetworkGene genes, double mutateChance, out bool didMutate) { NeuralNetworkGene newGenes = genes; didMutate = false; while (_random.NextDouble() <= mutateChance) { didMutate = true; int layerToReplace = _random.Next(newGenes.HiddenGenes.Count); int hiddenLayerSize = DetermineNumberOfHiddenNeuronsInLayer(genes, mutateChance); //update layer-1 axon terminals LayerGene previousLayer = GetPreviousLayerGene(newGenes, layerToReplace); foreach (NeuronGene neuron in previousLayer.Neurons) { neuron.Axon.Weights.Clear(); for (int i = 0; i < hiddenLayerSize; i++) { neuron.Axon.Weights.Add(_weightInitializer.InitializeWeight()); } } LayerGene newLayer = new LayerGene { Neurons = new List <NeuronGene>() }; newGenes.HiddenGenes.Insert(layerToReplace, newLayer); for (int i = 0; i < hiddenLayerSize; i++) { var newNeuron = GetRandomHiddenNeuronGene(newGenes, layerToReplace); newGenes.HiddenGenes[layerToReplace].Neurons.Add(newNeuron); } } return(newGenes); }
//////////////////////////////////////////////////////////////////////////////////////////////////// /// <summary> /// Initializes a new instance of the Autoencoders.RestrictedBoltzmannMachineWeightSet class. /// </summary> /// /// <param name="PPreSynapticLayerSize"> Size of the pre synaptic layer. </param> /// <param name="PPostSynapticLayerSize"> Size of the post synaptic layer. </param> /// <param name="PWeightInit"> The weight initialize. </param> //////////////////////////////////////////////////////////////////////////////////////////////////// public RestrictedBoltzmannMachineWeightSet(int PPreSynapticLayerSize, int PPostSynapticLayerSize, IWeightInitializer PWeightInit) { preSize = PPreSynapticLayerSize; postSize = PPostSynapticLayerSize; weights = new double[preSize][]; weightChanges = new double[preSize][]; for (int i = 0; i < preSize; i++) { weights[i] = new double[postSize]; weightChanges[i] = new double[postSize]; Utility.SetArrayToZero(weightChanges[i]); for (int j = 0; j < postSize; j++) { weights[i][j] = PWeightInit.InitializeWeight(); } } }
public RBMWeightSet(int PPreSynapticLayerSize, int PPostSynapticLayerSize, IWeightInitializer PWeightInit) { presize = PPreSynapticLayerSize; postsize = PPostSynapticLayerSize; weights = new double[presize][]; weightchanges = new double[presize][]; for (int i = 0; i < presize; i++) { weights[i] = new double[postsize]; weightchanges[i] = new double[postsize]; Utility.ZeroArray(weightchanges[i]); for (int j = 0; j < postsize; j++) { weights[i][j] = PWeightInit.InitializeWeight(); } } }