View Javadoc

1   /*
2    * Copyright (C) 2004 Christian Siefkes <christian@siefkes.net>.
3    * Development of this software is supported by the German Research Society,
4    * Berlin-Brandenburg Graduate School in Distributed Information Systems
5    * (DFG grant no. GRK 316).
6    *
7    * This library is free software; you can redistribute it and/or
8    * modify it under the terms of the GNU Lesser General Public
9    * License as published by the Free Software Foundation; either
10   * version 2.1 of the License, or (at your option) any later version.
11   *
12   * This library is distributed in the hope that it will be useful,
13   * but WITHOUT ANY WARRANTY; without even the implied warranty of
14   * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
15   * Lesser General Public License for more details.
16   *
17   * You should have received a copy of the GNU Lesser General Public
18   * License along with this library; if not, visit
19   * http://www.gnu.org/licenses/lgpl.html or write to the Free Software
20   * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307, USA.
21   */
22  package de.fu_berlin.ties.classify.winnow;
23  
24  import org.apache.commons.lang.builder.ToStringBuilder;
25  
26  import de.fu_berlin.ties.classify.PredictionDistribution;
27  
28  /***
29   * A distribution over the classes predicted by a
30   * {@link de.fu_berlin.ties.classify.winnow.Winnow Winnow classifier}.
31   * Extends the superclass by also storing the
32   * {@linkplain de.fu_berlin.ties.classify.winnow.Winnow#threshold(float)
33   * threshold} and raw threshold used by Winnow for this instance.
34   *
35   * @author Christian Siefkes
36   * @version $Revision: 1.7 $, $Date: 2004/08/23 17:08:41 $, $Author: siefkes $
37   */
38  public class WinnowDistribution extends PredictionDistribution {
39  
40      /***
41       * The {@linkplain Winnow#threshold(float) threshold} used
42       * by the Winnow classifier for this instance.
43       */
44      private final float threshold;
45  
46      /***
47       * The {@linkplain Winnow#rawThreshold raw threshold} used
48       * by the Winnow classifier for this instance.
49       */
50      private final float rawThreshold;
51  
52      /***
53       * Creates a new instance.
54       * @param theta the {@linkplain Winnow#threshold(float) threshold}
55       * used by Winnow
56       * @param rawTheta the {@linkplain Winnow#rawThreshold raw
57       * threshold} used by Winnow
58       */
59      public WinnowDistribution(final float theta, final float rawTheta) {
60          super();
61          threshold = theta;
62          rawThreshold = rawTheta;
63      }
64  
65      /***
66       * Returns the {@linkplain Winnow#rawThreshold raw threshold}
67       * used by the Winnow classifier for this instance.
68       * @return the value of the attribute
69       */
70      public float getRawThreshold() {
71          return rawThreshold;
72      }
73  
74      /***
75       * Returns the {@linkplain Winnow#threshold(float) threshold}
76       * used by the Winnow classifier for this instance.
77       * @return the value of the attribute
78       */
79      public float getThreshold() {
80          return threshold;
81      }
82  
83      /***
84       * Returns a string representation of this object.
85       *
86       * @return a textual representation
87       */
88      public String toString() {
89          final ToStringBuilder builder = new ToStringBuilder(this)
90              .appendSuper(super.toString())
91              .append("threshold", threshold);
92  
93          // omit raw threshold if equal to threshold
94          if (rawThreshold != threshold) {
95              builder.append("raw threshold", rawThreshold);
96          }
97          return builder.toString();
98      }
99  
100 }