示例#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));
        }
示例#2
0
        public static new StackVectorMapper FromMatlabStruct(MatlabStruct s)
        {
            //			s = struct();
            //			s.className=class(this);
            //			mapperCount = length(this.instancesMappers);
            //			mapperCell = cell(1, mapperCount);
            //			for i=1:mapperCount
            //					mapperCell{i} = this.instancesMappers{i}.toStruct();
            //			end
            //			s.instancesMappers = this.instancesMappers;

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

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

            object[,] mappersCell = s.GetCells("instancesMappers");
            if (mappersCell.Length != 2)
            {
                throw new ArgumentException("instancesMappers should have length 2.");
            }
            int m    = mappersCell.GetLength(1);
            var maps = new VectorMapper[m];

            for (int i = 0; i < m; i++)
            {
                var          mapStruct = new MatlabStruct((Dictionary <string, object>)mappersCell[0, i]);
                VectorMapper map       = VectorMapper.FromMatlabStruct(mapStruct);
                maps[i] = map;
            }

            return(new StackVectorMapper(maps));
        }
示例#3
0
        public CondFMFiniteOut(VectorMapper featureMap, Matrix mapMatrix)
        {
//			Console.WriteLine("featureMap's output dim: {0}", featureMap.GetOutputDimension());
//			Console.WriteLine("mapMatrix's #cols: {0}", mapMatrix.Cols);
            if (featureMap.GetOutputDimension() != mapMatrix.Cols)
            {
                throw new ArgumentException("featureMap output dimension does not match with mapMatrix.");
            }
            this.featureMap = featureMap;
            this.mapMatrix  = mapMatrix;
        }
示例#4
0
        // return the expected number of incoming messages
        // negative for any number.
        //		public abstract int NumInputMessages();

        // Load a FeatureMap in Matlab represented by the input
        // All FeatureMap objects can be serialized to struct with .toStruct()
        public static VectorMapper FromMatlabStruct(MatlabStruct s)
        {
            string       className = s.GetString("className");
            VectorMapper map       = null;

            if (className.Equals("RandFourierGaussMVMap"))
            {
                map = RFGMVMap.FromMatlabStruct(s);
            }
            else if (className.Equals("CondFMFiniteOut"))
            {
                map = CondFMFiniteOut.FromMatlabStruct(s);
            }
//			else if(className.Equals("CondCholFiniteOut")){
//				map = CondCholFiniteOut.FromMatlabStruct(s);
//			}
            else if (className.Equals(RFGJointKGG.MATLAB_CLASS))
            {
                map = RFGJointKGG.FromMatlabStruct(s);
            }
            else if (className.Equals(StackVectorMapper.MATLAB_CLASS))
            {
                map = StackVectorMapper.FromMatlabStruct(s);
            }
            else if (className.Equals(BayesLinRegFM.MATLAB_CLASS))
            {
                map = BayesLinRegFM.FromMatlabStruct(s);
            }
            else if (className.Equals(UAwareVectorMapper.MATLAB_CLASS))
            {
                map = UAwareVectorMapper.FromMatlabStruct(s);
            }
            else if (className.Equals(UAwareStackVectorMapper.MATLAB_CLASS))
            {
                map = UAwareStackVectorMapper.FromMatlabStruct(s);
            }
            else
            {
                throw new ArgumentException("Unknown className: " + className);
            }
            //			else if(className.Equals("RFGSumEProdMap")){
            //
            //			}else if(className.Equals("RFGEProdMap")){
            //
            //			}else if(className.Equals("RFGJointEProdMap")){
            //
            //			}else if(className.Equals("RFGProductEProdMap")){
            //
            //			}
            return(map);
        }
示例#5
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));
        }
示例#6
0
 public GenericMapper(VectorMapper suffMapper, DistBuilder <T> distBuilder)
 {
     this.suffMapper  = suffMapper;
     this.distBuilder = distBuilder;
 }