Difference between revisions of "ArgMin and ArgMax"

(Functions ArgMin and ArgMax)
Line 1: Line 1:
 
= Functions ArgMin and ArgMax =
 
= Functions ArgMin and ArgMax =
  
These functions return the index coordinate where the minimum or maximum value in an array occurs.
+
ArgMax(x, i) returns the value of index i for which array x is largest. More specifically, it returns a value, ix, of i, such that x[i =ix] = Max(x, i). Similarly, ArgMin(x, i) returns the value of i for which x is ''smallest''. If there are ties (e.g., x has two identical values that are largest, it returns the one nearer the end of i.
  
 
ArgMin is new to Analytica 4.0.   
 
ArgMin is new to Analytica 4.0.   
Line 16: Line 16:
 
the value in index I is returned containing the extrema.
 
the value in index I is returned containing the extrema.
  
In the event of ties, the element occuring closest to the end of index I is returned.
 
  
 
== Multiple Index Usage ==
 
== Multiple Index Usage ==
Line 30: Line 29:
 
== Positional Usage ==
 
== Positional Usage ==
  
By default, ArgMax and ArgMin return the index element(s)A positional dual is provided, in which the index position (rather than index element) is returned.  For example:
+
By default, ArgMax (ArgMin) returns a value of the index.  If you specify optional parameter position as true, they return the position of the value in the index for which x is maximum (minumum) -- a number.  For example:
 
   ArgMax( R : Profit, I : UnitPrice, position : true )
 
   ArgMax( R : Profit, I : UnitPrice, position : true )
returns the 1-based position in I, rather than the actual price.  If an index might contain duplicate values, it may be necessary to use positions rather than elements to avoid ambiguities.
+
This helps avoid ambiguity when the index contains duplicate values.
  
 
== Related Functions ==
 
== Related Functions ==

Revision as of 07:13, 25 January 2007

Functions ArgMin and ArgMax

ArgMax(x, i) returns the value of index i for which array x is largest. More specifically, it returns a value, ix, of i, such that x[i =ix] = Max(x, i). Similarly, ArgMin(x, i) returns the value of i for which x is smallest. If there are ties (e.g., x has two identical values that are largest, it returns the one nearer the end of i.

ArgMin is new to Analytica 4.0.

Declaration

ArgMin( R : vector[I] ; I : ... optional IndexType ; position : optional boolean )
ArgMax( R : vector[I] ; I : ... optional IndexType ; position : optional boolean )

Single Index Usage

When ArgMin or ArgMax is used with a single index, as in the following usage

ArgMax( R:Car_prices, I:Car_type )

the value in index I is returned containing the extrema.


Multiple Index Usage

(new to 4.0)

You can specify more than one index, e.g.

ArgMin( R:Cost, I:Mpg,Car_type )

in order to find the coordinate in a multi-D array containing the minimum or maximum value.

When more than one index is specified, these functions return a coordinate at which the smallest (ArgMin) or largest (ArgMax) value occurs. The coordinate is a 1-D array indexed by a local index having the name .Dim. The elements of the local index are the index names, and the value of the result is the element from that index.

Positional Usage

By default, ArgMax (ArgMin) returns a value of the index. If you specify optional parameter position as true, they return the position of the value in the index for which x is maximum (minumum) -- a number. For example:

 ArgMax( R : Profit, I : UnitPrice, position : true )

This helps avoid ambiguity when the index contains duplicate values.

Related Functions

Comments


You are not allowed to post comments.