def test_load_network_2_4_4_2(db_session): network_attributes = db_load_network(db_session, '2_4_4_2') perceptron = MLMCPerceptron(**network_attributes) assert_perceptron_equal( perceptron, { 'alpha': 0.5, 'momentum': 0.7, 'out_sigmoided': False, 'weights': [ numpy.array([ [100.1, -100.2, 100.3], [100.4, -100.5, 100.6], [100.7, -100.8, 100.9], [101.0, -101.1, 101.2], ]), numpy.array([ [-200.0, 200.1, -200.2, 200.3, -200.4], [-200.5, 200.6, -200.7, 200.8, -200.9], [-201.0, 201.1, -201.2, 201.3, -201.4], [-201.5, 201.6, -201.7, 201.8, -201.9], ]), numpy.array([ [300.0, -300.1, 300.2, -300.3, 300.4], [300.5, -300.6, 300.7, -300.8, 300.9], ]), ], } )
def load_from_db(self, db_session): try: network_attributes = db_load_network(db_session, self.db_name) self.perceptron = MLMCPerceptron(**network_attributes) except NoResultFound: message_fmt = 'Network {name!r} not found in db. Creating new...' print message_fmt.format(name=self.db_name), assert self.SIZES_NAME_RE.match(self.db_name) sizes = [int(size) for size in self.db_name.split('_')] self.perceptron = MLMCPerceptron( sizes, alpha=0.01, exploration_probability=0.5, ) name = self.db_name network = db_save_network(db_session, self.perceptron, name) db_session.commit() print 'created'
def test_update_network_2_2(db_session): network_name = '2_2' old_network_attributes = { 'alpha': 0.1, 'momentum': 0.8, 'out_sigmoided': True, 'weights': [ numpy.array([ [50.1, -50.2, 50.3], [50.4, -50.5, 50.6], ]), ] } perceptron = MLMCPerceptron(**old_network_attributes) db_save_network(db_session, perceptron, network_name) network = db_session.query(Network).filter_by(name=network_name).one() assert_network_equal(network, old_network_attributes) new_network_attributes = { 'alpha': 0.3, 'momentum': 0.1, 'out_sigmoided': False, 'weights': [ numpy.array([ [500.1, -500.2, 500.3], [500.4, -500.5, 500.6], ]), ], } perceptron = MLMCPerceptron(**new_network_attributes) db_update_network(db_session, perceptron, network_name) after_update_attributes = db_load_network(db_session, network_name) perceptron = MLMCPerceptron(**after_update_attributes) assert_perceptron_equal(perceptron, new_network_attributes)
def test_load_network_2_3_4(db_session): network_attributes = db_load_network(db_session, '2_3_4') perceptron = MLMCPerceptron(**network_attributes) assert_perceptron_equal( perceptron, { 'alpha': 0.1, 'momentum': 0.8, 'out_sigmoided': True, 'weights': [ numpy.array([ [0.1, 0.2, 0.3], [0.4, 0.5, 0.6], [0.7, 0.8, 0.9], ]), numpy.array([ [ 0.0, -0.1, -0.2, -0.3], [-0.4, -0.5, -0.6, -0.7], [-0.8, -0.9, -1.0, -1.1], [-1.2, -1.3, -1.4, -1.5], ]), ], } )