def runscore(gen_best): score = 0.0 for gen in gen_best: genout = test_generator(gen, cf['test_times']) gentxt = "".join([pick_letter(cf['alphabet'], out) for out in genout]) score += abbafit(gentxt) return score / len(gen_best)
def evalstep(classifier, teststring, times, balph): correct = 0.0 testout = '' for out in classifier.run_signal(teststring): ac = out[0][0,0] > 0 correct += 1.0/times if ac else 0.0 testout += '+' if ac else '-' refin = ''.join([helpers.pick_letter(balph, t) for t in teststring]) return (correct, testout, refin)
def teststep(gen, cla, ref_data): genout = test_generator(gen, cf['test_times']) # print genout gentxt = [pick_letter(cf['alphabet'], out) for out in genout] gcltxt = test_classifier(cla, genout) score = "" if cf['datasource'] == 'abba': score = " score: " + str(abbafit(''.join(gentxt))) print "".join(gentxt) + score print "".join(gcltxt) corin = [c for c in ref_data.next()] corin = corin[:min(cf['test_times'], len(corin))] # corin = [] # for c in cortxt: # corin.append(charvectors[alphabet.index(c)]) # corin = [charvectors[alphabet.index(c)] for c in cortxt] # print corin cortxt = [pick_letter(cf['alphabet'], c) for c in corin] ccltxt = test_classifier(cla, corin) print "".join(cortxt) print "".join(ccltxt)
c = c.lower() if c in balph: yield c yield " " def vcs(): for c in charstream(): yield np.mat([[1.0 if d == c else -1.0] for d in balph]) teacher = [v for (v,_) in zip(vcs(), xrange(40000))] RESSIZE = 400 INSIZE = 40 # __init__(self, ressize, insize, outsize, sparseness, scale): gen = resnet.ResGen(RESSIZE, INSIZE, len(balph), 0.3, 0.5) #print gen.outnet gen.teacher_forced(teacher, 80) print ".. after training:" #print gen.outnet testout = "" for i in xrange(100): testout += helpers.pick_letter(balph, gen.update_step()[0]) print testout
# while True: # yield np.mat([[1.0],[-1.0]]) TIMES = 9000 RESSIZE = 600 # ressize, insize, sparseness, scale classifier = resnet.ResClass(RESSIZE, len(balph), 0.3, 0.5) classifier.pretrain(vcs(), resnet.extremeRI(len(balph)), TIMES, 80) teststring = [v for (v,_) in zip(vcs(), xrange(100))] testout = '' for out in classifier.run_signal(teststring): testout += '+' if out[0][0,0] > 0 else '-' print ''.join([helpers.pick_letter(balph, t) for t in teststring]) print testout teststring = [v for (v,_) in zip(resnet.extremeRI(len(balph)), xrange(100))] testout = '' for out in classifier.run_signal(teststring): testout += '+' if out[0][0,0] > 0 else '-' print ''.join([helpers.pick_letter(balph, t) for t in teststring]) print testout