def runMain(): (ti, sparseX) = expt.setExptParams() X = sparseX.todense() # compile all the functions we'll need before I set up the session tlog = simple.Compiler(db=ti.db, prog=ti.prog, autoset_db_params=False) for modeString in [ "t_stress/io", "t_influences/io", "t_cancer_spont/io", "t_cancer_smoke/io" ]: _ = tlog.inference(modeString) session = tf.Session() session.run(tf.global_variables_initializer()) start0 = time.time() for modeString in [ "t_stress/io", "t_influences/io", "t_cancer_spont/io", "t_cancer_smoke/io" ]: session.run(tf.global_variables_initializer()) print 'eval', modeString, fd = {tlog.input_placeholder_name(modeString): X} session.run(tlog.inference(modeString), feed_dict=fd) print 'time', time.time() - start0, 'sec' tot = time.time() - start0 print 'total time', tot, 'sec' return tot
def runMain(): (db, prog, modeSet, queries) = expt.setExptParams() tlog = simple.Compiler(db=db, prog=prog, autoset_db_params=False) fps1 = expt.compileAll(db, prog, modeSet, queries) fps2 = tfCompileAll(tlog, modeSet, queries) # expect <= 2.5 fps qps = runTF(tlog) # expect less than 23 qps return fps2, qps
def runMain(num=250): params = expt.setExptParams(num) prog = params['prog'] tlog = simple.Compiler(db=prog.db, prog=prog, autoset_db_params=False) train_data = tlog.load_big_dataset('inputs/train-%d.exam' % num) mode = params['targetMode'] loss = tlog.loss(mode) optimizer = tf.train.AdagradOptimizer(0.1) train_step = optimizer.minimize(loss) session = tf.Session() session.run(tf.global_variables_initializer()) t0 = time.time() epochs = 10 for i in range(epochs): b = 0 for (_,(TX,TY)) in tlog.minibatches(train_data,batch_size=125): print 'epoch',i+1,'of',epochs,'minibatch',b+1 train_fd = {tlog.input_placeholder_name(mode):TX, tlog.target_output_placeholder_name(mode):TY} session.run(train_step, feed_dict=train_fd) b += 1 print 'learning time',time.time()-t0,'sec' predicted_y = tlog.inference(mode) actual_y = tlog.target_output_placeholder(mode) correct_predictions = tf.equal(tf.argmax(actual_y,1), tf.argmax(predicted_y,1)) accuracy = tf.reduce_mean(tf.cast(correct_predictions, tf.float32)) test_data = tlog.load_small_dataset('inputs/test-%d.exam' % num) UX,UY = test_data[mode] test_fd = {tlog.input_placeholder_name(mode):UX, tlog.target_output_placeholder_name(mode):UY} acc = session.run(accuracy, feed_dict=test_fd) print 'test acc',acc return acc #expect 27.2
def runMain(saveInPropprFormat=True): params = expt.setExptParams() prog = params['prog'] tlog = simple.Compiler(db=prog.db, prog=prog, autoset_db_params=False) train_data = tlog.load_small_dataset('inputs/train.examples') test_data = tlog.load_small_dataset('inputs/test.examples') mode = 'samebib/io' TX, TY = train_data[mode] UX, UY = test_data[mode] loss = tlog.loss(mode) optimizer = tf.train.AdagradOptimizer(0.1) train_step = optimizer.minimize(loss) train_fd = { tlog.input_placeholder_name(mode): TX, tlog.target_output_placeholder_name(mode): TY } test_fd = { tlog.input_placeholder_name(mode): UX, tlog.target_output_placeholder_name(mode): UY } t0 = time.time() session = tf.Session() session.run(tf.global_variables_initializer()) epochs = 30 for i in range(epochs): # progress print 'epoch', i + 1, 'of', epochs session.run(train_step, feed_dict=train_fd) print 'learning time', time.time() - t0, 'sec' inference = tlog.inference(mode) predicted_y = session.run(inference, feed_dict=test_fd) actual_y = tlog.target_output_placeholder(mode) correct_predictions = tf.equal(tf.argmax(actual_y, 1), tf.argmax(predicted_y, 1)) accuracy = tf.reduce_mean(tf.cast(correct_predictions, tf.float32)) if saveInPropprFormat: # save test results in ProPPR format from tensorlog import declare from tensorlog import dataset from tensorlog import expt as tlog_expt m = declare.asMode(mode) native_test_data = dataset.Dataset({m: tlog.xc._unwrapOutput(UX)}, {m: tlog.xc._unwrapOutput(UY)}) savedTestExamples = 'tmp-cache/cora-test.examples' savedTestPredictions = 'tmp-cache/cora-test.solutions.txt' native_test_data.saveProPPRExamples(savedTestExamples, tlog.db) tlog_expt.Expt.predictionAsProPPRSolutions( savedTestPredictions, 'samebib', tlog.db, tlog.xc._unwrapOutput(UX), tlog.xc._unwrapOutput(predicted_y)) print 'ready for commands like: proppr eval %s %s --metric auc --defaultNeg' % ( savedTestExamples, savedTestPredictions) acc = session.run(accuracy, feed_dict=test_fd) print 'test acc', acc return acc