{"action":"created","issue":{"url":"https://api.github.com/repos/ibab/python-mle/issues/24","labels_url":"https://api.github.com/repos/ibab/python-mle/issues/24/labels{/name}","comments_url":"https://api.github.com/repos/ibab/python-mle/issues/24/comments","events_url":"https://api.github.com/repos/ibab/python-mle/issues/24/events","html_url":"https://github.com/ibab/python-mle/issues/24","id":56347518,"number":24,"title":"Improving the API, how to implement constraints and extended likelihood","user":{"login":"MaxNoe","id":5488440,"avatar_url":"https://avatars.githubusercontent.com/u/5488440?v=3","gravatar_id":"","url":"https://api.github.com/users/MaxNoe","html_url":"https://github.com/MaxNoe","followers_url":"https://api.github.com/users/MaxNoe/followers","following_url":"https://api.github.com/users/MaxNoe/following{/other_user}","gists_url":"https://api.github.com/users/MaxNoe/gists{/gist_id}","starred_url":"https://api.github.com/users/MaxNoe/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/MaxNoe/subscriptions","organizations_url":"https://api.github.com/users/MaxNoe/orgs","repos_url":"https://api.github.com/users/MaxNoe/repos","events_url":"https://api.github.com/users/MaxNoe/events{/privacy}","received_events_url":"https://api.github.com/users/MaxNoe/received_events","type":"User","site_admin":false},"labels":[],"state":"open","locked":false,"assignee":null,"milestone":null,"comments":3,"created_at":"2015-02-03T08:25:29Z","updated_at":"2015-02-07T11:57:59Z","closed_at":null,"body":"## Constraints\r\nThese are nothing special i suppose, we just need an operator to join likelihoods with different data sizes.\r\nI think the logical approach for the end user for a constraint would be something like this:\r\n\r\n```{python}\r\n\r\n# unconstraint model for the data\r\nx = var(\"x\")\r\nmu = par(\"mu\")\r\nsigma = par(\"sigma\")\r\nmodel = Normal(x,  mu, sigma)\r\n\r\n# constraint to mu from other experiment:\r\nmu_meas = var(\"mu_con\")\r\nsigma_meas = var(\"sigma_con\")\r\nconstraint = Normal(mu_meas, mu, sigma_meas)\r\n\r\n# join the models:\r\nconst_model = Join(model, constraint)\r\n```\r\nAnd then fit as usual\r\n\r\n## Extended Likelihood\r\n\r\nIt should be as simple as this from the user point of view:\r\n\r\n```{python}\r\nx = var(\"x\")\r\nmu = par(\"mu\")\r\nsigma = par(\"sigma\")\r\nsignal_model = Normal(x, mu, sigma)\r\n\r\ntau = par(\"tau\")\r\nbackground_model = Exponential(tau)\r\n\r\nN1 = par(\"N_sig\")\r\nN2 = par(\"N_bkg\")\r\n\r\nmodel = Join(N1, signal_model, N2, background_model)\r\n```\r\n\r\nMaybe we can implement the Extended likelihood over a parameter attribute? LIke\r\n`N1 = par(\"N1\", num_events=True)` would trigger an extended Likelihood?\r\n\r\n"},"comment":{"url":"https://api.github.com/repos/ibab/python-mle/issues/comments/73361376","html_url":"https://github.com/ibab/python-mle/issues/24#issuecomment-73361376","issue_url":"https://api.github.com/repos/ibab/python-mle/issues/24","id":73361376,"user":{"login":"ibab","id":890531,"avatar_url":"https://avatars.githubusercontent.com/u/890531?v=3","gravatar_id":"","url":"https://api.github.com/users/ibab","html_url":"https://github.com/ibab","followers_url":"https://api.github.com/users/ibab/followers","following_url":"https://api.github.com/users/ibab/following{/other_user}","gists_url":"https://api.github.com/users/ibab/gists{/gist_id}","starred_url":"https://api.github.com/users/ibab/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/ibab/subscriptions","organizations_url":"https://api.github.com/users/ibab/orgs","repos_url":"https://api.github.com/users/ibab/repos","events_url":"https://api.github.com/users/ibab/events{/privacy}","received_events_url":"https://api.github.com/users/ibab/received_events","type":"User","site_admin":false},"created_at":"2015-02-07T11:57:59Z","updated_at":"2015-02-07T11:57:59Z","body":"Another idea: It should be possible to auto-join the model.\r\nThe user would write something like this:\r\n```python\r\nwith Model() as model:\r\n    # unconstrained model for the data\r\n    x = var(\"x\", observed=True)\r\n    mu = var(\"mu\")\r\n    sigma = var(\"sigma\")\r\n    dist1 = Normal(x,  mu, sigma)\r\n\r\n    # constraint to mu from other experiment:\r\n    mu_meas = var(\"mu_con\", observed=True)\r\n    sigma_meas = var(\"sigma_con\", observed=True)\r\n    constraint = Normal(mu_meas, mu, sigma_meas)\r\n```\r\n(No explicit combination of `dist` and `constraint` is performed)\r\nThen `model.fit` would be used to get the best estimate for `mu` and `sigma`."}}