def __call__(self, net, input, target): layer = net.layers[0] if self.adapt: while True: self.epochf(None, net, input, target) for inp, tar in zip(input, target): out = net.step(inp) err = tar - out win = np.argmax(layer.out) if np.max(err) == 0.0: layer.np["w"][win] += self.lr * (inp - layer.np["w"][win]) else: layer.np["w"][win] -= self.lr * (inp - layer.np["w"][win]) else: while True: output = [] winners = [] for inp, tar in zip(input, target): out = net.step(inp) output.append(out) winners.append(np.argmax(layer.out)) e = self.error(net, input, target, output) self.epochf(e, net, input, target) error = target - output sign = np.sign((np.max(error, axis=1) == 0) - 0.5) layer.np["w"][winners] += self.lr * (input - layer.np["w"][winners]) return None
def __init__(self, x): x = np.asfarray(x) if x.ndim != 2: raise ValueError('x mast have 2 dimensions') min = np.min(x, axis=0) dist = np.max(x, axis=0) - min min = min.reshape((1, min.size,)) #replacement for " min.shape = 1, min.size" dist = dist.reshape((1, dist.size,)) #replacement for " dist.shape = 1, dist.size" self.min = min self.dist = dist