statsample 0.8.1 → 0.8.2

Sign up to get free protection for your applications and to get access to all the features.
Binary file
@@ -1,3 +1,5 @@
1
+ === 0.8.2 / 2010-04-01
2
+ * Statsample::PromiseAfter replaced by external package DirtyMemoize [http://rubygems.org/gems/dirty-memoize]
1
3
  === 0.8.1 / 2010-03-29
2
4
  * Fixed Regression summaries
3
5
  === 0.8.0 / 2010-03-29
@@ -103,7 +103,6 @@ test/test_matrix.rb
103
103
  test/test_mle.rb
104
104
  test/test_multiset.rb
105
105
  test/test_permutation.rb
106
- test/test_promise_after.rb
107
106
  test/test_regression.rb
108
107
  test/test_reliability.rb
109
108
  test/test_resample.rb
data/Rakefile CHANGED
@@ -42,7 +42,7 @@ h=Hoe.spec('statsample') do
42
42
  self.version=Statsample::VERSION
43
43
  self.rubyforge_name = "ruby-statsample"
44
44
  self.developer('Claudio Bustos', 'clbustos@gmail.com')
45
- self.extra_deps << ["spreadsheet","~>0.6.0"] << ["svg-graph", "~>1.0"] << ["reportbuilder", "~>1.0"] << ["minimization", "~>0.1.0"] << ["fastercsv"]
45
+ self.extra_deps << ["spreadsheet","~>0.6.0"] << ["svg-graph", "~>1.0"] << ["reportbuilder", "~>1.0"] << ["minimization", "~>0.1.0"] << ["fastercsv"] << ["dirty-memoize", "~>0.0"]
46
46
  self.clean_globs << "test/images/*" << "demo/item_analysis/*" << "demo/Regression"
47
47
  self.need_rdoc=false
48
48
  end
@@ -21,6 +21,7 @@
21
21
  #$:.unshift(File.dirname(__FILE__))
22
22
  require 'matrix'
23
23
  require 'distribution'
24
+ require 'dirty-memoize'
24
25
  gem 'reportbuilder','~>1.0'
25
26
  require 'reportbuilder'
26
27
  class Numeric
@@ -111,7 +112,7 @@ module Statsample
111
112
  false
112
113
  end
113
114
  end
114
- VERSION = '0.8.1'
115
+ VERSION = '0.8.2'
115
116
  SPLIT_TOKEN = ","
116
117
  autoload(:Database, 'statsample/converters')
117
118
  autoload(:Anova, 'statsample/anova')
@@ -204,55 +205,6 @@ module Statsample
204
205
  end
205
206
  end
206
207
 
207
- module PromiseAfter
208
- # Like memoizable module (http://promise.rubyforge.org/Promise.html)
209
- # but this applies to set a lot or variables with one expensive method
210
- # with a direct calling of dependent methods.
211
- # If one of the dependent methods returns nil or false, the main method
212
- # is called.
213
- #
214
- # Use when
215
- # 1. You have one expensive operation which set many internal variables
216
- # 2. This expensive operations depends on values which can set
217
- # anytime BEFORE calculation of main function
218
- #
219
- # I use for classes which requires a iteration to set several variables,
220
- # hiding to user the need to explicitily call the iterate method.
221
- #
222
- # Example:
223
- # class ExpensiveCalculation
224
- # include PromiseAfter
225
- # attr_accessor :y, :z
226
- # def initialize(y=nil,z=nil)
227
- # @y=y
228
- # @z=z
229
- # def compute
230
- # @a=@y*1000+@z*1000
231
- # end
232
- # def a
233
- # @a.nil? nil : "This is the value: #{@a}"
234
- # end
235
- # promise_after :compute, :a, :b
236
- # end
237
- # puts ExpensiveCalculation.new(1,2).a
238
-
239
- def promise_after(function, *syms)
240
- syms.each do |sym|
241
- # You should doc the method!
242
- raise NoMethodError, "Method `#{sym}' doesn't exists! Create it first " unless method_defined? sym
243
- alias_method((sym.to_s+"_without_promise_after").intern, sym)
244
- define_method(sym) {
245
- #sym_to_iv="@#{sym.to_s.gsub(":","")}".intern
246
- #if !instance_variable_defined?(sym_to_iv) or instance_variable_get(sym_to_iv).nil?
247
- if(!send(sym.to_s+"_without_promise_after"))
248
- send(function)
249
- end
250
- send(sym.to_s+"_without_promise_after")
251
- }
252
-
253
- end
254
- end
255
- end
256
208
 
257
209
 
258
210
  module Writable
@@ -65,7 +65,7 @@ module Statsample
65
65
 
66
66
  class Polychoric
67
67
  include GetText
68
- extend Statsample::PromiseAfter
68
+ include DirtyMemoize
69
69
  bindtextdomain("statsample")
70
70
  # Name of the analysis
71
71
  attr_accessor :name
@@ -142,7 +142,8 @@ module Statsample
142
142
  # Returns the columns thresholds
143
143
  attr_reader :beta
144
144
 
145
- promise_after :compute, :r, :alpha, :beta
145
+ dirty_writer :max_iterations, :epsilon, :minimizer_type_two_step, :minimizer_type_joint, :method
146
+ dirty_memoize :r, :alpha, :beta
146
147
 
147
148
  alias :threshold_x :alpha
148
149
  alias :threshold_y :beta
@@ -733,7 +734,7 @@ module Statsample
733
734
 
734
735
 
735
736
  def report_building(generator) # :nodoc:
736
- #compute if r.nil?
737
+ compute if dirty?
737
738
  section=ReportBuilder::Section.new(:name=>@name)
738
739
  t=ReportBuilder::Table.new(:name=>_("Contingence Table"), :header=>[""]+(@n.times.collect {|i| "Y=#{i}"})+["Total"])
739
740
  @m.times do |i|
@@ -18,14 +18,15 @@ module Factor
18
18
  class Rotation
19
19
  EPSILON=1e-15
20
20
  MAX_ITERATIONS=25
21
- extend Statsample::PromiseAfter
21
+ include DirtyMemoize
22
22
  attr_reader :iterations, :rotated, :component_transformation_matrix, :h2
23
23
  # Maximum number of iterations
24
24
  attr_accessor :max_iterations
25
25
  # Maximum precision
26
26
  attr_accessor :epsilon
27
27
 
28
- promise_after :iterate, :iterations, :rotated, :component_transformation_matrix, :h2
28
+ dirty_writer :max_iterations, :epsilon
29
+ dirty_memoize :iterations, :rotated, :component_transformation_matrix, :h2
29
30
 
30
31
  def initialize(matrix, opts=Hash.new)
31
32
  @matrix=matrix
@@ -42,6 +43,9 @@ module Factor
42
43
  end
43
44
  alias_method :communalities, :h2
44
45
  alias_method :rotated_component_matrix, :rotated
46
+ def compute
47
+ iterate
48
+ end
45
49
  # Start iteration
46
50
  def iterate
47
51
  t=Matrix.identity(@m)
@@ -52,7 +56,7 @@ module Factor
52
56
  @not_converged=true
53
57
  @iterations=0
54
58
  while @not_converged
55
- break if iterations>@max_iterations
59
+ break if @iterations>@max_iterations
56
60
  @iterations+=1
57
61
  #puts "Iteration #{iterations}"
58
62
  num_pairs=@m*(@m-1).quo(2)
@@ -58,7 +58,7 @@ module Statsample
58
58
  class OneSample
59
59
  include Math
60
60
  include Statsample::Test
61
- extend Statsample::PromiseAfter
61
+ include DirtyMemoize
62
62
  # Options
63
63
  attr_accessor :opts
64
64
  # Name of test
@@ -73,6 +73,10 @@ module Statsample
73
73
  attr_reader :probability
74
74
  # Tails for probability (:both, :left or :right)
75
75
  attr_accessor :tails
76
+
77
+ dirty_writer :u, :tails
78
+ dirty_memoize :t, :probability
79
+
76
80
  def initialize(vector, opts=Hash.new)
77
81
  @vector=vector
78
82
  default={:u=>0, :name=>"One Sample T Test", :tails=>:both}
@@ -83,8 +87,7 @@ module Statsample
83
87
  @df= @vector.n_valid-1
84
88
  @t=nil
85
89
  end
86
-
87
- promise_after :compute, :t, :probability
90
+
88
91
 
89
92
  # Set t and probability for given u
90
93
  def compute
@@ -102,7 +105,6 @@ module Statsample
102
105
  s.text "Population mean:#{u}"
103
106
  s.text "Tails: #{tails}"
104
107
  s.text sprintf("t = %0.4f, p=%0.4f, d.f=%d", t, probability, df)
105
-
106
108
  }
107
109
  end
108
110
  end
@@ -117,7 +119,7 @@ module Statsample
117
119
  class TwoSamplesIndependent
118
120
  include Math
119
121
  include Statsample::Test
120
- extend Statsample::PromiseAfter
122
+ include DirtyMemoize
121
123
  # Options
122
124
  attr_accessor :opts
123
125
  # Name of test
@@ -137,6 +139,10 @@ module Statsample
137
139
  # Tails for probability (:both, :left or :right)
138
140
  attr_accessor :tails
139
141
  # Create the object
142
+
143
+ dirty_writer :tails
144
+ dirty_memoize :t_equal_variance, :t_not_equal_variance, :probability_equal_variance, :probability_not_equal_variance, :df_equal_variance, :df_not_equal_variance
145
+
140
146
  def initialize(v1, v2, opts=Hash.new)
141
147
  @v1=v1
142
148
  @v2=v2
@@ -145,8 +151,8 @@ module Statsample
145
151
  @name=@opts[:name]
146
152
  @tails=@opts[:tails]
147
153
  end
148
-
149
- promise_after :compute, :t_equal_variance, :t_not_equal_variance, :probability_equal_variance, :probability_not_equal_variance, :df_equal_variance, :df_not_equal_variance
154
+
155
+
150
156
 
151
157
  # Set t and probability for given u
152
158
  def compute
metadata CHANGED
@@ -1,15 +1,36 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: statsample
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.8.1
4
+ version: 0.8.2
5
5
  platform: ruby
6
6
  authors:
7
7
  - Claudio Bustos
8
8
  autorequire:
9
9
  bindir: bin
10
- cert_chain: []
10
+ cert_chain:
11
+ - |
12
+ -----BEGIN CERTIFICATE-----
13
+ MIIDMjCCAhqgAwIBAgIBADANBgkqhkiG9w0BAQUFADA/MREwDwYDVQQDDAhjbGJ1
14
+ c3RvczEVMBMGCgmSJomT8ixkARkWBWdtYWlsMRMwEQYKCZImiZPyLGQBGRYDY29t
15
+ MB4XDTEwMDMyOTIxMzg1NVoXDTExMDMyOTIxMzg1NVowPzERMA8GA1UEAwwIY2xi
16
+ dXN0b3MxFTATBgoJkiaJk/IsZAEZFgVnbWFpbDETMBEGCgmSJomT8ixkARkWA2Nv
17
+ bTCCASIwDQYJKoZIhvcNAQEBBQADggEPADCCAQoCggEBALf8JVMGqE7m5kYb+PNN
18
+ neZv2pcXV5fQCi6xkyG8bi2/SIFy/LyxuvLzEeOxBeaz1Be93bayIUquOIqw3dyw
19
+ /KXWa31FxuNuvAm6CN8fyeRYX/ou4cw3OIUUnIvB7RMNIu4wbgeM6htV/QEsNLrv
20
+ at1/mh9JpqawPrcjIOVMj4BIp67vmzJCaUf+S/H2uYtSO09F+YQE3tv85TPeRmqU
21
+ yjyXyTc/oJiw1cXskUL8UtMWZmrwNLHXuZWWIMzkjiz3UNdhJr/t5ROk8S2WPznl
22
+ 0bMy/PMIlAbqWolRn1zl2VFJ3TaXScbqImY8Wf4g62b/1ZSUlGrtnLNsCYXrWiso
23
+ UPUCAwEAAaM5MDcwCQYDVR0TBAIwADALBgNVHQ8EBAMCBLAwHQYDVR0OBBYEFGu9
24
+ rrJ1H64qRmNNu3Jj/Qjvh0u5MA0GCSqGSIb3DQEBBQUAA4IBAQCV0Unka5isrhZk
25
+ GjqSDqY/6hF+G2pbFcbWUpjmC8NWtAxeC+7NGV3ljd0e1SLfoyBj4gnFtFmY8qX4
26
+ K02tgSZM0eDV8TpgFpWXzK6LzHvoanuahHLZEtk/+Z885lFene+nHadkem1n9iAB
27
+ cs96JO9/JfFyuXM27wFAwmfHCmJfPF09R4VvGHRAvb8MGzSVgk2i06OJTqkBTwvv
28
+ JHJdoyw3+8bw9RJ+jLaNoQ+xu+1pQdS2bb3m7xjZpufml/m8zFCtjYM/7qgkKR8z
29
+ /ZZt8lCiKfFArppRrZayE2FVsps4X6WwBdrKTMZ0CKSXTRctbEj1BAZ67eoTvBBt
30
+ rpP0jjs0
31
+ -----END CERTIFICATE-----
11
32
 
12
- date: 2010-03-29 00:00:00 -03:00
33
+ date: 2010-04-01 00:00:00 -03:00
13
34
  default_executable:
14
35
  dependencies:
15
36
  - !ruby/object:Gem::Dependency
@@ -62,6 +83,16 @@ dependencies:
62
83
  - !ruby/object:Gem::Version
63
84
  version: "0"
64
85
  version:
86
+ - !ruby/object:Gem::Dependency
87
+ name: dirty-memoize
88
+ type: :runtime
89
+ version_requirement:
90
+ version_requirements: !ruby/object:Gem::Requirement
91
+ requirements:
92
+ - - ~>
93
+ - !ruby/object:Gem::Version
94
+ version: "0.0"
95
+ version:
65
96
  - !ruby/object:Gem::Dependency
66
97
  name: rubyforge
67
98
  type: :development
@@ -222,7 +253,6 @@ files:
222
253
  - test/test_mle.rb
223
254
  - test/test_multiset.rb
224
255
  - test/test_permutation.rb
225
- - test/test_promise_after.rb
226
256
  - test/test_regression.rb
227
257
  - test/test_reliability.rb
228
258
  - test/test_resample.rb
@@ -284,7 +314,6 @@ test_files:
284
314
  - test/test_mle.rb
285
315
  - test/test_resample.rb
286
316
  - test/test_stratified.rb
287
- - test/test_promise_after.rb
288
317
  - test/test_vector.rb
289
318
  - test/test_srs.rb
290
319
  - test/test_ggobi.rb
Binary file
@@ -1,39 +0,0 @@
1
- require(File.dirname(__FILE__)+'/test_helpers.rb')
2
-
3
-
4
- class StatsamplePromiseAfterTestCase < MiniTest::Unit::TestCase
5
- class ExpensiveClass
6
- extend Statsample::PromiseAfter
7
- attr_reader :dirty
8
- def initialize
9
- @a=nil
10
- @b=nil
11
- @dirty=false
12
- end
13
- def compute
14
- @a="After"
15
- @b="After"
16
- @dirty=true
17
- end
18
- def a
19
- @a.nil? ? nil : "@a=#{@a}"
20
- end
21
- def b
22
- "@b=#{@b}"
23
- end
24
- promise_after :compute, :a
25
- end
26
- def setup
27
- @ec=ExpensiveClass.new
28
- end
29
- def test_promise_after_before
30
- assert_equal(nil, @ec.instance_variable_get("@a"))
31
- assert_equal(nil, @ec.instance_variable_get("@b"))
32
- assert_equal("@b=",@ec.b)
33
- refute(@ec.dirty)
34
- # Calling method a active compute
35
- assert_equal("@a=After", @ec.a)
36
- assert(@ec.dirty)
37
- assert_equal("@b=After", @ec.b)
38
- end
39
- end