lightonml.encoding¶
lightonml.encoding.base¶
Encoders
These modules contains implementations of Encoders that can transform data in the binary uint8 format required by the OPU.

class
BinaryThresholdEncoder
(threshold_enc=25, greater_is_one=True)[source]¶ Bases:
sklearn.base.BaseEstimator
,sklearn.base.TransformerMixin
Implements binary encoding using a threshold function.
Parameters:

class
ConcatenatingBitPlanDecoder
(n_bits=8, decoding_decay=0.5)[source]¶ Bases:
sklearn.base.BaseEstimator
,sklearn.base.TransformerMixin
Implements a decoding that works by concatenating bitplanes.
n_bits
MUST be the same value used in SeparatedBitPlanEncoder. Read more in the Examples section.Parameters:

class
Float32Encoder
(sign_bit=True, exp_bits=8, mantissa_bits=23)[source]¶ Bases:
sklearn.base.BaseEstimator
,sklearn.base.TransformerMixin
Implements an encoding that works by separating bitplans and selecting how many bits to keep for sign, mantissa and exponent of the float32.
Parameters:

class
MixingBitPlanDecoder
(n_bits=8, decoding_decay=0.5)[source]¶ Bases:
sklearn.base.BaseEstimator
,sklearn.base.TransformerMixin
Implements a decoding that works by mixing bitplanes.
n_bits
MUST be the same value used in SeparatedBitPlanEncoder. Read more in the Examples section.Parameters:

class
NoDecoding
[source]¶ Bases:
sklearn.base.BaseEstimator
,sklearn.base.TransformerMixin
Implements a NoOp Decoding class for API consistency.

class
NoEncoding
[source]¶ Bases:
sklearn.base.BaseEstimator
,sklearn.base.TransformerMixin
Implements a NoOp Encoding class for API consistency.

class
SeparatedBitPlanEncoder
(n_bits=8, starting_bit=0)[source]¶ Bases:
sklearn.base.BaseEstimator
,sklearn.base.TransformerMixin
Implements an encoding that works by separating bitplans.
n_bits + starting_bit
must be lower than the bitwidth of data that are going to be fed to the encoder. E.g. ifX.dtype
isuint8
, thenn_bits + starting_bit
must be lower than 8. If insteadX.dtype
isuint32
, thenn_bits + starting_bit
must be lower than 32.Read more in the Examples section.
Parameters:

class
SequentialBaseTwoEncoder
(n_gray_levels=16)[source]¶ Bases:
sklearn.base.BaseEstimator
,sklearn.base.TransformerMixin
Implements a base 2 encoding.
E.g. \(5\) is written \(101\) in base 2: \(1 * 2^2 + 0 * 2^1 + 1 * 2^0\) = (1)*4 +(0)*2 +(1)*1, so the encoder will give 1111001.
Parameters: n_gray_levels (int,) – number of values that can be encoded. Must be a power of 2. 
fit
(X, y=None)[source]¶ Computes parameters for the normalization.
Must be run only on the training set to avoid leaking information to the dev/test set.
Parameters:  X (np.ndarray of uint [n_samples, n_features],) – the input data to encode.
 y (np.ndarray,) – the targets data.
Returns: self
Return type: SequentialBaseTwoEncoder.

lightonml.encoding.utils¶
This module contains all the functions that are used to implement the data formatting. Coordinates are (y, x).

compute_indices_1d_macro_pixels
(n_features, rectangle_shape, feature_shape='square')[source]¶ Computes indices of the macro pixels in a linear way. It means that it is using the whole width of the rectangle even if the quotient (rectangle_width / macro_pixel_width) is not an integer.
Parameters:  n_features (int,) – number of features for.
 rectangle_shape (tuple of 2 integer,) – shape of the rectangle area.
 feature_shape (string,) – shape of the macropixels (‘rectangle’ or ‘square’)
Returns:  indices (np.ndarray of int64/int32,) – indices in the rectangle.
 factor (int,) – size of the macropixels.

compute_indices_2d_macro_pixels
(n_features, rectangle_shape)[source]¶ Computes indices of the macro pixels as a classical zoom in of the squared features.
Parameters:  n_features (int,) – number of features for.
 rectangle_shape (tuple of 2 integer,) – shape of the rectangle area.
Returns:  indices (np.ndarray of int64/int32,) – indices in the rectangle.
 factor (int,) – size of the macropixels.

compute_indices_centered
(n_features, rectangle_shape)[source]¶ Computes indices in order to have the feature values in a square centered in the area.
Parameters:  n_features (int,) – number of features for.
 rectangle_shape (tuple of 2 integer,) – shape of the rectangle area.
Returns:  indices (np.ndarray of int64/int32,) – indices in the rectangle.
 factor (int,) – size of the macropixels.

compute_indices_lined
(n_features, rectangle_shape)[source]¶ Computes indices in order to have the feature values positioned in line.
Parameters:  n_features (int,) – number of features for.
 rectangle_shape (tuple of 2 integer,) – shape of the rectangle area.
Returns:  indices (np.ndarray of int64/int32,) – indices in the rectangle.
 factor (int,) – size of the macropixels.

compute_new_indices_greater_rectangle
(indices, old_rectangle_shape, old_rectangle_position, new_rectangle_shape)[source]¶ Computes new indices from an old rectangle to a new and larger one. It is useful in the case where the region of interest is smaller than the DMD area.
Parameters:  indices (np.ndarray of uint64/uint32,) – indices in the old rectangle.
 old_rectangle_shape (tuple of 2 integer,) – shape of the old rectangle.
 old_rectangle_position (tuple of 2 integer,) – position of the origin of the old rectangle inside the new one (distance from top, distance from left margin)
 new_rectangle_shape (tuple of 2 integer,) – shape of the new rectangle.
Returns: new_indices – indices in the new rectangle.
Return type: np.ndarray of uint64/uint32,

get_formatting_function
(n_features, position='2d_macro_pixels', roi_shape=(1140, 912), roi_position=(0, 0), dmd_shape=(1140, 912))[source]¶ Returns a formatting function that takes feature vectors and returns the dmd formatted vectors .
Parameters: Returns:  formatting_func (callable,) – callable to perform the formatting of the input arrays.
 factor (int,) – size of the macropixels.