private static void testWeights(double[][] inputs, int[] labels, IKernel kernel)
{
{
var machine = new KernelSupportVectorMachine(kernel, inputs[0].Length);
var smo = new SequentialMinimalOptimization(machine, inputs, labels);
smo.PositiveWeight = 100;
smo.NegativeWeight = 1;
double error = smo.Run();
int[] actual = new int[labels.Length];
for (int i = 0; i < actual.Length; i++)
actual[i] = Math.Sign(machine.Compute(inputs[i]));
ConfusionMatrix matrix = new ConfusionMatrix(actual, labels);
Assert.AreEqual(50, matrix.TruePositives); // has more importance
Assert.AreEqual(0, matrix.FalseNegatives); // has more importance
}
{
var machine = new KernelSupportVectorMachine(kernel, inputs[0].Length);
var smo = new SequentialMinimalOptimization(machine, inputs, labels);
smo.PositiveWeight = 1;
smo.NegativeWeight = 100;
double error = smo.Run();
int[] actual = new int[labels.Length];
for (int i = 0; i < actual.Length; i++)
actual[i] = Math.Sign(machine.Compute(inputs[i]));
var matrix = new ConfusionMatrix(actual, labels);
Assert.AreEqual(50, matrix.TrueNegatives); // has more importance
Assert.AreEqual(0, matrix.FalsePositives); // has more importance
}
}