mark.core.math
Class Argmax

java.lang.Object
  |
  +--mark.core.math.Argmax

public class Argmax
extends java.lang.Object

An Argmax accepts (argument, number) pairs and remembers the k pairs that have the greatest numbers. Arguments are integers, and numbers are doubles. Sample Usage: Argmax am = new Argmax (); am.consider (0, 12.0); am.consider (1, 2.3); am.consider (2, 3.0); System.out.println ( "The greatest pair is (" + am.argmax () + ", " + am.nummax ());


Constructor Summary
Argmax()
          Initializes the Argmax with k = 1.
Argmax(double[] nums)
          Initializes the Argmax with k = 1 and causes it to consider a number of pairs.
Argmax(int k)
          Initializes the Argmax with the given k.
Argmax(int k, double[] nums)
          Initializes the Argmax with the given k and causes it to consider a number of pairs.
 
Method Summary
 int argmax()
          Returns the argument corresponding to the largest number yet seen (starting at zero).
 int argmax(int n)
          Returns the argument corresponding to the nth largest number yet seen.
 void consider(double[] nums)
          Causes the Argmax to consider a number of pairs.
 void consider(int arg, double num)
          Causes the Argmax to consider the given pair.
 double nummax()
          Returns the largest number yet seen.
 double nummax(int n)
          Returns the nth largest number yet seen.
 int size()
          Returns the number of pairs the Argmax is remembering.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

Argmax

public Argmax(int k)
Initializes the Argmax with the given k.

Parameters:
k - the number of pairs to remember.

Argmax

public Argmax(int k,
              double[] nums)
Initializes the Argmax with the given k and causes it to consider a number of pairs.

Parameters:
nums - an arrray of doubles that contains the pairs to consider. Arguments are the indices of the array. Numbers are the values of the array.

Argmax

public Argmax()
Initializes the Argmax with k = 1.


Argmax

public Argmax(double[] nums)
Initializes the Argmax with k = 1 and causes it to consider a number of pairs.

Parameters:
nums - an arrray of doubles that contains the pairs to consider. Arguments are the indices of the array. Numbers are the values of the array.
Method Detail

size

public int size()
Returns the number of pairs the Argmax is remembering.

Returns:
the number of pairs the Argmax is remembering.

consider

public void consider(int arg,
                     double num)
Causes the Argmax to consider the given pair.

Parameters:
arg - the argument.
num - the number.

consider

public void consider(double[] nums)
Causes the Argmax to consider a number of pairs.

Parameters:
nums - an arrray of doubles that contains the pairs to consider. Arguments are the indices of the array. Numbers are the values of the array.

nummax

public double nummax(int n)
Returns the nth largest number yet seen.

Parameters:
n - zero for largest, one for second largest, etc.
Returns:
the nth largest number yet seen.

nummax

public double nummax()
Returns the largest number yet seen.

Returns:
the largest number yet seen.

argmax

public int argmax(int n)
Returns the argument corresponding to the nth largest number yet seen.

Parameters:
n - zero for largest, one for second largest, etc.
Returns:
the corresponding argument.

argmax

public int argmax()
Returns the argument corresponding to the largest number yet seen (starting at zero).

Returns:
the corresponding argument.