{"action":"created","comment":{"url":"https://api.github.com/repos/opencog/atomspace/pulls/comments/186052563","pull_request_review_id":117567684,"id":186052563,"diff_hunk":"@@ -320,21 +321,23 @@ void AttentionBank::updateAttentionalFocus(const Handle& h,\n \n Handle AttentionBank::getRandomAtomNotInAF(void)\n {\n-    std::lock_guard<std::mutex> lock(AFMutex);\n-    auto find_in_af = [this](const Handle& h){\n-       auto it = std::find_if(attentionalFocus.begin(), attentionalFocus.end(),\n-                [h](const std::pair<Handle, AttentionValuePtr>& hsp) { return hsp.first == h; });\n-       return it;\n-    };\n-\n-    int count = 50; // We might get stuck in the while loop if there are no atoms outside the AF\n-    Handle h = Handle::UNDEFINED;\n-    do {\n-        h = _importanceIndex.getRandomAtom();\n-    } while(find_in_af(h) != attentionalFocus.end() and --count > 0);\n-    // Make sure the last selection did not select from the AF.\n-    if(find_in_af(h) != attentionalFocus.end())\n+    UnorderedHandleSet atoms_not_in_af = _importanceIndex.getHandleSet(0);\n+\n+    {\n+        std::lock_guard<std::mutex> lock(AFMutex);\n+        for (const auto& hsp : attentionalFocus) {\n+            atoms_not_in_af.erase(hsp.first);\n+        }\n+    }\n+\n+    if (atoms_not_in_af.empty())\n         return Handle::UNDEFINED;\n \n-    return h;\n+    auto seed = std::chrono::duration_cast<std::chrono::microseconds>(\n+            std::chrono::system_clock::now().time_since_epoch());","path":"opencog/attentionbank/AttentionBank.cc","position":40,"original_position":40,"commit_id":"df673d8578c5b160ab2408c64466b9a97eff2f1b","original_commit_id":"df673d8578c5b160ab2408c64466b9a97eff2f1b","user":{"login":"ngeiswei","id":819225,"avatar_url":"https://avatars1.githubusercontent.com/u/819225?v=4","gravatar_id":"","url":"https://api.github.com/users/ngeiswei","html_url":"https://github.com/ngeiswei","followers_url":"https://api.github.com/users/ngeiswei/followers","following_url":"https://api.github.com/users/ngeiswei/following{/other_user}","gists_url":"https://api.github.com/users/ngeiswei/gists{/gist_id}","starred_url":"https://api.github.com/users/ngeiswei/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/ngeiswei/subscriptions","organizations_url":"https://api.github.com/users/ngeiswei/orgs","repos_url":"https://api.github.com/users/ngeiswei/repos","events_url":"https://api.github.com/users/ngeiswei/events{/privacy}","received_events_url":"https://api.github.com/users/ngeiswei/received_events","type":"User","site_admin":false},"body":"I don't think you need to worry about setting the random seed. The first time `randGen()` is called, its seed is set to 0 (see https://github.com/opencog/cogutil/blob/master/opencog/util/mt19937ar.cc#L93). It's up to the user to overwrite that seed whenever he/she wants to, from anywhere since this instance in unique.\r\n\r\nYeah, setting the seed isn't probably thread safe, it's never been a problem in practice because it is a seldom operation, but that doesn't mean we should be careless.","created_at":"2018-05-04T11:12:46Z","updated_at":"2018-05-04T11:12:46Z","html_url":"https://github.com/opencog/atomspace/pull/1656#discussion_r186052563","pull_request_url":"https://api.github.com/repos/opencog/atomspace/pulls/1656","author_association":"OWNER","_links":{"self":{"href":"https://api.github.com/repos/opencog/atomspace/pulls/comments/186052563"},"html":{"href":"https://github.com/opencog/atomspace/pull/1656#discussion_r186052563"},"pull_request":{"href":"https://api.github.com/repos/opencog/atomspace/pulls/1656"}},"in_reply_to_id":185895005},"pull_request":{"url":"https://api.github.com/repos/opencog/atomspace/pulls/1656","id":185778752,"html_url":"https://github.com/opencog/atomspace/pull/1656","diff_url":"https://github.com/opencog/atomspace/pull/1656.diff","patch_url":"https://github.com/opencog/atomspace/pull/1656.patch","issue_url":"https://api.github.com/repos/opencog/atomspace/issues/1656","number":1656,"state":"open","locked":false,"title":"Make AttentionBank::getRandomAtomNotInAF(void) stable","user":{"login":"vsbogd","id":983480,"avatar_url":"https://avatars0.githubusercontent.com/u/983480?v=4","gravatar_id":"","url":"https://api.github.com/users/vsbogd","html_url":"https://github.com/vsbogd","followers_url":"https://api.github.com/users/vsbogd/followers","following_url":"https://api.github.com/users/vsbogd/following{/other_user}","gists_url":"https://api.github.com/users/vsbogd/gists{/gist_id}","starred_url":"https://api.github.com/users/vsbogd/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/vsbogd/subscriptions","organizations_url":"https://api.github.com/users/vsbogd/orgs","repos_url":"https://api.github.com/users/vsbogd/repos","events_url":"https://api.github.com/users/vsbogd/events{/privacy}","received_events_url":"https://api.github.com/users/vsbogd/received_events","type":"User","site_admin":false},"body":"Previous AttentionBank::getRandomAtomNotInAF() implementation expects that it can get some random atom from _importanceIndex which is out of attentionalFocus collection in 50 attempts, which is not always true. Add unit test to demonstrate it and fix implementation.\r\n\r\nLooks like https://github.com/opencog/atomspace/blob/49b8eaa5d28c26549241c2f5cb7d3a7770ae8aac/opencog/attentionbank/ImportanceIndex.h#L123 can be removed as well as it is called from getRandomAtomNotInAF() only.\r\n\r\nOther random method was entered prior getRandomAtomNotInAF() adding: https://github.com/opencog/atomspace/blob/0031878db70fa978fb55a18773f7f0f098418c51/opencog/attentionbank/AtomBins.h#L72","created_at":"2018-05-03T16:58:27Z","updated_at":"2018-05-04T11:12:46Z","closed_at":null,"merged_at":null,"merge_commit_sha":"2025fba44594c025b0305f8ad31c13c4335cf1e0","assignee":null,"assignees":[],"requested_reviewers":[],"requested_teams":[],"labels":[],"milestone":null,"commits_url":"https://api.github.com/repos/opencog/atomspace/pulls/1656/commits","review_comments_url":"https://api.github.com/repos/opencog/atomspace/pulls/1656/comments","review_comment_url":"https://api.github.com/repos/opencog/atomspace/pulls/comments{/number}","comments_url":"https://api.github.com/repos/opencog/atomspace/issues/1656/comments","statuses_url":"https://api.github.com/repos/opencog/atomspace/statuses/df673d8578c5b160ab2408c64466b9a97eff2f1b","head":{"label":"vsbogd:fix-AttentionBank-getRandomAtomNotInAF","ref":"fix-AttentionBank-getRandomAtomNotInAF","sha":"df673d8578c5b160ab2408c64466b9a97eff2f1b","user":{"login":"vsbogd","id":983480,"avatar_url":"https://avatars0.githubusercontent.com/u/983480?v=4","gravatar_id":"","url":"https://api.github.com/users/vsbogd","html_url":"https://github.com/vsbogd","followers_url":"https://api.github.com/users/vsbogd/followers","following_url":"https://api.github.com/users/vsbogd/following{/other_user}","gists_url":"https://api.github.com/users/vsbogd/gists{/gist_id}","starred_url":"https://api.github.com/users/vsbogd/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/vsbogd/subscriptions","organizations_url":"https://api.github.com/users/vsbogd/orgs","repos_url":"https://api.github.com/users/vsbogd/repos","events_url":"https://api.github.com/users/vsbogd/events{/privacy}","received_events_url":"https://api.github.com/users/vsbogd/received_events","type":"User","site_admin":false},"repo":{"id":128222651,"name":"atomspace","full_name":"vsbogd/atomspace","owner":{"login":"vsbogd","id":983480,"avatar_url":"https://avatars0.githubusercontent.com/u/983480?v=4","gravatar_id":"","url":"https://api.github.com/users/vsbogd","html_url":"https://github.com/vsbogd","followers_url":"https://api.github.com/users/vsbogd/followers","following_url":"https://api.github.com/users/vsbogd/following{/other_user}","gists_url":"https://api.github.com/users/vsbogd/gists{/gist_id}","starred_url":"https://api.github.com/users/vsbogd/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/vsbogd/subscriptions","organizations_url":"https://api.github.com/users/vsbogd/orgs","repos_url":"https://api.github.com/users/vsbogd/repos","events_url":"https://api.github.com/users/vsbogd/events{/privacy}","received_events_url":"https://api.github.com/users/vsbogd/received_events","type":"User","site_admin":false},"private":false,"html_url":"https://github.com/vsbogd/atomspace","description":"The OpenCog hypergraph database, query system and rule engine","fork":true,"url":"https://api.github.com/repos/vsbogd/atomspace","forks_url":"https://api.github.com/repos/vsbogd/atomspace/forks","keys_url":"https://api.github.com/repos/vsbogd/atomspace/keys{/key_id}","collaborators_url":"https://api.github.com/repos/vsbogd/atomspace/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/vsbogd/atomspace/teams","hooks_url":"https://api.github.com/repos/vsbogd/atomspace/hooks","issue_events_url":"https://api.github.com/repos/vsbogd/atomspace/issues/events{/number}","events_url":"https://api.github.com/repos/vsbogd/atomspace/events","assignees_url":"https://api.github.com/repos/vsbogd/atomspace/assignees{/user}","branches_url":"https://api.github.com/repos/vsbogd/atomspace/branches{/branch}","tags_url":"https://api.github.com/repos/vsbogd/atomspace/tags","blobs_url":"https://api.github.com/repos/vsbogd/atomspace/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/vsbogd/atomspace/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/vsbogd/atomspace/git/refs{/sha}","trees_url":"https://api.github.com/repos/vsbogd/atomspace/git/trees{/sha}","statuses_url":"https://api.github.com/repos/vsbogd/atomspace/statuses/{sha}","languages_url":"https://api.github.com/repos/vsbogd/atomspace/languages","stargazers_url":"https://api.github.com/repos/vsbogd/atomspace/stargazers","contributors_url":"https://api.github.com/repos/vsbogd/atomspace/contributors","subscribers_url":"https://api.github.com/repos/vsbogd/atomspace/subscribers","subscription_url":"https://api.github.com/repos/vsbogd/atomspace/subscription","commits_url":"https://api.github.com/repos/vsbogd/atomspace/commits{/sha}","git_commits_url":"https://api.github.com/repos/vsbogd/atomspace/git/commits{/sha}","comments_url":"https://api.github.com/repos/vsbogd/atomspace/comments{/number}","issue_comment_url":"https://api.github.com/repos/vsbogd/atomspace/issues/comments{/number}","contents_url":"https://api.github.com/repos/vsbogd/atomspace/contents/{+path}","compare_url":"https://api.github.com/repos/vsbogd/atomspace/compare/{base}...{head}","merges_url":"https://api.github.com/repos/vsbogd/atomspace/merges","archive_url":"https://api.github.com/repos/vsbogd/atomspace/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/vsbogd/atomspace/downloads","issues_url":"https://api.github.com/repos/vsbogd/atomspace/issues{/number}","pulls_url":"https://api.github.com/repos/vsbogd/atomspace/pulls{/number}","milestones_url":"https://api.github.com/repos/vsbogd/atomspace/milestones{/number}","notifications_url":"https://api.github.com/repos/vsbogd/atomspace/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/vsbogd/atomspace/labels{/name}","releases_url":"https://api.github.com/repos/vsbogd/atomspace/releases{/id}","deployments_url":"https://api.github.com/repos/vsbogd/atomspace/deployments","created_at":"2018-04-05T15:02:26Z","updated_at":"2018-05-03T20:33:50Z","pushed_at":"2018-05-03T20:33:49Z","git_url":"git://github.com/vsbogd/atomspace.git","ssh_url":"git@github.com:vsbogd/atomspace.git","clone_url":"https://github.com/vsbogd/atomspace.git","svn_url":"https://github.com/vsbogd/atomspace","homepage":"","size":152436,"stargazers_count":0,"watchers_count":0,"language":"C++","has_issues":false,"has_projects":true,"has_downloads":true,"has_wiki":false,"has_pages":false,"forks_count":0,"mirror_url":null,"archived":false,"open_issues_count":0,"license":{"key":"agpl-3.0","name":"GNU Affero General Public License v3.0","spdx_id":"AGPL-3.0","url":"https://api.github.com/licenses/agpl-3.0"},"forks":0,"open_issues":0,"watchers":0,"default_branch":"master"}},"base":{"label":"opencog:master","ref":"master","sha":"0fb6a9c3313939aff4632426ee96177e815b8231","user":{"login":"opencog","id":2109913,"avatar_url":"https://avatars1.githubusercontent.com/u/2109913?v=4","gravatar_id":"","url":"https://api.github.com/users/opencog","html_url":"https://github.com/opencog","followers_url":"https://api.github.com/users/opencog/followers","following_url":"https://api.github.com/users/opencog/following{/other_user}","gists_url":"https://api.github.com/users/opencog/gists{/gist_id}","starred_url":"https://api.github.com/users/opencog/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/opencog/subscriptions","organizations_url":"https://api.github.com/users/opencog/orgs","repos_url":"https://api.github.com/users/opencog/repos","events_url":"https://api.github.com/users/opencog/events{/privacy}","received_events_url":"https://api.github.com/users/opencog/received_events","type":"Organization","site_admin":false},"repo":{"id":34678084,"name":"atomspace","full_name":"opencog/atomspace","owner":{"login":"opencog","id":2109913,"avatar_url":"https://avatars1.githubusercontent.com/u/2109913?v=4","gravatar_id":"","url":"https://api.github.com/users/opencog","html_url":"https://github.com/opencog","followers_url":"https://api.github.com/users/opencog/followers","following_url":"https://api.github.com/users/opencog/following{/other_user}","gists_url":"https://api.github.com/users/opencog/gists{/gist_id}","starred_url":"https://api.github.com/users/opencog/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/opencog/subscriptions","organizations_url":"https://api.github.com/users/opencog/orgs","repos_url":"https://api.github.com/users/opencog/repos","events_url":"https://api.github.com/users/opencog/events{/privacy}","received_events_url":"https://api.github.com/users/opencog/received_events","type":"Organization","site_admin":false},"private":false,"html_url":"https://github.com/opencog/atomspace","description":"The OpenCog hypergraph database, query system and rule engine","fork":false,"url":"https://api.github.com/repos/opencog/atomspace","forks_url":"https://api.github.com/repos/opencog/atomspace/forks","keys_url":"https://api.github.com/repos/opencog/atomspace/keys{/key_id}","collaborators_url":"https://api.github.com/repos/opencog/atomspace/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/opencog/atomspace/teams","hooks_url":"https://api.github.com/repos/opencog/atomspace/hooks","issue_events_url":"https://api.github.com/repos/opencog/atomspace/issues/events{/number}","events_url":"https://api.github.com/repos/opencog/atomspace/events","assignees_url":"https://api.github.com/repos/opencog/atomspace/assignees{/user}","branches_url":"https://api.github.com/repos/opencog/atomspace/branches{/branch}","tags_url":"https://api.github.com/repos/opencog/atomspace/tags","blobs_url":"https://api.github.com/repos/opencog/atomspace/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/opencog/atomspace/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/opencog/atomspace/git/refs{/sha}","trees_url":"https://api.github.com/repos/opencog/atomspace/git/trees{/sha}","statuses_url":"https://api.github.com/repos/opencog/atomspace/statuses/{sha}","languages_url":"https://api.github.com/repos/opencog/atomspace/languages","stargazers_url":"https://api.github.com/repos/opencog/atomspace/stargazers","contributors_url":"https://api.github.com/repos/opencog/atomspace/contributors","subscribers_url":"https://api.github.com/repos/opencog/atomspace/subscribers","subscription_url":"https://api.github.com/repos/opencog/atomspace/subscription","commits_url":"https://api.github.com/repos/opencog/atomspace/commits{/sha}","git_commits_url":"https://api.github.com/repos/opencog/atomspace/git/commits{/sha}","comments_url":"https://api.github.com/repos/opencog/atomspace/comments{/number}","issue_comment_url":"https://api.github.com/repos/opencog/atomspace/issues/comments{/number}","contents_url":"https://api.github.com/repos/opencog/atomspace/contents/{+path}","compare_url":"https://api.github.com/repos/opencog/atomspace/compare/{base}...{head}","merges_url":"https://api.github.com/repos/opencog/atomspace/merges","archive_url":"https://api.github.com/repos/opencog/atomspace/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/opencog/atomspace/downloads","issues_url":"https://api.github.com/repos/opencog/atomspace/issues{/number}","pulls_url":"https://api.github.com/repos/opencog/atomspace/pulls{/number}","milestones_url":"https://api.github.com/repos/opencog/atomspace/milestones{/number}","notifications_url":"https://api.github.com/repos/opencog/atomspace/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/opencog/atomspace/labels{/name}","releases_url":"https://api.github.com/repos/opencog/atomspace/releases{/id}","deployments_url":"https://api.github.com/repos/opencog/atomspace/deployments","created_at":"2015-04-27T16:32:57Z","updated_at":"2018-05-03T19:36:21Z","pushed_at":"2018-05-03T19:36:19Z","git_url":"git://github.com/opencog/atomspace.git","ssh_url":"git@github.com:opencog/atomspace.git","clone_url":"https://github.com/opencog/atomspace.git","svn_url":"https://github.com/opencog/atomspace","homepage":"","size":152422,"stargazers_count":161,"watchers_count":161,"language":"C++","has_issues":true,"has_projects":true,"has_downloads":true,"has_wiki":false,"has_pages":false,"forks_count":115,"mirror_url":null,"archived":false,"open_issues_count":60,"license":{"key":"agpl-3.0","name":"GNU Affero General Public License v3.0","spdx_id":"AGPL-3.0","url":"https://api.github.com/licenses/agpl-3.0"},"forks":115,"open_issues":60,"watchers":161,"default_branch":"master"}},"_links":{"self":{"href":"https://api.github.com/repos/opencog/atomspace/pulls/1656"},"html":{"href":"https://github.com/opencog/atomspace/pull/1656"},"issue":{"href":"https://api.github.com/repos/opencog/atomspace/issues/1656"},"comments":{"href":"https://api.github.com/repos/opencog/atomspace/issues/1656/comments"},"review_comments":{"href":"https://api.github.com/repos/opencog/atomspace/pulls/1656/comments"},"review_comment":{"href":"https://api.github.com/repos/opencog/atomspace/pulls/comments{/number}"},"commits":{"href":"https://api.github.com/repos/opencog/atomspace/pulls/1656/commits"},"statuses":{"href":"https://api.github.com/repos/opencog/atomspace/statuses/df673d8578c5b160ab2408c64466b9a97eff2f1b"}},"author_association":"CONTRIBUTOR"}}
{"actor":{"display_login":"ngeiswei"}}