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.
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. You should be able to run:
pip install -e <file path>/smoothDE/
or 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
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file smoothde-1.4.1.tar.gz.
File metadata
- Download URL: smoothde-1.4.1.tar.gz
- Upload date:
- Size: 16.9 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.0.1 CPython/3.12.3
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
d1ed2b958bfa3391db83d8328377d3c40de178d5407e3a76198b0b8cd9d239f8
|
|
| MD5 |
f39e91687fa0c8fba3dcb98a543bdb8f
|
|
| BLAKE2b-256 |
1d7fb99cda9258e549a67a9c58509498355f6439d756ee85aea465da8368e42f
|
File details
Details for the file smoothde-1.4.1-py3-none-any.whl.
File metadata
- Download URL: smoothde-1.4.1-py3-none-any.whl
- Upload date:
- Size: 19.3 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.0.1 CPython/3.12.3
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
599da7ab1ec89228c18a4bb4c23071915770df675a74afc4a44afcd7756329c7
|
|
| MD5 |
ff1904106e690f8326b737c1284c520f
|
|
| BLAKE2b-256 |
24685e08339f15346f49a2f5e8300229a85b3bce21ca2139602f3dcaaf131393
|