Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Save laurentperrinet/66efec3b6acb3db3293dc8e8bbb42747 to your computer and use it in GitHub Desktop.
Save laurentperrinet/66efec3b6acb3db3293dc8e8bbb42747 to your computer and use it in GitHub Desktop.
2018-05-22_minimal_working_example_lmfit
Display the source blob
Display the rendered blob
Raw
{
"cells": [
{
"cell_type": "markdown",
"metadata": {},
"source": [
"# 0.9.7"
]
},
{
"cell_type": "code",
"execution_count": 1,
"metadata": {
"ExecuteTime": {
"end_time": "2018-05-22T13:41:58.547118Z",
"start_time": "2018-05-22T13:41:56.314011Z"
}
},
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"Uninstalling lmfit-0.9.9:\n",
" Successfully uninstalled lmfit-0.9.9\n",
"Collecting lmfit==0.9.7\n",
"Requirement already satisfied: scipy in /usr/local/lib/python3.6/site-packages (from lmfit==0.9.7) (1.1.0)\n",
"Requirement already satisfied: six in /usr/local/lib/python3.6/site-packages (from lmfit==0.9.7) (1.11.0)\n",
"Requirement already satisfied: numpy in /usr/local/lib/python3.6/site-packages (from lmfit==0.9.7) (1.14.3)\n",
"\u001b[31mtensorboard 1.8.0 has requirement bleach==1.5.0, but you'll have bleach 2.1.3 which is incompatible.\u001b[0m\n",
"\u001b[31mtensorboard 1.8.0 has requirement html5lib==0.9999999, but you'll have html5lib 1.0.1 which is incompatible.\u001b[0m\n",
"Installing collected packages: lmfit\n",
"Successfully installed lmfit-0.9.7\n"
]
}
],
"source": [
"!pip3 uninstall -y lmfit\n",
"\n",
"!pip3 install lmfit==0.9.7"
]
},
{
"cell_type": "code",
"execution_count": 2,
"metadata": {
"ExecuteTime": {
"end_time": "2018-05-22T13:41:58.553103Z",
"start_time": "2018-05-22T13:41:58.548999Z"
}
},
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"Overwriting /tmp/test.py\n"
]
}
],
"source": [
"%%writefile /tmp/test.py\n",
"import numpy as np\n",
"import lmfit\n",
"print('lmfit version =', lmfit.__version__)"
]
},
{
"cell_type": "code",
"execution_count": 3,
"metadata": {
"ExecuteTime": {
"end_time": "2018-05-22T13:41:59.580412Z",
"start_time": "2018-05-22T13:41:58.554754Z"
}
},
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"lmfit version = 0.9.7\r\n"
]
}
],
"source": [
"!python3 /tmp/test.py"
]
},
{
"cell_type": "code",
"execution_count": 4,
"metadata": {
"ExecuteTime": {
"end_time": "2018-05-22T13:41:59.586593Z",
"start_time": "2018-05-22T13:41:59.582678Z"
}
},
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"Overwriting /tmp/test.py\n"
]
}
],
"source": [
"%%writefile /tmp/test.py\n",
"\n",
"import numpy as np\n",
"import lmfit\n",
"print('lmfit version =', lmfit.__version__)\n",
"from lmfit import Model, Parameters\n",
"\n",
"N, n = 500, 50\n",
"x = np.linspace(-1, 1, N)\n",
"gamma_true = 1.\n",
"np.random.seed(7)\n",
"\n",
"def ReLU(x, gamma) :\n",
" time = np.arange(len(x))\n",
" return time * gamma * (time > 0)\n",
"\n",
"a = ReLU(x, gamma_true)\n",
"a += np.random.randn(N)\n",
"a[N//2-n:N//2+n] *= np.nan\n",
"\n",
"model = Model(ReLU)\n",
"params = Parameters()\n",
"\n",
"params.add('gamma', value=gamma_true, min=.1, max=80.)\n",
"result_deg = model.fit(a, params, x=x, fit_kws={'nan_policy': 'omit'})\n",
"\n",
"print(result_deg.values)"
]
},
{
"cell_type": "code",
"execution_count": 5,
"metadata": {
"ExecuteTime": {
"end_time": "2018-05-22T13:42:00.644737Z",
"start_time": "2018-05-22T13:41:59.587970Z"
}
},
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"lmfit version = 0.9.7\r\n",
"{'gamma': 0.9996924995050569}\r\n"
]
}
],
"source": [
"!python3 /tmp/test.py"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"# 0.9.9"
]
},
{
"cell_type": "code",
"execution_count": 6,
"metadata": {
"ExecuteTime": {
"end_time": "2018-05-22T13:42:02.844429Z",
"start_time": "2018-05-22T13:42:00.646860Z"
}
},
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"Uninstalling lmfit-0.9.7:\n",
" Successfully uninstalled lmfit-0.9.7\n",
"Collecting lmfit==0.9.9\n",
"Requirement already satisfied: six in /usr/local/lib/python3.6/site-packages (from lmfit==0.9.9) (1.11.0)\n",
"Requirement already satisfied: scipy in /usr/local/lib/python3.6/site-packages (from lmfit==0.9.9) (1.1.0)\n",
"Requirement already satisfied: asteval in /usr/local/lib/python3.6/site-packages (from lmfit==0.9.9) (0.9.12)\n",
"Requirement already satisfied: numpy in /usr/local/lib/python3.6/site-packages (from lmfit==0.9.9) (1.14.3)\n",
"\u001b[31mtensorboard 1.8.0 has requirement bleach==1.5.0, but you'll have bleach 2.1.3 which is incompatible.\u001b[0m\n",
"\u001b[31mtensorboard 1.8.0 has requirement html5lib==0.9999999, but you'll have html5lib 1.0.1 which is incompatible.\u001b[0m\n",
"Installing collected packages: lmfit\n",
"Successfully installed lmfit-0.9.9\n"
]
}
],
"source": [
"!pip3 uninstall -y lmfit\n",
"\n",
"!pip3 install lmfit==0.9.9"
]
},
{
"cell_type": "code",
"execution_count": 7,
"metadata": {
"ExecuteTime": {
"end_time": "2018-05-22T13:42:02.850371Z",
"start_time": "2018-05-22T13:42:02.846509Z"
}
},
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"Overwriting /tmp/test.py\n"
]
}
],
"source": [
"%%writefile /tmp/test.py\n",
"import numpy as np\n",
"import lmfit\n",
"print('lmfit version =', lmfit.__version__)"
]
},
{
"cell_type": "code",
"execution_count": 8,
"metadata": {
"ExecuteTime": {
"end_time": "2018-05-22T13:42:03.882082Z",
"start_time": "2018-05-22T13:42:02.851973Z"
}
},
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"lmfit version = 0.9.9\r\n"
]
}
],
"source": [
"!python3 /tmp/test.py"
]
},
{
"cell_type": "code",
"execution_count": 11,
"metadata": {
"ExecuteTime": {
"end_time": "2018-05-22T13:42:12.634257Z",
"start_time": "2018-05-22T13:42:12.630203Z"
}
},
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"Overwriting /tmp/test.py\n"
]
}
],
"source": [
"%%writefile /tmp/test.py\n",
"\n",
"import numpy as np\n",
"import lmfit\n",
"print('lmfit version =', lmfit.__version__)\n",
"from lmfit import Model, Parameters\n",
"\n",
"N, n = 500, 50\n",
"x = np.linspace(-1, 1, N)\n",
"gamma_true = 1.\n",
"np.random.seed(7)\n",
"\n",
"def ReLU(x, gamma) :\n",
" time = np.arange(len(x))\n",
" return time * gamma * (time > 0)\n",
"\n",
"a = ReLU(x, gamma_true)\n",
"a += np.random.randn(N)\n",
"a[N//2-n:N//2+n] *= np.nan\n",
"\n",
"model = Model(ReLU)\n",
"params = Parameters()\n",
"\n",
"params.add('gamma', value=gamma_true, min=.1, max=80.)\n",
"result_deg = model.fit(a, params, x=x, nan_policy='omit')\n",
"\n",
"print(result_deg.values)"
]
},
{
"cell_type": "code",
"execution_count": 12,
"metadata": {
"ExecuteTime": {
"end_time": "2018-05-22T13:42:14.291280Z",
"start_time": "2018-05-22T13:42:13.281810Z"
}
},
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"lmfit version = 0.9.9\r\n",
"{'gamma': 1.2814511526760501}\r\n"
]
}
],
"source": [
"!python3 /tmp/test.py"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": []
}
],
"metadata": {
"kernelspec": {
"display_name": "Python 3",
"language": "python",
"name": "python3"
},
"language_info": {
"codemirror_mode": {
"name": "ipython",
"version": 3
},
"file_extension": ".py",
"mimetype": "text/x-python",
"name": "python",
"nbconvert_exporter": "python",
"pygments_lexer": "ipython3",
"version": "3.6.5"
},
"toc": {
"base_numbering": 1,
"nav_menu": {},
"number_sections": true,
"sideBar": true,
"skip_h1_title": false,
"title_cell": "Table of Contents",
"title_sidebar": "Contents",
"toc_cell": false,
"toc_position": {},
"toc_section_display": true,
"toc_window_display": false
}
},
"nbformat": 4,
"nbformat_minor": 2
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment