Пример #1
0
//		public override bool IsUncertain(params IKEPDist[] msgs){
//			// Return true if at least one of the mappers is uncertain
//			for(int i=0; i<onlineBayes.Length; i++){
//				if(onlineBayes[i].IsUncertain(msgs)){
//					return true;
//				}
//			}
//			return false;
//		}

        private bool IsUncertain(Vector[] features)
        {
            // Return true if at least one of the mappers is uncertain
            for (int i = 0; i < onlineBayes.Length; i++)
            {
                BayesLinRegFM bi     = onlineBayes[i];
                double[]      thresh = bi.GetUncertaintyThreshold();
                if (thresh.Length != 1)
                {
                    throw new ArgumentException("Threshold from a Bayesian linear regression should have just one number.");
                }
                double   t  = thresh[0];
                double[] un = bi.EstimateUncertainty();
                if (un.Length != 1)
                {
                    throw new ArgumentException("Uncertainty from a Bayesian linear regression should have just one number");
                }
                double u = un[0];
                if (u >= t)
                {
                    return(true);
                }
            }
            return(false);
        }
Пример #2
0
        // 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);
        }
Пример #3
0
 public override void UpdateVectorMapper(Vector target, params IKEPDist[] msgs)
 {
     // update each internal mapper
     if (target.Count != onlineBayes.Length)
     {
         throw new ArgumentException("Require target length == number of nested Bayes learners");
     }
     for (int i = 0; i < onlineBayes.Length; i++)
     {
         Vector        oneDTarget = Vector.FromArray(new double[] { target[i] });
         BayesLinRegFM map        = onlineBayes[i];
         map.UpdateVectorMapper(oneDTarget, msgs);
     }
 }
Пример #4
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);
        }