def testPercentErrorIsSame(self): NN.pat = zip(self.trn_d['input'], self.trn_d['target']) pyb_ws = self.net.params.copy() nn = NN() nn.wi = pyb_ws[:nn.wi.size].reshape(NN.nh, NN.ni).T nn.wo = pyb_ws[nn.wi.size:].reshape(NN.no, NN.nh).T correct = 0 wrong = 0 argmax_cor = 0 argmax_wng = 0 all_aos = [] for i, x in enumerate(self.trn_d['input']): nn.activate(x) out = self.net.activate(x) # print 'ga bp trg', nn.ao, out, self.trn_d['target'][i], '++++' if not (out - self.trn_d['target'][i]).any() else '-' all_aos.append(nn.ao.copy()) if not (out - self.trn_d['target'][i]).any(): correct += 1 else: wrong += 1 if argmax(out) == argmax(self.trn_d['target'][i]): argmax_cor += 1 else: argmax_wng += 1 print 'actual', wrong, 'wrong', correct, 'correct', float(wrong) / (wrong + correct) * 100 print 'using argmax', argmax_wng, 'wrong', argmax_cor, 'correct', float(argmax_wng) / (argmax_wng + argmax_cor) * 100 argmax_perc_err = float(argmax_wng) / (argmax_wng + argmax_cor) * 100 res = nn.sumErrors() nn_perc_err = 100 - res[1] pb_nn_perc_err = percentError(self.trainer.testOnClassData(), self.trn_d['class']) self.assertAlmostEqual(nn_perc_err, pb_nn_perc_err) self.assertAlmostEqual(nn_perc_err, pb_nn_perc_err, argmax_perc_err)
def testPercentErrorIsSame(self): NN.pat = zip(self.trn_d['input'], self.trn_d['target']) pyb_ws = self.net.params.copy() nn = NN() nn.wi = pyb_ws[:nn.wi.size].reshape(NN.nh, NN.ni).T nn.wo = pyb_ws[nn.wi.size:].reshape(NN.no, NN.nh).T correct = 0 wrong = 0 argmax_cor = 0 argmax_wng = 0 all_aos = [] for i, x in enumerate(self.trn_d['input']): nn.activate(x) out = self.net.activate(x) # print 'ga bp trg', nn.ao, out, self.trn_d['target'][i], '++++' if not (out - self.trn_d['target'][i]).any() else '-' all_aos.append(nn.ao.copy()) if not (out - self.trn_d['target'][i]).any(): correct += 1 else: wrong += 1 if argmax(out) == argmax(self.trn_d['target'][i]): argmax_cor += 1 else: argmax_wng += 1 print 'actual', wrong, 'wrong', correct, 'correct', float(wrong) / ( wrong + correct) * 100 print 'using argmax', argmax_wng, 'wrong', argmax_cor, 'correct', float( argmax_wng) / (argmax_wng + argmax_cor) * 100 argmax_perc_err = float(argmax_wng) / (argmax_wng + argmax_cor) * 100 res = nn.sumErrors() nn_perc_err = 100 - res[1] pb_nn_perc_err = percentError(self.trainer.testOnClassData(), self.trn_d['class']) self.assertAlmostEqual(nn_perc_err, pb_nn_perc_err) self.assertAlmostEqual(nn_perc_err, pb_nn_perc_err, argmax_perc_err)
def testFittestInd(rankedPop): tester = NN () fittestWeights = rankedPop[0][0] tester.assignWeights(fittestWeights) count = 0 for i, t in tester.test_pat: o = tester.activate(i) print i, o, t, '++' if list(o) == list(t) else '----' count += 1 if list(o) == list(t) else -1 print float(count) / len(tester.test_pat) err, per = tester.sumErrors(test_data=True) print per return err, per
def testFittestInd(rankedPop): tester = NN() fittestWeights = rankedPop[0][0] tester.assignWeights(fittestWeights) count = 0 for i, t in tester.test_pat: o = tester.activate(i) print i, o, t, '++' if list(o) == list(t) else '----' count += 1 if list(o) == list(t) else -1 print float(count) / len(tester.test_pat) err, per = tester.sumErrors(test_data=True) print per return err, per
def testFittestInd(rankedPop): tester = NN() fittestWeights = rankedPop[0][0] tester.assignWeights(fittestWeights) right = 0 for i, t, c, l in tester.test_pat: o = tester.activate(i) print i, o, t, '++' if list(o) == list(t) else '----' right += 1 if list(o) == list(t) else 0 print right, len(tester.test_pat) print 100 * (float(right) / len(tester.test_pat)) err, per = tester.sumErrors(test_data=True) print per return err, per
def testFittestInd(rankedPop): tester = NN () fittestWeights = rankedPop[0][0] tester.assignWeights(fittestWeights) right = 0 for i, t, c, l in tester.test_pat: o = tester.activate(i) print i, o, t, '++' if list(o) == list(t) else '----' right += 1 if list(o) == list(t) else 0 print right, len(tester.test_pat) print 100 * (float(right) / len(tester.test_pat)) err, per = tester.sumErrors(test_data=True) print per return err, per
def testFittestInd(rankedPop): tester = NN () fittestWeights = rankedPop[0][0] tester.assignWeights(fittestWeights) return tester.sumErrors(test_data=True)
def testFittestInd(rankedPop): tester = NN() fittestWeights = rankedPop[0][0] tester.assignWeights(fittestWeights) return tester.sumErrors(test_data=True)