Mixture

class compressed_kde.Mixture

Bases: pybind11_object

Mixture class for (compressed) kernel density estimation.

Parameters
  • space (Space) – Description of mixture space.

  • threshold (scalar) – Compression threshold

Attributes Summary

kernel_bandwidths

Bandwidths of all components.

kernel_locations

Locations of all components.

kernel_scale_factors

Scale factors of all components.

ncomponents

Number of components in (compressed) density.

space

Mixture space.

sum_of_nsamples

Number of samples that were added to the density.

sum_of_weights

Sum of weights of all samples that were added to the density.

threshold

Compression threshold.

weights

Weights of all components.

Methods Summary

add(samples)

Add samples to the mixture.

clear

Remove all components and reset mixture.

evaluate

evaulate(*args,**kwargs) -> array

from_yaml(str)

Create mixture from YAML.

load_from_hdf5(filename, path)

Load mixture from hdf5 file.

load_from_yaml(path)

Load mixture from file.

marginal(*args, **kwargs)

Evaluate marginal at samples for select dimensions.

merge(samples, random)

Merge samples into the mixture.

partial

Partially evaluate mixture at samples for select dimensions.

partialize(*args, **kwargs)

Partially evaluate mixture at grid points for select dimensions.

save_to_hdf5(filename, flags, path)

Save mixture to hdf5 file.

save_to_yaml(path)

Save mixture to YAML file.

to_yaml()

Represent mixture as YAML.

Attributes Documentation

kernel_bandwidths

Bandwidths of all components.

kernel_locations

Locations of all components.

kernel_scale_factors

Scale factors of all components.

ncomponents

Number of components in (compressed) density.

space

Mixture space.

sum_of_nsamples

Number of samples that were added to the density.

sum_of_weights

Sum of weights of all samples that were added to the density.

threshold

Compression threshold.

weights

Weights of all components.

Methods Documentation

add(samples) None

Add samples to the mixture.

New mixture components are added at the sample location with the default kernel bandwidth. No merging with existing components is performed.

Parameters

samples ((n,ndim) array) – Array of samples

clear()

Remove all components and reset mixture.

evaluate()

evaulate(*args,**kwargs) -> array

Evaluate mixture at samples.

evaluate(samples)
evaluate(grid)
Parameters
  • samples ((n,ndim) array) – Array of samples

  • grid (Grid) – grid specification

Returns

Evaluated probabilities at sample locations

Return type

ndarray

static from_yaml(str) Mixture

Create mixture from YAML.

Parameters

string (string) – YAML string space representation

Return type

Mixture

static load_from_hdf5(filename, path) Mixture

Load mixture from hdf5 file.

Parameters
  • filename (string) – path to hdf5 file

  • path (string) – path inside hdf5 file

Return type

Mixture

static load_from_yaml(path) Mixture

Load mixture from file.

Parameters

path (string) – path to YAML file

Return type

Mixture

marginal(*args, **kwargs) array

Evaluate marginal at samples for select dimensions.

marginal(samples, selection)
marginal(grid)
Parameters
  • samples ((n,nselect) array) – Array of samples

  • selection ((ndim,) boolean array) – Selected dimensions for marginal evaluation.

  • grid (Grid) – Grid on subspace of mixture

Returns

Marginal probabilities.

Return type

ndarray

merge(samples, random) None

Merge samples into the mixture.

New mixture components are added at the sample location with the default kernel bandwidth and merged with existing components if the mahalanobis distance is below the threshold.

Parameters
  • samples ((n,ndim) array) – Array of samples

  • random (bool) – Whether the samples will be randomized before merging.

partial()

Partially evaluate mixture at samples for select dimensions.

Parameters
  • samples ((n,nselect) array) – Array of samples

  • selection ((ndim,) boolean array) – Selected dimensions for partial evaluation.

Returns

Partial log probabilities

Return type

(ncomp,nsamples) array

partialize(*args, **kwargs) PartialMixture

Partially evaluate mixture at grid points for select dimensions.

partialize(grid)
partialize(samples, selection)
Parameters
  • grid (Grid) – Grid on subspace of mixture

  • samples ((n,nselect) array) – Array of samples

  • selection ((ndim,) boolean array) – Selected dimensions for partial evaluation.

Return type

PartialMixture

save_to_hdf5(filename, flags, path) None

Save mixture to hdf5 file.

Parameters
  • filename (str) – path to hdf5 file

  • flags (int) – flags for file creation

  • path (str) – path inside hdf5 file

save_to_yaml(path) None

Save mixture to YAML file.

Parameters

path (string) – path tho YAML file

to_yaml() str

Represent mixture as YAML.

Return type

string