Coder Social home page Coder Social logo

krunolp / non_param_score_est Goto Github PK

View Code? Open in Web Editor NEW
0.0 1.0 0.0 152 KB

Repository for the non_param_score_est package.

Home Page: https://pypi.org/project/non-param-score-est/

License: MIT License

Python 100.00%
non-parametric-density-estimation score-estimation

non_param_score_est's Introduction

Non-parametric score estimation

Welcome to the non_param_score_est Python package (GitHub repository, PyPi library).

Usage

Initial setup

To install the package, it is advised to have a Python 3.10 or newer environment. Then, simply run:

pip install non_param_score_est

Choosing the estimator

The following estimators are available (and the corresponding import names):

Estimator Import Name
Tikhonov regularization Tikhonov
NKEF (e.g., rate 0.75) Tikhonov(subsample_rate=0.75)
Kernel density estimator KDE
Landweber iteration Landweber
Nu-method NuMethod
Spectral Stein gradient estimator SSGE
Stein estimator Stein

Utilising the estimators

To use the estimators in your code, simply import the estimator and call the estimate_gradients_x_s or estimate_gradients_s function. For example, to utilise the Tikhonov estimator, you would write:

import numpy as np
from non_param_score_est.estimators import Tikhonov

samples = np.random.normal(1000)
est = Tikhonov(bandwidth=1., lam=1e-4)

#estimate the gradients of the generated samples
score_estimate = est.estimate_gradients_s(samples=samples)

#estimate the gradients of new query while fitting the score estimator to previously generated samples
new_query = np.random.normal(100)
new_estimate = est.estimate_gradients_s_x(queries=new_query, samples=samples)

Working with the estimators

A great way to further investigate how the estimators work is to check the plots.py file. It contains a script that generates plots of the estimators on a simple 1D and 2D examples. The plots are generated by running the following command:

from non_param_score_est.estimators import Tikhonov
from non_param_score_est.tests.plots import plotOneDim, plotTwoDim

# selecting Tikhonov regularization
est = Tikhonov(bandwidth=10., lam=1e-5)

# One-dimensional Gaussian distribution experiment
plotOneDim(estimator=est)

# Two-dimensional Gaussian distribution experiment
plotTwoDim(estimator=est)

These generate the following outputs:

One-dimensional experiment Two-dimensional experiment
One-dimensional experiment Two-dimensional experiment

Contributing

We welcome contributions! Please follow these guidelines if you'd like to contribute to the project:

  1. Fork our GitHub repository and clone it to your local machine.
  2. Create a new branch for your feature or bug fix.
  3. Make your changes and ensure that tests pass.
  4. Submit a pull request with a clear title and description.

License

This project is licensed under the MIT License - see the LICENSE file for details.

Acknowledgments

The code in JAX was inspired by the repository of the Nonparametric Score Estimators paper, by Yuhao Zhou, Jiaxin Shi, Jun Zhu.

Contact

Krunoslav Lehman Pavasovic Email: [email protected] GitHub: krunolp

non_param_score_est's People

Contributors

krunolp avatar

Watchers

 avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.