Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
PeakOTron
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Iterations
Wiki
Requirements
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Locked files
Build
Pipelines
Jobs
Pipeline schedules
Test cases
Artifacts
Deploy
Releases
Package registry
Model registry
Operate
Environments
Terraform modules
Monitor
Incidents
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Code review analytics
Issue analytics
Insights
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
UHHDetLab
SiPM
PeakOTron
Commits
e4ba6b13
Commit
e4ba6b13
authored
2 years ago
by
Jack Christopher Hutchinson Rolph
Browse files
Options
Downloads
Patches
Plain Diff
Delete Bootstrapping.py
parent
bc1a0b4d
Branches
Branches containing commit
Tags
Tags containing commit
No related merge requests found
Changes
1
Show whitespace changes
Inline
Side-by-side
Showing
1 changed file
Bootstrapping.py
+0
-105
0 additions, 105 deletions
Bootstrapping.py
with
0 additions
and
105 deletions
Bootstrapping.py
deleted
100644 → 0
+
0
−
105
View file @
bc1a0b4d
from
HelperFunctions
import
FakeFuncCode
,
SelectRangeNumba
,
EmpiricalPPF
from
KDEpy
import
FFTKDE
import
numpy
as
np
from
Model
import
epsilon
from
scipy.interpolate
import
interp1d
from
iminuit
import
Minuit
from
astropy.stats
import
bootstrap
,
scott_bin_width
import
scipy.special
as
sc
import
logging
def
Bootstrap
(
data
,
statistic
,
n_bootstrap
,
alpha
=
0.95
,
):
if
not
(
0
<
alpha
<
1
):
raise
ValueError
(
"
confidence level must be in (0, 1)
"
)
if
len
(
data
)
<
1
:
raise
ValueError
(
"
data must contain at least one measurement.
"
)
boot_stat
=
bootstrap
(
data
,
n_bootstrap
,
bootfunc
=
statistic
)
stat_data
=
statistic
(
data
)
mean_stat
=
np
.
mean
(
boot_stat
)
est_stat
=
2
*
stat_data
-
mean_stat
std_err
=
np
.
std
(
boot_stat
)
z_score
=
np
.
sqrt
(
2.0
)
*
sc
.
erfinv
(
alpha
)
conf_interval
=
est_stat
+
z_score
*
np
.
array
((
-
std_err
,
std_err
))
return
est_stat
,
std_err
,
conf_interval
def
BootstrapKDE
(
data
,
n_bootstrap
,
n_call
=
1000
,
n_iterations
=
10
,
kernel
=
"
gaussian
"
,
n_kde_samples
=
2
**
14
,
alpha
=
0.95
,
bw_limits
=
(
epsilon
(),
None
),
limits
=
None
,
verbose
=
False
,
bw
=
"
ISJ
"
):
if
not
(
0
<
alpha
<
1
):
raise
ValueError
(
"
Bootstrap confidence level, alpha, must be in (0, 1).
"
)
if
len
(
data
)
<=
3
:
raise
ValueError
(
"
Bootstrap data must contain at least three measurements.
"
)
print
(
verbose
)
kde
=
FFTKDE
(
kernel
=
kernel
,
bw
=
bw
).
fit
(
data
)
x_kde
,
y_kde_orig
=
kde
.
evaluate
(
n_kde_samples
)
boot_data
=
bootstrap
(
data
,
n_bootstrap
)
y_kde_bs
=
np
.
vstack
([
FFTKDE
(
kernel
=
kernel
,
bw
=
bw
).
fit
(
_data
).
evaluate
(
x_kde
)
for
_data
in
boot_data
])
y_kde_mean
=
np
.
mean
(
y_kde_bs
,
axis
=
0
)
y_kde
=
2
*
y_kde_orig
-
y_kde_mean
y_kde_err
=
np
.
std
(
y_kde_bs
,
axis
=
0
)
z_score
=
np
.
sqrt
(
2.0
)
*
sc
.
erfinv
(
alpha
)
y_kde_conf_interval
=
y_kde
+
z_score
*
np
.
array
((
-
y_kde_err
,
y_kde_err
))
if
(
limits
is
not
None
):
cond_inrange
=
(
x_kde
>
np
.
min
(
limits
))
&
(
x_kde
<
np
.
max
(
limits
))
x_kde
=
x_kde
[
cond_inrange
]
y_kde
=
y_kde
[
cond_inrange
]
y_kde_err
=
y_kde_err
[
cond_inrange
]
return
x_kde
,
y_kde
,
y_kde_err
,
y_kde_conf_interval
def
Bootstrap
(
data
,
statistic
,
n_bootstrap
,
alpha
=
0.95
):
if
not
(
0
<
alpha
<
1
):
raise
ValueError
(
"
Confidence level must be in (0, 1)
"
)
if
len
(
data
)
<
1
:
raise
ValueError
(
"
Data must contain at least one measurement.
"
)
boot_stat
=
bootstrap
(
data
,
n_bootstrap
,
bootfunc
=
statistic
)
stat_data
=
statistic
(
data
)
mean_stat
=
np
.
mean
(
boot_stat
)
est_stat
=
2
*
stat_data
-
mean_stat
std_err
=
np
.
std
(
boot_stat
)
z_score
=
np
.
sqrt
(
2.0
)
*
sc
.
erfinv
(
alpha
)
conf_interval
=
est_stat
+
z_score
*
np
.
array
((
-
std_err
,
std_err
))
return
est_stat
,
std_err
,
conf_interval
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