Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
P
postpic
Manage
Activity
Members
Labels
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Model registry
Operate
Environments
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
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
Stephan Kuschel
postpic
Commits
cb590328
Commit
cb590328
authored
9 years ago
by
Stephan Kuschel
Browse files
Options
Downloads
Patches
Plain Diff
add weighted quantile and median.
parent
9c55f055
No related branches found
Branches containing commit
Tags
v0.1.0
Tags containing commit
No related merge requests found
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
postpic/analyzer/particles.py
+19
-0
19 additions, 0 deletions
postpic/analyzer/particles.py
with
19 additions
and
0 deletions
postpic/analyzer/particles.py
+
19
−
0
View file @
cb590328
...
...
@@ -577,6 +577,25 @@ class ParticleAnalyzer(object):
m
=
np
.
average
(
data
,
weights
=
w
)
return
np
.
average
((
data
-
m
)
**
2
,
weights
=
w
)
def
quantile
(
self
,
func
,
q
,
weights
=
1.0
):
'''
The qth-quantile of the distribution.
'''
if
q
<
0
or
q
>
1
:
raise
ValueError
(
'
Quantile q ({:}) must be in range [0, 1]
'
.
format
(
q
))
w
=
self
.
weight
()
*
weights
data
=
func
(
self
)
sortidx
=
np
.
argsort
(
data
)
wcs
=
np
.
cumsum
(
w
[
sortidx
])
idx
=
np
.
searchsorted
(
wcs
,
wcs
[
-
1
]
*
np
.
array
(
q
))
return
data
[
sortidx
[
idx
]]
def
median
(
self
,
func
,
weights
=
1.0
):
'''
The median
'''
return
self
.
quantile
(
func
,
0.5
,
weights
=
weights
)
# ---- Functions to create a Histogram. ---
def
createHistgram1d
(
self
,
scalarfx
,
optargsh
=
{
'
bins
'
:
300
},
...
...
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