Skip to main content

This package uses smoothing to create a density estimate

Project description

SmoothDE

smoothDE is a python library that trains on data samples to learn a probability distribution and then make predictions about the probability of points.

plot

It uses a lattice based approach to estimate the smoothness of a potential probability distribution. Thus, while smoothDE can predict distributions in 1, 2, 3, or more dimensions, as the lattice increases in dimension smoothDE becomes slower.

Module docs: gitlab pages

Installation

The only tricky part of this install seems to be the scikit-sparse library. I suggest installing the fundamental libraries first as this installation gives faster scikit-sparse results:

# mac
brew install suite-sparse

# linux
sudo apt-get install libsuitesparse-dev

these commands were lifted straight from the scikit-sparse installation instructions. The conda installation did not perform operations as quickly as a fresh install of the above system libraries. smoothDE should install scikit-sparse as a pip, but you can install it yourself if the next step doesn't work.

The repositiory is at https://gitlab.com/rhys-m-adams/smoothde, but you don't need to download it to run it. If you download the repository, you should be able to run:

pip install -e <file path>/smoothDE/

The simpler way is to use the internet

pip install smoothDE

The preprint describing this library mathematically can be found and cited at here currently: preprint

Quick usage

To fit a density estimator:

import numpy as np
from smoothDE.estimator import DensityFitter
X = np.array([[3, 1],[2,2],[1, 1],[2,3]]) #observed data points, 3 samples in 2D
box = [[0,4,32],[0,4,32]] # fit field from 0 to 4, with 32 gridpoints in 2 dimensions
dr = DensityFitter(box, dpow=2) # create the smoothDE object
record = dr.fit(X) # fit the data, returns a record of the fit results
phi = dr.predict(X) # predict phi from data, X in this case for conciseness
p = np.exp(-phi) # pdf estimate of X points

If you have many features and want to just calculate the 1 dimensional fields, you can use the make_subfields module:

from smoothDE.make_subfields import MakeSubfields

trf = MakeSubfields([2], [128],n_threads=1, paired=True)
trf.fit(X, np.array([0,0,1, 1]))
sub_fields = trf.predict(X)
print(sub_fields)
sub_field_array = trf.transform(X)
print(sub_field_array)

For 2D fields, the lists need to be length 2 in MakeSubfieds;

from smoothDE.make_subfields import MakeSubfields

trf = MakeSubfields([2, 2], [128, 48],n_threads=1, paired=True)
trf.fit(X, np.array([0,0,1, 1]))
sub_fields = trf.predict(X)
print(sub_fields)
sub_field_array = trf.transform(X)
print(sub_field_array)

Demo also shown at youtube demo

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

smoothde-1.4.2.tar.gz (16.9 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

smoothde-1.4.2-py3-none-any.whl (19.3 kB view details)

Uploaded Python 3

File details

Details for the file smoothde-1.4.2.tar.gz.

File metadata

  • Download URL: smoothde-1.4.2.tar.gz
  • Upload date:
  • Size: 16.9 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.14.0

File hashes

Hashes for smoothde-1.4.2.tar.gz
Algorithm Hash digest
SHA256 662df76fe1a6398f06b10dc6f190248188320ad32b6701fcb3883e4edd07a804
MD5 d6663b7f3db59f348da436efb0cffbc9
BLAKE2b-256 ad9c01b94c6730784c120dd15e438ee53a2cf5e43812464c344a618de01daa9f

See more details on using hashes here.

File details

Details for the file smoothde-1.4.2-py3-none-any.whl.

File metadata

  • Download URL: smoothde-1.4.2-py3-none-any.whl
  • Upload date:
  • Size: 19.3 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.14.0

File hashes

Hashes for smoothde-1.4.2-py3-none-any.whl
Algorithm Hash digest
SHA256 07487c5df7cdd0d7b5330b2b4c92cfdd54a64d31ece0d40a6855814c6597fbb7
MD5 b1876a11eae360ac6084b84ded0e897b
BLAKE2b-256 3d69dd773ee8fcfe34dfeb8da8bf58d0108234ea7d5033dafc7637f034b827f3

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page