Package parsimony :: Package utils :: Module start_vectors :: Class RandomStartVector
[hide private]
[frames] | no frames]

Class RandomStartVector

source code

     object --+    
              |    
BaseStartVector --+
                  |
                 RandomStartVector

A start vector of uniformly distributed random values.

Parameters
----------
normalise : Bool. If True, normalise the randomly created vectors.
        Default is True.

seed : Integer or None. The seed to the pseudo-random number generator. If
        none, no seed is used. The seed is set at initialisation, so if the
        RNG is used in between initialisation and utilisation, then the
        random numbers will change. Default is None.

limits : List or tuple. A list or tuple with two elements, the lower and
        upper limits of the uniform distribution. If normalise=True, then
        these limits may not be honoured. Default is (0.0, 1.0).

Examples
--------
>>> from parsimony.utils.start_vectors import RandomStartVector
>>>
>>> # Without normalization
>>> start_vector = RandomStartVector(normalise=False, seed=42)
>>> random = start_vector.get_vector(3)
>>> print random
[[ 0.37454012]
 [ 0.95071431]
 [ 0.73199394]]
>>> print maths.norm(random)
1.25696186254
>>>
>>> # With normalization
>>> start_vector_normalized = RandomStartVector(normalise=True, seed=2)
>>> random_normalized = start_vector_normalized.get_vector(3)
>>> print random_normalized
[[ 0.62101956]
 [ 0.03692864]
 [ 0.78292463]]
>>> print maths.norm(random_normalized)
1.0
>>>
>>> # With limits
>>> start_vector_normalized = RandomStartVector(normalise=True, seed=2,
...                                             limits=(-1, 1))
>>> random_limits = start_vector_normalized.get_vector(3)
>>> print random_limits
[[-0.1330817 ]
 [-0.98571123]
 [ 0.10326001]]
>>> print maths.norm(random_limits)
1.0

Nested Classes [hide private]

Inherited from BaseStartVector: __metaclass__

Instance Methods [hide private]
 
__init__(self, limits=(0.0, 1.0), **kwargs)
x.__init__(...) initializes x; see help(type(x)) for signature
source code
 
get_vector(self, size)
Return randomly generated vector of given shape.
source code

Inherited from object: __delattr__, __format__, __getattribute__, __hash__, __new__, __reduce__, __reduce_ex__, __repr__, __setattr__, __sizeof__, __str__, __subclasshook__

Class Variables [hide private]
  __abstractmethods__ = frozenset([])
Properties [hide private]

Inherited from object: __class__

Method Details [hide private]

__init__(self, limits=(0.0, 1.0), **kwargs)
(Constructor)

source code 

x.__init__(...) initializes x; see help(type(x)) for signature

Overrides: object.__init__
(inherited documentation)

get_vector(self, size)

source code 
Return randomly generated vector of given shape.

Parameters
----------
size : Positive integer. Size of the vector to generate. The shape of
        the output is (size, 1).

Examples
--------
>>> from parsimony.utils.start_vectors import RandomStartVector
>>> start_vector = RandomStartVector(normalise=False, seed=42)
>>> random = start_vector.get_vector(3)
>>> print random
[[ 0.37454012]
 [ 0.95071431]
 [ 0.73199394]]
>>>
>>> start_vector = RandomStartVector(normalise=False, seed=1,
...                                  limits=(-1, 2))
>>> random = start_vector.get_vector(3)
>>> print random
[[ 0.25106601]
 [ 1.16097348]
 [-0.99965688]]

Overrides: BaseStartVector.get_vector