choose_objects#
- skrough.instances.choose_objects(group_index: GroupIndex, y: ndarray, y_count: int, objs: Optional[Union[int, float, ndarray]] = None, weights: Optional[ndarray] = None, return_representatives_only: bool = False, seed: Optional[Union[int, SeedSequence, Generator]] = None) List[int][source]#
Choose objects having uniform decision values within their groups.
The function returns a list of objects that have unique decision values within their groups in
group_index(seeGroupIndex). There are two ways to specify a hint on how the objects should be selected. If theobjsargument is given then its value specifies the subset of objects along with their order in which the objects are handled. In such a case only the specified objects can appear in the result. Moreover, the objects that are earlier inobjstake precedence, i.e., if two objects that belongs to the same group (determined bygroup_index) has conflicting decision values then only the earlier one is selected for the result. Ifobjs is Nonethen all objects represented ingroup_indexare taken into consideration and their order of precedence is established by means of theweightsinput argument, and theprepare_weights()andget_permutation()functions. The value ofweightsis taken into account only ifobjs is None, otherwise it is ignored. The value used during the process of establishing the order of objects is equivalent to the followingselectorexpression:proba = prepare_weights(weights, group_index.n_objs, expand_none=False) selector = get_permutation(0, group_index.n_objs, proba, seed=seed)
Thus, giving the opportunity to either set the
weightsused for drawing a permutation explicitly for each object (whenlen(weights) == group_index.n_objs) or let permutation to be drawn from uniform distribution - seeprepare_weights()andget_permutation()for details.The
return_representatives_onlyargument is used to control whether the result returned by the function should either include all non-conflicting objects (the default behavior) or to include at most one object from each group induced bygroup_index(whenreturn_representatives_only is True).- Parameters:
group_index – Group index that represents split of the objects represented by this structure into groups.
y – Factorized decision values for the objects represented by the input
group_index. The values should be given in a form of integer-location based indexing sequence of the factorized decision values, i.e., 0-based values that index distinct decisions.y_count – Number of distinct decision attribute values.
objs – A sequence of objects that the function should select from. It should be given in a form of integer-location based indexing sequence of the objects represented in
group_index.Nonevalue means to use all available objects. Defaults toNone.weights – Used only if
objs is None. The value is used for establishing the order of precedence of objects by means of theprepare_weights()andget_permutation()functions. It should be eitherlen(weights) == group_index.n_objs, a single weight value orNone.return_representatives_only – A flag controlling if the result should include to all non-conflicting objects (when set to
True) or to include at most one object from each group (when set toFalse). Defaults toFalse.seed – Random seed. Defaults to
None.
- Returns:
A set of objects having uniform decision values within their groups determined by
group_index. The return value has a form of integer-location based indexing sequence of objects represented bygroup_index.
Examples
>>> group_index = GroupIndex.from_index([0, 0, 1, 1]) >>> dec = np.array([0, 1, 0, 0])
>>> choose_objects(group_index, y=dec, y_count=2, objs=np.array([0, 1, 2, 3])) [0, 2, 3]
>>> choose_objects(group_index, y=dec, y_count=2, objs=np.array([1, 0, 2, 3])) [1, 2, 3]
>>> choose_objects(group_index, y=dec, y_count=2, objs=np.array([0, 1, 2, 3]), ... return_representatives_only=True) [0, 2]
>>> choose_objects(group_index, y=dec, y_count=2, objs=np.array([0, 1, 3, 2]), ... return_representatives_only=True) [0, 3]