def test_lagging(self): s = brica1.RealTimeSyncScheduler() ca = brica1.Agent(s) c = TimeReporterComponent() CompSet = brica1.ComponentSet() CompSet.add_component("C", c, 0) ModA = brica1.Module() ModA.add_component("CompSet", CompSet) ca.add_submodule("ModA", ModA) s.set_interval(0.1) c.delay = 0 ca.step() scheduled_time = s.current_time + s.interval ca.step() self.assertGreater(s.current_time, scheduled_time) self.assertLessEqual(abs(s.current_time - scheduled_time), TOLERANCE) self.assertFalse(s.lagged) c_interval = 0.2 c.delay = c_interval ca.step() self.assertTrue(s.lagged)
module = li.load_file(fp) agent = li.create_agent(scheduler) visual_comp = module["Base.InputModule"] \ .get_component("Base.InputModule") motor_comp = module["Base.OutputModule"] \ .get_component("Base.OutputModule") else: agent = brica1.Agent(scheduler) visual_comp = VisualAreaComponent() motor_comp = MotorAreaComponent() hipp_comp = HippocampusComponent() CompSet = brica1.ComponentSet() CompSet.add_component("visual_area_component", visual_comp, 0) CompSet.add_component("hippocampus_component", hipp_comp, 1) CompSet.add_component("motor_area_component", motor_comp, 2) main_module = brica1.Module() main_module.add_component("component_set", CompSet) # visual to hippocampus visual_comp.set_state("out_body_position", np.zeros(2, dtype=np.short)) visual_comp.make_out_port("out_body_position", 2) hipp_comp.make_in_port("in_body_position", 2) brica1.connect((visual_comp, "out_body_position"), (hipp_comp, "in_body_position")) # visual to motor
brica1.connect((convolutional1, "output"), (convolutional2, "input")) brica1.connect((convolutional2, "output"), (poolinganddropout1, "input")) brica1.connect((poolinganddropout1, "output"), (convolutional3, "input")) brica1.connect((convolutional3, "output"), (convolutional4, "input")) brica1.connect((convolutional4, "output"), (poolinganddropout2, "input")) brica1.connect((poolinganddropout2, "output"), (convolutional5, "input")) brica1.connect((convolutional5, "output"), (convolutional6, "input")) brica1.connect((convolutional6, "output"), (convolutional7, "input")) brica1.connect((convolutional7, "output"), (convolutional8, "input")) brica1.connect((convolutional8, "output"), (poolinganddropout3, "input")) brica1.connect((poolinganddropout3, "output"), (autoencoder1, "input")) brica1.connect((autoencoder1, "output"), (autoencoder2, "input")) brica1.connect((autoencoder2, "output"), (slp, "input")) stacked_autoencoder = brica1.ComponentSet() stacked_autoencoder.add_component("convolutional1", convolutional1, 1) stacked_autoencoder.add_component("convolutional2", convolutional2, 2) stacked_autoencoder.add_component("poolinganddropout1", poolinganddropout1, 3) stacked_autoencoder.add_component("convolutional3", convolutional3, 4) stacked_autoencoder.add_component("convolutional4", convolutional4, 5) stacked_autoencoder.add_component("poolinganddropout2", poolinganddropout2, 6) stacked_autoencoder.add_component("convolutional5", convolutional5, 7) stacked_autoencoder.add_component("convolutional6", convolutional6, 8) stacked_autoencoder.add_component("convolutional7", convolutional7, 9) stacked_autoencoder.add_component("convolutional8", convolutional8, 10) stacked_autoencoder.add_component("poolinganddropout3", poolinganddropout3, 11) stacked_autoencoder.add_component("autoencoder1", autoencoder1, 12)
cuda.init(args.gpu) s = brica1.VirtualTimeScheduler() ca = brica1.Agent(s) cycles = 24000 sensor = MNISTSensor() da1 = DAComponent(784, 1000, use_cuda=use_gpu, max_cycles=cycles) da2 = DAComponent(1000, 1000, use_cuda=use_gpu, max_cycles=cycles) da3 = DAComponent(1000, 1000, use_cuda=use_gpu, max_cycles=cycles) perceptron = PerceptronComponent(1000, 10, use_cuda=use_gpu, max_cycles=cycles) sda = brica1.ComponentSet() brica1.connect((da1, "out"), (da2, "in")) brica1.connect((da2, "out"), (da3, "in")) sda.add_component("da1", da1, 0) sda.add_component("da2", da2, 1) sda.add_component("da3", da3, 2) sda.make_in_port("x_in", 784) sda.make_in_port("y_in", 1) sda.make_out_port("out", 1) brica1.connect((sensor, "x_train"), (da1, "in")) brica1.connect((da1, "out"), (da2, "in")) brica1.connect((da2, "out"), (da3, "in")) brica1.connect((da3, "out"), (perceptron, "x_in")) brica1.connect((sensor, "y_train"), (perceptron, "y_in"))