Ejemplo n.º 1
0
def test_end2endtraining(config):
    """Test anomaly detection training on public dataset."""
    storage_adapter = SomStorageAdapter(config=config, feedback_strategy=None)
    model_adapter = SomModelAdapter(storage_adapter=storage_adapter)
    tc = SomTrainCommand(node_map=2, model_adapter=model_adapter)
    result, dist = tc.execute()
    assert result == 0
Ejemplo n.º 2
0
def test_model_shape(config):
    """Test that the trained model size is expected based on given parameters."""
    storage_adapter = SomStorageAdapter(config=config, feedback_strategy=None)
    model_adapter = SomModelAdapter(storage_adapter=storage_adapter)
    tc = SomTrainCommand(node_map=2, model_adapter=model_adapter)
    result, dist = tc.execute()
    assert model_adapter.model.model.shape[0:2] == (2, 2)
Ejemplo n.º 3
0
def test_output_length(config):
    """Test that correct number of outputs are generated with Hadoop_2k.json."""
    storage_adapter = SomStorageAdapter(config=config, feedback_strategy=None)
    model_adapter = SomModelAdapter(storage_adapter=storage_adapter)
    tc = SomTrainCommand(node_map=2, model_adapter=model_adapter)
    result, dist = tc.execute()
    assert len(dist) == 2000
Ejemplo n.º 4
0
def test_output_values(config):
    """Test that all distance values in training set are less than or equal to 1 on Hadoop_2k.json."""
    storage_adapter = SomStorageAdapter(config=config, feedback_strategy=None)
    model_adapter = SomModelAdapter(storage_adapter=storage_adapter)
    tc = SomTrainCommand(node_map=2, model_adapter=model_adapter)
    result, dist = tc.execute()
    assert sum(dist) <= 2000
Ejemplo n.º 5
0
def test_vocab_length(config):
    """Check length of processed vocab on on Hadoop_2k.json."""
    storage_adapter = SomStorageAdapter(config=config, feedback_strategy=None)
    model_adapter = SomModelAdapter(storage_adapter=storage_adapter)
    tc = SomTrainCommand(node_map=2, model_adapter=model_adapter)
    result, dist = tc.execute()

    assert len(model_adapter.w2v_model.model["message"].wv.vocab) == 141
Ejemplo n.º 6
0
def test_loss_value(config):
    """Check the loss value is not greater then during testing."""
    storage_adapter = SomStorageAdapter(config=config, feedback_strategy=None)
    model_adapter = SomModelAdapter(storage_adapter=storage_adapter)
    tc = SomTrainCommand(node_map=2, model_adapter=model_adapter)
    result, dist = tc.execute()
    print(model_adapter.w2v_model.model["message"].get_latest_training_loss())
    tl = model_adapter.w2v_model.model["message"].get_latest_training_loss()
    assert tl < 320000.0
Ejemplo n.º 7
0
def get_score(config, node_map, feedback):
    """Simple utility function for injecting custom mock function into Detector."""
    feedback_strategy = FeedbackStrategy(config, fn=feedback)
    storage_adapter = SomStorageAdapter(config=config,
                                        feedback_strategy=feedback_strategy)
    model_adapter = SomModelAdapter(storage_adapter=storage_adapter)
    tc = SomTrainCommand(node_map=node_map, model_adapter=model_adapter)
    success, dist = tc.execute()
    freq_one = dist[-1]
    return freq_one
Ejemplo n.º 8
0
def test_training_infer(config):
    """Test anomaly detection training on public dataset."""
    model_adapter = SomModelAdapter(
        SomStorageAdapter(config=config, feedback_strategy=None))
    tc_train = SomTrainCommand(node_map=2,
                               model_adapter=model_adapter,
                               recreate_model=True)
    result, dist = tc_train.execute()
    assert result == 0
    model_adapter = SomModelAdapter(
        SomStorageAdapter(config=config, feedback_strategy=None))
    tc_infer = SomInferCommand(model_adapter=model_adapter, sleep=False)
    result = tc_infer.execute()
    assert result == 0
    def train(self, node_map=24):
        """Run training of model and provides size of map.

        :param node_map: by default the node_map is 24 and is custom field for SOM model.
        :return: None
        """
        train = SomTrainCommand(node_map=node_map,
                                model_adapter=self.__model_adapter)
        self.tasks.add_steps(train)
        self.start_job()
 def run(self, single_run=False):
     """Abstraction around model adapter run method."""
     break_out = False
     train = SomTrainCommand(model_adapter=self.__model_adapter)
     infer = SomInferCommand(model_adapter=self.__model_adapter)
     self.mgr.add_steps(train)
     self.mgr.add_steps(infer)
     while break_out is False:
         self.mgr.execute_steps()
         print("log::facade::run")
         time.sleep(5)
         break_out = single_run
Ejemplo n.º 11
0
def test_log_similarity(config):
    """Check that two words have consistent similar logs after training."""
    storage_adapter = SomStorageAdapter(config=config, feedback_strategy=None)
    model_adapter = SomModelAdapter(storage_adapter=storage_adapter)
    tc = SomTrainCommand(node_map=2, model_adapter=model_adapter)
    result, dist = tc.execute()
    log_1 = 'INFOmainorgapachehadoopmapreducevappMRAppMasterExecutingwithtokens'
    answer_1 = 'INFOmainorgapachehadoopmapreducevappMRAppMasterCreatedMRAppMasterforapplicationappattempt'

    match_1 = [
        model_adapter.w2v_model.model["message"].wv.most_similar(log_1)[i][0]
        for i in range(3)
    ]
    assert answer_1 in match_1

    log_2 = 'ERRORRMCommunicatorAllocatororgapachehadoopmapreducevapprmRMContainerAllocatorERRORINCONTACTINGRM'
    answer_2 = 'WARNLeaseRenewermsrabimsrasaorgapachehadoophdfsLeaseRenewerFailedtorenewleaseforDFSClient' \
               'NONMAPREDUCEforsecondsWillretryshortly'
    match_2 = [
        model_adapter.w2v_model.model["message"].wv.most_similar(log_2)[i][0]
        for i in range(3)
    ]
    print(match_2[0])
    assert answer_2 in match_2
    def run(self, single_run=False):
        """Run train and inference and main event loop.

        :param single_run: if this is set to TRUE then we exit loop after first iteration.
        :return: None
        """
        exit = False

        while exit is False:
            try:
                train = SomTrainCommand(model_adapter=self.__model_adapter)
                infer = SomInferCommand(model_adapter=self.__model_adapter)
                self.tasks.add_steps(train)
                self.tasks.add_steps(infer)
                self.start_job()
                logging.info("Job ran succesfully")
            except EmptyDataSetException as e:
                logging.debug(e)
            finally:
                time.sleep(5)
                exit = single_run
 def train(self, node_map=24):
     """Abstraction around model adapter train method."""
     tc = SomTrainCommand(node_map=node_map,
                          model_adapter=self.__model_adapter)
     self.mgr.add_steps(tc)
     self.mgr.execute_steps()