Ejemplo n.º 1
0
        public static new CondFMFiniteOut FromMatlabStruct(MatlabStruct s)
        {
//			s.className=class(this);
//            s.featureMap=this.featureMap.toStruct();
//            s.regParam=this.regParam;
//            s.mapMatrix=this.mapMatrix;

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

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

            MatlabStruct mapStruct  = s.GetStruct("featureMap");
            VectorMapper featureMap = VectorMapper.FromMatlabStruct(mapStruct);

            // dz x numFeatures where dz is the dimension of output sufficient
            // statistic
            Matrix mapMatrix = s.GetMatrix("mapMatrix");

            Console.WriteLine("{0}.mapMatrix size: ({1}, {2})", MATLAB_CLASS,
                              mapMatrix.Rows, mapMatrix.Cols);
            return(new CondFMFiniteOut(featureMap, mapMatrix));
        }
Ejemplo n.º 2
0
        public new static GenericMapper <T> FromMatlabStruct(MatlabStruct s)
        {
            string className = s.GetString("className");

            if (!(className.Equals(MATLAB_CLASS) ||
                  className.Equals(UAwareGenericMapper <T> .MATLAB_CLASS)))
            {
                throw new ArgumentException("The input does not represent a " +
                                            typeof(GenericMapper <T>));
            }
            // nv = number of variables.
//			int inVars = s.GetInt("nv");
            MatlabStruct    rawOperator     = s.GetStruct("operator");
            VectorMapper    instancesMapper = VectorMapper.FromMatlabStruct(rawOperator);
            MatlabStruct    rawBuilder      = s.GetStruct("distBuilder");
            DistBuilder <T> distBuilder     = DistBuilderBase.FromMatlabStruct(rawBuilder)
                                              as DistBuilder <T>;

            return(new GenericMapper <T>(instancesMapper, distBuilder));
        }
Ejemplo 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);
        }
Ejemplo 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);
        }
Ejemplo n.º 5
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));
        }