Skip to content

Commit

Permalink
Preparations for release 2.15.
Browse files Browse the repository at this point in the history
  • Loading branch information
cesarsouza committed May 1, 2015
1 parent 3ff2213 commit 02d95ad
Show file tree
Hide file tree
Showing 9 changed files with 2,017 additions and 1,737 deletions.
2 changes: 1 addition & 1 deletion Sources/Accord.Core/Properties/VersionInfo.cs
Original file line number Diff line number Diff line change
Expand Up @@ -14,4 +14,4 @@

[assembly: AssemblyVersion("2.15.0")]
[assembly: AssemblyInformationalVersion("2.15.0")]
[assembly: AssemblyFileVersion("2.15.0.5229")]
[assembly: AssemblyFileVersion("2.15.0.5233")]
Original file line number Diff line number Diff line change
Expand Up @@ -735,14 +735,14 @@
<ImageId>scatterplot-box</ImageId>
<AlternateText>scatterplot-box</AlternateText>
</Content>
<Image Include="images\grid-fixed-steps.png">
<Content Include="images\grid-fixed-steps.png">
<ImageId>grid-fixed-steps</ImageId>
<AlternateText>grid-fixed-steps</AlternateText>
</Image>
<Image Include="images\grid-step-size.png">
</Content>
<Content Include="images\grid-step-size.png">
<ImageId>grid-step-size</ImageId>
<AlternateText>grid-step-size</AlternateText>
</Image>
</Content>
<Image Include="resources\Accord.NET.png">
<CopyToMedia>True</CopyToMedia>
<AlternateText>Accord.NET</AlternateText>
Expand Down
1,286 changes: 668 additions & 618 deletions Sources/Accord.MachineLearning/Bayes/NaiveBayes.cs

Large diffs are not rendered by default.

1,243 changes: 650 additions & 593 deletions Sources/Accord.MachineLearning/Bayes/NaiveBayes`1.cs

Large diffs are not rendered by default.

Original file line number Diff line number Diff line change
Expand Up @@ -147,7 +147,54 @@ public SubproblemEventArgs(int class1, int class2)
/// new SequentialMinimalOptimization(svm, classInputs, classOutputs);
///
/// // Run the learning algorithm
/// double error = teacher.Run();
/// double error = teacher.Run(); // output should be 0
///
/// // Compute the decision output for one of the input vectors
/// int decision = machine.Compute(new double[] { 3 }); // result should be 3
/// </code>
///
/// <para>
/// The next example is a simple 3 classes classification problem.
/// It shows how to use a different kernel function, such as the
/// polynomial kernel of degree 2.</para>
///
/// <code>
/// // Sample input data
/// double[][] inputs =
/// {
/// new double[] { -1, 3, 2 },
/// new double[] { -1, 3, 2 },
/// new double[] { -1, 3, 2 },
/// new double[] { 10, 82, 4 },
/// new double[] { 10, 15, 4 },
/// new double[] { 0, 0, 1 },
/// new double[] { 0, 0, 2 },
/// };
///
/// // Output for each of the inputs
/// int[] outputs = { 0, 3, 1, 2 };
///
///
/// // Create a new polynomial kernel
/// IKernel kernel = new Polynomial(2);
///
/// // Create a new Multi-class Support Vector Machine with one input,
/// // using the linear kernel and for four disjoint classes.
/// var machine = new MulticlassSupportVectorMachine(inputs: 3, kernel: kernel, classes: 4);
///
/// // Create the Multi-class learning algorithm for the machine
/// var teacher = new MulticlassSupportVectorLearning(machine, inputs, outputs);
///
/// // Configure the learning algorithm to use SMO to train the
/// // underlying SVMs in each of the binary class subproblems.
/// teacher.Algorithm = (svm, classInputs, classOutputs, i, j) =>
/// new SequentialMinimalOptimization(svm, classInputs, classOutputs);
///
/// // Run the learning algorithm
/// double error = teacher.Run(); // output should be 0
///
/// // Compute the decision output for one of the input vectors
/// int decision = machine.Compute( new double[] { -1, 3, 2 });
/// </code>
/// </example>
///
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,16 +21,16 @@
//

namespace Accord.MachineLearning.VectorMachines
{
using System;
using System.Collections.Generic;
using System.IO;
using System.Runtime.Serialization;
using System.Runtime.Serialization.Formatters.Binary;
using System.Threading;
{
using Accord.Math;
using Accord.Statistics.Kernels;
using System;
using System.Collections.Generic;
using System.IO;
using System.Runtime.Serialization;
using System.Runtime.Serialization.Formatters.Binary;
using System.Threading;
using System.Threading.Tasks;
using Accord.Math;
using Accord.Statistics.Kernels;

/// <summary>
/// Decision strategies for <see cref="MulticlassSupportVectorMachine">
Expand Down Expand Up @@ -116,8 +116,55 @@ public enum MulticlassComputeMethod
/// teacher.Algorithm = (svm, classInputs, classOutputs, i, j) =>
/// new SequentialMinimalOptimization(svm, classInputs, classOutputs);
///
/// // Run the learning algorithm
/// double error = teacher.Run();
/// // Run the learning algorithm
/// double error = teacher.Run(); // output should be 0
///
/// // Compute the decision output for one of the input vectors
/// int decision = machine.Compute(new double[] { 3 }); // result should be 3
/// </code>
///
/// <para>
/// The next example is a simple 3 classes classification problem.
/// It shows how to use a different kernel function, such as the
/// polynomial kernel of degree 2.</para>
///
/// <code>
/// // Sample input data
/// double[][] inputs =
/// {
/// new double[] { -1, 3, 2 },
/// new double[] { -1, 3, 2 },
/// new double[] { -1, 3, 2 },
/// new double[] { 10, 82, 4 },
/// new double[] { 10, 15, 4 },
/// new double[] { 0, 0, 1 },
/// new double[] { 0, 0, 2 },
/// };
///
/// // Output for each of the inputs
/// int[] outputs = { 0, 3, 1, 2 };
///
///
/// // Create a new polynomial kernel
/// IKernel kernel = new Polynomial(2);
///
/// // Create a new Multi-class Support Vector Machine with one input,
/// // using the linear kernel and for four disjoint classes.
/// var machine = new MulticlassSupportVectorMachine(inputs: 3, kernel: kernel, classes: 4);
///
/// // Create the Multi-class learning algorithm for the machine
/// var teacher = new MulticlassSupportVectorLearning(machine, inputs, outputs);
///
/// // Configure the learning algorithm to use SMO to train the
/// // underlying SVMs in each of the binary class subproblems.
/// teacher.Algorithm = (svm, classInputs, classOutputs, i, j) =>
/// new SequentialMinimalOptimization(svm, classInputs, classOutputs);
///
/// // Run the learning algorithm
/// double error = teacher.Run(); // output should be 0
///
/// // Compute the decision output for one of the input vectors
/// int decision = machine.Compute( new double[] { -1, 3, 2 });
/// </code>
/// </example>
///
Expand Down
86 changes: 62 additions & 24 deletions Unit Tests/Accord.Tests.MachineLearning/Bayes/NaiveBayesTest.cs
Original file line number Diff line number Diff line change
Expand Up @@ -21,35 +21,20 @@
//

namespace Accord.Tests.MachineLearning
{
using System.Data;
{
using Accord;
using Accord.MachineLearning;
using Accord.MachineLearning.Bayes;
using Accord.Math;
using Accord.Statistics.Filters;
using Microsoft.VisualStudio.TestTools.UnitTesting;
using System.Data;
using System.Text;
using Accord;
using Accord.MachineLearning;
using Accord.MachineLearning.Bayes;
using Accord.Math;
using Accord.Statistics.Filters;
using Microsoft.VisualStudio.TestTools.UnitTesting;

[TestClass()]
public class NaiveBayesTest
{

private TestContext testContextInstance;

public TestContext TestContext
{
get
{
return testContextInstance;
}
set
{
testContextInstance = value;
}
}



[TestMethod()]
public void NaiveBayesConstructorTest()
Expand Down Expand Up @@ -264,7 +249,60 @@ public static string[] Tokenize(string text)
sb.Replace(invalid[i], ' ');

return sb.ToString().Split(new[] { ' ' }, System.StringSplitOptions.RemoveEmptyEntries);
}
}

[TestMethod()]
public void ComputeTest3()
{
// Let's say we have the following data to be classified
// into three possible classes. Those are the samples:
//
int[][] inputs =
{
// input output
new int[] { 0, 1, 1, 0 }, // 0
new int[] { 0, 1, 0, 0 }, // 0
new int[] { 0, 0, 1, 0 }, // 0
new int[] { 0, 1, 1, 0 }, // 0
new int[] { 0, 1, 0, 0 }, // 0
new int[] { 1, 0, 0, 0 }, // 1
new int[] { 1, 0, 0, 0 }, // 1
new int[] { 1, 0, 0, 1 }, // 1
new int[] { 0, 0, 0, 1 }, // 1
new int[] { 0, 0, 0, 1 }, // 1
new int[] { 1, 1, 1, 1 }, // 2
new int[] { 1, 0, 1, 1 }, // 2
new int[] { 1, 1, 0, 1 }, // 2
new int[] { 0, 1, 1, 1 }, // 2
new int[] { 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 a discrete naive Bayes model for 3 classes and 4 binary inputs
var bayes = new NaiveBayes(classes: 3, symbols: new int[] { 2, 2, 2, 2 });

// Teach the model. The error should be zero:
double error = bayes.Estimate(inputs, outputs);

// Now, let's test the model output for the first input sample:
int answer = bayes.Compute(new int[] { 0, 1, 1, 0 }); // should be 1


Assert.AreEqual(0, error);
for (int i = 0; i < inputs.Length; i++)
{
error = bayes.Compute(inputs[i]);
double expected = outputs[i];
Assert.AreEqual(expected, error);
}
}


[TestMethod()]
public void DistributionsTest()
Expand Down
Loading

0 comments on commit 02d95ad

Please sign in to comment.