public new static KDistProduct2 <T1, T2> FromMatlabStruct(MatlabStruct s) { // s = struct(); // s.className=class(this); // kcount = length(this.kernels); // kerCell = cell(1, kcount); // for i=1:kcount // kerCell{i} = this.kernels{i}.toStruct(); // end // s.kernels = kerCell; string className = s.GetString("className"); if (!className.Equals(MATLAB_CLASS)) { throw new ArgumentException("The input does not represent a " + typeof(KDistProduct2 <T1, T2>)); } MatlabStruct[,] kerStructs = s.GetStructCells("kernels"); Kernel <T1> k1 = KDist <T1> .FromMatlabStruct(kerStructs[0, 0]); Kernel <T2> k2 = KDist <T2> .FromMatlabStruct(kerStructs[0, 1]); return(new KDistProduct2 <T1, T2>(k1, k2)); }
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 static DistBuilderBase FromMatlabStruct(MatlabStruct s) { string className = s.GetString("className"); if (className.Equals(DNormalBuilder.MATLAB_CLASS)) { return(DNormalBuilder.FromMatlabStruct(s)); } else if (className.Equals(DBetaBuilder.MATLAB_CLASS)) { return(DBetaBuilder.FromMatlabStruct(s)); } else if (className.Equals(DNormalLogVarBuilder.MATLAB_CLASS)) { return(DNormalLogVarBuilder.FromMatlabStruct(s)); } else if (className.Equals(DBetaLogBuilder.MATLAB_CLASS)) { return(DBetaLogBuilder.FromMatlabStruct(s)); } else { throw new ArgumentException("invalid MatlabStruct for a DistBuilder."); } }
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)); }
public new static KGGaussian <T> FromMatlabStruct(MatlabStruct s) { // s = struct(); // s.className=class(this); // s.kegauss = this.kegauss.toStruct(); // s.embed_width2 = this.embed_width2; // s.width2 = this.width2; // string className = s.GetString("className"); if (!className.Equals(MATLAB_CLASS)) { throw new ArgumentException("The input does not represent a " + typeof(KGGaussian <T>)); } // KEGaussian<T> keGauss = KEGaussian<T>.FromMatlabStruct(s.GetStruct("kegauss")); double[] embedSquaredWidths = s.Get1DDoubleArray("embed_width2s"); if (!MatrixUtils.IsAllPositive(embedSquaredWidths)) { throw new ArgumentException("all embedding width^2's must be positive."); } double squaredWidth = s.GetDouble("width2"); if (squaredWidth <= 0) { throw new ArgumentException("width2 must be > 0"); } return(new KGGaussian <T>(embedSquaredWidths, squaredWidth)); }
public new static DistArray <T> FromMatlabStruct(MatlabStruct s) { // s = struct(); // s.className=class(this); // distCell = cell(1, length(this.distArray)); // for i=1:length(this.distArray) // dist = this.distArray(i); // distCell{i} = dist.toStruct(); // end // s.distArray = distCell; // s.mean = this.mean; // s.variance = this.variance; // string className = s.GetString("className"); if (!className.Equals("DistArray")) { throw new ArgumentException("The input does not represent a " + "DistArray"); } object[,] distCell = s.GetCells("distArray"); List <T> dists = new List <T>(); for (int i = 0; i < distCell.Length; i++) { var distDict = (Dictionary <string, object>)distCell[0, i]; MatlabStruct distStruct = new MatlabStruct(distDict); IKEPDist disti = KEPDist.FromMatlabStruct(distStruct); dists.Add((T)disti); } return(new DistArray <T>(dists)); }
public new static DBetaLogBuilder FromMatlabStruct(MatlabStruct s) { string className = s.GetString("className"); if (!className.Equals(MATLAB_CLASS)) { throw new ArgumentException("The input does not represent a " + typeof(DBetaLogBuilder)); } return(DBetaLogBuilder.Instance); }
public static DistMapper <T> FromMatlabStruct(MatlabStruct s) { string className = s.GetString("className"); if (className.Equals(GenericMapper <T> .MATLAB_CLASS)) { return(GenericMapper <T> .FromMatlabStruct(s)); } else { throw new ArgumentException("Unknown DistMapper to load."); } }
public new static Kernel2 <T1, T2> FromMatlabStruct(MatlabStruct s) { string className = s.GetString("className"); if (className.Equals(KDistProduct2 <T1, T2> .MATLAB_CLASS)) { return(KDistProduct2 <T1, T2> .FromMatlabStruct(s)); } else { throw new ArgumentException("Unknown class in MatlabStruct for Kernel2."); } }
public static DBeta FromMatlabStruct(MatlabStruct s) { string className = s.GetString("className"); if (!className.Equals(MATLAB_CLASS)) { throw new ArgumentException("The input does not represent a " + typeof(DBeta)); } double a = s.GetDouble("alpha"); double b = s.GetDouble("beta"); return(new DBeta(a, b)); }
// 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); }
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 new static KEGaussian <T> FromMatlabStruct(MatlabStruct s) { string className = s.GetString("className"); if (!className.Equals(MATLAB_CLASS)) { throw new ArgumentException("The input does not represent a " + typeof(KEGaussian <T>)); } double[] gwidth2s = s.Get1DDoubleArray("gwidth2s"); if (!MatrixUtils.IsAllPositive(gwidth2s)) { throw new ArgumentException("all width^2's must be positive."); } return(new KEGaussian <T>(gwidth2s)); }
public new static UAwareVectorMapper FromMatlabStruct(MatlabStruct s) { string className = s.GetString("className"); UAwareVectorMapper map = null; if (className.Equals(MATLAB_CLASS)) { map = null; } else { throw new ArgumentException("Unknown className: " + className); } return(map); }
public new static IKEPDist FromMatlabStruct(MatlabStruct s) { string className = s.GetString("className"); if (className.Equals(DNormal.MATLAB_CLASS)) { return(DNormal.FromMatlabStruct(s)); } else if (className.Equals(DBeta.MATLAB_CLASS)) { return(DBeta.FromMatlabStruct(s)); } else { throw new ArgumentException("unknown distribution class."); } }
public new static Kernel <T> FromMatlabStruct(MatlabStruct s) { string className = s.GetString("className"); if (className.Equals(KEGaussian <T> .MATLAB_CLASS)) { return(KEGaussian <T> .FromMatlabStruct(s)); } else if (className.Equals(KGGaussian <T> .MATLAB_CLASS)) { return(KGGaussian <T> .FromMatlabStruct(s)); } else { String msg = String.Format("Unknown class: {0}", className); throw new ArgumentException(msg); } }
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); }
public static DNormal FromMatlabStruct(MatlabStruct s) { string className = s.GetString("className"); if (!className.Equals(MATLAB_CLASS)) { throw new ArgumentException("The input does not represent a " + typeof(DNormal)); } Vector meanVec = s.Get1DVector("mean"); if (meanVec.Count != 1) { throw new ArgumentException("mean vector is not 1 dimenion."); } double mean = meanVec[0]; double variance = s.GetDouble("variance"); return(new DNormal(mean, variance)); }
// 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 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)); }
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); }
// 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)); }
public static RandomFeatureMap FromMatlabStruct(MatlabStruct s) { string className = s.GetString("className"); RandomFeatureMap map = null; if (className.Equals(RFGJointKGG.MATLAB_CLASS)) { map = RFGJointKGG.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); }
public static Kernel <T> FromMatlabStruct(MatlabStruct s) { string className = s.GetString("className"); throw new NotImplementedException(); }