Exemple #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)
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()
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()
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()