Professional Documents
Culture Documents
java
1: /*
2: * Copyright: Denny Hermawanto - 2006
3: * Mail: d_3_nny@yahoo.com
4: */
5:
6: public class Kohonen{
7:
8: private void DefineInput(){
9: inputvector = new double[numberofinput][inputdimension];
10:
11: inputvector[0][0] = 1;
12: inputvector[0][1] = 1;
13: inputvector[0][2] = 0;
14: inputvector[0][3] = 0;
15:
16: inputvector[1][0] = 0;
17: inputvector[1][1] = 0;
18: inputvector[1][2] = 0;
19: inputvector[1][3] = 1;
20:
21: inputvector[2][0] = 0;
22: inputvector[2][1] = 0;
23: inputvector[2][2] = 1;
24: inputvector[2][3] = 0;
25:
26: inputvector[3][0] = 1;
27: inputvector[3][1] = 1;
28: inputvector[3][2] = 0;
29: inputvector[3][3] = 0;
30: }
31:
32: private double RandomNumberGenerator(){
33: java.util.Random rnd = new java.util.Random();
34: return rnd.nextDouble();
35: }
36:
37: private double LearningRateDecay(double currentlearningrate){
38: double result = 0;
39: result = 0.8 * currentlearningrate;
40: return result;
41: }
42:
43: private void InitializeWeigths(){
44: weights = new double[numberofcluster][inputdimension];
45: for(int i=0;i<numberofcluster;i++){
46: for(int j=0;j<inputdimension;j++){
47: weights[i][j] = RandomNumberGenerator();
48: }
49: }
50: }
51:
52: private double ComputeEuclideanDistance(double[] vector1, double[]
vector2){
53: double result;
54: double distance =0;
55: for(int j=0;j<inputdimension;j++){
56: distance += Math.pow((vector1[j] - vector2[j]), 2);
57: }
58: result = distance;
59: return result;
60: }
61:
62: private void TrainKohonen(int maxiteration){
63: euclideandistance = new double[numberofcluster];
64:
65: for(int iter=0;iter<maxiteration;iter++){