public void multilabelSVM() { var teacher = new MulticlassSupportVectorLearning <Gaussian>() { // Configure the learning algorithm to use SMO to train the // underlying SVMs in each of the binary class subproblems. Learner = (param) => new SequentialMinimalOptimization <Gaussian>() { // Estimate a suitable guess for the Gaussian kernel's parameters. // This estimate can serve as a starting point for a grid search. UseKernelEstimation = true } }; // Learn a machine var machine = teacher.Learn(inputs, outputs); // Create the multi-class learning algorithm for the machine var calibration = new MulticlassSupportVectorLearning <Gaussian>() { Model = machine, // We will start with an existing machine // Configure the learning algorithm to use Platt's calibration Learner = (param) => new ProbabilisticOutputCalibration <Gaussian>() { Model = param.Model // Start with an existing machine } }; // Configure parallel execution options calibration.ParallelOptions.MaxDegreeOfParallelism = 1; // Learn a machine calibration.Learn(inputs, outputs); // Obtain class predictions for each sample int[] predicted = machine.Decide(inputs); // Get class scores for each sample double[] scores = machine.Score(inputs); // Get log-likelihoods (should be same as scores) double[][] logl = machine.LogLikelihoods(inputs); // Get probability for each sample double[][] prob = machine.Probabilities(inputs); // Compute classification error double error = new ZeroOneLoss(outputs).Loss(predicted); double loss = new CategoryCrossEntropyLoss(outputs).Loss(prob); message += "SVM Validacja\n"; message += "error " + error.ToString() + "\n"; message += "loss " + loss.ToString() + "\n\n"; }
public void multiclass_calibration_generic_kernel() { // Let's say we have the following data to be classified // into three possible classes. Those are the samples: // double[][] inputs = { // input output new double[] { 0, 1, 1, 0 }, // 0 new double[] { 0, 1, 0, 0 }, // 0 new double[] { 0, 0, 1, 0 }, // 0 new double[] { 0, 1, 1, 0 }, // 0 new double[] { 0, 1, 0, 0 }, // 0 new double[] { 1, 0, 0, 1 }, // 1 new double[] { 0, 0, 0, 1 }, // 1 new double[] { 0, 0, 0, 1 }, // 1 new double[] { 1, 0, 1, 1 }, // 2 new double[] { 1, 1, 0, 1 }, // 2 new double[] { 0, 1, 1, 1 }, // 2 new double[] { 1, 1, 1, 1 }, // 2 }; int[] outputs = // those are the class labels { 0, 0, 0, 0, 0, 1, 1, 1, 2, 2, 2, 2, }; // Create the multi-class learning algorithm for the machine var teacher = new MulticlassSupportVectorLearning <IKernel>() { // Configure the learning algorithm to use SMO to train the // underlying SVMs in each of the binary class subproblems. Learner = (param) => new SequentialMinimalOptimization <IKernel>() { UseKernelEstimation = false, Kernel = Gaussian.FromGamma(0.5) } }; // Learn a machine var machine = teacher.Learn(inputs, outputs); // Create the multi-class learning algorithm for the machine var calibration = new MulticlassSupportVectorLearning <IKernel>(machine) { // Configure the learning algorithm to use SMO to train the // underlying SVMs in each of the binary class subproblems. Learner = (param) => new ProbabilisticOutputCalibration <IKernel>(param.Model) }; // Configure parallel execution options calibration.ParallelOptions.MaxDegreeOfParallelism = 1; // Learn a machine calibration.Learn(inputs, outputs); // Obtain class predictions for each sample int[] predicted = machine.Decide(inputs); // Get class scores for each sample double[] scores = machine.Score(inputs); // Get log-likelihoods (should be same as scores) double[][] logl = machine.LogLikelihoods(inputs); // Get probability for each sample double[][] prob = machine.Probabilities(inputs); // Compute classification error double error = new ZeroOneLoss(outputs).Loss(predicted); double loss = new CategoryCrossEntropyLoss(outputs).Loss(prob); //string str = logl.ToCSharp(); double[] expectedScores = { 1.87436400885238, 1.81168086449304, 1.74038320983522, 1.87436400885238, 1.81168086449304, 1.55446926953952, 1.67016543853596, 1.67016543853596, 1.83135194001403, 1.83135194001403, 1.59836868669125, 2.0618816310294 }; double[][] expectedLogL = { new double[] { 1.87436400885238, -1.87436400885238, -1.7463646841257 }, new double[] { 1.81168086449304, -1.81168086449304, -1.73142460658826 }, new double[] { 1.74038320983522, -1.58848669816072, -1.74038320983522 }, new double[] { 1.87436400885238, -1.87436400885238, -1.7463646841257 }, new double[] { 1.81168086449304, -1.81168086449304, -1.73142460658826 }, new double[] { -1.55446926953952, 1.55446926953952, -0.573599079216229 }, new double[] { -0.368823000428743, 1.67016543853596, -1.67016543853596 }, new double[] { -0.368823000428743, 1.67016543853596, -1.67016543853596 }, new double[] { -1.83135194001403, -1.20039293330558, 1.83135194001403 }, new double[] { -1.83135194001403, -1.20039293330558, 1.83135194001403 }, new double[] { -0.894598978116595, -1.59836868669125, 1.59836868669125 }, new double[] { -1.87336852014759, -2.0618816310294, 2.0618816310294 } }; double[][] expectedProbs = { new double[] { 0.95209908906855, 0.0224197237689656, 0.0254811871624848 }, new double[] { 0.947314032745205, 0.0252864560196241, 0.0273995112351714 }, new double[] { 0.937543314993345, 0.0335955309754816, 0.028861154031173 }, new double[] { 0.95209908906855, 0.0224197237689656, 0.0254811871624848 }, new double[] { 0.947314032745205, 0.0252864560196241, 0.0273995112351714 }, new double[] { 0.0383670466237636, 0.859316640577158, 0.102316312799079 }, new double[] { 0.111669460983068, 0.857937888238824, 0.0303926507781076 }, new double[] { 0.111669460983068, 0.857937888238824, 0.0303926507781076 }, new double[] { 0.0238971617859334, 0.0449126146360623, 0.931190223578004 }, new double[] { 0.0238971617859334, 0.0449126146360623, 0.931190223578004 }, new double[] { 0.0735735561383806, 0.0363980776342206, 0.890028366227399 }, new double[] { 0.0188668069460003, 0.0156252941482294, 0.96550789890577 } }; // Must be exactly the same as test above Assert.AreEqual(0, error); Assert.AreEqual(0.5, ((Gaussian)machine[0].Value.Kernel).Gamma); Assert.AreEqual(0.5, ((Gaussian)machine[1].Value.Kernel).Gamma); Assert.AreEqual(0.5, ((Gaussian)machine[2].Value.Kernel).Gamma); Assert.AreEqual(1.0231652126930515, loss); Assert.IsTrue(predicted.IsEqual(outputs)); Assert.IsTrue(expectedScores.IsEqual(scores, 1e-10)); Assert.IsTrue(expectedLogL.IsEqual(logl, 1e-10)); Assert.IsTrue(expectedProbs.IsEqual(prob, 1e-10)); }
public void multiclass_gaussian_new_usage() { #region doc_learn_gaussian // Let's say we have the following data to be classified // into three possible classes. Those are the samples: // double[][] inputs = { // input output new double[] { 0, 1, 1, 0 }, // 0 new double[] { 0, 1, 0, 0 }, // 0 new double[] { 0, 0, 1, 0 }, // 0 new double[] { 0, 1, 1, 0 }, // 0 new double[] { 0, 1, 0, 0 }, // 0 new double[] { 1, 0, 0, 0 }, // 1 new double[] { 1, 0, 0, 0 }, // 1 new double[] { 1, 0, 0, 1 }, // 1 new double[] { 0, 0, 0, 1 }, // 1 new double[] { 0, 0, 0, 1 }, // 1 new double[] { 1, 1, 1, 1 }, // 2 new double[] { 1, 0, 1, 1 }, // 2 new double[] { 1, 1, 0, 1 }, // 2 new double[] { 0, 1, 1, 1 }, // 2 new double[] { 1, 1, 1, 1 }, // 2 }; int[] outputs = // those are the class labels { 0, 0, 0, 0, 0, 1, 1, 1, 1, 1, 2, 2, 2, 2, 2, }; // Create the multi-class learning algorithm for the machine var teacher = new MulticlassSupportVectorLearning <Gaussian>() { // Configure the learning algorithm to use SMO to train the // underlying SVMs in each of the binary class subproblems. Learner = (param) => new SequentialMinimalOptimization <Gaussian>() { // Estimate a suitable guess for the Gaussian kernel's parameters. // This estimate can serve as a starting point for a grid search. UseKernelEstimation = true } }; // Configure parallel execution options teacher.ParallelOptions.MaxDegreeOfParallelism = 1; // Learn a machine var machine = teacher.Learn(inputs, outputs); // Obtain class predictions for each sample int[] predicted = machine.Decide(inputs); // Get class scores for each sample double[] scores = machine.Score(inputs); // Compute classification error double error = new ZeroOneLoss(outputs).Loss(predicted); #endregion // Get log-likelihoods (should be same as scores) double[][] logl = machine.LogLikelihoods(inputs); // Get probability for each sample double[][] prob = machine.Probabilities(inputs); // Compute classification error double loss = new CategoryCrossEntropyLoss(outputs).Loss(prob); string str = scores.ToCSharp(); double[] expectedScores = { 1.00888999727541, 1.00303259868784, 1.00068403386636, 1.00888999727541, 1.00303259868784, 1.00831890183328, 1.00831890183328, 0.843757409449037, 0.996768862332386, 0.996768862332386, 1.02627325826713, 1.00303259868784, 0.996967401312164, 0.961947708617365, 1.02627325826713 }; double[][] expectedLogL = { new double[] { 1.00888999727541, -1.00888999727541, -1.00135670089335 }, new double[] { 1.00303259868784, -0.991681098166717, -1.00303259868784 }, new double[] { 1.00068403386636, -0.54983354268499, -1.00068403386636 }, new double[] { 1.00888999727541, -1.00888999727541, -1.00135670089335 }, new double[] { 1.00303259868784, -0.991681098166717, -1.00303259868784 }, new double[] { -1.00831890183328, 1.00831890183328, -0.0542719287771535 }, new double[] { -1.00831890183328, 1.00831890183328, -0.0542719287771535 }, new double[] { -0.843757409449037, 0.843757409449037, -0.787899083913034 }, new double[] { -0.178272229157676, 0.996768862332386, -0.996768862332386 }, new double[] { -0.178272229157676, 0.996768862332386, -0.996768862332386 }, new double[] { -1.02627325826713, -1.00323113766761, 1.02627325826713 }, new double[] { -1.00303259868784, -0.38657999872922, 1.00303259868784 }, new double[] { -0.996967401312164, -0.38657999872922, 0.996967401312164 }, new double[] { -0.479189991343958, -0.961947708617365, 0.961947708617365 }, new double[] { -1.02627325826713, -1.00323113766761, 1.02627325826713 } }; double[][] expectedProbs = { new double[] { 0.789324598208647, 0.104940932711551, 0.105734469079803 }, new double[] { 0.78704862182644, 0.107080012017624, 0.105871366155937 }, new double[] { 0.74223157627093, 0.157455631737191, 0.100312791991879 }, new double[] { 0.789324598208647, 0.104940932711551, 0.105734469079803 }, new double[] { 0.78704862182644, 0.107080012017624, 0.105871366155937 }, new double[] { 0.0900153422818135, 0.676287261796794, 0.233697395921392 }, new double[] { 0.0900153422818135, 0.676287261796794, 0.233697395921392 }, new double[] { 0.133985810363445, 0.72433118122885, 0.141683008407705 }, new double[] { 0.213703968297751, 0.692032433073136, 0.0942635986291124 }, new double[] { 0.213703968297751, 0.692032433073136, 0.0942635986291124 }, new double[] { 0.10192623206507, 0.104302095948601, 0.79377167198633 }, new double[] { 0.0972161784678357, 0.180077937396817, 0.722705884135347 }, new double[] { 0.0981785890979593, 0.180760971768703, 0.721060439133338 }, new double[] { 0.171157270099157, 0.105617610634377, 0.723225119266465 }, new double[] { 0.10192623206507, 0.104302095948601, 0.79377167198633 } }; Assert.AreEqual(0, error); Assert.AreEqual(4.5289447815997672, loss, 1e-10); Assert.IsTrue(predicted.IsEqual(outputs)); Assert.IsTrue(expectedScores.IsEqual(scores, 1e-10)); Assert.IsTrue(expectedLogL.IsEqual(logl, 1e-10)); Assert.IsTrue(expectedProbs.IsEqual(prob, 1e-10)); }
public void multilabel_calibration_generic_kernel() { // Let's say we have the following data to be classified // into three possible classes. Those are the samples: // double[][] inputs = { // input output new double[] { 0, 1, 1, 0 }, // 0 new double[] { 0, 1, 0, 0 }, // 0 new double[] { 0, 0, 1, 0 }, // 0 new double[] { 0, 1, 1, 0 }, // 0 new double[] { 0, 1, 0, 0 }, // 0 new double[] { 1, 0, 0, 1 }, // 1 new double[] { 0, 0, 0, 1 }, // 1 new double[] { 0, 0, 0, 1 }, // 1 new double[] { 1, 0, 1, 1 }, // 2 new double[] { 1, 1, 0, 1 }, // 2 new double[] { 0, 1, 1, 1 }, // 2 new double[] { 1, 1, 1, 1 }, // 2 }; int[] outputs = // those are the class labels { 0, 0, 0, 0, 0, 1, 1, 1, 2, 2, 2, 2, }; // Create the multi-class learning algorithm for the machine var teacher = new MultilabelSupportVectorLearning <IKernel>() { // Configure the learning algorithm to use SMO to train the // underlying SVMs in each of the binary class subproblems. Learner = (param) => new SequentialMinimalOptimization <IKernel>() { UseKernelEstimation = false, Kernel = Gaussian.FromGamma(0.5) } }; // Learn a machine var machine = teacher.Learn(inputs, outputs); // Create the multi-class learning algorithm for the machine var calibration = new MultilabelSupportVectorLearning <IKernel>(machine) { // Configure the learning algorithm to use SMO to train the // underlying SVMs in each of the binary class subproblems. Learner = (p) => new ProbabilisticOutputCalibration <IKernel>(p.Model) }; // Configure parallel execution options calibration.ParallelOptions.MaxDegreeOfParallelism = 1; // Learn a machine calibration.Learn(inputs, outputs); // Obtain class predictions for each sample bool[][] predicted = machine.Decide(inputs); // Get class scores for each sample double[][] scores = machine.Scores(inputs); // Get log-likelihoods (should be same as scores) double[][] logl = machine.LogLikelihoods(inputs); // Get probability for each sample double[][] prob = machine.Probabilities(inputs); // Compute classification error using mean accuracy (mAcc) double error = new HammingLoss(outputs).Loss(predicted); double loss = new CategoryCrossEntropyLoss(outputs).Loss(prob); string a = scores.ToCSharp(); string b = logl.ToCSharp(); string c = prob.ToCSharp(); double[][] expectedScores = { new double[] { 1.85316017783605, -2.59688389729331, -2.32170102153988 }, new double[] { 1.84933597524124, -1.99399145231446, -2.2920299547693 }, new double[] { 1.44477953581274, -1.98592298465108, -2.27356092239125 }, new double[] { 1.85316017783605, -2.59688389729331, -2.32170102153988 }, new double[] { 1.84933597524124, -1.99399145231446, -2.2920299547693 }, new double[] { -2.40815576360914, 0.328362962196791, -0.932721757919691 }, new double[] { -2.13111157264226, 1.809192096031, -2.2920299547693 }, new double[] { -2.13111157264226, 1.809192096031, -2.2920299547693 }, new double[] { -2.14888646926108, -1.99399145231447, 1.33101148524982 }, new double[] { -2.12915064678299, -1.98592298465108, 1.3242171079396 }, new double[] { -1.47197826667149, -1.96368715704762, 0.843414180834243 }, new double[] { -2.14221021749314, -2.83117892529093, 2.61354519154994 } }; double[][] expectedLogL = { new double[] { -0.145606614365135, -2.66874434442222, -2.41528841111469 }, new double[] { -0.146125659911391, -2.12163759796483, -2.3883043096263 }, new double[] { -0.211716960454159, -2.11453945718522, -2.37154474995633 }, new double[] { -0.145606614365135, -2.66874434442222, -2.41528841111469 }, new double[] { -0.146125659911391, -2.12163759796483, -2.3883043096263 }, new double[] { -2.4943161092787, -0.542383360363463, -1.26452689970624 }, new double[] { -2.24328358118314, -0.151678833375872, -2.3883043096263 }, new double[] { -2.24328358118314, -0.151678833375872, -2.3883043096263 }, new double[] { -2.25918730624753, -2.12163759796483, -0.234447327588685 }, new double[] { -2.24153091066541, -2.11453945718522, -0.2358711195715 }, new double[] { -1.67856232802554, -2.0950136294762, -0.357841632335707 }, new double[] { -2.25321037906455, -2.88845047104229, -0.0707140798850236 } }; double[][] expectedProbs = { new double[] { 0.844913862516144, 0.0677684640174953, 0.0873176734663607 }, new double[] { 0.803266328757473, 0.111405242674824, 0.0853284285677024 }, new double[] { 0.790831391595502, 0.117950175028754, 0.0912184333757438 }, new double[] { 0.844913862516144, 0.0677684640174953, 0.0873176734663607 }, new double[] { 0.803266328757473, 0.111405242674824, 0.0853284285677024 }, new double[] { 0.0872387667998771, 0.614360294206236, 0.298400938993887 }, new double[] { 0.100372339295793, 0.812805149315815, 0.0868225113883914 }, new double[] { 0.100372339295793, 0.812805149315815, 0.0868225113883914 }, new double[] { 0.102863726210119, 0.11803188195247, 0.779104391837411 }, new double[] { 0.104532503226998, 0.118686968710368, 0.776780528062634 }, new double[] { 0.184996665350572, 0.121983586443407, 0.693019748206021 }, new double[] { 0.0961702585148881, 0.0509517983210315, 0.85287794316408 } }; int[] actual = predicted.ArgMax(dimension: 1); Assert.IsTrue(actual.IsEqual(outputs)); // Must be exactly the same as test above Assert.AreEqual(0, error); Assert.AreEqual(0.5, ((Gaussian)machine[0].Kernel).Gamma); Assert.AreEqual(0.5, ((Gaussian)machine[1].Kernel).Gamma); Assert.AreEqual(0.5, ((Gaussian)machine[2].Kernel).Gamma); Assert.AreEqual(2.9395943260892361, loss); Assert.IsTrue(expectedScores.IsEqual(scores, 1e-10)); Assert.IsTrue(expectedLogL.IsEqual(logl, 1e-10)); Assert.IsTrue(expectedProbs.IsEqual(prob, 1e-10)); double[] probabilities = CorrectProbabilities(machine, inputs[0]); double[] actualProb = machine.Probabilities(inputs[0]); Assert.IsTrue(probabilities.IsEqual(actualProb, 1e-8)); }
public void multilabel_calibration() { #region doc_learn_calibration // Let's say we have the following data to be classified // into three possible classes. Those are the samples: // double[][] inputs = { // input output new double[] { 0, 1, 1, 0 }, // 0 new double[] { 0, 1, 0, 0 }, // 0 new double[] { 0, 0, 1, 0 }, // 0 new double[] { 0, 1, 1, 0 }, // 0 new double[] { 0, 1, 0, 0 }, // 0 new double[] { 1, 0, 0, 1 }, // 1 new double[] { 0, 0, 0, 1 }, // 1 new double[] { 0, 0, 0, 1 }, // 1 new double[] { 1, 0, 1, 1 }, // 2 new double[] { 1, 1, 0, 1 }, // 2 new double[] { 0, 1, 1, 1 }, // 2 new double[] { 1, 1, 1, 1 }, // 2 }; int[] outputs = // those are the class labels { 0, 0, 0, 0, 0, 1, 1, 1, 2, 2, 2, 2, }; // Create the multi-class learning algorithm for the machine var teacher = new MultilabelSupportVectorLearning <Gaussian>() { // Configure the learning algorithm to use SMO to train the // underlying SVMs in each of the binary class subproblems. Learner = (param) => new SequentialMinimalOptimization <Gaussian>() { // Estimate a suitable guess for the Gaussian kernel's parameters. // This estimate can serve as a starting point for a grid search. UseKernelEstimation = true } }; // Learn a machine var machine = teacher.Learn(inputs, outputs); // Create the multi-class learning algorithm for the machine var calibration = new MultilabelSupportVectorLearning <Gaussian>() { Model = machine, // We will start with an existing machine // Configure the learning algorithm to use SMO to train the // underlying SVMs in each of the binary class subproblems. Learner = (param) => new ProbabilisticOutputCalibration <Gaussian>() { Model = param.Model // Start with an existing machine } }; // Configure parallel execution options calibration.ParallelOptions.MaxDegreeOfParallelism = 1; // Learn a machine calibration.Learn(inputs, outputs); // Obtain class predictions for each sample bool[][] predicted = machine.Decide(inputs); // Get class scores for each sample double[][] scores = machine.Scores(inputs); // Get log-likelihoods (should be same as scores) double[][] logl = machine.LogLikelihoods(inputs); // Get probability for each sample double[][] prob = machine.Probabilities(inputs); // Compute classification error using mean accuracy (mAcc) double error = new HammingLoss(outputs).Loss(predicted); double loss = new CategoryCrossEntropyLoss(outputs).Loss(prob); #endregion string a = scores.ToCSharp(); string b = logl.ToCSharp(); string c = prob.ToCSharp(); double[][] expectedScores = { new double[] { 1.85316017783605, -2.59688389729331, -2.32170102153988 }, new double[] { 1.84933597524124, -1.99399145231446, -2.2920299547693 }, new double[] { 1.44477953581274, -1.98592298465108, -2.27356092239125 }, new double[] { 1.85316017783605, -2.59688389729331, -2.32170102153988 }, new double[] { 1.84933597524124, -1.99399145231446, -2.2920299547693 }, new double[] { -2.40815576360914, 0.328362962196791, -0.932721757919691 }, new double[] { -2.13111157264226, 1.809192096031, -2.2920299547693 }, new double[] { -2.13111157264226, 1.809192096031, -2.2920299547693 }, new double[] { -2.14888646926108, -1.99399145231447, 1.33101148524982 }, new double[] { -2.12915064678299, -1.98592298465108, 1.3242171079396 }, new double[] { -1.47197826667149, -1.96368715704762, 0.843414180834243 }, new double[] { -2.14221021749314, -2.83117892529093, 2.61354519154994 } }; double[][] expectedLogL = { new double[] { -0.145606614365135, -2.66874434442222, -2.41528841111469 }, new double[] { -0.146125659911391, -2.12163759796483, -2.3883043096263 }, new double[] { -0.211716960454159, -2.11453945718522, -2.37154474995633 }, new double[] { -0.145606614365135, -2.66874434442222, -2.41528841111469 }, new double[] { -0.146125659911391, -2.12163759796483, -2.3883043096263 }, new double[] { -2.4943161092787, -0.542383360363463, -1.26452689970624 }, new double[] { -2.24328358118314, -0.151678833375872, -2.3883043096263 }, new double[] { -2.24328358118314, -0.151678833375872, -2.3883043096263 }, new double[] { -2.25918730624753, -2.12163759796483, -0.234447327588685 }, new double[] { -2.24153091066541, -2.11453945718522, -0.2358711195715 }, new double[] { -1.67856232802554, -2.0950136294762, -0.357841632335707 }, new double[] { -2.25321037906455, -2.88845047104229, -0.0707140798850236 } }; double[][] expectedProbs = { new double[] { 0.844913862516144, 0.0677684640174953, 0.0873176734663607 }, new double[] { 0.803266328757473, 0.111405242674824, 0.0853284285677024 }, new double[] { 0.790831391595502, 0.117950175028754, 0.0912184333757438 }, new double[] { 0.844913862516144, 0.0677684640174953, 0.0873176734663607 }, new double[] { 0.803266328757473, 0.111405242674824, 0.0853284285677024 }, new double[] { 0.0872387667998771, 0.614360294206236, 0.298400938993887 }, new double[] { 0.100372339295793, 0.812805149315815, 0.0868225113883914 }, new double[] { 0.100372339295793, 0.812805149315815, 0.0868225113883914 }, new double[] { 0.102863726210119, 0.11803188195247, 0.779104391837411 }, new double[] { 0.104532503226998, 0.118686968710368, 0.776780528062634 }, new double[] { 0.184996665350572, 0.121983586443407, 0.693019748206021 }, new double[] { 0.0961702585148881, 0.0509517983210315, 0.85287794316408 } }; int[] actual = predicted.ArgMax(dimension: 1); Assert.IsTrue(actual.IsEqual(outputs)); Assert.AreEqual(0, error); Assert.AreEqual(3, machine.Count); Assert.AreEqual(0.5, machine[0].Kernel.Gamma); Assert.AreEqual(0.5, machine[1].Kernel.Gamma); Assert.AreEqual(0.5, machine[2].Kernel.Gamma); Assert.AreEqual(2.9395943260892361, loss); Assert.IsTrue(expectedScores.IsEqual(scores, 1e-10)); Assert.IsTrue(expectedLogL.IsEqual(logl, 1e-10)); Assert.IsTrue(expectedProbs.IsEqual(prob, 1e-10)); double[] rowSums = expectedProbs.Sum(1); Assert.IsTrue(rowSums.IsEqual(Vector.Ones(expectedProbs.Length), 1e-10)); { bool[][] predicted2 = null; double[][] scores2 = machine.Scores(inputs, ref predicted2); Assert.IsTrue(scores2.IsEqual(scores)); Assert.IsTrue(predicted2.IsEqual(predicted)); double[][] logl2 = machine.LogLikelihoods(inputs, ref predicted2); Assert.IsTrue(logl2.IsEqual(logl)); Assert.IsTrue(predicted2.IsEqual(predicted)); double[][] prob2 = machine.Probabilities(inputs, ref predicted2); Assert.IsTrue(prob2.IsEqual(prob)); Assert.IsTrue(predicted2.IsEqual(predicted)); bool[][] predicted3 = new bool[predicted2.Length][]; double[][] scores3 = inputs.ApplyWithIndex((x, i) => machine.Scores(x, ref predicted3[i])); Assert.IsTrue(scores3.IsEqual(scores)); Assert.IsTrue(predicted3.IsEqual(predicted)); double[][] logl3 = inputs.ApplyWithIndex((x, i) => machine.LogLikelihoods(x, ref predicted3[i])); Assert.IsTrue(logl3.IsEqual(logl)); Assert.IsTrue(predicted3.IsEqual(predicted)); double[][] prob3 = inputs.ApplyWithIndex((x, i) => machine.Probabilities(x, ref predicted3[i])); Assert.IsTrue(prob3.IsEqual(prob)); Assert.IsTrue(predicted3.IsEqual(predicted)); } { double[] ed = new double[scores.Length]; double[] es = new double[scores.Length]; double[] el = new double[scores.Length]; double[] ep = new double[scores.Length]; for (int i = 0; i < expectedScores.Length; i++) { int j = scores[i].ArgMax(); ed[i] = j; es[i] = scores[i][j]; el[i] = logl[i][j]; ep[i] = prob[i][j]; } int[] predicted2 = null; double[] scores2 = machine.ToMulticlass().Score(inputs, ref predicted2); Assert.IsTrue(scores2.IsEqual(es)); Assert.IsTrue(predicted2.IsEqual(ed)); double[] logl2 = machine.ToMulticlass().LogLikelihood(inputs, ref predicted2); Assert.IsTrue(logl2.IsEqual(el)); Assert.IsTrue(predicted2.IsEqual(ed)); double[] prob2 = machine.ToMulticlass().Probability(inputs, ref predicted2); Assert.IsTrue(prob2.IsEqual(ep)); Assert.IsTrue(predicted2.IsEqual(ed)); int[] predicted3 = new int[predicted2.Length]; double[] scores3 = inputs.ApplyWithIndex((x, i) => machine.ToMulticlass().Score(x, out predicted3[i])); Assert.IsTrue(scores3.IsEqual(es)); Assert.IsTrue(predicted3.IsEqual(ed)); double[] logl3 = inputs.ApplyWithIndex((x, i) => machine.ToMulticlass().LogLikelihood(x, out predicted3[i])); Assert.IsTrue(logl3.IsEqual(el)); Assert.IsTrue(predicted3.IsEqual(ed)); double[] prob3 = inputs.ApplyWithIndex((x, i) => machine.ToMulticlass().Probability(x, out predicted3[i])); Assert.IsTrue(prob3.IsEqual(ep)); Assert.IsTrue(predicted3.IsEqual(ed)); } }
public void multiclass_calibration_generic_kernel() { // Let's say we have the following data to be classified // into three possible classes. Those are the samples: // double[][] inputs = { // input output new double[] { 0, 1, 1, 0 }, // 0 new double[] { 0, 1, 0, 0 }, // 0 new double[] { 0, 0, 1, 0 }, // 0 new double[] { 0, 1, 1, 0 }, // 0 new double[] { 0, 1, 0, 0 }, // 0 new double[] { 1, 0, 0, 1 }, // 1 new double[] { 0, 0, 0, 1 }, // 1 new double[] { 0, 0, 0, 1 }, // 1 new double[] { 1, 0, 1, 1 }, // 2 new double[] { 1, 1, 0, 1 }, // 2 new double[] { 0, 1, 1, 1 }, // 2 new double[] { 1, 1, 1, 1 }, // 2 }; int[] outputs = // those are the class labels { 0, 0, 0, 0, 0, 1, 1, 1, 2, 2, 2, 2, }; // Create the multi-class learning algorithm for the machine var teacher = new MulticlassSupportVectorLearning<IKernel>() { // Configure the learning algorithm to use SMO to train the // underlying SVMs in each of the binary class subproblems. Learner = (param) => new SequentialMinimalOptimization<IKernel>() { UseKernelEstimation = false, Kernel = Gaussian.FromGamma(0.5) } }; // Learn a machine var machine = teacher.Learn(inputs, outputs); // Create the multi-class learning algorithm for the machine var calibration = new MulticlassSupportVectorLearning<IKernel>(machine) { // Configure the learning algorithm to use SMO to train the // underlying SVMs in each of the binary class subproblems. Learner = (param) => new ProbabilisticOutputCalibration<IKernel>(param.Model) }; // Configure parallel execution options calibration.ParallelOptions.MaxDegreeOfParallelism = 1; // Learn a machine calibration.Learn(inputs, outputs); // Obtain class predictions for each sample int[] predicted = machine.Decide(inputs); // Get class scores for each sample double[] scores = machine.Score(inputs); // Get log-likelihoods (should be same as scores) double[][] logl = machine.LogLikelihoods(inputs); // Get probability for each sample double[][] prob = machine.Probabilities(inputs); // Compute classification error double error = new ZeroOneLoss(outputs).Loss(predicted); double loss = new CategoryCrossEntropyLoss(outputs).Loss(prob); //string str = logl.ToCSharp(); double[] expectedScores = { 1.87436400885238, 1.81168086449304, 1.74038320983522, 1.87436400885238, 1.81168086449304, 1.55446926953952, 1.67016543853596, 1.67016543853596, 1.83135194001403, 1.83135194001403, 1.59836868669125, 2.0618816310294 }; double[][] expectedLogL = { new double[] { 1.87436400885238, -1.87436400885238, -1.7463646841257 }, new double[] { 1.81168086449304, -1.81168086449304, -1.73142460658826 }, new double[] { 1.74038320983522, -1.58848669816072, -1.74038320983522 }, new double[] { 1.87436400885238, -1.87436400885238, -1.7463646841257 }, new double[] { 1.81168086449304, -1.81168086449304, -1.73142460658826 }, new double[] { -1.55446926953952, 1.55446926953952, -0.573599079216229 }, new double[] { -0.368823000428743, 1.67016543853596, -1.67016543853596 }, new double[] { -0.368823000428743, 1.67016543853596, -1.67016543853596 }, new double[] { -1.83135194001403, -1.20039293330558, 1.83135194001403 }, new double[] { -1.83135194001403, -1.20039293330558, 1.83135194001403 }, new double[] { -0.894598978116595, -1.59836868669125, 1.59836868669125 }, new double[] { -1.87336852014759, -2.0618816310294, 2.0618816310294 } }; double[][] expectedProbs = { new double[] { 0.95209908906855, 0.0224197237689656, 0.0254811871624848 }, new double[] { 0.947314032745205, 0.0252864560196241, 0.0273995112351714 }, new double[] { 0.937543314993345, 0.0335955309754816, 0.028861154031173 }, new double[] { 0.95209908906855, 0.0224197237689656, 0.0254811871624848 }, new double[] { 0.947314032745205, 0.0252864560196241, 0.0273995112351714 }, new double[] { 0.0383670466237636, 0.859316640577158, 0.102316312799079 }, new double[] { 0.111669460983068, 0.857937888238824, 0.0303926507781076 }, new double[] { 0.111669460983068, 0.857937888238824, 0.0303926507781076 }, new double[] { 0.0238971617859334, 0.0449126146360623, 0.931190223578004 }, new double[] { 0.0238971617859334, 0.0449126146360623, 0.931190223578004 }, new double[] { 0.0735735561383806, 0.0363980776342206, 0.890028366227399 }, new double[] { 0.0188668069460003, 0.0156252941482294, 0.96550789890577 } }; // Must be exactly the same as test above Assert.AreEqual(0, error); Assert.AreEqual(0.5, ((Gaussian)machine[0].Value.Kernel).Gamma); Assert.AreEqual(0.5, ((Gaussian)machine[1].Value.Kernel).Gamma); Assert.AreEqual(0.5, ((Gaussian)machine[2].Value.Kernel).Gamma); Assert.AreEqual(1.0231652126930515, loss); Assert.IsTrue(predicted.IsEqual(outputs)); Assert.IsTrue(expectedScores.IsEqual(scores, 1e-10)); Assert.IsTrue(expectedLogL.IsEqual(logl, 1e-10)); Assert.IsTrue(expectedProbs.IsEqual(prob, 1e-10)); }
public void multiclass_gaussian_new_usage() { #region doc_learn_gaussian // Let's say we have the following data to be classified // into three possible classes. Those are the samples: // double[][] inputs = { // input output new double[] { 0, 1, 1, 0 }, // 0 new double[] { 0, 1, 0, 0 }, // 0 new double[] { 0, 0, 1, 0 }, // 0 new double[] { 0, 1, 1, 0 }, // 0 new double[] { 0, 1, 0, 0 }, // 0 new double[] { 1, 0, 0, 0 }, // 1 new double[] { 1, 0, 0, 0 }, // 1 new double[] { 1, 0, 0, 1 }, // 1 new double[] { 0, 0, 0, 1 }, // 1 new double[] { 0, 0, 0, 1 }, // 1 new double[] { 1, 1, 1, 1 }, // 2 new double[] { 1, 0, 1, 1 }, // 2 new double[] { 1, 1, 0, 1 }, // 2 new double[] { 0, 1, 1, 1 }, // 2 new double[] { 1, 1, 1, 1 }, // 2 }; int[] outputs = // those are the class labels { 0, 0, 0, 0, 0, 1, 1, 1, 1, 1, 2, 2, 2, 2, 2, }; // Create the multi-class learning algorithm for the machine var teacher = new MulticlassSupportVectorLearning<Gaussian>() { // Configure the learning algorithm to use SMO to train the // underlying SVMs in each of the binary class subproblems. Learner = (param) => new SequentialMinimalOptimization<Gaussian>() { // Estimate a suitable guess for the Gaussian kernel's parameters. // This estimate can serve as a starting point for a grid search. UseKernelEstimation = true } }; // Configure parallel execution options teacher.ParallelOptions.MaxDegreeOfParallelism = 1; // Learn a machine var machine = teacher.Learn(inputs, outputs); // Obtain class predictions for each sample int[] predicted = machine.Decide(inputs); // Get class scores for each sample double[] scores = machine.Score(inputs); // Compute classification error double error = new ZeroOneLoss(outputs).Loss(predicted); #endregion // Get log-likelihoods (should be same as scores) double[][] logl = machine.LogLikelihoods(inputs); // Get probability for each sample double[][] prob = machine.Probabilities(inputs); // Compute classification error double loss = new CategoryCrossEntropyLoss(outputs).Loss(prob); string str = scores.ToCSharp(); double[] expectedScores = { 1.00888999727541, 1.00303259868784, 1.00068403386636, 1.00888999727541, 1.00303259868784, 1.00831890183328, 1.00831890183328, 0.843757409449037, 0.996768862332386, 0.996768862332386, 1.02627325826713, 1.00303259868784, 0.996967401312164, 0.961947708617365, 1.02627325826713 }; double[][] expectedLogL = { new double[] { 1.00888999727541, -1.00888999727541, -1.00135670089335 }, new double[] { 1.00303259868784, -0.991681098166717, -1.00303259868784 }, new double[] { 1.00068403386636, -0.54983354268499, -1.00068403386636 }, new double[] { 1.00888999727541, -1.00888999727541, -1.00135670089335 }, new double[] { 1.00303259868784, -0.991681098166717, -1.00303259868784 }, new double[] { -1.00831890183328, 1.00831890183328, -0.0542719287771535 }, new double[] { -1.00831890183328, 1.00831890183328, -0.0542719287771535 }, new double[] { -0.843757409449037, 0.843757409449037, -0.787899083913034 }, new double[] { -0.178272229157676, 0.996768862332386, -0.996768862332386 }, new double[] { -0.178272229157676, 0.996768862332386, -0.996768862332386 }, new double[] { -1.02627325826713, -1.00323113766761, 1.02627325826713 }, new double[] { -1.00303259868784, -0.38657999872922, 1.00303259868784 }, new double[] { -0.996967401312164, -0.38657999872922, 0.996967401312164 }, new double[] { -0.479189991343958, -0.961947708617365, 0.961947708617365 }, new double[] { -1.02627325826713, -1.00323113766761, 1.02627325826713 } }; double[][] expectedProbs = { new double[] { 0.789324598208647, 0.104940932711551, 0.105734469079803 }, new double[] { 0.78704862182644, 0.107080012017624, 0.105871366155937 }, new double[] { 0.74223157627093, 0.157455631737191, 0.100312791991879 }, new double[] { 0.789324598208647, 0.104940932711551, 0.105734469079803 }, new double[] { 0.78704862182644, 0.107080012017624, 0.105871366155937 }, new double[] { 0.0900153422818135, 0.676287261796794, 0.233697395921392 }, new double[] { 0.0900153422818135, 0.676287261796794, 0.233697395921392 }, new double[] { 0.133985810363445, 0.72433118122885, 0.141683008407705 }, new double[] { 0.213703968297751, 0.692032433073136, 0.0942635986291124 }, new double[] { 0.213703968297751, 0.692032433073136, 0.0942635986291124 }, new double[] { 0.10192623206507, 0.104302095948601, 0.79377167198633 }, new double[] { 0.0972161784678357, 0.180077937396817, 0.722705884135347 }, new double[] { 0.0981785890979593, 0.180760971768703, 0.721060439133338 }, new double[] { 0.171157270099157, 0.105617610634377, 0.723225119266465 }, new double[] { 0.10192623206507, 0.104302095948601, 0.79377167198633 } }; Assert.AreEqual(0, error); Assert.AreEqual(4.5289447815997672, loss, 1e-10); Assert.IsTrue(predicted.IsEqual(outputs)); Assert.IsTrue(expectedScores.IsEqual(scores, 1e-10)); Assert.IsTrue(expectedLogL.IsEqual(logl, 1e-10)); Assert.IsTrue(expectedProbs.IsEqual(prob, 1e-10)); }
public void multilabel_calibration_generic_kernel() { // Let's say we have the following data to be classified // into three possible classes. Those are the samples: // double[][] inputs = { // input output new double[] { 0, 1, 1, 0 }, // 0 new double[] { 0, 1, 0, 0 }, // 0 new double[] { 0, 0, 1, 0 }, // 0 new double[] { 0, 1, 1, 0 }, // 0 new double[] { 0, 1, 0, 0 }, // 0 new double[] { 1, 0, 0, 1 }, // 1 new double[] { 0, 0, 0, 1 }, // 1 new double[] { 0, 0, 0, 1 }, // 1 new double[] { 1, 0, 1, 1 }, // 2 new double[] { 1, 1, 0, 1 }, // 2 new double[] { 0, 1, 1, 1 }, // 2 new double[] { 1, 1, 1, 1 }, // 2 }; int[] outputs = // those are the class labels { 0, 0, 0, 0, 0, 1, 1, 1, 2, 2, 2, 2, }; // Create the multi-class learning algorithm for the machine var teacher = new MultilabelSupportVectorLearning <IKernel>() { // Configure the learning algorithm to use SMO to train the // underlying SVMs in each of the binary class subproblems. Learner = (param) => new SequentialMinimalOptimization <IKernel>() { UseKernelEstimation = false, Kernel = Gaussian.FromGamma(0.5) } }; // Learn a machine var machine = teacher.Learn(inputs, outputs); // Create the multi-class learning algorithm for the machine var calibration = new MultilabelSupportVectorLearning <IKernel>(machine) { // Configure the learning algorithm to use SMO to train the // underlying SVMs in each of the binary class subproblems. Learner = (p) => new ProbabilisticOutputCalibration <IKernel>(p.Model) }; // Configure parallel execution options calibration.ParallelOptions.MaxDegreeOfParallelism = 1; // Learn a machine calibration.Learn(inputs, outputs); // Obtain class predictions for each sample bool[][] predicted = machine.Decide(inputs); // Get class scores for each sample double[][] scores = machine.Scores(inputs); // Get log-likelihoods (should be same as scores) double[][] logl = machine.LogLikelihoods(inputs); // Get probability for each sample double[][] prob = machine.Probabilities(inputs); // Compute classification error using mean accuracy (mAcc) double error = new HammingLoss(outputs).Loss(predicted); double loss = new CategoryCrossEntropyLoss(outputs).Loss(prob); string a = scores.ToCSharp(); string b = logl.ToCSharp(); string c = prob.ToCSharp(); double[][] expectedScores = { new double[] { 1.85316017783605, -2.59688389729331, -2.32170102153988 }, new double[] { 1.84933597524124, -1.99399145231446, -2.2920299547693 }, new double[] { 1.44477953581274, -1.98592298465108, -2.27356092239125 }, new double[] { 1.85316017783605, -2.59688389729331, -2.32170102153988 }, new double[] { 1.84933597524124, -1.99399145231446, -2.2920299547693 }, new double[] { -2.40815576360914, 0.328362962196791, -0.932721757919691 }, new double[] { -2.13111157264226, 1.809192096031, -2.2920299547693 }, new double[] { -2.13111157264226, 1.809192096031, -2.2920299547693 }, new double[] { -2.14888646926108, -1.99399145231447, 1.33101148524982 }, new double[] { -2.12915064678299, -1.98592298465108, 1.3242171079396 }, new double[] { -1.47197826667149, -1.96368715704762, 0.843414180834243 }, new double[] { -2.14221021749314, -2.83117892529093, 2.61354519154994 } }; double[][] expectedLogL = { new double[] { 1.85316017783605, -2.59688389729331, -2.32170102153988 }, new double[] { 1.84933597524124, -1.99399145231446, -2.2920299547693 }, new double[] { 1.44477953581274, -1.98592298465108, -2.27356092239125 }, new double[] { 1.85316017783605, -2.59688389729331, -2.32170102153988 }, new double[] { 1.84933597524124, -1.99399145231446, -2.2920299547693 }, new double[] { -2.40815576360914, 0.328362962196791, -0.932721757919691 }, new double[] { -2.13111157264226, 1.809192096031, -2.2920299547693 }, new double[] { -2.13111157264226, 1.809192096031, -2.2920299547693 }, new double[] { -2.14888646926108, -1.99399145231447, 1.33101148524982 }, new double[] { -2.12915064678299, -1.98592298465108, 1.3242171079396 }, new double[] { -1.47197826667149, -1.96368715704762, 0.843414180834243 }, new double[] { -2.14221021749314, -2.83117892529093, 2.61354519154994 } }; double[][] expectedProbs = { new double[] { 6.37994947365835, 0.0745053832890827, 0.0981065622139132 }, new double[] { 6.35559784678136, 0.136150899620619, 0.101061104020747 }, new double[] { 4.24091706941419, 0.137253872418087, 0.102944947658882 }, new double[] { 6.37994947365835, 0.0745053832890827, 0.0981065622139132 }, new double[] { 6.35559784678136, 0.136150899620619, 0.101061104020747 }, new double[] { 0.0899810880411361, 1.38869292386051, 0.393481290780948 }, new double[] { 0.118705270957796, 6.10551277113228, 0.101061104020747 }, new double[] { 0.118705270957796, 6.10551277113228, 0.101061104020747 }, new double[] { 0.116613938707895, 0.136150899620619, 3.78486979203385 }, new double[] { 0.118938271567046, 0.137253872418087, 3.75924112261421 }, new double[] { 0.229471080877097, 0.140340010119971, 2.3242889884131 }, new double[] { 0.11739508739354, 0.0589433229176013, 13.6473476521179 } }; int[] actual = predicted.ArgMax(dimension: 1); Assert.IsTrue(actual.IsEqual(outputs)); // Must be exactly the same as test above Assert.AreEqual(0, error); Assert.AreEqual(0.5, ((Gaussian)machine[0].Kernel).Gamma); Assert.AreEqual(0.5, ((Gaussian)machine[1].Kernel).Gamma); Assert.AreEqual(0.5, ((Gaussian)machine[2].Kernel).Gamma); Assert.AreEqual(-18.908706961799737, loss); Assert.IsTrue(expectedScores.IsEqual(scores, 1e-10)); Assert.IsTrue(expectedLogL.IsEqual(logl, 1e-10)); Assert.IsTrue(expectedProbs.IsEqual(prob, 1e-10)); }
public void multilabel_calibration_generic_kernel() { // Let's say we have the following data to be classified // into three possible classes. Those are the samples: // double[][] inputs = { // input output new double[] { 0, 1, 1, 0 }, // 0 new double[] { 0, 1, 0, 0 }, // 0 new double[] { 0, 0, 1, 0 }, // 0 new double[] { 0, 1, 1, 0 }, // 0 new double[] { 0, 1, 0, 0 }, // 0 new double[] { 1, 0, 0, 1 }, // 1 new double[] { 0, 0, 0, 1 }, // 1 new double[] { 0, 0, 0, 1 }, // 1 new double[] { 1, 0, 1, 1 }, // 2 new double[] { 1, 1, 0, 1 }, // 2 new double[] { 0, 1, 1, 1 }, // 2 new double[] { 1, 1, 1, 1 }, // 2 }; int[] outputs = // those are the class labels { 0, 0, 0, 0, 0, 1, 1, 1, 2, 2, 2, 2, }; // Create the multi-class learning algorithm for the machine var teacher = new MultilabelSupportVectorLearning<IKernel>() { // Configure the learning algorithm to use SMO to train the // underlying SVMs in each of the binary class subproblems. Learner = (param) => new SequentialMinimalOptimization<IKernel>() { UseKernelEstimation = false, Kernel = Gaussian.FromGamma(0.5) } }; // Learn a machine var machine = teacher.Learn(inputs, outputs); // Create the multi-class learning algorithm for the machine var calibration = new MultilabelSupportVectorLearning<IKernel>(machine) { // Configure the learning algorithm to use SMO to train the // underlying SVMs in each of the binary class subproblems. Learner = (p) => new ProbabilisticOutputCalibration<IKernel>(p.Model) }; // Configure parallel execution options calibration.ParallelOptions.MaxDegreeOfParallelism = 1; // Learn a machine calibration.Learn(inputs, outputs); // Obtain class predictions for each sample bool[][] predicted = machine.Decide(inputs); // Get class scores for each sample double[][] scores = machine.Scores(inputs); // Get log-likelihoods (should be same as scores) double[][] logl = machine.LogLikelihoods(inputs); // Get probability for each sample double[][] prob = machine.Probabilities(inputs); // Compute classification error using mean accuracy (mAcc) double error = new HammingLoss(outputs).Loss(predicted); double loss = new CategoryCrossEntropyLoss(outputs).Loss(prob); string a = scores.ToCSharp(); string b = logl.ToCSharp(); string c = prob.ToCSharp(); double[][] expectedScores = { new double[] { 1.85316017783605, -2.59688389729331, -2.32170102153988 }, new double[] { 1.84933597524124, -1.99399145231446, -2.2920299547693 }, new double[] { 1.44477953581274, -1.98592298465108, -2.27356092239125 }, new double[] { 1.85316017783605, -2.59688389729331, -2.32170102153988 }, new double[] { 1.84933597524124, -1.99399145231446, -2.2920299547693 }, new double[] { -2.40815576360914, 0.328362962196791, -0.932721757919691 }, new double[] { -2.13111157264226, 1.809192096031, -2.2920299547693 }, new double[] { -2.13111157264226, 1.809192096031, -2.2920299547693 }, new double[] { -2.14888646926108, -1.99399145231447, 1.33101148524982 }, new double[] { -2.12915064678299, -1.98592298465108, 1.3242171079396 }, new double[] { -1.47197826667149, -1.96368715704762, 0.843414180834243 }, new double[] { -2.14221021749314, -2.83117892529093, 2.61354519154994 } }; double[][] expectedLogL = { new double[] { 1.85316017783605, -2.59688389729331, -2.32170102153988 }, new double[] { 1.84933597524124, -1.99399145231446, -2.2920299547693 }, new double[] { 1.44477953581274, -1.98592298465108, -2.27356092239125 }, new double[] { 1.85316017783605, -2.59688389729331, -2.32170102153988 }, new double[] { 1.84933597524124, -1.99399145231446, -2.2920299547693 }, new double[] { -2.40815576360914, 0.328362962196791, -0.932721757919691 }, new double[] { -2.13111157264226, 1.809192096031, -2.2920299547693 }, new double[] { -2.13111157264226, 1.809192096031, -2.2920299547693 }, new double[] { -2.14888646926108, -1.99399145231447, 1.33101148524982 }, new double[] { -2.12915064678299, -1.98592298465108, 1.3242171079396 }, new double[] { -1.47197826667149, -1.96368715704762, 0.843414180834243 }, new double[] { -2.14221021749314, -2.83117892529093, 2.61354519154994 } }; double[][] expectedProbs = { new double[] { 6.37994947365835, 0.0745053832890827, 0.0981065622139132 }, new double[] { 6.35559784678136, 0.136150899620619, 0.101061104020747 }, new double[] { 4.24091706941419, 0.137253872418087, 0.102944947658882 }, new double[] { 6.37994947365835, 0.0745053832890827, 0.0981065622139132 }, new double[] { 6.35559784678136, 0.136150899620619, 0.101061104020747 }, new double[] { 0.0899810880411361, 1.38869292386051, 0.393481290780948 }, new double[] { 0.118705270957796, 6.10551277113228, 0.101061104020747 }, new double[] { 0.118705270957796, 6.10551277113228, 0.101061104020747 }, new double[] { 0.116613938707895, 0.136150899620619, 3.78486979203385 }, new double[] { 0.118938271567046, 0.137253872418087, 3.75924112261421 }, new double[] { 0.229471080877097, 0.140340010119971, 2.3242889884131 }, new double[] { 0.11739508739354, 0.0589433229176013, 13.6473476521179 } }; int[] actual = predicted.ArgMax(dimension: 1); Assert.IsTrue(actual.IsEqual(outputs)); // Must be exactly the same as test above Assert.AreEqual(0, error); Assert.AreEqual(0.5, ((Gaussian)machine[0].Kernel).Gamma); Assert.AreEqual(0.5, ((Gaussian)machine[1].Kernel).Gamma); Assert.AreEqual(0.5, ((Gaussian)machine[2].Kernel).Gamma); Assert.AreEqual(-18.908706961799737, loss); Assert.IsTrue(expectedScores.IsEqual(scores, 1e-10)); Assert.IsTrue(expectedLogL.IsEqual(logl, 1e-10)); Assert.IsTrue(expectedProbs.IsEqual(prob, 1e-10)); }