README.md (4782B)
1 README 2 ====== 3 4 This is a Github repository with a set of Matlab scripts for reverse shooting. They originally come from Chad Jones' paper [Life and Growth](https://web.stanford.edu/~chadj/LifeandGrowthJPE2016.pdf), and were then modified for use on [Existential Risk and Growth](https://leopoldaschenbrenner.github.io/xriskandgrowth/ExistentialRiskAndGrowth050.pdf). I then cleaned it up and added comments, starting with some notes by Ben Snodin. 5 6 The code contains two parts, one which carries out some vanilla reverse shooting, and another which adds shocks and accelerations. I have only cleaned out the first part, and don't particularly intend to engage with the second. 7 8 ## Vanilla reverse shooting 9 Files: Calibrate.m, getsteadystate.m, transit1dx.m, solvetransition.m, getells0.m, Transition.m 10 11 How to use: Change the "matlabminiscriptspath" variable on Transition.m, and then run Transition.m 12 13 Modify: Change the hard-coded values and equations in the vanilla reverse shooting files to your desired equations and values. Change the "matlabminiscriptspath" variable on Calibration.m as well. 14 15 ## Shocks and accelerations 16 Files: Acceleration.m, TransitoryShock.m, FindAlternativePath.m 17 18 How to use and modify: Here be dragons. Don't. Leave that to less innocent souls. 19 20 ## What each file does 21 22 ### getsteadystate.m 23 Give the long-run values for important variables for some important cases (proposition 2 and proposition 5) 24 25 ### transit1dx.m 26 A function representing a system of 6 ODEs for the time evolution of the model. Specifically, I think it gives the changes in the time-dependent variables corresponding to the current values and step-size 27 28 ### solvetransition.m 29 A function that computes the path for the system over the specified time interval. It finds the "best" s_0 and l_0 given the other parameters provided, and returns the transition corresponding to that. It uses getells0.m to get the best s_0 and l_0 30 31 ### getells0.m 32 Returns values of s_o and l_o such that d(l)_0 - g_s* and d(s)_0 - g_s* and d(sigma)_0 are minimized, given all other model parameters (note that you don't need a transition path for this). d(some variable) is that variable with a ^ on top, in the paper. Represents the derivative 33 34 ### Calibrate.m 35 prints values for various values that represent a calibration that's specified in Appendix B1 of the paper. The objective function is based on the transition path. Note that, for each proposed choice of these variables, s_0 and l_0 are found using getells0.m, which is called by solvetransition.m as it gets the transition path. 36 37 ### Transition.m 38 Finds the transition path using solvetransition.m using the values from Calibrate.m for the various variables (note that these values are hard-coded) Plots some variables for the path (I think I recognise them from the paper) 39 40 ### Acceleration.m 41 Finds a transition path using solvetransition.m which represents the baseline case. Then uses FindAlternativePath to find the path with accelerated growth. FindAlternativePath.m works by generating paths with accelerated growth with various d_0 and N_0, choosing one that at some point passes through the same state as teh baseline case does at some time. Plots some variables from both paths (I think I recognise them from the patper) 42 43 ### TransitoryShock.m 44 As Acceleration.m, but for the transitory shock rather than the acceleration case. 45 46 ### FindAlternativePath.m 47 Returns values of delta_0 and N_0 such that the associated path minimizes the following objective function "find the time t_0 on the path where delta_(t_0) is close to a given target. Then get the weighted sum of squared deviations between the state variables and the target state variables. 48 49 ## General notes and gotchas 50 Matlab doesn't seem to have a return keyword; instead return variables are specified with the function definition. 51 52 I.e., what would be 53 54 ``` 55 someFunctionName = function(some variables){ 56 do something here 57 return(results) 58 } 59 ``` 60 61 in any reasonable programming language, is instead in matlab 62 63 ``` 64 [result1, result2, ...] = someFunctionName(some variables) 65 do something here 66 end 67 ``` 68 69 In functions which take a whole file (and which share the name with that file) it isn't necessary to write the end keyword, but I have because it's less confusing. 70 71 This code may not work on Octave, an open source matlab clone, and didn't as of 4/Sept/2020, because optimoptions and optimset have [not been exported](https://wiki.octave.org/Optimization_package) to Octave yet. 72 73 In matlab scripts (i.e., files with a .m extension, rather than inputs into the matlab terminal), function definitions must be placed at the end of a file, even if they are used before. 74 75 Logs are created on the directory returned by the pwd (print working directory) matlab function.