コード例 #1
0
	def testZeroIncrAndDecr(self):
		old_ws = [[x[0].copy(), x[1].copy()] for x in self.newpopW]
		new_ws = trainPP(self.newpopW, self.pop, incr=0, decr=0)
		for w1, w2 in zip(new_ws, old_ws):
			for io in range(2):
				npt.assert_array_equal(w1[io], w2[io])
				self.assertIsNot(w1[io], w2[io])	
コード例 #2
0
def runTrial():
    """
    Fresh population of NN individuals are evalutated, paired with 
    their fitness scores and ordered by fitness in descending order (fittest first)
    """
    pop = createPop()
    pairedPop = pairPop(pop)
    rankedPop = sorted(pairedPop, key=itemgetter(-1), reverse=True) 
    all_results = {
        'train_mses_top' : [],
        'train_mses_avg' : [],
        'train_percents_avg' : [],
        'train_percents_top' : [],
        'test_mse' : 0,
        'test_percent' : 0
    }
    for iters in range(max_iterations):
        # raw_input('==============NEXT==============')
        if not iters % 1:
            print 'Iteration'.rjust(120), iters
        newpopW = evolveNewPop(rankedPop)
        print '\n \nEVOLVE NEW POP'
        rankedPop, top_mse, avg_mse, top_per, avg_per = rankPop(newpopW, pop, verbose=NN.pop_size)
        if iters > 0 and iters < 1000:
            newpopW = trainPP(rankedPop, pop, incr=0.25, decr=0.5)
            print '\n \nTRAIN PP'
            rankedPop, top_mse, avg_mse, top_per, avg_per = rankPop(newpopW, pop, verbose=NN.pop_size)
        all_results['train_mses_top'].append(top_mse)
        all_results['train_mses_avg'].append(avg_mse)
        all_results['train_percents_top'].append(top_per)
        all_results['train_percents_avg'].append(avg_per)
    test_mse, test_per = testFittestInd(rankedPop)
    all_results['test_mse'] = test_mse
    all_results['test_percent'] = test_per
    return all_results
コード例 #3
0
def runTrial(iters):
    """
    Fresh population of NN individuals are evalutated, paired with 
    their fitness scores and ordered by fitness in descending order (fittest first)
    """
    pop = createPop()
    pairedPop = pairPop(pop, verbose=False)
    rankedPop = sorted(pairedPop, key=itemgetter(-1), reverse=True)
    all_results = {
        'train_mses_top': [],
        'train_mses_avg': [],
        'train_percents_avg': [],
        'train_percents_top': [],
        'test_mse': 0,
        'test_percent': 0
    }
    for iters in range(iters):
        # raw_input('==============NEXT==============')
        if not iters % 1:
            print 'Iteration'.rjust(120), iters
        newpopW = evolveNewPop(rankedPop)
        print '\n \nEVOLVE NEW POP'
        rankedPop, top_mse, avg_mse, top_per, avg_per = rankPop(newpopW,
                                                                pop,
                                                                verbose=False)
        print top_per
        if iters > 500:
            newpopW = trainPP(rankedPop, pop, incr=0.25, decr=0.5)
            print '\n \nTRAIN PP'
            rankedPop, top_mse, avg_mse, top_per, avg_per = rankPop(
                newpopW, pop, verbose=False)
        all_results['train_mses_top'].append(top_mse)
        all_results['train_mses_avg'].append(avg_mse)
        all_results['train_percents_top'].append(top_per)
        all_results['train_percents_avg'].append(avg_per)
    test_mse, test_per = testFittestInd(rankedPop)
    all_results['test_mse'] = test_mse
    all_results['test_percent'] = test_per
    return all_results