Silvia Rădulescu

Trace:

Differences

This shows you the differences between two versions of the page.

Link to this comparison view

Both sides previous revisionPrevious revision
Next revision
Previous revision
shannon_entropy_calculator [2015/02/03 17:23] silviashannon_entropy_calculator [2015/04/20 15:06] (current) – external edit 127.0.0.1
Line 1: Line 1:
-<CSS> span.entropy_small { font-size: 0.7em; color: #888888; } pre.entropy { font-size: 1em; font-family: "Lucida Console", Monaco, monospace; } pre.entropy_smaller { font-size: 0.8em; font-family: "Lucida Console", Monaco, monospace; } input.entropy, textarea.entropy { font-size: 1.1em; font-family: "Lucida Grande", sans-serif; width: 80%; } </CSS> <HTML> <textarea type="text" name="expr" id="expr" rows="3" class="entropy"></textarea> <br> <span class="entropy_small">* use STRING SPACE COUNT, separated by comma, eg. abc 3, def 4</span> <p> <pre id="result" name="result" class="entropy">H = </pre> <pre id="detail1" name="detail1" class="entropy_smaller"></pre> <pre id="detail2" name="detail2" class="entropy_smaller"></pre> </pre> </HTML> <JS> function setCookie(cname, cvalue, exdays) { +===== Shannon Entropy Calculator ===== 
- +<PRELOAD> 
-<code> +./lib/scripts/jquery/jquery.min.js 
-var d = new Date(); +</PRELOAD> 
-d.setTime(d.getTime() + (exdays*24*60*60*1000)); +<CSS> 
-var expires = "expires="+d.toUTCString(); +span.entropy_small { font-size: 0.7em; color: #888888; } 
-document.cookie = cname + "=" + cvalue + "; " + expires+pre.entropy { font-size: 1em; font-family: "Lucida Console", Monaco, monospace; } 
-</code> +pre.entropy_smaller { font-size: 0.8em; font-family: "Lucida Console", Monaco, monospace; } 
- +input.entropy, textarea.entropy { font-size: 1.1em; font-family: "Lucida Grande", sans-serif; width: 80%; } 
-} function getCookie(cname) { +</CSS> 
- +<HTML> 
-<code> +<textarea type="text" name="expr" id="expr" rows="3" class="entropy"></textarea> 
-var name = cname + "="; +<br> 
-var ca = document.cookie.split(';'); +<span class="entropy_small">* use STRING SPACE COUNT, separated by comma, eg. abc 3, def 4</span> 
-for(var i=0; i<ca.length; i++) { +<p> 
-    var c = ca[i]; +<pre id="result" name="result" class="entropy">H = ...</pre> 
-    while (c.charAt(0)==' ') c = c.substring(1); +<pre id="detail1" name="detail1" class="entropy_smaller">...</pre> 
-    if (c.indexOf(name) == 0) return c.substring(name.length,c.length);+<pre id="detail2" name="detail2" class="entropy_smaller">...</pre> 
 +</pre> 
 +</HTML> 
 +<JS> 
 +function setCookie(cname, cvalue, exdays) { 
 +  var d = new Date(); 
 +  d.setTime(d.getTime() + (exdays*24*60*60*1000)); 
 +  var expires = "expires="+d.toUTCString(); 
 +  document.cookie = cname + "=" + cvalue + "; " + expires;
 } }
-return ""; +function getCookie(cname) { 
-</code> +  var name cname + "="; 
- +  var ca = document.cookie.split(';'); 
-function unrtrim (str, max) { +  for(var i=0; i<ca.lengthi++{ 
- +      var ca[i]; 
-<code> +      while (c.charAt(0)==' 'c = c.substring(1); 
-str str.toString(); +      if (c.indexOf(name) == 0return c.substring(name.length,c.length);
-return str.length <max ? unrtrim(str + " ", max) : str; +
-</code> +
- +
-} function unltrim (str, max) { +
- +
-<code> +
-str str.toString(); +
-return str.length <max ? unltrim(" + str, max) : str+
-</code> +
- +
-var re /(.*) ([0-9]+)/; $( document ).ready(function() { +
- +
-<code> +
-  $("#expr").keyup(function () { +
-      var parts = $(this).val().split(','); +
-      var values = {}; +
-      var sum = 0; +
-      var num_values = 0; +
-      $('#result').text(""); +
-      $('#detail1').text(""); +
-      $('#detail2').text(""); +
-      $.each(parts, function (index, value) { +
-          value = value.trim(); +
-          var matches re.exec(value); +
-          if (matches) { +
-              if (values[matches[1]]) { +
-                  $('#detail2').append(unltrim((index + 1), 3) + ". ERROR! Value \"" + matches[1] + "\" was already used.\n")+
-              } else { +
-                  $('#detail2').append(unltrim((index + 1), 3) + ". " + unrtrim(matches[1], 12) + ' * ' + unltrim(matches[2], 3) + "\n"); +
-                  values[matches[1]] matches[2]; +
-                  sum +parseInt(matches[2]); +
-                  num_values++; +
-              } +
-          } else { +
-              $('#detail2').append(unltrim((index + 1), 3) + ". ERROR! Value has invalid format.\n"); +
-          } +
-      }); +
-      var h = 0; +
-      $.each(values, function(index, value) { +
-          var p = value / sum; +
-          var l = Math.log(p/ Math.log(2); +
-          h -(p * l); +
-      }); +
-      $('#result').append("" + h); +
-      $('#detail1').append(num_values + " valid values"); +
-      if (parts.length != num_values) { +
-          $('#detail1').append("" + (parts.length - num_values) + " ERRORs"); +
-      } +
-      setCookie("expr", $("#expr").val(), 365); +
-  }); +
-  if ($("#expr").val() == "") { +
-      $("#expr").val(getCookie("expr"));+
   }   }
-  $("#expr").trigger('keyup'); +  return ""; 
-</code>+
 +function unrtrim (str, max) { 
 +  str = str.toString(); 
 +  return str.length < max ? unrtrim(str + " ", max) : str; 
 +
 +function unltrim (str, max) { 
 +  str = str.toString(); 
 +  return str.length < max ? unltrim(" " + str, max) : str; 
 +
 +var re = /(.*) ([0-9]+)/; 
 +$( document ).ready(function() { 
 +    $("#expr").keyup(function () { 
 +        var parts = $(this).val().split(','); 
 +        var values = {}; 
 +        var sum = 0; 
 +        var num_values = 0; 
 +        $('#result').text(""); 
 +        $('#detail1').text(""); 
 +        $('#detail2').text(""); 
 +        $.each(parts, function (index, value) { 
 +            value = value.trim(); 
 +            var matches = re.exec(value); 
 +            if (matches) { 
 +                if (values[matches[1]]) { 
 +                    $('#detail2').append(unltrim((index + 1), 3) + ". ERROR! Value \"" + matches[1] + "\" was already used.\n"); 
 +                } else { 
 +                    $('#detail2').append(unltrim((index + 1), 3) + ". " + unrtrim(matches[1], 12) + ' * ' + unltrim(matches[2], 3) + "\n"); 
 +                    values[matches[1]] = matches[2]; 
 +                    sum += parseInt(matches[2]); 
 +                    num_values++; 
 +                } 
 +            } else { 
 +                $('#detail2').append(unltrim((index + 1), 3) + ". ERROR! Value has invalid format.\n"); 
 +            } 
 +        }); 
 +        var h = 0; 
 +        $.each(values, function(index, value) { 
 +            var p = value / sum; 
 +            var l = Math.log(p) / Math.log(2); 
 +            h -= (p * l); 
 +        }); 
 +        $('#result').append("H = " + h); 
 +        $('#detail1').append(num_values + " valid values"); 
 +        if (parts.length != num_values) { 
 +            $('#detail1').append(", " + (parts.length - num_values) + " ERRORs"); 
 +        } 
 +        setCookie("expr", $("#expr").val(), 365); 
 +    }); 
 +    if ($("#expr").val() == "") { 
 +        $("#expr").val(getCookie("expr")); 
 +    } 
 +    $("#expr").trigger('keyup'); 
 +}); 
 +</JS>
  
-}); </JS>