NetworkToArray() 공개 정적인 메소드

Convert to an array. This is used with some training algorithms that require that the "memory" of the neuron(the weight and bias values) be expressed as a linear array.
public static NetworkToArray ( IMLMethod network ) : double[]
network IMLMethod The network to encode.
리턴 double[]
예제 #1
0
        /// <summary>
        /// Flatten the weights of a neural network.
        /// </summary>
        public void FlattenWeights()
        {
            if (this.flat != null)
            {
                this.flatUpdate = FlatUpdateNeeded.Flatten;

                double[] targetWeights = this.flat.Weights;
                double[] sourceWeights = NetworkCODEC.NetworkToArray(this.network);

                EngineArray.ArrayCopy(sourceWeights, targetWeights);
                this.flatUpdate = FlatUpdateNeeded.None;

                // update context layers
                foreach (ILayer layer in this.layers)
                {
                    if (layer is ContextLayer)
                    {
                        ContextLayer context = (ContextLayer)layer;
                        if (context.FlatContextIndex != -1)
                        {
                            EngineArray.ArrayCopy(
                                context.Context.Data,
                                0,
                                this.flat.LayerOutput,
                                context.FlatContextIndex,
                                context.Context.Count);
                        }
                    }
                }


                // handle limited connection networks
                if (this.connectionLimited)
                {
                    this.flat.ConnectionLimit = this.connectionLimit;
                }
                else
                {
                    this.flat.ClearConnectionLimit();
                }
            }
        }
예제 #2
0
        /// <summary>
        /// Determine if the two neural networks are equal.
        /// </summary>
        /// <param name="network1">The first network.</param>
        /// <param name="network2">The second network.</param>
        /// <param name="precision">How many decimal places to check.</param>
        /// <returns>True if the two networks are equal.</returns>
        public static bool Equals(BasicNetwork network1,
                                  BasicNetwork network2, int precision)
        {
            double[] array1 = NetworkCODEC.NetworkToArray(network1);
            double[] array2 = NetworkCODEC.NetworkToArray(network2);

            if (array1.Length != array2.Length)
            {
                return(false);
            }

            double test = Math.Pow(10.0, precision);

            if (double.IsInfinity(test) || (test > long.MaxValue))
            {
                String str = "Precision of " + precision
                             + " decimal places is not supported.";
#if logging
                if (NetworkCODEC.LOGGER.IsErrorEnabled)
                {
                    NetworkCODEC.LOGGER.Error(str);
                }
#endif
                throw new NeuralNetworkError(str);
            }

            foreach (double element in array1)
            {
                long l1 = (long)(element * test);
                long l2 = (long)(element * test);
                if (l1 != l2)
                {
                    return(false);
                }
            }

            return(true);
        }