### Import scipy distributions Source: https://randall-romero.github.io/CompEcon/notebooks/math/03%20Major%20Distribution%20CDFs%20and%20PDFs.html Initial imports and setup for the distribution examples. ```python from scipy.stats import norm, lognorm, beta, gamma, expon, chi2, f, t, logistic n = 400 ``` -------------------------------- ### Install and Import Required Libraries Source: https://randall-romero.github.io/CompEcon/_sources/notebooks/dp/01%20Timber%20Harvesting%20Model%20-%20Cubic%20Spline%20Approximation.ipynb This snippet shows the recommended installation command for the CompEcon module and the necessary imports for the example. It uses numpy, matplotlib, and specific classes from compecon. ```bash !pip install compecon --upgrade ``` ```python import numpy as np import matplotlib.pyplot as plt import matplotlib.gridspec as gridspec from compecon import DPmodel, BasisSpline, NLP ``` -------------------------------- ### Set up DPmodel Source: https://randall-romero.github.io/CompEcon/notebooks/dp/10%20Water%20Resource%20Management%20Model.html Create the DPmodel instance with the basis, reward, transition, bounds, shocks, and discount factor. ```python water_model = DPmodel(basis, reward, transition, bounds,e=e,w=w, x=['Irrigation'], discount=δ ) ``` -------------------------------- ### Output of print statements for Rosencrantz root finding Source: https://randall-romero.github.io/CompEcon/notebooks/slv/02%20Compute%20root%20of%20Rosencrantz%20function.html Example output from the print statements, showing the starting point used in the run. The actual values depend on the random starting point. ```text Hundreds of seconds required to compute root of Rosencrantz function f(x1,x2)= [200*x1*(x2-x1^2)+1-x1;100*(x1^2-x2)] via Newton and Broyden methods, starting at x1 = -1.66 x2 = -0.22 ``` -------------------------------- ### Import CompEcon and set up environment Source: https://randall-romero.github.io/CompEcon/notebooks/ode/01%20Stability%20of%20Linear%20Homogeneous%20ODEs.html Import the ODE class from compecon and other required libraries. Set ANIMATED to 0 for static images or a positive number of seconds for videos, which requires ffmpeg. ```python from compecon import ODE import numpy as np import pandas as pd import matplotlib.pyplot as plt ANIMATED = 3 # static images if 0, videos of ANIMATED seconds if positive. Requires ffmpeg ``` -------------------------------- ### Import CompEcon and plotting libraries Source: https://randall-romero.github.io/CompEcon/_sources/notebooks/qua/50%20Change%20in%20consumer%20surplus.ipynb Imports the required modules: qnwlege from compecon, numpy, and matplotlib.pyplot. This is the initial setup for the example. ```python from compecon import qnwlege import numpy as np import matplotlib.pyplot as plt ``` -------------------------------- ### Import libraries and set up problem Source: https://randall-romero.github.io/CompEcon/notebooks/slv/03%20Compute%20fixedpoint%20of%20f%28x%29%20%3D%20sqrt%28x%29.html Import numpy, pandas, and CompEcon modules. Generate a random starting point and define the fixed-point problem g(x) = sqrt(x) using NLP. ```python import numpy as np import pandas as pd from compecon import tic, toc, NLP ``` ```python xinit = np.random.rand(1) + 0.5 ``` ```python def g(x): return np.sqrt(x) problem_as_fixpoint = NLP(g, xinit) ``` -------------------------------- ### Import qnwequi and matplotlib Source: https://randall-romero.github.io/CompEcon/_sources/notebooks/qua/01%20Equidistributed%20sequences%20on%20unit%20square%20in%20R2.ipynb Imports the `qnwequi` function from the `compecon` package and `matplotlib.pyplot` for plotting. This is the initial setup required to run the examples on this page. ```python from compecon import qnwequi import matplotlib.pyplot as plt ``` -------------------------------- ### Install CompEcon library Source: https://randall-romero.github.io/CompEcon/_sources/notebooks/dif/05%20Finite-Difference%20Jacobians%20and%20Hessians.ipynb Command to install or upgrade the CompEcon library via pip. ```bash !pip install compecon --upgrade ``` -------------------------------- ### Import CompEcon and NumPy Source: https://randall-romero.github.io/CompEcon/_sources/notebooks/dif/05%20Finite-Difference%20Jacobians%20and%20Hessians.ipynb Initial setup to import necessary functions and configure NumPy print options. ```python from compecon import jacobian, hessian import numpy as np np.set_printoptions(precision=15) ``` -------------------------------- ### Create DPmodel instance Source: https://randall-romero.github.io/CompEcon/notebooks/dp/07%20Stochastic%20Optimal%20Economic%20Growth%20Model.html Instantiates the CompEcon DPmodel with the basis, reward, transition, bounds, shock distribution, and discount factor δ. ```python growth_model = DPmodel(basis, reward, transition, bounds,e=e,w=w, x=['Investment'], discount=δ ) ``` -------------------------------- ### Generate random starting point Source: https://randall-romero.github.io/CompEcon/_sources/notebooks/slv/04%20Compute%20fixedpoint%20of%20f%28x1%2Cx2%29%3D%20%5Bx1%202%2Bx2%203; x1 x2 - 0.5].ipynb Generates a random starting point for the fixed-point algorithms. ```python xinit = np.random.randn(2) ``` -------------------------------- ### Set random starting point for root finding Source: https://randall-romero.github.io/CompEcon/notebooks/slv/02%20Compute%20root%20of%20Rosencrantz%20function.html Randomly generate a starting point for the root-finding algorithms. The starting point is stored in the problem's x0 attribute and is used by both Newton and Broyden methods. ```python problem.x0 = np.random.randn(2) ``` -------------------------------- ### Initialize DPmodel Source: https://randall-romero.github.io/CompEcon/_sources/notebooks/dp/03%20Industry%20Entry-Exit%20Model.ipynb Configures the DPmodel object with the defined basis, profit and transition functions, discrete states, actions, discount factor, and transition matrix. ```python model = DPmodel(basis, profit, transition, i=dstates, j=dactions, discount=0.9, e=e, w=w, h=[[0, 0], [1, 1]]) ``` -------------------------------- ### Create LCP instance Source: https://randall-romero.github.io/CompEcon/notebooks/slv/07%20Linear%20complementarity%20problem%20methods.html Instantiates the LCP problem with matrices M, q and bounds a, b. ```python L = LCP(M, q, a, b) ``` -------------------------------- ### Install compecon package Source: https://randall-romero.github.io/CompEcon/_sources/notebooks/interacting.ipynb Run this command in a notebook cell before running the notebook to install the compecon package. ```bash !pip install compecon ```