コード例 #1
0
        /// <summary>
        /// Construct a network analyze class.  Analyze the specified network.
        /// </summary>
        /// <param name="network">The network to analyze.</param>
        public AnalyzeNetwork(BasicNetwork network)
        {
            int            assignDisabled = 0;
            int            assignedTotal  = 0;
            IList <double> biasList       = new List <double>();
            IList <double> weightList     = new List <double>();
            IList <double> allList        = new List <double>();

            foreach (ILayer layer in network.Structure.Layers)
            {
                if (layer.HasBias)
                {
                    for (int i = 0; i < layer.NeuronCount; i++)
                    {
                        biasList.Add(layer.BiasWeights[i]);
                        allList.Add(layer.BiasWeights[i]);
                    }
                }
            }

            foreach (ISynapse synapse in network.Structure.Synapses)
            {
                if (synapse.MatrixSize > 0)
                {
                    for (int from = 0; from < synapse.FromNeuronCount; from++)
                    {
                        for (int to = 0; to < synapse.ToNeuronCount; to++)
                        {
                            if (network.IsConnected(synapse, from, to))
                            {
                                double d = synapse.WeightMatrix[from, to];
                                weightList.Add(d);
                                allList.Add(d);
                            }
                            else
                            {
                                assignDisabled++;
                            }
                            assignedTotal++;
                        }
                    }
                }
            }

            this.disabledConnections = assignDisabled;
            this.totalConnections    = assignedTotal;
            this.weights             = new NumericRange(weightList);
            this.bias           = new NumericRange(biasList);
            this.weightsAndBias = new NumericRange(allList);
            this.weightValues   = EngineArray.ListToDouble(weightList);
            this.allValues      = EngineArray.ListToDouble(allList);
            this.biasValues     = EngineArray.ListToDouble(biasList);
        }
コード例 #2
0
 /// <summary>
 /// Randomize a synapse, only randomize those connections that are actually connected.
 /// </summary>
 /// <param name="network">The network the synapse belongs to.</param>
 /// <param name="synapse">The synapse to randomize.</param>
 public virtual void Randomize(BasicNetwork network, ISynapse synapse)
 {
     if (synapse.WeightMatrix != null)
     {
         bool       limited = network.Structure.IsConnectionLimited;
         double[][] d       = synapse.WeightMatrix.Data;
         for (int fromNeuron = 0; fromNeuron < synapse.WeightMatrix.Rows; fromNeuron++)
         {
             for (int toNeuron = 0; toNeuron < synapse.WeightMatrix.Cols; toNeuron++)
             {
                 if (!limited || network.IsConnected(synapse, fromNeuron, toNeuron))
                 {
                     d[fromNeuron][toNeuron] = Randomize(d[fromNeuron][toNeuron]);
                 }
             }
         }
     }
 }
コード例 #3
0
        /// <summary>
        /// Construct a network analyze class.  Analyze the specified network.
        /// </summary>
        /// <param name="network">The network to analyze.</param>
        public AnalyzeNetwork(BasicNetwork network)
        {
            int assignDisabled = 0;
            int assignedTotal = 0;
            IList<double> biasList = new List<double>();
            IList<double> weightList = new List<double>();
            IList<double> allList = new List<double>();

            foreach (ILayer layer in network.Structure.Layers)
            {
                if (layer.HasBias)
                {
                    for (int i = 0; i < layer.NeuronCount; i++)
                    {
                        biasList.Add(layer.BiasWeights[i]);
                        allList.Add(layer.BiasWeights[i]);
                    }
                }
            }

            foreach (ISynapse synapse in network.Structure.Synapses)
            {
                if (synapse.MatrixSize > 0)
                {
                    for (int from = 0; from < synapse.FromNeuronCount; from++)
                    {
                        for (int to = 0; to < synapse.ToNeuronCount; to++)
                        {
                            if (network.IsConnected(synapse, from, to))
                            {
                                double d = synapse.WeightMatrix[from, to];
                                weightList.Add(d);
                                allList.Add(d);
                            }
                            else
                            {
                                assignDisabled++;
                            }
                            assignedTotal++;
                        }
                    }
                }
            }

            this.disabledConnections = assignDisabled;
            this.totalConnections = assignedTotal;
            this.weights = new NumericRange(weightList);
            this.bias = new NumericRange(biasList);
            this.weightsAndBias = new NumericRange(allList);
            this.weightValues = EngineArray.ListToDouble(weightList);
            this.allValues = EngineArray.ListToDouble(allList);
            this.biasValues = EngineArray.ListToDouble(biasList);
        }