prepare_weights#

skrough.weights.prepare_weights(weights: Optional[Union[int, float, ndarray]], size: int, *, expand_none: Literal[True] = True, normalize: bool = True) ndarray[source]#
skrough.weights.prepare_weights(weights: Optional[Union[int, float, ndarray]], size: Optional[int] = None, *, expand_none: Literal[False], normalize: bool = True) Optional[ndarray]

Prepare weights.

Process weights into an array form. The input weights can be given as a scalar value or an array-like structure of values. The following cases are handled in the function:

  • weights can be None, then if
    • expand_none == True - uniform output of 1 repeated size times is produced

    • expand_none == False - None output is produced

  • weights can be int or float - uniform output of weights (scalar)

    value repeated size times is produced

  • weights can be np.ndarray - input weights are taken as is and in this case size parameter is ignored

Additional normalization step (using normalize_weights() function) is performed for the above result when normalize == True. All the remarks of normalize_weights() applies when negative values are present. In such a case the function will not produce a discrete probability distribution.

Parameters:
  • weights – Value(s) to be processed.

  • size – Output length. May be omitted if code:weights is None and expand_none == False.

  • expand_none – Whether None weights input should be expanded to an array of non-null values. Defaults to True.

  • normalize – Whether to normalize the output values. Defaults to True.

Raises:

ValueError – If size is None or less than zero but it is necessary for producing the result. E.g., weights is one of int or float or weights is None and expand_none == True.

Returns:

Output weights.