{"action":"created","issue":{"url":"https://api.github.com/repos/gbouvignies/chemex/issues/27","repository_url":"https://api.github.com/repos/gbouvignies/chemex","labels_url":"https://api.github.com/repos/gbouvignies/chemex/issues/27/labels{/name}","comments_url":"https://api.github.com/repos/gbouvignies/chemex/issues/27/comments","events_url":"https://api.github.com/repos/gbouvignies/chemex/issues/27/events","html_url":"https://github.com/gbouvignies/chemex/issues/27","id":191518150,"number":27,"title":"negative R2s / parameter limits ignored","user":{"login":"chriswaudby","id":13577612,"avatar_url":"https://avatars.githubusercontent.com/u/13577612?v=3","gravatar_id":"","url":"https://api.github.com/users/chriswaudby","html_url":"https://github.com/chriswaudby","followers_url":"https://api.github.com/users/chriswaudby/followers","following_url":"https://api.github.com/users/chriswaudby/following{/other_user}","gists_url":"https://api.github.com/users/chriswaudby/gists{/gist_id}","starred_url":"https://api.github.com/users/chriswaudby/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/chriswaudby/subscriptions","organizations_url":"https://api.github.com/users/chriswaudby/orgs","repos_url":"https://api.github.com/users/chriswaudby/repos","events_url":"https://api.github.com/users/chriswaudby/events{/privacy}","received_events_url":"https://api.github.com/users/chriswaudby/received_events","type":"User","site_admin":false},"labels":[],"state":"open","locked":false,"assignee":null,"assignees":[],"milestone":null,"comments":4,"created_at":"2016-11-24T13:17:55Z","updated_at":"2016-11-24T17:21:18Z","closed_at":null,"body":"Hi,\r\n\r\nI've got an issue with some CEST and CPMG fitting. I'm finding that occasionally fit crash with the error:\r\n```\r\nTraceback (most recent call last):\r\n  File \"/Users/chris/anaconda/envs/chemex/bin/chemex\", line 11, in <module>\r\n    load_entry_point('chemex', 'console_scripts', 'chemex')()\r\n  File \"/Users/chris/git/chemex/chemex/chemex.py\", line 157, in main\r\n    params = fit_write_plot(args, params, data, output_dir)\r\n  File \"/Users/chris/git/chemex/chemex/chemex.py\", line 116, in fit_write_plot\r\n    params = fitting.run_fit(args.method, params, data)\r\n  File \"/Users/chris/git/chemex/chemex/fitting.py\", line 39, in run_fit\r\n    result = minimizer.minimize(params=c_params)\r\n  File \"/Users/chris/anaconda/envs/chemex/lib/python3.5/site-packages/lmfit/minimizer.py\", line 1242, in minimize\r\n    return function(**kwargs)\r\n  File \"/Users/chris/anaconda/envs/chemex/lib/python3.5/site-packages/lmfit/minimizer.py\", line 1072, in leastsq\r\n    lsout = scipy_leastsq(self.__residual, vars, **lskws)\r\n  File \"/Users/chris/anaconda/envs/chemex/lib/python3.5/site-packages/scipy/optimize/minpack.py\", line 387, in leastsq\r\n    gtol, maxfev, epsfcn, factor, diag)\r\n  File \"/Users/chris/anaconda/envs/chemex/lib/python3.5/site-packages/lmfit/minimizer.py\", line 371, in __residual\r\n    out = _nan_policy(out, nan_policy=self.nan_policy)\r\n  File \"/Users/chris/anaconda/envs/chemex/lib/python3.5/site-packages/lmfit/minimizer.py\", line 1432, in _nan_policy\r\n    raise ValueError(\"The input contains nan values\")\r\n```\r\n\r\nI added some debugging code to dump parameters on this error, and the crash looks like an overflow from a massively negative R2 value:\r\n```\r\n('__n_r2_c_n____r_104n_r____t_37__point__5_t____b_800__point__1_b__',\r\n  <Parameter '__n_r2_c_n____r_104n_r____t_37__point__5_t____b_800__point__1_b__', -5865.3896103458328, bounds=[-inf:inf]>)\r\n```\r\n\r\nI added in some parameter bounds in my parameters file to try and avoid this issue:\r\n```\r\nr2_a            = 10.0 [5, 50]   ;in s^-1\r\nr2_b            = 10.0 [5, 50]\r\nr2_c            = 10.0 [5, 50]\r\n```\r\n\r\nHowever, I still get the same crash, with negative parameters. When I examine the parameter dump it seems the bounds for state A are being respected but the bounds for the second and third states haven't been parsed or have been reset:\r\n```\r\n('__n_r2_a_n____r_104n_r____t_37__point__5_t____b_800__point__1_b__',\r\n  <Parameter '__n_r2_a_n____r_104n_r____t_37__point__5_t____b_800__point__1_b__', 7.1813557193376631, bounds=[5.0:50.0]>),\r\n('__n_r2_b_n____r_104n_r____t_37__point__5_t____b_800__point__1_b__',\r\n  <Parameter '__n_r2_b_n____r_104n_r____t_37__point__5_t____b_800__point__1_b__', 29.192100993005784, bounds=[-inf:inf]>),\r\n('__n_r2_c_n____r_104n_r____t_37__point__5_t____b_800__point__1_b__',\r\n  <Parameter '__n_r2_c_n____r_104n_r____t_37__point__5_t____b_800__point__1_b__', -5865.3896103458328, bounds=[-inf:inf]>),\r\n```\r\n\r\nAny ideas?\r\n\r\nBest,\r\n\r\nChris\r\n"},"comment":{"url":"https://api.github.com/repos/gbouvignies/chemex/issues/comments/262821164","html_url":"https://github.com/gbouvignies/chemex/issues/27#issuecomment-262821164","issue_url":"https://api.github.com/repos/gbouvignies/chemex/issues/27","id":262821164,"user":{"login":"chriswaudby","id":13577612,"avatar_url":"https://avatars.githubusercontent.com/u/13577612?v=3","gravatar_id":"","url":"https://api.github.com/users/chriswaudby","html_url":"https://github.com/chriswaudby","followers_url":"https://api.github.com/users/chriswaudby/followers","following_url":"https://api.github.com/users/chriswaudby/following{/other_user}","gists_url":"https://api.github.com/users/chriswaudby/gists{/gist_id}","starred_url":"https://api.github.com/users/chriswaudby/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/chriswaudby/subscriptions","organizations_url":"https://api.github.com/users/chriswaudby/orgs","repos_url":"https://api.github.com/users/chriswaudby/repos","events_url":"https://api.github.com/users/chriswaudby/events{/privacy}","received_events_url":"https://api.github.com/users/chriswaudby/received_events","type":"User","site_admin":false},"created_at":"2016-11-24T17:21:18Z","updated_at":"2016-11-24T17:21:18Z","body":"OK, just checked and I don’t see it with that example either - but I do see it for `examples/CEST/N15_InPhase_3States`. I've added some code in `datasets/calculate_residuals` to dump the parameters at each step:\r\n```python\r\nif change < -threshold:\r\n    nvarys = len([param for param in params.values() if param.vary])\r\n    redchi = chisq / (self.ndata - nvarys)\r\n\r\n    print(\"  * {:.3e} / {:.3e}\".format(chisq, redchi))\r\n                \r\n    print(\"Parameters:\")\r\n    import pprint\r\n    pprint.pprint(params)\r\n```\r\n\r\nand when I run the three-state CEST example I get:\r\n\r\n```\r\n step 1 \r\n--------\r\n\r\n[NUC->13N, T->1.0C]\r\nChi2 / Reduced Chi2:\r\n  * 2.234e+03 / 1.861e+01\r\nParameters:\r\nParameters([('__n_pb_n____t_1__point__0_t__',\r\n             <Parameter '__n_pb_n____t_1__point__0_t__', value=0.01 (fixed), bounds=[0.0:1.0]>),\r\n            ('__n_pc_n____t_1__point__0_t__',\r\n             <Parameter '__n_pc_n____t_1__point__0_t__', value=0.0050000000000000001 (fixed), bounds=[0.0:1.0]>),\r\n            ('__n_kex_ab_n____t_1__point__0_t__',\r\n             <Parameter '__n_kex_ab_n____t_1__point__0_t__', value=200.0 (fixed), bounds=[0.0:inf]>),\r\n            ('__n_kex_ac_n____t_1__point__0_t__',\r\n             <Parameter '__n_kex_ac_n____t_1__point__0_t__', value=0.0 (fixed), bounds=[0.0:inf]>),\r\n            ('__n_kex_bc_n____t_1__point__0_t__',\r\n             <Parameter '__n_kex_bc_n____t_1__point__0_t__', value=4000.0 (fixed), bounds=[0.0:inf]>),\r\n            ('__n_dw_ab_n____r_13n_r____t_1__point__0_t__',\r\n             <Parameter '__n_dw_ab_n____r_13n_r____t_1__point__0_t__', 4.226, bounds=[-inf:inf]>),\r\n            ('__n_dw_ac_n____r_13n_r____t_1__point__0_t__',\r\n             <Parameter '__n_dw_ac_n____r_13n_r____t_1__point__0_t__', 4.226, bounds=[-inf:inf]>),\r\n            ('__n_cs_a_n____r_13n_r____t_1__point__0_t__',\r\n             <Parameter '__n_cs_a_n____r_13n_r____t_1__point__0_t__', value=108.20699999999999 (fixed), bounds=[-inf:inf]>),\r\n            ('__n_r2_a_n____r_13n_r____t_1__point__0_t____b_499__point__2_b__',\r\n             <Parameter '__n_r2_a_n____r_13n_r____t_1__point__0_t____b_499__point__2_b__', 10.0, bounds=[0.0:inf]>),\r\n            ('__n_r1_a_n____r_13n_r____t_1__point__0_t____b_499__point__2_b__',\r\n             <Parameter '__n_r1_a_n____r_13n_r____t_1__point__0_t____b_499__point__2_b__', 1.2999999999999998, bounds=[0.0:inf]>),\r\n            ('__n_cs_b_n____r_13n_r____t_1__point__0_t__',\r\n             <Parameter '__n_cs_b_n____r_13n_r____t_1__point__0_t__', 112.43299999999999, bounds=[-inf:inf], expr='__n_cs_a_n____r_13n_r____t_1__point__0_t__ + __n_dw_ab_n____r_13n_r____t_1__point__0_t__'>),\r\n            ('__n_r2_b_n____r_13n_r____t_1__point__0_t____b_499__point__2_b__',\r\n             <Parameter '__n_r2_b_n____r_13n_r____t_1__point__0_t____b_499__point__2_b__', 10.0, bounds=[-inf:inf], expr='__n_r2_a_n____r_13n_r____t_1__point__0_t____b_499__point__2_b__'>),\r\n            ('__n_r1_b_n____r_13n_r____t_1__point__0_t____b_499__point__2_b__',\r\n             <Parameter '__n_r1_b_n____r_13n_r____t_1__point__0_t____b_499__point__2_b__', 1.2999999999999998, bounds=[0.0:inf], expr='__n_r1_a_n____r_13n_r____t_1__point__0_t____b_499__point__2_b__'>),\r\n            ('__n_cs_c_n____r_13n_r____t_1__point__0_t__',\r\n             <Parameter '__n_cs_c_n____r_13n_r____t_1__point__0_t__', 112.43299999999999, bounds=[-inf:inf], expr='__n_cs_a_n____r_13n_r____t_1__point__0_t__ + __n_dw_ac_n____r_13n_r____t_1__point__0_t__'>),\r\n            ('__n_r2_c_n____r_13n_r____t_1__point__0_t____b_499__point__2_b__',\r\n             <Parameter '__n_r2_c_n____r_13n_r____t_1__point__0_t____b_499__point__2_b__', 10.0, bounds=[-inf:inf], expr='__n_r2_a_n____r_13n_r____t_1__point__0_t____b_499__point__2_b__'>),\r\n            ('__n_r1_c_n____r_13n_r____t_1__point__0_t____b_499__point__2_b__',\r\n             <Parameter '__n_r1_c_n____r_13n_r____t_1__point__0_t____b_499__point__2_b__', 1.2999999999999998, bounds=[0.0:inf], expr='__n_r1_a_n____r_13n_r____t_1__point__0_t____b_499__point__2_b__'>)])\r\n```\r\n\r\nIt looks like the bounds are applied for the first state R2, but not the others?\r\n"}}
{"actor":{"display_login":"chriswaudby"}}