复制代码 代码如下:
<!doctype html>
<html>
<head>
<meta charset="utf-8">
<meta http-equiv="X-UA-Compatible" content="IE=7, IE=9, IE=10">
<meta name="viewport"
content="initial-scale=1, maximum-scale=1,user-scalable=no">
<title>自然分类法算法</title>
<script>
function getJenksBreaks(data,numclass) {
function sortNumber(a,b)//在javascript里,Array的sort方法,必须用这个函数,否则不是按数字大小排序
{
return a - b
}
// int numclass;
var numdata = data.length;
data.sort(sortNumber); //先排序
var mat1=new Array();
var mat2=new Array();
var st=new Array();
for (var j = 0; j <= numdata; j++){
mat1[j]=new Array();
mat2[j]=new Array();
st[j]=0;
for(var i=0;i<=numclass;i++){
mat1[j][i]=0;
mat2[j][i]=0;
}
}
for (var i = 1; i <= numclass; i++) {
mat1[1][i] = 1;
mat2[1][i] = 0;
for (var j = 2; j <= numdata; j++){
mat2[j][i]=Number.MAX_VALUE;
}
}
var v=0;
for (var l = 2; l <= numdata; l++) {
var s1=0;
var s2=0;
var w=0;
var i3=0;
for (var m = 1; m <= l; m++) {
i3 = l - m + 1;
var val=parseInt(data[i3-1]);
s2 += val * val;
s1 += val;
w++;
v = s2 - (s1 * s1) / w;
var i4 = i3 - 1;
if (i4 != 0) {
for (var j = 2; j <= numclass; j++) {
if (mat2[l][j] >= (v + mat2[i4][j - 1])) {
mat1[l][j] = i3;
mat2[l][j] = v + mat2[i4][j - 1];
if(l==200&&j==5) alert("l="+200+",j="+5+";mat2[200][5]="+mat1[l][j]+"i3="+i3);
}
}
}
}
mat1[l][1] = 1;
mat2[l][1] = v;
}
var k = numdata;
var kclass=new Array();
/* int[] kclass = new int[numclass]; */
kclass[numclass - 1] = parseInt(data[data.length-1]);
/* kclass[numclass - 1] = (Integer) data.get(data.size() - 1); */
for (var j = numclass; j >= 2; j--) {
var id = parseInt(mat1[k][j]) - 2;
kclass[j - 2] = parseInt( data[id]);
k = parseInt( mat1[k][j] - 1);
}
return kclass;
}
function doit(){
var data = new Array( 9, 9, 9, 9, 8, 1, 9, 7, 6, 7, 10, 7, 7, 8, 5, 7, 8, 2,
6, 6, 9, 10, 2, 2, 3, 9, 9, 1, 9, 1, 6, 7, 1, 9, 6, 5, 2, 8, 6,
6, 6, 4, 1, 4, 10, 9, 6, 9, 9, 7, 10, 9, 6, 6, 6, 9, 3, 2, 5,
10, 3, 9, 6, 1, 2, 1, 2, 7, 5, 2, 6, 6, 2, 7, 9, 9, 5, 4, 6, 4,
1, 1, 5, 1, 4, 4, 2, 6, 9, 7, 3, 10, 4, 4, 9, 5, 5, 3, 5, 3,
161, 136, 22, 113, 48, 114, 166, 33, 159, 182, 135, 22, 174,
191, 60, 176, 1, 155, 62, 142, 185, 84, 140, 27, 111, 176, 189,
24, 60, 29, 139, 20, 70, 172, 90, 120, 121, 173, 57, 138, 86,
180, 143, 155, 35, 10, 136, 158, 26, 29, 136, 97, 193, 194,
104, 147, 182, 44, 84, 139, 176, 16, 130, 168, 109, 182, 87,
78, 115, 75, 32, 88, 131, 168, 89, 25, 160, 60, 72, 92, 129,
159, 99, 5, 192, 6, 53, 15, 62, 176, 73, 129, 128, 34, 190, 95,
19, 19, 196, 30 );
/* var list = new Array();
for(int i = 0; i < data.length; i++){
list.add(data[i]);
} */
//Collections.sort(list);
var text=document.getElementById("text");
text.value="";
var grade = getJenksBreaks(data, 5);
for (var i = 0; i < grade.length; i++)
text.value=text.value+grade[i]+",";
}
</script>
</head>
<body >
<button type="button"onclick="doit()">自然分类法</button>
<input id="text"></input>
</body>
</html>
免责声明:本站资源来自互联网收集,仅供用于学习和交流,请遵循相关法律法规,本站一切资源不代表本站立场,如有侵权、后门、不妥请联系本站删除!
更新日志
- 凤飞飞《我们的主题曲》飞跃制作[正版原抓WAV+CUE]
- 刘嘉亮《亮情歌2》[WAV+CUE][1G]
- 红馆40·谭咏麟《歌者恋歌浓情30年演唱会》3CD[低速原抓WAV+CUE][1.8G]
- 刘纬武《睡眠宝宝竖琴童谣 吉卜力工作室 白噪音安抚》[320K/MP3][193.25MB]
- 【轻音乐】曼托凡尼乐团《精选辑》2CD.1998[FLAC+CUE整轨]
- 邝美云《心中有爱》1989年香港DMIJP版1MTO东芝首版[WAV+CUE]
- 群星《情叹-发烧女声DSD》天籁女声发烧碟[WAV+CUE]
- 刘纬武《睡眠宝宝竖琴童谣 吉卜力工作室 白噪音安抚》[FLAC/分轨][748.03MB]
- 理想混蛋《Origin Sessions》[320K/MP3][37.47MB]
- 公馆青少年《我其实一点都不酷》[320K/MP3][78.78MB]
- 群星《情叹-发烧男声DSD》最值得珍藏的完美男声[WAV+CUE]
- 群星《国韵飘香·贵妃醉酒HQCD黑胶王》2CD[WAV]
- 卫兰《DAUGHTER》【低速原抓WAV+CUE】
- 公馆青少年《我其实一点都不酷》[FLAC/分轨][398.22MB]
- ZWEI《迟暮的花 (Explicit)》[320K/MP3][57.16MB]