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 testDataAssignedCorrectly(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 all_aos = [] for i, x in enumerate(self.trn_d['input']): nn.activate(x) out = self.net.activate(x) all_aos.append(nn.ao) if not (out - self.trn_d['target'][i]).any(): correct += 1 else: wrong += 1 for i in range(len(array(NN.pat)[:, 0])): npt.assert_array_equal(self.trn_d['input'][i], array(NN.pat)[:, 0][i]) npt.assert_array_equal(self.trn_d['input'][i], array(nn.pat)[:, 0][i]) npt.assert_array_equal(self.trn_d['target'][i], array(NN.pat)[:, 1][i]) npt.assert_array_equal(self.trn_d['target'][i], array(nn.pat)[:, 1][i])
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 testWeightsAndActivationsEquivalent(self): pyb_ws = self.net.params 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 for i, x in enumerate(self.trn_d['input']): nn.activate(x) out = self.net.activate(x) npt.assert_array_equal(nn.ai, self.net['in'].outputbuffer[0]) # self.assertItemsEqual(list(nn.ah), list(self.net['hidden0'].outputbuffer[0])) for j, pb_ah in enumerate(self.net['hidden0'].outputbuffer[0]): self.assertAlmostEqual(nn.ah[j], pb_ah) for k, pb_ao in enumerate(out): self.assertAlmostEqual(nn.ao[k], pb_ao)
def testDataAssignedCorrectly(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 all_aos = [] for i, x in enumerate(self.trn_d['input']): nn.activate(x) out = self.net.activate(x) all_aos.append(nn.ao) if not (out - self.trn_d['target'][i]).any(): correct += 1 else: wrong += 1 for i in range(len(array(NN.pat)[:,0])): npt.assert_array_equal(self.trn_d['input'][i], array(NN.pat)[:,0][i]) npt.assert_array_equal(self.trn_d['input'][i], array(nn.pat)[:,0][i]) npt.assert_array_equal(self.trn_d['target'][i], array(NN.pat)[:,1][i]) npt.assert_array_equal(self.trn_d['target'][i], array(nn.pat)[:,1][i])