Package parsimony :: Package algorithms :: Module bases :: Class InformationAlgorithm
[hide private]
[frames] | no frames]

Class InformationAlgorithm

source code

object --+
         |
        InformationAlgorithm
Known Subclasses:

Algorithms that produce information about their run.

Implementing classes should update the INFO_PROVIDED class variable with
the information provided by the algorithm. Defauls to an empty list.

ALL algorithms that inherit from InformationAlgorithm MUST add force_reset
as a decorator to the run method.

Fields
------
info_ret : Dictionary. The algorithm outputs are collected in this
        dictionary.

info : List of utils.Info. The identifiers for the requested information
        outputs. The algorithms will store the requested outputs in
        self.info.

INFO_PROVIDED : List of utils.Info. The allowed output identifiers. The
        implementing class should update this list with the
        provided/allowed outputs.

Examples
--------
>>> import parsimony.algorithms as algorithms
>>> from parsimony.algorithms.utils import Info
>>> from parsimony.functions.losses import LinearRegression
>>> import numpy as np
>>> np.random.seed(42)
>>> gd = algorithms.gradient.GradientDescent(info=[Info.fvalue])
>>> gd.info_copy()
['fvalue']
>>> lr = LinearRegression(X=np.random.rand(10,15), y=np.random.rand(10,1))
>>> beta = gd.run(lr, np.random.rand(15, 1))
>>> fvalue = gd.info_get(Info.fvalue)
>>> round(fvalue[0], 10)
0.068510926
>>> round(fvalue[-1], 15)
1.886e-12

Instance Methods [hide private]
 
__init__(self, info=[], **kwargs)
Parameters ---------- info : List or tuple of utils.Info.
source code
 
info_get(self, nfo=None)
Returns the computed information about the algorithm run.
source code
 
info_set(self, nfo, value)
Sets the computed information about the algorithm run identified by nfo.
source code
 
info_provided(self, nfo)
Returns true if the current algorithm provides the given information, and False otherwise.
source code
 
info_requested(self, nfo)
Returns true if the the given information was requested, and False otherwise.
source code
 
info_reset(self)
Resets the information saved in the previous run.
source code
 
info_copy(self)
Returns a shallow copy of the requested information.
source code
 
check_info_compatibility(self, info)
Check if the requested information is provided.
source code

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

Class Variables [hide private]
  INFO_PROVIDED = []
Properties [hide private]

Inherited from object: __class__

Method Details [hide private]

__init__(self, info=[], **kwargs)
(Constructor)

source code 

Parameters
----------
info : List or tuple of utils.Info. The identifiers for the run
        information to return.

Overrides: object.__init__

info_get(self, nfo=None)

source code 
Returns the computed information about the algorithm run.

Parameters
----------
nfo : utils.Info. The identifier to return information about. If nfo is
        None, all information is returned in a dictionary.

info_set(self, nfo, value)

source code 
Sets the computed information about the algorithm run identified by
nfo.

Parameters
----------
nfo : utils.Info. The identifier to for the computed information about.

value : object. The value to associate with nfo.

info_reset(self)

source code 

Resets the information saved in the previous run. The info_ret field, a dictionary, is cleared.

check_info_compatibility(self, info)

source code 
Check if the requested information is provided.

Parameters
----------
info : A list of utils.Info. The identifiers for information that
        should be computed.