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
d6608211
Commit
d6608211
authored
1 year ago
by
Pat Alt
Browse files
Options
Downloads
Patches
Plain Diff
streamlining mostly done
parent
7a2a2853
No related branches found
Branches containing commit
No related tags found
Tags containing commit
1 merge request
!68
Post rebuttal
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
experiments/post_processing.jl
+76
-43
76 additions, 43 deletions
experiments/post_processing.jl
experiments/setup.jl
+1
-0
1 addition, 0 deletions
experiments/setup.jl
with
77 additions
and
43 deletions
experiments/post_processing.jl
+
76
−
43
View file @
d6608211
"""
"""
meta
_model_performance(outcome::ExperimentOutcome; measure=MODEL_MEASURES
)
meta
(exp::Experiment
)
Compute
and save
the model performance for the models in `outcome.model_dict`
.
Extract
and save
meta data about the experiment
.
"""
"""
function
meta
_model_performance
(
outcome
::
ExperimentOutcome
;
measure
=
MODEL_MEASURES
)
function
meta
(
outcome
::
ExperimentOutcome
)
exp
=
outcome
.
exp
meta_model
(
outcome
)
model_dict
=
outcome
.
model_dict
meta_model_performance
(
outcome
)
meta_generators
(
outcome
)
# Model performance:
model_performance
=
DataFrame
()
for
(
mod_name
,
model
)
in
model_dict
# Test performance:
_perf
=
CounterfactualExplanations
.
Models
.
model_evaluation
(
model
,
exp
.
test_data
,
measure
=
collect
(
values
(
measure
)))
_perf
=
DataFrame
([[
p
]
for
p
in
_perf
],
collect
(
keys
(
measure
)))
_perf
.
mod_name
.=
mod_name
_perf
.
dataname
.=
dataname
model_performance
=
vcat
(
model_performance
,
_perf
)
end
Serialization
.
serialize
(
joinpath
(
exp
.
output_path
,
"
$
(exp.save_name)_model_performance.jls"
),
model_performance
)
CSV
.
write
(
joinpath
(
exp
.
output_path
,
"
$
(exp.save_name)_model_performance.csv"
),
model_performance
)
@info
"Model performance:"
println
(
model_performance
)
return
model_performance
end
end
"""
"""
meta_
data(exp
::Experiment)
meta_
model(outcome
::Experiment
Outcome
)
Extract and save meta data about the
experiment
.
Extract and save meta data about the
data and models in `outcome.model_dict`
.
"""
"""
function
meta_
data
(
outcome
::
ExperimentOutcome
)
function
meta_
model
(
outcome
::
ExperimentOutcome
)
# Data params:
# Unpack:
_
,
_
,
n_obs
,
default_save_name
,
batch_size
,
sampler
=
prepare_data
(
exp
=
outcome
.
exp
exp
.
counterfactual_data
;
n_obs
,
batch_size
=
meta_data
(
exp
)
𝒟
x
=
exp
.
𝒟
x
,
sampling_batch_size
=
exp
.
sampling_batch_size
)
save_name
=
isnothing
(
save_name
)
?
default_save_name
:
save_name
params
=
DataFrame
(
params
=
DataFrame
(
Dict
(
Dict
(
:
n_obs
=>
Int
.
(
round
(
n_obs
/
10
)
*
10
),
:
n_obs
=>
Int
.
(
round
(
n_obs
/
10
)
*
10
),
:
epochs
=>
epochs
,
:
batch_size
=>
batch_size
,
:
batch_size
=>
batch_size
,
:
n_hidden
=>
n_hidden
,
:
dataname
=>
exp
.
dataname
,
:
n_layers
=>
length
(
model_dict
[
"MLP"
]
.
fitresult
[
1
][
1
])
-
1
,
:
sgld_batch_size
=>
exp
.
sampling_batch_size
,
:
activation
=>
string
(
activation
),
# :epochs => exp.epochs,
:
n_ens
=>
n_ens
,
# :n_hidden => n_hidden,
:
lambda
=>
string
(
α
[
3
]),
# :n_layers => length(model_dict["MLP"].fitresult[1][1]) - 1,
:
jem_sampling_steps
=>
jem
.
sampling_steps
,
# :activation => string(activation),
:
sgld_batch_size
=>
sampler
.
batch_size
,
# :n_ens => n_ens,
:
dataname
=>
dataname
,
# :lambda => string(α[3]),
# :jem_sampling_steps => jem.sampling_steps,
)
)
)
)
if
!
isnothing
(
save_path
)
CSV
.
write
(
joinpath
(
save_path
,
"
$(save_name)
_model_params.csv"
),
params
)
save_path
=
joinpath
(
exp
.
params_path
,
"
$
(exp.save_name)_model_params.csv"
)
end
@info
"Saving model parameters to
$(save_path)
."
CSV
.
write
(
save_path
,
params
)
return
params
end
function
meta_generators
(
outcome
::
ExperimentOutcome
)
# Unpack:
exp
=
outcome
.
exp
generator_dict
=
outcome
.
generator_dict
# Output:
# Output:
opt
=
first
(
values
(
generator_dict
))
.
opt
opt
=
first
(
values
(
generator_dict
))
.
opt
...
@@ -68,6 +61,46 @@ function meta_data(outcome::ExperimentOutcome)
...
@@ -68,6 +61,46 @@ function meta_data(outcome::ExperimentOutcome)
:
dataname
=>
dataname
,
:
dataname
=>
dataname
,
)
)
)
)
CSV
.
write
(
joinpath
(
params_path
,
"
$(save_name)
_generator_params.csv"
),
generator_params
)
save_path
=
joinpath
(
exp
.
params_path
,
"
$
(exp.save_name)_generator_params.csv"
)
@info
"Saving generator parameters to
$(save_path)
."
CSV
.
write
(
save_path
,
generator_params
)
return
generator_params
end
"""
meta_model_performance(outcome::ExperimentOutcome; measures=MODEL_MEASURES)
Compute and save the model performance for the models in `outcome.model_dict`.
"""
function
meta_model_performance
(
outcome
::
ExperimentOutcome
;
measures
::
Union
{
Nothing
,
Dict
}
=
nothing
)
# Unpack:
exp
=
outcome
.
exp
measures
=
isnothing
(
measures
)
?
exp
.
model_measures
:
measures
model_dict
=
outcome
.
model_dict
# Model performance:
model_performance
=
DataFrame
()
for
(
mod_name
,
model
)
in
model_dict
# Test performance:
_perf
=
CounterfactualExplanations
.
Models
.
model_evaluation
(
model
,
exp
.
test_data
,
measure
=
collect
(
values
(
measures
)))
_perf
=
DataFrame
([[
p
]
for
p
in
_perf
],
collect
(
keys
(
measures
)))
_perf
.
mod_name
.=
mod_name
_perf
.
dataname
.=
dataname
model_performance
=
vcat
(
model_performance
,
_perf
)
end
@info
"Model performance:"
println
(
model_performance
)
save_path
=
joinpath
(
exp
.
params_path
,
"
$
(exp.save_name)_model_performance.jls"
)
@info
"Saving model performance to
$(save_path)
."
Serialization
.
serialize
(
save_path
,
model_performance
)
save_path
=
joinpath
(
exp
.
params_path
,
"
$
(exp.save_name)_model_performance.csv"
)
@info
"Saving model performance to
$(save_path)
."
CSV
.
write
(
save_path
,
model_performance
)
return
model_performance
end
end
\ No newline at end of file
This diff is collapsed.
Click to expand it.
experiments/setup.jl
+
1
−
0
View file @
d6608211
...
@@ -52,6 +52,7 @@ Base.@kwdef struct Experiment
...
@@ -52,6 +52,7 @@ Base.@kwdef struct Experiment
generators
::
Union
{
Nothing
,
Dict
}
=
nothing
generators
::
Union
{
Nothing
,
Dict
}
=
nothing
n_individuals
::
Int
=
50
n_individuals
::
Int
=
50
ce_measures
::
AbstractArray
=
CE_MEASURES
ce_measures
::
AbstractArray
=
CE_MEASURES
model_measures
::
Dict
=
MODEL_MEASURES
end
end
"A container to hold the results of an experiment."
"A container to hold the results of an experiment."
...
...
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