Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
B
Bayesian_Causal_Inference
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
Model registry
Operate
Environments
Monitor
Incidents
Service Desk
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
GitLab community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
ift
Bayesian_Causal_Inference
Commits
8ffc8a5e
Commit
8ffc8a5e
authored
6 years ago
by
Maximilian Kurthen
Browse files
Options
Downloads
Patches
Plain Diff
fixed bug in benchmark script
parent
a2ef4923
No related branches found
No related tags found
No related merge requests found
Changes
1
Show whitespace changes
Inline
Side-by-side
Showing
1 changed file
do_benchmark.py
+28
-46
28 additions, 46 deletions
do_benchmark.py
with
28 additions
and
46 deletions
do_benchmark.py
+
28
−
46
View file @
8ffc8a5e
...
@@ -16,11 +16,8 @@ NAME = args.name
...
@@ -16,11 +16,8 @@ NAME = args.name
FIRST_ID
=
args
.
first_id
FIRST_ID
=
args
.
first_id
LAST_ID
=
args
.
last_id
LAST_ID
=
args
.
last_id
MODEL
=
args
.
model
N_BINS
=
args
.
nbins
N_BINS
=
args
.
nbins
NOISE_VAR
=
args
.
noise_var
NOISE_VAR
=
args
.
noise_var
ITERATION_LIMIT
=
args
.
iteration_limit
TOL_REL_GRADNORM
=
args
.
tol_rel_gradnorm
BENCHMARK
=
args
.
benchmark
BENCHMARK
=
args
.
benchmark
VERBOSITY
=
args
.
verbosity
VERBOSITY
=
args
.
verbosity
...
@@ -35,15 +32,12 @@ if CONFIG is not None:
...
@@ -35,15 +32,12 @@ if CONFIG is not None:
with
open
(
'
./model_configurations.txt
'
)
as
f
:
with
open
(
'
./model_configurations.txt
'
)
as
f
:
configs
=
eval
(
f
.
read
())
configs
=
eval
(
f
.
read
())
parameters
=
configs
[
CONFIG
]
parameters
=
configs
[
CONFIG
]
MODEL
=
parameters
.
get
(
'
model
'
,
MODEL
)
N_BINS
=
parameters
.
get
(
'
nbins
'
,
N_BINS
)
N_BINS
=
parameters
.
get
(
'
nbins
'
,
N_BINS
)
NOISE_VAR
=
parameters
.
get
(
'
noise_var
'
,
NOISE_VAR
)
NOISE_VAR
=
parameters
.
get
(
'
noise_var
'
,
NOISE_VAR
)
POWER_SPECTRUM_BETA_STR
=
parameters
.
get
(
POWER_SPECTRUM_BETA_STR
=
parameters
.
get
(
'
power_spectrum_beta
'
,
POWER_SPECTRUM_BETA_STR
)
'
power_spectrum_beta
'
,
POWER_SPECTRUM_BETA_STR
)
POWER_SPECTRUM_F_STR
=
parameters
.
get
(
POWER_SPECTRUM_F_STR
=
parameters
.
get
(
'
power_spectrum_f
'
,
POWER_SPECTRUM_F_STR
)
'
power_spectrum_f
'
,
POWER_SPECTRUM_F_STR
)
ITERATION_LIMIT
=
parameters
.
get
(
'
iteration_limit
'
,
ITERATION_LIMIT
)
TOL_REL_GRADNORM
=
parameters
.
get
(
'
tol_rel_gradnorm
'
,
TOL_REL_GRADNORM
)
if
LAST_ID
is
None
:
if
LAST_ID
is
None
:
LAST_ID
=
get_benchmark_default_length
(
BENCHMARK
)
LAST_ID
=
get_benchmark_default_length
(
BENCHMARK
)
...
@@ -55,14 +49,17 @@ print(
...
@@ -55,14 +49,17 @@ print(
'
power spectrum beta: {}
\n
'
'
power spectrum beta: {}
\n
'
'
power spectrum f: {}
\n
'
'
power spectrum f: {}
\n
'
'
rho: {}
\n
'
'
rho: {}
\n
'
'
scale_max: {}
\n
'
'
storing results with suffix {}
'
.
format
(
'
storing results with suffix {}
'
.
format
(
BENCHMARK
,
FIRST_ID
,
LAST_ID
,
N_BINS
,
BENCHMARK
,
FIRST_ID
,
LAST_ID
,
N_BINS
,
NOISE_VAR
,
NOISE_VAR
,
POWER_SPECTRUM_BETA_STR
,
POWER_SPECTRUM_BETA_STR
,
POWER_SPECTRUM_F_STR
,
POWER_SPECTRUM_F_STR
,
RHO
,
RHO
,
SCALE_MAX
,
NAME
))
NAME
))
np
.
random
.
seed
(
1
)
POWER_SPECTRUM_BETA
=
lambda
q
:
eval
(
POWER_SPECTRUM_BETA_STR
)
POWER_SPECTRUM_BETA
=
lambda
q
:
eval
(
POWER_SPECTRUM_BETA_STR
)
POWER_SPECTRUM_F
=
lambda
q
:
eval
(
POWER_SPECTRUM_F_STR
)
POWER_SPECTRUM_F
=
lambda
q
:
eval
(
POWER_SPECTRUM_F_STR
)
scale
=
(
0
,
SCALE_MAX
)
scale
=
(
0
,
SCALE_MAX
)
...
@@ -75,7 +72,8 @@ if os.path.isfile(prediction_file):
...
@@ -75,7 +72,8 @@ if os.path.isfile(prediction_file):
prediction_file
=
'
./benchmark_predictions/{}_{}_{}.txt
'
.
format
(
prediction_file
=
'
./benchmark_predictions/{}_{}_{}.txt
'
.
format
(
BENCHMARK
,
NAME
,
c
)
BENCHMARK
,
NAME
,
c
)
accuracy
=
0
np
.
random
.
seed
(
1
)
sum_of_weights
=
0
sum_of_weights
=
0
weighted_correct
=
0
weighted_correct
=
0
...
@@ -88,13 +86,6 @@ for i in range(FIRST_ID-1, LAST_ID):
...
@@ -88,13 +86,6 @@ for i in range(FIRST_ID-1, LAST_ID):
scaler
=
MinMaxScaler
(
scale
)
scaler
=
MinMaxScaler
(
scale
)
x
,
y
=
scaler
.
fit_transform
(
np
.
array
((
x
,
y
)).
T
).
T
x
,
y
=
scaler
.
fit_transform
(
np
.
array
((
x
,
y
)).
T
).
T
minimizer
=
nifty5
.
RelaxedNewton
(
controller
=
nifty5
.
GradientNormController
(
tol_rel_gradnorm
=
TOL_REL_GRADNORM
,
iteration_limit
=
ITERATION_LIMIT
,
convergence_level
=
5
,
))
if
MODEL
==
1
:
bcm
=
bayesian_causal_model
.
cause_model_shallow
.
CausalModelShallow
(
bcm
=
bayesian_causal_model
.
cause_model_shallow
.
CausalModelShallow
(
N_bins
=
N_BINS
,
N_bins
=
N_BINS
,
noise_var
=
NOISE_VAR
,
noise_var
=
NOISE_VAR
,
...
@@ -102,21 +93,12 @@ for i in range(FIRST_ID-1, LAST_ID):
...
@@ -102,21 +93,12 @@ for i in range(FIRST_ID-1, LAST_ID):
power_spectrum_beta
=
POWER_SPECTRUM_BETA
,
power_spectrum_beta
=
POWER_SPECTRUM_BETA
,
power_spectrum_f
=
POWER_SPECTRUM_F
,
power_spectrum_f
=
POWER_SPECTRUM_F
,
)
)
elif
MODEL
==
2
:
bcm
=
bayesian_causal_model_nifty
.
cause_model_shallow
.
CausalModelShallow
(
N_bins
=
N_BINS
,
noise_var
=
NOISE_VAR
,
rho
=
RHO
,
power_spectrum_beta
=
POWER_SPECTRUM_BETA
,
power_spectrum_f
=
POWER_SPECTRUM_F
,
minimizer
=
minimizer
,
)
bcm
.
set_data
(
x
,
y
)
bcm
.
set_data
(
x
,
y
)
H1
=
bcm
.
get_evidence
(
direction
=
1
,
verbosity
=
1
)
H1
=
bcm
.
get_evidence
(
direction
=
1
,
verbosity
=
VERBOSITY
-
1
)
H2
=
bcm
.
get_evidence
(
direction
=-
1
,
verbosity
=
1
)
H2
=
bcm
.
get_evidence
(
direction
=-
1
,
verbosity
=
VERBOSITY
-
1
)
predicted_direction
=
1
if
int
(
H1
<
H2
)
else
0
predicted_direction
=
1
if
int
(
H1
<
H2
)
else
-
1
if
predicted_direction
==
true_direction
:
if
predicted_direction
==
true_direction
:
fore
=
colorama
.
Fore
.
GREEN
fore
=
colorama
.
Fore
.
GREEN
...
@@ -126,6 +108,7 @@ for i in range(FIRST_ID-1, LAST_ID):
...
@@ -126,6 +108,7 @@ for i in range(FIRST_ID-1, LAST_ID):
sum_of_weights
+=
weight
sum_of_weights
+=
weight
accuracy
=
weighted_correct
/
sum_of_weights
accuracy
=
weighted_correct
/
sum_of_weights
if
VERBOSITY
>
0
:
print
(
print
(
'
dataset {}, {} true direction: {}, predicted direction {}
\n
'
'
dataset {}, {} true direction: {}, predicted direction {}
\n
'
'
H1: {:.2e},
\n
H2: {:.2e},
\n
{}
'
'
H1: {:.2e},
\n
H2: {:.2e},
\n
{}
'
...
@@ -147,7 +130,6 @@ print('accuracy: {:.2f}'.format(accuracy))
...
@@ -147,7 +130,6 @@ print('accuracy: {:.2f}'.format(accuracy))
benchmark_information
=
{
benchmark_information
=
{
'
benchmark
'
:
BENCHMARK
,
'
benchmark
'
:
BENCHMARK
,
'
model
'
:
MODEL
,
'
n_bins
'
:
N_BINS
,
'
n_bins
'
:
N_BINS
,
'
noise_var
'
:
NOISE_VAR
,
'
noise_var
'
:
NOISE_VAR
,
'
rho
'
:
RHO
,
'
rho
'
:
RHO
,
...
...
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