{"action":"created","comment":{"url":"https://api.github.com/repos/QuantEcon/QuantEcon.jl/pulls/comments/32953622","id":32953622,"diff_hunk":"@@ -107,81 +83,103 @@ function update_values!(lq::LQ)\n     # Set new state\n     lq.P = new_P\n     lq.d = new_d\n-    return nothing\n end\n \n-\n function stationary_values!(lq::LQ)\n     # simplify notation\n-    Q, R, A, B, C = lq.Q, lq.R, lq.A, lq.B, lq.C\n+    Q, R, A, B, N, C = lq.Q, lq.R, lq.A, lq.B, lq.N, lq.C\n \n     # solve Riccati equation, obtain P\n-    A0, B0 = sqrt(lq.bet) .* A, sqrt(lq.bet) .* B\n-    P = solve_discrete_riccati(A0, B0, R, Q)\n+    A0, B0 = sqrt(lq.bet) * A, sqrt(lq.bet) * B\n+    P = solve_discrete_riccati(A0, B0, R, Q, N)\n \n     # Compute F\n-    S1 = Q .+ lq.bet .* (B' * P * B)\n-    S2 = lq.bet .* (B' * P * A)\n-    F = S1 \\ S2\n+    s1 = Q + lq.bet * (B' * P * B)\n+    s2 = lq.bet * (B' * P * A) + N\n+    F = s1 \\ s2\n \n     # Compute d\n-    d = lq.bet .* trace(P * C * C') / (1 - lq.bet)\n+    d = lq.bet * trace(P * C * C') / (1 - lq.bet)\n \n     # Bind states\n     lq.P, lq.F, lq.d = P, F, d\n-    nothing\n end\n \n function stationary_values(lq::LQ)\n-    stationary_values!(lq)\n-    return lq.P, lq.F, lq.d\n+\t_lq = LQ(\n+\t\t\tcopy(lq.Q), \n+\t\t\tcopy(lq.R), \n+\t\t\tcopy(lq.A), \n+\t\t\tcopy(lq.B), \n+\t\t\tcopy(lq.C), \n+\t\t\tcopy(lq.N),\n+\t\t\tcopy(lq.bet), \n+\t\t\tlq.term,\n+\t\t\tcopy(lq.rf))\n+\n+    stationary_values!(_lq)\n+    return _lq.P, _lq.F, _lq.d\n end\n \n+# dispatch for a scalar problem\n+function _compute_sequence{T}(lq::LQ, x0::T, policies)\n+\tterm = length(policies)\n+\tx_path = Array(T, term+1)\n+\tu_path = Array(T, term)\n+\t\n+\tx_path[1] = x0\n+\tu_path[1] = -(first(policies)*x0)\n+\tw_path    = lq.C * randn(term+1)\n+\n+    for t = 2:term\n+        f = policies[t]\n+        x_path[t] = lq.A*x_path[t-1] + lq.B*u_path[t-1] + w_path[t]\n+        u_path[t] = -(f*x_path[t])\n+    end\n+    x_path[end] = lq.A*x_path[term] + lq.B*u_path[term] + w_path[end]\n \n-function compute_sequence(lq::LQ, x0::ScalarOrArray, ts_length=100)\n-    # simplify notation\n-    Q, R, A, B, C = lq.Q, lq.R, lq.A, lq.B, lq.C\n+    x_path, u_path, w_path\n+end\n+\n+# dispatch for a vector problem\n+function _compute_sequence{T}(lq::LQ, x0::Vector{T}, policies)\n+\tn, j, term = length(x0), length(lq.C), length(policies)","path":"src/lqcontrol.jl","position":204,"original_position":204,"commit_id":"a19f4c08f5c5a9a95a23b284c4e472956329971f","original_commit_id":"a19f4c08f5c5a9a95a23b284c4e472956329971f","user":{"login":"spencerlyon2","id":1001948,"avatar_url":"https://avatars.githubusercontent.com/u/1001948?v=3","gravatar_id":"","url":"https://api.github.com/users/spencerlyon2","html_url":"https://github.com/spencerlyon2","followers_url":"https://api.github.com/users/spencerlyon2/followers","following_url":"https://api.github.com/users/spencerlyon2/following{/other_user}","gists_url":"https://api.github.com/users/spencerlyon2/gists{/gist_id}","starred_url":"https://api.github.com/users/spencerlyon2/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/spencerlyon2/subscriptions","organizations_url":"https://api.github.com/users/spencerlyon2/orgs","repos_url":"https://api.github.com/users/spencerlyon2/repos","events_url":"https://api.github.com/users/spencerlyon2/events{/privacy}","received_events_url":"https://api.github.com/users/spencerlyon2/received_events","type":"User","site_admin":false},"body":"This is not `j`.\r\n\r\n`j` should be the number of columns in `C`: `j = size(C, 2)`","created_at":"2015-06-22T16:27:03Z","updated_at":"2015-06-22T16:27:03Z","html_url":"https://github.com/QuantEcon/QuantEcon.jl/pull/48#discussion_r32953622","pull_request_url":"https://api.github.com/repos/QuantEcon/QuantEcon.jl/pulls/48","_links":{"self":{"href":"https://api.github.com/repos/QuantEcon/QuantEcon.jl/pulls/comments/32953622"},"html":{"href":"https://github.com/QuantEcon/QuantEcon.jl/pull/48#discussion_r32953622"},"pull_request":{"href":"https://api.github.com/repos/QuantEcon/QuantEcon.jl/pulls/48"}}},"pull_request":{"url":"https://api.github.com/repos/QuantEcon/QuantEcon.jl/pulls/48","id":38086453,"html_url":"https://github.com/QuantEcon/QuantEcon.jl/pull/48","diff_url":"https://github.com/QuantEcon/QuantEcon.jl/pull/48.diff","patch_url":"https://github.com/QuantEcon/QuantEcon.jl/pull/48.patch","issue_url":"https://api.github.com/repos/QuantEcon/QuantEcon.jl/issues/48","number":48,"state":"open","locked":false,"title":"LQ Cross Product & Revamp","user":{"login":"ZacCranko","id":7624301,"avatar_url":"https://avatars.githubusercontent.com/u/7624301?v=3","gravatar_id":"","url":"https://api.github.com/users/ZacCranko","html_url":"https://github.com/ZacCranko","followers_url":"https://api.github.com/users/ZacCranko/followers","following_url":"https://api.github.com/users/ZacCranko/following{/other_user}","gists_url":"https://api.github.com/users/ZacCranko/gists{/gist_id}","starred_url":"https://api.github.com/users/ZacCranko/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/ZacCranko/subscriptions","organizations_url":"https://api.github.com/users/ZacCranko/orgs","repos_url":"https://api.github.com/users/ZacCranko/repos","events_url":"https://api.github.com/users/ZacCranko/events{/privacy}","received_events_url":"https://api.github.com/users/ZacCranko/received_events","type":"User","site_admin":false},"body":"This PR adds support for a cross product term in the LQ dynamic programming problem, addressing #16.\r\n\r\nAdditionally:\r\n* Cleaned up the linear algebra so that algorithms work natively with arrays and scalars without having to convert everything to `Array(T,1,1)` and use broadcast operators everywhere.\r\n* Now `compute_sequence` returns a one dimensional array for scalar problems, and a two dimensional array for vector problems. \r\n\r\nThings to discuss:\r\n* I have renamed the variable for the terminal period (in the finite horizon case) `T` to `term` since `T` is a very special name in the Julia universe, and nearly always used for a type variable. Is this okay?\r\n* I renamed `Rf` to `rf` to cut down on the capital variables floating around, happy to revert this if it offends.\r\n\r\nThings not in this PR:\r\n* Should we rename `LQ` to `LinearQuadratic` or `LinearQuadraticControl` in keeping with the julian camel case naming convention for types?\r\n* I have not implemented `Nullable` types for the optional arguments.... I had a quick go at this, but ran out of time. It took me a whole day to get this thing to work and there are other issues that need attending to, but I think the code is a lot cleaner now than before.\r\n\r\nN.b. Travis is failing because of some stuff in `robustlq.jl`. If [this line](https://github.com/QuantEcon/QuantEcon.jl/blob/master/src/QuantEcon.jl#L122) is commented out from `QuantEcon.jl` everything behaves itself.","created_at":"2015-06-19T08:26:27Z","updated_at":"2015-06-22T16:27:03Z","closed_at":null,"merged_at":null,"merge_commit_sha":"5aff51c5316d3f8b02537e2a99e79dd99b85cfe2","assignee":null,"milestone":null,"commits_url":"https://api.github.com/repos/QuantEcon/QuantEcon.jl/pulls/48/commits","review_comments_url":"https://api.github.com/repos/QuantEcon/QuantEcon.jl/pulls/48/comments","review_comment_url":"https://api.github.com/repos/QuantEcon/QuantEcon.jl/pulls/comments{/number}","comments_url":"https://api.github.com/repos/QuantEcon/QuantEcon.jl/issues/48/comments","statuses_url":"https://api.github.com/repos/QuantEcon/QuantEcon.jl/statuses/a19f4c08f5c5a9a95a23b284c4e472956329971f","head":{"label":"QuantEcon:lq-cross-product","ref":"lq-cross-product","sha":"a19f4c08f5c5a9a95a23b284c4e472956329971f","user":{"login":"QuantEcon","id":8703060,"avatar_url":"https://avatars.githubusercontent.com/u/8703060?v=3","gravatar_id":"","url":"https://api.github.com/users/QuantEcon","html_url":"https://github.com/QuantEcon","followers_url":"https://api.github.com/users/QuantEcon/followers","following_url":"https://api.github.com/users/QuantEcon/following{/other_user}","gists_url":"https://api.github.com/users/QuantEcon/gists{/gist_id}","starred_url":"https://api.github.com/users/QuantEcon/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/QuantEcon/subscriptions","organizations_url":"https://api.github.com/users/QuantEcon/orgs","repos_url":"https://api.github.com/users/QuantEcon/repos","events_url":"https://api.github.com/users/QuantEcon/events{/privacy}","received_events_url":"https://api.github.com/users/QuantEcon/received_events","type":"Organization","site_admin":false},"repo":{"id":21705573,"name":"QuantEcon.jl","full_name":"QuantEcon/QuantEcon.jl","owner":{"login":"QuantEcon","id":8703060,"avatar_url":"https://avatars.githubusercontent.com/u/8703060?v=3","gravatar_id":"","url":"https://api.github.com/users/QuantEcon","html_url":"https://github.com/QuantEcon","followers_url":"https://api.github.com/users/QuantEcon/followers","following_url":"https://api.github.com/users/QuantEcon/following{/other_user}","gists_url":"https://api.github.com/users/QuantEcon/gists{/gist_id}","starred_url":"https://api.github.com/users/QuantEcon/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/QuantEcon/subscriptions","organizations_url":"https://api.github.com/users/QuantEcon/orgs","repos_url":"https://api.github.com/users/QuantEcon/repos","events_url":"https://api.github.com/users/QuantEcon/events{/privacy}","received_events_url":"https://api.github.com/users/QuantEcon/received_events","type":"Organization","site_admin":false},"private":false,"html_url":"https://github.com/QuantEcon/QuantEcon.jl","description":"Julia implementation of QuantEcon routines","fork":false,"url":"https://api.github.com/repos/QuantEcon/QuantEcon.jl","forks_url":"https://api.github.com/repos/QuantEcon/QuantEcon.jl/forks","keys_url":"https://api.github.com/repos/QuantEcon/QuantEcon.jl/keys{/key_id}","collaborators_url":"https://api.github.com/repos/QuantEcon/QuantEcon.jl/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/QuantEcon/QuantEcon.jl/teams","hooks_url":"https://api.github.com/repos/QuantEcon/QuantEcon.jl/hooks","issue_events_url":"https://api.github.com/repos/QuantEcon/QuantEcon.jl/issues/events{/number}","events_url":"https://api.github.com/repos/QuantEcon/QuantEcon.jl/events","assignees_url":"https://api.github.com/repos/QuantEcon/QuantEcon.jl/assignees{/user}","branches_url":"https://api.github.com/repos/QuantEcon/QuantEcon.jl/branches{/branch}","tags_url":"https://api.github.com/repos/QuantEcon/QuantEcon.jl/tags","blobs_url":"https://api.github.com/repos/QuantEcon/QuantEcon.jl/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/QuantEcon/QuantEcon.jl/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/QuantEcon/QuantEcon.jl/git/refs{/sha}","trees_url":"https://api.github.com/repos/QuantEcon/QuantEcon.jl/git/trees{/sha}","statuses_url":"https://api.github.com/repos/QuantEcon/QuantEcon.jl/statuses/{sha}","languages_url":"https://api.github.com/repos/QuantEcon/QuantEcon.jl/languages","stargazers_url":"https://api.github.com/repos/QuantEcon/QuantEcon.jl/stargazers","contributors_url":"https://api.github.com/repos/QuantEcon/QuantEcon.jl/contributors","subscribers_url":"https://api.github.com/repos/QuantEcon/QuantEcon.jl/subscribers","subscription_url":"https://api.github.com/repos/QuantEcon/QuantEcon.jl/subscription","commits_url":"https://api.github.com/repos/QuantEcon/QuantEcon.jl/commits{/sha}","git_commits_url":"https://api.github.com/repos/QuantEcon/QuantEcon.jl/git/commits{/sha}","comments_url":"https://api.github.com/repos/QuantEcon/QuantEcon.jl/comments{/number}","issue_comment_url":"https://api.github.com/repos/QuantEcon/QuantEcon.jl/issues/comments{/number}","contents_url":"https://api.github.com/repos/QuantEcon/QuantEcon.jl/contents/{+path}","compare_url":"https://api.github.com/repos/QuantEcon/QuantEcon.jl/compare/{base}...{head}","merges_url":"https://api.github.com/repos/QuantEcon/QuantEcon.jl/merges","archive_url":"https://api.github.com/repos/QuantEcon/QuantEcon.jl/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/QuantEcon/QuantEcon.jl/downloads","issues_url":"https://api.github.com/repos/QuantEcon/QuantEcon.jl/issues{/number}","pulls_url":"https://api.github.com/repos/QuantEcon/QuantEcon.jl/pulls{/number}","milestones_url":"https://api.github.com/repos/QuantEcon/QuantEcon.jl/milestones{/number}","notifications_url":"https://api.github.com/repos/QuantEcon/QuantEcon.jl/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/QuantEcon/QuantEcon.jl/labels{/name}","releases_url":"https://api.github.com/repos/QuantEcon/QuantEcon.jl/releases{/id}","created_at":"2014-07-10T18:30:31Z","updated_at":"2015-06-15T19:24:51Z","pushed_at":"2015-06-22T14:21:23Z","git_url":"git://github.com/QuantEcon/QuantEcon.jl.git","ssh_url":"git@github.com:QuantEcon/QuantEcon.jl.git","clone_url":"https://github.com/QuantEcon/QuantEcon.jl.git","svn_url":"https://github.com/QuantEcon/QuantEcon.jl","homepage":null,"size":20323,"stargazers_count":39,"watchers_count":39,"language":"Julia","has_issues":true,"has_downloads":true,"has_wiki":true,"has_pages":false,"forks_count":36,"mirror_url":null,"open_issues_count":13,"forks":36,"open_issues":13,"watchers":39,"default_branch":"master"}},"base":{"label":"QuantEcon:master","ref":"master","sha":"c297d6cea243d9de6fb0162c9686b8b359720947","user":{"login":"QuantEcon","id":8703060,"avatar_url":"https://avatars.githubusercontent.com/u/8703060?v=3","gravatar_id":"","url":"https://api.github.com/users/QuantEcon","html_url":"https://github.com/QuantEcon","followers_url":"https://api.github.com/users/QuantEcon/followers","following_url":"https://api.github.com/users/QuantEcon/following{/other_user}","gists_url":"https://api.github.com/users/QuantEcon/gists{/gist_id}","starred_url":"https://api.github.com/users/QuantEcon/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/QuantEcon/subscriptions","organizations_url":"https://api.github.com/users/QuantEcon/orgs","repos_url":"https://api.github.com/users/QuantEcon/repos","events_url":"https://api.github.com/users/QuantEcon/events{/privacy}","received_events_url":"https://api.github.com/users/QuantEcon/received_events","type":"Organization","site_admin":false},"repo":{"id":21705573,"name":"QuantEcon.jl","full_name":"QuantEcon/QuantEcon.jl","owner":{"login":"QuantEcon","id":8703060,"avatar_url":"https://avatars.githubusercontent.com/u/8703060?v=3","gravatar_id":"","url":"https://api.github.com/users/QuantEcon","html_url":"https://github.com/QuantEcon","followers_url":"https://api.github.com/users/QuantEcon/followers","following_url":"https://api.github.com/users/QuantEcon/following{/other_user}","gists_url":"https://api.github.com/users/QuantEcon/gists{/gist_id}","starred_url":"https://api.github.com/users/QuantEcon/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/QuantEcon/subscriptions","organizations_url":"https://api.github.com/users/QuantEcon/orgs","repos_url":"https://api.github.com/users/QuantEcon/repos","events_url":"https://api.github.com/users/QuantEcon/events{/privacy}","received_events_url":"https://api.github.com/users/QuantEcon/received_events","type":"Organization","site_admin":false},"private":false,"html_url":"https://github.com/QuantEcon/QuantEcon.jl","description":"Julia implementation of QuantEcon routines","fork":false,"url":"https://api.github.com/repos/QuantEcon/QuantEcon.jl","forks_url":"https://api.github.com/repos/QuantEcon/QuantEcon.jl/forks","keys_url":"https://api.github.com/repos/QuantEcon/QuantEcon.jl/keys{/key_id}","collaborators_url":"https://api.github.com/repos/QuantEcon/QuantEcon.jl/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/QuantEcon/QuantEcon.jl/teams","hooks_url":"https://api.github.com/repos/QuantEcon/QuantEcon.jl/hooks","issue_events_url":"https://api.github.com/repos/QuantEcon/QuantEcon.jl/issues/events{/number}","events_url":"https://api.github.com/repos/QuantEcon/QuantEcon.jl/events","assignees_url":"https://api.github.com/repos/QuantEcon/QuantEcon.jl/assignees{/user}","branches_url":"https://api.github.com/repos/QuantEcon/QuantEcon.jl/branches{/branch}","tags_url":"https://api.github.com/repos/QuantEcon/QuantEcon.jl/tags","blobs_url":"https://api.github.com/repos/QuantEcon/QuantEcon.jl/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/QuantEcon/QuantEcon.jl/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/QuantEcon/QuantEcon.jl/git/refs{/sha}","trees_url":"https://api.github.com/repos/QuantEcon/QuantEcon.jl/git/trees{/sha}","statuses_url":"https://api.github.com/repos/QuantEcon/QuantEcon.jl/statuses/{sha}","languages_url":"https://api.github.com/repos/QuantEcon/QuantEcon.jl/languages","stargazers_url":"https://api.github.com/repos/QuantEcon/QuantEcon.jl/stargazers","contributors_url":"https://api.github.com/repos/QuantEcon/QuantEcon.jl/contributors","subscribers_url":"https://api.github.com/repos/QuantEcon/QuantEcon.jl/subscribers","subscription_url":"https://api.github.com/repos/QuantEcon/QuantEcon.jl/subscription","commits_url":"https://api.github.com/repos/QuantEcon/QuantEcon.jl/commits{/sha}","git_commits_url":"https://api.github.com/repos/QuantEcon/QuantEcon.jl/git/commits{/sha}","comments_url":"https://api.github.com/repos/QuantEcon/QuantEcon.jl/comments{/number}","issue_comment_url":"https://api.github.com/repos/QuantEcon/QuantEcon.jl/issues/comments{/number}","contents_url":"https://api.github.com/repos/QuantEcon/QuantEcon.jl/contents/{+path}","compare_url":"https://api.github.com/repos/QuantEcon/QuantEcon.jl/compare/{base}...{head}","merges_url":"https://api.github.com/repos/QuantEcon/QuantEcon.jl/merges","archive_url":"https://api.github.com/repos/QuantEcon/QuantEcon.jl/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/QuantEcon/QuantEcon.jl/downloads","issues_url":"https://api.github.com/repos/QuantEcon/QuantEcon.jl/issues{/number}","pulls_url":"https://api.github.com/repos/QuantEcon/QuantEcon.jl/pulls{/number}","milestones_url":"https://api.github.com/repos/QuantEcon/QuantEcon.jl/milestones{/number}","notifications_url":"https://api.github.com/repos/QuantEcon/QuantEcon.jl/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/QuantEcon/QuantEcon.jl/labels{/name}","releases_url":"https://api.github.com/repos/QuantEcon/QuantEcon.jl/releases{/id}","created_at":"2014-07-10T18:30:31Z","updated_at":"2015-06-15T19:24:51Z","pushed_at":"2015-06-22T14:21:23Z","git_url":"git://github.com/QuantEcon/QuantEcon.jl.git","ssh_url":"git@github.com:QuantEcon/QuantEcon.jl.git","clone_url":"https://github.com/QuantEcon/QuantEcon.jl.git","svn_url":"https://github.com/QuantEcon/QuantEcon.jl","homepage":null,"size":20323,"stargazers_count":39,"watchers_count":39,"language":"Julia","has_issues":true,"has_downloads":true,"has_wiki":true,"has_pages":false,"forks_count":36,"mirror_url":null,"open_issues_count":13,"forks":36,"open_issues":13,"watchers":39,"default_branch":"master"}},"_links":{"self":{"href":"https://api.github.com/repos/QuantEcon/QuantEcon.jl/pulls/48"},"html":{"href":"https://github.com/QuantEcon/QuantEcon.jl/pull/48"},"issue":{"href":"https://api.github.com/repos/QuantEcon/QuantEcon.jl/issues/48"},"comments":{"href":"https://api.github.com/repos/QuantEcon/QuantEcon.jl/issues/48/comments"},"review_comments":{"href":"https://api.github.com/repos/QuantEcon/QuantEcon.jl/pulls/48/comments"},"review_comment":{"href":"https://api.github.com/repos/QuantEcon/QuantEcon.jl/pulls/comments{/number}"},"commits":{"href":"https://api.github.com/repos/QuantEcon/QuantEcon.jl/pulls/48/commits"},"statuses":{"href":"https://api.github.com/repos/QuantEcon/QuantEcon.jl/statuses/a19f4c08f5c5a9a95a23b284c4e472956329971f"}}}}