001/*
002 * Licensed to the Apache Software Foundation (ASF) under one or more
003 * contributor license agreements.  See the NOTICE file distributed with
004 * this work for additional information regarding copyright ownership.
005 * The ASF licenses this file to You under the Apache License, Version 2.0
006 * (the "License"); you may not use this file except in compliance with
007 * the License.  You may obtain a copy of the License at
008 *
009 *      http://www.apache.org/licenses/LICENSE-2.0
010 *
011 * Unless required by applicable law or agreed to in writing, software
012 * distributed under the License is distributed on an "AS IS" BASIS,
013 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
014 * See the License for the specific language governing permissions and
015 * limitations under the License.
016 */
017package org.apache.commons.statistics.ranking;
018
019/**
020 * Strategies for handling tied values in rank transformations.
021 *
022 * @since 1.1
023 */
024public enum TiesStrategy {
025
026    /**
027     * Ties are assigned ranks in order of occurrence in the original array.
028     *
029     * <p>For example, {@code [1, 3, 4, 3]} is ranked as {@code [1, 2, 4, 3]}.
030     */
031    SEQUENTIAL,
032
033    /**
034     * Tied values are assigned the minimum applicable rank, or the rank of the
035     * first occurrence.
036     *
037     * <p>For example, {@code [1, 3, 4, 3]} is ranked as {@code [1, 2, 4, 2]}.
038     */
039    MINIMUM,
040
041    /**
042     * Tied values are assigned the maximum applicable rank, or the rank of the last
043     * occurrence. <p>For example, {@code [1, 3, 4, 3]} is ranked as {@code [1, 3, 4, 3]}.
044     */
045    MAXIMUM,
046
047    /**
048     * Tied values are assigned the average of the applicable ranks.
049     *
050     * <p>For example, {@code [1, 3, 4, 3]} is ranked as {@code [1, 2.5, 4, 2.5]}.
051     */
052    AVERAGE,
053
054    /**
055     * Tied values are assigned a <em>unique</em> random integral rank from among the
056     * applicable values.
057     *
058     * <p>For example, {@code [1, 3, 4, 3]} is ranked as either {@code [1, 2, 4, 3]} or
059     * {@code [1, 3, 4, 2]} where the choice is random.
060     *
061     * <p>The assigned rank will always be an integer, (inclusively) between the
062     * values returned by the {@link #MINIMUM} and {@link #MAXIMUM} strategies.
063     *
064     * <p>Use of a <em>unique</em> rank ensures that ties are resolved so that the
065     * rank order is stable.
066     */
067    RANDOM
068}