~ubuntu-branches/ubuntu/utopic/libhac-java/utopic

« back to all changes in this revision

Viewing changes to src/ch/usi/inf/sape/hac/agglomeration/CentroidLinkage.java

  • Committer: Package Import Robot
  • Author(s): Andreas Tille
  • Date: 2014-04-10 20:59:14 UTC
  • Revision ID: package-import@ubuntu.com-20140410205914-jul0jw261jyyy6nn
Tags: upstream-0.20110510
ImportĀ upstreamĀ versionĀ 0.20110510

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
/*
 
2
 * This file is licensed to You under the "Simplified BSD License".
 
3
 * You may not use this software except in compliance with the License. 
 
4
 * You may obtain a copy of the License at
 
5
 *
 
6
 * http://www.opensource.org/licenses/bsd-license.php
 
7
 * 
 
8
 * See the COPYRIGHT file distributed with this work for information
 
9
 * regarding copyright ownership.
 
10
 */
 
11
package ch.usi.inf.sape.hac.agglomeration;
 
12
 
 
13
 
 
14
/**
 
15
 * The "centroid" or "Unweighted Pair-Group Method using Centroids (UPGMC)" 
 
16
 * method is a geometric approach that links the centroids of clusters.
 
17
 * 
 
18
 * Each cluster is represented by its centroid.
 
19
 * The distance between two clusters is calculated as the distance between their centriods.
 
20
 * This method does not distort the cluster space.
 
21
 * [The data analysis handbook. By Ildiko E. Frank, Roberto Todeschini]
 
22
 *  
 
23
 * Can produce a dendrogram that is not monotonic
 
24
 * (it can have so called inversions, which are hard to interpret). 
 
25
 * This occurs when the distance from the union of two clusters, r and s, 
 
26
 * to a third cluster is less than the distance between r and s.
 
27
 * 
 
28
 * Used only for Euclidean distance!
 
29
 * 
 
30
 * The general form of the Lance-Williams matrix-update formula:
 
31
 * d[(i,j),k] = ai*d[i,k] + aj*d[j,k] + b*d[i,j] + g*|d[i,k]-d[j,k]|
 
32
 *
 
33
 * For the "centroid" method:
 
34
 * ai = ci/(ci+cj)
 
35
 * aj = cj/(ci+cj)
 
36
 * b  = -ci*cj/((ci+cj)*(ci+cj))
 
37
 * g  = 0
 
38
 * 
 
39
 * Thus:
 
40
 * d[(i,j),k] = ci/(ci+cj)*d[i,k] + cj/(ci+cj)*d[j,k] - ci*cj/((ci+cj)*(ci+cj))*d[i,j]
 
41
 *            = ( ci*d[i,k] + cj*d[j,k] - ci*cj/(ci+cj)*d[i,j] ) / (ci+cj)
 
42
 * 
 
43
 * @author Matthias.Hauswirth@usi.ch
 
44
 */
 
45
public final class CentroidLinkage implements AgglomerationMethod {
 
46
 
 
47
    public double computeDissimilarity(final double dik, final double djk, final double dij, final int ci, final int cj, final int ck) {
 
48
        return (ci*dik+cj*djk-ci*cj*dij/(ci+cj))/(ci+cj);
 
49
    }
 
50
 
 
51
    public String toString() {
 
52
        return "Centroid";
 
53
    }
 
54
 
 
55
}