class TestFeatureMaps(unittest.TestCase): def setUp(self): """ Create a CFSheet ('V1') connected to a GeneratorSheet ('Retina'). """ self.s = Simulation() self.s['Retina']=GeneratorSheet(nominal_density=4.0) self.s['V1']= CFSheet(nominal_density=4.0) self.s['V2'] = CFSheet(nominal_density=4.0) self.s.connect('Retina','V1',delay=0.5,connection_type=CFProjection, name='RtoV1',learning_fn=CFPLF_Hebbian()) self.s.connect('Retina','V2',delay=0.5,connection_type=CFProjection, name='RtoV2',learning_fn=CFPLF_Hebbian()) def test_measurefeaturemap(self): """ """ self.feature_param = [Feature(name="phase",range=(0.0,1.0),values=[0.2,0.4,0.6],cyclic=False), Feature(name="orientation",range=(0.0,1.0),step=0.5,cyclic=True)] self.x = FeatureMaps(self.feature_param)
def test_state_stack(self): s = Simulation() s['pulse1'] = PulseGenerator(period = 1) s['pulse2'] = PulseGenerator(period = 3) s['sum_unit'] = SumUnit() s.connect('pulse1','sum_unit',delay=1) s.connect('pulse2','sum_unit',delay=1) s.run(1.0) s.state_push() self.assertEqual(len(s._events_stack),1) s.state_pop() self.assertEqual(len(s._events_stack),0)
def test_state_stack(self): s = Simulation() s['pulse1'] = PulseGenerator(period=1) s['pulse2'] = PulseGenerator(period=3) s['sum_unit'] = SumUnit() s.connect('pulse1', 'sum_unit', delay=1) s.connect('pulse2', 'sum_unit', delay=1) s.run(1.0) s.state_push() self.assertEqual(len(s._events_stack), 1) s.state_pop() self.assertEqual(len(s._events_stack), 0)
def test_state_stack(self): s = Simulation() s["pulse1"] = PulseGenerator(period=1) s["pulse2"] = PulseGenerator(period=3) s["sum_unit"] = SumUnit() s.connect("pulse1", "sum_unit", delay=1) s.connect("pulse2", "sum_unit", delay=1) s.run(1.0) s.state_push() self.assertEqual(len(s._events_stack), 1) s.state_pop() self.assertEqual(len(s._events_stack), 0)
def test_get_objects(self): s = Simulation() s['pulse1'] = PulseGenerator(period = 1) s['pulse2'] = PulseGenerator(period = 3) s['sum_unit'] = SumUnit() n1 = s['pulse1'].name n2 = s['pulse2'].name s.connect('pulse1','sum_unit',delay=1) s.connect('pulse2','sum_unit',delay=1) t1 = s.objects() e1 = [ep for ep in t1.values() if isinstance(ep,PulseGenerator) and ep.name == n1] t2 = s.objects() e2 = [ep for ep in t2.values() if isinstance(ep,PulseGenerator) and ep.name == n2] assert e1.pop().name == n1, 'Object names do not match' assert e2.pop().name == n2, 'Object names do not match'
def test_get_objects(self): s = Simulation() s["pulse1"] = PulseGenerator(period=1) s["pulse2"] = PulseGenerator(period=3) s["sum_unit"] = SumUnit() n1 = s["pulse1"].name n2 = s["pulse2"].name s.connect("pulse1", "sum_unit", delay=1) s.connect("pulse2", "sum_unit", delay=1) t1 = s.objects() e1 = [ep for ep in t1.values() if isinstance(ep, PulseGenerator) and ep.name == n1] t2 = s.objects() e2 = [ep for ep in t2.values() if isinstance(ep, PulseGenerator) and ep.name == n2] assert e1.pop().name == n1, "Object names do not match" assert e2.pop().name == n2, "Object names do not match"
class TestFeatureMaps(unittest.TestCase): def setUp(self): """ Create a CFSheet ('V1') connected to a GeneratorSheet ('Retina'). """ self.s = Simulation() self.s['Retina'] = GeneratorSheet(nominal_density=4.0) self.s['V1'] = CFSheet(nominal_density=4.0) self.s['V2'] = CFSheet(nominal_density=4.0) self.s.connect('Retina', 'V1', delay=0.5, connection_type=CFProjection, name='RtoV1', learning_fn=CFPLF_Hebbian()) self.s.connect('Retina', 'V2', delay=0.5, connection_type=CFProjection, name='RtoV2', learning_fn=CFPLF_Hebbian()) def test_measurefeaturemap(self): """ """ self.feature_param = [ Feature(name="phase", range=(0.0, 1.0), values=[0.2, 0.4, 0.6], cyclic=False), Feature(name="orientation", range=(0.0, 1.0), step=0.5, cyclic=True) ] self.x = FeatureMaps( self.feature_param, pattern_response_fn=pattern_response.instance(progress_bar=False), pattern_generator=SineGrating())
class TestPlotGroupSaverBase(unittest.TestCase): def exists(self,name): target = os.path.join(normalize_path.prefix,name) files = glob.glob(os.path.join(normalize_path.prefix,"*")) self.assert_(os.path.exists(target), "'%s' not among '%s'"%(os.path.basename(target), [os.path.basename(f) for f in files])) def setUp(self): self.original_output_path = normalize_path.prefix normalize_path.prefix = tempfile.mkdtemp() self.sim = Simulation(register=True,name="testplotfilesaver") self.sim['A'] = GeneratorSheet(nominal_density=2) self.sim['B'] = CFSheet(nominal_density=2) self.sim.connect('A','B',connection_type=CFProjection,name='Afferent') def tearDown(self): shutil.rmtree(normalize_path.prefix) normalize_path.prefix = self.original_output_path
def test_get_objects(self): s = Simulation() s['pulse1'] = PulseGenerator(period=1) s['pulse2'] = PulseGenerator(period=3) s['sum_unit'] = SumUnit() n1 = s['pulse1'].name n2 = s['pulse2'].name s.connect('pulse1', 'sum_unit', delay=1) s.connect('pulse2', 'sum_unit', delay=1) t1 = s.objects() e1 = [ ep for ep in t1.values() if isinstance(ep, PulseGenerator) and ep.name == n1 ] t2 = s.objects() e2 = [ ep for ep in t2.values() if isinstance(ep, PulseGenerator) and ep.name == n2 ] assert e1.pop().name == n1, 'Object names do not match' assert e2.pop().name == n2, 'Object names do not match'
def _initialize(): """Make a simple simulation.""" from topo.base.simulation import Simulation from topo.base.cf import CFSheet, CFProjection from topo.sheet import GeneratorSheet sim = Simulation(register=True, name="test pattern tester") sim['GS'] = GeneratorSheet(nominal_density=2) sim['GS2'] = GeneratorSheet(nominal_density=2) sim['S'] = CFSheet(nominal_density=2) sim['S2'] = CFSheet(nominal_density=2) sim.connect('GS', 'S', connection_type=CFProjection, delay=0.05) sim.connect('GS', 'S2', connection_type=CFProjection, delay=0.05) sim.connect('GS2', 'S2', connection_type=CFProjection, delay=0.05)
def _initialize(): """Make a simple simulation.""" from topo.base.simulation import Simulation from topo.base.cf import CFSheet,CFProjection from topo.sheet import GeneratorSheet sim=Simulation(register=True,name="test pattern tester") sim['GS']=GeneratorSheet(nominal_density=2) sim['GS2']=GeneratorSheet(nominal_density=2) sim['S'] = CFSheet(nominal_density=2) sim['S2'] = CFSheet(nominal_density=2) sim.connect('GS','S',connection_type=CFProjection,delay=0.05) sim.connect('GS','S2',connection_type=CFProjection,delay=0.05) sim.connect('GS2','S2',connection_type=CFProjection,delay=0.05)
def new_simulation(name=None,register=True): from topo.base.simulation import Simulation from topo.base.cf import CFSheet,CFProjection from topo.sheet import GeneratorSheet from topo.base.boundingregion import BoundingBox sim=Simulation(register=register,name=name) b= BoundingBox(radius=0.5) sim['GS']=GeneratorSheet(nominal_density=2,nominal_bounds=b) sim['GS2']=GeneratorSheet(nominal_density=2,nominal_bounds=b) sim['S'] = CFSheet(nominal_density=2,nominal_bounds=b) sim['S2'] = CFSheet(nominal_density=2,nominal_bounds=b) sim.connect('GS','S',connection_type=CFProjection,delay=0.05) sim.connect('GS','S2',connection_type=CFProjection,delay=0.05) sim.connect('GS2','S2',connection_type=CFProjection,delay=0.05) return sim
def new_simulation(name=None, register=True): from topo.base.simulation import Simulation from topo.base.cf import CFSheet, CFProjection from topo.sheet import GeneratorSheet from topo.base.boundingregion import BoundingBox sim = Simulation(register=register, name=name) b = BoundingBox(radius=0.5) sim['GS'] = GeneratorSheet(nominal_density=2, nominal_bounds=b) sim['GS2'] = GeneratorSheet(nominal_density=2, nominal_bounds=b) sim['S'] = CFSheet(nominal_density=2, nominal_bounds=b) sim['S2'] = CFSheet(nominal_density=2, nominal_bounds=b) sim.connect('GS', 'S', connection_type=CFProjection, delay=0.05) sim.connect('GS', 'S2', connection_type=CFProjection, delay=0.05) sim.connect('GS2', 'S2', connection_type=CFProjection, delay=0.05) return sim
class TestCFIter(unittest.TestCase): iter_type = CFIter def setUp(self): self.sim = Simulation() self.sim['Dest'] = CFSheet(nominal_density=10,nominal_bounds=BoundingBox(radius=0.5)) self.sim['Src'] = CFSheet(nominal_density=10,nominal_bounds=BoundingBox(radius=0.5)) self.sim.connect('Src','Dest', connection_type = ResizableCFProjection, ) def test_iterate_all(self): """ Test to make sure the iterator hits every CF """ total = 0 dest = self.sim['Dest'] proj = dest.projections()['SrcToDest'] rows,cols = dest.shape iterator = self.iter_type(proj) for cf,i in iterator(): total += 1 self.failUnless(0 <= i < 100, "CFIter generated bogus CF index") cfxy = (proj.X_cf.flat[i],proj.Y_cf.flat[i]) r,c = i/cols,i%cols self.failUnlessEqual(cfxy,dest.matrixidx2sheet(r,c)) self.failUnlessEqual(total,100) def test_iterate_some_nil(self): """ Test to make sure iterator skips nil CFs (i.e cf == None) """ dest = self.sim['Dest'] proj = dest.projections()['SrcToDest'] total = 0 proj.flatcfs[24] = None for cf,i in self.iter_type(proj)(): total += 1 self.failIfEqual(i,24) self.failUnlessEqual(total,99) def test_iterate_masked(self): """ Test if iterator skips masked CFs """ total = 0 dest = self.sim['Dest'] proj = dest.projections()['SrcToDest'] dest.mask.data = numpy.zeros(dest.activity.shape) dest.mask.data.flat[24] = 1 for cf,i in self.iter_type(proj)(): total += 1 self.failUnlessEqual(i,24) self.failUnless(cf is proj.flatcfs[24]) self.failUnlessEqual(total,1)