{"action":"created","comment":{"url":"https://api.github.com/repos/pgmpy/pgmpy/pulls/comments/94180567","pull_request_review_id":14711211,"id":94180567,"diff_hunk":"@@ -134,11 +137,69 @@ def remove_factors(self, *factors):\n         >>> G = FactorGraph()\n         >>> G.add_nodes_from(['a', 'b', 'c'])\n         >>> phi1 = DiscreteFactor(['a', 'b'], [2, 2], np.random.rand(4))\n+        >>> G.add_edge('a',phi1)\n         >>> G.add_factors(phi1)\n         >>> G.remove_factors(phi1)\n         \"\"\"\n         for factor in factors:\n             self.factors.remove(factor)\n+            if factor in super(FactorGraph, self).nodes():\n+                super(FactorGraph, self).remove_node(factor)\n+\n+    def remove_node(self, node):\n+        \"\"\"\n+        Removes a single  given node from the added factors.\n+\n+        Examples\n+        --------\n+        >>> import numpy as np\n+        >>> from pgmpy.models import FactorGraph\n+        >>> from pgmpy.factors.discrete import DiscreteFactor\n+        >>> G = FactorGraph()\n+        >>> G.add_nodes_from(['a', 'b', 'c'])\n+        >>> phi1 = DiscreteFactor(['a', 'b'], [2, 2], np.random.rand(4))\n+        >>> G.add_factors(phi1)\n+        >>> G.add_edges_from([('a',phi1),('b',phi1)])\n+        >>> G.remove_node('a')\n+        \"\"\"\n+        if not isinstance(node, six.string_types):\n+            raise ValueError(\"Node must be a string given{s}\", s=type(node))\n+\n+        affected_factors = [v for u, v in self.edges() if u == node]\n+        affected_factors.extend([u for u, v in self.edges() if v == node])\n+        # remove and marginalise\n+        for factor in affected_factors:\n+            edge_nodes = [v for u, v in self.edges() if u == factor]\n+            edge_nodes.extend([u for u, v in self.edges() if v == factor])\n+            fac_temp = factor.marginalize([node], inplace=False)\n+            self.remove_factors(factor)\n+            if len(fac_temp.scope()) != 0:\n+                self.add_factors(fac_temp)\n+                edges = list(zip(edge_nodes, [fac_temp for _ in range(len(edge_nodes))]))\n+                self.add_edges_from(edges)\n+        super(FactorGraph, self).remove_node(node)\n+\n+    def remove_nodes_from(self, nodes):\n+        \"\"\"\n+        Removes multiple given nodes from the added factors.\n+\n+        Examples\n+        --------\n+        >>> import numpy as np\n+        >>> from pgmpy.models import FactorGraph\n+        >>> from pgmpy.factors.discrete import DiscreteFactor\n+        >>> G = FactorGraph()\n+        >>> G.add_nodes_from(['a', 'b', 'c'])\n+        >>> phi1 = DiscreteFactor(['a', 'b'], [2, 2], np.random.rand(4))\n+        >>> G.add_factors(phi1)\n+        >>> G.add_edges_from([('a',phi1),('b',phi1)])\n+        >>> G.remove_nodes_from(['a','b'])\n+        \"\"\"\n+        if not isinstance(nodes, (list, tuple, np.ndarray)):\n+            raise ValueError(\"nodes must be a iterable type {s} given\".format(s=type(nodes)))","path":"pgmpy/models/FactorGraph.py","position":92,"original_position":92,"commit_id":"a7e8b923d8fb31d472d283cfb781c8b3395befd8","original_commit_id":"a7e8b923d8fb31d472d283cfb781c8b3395befd8","user":{"login":"ankurankan","id":1461453,"avatar_url":"https://avatars.githubusercontent.com/u/1461453?v=3","gravatar_id":"","url":"https://api.github.com/users/ankurankan","html_url":"https://github.com/ankurankan","followers_url":"https://api.github.com/users/ankurankan/followers","following_url":"https://api.github.com/users/ankurankan/following{/other_user}","gists_url":"https://api.github.com/users/ankurankan/gists{/gist_id}","starred_url":"https://api.github.com/users/ankurankan/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/ankurankan/subscriptions","organizations_url":"https://api.github.com/users/ankurankan/orgs","repos_url":"https://api.github.com/users/ankurankan/repos","events_url":"https://api.github.com/users/ankurankan/events{/privacy}","received_events_url":"https://api.github.com/users/ankurankan/received_events","type":"User","site_admin":false},"body":"@kris-singh N should in be caps in `nodes`. Don't use variable name as `s`. Use something that tells what the variable is.","created_at":"2016-12-29T21:13:01Z","updated_at":"2016-12-29T21:17:14Z","html_url":"https://github.com/pgmpy/pgmpy/pull/804#discussion_r94180567","pull_request_url":"https://api.github.com/repos/pgmpy/pgmpy/pulls/804","_links":{"self":{"href":"https://api.github.com/repos/pgmpy/pgmpy/pulls/comments/94180567"},"html":{"href":"https://github.com/pgmpy/pgmpy/pull/804#discussion_r94180567"},"pull_request":{"href":"https://api.github.com/repos/pgmpy/pgmpy/pulls/804"}}},"pull_request":{"url":"https://api.github.com/repos/pgmpy/pgmpy/pulls/804","id":99310374,"html_url":"https://github.com/pgmpy/pgmpy/pull/804","diff_url":"https://github.com/pgmpy/pgmpy/pull/804.diff","patch_url":"https://github.com/pgmpy/pgmpy/pull/804.patch","issue_url":"https://api.github.com/repos/pgmpy/pgmpy/issues/804","number":804,"state":"open","locked":false,"title":"Factor Remove Node PR#752","user":{"login":"kris-singh","id":11256139,"avatar_url":"https://avatars.githubusercontent.com/u/11256139?v=3","gravatar_id":"","url":"https://api.github.com/users/kris-singh","html_url":"https://github.com/kris-singh","followers_url":"https://api.github.com/users/kris-singh/followers","following_url":"https://api.github.com/users/kris-singh/following{/other_user}","gists_url":"https://api.github.com/users/kris-singh/gists{/gist_id}","starred_url":"https://api.github.com/users/kris-singh/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/kris-singh/subscriptions","organizations_url":"https://api.github.com/users/kris-singh/orgs","repos_url":"https://api.github.com/users/kris-singh/repos","events_url":"https://api.github.com/users/kris-singh/events{/privacy}","received_events_url":"https://api.github.com/users/kris-singh/received_events","type":"User","site_admin":false},"body":"","created_at":"2016-12-24T20:16:55Z","updated_at":"2016-12-29T21:17:14Z","closed_at":null,"merged_at":null,"merge_commit_sha":"75e0c49664e104fadd42e2aaa253dbf2b067b5cb","assignee":null,"assignees":[],"milestone":null,"commits_url":"https://api.github.com/repos/pgmpy/pgmpy/pulls/804/commits","review_comments_url":"https://api.github.com/repos/pgmpy/pgmpy/pulls/804/comments","review_comment_url":"https://api.github.com/repos/pgmpy/pgmpy/pulls/comments{/number}","comments_url":"https://api.github.com/repos/pgmpy/pgmpy/issues/804/comments","statuses_url":"https://api.github.com/repos/pgmpy/pgmpy/statuses/a7e8b923d8fb31d472d283cfb781c8b3395befd8","head":{"label":"kris-singh:PR#752","ref":"PR#752","sha":"a7e8b923d8fb31d472d283cfb781c8b3395befd8","user":{"login":"kris-singh","id":11256139,"avatar_url":"https://avatars.githubusercontent.com/u/11256139?v=3","gravatar_id":"","url":"https://api.github.com/users/kris-singh","html_url":"https://github.com/kris-singh","followers_url":"https://api.github.com/users/kris-singh/followers","following_url":"https://api.github.com/users/kris-singh/following{/other_user}","gists_url":"https://api.github.com/users/kris-singh/gists{/gist_id}","starred_url":"https://api.github.com/users/kris-singh/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/kris-singh/subscriptions","organizations_url":"https://api.github.com/users/kris-singh/orgs","repos_url":"https://api.github.com/users/kris-singh/repos","events_url":"https://api.github.com/users/kris-singh/events{/privacy}","received_events_url":"https://api.github.com/users/kris-singh/received_events","type":"User","site_admin":false},"repo":{"id":75298259,"name":"pgmpy","full_name":"kris-singh/pgmpy","owner":{"login":"kris-singh","id":11256139,"avatar_url":"https://avatars.githubusercontent.com/u/11256139?v=3","gravatar_id":"","url":"https://api.github.com/users/kris-singh","html_url":"https://github.com/kris-singh","followers_url":"https://api.github.com/users/kris-singh/followers","following_url":"https://api.github.com/users/kris-singh/following{/other_user}","gists_url":"https://api.github.com/users/kris-singh/gists{/gist_id}","starred_url":"https://api.github.com/users/kris-singh/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/kris-singh/subscriptions","organizations_url":"https://api.github.com/users/kris-singh/orgs","repos_url":"https://api.github.com/users/kris-singh/repos","events_url":"https://api.github.com/users/kris-singh/events{/privacy}","received_events_url":"https://api.github.com/users/kris-singh/received_events","type":"User","site_admin":false},"private":false,"html_url":"https://github.com/kris-singh/pgmpy","description":"Python Library for Probabilistic Graphical Models","fork":true,"url":"https://api.github.com/repos/kris-singh/pgmpy","forks_url":"https://api.github.com/repos/kris-singh/pgmpy/forks","keys_url":"https://api.github.com/repos/kris-singh/pgmpy/keys{/key_id}","collaborators_url":"https://api.github.com/repos/kris-singh/pgmpy/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/kris-singh/pgmpy/teams","hooks_url":"https://api.github.com/repos/kris-singh/pgmpy/hooks","issue_events_url":"https://api.github.com/repos/kris-singh/pgmpy/issues/events{/number}","events_url":"https://api.github.com/repos/kris-singh/pgmpy/events","assignees_url":"https://api.github.com/repos/kris-singh/pgmpy/assignees{/user}","branches_url":"https://api.github.com/repos/kris-singh/pgmpy/branches{/branch}","tags_url":"https://api.github.com/repos/kris-singh/pgmpy/tags","blobs_url":"https://api.github.com/repos/kris-singh/pgmpy/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/kris-singh/pgmpy/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/kris-singh/pgmpy/git/refs{/sha}","trees_url":"https://api.github.com/repos/kris-singh/pgmpy/git/trees{/sha}","statuses_url":"https://api.github.com/repos/kris-singh/pgmpy/statuses/{sha}","languages_url":"https://api.github.com/repos/kris-singh/pgmpy/languages","stargazers_url":"https://api.github.com/repos/kris-singh/pgmpy/stargazers","contributors_url":"https://api.github.com/repos/kris-singh/pgmpy/contributors","subscribers_url":"https://api.github.com/repos/kris-singh/pgmpy/subscribers","subscription_url":"https://api.github.com/repos/kris-singh/pgmpy/subscription","commits_url":"https://api.github.com/repos/kris-singh/pgmpy/commits{/sha}","git_commits_url":"https://api.github.com/repos/kris-singh/pgmpy/git/commits{/sha}","comments_url":"https://api.github.com/repos/kris-singh/pgmpy/comments{/number}","issue_comment_url":"https://api.github.com/repos/kris-singh/pgmpy/issues/comments{/number}","contents_url":"https://api.github.com/repos/kris-singh/pgmpy/contents/{+path}","compare_url":"https://api.github.com/repos/kris-singh/pgmpy/compare/{base}...{head}","merges_url":"https://api.github.com/repos/kris-singh/pgmpy/merges","archive_url":"https://api.github.com/repos/kris-singh/pgmpy/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/kris-singh/pgmpy/downloads","issues_url":"https://api.github.com/repos/kris-singh/pgmpy/issues{/number}","pulls_url":"https://api.github.com/repos/kris-singh/pgmpy/pulls{/number}","milestones_url":"https://api.github.com/repos/kris-singh/pgmpy/milestones{/number}","notifications_url":"https://api.github.com/repos/kris-singh/pgmpy/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/kris-singh/pgmpy/labels{/name}","releases_url":"https://api.github.com/repos/kris-singh/pgmpy/releases{/id}","deployments_url":"https://api.github.com/repos/kris-singh/pgmpy/deployments","created_at":"2016-12-01T14:05:47Z","updated_at":"2016-12-01T14:05:49Z","pushed_at":"2016-12-29T19:08:32Z","git_url":"git://github.com/kris-singh/pgmpy.git","ssh_url":"git@github.com:kris-singh/pgmpy.git","clone_url":"https://github.com/kris-singh/pgmpy.git","svn_url":"https://github.com/kris-singh/pgmpy","homepage":null,"size":5437,"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":"9ad898a85a2de362ad3a8a7971790dbcf804be2f","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}","deployments_url":"https://api.github.com/repos/pgmpy/pgmpy/deployments","created_at":"2013-09-20T08:18:58Z","updated_at":"2016-12-29T15:53:26Z","pushed_at":"2016-12-29T20:54:05Z","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":5445,"stargazers_count":387,"watchers_count":387,"language":"Python","has_issues":true,"has_downloads":true,"has_wiki":true,"has_pages":false,"forks_count":178,"mirror_url":null,"open_issues_count":125,"forks":178,"open_issues":125,"watchers":387,"default_branch":"dev"}},"_links":{"self":{"href":"https://api.github.com/repos/pgmpy/pgmpy/pulls/804"},"html":{"href":"https://github.com/pgmpy/pgmpy/pull/804"},"issue":{"href":"https://api.github.com/repos/pgmpy/pgmpy/issues/804"},"comments":{"href":"https://api.github.com/repos/pgmpy/pgmpy/issues/804/comments"},"review_comments":{"href":"https://api.github.com/repos/pgmpy/pgmpy/pulls/804/comments"},"review_comment":{"href":"https://api.github.com/repos/pgmpy/pgmpy/pulls/comments{/number}"},"commits":{"href":"https://api.github.com/repos/pgmpy/pgmpy/pulls/804/commits"},"statuses":{"href":"https://api.github.com/repos/pgmpy/pgmpy/statuses/a7e8b923d8fb31d472d283cfb781c8b3395befd8"}}}}
{"actor":{"display_login":"ankurankan"}}