Reference

ParameterSet

class parameters.ParameterSet(initialiser, label=None, update_namespace=None)[source]

A class to manage hierarchical parameter sets.

Usage example:

>>> sim_params = ParameterSet({'dt': 0.1, 'tstop': 1000.0})
>>> exc_cell_params = ParameterSet("http://neuralensemble.org/svn/NeuroTools/example.params")
>>> inh_cell_params = ParameterSet({'tau_m': 15.0, 'cm': 0.5})
>>> network_params = ParameterSet({'excitatory_cells': exc_cell_params, 'inhibitory_cells': inh_cell_params})
>>> P = ParameterSet({'sim': sim_params, 'network': network_params})
>>> P.sim.dt
0.1
>>> P.network.inhibitory_cells.tau_m
15.0
>>> print P.pretty()
as_dict()[source]

Return a copy of the ParameterSet tree structure as a nested dictionary

static check_validity(k)[source]

docstring missing

export(filename, format='latex', **kwargs)[source]

docstring missing

find_references()[source]
flat()[source]
flat_add(name, value)[source]

Like __setitem__, but it will add ParameterSet({}) objects into the namespace tree if needed.

flatten()[source]
invalid_names = ['parameters', 'names']
non_parameter_attributes = ['_url', 'label', 'names', 'parameters', 'flat', 'flatten', 'non_parameter_attributes']
pretty(indent=' ', expand_urls=False)[source]

Return a unicode string representing the structure of the ParameterSet. evaluating the string should recreate the object.

static read_from_str(s, update_namespace=None)[source]

ParameterSet definition s should be a Python dict definition string, containing objects of types int, float, str, list, dict plus the classes defined in this module, Parameter, ParameterRange, etc. No other object types are allowed, except the function url(‘some_url’) or ref(‘point.delimited.path’), e.g.:

{ 'a' : {'A': 3, 'B': 4},
  'b' : [1,2,3],
  'c' : 'hello world',
  'd' : url('http://example.com/my_cool_parameter_set')
  'e' : ref('level1_param_name.level2_param_name.level3_param_name') }

This is largely the JSON (www.json.org) format, but with extra keywords in the namespace such as ParameterRange, GammaDist, etc.

replace_references()[source]
replace_values(**args)[source]

This expects its arguments to be in the form path=value, where path is a . (dot) delimited path to a parameter in the parameter tree rooted in this ParameterSet instance.

This function replaces the values of each parameter in the args with the corresponding values supplied in the arguments.

save(url=None, expand_urls=False)[source]

Write the parameter set to a text file.

The text file syntax is open to discussion. My idea is that it should be valid Python code, preferably importable as a module.

If url is None, try to save to self._url (if it is not None), otherwise save to url.

tree_copy()[source]

Return a copy of the ParameterSet tree structure. Nodes are not copied, but re-referenced.

update(E, **F)[source]

docstring missing

ParameterTable

class parameters.ParameterTable(initialiser, label=None)[source]

Bases: parameters.ParameterSet

A sub-class of ParameterSet that can represent a table of parameters.

i.e., it is limited to one-level of nesting, and each sub-dict must have the same keys. In addition to the possible initialisers for ParameterSet, a ParameterTable can be initialised from a multi-line string, e.g.:

>>> pt = ParameterTable('''
...     #       col1    col2    col3
...     row1     1       2       3
...     row2     4       5       6
...     row3     7       8       9
... ''')
>>> pt.row2.col3
6.0
>>> pt.column('col1')
{'row1': 1.0, 'row2': 4.0, 'row3': 7.0}
>>> pt.transpose().col3.row2
6.0
column(column_label)[source]

Return a ParameterSet object containing the requested column.

column_labels()[source]

Return a list of column labels.

columns()[source]

Return a list of (column_label, column) pairs, as 2-tuples.

non_parameter_attributes = ['_url', 'label', 'names', 'parameters', 'flat', 'flatten', 'non_parameter_attributes', 'row', 'rows', 'row_labels', 'column', 'columns', 'column_labels']
row(row_label)[source]

Return a ParameterSet object containing the requested row.

table_string()[source]

Returns the table as a string, suitable for being used as the initialiser for a new ParameterTable.

transpose()[source]

Return a new ParameterTable object with the same data as the current one but with rows and columns swapped.

ParameterSpace

class parameters.ParameterSpace(initialiser, label=None, update_namespace=None)[source]

A collection of ParameterSets, representing multiple points in parameter space. Created by putting ParameterRange and/or ParameterDist objects within a ParameterSet.

dist_keys()[source]

Return the list of keys for those elements which are ParameterDists.

get_ranges_values()[source]

Return a dict with the keys and values of the parameters with ParameterRanges

Example:

>>> p = ParameterSpace({})
>>> p.b = ParameterRange([1,2,3])
>>> p.a = ParameterRange(['p','y','t','h','o','n'])
>>> data = p.get_ranges_values()
>>> data
{'a': ['p', 'y', 't', 'h', 'o', 'n'], 'b': [1, 2, 3]}
iter_inner(copy=False)[source]

An iterator of the ParameterSpace which yields ParameterSets with all combinations of ParameterRange elements

iter_inner_range_keys(keys, copy=False)[source]

An iterator of the ParameterSpace which yields ParameterSets with all combinations of ParameterRange elements which are given by the keys list.

Note: each newly yielded value is one and the same object so storing the returned values results in a collection of many of the lastly yielded object.

copy=True causes each yielded object to be a newly created object, but be careful because this is spawning many dictionaries!

iter_range_key(range_key)[source]

An iterator of the ParameterSpace which yields the ParameterSet with the ParameterRange given by range_key replaced with each of its values

num_conditions()[source]

Return the number of ParameterSets that will be returned by the iter_inner() method.

parameter_space_dimension_labels()[source]

Return the dimensions and labels of the keys for those elements which are ParameterRanges. range_keys are sorted to ensure the same ordering each time.

parameter_space_index(current_experiment)[source]

Return the index of the current experiment in the dimension of the parameter space i.e. parameter space dimension: [2,3] i.e. index: (1,0)

Example:

p = ParameterSet({})
p.b = ParameterRange([1,2,3])
p.a = ParameterRange(['p','y','t','h','o','n'])

results_dim, results_label = p.parameter_space_dimension_labels()

results = numpy.empty(results_dim)
for experiment in p.iter_inner():
    index = p.parameter_space_index(experiment)
    results[index] = 2.
range_keys()[source]

Return the list of keys for those elements which are ParameterRanges.

realize_dists(n=1, copy=False)[source]

For each ParameterDist, realize the distribution and yield the result.

If copy==True, causes each yielded object to be a newly created object, but be careful because this is spawning many dictionaries!

ParameterRange

class parameters.ParameterRange(value, units=None, name='', shuffle=False)[source]

A class for specifying a list of possible values for a given parameter.

The value must be an iterable. It acts like a Parameter, but .next() can be called to iterate through the values

next()[source]

Parameter

class parameters.Parameter(value, units=None, name='')[source]

ParameterDist and its subclasses

class parameters.random.ParameterDist(**params)[source]

missing docstring

from_stats(vals, bias=0.0, expand=1.0)[source]

missing docstring

next(n=1)[source]
class parameters.random.GammaDist(mean=None, std=None, repr_mode='ms', **params)[source]

Bases: parameters.random.ParameterDist

gamma.pdf(x,a,b) = x**(a-1)*exp(-x/b)/gamma(a)/b**a

Yields strictly positive numbers. Generally the distribution is implemented by scipy.stats.gamma.pdf(x/b,a)/b For more info, in ipython type:

>>> ? scipy.stats.gamma
class parameters.random.NormalDist(mean=0.0, std=1.0)[source]

Bases: parameters.random.ParameterDist

normal distribution with parameters mean + std

class parameters.random.UniformDist(min=0.0, max=1.0, return_type=<type 'float'>)[source]

Bases: parameters.random.ParameterDist

uniform distribution with min,max

Validation

class parameters.validators.ParameterSchema(initializer)[source]

A sub-class of ParameterSet against which other ParameterSets can be validated.

Presently, it is more or less a ParameterSet, with all leafs(values) which are not explicitly a subclass of the SchemaBase object replaced by a Subclass(type=<leaf(value) type>) instance.

ParameterSchema may contain arbitrary Schema objects subclassed from SchemaBase which validate leafs by the member function validate(leaf) returning True or false if the given leaf in the ParameterSet at the same path should be validated or not, e.g.:

LambdaSchema('isinstance(x,str)',var='x'),
*unimplemented* Timedate('%.2d-%.2m-%.2y'), etc.
*unimplemented* Email()
*unimplemented* Url()
*unimplemented* File()
*unimplemented* FileExists()

etc.

Example:

>>> schema = ParameterSchema({'age': 0, 'height': Subclass(float)})
>>> # is equivalent to
>>> schema = ParameterSchema({'age': Subclass(int), 'height': Subclass(float)})

See also: SchemaBase, Eval, Subclass

class parameters.validators.CongruencyValidator[source]

A CongruencyValidator validates a ParameterSet against a ParameterSchema either returning True, or raising a ValidationError with the path, SchemaBase subclass and parameter value for which the validation failed.

The CongruencyValidator expects all names defined in the schema to be present in the parameter set and vice-versa, and will run validation for each item in the namespace tree.

The validation functionality is available via the “validate” member CongruencyValidator.validate(parameter_set, parameter_schema)

Example:

validator = CongruencyValidator()
try:
   validator.validate(parameter_set,parameter_schema)
except ValidationError, e:

See also: ParameterSet, ParameterSchema

validate(parameter_set, parameter_schema)[source]

Validates a ParameterSet against a ParameterSchema either returning True, or raising a ValidationError with the path and SchemaBase subclass for which validation failed.

Expects all names defined in the schema to be present in the parameter set and vice-versa, and will run validation for each item in the namespace tree.

See also: CongruencyValidator.

class parameters.validators.SchemaBase[source]

The base class of all “active” Schema objects to be placed in a ParameterSchema.

Schema objects define the “validate” member which accepts the to-be-validated ParameterSet value from the same path as the Schema object in the ParameterSchema and returns True if the value is valid, otherwise False.

validate(leaf)[source]
class parameters.validators.Subclass(type=None)[source]

Bases: parameters.validators.SchemaBase

To be used as a value in a ParameterSchema. Validates the same-path ParameterSet value if it is of the specified type.

See also: SchemaBase

class parameters.validators.Eval(expr, var='leaf')[source]

Bases: parameters.validators.SchemaBase

To be used as a value in a ParameterSchema. Validates the same-path ParameterSet value if the provided expression (with leaf(value) mapped to var in eval local namespace) evaluates to True.

See also: SchemaBase

Table Of Contents

Previous topic

Release notes

Next topic

How to contribute

This Page