Ejemplo n.º 1
0
 /// <summary>
 /// Construct a multi-dimensional neighborhood function. 
 /// </summary>
 /// <param name="size">The sizes of each dimension.</param>
 /// <param name="rbf">The multi-dimensional RBF to use.</param>
 public NeighborhoodRBF(int[] size,
         IRadialBasisFunction rbf)
 {
     this.rbf = rbf;
     this.size = size;
     CalculateDisplacement();
 }
Ejemplo n.º 2
0
        /// <summary>
        /// Perform one iteration.
        /// </summary>
        ///
        public override sealed void Iteration()
        {
            int length = network.RBF.Length;

            var funcs = new IRadialBasisFunction[length];

            // Iteration over neurons and determine the necessaries
            for (int i = 0; i < length; i++)
            {
                IRadialBasisFunction basisFunc = network.RBF[i];

                funcs[i] = basisFunc;

                // This is the value that is changed using other training methods.
                // weights[i] =
                // network.Structure.Synapses[0].WeightMatrix.Data[i][j];
            }

            ObjectPair <double[][], double[][]> data = TrainingSetUtil
                                                       .TrainingToArray(Training);

            double[][] matrix = EngineArray.AllocateDouble2D(length, network.OutputCount);

            FlatToMatrix(network.Flat.Weights, 0, matrix);
            Error = SVD.Svdfit(data.A, data.B, matrix, funcs);
            MatrixToFlat(matrix, network.Flat.Weights, 0);
        }
Ejemplo n.º 3
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);
            }
        }
Ejemplo n.º 4
0
 public RBFNetwork(int inputCount, int outputCount, IRadialBasisFunction[] rbf)
 {
     FlatNetworkRBF krbf = new FlatNetworkRBF(inputCount, rbf.Length, outputCount, rbf) {
         RBF = rbf
     };
     this._flat = krbf;
 }
Ejemplo n.º 5
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();
        }
Ejemplo n.º 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);
            }
        }
Ejemplo n.º 7
0
        private IRadialBasisFunction[] LoadAllRBF(ReadXML xmlin)
        {
            IList <IRadialBasisFunction> rbfs = new List <IRadialBasisFunction>();

            while (xmlin.ReadToTag())
            {
                if (xmlin.IsIt(PROPERTY_RBF, false))
                {
                    break;
                }
                else
                {
                    String name = xmlin.LastTag.Name;
                    IRadialBasisFunction rbf = LoadRBF(name, xmlin);
                    rbfs.Add(rbf);
                }
            }

            IRadialBasisFunction[] result = new IRadialBasisFunction[rbfs.Count];

            for (int i = 0; i < rbfs.Count; i++)
            {
                result[i] = rbfs[i];
            }

            return(result);
        }
        /// <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;
        }
Ejemplo n.º 9
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;
            }
        }
Ejemplo n.º 10
0
        /// <summary>
        /// Compute the values before sending output to the next layer.
        /// This function allows the activation functions to be called.
        /// </summary>
        /// <param name="pattern">The incoming Project.</param>
        /// <returns>The output from this layer.</returns>
        public override INeuralData Compute(INeuralData pattern)
        {
            INeuralData result = new BasicNeuralData(NeuronCount);

            for (int i = 0; i < NeuronCount; i++)
            {
                if (this.radialBasisFunction[i] == null)
                {
                    String str =
                        "Error, must define radial functions for each neuron";
#if logging
                    if (RadialBasisFunctionLayer.logger.IsErrorEnabled)
                    {
                        RadialBasisFunctionLayer.logger.Error(str);
                    }
#endif
                    throw new NeuralNetworkError(str);
                }

                IRadialBasisFunction f = this.radialBasisFunction[i];

                if (pattern.Data.Length != f.Dimensions)
                {
                    throw new Exception("Inputs must equal the number of dimensions.");
                }

                result[i] = f.Calculate(pattern.Data);
            }

            return(result);
        }
Ejemplo n.º 11
0
 /// <summary>
 /// Construct a multi-dimensional neighborhood function.
 /// </summary>
 /// <param name="size">The sizes of each dimension.</param>
 /// <param name="rbf">The multi-dimensional RBF to use.</param>
 public NeighborhoodRBF(int[] size,
                        IRadialBasisFunction rbf)
 {
     this.rbf  = rbf;
     this.size = size;
     CalculateDisplacement();
 }
Ejemplo n.º 12
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);
     }
 }
Ejemplo n.º 13
0
        /// <summary>
        /// Construct an RBF flat network.
        /// </summary>
        ///
        /// <param name="inputCount">The number of input neurons. (also the number of dimensions)</param>
        /// <param name="hiddenCount">The number of hidden neurons.</param>
        /// <param name="outputCount">The number of output neurons.</param>
        /// <param name="rbf"></param>
        public FlatNetworkRBF(int inputCount, int hiddenCount,
                              int outputCount, IRadialBasisFunction[] rbf)
        {
            var layers = new FlatLayer[3];
            _rbf = rbf;

            layers[0] = new FlatLayer(new ActivationLinear(), inputCount, 0.0d);
            layers[1] = new FlatLayer(new ActivationLinear(), hiddenCount, 0.0d);
            layers[2] = new FlatLayer(new ActivationLinear(), outputCount, 0.0d);

            Init(layers);
        }
Ejemplo n.º 14
0
Archivo: SVD.cs Proyecto: jongh0/MTree
        /// <summary>
        /// Perform a SVD fit.
        /// </summary>
        /// <param name="x">The X matrix.</param>
        /// <param name="y">The Y matrix.</param>
        /// <param name="a">The A matrix.</param>
        /// <param name="funcs">The RBF functions.</param>
        /// <returns>The fit.</returns>
        public static double Svdfit(double[][] x, double[][] y, double[][] a,
                                    IRadialBasisFunction[] funcs)
        {
            int i, j, k;
            double wmax, tmp, thresh, sum, TOL = 1e-13d;

            //Allocated memory for svd matrices
            double[][] u = EngineArray.AllocateDouble2D(x.Length, funcs.Length);
            double[][] v = EngineArray.AllocateDouble2D(funcs.Length, funcs.Length);
            var w = new double[funcs.Length];

            //Fill input matrix with values based on fitting functions and input coordinates 
            for (i = 0; i < x.Length; i++)
            {
                for (j = 0; j < funcs.Length; j++)
                    u[i][j] = funcs[j].Calculate(x[i]);
            }

            //Perform decomposition
            Svdcmp(u, w, v);

            //Check for w values that are close to zero and replace them with zeros such that they are ignored in backsub
            wmax = 0;
            for (j = 0; j < funcs.Length; j++)
                if (w[j] > wmax)
                    wmax = w[j];

            thresh = TOL*wmax;

            for (j = 0; j < funcs.Length; j++)
                if (w[j] < thresh)
                    w[j] = 0;

            //Perform back substitution to get result
            Svdbksb(u, w, v, y, a);

            //Calculate chi squared for the fit
            double chisq = 0;
            for (k = 0; k < y[0].Length; k++)
            {
                for (i = 0; i < y.Length; i++)
                {
                    sum = 0.0d;
                    for (j = 0; j < funcs.Length; j++)
                        sum += a[j][k]*funcs[j].Calculate(x[i]);
                    tmp = (y[i][k] - sum);
                    chisq += tmp*tmp;
                }
            }

            return Math.Sqrt(chisq/(y.Length*y[0].Length));
        }
Ejemplo n.º 15
0
 public FlatNetworkRBF(int inputCount, int hiddenCount, int outputCount, IRadialBasisFunction[] rbf)
 {
     FlatLayer[] layers = new FlatLayer[3];
     this._rbf = rbf;
     layers[0] = new FlatLayer(new ActivationLinear(), inputCount, 0.0);
     do
     {
         layers[1] = new FlatLayer(new ActivationLinear(), hiddenCount, 0.0);
     }
     while ((((uint) hiddenCount) & 0) != 0);
     if (2 != 0)
     {
         layers[2] = new FlatLayer(new ActivationLinear(), outputCount, 0.0);
         base.Init(layers);
     }
 }
Ejemplo n.º 16
0
        /// <summary>
        /// Construct an RBF flat network. 
        /// </summary>
        /// <param name="inputCount">The number of input neurons. (also the number of dimensions)</param>
        /// <param name="hiddenCount">The number of hidden neurons.</param>
        /// <param name="outputCount">The number of output neurons.</param>
        /// <param name="rbf">The RBF's to use.</param>
        public FlatNetworkRBF(int inputCount, int hiddenCount,
                 int outputCount, IRadialBasisFunction[] rbf)
        {
            this.rbf = rbf;
            FlatLayer[] layers = new FlatLayer[3];

            double[] slope = new double[1];
            slope[0] = 1.0;

            layers[0] = new FlatLayer(new ActivationLinear(), inputCount, 0.0,
                    slope);
            layers[1] = new FlatLayer(new ActivationLinear(), hiddenCount, 0.0,
                    slope);
            layers[2] = new FlatLayer(new ActivationLinear(), outputCount, 0.0,
                    slope);

            Init(layers);
        }
Ejemplo n.º 17
0
        /// <summary>
        /// Load a RBF layer.
        /// </summary>
        /// <param name="xmlin">The XML to read from.</param>
        /// <returns>The object that was loaded.</returns>
        public IEncogPersistedObject Load(ReadXML xmlin)
        {
            int neuronCount = 0;
            int x           = 0;
            int y           = 0;
            int dimensions  = 1;

            IRadialBasisFunction[] rbfs = new IRadialBasisFunction[0];

            String end = xmlin.LastTag.Name;

            while (xmlin.ReadToTag())
            {
                if (xmlin.IsIt(BasicLayerPersistor.PROPERTY_NEURONS, true))
                {
                    neuronCount = xmlin.ReadIntToTag();
                }
                else if (xmlin.IsIt(BasicLayerPersistor.PROPERTY_X, true))
                {
                    x = xmlin.ReadIntToTag();
                }
                else if (xmlin.IsIt(BasicLayerPersistor.PROPERTY_Y, true))
                {
                    y = xmlin.ReadIntToTag();
                }
                else if (xmlin.IsIt(RadialBasisFunctionLayerPersistor.PROPERTY_RBF,
                                    true))
                {
                    rbfs = LoadAllRBF(xmlin);
                }
                else if (xmlin.IsIt(end, false))
                {
                    break;
                }
            }

            RadialBasisFunctionLayer layer = new RadialBasisFunctionLayer(neuronCount);

            layer.RadialBasisFunction = rbfs;
            layer.X = x;
            layer.Y = y;

            return(layer);
        }
Ejemplo n.º 18
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();
        }
Ejemplo n.º 19
0
        private IRadialBasisFunction LoadRBF(String name, ReadXML xmlin)
        {
            String clazz = ReflectionUtil.ResolveEncogClass(name);

            if (clazz == null)
            {
                throw new NeuralNetworkError("Unknown RBF function type: " + name);
            }

            IRadialBasisFunction result = (IRadialBasisFunction)ReflectionUtil.LoadObject(clazz);

            while (xmlin.ReadToTag())
            {
                if (xmlin.IsIt(name, false))
                {
                    break;
                }
                else if (xmlin.IsIt(PROPERTY_CENTERS, true))
                {
                    String   str     = xmlin.ReadTextToTag();
                    double[] centers = NumberList.FromList(CSVFormat.EG_FORMAT, str);
                    result.Centers = centers;
                }
                else if (xmlin.IsIt(PROPERTY_PEAK, true))
                {
                    String str = xmlin.ReadTextToTag();
                    double d   = Double.Parse(str);
                    result.Peak = d;
                }
                else if (xmlin.IsIt(PROPERTY_WIDTH, true))
                {
                    String str = xmlin.ReadTextToTag();
                    double d   = Double.Parse(str);
                    result.Width = d;
                }
            }

            return(result);
        }
        /// <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;
        }
Ejemplo n.º 21
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();
        }
Ejemplo n.º 22
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)
        {
            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;
            }
            _size = size;
            CalculateDisplacement();
        }
Ejemplo n.º 23
0
 /// <summary>
 /// Construct the neighborhood function with the specified radial function.
 /// Generally this will be a Gaussian function but any RBF should do.
 /// </summary>
 /// <param name="radial">The radial basis function to use.</param>
 public NeighborhoodSingleRBF(IRadialBasisFunction radial)
 {
     this.radial = radial;
 }
 /// <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)
 {
     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;
     }
     _size = size;
     CalculateDisplacement();
 }
Ejemplo n.º 25
0
 public override sealed void Iteration()
 {
     IRadialBasisFunction function;
     ObjectPair<double[][], double[][]> pair;
     double[][] numArray;
     int length = this.x87a7fc6a72741c2e.RBF.Length;
     IRadialBasisFunction[] funcs = new IRadialBasisFunction[length];
     int index = 0;
     goto Label_00A7;
     Label_0013:
     this.FlatToMatrix(this.x87a7fc6a72741c2e.Flat.Weights, 0, numArray);
     this.Error = SVD.Svdfit(pair.A, pair.B, numArray, funcs);
     this.MatrixToFlat(numArray, this.x87a7fc6a72741c2e.Flat.Weights, 0);
     return;
     Label_00A7:
     if (index < length)
     {
         function = this.x87a7fc6a72741c2e.RBF[index];
     }
     else
     {
         pair = TrainingSetUtil.TrainingToArray(this.Training);
         numArray = EngineArray.AllocateDouble2D(length, this.x87a7fc6a72741c2e.OutputCount);
         if (4 != 0)
         {
             goto Label_0013;
         }
     }
     funcs[index] = function;
     if ((((uint) index) | uint.MaxValue) == 0)
     {
         return;
     }
     index++;
     if (-2147483648 == 0)
     {
         goto Label_0013;
     }
     goto Label_00A7;
 }
 /// <summary>
 /// Construct the neighborhood function with the specified radial function.
 /// Generally this will be a Gaussian function but any RBF should do. 
 /// </summary>
 /// <param name="radial">The radial basis function to use.</param>
 public NeighborhoodSingleRBF(IRadialBasisFunction radial)
 {
     this.radial = radial;
 }
 /// <summary>
 /// Construct the neighborhood function with the specified radial function.
 /// Generally this will be a Gaussian function but any RBF should do.
 /// </summary>
 ///
 /// <param name="radial">The radial basis function to use.</param>
 public NeighborhoodRBF1D(IRadialBasisFunction radial)
 {
     _radial = radial;
 }
        private IRadialBasisFunction[] LoadAllRBF(ReadXML xmlin)
        {

            IList<IRadialBasisFunction> rbfs = new List<IRadialBasisFunction>();

            while (xmlin.ReadToTag())
            {
                if (xmlin.IsIt(PROPERTY_RBF, false))
                {
                    break;
                }
                else
                {
                    String name = xmlin.LastTag.Name;
                    IRadialBasisFunction rbf = LoadRBF(name, xmlin);
                    rbfs.Add(rbf);
                }
            }

            IRadialBasisFunction[] result = new IRadialBasisFunction[rbfs.Count];

            for (int i = 0; i < rbfs.Count; i++)
                result[i] = rbfs[i];

            return result;
        }
        /// <summary>
        /// Load a RBF layer. 
        /// </summary>
        /// <param name="xmlin">The XML to read from.</param>
        /// <returns>The object that was loaded.</returns>
        public IEncogPersistedObject Load(ReadXML xmlin)
        {
            int neuronCount = 0;
            int x = 0;
            int y = 0;
            int dimensions = 1;
            IRadialBasisFunction[] rbfs = new IRadialBasisFunction[0];

            String end = xmlin.LastTag.Name;

            while (xmlin.ReadToTag())
            {
                if (xmlin.IsIt(BasicLayerPersistor.PROPERTY_NEURONS, true))
                {
                    neuronCount = xmlin.ReadIntToTag();
                }
                else if (xmlin.IsIt(BasicLayerPersistor.PROPERTY_X, true))
                {
                    x = xmlin.ReadIntToTag();
                }
                else if (xmlin.IsIt(BasicLayerPersistor.PROPERTY_Y, true))
                {
                    y = xmlin.ReadIntToTag();
                }
                else if (xmlin.IsIt(RadialBasisFunctionLayerPersistor.PROPERTY_RBF,
                      true))
                {
                    rbfs = LoadAllRBF(xmlin);
                }
                else if (xmlin.IsIt(end, false))
                {
                    break;
                }
            }

            RadialBasisFunctionLayer layer = new RadialBasisFunctionLayer(neuronCount);
            layer.RadialBasisFunction = rbfs;
            layer.X = x;
            layer.Y = y;

            return layer;
        }
Ejemplo n.º 30
0
 public NeighborhoodRBF1D(IRadialBasisFunction radial)
 {
     this._x69265a675586f26d = radial;
 }
Ejemplo n.º 31
0
        /// <summary>
        /// Internal function to increase the neuron count. This will add a
        /// zero-weight neuron to this layer. 
        /// </summary>
        /// <param name="layer">The layer to increase.</param>
        /// <param name="neuronCount">The new neuron count.</param>
        private void IncreaseNeuronCount(ILayer layer, int neuronCount)
        {
            // adjust the bias
            double[] newBias = new double[neuronCount];
            if (layer.HasBias)
            {
                for (int i = 0; i < layer.NeuronCount; i++)
                {
                    newBias[i] = layer.BiasWeights[i];
                }

                layer.BiasWeights = newBias;
            }

            // adjust the outbound weight matrixes
            foreach (ISynapse synapse in layer.Next)
            {
                if (synapse.WeightMatrix != null)
                {
                    Matrix newMatrix = new Matrix(neuronCount, synapse
                            .ToNeuronCount);
                    // copy existing matrix to new matrix
                    for (int row = 0; row < layer.NeuronCount; row++)
                    {
                        for (int col = 0; col < synapse.ToNeuronCount; col++)
                        {
                            newMatrix[row, col] = synapse.WeightMatrix[row, col];
                        }
                    }
                    synapse.WeightMatrix = newMatrix;
                }
            }

            // adjust the inbound weight matrixes
            ICollection<ISynapse> inboundSynapses = this.network.Structure
                    .GetPreviousSynapses(layer);

            foreach (ISynapse synapse in inboundSynapses)
            {
                if (synapse.WeightMatrix != null)
                {
                    Matrix newMatrix = new Matrix(synapse.FromNeuronCount,
                            neuronCount);
                    // copy existing matrix to new matrix
                    for (int row = 0; row < synapse.FromNeuronCount; row++)
                    {
                        for (int col = 0; col < synapse.ToNeuronCount; col++)
                        {
                            newMatrix[row, col] = synapse.WeightMatrix[row, col];
                        }
                    }
                    synapse.WeightMatrix = newMatrix;
                }
            }

            // adjust the bias
            if (layer.HasBias)
            {
                double[] newBias2 = new double[neuronCount];

                for (int i = 0; i < layer.NeuronCount; i++)
                {
                    newBias2[i] = layer.BiasWeights[i];
                }
                layer.BiasWeights = newBias2;
            }

            // adjust RBF
            if (layer is RadialBasisFunctionLayer)
            {
                RadialBasisFunctionLayer rbf = (RadialBasisFunctionLayer)layer;
                IRadialBasisFunction[] newRBF = new IRadialBasisFunction[neuronCount];
                for (int i = 0; i < rbf.RadialBasisFunction.Length; i++)
                {
                    newRBF[i] = rbf.RadialBasisFunction[i];
                }

                for (int i = rbf.RadialBasisFunction.Length; i < neuronCount; i++)
                {
                    newRBF[i] = new GaussianFunction(ThreadSafeRandom.NextDouble() - 0.5,
                         ThreadSafeRandom.NextDouble(), ThreadSafeRandom.NextDouble() - 0.5);
                }

                rbf.RadialBasisFunction = newRBF;

            }

            // finally, up the neuron count
            layer.NeuronCount = neuronCount;
        }
Ejemplo n.º 32
0
        /// <summary>
        /// Internal function to increase the neuron count. This will add a
        /// zero-weight neuron to this layer.
        /// </summary>
        /// <param name="layer">The layer to increase.</param>
        /// <param name="neuronCount">The new neuron count.</param>
        private void IncreaseNeuronCount(ILayer layer, int neuronCount)
        {
            // adjust the bias
            double[] newBias = new double[neuronCount];
            if (layer.HasBias)
            {
                for (int i = 0; i < layer.NeuronCount; i++)
                {
                    newBias[i] = layer.BiasWeights[i];
                }

                layer.BiasWeights = newBias;
            }

            // adjust the outbound weight matrixes
            foreach (ISynapse synapse in layer.Next)
            {
                if (synapse.WeightMatrix != null)
                {
                    Matrix newMatrix = new Matrix(neuronCount, synapse
                                                  .ToNeuronCount);
                    // copy existing matrix to new matrix
                    for (int row = 0; row < layer.NeuronCount; row++)
                    {
                        for (int col = 0; col < synapse.ToNeuronCount; col++)
                        {
                            newMatrix[row, col] = synapse.WeightMatrix[row, col];
                        }
                    }
                    synapse.WeightMatrix = newMatrix;
                }
            }

            // adjust the inbound weight matrixes
            ICollection <ISynapse> inboundSynapses = this.network.Structure
                                                     .GetPreviousSynapses(layer);

            foreach (ISynapse synapse in inboundSynapses)
            {
                if (synapse.WeightMatrix != null)
                {
                    Matrix newMatrix = new Matrix(synapse.FromNeuronCount,
                                                  neuronCount);
                    // copy existing matrix to new matrix
                    for (int row = 0; row < synapse.FromNeuronCount; row++)
                    {
                        for (int col = 0; col < synapse.ToNeuronCount; col++)
                        {
                            newMatrix[row, col] = synapse.WeightMatrix[row, col];
                        }
                    }
                    synapse.WeightMatrix = newMatrix;
                }
            }

            // adjust the bias
            if (layer.HasBias)
            {
                double[] newBias2 = new double[neuronCount];

                for (int i = 0; i < layer.NeuronCount; i++)
                {
                    newBias2[i] = layer.BiasWeights[i];
                }
                layer.BiasWeights = newBias2;
            }

            // adjust RBF
            if (layer is RadialBasisFunctionLayer)
            {
                RadialBasisFunctionLayer rbf    = (RadialBasisFunctionLayer)layer;
                IRadialBasisFunction[]   newRBF = new IRadialBasisFunction[neuronCount];
                for (int i = 0; i < rbf.RadialBasisFunction.Length; i++)
                {
                    newRBF[i] = rbf.RadialBasisFunction[i];
                }

                for (int i = rbf.RadialBasisFunction.Length; i < neuronCount; i++)
                {
                    newRBF[i] = new GaussianFunction(ThreadSafeRandom.NextDouble() - 0.5,
                                                     ThreadSafeRandom.NextDouble(), ThreadSafeRandom.NextDouble() - 0.5);
                }

                rbf.RadialBasisFunction = newRBF;
            }

            // finally, up the neuron count
            layer.NeuronCount = neuronCount;
        }
Ejemplo n.º 33
0
Archivo: SVD.cs Proyecto: neismit/emds
 public static double Svdfit(double[][] x, double[][] y, double[][] a, IRadialBasisFunction[] funcs)
 {
     int num;
     int num2;
     int num3;
     double num4;
     double num5;
     double num6;
     double num7;
     double[][] numArray;
     double[][] numArray2;
     double[] numArray3;
     double num9;
     double num8 = 1E-13;
     goto Label_0254;
     Label_0010:
     if (num < y.Length)
     {
         num7 = 0.0;
         for (num2 = 0; num2 < funcs.Length; num2++)
         {
             num7 += a[num2][num3] * funcs[num2].Calculate(x[num]);
         }
         num5 = y[num][num3] - num7;
         num9 += num5 * num5;
         num++;
         if (((uint) num9) >= 0)
         {
             goto Label_0010;
         }
         goto Label_0057;
     }
     Label_0016:
     num3++;
     Label_001A:
     if (num3 < y[0].Length)
     {
         num = 0;
         if ((((uint) num7) | 15) != 0)
         {
             goto Label_0010;
         }
         goto Label_010E;
     }
     Label_0057:
     if ((((uint) num8) + ((uint) num)) >= 0)
     {
         return Math.Sqrt(num9 / ((double) (y.Length * y[0].Length)));
     }
     goto Label_0254;
     Label_00F9:
     num2 = 0;
     while (num2 < funcs.Length)
     {
         if (numArray3[num2] < num6)
         {
             numArray3[num2] = 0.0;
         }
         num2++;
     }
     Svdbksb(numArray, numArray3, numArray2, y, a);
     goto Label_013E;
     Label_010E:
     num4 = numArray3[num2];
     goto Label_011C;
     Label_0115:
     if (numArray3[num2] > num4)
     {
         goto Label_010E;
     }
     Label_011C:
     num2++;
     Label_0120:
     if (num2 < funcs.Length)
     {
         goto Label_0115;
     }
     num6 = num8 * num4;
     if (((uint) num9) >= 0)
     {
         goto Label_00F9;
     }
     Label_013E:
     if ((((uint) num) - ((uint) num7)) >= 0)
     {
         num9 = 0.0;
         num3 = 0;
         goto Label_001A;
     }
     goto Label_0010;
     Label_0254:
     if (((uint) num6) > uint.MaxValue)
     {
         goto Label_0016;
     }
     if ((((uint) num5) + ((uint) num3)) <= uint.MaxValue)
     {
         numArray = EngineArray.AllocateDouble2D(x.Length, funcs.Length);
     }
     numArray2 = EngineArray.AllocateDouble2D(funcs.Length, funcs.Length);
     numArray3 = new double[funcs.Length];
     num = 0;
     if (-2 != 0)
     {
     Label_018D:
         if (num < x.Length)
         {
             num2 = 0;
         }
         else
         {
             Svdcmp(numArray, numArray3, numArray2);
             if (((uint) num) > uint.MaxValue)
             {
                 goto Label_011C;
             }
             if (0 != 0)
             {
                 goto Label_001A;
             }
             num4 = 0.0;
             num2 = 0;
             goto Label_0120;
         }
         while (true)
         {
             if (num2 < funcs.Length)
             {
                 numArray[num][num2] = funcs[num2].Calculate(x[num]);
             }
             else
             {
                 if ((((uint) num3) | 1) == 0)
                 {
                     goto Label_00F9;
                 }
                 if ((((uint) num7) + ((uint) num5)) >= 0)
                 {
                     num++;
                 }
                 goto Label_018D;
             }
             num2++;
             if (((uint) num3) <= uint.MaxValue)
             {
             }
         }
     }
     if (((uint) num8) <= uint.MaxValue)
     {
         goto Label_0115;
     }
     if ((((uint) num2) & 0) == 0)
     {
         goto Label_010E;
     }
     goto Label_0010;
 }
Ejemplo n.º 34
0
        /// <summary>
        /// Perform one iteration.
        /// </summary>
        ///
        public override sealed void Iteration()
        {
            int length = network.RBF.Length;

            var funcs = new IRadialBasisFunction[length];

            // Iteration over neurons and determine the necessaries
            for (int i = 0; i < length; i++)
            {
                IRadialBasisFunction basisFunc = network.RBF[i];

                funcs[i] = basisFunc;

                // This is the value that is changed using other training methods.
                // weights[i] =
                // network.Structure.Synapses[0].WeightMatrix.Data[i][j];
            }

            ObjectPair<double[][], double[][]> data = TrainingSetUtil
                .TrainingToArray(Training);

            double[][] matrix = EngineArray.AllocateDouble2D(length, network.OutputCount);

            FlatToMatrix(network.Flat.Weights, 0, matrix);
            Error = SVD.Svdfit(data.A, data.B, matrix, funcs);
            MatrixToFlat(matrix, network.Flat.Weights, 0);
        }
Ejemplo n.º 35
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;
        }
Ejemplo n.º 36
0
 /// <summary>
 /// Construct the neighborhood function with the specified radial function.
 /// Generally this will be a Gaussian function but any RBF should do.
 /// </summary>
 ///
 /// <param name="radial">The radial basis function to use.</param>
 public NeighborhoodRBF1D(IRadialBasisFunction radial)
 {
     _radial = radial;
 }