def create_problem_node2(nargs=4, seed=0): from EvoDAG import RootGP gp = RootGP(generations=1, popsize=nargs, multiple_outputs=True, seed=seed) gp.X = X gp.Xtest = X y = cl.copy() gp.nclasses(y) gp.y = y return gp, [gp.X[x] for x in range(nargs)]
def test_classification_y(): from EvoDAG import RootGP gp = RootGP(generations=1, multiple_outputs=True, popsize=4) assert gp._classifier gp.X = X y = cl.copy() gp.nclasses(y) gp.y = y print(gp._ytr, gp.y) for a, b in zip(gp._ytr, gp.y): assert a.SSE(b) > 0 assert a.sum() == 0 assert b.sum() < 0
def create_problem_node2(nargs=4, seed=0): from EvoDAG import RootGP from test_root import X, cl import numpy as np gp = RootGP(generations=1, popsize=nargs, multiple_outputs=True, seed=seed) X1 = np.concatenate((X, np.atleast_2d(np.zeros(X.shape[0])).T), axis=1) for i in range(10, 20): X1[i, -1] = 1 gp.X = X1 gp.Xtest = X1 y = cl.copy() gp.nclasses(y) gp.y = y return gp, [gp.X[x] for x in range(nargs)]
def test_BER(): from EvoDAG.node import Add from EvoDAG import RootGP from EvoDAG.utils import BER gp = RootGP(generations=1, popsize=4, multiple_outputs=True) assert gp._classifier gp.X = X y = cl.copy() gp.nclasses(y) gp.y = y m = np.sign(tonparray(gp._mask_ts)).astype(np.bool) v = gp.random_leaf() v1 = gp.random_leaf() v1 = gp.random_leaf() a = Add([0, 1], ytr=gp._ytr, mask=gp._mask) a.eval([v, v1]) hy = SparseArray.argmax(a.hy) b = BER(y[m], tonparray(hy)[m]) gp._bagging_fitness.fitness(a) print(b, a.fitness * 100) assert_almost_equals(b, -a.fitness * 100)