Class AbstractModel

Namespace
NOpenNLP.Tools.Ml.Model
Assembly
NOpenNLP.Tools.dll
public abstract class AbstractModel : IMaxentModel
Inheritance
AbstractModel
Implements
Derived
Inherited Members

Constructors

AbstractModel(Context[], string[], IDictionary<string, Context>, string[])

protected AbstractModel(Context[] @params, string[] predLabels, IDictionary<string, Context> pmap, string[] outcomeNames)

Parameters

params Context[]
predLabels string[]
pmap IDictionary<string, Context>
outcomeNames string[]

AbstractModel(Context[], string[], string[])

protected AbstractModel(Context[] @params, string[] predLabels, string[] outcomeNames)

Parameters

params Context[]
predLabels string[]
outcomeNames string[]

Fields

evalParams

Parameters for the model.

protected EvalParameters evalParams

Field Value

EvalParameters

modelType

The type of the model.

protected AbstractModel.ModelType modelType

Field Value

AbstractModel.ModelType

outcomeNames

The names of the outcomes.

protected string[] outcomeNames

Field Value

string[]

pmap

Mapping between predicates/contexts and an integer representing them.

protected IDictionary<string, Context> pmap

Field Value

IDictionary<string, Context>

Remarks

Backed by J2N.Collections.Generic.OrderedDictionary<TKey, TValue> so iteration order is insertion order, matching the LinkedHashMap upstream adopted in OPENNLP-1321. Declared as IDictionary<TKey, TValue> to keep the J2N type out of the exposed signature.

prior

Prior distribution for this model.

protected IPrior? prior

Field Value

IPrior

Properties

NumOutcomes

Returns the number of outcomes for this model.

public virtual int NumOutcomes { get; }

Property Value

int

The number of outcomes.

Methods

Equals(object?)

Determines whether the specified object is equal to the current object.

public override bool Equals(object? obj)

Parameters

obj object

The object to compare with the current object.

Returns

bool

true if the specified object is equal to the current object; otherwise, false.

Eval(string[])

Evaluates a context.

public abstract double[] Eval(string[] context)

Parameters

context string[]

A list of String names of the contextual predicates which are to be evaluated together.

Returns

double[]

an array of the probabilities for each of the different outcomes, all of which sum to 1.

Eval(string[], double[])

Evaluates a context.

public abstract double[] Eval(string[] context, double[] probs)

Parameters

context string[]

A list of String names of the contextual predicates which are to be evaluated together.

probs double[]

An array which is populated with the probabilities for each of the different outcomes, all of which sum to 1.

Returns

double[]

an array of the probabilities for each of the different outcomes, all of which sum to 1.

Eval(string[], float[])

Evaluates a contexts with the specified context values.

public abstract double[] Eval(string[] context, float[] values)

Parameters

context string[]

A list of String names of the contextual predicates which are to be evaluated together.

values float[]

The values associated with each context.

Returns

double[]

an array of the probabilities for each of the different outcomes, all of which sum to 1.

GetAllOutcomes(double[])

Return a string matching all the outcome names with all the probabilities produced by the Eval(string[]) method.

public string GetAllOutcomes(double[] ocs)

Parameters

ocs double[]

A double array as returned by the Eval(string[]) method.

Returns

string

String containing outcome names paired with the normalized probability (contained in the ocs) for each one.

GetBestOutcome(double[])

Return the name of the outcome corresponding to the highest likelihood in the parameter ocs.

public string GetBestOutcome(double[] ocs)

Parameters

ocs double[]

A double array as returned by the Eval(string[]) method.

Returns

string

The name of the most likely outcome.

GetDataStructures()

Provides the fundamental data structures which encode the maxent model information. This method will usually only be needed by GISModelWriters. The following values are held in the Object array which is returned by this method:

  • index 0: Context[] containing the model parameters
  • index 1: a dictionary containing the mapping of model predicates to unique integers
  • index 2: string[] containing the names of the outcomes, stored in the index of the array which represents their unique ids in the model.
public object[] GetDataStructures()

Returns

object[]

An Object[] with the values as described above.

GetHashCode()

Serves as the default hash function.

public override int GetHashCode()

Returns

int

A hash code for the current object.

GetIndex(string)

Gets the index associated with the string name of the given outcome.

public virtual int GetIndex(string outcome)

Parameters

outcome string

the string name of the outcome for which the index is desired

Returns

int

the index if the given outcome label exists for this model, -1 if it does not.

GetModelType()

public virtual AbstractModel.ModelType GetModelType()

Returns

AbstractModel.ModelType

GetOutcome(int)

Return the name of an outcome corresponding to an int id.

public string GetOutcome(int i)

Parameters

i int

An outcome id.

Returns

string

The name of the outcome associated with that id.