Returns an offspring with the associated weight(s)
486078
def random_offspring(self):
        ""
        function_set = self.function_set
        function_selection = self._function_selection_ins
        function_selection.density = self.population.density
        function_selection.unfeasible_functions.clear()
        for i in range(self._number_tries_feasible_ind):
            if self._function_selection:
                func_index = function_selection.tournament()
            else:
                func_index = function_selection.random_function()
            func = function_set[func_index]
            args = self.get_args(func)
            if args is None:
                continue
            args = [self.population.population[x].position for x in args]
            f = self._random_offspring(func, args)
            if f is None:
                function_selection.unfeasible_functions.add(func_index)
                continue
            function_selection[func_index] = f.fitness
            return f
        raise RuntimeError("Could not find a suitable random offpsring")
604791
def calcFnWeight(node):
    ''''''
    stack = [node]
    count = 0
    while len(stack) > 0:
        node = stack.pop()
        children = [x for x in ast.iter_child_nodes(node)]
        count += len(children)
        stack = stack + children
    return count
246241
def get_child(self, streamId, childId, options={}):
        """"""
        return self.get('stream/' + streamId + '/children/' + childId, options)
571450
def children(self):
        
        return pvector(
            sorted(self._children.values(), key=lambda m: m.task_level))
41449
def others(self):
        """"""
        if not self.parent: return
        yield self.parent
        for sibling in self.parent.children.values():
            if sibling.name == self.name: continue
            for node in sibling: yield node
        for node in self.parent.others: yield node
649564
function getParents (node, test, key, childrenKey, parentKey) {
  var i, v, p = node, path = [];
  while (p) {
    if (test(p)) {
      if (childrenKey) {
        for (i = 0; i < path.length; i++) {
          arrayKV(p, childrenKey, path[i], false, true);
        }
      }
      if (path[0] && parentKey) {
        path[0][parentKey] = p;
      }
      path.unshift(p);
    }
    p = p.parent;
  }
  for (i = 0; i < path.length; i++) {
    v = path[i];
    path[i] = key ? v[key] : v;
  }

  return path
}
366997
def get_id2parents(objs):
    """"""
    id2parents = {}
    for obj in objs:
        _get_id2parents(id2parents, obj.item_id, obj)
    return id2parents
553186
def get_child_values(parent, names):
        
        vals = []
        for name in names:
            if parent.hasElement(name):
                vals.append(XmlHelper.as_value(parent.getElement(name)))
            else:
                vals.append(np.nan)
        return vals
936848
def variation(self,parents):
        """"""
        # downselect to features that are important
        if (self.valid(parents) and
            self.ml_type != 'SVC' and self.ml_type != 'SVR'):
            # this is needed because svm has a bug that throws valueerror on
            # attribute check
            if hasattr(self.pipeline.named_steps['ml'],'coef_'):
                # for l1 regularization, filter individuals with 0 coefficients
                if self.weight_parents:
                    weights = self.pipeline.named_steps['ml'].coef_
                    if len(weights.shape)>1: # handle multi-coefficient models
                        weights = [np.mean(abs(c)) for c in weights.transpose()]
                    # softmax transformation of the weights
                    weights = np.exp(weights)/np.sum(np.exp(weights))
                    offspring = copy.deepcopy(
                        list(self.random_state.choice(self.valid(parents),
                                              self.population_size, p=weights)))
                else:
                    offspring = copy.deepcopy(list(
                        x for i,x in zip(self.pipeline.named_steps['ml'].coef_,
                                         self.valid(parents)) if  (i != 0).any()))
            elif hasattr(self.pipeline.named_steps['ml'],'feature_importances_'):
                # for tree methods, filter our individuals with 0 feature importance
                if self.weight_parents:
                    weights = self.pipeline.named_steps['ml'].feature_importances_
                    # softmax transformation of the weights
                    weights = np.exp(weights)/np.sum(np.exp(weights))
                    offspring = copy.deepcopy(list(
                        self.random_state.choice(self.valid(parents),
                                         self.population_size, p=weights)))
                else:
                    offspring = copy.deepcopy(list(
                        x for i,x in zip(self.pipeline.named_steps['ml'].feature_importances_,
                                         self.valid(parents)) if  i != 0))
            else:
                offspring = copy.deepcopy(self.valid(parents))
        else:
            offspring = copy.deepcopy(self.valid(parents))

        if self.elitism: # keep a copy of the elite individual
            elite_index = np.argmin([x.fitness for x in parents])
            elite = copy.deepcopy(parents[elite_index])

        # Apply crossover and mutation on the offspring
        if self.verbosity > 2: print("variation...")
        for child1, child2 in it.zip_longest(offspring[::2], offspring[1::2],
                                             fillvalue=None):

            if self.random_state.rand() < self.crossover_rate and child2 != None:
            # crossover
                self.cross(child1.stack, child2.stack, self.max_depth)
                # update ids
                child1.parentid = [child1.id,child2.id]
                child1.id = uuid.uuid4()
                child2.parentid = [child1.id,child2.id]
                child2.id = uuid.uuid4()
                # set default fitness
                child1.fitness = -1
                child2.fitness = -1
            elif child2 == None:
            # single mutation
                self.mutate(child1.stack,self.func_set,self.term_set)
                # update ids
                child1.parentid = [child1.id]
                child1.id = uuid.uuid4()
                # set default fitness
                child1.fitness = -1
            else:
            #double mutation
                self.mutate(child1.stack,self.func_set,self.term_set)
                self.mutate(child2.stack,self.func_set,self.term_set)
                # update ids
                child1.parentid = [child1.id]
                child1.id = uuid.uuid4()
                child2.parentid = [child2.id]
                child2.id = uuid.uuid4()
                # set default fitness
                child1.fitness = -1
                child2.fitness = -1

        while len(offspring) < self.population_size:
            #make new offspring to replace the invalid ones
            offspring.append(Ind())
            self.make_program(offspring[-1].stack,self.func_set,self.term_set,
                              self.random_state.randint(self.min_depth,
                                                        self.max_depth+1),
                              self.otype)
            offspring[-1].stack = list(reversed(offspring[-1].stack))
        
        return offspring,elite,elite_index
148053
def get_children(self):
        """"""
        if hasattr(self, '_cached_children'):
            children = self._toplevel().objects.filter(
                pk__in=[n.pk for n in self._cached_children]
            )
            children._result_cache = self._cached_children
            return children
        else:
            return self.get_descendants(include_self=False, depth=1)
542272
function getSiblingsOfAncestors(el) {
    return getAncestors(el).map(item => getSiblings(item)).reduce(flattenArrays, []);
}
863034
def _get_children(node, contexts=False, restrict=None, parent=None):
        """"""
        yield (parent, node) if contexts else node
        if restrict and isinstance(node, restrict):
            return
        for code in node.__children__():
            for child in code.nodes:
                sub = Wikicode._get_children(child, contexts, restrict, code)
                for result in sub:
                    yield result
421539
def weights(self, other):
        
        try:
            return self._wdata(other)
        except AttributeError:
            frequency_dim = other.dimensions[-1]
            return self._wdata(frequency_dim.scale)
649789
function getChildren(obj, name) {
  return _.filter(obj.children, function(child) {
    return child.name == name;
  });
}
573686
def compute_spawn(adjusted_fitness, previous_sizes, pop_size, min_species_size):
        """"""
        af_sum = sum(adjusted_fitness)

        spawn_amounts = []
        for af, ps in zip(adjusted_fitness, previous_sizes):
            if af_sum > 0:
                s = max(min_species_size, af / af_sum * pop_size)
            else:
                s = min_species_size

            d = (s - ps) * 0.5
            c = int(round(d))
            spawn = ps
            if abs(c) > 0:
                spawn += c
            elif d > 0:
                spawn += 1
            elif d < 0:
                spawn -= 1

            spawn_amounts.append(spawn)

        # Normalize the spawn amounts so that the next generation is roughly
        # the population size requested by the user.
        total_spawn = sum(spawn_amounts)
        norm = pop_size / total_spawn
        spawn_amounts = [max(min_species_size, int(round(n * norm))) for n in spawn_amounts]

        return spawn_amounts
142151
def children_sum( self, children,node ):
        """"""
        return sum( [self.value(value,node) for value in children] )
35665
def kids(tup_tree):
    
    k = tup_tree[2]
    if k is None:
        return []
    # pylint: disable=unidiomatic-typecheck
    return [x for x in k if type(x) == tuple]