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
6
* http://www.opensource.org/licenses/bsd-license.php
8
* See the COPYRIGHT file distributed with this work for information
9
* regarding copyright ownership.
11
package ch.usi.inf.sape.hac.dendrogram;
13
import ch.usi.inf.sape.hac.ClusteringBuilder;
17
* A DendrogramBuilder creates a Dendrogram consisting of ObservationNodes and
20
* @author Matthias.Hauswirth@usi.ch
22
public final class DendrogramBuilder implements ClusteringBuilder {
24
private final DendrogramNode[] nodes;
25
private MergeNode lastMergeNode;
28
public DendrogramBuilder(final int nObservations) {
29
nodes = new DendrogramNode[nObservations];
30
for (int i = 0; i<nObservations; i++) {
31
nodes[i] = new ObservationNode(i);
35
public final void merge(final int i, final int j, final double dissimilarity) {
36
final MergeNode node = new MergeNode(nodes[i], nodes[j], dissimilarity);
41
public final Dendrogram getDendrogram() {
42
if (nodes.length==1) {
43
return new Dendrogram(nodes[0]);
45
return new Dendrogram(lastMergeNode);