Skip to content

Commit

Permalink
removing refs to MDA, updating method names
Browse files Browse the repository at this point in the history
  • Loading branch information
cademack committed Feb 18, 2025
1 parent df654ae commit aa7eaa8
Show file tree
Hide file tree
Showing 9 changed files with 95 additions and 101 deletions.
2 changes: 1 addition & 1 deletion howso/analysis_weights.amlg
Original file line number Diff line number Diff line change
Expand Up @@ -133,7 +133,7 @@
;mda for each context feature as a ratio of error_with_feature_removed / baseline_error (where baseline uses all the context features)
(declare (assoc
context_features_mda_map
(call !DecreaseInAccuracy (assoc
(call !CalculateFeatureAccuracyContributions (assoc
context_features context_features
action_features (list action_feature)
output_ratio (true)
Expand Down
4 changes: 2 additions & 2 deletions howso/contributions.amlg
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
;Contains methods for computing and outputting feature contributions.
(null

;Calculate and cache feature contributions - average delta between predicted value for action_feature with and without a context feature
;Calculate feature prediction contributions - average delta between predicted value for action_feature with and without a context feature
; for all specified context_features.
;
;parameters:
Expand All @@ -21,7 +21,7 @@
; run_on_local_model: optional, if true will use all the provided cases and not store results to model
; context_condition_filter_query: a list of queries that can be used to filter the possible set of cases that can be used for predictions
; use_derivation_logic: flag, if true action feature will be derived and the features needed to derive will be predicted
#!CalculateFeatureContributions
#!CalculateFeaturePredictionContributions
(declare
(assoc
context_features (list)
Expand Down
10 changes: 5 additions & 5 deletions howso/details_influences.amlg
Original file line number Diff line number Diff line change
Expand Up @@ -47,15 +47,15 @@
output
(if robust
(assoc "feature_robust_accuracy_contributions"
(call !DecreaseInAccuracy (assoc
(call !CalculateFeatureAccuracyContributions (assoc
context_features context_features
action_features action_features
case_ids local_model_case_ids
robust (true)
))
)
(assoc "feature_full_accuracy_contributions"
(call !DecreaseInAccuracy (assoc
(call !CalculateFeatureAccuracyContributions (assoc
context_features context_features
action_features action_features
case_ids local_model_case_ids
Expand Down Expand Up @@ -119,15 +119,15 @@
output
(if robust
(assoc "feature_robust_accuracy_contributions_ex_post"
(call !DecreaseInAccuracy (assoc
(call !CalculateFeatureAccuracyContributions (assoc
context_features context_features
action_features action_features
case_ids local_model_case_ids
robust (true)
))
)
(assoc "feature_full_accuracy_contributions_ex_post"
(call !DecreaseInAccuracy (assoc
(call !CalculateFeatureAccuracyContributions (assoc
context_features context_features
action_features action_features
case_ids local_model_case_ids
Expand Down Expand Up @@ -653,7 +653,7 @@

(declare (assoc
feature_contributions_pair
(call !CalculateFeatureContributions (assoc
(call !CalculateFeaturePredictionContributions (assoc
context_features context_features
action_feature action_feature
robust robust
Expand Down
118 changes: 56 additions & 62 deletions howso/influences.amlg
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
;Contains methods for computing and outputting feature MDA.
(null
;calculate the decrease in accuracy for the specified list of context and action features
;calculate the accuracy contribution for each feature as the decrease in accuracy for the specified list of context and action features
;outputs an assoc of context features -> decrease in accuracy Mean Absolute Error value
; if output_ratio, the ratio is: feature_mae / baseline_mae
; else: feature_mae - baseline_mae
Expand All @@ -22,7 +22,7 @@
; weight_feature: optional, default '.case_weight'. name of feature whose values to use as case weights
; context_condition_filter_query: a list of queries that can be used to filter the possible set of cases that can be used for predictions
; use_derivation_logic: flag, if true action feature will be derived and the features needed to derive will be predicted
#!DecreaseInAccuracy
#!CalculateFeatureAccuracyContributions
(declare
(assoc
context_features (list)
Expand Down Expand Up @@ -95,75 +95,69 @@
))
))

(declare (assoc
output
;knock out each feature one by one and calculate the decrease in accuracy for each feature
(zip
(or details_context_features context_features)
(map
(lambda (let
(assoc
mae_context_features context_features
)
(zip
(or details_context_features context_features)
(map
(lambda (let
(assoc
mae_context_features context_features
)

;regular Decrease in accuracy is feature knockout instead of scrambling the feature
(if (not sensitivity_to_randomization)
;remove the feature
(assign (assoc
mae_context_features (indices (remove context_features_mda (current_value 1)))
))
)
;regular Decrease in accuracy is feature knockout instead of scrambling the feature
(if (not sensitivity_to_randomization)
;remove the feature
(assign (assoc
mae_context_features (indices (remove context_features_mda (current_value 1)))
))
)

(let
(assoc
feature_mda
(call !CalculateModelMAE (assoc
action_features action_features
context_features mae_context_features
case_ids case_ids
ignore_exact_cases (true)
classification_precision classification_precision
robust_residuals robust
custom_hyperparam_map hyperparam_map
use_case_weights use_case_weights
weight_feature weight_feature
context_condition_filter_query context_condition_filter_query
use_derivation_logic use_derivation_logic

;the scramble feature index will be null if doing feature knockout
scramble_feature_index
(if sensitivity_to_randomization
(current_index 2)
(null)
)
))
)
(let
(assoc
feature_mda
(call !CalculateModelMAE (assoc
action_features action_features
context_features mae_context_features
case_ids case_ids
ignore_exact_cases (true)
classification_precision classification_precision
robust_residuals robust
custom_hyperparam_map hyperparam_map
use_case_weights use_case_weights
weight_feature weight_feature
context_condition_filter_query context_condition_filter_query
use_derivation_logic use_derivation_logic

;the scramble feature index will be null if doing feature knockout
scramble_feature_index
(if sensitivity_to_randomization
(current_index 2)
(null)
)
))
)

;output the decrease in accuracy as a ratio of the feature / baseline MAE
(if output_ratio
;prevent output of (null) in case all maes are 0
(if (= 0 baseline_error)
.infinity
;output the decrease in accuracy as a ratio of the feature / baseline MAE
(if output_ratio
;prevent output of (null) in case all maes are 0
(if (= 0 baseline_error)
.infinity

(/ feature_mda baseline_error)
)
(/ feature_mda baseline_error)
)

;else output the difference in the MAE
(if (= .infinity baseline_error feature_mda)
0
;else output the difference in the MAE
(if (= .infinity baseline_error feature_mda)
0

(- feature_mda baseline_error)
)
)
(- feature_mda baseline_error)
)
))

(or details_context_features context_features)
)
)
)
))
))

output
(or details_context_features context_features)
)
)
)


Expand Down
12 changes: 6 additions & 6 deletions howso/react.amlg
Original file line number Diff line number Diff line change
Expand Up @@ -171,22 +171,22 @@
; If "all", then returns all including the confusion_matrix. Valid values are: "mae" "confusion_matrix" "r2" "rmse"
; "adjusted_smape" "smape" "spearman_coeff" "precision" "recall" "accuracy" "mcc" "all" "missing_value_accuracy"
;
; "feature_robust_accuracy_contributions" true or false. If true outputs each context feature's robust mean decrease in accuracy of predicting
; "feature_robust_accuracy_contributions" true or false. If true outputs each context feature's robust Accuracy Contribution in predicting
; the action feature given the context. Uses only the context features of the reacted
; case to determine that area. Uses robust calculations, which uses uniform sampling from
; the power set of features as the contexts for predictions.
;
; "feature_full_accuracy_contributions" true or false. If true outputs each context feature's full mean decrease in accuracy of predicting
; "feature_full_accuracy_contributions" true or false. If true outputs each context feature's full Accuracy Contribution in predicting
; the action feature given the context. Uses only the context features of the reacted
; case to determine that area. Uses full calculations, which uses leave-one-out context features for computations.
;
; "feature_robust_accuracy_contributions_ex_post" true or false. If true outputs each context feature's mean decrease in accuracy of
; "feature_robust_accuracy_contributions_ex_post" true or false. If true outputs each context feature's Accuracy Contribution in
; predicting the action feature as a detail given that the specified prediction was
; already made as specified by the action value. Uses both context and action features of
; the reacted case to determine that area. Uses robust calculations, which uses uniform sampling from
; the power set of features as the contexts for predictions.
;
; "feature_full_accuracy_contributions_ex_post" true or false. If true outputs each context feature's mean decrease in accuracy of
; "feature_full_accuracy_contributions_ex_post" true or false. If true outputs each context feature's Accuracy Contribution in
; predicting the action feature as a detail given that the specified prediction was
; already made as specified by the action value. Uses both context and action features of
; the reacted case to determine that area. Uses full calculations, which uses leave-one-out for features for computations.
Expand All @@ -204,12 +204,12 @@
; both 'feature_contributions' and non-absolute 'directional_feature_contributions'.
; Uses full calculations, which uses leave-one-out context features for computations.
;
; "case_robust_prediction_contributions" true or false. If true outputs each influential case's mean decrease in accuracy of predicting
; "case_robust_prediction_contributions" true or false. If true outputs each influential case's Accuracy Contribution in predicting
; the action feature in the local model area, as if each individual case were included
; versus not included. Uses only the context features of the reacted case to determine
; that area. Uses robust calculations, which uses uniform sampling from the power set of all combinations of cases.
;
; "case_full_prediction_contributions" true or false. If true outputs each influential case's mean decrease in accuracy of predicting
; "case_full_prediction_contributions" true or false. If true outputs each influential case's Accuracy Contribution in predicting
; the action feature in the local model area, as if each individual case were included
; versus not included. Uses only the context features of the reacted case to determine
; that area. Uses full calculations, which uses leave-one-out for cases for computations.
Expand Down
32 changes: 16 additions & 16 deletions howso/react_aggregate.amlg
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
;Contains methods for computing, storing into the trainee, and returning residuals, prediction_stats, feature_mda, and feature_contributions.
;Contains methods for computing, storing into the trainee, and returning residuals, prediction_stats, accuracy contributions, and prediction contributions.
(null
;Computes, caches, and returns specified details and feature prediction statistics such as Mean Decrease in Accuracy (MDA), residuals (accuracy, Mean Absolute Error),
;Computes, caches, and returns specified details and feature prediction statistics such as Accuracy Contributions, residuals (accuracy, Mean Absolute Error),
; precision, recall, etc. Returns details and feature prediction stats for all features in the format of feature -> assoc stat -> value
;{long_running (true) statistically_idempotent (true)}
#react_aggregate
Expand Down Expand Up @@ -39,7 +39,7 @@
; Applicable only to models > 1000 cases.
sub_model_size (null)
;{type "string"}
;target feature for which to do computations. If "prediction_stats_action_feature" and "feature_influences_action_feature"
;target feature for which to do feature influences computations (accuracy contributions or prediction contributions). If "prediction_stats_action_feature" and "feature_influences_action_feature"
; are not provided, they will default to this value.
action_feature (null)
;{type "string"}
Expand All @@ -49,11 +49,11 @@
; If this value is not specified but "action_feature" is provided, this value will default to the value of "action_feature".
prediction_stats_action_feature (null)
;{type "string"}
;When feature influences such as contributions and mda, use this feature as the action feature.
;When computing feature influences such as prediction contributions or accuracy contributions, use this feature as the action feature.
; If not provided, will default to the "action_feature" if provided.
feature_influences_action_feature (null)
;{type "boolean"}
;flag, optional. if specified, will attempt to return stats that were computed using hyperpparameters with the
;flag, optional. if specified, will attempt to return stats that were computed using hyperparameters with the
; specified robust or non-robust type.
robust_hyperparameters (null)
;{type "number" min 0}
Expand Down Expand Up @@ -91,13 +91,13 @@
; Uses robust computation.
; feature_deviations: optional, none/true/false. if true will compute feature deviations for each feature in action_features. The feature deviation is the mean absolute
; error of predicting the feature using all the context features as well as value of the feature being predicted as the context for each prediction.
; feature_full_accuracy_contributions: optional, none/true/false. if true will compute Mean Decrease in Accuracy (feature_mda) for each context feature at predicting action_feature.
; feature_full_accuracy_contributions: optional, none/true/false. if true will compute Accuracy Contributions for each context feature at predicting action_feature.
; Drop each feature and use the full set of remaining context features for each prediction. Uses full computation.
; feature_full_accuracy_contributions_permutation: optional, none/true/false. Compute feature_full_accuracy_contributions by scrambling each feature and using the full set of remaining context features
; feature_full_accuracy_contributions_permutation: optional, none/true/false. Compute Accuracy Contributions by scrambling each feature and using the full set of remaining context features
; for each prediction. Uses full computation.
; feature_robust_accuracy_contributions: optional, none/true/false. Compute feature_mda by dropping each feature and using the robust (power set/permutations) set of
; feature_robust_accuracy_contributions: optional, none/true/false. Compute Accuracy Contributions by dropping each feature and using the robust (power set/permutations) set of
; remaining context features for each prediction. Uses robust computation.
; feature_robust_accuracy_contributions_permutation: optional, none/true/false. Compute feature_mda by scrambling each feature and using the robust (power set/permutations)
; feature_robust_accuracy_contributions_permutation: optional, none/true/false. Compute Accuracy Contributions by scrambling each feature and using the robust (power set/permutations)
; set of remaining context features for each prediction. Uses robust computation.
; selected_prediction_stats": list of strings, optional. Allowed values are:
; "mae" : Mean absolute error. For continuous features, this is calculated as the mean of absolute values of the difference
Expand Down Expand Up @@ -211,7 +211,7 @@
)
)
(conclude
(call !Return (assoc errors (list "action_feature must be specified when computing feature_mda_permutation, feature_mda, or feature_contributions.")))
(call !Return (assoc errors (list "action_feature must be specified when computing Accuracy Contributions or Prediction Contributions.")))
)
)

Expand Down Expand Up @@ -549,7 +549,7 @@
(if (get details "feature_full_prediction_contributions")
(accum (assoc
output
(call !CalculateFeatureContributions (assoc
(call !CalculateFeaturePredictionContributions (assoc
context_features context_features
action_feature feature_influences_action_feature
robust (false)
Expand All @@ -566,7 +566,7 @@
(if (get details "feature_robust_prediction_contributions")
(accum (assoc
output
(call !CalculateFeatureContributions (assoc
(call !CalculateFeaturePredictionContributions (assoc
context_features context_features
action_feature feature_influences_action_feature
robust (true)
Expand Down Expand Up @@ -601,7 +601,7 @@
output
(assoc
"feature_full_accuracy_contributions"
(call !DecreaseInAccuracy (assoc
(call !CalculateFeatureAccuracyContributions (assoc
context_features context_features
action_features [feature_influences_action_feature]
sensitivity_to_randomization (false)
Expand All @@ -622,7 +622,7 @@
output
(assoc
"feature_robust_accuracy_contributions"
(call !DecreaseInAccuracy (assoc
(call !CalculateFeatureAccuracyContributions (assoc
context_features context_features
action_features [feature_influences_action_feature]
sensitivity_to_randomization (false)
Expand All @@ -643,7 +643,7 @@
output
(assoc
"feature_full_accuracy_contributions_permutation"
(call !DecreaseInAccuracy (assoc
(call !CalculateFeatureAccuracyContributions (assoc
context_features context_features
action_features [feature_influences_action_feature]
sensitivity_to_randomization (true)
Expand All @@ -664,7 +664,7 @@
output
(assoc
"feature_robust_accuracy_contributions_permutation"
(call !DecreaseInAccuracy (assoc
(call !CalculateFeatureAccuracyContributions (assoc
context_features context_features
action_features [feature_influences_action_feature]
sensitivity_to_randomization (true)
Expand Down
2 changes: 1 addition & 1 deletion howso/react_discriminative.amlg
Original file line number Diff line number Diff line change
Expand Up @@ -246,7 +246,7 @@
(get details "feature_robust_prediction_contributions")
(get details "case_full_prediction_contributions")
(get details "case_robust_prediction_contributions")
;feature mda does not need to output C.A.P. because it calls the generic DecreaseInAccuracy method which in turn uses
;feature mda does not need to output C.A.P. because it calls the generic CalculateFeatureAccuracyContributions method which in turn uses
;ReactDiscriminative method with different feature sets, instead of simply calling GenerateReaction or InterpolateActionValues
)

Expand Down
Loading

0 comments on commit aa7eaa8

Please sign in to comment.