Returns the scoring vector [1,0,0,...,0]. This function is called by getCandScoresMap()
        which is implemented in the parent class.

        :ivar Profile profile: A Profile object that represents an election profile.
164530
def getScoringVector(self, profile):
        

        scoringVector = []
        scoringVector.append(1)
        for i in range(1, profile.numCands):
            scoringVector.append(0)
        return scoringVector
658686
def profile(self):
    """"""
    leftmost_idx = np.argmax(self.matrix('dense').astype(bool), axis=0)
    return (np.arange(self.num_vertices()) - leftmost_idx).sum()
1172636
def getCandScoresMap(self, profile):
        

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

        wmg = profile.getWmg()

        # Initialize the maximin score for each candidate as infinity.
        maximinScores = dict()
        for cand in wmg.keys():
            maximinScores[cand] = float("inf")

        # For each pair of candidates, calculate the number of times each beats the other.
        for cand1, cand2 in itertools.combinations(wmg.keys(), 2):
            if cand2 in wmg[cand1].keys():
                maximinScores[cand1] = min(maximinScores[cand1], wmg[cand1][cand2])
                maximinScores[cand2] = min(maximinScores[cand2], wmg[cand2][cand1])

        return maximinScores
1027427
double scoreResults() {

		double totalScore = 0;

		for (int i = 0; i < normalizedP.size; i++) {
			DMatrixRMaj P = normalizedP.get(i);
			MultiViewOps.intrinsicFromAbsoluteQuadratic(Q,P,intrinsic);

			double score = 0;

			// skew should be zero
			score += w_sk*Math.abs(intrinsic.skew);
			// aspect ratio unity
			score += w_ar*(Math.max(intrinsic.fx,intrinsic.fy)/Math.min(intrinsic.fx,intrinsic.fy) - 1);
			// principle point zero
			score += w_uo*(Math.abs(intrinsic.cx) + Math.abs(intrinsic.cy));

			totalScore += score;
		}
		return totalScore;
	}
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)
909787
def PluRunOff_cowinners(self, profile):
        

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

        # Initialization
        prefcounts = profile.getPreferenceCounts()
        len_prefcounts = len(prefcounts)
        rankmaps = profile.getRankMaps()
        ranking = MechanismPlurality().getRanking(profile)

        known_winners = set()
        # 1st round: find the top 2 candidates in plurality scores
        top_2_combinations = []
        if len(ranking[0][0]) > 1:
            for cand1, cand2 in itertools.combinations(ranking[0][0], 2):
                top_2_combinations.append([cand1, cand2])
        else:
            max_cand = ranking[0][0][0]
            if len(ranking[0][1]) > 1:
                for second_max_cand in ranking[0][1]:
                    top_2_combinations.append([max_cand, second_max_cand])
            else:
                second_max_cand = ranking[0][1][0]
                top_2_combinations.append([max_cand, second_max_cand])

        # 2nd round: find the candidate with maximum plurality score
        for top_2 in top_2_combinations:
            dict_top2 = {top_2[0]: 0, top_2[1]: 0}
            for i in range(len_prefcounts):
                vote_top2 = {key: value for key, value in rankmaps[i].items() if key in top_2}
                top_position = min(vote_top2.values())
                keys = [x for x in vote_top2.keys() if vote_top2[x] == top_position]
                for key in keys:
                    dict_top2[key] += prefcounts[i]

            max_value = max(dict_top2.values())
            winners = [y for y in dict_top2.keys() if dict_top2[y] == max_value]
            known_winners = known_winners | set(winners)

        return sorted(known_winners)
320151
public double getScore()
    {
        if(sumOfWeights <= 0)
            return 0;
        double score = 0.0;

        if (impurityMeasure == ImpurityMeasure.INFORMATION_GAIN_RATIO
                || impurityMeasure == ImpurityMeasure.INFORMATION_GAIN
                || impurityMeasure == ImpurityMeasure.NMI)
        {
            for (Double count : counts)
            {
                double p = count / sumOfWeights;
                if (p > 0)
                    score += p * log(p) / log(2);
            }
        }
        else if (impurityMeasure == ImpurityMeasure.GINI)
        {
            score = 1;
            for (double count : counts)
            {
                double p = count / sumOfWeights;
                score -= p * p;
            }
        }
        else if (impurityMeasure == ImpurityMeasure.CLASSIFICATION_ERROR)
        {
            double maxClass = 0;
            for (double count : counts)
                maxClass = Math.max(maxClass, count / sumOfWeights);
            score = 1.0 - maxClass;
        }

        return abs(score);
    }

    /**
     * Returns the sum of the weights for all points currently in the impurity 
     * score
     * @return the sum of weights
     */
    public double getSumOfWeights()
    {
        return sumOfWeights;
    }
    
    /**
     * Returns the impurity measure being used 
     * @return the impurity measure being used 
     */
    public ImpurityMeasure getImpurityMeasure()
    {
        return impurityMeasure;
    }
    
    /**
     * Obtains the current categorical results by prior probability 
     * 
     * @return the categorical results for the current score
     */
    public CategoricalResults getResults()
    {
        CategoricalResults cr = new CategoricalResults(counts.length);
        for(int i = 0; i < counts.length; i++)
            cr.setProb(i, counts[i]/sumOfWeights);
        return cr;
    }
    
    /*
     * NOTE: for calulating the entropy in a split, if S is the current set of
     * all data points, and S_i denotes one of the subsets gained from splitting
     * The Gain for a split is
     *
     *                       n
     *                     ===== |S |
     *                     \     | i|
     * Gain = Entropy(S) -  >    ---- Entropy/S \
     *                     /      |S|        \ i/
     *                     =====
     *                     i = 1
     *
     *                   Gain
     * GainRatio = ----------------
     *             SplitInformation
     *
     *                        n
     *                      ===== |S |    /|S |\
     *                      \     | i|    || i||
     * SplitInformation = -  >    ---- log|----|
     *                      /      |S|    \ |S|/
     *                      =====
     *                      i = 1
     */
    
    /**
     * Computes the gain in score from a splitting of the data set
     * 
     * @param wholeData the score for the whole data set
     * @param splits the scores for each of the splits
     * @return the gain for the values given
     */
    public static double gain(ImpurityScore wholeData, ImpurityScore... splits)
    {
        return gain(wholeData, 1.0, splits);
    }
    
    /**
     * Computes the gain in score from a splitting of the data set
     * 
     * @param wholeData the score for the whole data set
     * @param wholeScale a constant to scale the wholeData counts and sums by, useful for handling missing value cases
     * @param splits the scores for each of the splits
     * @return the gain for the values given
     */
    public static double gain(ImpurityScore wholeData, double wholeScale, ImpurityScore... splits)
    {
        double sumOfAllSums = wholeScale*wholeData.sumOfWeights;
        
        if(splits[0].impurityMeasure == ImpurityMeasure.NMI)
        {
            double mi = 0, splitEntropy = 0.0, classEntropy = 0.0;
            
            for(int c = 0; c < wholeData.counts.length; c++)//c: class
            {
                final double p_c = wholeScale*wholeData.counts[c]/sumOfAllSums;
                if(p_c <= 0.0)
                    continue;
                
                double logP_c = log(p_c);
                
                classEntropy += p_c*logP_c;
                        
                for(int s = 0; s < splits.length; s++)//s: split
                {
                    final double p_s = splits[s].sumOfWeights/sumOfAllSums;
                    if(p_s <= 0)
                        continue;
                    final double p_cs = splits[s].counts[c]/sumOfAllSums;
                    if(p_cs <= 0)
                        continue;
                    
                    mi += p_cs * (log(p_cs) - logP_c - log(p_s));
                    
                    if(c == 0)
                        splitEntropy += p_s * log(p_s);
                }
            }
            
            splitEntropy = abs(splitEntropy);
            classEntropy = abs(classEntropy);
            
            return 2*mi/(splitEntropy+classEntropy);
            
        }
        //Else, normal cases
        double splitScore = 0.0;
        
        boolean useSplitInfo = splits[0].impurityMeasure == ImpurityMeasure.INFORMATION_GAIN_RATIO;
        
        if(useSplitInfo)
        {
            /*
             * TODO should actualy be 0, but performance bug is consistently 
             * occuring if I use another value. Needs serious investigation. 
             * I was testing on (Oracle) 1.7u51 & u20 smoething and both had the
             * issue, on OSX and Windows. 
             * 
             * I was unable to replicate the issue with a smaller self contained
             * program. So I suspect I might be at some threshold / corner case 
             * of the optimizer
             * 
             * Adding a -1 at the final results causes the performance 
             * degredation agian. Occures with both client and server JVM
             * 
             * Using the same code with an if stament seperating the 2 (see old revision) was originally backwards. Changing the correct way revealed the behavior. I'm leaving them seperated to ease investiation later. 
             */
            double splitInfo = 1.0;
            for(ImpurityScore split : splits)
            {
                double p = split.getSumOfWeights()/sumOfAllSums;
                if(p <= 0)//log(0) is -Inft, so skip and treat as zero
                    continue;
                splitScore += p * split.getScore();
                splitInfo += p * -log(p);
            }

            return (wholeData.getScore()-splitScore)/splitInfo;
        }
        else
        {
            for(ImpurityScore split : splits)
            {
                double p = split.getSumOfWeights()/sumOfAllSums;
                if(p <= 0)//log(0) is -Inft, so skip and treat as zero
                    continue;
                splitScore += p*split.getScore();
            }

            return wholeData.getScore()-splitScore;
        }
        
    }
    
    @Override
    protected ImpurityScore clone()
    {
        return new ImpurityScore(this);
    }
}
1087003
private double getScore(ArrayList candidateList) {
    matched = 0;
    largestIndex = -1;
    double scoreValue = 0;
    HashMap tMap = new HashMap(),
        uMap = new HashMap();
    java.util.Iterator it = candidateList.iterator();
    while (it.hasNext()) {
      TagLink.Candidates actualCandidates = (TagLink.Candidates) it.next();
      Integer actualTPos = new Integer(actualCandidates.getTPos()),
          actualUPos = new Integer(actualCandidates.getUPos());
      if ( (!tMap.containsKey(actualTPos)) &&
          (!uMap.containsKey(actualUPos))) {
        double actualScore = actualCandidates.getScore();
        scoreValue += actualScore;
        tMap.put(actualTPos, null);
        uMap.put(actualUPos, null);
        if (largestIndex < actualTPos.intValue()) {
          largestIndex = actualTPos.intValue();
        }
        matched++;
      }
    }
    return scoreValue;
  }
247732
def getCandScoresMapBruteForce(self, profile):
        

        wmg = profile.getWmg(True)
        m = len(wmg.keys())
        cands = range(m)
        V = self.createBinaryRelation(m)
        gains = dict()
        for cand in wmg.keys():
            gains[cand] = 0
        graphs = itertools.product(range(2), repeat=m*(m-1)/2)
        for comb in graphs:
            prob = 1
            i = 0
            for a, b in itertools.combinations(cands,2):
                V[a][b] = comb[i]
                V[b][a] = 1-comb[i]
                if comb[i] > 0:
                    prob *= 1/(1+self.phi ** float(wmg[a+1][b+1]))
                else:
                    prob *= 1/(1+self.phi ** float(wmg[b+1][a+1]))
                i += 1
                if i >= m*(m-1)/2:
                    break
            for cand in wmg.keys():
                gains[cand] += self.utilityFunction.getUtility([cand], V)*prob
        return gains
1339453
def getMov(self, profile):
        
        # from . import mov
        import mov
        return mov.MoVScoring(profile, self.getScoringVector(profile))
1115961
public Vector getFeatureVector(Lexicon lexicon,
			Parameters.WeightingMethod method, Map<Integer, Integer> equiv) {
		// we need to iterate on the features
		// of this document and compute a score
		double numDocs = (double) lexicon.getDocNum();
		int kept = 0;
		double[] copyvalues = new double[indices.length];
		
		// have the attribute numbers been changed in
		// the meantime?
		if (equiv != null) {
			for (int pos = 0; pos < indices.length; pos++) {
				Integer newPos = equiv.get(indices[pos]);
				// filtered
				if (newPos == null)
					indices[pos] = Integer.MAX_VALUE;
				else 
					indices[pos] = newPos.intValue();
			}
			// resort the arrays
			quicksort(indices, freqs, 0, indices.length - 1);
		}
		
		for (int pos = 0; pos < indices.length; pos++) {
			// need to check that a given term has not
			// been filtered since the creation of the corpus
			// the indices are sorted so we know there is no point
			// in going further
			// Integer.MAX_VALUE == unknown in model
			if (indices[pos] == Integer.MAX_VALUE) {
				break;
			}		
			if (lexicon.getDocFreq(indices[pos]) <= 0)
				continue;
			double score = getScore(pos, lexicon, method, numDocs);
			copyvalues[pos] = score;
			kept++;
		}
		// trim to size
		int[] trimmedindices = new int[kept];
		double[] trimmedvalues = new double[kept];

		// normalize the values?
		if (lexicon.isNormalizeVector())
			normalizeL2(trimmedvalues);

		System.arraycopy(indices, 0, trimmedindices, 0, kept);
		System.arraycopy(copyvalues, 0, trimmedvalues, 0, kept);
		return new Vector(trimmedindices, trimmedvalues);
	}
434382
private int getLeastScore(Collection<String> ids)
	{
		int s = Integer.MAX_VALUE;

		for (String id : ids)
		{
			if (score.get(id) < s) s = score.get(id);
		}

		return s;
	}
805436
def getCandScoresMap(self, profile):
        

        wmg = profile.getWmg(True)
        V = self.getInitialSample(wmg)

        utilities = dict()
        for cand in profile.candMap.keys():
            utilities[cand] = 0.0

        for i in range(0, self.burnIn):
            V = self.sampleGenerator.getNextSample(V)

        for i in range(0, self.n2):
            for j in range(0, self.n1):
                V = self.sampleGenerator.getNextSample(V)
            for cand in profile.candMap.keys():
                utilities[cand] += self.utilityFunction.getUtility([cand], V)

        for cand in profile.candMap.keys():
            utilities[cand] = utilities[cand]/self.n2

        return utilities
343131
def Borda_mean_winners(self, profile):
        
        n_candidates = profile.numCands
        prefcounts = profile.getPreferenceCounts()
        len_prefcounts = len(prefcounts)
        rankmaps = profile.getRankMaps()
        values = zeros([len_prefcounts, n_candidates], dtype=int)
        if min(list(rankmaps[0].keys())) == 0:
            delta = 0
        else:
            delta = 1
        for i in range(len_prefcounts):
            for j in range(delta, n_candidates + delta):
                values[i][j - delta] = rankmaps[i][j]
        # print("values=", values)
        mat0 = self._build_mat(values, n_candidates, prefcounts)
        borda = [0 for i in range(n_candidates)]
        for i in range(n_candidates):
            borda[i] = sum([mat0[i, j] for j in range(n_candidates)])
        borda_mean = mean(borda)
        bin_winners_list = [int(borda[i] >= borda_mean) for i in range(n_candidates)]
        return bin_winners_list
679592
public static Last[][] setScoreVector(int x, int xb, int yb, int ye, int gop, int gep, int[] subs,
			boolean storing, int[][][] scores, boolean startAnchored) {
		Last[][] pointers = new Last[ye + 1][];
		int min = Integer.MIN_VALUE - gop - gep;
		ensureScoringMatrixColumn(x, storing, scores);
		if (x == xb) {
			scores[xb][yb][1] = scores[xb][yb][2] = gop;
			pointers[yb] = new Last[] {null, null, null};
			if (startAnchored) {
				assert (xb > 0 && yb > 0);
				int subproblemStartingScore = scores[xb - 1][yb - 1][0] + subs[yb];
				scores[xb][yb][0] = subproblemStartingScore;
				scores[xb][yb][1] = subproblemStartingScore + gop;
				scores[xb][yb][2] = subproblemStartingScore + gop;
				pointers[yb] = new Last[] {Last.SUBSTITUTION, Last.SUBSTITUTION, Last.SUBSTITUTION};
			}
			Last[] insertion = new Last[] { null, null, Last.INSERTION };
			for (int y = yb + 1; y <= ye; y++) {
				scores[xb][y][0] = scores[xb][y][1] = min;
				scores[xb][y][2] = scores[xb][y - 1][2] + gep;
				pointers[y] = insertion;
			}
		} else {
			scores[x][yb][0] = scores[x][yb][2] = min;
			scores[x][yb][1] = scores[x - 1][yb][1] + gep;
			pointers[yb] = new Last[] { null, Last.DELETION, null };
			for (int y = yb + 1; y <= ye; y++) {
				pointers[y] = setScorePoint(x, y, gop, gep, subs[y], scores);
			}
		}
		return pointers;
	}
773733
private int scorerIndex(int n)
   {
      int lo = 0; // search starts array
      int hi = scorers.length - 1; // for first element less

      while (hi >= lo)
      {
         int mid = (lo + hi) >> 1;
         int midValue = starts[mid];
         if (n < midValue)
         {
            hi = mid - 1;
         }
         else if (n > midValue)
         {
            lo = mid + 1;
         }
         else
         { // found a match
            while (mid + 1 < scorers.length && starts[mid + 1] == midValue)
            {
               mid++; // scan to last match
            }
            return mid;
         }
      }
      return hi;
   }
150345
public double[][] getScoreMatrix() {
		double[][] matrix = new double[sequences.size()][sequences.size()];
		for (int i = 0, n = 0; i < matrix.length; i++) {
			matrix[i][i] = scorers.get(i).getMaxScore();
			for (int j = i+1; j < matrix.length; j++) {
				matrix[i][j] = matrix[j][i] = scorers.get(n++).getScore();
			}
		}
		return matrix;
	}