示例#1
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);
        }
示例#2
0
 public RFGMVMap(Vector mwidth2s, Vector vwidth2s, RFGMap rfgMap)
 {
     if (mwidth2s.Count != vwidth2s.Count)
     {
         throw new ArgumentException("Params. for means and variances must have the same length.");
     }
     for (int i = 0; i < mwidth2s.Count; ++i)
     {
         if (mwidth2s[i] <= 0)
         {
             throw new ArgumentException("mwidth2s: " + mwidth2s + " contains non-positive numbers.");
         }
         if (vwidth2s[i] <= 0)
         {
             throw new ArgumentException("vwidth2s: " + vwidth2s + " contains non-positive numbers.");
         }
     }
     this.mwidth2s = mwidth2s;
     this.vwidth2s = vwidth2s;
     this.rfgMap   = rfgMap;
 }
示例#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));
        }