Skip to content
Merged
Show file tree
Hide file tree
Changes from 6 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
100 changes: 52 additions & 48 deletions howso/contributions.amlg
Original file line number Diff line number Diff line change
Expand Up @@ -255,18 +255,24 @@
;of predicting the action_feature when using vs not using it as a context feature. Sets feature_contributions_map.
#!RunRobustContributions
(let
(assoc
enabled_num_features_probability_map
(call !ComputeNumEnabledFeaturesProbabilitiesMap (assoc num_features (size all_context_features) ))
num_features (size all_context_features)

)
;iterate over all the local cases, for each case, react multiple times with a different robust context feature set each time
;for each react, store the reacted value for features that were used as contexts into each of those features' 'with feature' list
;and store that reacted value for feature that were not used into each of their 'without feature' list
;Then for each feature, average out all the 'with' and all the 'without' values and take the delta to compute the average delta
;repeat for all cases and average those out.
(assoc
(declare (assoc
accrued_cases_delta_lists
||(map
(lambda (let
(assoc
case_id (current_value 1)
correct_value (retrieve_from_entity (current_value 1) action_feature)
correct_value (if action_is_nominal (retrieve_from_entity (current_value 1) action_feature) )
case_values_map (zip context_features (retrieve_from_entity (current_value 1) context_features))
local_case_reaction_pairs (list)
;save an inner version in this scope to update per case for time-series flows
Expand Down Expand Up @@ -305,9 +311,6 @@
(range
(lambda (let
(assoc
;list of bits for each remaining (non-removed) feature
remaining_feature_flags (list)
all_flags_set .true
;list of remaining filtered context features
filtered_context_features (list)
;set of all removed features
Expand All @@ -317,42 +320,29 @@
reaction (null)
)

;for robust computation we randomly (50/50) decide whether to remove a feature from the context
;by creating a random flag list to match each of the context features
;ensure that at least one feature is removed
;this while statement should only loop in rare edge cases
(while all_flags_set
(assign (assoc remaining_feature_flags (map (lambda (< (rand) 0.5)) all_context_features) ))
(if (< (size context_features) (size all_context_features))
;ensure TS filtered features stay false
(let
(assoc
original_indices_for_context_features
(unzip all_context_features_indices_map context_features)
;filter out a random number of context features
(assign (assoc
filtered_context_features
(rand
context_features
;number of features to enable is probabilistically weighted
(if (and !tsTimeFeature (!= (size context_features) num_features))
(rand
(call !ComputeNumEnabledFeaturesProbabilitiesMap (assoc num_features (size context_features) ))
)

(rand enabled_num_features_probability_map)
)
;keeps only those flags that match the original indices for remaining context_features
(assign (assoc
remaining_feature_flags
(map
(lambda
(if (contains_value original_indices_for_context_features (current_index))
(current_value)
.false
)
)
remaining_feature_flags
)
))
;unique random features (not with replacement)
.true
)
)
;shortcut on the all_flags_set logic so that if there is only one context feature, it can be left in the context
(assign (assoc all_flags_set (and (!= (size context_features) 1) (apply "and" remaining_feature_flags)) ))
)
;filter out context features based on the bitmask and also create a set of all the removed features
))

;assoc of all removed features to their residual values
(assign (assoc
filtered_context_features (filter (lambda (get remaining_feature_flags (current_index))) all_context_features)
without_features_set
(zip (filter (lambda (not (get remaining_feature_flags (current_index)) )) all_context_features) )
;filter the action features to be those that are not context features, feature/context_features params may overlap
(remove (zip all_context_features) filtered_context_features)
))

(if derive_action_feature
Expand Down Expand Up @@ -416,18 +406,32 @@
(assoc feature_index (current_index 1))

(declare (assoc
;for this feature, pull all the 'with' react values, filtering out nulls
;for this feature, pull all the 'with' react values, filtering out nulls if edit distance
feature_reactions_with
(filter (map
(lambda (get (first (current_value)) feature_index) )
local_case_reaction_pairs
))
;for this feature, pull all the 'without' react values, filtering out nulls
(if edit_distance_action_feature
(filter (map
(lambda (get (first (current_value)) feature_index) )
local_case_reaction_pairs
))
;else no need to filter nulls since generalized_mean does it automatically
(map
(lambda (get (first (current_value)) feature_index) )
local_case_reaction_pairs
)
)
;for this feature, pull all the 'without' react values, filtering out nulls if edit distance
feature_reactions_without
(filter (map
(lambda (get (last (current_value)) feature_index) )
local_case_reaction_pairs
))
(if edit_distance_action_feature
(filter (map
(lambda (get (last (current_value)) feature_index) )
local_case_reaction_pairs
))
;else no need to filter nulls since generalized_mean does it automatically
(map
(lambda (get (last (current_value)) feature_index) )
local_case_reaction_pairs
)
)
))

(if edit_distance_action_feature
Expand Down Expand Up @@ -494,7 +498,7 @@
))
case_ids
)
)
))

;compute feature contributions by averaging out each "column" feature delta across all cases, which is in the format of:
; (list
Expand Down
11 changes: 9 additions & 2 deletions howso/details_influences.amlg
Original file line number Diff line number Diff line change
Expand Up @@ -760,8 +760,15 @@
(assign (assoc
feature_contributions_pair_map
(if robust
(seq
;populate local_case_reaction_pairs, then the call !below computes the deltas for each feature
(let
(assoc
;used by !ComputeRobustContributionReactsPerCase below
enabled_num_features_probability_map
(call !ComputeNumEnabledFeaturesProbabilitiesMap (assoc num_features (size all_context_features) ))
num_features (size all_context_features)

)
;populate local_case_reaction_pairs, then the call !ComputeRobustWithAndWithoutDeltaPerCase computes the deltas for each feature
(call !ComputeRobustContributionReactsPerCase)
(zip context_features (call !ComputeRobustWithAndWithoutDeltaPerCase))
)
Expand Down
Loading
Loading