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.3.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.3-py3-none-any.whl (19.3 kB view details)

Uploaded Python 3

File details

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

File metadata

  • Download URL: smoothde-1.4.3.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.3.tar.gz
Algorithm Hash digest
SHA256 ea596e445e46f96072d92e016cb98f8e2e81b59845ce16994f62e2340a47b72c
MD5 35f00e6053f8321d69874ab8f8a2561e
BLAKE2b-256 d817765120970bfc9ca8845fe4f80bcbf5222c69ec377283c40275a3485aa5e5

See more details on using hashes here.

File details

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

File metadata

  • Download URL: smoothde-1.4.3-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.3-py3-none-any.whl
Algorithm Hash digest
SHA256 f231c00518e9c4637eb2e9af120e77814b2ed2202943d09450aaddb2281efebf
MD5 a92afbb8b83907d25eb0a9c26fbbb72a
BLAKE2b-256 331b84be23a492637b0d79ce90ea53ff143aa175133efe2cff6b0d6d196c1d06

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