API Reference¶
Top-level API¶
The top-level namespace of dolo re-exports the model import and
solution routines.
PolicyLinearOperator
¶
Bases: LinearOperator
Linear operator representing dF_2 = \partial F / \partial \varphi.
Acts on policy variations v defined on the continuous state grid
(L @ v)[n] = \sum_k F_{x, k}[n] \cdot v(S_k[n])
where v(S_k[n]) is the interpolation of v at the next-period state S_k[n].
Mirrors Dolo.jl's LL / LinearOperator struct.
Source code in src/dolo/numeric/residuals.py
403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 517 518 519 520 521 522 523 524 525 526 527 528 529 530 531 532 533 534 535 536 537 538 539 540 541 542 543 544 545 546 547 548 549 550 551 552 553 554 555 556 557 558 559 560 561 562 563 564 565 566 567 568 569 570 571 572 573 574 575 576 577 578 579 580 581 582 583 584 585 586 587 588 589 590 591 592 593 594 595 596 597 598 599 600 601 602 603 604 605 606 607 608 609 610 611 612 613 614 615 616 617 618 619 620 621 622 623 624 625 626 627 628 629 630 631 632 633 634 635 636 637 638 639 640 641 642 643 644 645 646 647 648 649 650 651 652 653 654 655 656 657 658 659 660 661 662 663 664 665 666 667 668 669 670 671 | |
apply(v)
¶
Apply linear operator to a policy variation v on the grid.
Source code in src/dolo/numeric/residuals.py
483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 517 518 519 520 521 522 523 524 525 526 527 528 529 530 531 532 533 534 535 536 537 538 539 540 541 542 543 544 545 546 547 548 549 550 551 552 553 554 555 556 557 558 559 560 561 562 563 564 565 566 567 568 569 | |
as_matrix()
¶
Compute explicit (dim, dim) dense matrix representation.
Source code in src/dolo/numeric/residuals.py
preconditioned(J)
¶
Return preconditioned operator J^{-1} L, where J = dF_1 is block-diagonal.
Source code in src/dolo/numeric/residuals.py
solve(b, linsolve='neumann', tol=1e-08, maxit=50, verbose=False)
¶
Solve (I - L) x = b using Neumann series or GMRES.
Source code in src/dolo/numeric/residuals.py
F(model, *args, engine='auto', backend=None, interp_method='cubic', device=None, **kwargs)
¶
Evaluate dynamic Euler equation residuals across grid points or at a single point.
Usage¶
-
Grid-level evaluation (mirroring Julia Dolo.jl): F(model, controls, dr=None, engine="auto") F(model, x0, x0) # dr initialized to initial guess x0 F(model, x0) # dr defaults to x0
-
Point-level evaluation: F(model, s, x, dr)
Parameters¶
model : Model, ModelV2, or DiscretizedModel
The economic model.
controls : GArray, np.ndarray, or jnp.ndarray
Control policy values across the grid (or point state s if point-call).
dr : DecisionRule, GArray, or array, optional
Decision rule (policy) to evaluate next-period controls φ(S).
If omitted or equal to controls, fits φ on controls.
engine / backend : str ("auto", "jax", "gpu", "cpu", "vectorized")
Computational backend to execute the residual evaluation.
interp_method : str ("cubic" or "linear")
Interpolation method for decision rule φ.
device : jax.Device, optional
Target JAX device (e.g. jax.devices('gpu')[0]).
Source code in src/dolo/numeric/residuals.py
68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 | |
F_and_dF_1(model, *args, engine='auto', backend=None, interp_method='cubic', diff_mode='fwd', device=None, **kwargs)
¶
Simultaneously evaluate residuals and Jacobian w.r.t controls in a single pass.
Returns¶
(res, dres) : Tuple of residuals and Jacobian tensor
Source code in src/dolo/numeric/residuals.py
321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 | |
colored(text, color=None, on_color=None, attrs=None)
¶
Colorize text.
Available text colors
red, green, yellow, blue, magenta, cyan, white.
Available text highlights
on_red, on_green, on_yellow, on_blue, on_magenta, on_cyan, on_white.
Available attributes
bold, dark, underline, blink, reverse, concealed.
Example
colored('Hello, World!', 'red', 'on_grey', ['blue', 'blink']) colored('Hello, World!', 'green')
Source code in src/dolo/misc/termcolor.py
dF_1(model, *args, engine='auto', backend=None, interp_method='cubic', diff_mode='fwd', device=None, **kwargs)
¶
Evaluate Jacobian of dynamic Euler residuals w.r.t controls across grid points.
Mirrors Julia Dolo.jl: dF_1(model, controls, φ=None)
Parameters¶
model : Model, ModelV2, or DiscretizedModel
The economic model.
controls : GArray, np.ndarray, or jnp.ndarray
Control policy values across the grid.
dr : DecisionRule, GArray, or array, optional
Decision rule (policy). Defaults to controls if omitted.
engine / backend : str ("auto", "jax", "gpu", "cpu", "vectorized")
Backend engine. JAX computes exact analytical autodiff derivatives.
interp_method : str ("cubic" or "linear")
Interpolation method.
diff_mode : str ("fwd" or "rev")
Autodiff mode for JAX ('fwd' for jacfwd, 'rev' for jacrev).
Source code in src/dolo/numeric/residuals.py
216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 | |
dF_2(model, *args, engine='auto', backend=None, interp_method='cubic', device=None, **kwargs)
¶
Evaluate derivative of dynamic Euler residuals w.r.t the decision rule φ.
Mirrors Julia Dolo.jl: dF_2(model, s, x, φ) and dF_2(model, controls, φ=None)
Usage¶
-
Grid-level evaluation: L = dF_2(model, controls, dr=None, engine="auto") L @ v # apply operator to variation v L.as_matrix() # explicit matrix
-
Point-level evaluation: branches = dF_2(model, s, x, dr) # returns tuple of (F_x, S) for each shock branch k
Parameters¶
model : Model, ModelV2, or DiscretizedModel
The economic model.
controls : GArray, np.ndarray, or jnp.ndarray
Control policy values across the grid (or point state s if point call).
dr : DecisionRule, GArray, or array, optional
Decision rule (policy). Defaults to controls if omitted.
engine / backend : str ("auto", "jax", "gpu", "cpu", "vectorized")
Backend engine.
interp_method : str ("cubic" or "linear")
Interpolation method for decision rule φ.
device : jax.Device, optional
Target JAX device (e.g. jax.devices('gpu')[0]).
Source code in src/dolo/numeric/residuals.py
674 675 676 677 678 679 680 681 682 683 684 685 686 687 688 689 690 691 692 693 694 695 696 697 698 699 700 701 702 703 704 705 706 707 708 709 710 711 712 713 714 715 716 717 718 719 720 721 722 723 724 725 726 727 728 729 730 731 732 733 734 735 736 737 738 739 740 741 742 743 744 745 746 747 748 749 750 751 752 753 754 755 756 757 758 759 760 761 762 763 764 765 766 767 768 769 770 771 772 773 774 775 776 777 778 779 780 781 782 783 784 785 786 787 788 789 790 791 792 793 794 795 796 797 798 799 800 801 802 803 804 805 806 807 808 809 810 811 812 813 814 815 816 817 818 819 820 821 822 823 824 825 826 827 828 829 830 831 832 833 834 835 836 837 838 839 840 841 842 843 844 845 846 847 848 849 850 851 852 853 854 855 856 857 858 859 860 861 862 863 864 865 866 867 868 869 870 871 872 873 874 875 876 877 878 879 880 881 882 883 884 885 886 887 888 889 890 891 892 893 894 895 896 897 898 899 900 901 902 903 904 905 906 907 908 909 910 911 912 913 914 915 916 917 918 919 920 921 922 923 | |
deterministic_solve(model, *, verbose=True, ignore_constraints=False, exogenous=None, s0=None, m0=None, T=100, maxit=100, initial_guess=None, solver='ncpsolve', keep_steady_state=False, s1=None, shocks=None, tol=1e-06)
¶
Computes a perfect foresight simulation using a stacked-time algorithm.
Typical simulation exercises are:
- start from an out-of-equilibrium exogenous and/or endogenous state: specify s0 and or m0. Missing values are taken from the calibration (model.calibration).
- specify an exogenous path for shocks exogenous. Initial exogenous state m0 is then first value of exogenous values. Economy is supposed to have been at the equilibrium for \(t<0\), which pins
down initial endogenous state s0. x0 is a jump variable.
If \(s0\) is not specified it is then set equal to the steady-state consistent with the first value
The initial state is specified either by providing a series of exogenous shocks and assuming the model is initially in equilibrium with the first value of the shock, or by specifying an initial value for the states.
Parameters¶
model : Model
Model to be solved
exogenous : array-like, dict, or pandas.DataFrame
A specification for the path of exogenous variables (aka shocks). Can be any of the
following (note by "declaration order" below we mean the order
of model.symbols["exogenous"]):
- A 1d numpy array-like specifying a time series for a single
exogenous variable, or all exogenous variables stacked into a single array.
- A 2d numpy array where each column specifies the time series
for one of the shocks in declaration order. This must be an
`N` by number of shocks 2d array.
- A dict where keys are strings found in
`model.symbols["exogenous"]` and values are a time series of
values for that shock. For exogenous variables that do not appear in
this dict, the shock is set to the calibrated value. Note
that this interface is the most flexible as it allows the user
to pass values for only a subset of the model shocks and it
allows the passed time series to be of different lengths.
- A DataFrame where columns map shock names into time series.
The same assumptions and behavior that are used in the dict
case apply here
If nothing is given here, `exogenous` is set equal to the
calibrated values found in `model.calibration["exogenous"]` for
all periods.
If the length of any time-series in shocks is less than `T`
(see below) it is assumed that that particular shock will
remain at the final given value for the duration of the
simulation.
s0 : None or ndarray or dict
If vector with the value of initial states
If an exogenous timeseries is given for exogenous shocks, s0 will be computed as the steady-state value that is consistent with its first value.
int
horizon for the perfect foresight simulation
maxit : int maximum number of iteration for the nonlinear solver verbose : boolean if True, the solver displays iterations tol : float stopping criterium for the nonlinear solver ignore_constraints : bool if True, complementarity constraints are ignored. keep_steady_state : bool if True, initial steady-states and steady-controls are appended to the simulation with date -1. Returns
pandas dataframe a dataframe with T+1 observations of the model variables along the simulation (states, controls, auxiliaries). The simulation should return to a steady-state consistent with the last specified value of the exogenous shocks.
Source code in src/dolo/algos/perfect_foresight.py
53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 | |
evaluate_policy(model, mdr, tol=1e-08, maxit=2000, grid={}, verbose=True, dr0=None, hook=None, integration_orders=None, details=False, interp_method='cubic')
¶
Compute value function corresponding to policy dr
Parameters:¶
model
"dtcscc" model. Must contain a 'value' function.
mdr
decision rule to evaluate
Returns:¶
decision rule
value function (a function of the space similar to a decision rule object)
Source code in src/dolo/algos/value_iteration.py
257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 | |
newton(model, *, engine='auto', backend=None, device=None, dr0=None, tol_eps=1e-08, tol_eta=1e-06, maxit=30, linsolve='gmres', linesearch='backtracking', interpolation='cubic', verbose=True, details=True, trace=False, dprocess=None, ignore_constraints=False, compute_radius=False, **kwargs)
¶
Finds a global solution for model using full-system Newton-Krylov solver.
Parameters¶
model : Model model to be solved dr0 : DecisionRule, optional initial guess for the decision rule tol_eps : float (1e-8) tolerance on Euler equation residuals ||F(x)|| tol_eta : float (1e-6) tolerance on policy update step ||x_{k+1} - x_k|| maxit : int (30) maximum number of outer Newton iterations linsolve : str or dict ("gmres") linear solver for the preconditioned system (I - L) dx = r. Options: "gmres", "neumann", or a dict(method=..., maxit=..., tol=...) linesearch : str or dict ("backtracking") step size stabilization. Options: "backtracking", "golden_section", False, None, or a dict(method=..., max_backsteps=...) interpolation : str ("cubic") interpolation method ("cubic" or "linear") verbose : bool (True) display iteration progress trace : bool (False) record intermediate decision rules
Source code in src/dolo/algos/newton.py
269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 517 518 519 520 521 522 523 524 525 526 527 528 529 530 531 532 533 534 535 536 537 538 539 540 541 542 543 544 545 546 547 548 549 550 551 552 553 554 555 556 557 558 559 560 561 562 563 564 565 566 567 568 569 570 571 572 573 574 575 576 577 578 579 580 581 582 583 584 585 586 587 588 589 590 591 592 593 594 595 596 597 598 599 600 601 602 603 604 605 606 607 608 609 610 611 612 613 614 615 616 617 618 619 620 621 622 623 624 625 626 627 628 629 630 631 632 633 634 635 636 637 638 639 640 641 642 643 644 645 646 647 648 649 650 651 652 653 654 655 656 657 658 659 660 661 662 663 664 665 666 667 668 669 670 671 672 673 674 675 676 677 678 679 680 681 682 683 684 685 686 687 688 689 690 691 692 693 694 695 696 697 698 699 700 701 702 703 704 705 706 707 708 709 710 711 712 713 714 715 716 717 718 719 720 721 722 723 724 725 726 727 728 729 730 731 732 733 734 735 736 737 738 739 740 741 742 743 744 745 746 747 748 749 750 751 752 753 754 755 756 757 758 759 760 761 762 763 764 765 766 767 768 769 770 771 772 773 774 775 776 777 778 779 780 781 782 783 784 785 786 787 788 789 790 791 792 793 794 795 796 797 798 799 800 801 802 803 804 805 806 807 808 809 810 811 812 813 814 815 816 817 818 819 820 821 822 823 824 825 826 827 828 829 830 831 832 833 834 835 836 837 838 839 840 841 842 843 844 845 846 847 848 849 850 851 852 853 854 | |
perturb(model, *, details=True, verbose=True, steady_state=None, eigmax=1.0 - 1e-06, solve_steady_state=False, order=1)
¶
Compute first order approximation of optimal controls
Parameters:¶
NumericModel
Model to be solved
boolean
If True: displays number of contracting eigenvalues
ndarray
Use supplied steady-state value to compute the approximation. The routine doesn't check whether it is really a solution or not.
boolean
Use nonlinear solver to find the steady-state
{1}
Approximation order. (Currently, only first order is supported).
Returns:¶
TaylorExpansion
Decision Rule for the optimal controls around the steady-state.
Source code in src/dolo/algos/perturbation.py
196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 | |
simulate(model, dr, *, process=None, N=1, T=40, s0=None, i0=None, m0=None, driving_process=None, seed=42, stochastic=True)
¶
Simulate a model using the specified decision rule.
Parameters¶
model: Model
dr: decision rule
process:
ndarray
initial state where all simulations start
ndarray
realization of exogenous driving process (drawn randomly if None)
int
number of simulations
T: int horizon for the simulations seed: int used to initialize the random number generator. Use it to replicate exact same results among simulations discard: boolean (False) if True, then all simulations containing at least one non finite value are discarded
Returns¶
xarray.DataArray:
returns a T x N x n_v array where n_v
is the number of variables.
Source code in src/dolo/algos/simulations.py
61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 | |
time_iteration(model, *, engine='auto', backend=None, dr0=None, tol_eps=1e-08, tol_eta=1e-06, maxit=500, inner=None, accelerate=False, interpolation='cubic', verbose=True, details=True, trace=False, ignore_constraints=False, hook=None, dprocess=None, **kwargs)
¶
Finds a global solution for model using backward time-iteration.
Parameters¶
model : Model, ModelV2, or DiscretizedModel model to be solved engine / backend : str ("auto", "jax", "gpu", "cpu", "vectorized") computational engine for residual and Jacobian evaluations dr0 : DecisionRule, optional initial guess for the decision rule tol_eps : float (1e-8) tolerance on Euler equation residuals ||F(x)|| tol_eta : float (1e-6) tolerance on policy update step ||x_{k+1} - x_k|| maxit : int (500) maximum number of outer time-iteration loops inner : dict, optional options for the inner pointwise Euler solver: dict(maxit=10, max_backsteps=10, tol=1e-8) accelerate : bool or dict (False) if True or a dict, accelerates policy iterations using a preconditioned Neumann or GMRES step on (I - L) dx = (x_1 - x_0) after a warm-up phase. e.g. dict(wait=10, linsolve="neumann", maxit=50, safeguarded=False) interpolation : str ("cubic") interpolation method ("cubic" or "linear") verbose : bool (True) display iteration progress trace : bool (False) record intermediate decision rules
Source code in src/dolo/algos/time_iteration.py
68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 | |
value_iteration(model, *, verbose=False, details=True, tol=1e-06, maxit=500, maxit_howard=20)
¶
Solve for the value function and associated Markov decision rule by iterating over the value function.
Parameters:¶
model : model to be solved dr : decision rule to evaluate
Returns:¶
mdr : Markov decision rule The solved decision rule/policy function mdrv: decision rule The solved value function
Source code in src/dolo/algos/value_iteration.py
34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 | |
Model¶
Model objects, produced by yaml_import, are the central piece of the
package: they hold the parsed specification, the calibration, and the
compiled functions of the model.
Model
¶
Bases: SymbolicModel
Model Object
Source code in src/dolo/compiler/model.py
531 532 533 534 535 536 537 538 539 540 541 542 543 544 545 546 547 548 549 550 551 552 553 554 555 556 557 558 559 560 561 562 563 564 565 566 567 568 569 570 571 572 573 574 575 576 577 578 579 580 581 582 583 584 585 586 587 588 589 590 591 592 593 594 595 596 597 598 599 600 601 602 603 604 605 606 607 608 609 610 611 612 613 614 615 616 617 618 619 620 621 622 623 624 625 626 627 628 629 630 631 632 633 634 635 636 637 638 639 640 641 642 643 644 645 646 647 648 649 650 651 652 653 654 655 656 657 658 659 660 661 662 663 664 665 666 667 668 669 670 671 672 673 674 675 676 677 678 679 680 681 682 683 684 685 686 687 688 689 690 691 692 693 694 695 696 697 698 699 700 701 702 703 704 705 706 707 708 709 710 711 712 713 714 715 716 717 718 719 720 721 722 723 724 725 726 727 728 729 730 731 732 733 734 735 736 737 738 739 740 741 742 743 744 745 746 747 748 749 750 751 752 753 754 755 756 757 758 759 760 761 762 763 764 765 766 767 768 769 770 771 772 773 774 775 776 777 778 779 780 781 782 783 784 785 786 787 788 789 790 791 792 793 794 795 796 797 798 799 800 801 802 803 804 805 806 807 808 809 810 811 812 813 814 815 816 817 818 819 820 821 822 823 824 825 826 827 | |
recalibrate(*pargs, **kwargs)
¶
Return a new, independent model with the given calibration overrides.
Models are immutable (dyno semantics): the calibration of self
is left untouched. Assign the returned model instead of mutating
in place::
model = model.recalibrate(delta=0.5)
Source code in src/dolo/compiler/model.py
decode_complementarity(comp, control)
¶
comp can be either:¶
- None
- "a<=expr" where a is a controls
- "expr<=a" where a is a control
- "expr1<=a<=expr2"
Source code in src/dolo/compiler/model.py
Importing models¶
dyno_import(fname, filename=None, check=True)
¶
Import a .dyno model file using the dynspec-based importer (ModelV2).
Source code in src/dolo/compiler/model_import.py
yaml_import_v2(fname, filename=None, check=True)
¶
Import a dolo YAML model using the dynspec-based importer (ModelV2).
Source code in src/dolo/compiler/model_import.py
Steady state and solution algorithms¶
Time Iteration Algorithm
euler_residuals_tau(dmodel, controls, dr)
¶
Universal Euler residuals written entirely in terms of GArray and Tau.
Source code in src/dolo/algos/time_iteration.py
residuals_simple(f, g, s, x, dr, dprocess, parms)
¶
Legacy residuals computation retained for backward compatibility.
Source code in src/dolo/algos/time_iteration.py
time_iteration(model, *, engine='auto', backend=None, dr0=None, tol_eps=1e-08, tol_eta=1e-06, maxit=500, inner=None, accelerate=False, interpolation='cubic', verbose=True, details=True, trace=False, ignore_constraints=False, hook=None, dprocess=None, **kwargs)
¶
Finds a global solution for model using backward time-iteration.
Parameters¶
model : Model, ModelV2, or DiscretizedModel model to be solved engine / backend : str ("auto", "jax", "gpu", "cpu", "vectorized") computational engine for residual and Jacobian evaluations dr0 : DecisionRule, optional initial guess for the decision rule tol_eps : float (1e-8) tolerance on Euler equation residuals ||F(x)|| tol_eta : float (1e-6) tolerance on policy update step ||x_{k+1} - x_k|| maxit : int (500) maximum number of outer time-iteration loops inner : dict, optional options for the inner pointwise Euler solver: dict(maxit=10, max_backsteps=10, tol=1e-8) accelerate : bool or dict (False) if True or a dict, accelerates policy iterations using a preconditioned Neumann or GMRES step on (I - L) dx = (x_1 - x_0) after a warm-up phase. e.g. dict(wait=10, linsolve="neumann", maxit=50, safeguarded=False) interpolation : str ("cubic") interpolation method ("cubic" or "linear") verbose : bool (True) display iteration progress trace : bool (False) record intermediate decision rules
Source code in src/dolo/algos/time_iteration.py
68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 | |
Newton-Krylov Policy Solver
Operator
¶
Bases: LinearOperator
Special Linear Operator representing the policy Jacobian L = -F_1^{-1} F_2
Source code in src/dolo/algos/newton.py
SparseTensor
¶
Source code in src/dolo/algos/bruteforce_lib.py
__init__(indices, values, shape)
¶
indices: N x d integers values: N floats
Source code in src/dolo/algos/bruteforce_lib.py
golden_section_search(f_eval, alpha_min=0.0, alpha_max=1.0, maxiter=8, tol=0.0001)
¶
Golden-section line search for step size alpha in [alpha_min, alpha_max].
Source code in src/dolo/algos/newton.py
invert_jac(res, dres, jres, fut_S, dumdr, tol=1e-10, maxit=1000, verbose=False)
¶
Solve (F_1 + F_2) tot = res via preconditioned Neumann series (I - L) tot = F_1^{-1} res.
Source code in src/dolo/algos/newton.py
neumann_solve(ddx, jres, fut_S, dumdr, tol=1e-08, maxit=50, verbose=False)
¶
Solve (I - L) tot = ddx using Neumann series expansion: sum_{k=0}^maxit L^k ddx.
Source code in src/dolo/algos/newton.py
newton(model, *, engine='auto', backend=None, device=None, dr0=None, tol_eps=1e-08, tol_eta=1e-06, maxit=30, linsolve='gmres', linesearch='backtracking', interpolation='cubic', verbose=True, details=True, trace=False, dprocess=None, ignore_constraints=False, compute_radius=False, **kwargs)
¶
Finds a global solution for model using full-system Newton-Krylov solver.
Parameters¶
model : Model model to be solved dr0 : DecisionRule, optional initial guess for the decision rule tol_eps : float (1e-8) tolerance on Euler equation residuals ||F(x)|| tol_eta : float (1e-6) tolerance on policy update step ||x_{k+1} - x_k|| maxit : int (30) maximum number of outer Newton iterations linsolve : str or dict ("gmres") linear solver for the preconditioned system (I - L) dx = r. Options: "gmres", "neumann", or a dict(method=..., maxit=..., tol=...) linesearch : str or dict ("backtracking") step size stabilization. Options: "backtracking", "golden_section", False, None, or a dict(method=..., max_backsteps=...) interpolation : str ("cubic") interpolation method ("cubic" or "linear") verbose : bool (True) display iteration progress trace : bool (False) record intermediate decision rules
Source code in src/dolo/algos/newton.py
269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 517 518 519 520 521 522 523 524 525 526 527 528 529 530 531 532 533 534 535 536 537 538 539 540 541 542 543 544 545 546 547 548 549 550 551 552 553 554 555 556 557 558 559 560 561 562 563 564 565 566 567 568 569 570 571 572 573 574 575 576 577 578 579 580 581 582 583 584 585 586 587 588 589 590 591 592 593 594 595 596 597 598 599 600 601 602 603 604 605 606 607 608 609 610 611 612 613 614 615 616 617 618 619 620 621 622 623 624 625 626 627 628 629 630 631 632 633 634 635 636 637 638 639 640 641 642 643 644 645 646 647 648 649 650 651 652 653 654 655 656 657 658 659 660 661 662 663 664 665 666 667 668 669 670 671 672 673 674 675 676 677 678 679 680 681 682 683 684 685 686 687 688 689 690 691 692 693 694 695 696 697 698 699 700 701 702 703 704 705 706 707 708 709 710 711 712 713 714 715 716 717 718 719 720 721 722 723 724 725 726 727 728 729 730 731 732 733 734 735 736 737 738 739 740 741 742 743 744 745 746 747 748 749 750 751 752 753 754 755 756 757 758 759 760 761 762 763 764 765 766 767 768 769 770 771 772 773 774 775 776 777 778 779 780 781 782 783 784 785 786 787 788 789 790 791 792 793 794 795 796 797 798 799 800 801 802 803 804 805 806 807 808 809 810 811 812 813 814 815 816 817 818 819 820 821 822 823 824 825 826 827 828 829 830 831 832 833 834 835 836 837 838 839 840 841 842 843 844 845 846 847 848 849 850 851 852 853 854 | |
qzordered(A, B, crit=1.0)
¶
Eigenvalues bigger than crit are sorted in the top-left.
Source code in src/dolo/numeric/extern/qz.py
Numeric Core Abstractions¶
The numeric core provides the grid, transition kernel, and discrete field abstractions:
DiscretizedModel: The primary representation of a discretized economic model.
Following Dolo.jl: A DiscretizedModel bundles: - The continuous/symbolic Model - The spatial Grid - The transition operator Tau - Methods for initial guess, bounds, arbitrage, and transition matrix generation.
DiscretizedModel
¶
Discretized economic model.
Encapsulates:
- model: Symbolic Model / ModelV2
- grid: Spatial Grid (ProductGrid or CartesianGrid)
- tau: Tau transition operator
- dprocess: Underlying discretized process
Source code in src/dolo/numeric/discretized_model.py
22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 | |
arbitrage(m, s, x, M, S, X)
¶
Arbitrage equation evaluation wrapper.
Source code in src/dolo/numeric/discretized_model.py
decision_rule(values=None, interp_method='cubic')
¶
Create a DecisionRule bound to this discretized model.
Source code in src/dolo/numeric/discretized_model.py
ergodic_distribution(controls)
¶
Compute the ergodic stationary distribution on the grid nodes.
Parameters¶
controls : GArray Policy controls defined on the grid.
Returns¶
mu : GArray Stationary probability distribution across all grid nodes.
Source code in src/dolo/numeric/discretized_model.py
initial_guess()
¶
Initial GArray of controls from model calibration.
Source code in src/dolo/numeric/discretized_model.py
lower_bounds()
¶
Lower bounds on controls as GArray, if specified.
Source code in src/dolo/numeric/discretized_model.py
regimes()
¶
Yields (regime_index, m_value, endo_nodes) for each discrete regime.
Source code in src/dolo/numeric/discretized_model.py
transition_matrix(controls)
¶
Compute the full Markov transition matrix P on the grid nodes using tau_fit.
Parameters¶
controls : GArray Policy controls defined on the grid.
Returns¶
P : np.ndarray, shape (N_total, N_total) Stochastic matrix where P[i, j] is the transition probability from node i to node j.
Source code in src/dolo/numeric/discretized_model.py
upper_bounds()
¶
Upper bounds on controls as GArray, if specified.
Source code in src/dolo/numeric/discretized_model.py
GArray and QP abstractions for dolo.py.
Following Dolo.jl: - QP: Quasi-Point separating discrete grid locators from continuous economic coordinates. - SliceQP: A batch/slice of state points for an entire continuous sub-grid. - GArray: A discrete field bundling a Grid with underlying Data, supporting both geometric indexing and a flat 1D view for numerical solvers.
GArray
¶
Represents a discrete field of values living on a Grid.
Supports: - Geometric indexing: garray[loc] accessing a node or slice. - Duality: flat 1D view via ravel() / unravel() for solvers. - Standard array arithmetic and norm.
Source code in src/dolo/numeric/garray.py
101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 | |
norm()
¶
ones_like(other)
classmethod
¶
Create a ones GArray matching the grid and shape of another GArray.
ravel()
¶
unravel(flat_data)
¶
zeros(grid, n_vars, n_regimes=None)
classmethod
¶
Create a zero GArray conforming to grid structure.
Source code in src/dolo/numeric/garray.py
zeros_like(other)
classmethod
¶
Create a zero GArray matching the grid and shape of another GArray.
QualifiedBatch
dataclass
¶
A batch/slice of qualified state points for an entire continuous sub-grid.
Attributes¶
loc : Any Target discrete regime index / locator (or None for pure continuous models). exo : np.ndarray Exogenous state values for this branch, shape (N, n_m) or (n_m,). endo : np.ndarray Endogenous state matrix, shape (N, n_s).
Source code in src/dolo/numeric/garray.py
QualifiedPoint
dataclass
¶
A point in a mathematical space qualified with locator context and evaluated values.
A QualifiedPoint bundles:
- loc (Locator / Address): How the point is addressed or indexed in the
computational domain. This can be discrete (e.g. a regime index i or grid
coordinate (i, j) for table lookups) or continuous / differentiable
(e.g. normalized coordinates for spline evaluation).
- val (Values / Payload): The evaluated economic coordinates and derived quantities
(e.g. state vector [z, k], coordinate products, or precomputed basis features)
passed to economic equations (arbitrage, transition, utility).
Attributes¶
loc : Any Computational locator / index. val : np.ndarray Evaluated economic coordinates / values.
Source code in src/dolo/numeric/garray.py
Tau transition operator and trembling hand grid projection.
Following Dolo.jl: - Tau: Generates the conditional transition distribution {(w_k, S_k)} over next states. - trembling_hand: Multilinear grid projector mapping continuous next states onto grid nodes. - tau_fit: Transition distribution projected onto discrete grid vertices.
Tau
¶
The Tau transition operator.
Encapsulates the model's exogenous stochastic process and endogenous law of motion into a single conditional distribution operator: (s, x) -> {(w_k, S_k)}
Source code in src/dolo/numeric/tau.py
97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 | |
point_transitions(s, x)
¶
Point-level transition (pure Julia-style).
Given a single state point QP(loc, val) and control vector x, yields (prob, QP(loc_next, val_next)).
Source code in src/dolo/numeric/tau.py
slice_transitions(i_m, m_val, s_endo, xm)
¶
Slice-level transition: vectorized across all N points of continuous grid.
Yields (prob, SliceQP) where SliceQP contains: - loc: target discrete regime index - exo: next exogenous shock vector - endo: next endogenous state matrix (N, n_s)
Source code in src/dolo/numeric/tau.py
tau_fit(i_m, m_val, s_endo, xm, endo_grid)
¶
Projected transitions on the grid vertices via trembling hand.
For each shock branch and each multilinear vertex corner, yields: (target_regime_j, shock_prob, corner_weights, corner_grid_indices) where: - corner_weights : np.ndarray of shape (N,) - corner_grid_indices : np.ndarray of shape (N,) on endo_grid
Source code in src/dolo/numeric/tau.py
euler_residuals_tau(dmodel, controls, dr)
¶
Universal Euler residuals written entirely in terms of GArray and Tau.
Source code in src/dolo/numeric/tau.py
trembling_hand(grid, points)
¶
Multilinear projection of continuous points onto Cartesian grid vertices.
Parameters¶
grid : UniformCartesianGrid
The target Cartesian grid with attributes min, max, n.
points : np.ndarray, shape (N, d)
Continuous points to project onto the grid.
Returns¶
List of (weights, indices) tuples for each of the 2^d vertices: - weights : np.ndarray, shape (N,) - indices : np.ndarray, shape (N,) - linear indices on the Cartesian grid.
Source code in src/dolo/numeric/tau.py
trembling_hand_1d(min_val, max_val, n_points, points_1d)
¶
1D trembling-hand multilinear decomposition.
For an array of values points_1d, finds the two enclosing grid vertices
i0, i1 and their linear weights w0 = 1 - lam, w1 = lam.
Returns¶
i0 : np.ndarray (int) Left vertex index (0 to n_points - 2). i1 : np.ndarray (int) Right vertex index (1 to n_points - 1). w0 : np.ndarray (float) Weight for left vertex. w1 : np.ndarray (float) Weight for right vertex.
Source code in src/dolo/numeric/tau.py
Space hierarchy for dolo.py.
Following Dolo.jl: - Space: Mathematical domain for economic variables (continuous or discrete). - CartesianSpace: Continuous bounded hypercube [min, max] (loc = val). - DiscreteSpace (GridSpace): Finite set of discrete points/regimes (loc = index). - ProductSpace: Cartesian product of multiple spaces (e.g. exo × endo). - EmptySpace: Neutral empty domain (discretizes to EmptyGrid).
CartesianSpace
¶
Bases: Space, dict
Continuous hypercube domain bounded by [min, max].
Supports dict-like access space['k'] for backwards compatibility with
legacy CartesianDomain.
Source code in src/dolo/numeric/spaces.py
69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 | |
DiscreteSpace
¶
Bases: Space
Finite discrete set of points or regimes (e.g. Markov states).
In a DiscreteSpace:
- loc is the integer regime index i (0 <= i < n_points).
- val is the discrete coordinate vector points[i].
Source code in src/dolo/numeric/spaces.py
EmptySpace
¶
Bases: Space
Empty / Neutral space (used when exogenous shocks are absent).
Source code in src/dolo/numeric/spaces.py
ProductSpace
¶
Bases: Space
Product of two or more spaces (e.g. Exogenous × Endogenous).
Source code in src/dolo/numeric/spaces.py
Space
¶
Bases: ABC
Abstract base class representing a mathematical space for economic variables.
Source code in src/dolo/numeric/spaces.py
Approximator hierarchy for dolo.py.
Following Dolo.jl: - Approximator: Operator knowing how to fit coefficients from values on a Grid, and evaluate approximations at query points (QualifiedPoint, QualifiedBatch, or coords). - LinearApproximator: Piecewise multilinear interpolation on CartesianGrid. - CubicSplineApproximator: Prefiltered cubic spline interpolation on CartesianGrid. - SmolyakApproximator: Multivariate Chebyshev polynomial basis on SmolyakGrid. - ProductApproximator: Regime-wise composite approximator over ProductGrid / ProductSpace.
Approximator
¶
Bases: ABC
Abstract base class for approximation schemes.
Source code in src/dolo/numeric/approximators.py
evaluate(coeffs, *args)
¶
Universal evaluation method for approximation schemes.
Supports:
- evaluate(coeffs, qp): single QualifiedPoint / QP
- evaluate(coeffs, batch): QualifiedBatch / SliceQP
- evaluate(coeffs, coords): coordinate array (N, d) or (d,)
- evaluate(coeffs, *args): multi-argument forms implemented by subclasses
Source code in src/dolo/numeric/approximators.py
evaluate_batch(coeffs, batch)
¶
evaluate_coords(coeffs, coords)
abstractmethod
¶
Evaluate approximation at continuous coordinate matrix of shape (N, d).
fit(values)
abstractmethod
¶
CubicSplineApproximator
¶
Bases: Approximator
Prefiltered cubic spline interpolation on CartesianGrid.
Source code in src/dolo/numeric/approximators.py
LinearApproximator
¶
Bases: Approximator
Piecewise multilinear interpolation on CartesianGrid.
Source code in src/dolo/numeric/approximators.py
ProductApproximator
¶
Bases: Approximator
Composite approximator over ProductGrid (e.g. exo × endo).
Source code in src/dolo/numeric/approximators.py
171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 | |
evaluate(coeffs, *args)
¶
Universal evaluation on ProductApproximator.
Supports:
- evaluate(coeffs, qp): single QualifiedPoint / QP
- evaluate(coeffs, batch): QualifiedBatch / SliceQP
- evaluate(coeffs, s): continuous endogenous states alone (empty exo or single-regime)
- evaluate(coeffs, i, s): discrete regime index i + continuous states s
- evaluate(coeffs, m, s): continuous exogenous m + endogenous s
Source code in src/dolo/numeric/approximators.py
evaluate_ms(coeffs, m, s)
¶
Evaluate continuous endogenous states s and exogenous states m.
Source code in src/dolo/numeric/approximators.py
evaluate_regime(coeffs, i, s)
¶
Evaluate continuous endogenous states s within discrete regime i.
Source code in src/dolo/numeric/approximators.py
evaluate_s(coeffs, s)
¶
Evaluate continuous endogenous states s when exogenous state is empty or single-regime.
Source code in src/dolo/numeric/approximators.py
SmolyakApproximator
¶
Bases: Approximator
Multivariate Chebyshev polynomial approximation on SmolyakGrid.
Source code in src/dolo/numeric/approximators.py
get_approximator(target, interp_method='cubic', **kwargs)
¶
Factory function returning the canonical Approximator for a given Grid or Space.