예제 #1
0
 def train(self, data_dict, supervision_influence=1.0):
     """
     Generate trained hmm and predict examples
     """
     self.supervision_influence = supervision_influence
     self.trained = self.get_trained_hmm(data_dict)
     self.timestamp = numeric_timestamp()
예제 #2
0
 def load_params(self, file_contents):
     (mod_check, model_txt, feature_txt, gui_state_dict_txt,
      pg_gui_state_dict_txt, str2num_state_dict_txt,
      misc_txt) = file_contents.split('\nSTART_NEW_SECTION\n')
     if mod_check != 'VanillaHmm':
         error_msg = '\nERROR: loaded model parameters are not for a Vanilla HMM!'
         # if self.gui:
         #     self.gui.notify(error_msg)
         #     return
         # else:
         raise ValueError(error_msg)
     self.trained = pg.HiddenMarkovModel().from_yaml(model_txt)
     self.feature_list = feature_txt.split('\n')
     self.gui_state_dict = yaml.load(gui_state_dict_txt,
                                     Loader=yaml.FullLoader)
     self.pg_gui_state_dict = yaml.load(pg_gui_state_dict_txt,
                                        Loader=yaml.FullLoader)
     self.str2num_state_dict = yaml.load(str2num_state_dict_txt,
                                         Loader=yaml.FullLoader)
     misc_dict = yaml.load(misc_txt, Loader=yaml.SafeLoader)
     if misc_dict['dbscan_epsilon'] == 'nan':
         misc_dict['dbscan_epsilon'] = np.nan
     self.nb_states = misc_dict['nb_states']
     self.data.eps = misc_dict['dbscan_epsilon']
     self.supervision_influence = misc_dict['supervision_influence']
     self.framerate = misc_dict['framerate']
     self.timestamp = numeric_timestamp()
예제 #3
0
    def load_params(self, file_contents):
        """
        STEP 4.2 (OPTIONAL):
        Load a previously trained model. Naturally, this only makes sense if the function save_params is also
        implemented. The result should be that the model in self.trained functions exactly the same way as it did
        when the model was first trained.
        """

        # Your implementation goes here

        self.timestamp = numeric_timestamp(
        )  # time stamp for model updating methods, please leave as is
예제 #4
0
    def __init__(self, nb_states, data, **kwargs):
        """
        :param nb_states: number of states to detect
        :param data: object of class MainTable
        :param gui: Gui object [optional]
        :param buffer: int, size of buffer area around regular classes [required if gui not given]
        """
        self.trained = None
        self.framerate = None
        self.timestamp = numeric_timestamp()
        self.nb_threads = kwargs.get('nb_threads', 8)
        self.feature_list = kwargs['features']
        self.supervision_influence = kwargs['supervision_influence']

        self.nb_states = nb_states
        self.data = data
예제 #5
0
    def __init__(self, nb_states, data, **kwargs):
        """
        :param nb_states: number of states to detect
        :param data: object of class MainTable
        :param gui: Gui object [optional]
        :param buffer: int, size of buffer area around regular classes [required if gui not given]
        """
        self.trained = None
        self.timestamp = numeric_timestamp()
        self.nb_threads = kwargs.get('nb_threads', 8)
        self.feature_list = kwargs['features']
        self.buffer = kwargs.get('buffer', 3)

        self.nb_states = nb_states
        self.data = data

        self.state_names = None  # names assigned to states in same order as pomegranate model
        self.pg_gui_state_dict = dict()
        self.gui_state_dict = dict()
        self.str2num_state_dict = dict()
예제 #6
0
    def init_table(self):
        # Create index table
        self.index_table = pd.DataFrame(columns=[
            'trace', 'eps', 'l', 'd', 'gamma', 'data_timestamp', 'logprob',
            'mod_timestamp'
        ]).set_index('trace')
        self.manual_table = df_empty(
            columns=['trace', 'is_labeled', 'is_junk'],
            dtypes=[str, np.bool, np.bool]).set_index('trace')
        with SafeHDFStore(self.traces_store_fn, 'a') as fh:
            fh.put('index_table',
                   value=self.index_table,
                   format='table',
                   append=True)

        # make traces group
        with SafeH5(self.traces_store_fn, 'a') as fh:
            fh.create_group('traces')

        # hdf5 file for transfer to file parser
        self.data_timestamp = numeric_timestamp()
        with SafeH5(self.toparse_fn, 'w') as fh:
            (fh.attrs['data_timestamp'], fh.attrs['framerate'],
             fh.attrs['eps'], fh.attrs['l'], fh.attrs['d'], fh.attrs['gamma'],
             fh.attrs['alex'],
             fh.attrs['traceswitch']) = (self.data_timestamp, self.framerate,
                                         self.eps, self.l, self.d, self.gamma,
                                         self.alex, self.traceswitch)

        # hdf5 file for transfer to predictor
        with SafeH5(self.predict_store_fn, 'w') as fh:
            pass
        fp_process = Process(target=FileParser,
                             args=(self.toparse_fn, self.traces_store_fn,
                                   self.main_process),
                             name='file_parser')
        fp_process.start()
        return fp_process
예제 #7
0
 def d(self, d):
     self.data_timestamp = numeric_timestamp()
     with SafeH5(self.toparse_fn, 'a') as fh:
         fh.attrs['d'] = d
         fh.attrs['data_timestamp'] = self.data_timestamp
     self._d = d
예제 #8
0
 def l(self, l):
     self.data_timestamp = numeric_timestamp()
     with SafeH5(self.toparse_fn, 'a') as fh:
         fh.attrs['l'] = l
         fh.attrs['data_timestamp'] = self.data_timestamp
     self._l = l
예제 #9
0
 def eps(self, eps):
     self.data_timestamp = numeric_timestamp()
     with SafeH5(self.toparse_fn, 'a') as fh:
         fh.attrs['eps'] = eps
         fh.attrs['data_timestamp'] = self.data_timestamp
     self._eps = eps
예제 #10
0
 def traceswitch(self, traceswitch):
     self.data_timestamp = numeric_timestamp()
     with SafeH5(self.toparse_fn, 'a') as fh:
         fh.attrs['traceswitch'] = traceswitch
         fh.attrs['data_timestamp'] = self.data_timestamp
     self._traceswitch = traceswitch
예제 #11
0
 def alex(self, alex):
     self.data_timestamp = numeric_timestamp()
     with SafeH5(self.toparse_fn, 'a') as fh:
         fh.attrs['alex'] = alex
         fh.attrs['data_timestamp'] = self.data_timestamp
     self._alex = alex
예제 #12
0
 def framerate(self, framerate):
     self.data_timestamp = numeric_timestamp()
     with SafeH5(self.toparse_fn, 'a') as fh:
         fh.attrs['framerate'] = framerate
         fh.attrs['data_timestamp'] = self.data_timestamp
     self._framerate = framerate
예제 #13
0
 def gamma(self, gamma):
     self.data_timestamp = numeric_timestamp()
     with SafeH5(self.toparse_fn, 'a') as fh:
         fh.attrs['gamma'] = gamma
         fh.attrs['data_timestamp'] = self.data_timestamp
     self._gamma = gamma