1 package edu.psu.geovista.app.errormatrix;
2
3 import java.util.*;
4 public class comparevalues
5 {
6 public double[][] euclidianDistance(Vector metricVector)
7 {
8 Vector tempVector= new Vector();
9 Vector tVec = new Vector();
10 int len = metricVector.size();
11 double[][] value = new double[len][len];
12 for (int i =0; i< len; i++)
13 {
14 tempVector = (Vector)metricVector.elementAt(i);
15 for (int j = 0; j< len; j++)
16 {
17 tVec = (Vector)metricVector.elementAt(j);
18 value[i][j] = calculatedistance(tempVector, tVec);
19 }
20
21 }
22 return value;
23 }
24 public double calculatedistance(Vector refer, Vector test)
25 {
26 double val = 0.0;
27 double temp;
28 if(refer.size()==test.size())
29 {
30 for (int i = 0; i< refer.size(); i++)
31 {
32 temp = ((Double)refer.elementAt(i)).doubleValue() - ((Double)test.elementAt(i)).doubleValue();
33 temp = temp* temp;
34 val += temp;
35 }
36 //find the square root
37 val = java.lang.Math.sqrt(val);
38 }
39 else
40 {
41 val = 0;
42 }
43 return val;
44 }
45 public double clusterdiameter(double[][] eucliddis)
46 {
47 double value= 0.0;
48 double modevalue;
49 double[] temp = new double[eucliddis.length-1];
50 for (int i = 0;i< eucliddis.length; i++)
51 {
52 for (int j = 0; j < eucliddis.length; j++)
53 {
54 if (j<i)
55 {
56 // check if this is correct.. if not put the two statements in the other options
57 temp[j]= eucliddis[i][j];
58 }
59 else if(i> j)
60 {
61 temp[j-1]= eucliddis[i][j];
62 }
63 }
64
65 for (int firstcount = 0; firstcount < temp.length-1; firstcount++)
66 {
67 for (int count = firstcount+1; count < temp.length; count++)
68 {
69 if (temp[firstcount] > temp[count])
70 {
71 //swap the two locations.
72 double t = temp[firstcount];
73 temp[firstcount] = temp[count];
74 temp[count] = t;
75 }
76 }
77 }
78
79 int n = temp.length;
80 //check if it is an even number
81 if (n== 0)
82 {
83 //calculate the mod of a set of n numbers where n is even
84
85 modevalue=(temp[(int)((double)(n/2)-0.5)] +temp[(int)((double)(n/2)+0.5)])/2;
86 }
87 else
88 {
89 // calculate the mod of a set of n numbers where n is odd
90
91 modevalue=temp[(int)n/2];
92 }
93 value += modevalue;
94 }
95 value = (value/(eucliddis.length));
96 return value;
97
98 }
99
100 }
This page was automatically generated by Maven