def learn_bg_model( sequences, num_mosaics=4, order=3, tolerance_per_base=7e-5 ): """ @return: (bg_model, converted_sequences) """ bg_model = hmm.as_model( create_mosaic_model( num_mosaics=4, p_transition=.1, alphabet_size=4, order=3, dirichlet_prior_strength=.3 ) ) converted_seqs = [bg_model.converter.to_order_n(s) for s in sequences] def _callback(LL): logging.debug('Background model LL: %f', LL) return True tolerance=tolerance_per_base*sum(len(s) for s in sequences) logging.info('Learning background model with %d mosaics of order %d, tolerance=%f', num_mosaics, order, tolerance) start = time.time() LL, iterations = bg_model.baum_welch(converted_seqs, tolerance=tolerance, callback=_callback) logging.info('Achieved LL=%f after %d iterations and %f seconds', LL, iterations, time.time() - start) return bg_model, converted_seqs
def uniform_bg_model(): bg_model = hmm.as_model( create_mosaic_model( num_mosaics=1, p_transition=.1, alphabet_size=4, order=0, dirichlet_prior_strength=None ) ) return bg_model