{"action":"created","comment":{"url":"https://api.github.com/repos/numenta/nupic/pulls/comments/25642912","id":25642912,"diff_hunk":"@@ -1459,7 +1424,63 @@ def addInstance(self, groundTruth, prediction, record = None):\n \n     return self.aggregateError\n \n+###################################################################################\n+class MetricMulti(MetricsIface):\n+  \"\"\"Multi metric can combine multiple other (sub)metrics and \n+     weight them to provide combined score.\"\"\"\n \n+  def __init__(self, metricSpec):\n+    \"\"\"MetricMulti constructor using metricSpec is not allowed.\"\"\"\n+    raise ValueError(\"MetricMulti cannot be constructed from metricSpec string! \"\n+                     \"Use MetricMulti(id,weights,metrics) constructor instead.\")\n+\n+  def __init__(self, weights, metrics, id=None, window=None):\n+    \"\"\"MetricMulti \n+       @param id - unique name for this metric\n+       @param weights - [list of floats] used as weights\n+       @param (sub)metrics - [list of metrics] \n+       @param id - (opt) name of the metric\n+       @param window - (opt) window size for moving average, or None\n+    \"\"\"\n+    if (weights is None or not isinstance(weights, list) or \n+                          not len(weights) > 0 or\n+                          not isinstance(weights[0], float)):\n+      raise ValueError(\"MetricMulti requires 'weights' parameter as a [list of floats]\")\n+    self.weights = weights\n+\n+    if (metrics is None or not isinstance(metrics, list) or\n+                          not len(metrics) > 0 or\n+                          not isinstance(metrics[0], MetricsIface)):\n+      raise ValueError(\"MetricMulti requires 'metrics' parameter as a [list of Metrics]\")\n+    self.metrics = metrics\n+    if window is not None:\n+      self.movingAvg = MovingAverage(windowSize=window)\n+    else:\n+      self.movingAvg = None\n \n \n+  def addInstance(self, groundTruth, prediction, record = None):\n+    err = 0.0\n+    subResults = [m.addInstance(groundTruth, prediction, record) for m in self.metrics]\n+    for i in xrange(len(self.weights)):\n+      try:\n+        err += subResults[i]*self.weights[i]\n+      except(TypeError):\n+        self.err = None","path":"nupic/frameworks/opf/metrics.py","position":177,"original_position":178,"commit_id":"18d67cfb8aa7a9a1e2d89b25c3afc4e89ae2870e","original_commit_id":"001d9057df49663919a952c7daeb6575c1e6f23a","user":{"login":"breznak","id":2166111,"avatar_url":"https://avatars.githubusercontent.com/u/2166111?v=3","gravatar_id":"","url":"https://api.github.com/users/breznak","html_url":"https://github.com/breznak","followers_url":"https://api.github.com/users/breznak/followers","following_url":"https://api.github.com/users/breznak/following{/other_user}","gists_url":"https://api.github.com/users/breznak/gists{/gist_id}","starred_url":"https://api.github.com/users/breznak/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/breznak/subscriptions","organizations_url":"https://api.github.com/users/breznak/orgs","repos_url":"https://api.github.com/users/breznak/repos","events_url":"https://api.github.com/users/breznak/events{/privacy}","received_events_url":"https://api.github.com/users/breznak/received_events","type":"User","site_admin":false},"body":"I only return None when the existing metric would return None, so just keeping status quo..","created_at":"2015-03-02T22:00:38Z","updated_at":"2015-03-02T22:00:38Z","html_url":"https://github.com/numenta/nupic/pull/1850#discussion_r25642912","pull_request_url":"https://api.github.com/repos/numenta/nupic/pulls/1850","_links":{"self":{"href":"https://api.github.com/repos/numenta/nupic/pulls/comments/25642912"},"html":{"href":"https://github.com/numenta/nupic/pull/1850#discussion_r25642912"},"pull_request":{"href":"https://api.github.com/repos/numenta/nupic/pulls/1850"}}},"pull_request":{"url":"https://api.github.com/repos/numenta/nupic/pulls/1850","id":29784860,"html_url":"https://github.com/numenta/nupic/pull/1850","diff_url":"https://github.com/numenta/nupic/pull/1850.diff","patch_url":"https://github.com/numenta/nupic/pull/1850.patch","issue_url":"https://api.github.com/repos/numenta/nupic/issues/1850","number":1850,"state":"open","locked":false,"title":"Metric multi","user":{"login":"breznak","id":2166111,"avatar_url":"https://avatars.githubusercontent.com/u/2166111?v=3","gravatar_id":"","url":"https://api.github.com/users/breznak","html_url":"https://github.com/breznak","followers_url":"https://api.github.com/users/breznak/followers","following_url":"https://api.github.com/users/breznak/following{/other_user}","gists_url":"https://api.github.com/users/breznak/gists{/gist_id}","starred_url":"https://api.github.com/users/breznak/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/breznak/subscriptions","organizations_url":"https://api.github.com/users/breznak/orgs","repos_url":"https://api.github.com/users/breznak/repos","events_url":"https://api.github.com/users/breznak/events{/privacy}","received_events_url":"https://api.github.com/users/breznak/received_events","type":"User","site_admin":false},"body":"new MetricMulti allows us to combine weighted values of many sub-metrics with different parameters. \r\nAlso reuses shared MovingAverage code in metrics.\r\nImplement `multi metric` + tests + cleanup\r\n\r\nFixes #1710 ","created_at":"2015-02-23T03:49:43Z","updated_at":"2015-03-02T22:00:38Z","closed_at":null,"merged_at":null,"merge_commit_sha":"6d114a6d8294cd4b860211b0cb95bc992640a36e","assignee":null,"milestone":null,"commits_url":"https://api.github.com/repos/numenta/nupic/pulls/1850/commits","review_comments_url":"https://api.github.com/repos/numenta/nupic/pulls/1850/comments","review_comment_url":"https://api.github.com/repos/numenta/nupic/pulls/comments{/number}","comments_url":"https://api.github.com/repos/numenta/nupic/issues/1850/comments","statuses_url":"https://api.github.com/repos/numenta/nupic/statuses/18d67cfb8aa7a9a1e2d89b25c3afc4e89ae2870e","head":{"label":"breznak:metric_multi","ref":"metric_multi","sha":"18d67cfb8aa7a9a1e2d89b25c3afc4e89ae2870e","user":{"login":"breznak","id":2166111,"avatar_url":"https://avatars.githubusercontent.com/u/2166111?v=3","gravatar_id":"","url":"https://api.github.com/users/breznak","html_url":"https://github.com/breznak","followers_url":"https://api.github.com/users/breznak/followers","following_url":"https://api.github.com/users/breznak/following{/other_user}","gists_url":"https://api.github.com/users/breznak/gists{/gist_id}","starred_url":"https://api.github.com/users/breznak/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/breznak/subscriptions","organizations_url":"https://api.github.com/users/breznak/orgs","repos_url":"https://api.github.com/users/breznak/repos","events_url":"https://api.github.com/users/breznak/events{/privacy}","received_events_url":"https://api.github.com/users/breznak/received_events","type":"User","site_admin":false},"repo":{"id":10535896,"name":"nupic","full_name":"breznak/nupic","owner":{"login":"breznak","id":2166111,"avatar_url":"https://avatars.githubusercontent.com/u/2166111?v=3","gravatar_id":"","url":"https://api.github.com/users/breznak","html_url":"https://github.com/breznak","followers_url":"https://api.github.com/users/breznak/followers","following_url":"https://api.github.com/users/breznak/following{/other_user}","gists_url":"https://api.github.com/users/breznak/gists{/gist_id}","starred_url":"https://api.github.com/users/breznak/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/breznak/subscriptions","organizations_url":"https://api.github.com/users/breznak/orgs","repos_url":"https://api.github.com/users/breznak/repos","events_url":"https://api.github.com/users/breznak/events{/privacy}","received_events_url":"https://api.github.com/users/breznak/received_events","type":"User","site_admin":false},"private":false,"html_url":"https://github.com/breznak/nupic","description":"","fork":true,"url":"https://api.github.com/repos/breznak/nupic","forks_url":"https://api.github.com/repos/breznak/nupic/forks","keys_url":"https://api.github.com/repos/breznak/nupic/keys{/key_id}","collaborators_url":"https://api.github.com/repos/breznak/nupic/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/breznak/nupic/teams","hooks_url":"https://api.github.com/repos/breznak/nupic/hooks","issue_events_url":"https://api.github.com/repos/breznak/nupic/issues/events{/number}","events_url":"https://api.github.com/repos/breznak/nupic/events","assignees_url":"https://api.github.com/repos/breznak/nupic/assignees{/user}","branches_url":"https://api.github.com/repos/breznak/nupic/branches{/branch}","tags_url":"https://api.github.com/repos/breznak/nupic/tags","blobs_url":"https://api.github.com/repos/breznak/nupic/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/breznak/nupic/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/breznak/nupic/git/refs{/sha}","trees_url":"https://api.github.com/repos/breznak/nupic/git/trees{/sha}","statuses_url":"https://api.github.com/repos/breznak/nupic/statuses/{sha}","languages_url":"https://api.github.com/repos/breznak/nupic/languages","stargazers_url":"https://api.github.com/repos/breznak/nupic/stargazers","contributors_url":"https://api.github.com/repos/breznak/nupic/contributors","subscribers_url":"https://api.github.com/repos/breznak/nupic/subscribers","subscription_url":"https://api.github.com/repos/breznak/nupic/subscription","commits_url":"https://api.github.com/repos/breznak/nupic/commits{/sha}","git_commits_url":"https://api.github.com/repos/breznak/nupic/git/commits{/sha}","comments_url":"https://api.github.com/repos/breznak/nupic/comments{/number}","issue_comment_url":"https://api.github.com/repos/breznak/nupic/issues/comments{/number}","contents_url":"https://api.github.com/repos/breznak/nupic/contents/{+path}","compare_url":"https://api.github.com/repos/breznak/nupic/compare/{base}...{head}","merges_url":"https://api.github.com/repos/breznak/nupic/merges","archive_url":"https://api.github.com/repos/breznak/nupic/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/breznak/nupic/downloads","issues_url":"https://api.github.com/repos/breznak/nupic/issues{/number}","pulls_url":"https://api.github.com/repos/breznak/nupic/pulls{/number}","milestones_url":"https://api.github.com/repos/breznak/nupic/milestones{/number}","notifications_url":"https://api.github.com/repos/breznak/nupic/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/breznak/nupic/labels{/name}","releases_url":"https://api.github.com/repos/breznak/nupic/releases{/id}","created_at":"2013-06-06T20:32:30Z","updated_at":"2015-02-24T11:13:05Z","pushed_at":"2015-03-02T10:17:20Z","git_url":"git://github.com/breznak/nupic.git","ssh_url":"git@github.com:breznak/nupic.git","clone_url":"https://github.com/breznak/nupic.git","svn_url":"https://github.com/breznak/nupic","homepage":null,"size":218905,"stargazers_count":0,"watchers_count":0,"language":"Python","has_issues":true,"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":"master"}},"base":{"label":"numenta:master","ref":"master","sha":"90460c4d99e134e2f7a325738764a157dcebf1a6","user":{"login":"numenta","id":1039191,"avatar_url":"https://avatars.githubusercontent.com/u/1039191?v=3","gravatar_id":"","url":"https://api.github.com/users/numenta","html_url":"https://github.com/numenta","followers_url":"https://api.github.com/users/numenta/followers","following_url":"https://api.github.com/users/numenta/following{/other_user}","gists_url":"https://api.github.com/users/numenta/gists{/gist_id}","starred_url":"https://api.github.com/users/numenta/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/numenta/subscriptions","organizations_url":"https://api.github.com/users/numenta/orgs","repos_url":"https://api.github.com/users/numenta/repos","events_url":"https://api.github.com/users/numenta/events{/privacy}","received_events_url":"https://api.github.com/users/numenta/received_events","type":"Organization","site_admin":false},"repo":{"id":9252533,"name":"nupic","full_name":"numenta/nupic","owner":{"login":"numenta","id":1039191,"avatar_url":"https://avatars.githubusercontent.com/u/1039191?v=3","gravatar_id":"","url":"https://api.github.com/users/numenta","html_url":"https://github.com/numenta","followers_url":"https://api.github.com/users/numenta/followers","following_url":"https://api.github.com/users/numenta/following{/other_user}","gists_url":"https://api.github.com/users/numenta/gists{/gist_id}","starred_url":"https://api.github.com/users/numenta/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/numenta/subscriptions","organizations_url":"https://api.github.com/users/numenta/orgs","repos_url":"https://api.github.com/users/numenta/repos","events_url":"https://api.github.com/users/numenta/events{/privacy}","received_events_url":"https://api.github.com/users/numenta/received_events","type":"Organization","site_admin":false},"private":false,"html_url":"https://github.com/numenta/nupic","description":"Numenta Platform for Intelligent Computing: a brain-inspired machine intelligence platform, and biologically accurate neural network based on cortical learning algorithms.","fork":false,"url":"https://api.github.com/repos/numenta/nupic","forks_url":"https://api.github.com/repos/numenta/nupic/forks","keys_url":"https://api.github.com/repos/numenta/nupic/keys{/key_id}","collaborators_url":"https://api.github.com/repos/numenta/nupic/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/numenta/nupic/teams","hooks_url":"https://api.github.com/repos/numenta/nupic/hooks","issue_events_url":"https://api.github.com/repos/numenta/nupic/issues/events{/number}","events_url":"https://api.github.com/repos/numenta/nupic/events","assignees_url":"https://api.github.com/repos/numenta/nupic/assignees{/user}","branches_url":"https://api.github.com/repos/numenta/nupic/branches{/branch}","tags_url":"https://api.github.com/repos/numenta/nupic/tags","blobs_url":"https://api.github.com/repos/numenta/nupic/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/numenta/nupic/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/numenta/nupic/git/refs{/sha}","trees_url":"https://api.github.com/repos/numenta/nupic/git/trees{/sha}","statuses_url":"https://api.github.com/repos/numenta/nupic/statuses/{sha}","languages_url":"https://api.github.com/repos/numenta/nupic/languages","stargazers_url":"https://api.github.com/repos/numenta/nupic/stargazers","contributors_url":"https://api.github.com/repos/numenta/nupic/contributors","subscribers_url":"https://api.github.com/repos/numenta/nupic/subscribers","subscription_url":"https://api.github.com/repos/numenta/nupic/subscription","commits_url":"https://api.github.com/repos/numenta/nupic/commits{/sha}","git_commits_url":"https://api.github.com/repos/numenta/nupic/git/commits{/sha}","comments_url":"https://api.github.com/repos/numenta/nupic/comments{/number}","issue_comment_url":"https://api.github.com/repos/numenta/nupic/issues/comments{/number}","contents_url":"https://api.github.com/repos/numenta/nupic/contents/{+path}","compare_url":"https://api.github.com/repos/numenta/nupic/compare/{base}...{head}","merges_url":"https://api.github.com/repos/numenta/nupic/merges","archive_url":"https://api.github.com/repos/numenta/nupic/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/numenta/nupic/downloads","issues_url":"https://api.github.com/repos/numenta/nupic/issues{/number}","pulls_url":"https://api.github.com/repos/numenta/nupic/pulls{/number}","milestones_url":"https://api.github.com/repos/numenta/nupic/milestones{/number}","notifications_url":"https://api.github.com/repos/numenta/nupic/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/numenta/nupic/labels{/name}","releases_url":"https://api.github.com/repos/numenta/nupic/releases{/id}","created_at":"2013-04-05T23:14:27Z","updated_at":"2015-03-02T17:58:09Z","pushed_at":"2015-02-27T23:24:29Z","git_url":"git://github.com/numenta/nupic.git","ssh_url":"git@github.com:numenta/nupic.git","clone_url":"https://github.com/numenta/nupic.git","svn_url":"https://github.com/numenta/nupic","homepage":"http://numenta.org/","size":300246,"stargazers_count":2824,"watchers_count":2824,"language":"Python","has_issues":true,"has_downloads":true,"has_wiki":true,"has_pages":false,"forks_count":730,"mirror_url":null,"open_issues_count":309,"forks":730,"open_issues":309,"watchers":2824,"default_branch":"master"}},"_links":{"self":{"href":"https://api.github.com/repos/numenta/nupic/pulls/1850"},"html":{"href":"https://github.com/numenta/nupic/pull/1850"},"issue":{"href":"https://api.github.com/repos/numenta/nupic/issues/1850"},"comments":{"href":"https://api.github.com/repos/numenta/nupic/issues/1850/comments"},"review_comments":{"href":"https://api.github.com/repos/numenta/nupic/pulls/1850/comments"},"review_comment":{"href":"https://api.github.com/repos/numenta/nupic/pulls/comments{/number}"},"commits":{"href":"https://api.github.com/repos/numenta/nupic/pulls/1850/commits"},"statuses":{"href":"https://api.github.com/repos/numenta/nupic/statuses/18d67cfb8aa7a9a1e2d89b25c3afc4e89ae2870e"}}}}