def __init__(self, initial_state, ctmcs, break_points): """Construct all the matrices and cache them for the method calls. :param initial_state: The initial state for this CTMC system. We include it in the constructor for this model because we want to handle both samples from each population and between them. :param ctmcs: CTMCs for each interval. :type ctmcs: list[IMCoalHMM.CTMC.CTMC] :param break_points: List of break points. :type break_points: list[float] """ super(VariableCoalAndMigrationRateCTMCSystem, self).__init__(no_hmm_states=len(ctmcs), initial_ctmc_state=initial_state) # Even though we have different CTMCs they have the same state space self.state_space = ctmcs[0].state_space self.through_ = _compute_through(ctmcs, break_points) # noinspection PyCallingNonCallable upto0 = matrix(identity(len(ctmcs[0].state_space.states))) self.upto_ = compute_upto(upto0, self.through_) self.between_ = compute_between(self.through_)
def __init__(self, model, epoch_1_ctmc, epoch_2_ctmc, epoch_3_ctmc, break_points_12, break_points_123): self.model = model self.epoch_1 = epoch_1_ctmc self.epoch_2 = epoch_2_ctmc self.epoch_3 = epoch_3_ctmc self.break_points_12 = break_points_12 self.break_points_123 = break_points_123 self.through_ = compute_through(self.epoch_2, self.epoch_3, self.break_points_12, self.break_points_123) self.up_to_ = compute_upto(compute_up_to0(self.epoch_1, self.epoch_2, self.break_points_12[0]), self.through_) self.between_ = compute_between(self.through_)
def __init__(self, isolation_ctmc, middle_ctmc, ancestral_ctmc, p, q, middle_break_points, ancestral_break_points): """Construct all the matrices and cache them for the method calls. """ super(AdmixtureCTMCSystem12, self).__init__( no_hmm_states=len(middle_break_points) + len(ancestral_break_points), initial_ctmc_state=isolation_ctmc.state_space.i12_index) self.no_middle_states = len(middle_break_points) self.middle = middle_ctmc self.no_ancestral_states = len(ancestral_break_points) self.ancestral = ancestral_ctmc self.through_ = [None] * (self.no_middle_states + self.no_ancestral_states - 1) for i in xrange(self.no_middle_states - 1): self.through_[i] = middle_ctmc.probability_matrix( middle_break_points[i + 1] - middle_break_points[i]) xx = middle_ctmc.probability_matrix(ancestral_break_points[0] - middle_break_points[-1]) projection = projection_matrix( middle_ctmc.state_space, ancestral_ctmc.state_space, lambda state: frozenset([(0, nucs) for (_, nucs) in state])) self.through_[self.no_middle_states - 1] = xx * projection for i in xrange(self.no_middle_states, self.no_middle_states + self.no_ancestral_states - 1): ii = i - self.no_middle_states self.through_[i] = ancestral_ctmc.probability_matrix( ancestral_break_points[ii + 1] - ancestral_break_points[ii]) pseudo_through = matrix( zeros((len(ancestral_ctmc.state_space.states), len(ancestral_ctmc.state_space.states)))) pseudo_through[:, ancestral_ctmc.state_space.end_states[0]] = 1.0 self.through_.append(pseudo_through) projection = admixture_state_space_map(isolation_ctmc.state_space, middle_ctmc.state_space, p, q) self.upto_ = compute_upto( isolation_ctmc.probability_matrix(middle_break_points[0]) * projection, self.through_) self.between_ = compute_between(self.through_)
def __init__(self, isolation_ctmc, migration_ctmcs, ancestral_ctmcs, migration_break_points, ancestral_break_points): """Construct all the matrices and cache them for the method calls. :param isolation_ctmc: CTMC for the isolation phase. :type isolation_ctmc: IMCoalHMM.CTMC.CTMC :param migration_ctmcs: CTMCs for the migration phase. :type migration_ctmcs: list[IMCoalHMM.CTMC.CTMC] :param ancestral_ctmcs: CTMCs for the ancestral population. :type ancestral_ctmcs: list[IMCoalHMM.CTMC.CTMC] :param migration_break_points: List of break points in the migration phase. :type migration_break_points: list[float] :param ancestral_break_points: List of break points in the ancestral population. :type ancestral_break_points: list[float] """ self.no_migration_states = len(migration_break_points) self.no_ancestral_states = len(ancestral_break_points) no_states = self.no_migration_states + self.no_ancestral_states super(IsolationMigrationEpochsCTMCSystem, self).__init__(no_states, isolation_ctmc.state_space.i12_index) # Don't include isolation_ctmc here... the ctmcs here are only those we can coalesce in! self.ctmcs = migration_ctmcs + ancestral_ctmcs # This is a hack to match the "pseudo_through" probability matrix for the last interval, # where we need the state space of the interval _past_ the last self.ctmcs.append(ancestral_ctmcs[-1]) break_points = list(migration_break_points) + list( ancestral_break_points) upto0 = _compute_upto0(isolation_ctmc, migration_ctmcs[0], break_points) self.through_ = _compute_through(migration_ctmcs, migration_break_points, ancestral_ctmcs, ancestral_break_points) self.upto_ = compute_upto(upto0, self.through_) self.between_ = compute_between(self.through_)
def __init__(self, isolation_ctmc, migration_ctmc, ancestral_ctmc, migration_break_points, ancestral_break_points): """Construct all the matrices and cache them for the method calls. :param isolation_ctmc: CTMC for the isolation phase. :type isolation_ctmc: IMCoalHMM.CTMC.CTMC :param migration_ctmc: CTMC for the migration phase. :type migration_ctmc: IMCoalHMM.CTMC.CTMC :param ancestral_ctmc: CTMC for the ancestral population. :type ancestral_ctmc: IMCoalHMM.CTMC.CTMC :param migration_break_points: List of break points in the migration phase. :type migration_break_points: list[int] :param ancestral_break_points: List of break points in the ancestral population. :type ancestral_break_points: list[int] """ self.no_migration_states = len(migration_break_points) self.no_ancestral_states = len(ancestral_break_points) no_states = self.no_migration_states + self.no_ancestral_states super(IsolationMigrationCTMCSystem, self).__init__(no_states, isolation_ctmc.state_space.i12_index) self.state_spaces = [ migration_ctmc.state_space, ancestral_ctmc.state_space ] break_points = list(migration_break_points) + list( ancestral_break_points) self.through_ = _compute_through(migration_ctmc, migration_break_points, ancestral_ctmc, ancestral_break_points) self.upto_ = compute_upto( _compute_upto0(isolation_ctmc, migration_ctmc, break_points), self.through_) self.between_ = compute_between(self.through_)
def __init__(self, isolation_ctmc, ancestral_ctmcs, break_points): """Construct all the matrices and cache them for the method calls. :param isolation_ctmc: CTMC for the initial isolation phase. :type isolation_ctmc: IMCoalHMM.CTMC.CTMC :param ancestral_ctmcs: CTMCs for the ancestral population. :type ancestral_ctmcs: list[IMCoalHMM.CTMC.CTMC] :param break_points: List of break points. :type break_points: list[float] """ super(VariableCoalRateCTMCSystem, self).__init__( no_hmm_states=len(ancestral_ctmcs), initial_ctmc_state=isolation_ctmc.state_space.i12_index) # Even though we have different CTMCs they have the same state space self.state_space = ancestral_ctmcs[0].state_space self.through_ = _compute_through(ancestral_ctmcs, break_points) self.upto_ = compute_upto( _compute_upto0(isolation_ctmc, ancestral_ctmcs, break_points), self.through_) self.between_ = compute_between(self.through_)