agentMET4FOF agents

Base agents

class agentMET4FOF.agents.base_agents.AgentMET4FOF(name='', host=None, serializer=None, transport=None, attributes=None, backend='osbrain', mesa_model=None)[source]

Base class for all agents with specific functions to be overridden/supplied by user.

Behavioral functions for users to provide are init_parameters, agent_loop and on_received_message. Communicative functions are bind_output, unbind_output and send_output.

_bind_output(output_agent, channel='default')[source]

Internal method which implements the logic for connecting this agent, to the output_agent.

_convert_matplotlib_fig(fig: matplotlib.figure.Figure, mode: str = 'image')[source]

Convert matplotlib figure to be rendered by the dashboard

_convert_to_plotly(matplotlib_fig: matplotlib.figure.Figure)[source]

Internal method to convert matplotlib figure to plotly figure

Parameters:matplotlib_fig (plt.Figure) – Matplotlib figure to be converted
_fig_to_uri(matplotlib_fig: matplotlib.figure.Figure)[source]

Internal method to convert matplotlib figure to base64 uri image for display

Parameters:matplotlib_fig (plt.Figure) – Matplotlib figure to be converted
_get_metadata(data)[source]

Internal helper function for getting the data type & dimensions of data. This is for update_output_channels_info()

_is_type_message(data)[source]

Internal method to check if the data carries signature of an agent message type

Parameters:data – Data to be checked for type
Returns:result
Return type:boolean
_remove_methods(cls)[source]

Remove methods from the other backends base class from the current agent

_update_output_channels_info(data, channel)[source]

Internal method to update the dict of output_channels_info. This is used in conjunction with send_output().

Checks and records data type & dimension and channel name If the data is nested within dict, then it will search deeper and subsequently record the info of each inner hierarchy

Parameters:
  • data – data to be checked for type & dimension
  • channel (str) – name of channel to be recorded
agent_loop()[source]

User defined method for the agent to execute for loop_wait seconds specified either in self.loop_wait or explicitly via init_agent_loop( loop_wait)

To start a new loop, call init_agent_loop(loop_wait) on the agent. Example of usage is to check the current_state of the agent and send data periodically.

bind_output(output_agent, channel='default')[source]

Forms Output connection with another agent

Any call on send_output will reach this newly binded agent. Adds the agent to its list of Outputs.

Parameters:
  • output_agent (AgentMET4FOF or list) – Agent(s) to be binded to this agent’s output channel
  • channel (str or list of str) – Specific name of the channel(s) to be subscribed to. (Default = “data”)
buffer_clear(agent_name: Optional[str] = None)[source]

Empties buffer which is a dict indexed by the agent_name.

Parameters:agent_name (str, optional) – Key of the memory dict, which can be the name of input agent, or self.name. If not supplied (default), we assume to clear the entire memory.
buffer_filled(agent_name=None)[source]

Checks whether the internal buffer has been filled to the maximum allowed specified by self.buffer_size

Parameters:agent_name (str) – Index of the buffer which is the name of input agent.
Returns:status of buffer filled
Return type:boolean
buffer_store(agent_from: str, data=None, concat_axis=0)[source]

Updates data stored in self.buffer with the received message

Checks if sender agent has sent any message before If it did,then append, otherwise create new entry for it

Parameters:
  • agent_from (str) – Name of agent sender
  • data – Any supported data which can be stored in dict as buffer. See AgentBuffer for more information.
get_attr(attr)[source]

Return the specified attribute of the agent.

Parameters:name – Name of the attribute to be retrieved.
handle_process_data(message)[source]

Internal method to handle incoming message before calling on_received_message

If current_state is either Stop or Reset, it will terminate early before entering on_received_message.

init_agent(buffer_size=1000, log_mode=True)[source]

Internal initialization to setup the agent: mainly on setting the dictionary of Inputs, Outputs, PubAddr. Calls user-defined init_parameters() upon finishing.

Inputs

Dictionary of Agents connected to its input channels. Messages will arrive from agents in this dictionary. Automatically updated when bind_output() function is called

Type:dict
Outputs

Dictionary of Agents connected to its output channels. Messages will be sent to agents in this dictionary. Automatically updated when bind_output() function is called

Type:dict
PubAddr_alias

Name of Publish address socket

Type:str
PubAddr

Publish address socket handle

Type:str
AgentType

Name of class

Type:str
current_state

Current state of agent. Can be used to define different states of operation such as “Running”, “Idle, “Stop”, etc.. Users will need to define their own flow of handling each type of self.current_state in the agent_loop

Type:str
loop_wait

The interval to wait between loop. Call init_agent_loop to restart the timer or set the value of loop_wait in init_parameters when necessary.

Type:int
buffer_size

The total number of elements to be stored in the agent buffer When total elements exceeds this number, the latest elements will be replaced with the incoming data elements

Type:int
init_agent_loop(loop_wait: Optional[int] = None)[source]

Initiates the agent loop, which iterates every loop_wait seconds

Stops every timers and initiate a new loop.

Parameters:loop_wait (int, optional) – The wait between each iteration of the loop
init_buffer(buffer_size)[source]

A method to initialise the buffer. By overriding this method, user can provide a custom buffer, instead of the regular AgentBuffer. This can be used, for example, to provide a MetrologicalAgentBuffer in the metrological agents.

init_parameters()[source]

User provided function to initialize parameters of choice.

log_info(message)[source]

Prints logs to be saved into logfile with Logger Agent

Parameters:message (str) – Message to be logged to the internal Logger Agent
on_connect_output(output_agent)[source]

This method is called whenever an agent is connected to its output

This can be for example, to send metadata or ping to the output agent.

on_received_message(message)[source]

User-defined method and is triggered to handle the message passed by Input.

Parameters:message (Dictionary) – The message received is in form {‘from’:agent_name, ‘data’: data, ‘senderType’: agent_class, ‘channel’:channel_name}. agent_name is the name of the Input agent which sent the message data is the actual content of the message.
pack_data(data, channel='default')[source]

Internal method to pack the data content into a dictionary before sending out.

Special case : if the data is already a message, then the from and senderType will be altered to this agent, without altering the data and channel within the message this is used for more succinct data processing and passing.

Parameters:
  • data (argument) – Data content to be packed before sending out to agents.
  • channel (str) – Key of dictionary which stores data
Returns:

  • Packed message data (dict of the form {‘from’:agent_name, ‘data’: data,)
  • ’senderType’ (agent_class, ‘channel’:channel_name}.)

reset()[source]

This method will be called on all agents when the global reset_agents is called by the AgentNetwork and when the Reset button is clicked on the dashboard.

Method to reset the agent’s states and parameters. User can override this method to reset the specific parameters.

respond_reply_attr_(message_data)[source]

Response to a reply of setting attribute

respond_request_attr_(attribute: str)[source]

Response to a request of attribute from input agents.

This agent reply with the requested attribute if it has it.

respond_request_method_(message_data: dict)[source]

Response to a request of executing method from input agents.

This agent will execute the method with the provided parameters of the method.

send_output(data, channel='default')[source]

Sends message data to all connected agents in self.Outputs.

Output connection can first be formed by calling bind_output. By default calls pack_data(data) before sending out. Can specify specific channel as opposed to ‘default’ channel.

Parameters:
  • data (argument) – Data content to be sent out
  • channel (str) – Key of message dictionary which stores data
Returns:

message – {‘from’:agent_name, ‘data’: data, ‘senderType’: agent_class, ‘channel’:channel_name}.

Return type:

dict

send_plot(fig: Union[matplotlib.figure.Figure, Dict[str, matplotlib.figure.Figure]], mode: str = 'image')[source]

Sends plot to agents connected to this agent’s Output channel.

This method is different from send_output which will be sent to through the ‘plot’ channel to be handled.

Tradeoffs between “image” and “plotly” modes are that “image” are more stable and “plotly” are interactive. Note not all (complicated) matplotlib figures can be converted into a plotly figure.

Parameters:
  • fig (matplotlib.figure.Figure or dict of matplotlib.figure.Figure) – Alternatively, multiple figures can be nested in a dict (with any preferred keys) e.g {“Temperature”:matplotlib.Figure, “Acceleration”:matplotlib.Figure}
  • mode (str) – “image” - converts into image via encoding at base64 string. “plotly” - converts into plotly figure using mpl_to_plotly Default: “image”
Returns:

graph

Return type:

str or plotly figure or dict of one of those converted figure(s)

send_request_attribute(attribute: str)[source]

Send a request of attribute to output agents.

Output agents will reply with the requested attribute if they have.

send_request_method(method: str, **method_params)[source]

Send a request of executing methods to output agents.

Output agents will respond by calling the method.

send_set_attr(attr: str, value)[source]

Sends a message to set the attr of another agent to that of value.

Parameters:
  • attr (str) – The variable name of the output agent to be set.
  • value – The value of the variable to be set
set_attr(**kwargs)[source]

Set object attributes.

Parameters:kwargs ([name, value]) – Keyword arguments will be used to set the object attributes.
shutdown()[source]

Cleanly stop and shut down the agent assuming the agent is running.

Will let the main thread do the tear down.

step()[source]

Used for MESA backend only. Behaviour on every update step.

stop_agent_loop()[source]

Stops agent_loop from running

Note that the agent will still be responding to messages.

unbind_output(output_agent)[source]

Remove existing output connection with another agent

This reverses the bind_output method.

Parameters:output_agent (AgentMET4FOF) – Agent binded to this agent’s output channel
class agentMET4FOF.agents.base_agents.DataStreamAgent(name='', host=None, serializer=None, transport=None, attributes=None, backend='osbrain', mesa_model=None)[source]

Able to simulate generation of datastream by loading a given DataStreamMET4FOF

Can be used in incremental training or batch training mode. To simulate batch training mode, set pretrain_size=-1 , otherwise, set pretrain_size and batch_size for the respective. See DataStreamMET4FOF on loading your own data set as a data stream.

agent_loop()[source]

User defined method for the agent to execute for loop_wait seconds specified either in self.loop_wait or explicitly via init_agent_loop( loop_wait)

To start a new loop, call init_agent_loop(loop_wait) on the agent. Example of usage is to check the current_state of the agent and send data periodically.

init_parameters(stream=<agentMET4FOF.streams.base_streams.DataStreamMET4FOF object>, pretrain_size=None, batch_size=1, loop_wait=1, randomize=False)[source]
Parameters:
  • stream (DataStreamMET4FOF) – A DataStreamMET4FOF object which provides the sample data
  • pretrain_size (int) – The number of sample data to send through in the first loop cycle, and subsequently, the batch_size will be used
  • batch_size (int) – The number of sample data to send in every loop cycle
  • loop_wait (int) – The duration to wait (seconds) at the end of each loop cycle before going into the next cycle
  • randomize (bool) – Determines if the dataset should be shuffled before streaming
reset()[source]

This method will be called on all agents when the global reset_agents is called by the AgentNetwork and when the Reset button is clicked on the dashboard.

Method to reset the agent’s states and parameters. User can override this method to reset the specific parameters.

class agentMET4FOF.agents.base_agents.MonitorAgent(name='', host=None, serializer=None, transport=None, attributes=None, backend='osbrain', mesa_model=None)[source]

Unique Agent for storing plots and data from messages received from input agents.

The dashboard searches for Monitor Agents’ buffer and plots to draw the graphs “plot” channel is used to receive base64 images from agents to plot on dashboard

plots

Dictionary of format {agent1_name : agent1_plot, agent2_name : agent2_plot}

Type:dict
plot_filter

List of keys to filter the ‘data’ upon receiving message to be saved into memory Used to specifically select only a few keys to be plotted

Type:list of str
custom_plot_function

a custom plot function that can be provided to handle the data in the monitor agents buffer (see AgentMET4FOF for details). The function gets provided with the content (value) of the buffer and with the string of the sender agent’s name as stored in the buffer’s keys. Additionally any other parameters can be provided as a dict in custom_plot_parameters.

Type:callable
custom_plot_parameters

a custom dictionary of parameters that shall be provided to each call of the custom_plot_function

Type:dict
init_parameters(plot_filter: Optional[List[str]] = None, custom_plot_function: Optional[Callable[[...], plotly.graph_objs._scatter.Scatter]] = None, **kwargs)[source]

Initialize the monitor agent’s parameters

Parameters:
  • plot_filter (list of str, optional) – List of keys to filter the ‘data’ upon receiving message to be saved into memory. Used to specifically select only a few keys to be plotted
  • custom_plot_function (callable, optional) – a custom plot function that can be provided to handle the data in the monitor agents buffer (see AgentMET4FOF for details). The function gets provided with the content (value) of the buffer and with the string of the sender agent’s name as stored in the buffer’s keys. Additionally any other parameters can be provided as a dict in custom_plot_parameters. By default the data gets plotted as shown in the various tutorials.
  • kwargs (Any) – custom key word parameters that shall be provided to each call of the custom_plot_function
on_received_message(message)[source]

Handles incoming data from ‘default’ and ‘plot’ channels.

Stores ‘default’ data into buffer and ‘plot’ data into plots

Parameters:message (dict) – Acceptable channel values are ‘default’ or ‘plot’
reset()[source]

This method will be called on all agents when the global reset_agents is called by the AgentNetwork and when the Reset button is clicked on the dashboard.

Method to reset the agent’s states and parameters. User can override this method to reset the specific parameters.

update_plot_memory(message: Dict[str, Any])[source]

Updates plot figures stored in self.plots with the received message

Parameters:message (dict) – Standard message format specified by AgentMET4FOF class Message[‘data’] needs to be base64 image string and can be nested in dictionary for multiple plots. Only the latest plot will be shown kept and does not keep a history of the plots.

Signal agents

class agentMET4FOF.agents.signal_agents.SineGeneratorAgent(name='', host=None, serializer=None, transport=None, attributes=None, backend='osbrain', mesa_model=None)[source]

An agent streaming a sine signal

Takes samples from the SineGenerator and pushes them sample by sample to connected agents via its output channel.

agent_loop()[source]

Model the agent’s behaviour

On state Running the agent will extract sample by sample the input data streams content and push it via invoking AgentMET4FOF.send_output().

init_parameters(sfreq=500, sine_freq=5, amplitude=1, initial_phase=0)[source]

Initialize the input data

Initialize the input data stream as an instance of the SineGenerator class.

Parameters:
  • sfreq (int) – sampling frequency for the underlying signal
  • sine_freq (float) – frequency of the generated sine wave
  • amplitude (float) – amplitude of the generated sine wave
  • initial_phase (float) – initial phase (at t=0) of the generated sine wave

Metrologically enabled base agents

class agentMET4FOF.agents.metrological_base_agents.MetrologicalAgent(name='', host=None, serializer=None, transport=None, attributes=None, backend='osbrain', mesa_model=None)[source]
_input_data = None

Input dictionary of all incoming data including metadata:

dict like {
    <from>: {
        "buffer": TimeSeriesBuffer(maxlen=buffer_size),
        "metadata": MetaData(**kwargs).metadata,
    }
_output_data = None

Output dictionary of all outgoing data including metadata:

dict like {
    <from>: {
        "buffer": TimeSeriesBuffer(maxlen=buffer_size),
        "metadata": MetaData(**kwargs).metadata,
    }
agent_loop()[source]

User defined method for the agent to execute for loop_wait seconds specified either in self.loop_wait or explicitly via init_agent_loop( loop_wait)

To start a new loop, call init_agent_loop(loop_wait) on the agent. Example of usage is to check the current_state of the agent and send data periodically.

init_parameters(input_data_maxlen=25, output_data_maxlen=25)[source]

User provided function to initialize parameters of choice.

on_received_message(message)[source]

User-defined method and is triggered to handle the message passed by Input.

Parameters:message (Dictionary) – The message received is in form {‘from’:agent_name, ‘data’: data, ‘senderType’: agent_class, ‘channel’:channel_name}. agent_name is the name of the Input agent which sent the message data is the actual content of the message.
pack_data(data, channel='default')[source]

Internal method to pack the data content into a dictionary before sending out.

Special case : if the data is already a message, then the from and senderType will be altered to this agent, without altering the data and channel within the message this is used for more succinct data processing and passing.

Parameters:
  • data (argument) – Data content to be packed before sending out to agents.
  • channel (str) – Key of dictionary which stores data
Returns:

  • Packed message data (dict of the form {‘from’:agent_name, ‘data’: data,)
  • ’senderType’ (agent_class, ‘channel’:channel_name}.)

class agentMET4FOF.agents.metrological_base_agents.MetrologicalMonitorAgent(name='', host=None, serializer=None, transport=None, attributes=None, backend='osbrain', mesa_model=None)[source]
init_parameters(*args, **kwargs)[source]

User provided function to initialize parameters of choice.

on_received_message(message)[source]

Handles incoming data from default and plot channels

Feeds default data into the buffer as a dictionary:

dict like {
“data”: message[“data”], “metadata”: message[“metadata”],

}

and hands over ‘plot’ data to plot memory.

Parameters:message (dict) – Acceptable channel values are default or plot
reset()[source]

This method will be called on all agents when the global reset_agents is called by the AgentNetwork and when the Reset button is clicked on the dashboard.

Method to reset the agent’s states and parameters. User can override this method to reset the specific parameters.

update_plot_memory(message)[source]

Updates plot figures stored in self.plots with the received message

Parameters:message (dict) – Standard message format specified by AgentMET4FOF class Message[‘data’] needs to be base64 image string and can be nested in dictionary for multiple plots Only the latest plot will be shown kept and does not keep a history of the plots.

Metrological agents to reduce redundancy

class agentMET4FOF.agents.metrological_redundancy_agents.RedundancyAgent(name='', host=None, serializer=None, transport=None, attributes=None, backend='osbrain', mesa_model=None)[source]

This is the main Redundancy Agent class

Redundancy means that there is more than one way to derive the value of the measurand Y from the values of the sensor data X_i. Following main cases are considered in the agent:

  • Redundant measurement of the measurand Y by independent sensors directly measuring Y
  • Redundant measurement of the measurand Y by correlated sensors directly measuring Y
  • Redundant measurement of the measurand Y by correlated sensors X_i indirectly measuring Y, with a linear relationship y = a + A * x between the vector x of sensor values and the vector y containing the various (redundant) estimates of the measurand Y, where a is a vector and A a matrix both of appropriate size.

Main calculations are performed in calc_lcs() and calc_lcss(). Usage of the RedundancyAgent is relatively straightforward. Note that all static functions have their own test functions illustrating their usage. Details of the different methods are presented in their respective docstrings.

Please refer to other sections in this documentation for more information. A scientific publication explaining the ideas behind this agent can be found in [Kok2020_1]. Related work can be found in [Kok2020_2].

The usage of the Redundancy Agent is illustrated with two examples contained in two tutorials.

References

agent_loop()[source]

Model the agent’s behaviour

On state Running the agent will extract sample by sample the input data streams content and push it via invoking send_output.

calc_best_est_lin_sys(a_arr, a_arr2d, x_arr, vx_arr2d, problim)[source]

Calculate the best estimate of a linear system y = a + A * x

Additionally determine if the inputs are consistent in view of problim.

Parameters:
  • a_arr (np.ndarray of shape (n_estimates)) – vector a of linear system y = a + A * x
  • a_arr2d (np.ndarray of shape (n_estimates, n_sensors)) – matrix A of linear system y = a + A * x
  • x_arr (np.ndarray of shape (n_sensors)) – vector with sensor values, vector x of linear system y = a + A * x
  • vx_arr2d (np.ndarray of shape (n_sensors, n_sensors)) – uncertainty matrix associated with vector x_arr
  • problim (float) – probability limit used for consistency evaluation. Typically 0.95.
Returns:

  • isconsist (bool) – indicator whether provided estimates are consistent in view of problim
  • ybest (float) – best estimate
  • uybest (float) – standard uncertainty of best estimate
  • chi2obs (float) – observed chi-squared value

static calc_best_estimate(y_arr, vy_arr2d, problim)[source]

Calculate the best estimate for a set of estimates with uncertainties

Additionally determine if the set of estimates are consistent using a provided limit probability.

Parameters:
  • y_arr (np.ndarray of shape (n)) – vector of estimates of a measurand Y
  • vy_arr2d (np.ndarray of shape (n, n)) – uncertainty matrix associated with y_arr
  • problim (float) – probability limit used for assessing the consistency of the estimates. Typically, problim equals 0.95.
Returns:

  • isconsist (bool) – indicator whether provided estimates are consistent in view of problim
  • ybest (float) – best estimate of measurand
  • uybest (float) – uncertainty associated with ybest
  • chi2obs (float) – observed value of chi-squared, used for consistency evaluation

static calc_consistent_estimates_no_corr(y_arr2d, uy_arr2d, prob_lim)[source]

Calculation of consistent estimate for sets of estimates y_ij

The y_ij (contained in y_arr2d) are the elements of Y, where each set contains n_estims estimates. The uncertainties are assumed to be independent and given in uy_arr2d. The consistency test is using limit probability limit prob_lim. For each set of estimates, the best estimate, uncertainty, observed chi-2 value and a flag if the provided estimates were consistent given the model are given as output.

Parameters:
  • y_arr2d (np.ndarray of size (n_rows, n_estimates)) – each row contains m=n_estimates independent estimates of a measurand
  • uy_arr2d (np.ndarray of size (n_rows, n_estimates)) – each row contains the standard uncertainty u(y_ij) of y_ij = y_arr2d[i,j]
  • prob_lim (float) – limit probability used in consistency test. Typically 0.95.
Returns:

  • isconsist_arr (bool array of shape (n_rows)) – indicates for each row if the n_estimates are consistent or not
  • ybest_arr (float or np.ndarray of float in shape (n_rows)) – contains the best estimate for each row of individual estimates
  • uybest_arr (float or np.ndarray of float in shape (n_rows)) – contains the uncertainty associated with each best estimate for each row of y_arr2d
  • chi2obs_arr (np.ndarray of float in shape (n_rows)) – observed chi-squared value for each row

calc_lcs(y_arr, vy_arr2d, problim)[source]

Calculate the best estimate of a measurand with associated uncertainty matrix

Parameters:
  • y_arr (np.ndarray of shape (n)) – vector with estimates of the measurand
  • vy_arr2d (np.ndarray of shape (n, n)) – uncertainty matrix of the vector y_arr
  • problim (float) – limit probability used in the consistency evaluation. Typically 0.95.
Returns:

  • n_solutions (int or np.ndarray of ints) – number of solutions
  • ybest (float or np.ndarray of floats) – best estimate
  • uybest (float or np.ndarray of floats) – standard uncertainty of best estimate
  • chi2obs (float or np.ndarray of floats) – observed chi-squared value
  • indkeep (np.ndarray of shape (n) or (n_sols, n)) – indices of kept estimates

calc_lcss(a_arr, a_arr2d, x_arr, vx_arr2d, problim)[source]

Calculation of the largest consistent subset of sensor values

Additionally the implied best estimate is returned.

Parameters:
  • a_arr (np.ndarray of shape (n_estimates)) – vector a of linear system y = a + A * x
  • a_arr2d (np.ndarray of shape (n_estimates, n_sensors)) – matrix A of linear system y = a + A * x
  • x_arr (np.ndarray of shape (n_sensors)) – vector with sensor values vector x of linear system y = a + A * x
  • vx_arr2d (np.ndarray of shape (n_sensors, n_sensors)) – uncertainty matrix associated with vector x_arr
  • problim (float) – probability limit used for consistency evaluation. Typically 0.95
Returns:

  • n_solutions (int or np.ndarray of ints) – number of solutions
  • isconsist (bool or np.ndarray of bool) – indicator whether provided estimates are consistent in view of problim
  • ybest (float or np.ndarray of floats) – best estimate
  • uybest (float or np.ndarray of floats) – standard uncertainty of best estimate
  • chi2obs (float or np.ndarray of floats) – observed chi-squared value

static get_combination(values, n_keep, certain_combinations_index)[source]

Return a certain subset of n_keep elements in a given array

Parameters:
  • values (np.ndarray) – original values
  • n_keep (int) – number of elements in subset
  • certain_combinations_index (int) – the index of the desired combination as a result of a call of combinations(values, n_keep)
static ind_reduce_a(a_arr2d, epszero)[source]

Returns the index of a linear dependent row of a matrix A

The motivation for this is, that this row does not contribute any new information to the system.

Parameters:
  • a_arr2d (np.ndarray) – The matrix to be reduced as 2-dimensional array
  • epszero (float) – some small constant used for checking equality to zero
Returns:

the index of the last row that can be taken out

Return type:

int

init_lcss_parameters(fsam, f1, f2, ampl_ratio, phi1, phi2)[source]

Additional parameters used for this particular example

Provides the prior knowledge needed to make the information contained in the data redundant. This method sets up the vector a and matrix A for the system y = a + A * x.

Parameters:
  • fsam (float) – sampling frequency
  • f1 (float) – first frequency of interest in signal
  • f2 (float) – second frequency of interest in signal
  • ampl_ratio (float) – ratio of the amplitudes of the two frequency components
  • phi1 (float) – initial phase of first frequency component
  • phi2 (float) – initial phase of second frequency component
init_parameters(input_data_maxlen: int = 25, output_data_maxlen: int = 25, sensor_key_list: list = None, n_pr: int = 1, problim: float = 0.9, calc_type: str = 'lcs')[source]

Initialize the redundancy agent

Parameters:
  • input_data_maxlen (int, optional) – Defaults to 25
  • output_data_maxlen (int, optional) – Defaults to 25
  • sensor_key_list (list of str, optional) – list containing the names of the sensors that should feed data to the Redundancy Agent. Defaults to None
  • n_pr (int, optional) – size of the batch of data that is handled at a time by the Redundancy Agent. Defaults to 1
  • problim (float, optional) – limit probability used for consistency evaluation. Defaults to .9
  • calc_type (str, optional) – calculation type: ‘lcs’ or ‘lcss’. Defaults to ‘lcs’
on_received_message(message)[source]

Handle incoming data from ‘default’ channels

Store ‘default’ data into an internal buffer.

Parameters:message (dict) – Only acceptable channel value is ‘default’.
static print_input_lcss(x_arr, vx_arr2d, a_arr, a_arr2d, problim)[source]

Prints the input parameters of the method

Parameters:
  • x_arr (np.ndarray of shape (n_sensors)) – vector with sensor values, vector x of linear system y = a + A * x
  • vx_arr2d (np.ndarray of shape (n_sensors, n_sensors)) – uncertainty matrix associated with vector x_arr
  • a_arr (np.ndarray of shape (n_estimates)) – vector a of linear system y = a + A * x
  • a_arr2d (np.ndarray of shape (n_estimates, n_sensors)) – matrix A of linear system y = a + A * x
  • problim (float) – probability limit used for consistency evaluation. Typically 0.95
print_output_cbe(isconsist_arr, ybest_arr, uybest_arr, chi2obs_arr)[source]

Function to print the full output of calc_best_estimate.

Parameters:
  • isconsist_arr (bool array of shape (n_rows)) – indicates for each row if the n_estimates are consistent or not
  • ybest_arr (np.ndarray of floats in shape (n_rows)) – contains the best estimate for each row of individual estimates
  • uybest_arr (np.ndarray of floats in shape (n_rows)) – contains the uncertainty associated with each best estimate for each row of y_arr2d
  • chi2obs_arr (np.ndarray of floats in shape (n_rows)) – observed chi-squared value for each row
static print_output_lcs(n_solutions, ybest, uybest, chi2obs, indkeep, y_arr)[source]

Method to print the output of the method calc_lcs()

Parameters:
  • n_solutions (int) – number of best solutions
  • ybest (float or np.ndarray of shape (n_sols)) – best estimate or vector of best estimates
  • uybest (float or np.ndarray of shape (n_sols)) – standard uncertainty of best estimate or vector with standard uncertainty of best estimates
  • chi2obs (float) – observed chi-squared value of all best solutions
  • indkeep (np.ndarray of shape (n) or (n_sols, n)) – indices of retained estimates of y_arr for the calculation of the best estimate ybest
  • y_arr (np.ndarray of shape (n)) – individual estimates of measurand
static print_output_lcss(n_solutions, ybest, uybest, chi2obs, indkeep, x_arr, a_arr2d)[source]

Prints the outputs of the method calc_lcss()

Parameters:
  • n_solutions (int or np.ndarray of ints) – number of solutions
  • ybest (float or np.ndarray of floats) – best estimate
  • uybest (float or np.ndarray of floats) – standard uncertainty of best estimate
  • chi2obs (float or np.ndarray of floats) – observed chi-squared value
  • indkeep (np.ndarray of int) – indices of kept estimates
  • x_arr (np.ndarray of shape (n_estimates)) – vector a of linear system y = a + A * x
  • a_arr2d (np.ndarray of shape (n_estimates, n_sensors)) – matrix A of linear system y = a + A * x
Returns:

Return type:

None

static print_output_single(isconsist, ybest, uybest, chi2obs)[source]

Print the output of a single row of the calculate_best_estimate function

Parameters:
  • isconsist (bool) – Indicates if provided estimates were consistent
  • ybest (float) – best estimate
  • uybest (float) – uncertainty of best estimate
  • chi2obs (float) – observed value of chi-squared
static reduce_vx(x_arr, vx_arr2d, a_arr, a_arr2d, epszero)[source]

Reduce the system if matrix Vx is not of full rank

This might be ambiguous, as constant sensor values or offsets have to be estimated and are not known.

Parameters:
  • x_arr (np.ndarray) – The vector x to be reduced
  • vx_arr2d (np.ndarray) – The matrix Vx to be reduced as 2-dimensional array
  • a_arr (np.ndarray) – The vector a to be reduced
  • a_arr2d (np.ndarray) – The matrix A to be reduced as 2-dimensional array
  • epszero (float) – some small constant used for checking equality to zero
Returns:

The reduced matrices and vectors xred_arr, vxred_arr2d, ared_arr, ared_arr2d

Return type:

np.ndarray, np.ndarray, np.ndarray, np.ndarray

Metrologically enabled signal agents

class agentMET4FOF.agents.metrological_signal_agents.MetrologicalGeneratorAgent(name='', host=None, serializer=None, transport=None, attributes=None, backend='osbrain', mesa_model=None)[source]

An agent streaming a specified signal

Takes samples from an instance of MetrologicalDataStreamMET4FOF with sampling frequency sfreq and signal frequency sine_freq and pushes them sample by sample to connected agents via its output channel.

agent_loop()[source]

Model the agent’s behaviour

On state Running the agent will extract sample by sample the input datastream’s content and push it into its output buffer.

init_parameters(signal: agentMET4FOF.streams.metrological_base_streams.MetrologicalDataStreamMET4FOF = <agentMET4FOF.streams.metrological_signal_streams.MetrologicalSineGenerator object>, **kwargs)[source]

Initialize the input data stream

Parameters:signal (MetrologicalDataStreamMET4FOF) – the underlying signal for the generator (defaults to MetrologicalSineGenerator)