DistanceGetDistanceT Method |
Namespace: Accord.Math
This method is intended to be used in scenarios where you have been using any of the static methods in the Distance class, but now you would like to obtain a reference to an object that implements the same distance you have been using before, but in a object-oriented, polymorphic manner. Please see the example below for more details.
Note: This method relies on reflection and might not work on all scenarios, environments, and/or platforms.
// Let's say you have been using the static Distance.Euclidean() method in // your code, and now you would like to obtain a reference to a class that // implements the IDistance interface for this same distance, such that you // could pass it to some other method in the framework: double[] x = new double[] { 2, 4, 1 }; double[] y = new double[] { 0, 0, 0 }; double a = Distance.Euclidean(x, y); // should be 4.58257569495584 // Use the GetDistance method to obtain an IDistance that implements it: IDistance<double[]> obj = Distance.GetDistance<double[]>(Distance.Euclidean); // We can continue computing the same distances as before using: double b = obj.Distance(x, y); // should be 4.58257569495584