naginterfaces.library.mip.best_subset_given_size_revcomm¶
- naginterfaces.library.mip.best_subset_given_size_revcomm(irevcm, mincr, m, ip, nbest, drop, lz, z, la, a, bscore, bz, mincnt, gamma, acc, comm, io_manager=None)[source]¶
Given a set of features and a scoring mechanism for any subset of those features,
best_subset_given_size_revcomm
selects the best subsets of size using a reverse communication branch and bound algorithm.For full information please refer to the NAG Library document for h05aa
https://www.nag.com/numeric/nl/nagdoc_29.3/flhtml/h/h05aaf.html
- Parameters
- irevcmint
On initial entry: must be set to .
On intermediate entry: must remain unchanged.
- mincrint
Flag indicating whether the scoring function is increasing or decreasing.
, i.e., the subsets with the largest score will be selected.
, i.e., the subsets with the smallest score will be selected.
For all and .
- mint
, the number of features in the full feature set.
- ipint
, the number of features in the subset of interest.
- nbestint
, the maximum number of best subsets required. The actual number of subsets returned is given by on final exit. If on final exit then = 53 is returned.
- dropint
On initial entry: need not be set.
On intermediate entry: must remain unchanged.
- lzint
On initial entry: need not be set.
On intermediate entry: must remain unchanged.
- zint, ndarray, shape , modified in place
On initial entry: need not be set.
On intermediate exit: , for , contains the list of features which, along with those specified in , define the subsets whose score is required. See for additional details.
On intermediate entry: must remain unchanged.
On final exit: is undefined.
- laint
On initial entry: need not be set.
On intermediate entry: must remain unchanged.
- aint, ndarray, shape , modified in place
On initial entry: need not be set.
On intermediate exit: , for , contains the list of features which, along with those specified in , define the subsets whose score is required. See for additional details.
On intermediate entry: must remain unchanged.
On final exit: is undefined.
- bscorefloat, ndarray, shape , modified in place
On initial entry: need not be set.
On intermediate exit: is undefined.
On intermediate entry: must hold the score for the th subset as described in .
On final exit: holds the score for the best subsets returned in .
- bzint, ndarray, shape , modified in place
On initial entry: need not be set.
On intermediate exit: is used for storage between calls to
best_subset_given_size_revcomm
.On intermediate entry: must remain unchanged.
On final exit: the th best subset is constructed by dropping the features specified in , for , for , from the set of all features, . The score for the th best subset is given in .
- mincntint
, the minimum number of times the effect of each feature, , must have been observed before is estimated from as opposed to being calculated directly.
If then is never estimated.
If then is set to .
- gammafloat
, the scaling factor used when estimating scores. If then is used.
- accfloat, array-like, shape
A measure of the accuracy of the scoring function, .
Letting , then when confirming whether the scoring function is strictly increasing or decreasing (as described in ), or when assessing whether a node defined by subset can be trimmed, then any values in the range are treated as being numerically equivalent.
If then , otherwise .
If then , otherwise .
In most situations setting both and to zero should be sufficient.
Using a nonzero value, when one is not required, can significantly increase the number of subsets that need to be evaluated.
- commdict, communication object, modified in place
Communication structure.
On initial entry: need not be set.
- io_managerFileObjManager, optional
Manager for I/O in this routine.
- Returns
- irevcmint
On intermediate exit: and before re-entry the scores associated with subsets must be calculated and returned in .
The subsets are constructed as follows:
The th subset is constructed by dropping the features specified in the first elements of and the single feature given in from the full set of features, . The subset will, therefore, contain features.
The th subset is constructed by adding the features specified in the first elements of and the single feature specified in to the empty set, . The subset will, therefore, contain features.
In both cases the individual features are referenced by the integers to with indicating the first feature, the second, etc., for some arbitrary ordering of the features.
The same ordering must be used in all calls to
best_subset_given_size_revcomm
.If , the score for a single subset should be returned.
This subset is constructed by adding or removing only those features specified in the first elements of .
If , this subset will either be or .
The score associated with the th subset must be returned in .
On final exit: , and the algorithm has terminated.
- dropint
On intermediate exit: flag indicating whether the intermediate subsets should be constructed by dropping features from the full set () or adding features to the empty set (). See for details.
On final exit: is undefined.
- lzint
On intermediate exit: the number of features stored in .
On final exit: is undefined.
- laint
On intermediate exit: if , the number of subsets for which a score must be returned.
If , the score for a single subset should be returned.
See for additional details.
On final exit: the number of best subsets returned.
- Raises
- NagValueError
- (errno )
On entry, .
Constraint: or .
- (errno )
On entry, .
Constraint: or .
- (errno )
has changed between calls.
On intermediate entry, .
On initial entry, .
- (errno )
On entry, .
Constraint: .
- (errno )
has changed between calls.
On intermediate entry, .
On initial entry, .
- (errno )
On entry, and .
Constraint: .
- (errno )
has changed between calls.
On intermediate entry, .
On initial entry, .
- (errno )
On entry, .
Constraint: .
- (errno )
has changed between calls.
On intermediate entry, .
On initial entry, .
- (errno )
has changed between calls.
On intermediate entry, .
On initial entry, .
- (errno )
has changed between calls.
On entry, .
On previous exit, .
- (errno )
has changed between calls.
On entry, .
On previous exit, .
- (errno )
, which is inconsistent with the score for the parent node. Score for the parent node is .
- (errno )
has changed between calls.
On intermediate entry, .
On initial entry, .
- (errno )
has changed between calls.
On intermediate entry, .
On initial entry, .
- (errno )
has changed between calls.
On intermediate entry, .
On initial entry, .
- (errno )
has changed between calls.
On intermediate entry, .
On initial entry, .
- (errno )
[‘icomm’] has been corrupted between calls.
- (errno )
[‘rcomm’] has been corrupted between calls.
- Warns
- NagAlgorithmicWarning
- (errno )
On entry, .
But only best subsets could be calculated.
- Notes
Given , a set of unique features and a scoring mechanism defined for all then
best_subset_given_size_revcomm
is designed to find , an optimal subset of size . Here denotes the cardinality of , the number of elements in the set.The definition of the optimal subset depends on the properties of the scoring mechanism, if
then the optimal subset is defined as one of the solutions to
else if
then the optimal subset is defined as one of the solutions to
If neither of these properties hold then
best_subset_given_size_revcomm
cannot be used.As well as returning the optimal subset, ,
best_subset_given_size_revcomm
can return the best solutions of size . If denotes the th best subset, for , then the th best subset is defined as the solution to eitheror
depending on the properties of .
The solutions are found using a branch and bound method, where each node of the tree is a subset of . Assuming that [equation] holds then a particular node, defined by subset , can be trimmed from the tree if where is the th highest score we have observed so far for a subset of size , i.e., our current best guess of the score for the th best subset. In addition, because of [equation] we can also drop all nodes defined by any subset where , thus avoiding the need to enumerate the whole tree. Similar short cuts can be taken if [equation] holds. A full description of this branch and bound algorithm can be found in Ridout (1988).
Rather than calculate the score at a given node of the tree
best_subset_given_size_revcomm
utilizes the fast branch and bound algorithm of Somol et al. (2004), and attempts to estimate the score where possible. For each feature, , two values are stored, a count and , an estimate of the contribution of that feature. An initial value of zero is used for both and . At any stage of the algorithm where both and have been calculated (as opposed to estimated), the estimated contribution of the feature is updated toand is incremented by , therefore, at each stage is the mean contribution of observed so far and is the number of observations used to calculate that mean.
As long as , for the user-supplied constant , then rather than calculating this function estimates it using or if has been estimated, where is a user-supplied scaling factor. An estimated score is never used to trim a node or returned as the optimal score.
Setting in this function will cause the algorithm to always calculate the scores, returning to the branch and bound algorithm of Ridout (1988). In most cases it is preferable to use the fast branch and bound algorithm, by setting , unless the score function is iterative in nature, i.e., must have been calculated before can be calculated.
- References
Narendra, P M and Fukunaga, K, 1977, A branch and bound algorithm for feature subset selection, IEEE Transactions on Computers (9), 917–922
Ridout, M S, 1988, Algorithm AS 233: An improved branch and bound algorithm for feature subset selection, Journal of the Royal Statistics Society, Series C (Applied Statistics) (Volume 37) (1), 139–147
Somol, P, Pudil, P and Kittler, J, 2004, Fast branch and bound algorithms for optimal feature selection, IEEE Transactions on Pattern Analysis and Machine Intelligence (Volume 26) (7), 900–912