Click or drag to resize
Accord.NET (logo)

LogLikelihoodLoss Class

Negative log-likelihood loss.
Inheritance Hierarchy
SystemObject
  Accord.Math.Optimization.LossesLogLikelihoodLoss

Namespace:  Accord.Math.Optimization.Losses
Assembly:  Accord.Math (in Accord.Math.dll) Version: 3.8.0
Syntax
[SerializableAttribute]
public class LogLikelihoodLoss : ILoss<double[][]>, 
	ILoss<double[][], double>, ILoss<double[]>, 
	ILoss<double[], double>
Request Example View Source

The LogLikelihoodLoss type exposes the following members.

Constructors
  NameDescription
Public methodLogLikelihoodLoss
Initializes a new instance of the LogLikelihoodLoss class.
Top
Methods
  NameDescription
Public methodEquals
Determines whether the specified object is equal to the current object.
(Inherited from Object.)
Protected methodFinalize
Allows an object to try to free resources and perform other cleanup operations before it is reclaimed by garbage collection.
(Inherited from Object.)
Public methodGetHashCode
Serves as the default hash function.
(Inherited from Object.)
Public methodGetType
Gets the Type of the current instance.
(Inherited from Object.)
Public methodLoss(Double)
Computes the loss between the expected values (ground truth) and the given actual values that have been predicted.
Public methodLoss(Double)
Computes the loss between the expected values (ground truth) and the given actual values that have been predicted.
Protected methodMemberwiseClone
Creates a shallow copy of the current Object.
(Inherited from Object.)
Public methodToString
Returns a string that represents the current object.
(Inherited from Object.)
Top
Extension Methods
  NameDescription
Public Extension MethodHasMethod
Checks whether an object implements a method with the given name.
(Defined by ExtensionMethods.)
Public Extension MethodIsEqual
Compares two objects for equality, performing an elementwise comparison if the elements are vectors or matrices.
(Defined by Matrix.)
Public Extension MethodTo(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.)
Public Extension MethodToTOverloaded.
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.)
Top
Remarks

The log-likelihood loss can be used to measure the performance of unsupervised model fitting algorithms. It simply computes the sum of all log-likelihood values produced by the model.

If you would like to measure the performance of a supervised classification model based on their probability predictions, please refer to the BinaryCrossEntropyLoss and CategoryCrossEntropyLoss for binary and multi-class decision problems, respectively.

Examples

The following example shows how to learn an one-class SVM and measure its performance using the log-likelihood loss class.

// Ensure that results are reproducible
Accord.Math.Random.Generator.Seed = 0;

// Generate some data to be learned
double[][] inputs =
{
    new double[] { +1.0312479734420776  },
    new double[] { +0.99444115161895752 },
    new double[] { +0.21835240721702576 },
    new double[] { +0.47197291254997253 },
    new double[] { +0.68701112270355225 },
    new double[] { -0.58556461334228516 },
    new double[] { -0.64154046773910522 },
    new double[] { -0.66485315561294556 },
    new double[] { +0.37940266728401184 },
    new double[] { -0.61046308279037476 }
};


// Create a new One-class SVM learning algorithm
var teacher = new OneclassSupportVectorLearning<Linear>()
{
    Kernel = new Linear(), // or, for example, 'new Gaussian(0.9)'
    Nu = 0.1
};

// Learn a support vector machine
var svm = teacher.Learn(inputs);

// Test the machine
double[] prediction = svm.Score(inputs);

// Compute the log-likelihood of the answer
double ll = new LogLikelihoodLoss().Loss(prediction);
See Also