{"action":"created","comment":{"url":"https://api.github.com/repos/gonum/optimize/pulls/comments/44100470","id":44100470,"diff_hunk":"@@ -59,65 +55,62 @@ func (b *BFGS) Iterate(loc *Location) (Operation, error) {\n func (b *BFGS) InitDirection(loc *Location, dir []float64) (stepSize float64) {\n \tdim := len(loc.X)\n \tb.dim = dim\n+\tb.first = true\n \n-\tb.x = resize(b.x, dim)\n-\tcopy(b.x, loc.X)\n-\tb.grad = resize(b.grad, dim)\n-\tcopy(b.grad, loc.Gradient)\n+\tx := mat64.NewVector(dim, loc.X)\n+\tgrad := mat64.NewVector(dim, loc.Gradient)\n+\tb.x.CloneVec(x)\n+\tb.grad.CloneVec(grad)\n \n-\tb.y = resize(b.y, dim)\n-\tb.s = resize(b.s, dim)\n-\tb.tmp = resize(b.tmp, dim)\n-\tb.yVec = mat64.NewVector(dim, b.y)\n-\tb.sVec = mat64.NewVector(dim, b.s)\n-\tb.tmpVec = mat64.NewVector(dim, b.tmp)\n+\tb.y.Reset()\n+\tb.s.Reset()\n+\tb.tmp.Reset()\n \n \tif b.invHess == nil || cap(b.invHess.RawSymmetric().Data) < dim*dim {\n \t\tb.invHess = mat64.NewSymDense(dim, nil)\n \t} else {\n \t\tb.invHess = mat64.NewSymDense(dim, b.invHess.RawSymmetric().Data[:dim*dim])\n \t}\n-\n-\t// The values of the hessian are initialized in the first call to NextDirection\n-\n-\t// initial direcion is just negative of gradient because the hessian is 1\n-\tcopy(dir, loc.Gradient)\n-\tfloats.Scale(-1, dir)\n-\n-\tb.first = true\n-\n-\treturn 1 / floats.Norm(dir, 2)\n+\t// The values of the inverse Hessian are initialized in the first call to\n+\t// NextDirection.\n+\n+\t// Initial direction is just negative of the gradient because the Hessian\n+\t// is an identity matrix.\n+\td := mat64.NewVector(dim, dir)\n+\td.ScaleVec(-1, grad)\n+\treturn 1 / mat64.Norm(d, 2)\n }\n \n func (b *BFGS) NextDirection(loc *Location, dir []float64) (stepSize float64) {\n-\tif len(loc.X) != b.dim {\n+\tdim := b.dim\n+\tif len(loc.X) != dim {\n \t\tpanic(\"bfgs: unexpected size mismatch\")\n \t}\n-\tif len(loc.Gradient) != b.dim {\n+\tif len(loc.Gradient) != dim {\n \t\tpanic(\"bfgs: unexpected size mismatch\")\n \t}\n-\tif len(dir) != b.dim {\n+\tif len(dir) != dim {\n \t\tpanic(\"bfgs: unexpected size mismatch\")\n \t}\n \n-\t// Compute the gradient difference in the last step\n-\t// y = g_{k+1} - g_{k}\n-\tfloats.SubTo(b.y, loc.Gradient, b.grad)\n+\tx := mat64.NewVector(dim, loc.X)\n+\tgrad := mat64.NewVector(dim, loc.Gradient)\n \n-\t// Compute the step difference\n \t// s = x_{k+1} - x_{k}\n-\tfloats.SubTo(b.s, loc.X, b.x)\n+\tb.s.SubVec(x, &b.x)\n+\t// y = g_{k+1} - g_{k}\n+\tb.y.SubVec(grad, &b.grad)\n \n-\tsDotY := floats.Dot(b.s, b.y)\n-\tsDotYSquared := sDotY * sDotY\n+\tsDotY := mat64.Dot(&b.s, &b.y)","path":"bfgs.go","position":135,"original_position":135,"commit_id":"e3b19c7a70ed9f61e9ca4a30b12080399b8c4db4","original_commit_id":"e3b19c7a70ed9f61e9ca4a30b12080399b8c4db4","user":{"login":"kortschak","id":275221,"avatar_url":"https://avatars.githubusercontent.com/u/275221?v=3","gravatar_id":"","url":"https://api.github.com/users/kortschak","html_url":"https://github.com/kortschak","followers_url":"https://api.github.com/users/kortschak/followers","following_url":"https://api.github.com/users/kortschak/following{/other_user}","gists_url":"https://api.github.com/users/kortschak/gists{/gist_id}","starred_url":"https://api.github.com/users/kortschak/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/kortschak/subscriptions","organizations_url":"https://api.github.com/users/kortschak/orgs","repos_url":"https://api.github.com/users/kortschak/repos","events_url":"https://api.github.com/users/kortschak/events{/privacy}","received_events_url":"https://api.github.com/users/kortschak/received_events","type":"User","site_admin":false},"body":"Collision.","created_at":"2015-11-06T03:26:36Z","updated_at":"2015-11-06T03:26:36Z","html_url":"https://github.com/gonum/optimize/pull/147#discussion_r44100470","pull_request_url":"https://api.github.com/repos/gonum/optimize/pulls/147","_links":{"self":{"href":"https://api.github.com/repos/gonum/optimize/pulls/comments/44100470"},"html":{"href":"https://github.com/gonum/optimize/pull/147#discussion_r44100470"},"pull_request":{"href":"https://api.github.com/repos/gonum/optimize/pulls/147"}}},"pull_request":{"url":"https://api.github.com/repos/gonum/optimize/pulls/147","id":49907734,"html_url":"https://github.com/gonum/optimize/pull/147","diff_url":"https://github.com/gonum/optimize/pull/147.diff","patch_url":"https://github.com/gonum/optimize/pull/147.patch","issue_url":"https://api.github.com/repos/gonum/optimize/issues/147","number":147,"state":"open","locked":false,"title":"Use mat64 instead of floats in BFGS","user":{"login":"vladimir-ch","id":1837502,"avatar_url":"https://avatars.githubusercontent.com/u/1837502?v=3","gravatar_id":"","url":"https://api.github.com/users/vladimir-ch","html_url":"https://github.com/vladimir-ch","followers_url":"https://api.github.com/users/vladimir-ch/followers","following_url":"https://api.github.com/users/vladimir-ch/following{/other_user}","gists_url":"https://api.github.com/users/vladimir-ch/gists{/gist_id}","starred_url":"https://api.github.com/users/vladimir-ch/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/vladimir-ch/subscriptions","organizations_url":"https://api.github.com/users/vladimir-ch/orgs","repos_url":"https://api.github.com/users/vladimir-ch/repos","events_url":"https://api.github.com/users/vladimir-ch/events{/privacy}","received_events_url":"https://api.github.com/users/vladimir-ch/received_events","type":"User","site_admin":false},"body":"I think that with mat64 the code is cleaner and clearer.\r\n\r\nAlso, don't update the inverse Hessian if `sDotY` is zero (to avoid division by zero).\r\n\r\n@btracey @kortschak PTAL","created_at":"2015-11-06T02:01:27Z","updated_at":"2015-11-06T03:26:36Z","closed_at":null,"merged_at":null,"merge_commit_sha":"9ea897db1c4d100a8f85fea532f21c656e8c1b0c","assignee":null,"milestone":null,"commits_url":"https://api.github.com/repos/gonum/optimize/pulls/147/commits","review_comments_url":"https://api.github.com/repos/gonum/optimize/pulls/147/comments","review_comment_url":"https://api.github.com/repos/gonum/optimize/pulls/comments{/number}","comments_url":"https://api.github.com/repos/gonum/optimize/issues/147/comments","statuses_url":"https://api.github.com/repos/gonum/optimize/statuses/e3b19c7a70ed9f61e9ca4a30b12080399b8c4db4","head":{"label":"gonum:bfgs-mat64","ref":"bfgs-mat64","sha":"e3b19c7a70ed9f61e9ca4a30b12080399b8c4db4","user":{"login":"gonum","id":3771091,"avatar_url":"https://avatars.githubusercontent.com/u/3771091?v=3","gravatar_id":"","url":"https://api.github.com/users/gonum","html_url":"https://github.com/gonum","followers_url":"https://api.github.com/users/gonum/followers","following_url":"https://api.github.com/users/gonum/following{/other_user}","gists_url":"https://api.github.com/users/gonum/gists{/gist_id}","starred_url":"https://api.github.com/users/gonum/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/gonum/subscriptions","organizations_url":"https://api.github.com/users/gonum/orgs","repos_url":"https://api.github.com/users/gonum/repos","events_url":"https://api.github.com/users/gonum/events{/privacy}","received_events_url":"https://api.github.com/users/gonum/received_events","type":"Organization","site_admin":false},"repo":{"id":24917465,"name":"optimize","full_name":"gonum/optimize","owner":{"login":"gonum","id":3771091,"avatar_url":"https://avatars.githubusercontent.com/u/3771091?v=3","gravatar_id":"","url":"https://api.github.com/users/gonum","html_url":"https://github.com/gonum","followers_url":"https://api.github.com/users/gonum/followers","following_url":"https://api.github.com/users/gonum/following{/other_user}","gists_url":"https://api.github.com/users/gonum/gists{/gist_id}","starred_url":"https://api.github.com/users/gonum/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/gonum/subscriptions","organizations_url":"https://api.github.com/users/gonum/orgs","repos_url":"https://api.github.com/users/gonum/repos","events_url":"https://api.github.com/users/gonum/events{/privacy}","received_events_url":"https://api.github.com/users/gonum/received_events","type":"Organization","site_admin":false},"private":false,"html_url":"https://github.com/gonum/optimize","description":"Package for finding the optimum value of functions.","fork":false,"url":"https://api.github.com/repos/gonum/optimize","forks_url":"https://api.github.com/repos/gonum/optimize/forks","keys_url":"https://api.github.com/repos/gonum/optimize/keys{/key_id}","collaborators_url":"https://api.github.com/repos/gonum/optimize/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/gonum/optimize/teams","hooks_url":"https://api.github.com/repos/gonum/optimize/hooks","issue_events_url":"https://api.github.com/repos/gonum/optimize/issues/events{/number}","events_url":"https://api.github.com/repos/gonum/optimize/events","assignees_url":"https://api.github.com/repos/gonum/optimize/assignees{/user}","branches_url":"https://api.github.com/repos/gonum/optimize/branches{/branch}","tags_url":"https://api.github.com/repos/gonum/optimize/tags","blobs_url":"https://api.github.com/repos/gonum/optimize/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/gonum/optimize/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/gonum/optimize/git/refs{/sha}","trees_url":"https://api.github.com/repos/gonum/optimize/git/trees{/sha}","statuses_url":"https://api.github.com/repos/gonum/optimize/statuses/{sha}","languages_url":"https://api.github.com/repos/gonum/optimize/languages","stargazers_url":"https://api.github.com/repos/gonum/optimize/stargazers","contributors_url":"https://api.github.com/repos/gonum/optimize/contributors","subscribers_url":"https://api.github.com/repos/gonum/optimize/subscribers","subscription_url":"https://api.github.com/repos/gonum/optimize/subscription","commits_url":"https://api.github.com/repos/gonum/optimize/commits{/sha}","git_commits_url":"https://api.github.com/repos/gonum/optimize/git/commits{/sha}","comments_url":"https://api.github.com/repos/gonum/optimize/comments{/number}","issue_comment_url":"https://api.github.com/repos/gonum/optimize/issues/comments{/number}","contents_url":"https://api.github.com/repos/gonum/optimize/contents/{+path}","compare_url":"https://api.github.com/repos/gonum/optimize/compare/{base}...{head}","merges_url":"https://api.github.com/repos/gonum/optimize/merges","archive_url":"https://api.github.com/repos/gonum/optimize/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/gonum/optimize/downloads","issues_url":"https://api.github.com/repos/gonum/optimize/issues{/number}","pulls_url":"https://api.github.com/repos/gonum/optimize/pulls{/number}","milestones_url":"https://api.github.com/repos/gonum/optimize/milestones{/number}","notifications_url":"https://api.github.com/repos/gonum/optimize/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/gonum/optimize/labels{/name}","releases_url":"https://api.github.com/repos/gonum/optimize/releases{/id}","created_at":"2014-10-08T00:14:50Z","updated_at":"2015-10-12T23:50:49Z","pushed_at":"2015-11-06T02:01:27Z","git_url":"git://github.com/gonum/optimize.git","ssh_url":"git@github.com:gonum/optimize.git","clone_url":"https://github.com/gonum/optimize.git","svn_url":"https://github.com/gonum/optimize","homepage":null,"size":1691,"stargazers_count":27,"watchers_count":27,"language":"Go","has_issues":true,"has_downloads":true,"has_wiki":true,"has_pages":false,"forks_count":6,"mirror_url":null,"open_issues_count":12,"forks":6,"open_issues":12,"watchers":27,"default_branch":"master"}},"base":{"label":"gonum:master","ref":"master","sha":"0c2ca8e6f18a3b5f02eb5db3c9253f35c56969bf","user":{"login":"gonum","id":3771091,"avatar_url":"https://avatars.githubusercontent.com/u/3771091?v=3","gravatar_id":"","url":"https://api.github.com/users/gonum","html_url":"https://github.com/gonum","followers_url":"https://api.github.com/users/gonum/followers","following_url":"https://api.github.com/users/gonum/following{/other_user}","gists_url":"https://api.github.com/users/gonum/gists{/gist_id}","starred_url":"https://api.github.com/users/gonum/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/gonum/subscriptions","organizations_url":"https://api.github.com/users/gonum/orgs","repos_url":"https://api.github.com/users/gonum/repos","events_url":"https://api.github.com/users/gonum/events{/privacy}","received_events_url":"https://api.github.com/users/gonum/received_events","type":"Organization","site_admin":false},"repo":{"id":24917465,"name":"optimize","full_name":"gonum/optimize","owner":{"login":"gonum","id":3771091,"avatar_url":"https://avatars.githubusercontent.com/u/3771091?v=3","gravatar_id":"","url":"https://api.github.com/users/gonum","html_url":"https://github.com/gonum","followers_url":"https://api.github.com/users/gonum/followers","following_url":"https://api.github.com/users/gonum/following{/other_user}","gists_url":"https://api.github.com/users/gonum/gists{/gist_id}","starred_url":"https://api.github.com/users/gonum/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/gonum/subscriptions","organizations_url":"https://api.github.com/users/gonum/orgs","repos_url":"https://api.github.com/users/gonum/repos","events_url":"https://api.github.com/users/gonum/events{/privacy}","received_events_url":"https://api.github.com/users/gonum/received_events","type":"Organization","site_admin":false},"private":false,"html_url":"https://github.com/gonum/optimize","description":"Package for finding the optimum value of functions.","fork":false,"url":"https://api.github.com/repos/gonum/optimize","forks_url":"https://api.github.com/repos/gonum/optimize/forks","keys_url":"https://api.github.com/repos/gonum/optimize/keys{/key_id}","collaborators_url":"https://api.github.com/repos/gonum/optimize/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/gonum/optimize/teams","hooks_url":"https://api.github.com/repos/gonum/optimize/hooks","issue_events_url":"https://api.github.com/repos/gonum/optimize/issues/events{/number}","events_url":"https://api.github.com/repos/gonum/optimize/events","assignees_url":"https://api.github.com/repos/gonum/optimize/assignees{/user}","branches_url":"https://api.github.com/repos/gonum/optimize/branches{/branch}","tags_url":"https://api.github.com/repos/gonum/optimize/tags","blobs_url":"https://api.github.com/repos/gonum/optimize/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/gonum/optimize/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/gonum/optimize/git/refs{/sha}","trees_url":"https://api.github.com/repos/gonum/optimize/git/trees{/sha}","statuses_url":"https://api.github.com/repos/gonum/optimize/statuses/{sha}","languages_url":"https://api.github.com/repos/gonum/optimize/languages","stargazers_url":"https://api.github.com/repos/gonum/optimize/stargazers","contributors_url":"https://api.github.com/repos/gonum/optimize/contributors","subscribers_url":"https://api.github.com/repos/gonum/optimize/subscribers","subscription_url":"https://api.github.com/repos/gonum/optimize/subscription","commits_url":"https://api.github.com/repos/gonum/optimize/commits{/sha}","git_commits_url":"https://api.github.com/repos/gonum/optimize/git/commits{/sha}","comments_url":"https://api.github.com/repos/gonum/optimize/comments{/number}","issue_comment_url":"https://api.github.com/repos/gonum/optimize/issues/comments{/number}","contents_url":"https://api.github.com/repos/gonum/optimize/contents/{+path}","compare_url":"https://api.github.com/repos/gonum/optimize/compare/{base}...{head}","merges_url":"https://api.github.com/repos/gonum/optimize/merges","archive_url":"https://api.github.com/repos/gonum/optimize/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/gonum/optimize/downloads","issues_url":"https://api.github.com/repos/gonum/optimize/issues{/number}","pulls_url":"https://api.github.com/repos/gonum/optimize/pulls{/number}","milestones_url":"https://api.github.com/repos/gonum/optimize/milestones{/number}","notifications_url":"https://api.github.com/repos/gonum/optimize/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/gonum/optimize/labels{/name}","releases_url":"https://api.github.com/repos/gonum/optimize/releases{/id}","created_at":"2014-10-08T00:14:50Z","updated_at":"2015-10-12T23:50:49Z","pushed_at":"2015-11-06T02:01:27Z","git_url":"git://github.com/gonum/optimize.git","ssh_url":"git@github.com:gonum/optimize.git","clone_url":"https://github.com/gonum/optimize.git","svn_url":"https://github.com/gonum/optimize","homepage":null,"size":1691,"stargazers_count":27,"watchers_count":27,"language":"Go","has_issues":true,"has_downloads":true,"has_wiki":true,"has_pages":false,"forks_count":6,"mirror_url":null,"open_issues_count":12,"forks":6,"open_issues":12,"watchers":27,"default_branch":"master"}},"_links":{"self":{"href":"https://api.github.com/repos/gonum/optimize/pulls/147"},"html":{"href":"https://github.com/gonum/optimize/pull/147"},"issue":{"href":"https://api.github.com/repos/gonum/optimize/issues/147"},"comments":{"href":"https://api.github.com/repos/gonum/optimize/issues/147/comments"},"review_comments":{"href":"https://api.github.com/repos/gonum/optimize/pulls/147/comments"},"review_comment":{"href":"https://api.github.com/repos/gonum/optimize/pulls/comments{/number}"},"commits":{"href":"https://api.github.com/repos/gonum/optimize/pulls/147/commits"},"statuses":{"href":"https://api.github.com/repos/gonum/optimize/statuses/e3b19c7a70ed9f61e9ca4a30b12080399b8c4db4"}}}}