Exemplo n.º 1
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);
        }
Exemplo n.º 2
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);
        }
Exemplo n.º 3
0
        // construct a RFGMVMap from MatlabStruct.
        // Matlab objects of class RadnFourierGaussMVMap.
        // See RandFourierGaussMVMap.toStruct()
        public new static RFGMVMap FromMatlabStruct(MatlabStruct s)
        {
            //            s.className=class(this);
            //            s.mwidth2s=this.mwidth2s;
            //            s.vwidth2s=this.vwidth2s;
            //            s.numFeatures=this.numFeatures;
            //            s.rfgMap=this.rfgMap.toStruct();

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

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

            // Gaussian width for mean of each input.
            Vector mwidth2s = s.Get1DVector("mwidth2s");
            Vector vwidth2s = s.Get1DVector("vwidth2s");
            //			int numFeatures = s.GetInt("numFeatures");
            RFGMap rfgMap = RFGMap.FromMatlabStruct(s.GetStruct("rfgMap"));

            // construct object
            return(new RFGMVMap(mwidth2s, vwidth2s, rfgMap));
        }
Exemplo n.º 4
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));
        }
Exemplo n.º 5
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);
        }
Exemplo n.º 6
0
        public new static RFGEProdMap FromMatlabStruct(MatlabStruct s)
        {
            //			s.className=class(this);
            //			s.gwidth2=this.gwidth2;
            //			s.numFeatures=this.numFeatures;
            //			s.W=this.W;
            //			s.B=this.B;

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

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

            // Vector of Gaussian width^2 for the mebedding kernel, one for
            // each dimension of the input.
            // Can be a scalar i.e., same param for each dimension.
            //			double[] gwidth2 = s.Get1DDoubleArray("gwidth2");
            int numFeatures = s.GetInt("numFeatures");
            // weight matrix. dim x numFeatures.
            Matrix W = s.GetMatrix("W");

            if (W.Cols != numFeatures)
            {
                throw new ArgumentException("numFeatures should be = #cols of W");
            }
            // coefficients b. a vector of length numFeatures.
            // Drawn form U[0, 2*pi]
            Vector B = s.Get1DVector("B");
            //			int numFeatures = s.GetInt("numFeatures");
            RFGEProdMap map = new RFGEProdMap();

            //			map.gwidth2 = gwidth2;
            map.numFeatures = numFeatures;
            map.W           = W;
            map.B           = B;
            return(map);
        }