Example #1
0
 public void ModelTrainingConverges()
 {
     ImageData img = ResourceManager.UsingDebugBitmap("testgrid1px.png", (bmp) => {
         return ImageData.FromImage(bmp);
     });
     Label[,] labels = new Label[img.XSites,img.YSites];
     Classification cfc = new Classification(labels);
     ModelBuilder mbr = new ModelBuilder(ConcatenateFeatures.INSTANCE, LinearBasis.INSTANCE, 1d, 3000, 1d, 1d);
     Model mfm = mbr.PseudoLikelihoodTrain("","", new ImageData[1]{img},new Classification[1]{cfc});
     Assert.AreNotEqual(mfm.TimeToConverge, mbr.MaxIters);
 }
Example #2
0
 public void CanClassify()
 {
     ImageData img = ResourceManager.UsingDebugBitmap("testgrid1px.png", (bmp) => {
         return ImageData.FromImage(bmp);
     });
     Label[,] labels = new Label[img.XSites,img.YSites];
     Classification cfc = new Classification(labels);
     ModelBuilder mbr = new ModelBuilder(ConcatenateFeatures.INSTANCE, LinearBasis.INSTANCE, 1d, 3000, 1d, 1d);
     Model mfm = mbr.PseudoLikelihoodTrain("", "", new ImageData[1]{img},new Classification[1]{cfc});
     Classification inferred = mfm.MaximumAPosterioriInfer(img);
     Assert.IsNotNull(inferred);
 }
Example #3
0
 public Classification LogisticInfer(ImageData test_input)
 {
     Classification curr_classification = new Classification(new Label[test_input.XSites, test_input.YSites]);
     for(int x = 0; x < test_input.XSites; x++) for(int y = 0; y < test_input.YSites; y++)
     {
         double modeled_prob_of_one = MathWrapper.Sigma(W.DotProduct(Transformer.Transform(test_input[x,y])));
         //double prob_one = ((double)OnsSeen)/((double) SitesSeen);
         //double prob_zero = 1d - prob_one;
         double lambda = MathWrapper.Log(modeled_prob_of_one) - MathWrapper.Log (1 - modeled_prob_of_one)/* + MathWrapper.Log (prob_one/prob_zero)*/;
         if(lambda > 0)
             curr_classification[x,y] = Label.ON;
         else
             curr_classification[x,y] = Label.OFF;
     }
     return curr_classification;
 }