예제 #1
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);
            }
        }
예제 #2
0
        /**  - Generate a cell array of FeatureMap candidates from medf,
         * a list of factors to be  multiplied with the
         * diagonal of the average covariance matrices.
         *
         * - subsamples can be used to limit the samples used to compute
         * median distance.
         * See RFGJointKGG in Matlab
         */
        public override List <RandomFeatureMap> GenCandidates(
            List <IKEPDist[]> msgs, int[] numFeatures, double[] medianFactors, Random rng)
        {
            if (numFeatures.Length != 2)
            {
                throw new ArgumentException("numFeatures must have length = 2");
            }
            List <DVectorNormal> joints = msgs.Select(m => ToJointGaussian(m)).ToList();
            int             n           = joints.Count;
            int             subsamples  = Math.Min(1500, n);
            List <IKEPDist> jointsBase  = joints.Cast <IKEPDist>().ToList();
            Vector          avgCov      = RFGEProdMap.GetAverageDiagCovariance(jointsBase, subsamples, rng);

            double[] embedWidth2 = avgCov.ToArray();

            // generate candidates
            double meanEmbedMedian2 = KGGaussian <DVectorNormal> .MedianPairwise(
                joints, embedWidth2);

            var mapCandidates = new List <RandomFeatureMap>(medianFactors.Length);

            for (int i = 0; i < medianFactors.Length; i++)
            {
                double medf = medianFactors[i];
                if (medf <= 0)
                {
                    string text = String.Format("medf must be strictly positive. Found i={0}, medf[i]={1}",
                                                i, medf);
                    throw new ArgumentException(text);
                }
                double width2 = meanEmbedMedian2 * medf;
                mapCandidates.Add(new RFGJointKGG(embedWidth2, width2,
                                                  numFeatures[0], numFeatures[1]));
            }
            return(mapCandidates);
        }