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); }
// 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 static TensorInstances <T1, T2> FromMatlabStruct(MatlabStruct s) { // s = struct(); // s.className=class(this); // instancesCount = length(this.instancesCell); // cellStruct = cell(1, instancesCount); // for i=1:instancesCount // cellStruct = this.instancesCell{i}.toStruct(); // end // s.instancesCell = cellStruct; string className = s.GetString("className"); if (!className.Equals(MATLAB_CLASS)) { throw new ArgumentException("The input does not represent a " + typeof(TensorInstances <T1, T2>)); } int instancesCount = s.GetInt("instancesCount"); if (instancesCount != 2) { throw new ArgumentException("expect instancesCount to be 2."); } object[,] instancesCell = s.GetCells("instancesCell"); if (instancesCell.Length != 2) { throw new ArgumentException("instancesCell does not have length 2."); } var da1Dict = (Dictionary <string, object>)instancesCell[0, 0]; var da2Dict = (Dictionary <string, object>)instancesCell[0, 1]; // assume instancesCell contains DistArray's DistArray <T1> da1 = DistArray <T1> .FromMatlabStruct( new MatlabStruct(da1Dict)); DistArray <T2> da2 = DistArray <T2> .FromMatlabStruct( new MatlabStruct(da2Dict)); return(new TensorInstances <T1, T2>(da1.GetDists(), da2.GetDists())); }
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); }