idhja22 0.14.3 → 0.14.4

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.
data/idhja22.gemspec CHANGED
@@ -22,4 +22,6 @@ Gem::Specification.new do |gem|
22
22
  gem.add_development_dependency 'simplecov'
23
23
  gem.add_development_dependency 'yard'
24
24
  gem.add_development_dependency 'redcarpet'
25
+
26
+ gem.add_dependency 'configuration'
25
27
  end
@@ -0,0 +1,5 @@
1
+ module Idhja22
2
+ class Bayes
3
+
4
+ end
5
+ end
@@ -0,0 +1,5 @@
1
+ Configuration.for('default') {
2
+ default_probability 0.5
3
+ termination_probability 0.95
4
+ min_dataset_size 20
5
+ }
@@ -15,12 +15,12 @@ module Idhja22
15
15
 
16
16
  def entropy
17
17
  total = self.size
18
- return 1.0 if total < Idhja22::MIN_DATASET_SIZE
18
+ return 1.0 if total < Idhja22.config.min_dataset_size
19
19
  category_counts.values.inject(0.0) { |ent, count| prop = count.to_f/total.to_f; ent-prop*Math.log(prop,2) }
20
20
  end
21
21
 
22
22
  def terminating?
23
- probability > Idhja22::TERMINATION_PROBABILITY || probability < 1-Idhja22::TERMINATION_PROBABILITY
23
+ (probability > Idhja22.config.termination_probability) || (probability < (1-Idhja22.config.termination_probability))
24
24
  end
25
25
  end
26
26
  end
@@ -2,7 +2,7 @@ module Idhja22
2
2
  class Node
3
3
  class << self
4
4
  def build_node(dataset, attributes_available, depth, parent_probability = nil)
5
- if(dataset.size < Idhja22::MIN_DATASET_SIZE)
5
+ if(dataset.size < Idhja22.config.min_dataset_size)
6
6
  return Idhja22::LeafNode.new(probability_guess(parent_probability, depth), dataset.category_label)
7
7
  end
8
8
 
@@ -48,7 +48,7 @@ module Idhja22
48
48
  end
49
49
 
50
50
  def probability_guess(parent_probability, depth)
51
- return (parent_probability + (Idhja22::DEFAULT_PROBABILITY-parent_probability)/2**depth)
51
+ return (parent_probability + (Idhja22.config.default_probability-parent_probability)/2**depth)
52
52
  end
53
53
  end
54
54
 
data/lib/idhja22/tree.rb CHANGED
@@ -1,3 +1,5 @@
1
+ require "idhja22/tree/node"
2
+
1
3
  module Idhja22
2
4
  # The main entry class for a training, viewing and evaluating a decision tree.
3
5
  class Tree
@@ -34,7 +36,7 @@ module Idhja22
34
36
  end
35
37
 
36
38
  def initialize(dataset, attributes_available)
37
- raise Idhja22::Dataset::InsufficientData, "require at least #{Idhja22::MIN_DATASET_SIZE} data points, only have #{dataset.size} in data set provided" if(dataset.size < Idhja22::MIN_DATASET_SIZE)
39
+ raise Idhja22::Dataset::InsufficientData, "require at least #{Idhja22.config.min_dataset_size} data points, only have #{dataset.size} in data set provided" if(dataset.size < Idhja22.config.min_dataset_size)
38
40
  @root = Node.build_node(dataset, attributes_available, 0)
39
41
  end
40
42
 
@@ -1,3 +1,3 @@
1
1
  module Idhja22
2
- VERSION = "0.14.3"
2
+ VERSION = "0.14.4"
3
3
  end
data/lib/idhja22.rb CHANGED
@@ -1,10 +1,23 @@
1
+ require 'configuration'
2
+ require 'idhja22/config/default'
3
+
1
4
  require "idhja22/version"
2
5
  require "idhja22/dataset"
3
6
  require "idhja22/tree"
4
- require "idhja22/node"
7
+ require "idhja22/bayes"
5
8
 
6
9
  module Idhja22
7
- DEFAULT_PROBABILITY = 0.5
8
- TERMINATION_PROBABILITY = 0.95
9
- MIN_DATASET_SIZE = 20
10
+ def self.default_config
11
+ Configuration.for('default')
12
+ end
13
+
14
+ def self.configure(name)
15
+ new_config = Configuration.for(name)
16
+ @cached_config = new_config
17
+ end
18
+
19
+ def self.config
20
+ @cached_config ||= default_config
21
+ end
22
+
10
23
  end
@@ -0,0 +1,5 @@
1
+ require 'spec_helper'
2
+
3
+ describe Idhja22::Bayes do
4
+
5
+ end
data/spec/spec_helper.rb CHANGED
@@ -9,11 +9,11 @@ $: << File.dirname(__FILE__) + '/../lib'
9
9
  require 'idhja22'
10
10
  require 'ruby-debug'
11
11
 
12
- module Idhja22
13
- MIN_DATASET_SIZE = 2
14
- end
15
-
12
+ Configuration.for('spec', Idhja22.config) {
13
+ min_dataset_size 2
14
+ }
16
15
 
16
+ Idhja22.configure('spec')
17
17
 
18
18
  RSpec.configure do |config|
19
19
 
data/spec/version_spec.rb CHANGED
@@ -3,7 +3,7 @@ require 'spec_helper'
3
3
  describe Idhja22 do
4
4
  describe 'VERSION' do
5
5
  it 'should be current version' do
6
- Idhja22::VERSION.should == '0.14.3'
6
+ Idhja22::VERSION.should == '0.14.4'
7
7
  end
8
8
  end
9
9
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: idhja22
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.14.3
4
+ version: 0.14.4
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-12-17 00:00:00.000000000 Z
12
+ date: 2012-12-18 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: rspec
@@ -107,6 +107,22 @@ dependencies:
107
107
  - - ! '>='
108
108
  - !ruby/object:Gem::Version
109
109
  version: '0'
110
+ - !ruby/object:Gem::Dependency
111
+ name: configuration
112
+ requirement: !ruby/object:Gem::Requirement
113
+ none: false
114
+ requirements:
115
+ - - ! '>='
116
+ - !ruby/object:Gem::Version
117
+ version: '0'
118
+ type: :runtime
119
+ prerelease: false
120
+ version_requirements: !ruby/object:Gem::Requirement
121
+ none: false
122
+ requirements:
123
+ - - ! '>='
124
+ - !ruby/object:Gem::Version
125
+ version: '0'
110
126
  description: Decision Trees
111
127
  email:
112
128
  executables:
@@ -124,14 +140,17 @@ files:
124
140
  - bin/idhja22
125
141
  - idhja22.gemspec
126
142
  - lib/idhja22.rb
143
+ - lib/idhja22/bayes.rb
144
+ - lib/idhja22/config/default.rb
127
145
  - lib/idhja22/dataset.rb
128
146
  - lib/idhja22/dataset/datum.rb
129
147
  - lib/idhja22/dataset/errors.rb
130
148
  - lib/idhja22/dataset/tree_methods.rb
131
- - lib/idhja22/node.rb
132
149
  - lib/idhja22/tree.rb
150
+ - lib/idhja22/tree/node.rb
133
151
  - lib/idhja22/version.rb
134
152
  - spec/another_large_spec_data.csv
153
+ - spec/bayes_spec.rb
135
154
  - spec/dataset/example_spec.rb
136
155
  - spec/dataset_spec.rb
137
156
  - spec/large_spec_data.csv
@@ -154,7 +173,7 @@ required_ruby_version: !ruby/object:Gem::Requirement
154
173
  version: '0'
155
174
  segments:
156
175
  - 0
157
- hash: 2323453043414878291
176
+ hash: -803768552583374641
158
177
  required_rubygems_version: !ruby/object:Gem::Requirement
159
178
  none: false
160
179
  requirements:
@@ -163,7 +182,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
163
182
  version: '0'
164
183
  segments:
165
184
  - 0
166
- hash: 2323453043414878291
185
+ hash: -803768552583374641
167
186
  requirements: []
168
187
  rubyforge_project:
169
188
  rubygems_version: 1.8.24
@@ -172,6 +191,7 @@ specification_version: 3
172
191
  summary: A gem for creating decision trees
173
192
  test_files:
174
193
  - spec/another_large_spec_data.csv
194
+ - spec/bayes_spec.rb
175
195
  - spec/dataset/example_spec.rb
176
196
  - spec/dataset_spec.rb
177
197
  - spec/large_spec_data.csv