<commit_before># python-mle

A Python package for performing Maximum Likelihood Estimates.

Inspired by [RooFit](https://root.cern.ch/drupal/content/roofit) and [pymc](https://github.com/pymc-devs/pymc).

mle is a Python framework for constructing probability models and estimating their parameters from data using the [Maximum Likelihood](http://en.wikipedia.org/wiki/Maximum_likelihood) approach.
While being less flexible than a full Bayesian probabilistic modeling framework, it can handle larger datasets (> 10^6 entries) and more complex statistical models.

To achieve maximum performance, this package (like pymc) uses [Theano](http://deeplearning.net/software/theano/tutorial/) to optimize and compile statistical models.
This also means that models can automatically be evaluated using multiple CPU cores or GPUs.
Derivatives used for the likelihood optimization are calculated using automatic differentiation.

Currently, the package is only a basic prototype and will change heavily in the future.

## Example

```python
# Create model
from mle import Normal, Mix2, var, par

x = var('x')
mu = par('mu')
frac = par('frac')
sigma1 = par('sigma1')
sigma2 = par('sigma2')

dist1 = Normal(x, mu, sigma1)
dist2 = Normal(x, mu, sigma2)
model = Mix2(frac, dist1, dist2)

# Generate data

import numpy as np
from numpy import append
from numpy.random import normal, shuffle

xs = append(normal(0, 1, 1000), normal(0, 1.5, 1000))
shuffle(xs)

# Fit model

init = {'mu': 0, 'sigma1': 1, 'sigma2': 3, 'frac': 0.6}
print(model.fit({'x': xs}, init))
```
<commit_msg>Make example more interesting<commit_after># python-mle

A Python package for performing Maximum Likelihood Estimates.

Inspired by [RooFit](https://root.cern.ch/drupal/content/roofit) and [pymc](https://github.com/pymc-devs/pymc).

mle is a Python framework for constructing probability models and estimating their parameters from data using the [Maximum Likelihood](http://en.wikipedia.org/wiki/Maximum_likelihood) approach.
While being less flexible than a full Bayesian probabilistic modeling framework, it can handle larger datasets (> 10^6 entries) and more complex statistical models.

To achieve maximum performance, this package (like pymc) uses [Theano](http://deeplearning.net/software/theano/tutorial/) to optimize and compile statistical models.
This also means that models can automatically be evaluated using multiple CPU cores or GPUs.
Derivatives used for the likelihood optimization are calculated using automatic differentiation.

Currently, the package is only a basic prototype and will change heavily in the future.

## Example

```python
# Create model
from mle import Normal, Mix2, var, par

x = var('x')
mu = par('mu')
frac = par('frac')
sigma1 = par('sigma1')
sigma2 = par('sigma2')

dist1 = Normal(x, mu, sigma1)
dist2 = Normal(x, mu, sigma2)
model = Mix2(frac, dist1, dist2)
# Mixture model with two Gaussians centered on each other

# Generate data
import numpy as np
from numpy import append
from numpy.random import normal, shuffle
from scipy.stats import bernoulli

N = 1000
N_1 = bernoulli.rvs(0.5, size=1000)
N_2 = N - N_1
xs = append(normal(0, 1, N_1), normal(0, 1.5, N_2))
shuffle(xs)

# Fit model
init = {'mu': 0, 'sigma1': 1, 'sigma2': 3, 'frac': 0.6}
print(model.fit({'x': xs}, init))
```

{'fraction_non_alphanumeric': 0.10628606134224111, 'fraction_numerical': 0.023382933495293044, 'mean_word_length': 5.1, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 5, 'https://': 4, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '3763315', 'n_tokens_mistral': 1060, 'n_tokens_neox': 973, 'n_words': 394}