jlperla / continuous_time_methods Goto Github PK
View Code? Open in Web Editor NEWLicense: MIT License
License: MIT License
From Ben:
Simply fix one element of the vector f, then solve the linear system (which is no longer singular) and the renormalize f afterwards. See e.g. this code snippet from http://www.princeton.edu/~moll/HACTproject/huggett_partialeq.m
AT = A';
b = zeros(2*I,1);
%need to fix one value, otherwise matrix is singular
i_fix = 1;
b(i_fix)=.1;
row = [zeros(1,i_fix-1),1,zeros(1,2*I-i_fix)];
AT(i_fix,:) = row;
%Solve linear system
gg = AT\b;
g_sum = gg'*ones(2*I,1)*da;
gg = gg./g_sum;
The question will be whether this approach can be generalized in a nonlinear setup.
See http://www.princeton.edu/~moll/HACTproject/HACT_Additional_Codes.pdf and http://www.princeton.edu/~moll/HACTproject/HACT_Numerical_Appendix.pdf
Build up to the http://www.princeton.edu/~moll/HACTproject/HJB_NGM_implicit.m solution for neoclassical growth with everything deterministic. No need to follow the explicit solution methods.
It seems like the discretized operator is Toeplitz as long as (1) the parameters don't change as a function of
The truncation of the operator seems to be used in https://ecommons.cornell.edu/handle/1813/5453 and it is worth seeing if the solution is close enough. This would be unlikely to work for the stationary distribution, though.
If so, then Toeplitz solvers could be used for the sparse stationary system, and possibly even the time-varying system.
Check all of the math in the docs/operator_discretization_finite_differences.tex
file. This has been separated from the older file, since I realized these notes will apply to all sorts of other examples.
A few things to check carefully:
I think there are numerical instabilities being introducing for large numbers of grid points due to the division by
I think I made all of the changes to the algebra document, though you should check very carefully in conjunction with #11 and then #13. After the algebra is verified, and before you do $13, you should convert the discretization code to match the algebra in the document.
Basically, the discretize_univariate_diffusion.m file just needs to match the new algebra for the A to return, and the checks in the test suite are modified to the new A.
Base this off of #8, though it could easily be done with the LCP.m based one.
Essentiallly, just do the finite differences with a fixed, but non-uniform grid. The key step will be that dx
is a vector of first differences of the x
vector (provided by the user).
Then when creating the X,Y,Z
matrices or generating the ./dx
The 2nd difference operator changes as well: Care will be need to be taken if diving by dx(i) vs. dx(i+1) vs. dx(i-1) given the current setup.
See http://www.princeton.edu/~moll/HACTproject/HACT_Numerical_Appendix.pdf page 22 for most of the work done and for verification.
@FernandoKuwer Once I get this up and running, you can start adding in your tests of the DiffEqOperators.
Following the basic pattern of #13, we want to create a set of regression tests for the simple optimal stopping problem. You will see simple_optimal_stopping_diffusion_test.m
which already has a test of the code against the old HACT setup.
Some of the tests to add are:
As always, the first part of the test is to make sure the results make sense, then the second part is to ensure it can automatically test that nothing changed.
Take a look at the stopping problem: http://www.princeton.edu/~moll/HACTproject/option_simple.pdf
Download http://www.princeton.edu/~moll/HACTproject/option_simple_LCP.m and http://www.princeton.edu/~moll/HACTproject/LCP.m
The goal is to figure out what the boundary value used for the right hand side of the finite difference scheme.. If the diffusion term was not there, this wouldn't be a problem since it uses the backward differences as upwind. But with the 2nd order term we need something else for the final point?
For the solution to the stationary_distribution_discretized_univariate.m and others, try to see if other preconditioning strategies work well for solving the LLS problem. For example, look at http://epubs.siam.org/doi/pdf/10.1137/140975358 and http://www2.cs.cas.cz/~tuma/ps/bru_mas_marin_tuma_2014.pdf for some references.
@stevenzhangdx you will see a change to the code, along with a new file run_examples.m
that can be modified to drive the examples.
This will be separated from the tests subdirectory.
Want the
Check for some interior set of the
$$
\max_{1/4 I < i < 3/4 I}{v^{n+1}_i - v^n}
$$
and see how that number changes with
In particular, the X matrices defined in the document are of size rank
function of matlab. The fact that this is really a system should be pointed out in the document prior to describing it as a LLS problem.
On the other hand, this doesn't necessarily change the solution technique for the system. For dense setups, the LLS approach can be compared to doing a pseudo-inverse or something similar in speed - but I suspect that LLS is close enough.
For sparse systems, we could investigate whether there are any sparse direct solvers that can solve rectangular systems. Iterative methods wouldn't work, but gaussian elimination should. Alternatively it is possible that sparse LLS is the best approach even if the rank is known.
When #33 is done, we can code up a basic test suite (along the lines of the current one) for the implicit system to compare it.
This is a continuation of #31
The trickiest part of this is figuring out what to do at the
After #1 is complete, you will see that the method uses an iterative step to update the value function. This works, but in principle the derivative information could provide better convergence of the model (and enable writing it in a way that can be extended).+
To do this, we first need to rewrite this as a system of equations in the vector V where a solution is given if the stacked equations are all close to 0. Unlike the existing code, which solves a linear system, this will be written as a nonlinear system of equations).
I want to update the neoclassical growth model to be as simple as possible and to test removing the dependence on the stationary solution. The task list is:
HJBE_discretization.pdf
as much as possible
s
-> gamma
df
to Delta
or whatever is the correct match)min(mub,0)
instead introduced mu_B_m
max(muf,0)introduces
mu_F_p`, etc.I want to ensure that /docs/HJBE_discretization.tex
has a complete set of algebra for the system of equations. I would like to write things in the notation of /docs/operator_discretization_finite_differences.tex
For example, using
After this, #2 becomes possible as the next step.
Given #16, stack with the
The issue is that it is it is a singular matrix, and ultimately an eigen problem. However, with an overconstrained system (adding the sum to 1 constraint and the weak positivity constraints), perhaps sparse linear least squares can solve the problem? Depends on #15
With a linear operator
Finish the annotation of: examples/continous_time_methods/optimal_stopping/option_simple_LCP.m
You will see a bunch of TODOs in the file. A few of them:
mu_bar = -0.01;
mu = ones(I,1).*mu_bar;
sig_bar = 0.01;
sig = x.*sig_bar;
sig2 = sig.^2;
Are we right to think that this says the drift is -0.01 and the variance squared is (0.01 *x)^2 ? Why no x on the drift?
A(N_x,N_x)= Y(N_x) + sigma_2(N_x)/(2*dx_2); A(N_x,N_x-1) = X(N_x);
variation in the code.After your modification and tests in discretize_univariate_diffusion_test.m
some of the other files are broken because of the change to multiplying
Can you fix this by modifying the following functions:
/matlab/lib/simple_HJBE_discretized_univariate.m
/matlab/lib/simple_joint_HJBE_stationary_distribution_univariate.m
/matlab/lib/simple_optimal_stopping_diffusion.m
/matlab/lib/stationary_distribution_discretized_univariate.m
/matlab/examples/optimal_stopping/LCP_example.m
The modifications will be pretty simple. In particular, mostly multiplying by operator_discretization_finite_differences.pdf
and optimal_stopping.pdf
You will know you are successful when you can run all of the tests in the matlab folder (i.e. run_tests.m
) with no errors. Also, the /matlab/examples/optimal_stopping/LCP_example.m
will require running manually.
Implement the #2 function. This will involve modification of http://www.princeton.edu/~moll/HACTproject/HJB_diffusion_implicit_RBC.m and http://www.princeton.edu/~moll/HACTproject/HJB_no_uncertainty_implicit.m
A few things:
This includes the logic on the boundary values and non-uniform grid, which you may not have run into.
Just to get started. Close once you think that you have reviewed it.
@stevenzhangdx I am starting on this, but have added you as an observer. May hand over to you for testing/etc.
While the code is written for generic upwind and downwind processes, the baseline has the same sign for all
The question is:
For example, in the
Is it the same story with a
Similar complications occur on the left hand boundary when done carefully.
For all cases, write things up very explicitly in optimal_stopping_notes
You will see that I modified /matlab/lib/simple_HJBE_discretized_univariate.m
(in 76e9373 ) to NOT divide A by operator_discretization_finite_differences.pdf
equation (39). The purpose of multiplying everything by
I didn't make the corresponding changes to simple_optimal_stopping_diffusion.m
or simple_joint_HJBE_stationary_distribution_univariate.m
, but we need to do a similar change to avoid dividing by simple_joint_HJBE_stationary_distribution_univariate.m
and simple_joint_HJBE_stationary_distribution_univariate.m
and make sure that the test cases pass (storing off new versions of the files as required).
Once #5, #6, and #7 are complete, we can swap out the LCP
function used in the baseline example for a high-performance commerical version. This is unlikely to help with this exact scenario since it is too simple, but may be necessary for larger problems with many more dimensions.
With tomab, see https://tomopt.com/docs/quickguide/quickguide027.php as a starting point. Knitro is likely to be the best solution.
It is essential that you verify it is setup (and solving) as a sparse problem. May require flipping through documents to look for possible settings that ensure sparseness, and setting sparseness patterns directly (or indirectly)?
Worst case, any quadratic solver with linear constraints can do LCP, since there is a mapping of the LCP to the KKT conditions of a quadratic problem. See https://en.wikipedia.org/wiki/Linear_complementarity_problem#Convex_quadratic-minimization:_Minimum_conditions for an example of the mapping.
Relies on #40 for the basic package.
You will need to get your basic julia workflow working with Juno/etc. Take a look at https://github.com/econtoolkit/julia
From the univariate diffusion, get the discretized operator with the reflecting boundaries, and compare to the matlab versions. We will add automatic tests later.
You will see that this is a split file which takes the discretization of the operator as given. Check the algebra against http://www.princeton.edu/~moll/HACTproject/option_simple.pdf and make sure that I added the slack variable correctly in my addition, as we may need to use that specification for some approaches.
Talk to Chris R about this as required to get the full DiffEqOperators setup. In the background, worth watching his tutorial to get a sense of how this stuff works: https://www.youtube.com/watch?v=tx8DRc7_c9I&=&t=2s
For our own simple testing setup, I will leave things much more open.
After #31 we can generate the
I added in two files \lib\discretize_time_varying_univariate_diffusion.m
has a skeleton of the function to generate the A
, just like in the non-time-varying case.
and the "matlab\tests\discretize_nonuniform_univariate_diffusion_test.m" provides a skeleton for it (including the way to stack the
Once you generate the code for the
Hi guys: I have set you both as assignees, and you can discuss splitting up any tasks.
I think I have a starting point for the algebra for discretizing the PDE. Get the latest version of the operator_discretization_finite_differences.tex
and compile it. You will see section 2 now has code on discretizing an operator with time dependence. Hopefully it is clear.
Some of the tasks here are:
Can we get analytical gradients with: http://tomsym.com/index.html
You will see a starting point in continuous_time_methods\matlab\tests\discretize_univariate_diffusion_test.m
The goal is to fully test the continuous_time_methods\matlab\lib\discretize_univariate_diffusion.m
script.
To come up with the comprehensive test suite, you will want to go through all of the key permutations of parameters. The idea is that everytime we make changes to the discretize_univariate_diffusion.m
file, we run the regression test to make sure nothing changed.
Beyond just ensuring that nothing changed, you should also make sure that the results match the theory in the continuous_time_methods\docs\optimal_stopping.pdf
notes. This is sometimes best done with simple versions (e.g. 5 nodes) where you can verify by hand that things make sense.
Some of the parameter variations to check:
x_min < 0
x_min
and x_max
give the correct answer for a given Given #37, you should fill in the continuous_time_methods\matlab\tests\time_varying_optimal_stopping_diffusion_test.m
tests with important tests to make sure you think the method is correct, and delivers sensible results. I threw in a few starting points, but they are not really verified.
Come up with a test case to ensure no bugs were introduced into the new code.
Save a vector of out put from original HACT code, put it in folder, and then automatically test at the bottom of the new file if it is the same.
@stevenzhangdx adding as observer. This depends on #28
First, go through the optimal_stopping.pdf
section 1 to make sure that you understand the stopping problem and how it maps to a LCP.
Then, go through the new section 2 to make sure I didn't introduce a mistake. It is very simple, as it relies on our discretization of the time-varying diffusion process (which we have hopefully fully tested by this point).
Finally, you will see in continuous_time_methods\matlab\lib\optimal_stopping_diffusion.m
an implementation of this method, which relies on the discretization of the linear operators. I wrote up a starting point for the tests in time_varying_optimal_stopping_diffusion_test.m
. Make sure that you think this implements what it says it does, and that the code matches the description. At this point, no need to test anything besides the yuval
algorithm
A declarative, efficient, and flexible JavaScript library for building user interfaces.
๐ Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. ๐๐๐
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google โค๏ธ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.