Class: Wallace::Koza::Builder
- Inherits:
-
Object
- Object
- Wallace::Koza::Builder
- Defined in:
- lib/modules/koza/builder.rb
Overview
The base class used by all Koza tree builders.
Direct Known Subclasses
Defined Under Namespace
Classes: FullBuilder, GrowBuilder, HalfBuilder
Instance Attribute Summary collapse
-
#depth_limits ⇒ Object
The range of depths that trees within this species may have.
-
#non_terminals ⇒ Object
readonly
Returns the value of attribute non_terminals.
-
#terminals ⇒ Object
readonly
Returns the value of attribute terminals.
Instance Method Summary collapse
-
#build_subtree(max_depth, opts = {}) ⇒ Object
Builds a new subtree of a maximum given depth.
-
#build_tree(opts = {}) ⇒ Object
Builds a new tree according to this build method that meets the depth constraints of the species.
-
#prepare(terminals, non_terminals, depth_limits) ⇒ Object
Prepares the builder.
Instance Attribute Details
#depth_limits ⇒ Object
The range of depths that trees within this species may have.
5 6 7 |
# File 'lib/modules/koza/builder.rb', line 5 def depth_limits @depth_limits end |
#non_terminals ⇒ Object (readonly)
Returns the value of attribute non_terminals.
7 8 9 |
# File 'lib/modules/koza/builder.rb', line 7 def non_terminals @non_terminals end |
#terminals ⇒ Object (readonly)
Returns the value of attribute terminals.
7 8 9 |
# File 'lib/modules/koza/builder.rb', line 7 def terminals @terminals end |
Instance Method Details
#build_subtree(max_depth, opts = {}) ⇒ Object
Builds a new subtree of a maximum given depth.
Parameters:
-
max_depth, the maximum depth of the sub-tree.
-
opts, a hash of keyword options for this method. -> random, the RNG to use for building the subtree.
Returns: The root node of the built sub-tree.
44 45 46 |
# File 'lib/modules/koza/builder.rb', line 44 def build_subtree(max_depth, opts = {}) raise NotImplementedError, 'No "build_subtree" function was implemented by this builder.' end |
#build_tree(opts = {}) ⇒ Object
Builds a new tree according to this build method that meets the depth constraints of the species.
Parameters:
-
opts, a hash of keyword options for this method. -> random, the RNG to use for building the tree.
Returns: The built tree.
31 32 33 |
# File 'lib/modules/koza/builder.rb', line 31 def build_tree(opts = {}) raise NotImplementedError, 'No "build_tree" function was implemented by this builder.' end |
#prepare(terminals, non_terminals, depth_limits) ⇒ Object
Prepares the builder.
Parameters:
-
terminals, the list of terminals.
-
non_terminals, the list of non-terminals.
-
depth_limits, the range of depths that trees within the species may have.
16 17 18 19 20 |
# File 'lib/modules/koza/builder.rb', line 16 def prepare(terminals, non_terminals, depth_limits) @terminals = terminals @non_terminals = non_terminals @depth_limits = depth_limits end |