yat/statistics/tScore.cc

Code
Comments
Other
Rev Date Author Line
98 10 Jun 04 peter 1 // $Id$
98 10 Jun 04 peter 2
675 10 Oct 06 jari 3 /*
2119 12 Dec 09 peter 4   Copyright (C) 2004 Jari Häkkinen, Peter Johansson
831 27 Mar 07 peter 5   Copyright (C) 2005 Peter Johansson
2119 12 Dec 09 peter 6   Copyright (C) 2006 Jari Häkkinen, Peter Johansson, Markus Ringnér
4359 23 Aug 23 peter 7   Copyright (C) 2007 Peter Johansson
4359 23 Aug 23 peter 8   Copyright (C) 2008 Jari Häkkinen, Peter Johansson
4359 23 Aug 23 peter 9   Copyright (C) 2012 Peter Johansson
675 10 Oct 06 jari 10
1437 25 Aug 08 peter 11   This file is part of the yat library, http://dev.thep.lu.se/yat
675 10 Oct 06 jari 12
675 10 Oct 06 jari 13   The yat library is free software; you can redistribute it and/or
675 10 Oct 06 jari 14   modify it under the terms of the GNU General Public License as
1486 09 Sep 08 jari 15   published by the Free Software Foundation; either version 3 of the
675 10 Oct 06 jari 16   License, or (at your option) any later version.
675 10 Oct 06 jari 17
675 10 Oct 06 jari 18   The yat library is distributed in the hope that it will be useful,
675 10 Oct 06 jari 19   but WITHOUT ANY WARRANTY; without even the implied warranty of
675 10 Oct 06 jari 20   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
675 10 Oct 06 jari 21   General Public License for more details.
675 10 Oct 06 jari 22
675 10 Oct 06 jari 23   You should have received a copy of the GNU General Public License
1487 10 Sep 08 jari 24   along with yat. If not, see <http://www.gnu.org/licenses/>.
675 10 Oct 06 jari 25 */
675 10 Oct 06 jari 26
2881 18 Nov 12 peter 27 #include <config.h>
2881 18 Nov 12 peter 28
680 11 Oct 06 jari 29 #include "tScore.h"
680 11 Oct 06 jari 30 #include "Averager.h"
680 11 Oct 06 jari 31 #include "AveragerWeighted.h"
779 05 Mar 07 peter 32 #include "yat/classifier/DataLookup1D.h"
676 10 Oct 06 jari 33 #include "yat/classifier/DataLookupWeighted1D.h"
676 10 Oct 06 jari 34 #include "yat/classifier/Target.h"
1023 01 Feb 08 peter 35 #include "yat/utility/VectorBase.h"
623 05 Sep 06 peter 36
98 10 Jun 04 peter 37 #include <cmath>
98 10 Jun 04 peter 38
98 10 Jun 04 peter 39 namespace theplu {
680 11 Oct 06 jari 40 namespace yat {
4200 19 Aug 22 peter 41 namespace statistics {
98 10 Jun 04 peter 42
4200 19 Aug 22 peter 43   tScore::tScore(bool b)
779 05 Mar 07 peter 44     : Score(b)
102 15 Jun 04 peter 45   {
102 15 Jun 04 peter 46   }
102 15 Jun 04 peter 47
779 05 Mar 07 peter 48
4200 19 Aug 22 peter 49   double tScore::score(const classifier::Target& target,
1023 01 Feb 08 peter 50                        const utility::VectorBase& value) const
98 10 Jun 04 peter 51   {
779 05 Mar 07 peter 52     return score(target, value, NULL);
779 05 Mar 07 peter 53   }
779 05 Mar 07 peter 54
779 05 Mar 07 peter 55
4200 19 Aug 22 peter 56   double tScore::score(const classifier::Target& target,
1023 01 Feb 08 peter 57                        const utility::VectorBase& value,
779 05 Mar 07 peter 58                        double* dof) const
779 05 Mar 07 peter 59   {
197 27 Oct 04 jari 60     statistics::Averager positive;
197 27 Oct 04 jari 61     statistics::Averager negative;
475 22 Dec 05 peter 62     for(size_t i=0; i<target.size(); i++){
514 20 Feb 06 peter 63       if (target.binary(i))
475 22 Dec 05 peter 64         positive.add(value(i));
98 10 Jun 04 peter 65       else
475 22 Dec 05 peter 66         negative.add(value(i));
98 10 Jun 04 peter 67     }
779 05 Mar 07 peter 68     return score(positive, negative, dof);
779 05 Mar 07 peter 69   }
532 02 Mar 06 peter 70
779 05 Mar 07 peter 71
4200 19 Aug 22 peter 72   double tScore::score(const classifier::Target& target,
779 05 Mar 07 peter 73                        const classifier::DataLookupWeighted1D& value) const
779 05 Mar 07 peter 74   {
779 05 Mar 07 peter 75     return score(target, value, NULL);
98 10 Jun 04 peter 76   }
98 10 Jun 04 peter 77
623 05 Sep 06 peter 78
4200 19 Aug 22 peter 79   double tScore::score(const classifier::Target& target,
779 05 Mar 07 peter 80                        const classifier::DataLookupWeighted1D& value,
779 05 Mar 07 peter 81                        double* dof) const
623 05 Sep 06 peter 82   {
623 05 Sep 06 peter 83     statistics::AveragerWeighted positive;
623 05 Sep 06 peter 84     statistics::AveragerWeighted negative;
623 05 Sep 06 peter 85     for(size_t i=0; i<target.size(); i++){
623 05 Sep 06 peter 86       if (target.binary(i))
623 05 Sep 06 peter 87         positive.add(value.data(i),value.weight(i));
623 05 Sep 06 peter 88       else
623 05 Sep 06 peter 89         negative.add(value.data(i),value.weight(i));
623 05 Sep 06 peter 90     }
779 05 Mar 07 peter 91     return score(positive, negative, dof);
779 05 Mar 07 peter 92   }
623 05 Sep 06 peter 93
779 05 Mar 07 peter 94
4200 19 Aug 22 peter 95   double tScore::score(const classifier::Target& target,
1023 01 Feb 08 peter 96                        const utility::VectorBase& value,
1023 01 Feb 08 peter 97                        const utility::VectorBase& weight) const
779 05 Mar 07 peter 98   {
779 05 Mar 07 peter 99     return score(target, value, weight, NULL);
623 05 Sep 06 peter 100   }
623 05 Sep 06 peter 101
623 05 Sep 06 peter 102
4200 19 Aug 22 peter 103   double tScore::score(const classifier::Target& target,
1023 01 Feb 08 peter 104                        const utility::VectorBase& value,
1023 01 Feb 08 peter 105                        const utility::VectorBase& weight,
779 05 Mar 07 peter 106                        double* dof) const
112 07 Jul 04 peter 107   {
414 01 Dec 05 peter 108     statistics::AveragerWeighted positive;
414 01 Dec 05 peter 109     statistics::AveragerWeighted negative;
475 22 Dec 05 peter 110     for(size_t i=0; i<target.size(); i++){
514 20 Feb 06 peter 111       if (target.binary(i))
475 22 Dec 05 peter 112         positive.add(value(i),weight(i));
119 20 Jul 04 peter 113       else
475 22 Dec 05 peter 114         negative.add(value(i),weight(i));
119 20 Jul 04 peter 115     }
779 05 Mar 07 peter 116     return score(positive, negative, dof);
112 07 Jul 04 peter 117   }
98 10 Jun 04 peter 118
680 11 Oct 06 jari 119 }}} // of namespace statistics, yat, and theplu