def test_random_state(self): a1 = copy.copy(self.a) ### # CEBALERT: hack because homeostaticmaxent doesn't get some # of its state until it's been called once! self.hme(a1) start_array = copy.copy(a1) ## save the state then generate some results... self.hme.state_push() self.hme(a1) res1 = copy.copy(a1) self.hme(a1) res2 = copy.copy(a1) # (check results do actually change so the test is valid) assert_array_not_equal(res1, res2) a2 = copy.copy(start_array) ### ...then restore the state & check results are the same self.hme.state_pop() self.hme(a2) assert_array_equal(a2, res1) self.hme(a2) assert_array_equal(a2, res2)
def test_random_state(self): a1 = copy.copy(self.a) ### # CEBALERT: hack because homeostaticmaxent doesn't get some # of its state until it's been called once! self.hme(a1) start_array = copy.copy(a1) ## save the state then generate some results... self.hme.state_push() self.hme(a1) res1 = copy.copy(a1) self.hme(a1) res2 = copy.copy(a1) # (check results do actually change so the test is valid) assert_array_not_equal(res1,res2) a2 = copy.copy(start_array) ### ...then restore the state & check results are the same self.hme.state_pop() self.hme(a2) assert_array_equal(a2,res1) self.hme(a2) assert_array_equal(a2,res2)
def test_test_pattern(): """Check that test pattern window is working.""" tp = topo.guimain['Simulation']['Test Pattern']() act = topo.guimain['Plots']['Activity']() tp.gui_set_param('edit_sheet', 'GS') ## Test for state_push bug (simulation not run() before Present pressed) assert len(topo.sim.eps_to_start ) > 0, "test must be run before simulation is run()" from topo.pattern import Gaussian from topo import numbergen topo.sim['GS'].set_input_generator(Gaussian(x=numbergen.UniformRandom())) tp.Present() topo.sim.run(1) act1 = copy.deepcopy(topo.sim['GS'].activity) topo.sim.run(2) assert_array_not_equal(topo.sim['GS'].activity, act1, "GeneratorSheet no longer generating patterns") ## tp.gui_set_param('pattern_generator', 'TwoRectangles') from topo.pattern import TwoRectangles assert isinstance(tp.pattern_generator, TwoRectangles), "Pattern generator did not change." preview = _get_named_plot('GS', tp.plotgroup.plots).view_dict.get( 'Strength', {})['Activity'].top.data two_rectangles = array([[0., 1], [1., 0.]]) assert_array_equal(preview, two_rectangles, "Incorrect pattern in preview plot.") tp.Present() gs_view = _get_named_plot('GS', act.plotgroup.plots).view_dict.get( 'Strength', {})['Activity'] assert gs_view.metadata.src_name == 'GS' gs_plot_array = gs_view.top.data assert_array_equal(gs_plot_array, two_rectangles, "Incorrect pattern in activity plot after Present.") tp.params_frame.gui_set_param('scale', 0.5) preview = _get_named_plot('GS', tp.plotgroup.plots).view_dict.get( 'Strength', {})['Activity'].top.data assert_array_equal(preview, 0.5 * two_rectangles, "Changing pattern parameters did not update preview.") ### Defaults button # first change several more parameters initial_preview = tp.plotgroup.plots[0].view_dict.get( 'Strength', {})['Activity'].top.data new_param_values = [ #('output_fns','Sigmoid'), ('scale', '2') ] for name, value in new_param_values: tp.params_frame.gui_set_param(name, value) changed_preview = _get_named_plot('GS', tp.plotgroup.plots).view_dict.get( 'Strength', {})['Activity'].top.data # and check the preview did change try: assert_array_equal(changed_preview, initial_preview) except AssertionError: pass else: raise AssertionError("Test pattern didn't change.") # test that preview display is correct tp.params_frame.Defaults() preview = _get_named_plot('GS', tp.plotgroup.plots).view_dict.get( 'Strength', {})['Activity'].top.data assert_array_equal( preview, two_rectangles, "Defaults button failed to revert params to default values.")
def test_test_pattern(): """Check that test pattern window is working.""" tp = topo.guimain['Simulation']['Test Pattern']() act = topo.guimain['Plots']['Activity']() tp.gui_set_param('edit_sheet','GS') ## Test for state_push bug (simulation not run() before Present pressed) assert len(topo.sim.eps_to_start)>0, "test must be run before simulation is run()" from topo.pattern import Gaussian from topo import numbergen topo.sim['GS'].set_input_generator(Gaussian(x=numbergen.UniformRandom())) tp.Present() topo.sim.run(1) act1 = copy.deepcopy(topo.sim['GS'].activity) topo.sim.run(2) assert_array_not_equal(topo.sim['GS'].activity,act1,"GeneratorSheet no longer generating patterns") ## tp.gui_set_param('pattern_generator','TwoRectangles') from topo.pattern import TwoRectangles assert isinstance(tp.pattern_generator,TwoRectangles), "Pattern generator did not change." preview = _get_named_plot('GS',tp.plotgroup.plots).view_dict['Activity'].top.data two_rectangles = array([[0.,1],[1.,0.]]) assert_array_equal(preview,two_rectangles,"Incorrect pattern in preview plot.") tp.Present() gs_view = _get_named_plot('GS',act.plotgroup.plots).view_dict['Activity'] assert gs_view.metadata.src_name=='GS' gs_plot_array = gs_view.top.data assert_array_equal(gs_plot_array,two_rectangles,"Incorrect pattern in activity plot after Present.") tp.params_frame.gui_set_param('scale',0.5) preview = _get_named_plot('GS',tp.plotgroup.plots).view_dict['Activity'].top.data assert_array_equal(preview,0.5*two_rectangles,"Changing pattern parameters did not update preview.") ### Defaults button # first change several more parameters initial_preview = tp.plotgroup.plots[0].view_dict['Activity'].top.data new_param_values = [#('output_fns','Sigmoid'), ('scale','2')] for name,value in new_param_values: tp.params_frame.gui_set_param(name,value) changed_preview = _get_named_plot('GS',tp.plotgroup.plots).view_dict['Activity'].top.data # and check the preview did change try: assert_array_equal(changed_preview,initial_preview) except AssertionError: pass else: raise AssertionError("Test pattern didn't change.") # test that preview display is correct tp.params_frame.Defaults() preview = _get_named_plot('GS',tp.plotgroup.plots).view_dict['Activity'].top.data assert_array_equal(preview,two_rectangles,"Defaults button failed to revert params to default values.")