Skip to content

Commit

Permalink
fix sporadic depth error (#77)
Browse files Browse the repository at this point in the history
* fix sporadic depth error

* update max_depth calc per meeting discussion

* redo max_depth calc per gh discussion

* update tests for new max_depth procedure

* Apply suggestions from code review

Co-authored-by: Ezio Melotti <[email protected]>

* Apply suggestions from code review 2

Co-authored-by: Ezio Melotti <[email protected]>

* Specify default type of `depth_base`.

Co-authored-by: Ezio Melotti <[email protected]>
  • Loading branch information
granawkins and ezio-melotti authored Jul 6, 2022
1 parent b5d1ada commit db2c47a
Show file tree
Hide file tree
Showing 11 changed files with 101 additions and 107 deletions.
8 changes: 4 additions & 4 deletions karoo-gp.py
Original file line number Diff line number Diff line change
Expand Up @@ -332,9 +332,9 @@
'(c)lassification, or (m)atching')
ap.add_argument('-typ', action='store', dest='type', default='r',
help='[f,g,r] Tree type: (f)ull, (g)row, or (r)amped half/half')
ap.add_argument('-bas', action='store', dest='depth_base', default=4,
ap.add_argument('-bas', action='store', dest='depth_base', type=int, default=4,
help='[3...10] maximum Tree depth for the initial population')
ap.add_argument('-max', action='store', dest='depth_max', default=4,
ap.add_argument('-max', action='store', dest='depth_max', type=int, default=None,
help='[3...10] maximum Tree depth for the entire run')
ap.add_argument('-min', action='store', dest='depth_min', default=3,
help='minimum nodes, from 3 to 2^(base_depth +1) - 1')
Expand Down Expand Up @@ -368,8 +368,8 @@
# pass the argparse defaults and/or user inputs to the required variables
kernel = str(args.kernel)
tree_type = str(args.type)
tree_depth_base = int(args.depth_base)
tree_depth_max = int(args.depth_max)
tree_depth_base = args.depth_base
tree_depth_max = args.depth_max
tree_depth_min = int(args.depth_min)
tree_pop_max = int(args.pop_max)
gen_max = int(args.gen_max)
Expand Down
12 changes: 10 additions & 2 deletions karoo_gp/base_class.py
Original file line number Diff line number Diff line change
Expand Up @@ -105,7 +105,7 @@ class BaseGP(object):
"""

def __init__(
self, tree_type='r', tree_depth_base=3, tree_depth_max=3,
self, tree_type='r', tree_depth_base=3, tree_depth_max=None,
tree_depth_min=1, tree_pop_max=100, gen_max=10, tourn_size=7,
filename='', output_dir='', evolve_repro=0.1, evolve_point=0.1,
evolve_branch=0.2, evolve_cross=0.6, display='s', precision=None,
Expand Down Expand Up @@ -159,7 +159,15 @@ def __init__(
self.X_hash = None # hash of last-used fit data
self.gen_max = gen_max # number of generations to evolve
self.swim = swim # culling method
self.tree_depth_max = tree_depth_max # max allowed depth

if tree_depth_max is None:
self.tree_depth_max = tree_depth_base
elif tree_depth_max >= tree_depth_base:
self.tree_depth_max = tree_depth_max
else:
raise ValueError(f'Max depth ({tree_depth_max}) must be greater '
f'or equal to base depth ({tree_depth_base})')

self.tree_depth_min = tree_depth_min # min allowed number of nodes
self.tourn_size = tourn_size # number of Trees per tournament
self.evolve_repro = evolve_repro # ratio of next_gen reproduced
Expand Down
42 changes: 21 additions & 21 deletions karoo_gp/test/data/results[c-f].json
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@
{
"package": "Karoo GP",
"launched": "2022-06-12_06-15-25-662209",
"launched": "2022-07-06_20-39-53-790684",
"dataset": "karoo_gp/files/data_CLASSIFY.csv",
"config": {
"kernel": "c",
"precision": 6,
"tree_type": "f",
"tree_depth_base": 3,
"tree_depth_max": 4,
"tree_depth_max": 3,
"min_node_count": 3,
"genetic_operators": {
"reproduction": 0.1,
Expand All @@ -21,41 +21,41 @@
},
"outcome": "SUCCESS",
"fittest_tree": {
"id": 5,
"expression": "pl**2/sw - sl - pw/(pl**2*sw)"
"id": 10,
"expression": "pl*sl/sw - pl/pw - sl"
},
"score": {
"fitness": 26.0,
"fitness": 23.0,
"classification_report": {
"0.0": {
"precision": 1.0,
"precision": 0.6,
"recall": 1.0,
"f1-score": 1.0,
"f1-score": 0.7499999999999999,
"support": 9
},
"1.0": {
"precision": 1.0,
"recall": 0.6666666666666666,
"f1-score": 0.8,
"recall": 0.4166666666666667,
"f1-score": 0.5882352941176471,
"support": 12
},
"2.0": {
"precision": 0.6923076923076923,
"precision": 0.9,
"recall": 1.0,
"f1-score": 0.8181818181818181,
"f1-score": 0.9473684210526316,
"support": 9
},
"accuracy": 0.8666666666666667,
"accuracy": 0.7666666666666667,
"macro avg": {
"precision": 0.8974358974358975,
"recall": 0.8888888888888888,
"f1-score": 0.8727272727272727,
"precision": 0.8333333333333334,
"recall": 0.8055555555555557,
"f1-score": 0.7618679050567595,
"support": 30
},
"weighted avg": {
"precision": 0.9076923076923077,
"recall": 0.8666666666666667,
"f1-score": 0.8654545454545455,
"precision": 0.85,
"recall": 0.7666666666666667,
"f1-score": 0.7445046439628483,
"support": 30
}
},
Expand All @@ -66,9 +66,9 @@
0
],
[
0,
8,
4
6,
5,
1
],
[
0,
Expand Down
40 changes: 20 additions & 20 deletions karoo_gp/test/data/results[c-g].json
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@
{
"package": "Karoo GP",
"launched": "2022-06-12_06-16-20-639880",
"launched": "2022-07-06_20-39-14-375734",
"dataset": "karoo_gp/files/data_CLASSIFY.csv",
"config": {
"kernel": "c",
"precision": 6,
"tree_type": "g",
"tree_depth_base": 3,
"tree_depth_max": 4,
"tree_depth_max": 3,
"min_node_count": 3,
"genetic_operators": {
"reproduction": 0.1,
Expand All @@ -21,41 +21,41 @@
},
"outcome": "SUCCESS",
"fittest_tree": {
"id": 9,
"expression": "pl*pw**2 + pw*sw - sl"
"id": 10,
"expression": "2*pl - sw**2 + 1"
},
"score": {
"fitness": 19.0,
"fitness": 20.0,
"classification_report": {
"0.0": {
"precision": 1.0,
"precision": 0.9,
"recall": 1.0,
"f1-score": 1.0,
"f1-score": 0.9473684210526316,
"support": 9
},
"1.0": {
"precision": 1.0,
"recall": 0.08333333333333333,
"f1-score": 0.15384615384615385,
"recall": 0.16666666666666666,
"f1-score": 0.2857142857142857,
"support": 12
},
"2.0": {
"precision": 0.45,
"precision": 0.5,
"recall": 1.0,
"f1-score": 0.6206896551724138,
"f1-score": 0.6666666666666666,
"support": 9
},
"accuracy": 0.6333333333333333,
"accuracy": 0.6666666666666666,
"macro avg": {
"precision": 0.8166666666666668,
"recall": 0.6944444444444443,
"f1-score": 0.5915119363395225,
"precision": 0.7999999999999999,
"recall": 0.7222222222222223,
"f1-score": 0.633249791144528,
"support": 30
},
"weighted avg": {
"precision": 0.8350000000000001,
"recall": 0.6333333333333333,
"f1-score": 0.5477453580901857,
"precision": 0.8200000000000001,
"recall": 0.6666666666666666,
"f1-score": 0.5984962406015039,
"support": 30
}
},
Expand All @@ -66,9 +66,9 @@
0
],
[
0,
1,
11
2,
9
],
[
0,
Expand Down
48 changes: 24 additions & 24 deletions karoo_gp/test/data/results[c-r].json
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@
{
"package": "Karoo GP",
"launched": "2022-06-12_06-16-39-210454",
"launched": "2022-07-06_20-38-32-741216",
"dataset": "karoo_gp/files/data_CLASSIFY.csv",
"config": {
"kernel": "c",
"precision": 6,
"tree_type": "r",
"tree_depth_base": 3,
"tree_depth_max": 4,
"tree_depth_max": 3,
"min_node_count": 3,
"genetic_operators": {
"reproduction": 0.1,
Expand All @@ -21,41 +21,41 @@
},
"outcome": "SUCCESS",
"fittest_tree": {
"id": 3,
"expression": "pl + pw - sl"
"id": 6,
"expression": "pw - 1"
},
"score": {
"fitness": 18.0,
"fitness": 27.0,
"classification_report": {
"0.0": {
"precision": 0.5625,
"precision": 1.0,
"recall": 1.0,
"f1-score": 0.72,
"f1-score": 1.0,
"support": 9
},
"1.0": {
"precision": 0.5,
"recall": 0.25,
"f1-score": 0.3333333333333333,
"precision": 0.9090909090909091,
"recall": 0.8333333333333334,
"f1-score": 0.8695652173913043,
"support": 12
},
"2.0": {
"precision": 0.75,
"recall": 0.6666666666666666,
"f1-score": 0.7058823529411765,
"precision": 0.8,
"recall": 0.8888888888888888,
"f1-score": 0.8421052631578948,
"support": 9
},
"accuracy": 0.6,
"accuracy": 0.9,
"macro avg": {
"precision": 0.6041666666666666,
"recall": 0.6388888888888888,
"f1-score": 0.5864052287581699,
"precision": 0.903030303030303,
"recall": 0.9074074074074074,
"f1-score": 0.9038901601830663,
"support": 30
},
"weighted avg": {
"precision": 0.59375,
"recall": 0.6,
"f1-score": 0.5610980392156864,
"precision": 0.9036363636363636,
"recall": 0.9,
"f1-score": 0.9004576659038901,
"support": 30
}
},
Expand All @@ -66,14 +66,14 @@
0
],
[
7,
3,
0,
10,
2
],
[
0,
3,
6
1,
8
]
]
}
Expand Down
13 changes: 3 additions & 10 deletions karoo_gp/test/data/results[m-f].json
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@
{
"package": "Karoo GP",
"launched": "2022-06-12_06-17-46-867022",
"launched": "2022-07-06_20-37-24-150346",
"dataset": "karoo_gp/files/data_MATCH.csv",
"config": {
"kernel": "m",
"precision": 6,
"tree_type": "f",
"tree_depth_base": 3,
"tree_depth_max": 4,
"tree_depth_max": 3,
"min_node_count": 3,
"genetic_operators": {
"reproduction": 0.1,
Expand All @@ -19,12 +19,5 @@
"population": 50,
"number_of_generations": 10
},
"outcome": "SUCCESS",
"fittest_tree": {
"id": 45,
"expression": "-a + 3*b + c - 2"
},
"score": {
"fitness": 10.0
}
"outcome": "FAILURE"
}
6 changes: 3 additions & 3 deletions karoo_gp/test/data/results[m-g].json
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@
{
"package": "Karoo GP",
"launched": "2022-06-12_06-18-20-189034",
"launched": "2022-07-06_20-36-33-411609",
"dataset": "karoo_gp/files/data_MATCH.csv",
"config": {
"kernel": "m",
"precision": 6,
"tree_type": "g",
"tree_depth_base": 3,
"tree_depth_max": 4,
"tree_depth_max": 3,
"min_node_count": 3,
"genetic_operators": {
"reproduction": 0.1,
Expand All @@ -21,7 +21,7 @@
},
"outcome": "SUCCESS",
"fittest_tree": {
"id": 25,
"id": 27,
"expression": "a + b + c"
},
"score": {
Expand Down
Loading

0 comments on commit db2c47a

Please sign in to comment.