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
723a0302
Commit
723a0302
authored
8 years ago
by
Alex Rubinsteyn
Browse files
Options
Downloads
Patches
Plain Diff
added tests for construction of neural nets
parent
5bbf2a3d
No related branches found
Branches containing commit
No related tags found
Tags containing commit
No related merge requests found
Changes
3
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
mhcflurry/feedforward.py
+4
-30
4 additions, 30 deletions
mhcflurry/feedforward.py
mhcflurry/imputation.py
+0
-1
0 additions, 1 deletion
mhcflurry/imputation.py
test/test_neural_nets.py
+64
-0
64 additions, 0 deletions
test/test_neural_nets.py
with
68 additions
and
31 deletions
mhcflurry/feedforward.py
+
4
−
30
View file @
723a0302
...
...
@@ -27,28 +27,6 @@ import theano
theano
.
config
.
exception_verbosity
=
'
high
'
def
compile_forward_predictor
(
model
,
theano_mode
=
None
):
"""
In cases where we want to get predictions from a model that hasn
'
t
been compiled (to avoid overhead of compiling training code),
use this helper to only compile the subset of Theano needed for
forward-propagation/predictions.
"""
model
.
X_test
=
model
.
get_input
(
train
=
False
)
model
.
y_test
=
model
.
get_output
(
train
=
False
)
if
type
(
model
.
X_test
)
==
list
:
predict_ins
=
model
.
X_test
else
:
predict_ins
=
[
model
.
X_test
]
model
.
_predict
=
theano
.
function
(
predict_ins
,
model
.
y_test
,
allow_input_downcast
=
True
,
mode
=
theano_mode
)
def
make_network
(
input_size
,
embedding_input_dim
=
None
,
...
...
@@ -61,8 +39,7 @@ def make_network(
dropout_probability
=
0.0
,
model
=
None
,
optimizer
=
None
,
learning_rate
=
0.001
,
compile_for_training
=
True
):
learning_rate
=
0.001
):
if
model
is
None
:
model
=
Sequential
()
...
...
@@ -112,16 +89,13 @@ def make_network(
output_dim
=
1
,
init
=
init
))
model
.
add
(
Activation
(
output_activation
))
if
compile_for_training
:
model
.
compile
(
loss
=
loss
,
optimizer
=
optimizer
)
else
:
compile_forward_predictor
(
model
)
model
.
compile
(
loss
=
loss
,
optimizer
=
optimizer
)
return
model
def
make_hotshot_network
(
peptide_length
=
9
,
layer_sizes
=
[
5
00
],
layer_sizes
=
[
1
00
],
activation
=
"
relu
"
,
init
=
"
lecun_uniform
"
,
loss
=
"
mse
"
,
...
...
@@ -146,7 +120,7 @@ def make_embedding_network(
peptide_length
=
9
,
embedding_input_dim
=
20
,
embedding_output_dim
=
20
,
layer_sizes
=
[
5
00
],
layer_sizes
=
[
1
00
],
activation
=
"
relu
"
,
init
=
"
lecun_uniform
"
,
loss
=
"
mse
"
,
...
...
This diff is collapsed.
Click to expand it.
mhcflurry/imputation.py
+
0
−
1
View file @
723a0302
...
...
@@ -25,7 +25,6 @@ from .data import (
create_allele_data_from_peptide_to_ic50_dict
,
)
def
prune_dense_matrix_and_labels
(
X
,
peptide_list
,
...
...
This diff is collapsed.
Click to expand it.
test/test_neural_nets.py
0 → 100644
+
64
−
0
View file @
723a0302
from
mhcflurry.feedforward
import
(
make_embedding_network
,
make_hotshot_network
,
)
import
numpy
as
np
def
test_make_embedding_network
():
nn
=
make_embedding_network
(
peptide_length
=
3
,
layer_sizes
=
[
3
],
activation
=
"
tanh
"
,
embedding_input_dim
=
3
,
embedding_output_dim
=
20
,
learning_rate
=
0.1
)
X_negative
=
np
.
array
([
[
0
]
*
3
,
[
1
]
*
3
,
[
1
,
0
,
0
],
[
1
,
1
,
0
],
[
0
,
1
,
0
],
[
0
,
0
,
1
],
[
1
,
0
,
1
],
])
X_positive
=
np
.
array
([
[
0
,
2
,
0
],
[
1
,
2
,
0
],
[
1
,
2
,
1
],
[
0
,
2
,
1
],
[
2
,
2
,
0
],
[
2
,
2
,
1
],
[
2
,
2
,
2
],
])
X_index
=
np
.
vstack
([
X_negative
,
X_positive
])
Y
=
np
.
array
([
0.0
]
*
len
(
X_negative
)
+
[
1.0
]
*
len
(
X_positive
))
nn
.
fit
(
X_index
,
Y
,
nb_epoch
=
10
)
Y_pred
=
nn
.
predict
(
X_index
)
print
(
Y
)
print
(
Y_pred
)
for
(
Y_i
,
Y_pred_i
)
in
zip
(
Y
,
Y_pred
):
assert
abs
(
Y_i
-
Y_pred_i
)
<=
0.25
,
(
Y_i
,
Y_pred_i
)
def
test_make_hotshot_network
():
nn
=
make_hotshot_network
(
peptide_length
=
3
,
activation
=
"
relu
"
,
layer_sizes
=
[
4
],
n_amino_acids
=
2
,
learning_rate
=
0.1
)
X_binary
=
np
.
array
([
[
True
,
False
,
True
,
False
,
True
,
False
],
[
True
,
False
,
True
,
False
,
False
,
True
],
[
True
,
False
,
False
,
True
,
True
,
False
],
[
True
,
False
,
False
,
True
,
False
,
True
],
[
False
,
True
,
True
,
False
,
True
,
False
],
[
False
,
True
,
True
,
False
,
False
,
True
],
],
dtype
=
bool
)
Y
=
np
.
array
([
0.0
,
0.0
,
0.0
,
0.0
,
1.0
,
1.0
])
nn
.
fit
(
X_binary
,
Y
,
nb_epoch
=
10
)
Y_pred
=
nn
.
predict
(
X_binary
)
print
(
Y
)
print
(
Y_pred
)
for
(
Y_i
,
Y_pred_i
)
in
zip
(
Y
,
Y_pred
):
assert
abs
(
Y_i
-
Y_pred_i
)
<=
0.25
,
(
Y_i
,
Y_pred_i
)
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