Skip to content

Commit

Permalink
Bug for missing context score fixed.
Browse files Browse the repository at this point in the history
  • Loading branch information
felixleopoldo committed Feb 7, 2024
1 parent e4f67f0 commit 02f14a1
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 4 deletions.
3 changes: 2 additions & 1 deletion src/cstrees/learning.py
Original file line number Diff line number Diff line change
Expand Up @@ -165,7 +165,8 @@ def _optimal_staging_at_level(
# here we (=I) anyway extract just the context, so the stage format
# is a bit redundant.
stage_context = sc._stage_to_context_key(stage, order)
score = context_scores["scores"][var][stage_context]
if stage_context in context_scores["scores"][var]:
score = context_scores["scores"][var][stage_context]
staging_score += score

# Update the max score and the max staging
Expand Down
9 changes: 6 additions & 3 deletions src/cstrees/scoring.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,8 @@
import cstrees.stage as st
import cstrees.dependence as csi_rel

import pp


def _counts_at_level(cstree: ct.CStree, level: int, data):
"""Collect all the observed counts at a specific level by stages.
Expand Down Expand Up @@ -264,9 +266,8 @@ def _context_score_tables(
# get the counts
testdf = test.to_frame().rename(
columns={var: str(var) + " counts"})
for index, r in testdf.iterrows():
for index, r in testdf.iterrows(): #index represents the context variables and the value of the variable
value = None

# Sort variables
context = ""
if len(active_labels) > 0:
Expand Down Expand Up @@ -518,7 +519,9 @@ def order_score_tables(
for stage in staging:
# OK! even when restricting to some possible cvars
stage_context = _stage_to_context_key(stage, subset)
staging_unnorm_post += context_scores["scores"][var][stage_context]
if stage_context in context_scores["scores"][var]:
# If the context is not in the data it can be ignored as it would vanish in the score.
staging_unnorm_post += context_scores["scores"][var][stage_context]

if i == 0:
order_scores["scores"][var][subset_str] = staging_unnorm_post
Expand Down

0 comments on commit 02f14a1

Please sign in to comment.