TODO: pick an alpha with fewer candidates to go through
435010
def initial_fill alpha
      alpha_top.wmes.each do |wme|
        alpha.activate wme if wme =~ alpha.template
      end
    end
1273697
def select_event(
    event                             = None,
    selection                         = "all",
    required_variables                = None,
    ensure_required_variables_present = False,
    verbose                           = True
    ):

    

    if required_variables is None:
        required_variables = [
            "Aplan_bjets",
            "Aplan_jets",
            "Centrality_all",
            "ClassifBDTOutput_6jsplit",
            "ClassifBDTOutput_basic",
            "ClassifBDTOutput_withReco_6jsplit",
            "ClassifBDTOutput_withReco_basic",
            "ClassifHPLUS_Semilep_HF_BDT200_Output",
            "dEtajj_MaxdEta",
            "dRbb_avg",
            "dRbb_MaxM",
            "dRbb_MaxPt",
            "dRbb_min",
            "dRbj_Wmass",
            "dRHl_MaxdR",
            "dRHl_MindR",
            "dRjj_min",
            "dRlepbb_MindR",
            "dRlj_MindR",
            "dRuu_MindR",
            "H1_all",
            "H4_all",
            "HhadT_nJets",
            "HiggsbbM",
            "HiggsjjM",
            "HT_all",
            "HT_jets",
            "Mbb_MaxM",
            "Mbb_MaxPt",
            "Mbb_MindR",
            "Mbj_MaxPt",
            "Mbj_MindR",
            "Mbj_Wmass",
            "met_met",
            "met_phi",
            "MHiggs",
            "Mjj_HiggsMass",
            "Mjjj_MaxPt",
            "Mjj_MaxPt",
            "Mjj_MindR",
            "Mjj_MinM",
            "mu",
            "Muu_MindR",
            "NBFricoNN_dil",
            "nBTags",
            "nBTags30",
            "nBTags50",
            "nBTags60",
            "nBTags70",
            "nBTags77",
            "nBTags80",
            "nBTags85",
            "nBTags90",
            "nBTagsFlatBEff_30",
            "nBTagsFlatBEff_40",
            "nBTagsFlatBEff_50",
            "nBTagsFlatBEff_60",
            "nBTagsFlatBEff_70",
            "nBTagsFlatBEff_77",
            "nBTagsFlatBEff_85",
            "nElectrons",
            "nHFJets",
            "NHiggs_30",
            "Njet_pt40",
            "Njet_pt40",
            "nJets",
            "nMuons",
            "nPrimaryVtx",
            "pT_jet3",
            "pT_jet5",
            "pTuu_MindR",
            "semilepMVAreco_b1higgsbhadtop_dR",
            "semilepMVAreco_bbhiggs_dR",
            "semilepMVAreco_BDT_output",
            "semilepMVAreco_BDT_output_6jsplit",
            "semilepMVAreco_BDT_output_truthMatchPattern",
            "semilepMVAreco_BDT_withH_output",
            "semilepMVAreco_BDT_withH_output_6jsplit",
            "semilepMVAreco_BDT_withH_output_truthMatchPattern",
            "semilepMVAreco_hadWb1Higgs_mass",
            "semilepMVAreco_higgsbhadtop_withH_dR",
            "semilepMVAreco_higgsbleptop_mass",
            "semilepMVAreco_higgsbleptop_withH_dR",
            "semilepMVAreco_higgslep_dR",
            "semilepMVAreco_higgsleptop_dR",
            "semilepMVAreco_higgs_mass",
            "semilepMVAreco_higgsq1hadW_mass",
            "semilepMVAreco_higgsttbar_withH_dR",
            "semilepMVAreco_leptophadtop_dR",
            "semilepMVAreco_leptophadtop_withH_dR",
            "semilepMVAreco_Ncombinations",
            "semilepMVAreco_nuApprox_recoBDT",
            "semilepMVAreco_nuApprox_recoBDT_6jsplit",
            "semilepMVAreco_nuApprox_recoBDT_withH",
            "semilepMVAreco_nuApprox_recoBDT_withH_6jsplit",
            "semilepMVAreco_ttH_Ht_withH",
            #"ttHF_mva_discriminant",
            "el_d0sig[0]",
            "el_delta_z0_sintheta[0]",
            "el_e[0]",
            "el_eta[0]",
            "el_phi[0]",
            "el_pt[0]",
            "el_topoetcone20[0]",
            #"mu_d0sig[0]",
            #"mu_delta_z0_sintheta[0]",
            #"mu_e[0]",
            #"mu_eta[0]",
            #"mu_phi[0]",
            #"mu_pt[0]",
            "mu_topoetcone20[0]",
            "jet_e[0]",
            "jet_eta[0]",
            "jet_jvt[0]",
            "jet_mv2c10[0]",
            "jet_mv2c20[0]",
            "jet_phi[0]",
            "jet_pt[0]",
            "jet_semilepMVAreco_recoBDT_cand[0]",
            "jet_semilepMVAreco_recoBDT_cand_6jsplit[0]",
            "jet_semilepMVAreco_recoBDT_withH_cand[0]",
            "jet_semilepMVAreco_recoBDT_withH_cand_6jsplit[0]",
            "jet_e[1]",
            "jet_eta[1]",
            "jet_jvt[1]",
            "jet_mv2c10[1]",
            "jet_mv2c20[1]",
            "jet_phi[1]",
            "jet_pt[1]",
            "jet_semilepMVAreco_recoBDT_cand[1]",
            "jet_semilepMVAreco_recoBDT_cand_6jsplit[1]",
            "jet_semilepMVAreco_recoBDT_withH_cand[1]",
            "jet_semilepMVAreco_recoBDT_withH_cand_6jsplit[1]",
            "jet_e[2]",
            "jet_eta[2]",
            "jet_jvt[2]",
            "jet_mv2c10[2]",
            "jet_mv2c20[2]",
            "jet_phi[2]",
            "jet_pt[2]",
            "jet_semilepMVAreco_recoBDT_cand[2]",
            "jet_semilepMVAreco_recoBDT_cand_6jsplit[2]",
            "jet_semilepMVAreco_recoBDT_withH_cand[2]",
            "jet_semilepMVAreco_recoBDT_withH_cand_6jsplit[2]",
            "jet_e[3]",
            "jet_eta[3]",
            "jet_jvt[3]",
            "jet_mv2c10[3]",
            "jet_mv2c20[3]",
            "jet_phi[3]",
            "jet_pt[3]",
            "jet_semilepMVAreco_recoBDT_cand[3]",
            "jet_semilepMVAreco_recoBDT_cand_6jsplit[3]",
            "jet_semilepMVAreco_recoBDT_withH_cand[3]",
            "jet_semilepMVAreco_recoBDT_withH_cand_6jsplit[3]"
        ]

    if ensure_required_variables_present and not all([hasattr(event, variable) for variable in required_variables]):

        return False

    #for variable in required_variables:
    #    if not hasattr(event, variable):
    #        print("missing {variable}".format(variable = variable))

    # By default, do not pass.
    conditions = [False]

    if selection == "ejets":

        conditions = [
            event.nElectrons == 1,                      # Require 1 electron.
            event.nJets >= 4,                           # Require >= 4 jets.
            #event.nLjets >= 1                          # Require a single large-R jet.
        ]

    elif selection == "mujets":

        conditions = [
            event.nMuons == 1,                          # Require 1 muon.
            event.nJets >= 4,                           # Require >= 4 jets.
            #event.nLjets >= 1                          # Require a single large-R jet.
        ]

    if selection == "ejets_5JE4BI":

        conditions = [
            event.nElectrons == 1,                      # Require 1 electron.
            event.nJets == 5,                           # Require 5 jets.
            event.nBTags >= 4                           # Require >= 4 b tags.
            #event.nLjets >= 1                          # Require a single large-R jet.
        ]

    if selection == "ejets_6JI4BI":

        conditions = [
            event.nElectrons == 1,                      # Require 1 electron.
            event.nJets >= 6,                           # Require >=6 jets.
            event.nBTags >= 4                           # Require >= 4 b tags.
            #event.nLjets >= 1                          # Require a single large-R jet.
        ]

    elif selection == "all":

        conditions = [
            event.nElectrons == 1 or event.nMuons == 1, # Require 1 electron or 1 muon.
            event.nJets >= 4,                           # Require >= 4 jets.
            #event.nLjets >= 1                          # Require a single large-R jet.
        ]

    if all(conditions):

        if verbose:
            log.info("event number {event_number} passed selection {selection}".format(
                event_number = event.eventNumber,
                selection    = selection
            ))

        return True

    else:

        return False
1281744
def sample_less_than_condition(choices_in, condition):
    
    output = np.zeros(min(condition.shape[0], choices_in.shape[0]))
    choices = copy.deepcopy(choices_in)
    for i, _ in enumerate(output):
        # randomly select one of the choices which meets condition
        avail_inds = np.where(choices < condition[i])[0]
        selected_ind = np.random.choice(avail_inds)
        output[i] = choices[selected_ind]
        # remove the chosen value
        choices = np.delete(choices, selected_ind)
    return output
740316
private ISeq<Phenotype<G, C>>
	selectSurvivors(final ISeq<Phenotype<G, C>> population) {
		return _survivorsCount > 0
			?_survivorsSelector.select(population, _survivorsCount, _optimize)
			: ISeq.empty();
	}
881195
def select(self, html, stype, expression):
        """"""
        etree = html5lib.parse(html,
                               treebuilder='lxml',
                               namespaceHTMLElements=False)
        if stype == 'css':
            selector = lxml.cssselect.CSSSelector(expression)
            frag = list(selector(etree))
        else:
            frag = etree.xpath(expression)
        if not frag:
            raise RuntimeError("Nothing found for: %s" % expression)
        return "".join([lxml.etree.tostring(x) for x in frag])
119146
def _ln_choose(n, k_agg):
    '''
    

    '''
    gammaln = special.gammaln
    return gammaln(n + 1) - (gammaln(k_agg + 1) + gammaln(n - k_agg + 1))
1121787
function() {
      this.candidates = []; // flush, if any
      for(var i=0;i<this.num_candidates;i++) {
        var cand = this.sampleCandidate();
        this.candidates.push(cand);
      }
    }
705031
function brighten(alpha) {
		if (isNumber(alpha) && alpha !== 0) {
			var i;
			for (i = 0; i < 3; i++) {
				rgba[i] += pInt(alpha * 255);

				if (rgba[i] < 0) {
					rgba[i] = 0;
				}
				if (rgba[i] > 255) {
					rgba[i] = 255;
				}
			}
		}
		return this;
	}
257546
static String firstNonEmpty(String... candidates) {
    for (String s : candidates) {
      if (!isEmpty(s)) {
        return s;
      }
    }
    return null;
  }
556655
def select(self, **kws):
        '''
            
        '''
        lst = [i for i in self.values() if i.select(**kws)]

        random.shuffle(lst)

        return lst
1042784
void alphaFunction(double alpha[], List<Double> x, int dim, int type) {
    if (dim == 2) {
      if (type == 21) {
        alpha[0] = x.get(0);
        alpha[1] = 1 - Math.sqrt(x.get(0));
      }

      if (type == 22) {
        alpha[0] = x.get(0);
        alpha[1] = 1 - x.get(0) * x.get(0);
      }

      if (type == 23) {
        alpha[0] = x.get(0);
        alpha[1] = 1 - Math.sqrt(alpha[0]) - alpha[0]
          * Math.sin(10 * alpha[0] * alpha[0] * Math.PI);
      }

      if (type == 24) {
        alpha[0] = x.get(0);
        alpha[1] = 1 - x.get(0) - 0.05 * Math.sin(4 * Math.PI * x.get(0));
      }
    } else {
      if (type == 31) {
        alpha[0] = Math.cos(x.get(0) * Math.PI / 2) * Math.cos(x.get(1) * Math.PI / 2);
        alpha[1] = Math.cos(x.get(0) * Math.PI / 2) * Math.sin(x.get(1) * Math.PI / 2);
        alpha[2] = Math.sin(x.get(0) * Math.PI / 2);
      }

      if (type == 32) {
        alpha[0] = 1 - Math.cos(x.get(0) * Math.PI / 2)
          * Math.cos(x.get(1) * Math.PI / 2);
        alpha[1] = 1 - Math.cos(x.get(0) * Math.PI / 2)
          * Math.sin(x.get(1) * Math.PI / 2);
        alpha[2] = 1 - Math.sin(x.get(0) * Math.PI / 2);
      }

      if (type == 33) {
        alpha[0] = x.get(0);
        alpha[1] = x.get(1);
        alpha[2] = 3
          - (Math.sin(3 * Math.PI * x.get(0)) + Math.sin(3 * Math.PI * x.get(1))) - 2
          * (x.get(0) + x.get(1));
      }

      if (type == 34) {
        alpha[0] = x.get(0) * x.get(1);
        alpha[1] = x.get(0) * (1 - x.get(1));
        alpha[2] = (1 - x.get(0));
      }
    }
  }
145357
function selectWithoutValidation(choices) {
	// Generate a list of options with positive non-zero chances
	let choicesWithNonZeroChances = [];
	let totalWeight = 0.0;
	for(let i = 0; i < choices.length; i++) {
		if(choices[i].chance > 0.0) {
			choicesWithNonZeroChances.push(choices[i]);
			totalWeight += choices[i].chance;
		}
	}

	// Pick a random value from [0,1)
	let value = Math.random() * totalWeight;

	// Iterate over possibilities until we find the selected one
	let chanceCovered = 0.0;
	for(let i = 0; i < choicesWithNonZeroChances.length; i++) {
		chanceCovered += choicesWithNonZeroChances[i].chance;
		if(value < chanceCovered) {
			return choicesWithNonZeroChances[i].result;
		}
	}
}
485626
def randomize(length=6, choices=None):
    """"""
    if type(choices) == str:
        choices = list(choices)
    choices = choices or ascii_lowercase
    return "".join(choice(choices) for _ in range(length))
436345
def select(method, choices = nil, options = {}, html_options = {}, &block)
      choices = instance_exec(&choices) if choices.is_a?(Proc)
      super
    end
354223
def choice(self, board: Union[chess.Board, int], *, minimum_weight: int = 1, exclude_moves: Container[chess.Move] = (), random=random) -> Entry:
        
        chosen_entry = None

        for i, entry in enumerate(self.find_all(board, minimum_weight=minimum_weight, exclude_moves=exclude_moves)):
            if chosen_entry is None or random.randint(0, i) == i:
                chosen_entry = entry

        if chosen_entry is None:
            raise IndexError()

        return chosen_entry
745643
def AppMoVCopeland(profile, alpha=0.5):
    

    # Currently, we expect the profile to contain complete ordering over candidates.
    elecType = profile.getElecType()
    if elecType != "soc" and elecType != "toc":
        print("ERROR: unsupported profile type")
        exit()

    # Initialization
    n = profile.numVoters
    m = profile.numCands

    # Compute the original winner d
    # Initialize each Copeland score as 0.0.
    copelandscores = {}
    for cand in profile.candMap.keys():
        copelandscores[cand] = 0.0

    # For each pair of candidates, calculate the number of votes in which one beat the other.
    wmgMap = profile.getWmg()
    for cand1, cand2 in itertools.combinations(wmgMap.keys(), 2):
        if cand2 in wmgMap[cand1].keys():
            if wmgMap[cand1][cand2] > 0:
                copelandscores[cand1] += 1.0
            elif wmgMap[cand1][cand2] < 0:
                copelandscores[cand2] += 1.0

            # If a pair of candidates is tied, we add alpha to their score for each vote.
            else:
                copelandscores[cand1] += alpha
                copelandscores[cand2] += alpha
    d = max(copelandscores.items(), key=lambda x: x[1])[0]

    #Compute c* = argmin_c RM(d,c)
    relative_margin = {}
    alter_without_d = delete(range(1, m + 1), d - 1)
    for c in alter_without_d:
        relative_margin[c] = RM(wmgMap, n, m, d, c, alpha)
    c_star = min(relative_margin.items(), key=lambda x: x[1])[0]

    return relative_margin[c_star]*(math.ceil(log(m)) + 1)
1291440
function alpha(req) {
  var name = undefsafe(req, 'session.user.name');
  if (name) {
    return alphausers.indexOf(name) !== -1;
  }
  return false;
}