def evaluate(data): sum_err = 0.0 for it in xrange(0, len(data), batch_size): batch = data[it:it + batch_size] if len(batch) < batch_size: batch.extend(data[0:batch_size - len(batch)]) src_batch, label_batch = zip(*batch) src_tuple = smiles2graph_list(src_batch) feed_map = {x: y for x, y in zip(src_holder, src_tuple)} feed_map.update({label: label_batch}) err = session.run(loss, feed_dict=feed_map) sum_err += err return math.sqrt(sum_err / len(data))
buckets.pop(i) sum_err, sum_gnorm = 0.0, 0.0 it = 0 _lr = 0.001 while True: it += batch_size batch = [] for i in xrange(batch_size): buk = random.choice(buckets) idx = buk.popleft() batch.append(train[idx]) buk.append(idx) src_batch, label_batch = zip(*batch) src_tuple = smiles2graph_list(src_batch) feed_map = {x: y for x, y in zip(src_holder, src_tuple)} feed_map.update({label: label_batch, lr: _lr}) _, err, pnorm, gnorm = session.run([backprop, loss, param_norm, grad_norm], feed_dict=feed_map) sum_err += err sum_gnorm += gnorm if it % 200 == 0 and it > 0: rmse = math.sqrt(sum_err / 200) print "Training RMSE: %.4f, Param Norm: %.2f, Grad Norm: %.2f" % ( rmse, pnorm, sum_gnorm / 200) sys.stdout.flush() sum_err, sum_gnorm = 0.0, 0.0 if it % 100000 == 0 and it > 0: