Ejemplo n.º 1
0
 public MultinomialLogitModel(alglib.logitmodel logitModel, string targetVariable, IEnumerable<string> allowedInputVariables, double[] classValues)
   : base(targetVariable) {
   this.name = ItemName;
   this.description = ItemDescription;
   this.logitModel = logitModel;
   this.allowedInputVariables = allowedInputVariables.ToArray();
   this.classValues = (double[])classValues.Clone();
 }
Ejemplo n.º 2
0
        public static List<double> Decode(alglib.complex[] freqSamples, bool needWindow = false)
        {
            
            double[] outSamples;
            alglib.fftr1dinv(freqSamples, out outSamples);

            return outSamples.ToList();
        }
Ejemplo n.º 3
0
 public NeuralNetworkModel(alglib.multilayerperceptron multiLayerPerceptron, string targetVariable, IEnumerable<string> allowedInputVariables, double[] classValues = null)
   : base(targetVariable) {
   this.name = ItemName;
   this.description = ItemDescription;
   this.multiLayerPerceptron = multiLayerPerceptron;
   this.allowedInputVariables = allowedInputVariables.ToArray();
   if (classValues != null)
     this.classValues = (double[])classValues.Clone();
 }
 public NeuralNetworkEnsembleModel(alglib.mlpensemble mlpEnsemble, string targetVariable, IEnumerable<string> allowedInputVariables, double[] classValues = null)
   : base() {
   this.name = ItemName;
   this.description = ItemDescription;
   this.mlpEnsemble = mlpEnsemble;
   this.targetVariable = targetVariable;
   this.allowedInputVariables = allowedInputVariables.ToArray();
   if (classValues != null)
     this.classValues = (double[])classValues.Clone();
 }
Ejemplo n.º 5
0
 /// <summary>
 /// 
 /// </summary>
 /// <param name="source"></param>
 /// <returns></returns>
 public static IList<Complex> convert(alglib.complex[] source)
 {
     int count = source.Length;
     IList<Complex> result = new Complex[count];
     for (int i = 0; i < count; i++)
     {
         result[i] = new Complex(source[i].x, source[i].y);
     }
     return result;
 }
Ejemplo n.º 6
0
    public static void splineSmoothFit(double[] x, double[] y, out alglib.spline1dinterpolant result, double rho = 0.3, int num_bases_functions = 50)
    {
      alglib.spline1dinterpolant s;
      alglib.spline1dfitreport rep;
      int info;

      alglib.spline1dfitpenalized(x, y, num_bases_functions, rho, out info, out s, out rep);

      result = s;
    }
        }//добавление АБГШ
        public static void generate_mixed_chirp_signal(int chirp_num, double duration_of_signal, double Fd, double[] Fmin, double[] Fmax, double[] init_phase, double[] A, out double[] t, out alglib.complex[] mixed_signal)//Амплитуды в децибелах
        {
            t = new double[(int)(duration_of_signal * Fd)];
            mixed_signal = new alglib.complex[(int)(duration_of_signal * Fd)];
            alglib.complex[] noise = create_AWGN(mixed_signal.Length);
            for (int i = 0; i < chirp_num; i++)
            {
                alglib.complex[] signal = chirp(Fmin[i], Fmax[i], Fd, duration_of_signal);
                double coeff = get_null_dB_mag(signal, noise, Fmin[i], Fmax[i], Fd);
                double new_coeff = Math.Sqrt(coeff * coeff * Math.Pow(10, A[i] / 10.0));
                for (int j = 0; j < signal.Length; j++)
                {
                    mixed_signal[j] += new_coeff * signal[j];
                }

               
                /* double noiseE = 0;
                 foreach (alglib.complex n in noise)
                 {
                     noiseE += Math.Pow(alglib.math.abscomplex(n), 2);
                 }
                 noiseE = noiseE * (Fmax[i] - Fmin[i]) / Fd;

                 double signalE = 0;
                 for (int j = 0; j < signal.Length; j++)
                 {
                     signalE += Math.Pow(alglib.math.abscomplex(new_coeff * signal[j]), 2);
                 }
                 double SNR =10* Math.Log10(signalE / noiseE) ;*/
            }

       /*   double E_sig = 0;
            foreach (alglib.complex val in mixed_signal)
            {
                E_sig += Math.Pow(alglib.math.abscomplex(val),2);

            }
            double E_noise = 0;
            foreach (alglib.complex val in noise)
            {
                E_noise += Math.Pow(alglib.math.abscomplex(val),2);

            }
            double SNR = 10 * Math.Log10(E_sig / E_noise);*/
            for (int j = 0; j < mixed_signal.Length; j++)
            {
                mixed_signal[j] += noise[j];
                t[j] = j / Fd;
            }

        }
 public static void create_RF_signal(alglib.complex[] baseband_signal, double Fd, double duration_of_signal, double Fc, double A, out alglib.complex[] RF_signal, out double[] t)
 {
     int samples = (int)(duration_of_signal * Fd);
     t = new double[samples];
     for (int i = 0; i < t.Length; i++)
     {
         t[i] = i / Fd;
     }
     RF_signal = new alglib.complex[t.Length];
     for (int i = 0; i < t.Length; i++)
     {
         RF_signal[i] = A * baseband_signal[i] * new alglib.complex(Math.Cos(Fc * 2 * Math.PI * t[i]), Math.Sin(Fc * 2 * Math.PI * t[i]));
     }
 }//создание радиосигнала, перенос на несущую
 public static double get_null_dB_mag(alglib.complex[] signal, alglib.complex[] noise, double Fmin, double Fmax, double Fd)//получения амплитуды сигнала соотвествующей SNR=0, 
 {
     double signal_mag = 0;
     //int i_start = (int)(Fmin * (signal.Length - 1) / Fd);
     //int i_end = (int)Math.Ceiling(Fmax * (signal.Length - 1) / Fd);
      for (int i = 0; i < signal.Length; i++)
      {
          signal_mag += Math.Pow(alglib.math.abscomplex(signal[i]), 2);
      }
     /*for (int i = i_start; i <= i_end; i++)
     {
         signal_mag += Math.Pow(alglib.math.abscomplex(signal[i]), 2);
     }*/
     double noise_mag = 0;
     for (int i = 0; i < noise.Length; i++)
     {
         noise_mag += Math.Pow(alglib.math.abscomplex(noise[i]), 2);
     }
     noise_mag = noise_mag * (Fmax - Fmin) / Fd;
     double coeff = noise_mag / signal_mag;
     return Math.Sqrt(coeff);
 }//добавление АБГШ
        /*************************************************************************
        Serializer: serialization

          -- ALGLIB --
             Copyright 14.03.2011 by Bochkanov Sergey
        *************************************************************************/
        public static void kdtreeserialize(alglib.serializer s,
            kdtree tree)
        {
            
            //
            // Header
            //
            s.serialize_int(scodes.getkdtreeserializationcode());
            s.serialize_int(kdtreefirstversion);
            
            //
            // Data
            //
            s.serialize_int(tree.n);
            s.serialize_int(tree.nx);
            s.serialize_int(tree.ny);
            s.serialize_int(tree.normtype);
            apserv.serializerealmatrix(s, tree.xy, -1, -1);
            apserv.serializeintegerarray(s, tree.tags, -1);
            apserv.serializerealarray(s, tree.boxmin, -1);
            apserv.serializerealarray(s, tree.boxmax, -1);
            apserv.serializeintegerarray(s, tree.nodes, -1);
            apserv.serializerealarray(s, tree.splits, -1);
        }
Ejemplo n.º 11
0
        /*************************************************************************
        Serializer: unserialization

          -- ALGLIB --
             Copyright 14.03.2011 by Bochkanov Sergey
        *************************************************************************/
        public static void dfunserialize(alglib.serializer s,
            decisionforest forest)
        {
            int i0 = 0;
            int i1 = 0;

            
            //
            // check correctness of header
            //
            i0 = s.unserialize_int();
            alglib.ap.assert(i0==scodes.getrdfserializationcode(), "DFUnserialize: stream header corrupted");
            i1 = s.unserialize_int();
            alglib.ap.assert(i1==dffirstversion, "DFUnserialize: stream header corrupted");
            
            //
            // Unserialize data
            //
            forest.nvars = s.unserialize_int();
            forest.nclasses = s.unserialize_int();
            forest.ntrees = s.unserialize_int();
            forest.bufsize = s.unserialize_int();
            apserv.unserializerealarray(s, ref forest.trees);
        }
Ejemplo n.º 12
0
        /*************************************************************************
        Serializer: allocation

          -- ALGLIB --
             Copyright 14.03.2011 by Bochkanov Sergey
        *************************************************************************/
        public static void dfalloc(alglib.serializer s,
            decisionforest forest)
        {
            s.alloc_entry();
            s.alloc_entry();
            s.alloc_entry();
            s.alloc_entry();
            s.alloc_entry();
            s.alloc_entry();
            apserv.allocrealarray(s, forest.trees, forest.bufsize);
        }
Ejemplo n.º 13
0
        /*************************************************************************
        Serializer: serialization

          -- ALGLIB --
             Copyright 14.03.2011 by Bochkanov Sergey
        *************************************************************************/
        public static void mlpeserialize(alglib.serializer s,
            mlpensemble ensemble)
        {
            s.serialize_int(scodes.getmlpeserializationcode());
            s.serialize_int(mlpefirstversion);
            s.serialize_int(ensemble.ensemblesize);
            apserv.serializerealarray(s, ensemble.weights, -1);
            apserv.serializerealarray(s, ensemble.columnmeans, -1);
            apserv.serializerealarray(s, ensemble.columnsigmas, -1);
            mlpbase.mlpserialize(s, ensemble.network);
        }
Ejemplo n.º 14
0
        /*************************************************************************
        Serializer: unserialization

          -- ALGLIB --
             Copyright 14.03.2011 by Bochkanov Sergey
        *************************************************************************/
        public static void mlpunserialize(alglib.serializer s,
            multilayerperceptron network)
        {
            int i0 = 0;
            int i1 = 0;
            int i = 0;
            int j = 0;
            int k = 0;
            int fkind = 0;
            double threshold = 0;
            double v0 = 0;
            double v1 = 0;
            int nin = 0;
            int nout = 0;
            bool issoftmax = new bool();
            int[] layersizes = new int[0];

            
            //
            // check correctness of header
            //
            i0 = s.unserialize_int();
            alglib.ap.assert(i0==scodes.getmlpserializationcode(), "MLPUnserialize: stream header corrupted");
            i1 = s.unserialize_int();
            alglib.ap.assert(i1==mlpfirstversion, "MLPUnserialize: stream header corrupted");
            
            //
            // Create network
            //
            issoftmax = s.unserialize_bool();
            apserv.unserializeintegerarray(s, ref layersizes);
            alglib.ap.assert((alglib.ap.len(layersizes)==2 || alglib.ap.len(layersizes)==3) || alglib.ap.len(layersizes)==4, "MLPUnserialize: too many hidden layers!");
            nin = layersizes[0];
            nout = layersizes[alglib.ap.len(layersizes)-1];
            if( alglib.ap.len(layersizes)==2 )
            {
                if( issoftmax )
                {
                    mlpcreatec0(layersizes[0], layersizes[1], network);
                }
                else
                {
                    mlpcreate0(layersizes[0], layersizes[1], network);
                }
            }
            if( alglib.ap.len(layersizes)==3 )
            {
                if( issoftmax )
                {
                    mlpcreatec1(layersizes[0], layersizes[1], layersizes[2], network);
                }
                else
                {
                    mlpcreate1(layersizes[0], layersizes[1], layersizes[2], network);
                }
            }
            if( alglib.ap.len(layersizes)==4 )
            {
                if( issoftmax )
                {
                    mlpcreatec2(layersizes[0], layersizes[1], layersizes[2], layersizes[3], network);
                }
                else
                {
                    mlpcreate2(layersizes[0], layersizes[1], layersizes[2], layersizes[3], network);
                }
            }
            
            //
            // Load neurons and weights
            //
            for(i=1; i<=alglib.ap.len(layersizes)-1; i++)
            {
                for(j=0; j<=layersizes[i]-1; j++)
                {
                    fkind = s.unserialize_int();
                    threshold = s.unserialize_double();
                    mlpsetneuroninfo(network, i, j, fkind, threshold);
                    for(k=0; k<=layersizes[i-1]-1; k++)
                    {
                        v0 = s.unserialize_double();
                        mlpsetweight(network, i-1, k, i, j, v0);
                    }
                }
            }
            
            //
            // Load standartizator
            //
            for(j=0; j<=nin-1; j++)
            {
                v0 = s.unserialize_double();
                v1 = s.unserialize_double();
                mlpsetinputscaling(network, j, v0, v1);
            }
            for(j=0; j<=nout-1; j++)
            {
                v0 = s.unserialize_double();
                v1 = s.unserialize_double();
                mlpsetoutputscaling(network, j, v0, v1);
            }
        }
Ejemplo n.º 15
0
        /*************************************************************************
        Serializer: allocation

          -- ALGLIB --
             Copyright 14.03.2011 by Bochkanov Sergey
        *************************************************************************/
        public static void mlpalloc(alglib.serializer s,
            multilayerperceptron network)
        {
            int i = 0;
            int j = 0;
            int k = 0;
            int fkind = 0;
            double threshold = 0;
            double v0 = 0;
            double v1 = 0;
            int nin = 0;
            int nout = 0;

            nin = network.hllayersizes[0];
            nout = network.hllayersizes[alglib.ap.len(network.hllayersizes)-1];
            s.alloc_entry();
            s.alloc_entry();
            s.alloc_entry();
            apserv.allocintegerarray(s, network.hllayersizes, -1);
            for(i=1; i<=alglib.ap.len(network.hllayersizes)-1; i++)
            {
                for(j=0; j<=network.hllayersizes[i]-1; j++)
                {
                    mlpgetneuroninfo(network, i, j, ref fkind, ref threshold);
                    s.alloc_entry();
                    s.alloc_entry();
                    for(k=0; k<=network.hllayersizes[i-1]-1; k++)
                    {
                        s.alloc_entry();
                    }
                }
            }
            for(j=0; j<=nin-1; j++)
            {
                mlpgetinputscaling(network, j, ref v0, ref v1);
                s.alloc_entry();
                s.alloc_entry();
            }
            for(j=0; j<=nout-1; j++)
            {
                mlpgetoutputscaling(network, j, ref v0, ref v1);
                s.alloc_entry();
                s.alloc_entry();
            }
        }
Ejemplo n.º 16
0
 /*************************************************************************
 Serialization: complex value
 *************************************************************************/
 public static void serializecomplex(alglib.serializer s,
     complex v)
 {
     s.serialize_double(v.x);
     s.serialize_double(v.y);
 }
Ejemplo n.º 17
0
        /*************************************************************************
        Unserialization: complex value
        *************************************************************************/
        public static complex unserializecomplex(alglib.serializer s)
        {
            complex result = 0;

            result.x = s.unserialize_double();
            result.y = s.unserialize_double();
            return result;
        }
Ejemplo n.º 18
0
        /*************************************************************************
        Allocation of serializer: Integer array
        *************************************************************************/
        public static void allocintegerarray(alglib.serializer s,
            int[] v,
            int n)
        {
            int i = 0;

            if( n<0 )
            {
                n = ap.len(v);
            }
            s.alloc_entry();
            for(i=0; i<=n-1; i++)
            {
                s.alloc_entry();
            }
        }
Ejemplo n.º 19
0
        /*************************************************************************
        Serializer: serialization

          -- ALGLIB --
             Copyright 14.03.2011 by Bochkanov Sergey
        *************************************************************************/
        public static void mlpserialize(alglib.serializer s,
            multilayerperceptron network)
        {
            int i = 0;
            int j = 0;
            int k = 0;
            int fkind = 0;
            double threshold = 0;
            double v0 = 0;
            double v1 = 0;
            int nin = 0;
            int nout = 0;

            nin = network.hllayersizes[0];
            nout = network.hllayersizes[alglib.ap.len(network.hllayersizes)-1];
            s.serialize_int(scodes.getmlpserializationcode());
            s.serialize_int(mlpfirstversion);
            s.serialize_bool(mlpissoftmax(network));
            apserv.serializeintegerarray(s, network.hllayersizes, -1);
            for(i=1; i<=alglib.ap.len(network.hllayersizes)-1; i++)
            {
                for(j=0; j<=network.hllayersizes[i]-1; j++)
                {
                    mlpgetneuroninfo(network, i, j, ref fkind, ref threshold);
                    s.serialize_int(fkind);
                    s.serialize_double(threshold);
                    for(k=0; k<=network.hllayersizes[i-1]-1; k++)
                    {
                        s.serialize_double(mlpgetweight(network, i-1, k, i, j));
                    }
                }
            }
            for(j=0; j<=nin-1; j++)
            {
                mlpgetinputscaling(network, j, ref v0, ref v1);
                s.serialize_double(v0);
                s.serialize_double(v1);
            }
            for(j=0; j<=nout-1; j++)
            {
                mlpgetoutputscaling(network, j, ref v0, ref v1);
                s.serialize_double(v0);
                s.serialize_double(v1);
            }
        }
Ejemplo n.º 20
0
        /*************************************************************************
        Serialization: Integer array
        *************************************************************************/
        public static void serializeintegerarray(alglib.serializer s,
            int[] v,
            int n)
        {
            int i = 0;

            if( n<0 )
            {
                n = ap.len(v);
            }
            s.serialize_int(n);
            for(i=0; i<=n-1; i++)
            {
                s.serialize_int(v[i]);
            }
        }
Ejemplo n.º 21
0
        /*************************************************************************
        Serializer: allocation

          -- ALGLIB --
             Copyright 19.10.2011 by Bochkanov Sergey
        *************************************************************************/
        public static void mlpealloc(alglib.serializer s,
            mlpensemble ensemble)
        {
            s.alloc_entry();
            s.alloc_entry();
            s.alloc_entry();
            apserv.allocrealarray(s, ensemble.weights, -1);
            apserv.allocrealarray(s, ensemble.columnmeans, -1);
            apserv.allocrealarray(s, ensemble.columnsigmas, -1);
            mlpbase.mlpalloc(s, ensemble.network);
        }
Ejemplo n.º 22
0
        /*************************************************************************
        Unserialization: complex value
        *************************************************************************/
        public static void unserializeintegerarray(alglib.serializer s,
            ref int[] v)
        {
            int n = 0;
            int i = 0;
            int t = 0;

            v = new int[0];

            n = s.unserialize_int();
            if( n==0 )
            {
                return;
            }
            v = new int[n];
            for(i=0; i<=n-1; i++)
            {
                t = s.unserialize_int();
                v[i] = t;
            }
        }
Ejemplo n.º 23
0
        /*************************************************************************
        Serializer: unserialization

          -- ALGLIB --
             Copyright 14.03.2011 by Bochkanov Sergey
        *************************************************************************/
        public static void mlpeunserialize(alglib.serializer s,
            mlpensemble ensemble)
        {
            int i0 = 0;
            int i1 = 0;

            
            //
            // check correctness of header
            //
            i0 = s.unserialize_int();
            alglib.ap.assert(i0==scodes.getmlpeserializationcode(), "MLPEUnserialize: stream header corrupted");
            i1 = s.unserialize_int();
            alglib.ap.assert(i1==mlpefirstversion, "MLPEUnserialize: stream header corrupted");
            
            //
            // Create network
            //
            ensemble.ensemblesize = s.unserialize_int();
            apserv.unserializerealarray(s, ref ensemble.weights);
            apserv.unserializerealarray(s, ref ensemble.columnmeans);
            apserv.unserializerealarray(s, ref ensemble.columnsigmas);
            mlpbase.mlpunserialize(s, ensemble.network);
            
            //
            // Allocate termoraries
            //
            ensemble.y = new double[mlpbase.mlpgetoutputscount(ensemble.network)];
        }
Ejemplo n.º 24
0
        /*************************************************************************
        Allocation of serializer: real matrix
        *************************************************************************/
        public static void allocrealmatrix(alglib.serializer s,
            double[,] v,
            int n0,
            int n1)
        {
            int i = 0;
            int j = 0;

            if( n0<0 )
            {
                n0 = ap.rows(v);
            }
            if( n1<0 )
            {
                n1 = ap.cols(v);
            }
            s.alloc_entry();
            s.alloc_entry();
            for(i=0; i<=n0-1; i++)
            {
                for(j=0; j<=n1-1; j++)
                {
                    s.alloc_entry();
                }
            }
        }
Ejemplo n.º 25
0
        /*************************************************************************
        Serializer: serialization

          -- ALGLIB --
             Copyright 14.03.2011 by Bochkanov Sergey
        *************************************************************************/
        public static void dfserialize(alglib.serializer s,
            decisionforest forest)
        {
            s.serialize_int(scodes.getrdfserializationcode());
            s.serialize_int(dffirstversion);
            s.serialize_int(forest.nvars);
            s.serialize_int(forest.nclasses);
            s.serialize_int(forest.ntrees);
            s.serialize_int(forest.bufsize);
            apserv.serializerealarray(s, forest.trees, forest.bufsize);
        }
Ejemplo n.º 26
0
        /*************************************************************************
        Serialization: complex value
        *************************************************************************/
        public static void serializerealmatrix(alglib.serializer s,
            double[,] v,
            int n0,
            int n1)
        {
            int i = 0;
            int j = 0;

            if( n0<0 )
            {
                n0 = ap.rows(v);
            }
            if( n1<0 )
            {
                n1 = ap.cols(v);
            }
            s.serialize_int(n0);
            s.serialize_int(n1);
            for(i=0; i<=n0-1; i++)
            {
                for(j=0; j<=n1-1; j++)
                {
                    s.serialize_double(v[i,j]);
                }
            }
        }
        /*************************************************************************
        Serializer: allocation

          -- ALGLIB --
             Copyright 14.03.2011 by Bochkanov Sergey
        *************************************************************************/
        public static void kdtreealloc(alglib.serializer s,
            kdtree tree)
        {
            
            //
            // Header
            //
            s.alloc_entry();
            s.alloc_entry();
            
            //
            // Data
            //
            s.alloc_entry();
            s.alloc_entry();
            s.alloc_entry();
            s.alloc_entry();
            apserv.allocrealmatrix(s, tree.xy, -1, -1);
            apserv.allocintegerarray(s, tree.tags, -1);
            apserv.allocrealarray(s, tree.boxmin, -1);
            apserv.allocrealarray(s, tree.boxmax, -1);
            apserv.allocintegerarray(s, tree.nodes, -1);
            apserv.allocrealarray(s, tree.splits, -1);
        }
Ejemplo n.º 28
0
        /*************************************************************************
        Unserialization: complex value
        *************************************************************************/
        public static void unserializerealmatrix(alglib.serializer s,
            ref double[,] v)
        {
            int i = 0;
            int j = 0;
            int n0 = 0;
            int n1 = 0;
            double t = 0;

            v = new double[0,0];

            n0 = s.unserialize_int();
            n1 = s.unserialize_int();
            if( n0==0 | n1==0 )
            {
                return;
            }
            v = new double[n0, n1];
            for(i=0; i<=n0-1; i++)
            {
                for(j=0; j<=n1-1; j++)
                {
                    t = s.unserialize_double();
                    v[i,j] = t;
                }
            }
        }
        /*************************************************************************
        Serializer: unserialization

          -- ALGLIB --
             Copyright 14.03.2011 by Bochkanov Sergey
        *************************************************************************/
        public static void kdtreeunserialize(alglib.serializer s,
            kdtree tree)
        {
            int i0 = 0;
            int i1 = 0;

            
            //
            // check correctness of header
            //
            i0 = s.unserialize_int();
            alglib.ap.assert(i0==scodes.getkdtreeserializationcode(), "KDTreeUnserialize: stream header corrupted");
            i1 = s.unserialize_int();
            alglib.ap.assert(i1==kdtreefirstversion, "KDTreeUnserialize: stream header corrupted");
            
            //
            // Unserialize data
            //
            tree.n = s.unserialize_int();
            tree.nx = s.unserialize_int();
            tree.ny = s.unserialize_int();
            tree.normtype = s.unserialize_int();
            apserv.unserializerealmatrix(s, ref tree.xy);
            apserv.unserializeintegerarray(s, ref tree.tags);
            apserv.unserializerealarray(s, ref tree.boxmin);
            apserv.unserializerealarray(s, ref tree.boxmax);
            apserv.unserializeintegerarray(s, ref tree.nodes);
            apserv.unserializerealarray(s, ref tree.splits);
            kdtreealloctemporaries(tree, tree.n, tree.nx, tree.ny);
        }
Ejemplo n.º 30
0
 /*************************************************************************
 Allocation of serializer: complex value
 *************************************************************************/
 public static void alloccomplex(alglib.serializer s,
     complex v)
 {
     s.alloc_entry();
     s.alloc_entry();
 }