lightonml.projections¶
lightonml.projections.sklearn¶

class
OPUMap
(n_components, opu=None, ndims=1, n_2d_features=None, packed=False, simulated=False, max_n_features=None, verbose_level= 1, linear=False)[source]¶ Bases:
sklearn.base.BaseEstimator
,sklearn.base.TransformerMixin
Adapter of the OPU to scikitlearn. Transform method is mapped to
transform
of theOPU
class.See also
 Parameters
n_components (int,) – dimensionality of the target projection space.
opu (lightonml.opu.OPU,) – optical processing unit instance (created at init if not provided)
ndims (int,) – number of dimensions of an input. Can be 1 or 2. if ndims is 1, transform accepts 1d vector or batch of 1d vectors. if ndims is 2, transform accepts 2d vector or batch of 2d vectors.
packed (bool, optional) – whether the input data is in bitpacked representation if packed is True and ndims is 2, each input vector is assumed to be a 1d array, and the “real” number of features must be provided using n_2d_features parameter defaults to False
n_2d_features (list(int) or tuple(int) or np.ndarray (optional)) – number of 2d features if the input is packed
simulated (bool, default False,) – use real or simulated OPU
linear (bool, default False,) – use the linear version of the OPU transform (lightonml.opu.OPU.linear_transform)
max_n_features (int, optional) – maximum number of binary features that the OPU will transform used only if simulated=True, in order to initiate the random matrix
verbose_level (int, optional) – Levels are 0: nothing, 1: print info, 2: debug info, 3: trace info deprecated, use lightonml.set_verbose_level instead

opu
¶ optical processing unit instance
 Type

ndims
¶ number of dimensions of an input. Can be 1 or 2. if ndims is 1, transform accepts 1d vector or batch of 1d vectors. if ndims is 2, transform accepts 2d vector or batch of 2d vectors.
 Type
int,

packed
¶ whether the input data is in bitpacked representation if packed is True and ndims is 2, each input vector is assumed to be a 1d array, and the “real” number of features must be provided using n_2d_features parameter defaults to False
 Type
bool, optional

n_2d_features
¶ number of 2d features if the input is packed

linear
¶ use the linear version of the OPU transform (lightonml.opu.OPU.linear_transform)
 Type
bool, default False,

max_n_features
¶ maximum number of binary features that the OPU will transform used only if simulated=True, in order to initiate the random matrix
 Type
int, optional

fit
(X=None, y=None, n_features=None, packed=False, online=False)[source]¶ Configure OPU transform for 1d or 2d vectors
The function can be either called with input vector, for fitting OPU parameters to it, or just vector dimensions, with
n_features
.When input is bitpacked the packed flag must be set to True.
When input vectors must be transformed one by one, performance will be improved with the online flag set to True.
 Parameters
X (np.ndarray,) – Fit will be made on this vector to optimize transform parameters
y (np.ndarray,) – For sklearn interface compatibility
n_features (int or tuple(int),) – Number of features for the input, necessary if X parameter isn’t provided
packed (bool, optional) – Set to true if the input vectors will be already bitpacked defaults to False
online (bool, optional) – Set to true if the transforms will be made one vector after the other defaults to False
 Returns
 Return type
self
lightonml.projections.torch¶

class
OPUMap
(n_components, opu=None, ndims=1, n_2d_features=None, packed=False, simulated=False, max_n_features=None, verbose_level= 1, linear=False)[source]¶ Bases:
torch.nn.modules.module.Module
Adapter of the OPU to the Pytorch interface.
Forward method is mapped to
transform
of theOPU
classSee also
 Parameters
n_components (int,) – dimensionality of the target projection space.
opu (lightonml.opu.OPU,) – optical processing unit instance
ndims (int,) – number of dimensions of an input. Can be 1, 2 or 3. if ndims is 1, transform accepts 1d vector or batch of 1d vectors. if ndims is 2, transform accepts 2d vector or batch of 2d vectors.
packed (bool, optional) – whether the input data is in bitpacked representation if packed is True and ndims is 2, each input vector is assumed to be a 1d array, and the “real” number of features must be provided using n_2d_features parameter defaults to False
n_2d_features (list(int) or tuple(int) or np.ndarray (optional)) – number of 2d features if the input is packed
simulated (bool, default False,) – use real or simulated OPU
linear (bool, default False,) – use the linear version of the OPU transform
max_n_features (int, optional) – maximum number of binary features that the OPU will transform used only if simulated=True, in order to initiate the random matrix
verbose_level (int, optional) – Levels are 0: nothing, 1: print info, 2: debug info, 3: trace info deprecated, use lightonml.set_verbose_level instead

opu
¶ optical processing unit instance
 Type

ndims
¶ number of dimensions of an input. Can be 1, 2 or 3. if ndims is 1, transform accepts 1d vector or batch of 1d vectors. if ndims is 2, transform accepts 2d vector or batch of 2d vectors.
 Type
int,

packed
¶ whether the input data is in bitpacked representation if packed is True and ndims is 2, each input vector is assumed to be a 1d array, and the “real” number of features must be provided using n_2d_features parameter defaults to False
 Type
bool, optional

n_2d_features
¶ number of 2d features if the input is packed

linear
¶ use the linear version of the OPU transform (lightonml.opu.OPU.linear_transform)
 Type
bool, default False,

max_n_features
¶ maximum number of binary features that the OPU will transform used only if simulated=True, in order to initiate the random matrix
 Type
int, optional

extra_repr
()[source]¶ Set the extra representation of the module
To print customized extra information, you should reimplement this method in your own modules. Both singleline and multiline strings are acceptable.

fit
(X=None, y=None, n_features=None, packed=False, online=False)[source]¶ Configure OPU transform for 1d or 2d vectors
The function can be either called with input vector, for fitting OPU parameters to it, or just vector dimensions, with
n_features
.When input is bitpacked the packed flag must be set to True.
When input vectors must be transformed one by one, performance will be improved with the online flag set to True.
 Parameters
X (np.ndarray or torch.Tensor, optional,) – Fit will be made on this vector to optimize transform parameters
y (np.ndarray or torch.Tensor, optional,) – For consistence with Sklearn API.
n_features (int or tuple(int)) – Number of features for the input, necessary if X parameter isn’t provided
packed (bool) – Set to true if the input vectors will be already bitpacked
online (bool, optional) –
Set to true if the transforms will be made one vector after the other defaults to False
See also
See also