Experiment - Olimaol/CompNeuroPy Wiki

The Experiment class

With the Experiment class one can combine recordings and simulations in one place. It is mainly thought of as a helper class for the opt_neuron class, but of course, can also be used separately.

Arguments of the Experiment class:

  • reset_function: function || optional, default=None || a function which resets the ANNarchy model
  • reset_kwargs: dictionary || optional, default={} || arguments of the reset_function

When initializing the Experiment class, a custom reset_function can be passed, which can be used instead of the standard ANNarchy reset function. For the separate use of the Experiment class (without opt_neuron) this is not really useful.

Usage:

The Experiment class is intended to be used as a parent class as in the following example:

class my_exp(Experiment):
    """
    parent class Experiment provides the variables:
        self.mon = self.cnp.Monitors() --> a CompNeuroPy Monitors object to do recordings
        self.data = {}                 --> a dictionary with any optional data
    and the functions:
        self.reset()   --> resets the model and monitors
        self.results() --> returns a results object (with recordings and optional data from self.data)
    """

    ### we have to define some funciton in which the simulations and recordings are done
    def run(self):
        """
        do the simulations and recordings

        in this example also the model and the simulations are defined here, also all related imports
        are done here... this is ot neccessary in this example but the original intention of the
        Experiment class was to have everything in one class
        """

        ### create and compile a model
        my_model = ...

        ### define some simulations
        my_sim = ...

        ### define recordings
        ### store them in self.mon
        self.mon = Monitors(...)

        ### run simulations/recordings
        self.mon.start()
        my_sim.run()
        ### if you want to reset the model, you can use the objects reset()
        ### it's the same as the ANNarchy reset (only necessary for the use with opt_neuron)
        self.reset()
        ### SIMULATION END

        ### optional: store anything you want in the data dict, for example infomration about
        ### the simulations
        self.data["sim"] = my_sim.simulation_info()
        self.data["population_name"] = my_model.populations[0]
        self.data["time_step"] = dt()
        self.data["recording_times"] = self.mon.get_recording_times()

        ### return results, use the object's self.results() function which automatically
        ### returns an object with "recordings", "monDict", and "data"
        return self.results()

A useful thing is that you can collect everything that belongs to an experiment (model, simulations, recordings) in one object. The function self.results() allows getting a results object containing the recordings, the monDict (from Monitors definition), and a data dictionary. A complete example is available in the examples/ folder of the source code.

⚠️ **GitHub.com Fallback** ⚠️