Esempio n. 1
0
        /**Compute the median of the pairwise distance. The distance is
         * |mu_p - mu_q|^2 where mu_p is the mean embedding.
         */

        public static double MedianPairwise <D>(
            List <D> dists, double[] embedSquaredWidths)
            where D : IKEPDist
        {
            KEGaussian <D> ke = new KEGaussian <D>(embedSquaredWidths);
            int            n  = dists.Count;

            double[]      selfKers  = dists.Select(di => ke.Eval(di, di)).ToArray();
            List <double> pairDists = new List <double>();

            for (int i = 0; i < n; i++)
            {
                D      p  = dists[i];
                double pp = selfKers[i];
                for (int j = i; j < n; j++)             // include j=i just like in Matlab
                {
                    D      q     = dists[j];
                    double qq    = selfKers[j];
                    double dist2 = pp - 2 * ke.Eval(p, q) + qq;
                    Debug.Assert(dist2 >= 0);
                    pairDists.Add(dist2);
                }
            }
            double med = MatrixUtils.Median(pairDists.ToArray());

            return(med);
        }
Esempio n. 2
0
        public new static Kernel <T> FromMatlabStruct(MatlabStruct s)
        {
            string className = s.GetString("className");

            if (className.Equals(KEGaussian <T> .MATLAB_CLASS))
            {
                return(KEGaussian <T> .FromMatlabStruct(s));
            }
            else if (className.Equals(KGGaussian <T> .MATLAB_CLASS))
            {
                return(KGGaussian <T> .FromMatlabStruct(s));
            }
            else
            {
                String msg = String.Format("Unknown class: {0}", className);
                throw new ArgumentException(msg);
            }
        }
Esempio n. 3
0
        public KGGaussian(double[] embedSquaredWidths, double squaredWidth)
        {
//			this.embedSquaredWidths = embedSquaredWidths;
            this.keGauss      = new KEGaussian <T>(embedSquaredWidths);
            this.squaredWidth = squaredWidth;
        }