secml.ml.stats

CDensityEstimation

class secml.ml.stats.c_density_estimation.CDensityEstimation(bandwidth=1.0, algorithm='auto', kernel='gaussian', metric='euclidean', atol=0, rtol=1e-08, breadth_first=True, leaf_size=40, metric_params=None)[source]

Bases: secml.core.c_creator.CCreator

Kernel Density Estimation

Parameters
bandwidthfloat, optional

The bandwidth of the kernel. Default 1.

algorithmstr, optional

The tree algorithm to use. Valid options are [‘kd_tree’|’ball_tree’|’auto’]. Default is ‘auto’.

kernelstr, optional

The kernel to use. Valid kernels are [‘gaussian’|’tophat’|’epanechnikov’|’exponential’|’linear’|’cosine’]. Default is ‘gaussian’.

metricstr, optional

The distance metric to use. Note that not all metrics are valid with all algorithms. Refer to the documentation of BallTree and KDTree for a description of available algorithms. Note that the normalization of the density output is correct only for the Euclidean distance metric. Default is ‘euclidean’.

atolfloat, optional

The desired absolute tolerance of the result. A larger tolerance will generally lead to faster execution. Default is 0.

rtolfloat, optional

The desired relative tolerance of the result. A larger tolerance will generally lead to faster execution. Default is 1E-8.

breadth_firstbool, optional

If true (default), use a breadth-first approach to the problem. Otherwise use a depth-first approach.

leaf_sizeint, optional

Specify the leaf size of the underlying tree. See BallTree or KDTree for details. Default is 40.

metric_paramsdict, optional

Additional parameters to be passed to the tree for use with the metric. For more information, see the documentation of BallTree or KDTree.

Attributes
class_type

Defines class type.

logger

Logger for current object.

verbose

Verbosity level of logger output.

Methods

copy(self)

Returns a shallow copy of current class.

create([class_item])

This method creates an instance of a class with given type.

deepcopy(self)

Returns a deep copy of current class.

estimate_density(self, x[, n_points])

Estimate density of input array.

get_class_from_type(class_type)

Return the class associated with input type.

get_params(self)

Returns the dictionary of class parameters.

get_subclasses()

Get all the subclasses of the calling class.

list_class_types()

This method lists all types of available subclasses of calling one.

load(path)

Loads class from pickle object.

save(self, path)

Save class object using pickle.

set(self, param_name, param_value[, copy])

Set a parameter that has a specific name to a specific value.

set_params(self, params_dict[, copy])

Set all parameters passed as a dictionary {key: value}.

timed([msg])

Timer decorator.

estimate_density(self, x, n_points=1000)[source]

Estimate density of input array.

Returns
xCArray

Arrays with coordinates used to estimate density.

dfCArray

Density function values.

CDistributionGaussian

class secml.ml.stats.c_distribution_gaussian.CDistributionGaussian(mean=0, cov=1)[source]

Bases: secml.core.c_creator.CCreator

A multivariate normal random variable.

Parameters
meanscalar, optional

Mean of the distribution (default zero)

covarray_like or scalar, optional

Covariance matrix of the distribution (default one)

Attributes
class_type

Defines class type.

logger

Logger for current object.

verbose

Verbosity level of logger output.

Methods

copy(self)

Returns a shallow copy of current class.

create([class_item])

This method creates an instance of a class with given type.

deepcopy(self)

Returns a deep copy of current class.

get_class_from_type(class_type)

Return the class associated with input type.

get_params(self)

Returns the dictionary of class parameters.

get_subclasses()

Get all the subclasses of the calling class.

list_class_types()

This method lists all types of available subclasses of calling one.

load(path)

Loads class from pickle object.

logpdf(self, data)

Log of the probability density function.

pdf(self, data)

Probability density function.

save(self, path)

Save class object using pickle.

set(self, param_name, param_value[, copy])

Set a parameter that has a specific name to a specific value.

set_params(self, params_dict[, copy])

Set all parameters passed as a dictionary {key: value}.

timed([msg])

Timer decorator.

logpdf(self, data)[source]

Log of the probability density function.

Parameters
dataCArray

Quantiles, with the last axis of x denoting the components.

Returns
pdf: CArray

Probability density function computed at input data.

pdf(self, data)[source]

Probability density function.

Parameters
dataCArray

Quantiles, with the last axis of x denoting the components.

Returns
pdf: CArray

Probability density function computed at input data.