Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
E
ECCCo-jl
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Package Registry
Model registry
Operate
Environments
Terraform modules
Monitor
Incidents
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Terms and privacy
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
Patrick Altmeyer
ECCCo-jl
Commits
04f4e9aa
Commit
04f4e9aa
authored
1 year ago
by
pat-alt
Browse files
Options
Downloads
Patches
Plain Diff
just saving meta data directly
parent
0c5b87c8
No related branches found
Branches containing commit
No related tags found
Tags containing commit
1 merge request
!76
69 initial run including fmnist lenet and new method
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
experiments/experiment.jl
+2
-0
2 additions, 0 deletions
experiments/experiment.jl
src/generator.jl
+3
-32
3 additions, 32 deletions
src/generator.jl
with
5 additions
and
32 deletions
experiments/experiment.jl
+
2
−
0
View file @
04f4e9aa
...
@@ -65,6 +65,8 @@ function run_experiment(exp::Experiment; save_output::Bool=true)
...
@@ -65,6 +65,8 @@ function run_experiment(exp::Experiment; save_output::Bool=true)
# Save data:
# Save data:
if
save_output
if
save_output
Serialization
.
serialize
(
joinpath
(
exp
.
output_path
,
"
$
(exp.save_name)_outcome.jls"
),
outcome
)
Serialization
.
serialize
(
joinpath
(
exp
.
output_path
,
"
$
(exp.save_name)_outcome.jls"
),
outcome
)
Serialization
.
serialize
(
joinpath
(
exp
.
output_path
,
"
$
(exp.save_name)_bmk.jls"
),
bmk
)
meta
(
outcome
::
ExperimentOutcome
;
save_output
::
Bool
=
true
)
end
end
return
outcome
return
outcome
...
...
This diff is collapsed.
Click to expand it.
src/generator.jl
+
3
−
32
View file @
04f4e9aa
using
CounterfactualExplanations
.
Objectives
using
CounterfactualExplanations
.
Objectives
using
CounterfactualExplanations
.
Generators
:
GradientBasedGenerator
using
CounterfactualExplanations
.
Generators
:
GradientBasedGenerator
"Constructor for `CCEGenerator`."
function
CCEGenerator
(;
λ
::
Union
{
AbstractFloat
,
Vector
{
<:
AbstractFloat
}}
=
[
0.1
,
1.0
],
κ
::
Real
=
1.0
,
temp
::
Real
=
0.1
,
kwargs
...
)
function
_set_size_penalty
(
ce
::
AbstractCounterfactualExplanation
)
return
ECCCo
.
set_size_penalty
(
ce
;
κ
=
κ
,
temp
=
temp
)
end
_penalties
=
[
Objectives
.
distance_l2
,
_set_size_penalty
]
λ
=
λ
isa
AbstractFloat
?
[
0.0
,
λ
]
:
λ
return
GradientBasedGenerator
(;
penalty
=
_penalties
,
λ
=
λ
,
kwargs
...
)
end
"Constructor for `ECECCCoGenerator`: Energy Constrained Conformal Counterfactual Explanation Generator."
"Constructor for `ECECCCoGenerator`: Energy Constrained Conformal Counterfactual Explanation Generator."
function
ECCCoGenerator
(;
function
ECCCoGenerator
(;
λ
::
Union
{
AbstractFloat
,
Vector
{
<:
AbstractFloat
}}
=
[
0.2
,
0.4
,
0.4
],
λ
::
Union
{
AbstractFloat
,
Vector
{
<:
AbstractFloat
}}
=
[
0.2
,
0.4
,
0.4
],
...
@@ -45,11 +30,11 @@ function ECCCoGenerator(;
...
@@ -45,11 +30,11 @@ function ECCCoGenerator(;
_set_size_penalty
=
(
ce
::
AbstractCounterfactualExplanation
)
->
ECCCo
.
set_size_penalty
(
ce
;
κ
=
κ
,
temp
=
temp
)
_set_size_penalty
=
(
ce
::
AbstractCounterfactualExplanation
)
->
ECCCo
.
set_size_penalty
(
ce
;
κ
=
κ
,
temp
=
temp
)
# Energy penalty
# Energy penalty
_energy_penalty
=
function
(
ce
::
AbstractCounterfactualExplanation
)
_energy_penalty
=
function
(
ce
::
AbstractCounterfactualExplanation
)
if
use_energy_delta
if
use_energy_delta
return
ECCCo
.
energy_delta
(
ce
;
n
=
nsamples
,
nmin
=
nmin
,
kwargs
...
)
return
ECCCo
.
energy_delta
(
ce
;
n
=
nsamples
,
nmin
=
nmin
)
else
else
return
ECCCo
.
distance_from_energy
(
ce
;
n
=
nsamples
,
nmin
=
nmin
,
kwargs
...
)
return
ECCCo
.
distance_from_energy
(
ce
;
n
=
nsamples
,
nmin
=
nmin
)
end
end
end
end
...
@@ -58,18 +43,4 @@ function ECCCoGenerator(;
...
@@ -58,18 +43,4 @@ function ECCCoGenerator(;
# Generator
# Generator
return
GradientBasedGenerator
(;
loss
=
loss_fun
,
penalty
=
_penalties
,
λ
=
λ
,
opt
=
opt
,
kwargs
...
)
return
GradientBasedGenerator
(;
loss
=
loss_fun
,
penalty
=
_penalties
,
λ
=
λ
,
opt
=
opt
,
kwargs
...
)
end
"Constructor for `EnergyDrivenGenerator`."
function
EnergyDrivenGenerator
(;
λ
::
Union
{
AbstractFloat
,
Vector
{
<:
AbstractFloat
}}
=
[
0.1
,
1.0
],
kwargs
...
)
_penalties
=
[
Objectives
.
distance_l2
,
ECCCo
.
distance_from_energy
]
λ
=
λ
isa
AbstractFloat
?
[
0.0
,
λ
]
:
λ
return
GradientBasedGenerator
(;
penalty
=
_penalties
,
λ
=
λ
,
kwargs
...
)
end
"Constructor for `TargetDrivenGenerator`."
function
TargetDrivenGenerator
(;
λ
::
Union
{
AbstractFloat
,
Vector
{
<:
AbstractFloat
}}
=
[
0.1
,
1.0
],
kwargs
...
)
_penalties
=
[
Objectives
.
distance_l2
,
ECCCo
.
distance_from_targets
]
λ
=
λ
isa
AbstractFloat
?
[
0.0
,
λ
]
:
λ
return
GradientBasedGenerator
(;
penalty
=
_penalties
,
λ
=
λ
,
kwargs
...
)
end
end
\ No newline at end of file
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment