Table Of Contents

Previous topic

paramtablecaller.py

Next topic

predictionmemory.py

This Page

predictioncaller.py

>>> from simo.simulation.caller.predictioncaller import PredictionModelCaller
>>> execfile('simulation/caller/test/mocks4predictioncaller.py')

class PredictionModelCaller(Caller):

Class for executing prediction models

Attributes:

  • memory: PredictionModelMemory object
  • arg: PredictionArg object

def __init__(self):

Initialize model caller. Warnings attribute is boolean defining whether warnings will be processed:

>>> pc = PredictionModelCaller(True)

def execute(self, model, params, sim, depthind):

Construct and execute prediction model call for a model where the result level is equal to model chain evaluation level (results are stored for existing objects):

>>> pc.execute(model, params, sim, 0)
Called Data.get_tind(1, 0, None, None, True, None, None)
Called Data.get_active()
Called Data.get_tind(1, 0, 0, None, True, None, None)
Called Data.get_active()
Called Data.get_value(
    array([[0, 0, 0, 0, 0],
       [0, 0, 1, 0, 0],
       [0, 1, 0, 0, 0]]),
    [0, 1])
Called Data.set_active(None)
Called Data.get_value(
    array([[0, 0, 0, 0, 0],
       [0, 0, 1, 0, 0],
       [0, 1, 0, 0, 0]]),
    [2, 3])
Called Data.set_value(
    1,
    array([[0, 0, 0, 0, 0],
       [0, 0, 1, 0, 0],
       [0, 1, 0, 0, 0]]),
    [1, 1, 1, 1],
    array([[ 0. ,  1. ,  2. ],
       [ 0.1,  1.1,  2.1],
       [ 0.2,  1.2,  2.2],
       [ 0.3,  1.3,  2.3]]),
    'dummymodel',
    True)

Construct and execute prediction model call for a model where the result level is a child level of model chain evaluation level (new objects are constructed and the results are calculated for the new objects):

>>> sim.level = 0
>>> model.result_level = 1
>>> del model.vars[1]
>>> pc.execute(model, params, sim, 0)
Called Data.get_tind(0, 0, None, None, True, None, None)
Called Data.get_active()
Called Data.set_active(None)
Called Data.get_value(
    array([[0, 0, 0, 0, 0],
       [0, 0, 1, 0, 0],
       [0, 1, 0, 0, 0]]),
    [0, 1])
Called Data.add_objects(0, 0, 1, 4, 0, 0)
Called Data.set_value(
    1,
    None,
    [1, 1, 1, 1],
    array([[ 0.  ,  0.1 ,  0.2 ,  0.3 ],
       [ 0.01,  0.11,  0.21,  0.31],
       [ 0.02,  0.12,  0.22,  0.32],
       [ 0.03,  0.13,  0.23,  0.33]]),
    'dummymodel',
    True)
Called Data.add_objects(0, 0, 1, 5, 0, 1)
Called Data.set_value(
    1,
    None,
    [1, 1, 1, 1],
    array([[ 1.  ,  1.04,  1.13,  1.22,  1.31],
       [ 1.01,  1.1 ,  1.14,  1.23,  1.32],
       [ 1.02,  1.11,  1.2 ,  1.24,  1.33],
       [ 1.03,  1.12,  1.21,  1.3 ,  1.34]]),
    'dummymodel',
    True)
Called Data.add_objects(0, 1, 1, 6, 0, 0)
Called Data.set_value(
    1,
    None,
    [1, 1, 1, 1],
    array([[ 2.  ,  2.04,  2.12,  2.2 ,  2.24,  2.32],
       [ 2.01,  2.05,  2.13,  2.21,  2.25,  2.33],
       [ 2.02,  2.1 ,  2.14,  2.22,  2.3 ,  2.34],
       [ 2.03,  2.11,  2.15,  2.23,  2.31,  2.35]]),
    'dummymodel',
    True)

Execute a prediction model so that data handler returns errors due to missing values

>>> values = numpy.array([[None, 2.1, 3.1],
...                       [1.2, None, 3.2]], dtype=float)
>>> err = ([('value missing', [0,1])], 'error_tind', set([0,1]))
>>> sim.data.get_value.mock_returns = values, err
>>> sim.level = 1
>>> model.result_level = 1
>>> pc.execute(model, params, sim, 0)
Called Data.get_tind(1, 0, None, None, True, None, None)
Called Data.get_active()
Called Data.get_tind(1, 0, 0, None, True, None, None)
Called Data.get_active()
Called Data.get_value(
    array([[0, 0, 0, 0, 0],
       [0, 0, 1, 0, 0],
       [0, 1, 0, 0, 0]]),
    [0, 1])
Called Simulator.add_error(
    "prediction model caller: value missing when calling model 'dummymodel'",
    1,
    array([[0, 0, 0, 0, 0],
       [0, 0, 1, 0, 0]]))
Called Data.set_value(
    1,
    array([[0, 1, 0, 0, 0]]),
    [1, 1, 1, 1],
    array([[ 0. ],
       [ 0.1],
       [ 0.2],
       [ 0.3]]),
    'dummymodel',
    True)

def _construct_call(self, model, params, sim, depthind, tind):

Construct prediction model call

def _construct_variables(self, model, sim, depthind, tind):

Get model input variable values and add the values to arguments

def _construct_parameters(self, model, params, sim):

Get model input parameter values and add the values to arguments

def _call_model(self, model, sim):

Call prediction model function

def _process_results(self, sim):

Process and store prediction model results

def _process_eval_level_results(self, level, attrs, sim):

Store results for existing objects

def _process_child_level_results(self, level, attrs, sim):

Create new objects and store model results to the new objects