>>> from simo.builder.modelbase.predictionmodel import PredictionModel
>>> from lxml import etree
>>> xml = u'''<model_group name="Distribution models">
... <model>
... <name>Productive_value_of_land_pine_Pukkala</name>
... <implemented_at>StaticstandModels.dll</implemented_at>
... <implemented_in>C</implemented_in>
... <author>
... <name>Timo Pukkala</name>
... </author>
... <description>...</description>
... <published_in>...</published_in>
... <species_list>
... <species>1</species>
... </species_list>
... <geographical_coverage>...</geographical_coverage>
... <applies_for>...</applies_for>
... <research_material>...</research_material>
... <variables>
... <variable>
... <name>TS</name>
... <level>comp_unit</level>
... </variable>
... </variables>
... <parameters>
... <parameter>
... <name>IR</name>
... </parameter>
... </parameters>
... <result>
... <object>self</object>
... <variables>
... <variable>
... <name>PVland_Sp</name>
... </variable>
... </variables>
... </result>
... </model>
... </model_group>'''
>>> class Validator:
... def elem_name(self, text):
... return text
... def variable_ind(self, level, variable, active=False):
... return (1,1)
... def add_model(self, mname, mtype):
... pass
>>> elem = etree.fromstring(xml)
Class for prediction model definitions
Properties:
Attributes:
Construct prediction model object from XML element:
>>> pr = PredictionModel('', elem[0], Validator(), 'dummydir',
... elem.attrib['name'])
>>> pr.name
'Productive_value_of_land_pine_Pukkala'
>>> pr.group
'Distribution models'
>>> pr.language
'c'
>>> pr.n_vars
1
>>> pr.vars
{1: {'index': array([1]), 'order': [0], 'limits': [None]}}
>>> pr.n_params
1
>>> pr.param_names
['IR']
>>> pr.param_limits
[None]
>>> pr.result_level
1
Class for prediction model result variables
Attributes:
Class for prediction model parameters
Initialize prediction model parameter object:
>>> execfile('builder/modelbase/test/mocktask.py')
>>> xml_no_param = u'''<prediction>
... <rect_factor>1.15</rect_factor>
... <risk_level>2</risk_level>
... </prediction>'''
>>> xml = u'''<prediction>
... <parameters>
... <parameter>
... <name>IR</name>
... <value>10.5</value>
... </parameter>
... <parameter>
... <name>PARAMETER2</name>
... <value>VALUE</value>
... </parameter>
... </parameters>
... <rect_factor>1.15</rect_factor>
... <risk_level>2</risk_level>
... </prediction>'''
>>> from simo.builder.modelbase.predictionmodel import PredictionModelParam
>>> elem = etree.fromstring(xml_no_param)
>>> pmp = PredictionModelParam('', elem, task, pr)
>>> abs(pmp.rect_factor - 1.15) < 0.0001
True
>>> abs(pmp.risk_level - 2.0) < 0.0001
True
>>> task.validator.errors
set(["No parameters defined in model chain for prediction model
'Productive_value_of_land_pine_Pukkala', 1 parameters expected"])
>>> task.validator.errors = set([])
>>> elem = etree.fromstring(xml)
>>> pmp = PredictionModelParam('', elem, task, pr)
>>> pmp.parameters
[10.5]
>>> task.validator.errors
set(["Parameter 'PARAMETER2' is not a valid parameter for prediction
model 'Productive_value_of_land_pine_Pukkala'"])