Trace:
Differences
This shows you the differences between two versions of the page.
Next revision | Previous revision | ||
shannon_entropy_calculator [2015/02/03 17:13] – created silvia | shannon_entropy_calculator [2015/04/20 15:06] (current) – external edit 127.0.0.1 | ||
---|---|---|---|
Line 1: | Line 1: | ||
- | <code> | + | ===== Shannon Entropy Calculator ===== |
+ | <PRELOAD> | ||
+ | ./ | ||
+ | </ | ||
+ | < | ||
+ | span.entropy_small { font-size: 0.7em; color: #888888; } | ||
+ | pre.entropy { font-size: 1em; font-family: | ||
+ | pre.entropy_smaller { font-size: 0.8em; font-family: | ||
+ | input.entropy, | ||
+ | </CSS> | ||
< | < | ||
+ | < | ||
+ | < | ||
+ | <span class=" | ||
+ | <p> | ||
+ | <pre id=" | ||
+ | <pre id=" | ||
+ | <pre id=" | ||
+ | </ | ||
</ | </ | ||
- | </code> | + | < |
+ | function setCookie(cname, | ||
+ | var d = new Date(); | ||
+ | d.setTime(d.getTime() + (exdays*24*60*60*1000)); | ||
+ | var expires = " | ||
+ | document.cookie = cname + " | ||
+ | } | ||
+ | function getCookie(cname) { | ||
+ | var name = cname + " | ||
+ | var ca = document.cookie.split(';' | ||
+ | for(var i=0; i< | ||
+ | var c = ca[i]; | ||
+ | while (c.charAt(0)==' | ||
+ | if (c.indexOf(name) == 0) return c.substring(name.length, | ||
+ | } | ||
+ | return ""; | ||
+ | } | ||
+ | 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(" | ||
+ | } | ||
+ | var re = /(.*) ([0-9]+)/; | ||
+ | $( document ).ready(function() { | ||
+ | $("# | ||
+ | var parts = $(this).val().split(',' | ||
+ | var values = {}; | ||
+ | var sum = 0; | ||
+ | var num_values = 0; | ||
+ | $('# | ||
+ | $('# | ||
+ | $('# | ||
+ | $.each(parts, | ||
+ | value = value.trim(); | ||
+ | var matches = re.exec(value); | ||
+ | if (matches) { | ||
+ | if (values[matches[1]]) { | ||
+ | $('# | ||
+ | } else { | ||
+ | $('# | ||
+ | values[matches[1]] = matches[2]; | ||
+ | sum += parseInt(matches[2]); | ||
+ | num_values++; | ||
+ | } | ||
+ | } else { | ||
+ | $('# | ||
+ | } | ||
+ | }); | ||
+ | var h = 0; | ||
+ | $.each(values, | ||
+ | var p = value / sum; | ||
+ | var l = Math.log(p) / Math.log(2); | ||
+ | h -= (p * l); | ||
+ | }); | ||
+ | $('# | ||
+ | $('# | ||
+ | if (parts.length != num_values) { | ||
+ | $('# | ||
+ | } | ||
+ | setCookie(" | ||
+ | }); | ||
+ | if ($("# | ||
+ | $("# | ||
+ | } | ||
+ | $("# | ||
+ | }); | ||
+ | </JS> | ||