using System;

namespace LabelerCore.Model.Math
{

    public static class Metrics
    {
        public enum Metric { Manhattan, SquaredEuclidean }

        public delegate double Distance(double[] x, double[] y);

        public static Distance SelectDistance(Metric metric)
        {
            if (metric == Metric.SquaredEuclidean)
                return SquaredEuclideanDistance;
            else if (metric == Metric.Manhattan)
                return ManhattanDistance;
            else
                return ManhattanDistance;
        }

        static public double ManhattanDistance(double[] x, double[] y)
        {
            if (x.Length != y.Length)
            {
                throw new ArgumentException("invalid x/y length");
            }
            double result = 0.0;
            for (int i = 0; i < x.Length; i++)
            {
                result += System.Math.Abs(x[i] - y[i]);
            }
            return result;
        }


        static public double SquaredEuclideanDistance(double[] x, double[] y)
        {
            if (x.Length != y.Length)
            {
                throw new ArgumentException("invalid x/y length");
            }
            double result = 0.0;
            for (int i = 0; i < x.Length; i++)
            {
                result += System.Math.Pow(x[i] - y[i], 2);
            }
            return result;
        }

    }





}
