示例#1
0
        private void CreateTestData(FaceData faceData, int idx)
        {
            AuTestData  = new svm_node[MaxAuFeatures];
            FppTestData = new svm_node[MaxFppFeatures];

            for (int i = 0; i < faceData.au_data.Count; i++)
            {
                AuTestData[i] = new svm_node();

                AuTestData[i].index = i;
                AuTestData[i].value = faceData.au_data[i];
            }

            int index = 0;
            int j     = 0;

            while (index < faceData.point_3D.Count)
            {
                if (FeaturePoint.ContainsValue(index / 3))
                {
                    FppTestData[j] = new svm_node();

                    FppTestData[j].index = j;
                    FppTestData[j].value = faceData.point_3D[index];

                    j++;
                }
                index++;
            }

            ScalingData(AuTestData, AuScaleMin, AuScaleMax, MaxAuFeatures, idx);
            ScalingData(FppTestData, FppScaleMin, FppScaleMax, MaxFppFeatures, idx);
        }
示例#2
0
        private static double ComputeValidationError(C_SVC svc, Matrix <double> xval, Vector <double> yval)
        {
            int    m          = xval.RowCount;
            double errorCount = 0;

            for (int i = 0; i < m; i++)
            {
                svm_node n1 = new svm_node();
                n1.index = 1;
                n1.value = xval.Row(i)[0];

                svm_node n2 = new svm_node();
                n2.index = 2;
                n2.value = xval.Row(i)[1];

                double pred = svc.Predict(new [] { n1, n2 });

                if (pred != yval[i])
                {
                    errorCount++;
                }
            }


            return(errorCount / m);
        }
示例#3
0
        public static SVMNode[] Convert(IntPtr ptr)
        {
            if (ptr == IntPtr.Zero)
            {
                return(null);
            }

            List <SVMNode> nodes       = new List <SVMNode>();
            IntPtr         i_ptr_nodes = ptr;

            while (true)
            {
                svm_node node = (svm_node)Marshal.PtrToStructure(i_ptr_nodes, typeof(svm_node));
                i_ptr_nodes = IntPtr.Add(i_ptr_nodes, Marshal.SizeOf(typeof(svm_node)));
                if (node.index >= 0)
                {
                    nodes.Add(new SVMNode(node.index, node.value));
                }
                else
                {
                    break;
                }
            }

            return(nodes.ToArray());
        }
        private svm_node[][] ReadSvmNodeArray(BinaryReader reader)
        {
            bool isNull = !reader.ReadBoolean();

            if (isNull)
            {
                return(null);
            }
            else
            {
                int          length = reader.ReadInt32();
                svm_node[][] array  = new svm_node[length][];
                for (int i = 0; i < length; i++)
                {
                    int sub_length = reader.ReadInt32();
                    array[i] = new svm_node[sub_length];

                    for (int j = 0; j < sub_length; j++)
                    {
                        svm_node node = new svm_node();
                        node.index         = reader.ReadInt32();
                        node.value_Renamed = reader.ReadDouble();
                        array[i][j]        = node;
                    }
                }
                return(array);
            }
        }
示例#5
0
    // read in a problem (in svmlight format)

    private void  read_problem()
    {
        /* UPGRADE_TODO: Expected value of parameters of constructor
         * 'java.io.BufferedReader.BufferedReader' are different in the equivalent in .NET.
         * 'ms-help://MS.VSCC.2003/commoner/redir/redirect.htm?keyword="jlca1092"'
         */
        System.IO.StreamReader       fp = new System.IO.StreamReader(input_file_name);
        System.Collections.ArrayList vy = new System.Collections.ArrayList(10);
        System.Collections.ArrayList vx = new System.Collections.ArrayList(10);
        int max_index = 0;

        while (true)
        {
            System.String line = fp.ReadLine();
            if ((System.Object)line == null)
            {
                break;
            }

            SupportClass.Tokenizer st = new SupportClass.Tokenizer(line, " \t\n\r\f:");

            vy.Add(st.NextToken());
            int        m = st.Count / 2;
            svm_node[] x = new svm_node[m];
            for (int j = 0; j < m; j++)
            {
                x[j]               = new svm_node();
                x[j].index         = atoi(st.NextToken());
                x[j].value_Renamed = atof(st.NextToken());
            }
            if (m > 0)
            {
                max_index = System.Math.Max(max_index, x[m - 1].index);
            }
            vx.Add(x);
        }

        prob   = new svm_problem();
        prob.l = vy.Count;
        prob.x = new svm_node[prob.l][];
        for (int i = 0; i < prob.l; i++)
        {
            prob.x[i] = (svm_node[])vx[i];
        }
        prob.y = new double[prob.l];
        for (int i = 0; i < prob.l; i++)
        {
            prob.y[i] = atof((System.String)vy[i]);
        }

        if (param.gamma == 0)
        {
            param.gamma = 1.0 / max_index;
        }

        fp.Close();
    }
 public static svm_node[][] CreateNodeArray(double [,] values)
 {
     svm_node[][] svm_nodes = new svm_node[values.GetLength(0)][];
     for (int row_index = 0; row_index < values.GetLength(0); row_index++)
     {
         svm_nodes[row_index] = CreateNodeArray(values.Select1DIndex0(row_index));;
     }
     return(svm_nodes);
 }
示例#7
0
        public int Classify()
        {
            try
            {
                if (lengths != null)
                {
                    var path = Environment.CurrentDirectory.Remove(Environment.CurrentDirectory.Length - 20, 20);
                    path = path + "RethinopathyAnalysisModule\\bin\\Debug\\";
                    var DvCsvm = new C_SVC(System.IO.Path.Combine(path, DvC_MODEL_FILE));
                    var DvHsvm = new C_SVC(System.IO.Path.Combine(path, DvH_MODEL_FILE));
                    var HvCsvm = new C_SVC(System.IO.Path.Combine(path, HvC_MODEL_FILE));

                    svm_node[] x = new svm_node[lengths.Count];
                    for (int j = 0; j < lengths.Count; j++)
                    {
                        x[j] = new svm_node()
                        {
                            index = j, value = lengths[j]
                        };
                    }
                    double DvCresult = DvCsvm.Predict(x);
                    double DvHresult = DvCsvm.Predict(x);
                    double HvCresult = DvCsvm.Predict(x);

                    if (DvCresult == 1)
                    {
                        if (DvHresult == 1)
                        {
                            return(1);
                        }
                    }
                    else
                    {
                        if (HvCresult == -1)
                        {
                            return(0);
                        }
                        else
                        if (DvHresult == -1)
                        {
                            return(2);
                        }
                    }
                    return(-1);
                }
                else
                {
                    return(-1);
                }
            }
            catch
            {
                return(-1);
            }
        }
        private svm_node[] nodeMaking()
        {
            String st = "";
            int    l  = 0;

            svm_node[] svmNodes = new svm_node[36];

            for (int i = 0; i < 4; i++)
            {
                for (int j = 0; j < 4; j++)
                {
                    svm_node svmNode = new svm_node();
                    double   value   = countEdgesForBlock(i * 33, j * 33, 33, 33);
                    svmNode.index = l + 1;
                    svmNode.value = value;
                    svmNodes[l++] = svmNode;
                }
                int q = 132;
                for (int j = 4; j < 6; j++)
                {
                    svm_node svmNode = new svm_node();
                    double   value   = countEdgesForBlock(i * 33, q, 34, 34);
                    svmNode.index = l + 1;
                    svmNode.value = value;
                    q             = q + 34;
                    svmNodes[l++] = svmNode;
                }
            }
            int p = 132;

            for (int i = 4; i < 6; i++)
            {
                for (int j = 0; j < 4; j++)
                {
                    svm_node svmNode = new svm_node();
                    double   value   = countEdgesForBlock(p, j * 33, 33, 33);
                    svmNode.index = l + 1;
                    svmNode.value = value;
                    svmNodes[l++] = svmNode;
                }

                int q = 132;
                for (int j = 4; j < 6; j++)
                {
                    svm_node svmNode = new svm_node();
                    double   value   = countEdgesForBlock(p, q, 34, 34);
                    svmNode.index = l + 1;
                    svmNode.value = value;
                    q             = q + 34;
                    svmNodes[l++] = svmNode;
                }
                p = p + 34;
            }
            return(svmNodes);
        }
示例#9
0
        /// <summary>
        /// Convert regular Encog NeuralData into the "sparse" data needed by an SVM.
        /// </summary>
        /// <param name="data">The data to convert.</param>
        /// <returns>The SVM sparse data.</returns>
        public svm_node[] MakeSparse(INeuralData data)
        {
            svm_node[] result = new svm_node[data.Count];
            for (int i = 0; i < data.Count; i++)
            {
                result[i]               = new svm_node();
                result[i].index         = i + 1;
                result[i].value_Renamed = data[i];
            }

            return(result);
        }
 public static svm_node [] CreateNodeArray(IReadOnlyList <double> values)
 {
     svm_node[] svm_node = new svm_node[values.Count + 1];
     for (int index = 0; index < values.Count; index++)
     {
         svm_node[index]       = new svm_node();
         svm_node[index].index = index;
         svm_node[index].value = values[index];
     }
     svm_node[values.Count]       = new svm_node();
     svm_node[values.Count].index = -1;      //Each row of properties should be terminated with a -1 according to the readme
     return(svm_node);
 }
        /// <summary>
        /// Convert regular Encog MLData into the "sparse" data needed by an SVM.
        /// </summary>
        ///
        /// <param name="data">The data to convert.</param>
        /// <returns>The SVM sparse data.</returns>
        public svm_node[] MakeSparse(IMLData data)
        {
            var result = new svm_node[data.Count];

            for (int i = 0; i < data.Count; i++)
            {
                result[i] = new svm_node {
                    index = i + 1, value_Renamed = data[i]
                };
            }

            return(result);
        }
示例#12
0
 /// <summary>
 /// Transforms the input array based upon the values provided.
 /// </summary>
 /// <param name="input">The input array</param>
 /// <returns>A scaled array</returns>
 public svm_node[] Transform(svm_node[] input)
 {
     svm_node[] output = new svm_node[input.Length];
     for (int i = 0; i < output.Length; i++)
     {
         int    index = input[i].index;
         double value = input[i].value;
         output[i] = new svm_node()
         {
             index = index, value = Transform(value, index)
         };
     }
     return(output);
 }
        /// <summary>
        /// Transforms <paramref name="dataset"/> into a data structure as needed by libSVM.
        /// </summary>
        /// <param name="dataset">The source dataset</param>
        /// <param name="targetVariable">The target variable</param>
        /// <param name="inputVariables">The selected input variables to include in the svm_problem.</param>
        /// <param name="rowIndices">The rows of the dataset that should be contained in the resulting SVM-problem</param>
        /// <returns>A problem data type that can be used to train a support vector machine.</returns>
        public static svm_problem CreateSvmProblem(IDataset dataset, string targetVariable, IEnumerable <string> inputVariables, IEnumerable <int> rowIndices)
        {
            double[] targetVector;
            var      nRows = rowIndices.Count();

            if (string.IsNullOrEmpty(targetVariable))
            {
                // if the target variable is not set (e.g. for prediction of a trained model) we just use a zero vector
                targetVector = new double[nRows];
            }
            else
            {
                targetVector = dataset.GetDoubleValues(targetVariable, rowIndices).ToArray();
            }
            svm_node[][]  nodes              = new svm_node[nRows][];
            int           maxNodeIndex       = 0;
            int           svmProblemRowIndex = 0;
            List <string> inputVariablesList = inputVariables.ToList();

            foreach (int row in rowIndices)
            {
                List <svm_node> tempRow  = new List <svm_node>();
                int             colIndex = 1; // make sure the smallest node index for SVM = 1
                foreach (var inputVariable in inputVariablesList)
                {
                    double value = dataset.GetDoubleValue(inputVariable, row);
                    // SVM also works with missing values
                    // => don't add NaN values in the dataset to the sparse SVM matrix representation
                    if (!double.IsNaN(value))
                    {
                        tempRow.Add(new svm_node()
                        {
                            index = colIndex, value = value
                        });
                        // nodes must be sorted in ascending ordered by column index
                        if (colIndex > maxNodeIndex)
                        {
                            maxNodeIndex = colIndex;
                        }
                    }
                    colIndex++;
                }
                nodes[svmProblemRowIndex++] = tempRow.ToArray();
            }
            return(new svm_problem {
                l = targetVector.Length, y = targetVector, x = nodes
            });
        }
示例#14
0
        public SVM()
        {
            fileExistance        = false;
            predictionDictionary = new Dictionary <int, string> {
                { 1, "Neutral" }, { 2, "Up" }, { 3, "Down" }, { 4, "Left" }, { 5, "Right" }
            };
            scale   = new SVMScale();
            svmnode = new svm_node[25];
            int i = 0;

            for (; i < 25; i++)
            {
                svmnode[i]       = new svm_node();
                svmnode[i].index = i + 1;
            }
        }
示例#15
0
        public svm_problem CreateProblem(List <DataEntry> dataEntry, List <string> vocabulary)
        {
            double[]     y = new double[dataEntry.Count];
            svm_node[][] x = new svm_node[dataEntry.Count][];

            for (int i = 0; i < dataEntry.Count; i++)
            {
                y[i] = dataEntry[i].claimSentiment;
                x[i] = CreateNode(dataEntry[i].stemmedClaim, vocabulary);
            }

            return(new svm_problem
            {
                y = y,
                x = x,
                l = y.Length
            });
        }
示例#16
0
        private static void PlotBoundary(Matrix <double> x, C_SVC svc)
        {
            double min = x.Column(0).Min();
            double max = x.Column(0).Max();

            double[] x0 = MathNet.Numerics.Generate.LinearSpaced(100, min, max);

            min = x.Column(1).Min();
            max = x.Column(1).Max();

            double[] x1 = MathNet.Numerics.Generate.LinearSpaced(100, min, max);

            int size = x0.Length * x1.Length;

            double[] sx = new double[size];
            double[] sy = new double[size];
            double[] sz = new double[size];

            int idx = 0;

            for (int i = 0; i < x0.Length; i++)
            {
                for (int j = 0; j < x1.Length; j++)
                {
                    sx[idx] = x0[i];
                    sy[idx] = x1[j];

                    svm_node n1 = new svm_node();
                    n1.index = 1;
                    n1.value = x0[i];

                    svm_node n2 = new svm_node();
                    n2.index = 2;
                    n2.value = x1[j];

                    double z = svc.Predict(new [] { n1, n2 });
                    sz[idx] = z;
                    idx++;
                }
            }

            GnuPlot.Set("cntrparam levels discrete 0.5");
            GnuPlot.Contour(sx, sy, sz, "title \"Decision Boundary\"");
        }
示例#17
0
        public static IntPtr Allocate(SVMNode[] x)
        {
            if (x == null)
            {
                return(IntPtr.Zero);
            }

            IntPtr ptr         = Marshal.AllocHGlobal(Marshal.SizeOf(typeof(svm_node)) * x.Length);
            IntPtr i_ptr_nodes = ptr;

            for (int i = 0; i < x.Length; i++)
            {
                svm_node node = new svm_node();
                node.index = x[i].Index;
                node.value = x[i].Value;
                Marshal.StructureToPtr(node, i_ptr_nodes, true);
                i_ptr_nodes = IntPtr.Add(i_ptr_nodes, Marshal.SizeOf(typeof(svm_node)));
            }

            return(ptr);
        }
示例#18
0
        private static Vector <double> SvmPredic(Matrix <double> X, C_SVC svc)
        {
            int             m          = X.RowCount;
            int             n          = X.ColumnCount;
            Vector <double> prediction = Vector <double> .Build.Dense(m);

            for (int i = 0; i < m; i++)
            {
                svm_node[] nodes = new svm_node[n];

                for (int k = 0; k < n; k++)
                {
                    nodes[k] = new svm_node()
                    {
                        index = k + 1, value = X[i, k]
                    };
                }

                prediction[i] = svc.Predict(nodes);
            }

            return(prediction);
        }
示例#19
0
        private void checkXOR(SVM svm)
        {
            var predictions = new double[2, 2];

            for (int i = 0; i < 2; i++)
            {
                for (int j = 0; j < 2; j++)
                {
                    var A = new svm_node()
                    {
                        index = 1, value = i == 0 ? -1 : 1
                    };
                    var B = new svm_node()
                    {
                        index = 2, value = j == 0 ? -1 : 1
                    };
                    predictions[i, j] = svm.Predict(new svm_node[] { A, B });
                }
            }
            Assert.AreEqual(predictions[0, 0], 0);
            Assert.AreEqual(predictions[0, 1], 1);
            Assert.AreEqual(predictions[1, 0], 1);
            Assert.AreEqual(predictions[1, 1], 0);
        }
示例#20
0
	private static void  predict(System.IO.StreamReader input, System.IO.BinaryWriter output, svm_model model, int predict_probability)
	{
		int correct = 0;
		int total = 0;
		double error = 0;
		double sumv = 0, sumy = 0, sumvv = 0, sumyy = 0, sumvy = 0;
		
		int svm_type = svm.svm_get_svm_type(model);
		int nr_class = svm.svm_get_nr_class(model);
		int[] labels = new int[nr_class];
		double[] prob_estimates = null;
		
		if (predict_probability == 1)
		{
			if (svm_type == svm_parameter.EPSILON_SVR || svm_type == svm_parameter.NU_SVR)
			{
				System.Console.Out.Write("Prob. model for test data: target value = predicted value + z,\nz: Laplace distribution e^(-|z|/sigma)/(2sigma),sigma=" + svm.svm_get_svr_probability(model) + "\n");
			}
			else
			{
				svm.svm_get_labels(model, labels);
				prob_estimates = new double[nr_class];
				//UPGRADE_ISSUE: Method 'java.io.DataOutputStream.Write' was not converted. 'ms-help://MS.VSCC.2003/commoner/redir/redirect.htm?keyword="jlca1000_javaioDataOutputStreamWrite_javalangString"'
				output.Write("labels");
				for (int j = 0; j < nr_class; j++)
				{
					//UPGRADE_ISSUE: Method 'java.io.DataOutputStream.Write' was not converted. 'ms-help://MS.VSCC.2003/commoner/redir/redirect.htm?keyword="jlca1000_javaioDataOutputStreamWrite_javalangString"'
					output.Write(" " + labels[j]);
				}
				//UPGRADE_ISSUE: Method 'java.io.DataOutputStream.Write' was not converted. 'ms-help://MS.VSCC.2003/commoner/redir/redirect.htm?keyword="jlca1000_javaioDataOutputStreamWrite_javalangString"'
				output.Write("\n");
			}
		}
		while (true)
		{
			System.String line = input.ReadLine();
			if ((System.Object) line == null)
				break;
			
			SupportClass.Tokenizer st = new SupportClass.Tokenizer(line, " \t\n\r\f:");
			
			double target = atof(st.NextToken());
			int m = st.Count / 2;
			svm_node[] x = new svm_node[m];
			for (int j = 0; j < m; j++)
			{
				x[j] = new svm_node();
				x[j].index = atoi(st.NextToken());
				x[j].value = atof(st.NextToken());
			}
			
			double v;
			if (predict_probability == 1 && (svm_type == svm_parameter.C_SVC || svm_type == svm_parameter.NU_SVC))
			{
				v = svm.svm_predict_probability(model, x, prob_estimates);
				//UPGRADE_ISSUE: Method 'java.io.DataOutputStream.Write' was not converted. 'ms-help://MS.VSCC.2003/commoner/redir/redirect.htm?keyword="jlca1000_javaioDataOutputStreamWrite_javalangString"'
				output.Write(v + " ");
				for (int j = 0; j < nr_class; j++)
				{
					//UPGRADE_ISSUE: Method 'java.io.DataOutputStream.Write' was not converted. 'ms-help://MS.VSCC.2003/commoner/redir/redirect.htm?keyword="jlca1000_javaioDataOutputStreamWrite_javalangString"'
					output.Write(prob_estimates[j] + " ");
				}
				//UPGRADE_ISSUE: Method 'java.io.DataOutputStream.Write' was not converted. 'ms-help://MS.VSCC.2003/commoner/redir/redirect.htm?keyword="jlca1000_javaioDataOutputStreamWrite_javalangString"'
				output.Write("\n");
			}
			else
			{
				v = svm.svm_predict(model, x);
				//UPGRADE_ISSUE: Method 'java.io.DataOutputStream.Write' was not converted. 'ms-help://MS.VSCC.2003/commoner/redir/redirect.htm?keyword="jlca1000_javaioDataOutputStreamWrite_javalangString"'
				output.Write(v + "\n");
			}
			
			if (v == target)
				++correct;
			error += (v - target) * (v - target);
			sumv += v;
			sumy += target;
			sumvv += v * v;
			sumyy += target * target;
			sumvy += v * target;
			++total;
		}
		System.Console.Out.Write("Accuracy = " + (double) correct / total * 100 + "% (" + correct + "/" + total + ") (classification)\n");
		System.Console.Out.Write("Mean squared error = " + error / total + " (regression)\n");
		System.Console.Out.Write("Squared correlation coefficient = " + ((total * sumvy - sumv * sumy) * (total * sumvy - sumv * sumy)) / ((total * sumvv - sumv * sumv) * (total * sumyy - sumy * sumy)) + " (regression)\n");
	}
示例#21
0
        static Tuple <double, double> RunPLAvsSVM(int experiments, int points)
        {
            const int TEST_POINTS = 10000;
            Random    rnd         = new Random();

            long svmWins = 0, svCount = 0;

            for (int i = 1; i <= experiments; i++)
            {
                //pick a random line y = a * x + b
                double x1 = rnd.NextDouble(), y1 = rnd.NextDouble(), x2 = rnd.NextDouble(), y2 = rnd.NextDouble();
                var    Wf = new DenseVector(3);
                Wf[0] = 1;
                Wf[1] = (y1 - y2) / (x1 * y2 - y1 * x2);
                Wf[2] = (x2 - x1) / (x1 * y2 - y1 * x2);
                Func <MathNet.Numerics.LinearAlgebra.Generic.Vector <double>, int> f = x => Wf.DotProduct(x) >= 0 ? 1 : -1;

                //generate training set of N random points
                var X = new DenseMatrix(points, 3);
                do
                {
                    for (int j = 0; j < points; j++)
                    {
                        X[j, 0] = 1;
                        X[j, 1] = rnd.NextDouble() * 2 - 1;
                        X[j, 2] = rnd.NextDouble() * 2 - 1;
                    }
                }while (Enumerable.Range(0, X.RowCount).All(j => f(X.Row(0)) == f(X.Row(j))));

                var W = new DenseVector(3);
                Func <MathNet.Numerics.LinearAlgebra.Generic.Vector <double>, int> h = x => W.DotProduct(x) >= 0 ? 1 : -1;

                //run Perceptron
                int k = 1;
                while (Enumerable.Range(0, points).Any(j => h(X.Row(j)) != f(X.Row(j))))
                {
                    //find all misclasified points
                    int[] M = Enumerable.Range(0, points).Where(j => h(X.Row(j)) != f(X.Row(j))).ToArray();
                    int   m = M[rnd.Next(0, M.Length)];

                    int sign = f(X.Row(m));
                    W[0] += sign;
                    W[1] += sign * X[m, 1];
                    W[2] += sign * X[m, 2];
                    k++;
                }

                //calculate P[f(Xtest) != h(Xtest)]
                DenseVector Xtest = new DenseVector(3);
                Xtest[0] = 1;
                int matches = 0;
                for (int j = 0; j < TEST_POINTS; j++)
                {
                    Xtest[1] = rnd.NextDouble() * 2 - 1;
                    Xtest[2] = rnd.NextDouble() * 2 - 1;
                    if (f(Xtest) == h(Xtest))
                    {
                        matches++;
                    }
                }
                double Ppla = (matches + 0.0) / TEST_POINTS;

                //Run SVM
                var prob = new svm_problem()
                {
                    x = Enumerable.Range(0, points).Select(j =>
                                                           new svm_node[] {
                        new svm_node()
                        {
                            index = 0, value = X[j, 1]
                        },
                        new svm_node()
                        {
                            index = 1, value = X[j, 2]
                        }
                    }).ToArray(),
                    y = Enumerable.Range(0, points).Select(j => (double)f(X.Row(j))).ToArray(),
                    l = points
                };

                var model = svm.svm_train(prob, new svm_parameter()
                {
                    svm_type    = (int)SvmType.C_SVC,
                    kernel_type = (int)KernelType.LINEAR,
                    C           = 1000000,
                    eps         = 0.001,
                    shrinking   = 0
                });

                //calculate P[f(Xtest) != h_svm(Xtest)]
                svm_node[] Xsvm = new svm_node[] {
                    new svm_node()
                    {
                        index = 0, value = 1.0
                    },
                    new svm_node()
                    {
                        index = 1, value = 1.0
                    }
                };
                matches = 0;

                for (int j = 0; j < TEST_POINTS; j++)
                {
                    Xtest[1]      = rnd.NextDouble() * 2 - 1;
                    Xsvm[0].value = Xtest[1];
                    Xtest[2]      = rnd.NextDouble() * 2 - 1;
                    Xsvm[1].value = Xtest[2];
                    if (f(Xtest) == (svm.svm_predict(model, Xsvm) > 0 ? 1 : -1))
                    {
                        matches++;
                    }
                }
                double Psvm = (matches + 0.0) / TEST_POINTS;

                svCount += model.l;
                if (Psvm >= Ppla)
                {
                    svmWins++;
                }
            }

            return(Tuple.Create((svmWins + 0.0) / experiments, (svCount + 0.0) / experiments));
        }