xxxx18一60岁hd中国/日韩女同互慰一区二区/西西人体扒开双腿无遮挡/日韩欧美黄色一级片 - 色护士精品影院www

資源簡介

使用純java實(shí)現(xiàn)KMeans模擬算法代碼,隨即撒點(diǎn),計(jì)算K個(gè)聚類,使用了javaFX繪圖工具包,結(jié)果有散點(diǎn)圖的顯示

資源截圖

代碼片段和文件信息

package?kmeans;
import?javafx.application.Application;
import?javafx.collections.FXCollections;
import?javafx.collections.ObservableList;
import?javafx.scene.Scene;
import?javafx.scene.chart.CategoryAxis;
import?javafx.scene.chart.NumberAxis;
import?javafx.scene.chart.ScatterChart;
import?javafx.scene.chart.XYChart;
import?javafx.scene.chart.XYChart.Series;
import?javafx.scene.layout.StackPane;
import?javafx.stage.Stage;

import?java.util.ArrayList;
import?java.util.Vector;

import?javafx.collections.FXCollections;
import?javafx.collections.ObservableList;
import?javafx.scene.Scene;
import?javafx.scene.chart.CategoryAxis;
import?javafx.scene.chart.NumberAxis;
import?javafx.scene.chart.ScatterChart;
import?javafx.scene.chart.XYChart;
import?javafx.scene.chart.XYChart.Series;
import?javafx.scene.layout.StackPane;
import?javafx.stage.Stage;
//隨機(jī)選取若干個(gè)聚類,計(jì)算所有點(diǎn)到這些聚類的距離,取最小值屬于該類
//分類后將每個(gè)類所有點(diǎn)取均值,算該類的中心點(diǎn),隨后對所有點(diǎn)再次計(jì)算歐氏距離,再次分類
//迭代到每個(gè)中心點(diǎn)不變?yōu)橹?br/>//生成指定個(gè)數(shù)和維數(shù)的隨機(jī)向量
public?class?KMeans?extends?Application{
static?ArrayList>?vectorList?;//向量組
static?Vector?center1?;//中心1
static?Vector?center2?;//中心2
static?ArrayList>??cluster1;//聚類1
static?ArrayList>??cluster2;//聚類2

static?double?threshold?=?0.01;
public?void?showVectorGroup(ArrayList>?vectorList?int?vectorNum?int?dim)?{
for(int?i=0;i for(int?j=0;j System.out.print(vectorList.get(i).get(j)+“?“);
}
System.out.println();
}
}

public?static?ArrayList>??generateVectorGroup(int?vectorNum?int?dim)?{
ArrayList>?vectorList?=?new?ArrayList>();
//隨機(jī)填充向量組
for(int?i=0;i Vector?vTemp?=?new?Vector<>();
for(int?j=0;j double?randomTemp?=?Math.random()*100-30;
vTemp.add((randomTemp)<0?(randomTemp+Math.random()*40):(randomTemp));
}vectorList.add(vTemp);//講向量加入向量組中
}
//增加偏置因子讓數(shù)據(jù)更好的顯示類別
for(int?i=0;i Vector?vTemp?=?new?Vector<>();
for(int?j=0;j double?randomTemp?=?Math.random()*100+30;
vTemp.add((randomTemp)>100?(randomTemp-Math.random()*40):(randomTemp));
}vectorList.add(vTemp);//講向量加入向量組中
}
return?vectorList;
}

//計(jì)算向量的歐式距離
public?static?double?calculationVectorDistance(Vector?v1Vector?v2?int?dim)?{
double?distance?=?0.0;
for(int?i=0;i distance?+=?Math.pow((v1.get(i)-v2.get(i))2);
}
return?Math.sqrt(distance);
}

//聚類方法
public?static?void?doCluster()?{

}

//計(jì)算聚類的中心
public?static?Vector?computeCenter(ArrayList>?cluster?int?dim){
Vector?center?=?new?Vector<>();
for(int?i=0;i double?calculate?=?0.0;
for(int?j=0;j calculate+=cluster.get(j).get(i);
}
c

評論

共有 條評論

相關(guān)資源