Exemplo n.º 1
0
        public void TestSvc()
        {
            var clf = new Svc <int>(kernel: Kernel.Linear, probability: true);

            clf.Fit(X, Y);

            var spClf = new Svc <int>(kernel: Kernel.Linear, probability: true);

            spClf.Fit(SparseMatrix.OfMatrix(X), Y);

            Assert.IsTrue(spClf.Predict(T).SequenceEqual(true_result));

            Assert.IsTrue(spClf.SupportVectors is SparseMatrix);
            Assert.IsTrue(clf.SupportVectors.AlmostEquals(spClf.SupportVectors));

            Assert.IsTrue(spClf.DualCoef is SparseMatrix);
            Assert.IsTrue(clf.DualCoef.AlmostEquals(spClf.DualCoef));

            Assert.IsTrue(spClf.Coef is SparseMatrix);
            Assert.IsTrue(clf.Coef.AlmostEquals(spClf.Coef));
            Assert.IsTrue(clf.Support.SequenceEqual(spClf.Support));
            Assert.IsTrue(clf.Predict(T).SequenceEqual(spClf.Predict(T)));

            // refit with a different dataset

            clf.Fit(X2, Y2);
            spClf.Fit(SparseMatrix.OfMatrix(X2), Y2);
            Assert.IsTrue(clf.SupportVectors.AlmostEquals(spClf.SupportVectors));
            Assert.IsTrue(clf.DualCoef.AlmostEquals(spClf.DualCoef));
            Assert.IsTrue(clf.Coef.AlmostEquals(spClf.Coef));
            Assert.IsTrue(clf.Support.SequenceEqual(spClf.Support));
            Assert.IsTrue(clf.Predict(T2).SequenceEqual(spClf.Predict(T2)));
            Assert.IsTrue(clf.PredictProba(T2).AlmostEquals(spClf.PredictProba(T2), 0.001));
        }
Exemplo n.º 2
0
        public void TestDecisionFunction()
        {
            // multi class:
            var clf = new Svc <int>(kernel: Kernel.Linear, c: 0.1);

            clf.Fit(iris.Data, iris.Target);

            var dec = (iris.Data * clf.Coef.Transpose()).AddRowVector(clf.Intercept);

            Assert.IsTrue(dec.AlmostEquals(clf.DecisionFunction(iris.Data)));

            // binary:
            clf.Fit(X, Y);
            dec = (X * clf.Coef.Transpose()).AddRowVector(clf.Intercept);
            int[] prediction = clf.Predict(X);
            Assert.IsTrue(dec.AlmostEquals(clf.DecisionFunction(X)));

            var b = clf.DecisionFunction(X).Column(0).Select(v => clf.Classes[v > 0 ? 1 : 0]);

            Assert.IsTrue(prediction.SequenceEqual(b));

            var expected = DenseMatrix.OfArray(new[, ] {
                { -1.0 }, { -0.66 }, { -1.0 }, { 0.66 }, { 1.0 }, { 1.0 }
            });

            Assert.IsTrue(clf.DecisionFunction(X).AlmostEquals(expected, 1E-2));
        }
Exemplo n.º 3
0
        //
        private static void SinglePredict(Svc secureSvc, double[] feature, int i, CKKSEncoder encoder, Encryptor encryptor, Decryptor decryptor,
                                          Stopwatch innerProductStopwatch, Stopwatch degreeStopwatch, Stopwatch negateStopwatch, Stopwatch serverDecisionStopWatch, double scale, Result[] results)
        {
            double finalResult = 0;

            Console.WriteLine($"start {i} \n");

            var plaintexts          = new Plaintext();
            var featuresCiphertexts = new Ciphertext();

            encoder.Encode(feature, scale, plaintexts);
            encryptor.Encrypt(plaintexts, featuresCiphertexts);
            // Server side start
            var cyphetResult = secureSvc.Predict(featuresCiphertexts, true, true, innerProductStopwatch, degreeStopwatch, negateStopwatch, serverDecisionStopWatch);
            // Server side end
            //timePredictSum.Stop();
            Plaintext plainResult = new Plaintext();

            decryptor.Decrypt(cyphetResult, plainResult);
            List <double> result = new List <double>();

            encoder.Decode(plainResult, result);
            finalResult = result[0];
            int estimation = finalResult > 0 ? 0 : 1;

            Console.WriteLine($"\n ************************************************");
            Console.WriteLine($"SVC estimation{i} is : {estimation} , result : {finalResult}");
            //file.WriteLine($"{i} , {estimation} , {finalResult} ");
            Console.WriteLine($"************************************************ \n");
            results[i] = new Result(finalResult, estimation);
            //Console.WriteLine($"SecureSVC estimation{i} is : {estimation} , finalResult = {finalResult} , Time = {timePredictSum.ElapsedMilliseconds}");
        }
Exemplo n.º 4
0
        /// <summary>
        /// Make sure some tweaking of parameters works.
        ///
        /// We change clf.dual_coef_ at run time and expect .predict() to change
        /// accordingly. Notice that this is not trivial since it involves a lot
        /// of C/Python copying in the libsvm bindings.
        ///
        /// The success of this test ensures that the mapping between libsvm and
        /// the python classifier is complete.
        /// </summary>
        public void TestTweakParams()
        {
            var clf = new Svc <int>(kernel: Kernel.Linear, c: 1.0);

            clf.Fit(X, Y);
            Assert.IsTrue(clf.DualCoef.AlmostEquals(DenseMatrix.OfArray(new[, ] {
                { 0.25, -0.25 }
            })));
            Assert.IsTrue(clf.Predict(DenseMatrix.OfArray(new[, ] {
                { -.1, -.1 }
            })).SequenceEqual(new[] { 1 }));
            clf.DualCoef = DenseMatrix.OfArray(new[, ] {
                { 0.0, 1.0 }
            });
            Assert.IsTrue(clf.Predict(DenseMatrix.OfArray(new[, ] {
                { -.1, -.1 }
            })).SequenceEqual(new[] { 2 }));
        }
Exemplo n.º 5
0
        /// <summary>
        /// Make some classification predictions on a toy dataset using a SVC
        ///
        /// If binary is True restrict to a binary classification problem instead of a
        /// multiclass classification problem
        /// </summary>
        /// <param name="x"></param>
        /// <param name="y"></param>
        /// <param name="binary"></param>
        private static Tuple <int[], int[], Matrix <double> > MakePrediction(
            Matrix <double> x = null,
            int[] y           = null,
            bool binary       = false)
        {
            if (x == null && y == null)
            {
                // import some data to play with
                var dataset = IrisDataset.Load();
                x = dataset.Data;
                y = dataset.Target;
            }

            if (binary)
            {
                // restrict to a binary classification task
                x = x.RowsAt(y.Indices(v => v < 2));
                y = y.Where(v => v < 2).ToArray();
            }

            int nSamples  = x.RowCount;
            int nFeatures = x.ColumnCount;
            var rng       = new Random(37);

            int[] p = Shuffle(rng, Enumerable.Range(0, nSamples).ToArray());
            x = x.RowsAt(p);
            y = y.ElementsAt(p);
            var half = nSamples / 2;

            // add noisy features to make the problem harder and avoid perfect results
            rng = new Random(0);
            x   = x.HStack(DenseMatrix.CreateRandom(nSamples, 200, new Normal {
                RandomSource = rng
            }));

            // run classifier, get class probabilities and label predictions
            var clf = new Svc <int>(kernel: Kernel.Linear, probability: true);

            clf.Fit(x.SubMatrix(0, half, 0, x.ColumnCount), y.Take(half).ToArray());
            Matrix <double> probasPred = clf.PredictProba(x.SubMatrix(half, x.RowCount - half, 0, x.ColumnCount));

            if (binary)
            {
                // only interested in probabilities of the positive case
                // XXX: do we really want a special API for the binary case?
                probasPred = probasPred.SubMatrix(0, probasPred.RowCount, 1, 1);
            }

            var yPred = clf.Predict(x.SubMatrix(half, x.RowCount - half, 0, x.ColumnCount));
            var yTrue = y.Skip(half).ToArray();

            return(Tuple.Create(yTrue, yPred, probasPred));
        }
Exemplo n.º 6
0
        public void TestSvcWithCustomKernel()
        {
            var clfLin = new Svc <int>(kernel: Kernel.Linear);

            clfLin.Fit(SparseMatrix.OfMatrix(X), Y);
            var clfMylin =
                new Svc <int>(kernel: Kernel.FromFunction((x, y) => x * y.Transpose()));

            clfMylin.Fit(SparseMatrix.OfMatrix(X), Y);
            Assert.IsTrue(
                clfLin.Predict(SparseMatrix.OfMatrix(X)).SequenceEqual(clfMylin.Predict(SparseMatrix.OfMatrix(X))));
        }
Exemplo n.º 7
0
 public void TestLibsvmIris()
 {
     // shuffle the dataset so that labels are not ordered
     foreach (var k in new[] { Kernel.Linear, Kernel.Rbf })
     {
         var clf = new Svc <int>(kernel: k);
         clf.Fit(iris.Data, iris.Target);
         var pred      = clf.Predict(iris.Data);
         var matchingN = pred.Zip(iris.Target, Tuple.Create).Where(t => t.Item1 == t.Item2).Count();
         Assert.IsTrue(1.0 * matchingN / pred.Length > 0.9);
         Assert.IsTrue(clf.Classes.SequenceEqual(clf.Classes.OrderBy(v => v)));
     }
 }
Exemplo n.º 8
0
        public void TestSingleSample_1D()
        {
            var clf = new Svc <int>();

            clf.Fit(X, Y);
            var p = clf.Predict(X.Row(0).ToRowMatrix());

            Assert.AreEqual(Y[0], p[0]);

            //todo:
            //clf = svm.LinearSVC(random_state=0).fit(X, Y)
            //clf.predict(X[0])
        }
Exemplo n.º 9
0
        /// <summary>
        /// Make some classification predictions on a toy dataset using a SVC
        ///
        /// If binary is True restrict to a binary classification problem instead of a
        /// multiclass classification problem
        /// </summary>
        /// <param name="x"></param>
        /// <param name="y"></param>
        /// <param name="binary"></param>
        private static Tuple<int[], int[], Matrix<double>> MakePrediction(
            Matrix<double> x = null,
            int[] y = null,
            bool binary = false)
        {
            if (x == null && y == null)
            {
                // import some data to play with
                var dataset = IrisDataset.Load();
                x = dataset.Data;
                y = dataset.Target;
            }

            if (binary)
            {
                // restrict to a binary classification task
                x = x.RowsAt(y.Indices(v => v < 2));
                y = y.Where(v => v < 2).ToArray();
            }

            int nSamples = x.RowCount;
            int nFeatures = x.ColumnCount;
            var rng = new Random(37);
            int[] p = Shuffle(rng, Enumerable.Range(0, nSamples).ToArray());
            x = x.RowsAt(p);
            y = y.ElementsAt(p);
            var half = nSamples/2;

            // add noisy features to make the problem harder and avoid perfect results
            rng = new Random(0);
            x = x.HStack(DenseMatrix.CreateRandom(nSamples, 200, new Normal{RandomSource = rng}));

            // run classifier, get class probabilities and label predictions
            var clf = new Svc<int>(kernel: Kernel.Linear, probability: true);
            clf.Fit(x.SubMatrix(0, half, 0, x.ColumnCount), y.Take(half).ToArray());
            Matrix<double> probasPred = clf.PredictProba(x.SubMatrix(half, x.RowCount - half, 0, x.ColumnCount));

            if (binary)
            {
                // only interested in probabilities of the positive case
                // XXX: do we really want a special API for the binary case?
                probasPred = probasPred.SubMatrix(0, probasPred.RowCount, 1, 1);
            }

            var yPred = clf.Predict(x.SubMatrix(half, x.RowCount - half, 0, x.ColumnCount));
            var yTrue = y.Skip(half).ToArray();
            return Tuple.Create(yTrue, yPred, probasPred);
        }
Exemplo n.º 10
0
        public void TestLibsvmParameters()
        {
            var clf = new Svc <int>(kernel: Kernel.Linear);

            clf.Fit(X, Y);
            Assert.IsTrue(clf.DualCoef.AlmostEquals(DenseMatrix.OfArray(new[, ] {
                { 0.25, -.25 }
            })));
            Assert.IsTrue(clf.Support.SequenceEqual(new[] { 1, 3 }));
            Assert.IsTrue(
                clf.SupportVectors.AlmostEquals(
                    DenseMatrix.OfRows(2, X.ColumnCount, new[] { X.Row(1), X.Row(3) })));

            Assert.IsTrue(clf.Intercept.SequenceEqual(new[] { 0.0 }));
            Assert.IsTrue(clf.Predict(X).SequenceEqual(Y));
        }
Exemplo n.º 11
0
        public void TestSvcWithCallableKernel()
        {
            // create SVM with callable linear kernel, check that results are the same
            // as with built-in linear kernel
            var svmCallable = new Svc <int>(kernel: Kernel.FromFunction((x, y) => x * (y.Transpose())),
                                            probability: true);

            svmCallable.Fit(X, Y);
            var svmBuiltin = new Svc <int>(kernel: Kernel.Linear, probability: true);

            svmBuiltin.Fit(X, Y);

            Assert.IsTrue(svmCallable.DualCoef.AlmostEquals(svmBuiltin.DualCoef));
            Assert.IsTrue(svmCallable.Intercept.AlmostEquals(svmBuiltin.Intercept));
            Assert.IsTrue(svmCallable.Predict(X).SequenceEqual(svmBuiltin.Predict(X)));

            Assert.IsTrue(svmCallable.PredictProba(X).AlmostEquals(svmBuiltin.PredictProba(X), 1));
            Assert.IsTrue(svmCallable.DecisionFunction(X).AlmostEquals(svmBuiltin.DecisionFunction(X), 2));
        }
Exemplo n.º 12
0
        public void TestSvcIris()
        {
            foreach (var k in new[] { Kernel.Linear, Kernel.Poly, Kernel.Rbf })
            {
                var spClf = new Svc <int>(kernel: k);
                spClf.Fit(SparseMatrix.OfMatrix(iris.Data), iris.Target);
                var clf = new Svc <int>(kernel: k);
                clf.Fit(DenseMatrix.OfMatrix(iris.Data), iris.Target);

                Assert.IsTrue(clf.SupportVectors.AlmostEquals(spClf.SupportVectors));
                Assert.IsTrue(clf.DualCoef.AlmostEquals(spClf.DualCoef));
                Assert.IsTrue(
                    clf.Predict(DenseMatrix.OfMatrix(iris.Data)).SequenceEqual(
                        spClf.Predict(SparseMatrix.OfMatrix(iris.Data))));

                if (k == Kernel.Linear)
                {
                    Assert.IsTrue(clf.Coef.AlmostEquals(spClf.Coef));
                }
            }
        }
Exemplo n.º 13
0
        public void test_weight()
        {
            var clf = new Svc <int>(classWeightEstimator: ClassWeightEstimator <int> .Explicit(new Dictionary <int, double> {
                { 1, 0.1 }
            }));

            // we give a small weights to class 1
            clf.Fit(X, Y);
            // so all predicted values belong to class 2
            Assert.IsTrue(clf.Predict(X).SequenceEqual(Enumerable.Repeat(2, 6)));

            /*
             * X_, y_ = make_classification(n_samples=200, n_features=10,
             *                   weights=[0.833, 0.167], random_state=2)
             *
             * for clf in (linear_model.LogisticRegression(),
             *  svm.LinearSVC(random_state=0), svm.SVC()):
             * clf.set_params(class_weight={0: .1, 1: 10})
             * clf.fit(X_[:100], y_[:100])
             * y_pred = clf.predict(X_[100:])
             * assert_true(f1_score(y_[100:], y_pred) > .3)
             * */
        }
Exemplo n.º 14
0
        public void TestLibsvmParameters()
        {
            var clf = new Svc<int>(kernel: Kernel.Linear);
            clf.Fit(X, Y);
            Assert.IsTrue(clf.DualCoef.AlmostEquals(DenseMatrix.OfArray(new[,] {{0.25, -.25}})));
            Assert.IsTrue(clf.Support.SequenceEqual(new[] {1, 3}));
            Assert.IsTrue(
                clf.SupportVectors.AlmostEquals(
                DenseMatrix.OfRows(2, X.ColumnCount, new[] {X.Row(1), X.Row(3)})));

            Assert.IsTrue(clf.Intercept.SequenceEqual(new[] {0.0}));
            Assert.IsTrue(clf.Predict(X).SequenceEqual(Y));
        }
Exemplo n.º 15
0
        public void TestSvcIris()
        {
            foreach (var k in new[] {Kernel.Linear, Kernel.Poly, Kernel.Rbf})
            {
                var spClf = new Svc<int>(kernel: k);
                spClf.Fit(SparseMatrix.OfMatrix(iris.Data), iris.Target);
                var clf = new Svc<int>(kernel: k);
                clf.Fit(DenseMatrix.OfMatrix(iris.Data), iris.Target);

                Assert.IsTrue(clf.SupportVectors.AlmostEquals(spClf.SupportVectors));
                Assert.IsTrue(clf.DualCoef.AlmostEquals(spClf.DualCoef));
                Assert.IsTrue(
                    clf.Predict(DenseMatrix.OfMatrix(iris.Data)).SequenceEqual(
                        spClf.Predict(SparseMatrix.OfMatrix(iris.Data))));

                if (k == Kernel.Linear)
                {
                    Assert.IsTrue(clf.Coef.AlmostEquals(spClf.Coef));
                }
            }
        }
Exemplo n.º 16
0
 public void TestSvcWithCustomKernel()
 {
     var clfLin = new Svc<int>(kernel: Kernel.Linear);
     clfLin.Fit(SparseMatrix.OfMatrix(X), Y);
     var clfMylin =
         new Svc<int>(kernel: Kernel.FromFunction((x, y) => x*y.Transpose()));
     clfMylin.Fit(SparseMatrix.OfMatrix(X), Y);
     Assert.IsTrue(
         clfLin.Predict(SparseMatrix.OfMatrix(X)).SequenceEqual(clfMylin.Predict(SparseMatrix.OfMatrix(X))));
 }
Exemplo n.º 17
0
        public void TestSvcWithCallableKernel()
        {
            // create SVM with callable linear kernel, check that results are the same
            // as with built-in linear kernel
            var svmCallable = new Svc<int>(kernel: Kernel.FromFunction((x, y) => x*(y.Transpose())),
                                            probability: true);

            svmCallable.Fit(X, Y);
            var svmBuiltin = new Svc<int>(kernel: Kernel.Linear, probability: true);
            svmBuiltin.Fit(X, Y);

            Assert.IsTrue(svmCallable.DualCoef.AlmostEquals(svmBuiltin.DualCoef));
            Assert.IsTrue(svmCallable.Intercept.AlmostEquals(svmBuiltin.Intercept));
            Assert.IsTrue(svmCallable.Predict(X).SequenceEqual(svmBuiltin.Predict(X)));

            Assert.IsTrue(svmCallable.PredictProba(X).AlmostEquals(svmBuiltin.PredictProba(X), 1));
            Assert.IsTrue(svmCallable.DecisionFunction(X).AlmostEquals(svmBuiltin.DecisionFunction(X), 2));
        }
Exemplo n.º 18
0
        public void test_weight()
        {
            var clf = new Svc<int>(classWeightEstimator: ClassWeightEstimator<int>.Explicit(new Dictionary<int, double> {{1, 0.1}}));

            // we give a small weights to class 1
            clf.Fit(X, Y);
            // so all predicted values belong to class 2
            Assert.IsTrue(clf.Predict(X).SequenceEqual(Enumerable.Repeat(2, 6)));
            /*
    X_, y_ = make_classification(n_samples=200, n_features=10,
                                 weights=[0.833, 0.167], random_state=2)

    for clf in (linear_model.LogisticRegression(),
                svm.LinearSVC(random_state=0), svm.SVC()):
        clf.set_params(class_weight={0: .1, 1: 10})
        clf.fit(X_[:100], y_[:100])
        y_pred = clf.predict(X_[100:])
        assert_true(f1_score(y_[100:], y_pred) > .3)
             * */
        }
Exemplo n.º 19
0
        public void TestDecisionFunction()
        {
            // multi class:
            var clf = new Svc<int>(kernel: Kernel.Linear, c: 0.1);
            clf.Fit(iris.Data, iris.Target);

            var dec = (iris.Data*clf.Coef.Transpose()).AddRowVector(clf.Intercept);

            Assert.IsTrue(dec.AlmostEquals(clf.DecisionFunction(iris.Data)));

            // binary:
            clf.Fit(X, Y);
            dec = (X*clf.Coef.Transpose()).AddRowVector(clf.Intercept);
            int[] prediction = clf.Predict(X);
            Assert.IsTrue(dec.AlmostEquals(clf.DecisionFunction(X)));

            var b = clf.DecisionFunction(X).Column(0).Select(v => clf.Classes[v > 0 ? 1 : 0]);
            Assert.IsTrue(prediction.SequenceEqual(b));

            var expected = DenseMatrix.OfArray(new[,] {{-1.0}, {-0.66}, {-1.0}, {0.66}, {1.0}, {1.0}});
            Assert.IsTrue(clf.DecisionFunction(X).AlmostEquals(expected, 1E-2));
        }
Exemplo n.º 20
0
 /// <summary>
 /// Make sure some tweaking of parameters works.
 /// 
 /// We change clf.dual_coef_ at run time and expect .predict() to change
 /// accordingly. Notice that this is not trivial since it involves a lot
 /// of C/Python copying in the libsvm bindings.
 ///
 /// The success of this test ensures that the mapping between libsvm and
 /// the python classifier is complete.
 /// </summary>
 public void TestTweakParams()
 {
     var clf = new Svc<int>(kernel: Kernel.Linear, c: 1.0);
     clf.Fit(X, Y);
     Assert.IsTrue(clf.DualCoef.AlmostEquals(DenseMatrix.OfArray(new[,]{{0.25, -0.25}})));
     Assert.IsTrue(clf.Predict(DenseMatrix.OfArray(new[,] {{-.1, -.1}})).SequenceEqual(new[] {1}));
     clf.DualCoef = DenseMatrix.OfArray(new[,] {{0.0, 1.0}});
     Assert.IsTrue(clf.Predict(DenseMatrix.OfArray(new[,] {{-.1, -.1}})).SequenceEqual(new[] {2}));
 }
Exemplo n.º 21
0
        static async Task Main(string[] args)
        {
            Console.WriteLine("Secure Iris");

            // Get Input from resource file or as args
            double[][] features;
            int        numberOfFeatures = 4;
            int        numOfRows        = 0;

            // Option to load from args and not the whole dataset that is stored in resources
            if (args.Length >= numberOfFeatures)
            {
                numOfRows = args.Length / numberOfFeatures;
                // Features:
                features = new double[numOfRows][];
                for (int i = 0; i < numOfRows; i++)
                {
                    features[i] = new double[numberOfFeatures];
                }
                for (int i = 0, l = args.Length; i < l; i++)
                {
                    features[i / numberOfFeatures][i % numberOfFeatures] = Double.Parse(args[i]);
                }
            }

            else  // load the whole dataset from resources
            {
                List <double[]> rows = new List <double[]>();

                var bytes = Properties.Resources.iris;
                numOfRows = 0;
                features  = SVCUtilities.SvcUtilities.LoadFeatures(bytes, numberOfFeatures, ref numOfRows);
            }
            Stopwatch clientStopwatch = new Stopwatch();

            clientStopwatch.Start();

            //svm algorithm parametrs calculated in python : training result
            double[][] vectors = new double[3][];
            vectors[0] = new[] { 4.5, 2.3, 1.3, 0.3 };
            vectors[1] = new[] { 5.1, 3.3, 1.7, 0.5 };
            vectors[2] = new[] { 5.1, 2.5, 3.0, 1.1 };

            double[][] coefficients = new double[1][];
            coefficients[0] = new double[] { -0.07724840262003278, -0.6705185831514366, 0.7477669857714694 };
            double[] intercepts = { 1.453766563649063 };


            // SEAL parameters client side
            Console.WriteLine("SecureSVC : ");

            EncryptionParameters parms = new EncryptionParameters(SchemeType.CKKS);

            ulong polyModulusDegree = 16384;
            int   power             = 40;

            double scale = Math.Pow(2.0, power);

            if (power >= 20 && power < 40)
            {
                parms.CoeffModulus = CoeffModulus.Create(polyModulusDegree,
                                                         new int[] { 60, 20, 21, 22, 23, 24, 25, 26, 27, 60 });
            }
            else if (power >= 40 && power < 60)
            {
                parms.CoeffModulus = CoeffModulus.Create(polyModulusDegree,
                                                         new int[] { 60, 40, 40, 40, 40, 40, 40, 40, 60 });
            }
            else if (power == 60)
            {
                polyModulusDegree  = 32768;
                parms.CoeffModulus = CoeffModulus.Create(polyModulusDegree,
                                                         new int[] { 60, 60, 60, 60, 60, 60, 60, 60, 60 });
            }
            parms.PolyModulusDegree = polyModulusDegree;



            var context = new SEALContext(parms);
            // Key generation
            KeyGenerator keygen    = new KeyGenerator(context);
            var          publicKey = keygen.PublicKey;
            var          secretKey = keygen.SecretKey;
            var          relinKeys = keygen.RelinKeys();

            var galoisKeys = keygen.GaloisKeys();
            var encryptor  = new Encryptor(context, publicKey);

            var decryptor = new Decryptor(context, secretKey);
            var encoder   = new CKKSEncoder(context);

            clientStopwatch.Stop();


            using (System.IO.StreamWriter file =
                       new System.IO.StreamWriter(
                           $@"{OutputDir}IrisLinearSecured_{IsParallel}_{DateTime.Now.Day}_{DateTime.Now.ToShortTimeString().ToString().Replace(":", "_")}.txt")
                   )
            {
                // Only CONCEPT demonstation how to parrallel all the computation on all machine cpu's
                // Though the parallel here is done on the client side , in "real life" this parallel mechanism
                // Should on the server side
                if (IsParallel)
                {
                    int processorCount = Environment.ProcessorCount;
                    Console.WriteLine("Number Of Logical Processors: {0}", processorCount);

                    Svc[] machines = new Svc[processorCount];

                    Stopwatch[] innerProductStopwatchArr   = new Stopwatch[processorCount];
                    Stopwatch[] negateStopwatchArr         = new Stopwatch[processorCount];
                    Stopwatch[] degreeStopwatchArr         = new Stopwatch[processorCount];
                    Stopwatch[] serverDecisionStopWatchArr = new Stopwatch[processorCount];
                    Result[]    results = new Result[numOfRows];

                    Task[] tasks = new Task[processorCount];
                    for (int i = 0; i < processorCount; i++)
                    {
                        machines[i] = new Svc(vectors, coefficients, intercepts, "Linear", 0.25, 0.0, 3, 40, publicKey /*, secretKey*/, relinKeys, galoisKeys, 1, 4);
                        innerProductStopwatchArr[i]   = new Stopwatch();
                        negateStopwatchArr[i]         = new Stopwatch();
                        degreeStopwatchArr[i]         = new Stopwatch();
                        serverDecisionStopWatchArr[i] = new Stopwatch();
                    }
                    Stopwatch totalTime = new Stopwatch();
                    totalTime.Start();
                    for (int i = 0; i < numOfRows;)
                    {
                        for (int j = 0; j < processorCount && i < numOfRows; j++)
                        {
                            var secureSvc = machines[i % processorCount];
                            var feature   = features[i];
                            //Console.WriteLine($"\n\n $$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$");
                            List <object> l = new List <object>();
                            l.Add(secureSvc);                  //0
                            l.Add(feature);                    //1
                            l.Add(i);                          //2
                            l.Add(encoder);                    //3
                            l.Add(encryptor);                  //4
                            l.Add(decryptor);                  //5
                            l.Add(innerProductStopwatchArr[i % processorCount]);
                            l.Add(degreeStopwatchArr[i % processorCount]);
                            l.Add(negateStopwatchArr[i % processorCount]);
                            l.Add(serverDecisionStopWatchArr[i % processorCount]);

                            l.Add(results);
                            tasks[j] = new TaskFactory().StartNew(new Action <object>((test) =>
                            {
                                List <object> l2 = (List <object>)test;

                                SinglePredict((Svc)l2[0], (double[])l2[1], (int)l2[2], (CKKSEncoder)l2[3], (Encryptor)l2[4], (Decryptor)l2[5], (Stopwatch)l2[6], (Stopwatch)l2[7], (Stopwatch)l2[8], (Stopwatch)l2[9], scale, (Result[])l2[10]);
                            }), l);
                            i++;
                        }

                        await Task.WhenAll(tasks);
                    }

                    totalTime.Stop();

                    for (int i = 0; i < numOfRows; i++)
                    {
                        var result = results[i];
                        file.WriteLine($"{i} , {result.Estimation} , {result.TotalValue} ");
                    }

                    double innerProductTime = 0;
                    double degreeTime       = 0;
                    double negateTime       = 0;
                    double serverTime       = 0;

                    for (int i = 0; i < processorCount; i++)
                    {
                        innerProductTime = innerProductStopwatchArr[i].ElapsedMilliseconds;
                        degreeTime       = degreeStopwatchArr[i].ElapsedMilliseconds;
                        negateTime       = negateStopwatchArr[i].ElapsedMilliseconds;
                        serverTime       = serverDecisionStopWatchArr[i].ElapsedMilliseconds;
                    }
                    file.WriteLine($" Client time :  {clientStopwatch.ElapsedMilliseconds} ms  ");
                    file.WriteLine($" Total time for {numOfRows} samples :  {totalTime.ElapsedMilliseconds} ms  ");
                    file.WriteLine($" Avg time  :  {totalTime.ElapsedMilliseconds * 1000 / numOfRows} microSec ");
                    file.WriteLine($" Inner Product time for  {numOfRows} samples :  {innerProductTime} ms  ");
                    file.WriteLine($" Inner Product Avg time  :  {innerProductTime * 1000 / numOfRows} microSec ");
                    file.WriteLine($" Degree time for  {numOfRows} samples :  {degreeTime} ms  ");
                    file.WriteLine($" Degree Avg time  :  {degreeTime * 1000 / numOfRows} microSec ");
                    file.WriteLine($" Negate time for  {numOfRows} samples :  {negateTime} ms  ");
                    file.WriteLine($" Negate Avg time  :  {negateTime * 1000 / numOfRows} microSec ");
                    file.WriteLine($" Decision time for  {numOfRows} samples :  {serverTime} ms  ");
                    file.WriteLine($" Decision Avg time  :  {serverTime * 1000 / numOfRows} microSec ");
                }
                else
                {
                    //Initiate Stopwatch for performance measure
                    Stopwatch innerProductStopwatch   = new Stopwatch();
                    Stopwatch negateStopwatch         = new Stopwatch();
                    Stopwatch degreeStopwatch         = new Stopwatch();
                    Stopwatch serverDecisionStopWatch = new Stopwatch();

                    int featureSizeWithSpace = numberOfFeatures;

                    int batchSize = 200;
                    if (batchSize > 1)
                    {
                        featureSizeWithSpace = numberOfFeatures * 2;
                    }

                    Svc       clf       = new Svc(vectors, coefficients, intercepts, "Linear", 0.25, 0.0, 3, 40, publicKey /*, secretKey*/, relinKeys, galoisKeys, batchSize, featureSizeWithSpace);
                    Stopwatch totalTime = new Stopwatch();
                    totalTime.Start();
                    int start = 0;
                    //double[] batchFeatures = new double[batchSize * featureSizeWithSpace];
                    for (int i = 0; i < numOfRows;)
                    {
                        start = i;
                        double     finalResult = -10000;
                        double[][] batchRows   = new double[batchSize][];
                        for (int j = 0; j < batchSize && i < numOfRows; j++)
                        {
                            batchRows[j] = features[i];
                            i++;
                        }
                        double[] batchFeatures = GetBatchFeatures(batchRows, batchSize, numberOfFeatures, featureSizeWithSpace);


                        var plaintexts          = new Plaintext();
                        var featuresCiphertexts = new Ciphertext();
                        encoder.Encode(batchFeatures, scale, plaintexts);
                        encryptor.Encrypt(plaintexts, featuresCiphertexts);

                        //Server side start
                        var cypherResult = clf.Predict(featuresCiphertexts, true, true, innerProductStopwatch, degreeStopwatch, negateStopwatch, serverDecisionStopWatch);
                        // Server side end
                        Plaintext plainResult = new Plaintext();
                        decryptor.Decrypt(cypherResult, plainResult);
                        List <double> result = new List <double>();
                        encoder.Decode(plainResult, result);

                        for (int j = 0; j < batchSize && start < numOfRows; j++)
                        {
                            finalResult = result[j * featureSizeWithSpace];
                            int estimation = finalResult > 0 ? 0 : 1;
                            Console.WriteLine($"\n ************************************************");
                            Console.WriteLine($"SVC estimation{i} is : {estimation} , result : {finalResult}");
                            file.WriteLine($"{start} , {estimation} , {finalResult} ");
                            Console.WriteLine($"************************************************ \n");
                            start++;
                        }
                    }
                    totalTime.Stop();
                    file.WriteLine($" Client time :  {clientStopwatch.ElapsedMilliseconds} ms  ");
                    file.WriteLine($" Total time for {numOfRows} samples :  {totalTime.ElapsedMilliseconds} ms  ");
                    file.WriteLine($" Avg time  :  {totalTime.ElapsedMilliseconds * 1000 / numOfRows} microSec ");
                    file.WriteLine($" Inner Product time for  {numOfRows} samples :  {innerProductStopwatch.ElapsedMilliseconds} ms  ");
                    file.WriteLine($" Inner Product Avg time  :  {innerProductStopwatch.ElapsedMilliseconds * 1000 / numOfRows} microSec ");
                    file.WriteLine($" Degree time for  {numOfRows} samples :  {degreeStopwatch.ElapsedMilliseconds} ms  ");
                    file.WriteLine($" Degree Avg time  :  {degreeStopwatch.ElapsedMilliseconds * 1000 / numOfRows} microSec ");
                    file.WriteLine($" Negate time for  {numOfRows} samples :  {negateStopwatch.ElapsedMilliseconds} ms  ");
                    file.WriteLine($" Negate Avg time  :  {negateStopwatch.ElapsedMilliseconds * 1000 / numOfRows} microSec ");
                    file.WriteLine($" Decision time for  {numOfRows} samples :  {serverDecisionStopWatch.ElapsedMilliseconds} ms  ");
                    file.WriteLine($" Decision Avg time  :  {serverDecisionStopWatch.ElapsedMilliseconds * 1000 / numOfRows} microSec ");
                }
            }
        }
Exemplo n.º 22
0
        public void TestSvc()
        {
            var clf = new Svc<int>(kernel: Kernel.Linear, probability: true);
            clf.Fit(X, Y);

            var spClf = new Svc<int>(kernel: Kernel.Linear, probability: true);
            spClf.Fit(SparseMatrix.OfMatrix(X), Y);

            Assert.IsTrue(spClf.Predict(T).SequenceEqual(true_result));

            Assert.IsTrue(spClf.SupportVectors is SparseMatrix);
            Assert.IsTrue(clf.SupportVectors.AlmostEquals(spClf.SupportVectors));

            Assert.IsTrue(spClf.DualCoef is SparseMatrix);
            Assert.IsTrue(clf.DualCoef.AlmostEquals(spClf.DualCoef));

            Assert.IsTrue(spClf.Coef is SparseMatrix);
            Assert.IsTrue(clf.Coef.AlmostEquals(spClf.Coef));
            Assert.IsTrue(clf.Support.SequenceEqual(spClf.Support));
            Assert.IsTrue(clf.Predict(T).SequenceEqual(spClf.Predict(T)));

            // refit with a different dataset

            clf.Fit(X2, Y2);
            spClf.Fit(SparseMatrix.OfMatrix(X2), Y2);
            Assert.IsTrue(clf.SupportVectors.AlmostEquals(spClf.SupportVectors));
            Assert.IsTrue(clf.DualCoef.AlmostEquals(spClf.DualCoef));
            Assert.IsTrue(clf.Coef.AlmostEquals(spClf.Coef));
            Assert.IsTrue(clf.Support.SequenceEqual(spClf.Support));
            Assert.IsTrue(clf.Predict(T2).SequenceEqual(spClf.Predict(T2)));
            Assert.IsTrue(clf.PredictProba(T2).AlmostEquals(spClf.PredictProba(T2), 0.001));
        }
        static void Main(string[] args)
        {
            Console.WriteLine("Plain Iris");
            double[][] features;
            int        numOfRows = 0;

            // Option to load from args and not the whole dataset that is stored in resources
            if (args.Length >= 4)
            {
                numOfRows = args.Length / 4;
                // Features:
                features = new double[numOfRows][];
                for (int i = 0; i < numOfRows; i++)
                {
                    features[i] = new double[4];
                }
                for (int i = 0, l = args.Length; i < l; i++)
                {
                    features[i / 4][i % 4] = Double.Parse(args[i]);
                }
            }
            else // load the whole dataset from resources
            {
                List <double[]> rows = new List <double[]>();

                var bytes = Properties.Resources.iris;
                numOfRows = 0;
                features  = SVCUtilities.SvcUtilities.LoadFeatures(bytes, 4, ref numOfRows);
            }

            // The support vectors and the coefficients of the Iris classification algorithm
            double[][] vectors = new double[3][];

            vectors[0] = new[] { 4.5, 2.3, 1.3, 0.3 };
            vectors[1] = new[] { 5.1, 3.3, 1.7, 0.5 };
            vectors[2] = new[] { 5.1, 2.5, 3.0, 1.1 };

            double[][] coefficients = new double[1][];
            coefficients[0] = new double[] { -0.0005100630977269122, -0.008885899026071108, 0.009395962123798021 };
            double[] intercepts = { 1.1358388232934824 };
            int[]    weights    = { 2, 1 };

            Console.WriteLine("SVC : ");
            // Estimator constructor
            Svc clf = new Svc(2, 2, vectors, coefficients, intercepts, weights, "Poly", 0.25, 0.0, 3);

            using (System.IO.StreamWriter file =
                       new System.IO.StreamWriter(
                           $@"{OutputDir}IrisPolyPlain_{DateTime.Now.Day}_{DateTime.Now.ToShortTimeString().ToString().Replace(":","_")}.txt")
                   )
            {
                Stopwatch totalTime = new Stopwatch();
                totalTime.Start();
                //Run prediction onthe loaded samples
                for (int i = 0; i < numOfRows; i++)
                {
                    double finalResult = -10000;
                    int    estimation  = clf.Predict(features[i], out finalResult);
                    Console.WriteLine($"\n ************************************************");
                    Console.WriteLine($"SVC estimation{i} is : {estimation} , result : {finalResult}");
                    //write classification result to file
                    file.WriteLine($"{i} , {estimation} , {finalResult} ");
                    Console.WriteLine($"************************************************ \n");
                }
                totalTime.Stop();
                //Write performance data to file
                file.WriteLine($" Total time for {numOfRows} samples :  {totalTime.ElapsedMilliseconds} ms  ");
                file.WriteLine($" Avg time  :  {totalTime.ElapsedMilliseconds *1000 / numOfRows} microSec ");
            }
        }
        static void Main(string[] args)
        {
            Console.WriteLine("Plain Mashroom");

            double[,] vectorsMashroomD      = { { -0.8403433999584713, 0.9532703900465632, -0.9838993878642219, 1.185916567160356, 0.40656202865404567, 0.16289645171177966, -0.4388636369510842, -0.6690383093994308, 0.05347685426934428, 0.8735106372181927, -0.10348153740396093, 0.6837776537937139, 0.5863846591895536, 0.622441390325499, 0.6319913825853262, 0.0, 0.14203663498716684, -0.2561317410190009, 0.9480808566164142, -0.250470603921817, 0.2843298100961381, -0.8771690980243297 }, { -0.8403433999584713, 0.14012794477794924, -1.376724168039617, 1.185916567160356, 0.40656202865404567, 0.16289645171177966, -0.4388636369510842, -0.6690383093994308, 1.4658499494714023, -1.1448057498013176, -0.10348153740396093, 0.6837776537937139, 0.5863846591895536, 0.622441390325499, 0.6319913825853262, 0.0, 0.14203663498716684, 3.4332552519568216, 0.9480808566164142, 1.4284264144452141, 0.2843298100961381, 1.448588654048012 }, { 1.029712237713905, 0.9532703900465632, -0.19824982751343181, 1.185916567160356, 0.40656202865404567, 0.16289645171177966, -0.4388636369510842, -0.6690383093994308, 0.6184260923501674, 0.8735106372181927, -0.10348153740396093, 0.6837776537937139, 0.5863846591895536, 0.622441390325499, 0.6319913825853262, 0.0, 0.14203663498716684, -0.2561317410190009, 0.9480808566164142, -0.6701948585135749, 0.2843298100961381, -0.8771690980243297 }, { -0.21699152073434588, -1.4861569457592787, -1.376724168039617, -0.8432296400028142, 0.40656202865404567, 0.16289645171177966, 2.278612115023465, 1.494682719884397, 1.4658499494714023, -1.1448057498013176, -0.10348153740396093, 0.6837776537937139, -2.3724904782364917, 0.622441390325499, -0.94101658068771, 0.0, 0.14203663498716684, -0.2561317410190009, -1.2722157358170676, 1.4284264144452141, 0.2843298100961381, 0.28570977801184116 }, { -0.21699152073434588, -1.4861569457592787, -1.376724168039617, -0.8432296400028142, 0.40656202865404567, 0.16289645171177966, 2.278612115023465, 1.494682719884397, 1.4658499494714023, -1.1448057498013176, -0.10348153740396093, 0.6837776537937139, 0.5863846591895536, 0.622441390325499, -0.94101658068771, 0.0, 0.14203663498716684, -0.2561317410190009, -1.2722157358170676, 1.4284264144452141, 0.2843298100961381, 0.28570977801184116 }, { -2.087047158406722, 0.14012794477794924, 1.3730492931881484, 1.185916567160356, -1.970316152682646, 0.16289645171177966, -0.4388636369510842, -0.6690383093994308, -0.2289977647710673, -1.1448057498013176, 0.8389893256787506, 0.6837776537937139, 0.5863846591895536, 0.622441390325499, 0.6319913825853262, 0.0, 0.14203663498716684, -0.2561317410190009, 0.9480808566164142, -0.6701948585135749, -0.5143892000079515, -0.2957296600062443 }, { 1.029712237713905, -1.4861569457592787, -0.19824982751343181, 1.185916567160356, 0.40656202865404567, 0.16289645171177966, -0.4388636369510842, -0.6690383093994308, 1.4658499494714023, 0.8735106372181927, -0.10348153740396093, 0.6837776537937139, 0.5863846591895536, 0.622441390325499, 0.6319913825853262, 0.0, 0.14203663498716684, -0.2561317410190009, 0.9480808566164142, -0.6701948585135749, 0.2843298100961381, -0.8771690980243297 }, { -0.8403433999584713, 0.9532703900465632, -0.19824982751343181, 1.185916567160356, 0.40656202865404567, 0.16289645171177966, -0.4388636369510842, -0.6690383093994308, 0.05347685426934428, 0.8735106372181927, -0.10348153740396093, 0.6837776537937139, 0.5863846591895536, 0.622441390325499, 0.10765539482764744, 0.0, 0.14203663498716684, -0.2561317410190009, 0.9480808566164142, -0.6701948585135749, 0.2843298100961381, -0.8771690980243297 }, { 1.029712237713905, 0.14012794477794924, -0.5910746076888268, -0.8432296400028142, 0.40656202865404567, 0.16289645171177966, 2.278612115023465, -0.6690383093994308, 0.6184260923501674, 0.8735106372181927, 1.7814601887614623, 0.6837776537937139, 0.5863846591895536, 0.622441390325499, 0.6319913825853262, 0.0, 0.14203663498716684, -0.2561317410190009, -1.2722157358170676, -0.250470603921817, -0.5143892000079515, -0.2957296600062443 }, { -0.8403433999584713, -1.4861569457592787, -0.19824982751343181, 1.185916567160356, 0.40656202865404567, 0.16289645171177966, -0.4388636369510842, -0.6690383093994308, 0.6184260923501674, 0.8735106372181927, -0.10348153740396093, 0.6837776537937139, 0.5863846591895536, 0.622441390325499, 0.10765539482764744, 0.0, 0.14203663498716684, -0.2561317410190009, 0.9480808566164142, -0.6701948585135749, 0.2843298100961381, -0.8771690980243297 }, { -0.21699152073434588, 0.14012794477794924, 1.3730492931881484, -0.8432296400028142, 0.40656202865404567, 0.16289645171177966, 2.278612115023465, -0.6690383093994308, 1.4658499494714023, -1.1448057498013176, -1.0459524004866725, 0.6837776537937139, 0.5863846591895536, 0.622441390325499, 0.6319913825853262, 0.0, 0.14203663498716684, 3.4332552519568216, 0.9480808566164142, 1.4284264144452141, -1.313108210112041, -0.2957296600062443 }, { 1.029712237713905, -1.4861569457592787, -0.19824982751343181, -0.8432296400028142, 0.40656202865404567, 0.16289645171177966, -0.4388636369510842, 1.494682719884397, 0.6184260923501674, -1.1448057498013176, 1.7814601887614623, 0.6837776537937139, 0.5863846591895536, 0.622441390325499, 0.6319913825853262, 0.0, 0.14203663498716684, -0.2561317410190009, 0.9480808566164142, -0.6701948585135749, 1.0830488202002277, 2.0300280920660976 }, { -0.8403433999584713, 0.14012794477794924, 1.7658740733635434, 1.185916567160356, -1.970316152682646, 0.16289645171177966, 2.278612115023465, 1.494682719884397, 0.05347685426934428, 0.8735106372181927, -0.10348153740396093, 0.6837776537937139, 0.5863846591895536, 0.622441390325499, 0.6319913825853262, 0.0, 0.14203663498716684, -0.2561317410190009, 0.9480808566164142, -0.250470603921817, 0.2843298100961381, -0.8771690980243297 }, { -0.8403433999584713, 0.9532703900465632, 0.1945749526619632, 1.185916567160356, 0.40656202865404567, 0.16289645171177966, -0.4388636369510842, -0.6690383093994308, 1.4658499494714023, -1.1448057498013176, -0.10348153740396093, 0.6837776537937139, 0.5863846591895536, 0.622441390325499, 0.6319913825853262, 0.0, 0.14203663498716684, 3.4332552519568216, 0.9480808566164142, 1.4284264144452141, 0.2843298100961381, 1.448588654048012 }, { 1.029712237713905, 0.14012794477794924, -0.19824982751343181, -0.8432296400028142, 0.40656202865404567, -6.1388691373667745, -0.4388636369510842, -0.6690383093994308, 1.7483245685118138, -1.1448057498013176, -1.0459524004866725, 0.6837776537937139, 0.5863846591895536, -0.42928778084845187, -0.4166805929300313, 0.0, -3.9790548744261973, -0.2561317410190009, 0.9480808566164142, -1.5096433676970904, 0.2843298100961381, 0.28570977801184116 }, { -0.8403433999584713, 0.9532703900465632, 0.1945749526619632, 1.185916567160356, 0.40656202865404567, 0.16289645171177966, -0.4388636369510842, -0.6690383093994308, 1.4658499494714023, -1.1448057498013176, -0.10348153740396093, 0.6837776537937139, 0.5863846591895536, 0.622441390325499, 0.6319913825853262, 0.0, 0.14203663498716684, 3.4332552519568216, 0.9480808566164142, 1.4284264144452141, 1.0830488202002277, 1.448588654048012 }, { 1.029712237713905, -1.4861569457592787, -0.19824982751343181, 1.185916567160356, 0.40656202865404567, 0.16289645171177966, -0.4388636369510842, -0.6690383093994308, 1.4658499494714023, 0.8735106372181927, -0.10348153740396093, 0.6837776537937139, 0.5863846591895536, -1.4810169520224028, -1.4653525684453887, 0.0, 0.14203663498716684, -0.2561317410190009, 0.9480808566164142, -0.6701948585135749, 0.2843298100961381, -0.8771690980243297 }, { 1.029712237713905, 0.14012794477794924, -0.5910746076888268, -0.8432296400028142, 0.40656202865404567, 0.16289645171177966, 2.278612115023465, -0.6690383093994308, 0.6184260923501674, 0.8735106372181927, 1.7814601887614623, 0.6837776537937139, 0.5863846591895536, 0.622441390325499, 0.6319913825853262, 0.0, 0.14203663498716684, -0.2561317410190009, -1.2722157358170676, -0.250470603921817, -2.9105462303202203, -0.2957296600062443 }, { 1.029712237713905, -1.4861569457592787, -0.19824982751343181, 1.185916567160356, 0.40656202865404567, 0.16289645171177966, -0.4388636369510842, -0.6690383093994308, 1.4658499494714023, 0.8735106372181927, -0.10348153740396093, 0.6837776537937139, 0.5863846591895536, 0.622441390325499, 0.10765539482764744, 0.0, 0.14203663498716684, -0.2561317410190009, 0.9480808566164142, -0.6701948585135749, 0.2843298100961381, -0.8771690980243297 }, { -0.8403433999584713, 0.9532703900465632, -1.376724168039617, -0.8432296400028142, 0.40656202865404567, 0.16289645171177966, 2.278612115023465, 1.494682719884397, 1.4658499494714023, -1.1448057498013176, -0.10348153740396093, -2.534652044595703, 0.5863846591895536, 0.622441390325499, -0.94101658068771, 0.0, 0.14203663498716684, -0.2561317410190009, -1.2722157358170676, 1.4284264144452141, 0.2843298100961381, 0.28570977801184116 }, { -2.087047158406722, 0.14012794477794924, 1.3730492931881484, 1.185916567160356, -1.970316152682646, 0.16289645171177966, -0.4388636369510842, -0.6690383093994308, 0.05347685426934428, -1.1448057498013176, 0.8389893256787506, 0.6837776537937139, 0.5863846591895536, 0.622441390325499, 0.6319913825853262, 0.0, 0.14203663498716684, -0.2561317410190009, 0.9480808566164142, -0.6701948585135749, -0.5143892000079515, -0.2957296600062443 }, { 1.029712237713905, -1.4861569457592787, -0.19824982751343181, -0.8432296400028142, 0.40656202865404567, 0.16289645171177966, -0.4388636369510842, 1.494682719884397, 0.6184260923501674, -1.1448057498013176, 1.7814601887614623, 0.6837776537937139, 0.5863846591895536, 0.622441390325499, 0.6319913825853262, 0.0, 0.14203663498716684, -0.2561317410190009, 0.9480808566164142, -0.6701948585135749, 0.2843298100961381, 2.0300280920660976 }, { -2.087047158406722, 0.14012794477794924, 1.3730492931881484, 1.185916567160356, -0.5441892438806311, 0.16289645171177966, -0.4388636369510842, -0.6690383093994308, 0.05347685426934428, -1.1448057498013176, 0.8389893256787506, 0.6837776537937139, 0.5863846591895536, 0.622441390325499, 0.6319913825853262, 0.0, 0.14203663498716684, -0.2561317410190009, 0.9480808566164142, -0.6701948585135749, -0.5143892000079515, 0.8671492160299267 }, { -0.8403433999584713, 0.14012794477794924, -0.19824982751343181, -0.8432296400028142, 0.40656202865404567, 0.16289645171177966, -0.4388636369510842, -0.6690383093994308, 1.4658499494714023, -1.1448057498013176, -0.10348153740396093, 2.2929925029884224, 2.065822227902576, -0.9551523664354273, -0.94101658068771, 0.0, 0.14203663498716684, 3.4332552519568216, 0.9480808566164142, 1.4284264144452141, 1.0830488202002277, -0.8771690980243297 }, { -0.8403433999584713, 0.9532703900465632, 1.3730492931881484, -0.8432296400028142, 0.40656202865404567, 0.16289645171177966, -0.4388636369510842, 1.494682719884397, 1.4658499494714023, -1.1448057498013176, -1.0459524004866725, 0.6837776537937139, -2.3724904782364917, 0.622441390325499, 0.6319913825853262, 0.0, 0.14203663498716684, -0.2561317410190009, -0.7171415877086972, -1.0899191131053325, 0.2843298100961381, -0.8771690980243297 }, { -0.8403433999584713, -1.4861569457592787, -0.9838993878642219, 1.185916567160356, 0.40656202865404567, 0.16289645171177966, -0.4388636369510842, -0.6690383093994308, 0.05347685426934428, 0.8735106372181927, -0.10348153740396093, 0.6837776537937139, 0.5863846591895536, 0.622441390325499, 0.6319913825853262, 0.0, 0.14203663498716684, -0.2561317410190009, 0.9480808566164142, -0.250470603921817, 0.2843298100961381, -0.8771690980243297 }, { 1.029712237713905, -1.4861569457592787, -0.19824982751343181, 1.185916567160356, 0.40656202865404567, 0.16289645171177966, -0.4388636369510842, -0.6690383093994308, 0.05347685426934428, 0.8735106372181927, -0.10348153740396093, 0.6837776537937139, 0.5863846591895536, 0.622441390325499, 0.10765539482764744, 0.0, 0.14203663498716684, -0.2561317410190009, 0.9480808566164142, -0.250470603921817, 0.2843298100961381, -0.8771690980243297 }, { 1.029712237713905, 0.14012794477794924, 1.3730492931881484, 1.185916567160356, -1.970316152682646, 0.16289645171177966, 2.278612115023465, 1.494682719884397, 0.05347685426934428, 0.8735106372181927, -0.10348153740396093, 0.6837776537937139, 0.5863846591895536, 0.622441390325499, 0.6319913825853262, 0.0, 0.14203663498716684, -0.2561317410190009, 0.9480808566164142, -0.250470603921817, 0.2843298100961381, -0.8771690980243297 }, { -0.8403433999584713, -1.4861569457592787, -0.19824982751343181, 1.185916567160356, 0.40656202865404567, 0.16289645171177966, -0.4388636369510842, -0.6690383093994308, 1.1833753304309906, 0.8735106372181927, -0.10348153740396093, 0.6837776537937139, 0.5863846591895536, 0.622441390325499, 0.10765539482764744, 0.0, 0.14203663498716684, -0.2561317410190009, 0.9480808566164142, -0.6701948585135749, 0.2843298100961381, -0.8771690980243297 }, { -0.8403433999584713, 0.9532703900465632, -0.19824982751343181, 1.185916567160356, 0.40656202865404567, 0.16289645171177966, -0.4388636369510842, -0.6690383093994308, 1.4658499494714023, 0.8735106372181927, -0.10348153740396093, 0.6837776537937139, 0.5863846591895536, -1.4810169520224028, -1.4653525684453887, 0.0, 0.14203663498716684, -0.2561317410190009, 0.9480808566164142, -0.6701948585135749, 0.2843298100961381, -0.8771690980243297 }, { -0.8403433999584713, 0.14012794477794924, 1.3730492931881484, -0.8432296400028142, 0.40656202865404567, 0.16289645171177966, 2.278612115023465, -0.6690383093994308, 0.6184260923501674, 0.8735106372181927, 1.7814601887614623, 0.6837776537937139, 0.5863846591895536, 0.622441390325499, 0.6319913825853262, 0.0, 0.14203663498716684, -0.2561317410190009, -1.2722157358170676, -0.250470603921817, -0.5143892000079515, -0.2957296600062443 }, { 1.029712237713905, 0.9532703900465632, -0.19824982751343181, 1.185916567160356, 0.40656202865404567, 0.16289645171177966, -0.4388636369510842, -0.6690383093994308, 1.4658499494714023, 0.8735106372181927, -0.10348153740396093, 0.6837776537937139, 0.5863846591895536, -1.4810169520224028, -1.4653525684453887, 0.0, 0.14203663498716684, -0.2561317410190009, 0.9480808566164142, -0.6701948585135749, 0.2843298100961381, -0.8771690980243297 }, { 1.029712237713905, 0.14012794477794924, 1.3730492931881484, 1.185916567160356, -1.970316152682646, 0.16289645171177966, -0.4388636369510842, -0.6690383093994308, 1.4658499494714023, -1.1448057498013176, 0.8389893256787506, 0.6837776537937139, 0.5863846591895536, 0.622441390325499, 0.6319913825853262, 0.0, 0.14203663498716684, -0.2561317410190009, 0.9480808566164142, -0.6701948585135749, -0.5143892000079515, -0.2957296600062443 }, { -0.8403433999584713, 0.14012794477794924, -0.5910746076888268, -0.8432296400028142, 0.40656202865404567, 0.16289645171177966, 2.278612115023465, -0.6690383093994308, 0.6184260923501674, 0.8735106372181927, 1.7814601887614623, 0.6837776537937139, 0.5863846591895536, 0.622441390325499, 0.6319913825853262, 0.0, 0.14203663498716684, -0.2561317410190009, -1.2722157358170676, -0.250470603921817, -2.9105462303202203, -0.2957296600062443 }, { 1.029712237713905, 0.9532703900465632, -0.19824982751343181, 1.185916567160356, 0.40656202865404567, 0.16289645171177966, -0.4388636369510842, -0.6690383093994308, 1.1833753304309906, 0.8735106372181927, -0.10348153740396093, 0.6837776537937139, 0.5863846591895536, 0.622441390325499, 0.6319913825853262, 0.0, 0.14203663498716684, -0.2561317410190009, 0.9480808566164142, -0.6701948585135749, 0.2843298100961381, -0.8771690980243297 }, { -0.8403433999584713, 0.14012794477794924, -0.5910746076888268, -0.8432296400028142, 0.40656202865404567, 0.16289645171177966, 2.278612115023465, -0.6690383093994308, 0.6184260923501674, 0.8735106372181927, 1.7814601887614623, 0.6837776537937139, -2.3724904782364917, 0.622441390325499, 0.6319913825853262, 0.0, 0.14203663498716684, -0.2561317410190009, -1.2722157358170676, -0.250470603921817, -0.5143892000079515, -0.2957296600062443 }, { 1.029712237713905, 0.14012794477794924, 1.3730492931881484, 1.185916567160356, -0.5441892438806311, 0.16289645171177966, -0.4388636369510842, -0.6690383093994308, 1.4658499494714023, -1.1448057498013176, 0.8389893256787506, 0.6837776537937139, 0.5863846591895536, 0.622441390325499, 0.6319913825853262, 0.0, 0.14203663498716684, -0.2561317410190009, 0.9480808566164142, -0.6701948585135749, -0.5143892000079515, -0.2957296600062443 }, { -0.8403433999584713, 0.14012794477794924, 1.3730492931881484, 1.185916567160356, -1.970316152682646, 0.16289645171177966, 2.278612115023465, 1.494682719884397, 0.05347685426934428, 0.8735106372181927, -0.10348153740396093, 0.6837776537937139, 0.5863846591895536, 0.622441390325499, 0.6319913825853262, 0.0, 0.14203663498716684, -0.2561317410190009, 0.9480808566164142, -0.250470603921817, 0.2843298100961381, -0.8771690980243297 }, { 1.029712237713905, 0.14012794477794924, 1.7658740733635434, 1.185916567160356, -0.5441892438806311, 0.16289645171177966, 2.278612115023465, 1.494682719884397, 0.05347685426934428, 0.8735106372181927, -0.10348153740396093, 0.6837776537937139, 0.5863846591895536, 0.622441390325499, 0.6319913825853262, 0.0, 0.14203663498716684, -0.2561317410190009, 0.9480808566164142, 1.0087021598534562, 0.2843298100961381, -0.8771690980243297 }, { -0.21699152073434588, 0.9532703900465632, -1.376724168039617, -0.8432296400028142, 0.40656202865404567, 0.16289645171177966, 2.278612115023465, 1.494682719884397, 1.4658499494714023, -1.1448057498013176, -0.10348153740396093, 0.6837776537937139, 0.5863846591895536, 0.622441390325499, -0.94101658068771, 0.0, 0.14203663498716684, -0.2561317410190009, -1.2722157358170676, 1.4284264144452141, 0.2843298100961381, 0.28570977801184116 }, { 1.029712237713905, 0.14012794477794924, 1.3730492931881484, 1.185916567160356, -1.970316152682646, 0.16289645171177966, -0.4388636369510842, -0.6690383093994308, -0.2289977647710673, -1.1448057498013176, 0.8389893256787506, 0.6837776537937139, 0.5863846591895536, 0.622441390325499, 0.6319913825853262, 0.0, 0.14203663498716684, -0.2561317410190009, 0.9480808566164142, -0.6701948585135749, -0.5143892000079515, -0.2957296600062443 }, { -0.8403433999584713, 0.9532703900465632, 1.3730492931881484, -0.8432296400028142, 0.40656202865404567, 0.16289645171177966, -0.4388636369510842, 1.494682719884397, -0.5114723838114789, -1.1448057498013176, -1.0459524004866725, 0.6837776537937139, -2.3724904782364917, 0.622441390325499, 0.6319913825853262, 0.0, 0.14203663498716684, -0.2561317410190009, -0.7171415877086972, -1.0899191131053325, 1.0830488202002277, -0.8771690980243297 }, { -0.21699152073434588, 0.14012794477794924, -0.19824982751343181, -0.8432296400028142, 0.40656202865404567, 0.16289645171177966, -0.4388636369510842, -0.6690383093994308, 1.4658499494714023, -1.1448057498013176, -0.10348153740396093, 2.2929925029884224, 2.065822227902576, -0.9551523664354273, -0.94101658068771, 0.0, 0.14203663498716684, 3.4332552519568216, 0.9480808566164142, 1.4284264144452141, 1.0830488202002277, -0.8771690980243297 }, { 1.029712237713905, 0.9532703900465632, 1.3730492931881484, -0.8432296400028142, 0.40656202865404567, 0.16289645171177966, -0.4388636369510842, 1.494682719884397, -0.5114723838114789, -1.1448057498013176, -1.0459524004866725, 0.6837776537937139, -2.3724904782364917, 0.622441390325499, 0.6319913825853262, 0.0, 0.14203663498716684, -0.2561317410190009, -0.7171415877086972, -1.0899191131053325, 1.0830488202002277, -0.8771690980243297 }, { 1.029712237713905, 0.14012794477794924, 1.3730492931881484, 1.185916567160356, -0.5441892438806311, 0.16289645171177966, -0.4388636369510842, -0.6690383093994308, 0.05347685426934428, -1.1448057498013176, 0.8389893256787506, 0.6837776537937139, 0.5863846591895536, 0.622441390325499, 0.6319913825853262, 0.0, 0.14203663498716684, -0.2561317410190009, 0.9480808566164142, -0.6701948585135749, -0.5143892000079515, 0.8671492160299267 }, { -0.8403433999584713, 0.9532703900465632, -0.19824982751343181, 1.185916567160356, 0.40656202865404567, 0.16289645171177966, -0.4388636369510842, -0.6690383093994308, 1.1833753304309906, 0.8735106372181927, -0.10348153740396093, 0.6837776537937139, 0.5863846591895536, 0.622441390325499, 0.6319913825853262, 0.0, 0.14203663498716684, -0.2561317410190009, 0.9480808566164142, -0.6701948585135749, 0.2843298100961381, -0.8771690980243297 }, { -0.8403433999584713, 0.9532703900465632, -0.19824982751343181, 1.185916567160356, 0.40656202865404567, 0.16289645171177966, -0.4388636369510842, -0.6690383093994308, 0.6184260923501674, 0.8735106372181927, -0.10348153740396093, 0.6837776537937139, 0.5863846591895536, 0.622441390325499, 0.6319913825853262, 0.0, 0.14203663498716684, -0.2561317410190009, 0.9480808566164142, -0.6701948585135749, 0.2843298100961381, -0.8771690980243297 }, { -2.087047158406722, 0.14012794477794924, 1.3730492931881484, -0.8432296400028142, 0.40656202865404567, 0.16289645171177966, 2.278612115023465, -0.6690383093994308, 1.4658499494714023, -1.1448057498013176, -1.0459524004866725, 0.6837776537937139, 0.5863846591895536, 0.622441390325499, 0.6319913825853262, 0.0, 0.14203663498716684, 3.4332552519568216, 0.9480808566164142, 1.4284264144452141, -1.313108210112041, -0.2957296600062443 }, { 1.029712237713905, -1.4861569457592787, -0.19824982751343181, 1.185916567160356, 0.40656202865404567, 0.16289645171177966, -0.4388636369510842, -0.6690383093994308, 0.05347685426934428, 0.8735106372181927, -0.10348153740396093, 0.6837776537937139, 0.5863846591895536, 0.622441390325499, -1.4653525684453887, 0.0, 0.14203663498716684, -0.2561317410190009, 0.9480808566164142, -0.250470603921817, 0.2843298100961381, -0.8771690980243297 }, { 1.029712237713905, 0.14012794477794924, 1.7658740733635434, 1.185916567160356, -0.5441892438806311, 0.16289645171177966, 2.278612115023465, 1.494682719884397, 1.4658499494714023, 0.8735106372181927, -0.10348153740396093, 0.6837776537937139, 0.5863846591895536, 0.622441390325499, 0.6319913825853262, 0.0, 0.14203663498716684, -0.2561317410190009, 0.9480808566164142, -0.250470603921817, 0.2843298100961381, -0.8771690980243297 }, { 1.029712237713905, 0.9532703900465632, -0.19824982751343181, 1.185916567160356, 0.40656202865404567, 0.16289645171177966, -0.4388636369510842, -0.6690383093994308, 0.6184260923501674, 0.8735106372181927, -0.10348153740396093, 0.6837776537937139, 0.5863846591895536, 0.622441390325499, 0.10765539482764744, 0.0, 0.14203663498716684, -0.2561317410190009, 0.9480808566164142, -0.6701948585135749, 0.2843298100961381, -0.8771690980243297 }, { 1.029712237713905, 0.9532703900465632, -0.19824982751343181, 1.185916567160356, 0.40656202865404567, 0.16289645171177966, -0.4388636369510842, -0.6690383093994308, 0.05347685426934428, 0.8735106372181927, -0.10348153740396093, 0.6837776537937139, 0.5863846591895536, 0.622441390325499, 0.10765539482764744, 0.0, 0.14203663498716684, -0.2561317410190009, 0.9480808566164142, -0.6701948585135749, 0.2843298100961381, -0.8771690980243297 }, { -0.8403433999584713, -1.4861569457592787, -0.19824982751343181, 1.185916567160356, 0.40656202865404567, 0.16289645171177966, -0.4388636369510842, -0.6690383093994308, 1.4658499494714023, 0.8735106372181927, -0.10348153740396093, 0.6837776537937139, 0.5863846591895536, -1.4810169520224028, -1.4653525684453887, 0.0, 0.14203663498716684, -0.2561317410190009, 0.9480808566164142, -0.6701948585135749, 0.2843298100961381, -0.8771690980243297 }, { 1.029712237713905, 0.14012794477794924, -0.5910746076888268, 1.185916567160356, -1.0195648801479693, 0.16289645171177966, -0.4388636369510842, -0.6690383093994308, 1.4658499494714023, 0.8735106372181927, -0.10348153740396093, 0.6837776537937139, 0.5863846591895536, 0.622441390325499, 0.6319913825853262, 0.0, 0.14203663498716684, -0.2561317410190009, 0.9480808566164142, -1.0899191131053325, 0.2843298100961381, -0.2957296600062443 }, { 1.029712237713905, 0.14012794477794924, 1.3730492931881484, 1.185916567160356, -1.0195648801479693, 0.16289645171177966, -0.4388636369510842, -0.6690383093994308, 0.6184260923501674, 0.8735106372181927, -0.10348153740396093, 0.6837776537937139, 0.5863846591895536, 0.622441390325499, 0.6319913825853262, 0.0, 0.14203663498716684, -0.2561317410190009, 0.9480808566164142, -1.0899191131053325, -0.5143892000079515, -0.2957296600062443 }, { 1.029712237713905, 0.14012794477794924, 1.3730492931881484, 1.185916567160356, -1.0195648801479693, 0.16289645171177966, -0.4388636369510842, -0.6690383093994308, -0.5114723838114789, 0.8735106372181927, -0.10348153740396093, 0.6837776537937139, 0.5863846591895536, 0.622441390325499, 0.6319913825853262, 0.0, 0.14203663498716684, -0.2561317410190009, 0.9480808566164142, -1.0899191131053325, 0.2843298100961381, -0.2957296600062443 }, { -0.8403433999584713, 0.9532703900465632, -0.5910746076888268, -0.8432296400028142, -1.0195648801479693, 0.16289645171177966, -0.4388636369510842, -0.6690383093994308, 0.6184260923501674, -1.1448057498013176, -0.10348153740396093, -0.9254371954009945, -0.893052909523469, 0.09657680473852359, -3.0383605317184252, 0.0, 0.14203663498716684, -0.2561317410190009, -0.16206743960032674, -1.0899191131053325, 0.2843298100961381, 1.448588654048012 }, { 1.029712237713905, 0.14012794477794924, 1.3730492931881484, 1.185916567160356, 0.881937664921384, 0.16289645171177966, -0.4388636369510842, 1.494682719884397, 1.4658499494714023, -1.1448057498013176, 1.7814601887614623, 0.6837776537937139, 0.5863846591895536, 0.622441390325499, 0.6319913825853262, 0.0, 0.14203663498716684, -0.2561317410190009, 0.9480808566164142, -0.250470603921817, 0.2843298100961381, 2.0300280920660976 }, { 1.029712237713905, -1.4861569457592787, 1.3730492931881484, -0.8432296400028142, -1.4949405164153078, 0.16289645171177966, 2.278612115023465, 1.494682719884397, -0.7939470028518905, -1.1448057498013176, -0.10348153740396093, 0.6837776537937139, 0.5863846591895536, 0.622441390325499, 0.6319913825853262, 0.0, 0.14203663498716684, -0.2561317410190009, 0.9480808566164142, -0.250470603921817, -0.5143892000079515, -0.8771690980243297 }, { 1.029712237713905, 0.14012794477794924, 1.3730492931881484, 1.185916567160356, 0.881937664921384, 0.16289645171177966, -0.4388636369510842, 1.494682719884397, 0.05347685426934428, -1.1448057498013176, 1.7814601887614623, 0.6837776537937139, 0.5863846591895536, 0.622441390325499, 0.6319913825853262, 0.0, 0.14203663498716684, -0.2561317410190009, 0.9480808566164142, -0.6701948585135749, 0.2843298100961381, -0.2957296600062443 }, { -0.8403433999584713, 0.14012794477794924, -0.5910746076888268, 1.185916567160356, -1.0195648801479693, 0.16289645171177966, -0.4388636369510842, -0.6690383093994308, -0.5114723838114789, 0.8735106372181927, -0.10348153740396093, 0.6837776537937139, 0.5863846591895536, 0.622441390325499, 0.6319913825853262, 0.0, 0.14203663498716684, -0.2561317410190009, 0.9480808566164142, -1.0899191131053325, 0.2843298100961381, -0.2957296600062443 }, { -0.8403433999584713, 0.14012794477794924, 1.3730492931881484, 1.185916567160356, -1.0195648801479693, 0.16289645171177966, -0.4388636369510842, -0.6690383093994308, 1.4658499494714023, 0.8735106372181927, -0.10348153740396093, 0.6837776537937139, 0.5863846591895536, 0.622441390325499, 0.6319913825853262, 0.0, 0.14203663498716684, -0.2561317410190009, 0.9480808566164142, -1.0899191131053325, 0.2843298100961381, -0.2957296600062443 }, { 1.029712237713905, 0.14012794477794924, 1.3730492931881484, -0.8432296400028142, -1.4949405164153078, 0.16289645171177966, 2.278612115023465, 1.494682719884397, -0.7939470028518905, -1.1448057498013176, -0.10348153740396093, 0.6837776537937139, 0.5863846591895536, 0.622441390325499, 0.6319913825853262, 0.0, 0.14203663498716684, -0.2561317410190009, 0.9480808566164142, -0.250470603921817, -0.5143892000079515, -0.8771690980243297 }, { 1.029712237713905, 0.14012794477794924, -0.5910746076888268, 1.185916567160356, -1.0195648801479693, 0.16289645171177966, -0.4388636369510842, -0.6690383093994308, -0.5114723838114789, 0.8735106372181927, -0.10348153740396093, -2.534652044595703, 0.5863846591895536, 0.622441390325499, 0.6319913825853262, 0.0, 0.14203663498716684, -0.2561317410190009, 0.9480808566164142, -1.0899191131053325, -0.5143892000079515, -0.2957296600062443 }, { -2.087047158406722, 0.9532703900465632, 1.3730492931881484, 1.185916567160356, 0.40656202865404567, 0.16289645171177966, 2.278612115023465, 1.494682719884397, 1.4658499494714023, -1.1448057498013176, -0.10348153740396093, 0.6837776537937139, 0.5863846591895536, 0.622441390325499, 0.6319913825853262, 0.0, 0.14203663498716684, -0.2561317410190009, 0.9480808566164142, 1.4284264144452141, -2.1118272202161306, 0.28570977801184116 }, { -0.21699152073434588, 0.9532703900465632, 1.7658740733635434, -0.8432296400028142, 0.40656202865404567, 0.16289645171177966, 2.278612115023465, 1.494682719884397, 1.7483245685118138, -1.1448057498013176, 0.8389893256787506, 2.2929925029884224, 2.065822227902576, 1.1483059759124745, 1.156327370343005, 0.0, 4.263128144400531, -0.2561317410190009, -1.2722157358170676, 1.4284264144452141, -2.1118272202161306, 0.28570977801184116 }, { -0.8403433999584713, 0.9532703900465632, -0.19824982751343181, -0.8432296400028142, -1.0195648801479693, 0.16289645171177966, -0.4388636369510842, 1.494682719884397, -1.3588962409327137, 0.8735106372181927, -1.0459524004866725, -0.9254371954009945, -0.893052909523469, 0.09657680473852359, 0.10765539482764744, 0.0, 0.14203663498716684, -0.2561317410190009, -1.2722157358170676, 1.4284264144452141, 0.2843298100961381, 1.448588654048012 }, { -0.8403433999584713, 0.14012794477794924, 1.3730492931881484, 1.185916567160356, -1.0195648801479693, 0.16289645171177966, -0.4388636369510842, -0.6690383093994308, 0.6184260923501674, 0.8735106372181927, -0.10348153740396093, 0.6837776537937139, 0.5863846591895536, 0.622441390325499, 0.6319913825853262, 0.0, 0.14203663498716684, -0.2561317410190009, 0.9480808566164142, -1.0899191131053325, -0.5143892000079515, -0.2957296600062443 }, { 1.029712237713905, -1.4861569457592787, 0.1945749526619632, -0.8432296400028142, -1.4949405164153078, 0.16289645171177966, -0.4388636369510842, 1.494682719884397, 1.1833753304309906, -1.1448057498013176, -0.10348153740396093, 0.6837776537937139, 0.5863846591895536, 0.622441390325499, 0.6319913825853262, 0.0, 0.14203663498716684, -0.2561317410190009, 0.9480808566164142, -0.250470603921817, 0.2843298100961381, -0.8771690980243297 }, { -0.8403433999584713, 0.14012794477794924, 0.1945749526619632, 1.185916567160356, 0.40656202865404567, 0.16289645171177966, -0.4388636369510842, -0.6690383093994308, -0.7939470028518905, -1.1448057498013176, -0.10348153740396093, 0.6837776537937139, 0.5863846591895536, 0.622441390325499, 0.6319913825853262, 0.0, 0.14203663498716684, 3.4332552519568216, 0.9480808566164142, 0.5889779052616985, 0.2843298100961381, 0.8671492160299267 }, { 1.029712237713905, 0.14012794477794924, -0.19824982751343181, 1.185916567160356, 0.881937664921384, 0.16289645171177966, -0.4388636369510842, 1.494682719884397, -0.2289977647710673, -1.1448057498013176, 1.7814601887614623, 0.6837776537937139, 0.5863846591895536, 0.622441390325499, 0.6319913825853262, 0.0, 0.14203663498716684, -0.2561317410190009, 0.9480808566164142, -0.6701948585135749, 0.2843298100961381, 2.0300280920660976 }, { -0.8403433999584713, 0.9532703900465632, 1.7658740733635434, -0.8432296400028142, -1.0195648801479693, 0.16289645171177966, -0.4388636369510842, -0.6690383093994308, -0.7939470028518905, -1.1448057498013176, -0.10348153740396093, -0.9254371954009945, -0.893052909523469, 0.09657680473852359, 0.10765539482764744, 0.0, 0.14203663498716684, -0.2561317410190009, -0.16206743960032674, -1.0899191131053325, 0.2843298100961381, -0.8771690980243297 }, { -0.8403433999584713, 0.14012794477794924, -0.19824982751343181, -0.8432296400028142, -1.0195648801479693, 0.16289645171177966, -0.4388636369510842, 1.494682719884397, -1.3588962409327137, 0.8735106372181927, -1.0459524004866725, -0.9254371954009945, -0.893052909523469, 0.09657680473852359, 0.10765539482764744, 0.0, 0.14203663498716684, -0.2561317410190009, -1.2722157358170676, 1.4284264144452141, 0.2843298100961381, 1.448588654048012 }, { -0.8403433999584713, 0.9532703900465632, -0.9838993878642219, -0.8432296400028142, 1.3573133011887224, 0.16289645171177966, -0.4388636369510842, 1.494682719884397, -1.3588962409327137, 0.8735106372181927, -1.0459524004866725, -0.9254371954009945, -0.893052909523469, 0.09657680473852359, 0.6319913825853262, 0.0, 0.14203663498716684, -0.2561317410190009, -1.2722157358170676, 1.4284264144452141, 0.2843298100961381, -0.8771690980243297 }, { 1.029712237713905, 0.9532703900465632, -0.5910746076888268, -0.8432296400028142, -1.0195648801479693, 0.16289645171177966, -0.4388636369510842, -0.6690383093994308, -0.7939470028518905, -1.1448057498013176, -0.10348153740396093, -0.9254371954009945, -0.893052909523469, 0.09657680473852359, 0.10765539482764744, 0.0, 0.14203663498716684, -0.2561317410190009, -0.16206743960032674, -1.0899191131053325, 0.2843298100961381, 1.448588654048012 }, { 1.029712237713905, 0.14012794477794924, 0.1945749526619632, -0.8432296400028142, -1.4949405164153078, 0.16289645171177966, 2.278612115023465, 1.494682719884397, 1.1833753304309906, -1.1448057498013176, -0.10348153740396093, 0.6837776537937139, 0.5863846591895536, 0.622441390325499, 0.6319913825853262, 0.0, 0.14203663498716684, -0.2561317410190009, 0.9480808566164142, -0.250470603921817, 0.2843298100961381, -0.8771690980243297 }, { 1.029712237713905, 0.14012794477794924, -0.5910746076888268, 1.185916567160356, -1.0195648801479693, 0.16289645171177966, -0.4388636369510842, -0.6690383093994308, 0.6184260923501674, 0.8735106372181927, -0.10348153740396093, 0.6837776537937139, 0.5863846591895536, 0.622441390325499, 0.6319913825853262, 0.0, 0.14203663498716684, -0.2561317410190009, 0.9480808566164142, -1.0899191131053325, 0.2843298100961381, -0.2957296600062443 }, { 1.029712237713905, 0.14012794477794924, 1.3730492931881484, 1.185916567160356, -1.0195648801479693, 0.16289645171177966, -0.4388636369510842, -0.6690383093994308, -0.5114723838114789, 0.8735106372181927, -0.10348153740396093, 0.6837776537937139, -2.3724904782364917, 0.622441390325499, 0.6319913825853262, 0.0, 0.14203663498716684, -0.2561317410190009, 0.9480808566164142, -1.0899191131053325, -0.5143892000079515, -0.2957296600062443 }, { 1.029712237713905, 0.14012794477794924, 1.3730492931881484, -0.8432296400028142, -1.4949405164153078, 0.16289645171177966, 2.278612115023465, 1.494682719884397, 1.1833753304309906, -1.1448057498013176, -0.10348153740396093, 0.6837776537937139, 0.5863846591895536, 0.622441390325499, 0.6319913825853262, 0.0, 0.14203663498716684, -0.2561317410190009, 0.9480808566164142, -0.250470603921817, 0.2843298100961381, -0.8771690980243297 }, { 1.029712237713905, 0.9532703900465632, -0.9838993878642219, -0.8432296400028142, 1.3573133011887224, 0.16289645171177966, -0.4388636369510842, 1.494682719884397, -1.3588962409327137, 0.8735106372181927, -1.0459524004866725, -0.9254371954009945, -0.893052909523469, 0.09657680473852359, 0.10765539482764744, 0.0, 0.14203663498716684, -0.2561317410190009, -1.2722157358170676, 1.4284264144452141, 0.2843298100961381, -0.8771690980243297 }, { -0.8403433999584713, 0.9532703900465632, 0.1945749526619632, 1.185916567160356, 0.40656202865404567, 0.16289645171177966, -0.4388636369510842, -0.6690383093994308, 1.4658499494714023, -1.1448057498013176, -0.10348153740396093, 0.6837776537937139, 0.5863846591895536, 0.622441390325499, 0.6319913825853262, 0.0, 0.14203663498716684, 3.4332552519568216, 0.9480808566164142, 0.5889779052616985, 0.2843298100961381, 0.8671492160299267 }, { -0.8403433999584713, 0.14012794477794924, 0.1945749526619632, 1.185916567160356, 0.40656202865404567, 0.16289645171177966, -0.4388636369510842, -0.6690383093994308, 1.4658499494714023, -1.1448057498013176, -0.10348153740396093, 0.6837776537937139, 0.5863846591895536, 0.622441390325499, 0.6319913825853262, 0.0, 0.14203663498716684, 3.4332552519568216, 0.9480808566164142, 0.5889779052616985, 0.2843298100961381, 0.8671492160299267 }, { -0.8403433999584713, -1.4861569457592787, -0.5910746076888268, -0.8432296400028142, -1.0195648801479693, 0.16289645171177966, -0.4388636369510842, -0.6690383093994308, -0.7939470028518905, -1.1448057498013176, -0.10348153740396093, -0.9254371954009945, -0.893052909523469, -0.9551523664354273, 0.10765539482764744, 0.0, 0.14203663498716684, -0.2561317410190009, -0.16206743960032674, -1.0899191131053325, 0.2843298100961381, 1.448588654048012 }, { 1.029712237713905, -1.4861569457592787, 1.3730492931881484, -0.8432296400028142, -1.4949405164153078, 0.16289645171177966, -0.4388636369510842, 1.494682719884397, -0.7939470028518905, -1.1448057498013176, -0.10348153740396093, 0.6837776537937139, 0.5863846591895536, 0.622441390325499, 0.6319913825853262, 0.0, 0.14203663498716684, -0.2561317410190009, 0.9480808566164142, -0.250470603921817, -0.5143892000079515, -0.8771690980243297 }, { -0.8403433999584713, -1.4861569457592787, -0.5910746076888268, -0.8432296400028142, -1.0195648801479693, 0.16289645171177966, -0.4388636369510842, -0.6690383093994308, 0.6184260923501674, -1.1448057498013176, -0.10348153740396093, -0.9254371954009945, -0.893052909523469, 0.09657680473852359, 0.10765539482764744, 0.0, 0.14203663498716684, -0.2561317410190009, -0.16206743960032674, -1.0899191131053325, 0.2843298100961381, 1.448588654048012 }, { 1.029712237713905, 0.14012794477794924, 1.3730492931881484, 1.185916567160356, -1.0195648801479693, 0.16289645171177966, -0.4388636369510842, -0.6690383093994308, -0.5114723838114789, 0.8735106372181927, -0.10348153740396093, -2.534652044595703, 0.5863846591895536, 0.622441390325499, 0.6319913825853262, 0.0, 0.14203663498716684, -0.2561317410190009, 0.9480808566164142, -1.0899191131053325, -0.5143892000079515, -0.2957296600062443 }, { -0.8403433999584713, 0.14012794477794924, -0.5910746076888268, 1.185916567160356, -1.0195648801479693, 0.16289645171177966, -0.4388636369510842, -0.6690383093994308, 1.4658499494714023, 0.8735106372181927, -0.10348153740396093, 0.6837776537937139, 0.5863846591895536, 0.622441390325499, 0.6319913825853262, 0.0, 0.14203663498716684, -0.2561317410190009, 0.9480808566164142, -1.0899191131053325, 0.2843298100961381, -0.2957296600062443 }, { -2.087047158406722, 0.9532703900465632, 1.7658740733635434, -0.8432296400028142, 0.40656202865404567, 0.16289645171177966, 2.278612115023465, 1.494682719884397, 1.7483245685118138, -1.1448057498013176, 0.8389893256787506, 2.2929925029884224, 2.065822227902576, 1.1483059759124745, 1.156327370343005, 0.0, 4.263128144400531, -0.2561317410190009, -1.2722157358170676, 1.4284264144452141, -2.1118272202161306, 0.28570977801184116 }, { 1.029712237713905, 0.14012794477794924, 1.3730492931881484, 1.185916567160356, 0.881937664921384, 0.16289645171177966, -0.4388636369510842, 1.494682719884397, -0.2289977647710673, -1.1448057498013176, 1.7814601887614623, 0.6837776537937139, 0.5863846591895536, 0.622441390325499, 0.6319913825853262, 0.0, 0.14203663498716684, -0.2561317410190009, 0.9480808566164142, -0.250470603921817, 0.2843298100961381, 2.0300280920660976 }, { -0.8403433999584713, 0.9532703900465632, -0.5910746076888268, -0.8432296400028142, -1.0195648801479693, 0.16289645171177966, -0.4388636369510842, -0.6690383093994308, -0.7939470028518905, -1.1448057498013176, -0.10348153740396093, -0.9254371954009945, -0.893052909523469, 0.09657680473852359, 0.10765539482764744, 0.0, 0.14203663498716684, -0.2561317410190009, -0.16206743960032674, -1.0899191131053325, 0.2843298100961381, 1.448588654048012 }, { 1.029712237713905, 0.14012794477794924, -0.5910746076888268, 1.185916567160356, -1.0195648801479693, 0.16289645171177966, -0.4388636369510842, -0.6690383093994308, -0.5114723838114789, 0.8735106372181927, -0.10348153740396093, 0.6837776537937139, 0.5863846591895536, 0.622441390325499, 0.6319913825853262, 0.0, 0.14203663498716684, -0.2561317410190009, 0.9480808566164142, -1.0899191131053325, -0.5143892000079515, -0.2957296600062443 }, { 1.029712237713905, -1.4861569457592787, -0.5910746076888268, -0.8432296400028142, -1.0195648801479693, 0.16289645171177966, -0.4388636369510842, -0.6690383093994308, -0.5114723838114789, -1.1448057498013176, -0.10348153740396093, -0.9254371954009945, -0.893052909523469, 0.09657680473852359, 0.10765539482764744, 0.0, 0.14203663498716684, -0.2561317410190009, -0.16206743960032674, -1.0899191131053325, 0.2843298100961381, 1.448588654048012 }, { -0.8403433999584713, -1.4861569457592787, 1.7658740733635434, -0.8432296400028142, -1.0195648801479693, 0.16289645171177966, -0.4388636369510842, -0.6690383093994308, -0.7939470028518905, -1.1448057498013176, -0.10348153740396093, -0.9254371954009945, -0.893052909523469, -0.9551523664354273, 0.10765539482764744, 0.0, 0.14203663498716684, -0.2561317410190009, -0.16206743960032674, -1.0899191131053325, 0.2843298100961381, 1.448588654048012 }, { 1.029712237713905, 0.14012794477794924, -0.19824982751343181, 1.185916567160356, 0.881937664921384, 0.16289645171177966, -0.4388636369510842, 1.494682719884397, 1.4658499494714023, -1.1448057498013176, 1.7814601887614623, 0.6837776537937139, 0.5863846591895536, 0.622441390325499, 0.6319913825853262, 0.0, 0.14203663498716684, -0.2561317410190009, 0.9480808566164142, -0.250470603921817, 0.2843298100961381, 2.0300280920660976 }, { -0.8403433999584713, 0.9532703900465632, 1.7658740733635434, -0.8432296400028142, -1.0195648801479693, 0.16289645171177966, -0.4388636369510842, -0.6690383093994308, -0.7939470028518905, -1.1448057498013176, -0.10348153740396093, -0.9254371954009945, -0.893052909523469, -0.9551523664354273, 0.10765539482764744, 0.0, 0.14203663498716684, -0.2561317410190009, -0.16206743960032674, -1.0899191131053325, 0.2843298100961381, -0.8771690980243297 }, { 1.029712237713905, -1.4861569457592787, 1.7658740733635434, -0.8432296400028142, -1.0195648801479693, 0.16289645171177966, -0.4388636369510842, -0.6690383093994308, -0.7939470028518905, -1.1448057498013176, -0.10348153740396093, -0.9254371954009945, -0.893052909523469, -3.058610708783329, 0.10765539482764744, 0.0, 0.14203663498716684, -0.2561317410190009, -0.16206743960032674, -1.0899191131053325, 0.2843298100961381, 1.448588654048012 } };
            double[,] coefficientsMashroomD = { { -1.3798597708867266, -4.883607955379984, -5.548165790648151, -0.061757313767708176, -1.0865719010661703, -0.01426424141400819, -0.6163936088063474, -4.260153928818506, -1.2569041780574652, -2.1466027594616666, -2.2687652579772193, -6.118469300074238, -0.4924357275715736, -19.86696648294654, -0.34593690639143176, -1.0568472890871559, -0.14068891807316228, -0.9774166529477862, -7.130533106146039, -1.4840676028542605, -1.7639384438998986, -1.2819441836162062, -5.406881303996927, -0.9428957399138065, -2.322454934072298, -1.256062020922827, -2.860208657375192, -8.666078918366267, -0.4259696231740045, -0.473397647886441, -0.573640257921649, -0.16074059078640462, -6.261905222713596, -0.2049332572451397, -1.424903904529542, -0.12479587490241022, -8.958852855238515, -0.12189667565667259, -0.24280512531928305, -8.553587621769204, -3.292456463251167, -0.1290079928645057, -1.5624125899701915, -1.4162751660162036, -9.559136292753655, -5.651622437034512, -9.154899613658696, -0.6599745540188126, -0.07990402107507785, -5.260578627046839, -2.724836345832232, -13.289853100018485, -0.9342464605060691, 9.909437436603506, 11.101371474384855, 14.60593660919845, 0.5929858932655261, 2.397355266695858, 1.4186969140985455, 2.2551230051915527, 13.044814491403326, 2.537949671413006, 0.09808894794076044, 0.451166340737226, 2.9190463941871516, 0.2879197684262461, 2.5310436365072775, 6.335447288910088, 0.46137414846171526, 2.5343253229422906, 1.192585411419088, 1.6910118124713702, 7.046825275416602, 1.88315353921033, 0.19950359763170292, 4.279542727719369, 0.15618881292275336, 4.969094934430523, 6.899153231002094, 0.2435028745144476, 22.331397870782144, 8.619190232607641, 1.9735084693990874, 2.0925254204676658, 1.7430664187590996, 3.363379375281906, 0.7355121005045911, 0.19870584895371457, 3.306725180785799, 3.834438723728394, 1.0693253739909567, 3.596272507907274, 4.818436678576192, 2.1717114699735163, 4.046615221790625, 0.936049495114594 } };
            double[] interceptsMashroom = { -0.3209481162941494 };
            int[]    weightsMashroom    = { 53, 43 };


            double[][] vectorsMashroom      = SVCUtilities.SvcUtilities.ToJaggedArray(vectorsMashroomD);
            double[][] coefficientsMashroom = SVCUtilities.SvcUtilities.ToJaggedArray(coefficientsMashroomD);


            double[][] features;
            int        numOfRows = 0;

            if (args.Length >= 4)
            {
                numOfRows = args.Length / 4;
                // Features:
                features = new double[numOfRows][];
                for (int i = 0; i < numOfRows; i++)
                {
                    features[i] = new double[4];
                }
                for (int i = 0, l = args.Length; i < l; i++)
                {
                    features[i / 4][i % 4] = Double.Parse(args[i]);
                }
            }
            else
            {
                List <double[]> rows = new List <double[]>();

                var bytesMashrooms = Properties.Resources.mashrooms;
                numOfRows = 0;
                features  = SVCUtilities.SvcUtilities.LoadFeatures(bytesMashrooms, vectorsMashroom[0].Length, ref numOfRows);
            }


            Svc clf = new Svc(2, 2, vectorsMashroom, coefficientsMashroom, interceptsMashroom, weightsMashroom, "Poly", 0.045454545454545456, 0.0, 2);

            using (System.IO.StreamWriter file =
                       new System.IO.StreamWriter(
                           $@"{OutputDir}MashroomPlain_{DateTime.Now.Day}_{DateTime.Now.ToShortTimeString().ToString().Replace(":", "_")}.txt")
                   )
            {
                Stopwatch totalTime = new Stopwatch();
                totalTime.Start();
                for (int i = 0; i < numOfRows; i++)
                {
                    double finalResult = -10000;
                    int    estimation  = clf.Predict(features[i], out finalResult);
                    Console.WriteLine($"\n ************************************************");
                    Console.WriteLine($"SVC estimation{i} is : {estimation} , result : {finalResult}");
                    file.WriteLine($"{i} , {estimation} , {finalResult} ");
                    Console.WriteLine($"************************************************ \n");
                }
                totalTime.Stop();
                file.WriteLine($" Total time for {numOfRows} samples :  {totalTime.ElapsedMilliseconds} ms  ");
                file.WriteLine($" Avg time  :  {totalTime.ElapsedMilliseconds * 1000 / numOfRows} microSec ");
            }
        }
Exemplo n.º 25
0
        public void TestSingleSample_1D()
        {
            var clf = new Svc<int>();
            clf.Fit(X, Y);
            var p = clf.Predict(X.Row(0).ToRowMatrix());
            Assert.AreEqual(Y[0], p[0]);

            //todo:
            //clf = svm.LinearSVC(random_state=0).fit(X, Y)
            //clf.predict(X[0])
        }
Exemplo n.º 26
0
        public void TestPrecomputed()
        {
            var clf = new Svc<int>(kernel: Kernel.Precomputed);
            // Gram matrix for train data (square matrix)
            // (we use just a linear kernel)
            var k = X*(X.Transpose());
            clf.Fit(k, Y);
            // Gram matrix for test data (rectangular matrix)
            var kt = T*X.Transpose();
            var pred = clf.Predict(kt);
            try
            {
                clf.Predict(kt.Transpose());
                Assert.Fail();
            }
            catch (ArgumentException)
            {
            }

            Assert.IsTrue(clf.DualCoef.AlmostEquals(DenseMatrix.OfArray(new[,] {{0.25, -.25}})));
            Assert.IsTrue(clf.Support.SequenceEqual(new[] {1, 3}));
            Assert.IsTrue(clf.Intercept.SequenceEqual(new[] {0.0}));
            Assert.IsTrue(pred.SequenceEqual(true_result));

            // Gram matrix for test data but compute KT[i,j]
            // for support vectors j only.
            kt = kt.CreateMatrix(kt.RowCount, kt.ColumnCount);
            for (int i = 0; i < T.RowCount; i++)
            {
                foreach (var j in clf.Support)
                {
                    kt[i, j] = T.Row(i)*X.Row(j);
                }
            }

            pred = clf.Predict(kt);
            Assert.IsTrue(pred.SequenceEqual(true_result));

            // same as before, but using a callable function instead of the kernel
            // matrix. kernel is just a linear kernel

            clf = new Svc<int>(kernel: Kernel.FromFunction((x, y) => x*y.Transpose()));
            clf.Fit(X, Y);
            pred = clf.Predict(T);

            Assert.IsTrue(clf.DualCoef.AlmostEquals(DenseMatrix.OfArray(new[,] {{0.25, -.25}})));
            Assert.IsTrue(clf.Support.SequenceEqual(new[] {1, 3}));
            Assert.IsTrue(clf.Intercept.SequenceEqual(new[] {0.0}));
            Assert.IsTrue(pred.SequenceEqual(true_result));

            // test a precomputed kernel with the iris dataset
            // and check parameters against a linear SVC
            clf = new Svc<int>(kernel: Kernel.Precomputed);
            var clf2 = new Svc<int>(kernel: Kernel.Linear);
            k = iris.Data*iris.Data.Transpose();
            clf.Fit(k, iris.Target);
            clf2.Fit(iris.Data, iris.Target);
            pred = clf.Predict(k);
            Assert.IsTrue(clf.Support.SequenceEqual(clf2.Support));
            Assert.IsTrue(clf.DualCoef.AlmostEquals(clf2.DualCoef));
            Assert.IsTrue(clf.Intercept.AlmostEquals(clf2.Intercept));

            var matchingN = pred.Zip(iris.Target, Tuple.Create).Where(t => t.Item1 == t.Item2).Count();
            Assert.IsTrue(1.0*matchingN/pred.Length > 0.99);

            // Gram matrix for test data but compute KT[i,j]
            // for support vectors j only.
            k = k.CreateMatrix(k.RowCount, k.ColumnCount);
            for (int i = 0; i < iris.Data.RowCount; i++)
            {
                foreach (var j in clf.Support)
                    k[i, j] = iris.Data.Row(i)*iris.Data.Row(j);
            }

            pred = clf.Predict(k);
            matchingN = pred.Zip(iris.Target, Tuple.Create).Where(t => t.Item1 == t.Item2).Count();
            Assert.IsTrue(1.0*matchingN/pred.Length > 0.99);

            clf = new Svc<int>(kernel: Kernel.FromFunction((x, y) => x*y.Transpose()));
            clf.Fit(iris.Data, iris.Target);
            matchingN = pred.Zip(iris.Target, Tuple.Create).Where(t => t.Item1 == t.Item2).Count();
            Assert.IsTrue(1.0*matchingN/pred.Length > 0.99);
        }
Exemplo n.º 27
0
 public void TestLibsvmIris()
 {
     // shuffle the dataset so that labels are not ordered
     foreach (var k in new[] {Kernel.Linear, Kernel.Rbf})
     {
         var clf = new Svc<int>(kernel: k);
         clf.Fit(iris.Data, iris.Target);
         var pred = clf.Predict(iris.Data);
         var matchingN = pred.Zip(iris.Target, Tuple.Create).Where(t => t.Item1 == t.Item2).Count();
         Assert.IsTrue(1.0*matchingN/pred.Length > 0.9);
         Assert.IsTrue(clf.Classes.SequenceEqual(clf.Classes.OrderBy(v => v)));
     }
 }
Exemplo n.º 28
0
        public void TestPrecomputed()
        {
            var clf = new Svc <int>(kernel: Kernel.Precomputed);
            // Gram matrix for train data (square matrix)
            // (we use just a linear kernel)
            var k = X * (X.Transpose());

            clf.Fit(k, Y);
            // Gram matrix for test data (rectangular matrix)
            var kt   = T * X.Transpose();
            var pred = clf.Predict(kt);

            try
            {
                clf.Predict(kt.Transpose());
                Assert.Fail();
            }
            catch (ArgumentException)
            {
            }

            Assert.IsTrue(clf.DualCoef.AlmostEquals(DenseMatrix.OfArray(new[, ] {
                { 0.25, -.25 }
            })));
            Assert.IsTrue(clf.Support.SequenceEqual(new[] { 1, 3 }));
            Assert.IsTrue(clf.Intercept.SequenceEqual(new[] { 0.0 }));
            Assert.IsTrue(pred.SequenceEqual(true_result));

            // Gram matrix for test data but compute KT[i,j]
            // for support vectors j only.
            kt = kt.CreateMatrix(kt.RowCount, kt.ColumnCount);
            for (int i = 0; i < T.RowCount; i++)
            {
                foreach (var j in clf.Support)
                {
                    kt[i, j] = T.Row(i) * X.Row(j);
                }
            }

            pred = clf.Predict(kt);
            Assert.IsTrue(pred.SequenceEqual(true_result));

            // same as before, but using a callable function instead of the kernel
            // matrix. kernel is just a linear kernel

            clf = new Svc <int>(kernel: Kernel.FromFunction((x, y) => x * y.Transpose()));
            clf.Fit(X, Y);
            pred = clf.Predict(T);

            Assert.IsTrue(clf.DualCoef.AlmostEquals(DenseMatrix.OfArray(new[, ] {
                { 0.25, -.25 }
            })));
            Assert.IsTrue(clf.Support.SequenceEqual(new[] { 1, 3 }));
            Assert.IsTrue(clf.Intercept.SequenceEqual(new[] { 0.0 }));
            Assert.IsTrue(pred.SequenceEqual(true_result));

            // test a precomputed kernel with the iris dataset
            // and check parameters against a linear SVC
            clf = new Svc <int>(kernel: Kernel.Precomputed);
            var clf2 = new Svc <int>(kernel: Kernel.Linear);

            k = iris.Data * iris.Data.Transpose();
            clf.Fit(k, iris.Target);
            clf2.Fit(iris.Data, iris.Target);
            pred = clf.Predict(k);
            Assert.IsTrue(clf.Support.SequenceEqual(clf2.Support));
            Assert.IsTrue(clf.DualCoef.AlmostEquals(clf2.DualCoef));
            Assert.IsTrue(clf.Intercept.AlmostEquals(clf2.Intercept));

            var matchingN = pred.Zip(iris.Target, Tuple.Create).Where(t => t.Item1 == t.Item2).Count();

            Assert.IsTrue(1.0 * matchingN / pred.Length > 0.99);

            // Gram matrix for test data but compute KT[i,j]
            // for support vectors j only.
            k = k.CreateMatrix(k.RowCount, k.ColumnCount);
            for (int i = 0; i < iris.Data.RowCount; i++)
            {
                foreach (var j in clf.Support)
                {
                    k[i, j] = iris.Data.Row(i) * iris.Data.Row(j);
                }
            }

            pred      = clf.Predict(k);
            matchingN = pred.Zip(iris.Target, Tuple.Create).Where(t => t.Item1 == t.Item2).Count();
            Assert.IsTrue(1.0 * matchingN / pred.Length > 0.99);

            clf = new Svc <int>(kernel: Kernel.FromFunction((x, y) => x * y.Transpose()));
            clf.Fit(iris.Data, iris.Target);
            matchingN = pred.Zip(iris.Target, Tuple.Create).Where(t => t.Item1 == t.Item2).Count();
            Assert.IsTrue(1.0 * matchingN / pred.Length > 0.99);
        }