Get the demographic breakdown for an input targeting criteria
973600
def demographics(self):
        
        body = {
            "audience_definition": self.audience_definition,
            "targeting_inputs": self.targeting_inputs
        }
        resource = self.RESOURCE_DEMOGRAPHICS.format(account_id=self.account.id)
        response = Request(
            self.account.client, self.METHOD,
            resource, headers=self.HEADERS, body=json.dumps(body)).perform()
        return response.body['data']
410707
def selection(x_bounds,
              x_types,
              clusteringmodel_gmm_good,
              clusteringmodel_gmm_bad,
              minimize_starting_points,
              minimize_constraints_fun=None):
    '''
    
    '''
    results = lib_acquisition_function.next_hyperparameter_lowest_mu(\
                    _ratio_scores, [clusteringmodel_gmm_good, clusteringmodel_gmm_bad],\
                    x_bounds, x_types, minimize_starting_points, \
                    minimize_constraints_fun=minimize_constraints_fun)

    return results
31685
public void setTargetingCriteriaBreakdowns(com.google.api.ads.admanager.axis.v201808.TargetingCriteriaBreakdown[] targetingCriteriaBreakdowns) {
        this.targetingCriteriaBreakdowns = targetingCriteriaBreakdowns;
    }
799170
function () {

    if (!this.used) return;

    var axis  = this,
      o       = axis.options,
      min     = o.min !== null ? o.min : axis.datamin,
      max     = o.max !== null ? o.max : axis.datamax,
      margin  = o.autoscaleMargin;
        
    if (o.scaling == 'logarithmic') {
      if (min <= 0) min = axis.datamin;

      // Let it widen later on
      if (max <= 0) max = min;
    }

    if (max == min) {
      var widen = max ? 0.01 : 1.00;
      if (o.min === null) min -= widen;
      if (o.max === null) max += widen;
    }

    if (o.scaling === 'logarithmic') {
      if (min < 0) min = max / o.base;  // Could be the result of widening

      var maxexp = Math.log(max);
      if (o.base != Math.E) maxexp /= Math.log(o.base);
      maxexp = Math.ceil(maxexp);

      var minexp = Math.log(min);
      if (o.base != Math.E) minexp /= Math.log(o.base);
      minexp = Math.ceil(minexp);
      
      axis.tickSize = Flotr.getTickSize(o.noTicks, minexp, maxexp, o.tickDecimals === null ? 0 : o.tickDecimals);
                        
      // Try to determine a suitable amount of miniticks based on the length of a decade
      if (o.minorTickFreq === null) {
        if (maxexp - minexp > 10)
          o.minorTickFreq = 0;
        else if (maxexp - minexp > 5)
          o.minorTickFreq = 2;
        else
          o.minorTickFreq = 5;
      }
    } else {
      axis.tickSize = Flotr.getTickSize(o.noTicks, min, max, o.tickDecimals);
    }

    axis.min = min;
    axis.max = max; //extendRange may use axis.min or axis.max, so it should be set before it is caled

    // Autoscaling. @todo This probably fails with log scale. Find a testcase and fix it
    if(o.min === null && o.autoscale){
      axis.min -= axis.tickSize * margin;
      // Make sure we don't go below zero if all values are positive.
      if(axis.min < 0 && axis.datamin >= 0) axis.min = 0;
      axis.min = axis.tickSize * Math.floor(axis.min / axis.tickSize);
    }
    
    if(o.max === null && o.autoscale){
      axis.max += axis.tickSize * margin;
      if(axis.max > 0 && axis.datamax <= 0 && axis.datamax != axis.datamin) axis.max = 0;        
      axis.max = axis.tickSize * Math.ceil(axis.max / axis.tickSize);
    }

    if (axis.min == axis.max) axis.max = axis.min + 1;
  }
1374135
def _known_populations(row, pops):
    
    cutoff = 0.01
    out = set([])
    for pop, base in [("esp", "af_esp_all"), ("1000g", "af_1kg_all"),
                      ("exac", "af_exac_all"), ("anypop", "max_aaf_all")]:
        for key in [x for x in pops if x.startswith(base)]:
            val = row[key]
            if val and val > cutoff:
                out.add(pop)
    return sorted(list(out))
895548
def handle_base_populations(population_def, population)
      {
        HQMF::PopulationCriteria::IPP => 'initialPopulationCriteria',
        HQMF::PopulationCriteria::DENOM => 'denominatorCriteria',
        HQMF::PopulationCriteria::NUMER => 'numeratorCriteria',
        HQMF::PopulationCriteria::NUMEX => 'numeratorExclusionCriteria',
        HQMF::PopulationCriteria::DENEXCEP => 'denominatorExceptionCriteria',
        HQMF::PopulationCriteria::DENEX => 'denominatorExclusionCriteria',
        HQMF::PopulationCriteria::MSRPOPL => 'measurePopulationCriteria',
        HQMF::PopulationCriteria::MSRPOPLEX => 'measurePopulationExclusionCriteria'
      }.each_pair do |criteria_id, criteria_element_name|
        criteria_def = population_def.at_xpath("cda:component[cda:#{criteria_element_name}]", HQMF2::Document::NAMESPACES)
        if criteria_def
          build_population_criteria(criteria_def, criteria_id, population)
        end
      end
    end
21020
def find_needed_input(input_format):
    
    needed_inputs = [re.cls for re in registry if re.category==RegistryCategories.inputs and re.cls.input_format == input_format]
    if len(needed_inputs)>0:
        return needed_inputs[0]
    return None
878244
def extract_populations_cql_map
      populations_cql_map = {}
      @doc.xpath("//cda:populationCriteriaSection/cda:component[@typeCode='COMP']", HQMF2::Document::NAMESPACES).each do |population_def|
        {
          HQMF::PopulationCriteria::IPP => 'initialPopulationCriteria',
          HQMF::PopulationCriteria::DENOM => 'denominatorCriteria',
          HQMF::PopulationCriteria::NUMER => 'numeratorCriteria',
          HQMF::PopulationCriteria::NUMEX => 'numeratorExclusionCriteria',
          HQMF::PopulationCriteria::DENEXCEP => 'denominatorExceptionCriteria',
          HQMF::PopulationCriteria::DENEX => 'denominatorExclusionCriteria',
          HQMF::PopulationCriteria::MSRPOPL => 'measurePopulationCriteria',
          HQMF::PopulationCriteria::MSRPOPLEX => 'measurePopulationExclusionCriteria',
          HQMF::PopulationCriteria::STRAT => 'stratifierCriteria'
        }.each_pair do |criteria_id, criteria_element_name|
          criteria_def = population_def.at_xpath("cda:#{criteria_element_name}", HQMF2::Document::NAMESPACES)
          if criteria_def
            # Ignore Supplemental Data Elements
            next if HQMF::PopulationCriteria::STRAT == criteria_id &&
                !criteria_def.xpath("cda:component[@typeCode='COMP']/cda:measureAttribute/cda:code[@code='SDE']").empty?
            cql_statement = criteria_def.at_xpath("*/*/cda:id", HQMF2::Document::NAMESPACES).attribute('extension').to_s.match(/"([^"]*)"/)
            if populations_cql_map[criteria_id].nil?
              populations_cql_map[criteria_id] = []
            end
            cql_statement = cql_statement.to_s.delete('\\"')
            populations_cql_map[criteria_id].push cql_statement
          end
        end
      end
      populations_cql_map
    end
158574
def _filter(self, criteria: Q, db):
        """"""
        # Filter the dictionary objects based on the filters
        negated = criteria.negated
        input_db = None

        if criteria.connector == criteria.AND:
            # Trim database records over successive iterations
            #   Whatever is left at the end satisfy all criteria (AND)
            input_db = db
            for child in criteria.children:
                if isinstance(child, Q):
                    input_db = self._filter(child, input_db)
                else:
                    input_db = self.provider._evaluate_lookup(child[0], child[1],
                                                              negated, input_db)
        else:
            # Grow database records over successive iterations
            #   Whatever is left at the end satisfy any criteria (OR)
            input_db = {}
            for child in criteria.children:
                if isinstance(child, Q):
                    results = self._filter(child, db)
                else:
                    results = self.provider._evaluate_lookup(child[0], child[1], negated, db)

                input_db = {**input_db, **results}

        return input_db
106638
def age_range(self):
        """"""
        if self.date_range is None:
            return None, None
        start_date = DateRange(self.date_range.start, self.date_range.start)
        end_date = DateRange(self.date_range.end, self.date_range.end)
        start_age = DOB(date_range=end_date).age
        end_age = DOB(date_range=start_date).age
        return start_age, end_age
975485
def unit_targeting(w, k):
  """"""
  k = tf.to_int32(k)
  w_shape = shape_list(w)
  size = tf.to_int32(tf.reduce_prod(w_shape[:-1]))
  w = tf.reshape(w, [size, w_shape[-1]])

  norm = tf.norm(w, axis=0)
  thres = tf.contrib.framework.sort(norm, axis=0)[k]
  mask = to_float(thres >= norm)[None, :]
  mask = tf.tile(mask, [size, 1])

  return tf.reshape(mask, w_shape)
400742
def formula(person, period, parameters):
        '''
        
        '''
        age_condition = person('age', period) >= parameters(period).general.age_of_retirement
        return age_condition
604523
def display(self):
        """"""
        if self.title and self.organization:
            disp = self.title + u' at ' + self.organization
        else:
            disp = self.title or self.organization or None
        if disp and self.industry:
            if self.date_range is not None:
                disp += u' (%s, %d-%d)' % ((self.industry,) + \
                                           self.date_range.years_range)
            else:
                disp += u' (%s)' % self.industry
        else:
            disp = ((disp or u'') + u' ' + (self.industry or u'')).strip()
            if disp and self.date_range is not None:
                disp += u' (%d-%d)' % self.date_range.years_range
        return disp
668255
function getPopulation( props ) {
  // extract all the population values as numbers and find the first non-negative value
  // returns undefined if there are no such values
  return population_hierarchy.
          map((field) => { return _.toNumber(props[field]); }).
          find((val) => { return val >= 0; } );
}
546962
private int collectCandidates(Map<Long, Score> candidates,
                                List<Bucket> buckets,
                                int threshold) {
    int ix;
    for (ix = 0; ix < threshold &&
           candidates.size() < (CUTOFF_FACTOR_1 * max_search_hits); ix++) {
      Bucket b = buckets.get(ix);
      long[] ids = b.records;
      double score = b.getScore();
      
      for (int ix2 = 0; ix2 < b.nextfree; ix2++) {
        Score s = candidates.get(ids[ix2]);
        if (s == null) {
          s = new Score(ids[ix2]);
          candidates.put(ids[ix2], s);
        }
        s.score += score;
      }
      if (DEBUG)
        System.out.println("Bucket " + b.nextfree + " -> " + candidates.size());
    }
    return ix;
  }
142643
def hittime(cls, timestamp=None, age=None, milliseconds=None):
        
        if isinstance(timestamp, (int, float)):
            return int(Time.milliseconds_offset(Time.from_unix(timestamp, milliseconds=milliseconds)))
        if isinstance(timestamp, datetime.datetime):
            return int(Time.milliseconds_offset(timestamp))
        if isinstance(age, (int, float)):
            return int(age * 1000) + (milliseconds or 0)
160637
def _won_in(self):
        """"""
        if not self._summary['finished']:
            return
        starting_age = self._summary['settings']['starting_age'].lower()
        if starting_age == 'post imperial':
            starting_age = 'imperial'
        ages_reached = set([starting_age])
        for player in self._summary['players']:
            for age, reached in player['ages'].items():
                if reached:
                    ages_reached.add(age)
        ages = ['imperial', 'castle', 'feudal', 'dark']
        for age in ages:
            if age in ages_reached:
                return age