diff --git a/howso/value_contributions.amlg b/howso/value_contributions.amlg index 9e1b6c53..1338c426 100644 --- a/howso/value_contributions.amlg +++ b/howso/value_contributions.amlg @@ -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) )) @@ -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) @@ -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) ) @@ -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 diff --git a/unit_tests/ut_h_value_contributions.amlg b/unit_tests/ut_h_value_contributions.amlg index f1341445..7fa21bab 100644 --- a/unit_tests/ut_h_value_contributions.amlg +++ b/unit_tests/ut_h_value_contributions.amlg @@ -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")) @@ -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) @@ -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 @@ -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) @@ -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 @@ -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 @@ -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 @@ -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 @@ -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.")) @@ -249,7 +259,7 @@ [73.3 79] ] [ - [134.2 148.5] + [109 109.7] ] ] ))