-
Notifications
You must be signed in to change notification settings - Fork 7
/
data_contraints.jl
31 lines (26 loc) · 1.02 KB
/
data_contraints.jl
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
"""
mutability_constraints(counterfactual_data::CounterfactualData)
A convenience function that returns the mutability constraints. If none were specified, it is assumed that all features are mutable in `:both` directions.
"""
function mutability_constraints(counterfactual_data::CounterfactualData)
return if isnothing(counterfactual_data.mutability)
[:both for i in 1:size(counterfactual_data.X)[1]]
else
counterfactual_data.mutability
end
end
"""
apply_domain_constraints(counterfactual_data::CounterfactualData, x::AbstractArray)
A subroutine that is used to apply the predetermined domain constraints.
"""
function apply_domain_constraints(counterfactual_data::CounterfactualData, x::AbstractArray)
# Continuous variables:
if !isnothing(counterfactual_data.domain)
for i in counterfactual_data.features_continuous
x[i] = clamp(
x[i], counterfactual_data.domain[i][1], counterfactual_data.domain[i][2]
)
end
end
return x
end