{ "cells": [ { "cell_type": "markdown", "metadata": {}, "source": [ "# Fit a distribution by maximum likelihood" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "In this example we are going to estimate the parameters of a parametric by generic numerical optimization of the likelihood.\n", "\n", "The likelihood of a sample $X$ according to a parametric density function $p_{\\underline{\\theta}}$ is:\n", "$$likelihood(\\underline{x}_1, \\dots, \\underline{x}_n,\\underline{\\theta}) = \\prod_{i=1}^n p_{\\underline{\\theta}}(\\underline{x}_i)$$" ] }, { "cell_type": "code", "execution_count": 1, "metadata": { "collapsed": true }, "outputs": [], "source": [ "from __future__ import print_function\n", "import openturns as ot\n", "import math as m" ] }, { "cell_type": "code", "execution_count": 2, "metadata": { "collapsed": true }, "outputs": [], "source": [ "# Create data from a gaussian pdf with mu=4, sigma=1.5\n", "sample = ot.Normal(4.0, 1.5).getSample(200)" ] }, { "cell_type": "code", "execution_count": 3, "metadata": { "collapsed": true }, "outputs": [], "source": [ "# Create the search interval of (mu, sigma): the constraint is sigma>0\n", "lowerBound = [-1.0, 1.0e-4]\n", "upperBound = [-1.0, -1.0]\n", "finiteLowerBound = [False, True]\n", "finiteUpperBound = [False, False]\n", "bounds = ot.Interval(lowerBound, upperBound, finiteLowerBound, finiteUpperBound)" ] }, { "cell_type": "code", "execution_count": 4, "metadata": {}, "outputs": [ { "data": { "text/html": [ "
[4.9123,2.81156]
\n",
"
[3.94055,1.48893]
\n",
"