001package org.dllearner.accuracymethods;
002
003import org.dllearner.core.Component;
004import org.dllearner.core.ComponentAnn;
005import org.dllearner.core.config.ConfigOption;
006import org.dllearner.learningproblems.Heuristics;
007
008@ComponentAnn(name = "AMeasure", shortName = "ameasure", version = 0.1)
009public class AccMethodAMeasure implements Component, AccMethodTwoValued, AccMethodWithBeta {
010
011        @ConfigOption(description = "beta factor (0 = do not use)", defaultValue = "0")
012        protected double beta = 0;
013
014        public AccMethodAMeasure() {}
015        
016        public AccMethodAMeasure(boolean init) {
017                if(init)init();
018        }
019
020        @Override
021        public void init() {
022        }
023
024        @Override
025        public double getAccOrTooWeak2(int tp, int fn, int fp, int tn, double noise) {
026                double recall = Heuristics.divideOrZero( tp , tp+fn );
027                double precision = Heuristics.divideOrZero( tp , tp+fp );
028
029        // best reachable concept has same recall and precision 1:
030                // 1/t+1 * (t*r + 1)
031                if (beta == 0) {
032                        if (recall + 1 < 1 - noise) {
033                                return -1;
034                        }
035                } else {
036                        if ((beta * recall + 1) / (beta + 1) < 1 - noise) {
037                                return -1;
038                        }
039                }
040
041                if (beta == 0) {
042                        return Heuristics.getAScore(recall, precision);
043                } else {
044                        return Heuristics.getAScore(recall, precision, beta);
045                }
046        }
047
048        @Override
049        public void setBeta(double beta) {
050                this.beta = beta;
051        }
052}