Error running EpsteinZinPreferences Example

Hi Robert,

I got the following error when running the EpsteinZinPreferences.m example. I have no idea how to fix it. Thank you.

Error using .^
POWER: needs to return a complex result, but this is not supported for real input X and Y on the GPU. Use POWER(COMPLEX(X),COMPLEX(Y,0)) instead.
Error in ValueFnIter_Case1_EpsteinZin_Par2_raw (line 70)
[Vtemp,maxindex]=max(entireRHS.^(1/(1-1/DiscountFactorParamsVec(3))),[],1);
Error in ValueFnIter_Case1_EpsteinZin (line 61)
[VKron, Policy]=ValueFnIter_Case1_EpsteinZin_Par2_raw(V0, n_d,n_a,n_z, pi_z, DiscountFactorParamsVec, ReturnMatrix,vfoptions.howards, vfoptions.maxhowards,vfoptions.tolerance);
Error in ValueFnIter_Case1 (line 253)
[V, Policy]=ValueFnIter_Case1_EpsteinZin(V0, n_d,n_a,n_z,d_grid,a_grid,z_grid, pi_z, DiscountFactorParamNames, ReturnFn, vfoptions,Parameters,ReturnFnParamNames);
Error in EpsteinZinPreferences (line 137)
[V, Policy]=ValueFnIter_Case1(n_d,n_a,n_s,d_grid,a_grid,s_grid, pi_s, ReturnFn, Params, DiscountFactorParamNames, [], vfoptions);

1 Like

Sorry but I am not able to take a look as I am about a week or two away from releasing an overhaul of the implementation of Epstein-Zin preferences (to properly handle conditional survival probabilities and bequests) and so I only have the ‘new’ version on my computer.

You might try running Life-Cycle Model 12 from the Intro to Life-Cycle Models which also uses Epstein-Zin preferences.

The new and improved implementation of Epstein-Zin preferences should hopefully be out in a week or two at which point I will also be overhauling all the example codes so I will be updating the example you mention then in any case.

Thank you, Robert. This is very helpful.

Just pushed the (breaking) overhaul of Epstein-Zin preferences. You can find the new way it works in the Intro to Life-Cycle Models, specifically model 12 (and an appendix on EZ prefs). Is already documented in the Intro to Life-Cycle Models, and in the Exotic Preferences pdf, but won’t make actual public announcement for another week or two (want to do it at same time as portfolio-choice which is almost ready).

[Two improvements: Implements EZ in utility-units, alongside the traditional consumption-units. Also properly handles warm-glow of bequests with EZ preferences which is subtle and goes badly wrong if you just treat them naively, as shown by Kraft, Munk & Weiss (2022)]

There are also some codes I used to double-check that EZ with the right parametrization does just give standard preferences. In case anyone is interested they can be found here.

1 Like

Hi there!

I tried running the same example and I’m getting the following error:

>> EpsteinZinPreferences
Grid sizes n_k=200, n_l=31, n_z=25, n_sigma=5 

vfoptions = 

  struct with fields:

              exoticpreferences: 'EpsteinZin'
                        EZutils: 0
                 EZoneminusbeta: 1
                 EZriskaversion: 'gamma'
                          EZeis: 'psi'
                        verbose: 1
                     solnmethod: 'purediscretization'
                       parallel: 1
                   returnmatrix: 0
                      lowmemory: 0
                      tolerance: 1.0000e-09
                        howards: 80
                     maxhowards: 500
                 endogenousexit: 0
                       endotype: 0
                incrementaltype: 0
                    polindorval: 1
        policy_forceintegertype: 0
    piz_strictonrowsaddingtoone: 0
                     outputkron: 0

Creating return fn matrix
Not enough input arguments.

Error in CreateReturnFnMatrix_Case1_Disc (line 8)
ParamCell=cell(length(ReturnFnParamsVec),1);

Error in ValueFnIter_Case1_EpsteinZin (line 111)
        ReturnMatrix=CreateReturnFnMatrix_Case1_Disc(ReturnFn, n_d, n_a, n_z, d_grid, a_grid, z_grid, vfoptions.parallel);

Error in ValueFnIter_Case1 (line 258)
        [V, Policy]=ValueFnIter_Case1_EpsteinZin(V0, n_d,n_a,n_z,d_grid,a_grid,z_grid, pi_z, DiscountFactorParamNames, ReturnFn, vfoptions,Parameters,ReturnFnParamNames);

Error in EpsteinZinPreferences (line 133)
[V, Policy]=ValueFnIter_Case1(n_d,n_a,n_s,d_grid,a_grid,s_grid, pi_s, ReturnFn, Params, DiscountFactorParamNames, [], vfoptions);

Any ideas on what’s happening?

Cheers!

1 Like

Hi @diegobpgomes! I notice that you are using vfoption.parallel=1. If I use this option, I get an error too, even though it is a different one:

struct with fields:

            exoticpreferences: 'EpsteinZin'
            EZpositiveutility: 0
               EZriskaversion: 'phi'
           WarmGlowBequestsFn: @(aprime,sigma,wg,agej,Jr)(agej>=Jr+10)*wg*(aprime^(1-sigma))/(1-sigma)
          survivalprobability: 'sj'
                      verbose: 1
                     parallel: 1
                 returnmatrix: 0
                    lowmemory: 0
                     paroverz: 0
              incrementaltype: 0
                  polindorval: 1
      policy_forceintegertype: 0
                   outputkron: 0
                      dynasty: 0
              experienceasset: 0
                   riskyasset: 0
                residualasset: 0
WarmGlowBequestsFnParamsNames: {'sigma'  'wg'  'agej'  'Jr'}

Error using ValueFnIter_Case1_FHorz_EpsteinZin
Epstein-Zin currently only implemented for Parallel=2 (gpu): request on discourse/forum if you need this

If instead I set vfoptions.parallel=2 (it is the default), the code runs correctly. So it seems that the Epstein-Zin case is implemented only for GPU.

Hi @aledinola! Many thanks for your reply! Unfortunately, I don’t have access to GPU in my work’s computer. That is why I exclusively utilize parallelization among CPUs.

Is there documentation indicating which models only work on GPU and which work on both GPU and CPU?

1 Like

I figured that what works without gpu deserves its own topic as is probably something a bunch of people want to know

Sorry but Epstein-Zin requires gpu.

2 Likes

Howdy,

I finally got access to a machine with GPU and started testing the toolkit again. When running the EpsteinZin example, I get the outcome below, which contains an error in the end. Any ideas?

>> EpsteinZinPreferences
Grid sizes n_k=200, n_l=31, n_z=25, n_sigma=5 

vfoptions = 

  struct with fields:

              exoticpreferences: 'EpsteinZin'
                        EZutils: 0
                 EZoneminusbeta: 1
                 EZriskaversion: 'gamma'
                          EZeis: 'psi'
                        verbose: 1
                     solnmethod: 'purediscretization_refinement'
                       parallel: 2
                   returnmatrix: 2
                      lowmemory: 0
                      tolerance: 1.0000e-09
                        howards: 80
                     maxhowards: 500
                 endogenousexit: 0
                       endotype: 0
                incrementaltype: 0
                    polindorval: 1
        policy_forceintegertype: 0
    piz_strictonrowsaddingtoone: 0
                     outputkron: 0

Creating return fn matrix
Time to create return fn matrix:   1.3517 
Starting Value Function
Error using indexing
Out of memory on device. To view more detail about available memory on
the GPU, use 'gpuDevice()'. If the problem persists, reset the GPU by
calling 'gpuDevice(1)'.

Error in ValueFnIter_Case1_EpsteinZin_Par2_raw (line 25)
temp2(becareful)=ReturnMatrix(becareful).^ezc2; % Otherwise can get things like 0 to negative power equals infinity

Error in ValueFnIter_Case1_EpsteinZin (line 130)
            [VKron, Policy]=ValueFnIter_Case1_EpsteinZin_Par2_raw(V0, n_d,n_a,n_z, pi_z, DiscountFactorParamsVec, ReturnMatrix,vfoptions.howards, vfoptions.maxhowards,vfoptions.tolerance, ezc1,ezc2,ezc3,ezc4,ezc5,ezc6,ezc7);

Error in ValueFnIter_Case1 (line 254)
        [V, Policy]=ValueFnIter_Case1_EpsteinZin(V0, n_d,n_a,n_z,d_grid,a_grid,z_grid, pi_z, DiscountFactorParamNames, ReturnFn, vfoptions,Parameters,ReturnFnParamNames);

Error in EpsteinZinPreferences (line 133)
[V, Policy]=ValueFnIter_Case1(n_d,n_a,n_s,d_grid,a_grid,s_grid, pi_s, ReturnFn, Params, DiscountFactorParamNames, [], vfoptions);
1 Like

Hi @diegobpgomes! I think the error is because you don’t have enough RAM on your gpu… try setting vfoptions.lowmemory=1 or 2 (the default is 0) and see if it runs.
Another option is to reduce the number of points on the grids; by doing so you will get a less accurate solution though

1 Like

Thank you!

What does the lowmemory option actually do?

When I set vfoptions.lowmemory = 1, I get I different error:

>> EpsteinZinPreferences
Grid sizes n_k=200, n_l=31, n_z=25, n_sigma=5 

vfoptions = 

  struct with fields:

              exoticpreferences: 'EpsteinZin'
                        EZutils: 0
                 EZoneminusbeta: 1
                      lowmemory: 1
                 EZriskaversion: 'gamma'
                          EZeis: 'psi'
                        verbose: 1
                     solnmethod: 'purediscretization_refinement'
                       parallel: 2
                   returnmatrix: 2
                      tolerance: 1.0000e-09
                        howards: 80
                     maxhowards: 500
                 endogenousexit: 0
                       endotype: 0
                incrementaltype: 0
                    polindorval: 1
        policy_forceintegertype: 0
    piz_strictonrowsaddingtoone: 0
                     outputkron: 0

Starting Value Function
Unrecognized function or variable 'V0Kron'.

Error in ValueFnIter_Case1_EpsteinZin (line 145)
            [VKron, Policy]=ValueFnIter_Case1_EpsteinZin_LowMem_Par2_raw(V0Kron, n_d,n_a,n_z, d_grid, a_grid, z_grid, pi_z, DiscountFactorParamsVec, ReturnFn, ReturnFnParamsVec,vfoptions.howards, vfoptions.maxhowards,vfoptions.tolerance, ezc1,ezc2,ezc3,ezc4,ezc5,ezc6,ezc7);

Error in ValueFnIter_Case1 (line 254)
        [V, Policy]=ValueFnIter_Case1_EpsteinZin(V0, n_d,n_a,n_z,d_grid,a_grid,z_grid, pi_z, DiscountFactorParamNames, ReturnFn, vfoptions,Parameters,ReturnFnParamNames);

Error in EpsteinZinPreferences (line 136)
[V, Policy]=ValueFnIter_Case1(n_d,n_a,n_s,d_grid,a_grid,s_grid, pi_s, ReturnFn, Params, DiscountFactorParamNames, [], vfoptions);

When I set vfoptions.lowmemory = 2, I get the following (and different) error:

>> EpsteinZinPreferences
Grid sizes n_k=200, n_l=31, n_z=25, n_sigma=5 

vfoptions = 

  struct with fields:

              exoticpreferences: 'EpsteinZin'
                        EZutils: 0
                 EZoneminusbeta: 1
                      lowmemory: 2
                 EZriskaversion: 'gamma'
                          EZeis: 'psi'
                        verbose: 1
                     solnmethod: 'purediscretization_refinement'
                       parallel: 2
                   returnmatrix: 2
                      tolerance: 1.0000e-09
                        howards: 80
                     maxhowards: 500
                 endogenousexit: 0
                       endotype: 0
                incrementaltype: 0
                    polindorval: 1
        policy_forceintegertype: 0
    piz_strictonrowsaddingtoone: 0
                     outputkron: 0

Time to solve for Value Fn and Policy: 123.3455 
Transforming Value Fn and Optimal Policy matrices back out of Kronecker Form
Unrecognized function or variable 'VKron'.

Error in ValueFnIter_Case1_EpsteinZin (line 159)
V=reshape(VKron,[n_a,n_z]);

Error in ValueFnIter_Case1 (line 254)
        [V, Policy]=ValueFnIter_Case1_EpsteinZin(V0, n_d,n_a,n_z,d_grid,a_grid,z_grid, pi_z, DiscountFactorParamNames, ReturnFn, vfoptions,Parameters,ReturnFnParamNames);

Error in EpsteinZinPreferences (line 136)
[V, Policy]=ValueFnIter_Case1(n_d,n_a,n_s,d_grid,a_grid,s_grid, pi_s, ReturnFn, Params, DiscountFactorParamNames, [], vfoptions);
1 Like

The lowmemory option reduces the memory requirements of the code, so that it can run also on GPU with a smaller RAM. The downside is that it will be slower.
I don’t know about these new error messages that you’ve got :frowning:

Fixed, Sorry! (update to latest github version)

VFI Toolkit tries to take full advantage of parallelization, by creating big matrices and avoiding loops (which is the default of vfoptions.lowmemory=0). Setting vfoptions.lowmemory=1 uses more loops, smaller matrices, which means slower runtimes but less memory use (=2 is even more loops, less memory, slower).

On my desktop the value fn for this specific example takes ~5 seconds with vfoptions.lowmemory=1, vs ~3 seconds if using the default of vfoptions.lowmemory=0. Exact speed penalty varies depending on the setting.

1 Like

Thank you!

It worked with vfoptions.lowmemory = 1. However, I still get an error with vfoptions.lowmemory = 2:

>> EpsteinZinPreferences
Grid sizes n_k=200, n_l=31, n_z=25, n_sigma=5 

vfoptions = 

  struct with fields:

              exoticpreferences: 'EpsteinZin'
                        EZutils: 0
                 EZoneminusbeta: 1
                      lowmemory: 2
                 EZriskaversion: 'gamma'
                          EZeis: 'psi'
                        verbose: 1
                     solnmethod: 'purediscretization_refinement'
                       parallel: 2
                   returnmatrix: 2
                      tolerance: 1.0000e-09
                        howards: 80
                     maxhowards: 500
                 endogenousexit: 0
                       endotype: 0
                incrementaltype: 0
                    polindorval: 1
        policy_forceintegertype: 0
    piz_strictonrowsaddingtoone: 0
                     outputkron: 0

Error using toc
You must call TIC without an output argument before calling TOC
without an input argument.

Error in ValueFnIter_Case1_EpsteinZin (line 152)
    time=toc;

Error in ValueFnIter_Case1 (line 254)
        [V, Policy]=ValueFnIter_Case1_EpsteinZin(V0, n_d,n_a,n_z,d_grid,a_grid,z_grid, pi_z, DiscountFactorParamNames, ReturnFn, vfoptions,Parameters,ReturnFnParamNames);

Error in EpsteinZinPreferences (line 136)
[V, Policy]=ValueFnIter_Case1(n_d,n_a,n_s,d_grid,a_grid,s_grid, pi_s, ReturnFn, Params, DiscountFactorParamNames, [], vfoptions);

Interestingly, if I run option 1 first and then option 2, I get a different error for option 2:

>> EpsteinZinPreferences
Grid sizes n_k=200, n_l=31, n_z=25, n_sigma=5 

vfoptions = 

  struct with fields:

              exoticpreferences: 'EpsteinZin'
                        EZutils: 0
                 EZoneminusbeta: 1
                      lowmemory: 2
                 EZriskaversion: 'gamma'
                          EZeis: 'psi'
                        verbose: 1
                     solnmethod: 'purediscretization_refinement'
                       parallel: 2
                   returnmatrix: 2
                      tolerance: 1.0000e-09
                        howards: 80
                     maxhowards: 500
                 endogenousexit: 0
                       endotype: 0
                incrementaltype: 0
                    polindorval: 1
        policy_forceintegertype: 0
    piz_strictonrowsaddingtoone: 0
                     outputkron: 0

Time to solve for Value Fn and Policy:  12.7212 
Transforming Value Fn and Optimal Policy matrices back out of Kronecker Form
Unrecognized function or variable 'VKron'.

Error in ValueFnIter_Case1_EpsteinZin (line 159)
V=reshape(VKron,[n_a,n_z]);

Error in ValueFnIter_Case1 (line 254)
        [V, Policy]=ValueFnIter_Case1_EpsteinZin(V0, n_d,n_a,n_z,d_grid,a_grid,z_grid, pi_z, DiscountFactorParamNames, ReturnFn, vfoptions,Parameters,ReturnFnParamNames);

Error in EpsteinZinPreferences (line 136)
[V, Policy]=ValueFnIter_Case1(n_d,n_a,n_s,d_grid,a_grid,s_grid, pi_s, ReturnFn, Params, DiscountFactorParamNames, [], vfoptions);
1 Like

Heh, there actually is no lowmemory=2 option when using Epstein-Zin preferences in infinite horizon. I have added an error message so that this is clear.

[Depending on context there might be something worth looping, but some things are just silly to loop over as too slow to be usable. Hence lowmemory=2 is not always an option (off the top of my head lowmemory=1 is always there).]

2 Likes