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)); }
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); }
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); }
// 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); }
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); }