-
Notifications
You must be signed in to change notification settings - Fork 14
/
predictor.py
executable file
·52 lines (36 loc) · 1.43 KB
/
predictor.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
#!/usr/bin/env python
# This script runs a trained DeepCov model using covariance or pair frequency data
# We recommend using the helper script deepcov.sh to make predictions
from __future__ import print_function
import sys
import os
import time
from math import sqrt
import numpy as np
import theano
import theano.tensor as T
import lasagne
# This assumes nndef.py is in pwd
from nndef import build_cnn
def main():
input_var = T.ftensor4('inputs')
# Create neural network model
network = build_cnn(input_var)
# Load parameters; the file must be in pwd
with np.load('FINAL_fullmap_metapsicov_model.npz') as f:
param_values = [f['arr_%d' % i] for i in range(len(f.files))]
lasagne.layers.set_all_param_values(network, param_values)
# Load input data (.21stats file)
mapdata = np.fromfile(sys.argv[1], dtype=np.float32)
length = int(sqrt(mapdata.shape[0]/21/21))
inputs = mapdata.reshape(1,441,length,length)
predict = lasagne.layers.get_output(network, input_var, deterministic=True)
predict_fn = theano.function([input_var], predict)
# Make the predictions
result = predict_fn(inputs)
# Write output to stdout; average values for residue pairs i,j and j,i
for wi in range(0, length-1):
for wj in range(wi+1, length):
print("{0} {1} 0 8 {2:.12g}".format(wi+1, wj+1, 0.5 * (result[0,0,wi,wj] + result[0,0,wj,wi])))
if __name__=="__main__":
main()