JavaScript Natural taxonomy algorithm implements code _javascript techniques

Source: Internet
Author: User
Tags button type

Copy Code code as follows:

<!doctype html>
<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> Natural Taxonomy Algorithm </title>
<script>
function Getjenksbreaks (data,numclass) {
function Sortnumber (A,B)//In JavaScript, array's Sort method must use this function, otherwise it is not sorted by number size
{
Return A-b
}
int numclass;
var numdata = data.length;
Data.sort (Sortnumber); Sort first

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, ten, 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, 9, 6,, 9, 9, 7, 9, 6, 6, 6, 9,
3, 2, 5, 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, 4, 4, 9, 5, 5, 3, 5, 3,
161, 136, 166, 113, 159, 114, 135, 1, 174,
191, 60, 176,, 155, 62, 142, 185, 84, 140, 27, 111, 176, 189,
143, 155, 35, 10, 136, 158, 26, 29, 136, 97, 121, 172, 139, 173, 138, K, K., , 193, 194,
, 147, 139, 176, 130, MB, 109, 78, 75, 32, 88, 131, 168, 89, 25, 160, and 5, 129, 159, 128, 190, 129, 6, 176, and 196,
, and, of the same, in the same, at the same.

/* 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>

<body >
<button type= "button" onclick= "doit ()" > Natural Taxonomy </button>

<input id= "Text" ></input>
</body>

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.