{"action":"created","comment":{"url":"https://api.github.com/repos/pgmpy/pgmpy/pulls/comments/34414562","id":34414562,"diff_hunk":"@@ -0,0 +1,752 @@\n+import itertools\n+import numpy as np\n+from operator import sub\n+from operator import add\n+import queue\n+import math\n+from collections import namedtuple\n+from pgmpy.models import MarkovModel\n+from pgmpy.inference import ApproxInference\n+\n+\n+class MPLP(ApproxInference):\n+    \"\"\"\n+    Class for performing inference using Max-Product Linear Programming Relaxations.\n+    We use the Max-Product Linear Programming (MPLP) algorithm to minimize the dual .\n+    \"\"\"\n+\n+    def __init__(self, model):\n+        super().__init__(model)\n+\n+        if not isinstance(model, MarkovModel):\n+            raise ValueError('The model given is not MarkovModel.')\n+\n+        # For containing the cardinalities of all the variables present in the model\n+        self.m_var_sizes = self.cardinality\n+        # All the factors are kept here\n+        self.m_all_intersect = self.factors\n+        # All the messages per factor is kept here. It is updated in each iteration of run_mplp\n+        self.objective = []\n+        # It contain the Region objects for all the factors which are made of more than one variable\n+        self.m_all_regions = []\n+        # Initial messages for more than single node regions are kept here. These don't change.\n+        self.m_region_lambdas = []\n+        # Maximum integral solution of the single nodes makes the m_best_val\n+        self.m_best_val = -1000000\n+        # This is to be used for calculating the breaking point of RunMPLP\n+        self.last_obj = 1e40\n+        self.m_intersect_map = []\n+        for i in range(len(self.factors)):\n+            self.objective.append([np.log(y) for y in self.factor_values[i]])\n+            if len(self.factors[i]) > 1:\n+                self.m_region_lambdas.append(self.objective[i])\n+                curr_region = Region(self.factors[i], self.factors[:i + 1], self.factors[i], self.cardinality, i)\n+                self.m_all_regions.append(curr_region)\n+            if len(self.factors[i]) == 2:\n+                self.m_intersect_map.append((self.factors[i], i))\n+\n+            # Initialise output vector\n+            self.m_decoded_res = [0] * len(self.cardinality)\n+            self.m_best_decoded_res = [0] * len(self.cardinality)\n+\n+    def _get_flat_ind(self, base_ind, base_card):","path":"pgmpy/inference/mplp.py","position":52,"original_position":52,"commit_id":"d391962bc0caf27a62758ec2e6fd79d1e077bdbd","original_commit_id":"d391962bc0caf27a62758ec2e6fd79d1e077bdbd","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":"As I said earlier, move this method from this class. ASAP ","created_at":"2015-07-11T17:15:51Z","updated_at":"2015-07-11T17:15:51Z","html_url":"https://github.com/pgmpy/pgmpy/pull/447#discussion_r34414562","pull_request_url":"https://api.github.com/repos/pgmpy/pgmpy/pulls/447","_links":{"self":{"href":"https://api.github.com/repos/pgmpy/pgmpy/pulls/comments/34414562"},"html":{"href":"https://github.com/pgmpy/pgmpy/pull/447#discussion_r34414562"},"pull_request":{"href":"https://api.github.com/repos/pgmpy/pgmpy/pulls/447"}}},"pull_request":{"url":"https://api.github.com/repos/pgmpy/pgmpy/pulls/447","id":39748253,"html_url":"https://github.com/pgmpy/pgmpy/pull/447","diff_url":"https://github.com/pgmpy/pgmpy/pull/447.diff","patch_url":"https://github.com/pgmpy/pgmpy/pull/447.patch","issue_url":"https://api.github.com/repos/pgmpy/pgmpy/issues/447","number":447,"state":"open","locked":false,"title":"Max Product LP for approximate inference","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":"I have:\r\n* added map_query method\r\n* inherited from a base class.(I really thought the need of this)\r\n* Made it UAI independent. (only a markov model is needed)\r\n* Added doc-strings.\r\n* Pep8 \r\n\r\nCurrently working on:\r\n* shortening the code\r\n","created_at":"2015-07-11T16:22:47Z","updated_at":"2015-07-11T17:15:51Z","closed_at":null,"merged_at":null,"merge_commit_sha":"5ac149bafb9266be8d2f25442f3dff41b7137f6c","assignee":null,"milestone":null,"commits_url":"https://api.github.com/repos/pgmpy/pgmpy/pulls/447/commits","review_comments_url":"https://api.github.com/repos/pgmpy/pgmpy/pulls/447/comments","review_comment_url":"https://api.github.com/repos/pgmpy/pgmpy/pulls/comments{/number}","comments_url":"https://api.github.com/repos/pgmpy/pgmpy/issues/447/comments","statuses_url":"https://api.github.com/repos/pgmpy/pgmpy/statuses/d391962bc0caf27a62758ec2e6fd79d1e077bdbd","head":{"label":"kislayabhi:new_mplp","ref":"new_mplp","sha":"d391962bc0caf27a62758ec2e6fd79d1e077bdbd","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-11T16:18:47Z","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-10T17:21:06Z","pushed_at":"2015-07-11T16:22:48Z","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":100,"watchers_count":100,"language":"Python","has_issues":true,"has_downloads":true,"has_wiki":true,"has_pages":false,"forks_count":49,"mirror_url":null,"open_issues_count":83,"forks":49,"open_issues":83,"watchers":100,"default_branch":"dev"}},"_links":{"self":{"href":"https://api.github.com/repos/pgmpy/pgmpy/pulls/447"},"html":{"href":"https://github.com/pgmpy/pgmpy/pull/447"},"issue":{"href":"https://api.github.com/repos/pgmpy/pgmpy/issues/447"},"comments":{"href":"https://api.github.com/repos/pgmpy/pgmpy/issues/447/comments"},"review_comments":{"href":"https://api.github.com/repos/pgmpy/pgmpy/pulls/447/comments"},"review_comment":{"href":"https://api.github.com/repos/pgmpy/pgmpy/pulls/comments{/number}"},"commits":{"href":"https://api.github.com/repos/pgmpy/pgmpy/pulls/447/commits"},"statuses":{"href":"https://api.github.com/repos/pgmpy/pgmpy/statuses/d391962bc0caf27a62758ec2e6fd79d1e077bdbd"}}}}