source: src/main/java/weka/core/ManhattanDistance.java @ 18

Last change on this file since 18 was 4, checked in by gnappo, 14 years ago

Import di weka.

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 *    ManhattanDistance.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 Manhattan distance (or Taxicab geometry). The distance between two points is the sum of the (absolute) differences of their coordinates.<br/>
31 * <br/>
32 * For more information, see:<br/>
33 * <br/>
34 * Wikipedia. Taxicab geometry. URL http://en.wikipedia.org/wiki/Taxicab_geometry.
35 * <p/>
36 <!-- globalinfo-end -->
37 *
38 <!-- technical-bibtex-start -->
39 * BibTeX:
40 * <pre>
41 * &#64;misc{missing_id,
42 *    author = {Wikipedia},
43 *    title = {Taxicab geometry},
44 *    URL = {http://en.wikipedia.org/wiki/Taxicab_geometry}
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 ManhattanDistance
71  extends NormalizableDistance
72  implements TechnicalInformationHandler {
73 
74  /** for serialization. */
75  private static final long serialVersionUID = 6783782554224000243L;
76
77  /**
78   * Constructs an Manhattan Distance object, Instances must be still set.
79   */
80  public ManhattanDistance() {
81    super();
82  }
83
84  /**
85   * Constructs an Manhattan Distance object and automatically initializes the
86   * ranges.
87   *
88   * @param data        the instances the distance function should work on
89   */
90  public ManhattanDistance(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 Manhattan distance (or Taxicab geometry). The distance "
103      + "between two points is the sum of the (absolute) differences of their "
104      + "coordinates.\n\n"
105      + "For more information, see:\n\n"
106      + getTechnicalInformation().toString();
107  }
108
109  /**
110   * Returns an instance of a TechnicalInformation object, containing
111   * detailed information about the technical background of this class,
112   * e.g., paper reference or book this class is based on.
113   *
114   * @return            the technical information about this class
115   */
116  public TechnicalInformation getTechnicalInformation() {
117    TechnicalInformation        result;
118   
119    result = new TechnicalInformation(Type.MISC);
120    result.setValue(Field.AUTHOR, "Wikipedia");
121    result.setValue(Field.TITLE, "Taxicab geometry");
122    result.setValue(Field.URL, "http://en.wikipedia.org/wiki/Taxicab_geometry");
123
124    return result;
125  }
126 
127  /**
128   * Updates the current distance calculated so far with the new difference
129   * between two attributes. The difference between the attributes was
130   * calculated with the difference(int,double,double) method.
131   *
132   * @param currDist    the current distance calculated so far
133   * @param diff        the difference between two new attributes
134   * @return            the update distance
135   * @see               #difference(int, double, double)
136   */
137  protected double updateDistance(double currDist, double diff) {
138    double      result;
139   
140    result  = currDist;
141    result += Math.abs(diff);
142   
143    return result;
144  }
145 
146  /**
147   * Returns the revision string.
148   *
149   * @return            the revision
150   */
151  public String getRevision() {
152    return RevisionUtils.extract("$Revision: 5953 $");
153  }
154}
Note: See TracBrowser for help on using the repository browser.