logit_rules.py 文件源码

python
阅读 31 收藏 0 点赞 0 评论 0

项目:mitre 作者: gerberlab 项目源码 文件源码
def __init__(self, model, r0, local_updates_per_structure_update=10):
        self.model = model
        # Ensure r0 is sorted within each sublist
        r0 = r0.copy()
        for i in xrange(len(r0)):
            model.rule_population.sort_list_of_primitives(r0[i])
        # This may be a bad choice of omega_0...
        omega = np.ones(self.model.data.y.shape) 
        # Come up with some sensible initial values for the various
        # structure parameters
        phylogeny_mean = self.model.phylogeny_lambda_l
        phylogeny_std = min(self.model.phylogeny_std_upper_bound,
                            5.0*self.model.phylogeny_delta_l)
        self.current_state = LogisticRuleState(
            r0,omega,np.zeros(len(r0)+model.data.n_fixed_covariates),
            phylogeny_mean, phylogeny_std
         )
        # Could include X in the state except we don't really want to 
        # track it over the whole sampling process; definitely do 
        # need it to persist between subparts of iterations at least, though
        self.current_X = self.model.data.covariate_matrix(r0)
        # We specified an arbitary beta: we will overwrite it when we draw
        # it from its conditional in the first iteration. Because this
        # is not a valid value of beta, we don't add the initial state
        # to self.states.
        self.initial_state = self.current_state.copy()
        self.states = []
        ### The following are not updated after updating beta/z, but are 
        # after every change or attempted change to the rule list structure.
        self.likelihoods = []
        self.priors = [] 
        self.comments = []
        self.attempts = {}
        self.successes = {}
        self.local_updates_per_structure_update = (
            local_updates_per_structure_update
            )
        # We do want some better resolution on the distribution of 
        # coefficients for each state, so we'll store the interstitial beta
        # samples before each structure update step:
        self.additional_beta_values = []

        ### These don't conceptually need to be attributes of the sampler
        # object but this way we avoid recalculating them every iteration
        self.phylogeny_mean_proposal_std = (
            0.5*self.model.phylogeny_delta_l
        )
        self.phylogeny_std_proposal_std = (
            0.5*self.model.phylogeny_delta_l
        )
        self.window_fraction_proposal_std = (
            self.model.tmin /
            (self.model.data.experiment_end - 
             self.model.data.experiment_start)
        )
        self.window_concentration_proposal_std = (
            self.model.window_concentration_typical *
            self.model.window_concentration_update_ratio
        )
评论列表
文章目录


问题


面经


文章

微信
公众号

扫码关注公众号