yat/statistics/AUC.h

Code
Comments
Other
Rev Date Author Line
4200 19 Aug 22 peter 1 #ifndef _theplu_yat_statistics_auc_
4200 19 Aug 22 peter 2 #define _theplu_yat_statistics_auc_
69 29 Apr 04 peter 3
616 31 Aug 06 jari 4 // $Id$
616 31 Aug 06 jari 5
675 10 Oct 06 jari 6 /*
831 27 Mar 07 peter 7   Copyright (C) 2004 Peter Johansson
4359 23 Aug 23 peter 8   Copyright (C) 2005, 2006 Jari Häkkinen, Peter Johansson
4359 23 Aug 23 peter 9   Copyright (C) 2007 Peter Johansson
4359 23 Aug 23 peter 10   Copyright (C) 2008 Jari Häkkinen, Peter Johansson
4359 23 Aug 23 peter 11   Copyright (C) 2011 Peter Johansson
69 29 Apr 04 peter 12
1437 25 Aug 08 peter 13   This file is part of the yat library, http://dev.thep.lu.se/yat
675 10 Oct 06 jari 14
675 10 Oct 06 jari 15   The yat library is free software; you can redistribute it and/or
675 10 Oct 06 jari 16   modify it under the terms of the GNU General Public License as
1486 09 Sep 08 jari 17   published by the Free Software Foundation; either version 3 of the
675 10 Oct 06 jari 18   License, or (at your option) any later version.
675 10 Oct 06 jari 19
675 10 Oct 06 jari 20   The yat library is distributed in the hope that it will be useful,
675 10 Oct 06 jari 21   but WITHOUT ANY WARRANTY; without even the implied warranty of
675 10 Oct 06 jari 22   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
675 10 Oct 06 jari 23   General Public License for more details.
675 10 Oct 06 jari 24
675 10 Oct 06 jari 25   You should have received a copy of the GNU General Public License
1487 10 Sep 08 jari 26   along with yat. If not, see <http://www.gnu.org/licenses/>.
675 10 Oct 06 jari 27 */
675 10 Oct 06 jari 28
680 11 Oct 06 jari 29 #include "Score.h"
779 05 Mar 07 peter 30 #include "yat/utility/stl_utility.h"
675 10 Oct 06 jari 31
779 05 Mar 07 peter 32 #include <utility>
779 05 Mar 07 peter 33 #include <map>
69 29 Apr 04 peter 34
69 29 Apr 04 peter 35 namespace theplu {
680 11 Oct 06 jari 36 namespace yat {
747 11 Feb 07 peter 37 namespace classifier {
747 11 Feb 07 peter 38   class Target;
747 11 Feb 07 peter 39 }
747 11 Feb 07 peter 40 namespace utility {
1023 01 Feb 08 peter 41   class VectorBase;
747 11 Feb 07 peter 42 }
4200 19 Aug 22 peter 43 namespace statistics {
414 01 Dec 05 peter 44
2594 30 Oct 11 peter 45   /**
2594 30 Oct 11 peter 46      \brief Area Under ROC Curve
2594 30 Oct 11 peter 47
2594 30 Oct 11 peter 48      Class calculates area under curve from values, Target, and
2594 30 Oct 11 peter 49      possibly weights. If weights are left out, unity weights are
4200 19 Aug 22 peter 50      assumed. The area under curve is defined as
2594 30 Oct 11 peter 51      \f[
2594 30 Oct 11 peter 52      \frac{\sum_{i,j} I(x_i^+-x_j^-) w_i^+w_j^-} {\sum_{i,j}
4200 19 Aug 22 peter 53      w_i^+w_j^-} \f]
4200 19 Aug 22 peter 54      where
4200 19 Aug 22 peter 55      \f{eqnarray*}{
2594 30 Oct 11 peter 56             &0; &x<0 \\
2594 30 Oct 11 peter 57      I(x) = &0.5; &x=0 \\
4200 19 Aug 22 peter 58             &1; &x>0
2594 30 Oct 11 peter 59      \f}
2594 30 Oct 11 peter 60
2594 30 Oct 11 peter 61      Complexity of calculating the AUC is \f$ N \log N \f$.
4200 19 Aug 22 peter 62   */
820 17 Mar 07 peter 63   class AUC : public Score
69 29 Apr 04 peter 64   {
4200 19 Aug 22 peter 65
69 29 Apr 04 peter 66   public:
718 26 Dec 06 jari 67     ///
2594 30 Oct 11 peter 68     /// \brief Default Constructor
966 11 Oct 07 peter 69     /// \param absolute if true max(AUC, 1-AUC) is used
4200 19 Aug 22 peter 70     ///
820 17 Mar 07 peter 71     AUC(bool absolute=true);
718 26 Dec 06 jari 72
2594 30 Oct 11 peter 73     /**
2594 30 Oct 11 peter 74        \return area under the ROC curve.
2594 30 Oct 11 peter 75     */
4200 19 Aug 22 peter 76     double score(const classifier::Target& target,
4200 19 Aug 22 peter 77                  const utility::VectorBase& value) const;
4200 19 Aug 22 peter 78
2594 30 Oct 11 peter 79     /**
2594 30 Oct 11 peter 80        \return area under the ROC curve.
650 15 Sep 06 peter 81     */
4200 19 Aug 22 peter 82     double score(const classifier::Target& target,
4200 19 Aug 22 peter 83                  const classifier::DataLookupWeighted1D& value) const;
623 05 Sep 06 peter 84
2594 30 Oct 11 peter 85     /**
2594 30 Oct 11 peter 86        \return area under the ROC curve.
650 15 Sep 06 peter 87     */
4200 19 Aug 22 peter 88     double score(const classifier::Target& target,
4200 19 Aug 22 peter 89                  const utility::VectorBase& value,
4200 19 Aug 22 peter 90                  const utility::VectorBase& weight) const;
179 04 Oct 04 peter 91
475 22 Dec 05 peter 92   private:
821 18 Mar 07 peter 93     friend class ROC;
821 18 Mar 07 peter 94
779 05 Mar 07 peter 95     typedef std::multimap<double, std::pair<bool, double> > MultiMap;
779 05 Mar 07 peter 96     double score(const MultiMap&) const;
69 29 Apr 04 peter 97    };
69 29 Apr 04 peter 98
683 11 Oct 06 jari 99 }}} // of namespace statistics, yat, and theplu
103 15 Jun 04 peter 100
69 29 Apr 04 peter 101 #endif