Esempio n. 1
0
        public static DBeta FromMatlabStruct(MatlabStruct s)
        {
            string className = s.GetString("className");

            if (!className.Equals(MATLAB_CLASS))
            {
                throw new ArgumentException("The input does not represent a " + typeof(DBeta));
            }
            double a = s.GetDouble("alpha");
            double b = s.GetDouble("beta");

            return(new DBeta(a, b));
        }
Esempio n. 2
0
        public new static KGGaussian <T> FromMatlabStruct(MatlabStruct s)
        {
//			s = struct();
//			s.className=class(this);
//			s.kegauss = this.kegauss.toStruct();
//			s.embed_width2 = this.embed_width2;
//			s.width2 = this.width2;
//
            string className = s.GetString("className");

            if (!className.Equals(MATLAB_CLASS))
            {
                throw new ArgumentException("The input does not represent a " + typeof(KGGaussian <T>));
            }
//			KEGaussian<T> keGauss = KEGaussian<T>.FromMatlabStruct(s.GetStruct("kegauss"));
            double[] embedSquaredWidths = s.Get1DDoubleArray("embed_width2s");
            if (!MatrixUtils.IsAllPositive(embedSquaredWidths))
            {
                throw new ArgumentException("all embedding width^2's must be positive.");
            }
            double squaredWidth = s.GetDouble("width2");

            if (squaredWidth <= 0)
            {
                throw new ArgumentException("width2 must be > 0");
            }
            return(new KGGaussian <T>(embedSquaredWidths, squaredWidth));
        }
Esempio n. 3
0
        public new static RFGJointKGG FromMatlabStruct(MatlabStruct s)
        {
            //			s.className=class(this);
            //			s.embed_width2s_cell = this.embed_width2s_cell;
            //			s.outer_width2 = this.outer_width2;
            //			s.numFeatures=this.numFeatures;
            //			s.innerNumFeatures = this.innerNumFeatures;
            //			s.eprodMap=this.eprodMap.toStruct();
            //			s.Wout = this.Wout;
            //			s.Bout = this.Bout;

            string className = s.GetString("className");

            if (!className.Equals(MATLAB_CLASS))
            {
                throw new ArgumentException("The input does not represent a " + MATLAB_CLASS);
            }

            double       outer_width2     = s.GetDouble("outer_width2");
            int          numFeatures      = s.GetInt("numFeatures");
            int          innerNumFeatures = s.GetInt("innerNumFeatures");
            MatlabStruct mapStruct        = s.GetStruct("eprodMap");
            RFGEProdMap  eprodMap         = RFGEProdMap.FromMatlabStruct(mapStruct);
            Matrix       Wout             = s.GetMatrix("Wout");

            if (innerNumFeatures != Wout.Rows)
            {
                throw new ArgumentException("inner #features must be  = #rows of Wout");
            }
            if (numFeatures != Wout.Cols)
            {
                throw new ArgumentException("numFeatures must be = #cols of Wout");
            }
            Vector Bout = s.Get1DVector("Bout");

            if (Bout.Count != numFeatures)
            {
                throw new ArgumentException("Bout must have length = numFeatures");
            }
            RFGJointKGG jointMap = new RFGJointKGG();

            jointMap.outer_width2     = outer_width2;
            jointMap.numFeatures      = numFeatures;
            jointMap.innerNumFeatures = innerNumFeatures;
            jointMap.eprodMap         = eprodMap;
            jointMap.Wout             = Wout;
            jointMap.Bout             = Bout;
            // construct object
            return(jointMap);
        }
Esempio n. 4
0
        public static new BayesLinRegFM FromMatlabStruct(MatlabStruct s)
        {
//			s.className=class(this);
//			s.featureMap=this.featureMap.toStruct();
//			%s.regParam=this.regParam;
//			s.mapMatrix=this.mapMatrix;
//			s.posteriorCov = this.posteriorCov;
//			s.noise_var = this.noise_var;

            string className = s.GetString("className");

            if (!className.Equals(MATLAB_CLASS))
            {
                throw new ArgumentException("The input does not represent a " + MATLAB_CLASS);
            }
            MatlabStruct     fmStruct   = s.GetStruct("featureMap");
            RandomFeatureMap featureMap = RandomFeatureMap.FromMatlabStruct(fmStruct);
            // This is the same as a posterior mean
            Vector mapMatrix = s.Get1DVector("mapMatrix");

            if (mapMatrix.Count != featureMap.GetOutputDimension())
            {
                throw new ArgumentException("mapMatrix and featureMap's dimenions are incompatible.");
            }
            Matrix postCov = s.GetMatrix("posteriorCov");

            if (postCov.Cols != featureMap.GetOutputDimension())
            {
                throw new ArgumentException("posterior covariance and featureMap's dimenions are incompatible.");
            }
            double noise_var = s.GetDouble("noise_var");
            Vector crossCorr = s.Get1DVector("crossCorrelation");
            var    bayes     = new BayesLinRegFM();

            bayes.featureMap    = featureMap;
            bayes.posteriorMean = mapMatrix;
            bayes.posteriorCov  = postCov;
            bayes.noiseVar      = noise_var;
            bayes.crossCorr     = crossCorr;
            // No need to do the initial batch train because we loaded the result
            // from .mat.
            bayes.WillNeedInitialTrain = false;
            return(bayes);
        }
Esempio n. 5
0
        public static DNormal FromMatlabStruct(MatlabStruct s)
        {
            string className = s.GetString("className");

            if (!className.Equals(MATLAB_CLASS))
            {
                throw new ArgumentException("The input does not represent a " + typeof(DNormal));
            }
            Vector meanVec = s.Get1DVector("mean");

            if (meanVec.Count != 1)
            {
                throw new ArgumentException("mean vector is not 1 dimenion.");
            }
            double mean     = meanVec[0];
            double variance = s.GetDouble("variance");

            return(new DNormal(mean, variance));
        }
Esempio n. 6
0
        // construct a RFGMap from MatlabStruct.
        // Matlab objects of class RandFourierGaussMap.
        // See RandFourierGaussMap.toStruct()
        public static RFGMap FromMatlabStruct(MatlabStruct s)
        {
            //			s.className = class(this);
            //            s.gwidth2=this.gwidth2;
            //            s.numFeatures=this.numFeatures;
            //            s.dim=this.dim;
            //            s.W=this.W;
            //            s.B=this.B;
            string className = s.GetString("className");

            if (!className.Equals("RandFourierGaussMap"))
            {
                throw new ArgumentException("The input does not represent a " + typeof(RFGMap));
            }

            double gwidth2     = s.GetDouble("gwidth2");
            int    numFeatures = s.GetInt("numFeatures");
            //			int dim = s.GetInt("dim");
            Matrix W = s.GetMatrix("W");

            if (W.Rows <= 0 || W.Cols <= 0)
            {
                throw new Exception("Loaded weight matrix has collapsed dimensions");
            }
            if (numFeatures != W.Cols)
            {
                // expect W to be dim x numFeatures
                throw new ArgumentException("Loaded weight matrix's #cols does not match numFeatures.");
            }
            Vector B = s.Get1DVector("B");

            // construct object
            RFGMap map = new RFGMap();

            map.GaussWidthSq = gwidth2;
            map.WeightMatrix = W;
            map.BiasVector   = B;

            Console.WriteLine("mapMatrix W's size: ({0}, {1})", W.Rows, W.Cols);
            Console.WriteLine("bias vector length: {0}", B.Count);
            return(map);
        }