Container class for passing the prediction model arguments to prediction library
Attributes:
Initialize a prediction model argument container:
>>> from simo.simulation.model.predictionarg import PredictionArg
>>> import numpy
>>> arg = PredictionArg('modelname', 'C')
>>> arg.model_name
'modelname'
>>> arg.model_language
'C'
Store target object indices in the argument container:
>>> tind = numpy.array([[0,0,0,0,0],
... [0,0,1,0,0],
... [0,0,2,0,0],
... [0,0,3,0,0],
... [0,0,4,0,0],
... [0,0,5,0,0]], dtype=int)
>>> arg.set_targets(tind, set([3]), 1)
>>> arg.num_of_targets
6
>>> arg.target_index
array([[0, 0, 0, 0, 0],
[0, 0, 1, 0, 0],
[0, 0, 2, 0, 0],
[0, 0, 3, 0, 0],
[0, 0, 4, 0, 0],
[0, 0, 5, 0, 0]])
>>> arg.remove_targets
set([3])
Set model result level:
>>> arg.set_result_level(0, 'self')
>>> arg.result_level
0
Create container for model input variable values if None and store input variable values into the container:
>>> values = numpy.ones(tind.shape[0], dtype=float)
>>> values[0] = numpy.NaN
>>> loc = 2
>>> arg.set_input_variables(3, values, loc, set([0]))
>>> arg.variables
array([[ 0., 0., 0., 0., 0., 0.],
[ 0., 0., 0., 0., 0., 0.],
[ ..., 1., 1., 1., 1., 1.]])
>>> arg.remove_targets
set([0, 3])
Store result variable indices:
>>> arg.set_result_variables([0,1,2])
>>> arg.result_vars
[0, 1, 2]
>>> arg.num_of_res_vars
3
Add input parameter value to model arguments:
>>> arg.add_parameter(1.0)
>>> arg.add_parameter(2.0)
>>> arg.parameters
deque([1.0, 2.0])
Construct containers for passing results back from the model:
>>> arg.set_containers()
>>> arg.num_of_res_objs
array([0, 0, 0, 0, 0, 0])
>>> arg.mem
array([[ 0., 0., 0., 0., 0., 0.],
[ 0., 0., 0., 0., 0., 0.],
[ 0., 0., 0., 0., 0., 0.]])
>>> arg.errors
['', '', '', '', '', '']
Remove objects with missing input variable values:
>>> arg.remove_missing()
>>> arg.variables
array([[ 0., 0., 0., 0.],
[ 0., 0., 0., 0.],
[ 1., 1., 1., 1.]])
>>> arg.num_of_res_objs
array([0, 0, 0, 0])
>>> arg.mem
array([[ 0., 0., 0., 0.],
[ 0., 0., 0., 0.],
[ 0., 0., 0., 0.]])
>>> arg.errors
['', '', '', '']
>>> arg.num_of_targets
4
>>> arg.target_index
array([[0, 0, 1, 0, 0],
[0, 0, 2, 0, 0],
[0, 0, 4, 0, 0],
[0, 0, 5, 0, 0]])
Change argument types from python data types to c data types:
>>> arg.python2ctypes()
>>> arg.mem
[<simo.simulation.model.predictionarg.c_double_Array_3 object at ...>,
<simo.simulation.model.predictionarg.c_double_Array_3 object at ...>,
<simo.simulation.model.predictionarg.c_double_Array_3 object at ...>,
<simo.simulation.model.predictionarg.c_double_Array_3 object at ...>]
>>> arg.mem[0][0] = 0.0
>>> arg.mem[0][1] = 1.0
>>> arg.mem[0][2] = 2.0
>>> arg.mem[1][0] = 0.1
>>> arg.mem[2][0] = 0.2
>>> arg.mem[3][0] = 0.3
Change argument types from ctypes to python and remove objects with evaluation errors from target objects:
>>> arg.ctypes2python()
>>> arg.mem
array([[ 0. , 0.1, 0.2, 0.3],
[ 1. , 0. , 0. , 0. ],
[ 2. , 0. , 0. , 0. ]])
structure. These arrays are used for passing data to the DLL model libraries. Uses ctypes package for the variable types
Add error to target object i:
>>> arg.add_error(2)
>>> arg.errors
array(['', '', '', ''],
dtype='|S1')
Trim the prediction model result structures to only contain valid results; i.e., no error in model call. Also remove empty error strings.:
>>> arg.drop_error_objects()
>>> arg.target_index
array([[0, 0, 1, 0, 0],
[0, 0, 2, 0, 0],
[0, 0, 5, 0, 0]])
>>> arg.num_of_res_objs
array([0, 0, 0])
>>> arg.mem
array([[ 0. , 0.1, 0.3],
[ 1. , 0. , 0. ],
[ 2. , 0. , 0. ]])