/* * Copyright 2004 The Apache Software Foundation. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ package org.apache.commons.math.stat.mining; import java.util.Arrays; import java.util.Set; import java.util.TreeSet; /** * Concrete class of Ranking Algorithm, who is responsible for ranking an array of data. * This class handles ties, or duplicate raw data, by assigning the all duplicate data the * same rank as the corresponding distinct value. For instance if we pass in the following list, * {1, 4, 2, 2, 1}, we would expect the Ranking Algorithm to return an array of ranks {1, 3, 2, 2, 1}. * This shows that all ties, of a raw value, are given the same rank. */ public class TiesEquivalentRank implements RankingAlgorithm{ /** * Ranks an array of data, while all ties of a given value are assigned an equal rank. * * @param data Input array of raw data to be ranked. */ public double[] rank(double[] data) { /* * simple rank algorithm * 1. Separate data * a. Distinct values in set. * 2. Order set * 3. Itertate through intial data, grabbing index from set */ //separate data, add only distinct values to the set Set dataSet = new TreeSet(); for(int i=0; i