001package org.dllearner.accuracymethods;
002
003import org.dllearner.core.ComponentAnn;
004import org.dllearner.core.config.ConfigOption;
005import org.dllearner.learningproblems.Heuristics;
006
007@ComponentAnn(name = "Generalised FMeasure", shortName = "gen_fmeasure", version = 0.1)
008public class AccMethodGenFMeasure implements AccMethodThreeValued, AccMethodWithBeta {
009
010        @ConfigOption(description = "beta factor (0 = do not use)", defaultValue = "0")
011        private double beta = 0;
012
013        @Override
014        public double getAccOrTooWeak3(int pos1, int neg1, int icPos, int icNeg, int posEx, int negatedPosEx, double noise) {
015                        // Cn(I_C) \cap D_C is the same set if we ignore Cn ...
016                int tmp1Size = pos1 + neg1; // true positives (correct examples)
017
018                int icSize = icPos + icNeg;
019                double prec = Heuristics.divideOrZero(tmp1Size, icSize);
020                double rec = tmp1Size / (double) (posEx + negatedPosEx);
021
022                        // we only return too weak if there is no recall
023                        if(rec <= 0.0000001) {
024                                return -1;
025                        }
026
027                        return Heuristics.getFScoreBalanced(rec,prec,beta);
028        }
029
030        @Override
031        public void init() {
032        }
033
034        @Override
035        public void setBeta(double beta) {
036                this.beta = beta;
037
038        }
039
040}