Skip to main content

Package to perform fits in both CPUs and GPUs

Project description

https://travis-ci.org/mramospe/minkit.svg?branch=master https://img.shields.io/badge/documentation-link-blue.svg https://codecov.io/gh/mramospe/minkit/branch/master/graph/badge.svg

This package provides tools to fit probability density functions (PDFs) to both unbinned and binned data, using different minimizers (like Minuit). The MinKit package appears as an alternative to existing minimization packages, like RooFit. The idea is to provide a friendly pure python API to do minimization and calculations with PDFs. It has support for both CPU and GPU backends, being very easy for the user to change from one to the other. PDFs are implemented in C++, OpenCL and CUDA, allowing a fast evaluation of the functions.

The package is built on top of the numpy and iminuit packages. The interface with CUDA and OpenCL is handled using reikna, which is itself an API for PyCUDA and PyOpenCL.

Basic example

Classes meant for the user are imported directly from the main module

import minkit

x = minkit.Parameter('x', bounds=(-10, +10))
c = minkit.Parameter('c', 0.)
s = minkit.Parameter('s', 1.)
g = minkit.Gaussian('Gaussian', x, c, s)

data = g.generate(10000)

These lines define the parameters used by a Gaussian function, and a data set is generated following this distribution. The sample can be easily fitted calling:

with minkit.unbinned_minimizer('uml', g, data) as minimizer:
   r = minimizer.migrad()

In this case minimizer is a Minuit instance, since by default Minuit is used to do the minimization. The string uml specifies the type of figure to minimize (FCN), unbinned-maximum likelihood, in this case.

The compilation of C++ sources is completely system dependent (Linux, MacOS, Windows), and it also depends on the way python has been installed. The PDFs in this package need the C++ standard from 2011. Depending on the system, functions might need to be compiled with extra flags that are not used by default in distutils. If you get errors of the type:

relocation R_X86_64_PC32 against undefined symbol

suggesting to use -fPIC option (when the system is using gcc to compile C code) or

error: ‘erf’ is not a member of ‘std’

more likely it is needed to specify the flags to use. In order to do so, simply execute your script setting the value of the environmental variable CFLAGS accordingly:

CFLAGS="-fPIC -std=c++11" python script.py

Fast installation:

This package is available on PyPi, so simply type

pip install minkit

to install the package in your current python environment. To use the latest development version, clone the repository and install with pip:

git clone https://github.com/mramospe/minkit.git
pip install minkit

In order to profit from certain features of the package, like numerical integration, it is necessary that the system has the GSL libraries visible to the compiler. To install them on Linux, you can simply run

sudo apt-get install libgsl-dev

Depending on the system, you might need to set also the necessary environment variables specifying the path to the include and libraries directory, like

export CFLAGS="$CFLAGS -I/usr/include -L/usr/lib/x86_64-linux-gnu"

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

minkit-0.0.0.dev1.tar.gz (88.6 kB view hashes)

Uploaded Source

Built Distribution

minkit-0.0.0.dev1-py3-none-any.whl (102.9 kB view hashes)

Uploaded Python 3

Supported by

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