skab 0.1.0 → 0.1.2

Sign up to get free protection for your applications and to get access to all the features.
@@ -7,6 +7,7 @@ module Skab
7
7
  @a_success = args.shift.to_i
8
8
  @b_trials = args.shift.to_i
9
9
  @b_success = args.shift.to_i
10
+ @fact = { }
10
11
  end
11
12
 
12
13
  def distribution
@@ -67,17 +68,13 @@ skab [output] binomial [trials_a] [successes_a] [trials_b] [successes_b]
67
68
  end
68
69
 
69
70
  def binomial_coef(n, k)
70
- fact(n) / (fact(k) * fact(n - k))
71
+ factorial(n) / (factorial(k) * factorial(n - k))
71
72
  end
72
73
 
73
- def fact(n)
74
- f = 1
75
- (1..n).each do |i|
76
- f *= i
77
- end
78
- f
74
+ def factorial(n)
75
+ return @fact[n] if @fact[n]
76
+ @fact[n] = (n > 1) ? n * factorial(n - 1) : 1
79
77
  end
80
-
81
78
  end
82
79
  end
83
80
  end
@@ -5,6 +5,7 @@ module Skab
5
5
  def initialize(args)
6
6
  @a = args.shift.to_i
7
7
  @b = args.shift.to_i
8
+ @fact = { }
8
9
  end
9
10
 
10
11
  def distribution
@@ -55,13 +56,9 @@ skab [output] poisson [a] [b]
55
56
  end
56
57
 
57
58
  def factorial(n)
58
- f = 1
59
- (1..n).each do |i|
60
- f *= i
61
- end
62
- f
59
+ return @fact[n] if @fact[n]
60
+ @fact[n] = (n > 1) ? n * fact(n - 1) : 1
63
61
  end
64
-
65
62
  end
66
63
  end
67
64
  end
@@ -2,6 +2,8 @@ module Skab
2
2
  require ROOT + '/skab/output/distribution'
3
3
  require ROOT + '/skab/output/differential'
4
4
  require ROOT + '/skab/output/summary'
5
+ require ROOT + '/skab/output/gnuplot_distribution'
6
+ require ROOT + '/skab/output/gnuplot_differential'
5
7
 
6
8
  module Output
7
9
  def self.from_name(name)
@@ -12,11 +14,21 @@ module Skab
12
14
  Distribution
13
15
  when 'summary'
14
16
  Summary
17
+ when 'gnuplot_distribution'
18
+ GnuplotDistribution
19
+ when 'gnuplot_differential'
20
+ GnuplotDifferential
15
21
  end
16
22
  end
17
23
 
18
24
  def self.output_names
19
- ['distribution', 'differential', 'summary']
25
+ [
26
+ 'distribution',
27
+ 'differential',
28
+ 'summary',
29
+ 'gnuplot_distribution',
30
+ 'gnuplot_differential'
31
+ ]
20
32
  end
21
33
 
22
34
  def self.help
@@ -0,0 +1,23 @@
1
+ module Skab
2
+ module Output
3
+ class GnuplotDifferential
4
+ def initialize(out)
5
+ @out = out
6
+ end
7
+
8
+ def output(model)
9
+ @out.puts "set encoding utf8"
10
+ @out.puts "set title"
11
+ @out.puts "set key outside"
12
+ @out.puts "set title \"Difference distribution\""
13
+
14
+ @out.puts "set style fill transparent solid 0.5 border"
15
+
16
+ @out.puts "plot '-' using 1:2 with filledcurve lc rgb 'red' title \"Pr(\316\264)\""
17
+ model.differential.sort.each do |k, v|
18
+ @out.puts " #{k} #{v}"
19
+ end
20
+ end
21
+ end
22
+ end
23
+ end
@@ -0,0 +1,29 @@
1
+ module Skab
2
+ module Output
3
+ class GnuplotDistribution
4
+ def initialize(out)
5
+ @out = out
6
+ end
7
+
8
+ def output(model)
9
+ @out.puts "set title"
10
+ @out.puts "set key outside"
11
+ @out.puts "set title \"Probability density distribution\""
12
+
13
+ @out.puts "set style fill transparent solid 0.5 border"
14
+
15
+ interval = [model.distribution.first[0], model.distribution.last[0]]
16
+ @out.puts "plot '-' using 1:2 with filledcurve lc rgb 'red' title 'Group A', \\"
17
+ @out.puts "\t'' using 1:2 with filledcurve lc rgb 'blue' title 'Group B'"
18
+ model.distribution.each do |d|
19
+ @out.puts " #{d[0]} #{d[1]}"
20
+ end
21
+ @out.puts "e"
22
+ model.distribution.each do |d|
23
+ @out.puts " #{d[0]} #{d[2]}"
24
+ end
25
+ @out.puts "e"
26
+ end
27
+ end
28
+ end
29
+ end
metadata CHANGED
@@ -1,64 +1,60 @@
1
- --- !ruby/object:Gem::Specification
1
+ --- !ruby/object:Gem::Specification
2
2
  name: skab
3
- version: !ruby/object:Gem::Version
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.1.2
4
5
  prerelease:
5
- version: 0.1.0
6
6
  platform: ruby
7
- authors:
7
+ authors:
8
8
  - Vivien Barousse
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
-
13
- date: 2012-10-10 00:00:00 Z
12
+ date: 2013-05-30 00:00:00.000000000 Z
14
13
  dependencies: []
15
-
16
14
  description:
17
15
  email: vivien@songkick.com
18
- executables:
16
+ executables:
19
17
  - skab
20
18
  extensions: []
21
-
22
- extra_rdoc_files:
19
+ extra_rdoc_files:
23
20
  - README.rdoc
24
- files:
21
+ files:
25
22
  - README.rdoc
26
23
  - bin/skab
27
24
  - lib/skab.rb
28
- - lib/skab/output.rb
29
- - lib/skab/models/binomial.rb
30
- - lib/skab/models/poisson.rb
31
25
  - lib/skab/output/summary.rb
32
26
  - lib/skab/output/distribution.rb
33
27
  - lib/skab/output/differential.rb
28
+ - lib/skab/output/gnuplot_distribution.rb
29
+ - lib/skab/output/gnuplot_differential.rb
30
+ - lib/skab/output.rb
31
+ - lib/skab/models/binomial.rb
32
+ - lib/skab/models/poisson.rb
34
33
  - lib/skab/models.rb
35
34
  homepage: http://github.com/songkick/skab
36
35
  licenses: []
37
-
38
36
  post_install_message:
39
- rdoc_options:
37
+ rdoc_options:
40
38
  - --main
41
39
  - README.rdoc
42
- require_paths:
40
+ require_paths:
43
41
  - lib
44
- required_ruby_version: !ruby/object:Gem::Requirement
42
+ required_ruby_version: !ruby/object:Gem::Requirement
45
43
  none: false
46
- requirements:
47
- - - ">="
48
- - !ruby/object:Gem::Version
49
- version: "0"
50
- required_rubygems_version: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - ! '>='
46
+ - !ruby/object:Gem::Version
47
+ version: '0'
48
+ required_rubygems_version: !ruby/object:Gem::Requirement
51
49
  none: false
52
- requirements:
53
- - - ">="
54
- - !ruby/object:Gem::Version
55
- version: "0"
50
+ requirements:
51
+ - - ! '>='
52
+ - !ruby/object:Gem::Version
53
+ version: '0'
56
54
  requirements: []
57
-
58
55
  rubyforge_project:
59
- rubygems_version: 1.8.21
56
+ rubygems_version: 1.8.25
60
57
  signing_key:
61
58
  specification_version: 3
62
59
  summary: A/B testing statistical analysis utility
63
60
  test_files: []
64
-