entropy 0.0.2

Sign up to get free protection for your applications and to get access to all the features.
Files changed (63) hide show
  1. data/.gitignore +4 -0
  2. data/Gemfile +4 -0
  3. data/LICENSE.txt +674 -0
  4. data/README.txt +48 -0
  5. data/Rakefile +22 -0
  6. data/doc/rdocs/Entropy.html +234 -0
  7. data/doc/rdocs/Entropy/Dict.html +311 -0
  8. data/doc/rdocs/Entropy/ProbabilityMetricSpace.html +544 -0
  9. data/doc/rdocs/Entropy/ProbabilitySpace.html +473 -0
  10. data/doc/rdocs/Entropy/Stream.html +281 -0
  11. data/doc/rdocs/LICENSE_txt.html +834 -0
  12. data/doc/rdocs/README_txt.html +138 -0
  13. data/doc/rdocs/created.rid +9 -0
  14. data/doc/rdocs/images/brick.png +0 -0
  15. data/doc/rdocs/images/brick_link.png +0 -0
  16. data/doc/rdocs/images/bug.png +0 -0
  17. data/doc/rdocs/images/bullet_black.png +0 -0
  18. data/doc/rdocs/images/bullet_toggle_minus.png +0 -0
  19. data/doc/rdocs/images/bullet_toggle_plus.png +0 -0
  20. data/doc/rdocs/images/date.png +0 -0
  21. data/doc/rdocs/images/find.png +0 -0
  22. data/doc/rdocs/images/loadingAnimation.gif +0 -0
  23. data/doc/rdocs/images/macFFBgHack.png +0 -0
  24. data/doc/rdocs/images/package.png +0 -0
  25. data/doc/rdocs/images/page_green.png +0 -0
  26. data/doc/rdocs/images/page_white_text.png +0 -0
  27. data/doc/rdocs/images/page_white_width.png +0 -0
  28. data/doc/rdocs/images/plugin.png +0 -0
  29. data/doc/rdocs/images/ruby.png +0 -0
  30. data/doc/rdocs/images/tag_green.png +0 -0
  31. data/doc/rdocs/images/wrench.png +0 -0
  32. data/doc/rdocs/images/wrench_orange.png +0 -0
  33. data/doc/rdocs/images/zoom.png +0 -0
  34. data/doc/rdocs/index.html +155 -0
  35. data/doc/rdocs/js/darkfish.js +116 -0
  36. data/doc/rdocs/js/jquery.js +32 -0
  37. data/doc/rdocs/js/quicksearch.js +114 -0
  38. data/doc/rdocs/js/thickbox-compressed.js +10 -0
  39. data/doc/rdocs/lib/entropy/dict_rb.html +56 -0
  40. data/doc/rdocs/lib/entropy/metric_space_rb.html +54 -0
  41. data/doc/rdocs/lib/entropy/probability_space_rb.html +52 -0
  42. data/doc/rdocs/lib/entropy/stream_rb.html +52 -0
  43. data/doc/rdocs/lib/entropy/version_rb.html +52 -0
  44. data/doc/rdocs/lib/entropy_rb.html +62 -0
  45. data/doc/rdocs/rdoc.css +763 -0
  46. data/entropy.gemspec +24 -0
  47. data/example/metric_prob_space.rb +42 -0
  48. data/example/prob_space.rb +31 -0
  49. data/lib/entropy.rb +13 -0
  50. data/lib/entropy/dict.rb +30 -0
  51. data/lib/entropy/metric_space.rb +116 -0
  52. data/lib/entropy/probability_space.rb +91 -0
  53. data/lib/entropy/stream.rb +37 -0
  54. data/lib/entropy/version.rb +3 -0
  55. data/test/stream0.txt +1 -0
  56. data/test/stream1.txt +1 -0
  57. data/test/stream2.txt +1 -0
  58. data/test/stream_random.bin +2 -0
  59. data/test/test_entropy_def.rb +10 -0
  60. data/test/test_entropy_metr.rb +36 -0
  61. data/test/test_entropy_prob.rb +64 -0
  62. data/test/test_entropy_stream.rb +29 -0
  63. metadata +127 -0
@@ -0,0 +1,64 @@
1
+ require 'test/unit'
2
+ require 'entropy'
3
+
4
+ class TestEntropy < Test::Unit::TestCase
5
+
6
+ def test_string_prob
7
+ obj = Entropy::ProbabilitySpace.new
8
+ obj.add_stream("000000000")
9
+ assert_equal obj.prob_space, [1.0]
10
+ end
11
+
12
+ def test_string_prob_2
13
+ obj = Entropy::ProbabilitySpace.new
14
+ obj.add_stream("1000")
15
+ assert_equal obj.prob_space.sort, [0.25, 0.75]
16
+ end
17
+
18
+ def test_cardinality
19
+ obj = Entropy::ProbabilitySpace.new
20
+ stream = "11111111"
21
+ obj.add_stream(stream)
22
+ assert_equal obj.cardinality(2).round, 1
23
+ end
24
+
25
+ def test_cardinality_2
26
+ obj = Entropy::ProbabilitySpace.new
27
+ stream = "1234"
28
+ obj.add_stream(stream)
29
+ assert_equal obj.cardinality(2).round, stream.size
30
+ end
31
+
32
+ def test_diversity
33
+ obj = Entropy::ProbabilitySpace.new
34
+ stream = "11111111"
35
+ obj.add_stream(stream)
36
+ assert_equal obj.diversity(2).round, 0
37
+ assert_equal obj.renyi_entropy(:infinite).round, 0
38
+ end
39
+
40
+ def test_diversity_2
41
+ obj = Entropy::ProbabilitySpace.new
42
+ stream = "1234"
43
+ obj.add_stream(stream)
44
+ assert_equal obj.diversity(2), obj.surprise(2, 1.0/stream.size)
45
+ assert_equal obj.renyi_entropy(:infinite), -Math.log(0.25)
46
+ end
47
+
48
+ def test_entropy_renyi
49
+ obj = Entropy::ProbabilitySpace.new
50
+ stream = "11111111"
51
+ obj.add_stream(stream)
52
+ assert_equal obj.renyi_entropy(2), 0
53
+ end
54
+
55
+ def test_entropy_renyi_2
56
+ obj = Entropy::ProbabilitySpace.new
57
+ stream = "1234"
58
+ obj.add_stream(stream)
59
+ p = 0.25*0.25
60
+ assert_equal obj.renyi_entropy(2), -Math.log(4*p)
61
+ assert_equal obj.renyi_entropy(:infinite), -Math.log(0.25)
62
+ end
63
+ end
64
+
@@ -0,0 +1,29 @@
1
+ require 'test/unit'
2
+ require 'entropy'
3
+
4
+ class TestEntropy < Test::Unit::TestCase
5
+
6
+ def test_char_file
7
+ assert_nothing_raised do
8
+ file = File.open("test/stream1.txt", "r")
9
+ obj = Entropy::Stream.new
10
+ obj.add_stream(file)
11
+ end
12
+ end
13
+ def test_string
14
+ assert_nothing_raised do
15
+ obj = Entropy::Stream.new
16
+ obj.add_stream("000000000")
17
+ end
18
+ end
19
+
20
+ def test_string_and_file
21
+ assert_nothing_raised do
22
+ obj = Entropy::Stream.new
23
+ obj.add_stream("000000000")
24
+ file = File.open("test/stream1.txt", "r")
25
+ obj.add_stream(file)
26
+ end
27
+ end
28
+ end
29
+
metadata ADDED
@@ -0,0 +1,127 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: entropy
3
+ version: !ruby/object:Gem::Version
4
+ hash: 27
5
+ prerelease:
6
+ segments:
7
+ - 0
8
+ - 0
9
+ - 2
10
+ version: 0.0.2
11
+ platform: ruby
12
+ authors:
13
+ - hiraedd
14
+ autorequire:
15
+ bindir: bin
16
+ cert_chain: []
17
+
18
+ date: 2011-09-27 00:00:00 Z
19
+ dependencies: []
20
+
21
+ description: This little gem calculates the entropy and ( the cardinality) of a finite probability space, defined by a probability vector; and of a finite probability metric space, defined by a probability vector and metric function.
22
+ email:
23
+ - hiraedd@hiraedd.com
24
+ executables: []
25
+
26
+ extensions: []
27
+
28
+ extra_rdoc_files: []
29
+
30
+ files:
31
+ - .gitignore
32
+ - Gemfile
33
+ - LICENSE.txt
34
+ - README.txt
35
+ - Rakefile
36
+ - doc/rdocs/Entropy.html
37
+ - doc/rdocs/Entropy/Dict.html
38
+ - doc/rdocs/Entropy/ProbabilityMetricSpace.html
39
+ - doc/rdocs/Entropy/ProbabilitySpace.html
40
+ - doc/rdocs/Entropy/Stream.html
41
+ - doc/rdocs/LICENSE_txt.html
42
+ - doc/rdocs/README_txt.html
43
+ - doc/rdocs/created.rid
44
+ - doc/rdocs/images/brick.png
45
+ - doc/rdocs/images/brick_link.png
46
+ - doc/rdocs/images/bug.png
47
+ - doc/rdocs/images/bullet_black.png
48
+ - doc/rdocs/images/bullet_toggle_minus.png
49
+ - doc/rdocs/images/bullet_toggle_plus.png
50
+ - doc/rdocs/images/date.png
51
+ - doc/rdocs/images/find.png
52
+ - doc/rdocs/images/loadingAnimation.gif
53
+ - doc/rdocs/images/macFFBgHack.png
54
+ - doc/rdocs/images/package.png
55
+ - doc/rdocs/images/page_green.png
56
+ - doc/rdocs/images/page_white_text.png
57
+ - doc/rdocs/images/page_white_width.png
58
+ - doc/rdocs/images/plugin.png
59
+ - doc/rdocs/images/ruby.png
60
+ - doc/rdocs/images/tag_green.png
61
+ - doc/rdocs/images/wrench.png
62
+ - doc/rdocs/images/wrench_orange.png
63
+ - doc/rdocs/images/zoom.png
64
+ - doc/rdocs/index.html
65
+ - doc/rdocs/js/darkfish.js
66
+ - doc/rdocs/js/jquery.js
67
+ - doc/rdocs/js/quicksearch.js
68
+ - doc/rdocs/js/thickbox-compressed.js
69
+ - doc/rdocs/lib/entropy/dict_rb.html
70
+ - doc/rdocs/lib/entropy/metric_space_rb.html
71
+ - doc/rdocs/lib/entropy/probability_space_rb.html
72
+ - doc/rdocs/lib/entropy/stream_rb.html
73
+ - doc/rdocs/lib/entropy/version_rb.html
74
+ - doc/rdocs/lib/entropy_rb.html
75
+ - doc/rdocs/rdoc.css
76
+ - entropy.gemspec
77
+ - example/metric_prob_space.rb
78
+ - example/prob_space.rb
79
+ - lib/entropy.rb
80
+ - lib/entropy/dict.rb
81
+ - lib/entropy/metric_space.rb
82
+ - lib/entropy/probability_space.rb
83
+ - lib/entropy/stream.rb
84
+ - lib/entropy/version.rb
85
+ - test/stream0.txt
86
+ - test/stream1.txt
87
+ - test/stream2.txt
88
+ - test/stream_random.bin
89
+ - test/test_entropy_def.rb
90
+ - test/test_entropy_metr.rb
91
+ - test/test_entropy_prob.rb
92
+ - test/test_entropy_stream.rb
93
+ homepage: https://github.com/hiraedd/entropy_gem
94
+ licenses: []
95
+
96
+ post_install_message:
97
+ rdoc_options: []
98
+
99
+ require_paths:
100
+ - lib
101
+ required_ruby_version: !ruby/object:Gem::Requirement
102
+ none: false
103
+ requirements:
104
+ - - ">="
105
+ - !ruby/object:Gem::Version
106
+ hash: 3
107
+ segments:
108
+ - 0
109
+ version: "0"
110
+ required_rubygems_version: !ruby/object:Gem::Requirement
111
+ none: false
112
+ requirements:
113
+ - - ">="
114
+ - !ruby/object:Gem::Version
115
+ hash: 3
116
+ segments:
117
+ - 0
118
+ version: "0"
119
+ requirements: []
120
+
121
+ rubyforge_project: entropy
122
+ rubygems_version: 1.7.2
123
+ signing_key:
124
+ specification_version: 3
125
+ summary: Computes the entropy of a finite probability space
126
+ test_files: []
127
+