Пример #1
0
 public RBFNetwork(int inputCount, int hiddenCount, int outputCount, RBFEnum t)
 {
     if (hiddenCount != 0)
     {
         IRadialBasisFunction[] rbf = new IRadialBasisFunction[hiddenCount];
         double volumeNeuronRBFWidth = 2.0 / ((double) hiddenCount);
         this._flat = new FlatNetworkRBF(inputCount, rbf.Length, outputCount, rbf);
         try
         {
             this.SetRBFCentersAndWidthsEqualSpacing(-1.0, 1.0, t, volumeNeuronRBFWidth, false);
         }
         catch (EncogError)
         {
             this.RandomizeRBFCentersAndWidths(-1.0, 1.0, t);
         }
     }
     else
     {
         do
         {
             throw new NeuralNetworkError("RBF network cannot have zero hidden neurons.");
         }
         while ((((uint) outputCount) | 2) == 0);
     }
 }
Пример #2
0
        /// <summary>
        ///     Construct a multi-dimensional neighborhood function.
        /// </summary>
        /// <param name="size">The sizes of each dimension.</param>
        /// <param name="type">The RBF type to use.</param>
        public NeighborhoodRBF(int[] size, RBFEnum type)
        {
            _params = new double[size.Length];

            switch (type)
            {
            case RBFEnum.Gaussian:
                _rbf = new GaussianFunction(size.Length, _params, 0);
                break;

            case RBFEnum.InverseMultiquadric:
                _rbf = new InverseMultiquadricFunction(size.Length, _params, 0);
                break;

            case RBFEnum.Multiquadric:
                _rbf = new MultiquadricFunction(size.Length, _params, 0);
                break;

            case RBFEnum.MexicanHat:
                _rbf = new MexicanHatFunction(size.Length, _params, 0);
                break;
            }
            _size = size;
            CalculateDisplacement();
        }
Пример #3
0
        /// <summary>
        /// Construct a 1d neighborhood function.
        /// </summary>
        /// <param name="type">The RBF type to use.</param>
        public NeighborhoodRBF1D(RBFEnum type)
        {
            switch (type)
            {
            case RBFEnum.Gaussian:
                _radial = new GaussianFunction(1, _params, 0);
                break;

            case RBFEnum.InverseMultiquadric:
                _radial = new InverseMultiquadricFunction(1, _params, 0);
                break;

            case RBFEnum.Multiquadric:
                _radial = new MultiquadricFunction(1, _params, 0);
                break;

            case RBFEnum.MexicanHat:
                _radial = new MexicanHatFunction(1, _params, 0);
                break;

            default:
                throw new AIFHError("Unknown RBF type: " + type.ToString());
            }

            _radial.Width = 1.0;
        }
Пример #4
0
 /// <summary>
 /// Construct the object.
 /// </summary>
 public RadialBasisPattern()
 {
     _rbfType = RBFEnum.Gaussian;
     _inputNeurons = -1;
     _outputNeurons = -1;
     _hiddenNeurons = -1;
 }
 /// <summary>
 /// Construct the object.
 /// </summary>
 public RadialBasisPattern()
 {
     _rbfType       = RBFEnum.Gaussian;
     _inputNeurons  = -1;
     _outputNeurons = -1;
     _hiddenNeurons = -1;
 }
Пример #6
0
        /// <summary>
        /// Construct RBF network.
        /// </summary>
        ///
        /// <param name="inputCount">The input count.</param>
        /// <param name="hiddenCount">The hidden count.</param>
        /// <param name="outputCount">The output count.</param>
        /// <param name="t">The RBF type.</param>
        public RBFNetwork(int inputCount, int hiddenCount,
                          int outputCount, RBFEnum t)
        {
            if (hiddenCount == 0)
            {
                throw new NeuralNetworkError(
                          "RBF network cannot have zero hidden neurons.");
            }

            var rbf = new IRadialBasisFunction[hiddenCount];

            // Set the standard RBF neuron width.
            // Literature seems to suggest this is a good default value.
            double volumeNeuronWidth = 2.0d / hiddenCount;

            _flat = new FlatNetworkRBF(inputCount, rbf.Length, outputCount, rbf);

            try
            {
                // try this
                SetRBFCentersAndWidthsEqualSpacing(-1, 1, t, volumeNeuronWidth,
                                                   false);
            }
            catch (EncogError)
            {
                // if we have the wrong number of hidden neurons, try this
                RandomizeRBFCentersAndWidths(-1, 1, t);
            }
        }
Пример #7
0
        public NeighborhoodRBF(int[] size, RBFEnum type)
        {
            if (-1 != 0)
            {
                RBFEnum enum2 = type;
                if (-2147483648 != 0)
                {
                    switch (enum2)
                    {
                        case RBFEnum.Gaussian:
                            this._x542ac40d5d0f20b7 = new GaussianFunction(2);
                            break;

                        case RBFEnum.Multiquadric:
                            this._x542ac40d5d0f20b7 = new MultiquadricFunction(2);
                            break;

                        case RBFEnum.InverseMultiquadric:
                            this._x542ac40d5d0f20b7 = new InverseMultiquadricFunction(2);
                            break;

                        case RBFEnum.MexicanHat:
                            this._x542ac40d5d0f20b7 = new MexicanHatFunction(2);
                            break;
                    }
                }
            }
            this._x0ceec69a97f73617 = size;
            this.x2d3eee42a645354a();
        }
        /// <summary>
        /// Construct a 1d neighborhood function.
        /// </summary>
        ///
        /// <param name="type">The RBF type to use.</param>
        public NeighborhoodRBF1D(RBFEnum type)
        {
            switch (type)
            {
            case RBFEnum.Gaussian:
                _radial = new GaussianFunction(1);
                break;

            case RBFEnum.InverseMultiquadric:
                _radial = new InverseMultiquadricFunction(1);
                break;

            case RBFEnum.Multiquadric:
                _radial = new MultiquadricFunction(1);
                break;

            case RBFEnum.MexicanHat:
                _radial = new MexicanHatFunction(1);
                break;

            default:
                throw new NeuralNetworkError("Unknown RBF type: " + type);
            }

            _radial.Width = 1.0d;
        }
Пример #9
0
 /// <summary>
 /// Specify specific centers and widths for the provided RBFType
 /// </summary>
 /// <param name="centers">Array containing center position. Row n contains centers for neuron n. Row n contains x elements for x number of dimensions.</param>
 /// <param name="widths">Array containing widths. Row n contains widths for neuron n. Row n contains x elements for x number of dimensions.</param>
 /// <param name="RBFType">The RBF Function to use for this layer.</param>
 public void SetRBFCentersAndWidths(double[][] centers, double[] widths, RBFEnum RBFType)
 {
     for (int i = 0; i < this.NeuronCount; i++)
     {
         SetRBFFunction(i, RBFType, centers[i], widths[i]);
     }
 }
Пример #10
0
        public NeighborhoodRBF1D(RBFEnum type)
        {
            switch (type)
            {
                case RBFEnum.Gaussian:
                    this._x69265a675586f26d = new GaussianFunction(1);
                    break;

                case RBFEnum.Multiquadric:
                    this._x69265a675586f26d = new MultiquadricFunction(1);
                    break;

                case RBFEnum.InverseMultiquadric:
                    this._x69265a675586f26d = new InverseMultiquadricFunction(1);
                    if (1 == 0)
                    {
                        goto Label_0032;
                    }
                    break;

                case RBFEnum.MexicanHat:
                    this._x69265a675586f26d = new MexicanHatFunction(1);
                    break;

                default:
                    throw new NeuralNetworkError("Unknown RBF type: " + type);
            }
            Label_001E:
            this._x69265a675586f26d.Width = 1.0;
            Label_0032:
            if (-1 == 0)
            {
                goto Label_001E;
            }
        }
Пример #11
0
        /// <summary>
        ///     Construct a 2d neighborhood function based on the sizes for the
        ///     x and y dimensions.
        /// </summary>
        /// <param name="type">The RBF type to use.</param>
        /// <param name="x">The size of the x-dimension.</param>
        /// <param name="y">The size of the y-dimension.</param>
        public NeighborhoodRBF(RBFEnum type, int x, int y)
        {
            var size = new int[2];
            size[0] = x;
            size[1] = y;

            _params = new double[3];

            switch (type)
            {
                case RBFEnum.Gaussian:
                    _rbf = new GaussianFunction(2, _params, 0);
                    break;
                case RBFEnum.InverseMultiquadric:
                    _rbf = new InverseMultiquadricFunction(2, _params, 0);
                    break;
                case RBFEnum.Multiquadric:
                    _rbf = new MultiquadricFunction(2, _params, 0);
                    break;
                case RBFEnum.MexicanHat:
                    _rbf = new MexicanHatFunction(2, _params, 0);
                    break;
            }

            _rbf.Width = 1;

            _size = size;

            CalculateDisplacement();
        }
Пример #12
0
        /// <summary>
        ///     Construct a 2d neighborhood function based on the sizes for the
        ///     x and y dimensions.
        /// </summary>
        /// <param name="type">The RBF type to use.</param>
        /// <param name="x">The size of the x-dimension.</param>
        /// <param name="y">The size of the y-dimension.</param>
        public NeighborhoodRBF(RBFEnum type, int x, int y)
        {
            var size = new int[2];

            size[0] = x;
            size[1] = y;

            _params = new double[3];

            switch (type)
            {
            case RBFEnum.Gaussian:
                _rbf = new GaussianFunction(2, _params, 0);
                break;

            case RBFEnum.InverseMultiquadric:
                _rbf = new InverseMultiquadricFunction(2, _params, 0);
                break;

            case RBFEnum.Multiquadric:
                _rbf = new MultiquadricFunction(2, _params, 0);
                break;

            case RBFEnum.MexicanHat:
                _rbf = new MexicanHatFunction(2, _params, 0);
                break;
            }

            _rbf.Width = 1;

            _size = size;

            CalculateDisplacement();
        }
Пример #13
0
        /// <summary>
        /// Construct RBF network.
        /// </summary>
        ///
        /// <param name="inputCount">The input count.</param>
        /// <param name="hiddenCount">The hidden count.</param>
        /// <param name="outputCount">The output count.</param>
        /// <param name="t">The RBF type.</param>
        public RBFNetwork(int inputCount, int hiddenCount,
                          int outputCount, RBFEnum t)
        {
            if (hiddenCount == 0)
            {
                throw new NeuralNetworkError(
                    "RBF network cannot have zero hidden neurons.");
            }

            var rbf = new IRadialBasisFunction[hiddenCount];

            // Set the standard RBF neuron width.
            // Literature seems to suggest this is a good default value.
            double volumeNeuronWidth = 2.0d/hiddenCount;

            _flat = new FlatNetworkRBF(inputCount, rbf.Length, outputCount, rbf);

            try
            {
                // try this
                SetRBFCentersAndWidthsEqualSpacing(-1, 1, t, volumeNeuronWidth,
                                                   false);
            }
            catch (EncogError)
            {
                // if we have the wrong number of hidden neurons, try this
                RandomizeRBFCentersAndWidths(-1, 1, t);
            }
        }
Пример #14
0
 /// <summary>
 /// Array containing center position. Row n contains centers for neuron n.
 /// Row n contains x elements for x number of dimensions.
 /// </summary>
 ///
 /// <param name="centers">The centers.</param>
 /// <param name="widths"></param>
 /// <param name="t">The RBF Function to use for this layer.</param>
 public void SetRBFCentersAndWidths(double[][] centers,
                                    double[] widths, RBFEnum t)
 {
     for (int i = 0; i < _flat.RBF.Length; i++)
     {
         SetRBFFunction(i, t, centers[i], widths[i]);
     }
 }
Пример #15
0
 private void SetRBFFunction(int RBFIndex, RBFEnum RBFType, double[] centers, double width)
 {
     if (RBFType == RBFEnum.Gaussian)
     {
         this.radialBasisFunction[RBFIndex] = new GaussianFunction(0.5, centers, width);
     }
     else if (RBFType == RBFEnum.Multiquadric)
     {
         this.radialBasisFunction[RBFIndex] = new MultiquadricFunction(0.5, centers, width);
     }
     else if (RBFType == RBFEnum.InverseMultiquadric)
     {
         this.radialBasisFunction[RBFIndex] = new InverseMultiquadricFunction(0.5, centers, width);
     }
 }
Пример #16
0
        /// <summary>
        /// Set the RBF components to random values.
        /// </summary>
        ///
        /// <param name="min">Minimum random value.</param>
        /// <param name="max">Max random value.</param>
        /// <param name="t">The type of RBF to use.</param>
        public void RandomizeRBFCentersAndWidths(double min,
                                                 double max, RBFEnum t)
        {
            int dimensions = InputCount;
            var centers    = new double[dimensions];

            for (int i = 0; i < dimensions; i++)
            {
                centers[i] = RangeRandomizer.Randomize(min, max);
            }

            for (int i = 0; i < _flat.RBF.Length; i++)
            {
                SetRBFFunction(i, t, centers, RangeRandomizer.Randomize(min, max));
            }
        }
Пример #17
0
        /// <summary>
        /// Construct a 2d neighborhood function based on the sizes for the
        /// x and y dimensions.
        /// </summary>
        ///
        /// <param name="type">The RBF type to use.</param>
        /// <param name="x">The size of the x-dimension.</param>
        /// <param name="y">The size of the y-dimension.</param>
        public NeighborhoodRBF(RBFEnum type, int x, int y)
        {
            var size = new int[2];

            size[0] = x;
            size[1] = y;

            var centerArray = new double[2];

            centerArray[0] = 0;
            centerArray[1] = 0;

            var widthArray = new double[2];

            widthArray[0] = 1;
            widthArray[1] = 1;

            switch (type)
            {
            case RBFEnum.Gaussian:
                _rbf = new GaussianFunction(2);
                break;

            case RBFEnum.InverseMultiquadric:
                _rbf = new InverseMultiquadricFunction(2);
                break;

            case RBFEnum.Multiquadric:
                _rbf = new MultiquadricFunction(2);
                break;

            case RBFEnum.MexicanHat:
                _rbf = new MexicanHatFunction(2);
                break;
            }

            _rbf.Width = 1;
            EngineArray.ArrayCopy(centerArray, _rbf.Centers);

            _size = size;

            CalculateDisplacement();
        }
Пример #18
0
 /// <summary>
 /// Set an RBF function.
 /// </summary>
 ///
 /// <param name="index">The index to set.</param>
 /// <param name="t">The function type.</param>
 /// <param name="centers">The centers.</param>
 /// <param name="width">The width.</param>
 public void SetRBFFunction(int index, RBFEnum t,
                            double[] centers, double width)
 {
     if (t == RBFEnum.Gaussian)
     {
         _flat.RBF[index] = new GaussianFunction(0.5d, centers,
                                                 width);
     }
     else if (t == RBFEnum.Multiquadric)
     {
         _flat.RBF[index] = new MultiquadricFunction(0.5d, centers,
                                                     width);
     }
     else if (t == RBFEnum.InverseMultiquadric)
     {
         _flat.RBF[index] = new InverseMultiquadricFunction(0.5d,
                                                            centers, width);
     }
 }
        /// <summary>
        /// Construct a 1d neighborhood function.
        /// </summary>
        ///
        /// <param name="type">The RBF type to use.</param>
        public NeighborhoodRBF1D(RBFEnum type)
        {
            switch (type)
            {
                case RBFEnum.Gaussian:
                    _radial = new GaussianFunction(1);
                    break;
                case RBFEnum.InverseMultiquadric:
                    _radial = new InverseMultiquadricFunction(1);
                    break;
                case RBFEnum.Multiquadric:
                    _radial = new MultiquadricFunction(1);
                    break;
                case RBFEnum.MexicanHat:
                    _radial = new MexicanHatFunction(1);
                    break;
                default:
                    throw new NeuralNetworkError("Unknown RBF type: " + type);
            }

            _radial.Width = 1.0d;
        }
Пример #20
0
        /// <summary>
        /// Construct a 1d neighborhood function. 
        /// </summary>
        /// <param name="type">The RBF type to use.</param>
        public NeighborhoodRBF1D(RBFEnum type)
        {
            switch (type)
            {
                case RBFEnum.Gaussian:
                    _radial = new GaussianFunction(1, _params, 0);
                    break;
                case RBFEnum.InverseMultiquadric:
                    _radial = new InverseMultiquadricFunction(1, _params, 0);
                    break;
                case RBFEnum.Multiquadric:
                    _radial = new MultiquadricFunction(1, _params, 0);
                    break;
                case RBFEnum.MexicanHat:
                    _radial = new MexicanHatFunction(1, _params, 0);
                    break;
                default:
                    throw new AIFHError("Unknown RBF type: " + type.ToString());
            }

            _radial.Width = 1.0;
        }
Пример #21
0
        /// <summary>
        /// Construct a multi-dimensional neighborhood function. 
        /// </summary>
        /// <param name="size">The sizes of each dimension.</param>
        /// <param name="type">The RBF type to use.</param>
        public NeighborhoodRBF(int[] size, RBFEnum type)
        {
            _params = new double[size.Length];

            switch (type)
            {
                case RBFEnum.Gaussian:
                    _rbf = new GaussianFunction(size.Length, _params, 0);
                    break;
                case RBFEnum.InverseMultiquadric:
                    _rbf = new InverseMultiquadricFunction(size.Length, _params, 0);
                    break;
                case RBFEnum.Multiquadric:
                    _rbf = new MultiquadricFunction(size.Length, _params, 0);
                    break;
                case RBFEnum.MexicanHat:
                    _rbf = new MexicanHatFunction(size.Length, _params, 0);
                    break;
            }
            _size = size;
            CalculateDisplacement();
        }
Пример #22
0
        /// <summary>
        /// Construct a 2d neighborhood function based on the sizes for the
        /// x and y dimensions. 
        /// </summary>
        /// <param name="type">The RBF type to use.</param>
        /// <param name="x">The size of the x-dimension.</param>
        /// <param name="y">The size of the y-dimension.</param>
        public NeighborhoodRBF(RBFEnum type,
                 int x, int y)
        {
            int[] size = new int[2];
            size[0] = x;
            size[1] = y;

            double[] centerArray = new double[2];
            centerArray[0] = 0;
            centerArray[1] = 0;

            double[] widthArray = new double[2];
            widthArray[0] = 1;
            widthArray[1] = 1;

            switch (type)
            {
                case RBFEnum.Gaussian:
                    this.rbf = new GaussianFunction(2);
                    break;
                case RBFEnum.InverseMultiquadric:
                    this.rbf = new InverseMultiquadricFunction(2);
                    break;
                case RBFEnum.Multiquadric:
                    this.rbf = new MultiquadricFunction(2);
                    break;
                case RBFEnum.MexicanHat:
                    this.rbf = new MexicanHatFunction(2);
                    break;
            }

            this.rbf.Width = 1;
            EngineArray.ArrayCopy(centerArray, this.rbf.Centers);

            this.size = size;

            CalculateDisplacement();
        }
 /// <summary>
 /// Specify specific centers and widths for the provided RBFType
 /// </summary>
 /// <param name="centers">Array containing center position. Row n contains centers for neuron n. Row n contains x elements for x number of dimensions.</param>
 /// <param name="widths">Array containing widths. Row n contains widths for neuron n. Row n contains x elements for x number of dimensions.</param>
 /// <param name="RBFType">The RBF Function to use for this layer.</param>
 public void SetRBFCentersAndWidths(double[][] centers, double[] widths, RBFEnum RBFType)
 {
     for (int i = 0; i < this.NeuronCount; i++)
     {
         SetRBFFunction(i, RBFType, centers[i], widths[i]);
     }
 }
Пример #24
0
        /// <summary>
        /// Set the gausian components to random values.
        /// </summary>
        /// <param name="dimensions">The number of dimensions in the network.</param>
        /// <param name="min">The minimum value for the centers, widths and peaks.</param>
        /// <param name="max">The maximum value for the centers, widths and peaks.</param>
        /// <param name="t">The RBF to use.</param>
        public void RandomizeRBFCentersAndWidths(int dimensions, double min, double max, RBFEnum t)
        {
            double[] centers = new double[dimensions];

            for (int i = 0; i < dimensions; i++)
            {
                centers[i] = RangeRandomizer.Randomize(min, max);
            }

            for (int i = 0; i < this.NeuronCount; i++)
            {
                SetRBFFunction(i, t, centers, RangeRandomizer.Randomize(min, max));
            }
        }
Пример #25
0
        /// <summary>
        /// Equally spaces all hidden neurons within the n dimensional variable space.
        /// </summary>
        /// <param name="minPosition">The minimum position neurons should be centered. Typically 0.</param>
        /// <param name="maxPosition">The maximum position neurons should be centered. Typically 1</param>
        /// <param name="RBFType">The RBF type to use.</param>
        /// <param name="dimensions">The number of dimensions.</param>
        /// <param name="volumeNeuronRBFWidth">The neuron width of neurons within the mesh.</param>
        /// <param name="useWideEdgeRBFs">Enables wider RBF's around the boundary of the neuron mesh.</param>
        public void SetRBFCentersAndWidthsEqualSpacing(double minPosition, double maxPosition, RBFEnum RBFType, int dimensions, double volumeNeuronRBFWidth, bool useWideEdgeRBFs)
        {
            int totalNumHiddenNeurons = NeuronCount;

            double disMinMaxPosition = Math.Abs(maxPosition - minPosition);

            //Check to make sure we have the correct number of neurons for the provided dimensions
            int expectedSideLength = (int)Math.Pow(totalNumHiddenNeurons, 1.0 / dimensions);

            if ((double)expectedSideLength != Math.Pow(totalNumHiddenNeurons, 1.0 / dimensions))
            {
                throw new Exception("Total number of RBF neurons must be some integer to the power of 'dimensions'.");
            }

            double edgeNeuronRBFWidth = 2.5 * volumeNeuronRBFWidth;

            double[][] centers = new double[totalNumHiddenNeurons][];
            double[]   widths  = new double[totalNumHiddenNeurons];

            #region buildCentersAndWidths Volume Neurons
            for (int i = 0; i < totalNumHiddenNeurons; i++)
            {
                centers[i] = new double[dimensions];

                int sideLength = expectedSideLength;

                //Evenly distribute the volume neurons.
                int temp = i;

                //First determine the centers
                for (int j = dimensions; j > 0; j--)
                {
                    //i + j * sidelength + k * sidelength ^2 + ... l * sidelength ^ n
                    //i - neuron number in x direction, i.e. 0,1,2,3
                    //j - neuron number in y direction, i.e. 0,1,2,3
                    //Following example assumes sidelength of 4
                    //e.g Neuron 5 - x position is (int)5/4 * 0.33 = 0.33
                    //then take modulus of 5%4 = 1
                    //Neuron 5 - y position is (int)1/1 * 0.33 = 0.33
                    centers[i][j - 1] = ((int)(temp / Math.Pow(sideLength, j - 1)) * (disMinMaxPosition / (sideLength - 1))) + minPosition;
                    temp = temp % (int)(Math.Pow(sideLength, j - 1));
                }

                //Now set the widths
                if ((centers[i].Contains(1) || centers[i].Contains(0)) && useWideEdgeRBFs)
                {
                    widths[i] = edgeNeuronRBFWidth;
                }
                else
                {
                    widths[i] = volumeNeuronRBFWidth;
                }

                //centers[i] = (double)(1 / (double)(neuronCount - 1)) * (double)i;
            }
            #endregion

            SetRBFCentersAndWidths(centers, widths, RBFType);
            //SaveOutNeuronCentersAndWeights(centers, widths);
        }
Пример #26
0
 public void RandomizeRBFCentersAndWidths(double min, double max, RBFEnum t)
 {
     int num2;
     int num3;
     int inputCount = this.InputCount;
     double[] centers = new double[inputCount];
     if ((((uint) inputCount) & 0) == 0)
     {
         num2 = 0;
         goto Label_004D;
     }
     Label_0037:
     while (num3 < this._flat.RBF.Length)
     {
         this.SetRBFFunction(num3, t, centers, RangeRandomizer.Randomize(min, max));
         num3++;
         if ((((uint) num3) - ((uint) num3)) > uint.MaxValue)
         {
             return;
         }
     }
     return;
     Label_004D:
     if (num2 < inputCount)
     {
         centers[num2] = RangeRandomizer.Randomize(min, max);
     }
     else
     {
         num3 = 0;
         goto Label_0037;
     }
     num2++;
     goto Label_004D;
 }
Пример #27
0
 public void SetRBFCentersAndWidthsEqualSpacing(double minPosition, double maxPosition, RBFEnum t, double volumeNeuronRBFWidth, bool useWideEdgeRBFs)
 {
     int num2;
     double num3;
     int num4;
     double num5;
     double num6;
     double[][] numArray;
     double[] numArray2;
     int num7;
     int num8;
     int num9;
     int num10;
     int num11;
     int length = this._flat.RBF.Length;
     goto Label_0257;
     Label_0013:
     num7++;
     Label_0019:
     if (num7 < length)
     {
         numArray[num7] = new double[num2];
         if (((uint) num8) >= 0)
         {
             num8 = num4;
             num9 = num7;
             goto Label_019F;
         }
         goto Label_012A;
     }
     this.SetRBFCentersAndWidths(numArray, numArray2, t);
     return;
     Label_003B:
     if ((((uint) volumeNeuronRBFWidth) | 8) == 0)
     {
         goto Label_019F;
     }
     if ((((uint) maxPosition) & 0) == 0)
     {
         goto Label_0013;
     }
     return;
     Label_012A:
     if (num10 <= 0)
     {
         bool flag = false;
         if ((((uint) num5) + ((uint) num6)) >= 0)
         {
             num11 = 0;
             while (true)
             {
                 if (num11 < numArray[0].Length)
                 {
                     if ((numArray[num7][num11] == 1.0) || (numArray[num7][num11] == 0.0))
                     {
                         flag = true;
                     }
                     num11++;
                 }
                 else if (flag && useWideEdgeRBFs)
                 {
                     numArray2[num7] = num6;
                     if (((uint) num8) > uint.MaxValue)
                     {
                         goto Label_015C;
                     }
                     if (0 != 0)
                     {
                         goto Label_003B;
                     }
                     if ((((uint) num11) & 0) == 0)
                     {
                         if ((((uint) useWideEdgeRBFs) + ((uint) maxPosition)) >= 0)
                         {
                             goto Label_0013;
                         }
                         goto Label_0257;
                     }
                 }
                 else
                 {
                     numArray2[num7] = volumeNeuronRBFWidth;
                     goto Label_003B;
                 }
                 if ((((uint) num9) + ((uint) maxPosition)) < 0)
                 {
                     goto Label_0183;
                 }
             }
         }
         goto Label_0230;
     }
     Label_015C:
     numArray[num7][num10 - 1] = (((int) (((double) num9) / Math.Pow((double) num8, (double) (num10 - 1)))) * (num3 / ((double) (num8 - 1)))) + minPosition;
     Label_0183:
     num9 = num9 % ((int) Math.Pow((double) num8, (double) (num10 - 1)));
     goto Label_01BA;
     Label_019F:
     num10 = num2;
     if ((((uint) num4) + ((uint) useWideEdgeRBFs)) <= uint.MaxValue)
     {
         goto Label_012A;
     }
     Label_01BA:
     if (((uint) num11) >= 0)
     {
         num10--;
     }
     goto Label_012A;
     Label_0230:
     if (num4 != num5)
     {
         throw new NeuralNetworkError("Total number of RBF neurons must be some integer to the power of 'dimensions'.\n" + Format.FormatDouble((double) num4, 5) + " <> " + Format.FormatDouble(num5, 5));
     }
     num6 = 2.5 * volumeNeuronRBFWidth;
     numArray = new double[length][];
     numArray2 = new double[length];
     num7 = 0;
     goto Label_0019;
     Label_0257:
     num2 = this.InputCount;
     num3 = Math.Abs((double) (maxPosition - minPosition));
     num4 = (int) Math.Pow((double) length, 1.0 / ((double) num2));
     num5 = Math.Pow((double) length, 1.0 / ((double) num2));
     goto Label_0230;
 }
Пример #28
0
        /// <summary>
        /// Equally spaces all hidden neurons within the n dimensional variable
        /// space.
        /// </summary>
        ///
        /// <param name="minPosition">The minimum position neurons should be centered. Typically 0.</param>
        /// <param name="maxPosition">The maximum position neurons should be centered. Typically 1</param>
        /// <param name="t">The RBF type.</param>
        /// <param name="volumeNeuronRBFWidth">The neuron width of neurons within the mesh.</param>
        /// <param name="useWideEdgeRBFs">Enables wider RBF's around the boundary of the neuron mesh.</param>
        public void SetRBFCentersAndWidthsEqualSpacing(
            double minPosition, double maxPosition,
            RBFEnum t, double volumeNeuronRBFWidth,
            bool useWideEdgeRBFs)
        {
            int totalNumHiddenNeurons = _flat.RBF.Length;

            int    dimensions        = InputCount;
            double disMinMaxPosition = Math.Abs(maxPosition - minPosition);

            // Check to make sure we have the correct number of neurons for the
            // provided dimensions
            var    expectedSideLength = (int)Math.Pow(totalNumHiddenNeurons, 1.0d / dimensions);
            double cmp = Math.Pow(totalNumHiddenNeurons, 1.0d / dimensions);

            if (expectedSideLength != cmp)
            {
                throw new NeuralNetworkError(
                          "Total number of RBF neurons must be some integer to the power of 'dimensions'.\n"
                          + Format.FormatDouble(expectedSideLength, 5)
                          + " <> " + Format.FormatDouble(cmp, 5));
            }

            double edgeNeuronRBFWidth = 2.5d * volumeNeuronRBFWidth;

            var centers = new double[totalNumHiddenNeurons][];
            var widths  = new double[totalNumHiddenNeurons];

            for (int i = 0; i < totalNumHiddenNeurons; i++)
            {
                centers[i] = new double[dimensions];

                int sideLength = expectedSideLength;

                // Evenly distribute the volume neurons.
                int temp = i;

                // First determine the centers
                for (int j = dimensions; j > 0; j--)
                {
                    // i + j * sidelength + k * sidelength ^2 + ... l * sidelength ^
                    // n
                    // i - neuron number in x direction, i.e. 0,1,2,3
                    // j - neuron number in y direction, i.e. 0,1,2,3
                    // Following example assumes sidelength of 4
                    // e.g Neuron 5 - x position is (int)5/4 * 0.33 = 0.33
                    // then take modulus of 5%4 = 1
                    // Neuron 5 - y position is (int)1/1 * 0.33 = 0.33
                    centers[i][j - 1] = ((int)(temp / Math.Pow(sideLength, j - 1)) * (disMinMaxPosition / (sideLength - 1)))
                                        + minPosition;
                    temp = temp % (int)(Math.Pow(sideLength, j - 1));
                }

                // Now set the widths
                bool contains = false;

                for (int z = 0; z < centers[0].Length; z++)
                {
                    if ((centers[i][z] == 1.0d) || (centers[i][z] == 0.0d))
                    {
                        contains = true;
                    }
                }

                if (contains && useWideEdgeRBFs)
                {
                    widths[i] = edgeNeuronRBFWidth;
                }
                else
                {
                    widths[i] = volumeNeuronRBFWidth;
                }
            }

            SetRBFCentersAndWidths(centers, widths, t);
        }
Пример #29
0
 public void SetRBFFunction(int index, RBFEnum t, double[] centers, double width)
 {
     if (t == RBFEnum.Gaussian)
     {
         this._flat.RBF[index] = new GaussianFunction(0.5, centers, width);
     }
     else
     {
         if (t == RBFEnum.Multiquadric)
         {
             this._flat.RBF[index] = new MultiquadricFunction(0.5, centers, width);
             if (-2 != 0)
             {
                 return;
             }
         }
         else if (t != RBFEnum.InverseMultiquadric)
         {
             return;
         }
         this._flat.RBF[index] = new InverseMultiquadricFunction(0.5, centers, width);
     }
 }
Пример #30
0
        public NeighborhoodRBF(RBFEnum type, int x, int y)
        {
            int[] numArray;
            double[] numArray2;
            goto Label_0152;
            Label_000B:
            EngineArray.ArrayCopy(numArray2, this._x542ac40d5d0f20b7.Centers);
            this._x0ceec69a97f73617 = numArray;
            if (((uint) y) > uint.MaxValue)
            {
                goto Label_0122;
            }
            this.x2d3eee42a645354a();
            if ((((uint) y) + ((uint) y)) > uint.MaxValue)
            {
                goto Label_00EB;
            }
            if (-2 != 0)
            {
                return;
            }
            goto Label_0152;
            Label_0068:
            this._x542ac40d5d0f20b7.Width = 1.0;
            Label_00E4:
            if (8 != 0)
            {
                if (0 == 0)
                {
                    goto Label_000B;
                }
                goto Label_0129;
            }
            Label_00EB:
            numArray2[0] = 0.0;
            numArray2[1] = 0.0;
            double[] numArray3 = new double[] { 1.0, 1.0 };
            Label_0122:
            switch (type)
            {
                case RBFEnum.Gaussian:
                    this._x542ac40d5d0f20b7 = new GaussianFunction(2);
                    goto Label_0068;

                case RBFEnum.Multiquadric:
                    this._x542ac40d5d0f20b7 = new MultiquadricFunction(2);
                    goto Label_0068;

                case RBFEnum.InverseMultiquadric:
                    this._x542ac40d5d0f20b7 = new InverseMultiquadricFunction(2);
                    goto Label_0068;

                case RBFEnum.MexicanHat:
                    this._x542ac40d5d0f20b7 = new MexicanHatFunction(2);
                    if (((0 == 0) && (-1 != 0)) && (0 != 0))
                    {
                        goto Label_00E4;
                    }
                    goto Label_0068;

                default:
                    goto Label_0068;
            }
            Label_0129:
            numArray[0] = x;
            numArray[1] = y;
            numArray2 = new double[2];
            if ((((uint) y) - ((uint) y)) <= uint.MaxValue)
            {
                goto Label_00EB;
            }
            goto Label_000B;
            Label_0152:
            if ((((uint) x) - ((uint) x)) < 0)
            {
                goto Label_0068;
            }
            numArray = new int[2];
            goto Label_0129;
        }
 private void SetRBFFunction(int RBFIndex, RBFEnum RBFType, double[] centers, double width)
 {
     if (RBFType == RBFEnum.Gaussian)
         this.radialBasisFunction[RBFIndex] = new GaussianFunction(0.5, centers, width);
     else if (RBFType == RBFEnum.Multiquadric)
         this.radialBasisFunction[RBFIndex] = new MultiquadricFunction(0.5, centers, width);
     else if (RBFType == RBFEnum.InverseMultiquadric)
         this.radialBasisFunction[RBFIndex] = new InverseMultiquadricFunction(0.5, centers, width);
 }
        /// <summary>
        /// Set the gausian components to random values.
        /// </summary>
        /// <param name="dimensions">The number of dimensions in the network.</param>
        /// <param name="min">The minimum value for the centers, widths and peaks.</param>
        /// <param name="max">The maximum value for the centers, widths and peaks.</param>
        /// <param name="t">The RBF to use.</param>
        public void RandomizeRBFCentersAndWidths(int dimensions, double min, double max, RBFEnum t)
        {
            double[] centers = new double[dimensions];

            for (int i = 0; i < dimensions; i++)
            {
                centers[i] = RangeRandomizer.Randomize(min, max);
            }

            for (int i = 0; i < this.NeuronCount; i++)
            {
                SetRBFFunction(i, t, centers, RangeRandomizer.Randomize(min, max));
            }
        }
Пример #33
0
 /// <summary>
 /// Set an RBF function.
 /// </summary>
 ///
 /// <param name="index">The index to set.</param>
 /// <param name="t">The function type.</param>
 /// <param name="centers">The centers.</param>
 /// <param name="width">The width.</param>
 public void SetRBFFunction(int index, RBFEnum t,
                            double[] centers, double width)
 {
     if (t == RBFEnum.Gaussian)
     {
         _flat.RBF[index] = new GaussianFunction(0.5d, centers,
                                                width);
     }
     else if (t == RBFEnum.Multiquadric)
     {
         _flat.RBF[index] = new MultiquadricFunction(0.5d, centers,
                                                    width);
     }
     else if (t == RBFEnum.InverseMultiquadric)
     {
         _flat.RBF[index] = new InverseMultiquadricFunction(0.5d,
                                                           centers, width);
     }
 }
Пример #34
0
        /// <summary>
        /// Equally spaces all hidden neurons within the n dimensional variable
        /// space.
        /// </summary>
        ///
        /// <param name="minPosition">The minimum position neurons should be centered. Typically 0.</param>
        /// <param name="maxPosition">The maximum position neurons should be centered. Typically 1</param>
        /// <param name="t">The RBF type.</param>
        /// <param name="volumeNeuronRBFWidth">The neuron width of neurons within the mesh.</param>
        /// <param name="useWideEdgeRBFs">Enables wider RBF's around the boundary of the neuron mesh.</param>
        public void SetRBFCentersAndWidthsEqualSpacing(
            double minPosition, double maxPosition,
            RBFEnum t, double volumeNeuronRBFWidth,
            bool useWideEdgeRBFs)
        {
            int totalNumHiddenNeurons = _flat.RBF.Length;

            int dimensions = InputCount;
            double disMinMaxPosition = Math.Abs(maxPosition - minPosition);

            // Check to make sure we have the correct number of neurons for the
            // provided dimensions
            var expectedSideLength = (int) Math.Pow(totalNumHiddenNeurons, 1.0d/dimensions);
            double cmp = Math.Pow(totalNumHiddenNeurons, 1.0d/dimensions);

            if (expectedSideLength != cmp)
            {
                throw new NeuralNetworkError(
                    "Total number of RBF neurons must be some integer to the power of 'dimensions'.\n"
                    + Format.FormatDouble(expectedSideLength, 5)
                    + " <> " + Format.FormatDouble(cmp, 5));
            }

            double edgeNeuronRBFWidth = 2.5d*volumeNeuronRBFWidth;

            var centers = new double[totalNumHiddenNeurons][];
            var widths = new double[totalNumHiddenNeurons];

            for (int i = 0; i < totalNumHiddenNeurons; i++)
            {
                centers[i] = new double[dimensions];

                int sideLength = expectedSideLength;

                // Evenly distribute the volume neurons.
                int temp = i;

                // First determine the centers
                for (int j = dimensions; j > 0; j--)
                {
                    // i + j * sidelength + k * sidelength ^2 + ... l * sidelength ^
                    // n
                    // i - neuron number in x direction, i.e. 0,1,2,3
                    // j - neuron number in y direction, i.e. 0,1,2,3
                    // Following example assumes sidelength of 4
                    // e.g Neuron 5 - x position is (int)5/4 * 0.33 = 0.33
                    // then take modulus of 5%4 = 1
                    // Neuron 5 - y position is (int)1/1 * 0.33 = 0.33
                    centers[i][j - 1] = ((int) (temp/Math.Pow(sideLength, j - 1))*(disMinMaxPosition/(sideLength - 1)))
                                        + minPosition;
                    temp = temp%(int) (Math.Pow(sideLength, j - 1));
                }

                // Now set the widths
                bool contains = false;

                for (int z = 0; z < centers[0].Length; z++)
                {
                    if ((centers[i][z] == 1.0d) || (centers[i][z] == 0.0d))
                    {
                        contains = true;
                    }
                }

                if (contains && useWideEdgeRBFs)
                {
                    widths[i] = edgeNeuronRBFWidth;
                }
                else
                {
                    widths[i] = volumeNeuronRBFWidth;
                }
            }

            SetRBFCentersAndWidths(centers, widths, t);
        }
Пример #35
0
 /// <summary>
 /// Array containing center position. Row n contains centers for neuron n.
 /// Row n contains x elements for x number of dimensions.
 /// </summary>
 ///
 /// <param name="centers">The centers.</param>
 /// <param name="widths"></param>
 /// <param name="t">The RBF Function to use for this layer.</param>
 public void SetRBFCentersAndWidths(double[][] centers,
                                    double[] widths, RBFEnum t)
 {
     for (int i = 0; i < _flat.RBF.Length; i++)
     {
         SetRBFFunction(i, t, centers[i], widths[i]);
     }
 }
Пример #36
0
        /// <summary>
        /// Set the RBF components to random values.
        /// </summary>
        ///
        /// <param name="min">Minimum random value.</param>
        /// <param name="max">Max random value.</param>
        /// <param name="t">The type of RBF to use.</param>
        public void RandomizeRBFCentersAndWidths(double min,
                                                 double max, RBFEnum t)
        {
            int dimensions = InputCount;
            var centers = new double[dimensions];

            for (int i = 0; i < dimensions; i++)
            {
                centers[i] = RangeRandomizer.Randomize(min, max);
            }

            for (int i = 0; i < _flat.RBF.Length; i++)
            {
                SetRBFFunction(i, t, centers, RangeRandomizer.Randomize(min, max));
            }
        }
        /// <summary>
        /// Equally spaces all hidden neurons within the n dimensional variable space.
        /// </summary>
        /// <param name="minPosition">The minimum position neurons should be centered. Typically 0.</param>
        /// <param name="maxPosition">The maximum position neurons should be centered. Typically 1</param>
        /// <param name="RBFType">The RBF type to use.</param>
        /// <param name="dimensions">The number of dimensions.</param>
        /// <param name="volumeNeuronRBFWidth">The neuron width of neurons within the mesh.</param>
        /// <param name="useWideEdgeRBFs">Enables wider RBF's around the boundary of the neuron mesh.</param>
        public void SetRBFCentersAndWidthsEqualSpacing(double minPosition, double maxPosition, RBFEnum RBFType, int dimensions, double volumeNeuronRBFWidth, bool useWideEdgeRBFs)
        {
            int totalNumHiddenNeurons = NeuronCount;

            double disMinMaxPosition = Math.Abs(maxPosition - minPosition);

            //Check to make sure we have the correct number of neurons for the provided dimensions
            int expectedSideLength = (int)Math.Pow(totalNumHiddenNeurons, 1.0 / dimensions);
            if ((double)expectedSideLength != Math.Pow(totalNumHiddenNeurons, 1.0 / dimensions))
                throw new Exception("Total number of RBF neurons must be some integer to the power of 'dimensions'.");

            double edgeNeuronRBFWidth = 2.5 * volumeNeuronRBFWidth;

            double[][] centers = new double[totalNumHiddenNeurons][];
            double[] widths = new double[totalNumHiddenNeurons];

            #region buildCentersAndWidths Volume Neurons
            for (int i = 0; i < totalNumHiddenNeurons; i++)
            {
                centers[i] = new double[dimensions];

                int sideLength = expectedSideLength;

                //Evenly distribute the volume neurons.
                int temp = i;

                //First determine the centers
                for (int j = dimensions; j > 0; j--)
                {
                    //i + j * sidelength + k * sidelength ^2 + ... l * sidelength ^ n
                    //i - neuron number in x direction, i.e. 0,1,2,3
                    //j - neuron number in y direction, i.e. 0,1,2,3
                    //Following example assumes sidelength of 4
                    //e.g Neuron 5 - x position is (int)5/4 * 0.33 = 0.33
                    //then take modulus of 5%4 = 1
                    //Neuron 5 - y position is (int)1/1 * 0.33 = 0.33
                    centers[i][j - 1] = ((int)(temp / Math.Pow(sideLength, j - 1)) * (disMinMaxPosition / (sideLength - 1))) + minPosition;
                    temp = temp % (int)(Math.Pow(sideLength, j - 1));
                }

                //Now set the widths
                if ((centers[i].Contains(1) || centers[i].Contains(0)) && useWideEdgeRBFs)
                {
                    widths[i] = edgeNeuronRBFWidth;
                }
                else
                {
                    widths[i] = volumeNeuronRBFWidth;
                }

                //centers[i] = (double)(1 / (double)(neuronCount - 1)) * (double)i;
            }
            #endregion

            SetRBFCentersAndWidths(centers, widths, RBFType);
            //SaveOutNeuronCentersAndWeights(centers, widths);
        }