{"id":20526223,"url":"https://github.com/pythoncharmers/scipy-maxentropy","last_synced_at":"2026-05-21T16:10:16.484Z","repository":{"id":227952020,"uuid":"772797075","full_name":"PythonCharmers/scipy-maxentropy","owner":"PythonCharmers","description":"The `maxentropy` package that was in SciPy until v0.11.0","archived":false,"fork":false,"pushed_at":"2024-03-16T01:37:21.000Z","size":86,"stargazers_count":0,"open_issues_count":0,"forks_count":0,"subscribers_count":2,"default_branch":"master","last_synced_at":"2025-01-16T11:27:00.248Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":null,"language":"Python","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"other","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/PythonCharmers.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE.md","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2024-03-15T23:23:35.000Z","updated_at":"2024-03-15T23:24:07.000Z","dependencies_parsed_at":"2024-03-22T07:30:56.875Z","dependency_job_id":null,"html_url":"https://github.com/PythonCharmers/scipy-maxentropy","commit_stats":null,"previous_names":["pythoncharmers/scipy-maxentropy"],"tags_count":0,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/PythonCharmers%2Fscipy-maxentropy","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/PythonCharmers%2Fscipy-maxentropy/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/PythonCharmers%2Fscipy-maxentropy/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/PythonCharmers%2Fscipy-maxentropy/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/PythonCharmers","download_url":"https://codeload.github.com/PythonCharmers/scipy-maxentropy/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":242133343,"owners_count":20077095,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":[],"created_at":"2024-11-15T23:13:14.560Z","updated_at":"2026-05-21T16:10:16.424Z","avatar_url":"https://github.com/PythonCharmers.png","language":"Python","funding_links":[],"categories":[],"sub_categories":[],"readme":"# scipy-maxentropy: maximum entropy models\n\nThis is the former `scipy.maxentropy` package that was available in SciPy up to\nversion 0.10.1. It was under-maintained and later removed in SciPy 0.11. It is\nnow available as this separate package for backward compatibility.\n\nFor new projects, consider the\n[maxentropy](https://github.com/PythonCharmers/maxentropy) package instead,\nwhich offers a more modern scikit-learn compatible API.\n\n## Purpose\n\nThis package fits \"exponential family\" models, including models of maximum\nentropy and minimum KL divergence to other models, subject to linear constraints\non the expectations of arbitrary feature statistics. Applications include\nlanguage models for natural language processing and understanding, machine\ntranslation, etc., environmental species modelling, image reconstruction, and\nothers.\n\n## Quickstart\n\nHere is a quick usage example based on the trivial machine translation example\nfrom the paper 'A maximum entropy approach to natural language processing' by\nBerger et al., Computational Linguistics, 1996.\n\nConsider the translation of the English word 'in' into French. Assume we notice\nin a corpus of parallel texts the following facts:\n\n    (1)    p(dans) + p(en) + p(à) + p(au cours de) + p(pendant) = 1\n    (2)    p(dans) + p(en) = 3/10\n    (3)    p(dans) + p(à)  = 1/2\n\nThis code finds the probability distribution with maximal entropy subject to\nthese constraints.\n\n```python\nfrom scipy_maxentropy import Model    # previously scipy.maxentropy\n\nsamplespace = ['dans', 'en', 'à', 'au cours de', 'pendant']\n\ndef f0(x):\n    return x in samplespace\n\ndef f1(x):\n    return x=='dans' or x=='en'\n\ndef f2(x):\n    return x=='dans' or x=='à'\n\nf = [f0, f1, f2]\n\nmodel = Model(f, samplespace)\n\n# Now set the desired feature expectations\nb = [1.0, 0.3, 0.5]\n\nmodel.verbose = False    # set to True to show optimization progress\n\n# Fit the model\nmodel.fit(b)\n\n# Output the distribution\nprint()\nprint(\"Fitted model parameters are:\\n\" + str(model.params))\nprint()\nprint(\"Fitted distribution is:\")\np = model.probdist()\nfor j in range(len(model.samplespace)):\n    x = model.samplespace[j]\n    print(f\"    x = {x + ':':15s} p(x) = {p[j]:.3f}\")\n\n# Now show how well the constraints are satisfied:\nprint()\nprint(\"Desired constraints:\")\nprint(\"    sum(p(x))           = 1.0\")\nprint(\"    p['dans'] + p['en'] = 0.3\")\nprint(\"    p['dans'] + p['à']  = 0.5\")\nprint()\nprint(\"Actual expectations under the fitted model:\")\nprint(f\"    sum(p(x))           = {p.sum():.3f}\")\nprint(f\"    p['dans'] + p['en'] = {p[0] + p[1]:.3f}\")\nprint(f\"    p['dans'] + p['à']  = {p[0] + p[2]:.3f}\")\n```\n\n## Models available\n\nThese model classes are available:\n- `scipy_maxentropy.Model`: for models on discrete, enumerable sample spaces\n- `scipy_maxentropy.ConditionalModel`: for conditional models on discrete, enumerable sample spaces\n- `scipy_maxentropy.BigModel`: for models on sample spaces that are either continuous (and\nperhaps high-dimensional) or discrete but too large to enumerate, like all possible\nsentences in a natural language. This model uses conditional Monte Carlo methods\n(primarily importance sampling).\n\n## Background\n\nThis package fits probabilistic models of the following exponential form:\n\n$$\n   p(x) = p_0(x) \\exp(\\theta^T f(x)) / Z(\\theta; p_0)\n$$\n\nwith a real parameter vector $\\theta$ of the same length $n$ as the feature\nstatistics $f(x) = \\left(f_1(x), ..., f_n(x)\\right)$.\n\nThis is the \"closest\" model (in the sense of minimizing KL divergence or\n\"relative entropy\") to the prior model $p_0$ subject to the following additional\nconstraints on the expectations of the features:\n\n```\n    E f_1(X) = b_1\n    ...\n    E f_n(X) = b_n\n```\n\nfor some constants $b_i$, such as statistics estimated from a dataset.\n\nIn the special case where $p_0$ is the uniform distribution, this is the\n\"flattest\" model subject to the constraints, in the sense of having **maximum\nentropy**.\n\nFor more background, see, for example, Cover and Thomas (1991), *Elements of\nInformation Theory*.\n\n\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fpythoncharmers%2Fscipy-maxentropy","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fpythoncharmers%2Fscipy-maxentropy","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fpythoncharmers%2Fscipy-maxentropy/lists"}