def __init__(self, concept_id=0, seed=None, noise=0):
     self.cf = concept_id
     self.seed = seed
     stream = SineGenerator(classification_function=concept_id,
                            random_state=seed)
     stream.prepare_for_use()
     super().__init__(stream)
Exemplo n.º 2
0
def main():
    # start agent network server
    agentNetwork = AgentNetwork()
    # init agents
    gen_agent = agentNetwork.add_agent(agentType=DataStreamAgent)
    trainer_agent = agentNetwork.add_agent(agentType=Trainer)
    predictor_agent = agentNetwork.add_agent(agentType=Predictor)
    evaluator_agent = agentNetwork.add_agent(agentType=Evaluator)
    monitor_agent_1 = agentNetwork.add_agent(agentType=MonitorAgent)
    monitor_agent_2 = agentNetwork.add_agent(agentType=MonitorAgent)
    gen_agent.init_parameters(stream=SineGenerator(), pretrain_size=1000,
                              batch_size=1)
    trainer_agent.init_parameters(ml_model=HoeffdingTree())
    # connect agents : We can connect multiple agents to any particular agent
    # However the agent needs to implement handling multiple input types
    agentNetwork.bind_agents(gen_agent, trainer_agent)
    agentNetwork.bind_agents(gen_agent, predictor_agent)
    agentNetwork.bind_agents(trainer_agent, predictor_agent)
    agentNetwork.bind_agents(predictor_agent, evaluator_agent)
    agentNetwork.bind_agents(evaluator_agent, monitor_agent_1)
    agentNetwork.bind_agents(predictor_agent, monitor_agent_2)
    # set all agents states to "Running"
    agentNetwork.set_running_state()

    # allow for shutting down the network after execution
    return agentNetwork
Exemplo n.º 3
0
            self.send_output(res)


if __name__ == '__main__':
    # start agent network server
    agentNetwork = AgentNetwork()

    # init agents
    gen_agent = agentNetwork.add_agent(agentType=DataStreamAgent)
    trainer_agent = agentNetwork.add_agent(agentType=Trainer)
    predictor_agent = agentNetwork.add_agent(agentType=Predictor)
    evaluator_agent = agentNetwork.add_agent(agentType=Evaluator)
    monitor_agent_1 = agentNetwork.add_agent(agentType=MonitorAgent)
    monitor_agent_2 = agentNetwork.add_agent(agentType=MonitorAgent)

    gen_agent.init_parameters(stream=SineGenerator(),
                              pretrain_size=1000,
                              batch_size=1)
    trainer_agent.init_parameters(ml_model=HoeffdingTree())
    # connect agents : We can connect multiple agents to any particular agent
    # However the agent needs to implement handling multiple input types
    agentNetwork.bind_agents(gen_agent, trainer_agent)
    agentNetwork.bind_agents(gen_agent, predictor_agent)
    agentNetwork.bind_agents(trainer_agent, predictor_agent)
    agentNetwork.bind_agents(predictor_agent, evaluator_agent)

    agentNetwork.bind_agents(evaluator_agent, monitor_agent_1)
    agentNetwork.bind_agents(predictor_agent, monitor_agent_2)

    # set all agents states to "Running"
    agentNetwork.set_running_state()
Exemplo n.º 4
0
    def prepare_for_use(self):
        if self.generator in ['sea', 'sine']:
            self.concepts = [v for v in range(0, 4)]
        elif self.generator in ['stagger']:
            self.concepts = [v for v in range(0, 3)]
        elif self.generator in ['mixed']:
            self.concepts = [v for v in range(0, 2)]
        elif self.generator in ['led']:
            self.concepts = [v for v in range(0, 7)]
        elif self.generator in ['tree']:
            self.concepts = [2, 3, 4, 5, 6, 7, 8, 9, 10]

        if self.concept_shift_step > 0:
            for concept in self.all_concepts:
                stream = AGRAWALGenerator(classification_function=concept,
                                          random_state=self.random_state,
                                          balance_classes=False,
                                          perturbation=0.05)
                stream.prepare_for_use()
                self.streams.append(stream)
        else:

            for concept in self.concepts:
                if self.generator == 'agrawal':
                    stream = AGRAWALGenerator(classification_function=concept,
                                              random_state=self.random_state,
                                              balance_classes=False,
                                              perturbation=0.05)
                elif self.generator == 'sea':
                    stream = SEAGenerator(classification_function=concept,
                                          random_state=self.random_state,
                                          balance_classes=False,
                                          noise_percentage=0.05)
                elif self.generator == 'sine':
                    stream = SineGenerator(classification_function=concept,
                                           random_state=self.random_state,
                                           balance_classes=False,
                                           has_noise=False)
                elif self.generator == 'stagger':
                    stream = STAGGERGenerator(classification_function=concept,
                                              random_state=self.random_state,
                                              balance_classes=False)
                elif self.generator == 'mixed':
                    stream = MIXEDGenerator(classification_function=concept,
                                            random_state=self.random_state,
                                            balance_classes=False)
                elif self.generator == 'led':
                    stream = LEDGeneratorDrift(random_state=self.random_state,
                                               has_noise=True,
                                               n_drift_features=concept)
                elif self.generator == 'tree':
                    stream = RandomTreeGenerator(tree_random_state=concept,
                                                 sample_random_state=concept,
                                                 max_tree_depth=concept+2,
                                                 min_leaf_depth=concept,
                                                 n_classes=2)
                else:
                    print(f"unknown stream generator {self.generator}")
                    exit()

                stream.prepare_for_use()
                self.streams.append(stream)

        self.cur_stream = self.streams[0]
        self.drift_stream = self.streams[1]

        stream = self.cur_stream
        self.n_samples = stream.n_samples
        self.n_targets = stream.n_targets
        self.n_features = stream.n_features
        self.n_num_features = stream.n_num_features
        self.n_cat_features = stream.n_cat_features
        self.n_classes = stream.n_classes
        self.cat_features_idx = stream.cat_features_idx
        self.feature_names = stream.feature_names
        self.target_names = stream.target_names
        self.target_values = stream.target_values
        self.n_targets = stream.n_targets
        self.name = 'drifting' + stream.name

        print(f"len: {len(self.concepts)}")
        self.concept_probs = \
                self.__get_poisson_probs(len(self.concepts), self.lam)
Exemplo n.º 5
0
"""CD at 2000 and then every 1000"""
# MIXED
stream = ReoccuringDriftStream(stream=MIXEDGenerator(classification_function=0), drift_stream=MIXEDGenerator(classification_function=1), width=1, alpha=90, pause=1000, position=2000)

stream.name = 'MIXED Abrupt Reoccuring'
streams.append(stream)

# SEA
stream = ReoccuringDriftStream(stream=SEAGenerator(classification_function=0), drift_stream=SEAGenerator(classification_function=1), width=1, alpha=90, pause=1000, position=2000)

stream.name = 'SEA Abrupt Reoccuring'
streams.append(stream)

# SINE
stream = ReoccuringDriftStream(stream=SineGenerator(classification_function=0), drift_stream=SineGenerator(classification_function=1), width=1, alpha=90, pause=1000, position=2000)

stream.name = 'Sine Abrupt Reoccuring'
streams.append(stream)

# LED
stream = ReoccuringDriftStream(stream=LEDGeneratorDrift(noise_percentage=0.2, has_noise=True, n_drift_features=5), drift_stream=LEDGeneratorDrift(noise_percentage=0, has_noise=True, n_drift_features=10), width=1, alpha=90, pause=1000, position=2000)

stream.name = 'LED Abrupt Reoccuring'
streams.append(stream)

# TODO: lets calc conf matrix over all streams

def main():
    
    overall_kswin_tp = overall_kswin_tn = overall_kswin_fp = overall_kswin_fn = 0