diverge 1.0.3 → 1.1.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (4) hide show
  1. data/LICENSE +20 -0
  2. data/README.md +34 -0
  3. data/lib/diverge.rb +9 -1
  4. metadata +22 -4
data/LICENSE ADDED
@@ -0,0 +1,20 @@
1
+ Copyright (c) 2012 Evan Senter
2
+
3
+ Permission is hereby granted, free of charge, to any person obtaining
4
+ a copy of this software and associated documentation files (the
5
+ "Software"), to deal in the Software without restriction, including
6
+ without limitation the rights to use, copy, modify, merge, publish,
7
+ distribute, sublicense, and/or sell copies of the Software, and to
8
+ permit persons to whom the Software is furnished to do so, subject to
9
+ the following conditions:
10
+
11
+ The above copyright notice and this permission notice shall be
12
+ included in all copies or substantial portions of the Software.
13
+
14
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
15
+ EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
16
+ MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
17
+ NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
18
+ LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
19
+ OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
20
+ WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
data/README.md ADDED
@@ -0,0 +1,34 @@
1
+ = diverge
2
+
3
+ Diverge is a very simple class for calculating the Kullback–Leibler divergence or Jensen–Shannon divergence of two datasets. Example usage is as follows:
4
+
5
+ 1.9.3p194 :001 > require "diverge"
6
+ => true
7
+ 1.9.3p194 :002 > Diverge.new([0.25, 0.5, 0.25], [0.5, 0.3, 0.2]).kl
8
+ => 0.1379119045715615
9
+ 1.9.3p194 :003 > Diverge.new([0.25, 0.5, 0.25], [0.5, 0.3, 0.2]).kl(:reverse)
10
+ => 0.14869719288733346
11
+ 1.9.3p194 :004 > Diverge.new([0.5, 0.3, 0.2], [0.25, 0.5, 0.25]).kl
12
+ => 0.14869719288733346
13
+ 1.9.3p194 :005 > Diverge.new([0.25, 0.5, 0.25], [0.5, 0.3, 0.2]).js
14
+ => 0.14330454872944748
15
+ 1.9.3p194 :006 > Diverge.new([0.5, 0.3, 0.2], [0.25, 0.5, 0.25]).js
16
+ => 0.14330454872944748
17
+
18
+ http://rubygems.org/gems/diverge
19
+
20
+ == Contributing to diverge
21
+
22
+ * Check out the latest master to make sure the feature hasn't been implemented or the bug hasn't been fixed yet.
23
+ * Check out the issue tracker to make sure someone already hasn't requested it and/or contributed it.
24
+ * Fork the project.
25
+ * Start a feature/bugfix branch.
26
+ * Commit and push until you are happy with your contribution.
27
+ * Make sure to add tests for it. This is important so I don't break it in a future version unintentionally.
28
+ * Please try not to mess with the Rakefile, version, or history. If you want to have your own version, or is otherwise necessary, that is fine, but please isolate to its own commit so I can cherry-pick around it.
29
+
30
+ == Copyright
31
+
32
+ Copyright (c) 2012 Evan Senter. See LICENSE.txt for
33
+ further details.
34
+
data/lib/diverge.rb CHANGED
@@ -1,3 +1,5 @@
1
+ require "gsl"
2
+
1
3
  class Diverge
2
4
  attr_reader :p, :q
3
5
 
@@ -36,8 +38,14 @@ class Diverge
36
38
  alias :js :jensen_shannon
37
39
 
38
40
  def total_variation_distance
39
- 0.5 * p.zip(q).inject(0.0) { |sum, (i, j)| sum + ((i || 0) - (j || 0)).abs }
41
+ 0.5 * p.zip(q).inject(0.0) { |sum, (i, j)| sum + (i - j).abs }
40
42
  end
41
43
 
42
44
  alias :tvd :total_variation_distance
45
+
46
+ def correlation
47
+ GSL::Stats::correlation(GSL::Vector.alloc(p), GSL::Vector.alloc(q))
48
+ end
49
+
50
+ alias :corr :correlation
43
51
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: diverge
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.0.3
4
+ version: 1.1.0
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors:
@@ -9,8 +9,24 @@ authors:
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2012-06-26 00:00:00.000000000 Z
13
- dependencies: []
12
+ date: 2012-08-17 00:00:00.000000000 Z
13
+ dependencies:
14
+ - !ruby/object:Gem::Dependency
15
+ name: gsl
16
+ requirement: !ruby/object:Gem::Requirement
17
+ none: false
18
+ requirements:
19
+ - - ! '>='
20
+ - !ruby/object:Gem::Version
21
+ version: 1.14.0
22
+ type: :runtime
23
+ prerelease: false
24
+ version_requirements: !ruby/object:Gem::Requirement
25
+ none: false
26
+ requirements:
27
+ - - ! '>='
28
+ - !ruby/object:Gem::Version
29
+ version: 1.14.0
14
30
  description: A simple collection of functions for determining the divergence between
15
31
  two distributions.
16
32
  email: evansenter@gmail.com
@@ -18,7 +34,9 @@ executables: []
18
34
  extensions: []
19
35
  extra_rdoc_files: []
20
36
  files:
21
- - ./lib/diverge.rb
37
+ - lib/diverge.rb
38
+ - LICENSE
39
+ - README.md
22
40
  homepage: http://rubygems.org/gems/diverge
23
41
  licenses: []
24
42
  post_install_message: