Пример #1
0
def test_simpleAgent(agentType, expected_monitor_results):
    #start agent network server
    agentNetwork = AgentNetwork(dashboard_modules=False)

    #init agents by adding into the agent network
    simple_agent = agentNetwork.add_agent(agentType=agentType)
    monitor_agent_1 = agentNetwork.add_agent(agentType=MonitorAgent)

    #shorten n wait loop time
    simple_agent.init_agent_loop(0.01)

    #connect agents
    agentNetwork.bind_agents(simple_agent, monitor_agent_1)

    # set all agents states to "Running"
    agentNetwork.set_running_state()
    time.sleep(test_timeout)

    # test to see if monitor agents have received the correct data
    assert str(
        monitor_agent_1.get_attr('memory')) == str(expected_monitor_results)

    # shutdown agent network
    agentNetwork.shutdown()
    time.sleep(3)
Пример #2
0
def demonstrate_generator_agent_use() -> AgentNetwork:
    # Start agent network server.
    agent_network = AgentNetwork()

    # Initialize agents by adding them to the agent network.
    default_sine_agent = agent_network.add_agent(name="Default Sine generator",
                                                 agentType=SineGeneratorAgent)

    # Custom parameters of the specified agentType can either be handed over as **kwargs
    # in the network instance's add_agent() method, or...
    custom_sine_agent = agent_network.add_agent(
        name="Custom Sine generator",
        agentType=SineGeneratorAgent,
        sfreq=75,
        sine_freq=np.pi,
    )
    # ... in a separate call of the agent instance's init_parameters() method.
    custom_sine_agent.init_parameters(amplitude=0.75, )

    monitor_agent = agent_network.add_agent(
        name="Showcase a default and a customized sine signal",
        agentType=MonitorAgent)

    # Interconnect agents by either way:
    # 1) by agent network.bind_agents(source, target).
    agent_network.bind_agents(default_sine_agent, monitor_agent)

    # 2) by the agent.bind_output().
    custom_sine_agent.bind_output(monitor_agent)

    # Set all agents' states to "Running".
    agent_network.set_running_state()

    # Allow for shutting down the network after execution
    return agent_network
Пример #3
0
def main():
    # start agent network server
    agentNetwork = AgentNetwork()

    # init agents by adding into the agent network
    gen_agent = agentNetwork.add_agent(agentType=TimeSineGeneratorAgent)
    monitor_agent = agentNetwork.add_agent(agentType=MonitorAgent)

    # provide custom parameters to the monitor agent
    xname, yname = "Time", "Y"
    monitor_agent.init_parameters(
        custom_plot_function=custom_create_monitor_graph,
        xname=xname,
        yname=yname,
        noise_level=0.1,
    )

    # bind agents
    agentNetwork.bind_agents(gen_agent, monitor_agent)

    # set all agents states to "Running"
    agentNetwork.set_running_state()

    # allow for shutting down the network after execution
    return agentNetwork
Пример #4
0
def main():
    #start agent network server
    log_file = False
    agentNetwork = AgentNetwork(log_filename=log_file, dashboard_update_interval=1)

    #init agents by adding into the agent network
    #x_sensor_agent = agentNetwork.add_agent(name="X_acceleration",agentType= AccelerationSensorAgent).init_parameters(axis='y')
    #y_sensor_agent = agentNetwork.add_agent(name="Y_acceleration",agentType= AccelerationSensorAgent).init_parameters(axis='y')
    #z_sensor_agent = agentNetwork.add_agent(name="Z_acceleration",agentType= AccelerationSensorAgent).init_parameters(axis='z')
    sensor_buffer_size = 1
    acceleration_agent = agentNetwork.add_agent(name="XYZ_acceleration",buffer_size=1, agentType=AccelerationSensorAgent).init_parameters(axis='xyz')
    nozzle_sensor_agent = agentNetwork.add_agent(name="Nozzle_temperature",buffer_size=1, agentType= TemperatureSensorAgent).init_parameters(position='tool0')
    platform_sensor_agent = agentNetwork.add_agent(name="Platform_temperature",buffer_size=1, agentType= TemperatureSensorAgent).init_parameters(position='bed')

    sensor_agents = [acceleration_agent,nozzle_sensor_agent,platform_sensor_agent]

    #do something for all agents
    for sensor_agent in sensor_agents:
        #bind sensor agent to monitor
        monitor_agent = agentNetwork.add_agent(agentType= MonitorAgent,buffer_size=100)
        sensor_agent.bind_output(monitor_agent)

        #set loop interval for each sensor agent
        sensor_agent.init_agent_loop(loop_wait=1)

    # set all agents states to "Running"
    agentNetwork.set_running_state()

    # allow for shutting down the network after execution
    return agentNetwork
Пример #5
0
def main():
    #connect to agent network server
    log_file = False
    agentNetwork = AgentNetwork(dashboard_modules=False,
                                log_filename=log_file,
                                ip_addr=host_ip)

    #init agents by adding into the agent network
    gen_agent = agentNetwork.add_agent(agentType=OpenSenecaAgent,
                                       ip_addr=local_ip,
                                       buffer_size=1)
    gen_agent.init_parameters(port_name='/dev/ttyUSB0')
    gen_agent.init_agent_loop(loop_wait=1)

    # set all agents states to "Running"
    agentNetwork.set_running_state()

    # allow for shutting down the network after execution
    return agentNetwork
def main():
    #initialise with dashboard ml experiments
    agentNetwork = AgentNetwork(dashboard_extensions=Dashboard_ML_Experiment)

    ml_exp_name = "complex"

    kernel_iso = 1.0 * RBF([1.0])

    ML_Agent_pipelines_A = AgentPipeline(agentNetwork, [
        StandardScaler, RobustScaler, MinMaxScaler, MaxAbsScaler,
        PowerTransformer
    ], [PCA], [GaussianProcessClassifier],
                                         hyperparameters=[[], [],
                                                          [{
                                                              "kernel":
                                                              [kernel_iso]
                                                          }]])

    #init
    datastream_agent = agentNetwork.add_agent(agentType=ML_DataStreamAgent)
    evaluation_agent = agentNetwork.add_agent(agentType=ML_EvaluatorAgent)

    datastream_agent.init_parameters(data_name="iris",
                                     x=datasets.load_iris().data,
                                     y=datasets.load_iris().target)
    evaluation_agent.init_parameters([f1_score], [{
        "average": 'micro'
    }],
                                     ML_exp=True)

    #setup ml experiment
    ml_experiment = ML_Experiment(datasets=[datastream_agent],
                                  pipelines=[ML_Agent_pipelines_A],
                                  evaluation=[evaluation_agent],
                                  name=ml_exp_name,
                                  train_mode="Kfold5")
    agentNetwork.get_agent("Logger").set_ml_experiment(ml_experiment)

    #optional: connect evaluation agent to monitor agent
    monitor_agent = agentNetwork.add_agent(agentType=MonitorAgent)
    evaluation_agent.bind_output(monitor_agent)

    #set to active running
    agentNetwork.set_running_state()

    # allow for shutting down the network after execution
    return agentNetwork
Пример #7
0
def demonstrate_metrological_stream():

    # start agent network server
    agent_network = AgentNetwork(backend=Backend.MESA)

    # Initialize signal generating class outside of agent framework.
    signal = MetrologicalSineGenerator()

    # Initialize metrologically enabled agent taking name from signal source metadata.
    source_name = signal.metadata.metadata["device_id"]
    source_agent = agent_network.add_agent(
        name=source_name, agentType=MetrologicalSineGeneratorAgent)
    source_agent.init_parameters(signal)

    # Initialize metrologically enabled plotting agent.
    monitor_agent = agent_network.add_agent(
        "Metrological plot including measurement uncertainties",
        agentType=MetrologicalMonitorAgent,
        buffer_size=50,
    )

    # Bind agents.
    source_agent.bind_output(monitor_agent)

    # Set all agents states to "Running".
    agent_network.set_running_state()

    # Allow for shutting down the network after execution.
    return agent_network
Пример #8
0
def demonstrate_generator_agent_use():
    # Start agent network server.
    agent_network = AgentNetwork()

    # Initialize agents by adding them to the agent network.
    gen_agent_1 = agent_network.add_agent(agentType=SineGeneratorAgent)
    gen_agent_2 = agent_network.add_agent(agentType=SineGeneratorAgent)
    monitor_agent = agent_network.add_agent(agentType=MonitorAgent)

    # bind generator agents outputs to monitor
    agent_network.bind_agents(gen_agent_1, monitor_agent)
    agent_network.bind_agents(gen_agent_2, monitor_agent)

    # setup health coalition group
    agent_network.add_coalition("REDUNDANT_SENSORS",
                                [gen_agent_1, gen_agent_2, monitor_agent])

    # Set all agents' states to "Running".
    agent_network.set_running_state()

    # Allow for shutting down the network after execution
    return agent_network
Пример #9
0
def main():
    # start agent network server
    agentNetwork = AgentNetwork()
    # init agents
    sub_agent = agentNetwork.add_agent(agentType=SubtractAgent)
    add_agent = agentNetwork.add_agent(agentType=AdditionAgent)
    monitor_agent = agentNetwork.add_agent(agentType=MonitorAgent)
    # connect
    agentNetwork.bind_agents(sub_agent, monitor_agent)
    agentNetwork.bind_agents(add_agent, monitor_agent)
    # set all agents states to "Running"
    agentNetwork.set_running_state()

    # allow for shutting down the network after execution
    return agentNetwork
Пример #10
0
def main():
    agentNetwork = AgentNetwork(dashboard_extensions=Dashboard_ML_Experiment)

    ml_exp_name = "multiple"

    ML_Agent_pipelines_A = AgentPipeline(agentNetwork, [BNN_Model],
                                         hyperparameters=[[{
                                             "num_epochs": [500],
                                             "task": ["classification"],
                                             "architecture":
                                             [["d1", "d1"], ["d1", "d1", "d1"],
                                              ["d1", "d1", "d1", "d1"]]
                                         }]])
    ML_Agent_pipelines_B = AgentPipeline(
        agentNetwork, [StandardScaler], [BNN_Model],
        hyperparameters=[[],
                         [{
                             "num_epochs": [500],
                             "task": ["classification"],
                             "architecture": [["d1", "d1"], ["d1", "d1", "d1"],
                                              ["d1", "d1", "d1", "d1"]]
                         }]])

    #init
    datastream_agent = agentNetwork.add_agent(agentType=ML_DataStreamAgent)
    evaluation_agent = agentNetwork.add_agent(agentType=ML_EvaluatorAgent)

    datastream_agent.init_parameters(data_name="iris",
                                     x=datasets.load_iris().data,
                                     y=datasets.load_iris().target)
    evaluation_agent.init_parameters([f1_score, p_acc_unc, avg_unc],
                                     [{
                                         "average": 'micro'
                                     }, {}, {}],
                                     ML_exp=True)

    #setup ml experiment
    ml_experiment = ML_Experiment(
        datasets=[datastream_agent],
        pipelines=[ML_Agent_pipelines_A, ML_Agent_pipelines_B],
        evaluation=[evaluation_agent],
        name=ml_exp_name,
        train_mode="Kfold5")

    #optional: connect evaluation agent to monitor agent
    monitor_agent = agentNetwork.add_agent(agentType=MonitorAgent)
    evaluation_agent.bind_output(monitor_agent)

    #set to active running
    agentNetwork.set_running_state()

    # allow for shutting down the network after execution
    return agentNetwork
Пример #11
0
def test_send_plot():
    # start agent network server
    agentNetwork = AgentNetwork(dashboard_modules=False)

    # init agents
    gen_agent = agentNetwork.add_agent(agentType=GeneratorAgent)
    monitor_agent = agentNetwork.add_agent(agentType=MonitorAgent)

    agentNetwork.bind_agents(gen_agent, monitor_agent, channel="plot")

    gen_agent.dummy_send_graph(mode="plotly")
    time.sleep(3)

    assert monitor_agent.get_attr("plots")["GeneratorAgent_1"]

    agentNetwork.shutdown()
Пример #12
0
def test_send_plot():
    # start agent network server
    agentNetwork = AgentNetwork(dashboard_modules=False)

    # init agents
    gen_agent = agentNetwork.add_agent(agentType=GeneratorAgent)
    monitor_agent = agentNetwork.add_agent(agentType=MonitorAgent)

    agentNetwork.bind_agents(gen_agent, monitor_agent)

    gen_agent.dummy_send_graph()
    time.sleep(3)

    assert monitor_agent.get_attr('plots')['GeneratorAgent_1']

    agentNetwork.shutdown()
Пример #13
0
def demonstrate_metrological_stream():
    """Demonstrate an agent network with two metrologically enabled agents

    The agents are defined as objects of the :class:`MetrologicalGeneratorAgent`
    class whose outputs are bound to a single monitor agent.

    The metrological agents generate signals from a sine wave and a multiwave generator
    source.

    Returns
    -------
    :class:`AgentNetwork`
        The initialized and running agent network object
    """
    # start agent network server
    agent_network = AgentNetwork(dashboard_modules=True)

    # Initialize metrologically enabled agent with a multiwave (sum of cosines)
    # generator as signal source taking name from signal source metadata.
    signal_multiwave = MetrologicalMultiWaveGenerator(quantity_names="Voltage",
                                                      quantity_units="V")
    source_name_multiwave = signal_multiwave.metadata.metadata["device_id"]
    source_agent_multiwave = agent_network.add_agent(
        name=source_name_multiwave, agentType=MetrologicalGeneratorAgent)
    source_agent_multiwave.init_parameters(signal=signal_multiwave)

    # Initialize second metrologically enabled agent with a sine generator as signal
    # source taking name from signal source metadata.
    signal_sine = MetrologicalSineGenerator()
    source_name_sine = signal_sine.metadata.metadata["device_id"]
    source_agent_sine = agent_network.add_agent(
        name=source_name_sine, agentType=MetrologicalGeneratorAgent)
    source_agent_sine.init_parameters(signal=signal_sine)

    # Initialize metrologically enabled plotting agent.
    monitor_agent = agent_network.add_agent(
        "MonitorAgent",
        agentType=MetrologicalMonitorAgent,
        buffer_size=50,
    )

    # Bind agents.
    source_agent_multiwave.bind_output(monitor_agent)
    source_agent_sine.bind_output(monitor_agent)

    # Set all agents states to "Running".
    agent_network.set_running_state()

    # Allow for shutting down the network after execution.
    return agent_network
Пример #14
0
def demonstrate_generator_agent_use():
    # Start agent network server.
    agent_network = AgentNetwork()

    # Initialize agents by adding them to the agent network.
    # The buffer size is set during initialisation
    gen_agent = agent_network.add_agent(
        agentType=BufferSineGeneratorAgent, buffer_size=5
    )
    monitor_agent = agent_network.add_agent(agentType=MonitorAgent)

    # bind agents
    agent_network.bind_agents(gen_agent, monitor_agent)

    # Set all agents' states to "Running".
    agent_network.set_running_state()

    # Allow for shutting down the network after execution
    return agent_network
Пример #15
0
def main():
    #start agent network server
    log_file = False
    agentNetwork = AgentNetwork(log_filename=log_file, dashboard_update_interval=1)

    #init agents by adding into the agent network
    sensor_agent = agentNetwork.add_agent(agentType = OpenSenecaAgent, buffer_size=1)
    monitor_agent = agentNetwork.add_agent(agentType = MonitorAgent, buffer_size=100)

    sensor_agent.init_parameters(port_name='/dev/ttyUSB0')
    sensor_agent.init_agent_loop(loop_wait=1)

    #connect the sensor agent to the monitor agent
    agentNetwork.bind_agents(sensor_agent, monitor_agent)

    # set all agents states to "Running"
    agentNetwork.set_running_state()

    # allow for shutting down the network after execution
    return agentNetwork
def main():
    #start agent network server
    agentNetwork = AgentNetwork()

    #init agents by adding into the agent network
    gen_agent = agentNetwork.add_agent(agentType=SineGeneratorAgent)
    monitor_agent = agentNetwork.add_agent(agentType=MonitorAgent)

    #connect agents by either way:
    # 1) by agent network.bind_agents(source,target)
    agentNetwork.bind_agents(gen_agent, monitor_agent)

    # 2) by the agent.bind_output()
    gen_agent.bind_output(monitor_agent)

    # set all agents states to "Running"
    agentNetwork.set_running_state()

    # allow for shutting down the network after execution
    return agentNetwork
Пример #17
0
def demonstrate_generator_agent_use():
    # Start agent network server.
    agent_network = AgentNetwork()

    # Initialize agents by adding them to the agent network.
    gen_agent = agent_network.add_agent(agentType=MultiGeneratorAgent)
    monitor_agent = agent_network.add_agent(agentType=MonitorAgent)

    # Interconnect agents by either way:
    # 1) by agent network.bind_agents(source, target).
    agent_network.bind_agents(gen_agent, monitor_agent)

    # 2) by the agent.bind_output().
    gen_agent.bind_output(monitor_agent)

    # Set all agents' states to "Running".
    agent_network.set_running_state()

    # Allow for shutting down the network after execution
    return agent_network
Пример #18
0
def main():
    #start agent network server
    agentNetwork = AgentNetwork(dashboard_modules=[],
                                dashboard_update_interval=0.75,
                                log_filename='log_name.csv',
                                backend="mesa")

    #init agents by adding into the agent network
    gen_agent = agentNetwork.add_agent(agentType=SineGeneratorAgent,
                                       buffer_size=1,
                                       log_mode=False)
    monitor_agent = agentNetwork.add_agent(agentType=MonitorAgent,
                                           buffer_size=50,
                                           log_mode=False)
    monitor_agent_2 = agentNetwork.add_agent(agentType=MonitorAgent,
                                             buffer_size=10,
                                             log_mode=False)

    gen_agent.init_agent_loop(loop_wait=1)

    #This monitor agent will only store 'quantities' of the data keys into its memory
    monitor_agent.init_parameters(plot_filter=['quantities'])

    #connect agents by either way:
    # 1) by agent network.bind_agents(source,target)
    agentNetwork.bind_agents(gen_agent, monitor_agent)

    # 2) by the agent.bind_output()
    gen_agent.bind_output(monitor_agent)
    gen_agent.bind_output(monitor_agent_2)

    # set all agents states to "Running"
    agentNetwork.set_running_state()

    # allow for shutting down the network after execution
    return agentNetwork
Пример #19
0
def demonstrate_mesa_backend():

    # Start agent network and specify backend via the corresponding keyword parameter.
    _agent_network = AgentNetwork(backend=Backend.MESA)

    # Initialize agents by adding them to the agent network.
    sine_agent = _agent_network.add_agent(agentType=SineGeneratorAgent)
    monitor_agent = _agent_network.add_agent(agentType=MonitorAgent,
                                             buffer_size=200)
    sine_agent.bind_output(monitor_agent)

    # Set all agents states to "Running".
    _agent_network.set_running_state()

    return _agent_network
Пример #20
0
def demonstrate_generator_agent_use():
    # Start agent network server.
    agent_network = AgentNetwork()

    # Initialize agents by adding them to the agent network.
    gen_agent: AgentMET4FOF = agent_network.add_agent(
        agentType=GaussianShockGeneratorAgent
    )
    # Here we apply the default settings we chose above.
    gen_agent.init_parameters()
    monitor_agent = agent_network.add_agent(agentType=MonitorAgent)

    # Interconnect agents by either way:
    # 1) by agent network.bind_agents(source, target).
    agent_network.bind_agents(gen_agent, monitor_agent)

    # 2) by the agent.bind_output().
    gen_agent.bind_output(monitor_agent)

    # Set all agents' states to "Running".
    agent_network.set_running_state()

    # Allow for shutting down the network after execution
    return agent_network
Пример #21
0
def main():
    #start agent network server
    agentNetwork = AgentNetwork()

    #init agents by adding into the agent network
    monitor_agent = agentNetwork.add_agent(agentType=MonitorAgent)
    iiR_agent = agentNetwork.add_agent(agentType=iiRAgent)
    agentNetwork.bind_agents(iiR_agent, monitor_agent)
    iiR_agent.bind_output(monitor_agent)

    # there will be len(genTypes) generator agents with the specified type in genTypes
    # the first geerator agent (i.e., genAgents[0]) with signal type genTypes[0] will be connected to the filter

    genTypes = [SineGeneratorAgent, RectGeneratorAgent, ShockGeneratorAgent]
    genAgents = []
    for i in range(len(genTypes)):
        genAgents.append(agentNetwork.add_agent(agentType=genTypes[i]))
        agentNetwork.bind_agents(genAgents[i], monitor_agent)
        genAgents[i].bind_output(monitor_agent)

    agentNetwork.bind_agents(genAgents[0], iiR_agent)
    genAgents[0].bind_output(iiR_agent)

    # set all agents states to "Running"
    agentNetwork.set_running_state()

    # allow for shutting down the network after execution
    return agentNetwork
Пример #22
0
def main():
    global agentNetwork
    # start agent network
    agentNetwork = AgentNetwork()
    # add agents
    data_stream_agent_1 = agentNetwork.add_agent(agentType=DataStreamAgent)
    ml_agent_hoeffdingTree = agentNetwork.add_agent(agentType=ML_Model)
    ml_agent_neuralNets = agentNetwork.add_agent(agentType=ML_Model)
    monitor_agent_1 = agentNetwork.add_agent(agentType=MonitorAgent)
    # init parameters
    data_stream_agent_1.init_parameters(stream=WaveformGenerator(),
                                        pretrain_size=1000,
                                        batch_size=100)
    ml_agent_hoeffdingTree.init_parameters(ml_model=HoeffdingTreeClassifier())
    ml_agent_neuralNets.init_parameters(ml_model=NaiveBayes())
    # connect agents
    agentNetwork.bind_agents(data_stream_agent_1, ml_agent_hoeffdingTree)
    agentNetwork.bind_agents(data_stream_agent_1, ml_agent_neuralNets)
    agentNetwork.bind_agents(ml_agent_hoeffdingTree, monitor_agent_1)
    agentNetwork.bind_agents(ml_agent_neuralNets, monitor_agent_1)
    agentNetwork.set_running_state()

    # allow for shutting down the network after execution
    return agentNetwork
Пример #23
0
def main():
    # start agent network server
    agentNetwork = AgentNetwork(
        dashboard_modules=[zema_datastream,
                           zema_agents], log_filename=False, backend="mesa")
    # init agents by adding into the agent network
    datastream_agent = agentNetwork.add_agent(agentType=DataStreamAgent)
    train_test_split_agent = agentNetwork.add_agent(
        agentType=TrainTestSplitAgent)
    fft_bfc_agent = agentNetwork.add_agent(agentType=FFT_BFCAgent)
    pearson_fs_agent = agentNetwork.add_agent(
        agentType=Pearson_FeatureSelectionAgent)
    lda_agent = agentNetwork.add_agent(agentType=LDA_Agent)
    bayesianRidge_agent = agentNetwork.add_agent(agentType=Regression_Agent,
                                                 name="BayesianRidge_Agent")
    randomForest_agent = agentNetwork.add_agent(agentType=Regression_Agent,
                                                name="RandomForest_Agent")
    evaluator_agent = agentNetwork.add_agent(agentType=EvaluatorAgent)
    monitor_agent = agentNetwork.add_agent(agentType=MonitorAgent)
    # init parameters
    # incremental training
    datastream_agent.init_parameters(stream=ZEMA_DataStream(),
                                     pretrain_size=1000, batch_size=250,
                                     loop_wait=10, randomize=True)
    # batch training
    # datastream_agent.init_parameters(stream=ZEMA_DataStream(),
    # pretrain_size=-1, randomize=True)
    # hold-out or prequential mode
    # train_test_split_agent.init_parameters(train_ratio=0.8) #hold-out
    train_test_split_agent.init_parameters(train_ratio=-1)  # prequential
    # init parameters for base models
    lda_agent.init_parameters()
    bayesianRidge_agent.init_parameters(regression_model="BayesianRidge")
    randomForest_agent.init_parameters(regression_model="RandomForest")
    # bind agents
    agentNetwork.bind_agents(datastream_agent, train_test_split_agent)
    agentNetwork.bind_agents(train_test_split_agent, fft_bfc_agent)
    agentNetwork.bind_agents(fft_bfc_agent, pearson_fs_agent)
    agentNetwork.bind_agents(pearson_fs_agent, lda_agent)
    agentNetwork.bind_agents(lda_agent, evaluator_agent)
    agentNetwork.bind_agents(pearson_fs_agent, bayesianRidge_agent)
    agentNetwork.bind_agents(bayesianRidge_agent, evaluator_agent)
    agentNetwork.bind_agents(pearson_fs_agent, randomForest_agent)
    agentNetwork.bind_agents(randomForest_agent, evaluator_agent)
    # bind to monitor agents
    agentNetwork.bind_agents(fft_bfc_agent, monitor_agent)
    agentNetwork.bind_agents(pearson_fs_agent, monitor_agent)
    agentNetwork.bind_agents(evaluator_agent, monitor_agent)
    # set running state
    agentNetwork.set_running_state()

    # allow for shutting down the network after execution
    return agentNetwork
def demonstrate_redundancy_agent_onesignal():
    """
    At the start of the main module all important parameters are defined. Then the agents are defined and the network
    is started. The network and the calculated results can be monitored in a browser at the address http://127.0.0.1:8050/.
    """
    # parameters
    batch_size = 20
    n_pr = 20
    fsam = 40
    f1 = 6
    f2 = 10
    phi1 = 1
    phi2 = 2
    ampl1 = 230
    ampl2 = 20
    exp_unc_abs = 0.2  # absolute expanded uncertainty
    problim = 0.95

    # start agent network server
    agent_network = AgentNetwork(dashboard_modules=True)

    # Initialize signal generating class outside of agent framework.
    signal1 = MetrologicalMultiWaveGenerator(sfreq=fsam,
                                             freq_arr=np.array([f1, f2]),
                                             ampl_arr=np.array([ampl1, ampl2]),
                                             phase_ini_arr=np.array(
                                                 [phi1, phi2]),
                                             value_unc=exp_unc_abs)
    # signal1.init_parameters(batch_size1=batch_size)

    # Data source agents.
    source_name1 = "Sensor1"  #signal1.metadata.metadata["device_id"]
    source_agent1 = agent_network.add_agent(
        name=source_name1, agentType=MetrologicalMultiWaveGeneratorAgent)
    source_agent1.init_parameters(signal=signal1, batch_size=batch_size)

    # Redundant data processing agent
    sensor_key_list = [source_name1]
    redundancy_name1 = "RedundancyAgent1"  # Name cannot contain spaces!!
    redundancy_agent1 = agent_network.add_agent(name=redundancy_name1,
                                                agentType=RedundancyAgent)
    redundancy_agent1.init_parameters1(sensor_key_list=sensor_key_list,
                                       calc_type="lcss",
                                       n_pr=n_pr,
                                       problim=problim)
    # prior knowledge needed for redundant evaluation of the data
    redundancy_agent1.init_parameters2(fsam=fsam,
                                       f1=f1,
                                       f2=f2,
                                       ampl_ratio=ampl1 / ampl2,
                                       phi1=phi1,
                                       phi2=phi2)

    # Initialize metrologically enabled plotting agent. Agent name cannot contain spaces!!
    monitor_agent1 = agent_network.add_agent(
        name="MonitorAgent_SensorValues", agentType=MetrologicalMonitorAgent)
    monitor_agent2 = agent_network.add_agent(
        name="MonitorAgent_RedundantEstimate",
        agentType=MetrologicalMonitorAgent)

    # Bind agents.
    source_agent1.bind_output(monitor_agent1)
    source_agent1.bind_output(redundancy_agent1)
    redundancy_agent1.bind_output(monitor_agent2)

    # Set all agents states to "Running".
    agent_network.set_running_state()

    # Allow for shutting down the network after execution.
    return agent_network
def test_zema_emc_lda_agents():
    np.random.seed(100)
    #start agent network server
    agentNetwork = AgentNetwork(dashboard_modules=False)

    #init agents by adding into the agent network
    datastream_agent = agentNetwork.add_agent(agentType=DataStreamAgent)
    train_test_split_agent = agentNetwork.add_agent(
        agentType=TrainTestSplitAgent)
    fft_bfc_agent = agentNetwork.add_agent(agentType=FFT_BFCAgent)
    pearson_fs_agent = agentNetwork.add_agent(
        agentType=Pearson_FeatureSelectionAgent)
    lda_agent = agentNetwork.add_agent(agentType=LDA_Agent)
    evaluator_agent = agentNetwork.add_agent(agentType=EvaluatorAgent)
    monitor_agent = agentNetwork.add_agent(agentType=MonitorAgent)

    #init parameters
    datastream_agent.init_parameters(ZEMA_DataStream())
    train_test_split_agent.init_parameters(train_ratio=0.8)

    #bind agents
    agentNetwork.bind_agents(datastream_agent, train_test_split_agent)
    agentNetwork.bind_agents(train_test_split_agent, fft_bfc_agent)
    agentNetwork.bind_agents(fft_bfc_agent, pearson_fs_agent)
    agentNetwork.bind_agents(pearson_fs_agent, lda_agent)
    agentNetwork.bind_agents(lda_agent, evaluator_agent)

    #bind to monitor agents
    agentNetwork.bind_agents(fft_bfc_agent, monitor_agent)
    agentNetwork.bind_agents(pearson_fs_agent, monitor_agent)
    agentNetwork.bind_agents(lda_agent, monitor_agent)
    agentNetwork.bind_agents(evaluator_agent, monitor_agent)

    #trigger datastream to send all at once
    datastream_agent.send_all_sample()

    time.sleep(timeout_wait)

    assert lda_agent.get_attr('lda_test_score') == 0.8204924543288324

    agentNetwork.shutdown()
def demonstrate_redundancy_agent_four_signals():
    """
    At the start of the main module all important parameters are defined. Then the agents are defined and the network
    is started. The network and the calculated results can be monitored in a browser at the address http://127.0.0.1:8050/.
    """
    # parameters
    batch_size = 20
    n_pr = batch_size
    fsam = 100
    intercept = 10
    freqs = [6, 10, 8, 12]
    phases = [1, 2, 3, 4]
    ampls = [0.3, 0.2, 0.5, 0.4]
    exp_unc_abs = 0.2
    problim = 0.95

    # start agent network server
    agent_network: AgentNetwork = AgentNetwork(dashboard_modules=True)

    # Initialize signal generating class outside of agent framework.
    signal_arr = [
        MetrologicalMultiWaveGenerator(sfreq=fsam,
                                       freq_arr=np.array([freq]),
                                       intercept=intercept,
                                       ampl_arr=np.array([ampl]),
                                       phase_ini_arr=np.array([phi]),
                                       value_unc=exp_unc_abs)
        for freq, phi, ampl in zip(freqs, phases, ampls)
    ]

    # Data source agents.
    source_agents = []
    sensor_key_list = []
    for count, signal in enumerate(signal_arr):
        sensor_key_list += ["Sensor" + str(count + 1)]
        source_agents += [
            agent_network.add_agent(
                name=sensor_key_list[-1],
                agentType=MetrologicalMultiWaveGeneratorAgent)
        ]
        source_agents[-1].init_parameters(signal=signal, batch_size=batch_size)

    # Redundant data processing agent
    redundancy_name1 = "RedundancyAgent1"
    redundancy_agent1 = agent_network.add_agent(name=redundancy_name1,
                                                agentType=RedundancyAgent)
    redundancy_agent1.init_parameters1(sensor_key_list=sensor_key_list,
                                       n_pr=n_pr,
                                       problim=problim,
                                       calc_type="lcs")

    # Initialize metrologically enabled plotting agent.
    monitor_agent1 = agent_network.add_agent(
        name="MonitorAgent_SensorValues", agentType=MetrologicalMonitorAgent)
    monitor_agent2 = agent_network.add_agent(
        name="MonitorAgent_RedundantEstimate",
        agentType=MetrologicalMonitorAgent)

    # Bind agents.
    for source_agent in source_agents:
        source_agent.bind_output(monitor_agent1)
        source_agent.bind_output(redundancy_agent1)

    redundancy_agent1.bind_output(monitor_agent2)

    # Set all agents states to "Running".
    agent_network.set_running_state()

    # Allow for shutting down the network after execution.
    return agent_network
Пример #27
0
def main():
    # start agent network server
    agentNetwork = AgentNetwork()
    # init agents
    gen_agent = agentNetwork.add_agent(agentType=SineGeneratorAgent)
    math_agent = agentNetwork.add_agent(agentType=MathAgent)
    multi_math_agent = agentNetwork.add_agent(agentType=MultiMathAgent)
    monitor_agent = agentNetwork.add_agent(agentType=MonitorAgent)
    # connect agents : We can connect multiple agents to any particular agent
    agentNetwork.bind_agents(gen_agent, math_agent)
    agentNetwork.bind_agents(gen_agent, multi_math_agent)
    # connect
    agentNetwork.bind_agents(gen_agent, monitor_agent)
    agentNetwork.bind_agents(math_agent, monitor_agent)
    agentNetwork.bind_agents(multi_math_agent, monitor_agent)
    # set all agents states to "Running"
    agentNetwork.set_running_state()

    # allow for shutting down the network after execution
    return agentNetwork
Пример #28
0
def main():
    """
    At the start of the main module all important parameters are defined. Then the agents are defined and the network
    is started. The network and the calculated results can be monitored in a browser at the address http://127.0.0.1:8050/.
    """
    # parameters
    batch_size = 10
    n_pr = batch_size
    fsam = 100
    intercept = 10
    f1 = 6
    f2 = 10
    f3 = 8
    f4 = 12
    phi1 = 1
    phi2 = 2
    phi3 = 3
    phi4 = 4
    ampl1 = 0.3
    ampl2 = 0.2
    ampl3 = 0.5
    ampl4 = 0.4
    expunc_abs = 0.2
    problim = 0.95

    # start agent network server
    agent_network = AgentNetwork(dashboard_modules=True)

    # Initialize signal generating class outside of agent framework.
    signal1 = MetrologicalMultiWaveGenerator(sfreq=fsam, intercept=intercept, freq_arr=np.array([f1]),
                                             ampl_arr=np.array([ampl1]), phase_ini_arr=np.array([phi1]),
                                             expunc_abs=expunc_abs)
    signal1.init_parameters(batch_size1=batch_size)

    signal2 = MetrologicalMultiWaveGenerator(sfreq=fsam, intercept=intercept, freq_arr=np.array([f2]),
                                             ampl_arr=np.array([ampl2]), phase_ini_arr=np.array([phi2]),
                                             expunc_abs=expunc_abs)
    signal2.init_parameters(batch_size1=batch_size)

    signal3 = MetrologicalMultiWaveGenerator(sfreq=fsam, intercept=intercept, freq_arr=np.array([f3]),
                                             ampl_arr=np.array([ampl3]), phase_ini_arr=np.array([phi3]),
                                             expunc_abs=expunc_abs)
    signal3.init_parameters(batch_size1=batch_size)

    signal4 = MetrologicalMultiWaveGenerator(sfreq=fsam, intercept=intercept, freq_arr=np.array([f4]),
                                             ampl_arr=np.array([ampl4]), phase_ini_arr=np.array([phi4]),
                                             expunc_abs=expunc_abs)
    signal4.init_parameters(batch_size1=batch_size)

    # Data source agents.
    source_name1 = "Sensor1"
    source_agent1 = agent_network.add_agent(name=source_name1, agentType=MetrologicalMultiWaveGeneratorAgent)
    source_agent1.init_parameters(signal=signal1)

    source_name2 = "Sensor2"
    source_agent2 = agent_network.add_agent(name=source_name2, agentType=MetrologicalMultiWaveGeneratorAgent)
    source_agent2.init_parameters(signal=signal2)

    source_name3 = "Sensor3"
    source_agent3 = agent_network.add_agent(name=source_name3, agentType=MetrologicalMultiWaveGeneratorAgent)
    source_agent3.init_parameters(signal=signal3)

    source_name4 = "Sensor4"
    source_agent4 = agent_network.add_agent(name=source_name4, agentType=MetrologicalMultiWaveGeneratorAgent)
    source_agent4.init_parameters(signal=signal4)

    # Redundant data processing agent
    sensor_key_list = [source_name1, source_name2, source_name3, source_name4]
    redundancy_name1 = "RedundancyAgent1"  # Name cannot contain spaces!!
    redundancy_agent1 = agent_network.add_agent(name=redundancy_name1, agentType=RedundancyAgent)
    redundancy_agent1.init_parameters1(sensor_key_list=sensor_key_list, calc_type="lcs", n_pr=n_pr, problim=problim)

    # Initialize metrologically enabled plotting agent.
    monitor_agent1 = agent_network.add_agent(name="MonitorAgent_SensorValues", agentType=MetrologicalMonitorAgent) # Name cannot contain spaces!!
    monitor_agent2 = agent_network.add_agent(name="MonitorAgent_RedundantEstimate", agentType=MetrologicalMonitorAgent)

    # Bind agents.
    source_agent1.bind_output(monitor_agent1)
    source_agent2.bind_output(monitor_agent1)
    source_agent3.bind_output(monitor_agent1)
    source_agent4.bind_output(monitor_agent1)
    source_agent1.bind_output(redundancy_agent1)
    source_agent2.bind_output(redundancy_agent1)
    source_agent3.bind_output(redundancy_agent1)
    source_agent4.bind_output(redundancy_agent1)
    redundancy_agent1.bind_output(monitor_agent2)

    # Set all agents states to "Running".
    agent_network.set_running_state()

    # Allow for shutting down the network after execution.
    return agent_network
Пример #29
0
def test_remove_agent():
    #start agent network server
    agentNetwork = AgentNetwork(dashboard_modules=False)

    #init agents by adding into the agent network
    dummy_agent1 = agentNetwork.add_agent(agentType= AgentMET4FOF)
    dummy_agent2 = agentNetwork.add_agent(agentType= AgentMET4FOF)
    dummy_agent3 = agentNetwork.add_agent(agentType= AgentMET4FOF)
    dummy_agent4 = agentNetwork.add_agent(agentType= AgentMET4FOF)

    agentNetwork.bind_agents(dummy_agent1, dummy_agent2)
    agentNetwork.bind_agents(dummy_agent1, dummy_agent3)
    agentNetwork.bind_agents(dummy_agent1, dummy_agent4)

    agentNetwork.bind_agents(dummy_agent4, dummy_agent2)
    agentNetwork.bind_agents(dummy_agent3, dummy_agent4)
    agentNetwork.bind_agents(dummy_agent2, dummy_agent4)

    agentNetwork.remove_agent(dummy_agent1)
    agentNetwork.remove_agent(dummy_agent2)
    agentNetwork.remove_agent(dummy_agent3)
    agentNetwork.remove_agent(dummy_agent4)
    time.sleep(2)
    assert len(agentNetwork.agents()) == 0
    agentNetwork.shutdown()
Пример #30
0
def main():
    # start agent network server
    agentNetwork = AgentNetwork()

    # init agents
    gen_agent = agentNetwork.add_agent(agentType=RandomGeneratorAgent)
    plotting_image_agent = agentNetwork.add_agent(agentType=PlottingAgent,
                                                  name="Plot_image")
    plotting_plotly_agent = agentNetwork.add_agent(agentType=PlottingAgent,
                                                   name="Plot_plotly")
    plotting_mpld3_agent = agentNetwork.add_agent(agentType=PlottingAgent,
                                                  name="Plot_mpld3")
    monitor_agent = agentNetwork.add_agent(agentType=MonitorAgent)

    # init parameters
    plotting_image_agent.init_parameters(plot_mode="image")
    plotting_plotly_agent.init_parameters(plot_mode="plotly")
    plotting_mpld3_agent.init_parameters(plot_mode="mpld3")

    # bind agents
    agentNetwork.bind_agents(gen_agent, plotting_image_agent)
    agentNetwork.bind_agents(gen_agent, plotting_plotly_agent)
    agentNetwork.bind_agents(gen_agent, plotting_mpld3_agent)
    agentNetwork.bind_agents(plotting_image_agent, monitor_agent)
    agentNetwork.bind_agents(plotting_plotly_agent, monitor_agent)
    agentNetwork.bind_agents(plotting_mpld3_agent, monitor_agent)

    # set all agents states to "Running"
    agentNetwork.set_running_state()

    # allow for shutting down the network after execution
    return agentNetwork