tree module¶
-
class
ezclimate.tree.
TreeModel
(decision_times, prob_scale=1.0)[source]¶ Bases:
object
Tree model for the EZ-Climate model. It provides the structure of a non-recombining tree.
Parameters: - decision_times (ndarray or list) – years in the future where decisions will be made
- prob_scale (float, optional) – scaling constant for probabilities
-
decision_times
¶ ndarray – years in the future where decisions will be made
-
prob_scale
¶ float – scaling constant for probabilities
-
node_prob
¶ ndarray – probability of reaching node from period 0
-
final_states_prob
¶ ndarray – last periods node_prob
-
get_node
(period, state)[source]¶ Returns the node in period and state provided.
Parameters: - period (int) – period
- state (int) – state of the node
Returns: node number
Return type: int
Examples
>>> t = TreeModel([0, 15, 45, 85, 185, 285, 385]) >>> t.get_node(1, 1) 2 >>> t.get_node(4, 10) 25 >>> t.get_node(4, 20) ValueError: No such state in period 4
Raises: ValueError
– If period is too large or if the state is too large for the period.
-
get_nodes_in_period
(period)[source]¶ Returns the first and last nodes in the period.
Parameters: period (int) – period Returns: number of nodes in period Return type: int Examples
>>> t = TreeModel([0, 15, 45, 85, 185, 285, 385]) >>> t.get_nodes_in_period(0) (0, 0) >>> t.get_nodes_in_period(1) (1, 2) >>> t.get_nodes_in_period(4) (15, 30)
-
get_num_nodes_period
(period)[source]¶ Returns the number of nodes in the period.
Parameters: period (int) – period Returns: number of nodes in period Return type: int Examples
>>> t = TreeModel([0, 15, 45, 85, 185, 285, 385]) >>> t.get_num_nodes_period(2) 4 >>> t.get_num_nodes_period(5) 32
-
get_parent_node
(child)[source]¶ Returns the previous or parent node of the given child node.
Parameters: child (int) – the child node Returns: partent node Return type: int Examples
>>> t = TreeModel([0, 15, 45, 85, 185, 285, 385]) >>> t.get_parent_node(2) 0 >>> t.get_parent_node(4) 1 >>> t.get_parent_node(10) 4
-
get_path
(node, period=None)[source]¶ Returns the unique path taken to come to given node.
Parameters: node (int) – the node Returns: path to get to node Return type: ndarray Examples
>>> t = TreeModel([0, 15, 45, 85, 185, 285, 385]) >>> t.get_path(2) array([0, 2]) >>> t.get_parent_node(4) array([0, 1, 4]) >>> t.get_parent_node(62) array([ 0, 2, 6, 14, 30, 62])
-
get_period
(node)[source]¶ Returns what period the node is in.
Parameters: node (int) – the node Returns: period Return type: int Examples
>>> t = TreeModel([0, 15, 45, 85, 185, 285, 385]) >>> t.get_period(0) 0 >>> t.get_period(4) 2
-
get_probs_in_period
(period)[source]¶ Returns the probabilities to get from period 0 to nodes in period.
Parameters: period (int) – the period Returns: probabilities Return type: ndarray Examples
>>> t = TreeModel([0, 15, 45, 85, 185, 285, 385]) >>> t.get_probs_in_period(2) array([ 0.25, 0.25, 0.25, 0.25]) >>> t.get_probs_in_period(4) array([ 0.0625, 0.0625, 0.0625, 0.0625, 0.0625, 0.0625, 0.0625, 0.0625, 0.0625, 0.0625, 0.0625, 0.0625, 0.0625, 0.0625, 0.0625, 0.0625])
-
get_state
(node, period=None)[source]¶ Returns the state the node represents.
Parameters: - node (int) – the node
- period (int, optional) – the period
Returns: state
Return type: int
Examples
>>> t = TreeModel([0, 15, 45, 85, 185, 285, 385]) >>> t.get_state(0) 0 >>> t.get_state(4, 2) 1
-
num_decision_nodes
¶ int – the number of nodes in tree
-
num_final_states
¶ int – the number of nodes in the last period
-
num_periods
¶ int – the number of periods in the tree
-
reachable_end_states
(node, period=None, state=None)[source]¶ Returns what future end states can be reached from given node.
Parameters: - node (int) – the node
- period (int, optional) – the period
- state (int, optional) – the state the node is in
Returns: (worst end state, best end state)
Return type: tuple
Examples
>>> t = TreeModel([0, 15, 45, 85, 185, 285, 385]) >>> t.reachable_end_states(0) (0, 31) >>> t.reachable_end_states(10) (12, 15) >>> t.reachable_end_states(32) (1, 1)