optimizer Package¶
Core Module¶
cmd_line Module¶
fitnessFunctions Module¶
graphic Module¶
modelHandler Module¶
-
class
optimizer.modelHandler.externalHandler(command)¶ Handles models which are using a simulator other than Neuron. :param command: the command string which should be executed
Note
- The command must consist of the following parts:
- the command to execute
- the model file
- options (optional)
- number of parameters to optimize
-
CreateStimuli(s)¶
-
GetExec()¶ Creates the command that runs the simulator with the model and with the appropriate options. :return: a
listof strings ready for execution
-
GetParameters()¶
-
SetNParams(o)¶ Sets the number of parameters in the given object by calling it’s
SetObjTOOptmethod.Parameters: o – the object whose method will be called Note
This is necessary because the other parts expects that the option handler objects knows the parameters subjects to optimization. Since this is not true in the case of an external simulator, this workaround is needed.
-
SetStimuli(p, e)¶
-
class
optimizer.modelHandler.modelHandlerNeuron(model_path, special_path, base='/home/docs/checkouts/readthedocs.org/user_builds/optimizer/checkouts/latest/doc')¶ Imports the necessary modules to handle Neuron models and loads the model as well as the additional mechanisms. Creates containers for the sections and the channels for easier handling.
Parameters: - model_path – the path to the model file
- special_path – the path to the special file (.mod files)
- base – the base working directory
-
CreateStimuli(stims)¶ Creates a Neuron pointprocess which is responsible for the stimulation of the model.
Note
The type of the point process is either an
IClampor aSEClamp.Parameters: stims – a
listwith the following values:- stimulation type as
string - position inside section
- name of the section
- stimulation type as
-
GetParameters()¶ Collects every member of every section object and filters out those that are not parameters of the model. The function will collect:
- every parameter of the the mechanisms
- every mechanism
- some default parameters that are always included in a model, and pointprocesses that are not some sort of Clamp
Returns: the filtered content of the model in a string matrix
-
Recordings(vector)¶ Converts the hoc vector obtained from the simulation and converts it into a
Traceobject.Parameters: vector – a hoc vector Returns: the data trace from the created object
-
RunControll(settings)¶ - Sets up the recording procedure and the simulation, then runs it.
Parameters: settings – the settings of the recording and the parameters of the simulation:
- length of simulation
- integration step size
- parameter to record
- section to record from
- position inside the section
- initial voltage
-
SetChannelParameters(section, segment, channel, params, values)¶ Sets the given channel’s parameter to the given value. If the section is not known that indicates a serious internal error and the program will abort.
Parameters: - section – the selected section’s name as
string - channel – the selected channel’s name as
string - params – the selected channel parameter’s name as
string - values – the value to be set
- section – the selected section’s name as
-
SetCustStimuli(params)¶ Uses the vector.play method from Neuron to create a time varying stimulus. The stimulus is read from the given file.
Parameters: params – listwith the name of the file containing the stimulus as first elementNote
The delay value must be set to zero and the duration must be set to 1e9, but these are not the actual parameters of the stimulus. This is necessary for Neuron in order to work.
-
SetMorphParameters(section, params, values)¶ Sets the given morphological parameter to the given value. If the section is not known that indicates a serious internal error and the program will abort. If the section has no parameter with the given name then it is interpreted as a parameter of a pointprocess and the function will set the parameter assuming the pointprocess exists in the middle (0.5) at the given section and there is only one other pointprocess in the section.
Note
This workaround is implemented because some mechanisms are implemented as pointprocesses.
param section: the name of the section as stringparam params: the name of the parameter as stringparam values: the value to set
-
SetStimuli(params, extra_params)¶ - Sets the parameters of the stimulating object. The parameters are the following:
- amplitude
- delay
- duration
or
- amplitude1
- amplitude2
- amplitude3
- duration1
- duration2
- duration3
Parameters: - params – the
listof parameters containing the first 3 values from the above list - extra_params –
listof parameters containing additional values to set up theSEClamp
Note
The rs parameter of the
SEClampis set to 0.01
-
contains(string, ss)¶ Checks if substring is in the given
listand creates a string which contains only the matching elements separated by spaces.Parameters: - string –
listof strings - ss – the substring to be matched
Returns: a string which contains only the matching elements separated by spaces
- string –
optimizer Module¶
-
optimizer.optimizer.main(parameters)¶ The main function, which starts to software according to the given command line arguments.
Parameters: parameters – the command line parameters: * -h help * -c command line * -g graphic interface
optimizerHandler Module¶
optionHandler Module¶
-
class
optimizer.optionHandler.optionHandler¶ Bases:
objectObject to store the settings required by the optimization work flow.
-
GetFileOption()¶ Returns: the current working directory (referred as base in modelHandler, used in traceReader )
-
GetFitnessParam()¶ - Gets the parameters required by the fitness functions:
listconsisting of:- a
dictionarycontaining the spike detection threshold and the spike window - a
listof fitness function names
- a
listof weights to combine the fitness functions
Returns: a listcontaining the structures described above
-
GetInputOptions()¶ - Gets the input related settings:
- input file
- number of traces in file
- unit of input
- length of the individual traces (see traceHandler)
- sampling frequency of the trace(s)
- flag indicating if file included time scale or not (will be removed, see traceHandler)
- the type of the trace(s)
Returns: the parameters listed above in a list
-
GetModelOptions()¶ - Gets the model related options:
- path to the model
- path to the directory containing the special files (see modelHanlder)
Returns: the parameters listed above in a list
-
GetModelRun()¶ - Gets the parameters corresponding to the simulation:
- length of simulation
- integration step
- parameter to record
- section name
- position inside the section
- initial voltage
Returns: the parameters above in a list
-
GetModelStim()¶ - Gets the parameters regarding the stimulus type:
- type of the stimulus
- position of stimulus
- name of the stimulated section
Returns: the parameters listed above in a list
-
GetModelStimParam()¶ - Gets the parameters of the stimulus:
- amplitude
- delay
- duration
Returns: the parameters listed above in a list
-
GetObjTOOpt()¶ Gets the parameters selected to optimization.
Returns: a listofstrings
-
GetOptParam()¶ Not in use! Gets the list of parameter values corresponding to the parameters subject to optimization.
Returns: listof real values
-
GetOptimizerOptions()¶ - Gets the parameters regarding the optimization process:
- seed: random seed
- evo_strat: name of evolution algorithm
- Size of Population: size of population
- Number of Generations: number of generations
- Mutation Rate: mutation rate (0-1)
- Cooling Rate: cooling rate (0-1)
- Mean of Gaussian: mean value of gaussian
- Std. Deviation of Gaussian: standard deviation of gaussian
- Cooling Schedule: index of cooling schedule
- Initial Temperature: initial temperature
- Final Temperature: final temperature
- Accuracy: accuracy
- Dwell: number of evaluation on the given temperature level
- Error Tolerance for x: error tolerance for input values
- Error Tolerance for f: error tolerance for fitness values
- num_params: number of input parameters
- boundaries: bounds of the parameters
- starting_points: initial values to the algorithm
Returns: a dictionarycontaining the parameters above
-
GetSimParam()¶ - Gets the simulator related parameters:
- the name of the simulator
- the command which should be executed to run the model (see modelHandler)
Returns: the parameters listed above in a list
-
GetUFunString()¶ Gets the user defined function.
Returns: the function as a string
-
SetFileOptions(options)¶ Sets the current working directory
Parameters: options – the path of the directory
-
SetFitnesParam(options)¶ Sets the parameters required by the fitness functions.
Parameters: options – the required values in the structure described in GetFitnessParam
-
SetInputOptions(options)¶ Sets the options related to the input to the given values.
Parameters: options – a listof values (order of parameter should be the same as listed inGetInputOptions)
-
SetModelOptions(options)¶ Sets the model related options.
Parameters: options – a listof values
-
SetModelRun(options)¶ Sets the parameters regarding the simulation to the given values.
Parameters: options – listof parameters
-
SetModelStim(options)¶ Sets the parameters regarding the stimulus type to the given values.
Parameters: options – listof values
-
SetModelStimParam(options)¶ Sets the parameters of the stimulus to the given values.
Parameters: options – listof valuesNote
Only the parameters of the IClamp are stored this way since the parameters of the SEClamp are obtained by combining the values here and the values regarding the simulation.
-
SetObjTOOpt(options)¶ Adds the given parameter to the list of parameters selected for optimization.
Parameters: options – a stringcontaining the section, a channel name and a channel parameter name, or a morphological parameter separated by spacesNote
If a given parameter is already stored then it will not added to the list.
-
SetOptParam(options)¶ Not in use! Adds the given value to the list of parameter values corresponding to the parameters subject to optimization.
Parameters: options – a real value
-
SetOptimizerOptions(options)¶ Sets the parameters regarding the optimization process.
Parameters: options – a dictionarycontaining the parameters
-
SetSimParam(options)¶ Sets the simulator related parameters.
Parameters: options – a listof values
-
SetUFunString(s)¶ Sets the user defined function.
Parameters: s – the function as a string
-
dump(f_mapper)¶ Dumps the content of the class into a string.
Parameters: f_mapper – a dictionarythat maps the fitness function objects to their names (used in the GUI)Returns: the content of the class as string
-
read_all(root)¶ Reads settings from an xml tree and converts them to the necessary type.
Parameters: root – the root of the xml tree Note
If there is an element in the tree whose tag is not a valid option name, then
AttributeErroris raised.Note
The program does not verify if every parameter which are needed to the current process is present. We strongly recommend that you use the GUI to create a configuration file, which will contain the needed values, instead of writing the xml file by hand.
-
-
optimizer.optionHandler.prettify(e)¶ Converts the given xml tree object to human readable form.
Parameters: e – the xml tree element Returns: the reformatted content of the xml tree as string
traceHandler Module¶
-
class
optimizer.traceHandler.DATA¶ The main data container class. :attr: data: holds the
Traceobject which contains the trace setNote
This class will be able to hold multiple data sets with multiple types.
-
PyNNReader(path, no_traces, scale, t_length, freq, trace_type)¶ Reads a default recording result from PyNN with 9 line of headers (the parameters are the same as in the
Readfunction)Returns: a traceobject holding the content of the fileNote
If the given file is not accessible the program will abort.
Note
If the number of traces in the file and the corresponding parameter is not equal, a
sizeErroris raised.
-
Read(path=['/home/docs/checkouts/readthedocs.org/user_builds/optimizer/checkouts/latest/doc/inputTrace.txt'], no_traces=1, scale='mV', t_length=1000, freq=1000, trace_type='voltage')¶ The main reader function. This calls the recognition function
detect_formatand uses the obtained reader function to read the data.Parameters: path – list of data path(s) (currently only one file is handled) (see the explanation of the other parameters in the description of
Trace)Note
The function uses the 5. line of the file for recognition.
-
abstractDataReader(path)¶
-
convert(dict_to_conv)¶
-
detect_format(line)¶ Automatically detects the format of the file and returns a reader functions which can process it correctly. The recognized formats are the following:
- simple text file with data columns separated by “\t”
- simple text file, containing time trace as well and data columns separated by “\t”
- default recording result from PyNN with 9 line of headers
- spike timing file from PyNN with 9 line of headers (not used)
Parameters: line – one line from the file, which the recognition is based on Returns: a reader function
-
get_type()¶ Gets the type of the trace set.
Returns: type
-
number_of_traces()¶ Gets the number of traces held by the object.
Returns: number of traces
-
spikeTimeReader(path, no_traces, scale, t_length, freq, trace_type)¶ Not available yet! Reads a spike timing file from PyNN with 9 line of headers (the parameters are the same as in the
Readfunction)Returns: a dictionaryobject holding the content of the fileNote
If the given file is not accessible the program will abort.
Note
If the number of traces in the file and the corresponding parameter is not equal, a
sizeErroris raised.Note
In the future, it will return a
SpikeTimesobject instead.
-
traceReader(path, no_traces, scale, t_length, freq, trace_type)¶ Reads a simple text file with data columns separated by ” ”. (the parameters are the same as in the
Readfunction)Returns: a traceobject holding the content of the fileNote
If the given file is not accessible the program will abort.
Note
If the number of traces in the file and the corresponding parameter is not equal, a
sizeErroris raised.
-
traceReaderTime(path, no_traces, scale, t_length, freq, trace_type)¶ Reads a simple text file, containing time trace as well and data columns separated by “t”. (the parameters are the same as in the
Readfunction)Returns: a traceobject holding the content of the fileNote
If the given file is not accessible the program will abort.
Note
If the number of traces in the file and the corresponding parameter is not equal, a
sizeErroris raised.
-
-
class
optimizer.traceHandler.SpikeTimes(dictionary, trace_type='spikes')¶ Not in use! Stores spike times in
dictionaryindexed by the cell’s id.Parameters: - dictionary – the
dictionarywhich contains the data - trace_type – type of the trace (should be fixed to “spikes”)
- dictionary – the
-
class
optimizer.traceHandler.Trace(no_traces, scale='milli', t_length=1000, freq=100, trace_type=None)¶ Trace set object. Stores a trace set of a given type with every relevant data.
Parameters: - no_traces – number of traces held by the object
- scale – the unit of the data (required for conversions)
- t_length – length of the trace(s)
- freq – sampling frequency
- trace_type – type of the trace set
Attr: data: the traces are contained in the attribute named
datain the order they were in the input fileNote
The sampling rate should be uniform in the set.
Note
The length of the traces should be the same, or the length of the shortest one should be considered.
Note
If the type of the trace is not recognized, the program will abort. The recognized types are “voltage”, “current” and “other” (“spike” is not available yet).
-
Convert(hoc_obj)¶ Converts a hoc vector into a python
listand stores it in the container.Parameters: hoc_obj – a hoc vector object
-
GetTrace(index)¶ Returns the trace having the index
indexform the container. Always use this function to get a given trace as they are stored in a non intuitive way and direct access would probably cause errors.Parameters: index – the index of the trace to get Note
If the given index is out of range, a
sizeErroris raised.Returns: the required trace
-
Print()¶ Prints the contained data. Created for debugging purpose.
-
SetTrace(d)¶ Adds the given trace to the container.
Parameters: d – listcontaining the trace
-
reScale(value)¶ Re-scales the given value based on the scale of the
Traceobject.Parameters: value – the value to be rescaled Returns: the rescaled value
-
optimizer.traceHandler.real_range(start, step, end)¶ Not in use! Generates real values from the given range.
Parameters: - start – begin of range
- step – step between the values
- end – the end of the range
Returns: listof real values
-
exception
optimizer.traceHandler.sizeError(message)¶ Bases:
exceptions.ExceptionException class used by the trace handling related objects.
Parameters: message – error message to be displayed
-
class
optimizer.traceHandler.traceWriter(tr_object, full_path, comment='', flag_write=1, sep='n', flag_multi=0)¶ Bases:
optimizer.traceHandler.TraceNot used! Writes the content of the given trace object to the given file(s).
Parameters: - tr_object – trace object which must have
dataattribute - full_path – the path of the output file
- comment – some header information
- flag_write – indicates if the properties of the trace is written or not
- sep – data separator
string - flag_multi – indicates if the separate traces should be written into separate files
-
Write()¶ Performs the writing.
Note
If
flag_multiwas set to true, then the traces will be written to multiple files.
- tr_object – trace object which must have