Description:
        Top 2 alternatives 16 moment conditions values calculation
    Parameters:
        votes: ordinal preference data (numpy ndarray of integers)
162785
def top2_full(votes):
    
    res = np.zeros(16)
    for vote in votes:
        # the top ranked alternative is in vote[0][0], second in vote[1][0]
        if vote[0][0] == 0: # i.e. the first alt is ranked first
            res[0] += 1
            if vote[1][0] == 1: # i.e. the second alt is ranked second
                res[4] += 1
            elif vote[1][0] == 2:
                res[5] += 1
            elif vote[1][0] == 3:
                res[6] += 1
        elif vote[0][0] == 1:
            res[1] += 1
            if vote[1][0] == 0:
                res[7] += 1
            elif vote[1][0] == 2:
                res[8] += 1
            elif vote[1][0] == 3:
                res[9] += 1
        elif vote[0][0] == 2:
            res[2] += 1
            if vote[1][0] == 0:
                res[10] += 1
            elif vote[1][0] == 1:
                res[11] += 1
            elif vote[1][0] == 3:
                res[12] += 1
        elif vote[0][0] == 3:
            res[3] += 1
            if vote[1][0] == 0:
                res[13] += 1
            elif vote[1][0] == 1:
                res[14] += 1
            elif vote[1][0] == 2:
                res[15] += 1
    res /= len(votes)
    return res
199345
async def _rank_text(self, choices):
        

        tl = self.request.get_layer(l.RawText)
        best = 0.0

        for slug, params in choices.items():
            strings = []

            if params['intent']:
                intent = getattr(intents, params['intent'])
                strings += await intent.strings(self.request)

            if params['text']:
                strings.append((params['text'],))

            matcher = Matcher([tuple(Trigram(y) for y in x) for x in strings])
            score = matcher % Trigram(await render(tl.text, self.request))

            if score > best:
                self.chosen = params
                self.slug = slug
                best = score

        if self.when is None or self.slug == self.when:
            return best
710367
def rtruncated_pareto(alpha, m, b, size=None):
    
    u = random_number(size)
    return (-(u * b ** alpha - u * m ** alpha - b ** alpha) /
            (b ** alpha * m ** alpha)) ** (-1. / alpha)
1019029
def ordinal(self, num):
        
        if re.match(r"\d", str(num)):
            try:
                num % 2
                n = num
            except TypeError:
                if "." in str(num):
                    try:
                        # numbers after decimal,
                        # so only need last one for ordinal
                        n = int(num[-1])

                    except ValueError:  # ends with '.', so need to use whole string
                        n = int(num[:-1])
                else:
                    n = int(num)
            try:
                post = nth[n % 100]
            except KeyError:
                post = nth[n % 10]
            return "{}{}".format(num, post)
        else:
            mo = re.search(r"(%s)\Z" % ordinal_suff, num)
            try:
                post = ordinal[mo.group(1)]
                return re.sub(r"(%s)\Z" % ordinal_suff, post, num)
            except AttributeError:
                return "%sth" % num
195260
def get_choices(cls, condition=None, order_by=None, query=None, value_field=None, text_field=None):
        
        result = []
        if query is None:
            query = cls.filter(condition).order_by(order_by)
        for row in query:
            if not value_field:
                value = row._key
            else:
                value = getattr(row, value_field)
            if not text_field:
                text = unicode(row)
            else:
                text = getattr(row, text_field)
            result.append((value, text))
        return result
890418
def _choicerank(n_items, data, params):
    """"""
    weights = exp_transform(params)
    adj, adj_t, traffic_in, traffic_out = data
    # First phase of message passing.
    zs = adj.dot(weights)
    # Second phase of message passing.
    with np.errstate(invalid="ignore"):
        denoms = adj_t.dot(traffic_out / zs)
    return traffic_in, denoms
434450
def weighted_choice(self, probabilities, key):
        """"""

        try:
            choice = self.values[key].lower()
        except KeyError:
            # override not set.
            result = super(OverridableParameters, self)\
                .weighted_choice(probabilities, key)
            if hasattr(result, "__call__"):
                self.results[key] = result.__name__
            else:
                self.results[key] = str(result)
            return result

        # Find the matching key (case insensitive)
        for probability, option in probabilities:
            if str(option).lower() == choice:
                self.results[key] = option
                return option

        # for function or class-type choices, also check __name__
        for probability, option in probabilities:
            if option.__name__.lower() == choice:
                self.results[key] = option.__name__
                return option

        assert False, "Invalid value provided"
219995
def _human_score_map(human_consensus, methods_attrs):
    

    v = 1 - min(np.sum(np.abs(methods_attrs - human_consensus)) / (np.abs(human_consensus).sum() + 1), 1.0)
    return v
734651
def vote(self, upvote, id, remote_addr):
        """"""

        rv = self.db.execute(
            'SELECT likes, dislikes, voters FROM comments WHERE id=?', (id, )) \
            .fetchone()

        if rv is None:
            return None

        likes, dislikes, voters = rv
        if likes + dislikes >= 142:
            return {'likes': likes, 'dislikes': dislikes}

        bf = Bloomfilter(bytearray(voters), likes + dislikes)
        if remote_addr in bf:
            return {'likes': likes, 'dislikes': dislikes}

        bf.add(remote_addr)
        self.db.execute([
            'UPDATE comments SET',
            '    likes = likes + 1,' if upvote else 'dislikes = dislikes + 1,',
            '    voters = ?'
            'WHERE id=?;'], (buffer(bf.array), id))

        if upvote:
            return {'likes': likes + 1, 'dislikes': dislikes}
        return {'likes': likes, 'dislikes': dislikes + 1}
135331
private double computeStabilityIndex(){
    	
    	int m = (int)Math.floor((this.ensemble.length-MAXPERMANENT)/2);
    	int[][] votes=new int[m][tau_size];
    	double errors=0;
    	int count=0;
   
    	
    	Pair[] arr = getHalf(true);
    	
    	for (int i=0;i<m;i++){
    		for (int j=0;j<tau_size;j++){
    			votes[i][j]=Utils.maxIndex(this.ensemble[arr[i].index].getVotesForInstance(recentChunk.get(j)));
    			errors+=(votes[i][j]==(int) this.recentChunk.get(j).classValue())?0:1;
    			count++;
    		}
    	}
    	errors = errors/count;

    	double res=0;  count=0;
    	for (int i=0;i<m;i++)
        	for (int j=i+1;j<m;j++)
        		if (i!=j){
        			res+=computeKappa(votes[i],votes[j]);
        			count++;	
        		}

    	return res/count-errors;
    }
384891
def nvalues(self):
        """"""
        if self._nvalues is None:
            self._nvalues = 0
            for val in self.values:
                if type(val) == type(int):
                    self._nvalues += val
                else:
                    self._nvalues = -1
                    break

        return self._nvalues
287752
def recommend(self, userid, user_items,
                  N=10, filter_already_liked_items=True, filter_items=None, recalculate_user=False):
        
        if userid >= user_items.shape[0]:
            raise ValueError("userid is out of bounds of the user_items matrix")

        # recalculate_user is ignored because this is not a model based algorithm
        items = N
        if filter_items:
            items += len(filter_items)

        indices, data = self.scorer.recommend(userid, user_items.indptr, user_items.indices,
                                              user_items.data, K=items,
                                              remove_own_likes=filter_already_liked_items)
        best = sorted(zip(indices, data), key=lambda x: -x[1])

        if not filter_items:
            return best

        liked = set(filter_items)
        return list(itertools.islice((rec for rec in best if rec[0] not in liked), N))
919511
def top3_reduced(votes):
    
    res = np.zeros(16)
    for vote in votes:
        # the top ranked alternative is in vote[0][0], second in vote[1][0]
        if vote[0][0] == 0: # i.e. the first alt is ranked first
            res[0] += 1
            if vote[1][0] == 2:
                res[4] += 1
            elif vote[1][0] == 3:
                res[5] += 1
            elif vote[1][0] == 1 and vote[2][0] == 2:
                res[14] += 1
        elif vote[0][0] == 1:
            res[1] += 1
            if vote[1][0] == 0:
                res[6] += 1
            elif vote[1][0] == 3:
                res[7] += 1
            elif vote[1][0] == 2 and vote[2][0] == 3:
                res[15] += 1
        elif vote[0][0] == 2:
            res[2] += 1
            if vote[1][0] == 0:
                res[8] += 1
            elif vote[1][0] == 1:
                res[9] += 1
            elif vote[1][0] == 3 and vote[2][0] == 0:
                res[12] += 1
        elif vote[0][0] == 3:
            res[3] += 1
            if vote[1][0] == 1:
                res[10] += 1
            elif vote[1][0] == 2:
                res[11] += 1
            elif vote[1][0] == 0 and vote[2][0] == 1:
                res[13] += 1
    res /= len(votes)
    return res
497651
def choice(self,arr):
    
    ind = self.randint(0,len(arr)-1)
    return arr[ind]
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
424937
def vote_total(self):
        
        modelbase_obj = self.modelbase_obj
        return modelbase_obj.votes.filter(vote=+1).count() - modelbase_obj.votes.filter(vote=-1).count()
918647
def _compute_results(self):
        
        self.Y_best = best_value(self.Y)
        self.x_opt = self.X[np.argmin(self.Y),:]
        self.fx_opt = np.min(self.Y)