Class Minkowski
The Minkowski distance is a metric in a normed vector space which can be
considered as a generalization of both the
Euclidean
and the Manhattan.
Inheritance
System.Object
Minkowski
Implements
IMetric<System.Double[]>
IDistance<System.Double[]>
IMetric<System.Int32[]>
IDistance<System.Int32[]>
ICloneable
Namespace: Mars.Numerics.Distances
Assembly: Mars.Numerics.dll
Syntax
public class Minkowski : object, IMetric<double[]>, IDistance<double[]>, IDistance<double[], double[]>, IMetric<int[]>, IDistance<int[]>, IDistance<int[], int[]>, ICloneable
Remarks
The framework distinguishes between metrics and distances by using different types for them. This makes it possible to let the compiler figure out logic problems such as the specification of a non-metric for a method that requires a proper metric (i.e. that respects the triangle inequality).
The objective of this technique is to make it harder to make some mistakes. However, it is possible to bypass this mechanism by using the named constructors such as Nonmetric(Double) to create distances implementing the IMetric<T> interface that are not really metrics. Use at your own risk.
Constructors
Minkowski(Double)
Initializes a new instance of the Minkowski class.
Declaration
public Minkowski(double p)
Parameters
Type | Name | Description |
---|---|---|
System.Double | p | The Minkowski order p . |
Fields
Euclidean
Declaration
public static readonly Minkowski Euclidean
Field Value
Type | Description |
---|---|
Minkowski |
Manhattan
Declaration
public static readonly Minkowski Manhattan
Field Value
Type | Description |
---|---|
Minkowski |
Properties
Order
Gets the order
p
of this Minkowski distance.
Declaration
public double Order { get; }
Property Value
Type | Description |
---|---|
System.Double |
Methods
Clone()
Creates a new object that is a copy of the current instance.
Declaration
public object Clone()
Returns
Type | Description |
---|---|
System.Object | A new object that is a copy of this instance. |
Distance(Double[], Double[])
Computes the distance
d(x,y)
between points
x
and y
.
Declaration
public double Distance(double[] x, double[] y)
Parameters
Type | Name | Description |
---|---|---|
System.Double[] | x | The first point x . |
System.Double[] | y | The second point y . |
Returns
Type | Description |
---|---|
System.Double |
A double-precision value representing the distance d(x,y)
between x and y according
to the distance function implemented by this class.
|
Distance(Int32[], Int32[])
Computes the distance
d(x,y)
between points
x
and y
.
Declaration
public double Distance(int[] x, int[] y)
Parameters
Type | Name | Description |
---|---|---|
System.Int32[] | x | The first point x . |
System.Int32[] | y | The second point y . |
Returns
Type | Description |
---|---|
System.Double |
A double-precision value representing the distance d(x,y)
between x and y according
to the distance function implemented by this class.
|
Nonmetric(Double)
Creates a non-metric Minkowski distance, bypassing
argument checking. Use at your own risk.
Declaration
public static Minkowski Nonmetric(double p)
Parameters
Type | Name | Description |
---|---|---|
System.Double | p | The Minkowski order p . |
Returns
Type | Description |
---|---|
Minkowski | A Minkowski object implementing a Minkowski distance that is not necessarily a metric. Use at your own risk. |
Implements
ICloneable