def test2Neuro(self): return True def signal(point): x, y = point return 20.0 * math.exp(-(math.pow(0.5 - x, 2.0) + math.pow(0.82 - y, 2.0))/(0.5 ** 2)) + \ 25.0 * math.exp(-(math.pow(0.34 - x, 2.0) + math.pow(0.16 - y, 2.0))/(0.35 ** 2)) points = [[random.random(), random.random()] for _ in range(300)] def residual(l): NN = network_from_list(l) return sum(map(lambda x: math.fabs(signal(x) - NN(x)), points)) res = complex_box(residual, 8, [0, 0.1, 0.0, 0.0] * 2, [100, 1.0, 1.0, 1.0] * 2) print res
def test3Neuro(self): def signal(point): x, y = point return 43.0 * math.exp(-(math.pow(0.5 - x, 2.0) + math.pow(0.82 - y, 2.0))/(0.5 ** 2)) + \ 20.0 * math.exp(-(math.pow(0.34 - x, 2.0) + math.pow(0.16 - y, 2.0))/(0.35 ** 2)) + \ 14.0 * math.exp(-(math.pow(0.2 - x, 2.0) + math.pow(0.7 - y, 2.0))/(0.31 ** 2)) points = [[random.random(), random.random()] for _ in range(100)] def residual(l): NN = network_from_list(l) return sum(map(lambda x: math.fabs(signal(x) - NN(x)), points)) res = complex_box(residual, 12, [0, 0.1, 0.0, 0.0] * 3, [60, 0.7, 1.0, 1.0] * 3) print res
def test1Neuro(self): return True def signal(point): x, y = point return 43.0 * math.exp(-(math.pow(0.5 - x, 2.0) + math.pow(0.82 - y, 2.0))/(0.5 ** 2)) points = [[random.random(), random.random()] for _ in range(100)] def residual(l): NN = network_from_list(l) return sum(map(lambda x: math.fabs(signal(x) - NN(x)), points)) res = complex_box(residual, 4, [0, 0.1, 0.0, 0.0], [100, 1.0, 1.0, 1.0]) diffs = map(lambda x, y: math.fabs(x - y), [43.0, 0.5, 0.5, 0.82], res) print diffs self.assertTrue(all(map(lambda x: x < 1e-4, diffs)))
# -*- coding: utf-8 -*- from time import time from __init__ import to_minimize, neurons, dimensions, J_grad_wrap from complex_box import complex_box from first_order_methods.simulated_annealing import simulated_annealing from report import generate_report t_start = time() l = complex_box(to_minimize, neurons * (2 + dimensions), [-250.0, 1.0, -2.0, -2.0] * neurons, [250.0, 10.0, 6.0, 6.0] * neurons) l = simulated_annealing(l, J_grad_wrap, to_minimize) t_end = time() generate_report(l, t_start, t_end) print u"Готово"