Skip to content

Commit

Permalink
use 'surprisal' for conviction when dt is 'surprisal_to_prob'
Browse files Browse the repository at this point in the history
  • Loading branch information
howsoRes committed Dec 19, 2024
1 parent 1aaa32b commit b4b396e
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 15 deletions.
38 changes: 24 additions & 14 deletions howso/conviction.amlg
Original file line number Diff line number Diff line change
Expand Up @@ -160,7 +160,7 @@
query_feature_attributes_map
feature_deviations
(get hyperparam_map "p")
(get hyperparam_map "dt")
(if (= (get hyperparam_map "dt") "surprisal_to_prob") "surprisal" (get hyperparam_map "dt") )
(if valid_weight_feature weight_feature (null))
;use a fixed random seed to guarantee deterministic behavior for reacts (named "fixed rand seed")
"fixed rand seed"
Expand Down Expand Up @@ -231,7 +231,7 @@
query_feature_attributes_map
feature_deviations
(get hyperparam_map "p")
(get hyperparam_map "dt")
(if (= (get hyperparam_map "dt") "surprisal_to_prob") "surprisal" (get hyperparam_map "dt") )
(if valid_weight_feature weight_feature (null))
;use a fixed random seed to guarantee deterministic behavior for reacts (named "fixed rand seed")
"fixed rand seed"
Expand Down Expand Up @@ -296,7 +296,7 @@
query_feature_attributes_map
feature_deviations
(get hyperparam_map "p")
(get hyperparam_map "dt")
(if (= (get hyperparam_map "dt") "surprisal_to_prob") "surprisal" (get hyperparam_map "dt") )
(if valid_weight_feature weight_feature (null))
;use a fixed random seed to guarantee deterministic behavior for reacts (named "fixed rand seed")
"fixed rand seed"
Expand Down Expand Up @@ -427,7 +427,7 @@
query_feature_attributes_map
feature_deviations
(get hyperparam_map "p")
(get hyperparam_map "dt")
(if (= (get hyperparam_map "dt") "surprisal_to_prob") "surprisal" (get hyperparam_map "dt") )
(if valid_weight_feature weight_feature (null))
;use a fixed random seed to guarantee deterministic behavior for reacts (named "fixed rand seed")
"fixed rand seed"
Expand Down Expand Up @@ -461,7 +461,7 @@
query_feature_attributes_map
feature_deviations
(get hyperparam_map "p")
(get hyperparam_map "dt")
(if (= (get hyperparam_map "dt") "surprisal_to_prob") "surprisal" (get hyperparam_map "dt") )
(if valid_weight_feature weight_feature (null))
;use a fixed random seed to guarantee deterministic behavior for reacts (named "fixed rand seed")
"fixed rand seed"
Expand Down Expand Up @@ -496,7 +496,7 @@
query_feature_attributes_map
feature_deviations
(get hyperparam_map "p")
(get hyperparam_map "dt")
(if (= (get hyperparam_map "dt") "surprisal_to_prob") "surprisal" (get hyperparam_map "dt") )
(if valid_weight_feature weight_feature (null))
;use a fixed random seed to guarantee deterministic behavior for reacts (named "fixed rand seed")
"fixed rand seed"
Expand Down Expand Up @@ -530,7 +530,7 @@
query_feature_attributes_map
feature_deviations
(get hyperparam_map "p")
(get hyperparam_map "dt")
(if (= (get hyperparam_map "dt") "surprisal_to_prob") "surprisal" (get hyperparam_map "dt") )
(if valid_weight_feature weight_feature (null))
;use a fixed random seed to guarantee deterministic behavior for reacts (named "fixed rand seed")
"fixed rand seed"
Expand Down Expand Up @@ -570,7 +570,7 @@
query_feature_attributes_map
feature_deviations
(get hyperparam_map "p")
(get hyperparam_map "dt")
(if (= (get hyperparam_map "dt") "surprisal_to_prob") "surprisal" (get hyperparam_map "dt") )
(if valid_weight_feature weight_feature (null))
;use a fixed random seed to guarantee deterministic behavior for reacts (named "fixed rand seed")
"fixed rand seed"
Expand Down Expand Up @@ -614,7 +614,7 @@
query_feature_attributes_map
feature_deviations
(get hyperparam_map "p")
(get hyperparam_map "dt")
(if (= (get hyperparam_map "dt") "surprisal_to_prob") "surprisal" (get hyperparam_map "dt") )
(if valid_weight_feature weight_feature (null))
;use a fixed random seed to guarantee deterministic behavior for reacts (named "fixed rand seed")
"fixed rand seed"
Expand Down Expand Up @@ -722,7 +722,7 @@
(get hyperparam_map "featureDomainAttributes")
feature_deviations
(get hyperparam_map "p")
(get hyperparam_map "dt")
(if (= (get hyperparam_map "dt") "surprisal_to_prob") "surprisal" (get hyperparam_map "dt") )
(if use_case_weights weight_feature (null))
;use a fixed random seed to guarantee deterministic behavior for reacts (named "fixed rand seed")
"fixed rand seed"
Expand Down Expand Up @@ -797,7 +797,7 @@
feature_weights (get hyperparam_map "featureWeights")
feature_deviations (get hyperparam_map "featureDeviations")
model_size (call !GetNumTrainingCases)
dt_parameter (get hyperparam_map "dt")
dt_parameter (if (= (get hyperparam_map "dt") "surprisal_to_prob") "surprisal" (get hyperparam_map "dt") )
p_parameter (get hyperparam_map "p")
query_closest_k (get hyperparam_map "k")
query_feature_attributes_map (get hyperparam_map "featureDomainAttributes")
Expand Down Expand Up @@ -836,7 +836,8 @@
query_feature_attributes_map
feature_deviations
p_parameter
1 ;dt is since we just want actual distances
;pull actual distance or surprisal, not influence
(if (= "surprisal" dt_parameter) "surprisal" 1)
(if use_case_weights weight_feature (null))
(rand)
(null) ;radius
Expand Down Expand Up @@ -868,7 +869,7 @@
)

;if the distance weight exponent is not the default value of -1, apply the negative value of it to all the distances
(if (!= -1 dt_parameter)
(if (and (!= -1 dt_parameter) (!= "surprisal" dt_parameter))
(assign (assoc
non_zero_distances
(map (lambda (pow (current_value) (- dt_parameter))) non_zero_distances)
Expand All @@ -893,7 +894,16 @@
))

;if all the neighbors have zero distance, return a 0
(if (= 0 (size non_zero_distances))
(if (= "surprisal" dt_parameter)
(let
(assoc
probabilities (map (lambda (exp (- (current_value)))) (values closest_cases_distances_map))
)
;normalize by total probabilities
(/ (entropy probabilities) (apply "+" probabilities ) )
)

(= 0 (size non_zero_distances))
0

;else scale the harmonic mean by corresponding count of zero distance neighbors
Expand Down
4 changes: 3 additions & 1 deletion howso/distances.amlg
Original file line number Diff line number Diff line change
Expand Up @@ -295,6 +295,7 @@
feature_deviations (get hyperparam_map "featureDeviations")
p_value (get hyperparam_map "p")
query_feature_attributes_map (get hyperparam_map "featureDomainAttributes")
in_surprisal_space (= "surprisal_to_prob" (get hyperparam_map "dt"))
))

;iterate over all the unique session ids and create a map of session id -> session indices map
Expand Down Expand Up @@ -397,6 +398,7 @@
to_case_values
(null)
features
in_surprisal_space
)
))
(range 0 last_index)
Expand Down Expand Up @@ -628,7 +630,7 @@
query_feature_attributes_map
feature_deviations
p_value
1 ;dt
(if (= "surprisal_to_prob" dt_value) "surprisal" 1)
(if valid_weight_feature weight_feature (null))
"fixed rand seed"
(null) ;radius
Expand Down

0 comments on commit b4b396e

Please sign in to comment.