-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
12 changed files
with
226 additions
and
60 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,50 @@ | ||
module Initialization where | ||
|
||
data InitiMethod = GROW | FULL | BTC | HALFHALF | ||
{- | ||
btc = undefined | ||
def btc(pset_, depth_, length_, type_=None): | ||
if type_ is None: | ||
type_ = pset_.ret | ||
expr = [] | ||
arities = list(map(lambda x: x.arity, pset_.primitives[type_])) | ||
minFunctionArity = min(arities) | ||
maxFunctionArity = max(arities) | ||
# adapt length to restrictions of the primitive set | ||
if length_ % 2 == 0 and minFunctionArity > 1: | ||
length_ = length_ + 1 if np.random.random_sample(1) > 0.5 else length_ - 1 | ||
targetLength = length_ - 1 # don't count the root node | ||
maxFunctionArity = min(maxFunctionArity, targetLength) | ||
minFunctionArity = min(minFunctionArity, targetLength) | ||
root = sampleChild(pset_, minFunctionArity, maxFunctionArity, type_) | ||
# inner lists of the form [node, depth, childIndex] | ||
# childIndex is only used at the end to transform | ||
# the representation from breadth to prefix | ||
expr.append([root, 0, 1]) | ||
openSlots = root.arity | ||
for i in range(0, length_): | ||
(node, nodeDepth, childIndex) = expr[i] | ||
childDepth = nodeDepth + 1 | ||
for j in range(0, getArity(node)): | ||
maxArity = 0 if childDepth == depth_ - 1 else min(maxFunctionArity, targetLength - openSlots) | ||
minArity = min(minFunctionArity, maxArity) | ||
child = sampleChild(pset_, minArity, maxArity, type_) | ||
if j == 0: | ||
expr[i][2] = len(expr) | ||
expr.append([child, childDepth, 0]) | ||
openSlots += getArity(child) | ||
nodes = breadthToPrefix(expr) | ||
return nodes | ||
-} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.