def main(): import input import random logging.basicConfig(level=logging.DEBUG) np.set_printoptions(precision=3, edgeitems=3, threshold=20) randSample = random.Random(input.SAMPLE_SEED) a = ANN() inp = input.Input("train3.tsv", randSample) popSize = 10 timefun(a.prepare, inp.trainSet, popSize) params = [] for paramsIndex in range(popSize): p = Parameters() for i in range(19): p.ih[0][i] = 0.0 p.ih[1][i] = p.ih[2][i] = p.ih[3][i] = 0.0 p.c[0][i] = 0.0 p.c[1][i] = p.c[2][i] = p.c[3][i] = 0.0 p.ih[0][0] = 1.0 p.ih[1][11] = 1.0 p.w[0] = -1e-0 p.w[1] = -1.0 / (10.0 ** linterp(0, 4, float(paramsIndex) / popSize)) p.w[2] = p.w[3] = 0.0 p.ho[0] = 1.0 p.ho[1] = 0.0 #-1.0 p.ho[2] = p.ho[3] = 0.0 params.append(p) outputValues = timefun(a.evaluate, params, True) n = inp.trainSet.size * 20/100 thresholds = timefun(a.nlargest, n) lifts = timefun(a.lift, n) print "Lifts:", lifts
def benchImpl(impl): a = impl.ANN() a.prepare(trainSet, len(population)) def benchmarkee(): a.evaluate(population, returnOutputs=False) a.nlargest(n) a.lift(n) avg, std = bench.timefun(benchmarkee, repeat=10, stats=True) sys.stdout.write("%12.01f" % (avg * 1000.0))
def main(): import input logging.basicConfig(level=logging.DEBUG) np.set_printoptions(precision=3, edgeitems=3, threshold=10) # don't clutter the screen with details logging.getLogger("ann").setLevel(logging.ERROR) fullTrainSet = list(input.Input("train.tsv")) popSizes = [10, 100, 1000] trainSizes = [90, 900, 9000, 90000] benchParams = list(product(enumerate(popSizes), enumerate(trainSizes))) benchGpuAvg = np.zeros((len(popSizes), len(trainSizes)), np.float32) benchGpuStd = np.zeros_like(benchGpuAvg) benchCpuAvg = np.zeros_like(benchGpuAvg) benchCpuStd = np.zeros_like(benchGpuAvg) for index, ((popIndex, popSize), (trainIndex, trainSize)) in enumerate(benchParams): log.info("benchmarking %.01f%% popSize %d trainSize %d", 100.0 * index / len(benchParams), popSize, trainSize) a = ann.ANN() trainSet = fullTrainSet[:trainSize] assert len(trainSet) == trainSize a.prepare(trainSet, popSize) params = [generateParams(linterp(1e-4, 1e-5, float(index) / popSize)) for index in range(popSize)] a.evaluate(params) n = len(trainSet) * 20/100 avg, std = stats = timefun(a.nlargest, n, repeat=10, stats=True) benchGpuAvg[popIndex, trainIndex] = avg benchGpuStd[popIndex, trainIndex] = std outputs = a.evaluate(params, returnOutputs=True) avg, std = stats = timefun(nlargest_cpu, a, n, repeat=10, stats=True) benchCpuAvg[popIndex, trainIndex] = avg benchCpuStd[popIndex, trainIndex] = std