Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 5 additions & 9 deletions howso/value_contributions.amlg
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,9 @@
))

(declare (assoc
enabled_num_features_probability_map (call !ComputeNumEnabledFeaturesProbabilitiesMap (assoc num_features num_features))
;!ComputeNumEnabledFeaturesProbabilitiesMap only creates probabilities up to num_features - 1,
; add 1 to num_features to create probabilities for 0 - num_features
enabled_num_features_probability_map (call !ComputeNumEnabledFeaturesProbabilitiesMap (assoc num_features (+ 1 num_features)))
all_features_map (zip features)
))

Expand Down Expand Up @@ -103,7 +105,7 @@
;number of features to enable is probabilistically weighted
(if (and !tsTimeFeature (!= (size context_features) num_features))
(rand
(call !ComputeNumEnabledFeaturesProbabilitiesMap (assoc num_features num_features))
(call !ComputeNumEnabledFeaturesProbabilitiesMap (assoc num_features (+ 1 num_features)))
)

(rand enabled_num_features_probability_map)
Expand All @@ -113,9 +115,6 @@
)
))

;assoc of all removed features to their residual values, filter the action features to be those that are not context features
(declare (assoc removed_features_map (remove all_features_map react_context_features) ))

(if !tsTimeFeature
(let
(assoc context_map (keep case_values_map react_context_features) )
Expand Down Expand Up @@ -236,10 +235,7 @@

;append features
(accum (assoc react_context_features value_robust_contributions_features ))
(assign (assoc
removed_features_map (remove removed_features_map value_robust_contributions_features)
categorical_action_probabilities_map (assoc)
))
(assign (assoc categorical_action_probabilities_map (assoc) ))

(if !tsTimeFeature
(let
Expand Down
24 changes: 17 additions & 7 deletions unit_tests/ut_h_value_contributions.amlg
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
(seq
#unit_test (direct_assign_to_entities (assoc unit_test (load "unit_test.amlg")))
(call (load "unit_test_howso.amlg") (assoc name "ut_h_value_contributions.amlg"))
(call (load "unit_test_howso.amlg") (assoc name "ut_h_value_contributions.amlg" retries 1))

(call_entity "howso" "create_trainee" (assoc trainee "model"))

Expand Down Expand Up @@ -65,6 +65,7 @@
}
value_robust_contributions_action_feature "score"
value_robust_contributions_features [ "subject" ]
num_robust_accuracy_contributions_samples 200000
))
))
(call keep_result_payload)
Expand All @@ -85,12 +86,20 @@
thresh 0.2
))

(print "Average 'subject' PC matches its avg decomposed robust PC:")
(call assert_approximate (assoc
obs (generalized_mean (get result ["value_robust_contributions" "pc_values"]))
exp (get ac_map ["feature_robust_prediction_contributions" "subject"])
thresh 0.3
))

(print "Average 'subject' PC matches its avg decomposed robust directional PC:")
(call assert_approximate (assoc
obs (generalized_mean (get result ["value_robust_contributions" "pc_directional_values"]))
exp (get ac_map ["feature_robust_directional_prediction_contributions" "subject"])
thresh 0.2
))
(call exit_if_failures (assoc msg "Values A.C. and P.C. computed correctly for 'subject'."))

(print "Computing for 'name': ")
(assign (assoc
Expand All @@ -102,6 +111,7 @@
}
value_robust_contributions_action_feature "score"
value_robust_contributions_features [ "name" ]
num_robust_accuracy_contributions_samples 200000
))
))
(call keep_result_payload)
Expand Down Expand Up @@ -130,7 +140,7 @@
(call assert_approximate (assoc
obs (generalized_mean (get result ["value_robust_contributions" "pc_values"]))
exp (get ac_map ["feature_robust_prediction_contributions" "name"])
thresh 0.6
thresh 0.5
))
(print "both computed and avg decomposed PC are > 2.5: ")
(call assert_true (assoc
Expand All @@ -145,7 +155,7 @@
(call assert_approximate (assoc
obs (generalized_mean (get result ["value_robust_contributions" "pc_directional_values"]))
exp (get ac_map ["feature_robust_directional_prediction_contributions" "name"])
thresh 0.5
thresh 0.4
))
(print "both computed and avg decomposed directional PC are < -0.2: ")
(call assert_true (assoc
Expand All @@ -156,7 +166,7 @@
)
))

(call exit_if_failures (assoc msg "Values A.C. computed correctly."))
(call exit_if_failures (assoc msg "Values A.C. and P.C. computed correctly for 'name'."))

(print "Computing for 'name' and 'subject': ")
(assign (assoc
Expand Down Expand Up @@ -209,7 +219,7 @@
(print "'Anne + math' and 'Fiona + science' both have high P.C. because they are so extreme: ")
(call assert_approximate (assoc
obs (trunc (get result ["value_robust_contributions" "pc_values"]) 2)
exp [5.5 4.5]
exp [5 3.5]
thresh 0.7
))
(print
Expand All @@ -218,7 +228,7 @@
)
(call assert_approximate (assoc
obs (trunc (get result ["value_robust_contributions" "pc_directional_values"]) 2)
exp [5.5 -3.5]
exp [5 -2.5]
thresh 0.7
))
(call exit_if_failures (assoc msg "A.C. and P.C. for two features."))
Expand Down Expand Up @@ -249,7 +259,7 @@
[73.3 79]
]
[
[134.2 148.5]
[109 109.7]
]
]
))
Expand Down