예제 #1
0
 def load_partial_annotations(self, filename, annotations_id):
     if filename is None:
         return
     filename = path.join(self.dataset_conf.input_dir(self.secuml_conf),
                          'annotations', filename)
     if not path.isfile(filename):
         raise SecuMLexpException('The annotations file %s does not exist.'
                                  % filename)
     conn = self.session.connection().connection
     cursor = conn.cursor()
     call_specific_db_func(self.secuml_conf.db_type,
                           'load_partial_annotations',
                           (cursor, filename, annotations_id,
                            self.dataset_conf.dataset_id))
     self.session.flush()
예제 #2
0
파일: diadem.py 프로젝트: x0rzkov/SecuML
def getAlerts(exp_id, analysis_type):
    exp = update_curr_exp(exp_id)
    # With proba ? With scores ?
    query = session.query(DiademExpAlchemy)
    query = query.filter(DiademExpAlchemy.exp_id == exp_id)
    diadem_exp = query.one()
    with_proba, with_scores = diadem_exp.proba, diadem_exp.with_scoring
    # Get alerts
    query = session.query(PredictionsAlchemy)
    query = query.filter(PredictionsAlchemy.exp_id == exp_id)
    if with_proba:
        threshold = exp.exp_conf.core_conf.detection_threshold
        query = query.filter(PredictionsAlchemy.proba >= threshold)
    else:
        query = query.filter(
            PredictionsAlchemy.value == label_str_to_bool(MALICIOUS))
    if analysis_type == 'topN' and (with_proba or with_scores):
        if with_proba:
            query = query.order_by(PredictionsAlchemy.proba.desc())
        else:
            query = query.order_by(PredictionsAlchemy.score.desc())
    elif analysis_type == 'random':
        query = call_specific_db_func(secuml_conf.db_type, 'random_order',
                                      (query, ))
    query = query.limit(NUM_MAX_DISPLAY)
    return jsonify(_predictions_results(query))
예제 #3
0
 def load(self):
     filepath, _ = self.get_filepath_hash()
     has_ground_truth = call_specific_db_func(self.secuml_conf.db_type,
                                              'load_idents',
                                              (self.cursor, filepath,
                                               self.dataset_conf.dataset_id)
                                              )
     self.secuml_conf.logger.info('Idents file for the dataset %s/%s '
                                  'loaded into the database (%s).'
                                  % (self.dataset_conf.project,
                                     self.dataset_conf.dataset,
                                     filepath))
     return has_ground_truth
예제 #4
0
파일: diadem.py 프로젝트: x0rzkov/SecuML
def getPredictionsScores(exp_id, range_, label):
    score_min, score_max = [float(x) for x in range_.split(' - ')]
    query = session.query(PredictionsAlchemy)
    query = query.filter(PredictionsAlchemy.exp_id == exp_id)
    query = query.filter(PredictionsAlchemy.score >= score_min)
    query = query.filter(PredictionsAlchemy.score <= score_max)
    query = query.order_by(PredictionsAlchemy.score.asc())
    if label != 'all':
        query = query.join(PredictionsAlchemy.instance)
        query = query.filter(
            InstancesAlchemy.label == label_str_to_bool(label))
    query = call_specific_db_func(secuml_conf.db_type, 'random_order',
                                  (query, ))
    query = query.limit(NUM_MAX_DISPLAY)
    return jsonify(_predictions_results(query))
예제 #5
0
파일: diadem.py 프로젝트: x0rzkov/SecuML
 def _get_errors(exp_id, fn_fp):
     if fn_fp == 'FN':
         predicted_value = BENIGN
         ground_truth = label_str_to_bool(MALICIOUS)
     else:
         predicted_value = MALICIOUS
         ground_truth = label_str_to_bool(BENIGN)
     query = session.query(PredictionsAlchemy)
     query = query.filter(PredictionsAlchemy.exp_id == exp_id)
     query = query.filter(PredictionsAlchemy.value == predicted_value)
     query = query.join(PredictionsAlchemy.instance)
     query = query.filter(InstancesAlchemy.label == ground_truth)
     query = call_specific_db_func(secuml_conf.db_type, 'random_order',
                                   (query, ))
     query = query.limit(NUM_MAX_DISPLAY)
     return _predictions_results(query)
예제 #6
0
파일: diadem.py 프로젝트: x0rzkov/SecuML
def getPredictionsProbas(exp_id, index, label):
    index = int(index)
    proba_min = index * 0.1
    proba_max = (index + 1) * 0.1
    query = session.query(PredictionsAlchemy)
    query = query.filter(PredictionsAlchemy.exp_id == exp_id)
    query = query.filter(PredictionsAlchemy.proba >= proba_min)
    query = query.filter(PredictionsAlchemy.proba <= proba_max)
    query = query.order_by(PredictionsAlchemy.proba.asc())
    if label != 'all':
        query = query.join(PredictionsAlchemy.instance)
        query = query.filter(
            InstancesAlchemy.label == label_str_to_bool(label))
    query = call_specific_db_func(secuml_conf.db_type, 'random_order',
                                  (query, ))
    query = query.limit(NUM_MAX_DISPLAY)
    return jsonify(_predictions_results(query))
예제 #7
0
파일: diadem.py 프로젝트: x0rzkov/SecuML
def getPredictions(exp_id, predicted_value, right_wrong, multiclass):
    multiclass = multiclass == 'true'
    query = session.query(PredictionsAlchemy)
    query = query.filter(PredictionsAlchemy.exp_id == exp_id)
    query = query.filter(PredictionsAlchemy.value == predicted_value)
    if right_wrong != 'all':
        query = query.join(PredictionsAlchemy.instance)
        if multiclass:
            field = 'family'
        else:
            field = 'label'
            predicted_value = label_str_to_bool(predicted_value)
        if right_wrong == 'right':
            query = query.filter(
                getattr(InstancesAlchemy, field) == predicted_value)
        elif right_wrong == 'wrong':
            query = query.filter(
                getattr(InstancesAlchemy, field) != predicted_value)
        else:
            assert (False)
    query = call_specific_db_func(secuml_conf.db_type, 'random_order',
                                  (query, ))
    query = query.limit(NUM_MAX_DISPLAY)
    return jsonify(_predictions_results(query))
예제 #8
0
파일: secuml.py 프로젝트: zzszmyf/SecuML
 def get_engine(self):
     return call_specific_db_func(self.db_type, 'get_engine',
                                  (self.db_uri, ))