def _truncate_frac_to_upper_alleles(self, genotype):
     for frac_to_upper_idx in range(1, len(genotype), 2):
         frac_to_upper_allele = genotype[frac_to_upper_idx]
         frac_to_upper_allele = \
             truncate_val(frac_to_upper_allele,
                          lower_bound=self._MIN_FRAC_TO_UPPER_VAL,
                          upper_bound=self._MAX_FRAC_TO_UPPER_VAL)
         genotype[frac_to_upper_idx] = frac_to_upper_allele
 def _truncate_lower_alleles(self, genotype):
     for lower_allele_idx in range(0, len(genotype), 2):
         situation_space_idx = int(lower_allele_idx / 2)
         dimension = self._situation_space[situation_space_idx]
         lower_allele = genotype[lower_allele_idx]
         lower_allele = truncate_val(lower_allele,
                                     lower_bound=dimension.lower,
                                     upper_bound=dimension.upper)
         genotype[lower_allele_idx] = lower_allele
示例#3
0
 def _enforce_genotype_maps_to_valid_phenotype(self, genotype):
     assert len(genotype) == len(self._ling_vars)
     for (allele_idx, ling_var) in zip(range(0, len(genotype)),
                                       self._ling_vars):
         allele = genotype[allele_idx]
         min_val = 0
         max_val = (len(ling_var.membership_funcs) - 1)
         allele = truncate_val(allele,
                               lower_bound=min_val,
                               upper_bound=max_val)
         genotype[allele_idx] = allele
 def gen_covering_condition(self, situation):
     alleles = []
     for (idx, situation_elem) in enumerate(situation):
         lower = situation_elem - get_rng().uniform(
             0, get_hyperparam("s_nought"))
         upper = situation_elem + get_rng().uniform(
             0, get_hyperparam("s_nought"))
         dimension = self._situation_space[idx]
         lower = truncate_val(lower,
                              lower_bound=dimension.lower,
                              upper_bound=dimension.upper)
         upper = truncate_val(upper,
                              lower_bound=dimension.lower,
                              upper_bound=dimension.upper)
         assert lower <= upper
         frac_to_upper = self._calc_frac_to_upper(lower, upper,
                                                  dimension.upper)
         alleles.append(lower)
         alleles.append(frac_to_upper)
     genotype = Genotype(alleles)
     return Condition(genotype)
 def gen_covering_condition(self, situation):
     alleles = []
     for (idx, situation_elem) in enumerate(situation):
         # covering draws from (0, r_nought)
         r_nought = get_hyperparam("r_nought")
         assert r_nought > 1
         cover_choices = range(1, r_nought)
         lower = situation_elem - get_rng().choice(cover_choices)
         upper = situation_elem + get_rng().choice(cover_choices)
         dimension = self._situation_space[idx]
         lower = truncate_val(lower,
                              lower_bound=dimension.lower,
                              upper_bound=dimension.upper)
         upper = truncate_val(upper,
                              lower_bound=dimension.lower,
                              upper_bound=dimension.upper)
         assert lower <= upper
         span_to_upper = self._calc_span_to_upper(lower, upper, dimension)
         alleles.append(lower)
         alleles.append(span_to_upper)
     genotype = Genotype(alleles)
     return Condition(genotype)
    def _truncate_span_to_upper_alleles(self, genotype):
        for lower_allele_idx in range(0, len(genotype), 2):
            span_to_upper_allele_idx = lower_allele_idx + 1
            situation_space_idx = int(lower_allele_idx / 2)
            dimension = self._situation_space[situation_space_idx]

            lower_allele = genotype[lower_allele_idx]
            span_to_upper_allele = genotype[span_to_upper_allele_idx]
            max_span_to_upper_val = dimension.upper - lower_allele
            span_to_upper_allele = \
                truncate_val(span_to_upper_allele,
                             lower_bound=self._MIN_SPAN_TO_UPPER_VAL,
                             upper_bound=max_span_to_upper_val)
            genotype[span_to_upper_allele_idx] = span_to_upper_allele