Ejemplo n.º 1
0
    def run(self):
        """
        Run stuff and save stuff.

        :return:
        """

        out_dir = "out_directories"
        name = "test1.avi"
        out_path = os.path.abspath(os.path.join(out_dir, name))

        self.make_temp_directory(out_dir)

        self.ani.run(out_path, 10, 10)

        self.estmd.open_movie(out_path)
        self.estmd.run(by_frame=True)
        self.estmd.run(by_frame=True)
        frame_array = self.estmd.create_list_of_arrays()
        n = len(frame_array)
        for i in range(n):
            frame_array[i] = {'frame': frame_array[i].flatten()}

        self.cstmd.input = frame_array
        self.cstmd.spike_trains = cstmd.run()[1]

        # Adding simulation

        sim = Simulation("Test", True)

        sim.spike_trains = self.cstmd.spike_trains
        sim.start_positions = 0
        sim.pattern_duration = self.cstmd.duration
        sim.num_afferents = self.cstmd.spike_trains.shape[0]
        sim.duration = self.cstmd.spike_trains.shape[1]
        sim.sampling_interval = math.ceil(self.cstmd.duration / 5)

        n1 = sim.add_neuron(0.03125, .95, 300)
        n2 = sim.add_neuron(0.03125, 0.91, 125)
        n3 = sim.add_neuron(0.03125, 0.91, 125)
        n1.connect(n2)
        n1.connect(n3)
        n2.connect(n3)

        sim.run()

        # Adding ActionSelection

        pattern_input = []
        for neuron in sim.neurons:
            pattern_input.append(neuron.spike_times)

        print "================================"
        print pattern_input
        print "================================"

        a_s = ActionSelection(pattern_input=pattern_input,
                              pattern_duration=self.ani.total_frames,
                              animation=self.ani)
        a_s.run(show_plots=False)
    def run_simulation(self, 
                       N=4,
                       taum=10*ms,
                       taupre=20*ms,
                       taupost=20*ms,
                       tauc=20*ms,
                       tauDop=20*ms,
                       Ee=0*mV,
                       vt=-54*mV,
                       vr=-60*mV,
                       El=-74*mV,
                       taue=5*ms,
                       F=15*Hz,
                       gmax=1,
                       dApre=1,
                       sim_time=100.0*ms,
                       frame_length=10.0*ms,
                       dopBoost=0.5,
                       reward_distance=40,
                       SPEED_FACTOR=2*second,
                       dragonfly_start=[300, 300, 0.0],
                       description="",
                       pattern_duration=None,
                       pattern_input=None,
                       animation=None,
                       animation_id=None,
                       pattern_recognition_id=None,
                       saved_weights=None,
                       training=True):
        """
        Generates and saves a simulation.
        """

        # Get the input.

        # Instantiate an ActionSelection object.
        a_s = ActionSelection(N=N,
                              taum=taum,
                              taupre=taupre,
                              taupost=taupost,
                              tauc=tauc,
                              tauDop=tauDop,
                              Ee=Ee,
                              vt=vt,
                              vr=vr,
                              El=El,
                              taue=taue,
                              F=F,
                              gmax=gmax,
                              dApre=dApre,
                              sim_time=sim_time,
                              frame_length=frame_length,
                              dopBoost=dopBoost,
                              reward_distance=reward_distance,
                              SPEED_FACTOR=SPEED_FACTOR,
                              dragonfly_start=dragonfly_start,
                              description=description,
                              animation=animation,
                              pattern_duration=pattern_duration,
                              pattern_input=pattern_input,
                              animation_id=animation_id,
                              pattern_recognition_id=pattern_recognition_id,
                              saved_weights=saved_weights,
                              training=training)

        a_s.run()

        # Save action selection simulation.
        _id = self.save(a_s)

        # Save video to filesystem.
        self.save_video(a_s, str(_id))

        # Save graphs.
        self.save_graphs(a_s, str(_id))

        return _id