Exemplo n.º 1
0
 def run(self, train_instances, cv_monitoring=False):
     Experiment.run(self)
     self._train(train_instances)
     if cv_monitoring:
         self._cv_monitoring(train_instances)
     else:
         self.cv_monitoring = None
     self._export()
Exemplo n.º 2
0
 def add_to_db(self):
     from secuml.exp.diadem import add_diadem_exp_to_db
     Experiment.add_to_db(self)
     add_diadem_exp_to_db(self.session,
                          self.exp_conf.exp_id,
                          self.exp_conf.fold_id,
                          'train',
                          classifier_conf=self.exp_conf.core_conf)
Exemplo n.º 3
0
 def run(self, instances=None, drop_annotated_instances=False, quick=False):
     Experiment.run(self)
     instances = self.get_instances()
     core_conf = self.exp_conf.core_conf
     clustering = core_conf.algo(instances, core_conf)
     clustering.fit()
     clustering.generate(drop_annotated_instances=drop_annotated_instances)
     clustering.export(self.output_dir(), quick=quick)
Exemplo n.º 4
0
 def __init__(self, exp_conf, create=True, session=None):
     self.kind = exp_conf.kind
     Experiment.__init__(self, exp_conf, create=create, session=session)
     self.test_instances = None
     self.predictions = None
     self.prediction_time = None
     self.classifier = None
     alerts_conf = self.exp_conf.core_conf
     self.monitoring = DetectionMonitoring(self, alerts_conf=alerts_conf)
Exemplo n.º 5
0
 def add_to_db(self):
     Experiment.add_to_db(self)
     from secuml.exp.diadem import add_diadem_exp_to_db
     add_diadem_exp_to_db(self.session,
                          self.exp_conf.exp_id,
                          self.exp_conf.fold_id,
                          self.kind,
                          alerts_conf=self.alerts_conf,
                          classifier_conf=self.exp_conf.core_conf)
Exemplo n.º 6
0
 def set_clusters(self, instances, assigned_clusters, centroids,
                  drop_annotated_instances, cluster_labels):
     Experiment.run(self)
     clustering = Clusters(instances, assigned_clusters)
     clustering.generate(centroids,
                         drop_annotated_instances=drop_annotated_instances,
                         cluster_labels=cluster_labels)
     clustering.export(self.output_dir(),
                       drop_annotated_instances=drop_annotated_instances)
Exemplo n.º 7
0
 def add_to_db(self):
     Experiment.add_to_db(self)
     features_set_id = self.exp_conf.features_conf.set_id
     annotations_file = self.exp_conf.annotations_conf.annotations_filename
     stats_exp = FeaturesAnalysisExpAlchemy(
         id=self.exp_id,
         features_set_id=features_set_id,
         annotations_filename=annotations_file)
     self.session.add(stats_exp)
     self.session.flush()
Exemplo n.º 8
0
 def add_to_db(self):
     Experiment.add_to_db(self)
     has_ground_truth = self.exp_conf.dataset_conf.has_ground_truth
     dataset_id = self.exp_conf.dataset_conf.dataset_id
     self.session.add(
         DiademExpAlchemy(exp_id=self.exp_conf.exp_id,
                          dataset_id=dataset_id,
                          fold_id=self.exp_conf.fold_id,
                          type=self.kind,
                          perf_monitoring=has_ground_truth))
     self.session.flush()
Exemplo n.º 9
0
 def __init__(self,
              exp_conf,
              classifier=None,
              alerts_conf=None,
              create=True,
              session=None):
     self.classifier = classifier
     self.kind = exp_conf.kind
     self.alerts_conf = alerts_conf
     self.test_instances = None
     self.predictions = None
     self.monitoring = None
     Experiment.__init__(self, exp_conf, create=create, session=session)
Exemplo n.º 10
0
 def run(self):
     Experiment.run(self)
     instances = self.get_instances()
     with_density = instances.num_instances() < 150000
     if not with_density:
         self.exp_conf.logger.warning('There are more than 150.000, so '
                                      'the density plots are not '
                                      'displayed. ')
     stats = FeaturesAnalysis(instances,
                              self.exp_conf.multiclass,
                              self.exp_conf.logger,
                              with_density=with_density)
     stats.gen_plots(self.output_dir())
     stats.gen_scoring(self.output_dir())
Exemplo n.º 11
0
 def run(self, instances=None, export=True):
     Experiment.run(self)
     instances = self.get_instances()
     core_conf = self.exp_conf.core_conf
     dimension_reduction = core_conf.algo(core_conf)
     # Fit
     dimension_reduction.fit(instances)
     if export:
         dimension_reduction.export_fit(self.output_dir(), instances)
     # Transformation
     projected_instances = dimension_reduction.transform(instances)
     if export:
         dimension_reduction.export_transform(self.output_dir(), instances,
                                              projected_instances)
     return projected_instances
Exemplo n.º 12
0
 def run(self):
     Experiment.run(self)
     datasets = Datasets(self.get_instances())
     active_learning = ActiveLearning(self, datasets)
     if not self.exp_conf.core_conf.auto:
         from secuml.exp.celery_app.app import secumlworker
         from secuml.exp.active_learning.celery_tasks import IterationTask
         options = {}
         # bind iterations object to IterationTask class
         active_learning.run_next_iter(output_dir=self.output_dir())
         IterationTask.iteration_object = active_learning
         # Start worker
         secumlworker.enable_config_fromcmdline = False
         secumlworker.run(**options)
     else:
         active_learning.run_iterations(output_dir=self.output_dir())
Exemplo n.º 13
0
 def create_exp(self):
     Experiment.create_exp(self)
     # create projection experiment
     self.projection_exp = None
     if self.exp_conf.core_conf is None:
         return
     projection_core_conf = self.exp_conf.core_conf.projection_conf
     if projection_core_conf is not None:
         features_conf = FeaturesConf(
             self.exp_conf.features_conf.input_features,
             self.exp_conf.secuml_conf.logger)
         projection_conf = ProjectionConf(self.exp_conf.secuml_conf,
                                          self.exp_conf.dataset_conf,
                                          features_conf,
                                          self.exp_conf.annotations_conf,
                                          projection_core_conf,
                                          name='-'.join(
                                              [self.exp_conf.name, 'proj']),
                                          parent=self.exp_id)
         self.projection_exp = ProjectionExperiment(projection_conf,
                                                    session=self.session)
Exemplo n.º 14
0
 def get_instances(self, instances=None):
     instances = Experiment.get_instances(self, instances=instances)
     if self.exp_conf.label != 'all':
         selected_ids = instances.ground_truth.get_annotated_ids(
                                                 label=self.exp_conf.label)
         instances = instances.get_from_ids(selected_ids)
     if self.projection_exp is not None:
         try:
             instances = self.projection_exp.run(instances=instances,
                                                 export=False)
         except FewerThanTwoLabels:
             self.conf.logger.warning('There are too few class labels.'
                                      'The instances are not projected '
                                      'before building the clustering.')
     return instances
Exemplo n.º 15
0
 def __init__(self, exp_conf, create=True, session=None):
     Experiment.__init__(self, exp_conf, create=create, session=session)
     self.classifier = None
     self.train_time = None
     self.monitoring = TrainMonitoring(self)
Exemplo n.º 16
0
 def add_to_db(self):
     Experiment.add_to_db(self)
     al_exp = ActiveLearningExpAlchemy(id=self.exp_id, current_iter=0,
                                       finished=False)
     self.session.add(al_exp)
     self.session.flush()
Exemplo n.º 17
0
 def run(self):
     Experiment.run(self)
     stats = FeaturesAnalysis(self.get_instances())
     stats.compute()
     stats.export(self.output_dir())
Exemplo n.º 18
0
 def run(self, classifier, test_instances):
     Experiment.run(self)
     self.test_instances = self.get_instances(test_instances)
     self.classifier = classifier
     self._test()
     self._export()
Exemplo n.º 19
0
 def __init__(self, exp_conf, create=True, session=None):
     Experiment.__init__(self, exp_conf, create=create, session=session)
     self.classifier = None
     self.predictions = None
     self.monitoring = None
     self.cv_monitoring = None
Exemplo n.º 20
0
 def __init__(self, exp_conf, create=True, session=None):
     Experiment.__init__(self, exp_conf, create, session)
     self.test_conf = self.exp_conf.core_conf.test_conf
     self.validation_conf = self.exp_conf.core_conf.validation_conf
     self._train_test_exps = {}
Exemplo n.º 21
0
 def add_to_db(self):
     Experiment.add_to_db(self)
     self.session.add(DiademExpAlchemy(exp_id=self.exp_conf.exp_id,
                                       fold_id=self.exp_conf.fold_id,
                                       type=self.kind))
     self.session.flush()
Exemplo n.º 22
0
 def run(self, train_instances, cv_monitoring=False):
     Experiment.run(self)
     self._train(train_instances)
     if cv_monitoring:
         self._cv_monitoring(train_instances)
     self.monitoring.display(self.output_dir())
Exemplo n.º 23
0
 def run(self, test_instances):
     Experiment.run(self)
     self.test_instances = self.get_instances(test_instances)
     self._test()
     self._export()