예제 #1
0
        private static double RunBPMGeneral(BPMDataModel model, bool addBias, Vector[] testSet, int[] testResults)
        {
            int correctCount = 0;

            VectorGaussian[] posteriorWeights = _bpm.Train(model.GetInputs(), model.GetClasses());
            string           actualWeights    = posteriorWeights[1].ToString();
            int breakLocation = actualWeights.IndexOf("\r", StringComparison.Ordinal);

            actualWeights = actualWeights.Substring(0, breakLocation);
            if (!_onlyWriteAggregateResults && _writeGaussians)
            {
                _writer.WriteLine("Weights= " + actualWeights);
            }
            Discrete[] predictions = _bpm.Test(testSet);
            int        i           = 0;

            foreach (Discrete prediction in predictions)
            {
                if (FindMaxValPosition(prediction.GetProbs().ToArray()) == testResults[i])
                {
                    correctCount++;
                }
                i++;
            }
            double accuracy = ((double)correctCount / predictions.Length) * 100;

            //double logEvidence = bpm.GetLogEvidence();
            return(accuracy);
        }
예제 #2
0
        public static BPMDataModel CreateNoisyModel(BPMDataModel model, double epsilon)
        {
            Random        generator  = new Random();
            BPMDataModel  noisyModel = new BPMDataModel(model.GetInputs().Length, model.GetNoOfFeatures());
            List <double> ranges     = model.GetRanges();

            double[]      values = new double[model.GetInputs()[0].Count];
            List <Vector> x      = new List <Vector>();

            foreach (Vector vector in model.GetInputs())
            {
                for (int i = 0; i < ranges.Count; i++)
                {
                    double randomVal = (0.5 - generator.NextDouble());
                    double newVal    = CreateLaplacian(epsilon, 0, vector[i], ranges[i], randomVal);
                    values[i] = newVal;
                }
                x.Add(Vector.FromArray(values));
            }
            noisyModel.SetAllVectorFeatures(x.ToArray());
            noisyModel.SetClasses(model.GetClasses());
            //noisyModel.CalculateFeatureLimits();
            //noisyModel.ScaleFeatures();
            return(noisyModel);
        }
예제 #3
0
 public static BPMDataModel CreateNoisyModel(BPMDataModel model, double epsilon)
 {
     Random generator = new Random();
     BPMDataModel noisyModel = new BPMDataModel(model.GetInputs().Length, model.GetNoOfFeatures());
     List<double> ranges = model.GetRanges();
     double[] values = new double[model.GetInputs()[0].Count];
     List<Vector> x = new List<Vector>();
     foreach (Vector vector in model.GetInputs())
     {
         for (int i = 0; i < ranges.Count; i++)
         {
             double randomVal = (0.5 - generator.NextDouble());
             double newVal = CreateLaplacian(epsilon, 0, vector[i], ranges[i], randomVal);
             values[i] = newVal;
         }
         x.Add(Vector.FromArray(values));
     }
     noisyModel.SetAllVectorFeatures(x.ToArray());
     noisyModel.SetClasses(model.GetClasses());
     //noisyModel.CalculateFeatureLimits();
     //noisyModel.ScaleFeatures();
     return noisyModel;
 }
예제 #4
0
        private static double RunBPMGeneral(BPMDataModel model, bool addBias, Vector[] testSet, int[] testResults)
        {
            int correctCount = 0;
            VectorGaussian[] posteriorWeights = _bpm.Train(model.GetInputs(), model.GetClasses());
            string actualWeights = posteriorWeights[1].ToString();
            int breakLocation = actualWeights.IndexOf("\r", StringComparison.Ordinal);
            actualWeights = actualWeights.Substring(0, breakLocation);
            if (!_onlyWriteAggregateResults && _writeGaussians) _writer.WriteLine("Weights= " + actualWeights);
            Discrete[] predictions = _bpm.Test(testSet);
            int i = 0;

            foreach (Discrete prediction in predictions)
            {
                if (FindMaxValPosition(prediction.GetProbs().ToArray()) == testResults[i]) correctCount++;
                i++;
            }
            double accuracy = ((double)correctCount / predictions.Length) * 100;
            //double logEvidence = bpm.GetLogEvidence();
            return accuracy;
        }