<commit_before><!DOCTYPE html><html lang='en'><head>
	<meta charset='utf-8'>
	<meta http-equiv='X-UA-Compatible' content='IE=edge'>
	<meta name='viewport' content='width=device-width, initial-scale=1'>
	
	<title>EJS K-Means Clustering</title>
	<meta name='description' content='Penerapan K-Means Clustering' />
	<meta name='keywords' content='K-Means Clustering,K-Means Algorithm' />
	<meta name='distribution' content='Global' />
	<meta name='author' content='<NAME>' />
	<meta name='Robots' content='index,follow' />
	
	<link rel='stylesheet' href='bootstrap.min.css'/>
	<script type='text/javascript' src='ejs_kmeans.js'></script>
	<script type='text/javascript' src='jquery-2.1.4.min.js'></script>
	<script type='text/javascript' src='bootstrap.min.js'></script>
</head><body><style type='text/css'>
.form_bg {
	background-color:#eee;
	color:#666;
	padding:20px;
	border-radius:10px;
	position: absolute;
	border:1px solid #fff;
	margin: auto;
	top: 0;
	right: 0;
	bottom: 0;
	left: 0;
	width: 320px;
	height: 280px;
}
</style>
<div class='container'>
	<div class='panel panel-primary'>
		<div class='panel-heading'><h3 class='text-center'>K-Means Clustering</h2></div>
		<div class='panel-body'>
			<p>Contoh Input Data : </p>
			<p>N Dimensions (n,m): 2,2</p>
			<p>Samples : 5.09,5.80,3.24,5.90,1.68,4.90,1.00,3.17,1.48,1.38,2.91,0.20,4.76,0.10,6.32,1.10,7.00,2.83,6.52,4.62</p>
			<p>Centroids : 1.48,1.38,4.76,0.10</p><br />
			<p>Keterangan :</p>
			<p>N Dimensions : Dimensi Array dari data samples dan centroids.<br />Contoh : N Dimension = 2,2, maka samples = [5.09,5.80],[3.24,5.90],[1.68,4.90],[1.00,3.17],[1.48,1.38],[2.91,0.20],[4.76,0.10],[6.32,1.10],[7.00,2.83],[6.52,4.62].<br />centroids = [[1.48,1.38],[4.76,0.10]]</p>
			<p>Samples : Data yang akan dipartisi</p>
			<p>Centroids (Optional) : Nilai awal set point pada tiap cluster, bila n,m dimensions 2,2 maka centroid haruslah berisi 2^n float number (4 angka) seperti contoh diatas. Bila tidak diisi, maka centroid akan diambil dari nilai awal samples.<br />Contoh bila N Dimensions : 2,3 maka samples akan sample 2 dimensi dan centroid 3 dimensi [[5.09,5.80],[3.24,5.90],[1.68,4.90]]</p>
			<h3>Masukkan sumber data</h3>
			<div class='row'>
				<div class='col-xs-4 col-sm-4'>
					<input name='txt_dim' type='text' class='form-control' placeholder='N Dimensions...'>
				</div>
				<div class='col-xs-4 col-sm-4'>
					<input name='txt_samples' type='text' class='form-control' placeholder='Samples...'>
				</div>
				<div class='col-xs-4 col-sm-4'>
					<div class='input-group'>
						<input name='txt_centroids' type='text' class='form-control' placeholder='Centroids...'>
						<span class='input-group-btn'>
							<button id='btn_hitung' class='btn btn-default' type='button'>Hitung !!!</button>
						</span>
					</div>
				</div>
			</div>
			<br />
			<p id='samples'></p>
			<p id='result'></p>
		</div>
		<div class='panel-footer text-center'>Created By <NAME></div>
	</div>
</div>

<script>
	$(function(){		
		$('#btn_hitung').click(function(){
			var dim = $('[name="txt_dim"]').val().replace(/ +/g,'').split(',');
			var str = $('[name="txt_samples"]').val().replace(/ +/g,'');
			
			if(dim === '' || str === '' || dim === ' ' || str === ' '){
				alert('N Dimensions dan Samples harus diisi !!!');
				return;
			}
			
			var str_centroid = $('[name="txt_centroids"]').val().replace(/ +/g,'');
			var buff = str.split(',');
			var samples = [],centroids = [],tmp = [];
			for(i=0;i<buff.length;i++){
				if(i != 0 && (i%dim[0] == 0)){
					samples.push(tmp);
					tmp = [];
					tmp.push(parseFloat(buff[i]));
				}else{
					tmp.push(parseFloat(buff[i]));
				}
			}
			samples.push(tmp);
			if(str_centroid.length > 0 && (str_centroid != '' || str_centroid != ' ')){
				tmp = [];
				buff = str_centroid.split(',');
				if(buff.length%dim[1] != 0){
					alert('Dimensi m : '+dim[1]+' tidak sesuai dengan jumlah data centroid. Jumlah data haruslah 2*'+dim[1]+' bukan '+buff.length+' !!!');
					return;
				}
				for(i=0;i<buff.length;i++){
					if(i != 0 && (i%dim[0] == 0)){
						centroids.push(tmp);
						tmp = [];
						tmp.push(parseFloat(buff[i]));
					}else{
						tmp.push(parseFloat(buff[i]));
					}
				}
				centroids.push(tmp);
			}else{
				for(i=0;i<dim[1];i++){
					centroids.push(samples[i]);
					console.log('iterasi %d',i);
					console.log(samples[i]);
				}
			}
			console.log(samples);
			console.log(centroids);
			
			var k_means = new k_mean_cluster(samples);
			k_means.initialize(centroids);
			k_means.calculate();
			var res = k_means.result();
			var t = 'Samples Data : ('+samples.join(') (')+')<br /><br />';
			$('#samples').replaceWith('<p id="samples">'+t+'</p>');
			$('#result').replaceWith("<p id='result'>"+res+"</p>");
		});
		
		
		
		/*$('#username').focus();
		$('#password').keypress(function(e){
			if(e.which == 13 ){
				$("#btn_login").trigger("click");
			}
		});
		$('#btn_login').click(function(){
			var data = {
				user: $('#username').val(),
				pass: $('#password').val(),
				remember: $('[name="remember"]').is(':checked')
			};
			$.post('c_login/login', {data:JSON.stringify(data)}, function(res){
				var json = (res?JSON.parse(res):{success:false});
				if(json.success){
					$('[name="btn_login"]').find('.modal-body p').text(json.msg);
					$('[name="btn_login"]').modal('show');
					var redirect = 'welcome';
					window.location = redirect;
					// console.info(json);
				}else{
					$('[name="btn_login"]').modal('show');
				}
			});
		});*/
	});
</script>

</body>
</html><commit_msg>Add Validation<commit_after><!DOCTYPE html><html lang='en'><head>
	<meta charset='utf-8'>
	<meta http-equiv='X-UA-Compatible' content='IE=edge'>
	<meta name='viewport' content='width=device-width, initial-scale=1'>
	
	<title>EJS K-Means Clustering</title>
	<meta name='description' content='Penerapan K-Means Clustering' />
	<meta name='keywords' content='K-Means Clustering,K-Means Algorithm' />
	<meta name='distribution' content='Global' />
	<meta name='author' content='<NAME>' />
	<meta name='Robots' content='index,follow' />
	
	<link rel='stylesheet' href='bootstrap.min.css'/>
	<script type='text/javascript' src='ejs_kmeans.js'></script>
	<script type='text/javascript' src='jquery-2.1.4.min.js'></script>
	<script type='text/javascript' src='bootstrap.min.js'></script>
</head><body><style type='text/css'>
.form_bg {
	background-color:#eee;
	color:#666;
	padding:20px;
	border-radius:10px;
	position: absolute;
	border:1px solid #fff;
	margin: auto;
	top: 0;
	right: 0;
	bottom: 0;
	left: 0;
	width: 320px;
	height: 280px;
}
</style>
<div class='container'>
	<div class='panel panel-primary'>
		<div class='panel-heading'><h3 class='text-center'>K-Means Clustering</h2></div>
		<div class='panel-body'>
			<p>Contoh Input Data : </p>
			<p>N Dimensions (n,m): 2,2</p>
			<p>Samples : 5.09,5.80,3.24,5.90,1.68,4.90,1.00,3.17,1.48,1.38,2.91,0.20,4.76,0.10,6.32,1.10,7.00,2.83,6.52,4.62</p>
			<p>Centroids : 1.48,1.38,4.76,0.10</p><br />
			<p>Keterangan :</p>
			<p>N Dimensions : Dimensi Array dari data samples dan centroids.<br />Contoh : N Dimension = 2,2, maka samples = [5.09,5.80],[3.24,5.90],[1.68,4.90],[1.00,3.17],[1.48,1.38],[2.91,0.20],[4.76,0.10],[6.32,1.10],[7.00,2.83],[6.52,4.62].<br />centroids = [[1.48,1.38],[4.76,0.10]]</p>
			<p>Samples : Data yang akan dipartisi</p>
			<p>Centroids (Optional) : Nilai awal set point pada tiap cluster, bila n,m dimensions 2,2 maka centroid haruslah berisi 2^n float number (4 angka) seperti contoh diatas. Bila tidak diisi, maka centroid akan diambil dari nilai awal samples.<br />Contoh bila N Dimensions : 2,3 maka samples akan sample 2 dimensi dan centroid 3 dimensi [[5.09,5.80],[3.24,5.90],[1.68,4.90]]</p>
			<h3>Masukkan sumber data</h3>
			<div class='row'>
				<div class='col-xs-4 col-sm-4'>
					<input name='txt_dim' type='text' class='form-control' placeholder='N Dimensions...'>
				</div>
				<div class='col-xs-4 col-sm-4'>
					<input name='txt_samples' type='text' class='form-control' placeholder='Samples...'>
				</div>
				<div class='col-xs-4 col-sm-4'>
					<div class='input-group'>
						<input name='txt_centroids' type='text' class='form-control' placeholder='Centroids...'>
						<span class='input-group-btn'>
							<button id='btn_hitung' class='btn btn-default' type='button'>Hitung !!!</button>
						</span>
					</div>
				</div>
			</div>
			<br />
			<p id='samples'></p>
			<p id='result'></p>
		</div>
		<div class='panel-footer text-center'>Created By <NAME></div>
	</div>
</div>

<script>
	$(function(){		
		$('#btn_hitung').click(function(){
			var dim = $('[name="txt_dim"]').val().replace(/ +/g,'');
			var str = $('[name="txt_samples"]').val().replace(/ +/g,'');
			
			if(dim === '' || str === '' || dim === ' ' || str === ' '){
				alert('N Dimensions dan Samples harus diisi !!!');
				return;
			}else if(!dim.match(/[\d,.]/g) || !str.match(/[\d,.]/g)){
				alert('Data haruslah number atau float !!!');
				return;
			}
			dim = dim.split(',');
			var str_centroid = $('[name="txt_centroids"]').val().replace(/ +/g,'');
			var buff = str.split(',');
			var samples = [],centroids = [],tmp = [];
			for(i=0;i<buff.length;i++){
				if(i != 0 && (i%dim[0] == 0)){
					samples.push(tmp);
					tmp = [];
					tmp.push(parseFloat(buff[i]));
				}else{
					tmp.push(parseFloat(buff[i]));
				}
			}
			samples.push(tmp);
			if(str_centroid.length > 0 && (str_centroid != '' || str_centroid != ' ')){
				if(!str_centroid.match(/[\d,.]/g)){
					alert('Data centroids haruslah number atau float !!!');
					return;
				}
				tmp = [];
				buff = str_centroid.split(',');
				if(buff.length%dim[1] != 0){
					alert('Dimensi m : '+dim[1]+' tidak sesuai dengan jumlah data centroid. Jumlah data haruslah 2*'+dim[1]+' bukan '+buff.length+' !!!');
					return;
				}
				for(i=0;i<buff.length;i++){
					if(i != 0 && (i%dim[0] == 0)){
						centroids.push(tmp);
						tmp = [];
						tmp.push(parseFloat(buff[i]));
					}else{
						tmp.push(parseFloat(buff[i]));
					}
				}
				centroids.push(tmp);
			}else{
				for(i=0;i<dim[1];i++){
					centroids.push(samples[i]);
					console.log('iterasi %d',i);
					console.log(samples[i]);
				}
			}
			console.log(samples);
			console.log(centroids);
			
			var k_means = new k_mean_cluster(samples);
			k_means.initialize(centroids);
			k_means.calculate();
			var res = k_means.result();
			var t = 'Samples Data : ('+samples.join(') (')+')<br /><br />';
			$('#samples').replaceWith('<p id="samples">'+t+'</p>');
			$('#result').replaceWith("<p id='result'>"+res+"</p>");
		});
	});
</script>

</body>
</html>
{'fraction_non_alphanumeric': 0.23776815957847197, 'fraction_numerical': 0.042152803914188935, 'mean_word_length': 3.6989389920424403, 'pattern_counts': {'":': 0, '<': 193, '<?xml version=': 0, '>': 189, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '6974534', 'n_tokens_mistral': 5050, 'n_tokens_neox': 4185, 'n_words': 737}