Skip to content

Quick start

This page runs the project's main example, compares the learning economy with the rational expectations (RE) benchmark, and changes one assumption. It assumes the installation is done.

1. Start a session

cd('C:\path\to\iris_toolbox_learning')
setup_paths

2. Run the two scenarios of Application 1

res_re = hetlearn.run(a1_re());      % every agent rational
res    = hetlearn.run(a1_learn());   % RE agents and AR(1) inflation learners, switching shares

Each call reads a scenario file (scenarios/sw07/app1_peak/a1_re.m, a1_learn.m), merges it with the project options, runs the history and the 16-quarter forecast from the 2022Q2 inflation peak, and writes results/a1_re/ and results/a1_learn/. On a warm cache each run takes 10-20 seconds.

The same two runs, logged in results/run_log.csv:

run_applications('app1')

3. Compare the forecasts

T = hetlearn.compare({'a1_re', 'a1_learn'}, {'pinfobs', 'robs'})

T is a table with one row per forecast quarter, the level of each variable in each scenario (pinfobs__a1_re, pinfobs__a1_learn) and the difference from the first scenario (pinfobs__a1_learn_minus_a1_re). Values are in model units: inflation and the policy rate in percent per quarter, so multiplying by 4 gives annual rates.

Averages over the forecast, annualized:

h = qq(2022, 3):qq(2026, 2);
mean(4*res_re.paths.pinfobs(h))     % 2.59
mean(4*res.paths.pinfobs(h))        % 3.45

4. Look at the learners

The learners forecast inflation from a perceived law of motion (PLM), here an AR(1):

L = res.learning.pinf;              % learning series of the inflation PLM
L.beta_pinf(qq(2022, 2))            % perceived AR(1) coefficient at the origin: 1.061
L.n2(qq(2022, 2))                   % learners' share at the end of 2022Q2: 0.591

The learners' share over the history and the forecast:

figure
plot(qq(2018, 1):qq(2026, 2), L.n2)
title('Learners'' share of inflation expectations, end of quarter')

5. Change one assumption

A scenario is a MATLAB function that returns a struct, so it can be changed in memory and run without creating a file:

cfg = a1_learn();
cfg.id = 'a1_learn_chi1';             % results go to results/a1_learn_chi1/
cfg.switching.intensity = 1;          % intensity of choice (baseline 2)
res1 = hetlearn.run(cfg);
T = hetlearn.compare({'a1_learn', 'a1_learn_chi1'}, {'pinfobs'});

The option 'save', false keeps a run out of results/:

res1 = hetlearn.run(cfg, 'save', false);

6. Make it permanent

A scenario saved as a file under scenarios/ (any subfolder) becomes permanent. The file name, the function name and cfg.id should be the same:

function cfg = a1_learn_chi1()
%A1_LEARN_CHI1  Application 1 with a lower intensity of choice.
cfg = a1_learn();
cfg.id = 'a1_learn_chi1';
cfg.title = 'App 1 with chi = 1';
cfg.switching.intensity = 1;
cfg.compare_with = {'a1_learn'};      % also writes compare_a1_learn.csv
end

Then hetlearn.run(a1_learn_chi1()) or run_applications('a1_learn_chi1').

Where next