ml4cps.automata.base module¶
The module provides a class Automaton which inherits CPSComponent and implements the dynamics of different kinds of automata.
Authors: - Nemanja Hranisavljevic, hranisan@hsu-hh.de, nemanja@ai4cps.com - Tom Westermann, tom.westermann@hsu-hh.de, tom@ai4cps.com
- class ml4cps.automata.base.Automaton(states: list = None, transitions: list = None, unknown_state: str = 'raise', id='', initial_q=(), final_q=(), super_states=(), decision_states=(), **kwargs)¶
Bases:
CPSComponentAutomaton class is the main class for modeling various kinds of hybrid systems.
- property Sigma¶
- accepts(string, return_states=False)¶
- add_final_state(states)¶
- Add final state(s) of the automaton.
- param states:
States to add.
- add_initial_state(states)¶
- Add initial state(s) of the automaton.
- param states:
States to add.
- add_single_transition(s, d, e, timing=None)¶
- add_state(new_state, **kwargs)¶
- Add state to the automaton.
- param new_state:
State to be added.
- add_state_data(s: str, d: object)¶
- Add state data to a state s the automaton.
- param s:
state
- param d:
data to be added to s
- return:
- add_states_from(new_state, **kwargs)¶
- Add multiple states to the automaton.
- param new_state:
States to be added.
- add_transition(s, d, e, **other)¶
- Add multiple transition.
- param list_of_tuples:
List of transitions in the form (source_state, destination_state, event, …<unused>…).
- add_transitions_from(list_of_tuples, **other)¶
- Add multiple transition.
- param list_of_tuples:
List of transitions in the form (source_state, destination_state, event, …<unused>…).
- determinize(s, state_index, verbose=False)¶
- discrete_event_dynamics(q, xt, xk, p) tuple¶
- property discrete_state¶
- property discrete_states¶
- flow(q, p, x, u)¶
- Flow equation gives derivative of the continuous variables.
- param q:
Current discrete state of the model.
- param p:
Stochastic parameters generated on entry to state current_q.
- param x:
Current continuous state of the model.
- param u:
Calculated internal i signals.
- return:
Derivative of the continuous state x.
- generate(number_of_sequences=1, return_states=False, prob_to_accept=0.5)¶
- get_alternatives(state, system_state)¶
- get_num_in(q)¶
Returns the number of in transitions of state q in the automaton. :return: number of transitions.
- get_num_out(q)¶
Returns the number of out transitions of state q in the automaton. :return: number of transitions.
- get_transition(s, d=None, e=None, if_more_than_one='raise')¶
Get all transitions with source state s, destination state __d. In case when e is provided, the returned list contains transitions where event is e. :param if_more_than_one: :param s: Source state. :param d: Destination state. :param e: Event. :return:
- get_transitions()¶
- guards(q, x)¶
- in_transitions(s, event=None)¶
- Get all incoming transitions of state s.
- param s:
- return:
- inv(t, q, x, y, z, p)¶
- Invariants.
- param t:
- param q:
- param x:
- param y:
- param z:
- param p:
- is_decision(state, overall_state)¶
- is_deterministic()¶
- is_state(q)¶
- is_transition(s, d, e)¶
- Check if a transition (s,d,e) exists in the automaton.
- param s:
Source.
- param d:
Destination.
- param e:
Event.
- return:
- learn_transition_probabilities()¶
- merge(q1, q2)¶
If two states are compatible, they are merged with the function merge. The transitions of the automaton, the in- and outdegree of the states and the number of transitions happening are adjusted.
- property num_events¶
- property num_modes¶
Returns the number of modes in the automaton. :return: number of states.
- num_occur(tr)¶
- num_timings()¶
- property num_transitions¶
Returns the number of transitions in the automaton. :return: number of transitions.
- out_transitions(s, event=None)¶
- Get all outgoing transitions of state s.
- param event:
- param s:
- return:
- predict_state(data_collection, time_col_name=None, discr_col_names=None)¶
- print_state(v)¶
Prints outgoing transitions of a state v.
- Parameters:
v (state)
- Returns:
Description of the outgoing transitions of the state.
- Return type:
String
- read_event(t, e, clear_p=False, keep_p=None, **kwargs)¶
- remove_rare_transitions(min_p=0, min_num=0, keep_from_initial=False, keep_states=False, keep=None)¶
- remove_state(s)¶
- remove_transition(source, dest)¶
Remove the transition(s) from source to dest. :param source: :param dest: :return:
- rename_events(prefix='e_')¶
Rename events to become e_0, e_1… The old id is stored in the field ‘old_symbol’ of the state data.
- sample_initial()¶
- property state¶
Automata discrete state is uni-variate. :return:
- state_is_deterministic(q)¶
- step(q, x0, t, u)¶
- Simulates one time step of continuous behavior from t to t+dt. Underlying function is solve_ivp with method is ‘RK23’.
- param x0:
Initial state vector.
- param t:
Time at start of the step simulation.
- param u:
Arguments passed…..
- return:
Time t+dt, value of state at t+dt
- timed_event(q, xc, xd)¶
Calculates if and when the next time event will happen and the new state values. :param t: Current time. :param q: Discrete-event part of the state. :param xc: Time-continuous part of the state. :param xd: Time-discrete part of the state. :return: Time delay of the timed event, new state value.
- property transitions¶
- try_merge_states(state1, state2, try_fun=None)¶
Merge state2 into state1 and update transitions.
- update_timing_boundaries(source, destination, event, newTiming)¶