Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
M
mhc_rank
Manage
Activity
Members
Labels
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
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 Skillman-Lawrence
mhc_rank
Commits
b549dada
Commit
b549dada
authored
7 years ago
by
Tim O'Donnell
Browse files
Options
Downloads
Patches
Plain Diff
Fix robust_mean implementation
parent
612fe5c8
Loading
Loading
No related merge requests found
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
mhcflurry/ensemble_centrality.py
+4
-3
4 additions, 3 deletions
mhcflurry/ensemble_centrality.py
test/test_ensemble_centrality.py
+24
-0
24 additions, 0 deletions
test/test_ensemble_centrality.py
with
28 additions
and
3 deletions
mhcflurry/ensemble_centrality.py
+
4
−
3
View file @
b549dada
...
...
@@ -25,10 +25,11 @@ def robust_mean(log_values):
if
log_values
.
shape
[
1
]
<=
3
:
# Too few values to use robust mean.
return
numpy
.
nanmean
(
log_values
,
axis
=
1
)
without_nans
=
numpy
.
nan_to_num
(
log_values
)
# replace nan with 0
mask
=
(
(
log_value
s
<=
numpy
.
nanpercentile
(
log_values
,
75
,
axis
=
1
).
reshape
((
-
1
,
1
)))
&
(
log_value
s
>=
numpy
.
nanpercentile
(
log_values
,
25
,
axis
=
1
).
reshape
((
-
1
,
1
))))
return
(
log_value
s
*
mask
.
astype
(
float
)).
sum
(
1
)
/
mask
.
sum
(
1
)
(
without_nan
s
<=
numpy
.
nanpercentile
(
log_values
,
75
,
axis
=
1
).
reshape
((
-
1
,
1
)))
&
(
without_nan
s
>=
numpy
.
nanpercentile
(
log_values
,
25
,
axis
=
1
).
reshape
((
-
1
,
1
))))
return
(
without_nan
s
*
mask
.
astype
(
float
)).
sum
(
1
)
/
mask
.
sum
(
1
)
CENTRALITY_MEASURES
=
{
"
mean
"
:
partial
(
numpy
.
nanmean
,
axis
=
1
),
...
...
This diff is collapsed.
Click to expand it.
test/test_ensemble_centrality.py
0 → 100644
+
24
−
0
View file @
b549dada
import
numpy
from
numpy.testing
import
assert_equal
from
mhcflurry
import
ensemble_centrality
def
test_robust_mean
():
arr1
=
numpy
.
array
([
[
1
,
2
,
3
,
4
,
5
],
[
-
10000
,
2
,
3
,
4
,
100000
],
])
results
=
ensemble_centrality
.
robust_mean
(
arr1
)
assert_equal
(
results
,
[
3
,
3
])
# Should ignore nans.
arr2
=
numpy
.
array
([
[
1
,
2
,
3
,
4
,
5
],
[
numpy
.
nan
,
2
,
3
,
4
,
numpy
.
nan
],
])
results
=
ensemble_centrality
.
robust_mean
(
arr2
)
assert_equal
(
results
,
[
3
,
3
])
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