Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- WSH.echo('Type str in console');
- var str = WScript.StdIn.ReadLine();
- var alf = new Array();
- /*Initialization*/
- for (var i = 0; i < str.length; i++){
- alf[str.charAt(i)] = 0;
- }
- /*frq calc*/
- for (var i = 0; i < str.length; i++){
- alf[str.charAt(i)]++;
- }
- var sum = 0.0;
- var entropy = 0.0;
- var n = 0;
- for (i in alf){
- sum += alf[i];
- n++;
- }
- //WSH.echo(alf.length);
- for (i in alf){
- alf[i] = alf[i]/sum;
- }
- if (n>1)
- for (i in alf){
- entropy += (alf[i])*((Math.log(alf[i]))/(Math.log(n)));
- }
- else
- entropy = -1;
- entropy *= -1;
- if (str.length == 0)
- WSH.echo("str is null");
- else
- WSH.echo(entropy);
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement