コード例 #1
0
ファイル: Brain.cs プロジェクト: kroll-software/KS.Brain
        private void SimpleWhatFiresTogetherWiresTogether()
        {
            if (!EnableWhatFiresTogetherWiresTogether)
            {
                return;
            }

            if (ParallelExecution)
            {
                Parallel.For(0, Layers.Count - 1, i =>
                {
                    IBrainLayer layerTransmit = Layers[i];
                    IBrainLayer layerRecieve  = Layers[i + 1];

                    for (int m = 0; m < layerTransmit.FiredNeurons.Count; m++)
                    {
                        Neuron neuron1 = layerTransmit.FiredNeurons[m];
                        for (int n = 0; n < layerRecieve.FiredNeurons.Count; n++)
                        {
                            Neuron neuron2 = layerRecieve.FiredNeurons[n];
                            AddConnection(neuron1, neuron2, 0.2f, false);
                        }
                    }
                });
            }
            else
            {
                for (int i = 0; i < Layers.Count - 1; i++)
                {
                    IBrainLayer layerTransmit = Layers[i];
                    IBrainLayer layerRecieve  = Layers[i + 1];

                    for (int m = 0; m < layerTransmit.FiredNeurons.Count; m++)
                    {
                        Neuron neuron1 = layerTransmit.FiredNeurons[m];
                        for (int n = 0; n < layerRecieve.FiredNeurons.Count; n++)
                        {
                            Neuron neuron2 = layerRecieve.FiredNeurons[n];
                            AddConnection(neuron1, neuron2, 0.2f, false);
                        }
                    }
                }
            }
        }
コード例 #2
0
ファイル: Brain.cs プロジェクト: kroll-software/KS.Brain
        private void ComplexWhatFiresTogetherWiresTogether()
        {
            if (!EnableWhatFiresTogetherWiresTogether)
            {
                return;
            }

            if (ParallelExecution)
            {
                Parallel.For(1, Layers.Count, i => {
                    IBrainLayer layerRecieve = Layers[i];

                    for (int m = 0; m < layerRecieve.FiredNeurons.Count; m++)
                    {
                        Neuron receptor = layerRecieve.FiredNeurons[m];

                        IBrainLayer layerTransmit = layerRecieve;
                        int startIndex            = 0;

                        switch (receptor.ConnectionType)
                        {
                        case ConnectionTypes.LocalLayer:
                            startIndex = m + 1;
                            break;

                        case ConnectionTypes.PreviousLayer:
                            layerTransmit = Layers[i - 1];
                            break;

                        default:
                            continue;
                        }

                        for (int n = startIndex; n < layerTransmit.FiredNeurons.Count; n++)
                        {
                            Neuron transmitter = layerTransmit.FiredNeurons[n];
                            if (receptor.Rank == transmitter.Rank)
                            {
                                AddConnectionRandomDirection(transmitter, receptor);
                            }
                            else if (transmitter.ConnectionType == ConnectionTypes.LocalLayer || transmitter.ConnectionType == ConnectionTypes.None)
                            {
                                AddConnection(transmitter, receptor);
                            }
                        }
                    }
                });
            }
            else
            {
                for (int i = 1; i < Layers.Count; i++)
                {
                    IBrainLayer layerRecieve = Layers[i];

                    for (int m = 0; m < layerRecieve.FiredNeurons.Count; m++)
                    {
                        Neuron receptor = layerRecieve.FiredNeurons[m];

                        IBrainLayer layerTransmit = layerRecieve;
                        int         startIndex    = 0;

                        switch (receptor.ConnectionType)
                        {
                        case ConnectionTypes.LocalLayer:
                            startIndex = m + 1;
                            break;

                        case ConnectionTypes.PreviousLayer:
                            layerTransmit = Layers[i - 1];
                            break;

                        default:
                            continue;
                        }

                        for (int n = startIndex; n < layerTransmit.FiredNeurons.Count; n++)
                        {
                            Neuron transmitter = layerTransmit.FiredNeurons[n];
                            if (receptor.Rank == transmitter.Rank)
                            {
                                AddConnectionRandomDirection(transmitter, receptor);
                            }
                            else if (transmitter.ConnectionType == ConnectionTypes.LocalLayer || transmitter.ConnectionType == ConnectionTypes.None)
                            {
                                AddConnection(transmitter, receptor);
                            }
                        }
                    }
                }
            }
        }