Example #1
0
        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);
        }
Example #2
0
        /**
         * Initialize an empty Bayesian linear regressor suitable for online
         * learning from scratch.
         */
        public BayesLinRegFM(RandomFeatureMap featureMap)
        {
//			if(noiseVar < 0){
//				throw new ArgumentException("Require noise variance >= 0");
//			}
//			this.noiseVar = noiseVar;
//			if(uThreshold < 0){
//				throw new ArgumentException("Require uncertainty threshold >= 0");
//			}
//			this.uThreshold = uThreshold;
            int D = featureMap.GetOutputDimension();

            this.featureMap = featureMap;
//			this.noiseVar = noiseVar;
//			this.uThreshold = uThreshold;
            this.posteriorMean = Vector.Zero(D);
            // assume that the prior for W is N(0, 1)
            this.posteriorCov = Matrix.IdentityScaledBy(D, 1.0);
            this.crossCorr    = Vector.Zero(D);
        }