Difference between revisions of "ArgMin and ArgMax"

m
 
(14 intermediate revisions by 4 users not shown)
Line 1: Line 1:
= Functions ArgMin and ArgMax =
+
[[Category:Array-reducing functions]]
 +
[[Category:Doc Status C]] <!-- For Lumina use, do not change -->
 +
{{ReleaseBar}}
  
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.
+
== ArgMax(r, i'', position{{Release|5.2||, first}}''), ArgMin(r, i'', position{{Release|5.2||, first}}'')==
  
ArgMin is new to Analytica 4.0. 
+
<code>'''ArgMax'''(r, i)</code> returns the value of index «i» for which array «r» contains the largest numerical value (or if  «r» contains text, the last in alphabetic order.) More specifically, it returns a value, ''ix'' where <code>r[i = ix] = Max(r, i)</code>. If there are ties, i.e. «r» has two or more values that are equal largest, it returns the value of «i» nearest the end.  Similarly, <code>'''ArgMin'''(r, i)</code> returns the value of «i» for which «r» is smallest (or if  «r» contains text, the first alphabetically.)
  
== Declaration ==
+
Optional flags:
 +
* '''''position''''': (default:false) When true, it returns the index position -- 1 when the max or min appears in the first element.{{Release|5.2||
 +
* '''''first''''': (default:false) If True, it returns  first position (rather than the default last when there are ties.}}
  
ArgMin( R : vector[I] ; I : ... optional IndexType ; position : optional boolean )
+
== Use with multiple indexes ==
ArgMax( R : vector[I] ; I : ... optional IndexType ; position : optional boolean )
 
  
== Single Index Usage ==
+
<code>'''ArgMax'''(r, i)</code> and <code>'''ArgMin'''(r, i)</code> expect «r» to be an array with index <code>i</code>, and return a result not indexed by <code>i</code>.  If array «r» has any indexes in addition to «i», the result will retain those other indexes.  For example, if «r» is indexed by «i» and ''j'', it will return the value of «i» for which «r» is largest (or smallest) for each value of ''j''.
  
When ArgMin or ArgMax is used with a single index, as in the following usage
+
If you want to find the smallest or largest value of ''x'' over more than one index, you can list all those indexes: e.g.
ArgMax( R:Car_prices, I:Car_type )
+
:<code>ArgMax(X, I: Mpg, Car_type)</code>
the value in index I is returned containing the extrema.
 
  
 +
It will then return an array dimensioned by a local index <code>.Dim</code> and any indexes of <code>X</code> that you did not list as parameters. Index <code>.Dim</code> will contain the names of the indexes given as parameters, <code>Mpg</code> and <code>Car_type</code>, in this case. The result will contain the values of Index <code>Mpg</code> and <code>Car_type</code> for which <code>X</code> is maximum (or minimum).
  
== Multiple Index Usage ==
+
== Positional usage ==
  
(new to 4.0)
+
By default, '''ArgMax''' and '''ArgMin''' return a value of the index.  If you specify optional parameter «position» as <code>True</code>, they return the ''position'' instead of the ''value'' of the index containing the maximum (minimum). For example:
 +
:<code>ArgMax(R: Profit, I: UnitPrice, Position: true)</code>
  
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.
 
This helps avoid ambiguity when the index contains duplicate values.
  
== Related Functions ==
+
== History ==
 +
The «first» attrribute was introduced in [[Analytica 5.2]].
  
* [[Ana:Fn:Functions_Min_and_Max|Min]] and [[Ana:Fn:Functions_Min_and_Max|Max]]
+
== See Also ==
* [[Ana:Fn:Functions_Min_and_Max|CondMin]] and [[Ana:Fn:Functions_Min_and_Max|CondMax]]
+
* [[Min]]
* [[Ana:Fn:SubIndex|SubIndex]] and [[Ana:Fn:PositionInIndex|PositionInIndex]]
+
* [[Max]]
 +
* [[CondMin]]
 +
* [[CondMax]]
 +
* [[SubIndex]]
 +
* [[PositionInIndex]]
 +
* [[Array-reducing functions]]

Latest revision as of 23:14, 27 August 2019



Release:

4.6  •  5.0  •  5.1  •  5.2  •  5.3  •  5.4  •  6.0  •  6.1  •  6.2  •  6.3  •  6.4  •  6.5


ArgMax(r, i, position, first), ArgMin(r, i, position, first)

ArgMax(r, i) returns the value of index «i» for which array «r» contains the largest numerical value (or if «r» contains text, the last in alphabetic order.) More specifically, it returns a value, ix where r[i = ix] = Max(r, i). If there are ties, i.e. «r» has two or more values that are equal largest, it returns the value of «i» nearest the end. Similarly, ArgMin(r, i) returns the value of «i» for which «r» is smallest (or if «r» contains text, the first alphabetically.)

Optional flags:

  • position: (default:false) When true, it returns the index position -- 1 when the max or min appears in the first element.
  • first: (default:false) If True, it returns first position (rather than the default last when there are ties.

Use with multiple indexes

ArgMax(r, i) and ArgMin(r, i) expect «r» to be an array with index i, and return a result not indexed by i. If array «r» has any indexes in addition to «i», the result will retain those other indexes. For example, if «r» is indexed by «i» and j, it will return the value of «i» for which «r» is largest (or smallest) for each value of j.

If you want to find the smallest or largest value of x over more than one index, you can list all those indexes: e.g.

ArgMax(X, I: Mpg, Car_type)

It will then return an array dimensioned by a local index .Dim and any indexes of X that you did not list as parameters. Index .Dim will contain the names of the indexes given as parameters, Mpg and Car_type, in this case. The result will contain the values of Index Mpg and Car_type for which X is maximum (or minimum).

Positional usage

By default, ArgMax and ArgMin return a value of the index. If you specify optional parameter «position» as True, they return the position instead of the value of the index containing the maximum (minimum). For example:

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

This helps avoid ambiguity when the index contains duplicate values.

History

The «first» attrribute was introduced in Analytica 5.2.

See Also

Comments


You are not allowed to post comments.