{"action":"created","comment":{"url":"https://api.github.com/repos/pgmpy/pgmpy/pulls/comments/34926646","id":34926646,"diff_hunk":"@@ -0,0 +1,172 @@\n+from pgmpy.inference import Inference\n+from pgmpy.models import MarkovModel\n+import numpy as np\n+import itertools as it\n+import copy\n+\n+\n+class Mplp(Inference):\n+    \"\"\"\n+    Class for performing approximate inference using Max-Product Linear Programming method.\n+\n+    We derive message passing updates that result in monotone decrease of the dual of the\n+    MAP LP Relaxation.\n+\n+    Parameters\n+    ----------\n+    model: MarkovModel for which inference is to be performed.\n+    Examples\n+    --------\n+    >>> from pgmpy.models import MarkovModel\n+    >>> from pgmpy.factors import Factor\n+    >>> import numpy as np\n+    >>> student = MarkovModel()\n+    >>> student.add_edges_from([('A', 'B'), ('B', 'C'), ('C', 'D'), ('E', 'F')])\n+    >>> factor_a = Factor(['A'], cardinality=[2], value=np.array([0.54577, 1.8323]))\n+    >>> factor_b = Factor(['B'], cardinality=[2], value=np.array([0.93894, 1.065]))\n+    >>> factor_c = Factor(['C'], cardinality=[2], value=np.array([0.89205, 1.121]))\n+    >>> factor_d = Factor(['D'], cardinality=[2], value=np.array([0.56292, 1.7765]))\n+    >>> factor_e = Factor(['E'], cardinality=[2], value=np.array([0.47117, 2.1224]))\n+    >>> factor_f = Factor(['F'], cardinality=[2], value=np.array([1.5093, 0.66257]))\n+    >>> factor_a_b = Factor(['A', 'B'], cardinality=[2, 2], value=np.array([1.3207, 0.75717, 0.75717, 1.3207]))\n+    >>> factor_b_c = Factor(['B', 'C'], cardinality=[2, 2], value=np.array([0.00024189, 4134.2, 4134.2, 0.00024189]))\n+    >>> factor_c_d = Factor(['C', 'D'], cardinality=[2, 2], value=np.array([0.0043227, 231.34, 231.34, 0.0043227]))\n+    >>> factor_d_e = Factor(['E', 'F'], cardinality=[2, 2], value=np.array([31.228, 0.032023, 0.032023, 31.228]))\n+    >>> student.add_factors(factor_a, factor_b, factor_c, factor_d, factor_e, factor_f, factor_a_b,\n+    ...    factor_b_c, factor_c_d, factor_d_e)\n+    >>> mplp = Mplp(student)\n+    \"\"\"\n+    def __init__(self, model):\n+        super().__init__(model)\n+\n+        if not isinstance(model, MarkovModel):\n+            raise ValueError('Only MarkovModel is supported')\n+\n+        # S = { c ∩ c': c, c' ∈ C, c ∩ c' != Null}\n+        # It should be ready before initializing Cluster.\n+        # Nothing but union of all the edge variables.\n+        self.intersection_set_variables = set()\n+\n+        # The generation of all the Intersections of all\n+        # the pairwise edges taken one at a time\n+        for edge_pair in it.combinations([sorted(i) for i in model.edges()], 2):\n+            self.intersection_set_variables.add(frozenset(edge_pair[0]) & frozenset(edge_pair[1]))\n+\n+        # Initialize each cluster for variables appearing in each of the edges.\n+        # We also need the potentials of the current edges.\n+        self.cluster_set = []\n+        scope_list = [i.scope() for i in model.get_factors()]","path":"pgmpy/inference/mplp.py","position":58,"original_position":58,"commit_id":"04cbba360683e78bee3f03936b94c5dc25e76ace","original_commit_id":"04cbba360683e78bee3f03936b94c5dc25e76ace","user":{"login":"abinashpanda","id":2332955,"avatar_url":"https://avatars.githubusercontent.com/u/2332955?v=3","gravatar_id":"","url":"https://api.github.com/users/abinashpanda","html_url":"https://github.com/abinashpanda","followers_url":"https://api.github.com/users/abinashpanda/followers","following_url":"https://api.github.com/users/abinashpanda/following{/other_user}","gists_url":"https://api.github.com/users/abinashpanda/gists{/gist_id}","starred_url":"https://api.github.com/users/abinashpanda/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/abinashpanda/subscriptions","organizations_url":"https://api.github.com/users/abinashpanda/orgs","repos_url":"https://api.github.com/users/abinashpanda/repos","events_url":"https://api.github.com/users/abinashpanda/events{/privacy}","received_events_url":"https://api.github.com/users/abinashpanda/received_events","type":"User","site_admin":false},"body":"Please don't use variables like ```i```. You can converted this a\r\n\r\n```python\r\nscope_list = [factor.scope() for factor in model.get_factors()]\r\n```","created_at":"2015-07-17T20:13:06Z","updated_at":"2015-07-17T20:13:06Z","html_url":"https://github.com/pgmpy/pgmpy/pull/449#discussion_r34926646","pull_request_url":"https://api.github.com/repos/pgmpy/pgmpy/pulls/449","_links":{"self":{"href":"https://api.github.com/repos/pgmpy/pgmpy/pulls/comments/34926646"},"html":{"href":"https://github.com/pgmpy/pgmpy/pull/449#discussion_r34926646"},"pull_request":{"href":"https://api.github.com/repos/pgmpy/pgmpy/pulls/449"}}},"pull_request":{"url":"https://api.github.com/repos/pgmpy/pgmpy/pulls/449","id":40216176,"html_url":"https://github.com/pgmpy/pgmpy/pull/449","diff_url":"https://github.com/pgmpy/pgmpy/pull/449.diff","patch_url":"https://github.com/pgmpy/pgmpy/pull/449.patch","issue_url":"https://api.github.com/repos/pgmpy/pgmpy/issues/449","number":449,"state":"open","locked":false,"title":"Mplp reworked","user":{"login":"kislayabhi","id":5661623,"avatar_url":"https://avatars.githubusercontent.com/u/5661623?v=3","gravatar_id":"","url":"https://api.github.com/users/kislayabhi","html_url":"https://github.com/kislayabhi","followers_url":"https://api.github.com/users/kislayabhi/followers","following_url":"https://api.github.com/users/kislayabhi/following{/other_user}","gists_url":"https://api.github.com/users/kislayabhi/gists{/gist_id}","starred_url":"https://api.github.com/users/kislayabhi/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/kislayabhi/subscriptions","organizations_url":"https://api.github.com/users/kislayabhi/orgs","repos_url":"https://api.github.com/users/kislayabhi/repos","events_url":"https://api.github.com/users/kislayabhi/events{/privacy}","received_events_url":"https://api.github.com/users/kislayabhi/received_events","type":"User","site_admin":false},"body":"@abinashpanda , @ankurankan \r\nI have written the update_message method here. \r\nAlso did some changes in the factor class to meet my needs. (As it is getting reworked so did some hacks there)","created_at":"2015-07-17T09:55:34Z","updated_at":"2015-07-17T20:13:06Z","closed_at":null,"merged_at":null,"merge_commit_sha":"a128ae828e6098292cf80498706ab4c748d66dd4","assignee":null,"milestone":null,"commits_url":"https://api.github.com/repos/pgmpy/pgmpy/pulls/449/commits","review_comments_url":"https://api.github.com/repos/pgmpy/pgmpy/pulls/449/comments","review_comment_url":"https://api.github.com/repos/pgmpy/pgmpy/pulls/comments{/number}","comments_url":"https://api.github.com/repos/pgmpy/pgmpy/issues/449/comments","statuses_url":"https://api.github.com/repos/pgmpy/pgmpy/statuses/04cbba360683e78bee3f03936b94c5dc25e76ace","head":{"label":"kislayabhi:m_p_reworked","ref":"m_p_reworked","sha":"04cbba360683e78bee3f03936b94c5dc25e76ace","user":{"login":"kislayabhi","id":5661623,"avatar_url":"https://avatars.githubusercontent.com/u/5661623?v=3","gravatar_id":"","url":"https://api.github.com/users/kislayabhi","html_url":"https://github.com/kislayabhi","followers_url":"https://api.github.com/users/kislayabhi/followers","following_url":"https://api.github.com/users/kislayabhi/following{/other_user}","gists_url":"https://api.github.com/users/kislayabhi/gists{/gist_id}","starred_url":"https://api.github.com/users/kislayabhi/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/kislayabhi/subscriptions","organizations_url":"https://api.github.com/users/kislayabhi/orgs","repos_url":"https://api.github.com/users/kislayabhi/repos","events_url":"https://api.github.com/users/kislayabhi/events{/privacy}","received_events_url":"https://api.github.com/users/kislayabhi/received_events","type":"User","site_admin":false},"repo":{"id":30786436,"name":"pgmpy","full_name":"kislayabhi/pgmpy","owner":{"login":"kislayabhi","id":5661623,"avatar_url":"https://avatars.githubusercontent.com/u/5661623?v=3","gravatar_id":"","url":"https://api.github.com/users/kislayabhi","html_url":"https://github.com/kislayabhi","followers_url":"https://api.github.com/users/kislayabhi/followers","following_url":"https://api.github.com/users/kislayabhi/following{/other_user}","gists_url":"https://api.github.com/users/kislayabhi/gists{/gist_id}","starred_url":"https://api.github.com/users/kislayabhi/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/kislayabhi/subscriptions","organizations_url":"https://api.github.com/users/kislayabhi/orgs","repos_url":"https://api.github.com/users/kislayabhi/repos","events_url":"https://api.github.com/users/kislayabhi/events{/privacy}","received_events_url":"https://api.github.com/users/kislayabhi/received_events","type":"User","site_admin":false},"private":false,"html_url":"https://github.com/kislayabhi/pgmpy","description":"Python Library for Probabilistic Graphical Models","fork":true,"url":"https://api.github.com/repos/kislayabhi/pgmpy","forks_url":"https://api.github.com/repos/kislayabhi/pgmpy/forks","keys_url":"https://api.github.com/repos/kislayabhi/pgmpy/keys{/key_id}","collaborators_url":"https://api.github.com/repos/kislayabhi/pgmpy/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/kislayabhi/pgmpy/teams","hooks_url":"https://api.github.com/repos/kislayabhi/pgmpy/hooks","issue_events_url":"https://api.github.com/repos/kislayabhi/pgmpy/issues/events{/number}","events_url":"https://api.github.com/repos/kislayabhi/pgmpy/events","assignees_url":"https://api.github.com/repos/kislayabhi/pgmpy/assignees{/user}","branches_url":"https://api.github.com/repos/kislayabhi/pgmpy/branches{/branch}","tags_url":"https://api.github.com/repos/kislayabhi/pgmpy/tags","blobs_url":"https://api.github.com/repos/kislayabhi/pgmpy/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/kislayabhi/pgmpy/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/kislayabhi/pgmpy/git/refs{/sha}","trees_url":"https://api.github.com/repos/kislayabhi/pgmpy/git/trees{/sha}","statuses_url":"https://api.github.com/repos/kislayabhi/pgmpy/statuses/{sha}","languages_url":"https://api.github.com/repos/kislayabhi/pgmpy/languages","stargazers_url":"https://api.github.com/repos/kislayabhi/pgmpy/stargazers","contributors_url":"https://api.github.com/repos/kislayabhi/pgmpy/contributors","subscribers_url":"https://api.github.com/repos/kislayabhi/pgmpy/subscribers","subscription_url":"https://api.github.com/repos/kislayabhi/pgmpy/subscription","commits_url":"https://api.github.com/repos/kislayabhi/pgmpy/commits{/sha}","git_commits_url":"https://api.github.com/repos/kislayabhi/pgmpy/git/commits{/sha}","comments_url":"https://api.github.com/repos/kislayabhi/pgmpy/comments{/number}","issue_comment_url":"https://api.github.com/repos/kislayabhi/pgmpy/issues/comments{/number}","contents_url":"https://api.github.com/repos/kislayabhi/pgmpy/contents/{+path}","compare_url":"https://api.github.com/repos/kislayabhi/pgmpy/compare/{base}...{head}","merges_url":"https://api.github.com/repos/kislayabhi/pgmpy/merges","archive_url":"https://api.github.com/repos/kislayabhi/pgmpy/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/kislayabhi/pgmpy/downloads","issues_url":"https://api.github.com/repos/kislayabhi/pgmpy/issues{/number}","pulls_url":"https://api.github.com/repos/kislayabhi/pgmpy/pulls{/number}","milestones_url":"https://api.github.com/repos/kislayabhi/pgmpy/milestones{/number}","notifications_url":"https://api.github.com/repos/kislayabhi/pgmpy/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/kislayabhi/pgmpy/labels{/name}","releases_url":"https://api.github.com/repos/kislayabhi/pgmpy/releases{/id}","created_at":"2015-02-14T03:55:46Z","updated_at":"2015-02-14T03:55:46Z","pushed_at":"2015-07-17T09:50:55Z","git_url":"git://github.com/kislayabhi/pgmpy.git","ssh_url":"git@github.com:kislayabhi/pgmpy.git","clone_url":"https://github.com/kislayabhi/pgmpy.git","svn_url":"https://github.com/kislayabhi/pgmpy","homepage":null,"size":4390,"stargazers_count":0,"watchers_count":0,"language":"Python","has_issues":false,"has_downloads":true,"has_wiki":true,"has_pages":false,"forks_count":0,"mirror_url":null,"open_issues_count":0,"forks":0,"open_issues":0,"watchers":0,"default_branch":"dev"}},"base":{"label":"pgmpy:dev","ref":"dev","sha":"f3121a0add3127ddd1d3625e07d919f765b7287a","user":{"login":"pgmpy","id":5500131,"avatar_url":"https://avatars.githubusercontent.com/u/5500131?v=3","gravatar_id":"","url":"https://api.github.com/users/pgmpy","html_url":"https://github.com/pgmpy","followers_url":"https://api.github.com/users/pgmpy/followers","following_url":"https://api.github.com/users/pgmpy/following{/other_user}","gists_url":"https://api.github.com/users/pgmpy/gists{/gist_id}","starred_url":"https://api.github.com/users/pgmpy/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/pgmpy/subscriptions","organizations_url":"https://api.github.com/users/pgmpy/orgs","repos_url":"https://api.github.com/users/pgmpy/repos","events_url":"https://api.github.com/users/pgmpy/events{/privacy}","received_events_url":"https://api.github.com/users/pgmpy/received_events","type":"Organization","site_admin":false},"repo":{"id":12968651,"name":"pgmpy","full_name":"pgmpy/pgmpy","owner":{"login":"pgmpy","id":5500131,"avatar_url":"https://avatars.githubusercontent.com/u/5500131?v=3","gravatar_id":"","url":"https://api.github.com/users/pgmpy","html_url":"https://github.com/pgmpy","followers_url":"https://api.github.com/users/pgmpy/followers","following_url":"https://api.github.com/users/pgmpy/following{/other_user}","gists_url":"https://api.github.com/users/pgmpy/gists{/gist_id}","starred_url":"https://api.github.com/users/pgmpy/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/pgmpy/subscriptions","organizations_url":"https://api.github.com/users/pgmpy/orgs","repos_url":"https://api.github.com/users/pgmpy/repos","events_url":"https://api.github.com/users/pgmpy/events{/privacy}","received_events_url":"https://api.github.com/users/pgmpy/received_events","type":"Organization","site_admin":false},"private":false,"html_url":"https://github.com/pgmpy/pgmpy","description":"Python Library for Probabilistic Graphical Models","fork":false,"url":"https://api.github.com/repos/pgmpy/pgmpy","forks_url":"https://api.github.com/repos/pgmpy/pgmpy/forks","keys_url":"https://api.github.com/repos/pgmpy/pgmpy/keys{/key_id}","collaborators_url":"https://api.github.com/repos/pgmpy/pgmpy/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/pgmpy/pgmpy/teams","hooks_url":"https://api.github.com/repos/pgmpy/pgmpy/hooks","issue_events_url":"https://api.github.com/repos/pgmpy/pgmpy/issues/events{/number}","events_url":"https://api.github.com/repos/pgmpy/pgmpy/events","assignees_url":"https://api.github.com/repos/pgmpy/pgmpy/assignees{/user}","branches_url":"https://api.github.com/repos/pgmpy/pgmpy/branches{/branch}","tags_url":"https://api.github.com/repos/pgmpy/pgmpy/tags","blobs_url":"https://api.github.com/repos/pgmpy/pgmpy/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/pgmpy/pgmpy/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/pgmpy/pgmpy/git/refs{/sha}","trees_url":"https://api.github.com/repos/pgmpy/pgmpy/git/trees{/sha}","statuses_url":"https://api.github.com/repos/pgmpy/pgmpy/statuses/{sha}","languages_url":"https://api.github.com/repos/pgmpy/pgmpy/languages","stargazers_url":"https://api.github.com/repos/pgmpy/pgmpy/stargazers","contributors_url":"https://api.github.com/repos/pgmpy/pgmpy/contributors","subscribers_url":"https://api.github.com/repos/pgmpy/pgmpy/subscribers","subscription_url":"https://api.github.com/repos/pgmpy/pgmpy/subscription","commits_url":"https://api.github.com/repos/pgmpy/pgmpy/commits{/sha}","git_commits_url":"https://api.github.com/repos/pgmpy/pgmpy/git/commits{/sha}","comments_url":"https://api.github.com/repos/pgmpy/pgmpy/comments{/number}","issue_comment_url":"https://api.github.com/repos/pgmpy/pgmpy/issues/comments{/number}","contents_url":"https://api.github.com/repos/pgmpy/pgmpy/contents/{+path}","compare_url":"https://api.github.com/repos/pgmpy/pgmpy/compare/{base}...{head}","merges_url":"https://api.github.com/repos/pgmpy/pgmpy/merges","archive_url":"https://api.github.com/repos/pgmpy/pgmpy/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/pgmpy/pgmpy/downloads","issues_url":"https://api.github.com/repos/pgmpy/pgmpy/issues{/number}","pulls_url":"https://api.github.com/repos/pgmpy/pgmpy/pulls{/number}","milestones_url":"https://api.github.com/repos/pgmpy/pgmpy/milestones{/number}","notifications_url":"https://api.github.com/repos/pgmpy/pgmpy/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/pgmpy/pgmpy/labels{/name}","releases_url":"https://api.github.com/repos/pgmpy/pgmpy/releases{/id}","created_at":"2013-09-20T08:18:58Z","updated_at":"2015-07-15T17:41:47Z","pushed_at":"2015-07-17T09:55:35Z","git_url":"git://github.com/pgmpy/pgmpy.git","ssh_url":"git@github.com:pgmpy/pgmpy.git","clone_url":"https://github.com/pgmpy/pgmpy.git","svn_url":"https://github.com/pgmpy/pgmpy","homepage":null,"size":6380,"stargazers_count":103,"watchers_count":103,"language":"Python","has_issues":true,"has_downloads":true,"has_wiki":true,"has_pages":false,"forks_count":49,"mirror_url":null,"open_issues_count":85,"forks":49,"open_issues":85,"watchers":103,"default_branch":"dev"}},"_links":{"self":{"href":"https://api.github.com/repos/pgmpy/pgmpy/pulls/449"},"html":{"href":"https://github.com/pgmpy/pgmpy/pull/449"},"issue":{"href":"https://api.github.com/repos/pgmpy/pgmpy/issues/449"},"comments":{"href":"https://api.github.com/repos/pgmpy/pgmpy/issues/449/comments"},"review_comments":{"href":"https://api.github.com/repos/pgmpy/pgmpy/pulls/449/comments"},"review_comment":{"href":"https://api.github.com/repos/pgmpy/pgmpy/pulls/comments{/number}"},"commits":{"href":"https://api.github.com/repos/pgmpy/pgmpy/pulls/449/commits"},"statuses":{"href":"https://api.github.com/repos/pgmpy/pgmpy/statuses/04cbba360683e78bee3f03936b94c5dc25e76ace"}}}}