-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathscore.py
98 lines (80 loc) · 2.92 KB
/
score.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
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
#!/usr/bin/env python3
##########################################################################################
# Author: Jared L. Ostmeyer
# Date Started: 2016-07-26
# License: See LICENSE
# Purpose: Score statistical classifier on repertoire data on unseen data
##########################################################################################
##########################################################################################
# Libraries
##########################################################################################
import lib_paths
import dataplumbing as dp
import numpy as np
import tensorflow as tf
from model import *
##########################################################################################
# Data
##########################################################################################
# Load data
#
path_dir = 'PATH_TO_YOUR_VALIDATION_DATA'
samples = dp.load_repertoires(path_dir)
xs, cs, ys = dp.process_repertoires(samples, snip_size=6)
##########################################################################################
# Load parameters
##########################################################################################
# Load parameters from trained model
#
weights_bestfit = np.loadtxt('weights.txt')
weights_bestfit = np.expand_dims(weights_bestfit, 1)
bias_bestfit = np.loadtxt('bias.txt')
##########################################################################################
# Operators
##########################################################################################
# Model settings
#
batch_size = xs.shape[0]
max_instances = xs.shape[1]
num_features = xs.shape[2]
# Inputs
#
features = tf.placeholder(tf.float32, [batch_size, max_instances, num_features])
counts = tf.placeholder(tf.float32, [batch_size, max_instances])
labels = tf.placeholder(tf.float32, [batch_size])
# Repertoire model
#
models = MaxSnippetModel(num_features)
models.weights = tf.Variable(weights_bestfit, name='weights', dtype=tf.float32)
models.biases = tf.Variable(bias_bestfit, name='biases', dtype=tf.float32)
logits = models(features, counts)
cost = models.costs(logits, labels)
accuracy = models.accuracies(logits, labels)
# Create operator to initialize session
#
initializer = tf.global_variables_initializer()
##########################################################################################
# Session
##########################################################################################
# Open session
#
with tf.Session() as session:
# Initialize variables
#
session.run(initializer)
# Grab a batch of training data
#
feed = {features: xs, counts: cs, labels: ys}
# Evaluate model
#
out = session.run(
(
cost,
accuracy
),
feed_dict=feed
)
print(
'Cost:', '%4.3f'%(out[0]/np.log(2.0)),
'Accuracy:', '%4.3f'%(100.0*out[1])
)