Samples(samples=None, forced_original_shape=None, **kwargs)¶
A collection of data points.
>>> from picos.expressions import Samples >>> # Load the column-major vectorization of six matrices. >>> data = [[[1*i, 3*i], ... [2*i, 4*i]] for i in range(1, 7)] >>> S = Samples(data) >>> S <Samples: (6 4-dimensional samples)> >>> [S.num, S.dim, S.original_shape] # Metadata. [6, 4, (2, 2)] >>> S.matrix # All samples as the columns of one matrix. <4×6 Real Constant: [4×6]> >>> print(S.matrix) [ 1.00e+00 2.00e+00 3.00e+00 4.00e+00 5.00e+00 6.00e+00] [ 2.00e+00 4.00e+00 6.00e+00 8.00e+00 1.00e+01 1.20e+01] [ 3.00e+00 6.00e+00 9.00e+00 1.20e+01 1.50e+01 1.80e+01] [ 4.00e+00 8.00e+00 1.20e+01 1.60e+01 2.00e+01 2.40e+01] >>> print(S.T) # The first sample (transposed for brevity). [ 1.00e+00 2.00e+00 3.00e+00 4.00e+00] >>> print(S.mean.T) # The sample mean (transposed for brevity). [ 3.50e+00 7.00e+00 1.05e+01 1.40e+01] >>> print(S.covariance) # The sample covariance matrix. [ 3.50e+00 7.00e+00 1.05e+01 1.40e+01] [ 7.00e+00 1.40e+01 2.10e+01 2.80e+01] [ 1.05e+01 2.10e+01 3.15e+01 4.20e+01] [ 1.40e+01 2.80e+01 4.20e+01 5.60e+01] >>> print(S.original) # The first sample in its original shape. [ 1.00e+00 3.00e+00] [ 2.00e+00 4.00e+00] >>> U = S.select([0, 2, 4]) # Select a subset of samples by indices. >>> print(U.matrix) [ 1.00e+00 3.00e+00 5.00e+00] [ 2.00e+00 6.00e+00 1.00e+01] [ 3.00e+00 9.00e+00 1.50e+01] [ 4.00e+00 1.20e+01 2.00e+01] >>> T, V = S.partition() # Split into training and validation samples. >>> print(T.matrix) [ 1.00e+00 2.00e+00 3.00e+00] [ 2.00e+00 4.00e+00 6.00e+00] [ 3.00e+00 6.00e+00 9.00e+00] [ 4.00e+00 8.00e+00 1.20e+01] >>> print(V.matrix) [ 4.00e+00 5.00e+00 6.00e+00] [ 8.00e+00 1.00e+01 1.20e+01] [ 1.20e+01 1.50e+01 1.80e+01] [ 1.60e+01 2.00e+01 2.40e+01]
__init__(samples, forced_original_shape=None, always_copy=True)¶
Load a number of data points (samples).
Any of the following:
A tuple or list of constants, each of which denotes a sample vector. Matrices are vectorized but their
original_shapeis stored and may be used by PICOS internally.
A constant row or column vector whose entries denote scalar samples.
A constant matrix whose columns denote the samples.
In any case, constants may be given as constant numeric data values (anything recognized by
load_data) or as constant PICOS expressions.
forced_original_shape – Overwrites
original_shapewith the given shape.
always_copy (bool) – If this is
False, then data that is provided in the form of CVXOPT types is not copied but referenced if possible. This can speed up instance creation but will introduce inconsistencies if the original data is modified. Note that this argument has no impact if the
samplesargument already is a
Samplesinstance; in this case data is never copied.
__new__(cls, samples=None, forced_original_shape=None, **kwargs)¶
Split the samples into two parts.
Return a new
Samplesinstance with only selected samples.
indices – The indices of the samples to select.
The sample covariance matrix.
A matrix whose columns are the samples.
The sample mean as a column vector.
Number of samples.
Original shape of the samples before vectorization.