Difference between revisions of "ArgMin and ArgMax"
m (adding doc status category) |
|||
Line 2: | Line 2: | ||
[[Category:Doc Status C]] <!-- For Lumina use, do not change --> | [[Category:Doc Status C]] <!-- For Lumina use, do not change --> | ||
− | = Functions ArgMin | + | = Functions ArgMax(x, i) and ArgMin(x, i)= |
− | ArgMax(x, i) returns the value of index i | + | ArgMax(x, i) returns the value of index i corresponding to the largest value from array x, which must be indexed by i. More specifically, it returns a value, ix where x[i =ix] = Max(x, i). If there are ties, i.e. x has two or more values that are equal largest, it returns the value nearest the end of i. Similarly, ArgMin(x, i) returns the value of i for which x is ''smallest''. |
ArgMin is new to Analytica 4.0. | ArgMin is new to Analytica 4.0. | ||
Line 13: | Line 13: | ||
ArgMax( R : vector[I] ; I : ... optional IndexType ; position : optional boolean ) | ArgMax( R : vector[I] ; I : ... optional IndexType ; position : optional boolean ) | ||
− | == | + | == When x has multiple indexes == |
− | + | If array x has an index or indexes in addition to i, Argmax(x, i) or Argmin(x, i) return an array indexed by those other indexes, but not by i. For example, if x is indexed by i and j, it will return the value of i for which x is largest (or smallest) for each value of j. | |
− | |||
− | |||
− | |||
− | |||
− | If array x has indexes in addition to i, Argmax(x, i) or Argmin(x, i) | ||
== Searching over Multiple Indexes == | == Searching over Multiple Indexes == | ||
Line 27: | Line 22: | ||
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. | 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 ) | + | 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). | 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). | ||
Line 34: | Line 29: | ||
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: | 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, | + | 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. | ||
Revision as of 17:42, 5 June 2007
Functions ArgMax(x, i) and ArgMin(x, i)
ArgMax(x, i) returns the value of index i corresponding to the largest value from array x, which must be indexed by i. More specifically, it returns a value, ix where x[i =ix] = Max(x, i). If there are ties, i.e. x has two or more values that are equal largest, it returns the value nearest the end of i. Similarly, ArgMin(x, i) returns the value of i for which x is smallest.
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 )
When x has multiple indexes
If array x has an index or indexes in addition to i, Argmax(x, i) or Argmin(x, i) return an array indexed by those other indexes, but not by i. For example, if x is indexed by i and j, it will return the value of i for which x is largest (or smallest) for each value of j.
Searching over Multiple Indexes
(new to 4.0)
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 (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.
Enable comment auto-refresher