Java Array Max Value argmax(double[] array, boolean naturalNumbers)

Here you can find the source of argmax(double[] array, boolean naturalNumbers)

Description

Returns the index of the maximal value in a double[]

License

Open Source License

Parameter

Parameter Description
array a parameter
naturalNumbers a parameter

Return

The index of the highest number in the array

Declaration

public static int argmax(double[] array, boolean naturalNumbers) 

Method Source Code

//package com.java2s;
/*//w w w  .j a  v  a 2 s.c o m
 *  OpenmlApiConnector - Java integration of the OpenML Web API
 *  Copyright (C) 2014 
 *  @author Jan N. van Rijn (j.n.van.rijn@liacs.leidenuniv.nl)
 *  
 *  This program is free software: you can redistribute it and/or modify
 *  it under the terms of the GNU General Public License as published by
 *  the Free Software Foundation, either version 3 of the License, or
 *  (at your option) any later version.
 *  
 *  This program is distributed in the hope that it will be useful,
 *  but WITHOUT ANY WARRANTY; without even the implied warranty of
 *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 *  GNU General Public License for more details.
 *  
 *  You should have received a copy of the GNU General Public License
 *  along with this program.  If not, see <http://www.gnu.org/licenses/>.
 *  
 */

public class Main {
    /**
     * Returns the index of the maximal value in a double[] 
     * 
     * @param array
     * @param naturalNumbers
     * @return The index of the highest number in the array
     */
    public static int argmax(double[] array, boolean naturalNumbers) {
        int best = -1;
        double value = (naturalNumbers) ? 0D : Double.MIN_VALUE;
        for (int i = 0; i < array.length; ++i) {
            if (array[i] > value) {
                value = array[i];
                best = i;
            }
        }
        return best;
    }
}

Related

  1. argmax(double[] weights)
  2. argmax(final double[] vec)
  3. argmax(float[] args)
  4. argMax(int[] a)