Skip to content

Instantly share code, notes, and snippets.

@KucherenkoIhor
Created December 18, 2016 16:23
Show Gist options
  • Save KucherenkoIhor/5f70f8be22cb161c39add3c5267c3ca8 to your computer and use it in GitHub Desktop.
Save KucherenkoIhor/5f70f8be22cb161c39add3c5267c3ca8 to your computer and use it in GitHub Desktop.
double kf = 0.5;
int [] nObr = new int[samples.length];
while(kf >= 0.1) {
for (int i = 0; i < samples.length; i++) {
//1. Извлечение образца из матрицы образцов
double[] sample = samples[i];
//2. Цикл по номерам кластеров
double[] distance = new double[clusterCount];
for (int j = 0; j < clusterCount; j++) {
distance[j] = 0.0;
//2.1. Вычисление меры приближения
for (int k = 0; k < coordinatesCount; k++) {
distance[j] = distance[j] + Math.pow((sample[k] - weightMatrix[j][k]), 2);
}
}
//2.2. Определение номера кластера
double distanceMin = minFromArray(distance);
int index = 0;
for (int j = 0; j < clusterCount; j++) {
if (distance[j] == distanceMin) {
index = j;
}
}
nObr[i] = index;
//3. Пересчет координат центра кластера
for (int j = 0; j < coordinatesCount; j++) {
weightMatrix[index][j] = weightMatrix[index][j] + kf * (sample[j] - weightMatrix[index][j]);
}
}
kf = kf * 0.5;
}
for (int i = 0; i < nObr.length; i++) {
switch (nObr[i]) {
case 0: {
firstCluster.add(original[i]);
break;
}
case 1: {
secondCluster.add(original[i]);
break;
}
case 2: {
thirdCluster.add(original[i]);
break;
}
case 3: {
fourthCluster.add(original[i]);
break;
}
case 4: {
fifthCluster.add(original[i]);
break;
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment