pest 0.0.0 → 0.1.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -7,11 +7,19 @@ end
7
7
 
8
8
  describe Pest::Function::Probability do
9
9
  before(:each) do
10
- @v1 = Pest::Variable.new(:name => :foo)
11
- @v2 = Pest::Variable.new(:name => :bar)
12
- @v3 = Pest::Variable.new(:name => :baz)
13
10
  @instance = ProbabilityTestClass.new
14
- @instance.stub(:variables).and_return({:foo => @v1, :bar => @v2})
11
+ @instance.stub(:data).and_return(Pest::DataSet::Hash.from_hash(:foo => [1], :bar => [1]))
12
+ @instance.stub(:variables).and_return([:foo,:bar].to_set)
13
+ end
14
+
15
+ describe "#batch_probability" do
16
+ it "returns a Builder" do
17
+ @instance.batch_probability.should be_a(Pest::Function::Probability::BatchBuilder)
18
+ end
19
+
20
+ it "is aliased as batch_p" do
21
+ @instance.batch_p.should be_a(Pest::Function::Probability::BatchBuilder)
22
+ end
15
23
  end
16
24
 
17
25
  describe "#probability" do
@@ -24,35 +32,35 @@ describe Pest::Function::Probability do
24
32
  end
25
33
  end
26
34
 
27
- describe Pest::Function::Probability::Builder do
35
+ describe Pest::Function::Probability::BatchBuilder do
28
36
  describe "::new" do
29
- before(:each) { @builder = ProbabilityTestClass::Builder.new(@instance, [@v1, :bar]) }
37
+ before(:each) { @builder = ProbabilityTestClass::BatchBuilder.new(@instance, [:foo, :bar]) }
30
38
 
31
39
  it "sets estimator" do
32
40
  @builder.estimator.should == @instance
33
41
  end
34
42
 
35
43
  it "sets event" do
36
- @builder.event.should == [@v1, @v2].to_set
44
+ @builder.event.should == [:foo, :bar].to_set
37
45
  end
38
46
 
39
47
  it "fails if variable undefined for estimator" do
40
- lambda { ProbabilityTestClass::Builder.new(@instance, [@v1, @v3]) }.should raise_error(ArgumentError)
48
+ lambda { ProbabilityTestClass::BatchBuilder.new(@instance, [:foo, :baz]) }.should raise_error(ArgumentError)
41
49
  end
42
50
 
43
51
  it "constructs dataset if passed hash"
44
52
  end
45
53
 
46
54
  describe "#given" do
47
- before(:each) { @builder = ProbabilityTestClass::Builder.new(@instance, [:foo]) }
55
+ before(:each) { @builder = ProbabilityTestClass::BatchBuilder.new(@instance, [:foo]) }
48
56
 
49
57
  it "sets givens" do
50
58
  @builder.given(:bar)
51
- @builder.givens.should include(@v2)
59
+ @builder.givens.should include(:bar)
52
60
  end
53
61
 
54
62
  it "returns self" do
55
- @builder.given(:bar).should be_a(ProbabilityTestClass::Builder)
63
+ @builder.given(:bar).should be_a(ProbabilityTestClass::BatchBuilder)
56
64
  end
57
65
 
58
66
  it "fails if variables aren't variables on the estimator" do
@@ -67,7 +75,7 @@ describe Pest::Function::Probability do
67
75
  describe "#in" do
68
76
  it "sets data source" do
69
77
  data_set = double('DataSet')
70
- ProbabilityTestClass::Builder.new(@instance,[:foo]).in(data_set).data_source.should == data_set
78
+ ProbabilityTestClass::BatchBuilder.new(@instance,[:foo]).in(data_set).data_source.should == data_set
71
79
  end
72
80
 
73
81
  it "raises error if existing data source"
@@ -78,40 +86,101 @@ describe Pest::Function::Probability do
78
86
 
79
87
  it "gets probability of event" do
80
88
  event = double('EventDist')
81
- @instance.distributions.stub(:[]).with([@v1].to_set).and_return(event)
82
- event.should_receive(:probability).and_return 0.5
89
+ @instance.distributions.stub(:[]).with(:foo).and_return(event)
90
+ event.should_receive(:probability).and_return NArray[0.5]
83
91
 
84
- ProbabilityTestClass::Builder.new(@instance,[:foo]).evaluate
92
+ ProbabilityTestClass::BatchBuilder.new(@instance,[:foo]).evaluate
85
93
  end
86
94
 
87
95
  it "gets probability of givens" do
88
96
  event = double('EventDist')
89
97
  given = double('GivenDist')
90
- @instance.distributions.stub(:[]).with([@v1].to_set).and_return(event)
91
- @instance.distributions.stub(:[]).with([@v2].to_set).and_return(given)
92
- event.stub(:probability).and_return 0.5
93
- given.should_receive(:probability).and_return 0.5
98
+ @instance.distributions.stub(:[]).with(:foo, :bar).and_return(event)
99
+ @instance.distributions.stub(:[]).with(:bar).and_return(given)
100
+ event.stub(:probability).and_return NArray[0.5]
101
+ given.should_receive(:probability).and_return NArray[0.5]
94
102
 
95
- ProbabilityTestClass::Builder.new(@instance,[:foo]).given(:bar).evaluate
103
+ ProbabilityTestClass::BatchBuilder.new(@instance,[:foo]).given(:bar).evaluate
96
104
  end
97
105
 
98
106
  it "returns Pr event / givens (if givens)" do
99
107
  event = double('EventDist')
100
108
  given = double('GivenDist')
101
- @instance.distributions.stub(:[]).with([@v1].to_set).and_return(event)
102
- @instance.distributions.stub(:[]).with([@v2].to_set).and_return(given)
103
- event.stub(:probability).and_return 0.5
104
- given.stub(:probability).and_return 0.5
109
+ @instance.distributions.stub(:[]).with(:foo, :bar).and_return(event)
110
+ @instance.distributions.stub(:[]).with(:bar).and_return(given)
111
+ event.stub(:probability).and_return NArray[0.5]
112
+ given.stub(:probability).and_return NArray[0.5]
105
113
 
106
- ProbabilityTestClass::Builder.new(@instance,[:foo]).given(:bar).evaluate.should == 1.0
114
+ ProbabilityTestClass::BatchBuilder.new(@instance,[:foo]).given(:bar).evaluate.should == [1.0]
107
115
  end
108
116
 
109
117
  it "returns Pr event (if no givens)" do
110
118
  event = double('EventDist')
111
- @instance.distributions.stub(:[]).with([@v1].to_set).and_return(event)
112
- event.stub(:probability).and_return 0.5
119
+ @instance.distributions.stub(:[]).with(:foo).and_return(event)
120
+ event.stub(:probability).and_return NArray[0.5]
121
+
122
+ ProbabilityTestClass::BatchBuilder.new(@instance,[:foo]).evaluate.should == [0.5]
123
+ end
124
+ end
125
+ end
126
+
127
+ describe Pest::Function::Probability::Builder do
128
+ describe "::new" do
129
+ before(:each) { @builder = ProbabilityTestClass::Builder.new(@instance, [:foo, :bar]) }
130
+
131
+ it "sets estimator" do
132
+ @builder.estimator.should == @instance
133
+ end
134
+
135
+ it "sets event" do
136
+ pending "do you need this?"
137
+ @builder.event.should == [:foo, :bar].to_set
138
+ end
139
+
140
+ it "fails if variable undefined for estimator" do
141
+ pending "do you need this?"
142
+ lambda { ProbabilityTestClass::Builder.new(@instance, [:foo, :baz]) }.should raise_error(ArgumentError)
143
+ end
144
+ end
113
145
 
114
- ProbabilityTestClass::Builder.new(@instance,[:foo]).evaluate.should == 0.5
146
+ describe "#given" do
147
+ before(:each) { @builder = ProbabilityTestClass::Builder.new(@instance, {:foo => 1}) }
148
+
149
+ it "sets givens" do
150
+ @builder.given(:bar => 2)
151
+ @builder.givens.should == {:bar => 2}
152
+ end
153
+
154
+ it "returns self" do
155
+ @builder.given(:bar => 2).should be_a(ProbabilityTestClass::Builder)
156
+ end
157
+
158
+ it "fails if variables aren't variables on the estimator" do
159
+ lambda { @builder.given(:baz => 3) }.should raise_error(ArgumentError)
160
+ end
161
+
162
+ it "adds to dataset if passed hash" do
163
+ @builder.given(:foo => 2)
164
+ @builder.given(:foo => 3, :bar => 4)
165
+ @builder.givens.should == {:foo => 3, :bar => 4}
166
+ end
167
+ end
168
+
169
+ describe "#evaluate" do
170
+ it "gets probability of event" do
171
+ pending "is this really worth testing?"
172
+ end
173
+
174
+ it "gets probability of givens" do
175
+ pending "is this really worth testing?"
176
+ end
177
+
178
+ it "returns Pr event / givens (if givens)" do
179
+ pending "is this really worth testing?"
180
+ end
181
+
182
+ it "returns Pr event (if no givens)" do
183
+ pending "is this really worth testing?"
115
184
  end
116
185
  end
117
186
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: pest
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.0
4
+ version: 0.1.0
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors:
@@ -9,7 +9,7 @@ authors:
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2012-06-24 00:00:00.000000000 Z
12
+ date: 2012-07-05 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: pest
@@ -251,6 +251,70 @@ dependencies:
251
251
  - - ! '>='
252
252
  - !ruby/object:Gem::Version
253
253
  version: '0'
254
+ - !ruby/object:Gem::Dependency
255
+ name: jeweler
256
+ requirement: !ruby/object:Gem::Requirement
257
+ none: false
258
+ requirements:
259
+ - - ! '>='
260
+ - !ruby/object:Gem::Version
261
+ version: '0'
262
+ type: :development
263
+ prerelease: false
264
+ version_requirements: !ruby/object:Gem::Requirement
265
+ none: false
266
+ requirements:
267
+ - - ! '>='
268
+ - !ruby/object:Gem::Version
269
+ version: '0'
270
+ - !ruby/object:Gem::Dependency
271
+ name: rake
272
+ requirement: !ruby/object:Gem::Requirement
273
+ none: false
274
+ requirements:
275
+ - - ! '>='
276
+ - !ruby/object:Gem::Version
277
+ version: '0'
278
+ type: :development
279
+ prerelease: false
280
+ version_requirements: !ruby/object:Gem::Requirement
281
+ none: false
282
+ requirements:
283
+ - - ! '>='
284
+ - !ruby/object:Gem::Version
285
+ version: '0'
286
+ - !ruby/object:Gem::Dependency
287
+ name: pry
288
+ requirement: !ruby/object:Gem::Requirement
289
+ none: false
290
+ requirements:
291
+ - - ! '>='
292
+ - !ruby/object:Gem::Version
293
+ version: '0'
294
+ type: :development
295
+ prerelease: false
296
+ version_requirements: !ruby/object:Gem::Requirement
297
+ none: false
298
+ requirements:
299
+ - - ! '>='
300
+ - !ruby/object:Gem::Version
301
+ version: '0'
302
+ - !ruby/object:Gem::Dependency
303
+ name: rspec
304
+ requirement: !ruby/object:Gem::Requirement
305
+ none: false
306
+ requirements:
307
+ - - ! '>='
308
+ - !ruby/object:Gem::Version
309
+ version: '0'
310
+ type: :development
311
+ prerelease: false
312
+ version_requirements: !ruby/object:Gem::Requirement
313
+ none: false
314
+ requirements:
315
+ - - ! '>='
316
+ - !ruby/object:Gem::Version
317
+ version: '0'
254
318
  description: Wrappers to facilitate different classes of probability estimators
255
319
  email: kerinin@gmail.com
256
320
  executables: []
@@ -272,7 +336,6 @@ files:
272
336
  - lib/pest/function.rb
273
337
  - lib/pest/function/entropy.rb
274
338
  - lib/pest/function/probability.rb
275
- - lib/pest/variable.rb
276
339
  - lib/pest/version.rb
277
340
  - pest.gemspec
278
341
  - spec/pest/data_set/hash_spec.rb
@@ -287,7 +350,6 @@ files:
287
350
  - spec/pest/estimator_spec.rb
288
351
  - spec/pest/function/entropy_spec.rb
289
352
  - spec/pest/function/probability_spec.rb
290
- - spec/pest/variable_spec.rb
291
353
  - spec/pest_spec.rb
292
354
  - spec/spec_helper.rb
293
355
  homepage: http://github.com/kerinin/pest
@@ -305,7 +367,7 @@ required_ruby_version: !ruby/object:Gem::Requirement
305
367
  version: '0'
306
368
  segments:
307
369
  - 0
308
- hash: 1228436893259632292
370
+ hash: 851348259220789054
309
371
  required_rubygems_version: !ruby/object:Gem::Requirement
310
372
  none: false
311
373
  requirements:
@@ -314,7 +376,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
314
376
  version: '0'
315
377
  requirements: []
316
378
  rubyforge_project:
317
- rubygems_version: 1.8.24
379
+ rubygems_version: 1.8.23
318
380
  signing_key:
319
381
  specification_version: 3
320
382
  summary: Probability Estimation
@@ -1,34 +0,0 @@
1
- class Pest::Variable
2
- def self.deserialize(string)
3
- if string.chomp =~ /^([^\:]+)\:(\w{8}-\w{4}-\w{4}-\w{4}-\w{12})$/
4
- new :name => $1, :uuid => $2
5
- else
6
- raise "Unable to parse string"
7
- end
8
- end
9
-
10
- attr_reader :name, :uuid
11
-
12
- def initialize(args={})
13
- @name = args[:name]
14
- @uuid = args[:uuid] || UUIDTools::UUID.random_create
15
- end
16
-
17
- def identifier
18
- "#{name}:#{uuid}"
19
- end
20
- alias :serialize :identifier
21
-
22
- def hash
23
- identifier.hash
24
- end
25
-
26
- def ==(other)
27
- other.kind_of?(self.class) and identifier == other.identifier
28
- end
29
- alias :eql? :==
30
-
31
- def <=>(other)
32
- identifier <=> other.identifier
33
- end
34
- end
@@ -1,73 +0,0 @@
1
- require 'spec_helper'
2
-
3
- describe Pest::Variable do
4
- before(:each) { @class = Pest::Variable }
5
-
6
- describe "#uuid" do
7
- it "is generated if not specified" do
8
- @class.new.uuid.should be_true
9
- end
10
-
11
- it "uses uuid passed at instantiation" do
12
- @class.new(:uuid => 'foo').uuid.should == 'foo'
13
- end
14
- end
15
-
16
- describe "#name" do
17
- it "has it" do
18
- @class.new(:name => 'foo').name.should == 'foo'
19
- end
20
- end
21
-
22
- describe "#identifier" do
23
- before(:each) do
24
- @instance = @class.new(:name => 'foo', :uuid => 'bar')
25
- end
26
-
27
- it "concatenates name:uuid" do
28
- @instance.identifier.should == 'foo:bar'
29
- end
30
-
31
- it "is aliased as serialize" do
32
- @instance.serialize.should == 'foo:bar'
33
- end
34
- end
35
-
36
- describe "#==" do
37
- before(:each) do
38
- @one = @class.new(:name => 'foo', :uuid => 'bar')
39
- @two = @class.new(:name => 'foo', :uuid => 'bar')
40
- @three = @class.new(:name => 'foo', :uuid => 'baz')
41
- end
42
-
43
- it "returns true if same identifier" do
44
- @one.should == @two
45
- end
46
-
47
- it "returns false if identifier doesn't match" do
48
- @one.should_not == @three
49
- end
50
-
51
- it "returns false if not a Variable instance" do
52
- @one.should_not == 'hello'
53
- end
54
-
55
- it "works for sets" do
56
- [@one].to_set.should == [@two].to_set
57
- end
58
- end
59
-
60
- describe "::deserialize" do
61
- before(:each) do
62
- @instance = @class.deserialize('foo:4f9b5243-2e2e-4a90-8009-21079fad5855')
63
- end
64
-
65
- it "instantiates with name" do
66
- @instance.name.should == 'foo'
67
- end
68
-
69
- it "instantiates with uuid" do
70
- @instance.uuid.should == '4f9b5243-2e2e-4a90-8009-21079fad5855'
71
- end
72
- end
73
- end