SparseLinear Class |
Note: This API is now obsolete.
Namespace: Accord.Statistics.Kernels.Sparse
[SerializableAttribute] [ObsoleteAttribute("Please use the Linear kernel with Sparse<double> instead.")] public sealed class SparseLinear : KernelBase, IKernel, IKernel<double[]>
The SparseLinear type exposes the following members.
Name | Description | |
---|---|---|
SparseLinear |
Constructs a new Linear Kernel.
| |
SparseLinear(Double) |
Constructs a new Linear kernel.
|
Name | Description | |
---|---|---|
Clone |
Creates a new object that is a copy of the current instance.
| |
Distance |
Computes the squared distance in feature space
between two points given in input space.
(Overrides KernelBaseTInputDistance(TInput, TInput).) | |
Equals | Determines whether the specified object is equal to the current object. (Inherited from Object.) | |
Function |
Sparse Linear kernel function.
(Overrides KernelBaseTInputFunction(TInput, TInput).) | |
GetHashCode | Serves as the default hash function. (Inherited from Object.) | |
GetType | Gets the Type of the current instance. (Inherited from Object.) | |
Product |
Computes the product of two vectors given in sparse representation.
| |
SquaredEuclidean |
Computes the squared Euclidean distance of two vectors given in sparse representation.
| |
ToString | Returns a string that represents the current object. (Inherited from Object.) |
Name | Description | |
---|---|---|
Distance |
Computes the kernel distance for a kernel function even if it doesn't
implement the IDistance interface. Can be used to check
the proper implementation of the distance function.
(Defined by Tools.) | |
HasMethod |
Checks whether an object implements a method with the given name.
(Defined by ExtensionMethods.) | |
IsEqual |
Compares two objects for equality, performing an elementwise
comparison if the elements are vectors or matrices.
(Defined by Matrix.) | |
To(Type) | Overloaded.
Converts an object into another type, irrespective of whether
the conversion can be done at compile time or not. This can be
used to convert generic types to numeric types during runtime.
(Defined by ExtensionMethods.) | |
ToT | Overloaded.
Converts an object into another type, irrespective of whether
the conversion can be done at compile time or not. This can be
used to convert generic types to numeric types during runtime.
(Defined by ExtensionMethods.) |
The following example shows how to teach a kernel support vector machine using the linear sparse kernel to perform the AND classification task using sparse vectors.
// Example AND problem double[][] inputs = { new double[] { }, // 0 and 0: 0 (label -1) new double[] { 2,1 }, // 0 and 1: 0 (label -1) new double[] { 1,1 }, // 1 and 0: 0 (label -1) new double[] { 1,1, 2,1 } // 1 and 1: 1 (label +1) }; // Dichotomy SVM outputs should be given as [-1;+1] int[] labels = { // 0, 0, 0, 1 -1, -1, -1, 1 }; // Create a Support Vector Machine for the given inputs // (sparse machines should use 0 as the number of inputs) var machine = new KernelSupportVectorMachine(new SparseLinear(), inputs: 0); // Instantiate a new learning algorithm for SVMs var smo = new SequentialMinimalOptimization(machine, inputs, labels); // Set up the learning algorithm smo.Complexity = 100000.0; // Run double error = smo.Run(); // should be zero double[] predicted = inputs.Apply(machine.Compute).Sign(); // Outputs should be -1, -1, -1, +1