source: branches/MetisMQI/src/main/java/weka/core/ChebyshevDistance.java

Last change on this file was 29, checked in by gnappo, 14 years ago

Taggata versione per la demo e aggiunto branch.

File size: 4.5 KB
Line 
1/*
2 *    This program is free software; you can redistribute it and/or modify
3 *    it under the terms of the GNU General Public License as published by
4 *    the Free Software Foundation; either version 2 of the License, or
5 *    (at your option) any later version.
6 *
7 *    This program is distributed in the hope that it will be useful,
8 *    but WITHOUT ANY WARRANTY; without even the implied warranty of
9 *    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
10 *    GNU General Public License for more details.
11 *
12 *    You should have received a copy of the GNU General Public License
13 *    along with this program; if not, write to the Free Software
14 *    Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
15 */
16
17/*
18 *    ChebyshevDistance.java
19 *    Copyright (C) 2007 University of Waikato, Hamilton, New Zealand
20 *
21 */
22
23package weka.core;
24
25import weka.core.TechnicalInformation.Field;
26import weka.core.TechnicalInformation.Type;
27
28/**
29 <!-- globalinfo-start -->
30 * Implements the Chebyshev distance. The distance between two vectors is the greatest of their differences along any coordinate dimension.<br/>
31 * <br/>
32 * For more information, see:<br/>
33 * <br/>
34 * Wikipedia. Chebyshev distance. URL http://en.wikipedia.org/wiki/Chebyshev_distance.
35 * <p/>
36 <!-- globalinfo-end -->
37 *
38 <!-- technical-bibtex-start -->
39 * BibTeX:
40 * <pre>
41 * &#64;misc{missing_id,
42 *    author = {Wikipedia},
43 *    title = {Chebyshev distance},
44 *    URL = {http://en.wikipedia.org/wiki/Chebyshev_distance}
45 * }
46 * </pre>
47 * <p/>
48 <!-- technical-bibtex-end -->
49 *
50 <!-- options-start -->
51 * Valid options are: <p/>
52 *
53 * <pre> -D
54 *  Turns off the normalization of attribute
55 *  values in distance calculation.</pre>
56 *
57 * <pre> -R &lt;col1,col2-col4,...&gt;
58 *  Specifies list of columns to used in the calculation of the
59 *  distance. 'first' and 'last' are valid indices.
60 *  (default: first-last)</pre>
61 *
62 * <pre> -V
63 *  Invert matching sense of column indices.</pre>
64 *
65 <!-- options-end -->
66 *
67 * @author Fracpete (fracpete at waikato dot ac dot nz)
68 * @version $Revision: 5953 $
69 */
70public class ChebyshevDistance
71  extends NormalizableDistance
72  implements TechnicalInformationHandler {
73 
74  /** for serialization. */
75  private static final long serialVersionUID = -7739904999895461429L;
76
77  /**
78   * Constructs an Chebyshev Distance object, Instances must be still set.
79   */
80  public ChebyshevDistance() {
81    super();
82  }
83
84  /**
85   * Constructs an Chebyshev Distance object and automatically initializes the
86   * ranges.
87   *
88   * @param data        the instances the distance function should work on
89   */
90  public ChebyshevDistance(Instances data) {
91    super(data);
92  }
93
94  /**
95   * Returns a string describing this object.
96   *
97   * @return            a description of the evaluator suitable for
98   *                    displaying in the explorer/experimenter gui
99   */
100  public String globalInfo() {
101    return 
102        "Implements the Chebyshev distance. The distance between two vectors "
103      + "is the greatest of their differences along any coordinate dimension.\n\n"
104      + "For more information, see:\n\n"
105      + getTechnicalInformation().toString();
106  }
107
108  /**
109   * Returns an instance of a TechnicalInformation object, containing
110   * detailed information about the technical background of this class,
111   * e.g., paper reference or book this class is based on.
112   *
113   * @return            the technical information about this class
114   */
115  public TechnicalInformation getTechnicalInformation() {
116    TechnicalInformation        result;
117   
118    result = new TechnicalInformation(Type.MISC);
119    result.setValue(Field.AUTHOR, "Wikipedia");
120    result.setValue(Field.TITLE, "Chebyshev distance");
121    result.setValue(Field.URL, "http://en.wikipedia.org/wiki/Chebyshev_distance");
122
123    return result;
124  }
125 
126  /**
127   * Updates the current distance calculated so far with the new difference
128   * between two attributes. The difference between the attributes was
129   * calculated with the difference(int,double,double) method.
130   *
131   * @param currDist    the current distance calculated so far
132   * @param diff        the difference between two new attributes
133   * @return            the update distance
134   * @see               #difference(int, double, double)
135   */
136  protected double updateDistance(double currDist, double diff) {
137    double      result;
138   
139    result = currDist;
140   
141    diff = Math.abs(diff);
142    if (diff > result)
143      result = diff;
144   
145    return result;
146  }
147 
148  /**
149   * Returns the revision string.
150   *
151   * @return            the revision
152   */
153  public String getRevision() {
154    return RevisionUtils.extract("$Revision: 5953 $");
155  }
156}
Note: See TracBrowser for help on using the repository browser.