partition stringclasses 3
values | func_name stringlengths 1 134 | docstring stringlengths 1 46.9k | path stringlengths 4 223 | original_string stringlengths 75 104k | code stringlengths 75 104k | docstring_tokens listlengths 1 1.97k | repo stringlengths 7 55 | language stringclasses 1
value | url stringlengths 87 315 | code_tokens listlengths 19 28.4k | sha stringlengths 40 40 |
|---|---|---|---|---|---|---|---|---|---|---|---|
train | DLE.compute_steadystate | Computes the non-stochastic steady-state of the economy.
Parameters
----------
nnc : array_like(float)
nnc is the location of the constant in the state vector x_t | quantecon/dle.py | def compute_steadystate(self, nnc=2):
"""
Computes the non-stochastic steady-state of the economy.
Parameters
----------
nnc : array_like(float)
nnc is the location of the constant in the state vector x_t
"""
zx = np.eye(self.A0.shape[0])-self.A0
... | def compute_steadystate(self, nnc=2):
"""
Computes the non-stochastic steady-state of the economy.
Parameters
----------
nnc : array_like(float)
nnc is the location of the constant in the state vector x_t
"""
zx = np.eye(self.A0.shape[0])-self.A0
... | [
"Computes",
"the",
"non",
"-",
"stochastic",
"steady",
"-",
"state",
"of",
"the",
"economy",
"."
] | QuantEcon/QuantEcon.py | python | https://github.com/QuantEcon/QuantEcon.py/blob/26a66c552f2a73967d7efb6e1f4b4c4985a12643/quantecon/dle.py#L159-L178 | [
"def",
"compute_steadystate",
"(",
"self",
",",
"nnc",
"=",
"2",
")",
":",
"zx",
"=",
"np",
".",
"eye",
"(",
"self",
".",
"A0",
".",
"shape",
"[",
"0",
"]",
")",
"-",
"self",
".",
"A0",
"self",
".",
"zz",
"=",
"nullspace",
"(",
"zx",
")",
"se... | 26a66c552f2a73967d7efb6e1f4b4c4985a12643 |
train | DLE.compute_sequence | Simulate quantities and prices for the economy
Parameters
----------
x0 : array_like(float)
The initial state
ts_length : scalar(int)
Length of the simulation
Pay : array_like(float)
Vector to price an asset whose payout is Pay*xt | quantecon/dle.py | def compute_sequence(self, x0, ts_length=None, Pay=None):
"""
Simulate quantities and prices for the economy
Parameters
----------
x0 : array_like(float)
The initial state
ts_length : scalar(int)
Length of the simulation
Pay : array_like... | def compute_sequence(self, x0, ts_length=None, Pay=None):
"""
Simulate quantities and prices for the economy
Parameters
----------
x0 : array_like(float)
The initial state
ts_length : scalar(int)
Length of the simulation
Pay : array_like... | [
"Simulate",
"quantities",
"and",
"prices",
"for",
"the",
"economy"
] | QuantEcon/QuantEcon.py | python | https://github.com/QuantEcon/QuantEcon.py/blob/26a66c552f2a73967d7efb6e1f4b4c4985a12643/quantecon/dle.py#L180-L249 | [
"def",
"compute_sequence",
"(",
"self",
",",
"x0",
",",
"ts_length",
"=",
"None",
",",
"Pay",
"=",
"None",
")",
":",
"lq",
"=",
"LQ",
"(",
"self",
".",
"Q",
",",
"self",
".",
"R",
",",
"self",
".",
"A",
",",
"self",
".",
"B",
",",
"self",
"."... | 26a66c552f2a73967d7efb6e1f4b4c4985a12643 |
train | DLE.irf | Create Impulse Response Functions
Parameters
----------
ts_length : scalar(int)
Number of periods to calculate IRF
Shock : array_like(float)
Vector of shocks to calculate IRF to. Default is first element of w | quantecon/dle.py | def irf(self, ts_length=100, shock=None):
"""
Create Impulse Response Functions
Parameters
----------
ts_length : scalar(int)
Number of periods to calculate IRF
Shock : array_like(float)
Vector of shocks to calculate IRF to. Default is first ele... | def irf(self, ts_length=100, shock=None):
"""
Create Impulse Response Functions
Parameters
----------
ts_length : scalar(int)
Number of periods to calculate IRF
Shock : array_like(float)
Vector of shocks to calculate IRF to. Default is first ele... | [
"Create",
"Impulse",
"Response",
"Functions"
] | QuantEcon/QuantEcon.py | python | https://github.com/QuantEcon/QuantEcon.py/blob/26a66c552f2a73967d7efb6e1f4b4c4985a12643/quantecon/dle.py#L251-L297 | [
"def",
"irf",
"(",
"self",
",",
"ts_length",
"=",
"100",
",",
"shock",
"=",
"None",
")",
":",
"if",
"type",
"(",
"shock",
")",
"!=",
"np",
".",
"ndarray",
":",
"# Default is to select first element of w",
"shock",
"=",
"np",
".",
"vstack",
"(",
"(",
"n... | 26a66c552f2a73967d7efb6e1f4b4c4985a12643 |
train | DLE.canonical | Compute canonical preference representation
Uses auxiliary problem of 9.4.2, with the preference shock process reintroduced
Calculates pihat, llambdahat and ubhat for the equivalent canonical household technology | quantecon/dle.py | def canonical(self):
"""
Compute canonical preference representation
Uses auxiliary problem of 9.4.2, with the preference shock process reintroduced
Calculates pihat, llambdahat and ubhat for the equivalent canonical household technology
"""
Ac1 = np.hstack((self.deltah,... | def canonical(self):
"""
Compute canonical preference representation
Uses auxiliary problem of 9.4.2, with the preference shock process reintroduced
Calculates pihat, llambdahat and ubhat for the equivalent canonical household technology
"""
Ac1 = np.hstack((self.deltah,... | [
"Compute",
"canonical",
"preference",
"representation",
"Uses",
"auxiliary",
"problem",
"of",
"9",
".",
"4",
".",
"2",
"with",
"the",
"preference",
"shock",
"process",
"reintroduced",
"Calculates",
"pihat",
"llambdahat",
"and",
"ubhat",
"for",
"the",
"equivalent",... | QuantEcon/QuantEcon.py | python | https://github.com/QuantEcon/QuantEcon.py/blob/26a66c552f2a73967d7efb6e1f4b4c4985a12643/quantecon/dle.py#L299-L330 | [
"def",
"canonical",
"(",
"self",
")",
":",
"Ac1",
"=",
"np",
".",
"hstack",
"(",
"(",
"self",
".",
"deltah",
",",
"np",
".",
"zeros",
"(",
"(",
"self",
".",
"nh",
",",
"self",
".",
"nz",
")",
")",
")",
")",
"Ac2",
"=",
"np",
".",
"hstack",
... | 26a66c552f2a73967d7efb6e1f4b4c4985a12643 |
train | Kalman.whitener_lss | r"""
This function takes the linear state space system
that is an input to the Kalman class and it converts
that system to the time-invariant whitener represenation
given by
.. math::
\tilde{x}_{t+1}^* = \tilde{A} \tilde{x} + \tilde{C} v
a = \tilde{G} \t... | quantecon/kalman.py | def whitener_lss(self):
r"""
This function takes the linear state space system
that is an input to the Kalman class and it converts
that system to the time-invariant whitener represenation
given by
.. math::
\tilde{x}_{t+1}^* = \tilde{A} \tilde{x} + \tilde{C... | def whitener_lss(self):
r"""
This function takes the linear state space system
that is an input to the Kalman class and it converts
that system to the time-invariant whitener represenation
given by
.. math::
\tilde{x}_{t+1}^* = \tilde{A} \tilde{x} + \tilde{C... | [
"r",
"This",
"function",
"takes",
"the",
"linear",
"state",
"space",
"system",
"that",
"is",
"an",
"input",
"to",
"the",
"Kalman",
"class",
"and",
"it",
"converts",
"that",
"system",
"to",
"the",
"time",
"-",
"invariant",
"whitener",
"represenation",
"given"... | QuantEcon/QuantEcon.py | python | https://github.com/QuantEcon/QuantEcon.py/blob/26a66c552f2a73967d7efb6e1f4b4c4985a12643/quantecon/kalman.py#L105-L178 | [
"def",
"whitener_lss",
"(",
"self",
")",
":",
"K",
"=",
"self",
".",
"K_infinity",
"# Get the matrix sizes",
"n",
",",
"k",
",",
"m",
",",
"l",
"=",
"self",
".",
"ss",
".",
"n",
",",
"self",
".",
"ss",
".",
"k",
",",
"self",
".",
"ss",
".",
"m"... | 26a66c552f2a73967d7efb6e1f4b4c4985a12643 |
train | Kalman.prior_to_filtered | r"""
Updates the moments (x_hat, Sigma) of the time t prior to the
time t filtering distribution, using current measurement :math:`y_t`.
The updates are according to
.. math::
\hat{x}^F = \hat{x} + \Sigma G' (G \Sigma G' + R)^{-1}
(y - G \hat{x})
... | quantecon/kalman.py | def prior_to_filtered(self, y):
r"""
Updates the moments (x_hat, Sigma) of the time t prior to the
time t filtering distribution, using current measurement :math:`y_t`.
The updates are according to
.. math::
\hat{x}^F = \hat{x} + \Sigma G' (G \Sigma G' + R)^{-1}
... | def prior_to_filtered(self, y):
r"""
Updates the moments (x_hat, Sigma) of the time t prior to the
time t filtering distribution, using current measurement :math:`y_t`.
The updates are according to
.. math::
\hat{x}^F = \hat{x} + \Sigma G' (G \Sigma G' + R)^{-1}
... | [
"r",
"Updates",
"the",
"moments",
"(",
"x_hat",
"Sigma",
")",
"of",
"the",
"time",
"t",
"prior",
"to",
"the",
"time",
"t",
"filtering",
"distribution",
"using",
"current",
"measurement",
":",
"math",
":",
"y_t",
"."
] | QuantEcon/QuantEcon.py | python | https://github.com/QuantEcon/QuantEcon.py/blob/26a66c552f2a73967d7efb6e1f4b4c4985a12643/quantecon/kalman.py#L180-L211 | [
"def",
"prior_to_filtered",
"(",
"self",
",",
"y",
")",
":",
"# === simplify notation === #",
"G",
",",
"H",
"=",
"self",
".",
"ss",
".",
"G",
",",
"self",
".",
"ss",
".",
"H",
"R",
"=",
"np",
".",
"dot",
"(",
"H",
",",
"H",
".",
"T",
")",
"# =... | 26a66c552f2a73967d7efb6e1f4b4c4985a12643 |
train | Kalman.filtered_to_forecast | Updates the moments of the time t filtering distribution to the
moments of the predictive distribution, which becomes the time
t+1 prior | quantecon/kalman.py | def filtered_to_forecast(self):
"""
Updates the moments of the time t filtering distribution to the
moments of the predictive distribution, which becomes the time
t+1 prior
"""
# === simplify notation === #
A, C = self.ss.A, self.ss.C
Q = np.dot(C, C.T)
... | def filtered_to_forecast(self):
"""
Updates the moments of the time t filtering distribution to the
moments of the predictive distribution, which becomes the time
t+1 prior
"""
# === simplify notation === #
A, C = self.ss.A, self.ss.C
Q = np.dot(C, C.T)
... | [
"Updates",
"the",
"moments",
"of",
"the",
"time",
"t",
"filtering",
"distribution",
"to",
"the",
"moments",
"of",
"the",
"predictive",
"distribution",
"which",
"becomes",
"the",
"time",
"t",
"+",
"1",
"prior"
] | QuantEcon/QuantEcon.py | python | https://github.com/QuantEcon/QuantEcon.py/blob/26a66c552f2a73967d7efb6e1f4b4c4985a12643/quantecon/kalman.py#L213-L226 | [
"def",
"filtered_to_forecast",
"(",
"self",
")",
":",
"# === simplify notation === #",
"A",
",",
"C",
"=",
"self",
".",
"ss",
".",
"A",
",",
"self",
".",
"ss",
".",
"C",
"Q",
"=",
"np",
".",
"dot",
"(",
"C",
",",
"C",
".",
"T",
")",
"# === and then... | 26a66c552f2a73967d7efb6e1f4b4c4985a12643 |
train | Kalman.stationary_values | Computes the limit of :math:`\Sigma_t` as t goes to infinity by
solving the associated Riccati equation. The outputs are stored in the
attributes `K_infinity` and `Sigma_infinity`. Computation is via the
doubling algorithm (default) or a QZ decomposition method (see the
documentation in ... | quantecon/kalman.py | def stationary_values(self, method='doubling'):
"""
Computes the limit of :math:`\Sigma_t` as t goes to infinity by
solving the associated Riccati equation. The outputs are stored in the
attributes `K_infinity` and `Sigma_infinity`. Computation is via the
doubling algorithm (defa... | def stationary_values(self, method='doubling'):
"""
Computes the limit of :math:`\Sigma_t` as t goes to infinity by
solving the associated Riccati equation. The outputs are stored in the
attributes `K_infinity` and `Sigma_infinity`. Computation is via the
doubling algorithm (defa... | [
"Computes",
"the",
"limit",
"of",
":",
"math",
":",
"\\",
"Sigma_t",
"as",
"t",
"goes",
"to",
"infinity",
"by",
"solving",
"the",
"associated",
"Riccati",
"equation",
".",
"The",
"outputs",
"are",
"stored",
"in",
"the",
"attributes",
"K_infinity",
"and",
"... | QuantEcon/QuantEcon.py | python | https://github.com/QuantEcon/QuantEcon.py/blob/26a66c552f2a73967d7efb6e1f4b4c4985a12643/quantecon/kalman.py#L242-L277 | [
"def",
"stationary_values",
"(",
"self",
",",
"method",
"=",
"'doubling'",
")",
":",
"# === simplify notation === #",
"A",
",",
"C",
",",
"G",
",",
"H",
"=",
"self",
".",
"ss",
".",
"A",
",",
"self",
".",
"ss",
".",
"C",
",",
"self",
".",
"ss",
"."... | 26a66c552f2a73967d7efb6e1f4b4c4985a12643 |
train | Kalman.stationary_coefficients | Wold representation moving average or VAR coefficients for the
steady state Kalman filter.
Parameters
----------
j : int
The lag length
coeff_type : string, either 'ma' or 'var' (default='ma')
The type of coefficent sequence to compute. Either 'ma' for
... | quantecon/kalman.py | def stationary_coefficients(self, j, coeff_type='ma'):
"""
Wold representation moving average or VAR coefficients for the
steady state Kalman filter.
Parameters
----------
j : int
The lag length
coeff_type : string, either 'ma' or 'var' (default='ma')... | def stationary_coefficients(self, j, coeff_type='ma'):
"""
Wold representation moving average or VAR coefficients for the
steady state Kalman filter.
Parameters
----------
j : int
The lag length
coeff_type : string, either 'ma' or 'var' (default='ma')... | [
"Wold",
"representation",
"moving",
"average",
"or",
"VAR",
"coefficients",
"for",
"the",
"steady",
"state",
"Kalman",
"filter",
"."
] | QuantEcon/QuantEcon.py | python | https://github.com/QuantEcon/QuantEcon.py/blob/26a66c552f2a73967d7efb6e1f4b4c4985a12643/quantecon/kalman.py#L279-L312 | [
"def",
"stationary_coefficients",
"(",
"self",
",",
"j",
",",
"coeff_type",
"=",
"'ma'",
")",
":",
"# == simplify notation == #",
"A",
",",
"G",
"=",
"self",
".",
"ss",
".",
"A",
",",
"self",
".",
"ss",
".",
"G",
"K_infinity",
"=",
"self",
".",
"K_infi... | 26a66c552f2a73967d7efb6e1f4b4c4985a12643 |
train | lemke_howson | Find one mixed-action Nash equilibrium of a 2-player normal form
game by the Lemke-Howson algorithm [2]_, implemented with
"complementary pivoting" (see, e.g., von Stengel [3]_ for details).
Parameters
----------
g : NormalFormGame
NormalFormGame instance with 2 players.
init_pivot : s... | quantecon/game_theory/lemke_howson.py | def lemke_howson(g, init_pivot=0, max_iter=10**6, capping=None,
full_output=False):
"""
Find one mixed-action Nash equilibrium of a 2-player normal form
game by the Lemke-Howson algorithm [2]_, implemented with
"complementary pivoting" (see, e.g., von Stengel [3]_ for details).
Par... | def lemke_howson(g, init_pivot=0, max_iter=10**6, capping=None,
full_output=False):
"""
Find one mixed-action Nash equilibrium of a 2-player normal form
game by the Lemke-Howson algorithm [2]_, implemented with
"complementary pivoting" (see, e.g., von Stengel [3]_ for details).
Par... | [
"Find",
"one",
"mixed",
"-",
"action",
"Nash",
"equilibrium",
"of",
"a",
"2",
"-",
"player",
"normal",
"form",
"game",
"by",
"the",
"Lemke",
"-",
"Howson",
"algorithm",
"[",
"2",
"]",
"_",
"implemented",
"with",
"complementary",
"pivoting",
"(",
"see",
"... | QuantEcon/QuantEcon.py | python | https://github.com/QuantEcon/QuantEcon.py/blob/26a66c552f2a73967d7efb6e1f4b4c4985a12643/quantecon/game_theory/lemke_howson.py#L16-L161 | [
"def",
"lemke_howson",
"(",
"g",
",",
"init_pivot",
"=",
"0",
",",
"max_iter",
"=",
"10",
"**",
"6",
",",
"capping",
"=",
"None",
",",
"full_output",
"=",
"False",
")",
":",
"try",
":",
"N",
"=",
"g",
".",
"N",
"except",
":",
"raise",
"TypeError",
... | 26a66c552f2a73967d7efb6e1f4b4c4985a12643 |
train | _lemke_howson_capping | Execute the Lemke-Howson algorithm with the heuristics proposed by
Codenotti et al.
Parameters
----------
payoff_matrices : tuple(ndarray(ndim=2))
Tuple of two arrays representing payoff matrices, of shape
(m, n) and (n, m), respectively.
tableaux : tuple(ndarray(float, ndim=2))
... | quantecon/game_theory/lemke_howson.py | def _lemke_howson_capping(payoff_matrices, tableaux, bases, init_pivot,
max_iter, capping):
"""
Execute the Lemke-Howson algorithm with the heuristics proposed by
Codenotti et al.
Parameters
----------
payoff_matrices : tuple(ndarray(ndim=2))
Tuple of two array... | def _lemke_howson_capping(payoff_matrices, tableaux, bases, init_pivot,
max_iter, capping):
"""
Execute the Lemke-Howson algorithm with the heuristics proposed by
Codenotti et al.
Parameters
----------
payoff_matrices : tuple(ndarray(ndim=2))
Tuple of two array... | [
"Execute",
"the",
"Lemke",
"-",
"Howson",
"algorithm",
"with",
"the",
"heuristics",
"proposed",
"by",
"Codenotti",
"et",
"al",
"."
] | QuantEcon/QuantEcon.py | python | https://github.com/QuantEcon/QuantEcon.py/blob/26a66c552f2a73967d7efb6e1f4b4c4985a12643/quantecon/game_theory/lemke_howson.py#L165-L223 | [
"def",
"_lemke_howson_capping",
"(",
"payoff_matrices",
",",
"tableaux",
",",
"bases",
",",
"init_pivot",
",",
"max_iter",
",",
"capping",
")",
":",
"m",
",",
"n",
"=",
"tableaux",
"[",
"1",
"]",
".",
"shape",
"[",
"0",
"]",
",",
"tableaux",
"[",
"0",
... | 26a66c552f2a73967d7efb6e1f4b4c4985a12643 |
train | _initialize_tableaux | Given a tuple of payoff matrices, initialize the tableau and basis
arrays in place.
For each player `i`, if `payoff_matrices[i].min()` is non-positive,
then stored in the tableau are payoff values incremented by
`abs(payoff_matrices[i].min()) + 1` (to ensure for the tableau not
to have a negative e... | quantecon/game_theory/lemke_howson.py | def _initialize_tableaux(payoff_matrices, tableaux, bases):
"""
Given a tuple of payoff matrices, initialize the tableau and basis
arrays in place.
For each player `i`, if `payoff_matrices[i].min()` is non-positive,
then stored in the tableau are payoff values incremented by
`abs(payoff_matrice... | def _initialize_tableaux(payoff_matrices, tableaux, bases):
"""
Given a tuple of payoff matrices, initialize the tableau and basis
arrays in place.
For each player `i`, if `payoff_matrices[i].min()` is non-positive,
then stored in the tableau are payoff values incremented by
`abs(payoff_matrice... | [
"Given",
"a",
"tuple",
"of",
"payoff",
"matrices",
"initialize",
"the",
"tableau",
"and",
"basis",
"arrays",
"in",
"place",
"."
] | QuantEcon/QuantEcon.py | python | https://github.com/QuantEcon/QuantEcon.py/blob/26a66c552f2a73967d7efb6e1f4b4c4985a12643/quantecon/game_theory/lemke_howson.py#L227-L318 | [
"def",
"_initialize_tableaux",
"(",
"payoff_matrices",
",",
"tableaux",
",",
"bases",
")",
":",
"nums_actions",
"=",
"payoff_matrices",
"[",
"0",
"]",
".",
"shape",
"consts",
"=",
"np",
".",
"zeros",
"(",
"2",
")",
"# To be added to payoffs if min <= 0",
"for",
... | 26a66c552f2a73967d7efb6e1f4b4c4985a12643 |
train | _lemke_howson_tbl | Main body of the Lemke-Howson algorithm implementation.
Perform the complementary pivoting. Modify `tablaux` and `bases` in
place.
Parameters
----------
tableaux : tuple(ndarray(float, ndim=2))
Tuple of two arrays containing the tableaux, of shape (n, m+n+1)
and (m, m+n+1), respect... | quantecon/game_theory/lemke_howson.py | def _lemke_howson_tbl(tableaux, bases, init_pivot, max_iter):
"""
Main body of the Lemke-Howson algorithm implementation.
Perform the complementary pivoting. Modify `tablaux` and `bases` in
place.
Parameters
----------
tableaux : tuple(ndarray(float, ndim=2))
Tuple of two arrays co... | def _lemke_howson_tbl(tableaux, bases, init_pivot, max_iter):
"""
Main body of the Lemke-Howson algorithm implementation.
Perform the complementary pivoting. Modify `tablaux` and `bases` in
place.
Parameters
----------
tableaux : tuple(ndarray(float, ndim=2))
Tuple of two arrays co... | [
"Main",
"body",
"of",
"the",
"Lemke",
"-",
"Howson",
"algorithm",
"implementation",
"."
] | QuantEcon/QuantEcon.py | python | https://github.com/QuantEcon/QuantEcon.py/blob/26a66c552f2a73967d7efb6e1f4b4c4985a12643/quantecon/game_theory/lemke_howson.py#L322-L421 | [
"def",
"_lemke_howson_tbl",
"(",
"tableaux",
",",
"bases",
",",
"init_pivot",
",",
"max_iter",
")",
":",
"init_player",
"=",
"0",
"for",
"k",
"in",
"bases",
"[",
"0",
"]",
":",
"if",
"k",
"==",
"init_pivot",
":",
"init_player",
"=",
"1",
"break",
"pls"... | 26a66c552f2a73967d7efb6e1f4b4c4985a12643 |
train | _pivoting | Perform a pivoting step. Modify `tableau` in place.
Parameters
----------
tableau : ndarray(float, ndim=2)
Array containing the tableau.
pivot : scalar(int)
Pivot.
pivot_row : scalar(int)
Pivot row index.
Returns
-------
tableau : ndarray(float, ndim=2)
... | quantecon/game_theory/lemke_howson.py | def _pivoting(tableau, pivot, pivot_row):
"""
Perform a pivoting step. Modify `tableau` in place.
Parameters
----------
tableau : ndarray(float, ndim=2)
Array containing the tableau.
pivot : scalar(int)
Pivot.
pivot_row : scalar(int)
Pivot row index.
Returns
... | def _pivoting(tableau, pivot, pivot_row):
"""
Perform a pivoting step. Modify `tableau` in place.
Parameters
----------
tableau : ndarray(float, ndim=2)
Array containing the tableau.
pivot : scalar(int)
Pivot.
pivot_row : scalar(int)
Pivot row index.
Returns
... | [
"Perform",
"a",
"pivoting",
"step",
".",
"Modify",
"tableau",
"in",
"place",
"."
] | QuantEcon/QuantEcon.py | python | https://github.com/QuantEcon/QuantEcon.py/blob/26a66c552f2a73967d7efb6e1f4b4c4985a12643/quantecon/game_theory/lemke_howson.py#L425-L461 | [
"def",
"_pivoting",
"(",
"tableau",
",",
"pivot",
",",
"pivot_row",
")",
":",
"nrows",
",",
"ncols",
"=",
"tableau",
".",
"shape",
"pivot_elt",
"=",
"tableau",
"[",
"pivot_row",
",",
"pivot",
"]",
"for",
"j",
"in",
"range",
"(",
"ncols",
")",
":",
"t... | 26a66c552f2a73967d7efb6e1f4b4c4985a12643 |
train | _get_mixed_actions | From `tableaux` and `bases`, extract non-slack basic variables and
return a tuple of the corresponding, normalized mixed actions.
Parameters
----------
tableaux : tuple(ndarray(float, ndim=2))
Tuple of two arrays containing the tableaux, of shape (n, m+n+1)
and (m, m+n+1), respectively.... | quantecon/game_theory/lemke_howson.py | def _get_mixed_actions(tableaux, bases):
"""
From `tableaux` and `bases`, extract non-slack basic variables and
return a tuple of the corresponding, normalized mixed actions.
Parameters
----------
tableaux : tuple(ndarray(float, ndim=2))
Tuple of two arrays containing the tableaux, of s... | def _get_mixed_actions(tableaux, bases):
"""
From `tableaux` and `bases`, extract non-slack basic variables and
return a tuple of the corresponding, normalized mixed actions.
Parameters
----------
tableaux : tuple(ndarray(float, ndim=2))
Tuple of two arrays containing the tableaux, of s... | [
"From",
"tableaux",
"and",
"bases",
"extract",
"non",
"-",
"slack",
"basic",
"variables",
"and",
"return",
"a",
"tuple",
"of",
"the",
"corresponding",
"normalized",
"mixed",
"actions",
"."
] | QuantEcon/QuantEcon.py | python | https://github.com/QuantEcon/QuantEcon.py/blob/26a66c552f2a73967d7efb6e1f4b4c4985a12643/quantecon/game_theory/lemke_howson.py#L566-L603 | [
"def",
"_get_mixed_actions",
"(",
"tableaux",
",",
"bases",
")",
":",
"nums_actions",
"=",
"tableaux",
"[",
"1",
"]",
".",
"shape",
"[",
"0",
"]",
",",
"tableaux",
"[",
"0",
"]",
".",
"shape",
"[",
"0",
"]",
"num",
"=",
"nums_actions",
"[",
"0",
"]... | 26a66c552f2a73967d7efb6e1f4b4c4985a12643 |
train | var_quadratic_sum | r"""
Computes the expected discounted quadratic sum
.. math::
q(x_0) = \mathbb{E} \Big[ \sum_{t=0}^{\infty} \beta^t x_t' H x_t \Big]
Here :math:`{x_t}` is the VAR process :math:`x_{t+1} = A x_t + C w_t`
with :math:`{x_t}` standard normal and :math:`x_0` the initial condition.
Parameters
... | quantecon/quadsums.py | def var_quadratic_sum(A, C, H, beta, x0):
r"""
Computes the expected discounted quadratic sum
.. math::
q(x_0) = \mathbb{E} \Big[ \sum_{t=0}^{\infty} \beta^t x_t' H x_t \Big]
Here :math:`{x_t}` is the VAR process :math:`x_{t+1} = A x_t + C w_t`
with :math:`{x_t}` standard normal and :math... | def var_quadratic_sum(A, C, H, beta, x0):
r"""
Computes the expected discounted quadratic sum
.. math::
q(x_0) = \mathbb{E} \Big[ \sum_{t=0}^{\infty} \beta^t x_t' H x_t \Big]
Here :math:`{x_t}` is the VAR process :math:`x_{t+1} = A x_t + C w_t`
with :math:`{x_t}` standard normal and :math... | [
"r",
"Computes",
"the",
"expected",
"discounted",
"quadratic",
"sum"
] | QuantEcon/QuantEcon.py | python | https://github.com/QuantEcon/QuantEcon.py/blob/26a66c552f2a73967d7efb6e1f4b4c4985a12643/quantecon/quadsums.py#L14-L62 | [
"def",
"var_quadratic_sum",
"(",
"A",
",",
"C",
",",
"H",
",",
"beta",
",",
"x0",
")",
":",
"# == Make sure that A, C, H and x0 are array_like == #",
"A",
",",
"C",
",",
"H",
"=",
"list",
"(",
"map",
"(",
"np",
".",
"atleast_2d",
",",
"(",
"A",
",",
"C... | 26a66c552f2a73967d7efb6e1f4b4c4985a12643 |
train | m_quadratic_sum | r"""
Computes the quadratic sum
.. math::
V = \sum_{j=0}^{\infty} A^j B A^{j'}
V is computed by solving the corresponding discrete lyapunov
equation using the doubling algorithm. See the documentation of
`util.solve_discrete_lyapunov` for more information.
Parameters
----------
... | quantecon/quadsums.py | def m_quadratic_sum(A, B, max_it=50):
r"""
Computes the quadratic sum
.. math::
V = \sum_{j=0}^{\infty} A^j B A^{j'}
V is computed by solving the corresponding discrete lyapunov
equation using the doubling algorithm. See the documentation of
`util.solve_discrete_lyapunov` for more in... | def m_quadratic_sum(A, B, max_it=50):
r"""
Computes the quadratic sum
.. math::
V = \sum_{j=0}^{\infty} A^j B A^{j'}
V is computed by solving the corresponding discrete lyapunov
equation using the doubling algorithm. See the documentation of
`util.solve_discrete_lyapunov` for more in... | [
"r",
"Computes",
"the",
"quadratic",
"sum"
] | QuantEcon/QuantEcon.py | python | https://github.com/QuantEcon/QuantEcon.py/blob/26a66c552f2a73967d7efb6e1f4b4c4985a12643/quantecon/quadsums.py#L65-L99 | [
"def",
"m_quadratic_sum",
"(",
"A",
",",
"B",
",",
"max_it",
"=",
"50",
")",
":",
"gamma1",
"=",
"solve_discrete_lyapunov",
"(",
"A",
",",
"B",
",",
"max_it",
")",
"return",
"gamma1"
] | 26a66c552f2a73967d7efb6e1f4b4c4985a12643 |
train | rouwenhorst | r"""
Takes as inputs n, p, q, psi. It will then construct a markov chain
that estimates an AR(1) process of:
:math:`y_t = \bar{y} + \rho y_{t-1} + \varepsilon_t`
where :math:`\varepsilon_t` is i.i.d. normal of mean 0, std dev of sigma
The Rouwenhorst approximation uses the following recursive defin... | quantecon/markov/approximation.py | def rouwenhorst(n, ybar, sigma, rho):
r"""
Takes as inputs n, p, q, psi. It will then construct a markov chain
that estimates an AR(1) process of:
:math:`y_t = \bar{y} + \rho y_{t-1} + \varepsilon_t`
where :math:`\varepsilon_t` is i.i.d. normal of mean 0, std dev of sigma
The Rouwenhorst approx... | def rouwenhorst(n, ybar, sigma, rho):
r"""
Takes as inputs n, p, q, psi. It will then construct a markov chain
that estimates an AR(1) process of:
:math:`y_t = \bar{y} + \rho y_{t-1} + \varepsilon_t`
where :math:`\varepsilon_t` is i.i.d. normal of mean 0, std dev of sigma
The Rouwenhorst approx... | [
"r",
"Takes",
"as",
"inputs",
"n",
"p",
"q",
"psi",
".",
"It",
"will",
"then",
"construct",
"a",
"markov",
"chain",
"that",
"estimates",
"an",
"AR",
"(",
"1",
")",
"process",
"of",
":",
":",
"math",
":",
"y_t",
"=",
"\\",
"bar",
"{",
"y",
"}",
... | QuantEcon/QuantEcon.py | python | https://github.com/QuantEcon/QuantEcon.py/blob/26a66c552f2a73967d7efb6e1f4b4c4985a12643/quantecon/markov/approximation.py#L15-L135 | [
"def",
"rouwenhorst",
"(",
"n",
",",
"ybar",
",",
"sigma",
",",
"rho",
")",
":",
"# Get the standard deviation of y",
"y_sd",
"=",
"sqrt",
"(",
"sigma",
"**",
"2",
"/",
"(",
"1",
"-",
"rho",
"**",
"2",
")",
")",
"# Given the moments of our process we can fin... | 26a66c552f2a73967d7efb6e1f4b4c4985a12643 |
train | tauchen | r"""
Computes a Markov chain associated with a discretized version of
the linear Gaussian AR(1) process
.. math::
y_{t+1} = \rho y_t + u_{t+1}
using Tauchen's method. Here :math:`{u_t}` is an i.i.d. Gaussian process
with zero mean.
Parameters
----------
rho : scalar(float)
... | quantecon/markov/approximation.py | def tauchen(rho, sigma_u, m=3, n=7):
r"""
Computes a Markov chain associated with a discretized version of
the linear Gaussian AR(1) process
.. math::
y_{t+1} = \rho y_t + u_{t+1}
using Tauchen's method. Here :math:`{u_t}` is an i.i.d. Gaussian process
with zero mean.
Parameters
... | def tauchen(rho, sigma_u, m=3, n=7):
r"""
Computes a Markov chain associated with a discretized version of
the linear Gaussian AR(1) process
.. math::
y_{t+1} = \rho y_t + u_{t+1}
using Tauchen's method. Here :math:`{u_t}` is an i.i.d. Gaussian process
with zero mean.
Parameters
... | [
"r",
"Computes",
"a",
"Markov",
"chain",
"associated",
"with",
"a",
"discretized",
"version",
"of",
"the",
"linear",
"Gaussian",
"AR",
"(",
"1",
")",
"process"
] | QuantEcon/QuantEcon.py | python | https://github.com/QuantEcon/QuantEcon.py/blob/26a66c552f2a73967d7efb6e1f4b4c4985a12643/quantecon/markov/approximation.py#L138-L189 | [
"def",
"tauchen",
"(",
"rho",
",",
"sigma_u",
",",
"m",
"=",
"3",
",",
"n",
"=",
"7",
")",
":",
"# standard deviation of y_t",
"std_y",
"=",
"np",
".",
"sqrt",
"(",
"sigma_u",
"**",
"2",
"/",
"(",
"1",
"-",
"rho",
"**",
"2",
")",
")",
"# top of d... | 26a66c552f2a73967d7efb6e1f4b4c4985a12643 |
train | nelder_mead | .. highlight:: none
Maximize a scalar-valued function with one or more variables using the
Nelder-Mead method.
This function is JIT-compiled in `nopython` mode using Numba.
Parameters
----------
fun : callable
The objective function to be maximized: `fun(x, *args) -> float`
wh... | quantecon/optimize/nelder_mead.py | def nelder_mead(fun, x0, bounds=np.array([[], []]).T, args=(), tol_f=1e-10,
tol_x=1e-10, max_iter=1000):
"""
.. highlight:: none
Maximize a scalar-valued function with one or more variables using the
Nelder-Mead method.
This function is JIT-compiled in `nopython` mode using Numba.
... | def nelder_mead(fun, x0, bounds=np.array([[], []]).T, args=(), tol_f=1e-10,
tol_x=1e-10, max_iter=1000):
"""
.. highlight:: none
Maximize a scalar-valued function with one or more variables using the
Nelder-Mead method.
This function is JIT-compiled in `nopython` mode using Numba.
... | [
"..",
"highlight",
"::",
"none"
] | QuantEcon/QuantEcon.py | python | https://github.com/QuantEcon/QuantEcon.py/blob/26a66c552f2a73967d7efb6e1f4b4c4985a12643/quantecon/optimize/nelder_mead.py#L15-L122 | [
"def",
"nelder_mead",
"(",
"fun",
",",
"x0",
",",
"bounds",
"=",
"np",
".",
"array",
"(",
"[",
"[",
"]",
",",
"[",
"]",
"]",
")",
".",
"T",
",",
"args",
"=",
"(",
")",
",",
"tol_f",
"=",
"1e-10",
",",
"tol_x",
"=",
"1e-10",
",",
"max_iter",
... | 26a66c552f2a73967d7efb6e1f4b4c4985a12643 |
train | _nelder_mead_algorithm | .. highlight:: none
Implements the Nelder-Mead algorithm described in Lagarias et al. (1998)
modified to maximize instead of minimizing. JIT-compiled in `nopython`
mode using Numba.
Parameters
----------
fun : callable
The objective function to be maximized.
`fun(x, *args) ... | quantecon/optimize/nelder_mead.py | def _nelder_mead_algorithm(fun, vertices, bounds=np.array([[], []]).T,
args=(), ρ=1., χ=2., γ=0.5, σ=0.5, tol_f=1e-8,
tol_x=1e-8, max_iter=1000):
"""
.. highlight:: none
Implements the Nelder-Mead algorithm described in Lagarias et al. (1998)
modifi... | def _nelder_mead_algorithm(fun, vertices, bounds=np.array([[], []]).T,
args=(), ρ=1., χ=2., γ=0.5, σ=0.5, tol_f=1e-8,
tol_x=1e-8, max_iter=1000):
"""
.. highlight:: none
Implements the Nelder-Mead algorithm described in Lagarias et al. (1998)
modifi... | [
"..",
"highlight",
"::",
"none"
] | QuantEcon/QuantEcon.py | python | https://github.com/QuantEcon/QuantEcon.py/blob/26a66c552f2a73967d7efb6e1f4b4c4985a12643/quantecon/optimize/nelder_mead.py#L126-L290 | [
"def",
"_nelder_mead_algorithm",
"(",
"fun",
",",
"vertices",
",",
"bounds",
"=",
"np",
".",
"array",
"(",
"[",
"[",
"]",
",",
"[",
"]",
"]",
")",
".",
"T",
",",
"args",
"=",
"(",
")",
",",
"ρ=",
"1",
".,",
" ",
"=2",
".",
", ",
"γ",
"0.",
... | 26a66c552f2a73967d7efb6e1f4b4c4985a12643 |
train | _initialize_simplex | Generates an initial simplex for the Nelder-Mead method. JIT-compiled in
`nopython` mode using Numba.
Parameters
----------
x0 : ndarray(float, ndim=1)
Initial guess. Array of real elements of size (n,), where ‘n’ is the
number of independent variables.
bounds: ndarray(float, ndim=... | quantecon/optimize/nelder_mead.py | def _initialize_simplex(x0, bounds):
"""
Generates an initial simplex for the Nelder-Mead method. JIT-compiled in
`nopython` mode using Numba.
Parameters
----------
x0 : ndarray(float, ndim=1)
Initial guess. Array of real elements of size (n,), where ‘n’ is the
number of indepen... | def _initialize_simplex(x0, bounds):
"""
Generates an initial simplex for the Nelder-Mead method. JIT-compiled in
`nopython` mode using Numba.
Parameters
----------
x0 : ndarray(float, ndim=1)
Initial guess. Array of real elements of size (n,), where ‘n’ is the
number of indepen... | [
"Generates",
"an",
"initial",
"simplex",
"for",
"the",
"Nelder",
"-",
"Mead",
"method",
".",
"JIT",
"-",
"compiled",
"in",
"nopython",
"mode",
"using",
"Numba",
"."
] | QuantEcon/QuantEcon.py | python | https://github.com/QuantEcon/QuantEcon.py/blob/26a66c552f2a73967d7efb6e1f4b4c4985a12643/quantecon/optimize/nelder_mead.py#L294-L331 | [
"def",
"_initialize_simplex",
"(",
"x0",
",",
"bounds",
")",
":",
"n",
"=",
"x0",
".",
"size",
"vertices",
"=",
"np",
".",
"empty",
"(",
"(",
"n",
"+",
"1",
",",
"n",
")",
",",
"dtype",
"=",
"np",
".",
"float64",
")",
"# Broadcast x0 on row dimension... | 26a66c552f2a73967d7efb6e1f4b4c4985a12643 |
train | _check_params | Checks whether the parameters for the Nelder-Mead algorithm are valid.
JIT-compiled in `nopython` mode using Numba.
Parameters
----------
ρ : scalar(float)
Reflection parameter. Must be strictly greater than 0.
χ : scalar(float)
Expansion parameter. Must be strictly greater than ma... | quantecon/optimize/nelder_mead.py | def _check_params(ρ, χ, γ, σ, bounds, n):
"""
Checks whether the parameters for the Nelder-Mead algorithm are valid.
JIT-compiled in `nopython` mode using Numba.
Parameters
----------
ρ : scalar(float)
Reflection parameter. Must be strictly greater than 0.
χ : scalar(float)
... | def _check_params(ρ, χ, γ, σ, bounds, n):
"""
Checks whether the parameters for the Nelder-Mead algorithm are valid.
JIT-compiled in `nopython` mode using Numba.
Parameters
----------
ρ : scalar(float)
Reflection parameter. Must be strictly greater than 0.
χ : scalar(float)
... | [
"Checks",
"whether",
"the",
"parameters",
"for",
"the",
"Nelder",
"-",
"Mead",
"algorithm",
"are",
"valid",
".",
"JIT",
"-",
"compiled",
"in",
"nopython",
"mode",
"using",
"Numba",
"."
] | QuantEcon/QuantEcon.py | python | https://github.com/QuantEcon/QuantEcon.py/blob/26a66c552f2a73967d7efb6e1f4b4c4985a12643/quantecon/optimize/nelder_mead.py#L335-L375 | [
"def",
"_check_params",
"(",
"ρ,",
" ",
", ",
"γ",
" σ",
",",
"bo",
"u",
"ds, n)",
":",
"",
"",
"",
"if",
"ρ ",
" ",
":",
"",
"raise",
"ValueError",
"(",
"\"ρ must be strictly greater than 0.\")",
"",
"if",
"χ ",
" ",
":",
"",
"raise",
"ValueError",
... | 26a66c552f2a73967d7efb6e1f4b4c4985a12643 |
train | _check_bounds | Checks whether `x` is within `bounds`. JIT-compiled in `nopython` mode
using Numba.
Parameters
----------
x : ndarray(float, ndim=1)
1-D array with shape (n,) of independent variables.
bounds: ndarray(float, ndim=2)
Sequence of (min, max) pairs for each element in x.
Returns
... | quantecon/optimize/nelder_mead.py | def _check_bounds(x, bounds):
"""
Checks whether `x` is within `bounds`. JIT-compiled in `nopython` mode
using Numba.
Parameters
----------
x : ndarray(float, ndim=1)
1-D array with shape (n,) of independent variables.
bounds: ndarray(float, ndim=2)
Sequence of (min, max) p... | def _check_bounds(x, bounds):
"""
Checks whether `x` is within `bounds`. JIT-compiled in `nopython` mode
using Numba.
Parameters
----------
x : ndarray(float, ndim=1)
1-D array with shape (n,) of independent variables.
bounds: ndarray(float, ndim=2)
Sequence of (min, max) p... | [
"Checks",
"whether",
"x",
"is",
"within",
"bounds",
".",
"JIT",
"-",
"compiled",
"in",
"nopython",
"mode",
"using",
"Numba",
"."
] | QuantEcon/QuantEcon.py | python | https://github.com/QuantEcon/QuantEcon.py/blob/26a66c552f2a73967d7efb6e1f4b4c4985a12643/quantecon/optimize/nelder_mead.py#L379-L402 | [
"def",
"_check_bounds",
"(",
"x",
",",
"bounds",
")",
":",
"if",
"bounds",
".",
"shape",
"==",
"(",
"0",
",",
"2",
")",
":",
"return",
"True",
"else",
":",
"return",
"(",
"(",
"np",
".",
"atleast_2d",
"(",
"bounds",
")",
"[",
":",
",",
"0",
"]"... | 26a66c552f2a73967d7efb6e1f4b4c4985a12643 |
train | _neg_bounded_fun | Wrapper for bounding and taking the negative of `fun` for the
Nelder-Mead algorithm. JIT-compiled in `nopython` mode using Numba.
Parameters
----------
fun : callable
The objective function to be minimized.
`fun(x, *args) -> float`
where x is an 1-D array with shape (n,) and... | quantecon/optimize/nelder_mead.py | def _neg_bounded_fun(fun, bounds, x, args=()):
"""
Wrapper for bounding and taking the negative of `fun` for the
Nelder-Mead algorithm. JIT-compiled in `nopython` mode using Numba.
Parameters
----------
fun : callable
The objective function to be minimized.
`fun(x, *args) ->... | def _neg_bounded_fun(fun, bounds, x, args=()):
"""
Wrapper for bounding and taking the negative of `fun` for the
Nelder-Mead algorithm. JIT-compiled in `nopython` mode using Numba.
Parameters
----------
fun : callable
The objective function to be minimized.
`fun(x, *args) ->... | [
"Wrapper",
"for",
"bounding",
"and",
"taking",
"the",
"negative",
"of",
"fun",
"for",
"the",
"Nelder",
"-",
"Mead",
"algorithm",
".",
"JIT",
"-",
"compiled",
"in",
"nopython",
"mode",
"using",
"Numba",
"."
] | QuantEcon/QuantEcon.py | python | https://github.com/QuantEcon/QuantEcon.py/blob/26a66c552f2a73967d7efb6e1f4b4c4985a12643/quantecon/optimize/nelder_mead.py#L406-L439 | [
"def",
"_neg_bounded_fun",
"(",
"fun",
",",
"bounds",
",",
"x",
",",
"args",
"=",
"(",
")",
")",
":",
"if",
"_check_bounds",
"(",
"x",
",",
"bounds",
")",
":",
"return",
"-",
"fun",
"(",
"x",
",",
"*",
"args",
")",
"else",
":",
"return",
"np",
... | 26a66c552f2a73967d7efb6e1f4b4c4985a12643 |
train | solve_discrete_lyapunov | r"""
Computes the solution to the discrete lyapunov equation
.. math::
AXA' - X + B = 0
:math:`X` is computed by using a doubling algorithm. In particular, we
iterate to convergence on :math:`X_j` with the following recursions for
:math:`j = 1, 2, \dots` starting from :math:`X_0 = B`, :ma... | quantecon/matrix_eqn.py | def solve_discrete_lyapunov(A, B, max_it=50, method="doubling"):
r"""
Computes the solution to the discrete lyapunov equation
.. math::
AXA' - X + B = 0
:math:`X` is computed by using a doubling algorithm. In particular, we
iterate to convergence on :math:`X_j` with the following recursio... | def solve_discrete_lyapunov(A, B, max_it=50, method="doubling"):
r"""
Computes the solution to the discrete lyapunov equation
.. math::
AXA' - X + B = 0
:math:`X` is computed by using a doubling algorithm. In particular, we
iterate to convergence on :math:`X_j` with the following recursio... | [
"r",
"Computes",
"the",
"solution",
"to",
"the",
"discrete",
"lyapunov",
"equation"
] | QuantEcon/QuantEcon.py | python | https://github.com/QuantEcon/QuantEcon.py/blob/26a66c552f2a73967d7efb6e1f4b4c4985a12643/quantecon/matrix_eqn.py#L22-L96 | [
"def",
"solve_discrete_lyapunov",
"(",
"A",
",",
"B",
",",
"max_it",
"=",
"50",
",",
"method",
"=",
"\"doubling\"",
")",
":",
"if",
"method",
"==",
"\"doubling\"",
":",
"A",
",",
"B",
"=",
"list",
"(",
"map",
"(",
"np",
".",
"atleast_2d",
",",
"[",
... | 26a66c552f2a73967d7efb6e1f4b4c4985a12643 |
train | solve_discrete_riccati | Solves the discrete-time algebraic Riccati equation
.. math::
X = A'XA - (N + B'XA)'(B'XB + R)^{-1}(N + B'XA) + Q
Computation is via a modified structured doubling algorithm, an
explanation of which can be found in the reference below, if
`method="doubling"` (default), and via a QZ decomposit... | quantecon/matrix_eqn.py | def solve_discrete_riccati(A, B, Q, R, N=None, tolerance=1e-10, max_iter=500,
method="doubling"):
"""
Solves the discrete-time algebraic Riccati equation
.. math::
X = A'XA - (N + B'XA)'(B'XB + R)^{-1}(N + B'XA) + Q
Computation is via a modified structured doubling ... | def solve_discrete_riccati(A, B, Q, R, N=None, tolerance=1e-10, max_iter=500,
method="doubling"):
"""
Solves the discrete-time algebraic Riccati equation
.. math::
X = A'XA - (N + B'XA)'(B'XB + R)^{-1}(N + B'XA) + Q
Computation is via a modified structured doubling ... | [
"Solves",
"the",
"discrete",
"-",
"time",
"algebraic",
"Riccati",
"equation"
] | QuantEcon/QuantEcon.py | python | https://github.com/QuantEcon/QuantEcon.py/blob/26a66c552f2a73967d7efb6e1f4b4c4985a12643/quantecon/matrix_eqn.py#L99-L225 | [
"def",
"solve_discrete_riccati",
"(",
"A",
",",
"B",
",",
"Q",
",",
"R",
",",
"N",
"=",
"None",
",",
"tolerance",
"=",
"1e-10",
",",
"max_iter",
"=",
"500",
",",
"method",
"=",
"\"doubling\"",
")",
":",
"methods",
"=",
"[",
"'doubling'",
",",
"'qz'",... | 26a66c552f2a73967d7efb6e1f4b4c4985a12643 |
train | next_k_array | Given an array `a` of k distinct nonnegative integers, sorted in
ascending order, return the next k-array in the lexicographic
ordering of the descending sequences of the elements [1]_. `a` is
modified in place.
Parameters
----------
a : ndarray(int, ndim=1)
Array of length k.
Retu... | quantecon/util/combinatorics.py | def next_k_array(a):
"""
Given an array `a` of k distinct nonnegative integers, sorted in
ascending order, return the next k-array in the lexicographic
ordering of the descending sequences of the elements [1]_. `a` is
modified in place.
Parameters
----------
a : ndarray(int, ndim=1)
... | def next_k_array(a):
"""
Given an array `a` of k distinct nonnegative integers, sorted in
ascending order, return the next k-array in the lexicographic
ordering of the descending sequences of the elements [1]_. `a` is
modified in place.
Parameters
----------
a : ndarray(int, ndim=1)
... | [
"Given",
"an",
"array",
"a",
"of",
"k",
"distinct",
"nonnegative",
"integers",
"sorted",
"in",
"ascending",
"order",
"return",
"the",
"next",
"k",
"-",
"array",
"in",
"the",
"lexicographic",
"ordering",
"of",
"the",
"descending",
"sequences",
"of",
"the",
"e... | QuantEcon/QuantEcon.py | python | https://github.com/QuantEcon/QuantEcon.py/blob/26a66c552f2a73967d7efb6e1f4b4c4985a12643/quantecon/util/combinatorics.py#L12-L70 | [
"def",
"next_k_array",
"(",
"a",
")",
":",
"# Logic taken from Algotirhm T in D. Knuth, The Art of Computer",
"# Programming, Section 7.2.1.3 \"Generating All Combinations\".",
"k",
"=",
"len",
"(",
"a",
")",
"if",
"k",
"==",
"1",
"or",
"a",
"[",
"0",
"]",
"+",
"1",
... | 26a66c552f2a73967d7efb6e1f4b4c4985a12643 |
train | k_array_rank | Given an array `a` of k distinct nonnegative integers, sorted in
ascending order, return its ranking in the lexicographic ordering of
the descending sequences of the elements [1]_.
Parameters
----------
a : ndarray(int, ndim=1)
Array of length k.
Returns
-------
idx : scalar(in... | quantecon/util/combinatorics.py | def k_array_rank(a):
"""
Given an array `a` of k distinct nonnegative integers, sorted in
ascending order, return its ranking in the lexicographic ordering of
the descending sequences of the elements [1]_.
Parameters
----------
a : ndarray(int, ndim=1)
Array of length k.
Return... | def k_array_rank(a):
"""
Given an array `a` of k distinct nonnegative integers, sorted in
ascending order, return its ranking in the lexicographic ordering of
the descending sequences of the elements [1]_.
Parameters
----------
a : ndarray(int, ndim=1)
Array of length k.
Return... | [
"Given",
"an",
"array",
"a",
"of",
"k",
"distinct",
"nonnegative",
"integers",
"sorted",
"in",
"ascending",
"order",
"return",
"its",
"ranking",
"in",
"the",
"lexicographic",
"ordering",
"of",
"the",
"descending",
"sequences",
"of",
"the",
"elements",
"[",
"1"... | QuantEcon/QuantEcon.py | python | https://github.com/QuantEcon/QuantEcon.py/blob/26a66c552f2a73967d7efb6e1f4b4c4985a12643/quantecon/util/combinatorics.py#L73-L100 | [
"def",
"k_array_rank",
"(",
"a",
")",
":",
"k",
"=",
"len",
"(",
"a",
")",
"idx",
"=",
"int",
"(",
"a",
"[",
"0",
"]",
")",
"# Convert to Python int",
"for",
"i",
"in",
"range",
"(",
"1",
",",
"k",
")",
":",
"idx",
"+=",
"comb",
"(",
"a",
"["... | 26a66c552f2a73967d7efb6e1f4b4c4985a12643 |
train | k_array_rank_jit | Numba jit version of `k_array_rank`.
Notes
-----
An incorrect value will be returned without warning or error if
overflow occurs during the computation. It is the user's
responsibility to ensure that the rank of the input array fits
within the range of possible values of `np.intp`; a sufficient... | quantecon/util/combinatorics.py | def k_array_rank_jit(a):
"""
Numba jit version of `k_array_rank`.
Notes
-----
An incorrect value will be returned without warning or error if
overflow occurs during the computation. It is the user's
responsibility to ensure that the rank of the input array fits
within the range of possi... | def k_array_rank_jit(a):
"""
Numba jit version of `k_array_rank`.
Notes
-----
An incorrect value will be returned without warning or error if
overflow occurs during the computation. It is the user's
responsibility to ensure that the rank of the input array fits
within the range of possi... | [
"Numba",
"jit",
"version",
"of",
"k_array_rank",
"."
] | QuantEcon/QuantEcon.py | python | https://github.com/QuantEcon/QuantEcon.py/blob/26a66c552f2a73967d7efb6e1f4b4c4985a12643/quantecon/util/combinatorics.py#L104-L122 | [
"def",
"k_array_rank_jit",
"(",
"a",
")",
":",
"k",
"=",
"len",
"(",
"a",
")",
"idx",
"=",
"a",
"[",
"0",
"]",
"for",
"i",
"in",
"range",
"(",
"1",
",",
"k",
")",
":",
"idx",
"+=",
"comb_jit",
"(",
"a",
"[",
"i",
"]",
",",
"i",
"+",
"1",
... | 26a66c552f2a73967d7efb6e1f4b4c4985a12643 |
train | _numba_linalg_solve | Solve the linear equation ax = b directly calling a Numba internal
function. The data in `a` and `b` are interpreted in Fortran order,
and dtype of `a` and `b` must be the same, one of {float32, float64,
complex64, complex128}. `a` and `b` are modified in place, and the
solution is stored in `b`. *No er... | quantecon/util/numba.py | def _numba_linalg_solve(a, b):
"""
Solve the linear equation ax = b directly calling a Numba internal
function. The data in `a` and `b` are interpreted in Fortran order,
and dtype of `a` and `b` must be the same, one of {float32, float64,
complex64, complex128}. `a` and `b` are modified in place, an... | def _numba_linalg_solve(a, b):
"""
Solve the linear equation ax = b directly calling a Numba internal
function. The data in `a` and `b` are interpreted in Fortran order,
and dtype of `a` and `b` must be the same, one of {float32, float64,
complex64, complex128}. `a` and `b` are modified in place, an... | [
"Solve",
"the",
"linear",
"equation",
"ax",
"=",
"b",
"directly",
"calling",
"a",
"Numba",
"internal",
"function",
".",
"The",
"data",
"in",
"a",
"and",
"b",
"are",
"interpreted",
"in",
"Fortran",
"order",
"and",
"dtype",
"of",
"a",
"and",
"b",
"must",
... | QuantEcon/QuantEcon.py | python | https://github.com/QuantEcon/QuantEcon.py/blob/26a66c552f2a73967d7efb6e1f4b4c4985a12643/quantecon/util/numba.py#L20-L71 | [
"def",
"_numba_linalg_solve",
"(",
"a",
",",
"b",
")",
":",
"numba_xgesv",
"=",
"_LAPACK",
"(",
")",
".",
"numba_xgesv",
"(",
"a",
".",
"dtype",
")",
"kind",
"=",
"ord",
"(",
"_blas_kinds",
"[",
"a",
".",
"dtype",
"]",
")",
"def",
"_numba_linalg_solve_... | 26a66c552f2a73967d7efb6e1f4b4c4985a12643 |
train | comb_jit | Numba jitted function that computes N choose k. Return `0` if the
outcome exceeds the maximum value of `np.intp` or if N < 0, k < 0,
or k > N.
Parameters
----------
N : scalar(int)
k : scalar(int)
Returns
-------
val : scalar(int) | quantecon/util/numba.py | def comb_jit(N, k):
"""
Numba jitted function that computes N choose k. Return `0` if the
outcome exceeds the maximum value of `np.intp` or if N < 0, k < 0,
or k > N.
Parameters
----------
N : scalar(int)
k : scalar(int)
Returns
-------
val : scalar(int)
"""
# Fro... | def comb_jit(N, k):
"""
Numba jitted function that computes N choose k. Return `0` if the
outcome exceeds the maximum value of `np.intp` or if N < 0, k < 0,
or k > N.
Parameters
----------
N : scalar(int)
k : scalar(int)
Returns
-------
val : scalar(int)
"""
# Fro... | [
"Numba",
"jitted",
"function",
"that",
"computes",
"N",
"choose",
"k",
".",
"Return",
"0",
"if",
"the",
"outcome",
"exceeds",
"the",
"maximum",
"value",
"of",
"np",
".",
"intp",
"or",
"if",
"N",
"<",
"0",
"k",
"<",
"0",
"or",
"k",
">",
"N",
"."
] | QuantEcon/QuantEcon.py | python | https://github.com/QuantEcon/QuantEcon.py/blob/26a66c552f2a73967d7efb6e1f4b4c4985a12643/quantecon/util/numba.py#L75-L117 | [
"def",
"comb_jit",
"(",
"N",
",",
"k",
")",
":",
"# From scipy.special._comb_int_long",
"# github.com/scipy/scipy/blob/v1.0.0/scipy/special/_comb.pyx",
"INTP_MAX",
"=",
"np",
".",
"iinfo",
"(",
"np",
".",
"intp",
")",
".",
"max",
"if",
"N",
"<",
"0",
"or",
"k",
... | 26a66c552f2a73967d7efb6e1f4b4c4985a12643 |
train | IVP._integrate_fixed_trajectory | Generates a solution trajectory of fixed length. | quantecon/ivp.py | def _integrate_fixed_trajectory(self, h, T, step, relax):
"""Generates a solution trajectory of fixed length."""
# initialize the solution using initial condition
solution = np.hstack((self.t, self.y))
while self.successful():
self.integrate(self.t + h, step, relax)
... | def _integrate_fixed_trajectory(self, h, T, step, relax):
"""Generates a solution trajectory of fixed length."""
# initialize the solution using initial condition
solution = np.hstack((self.t, self.y))
while self.successful():
self.integrate(self.t + h, step, relax)
... | [
"Generates",
"a",
"solution",
"trajectory",
"of",
"fixed",
"length",
"."
] | QuantEcon/QuantEcon.py | python | https://github.com/QuantEcon/QuantEcon.py/blob/26a66c552f2a73967d7efb6e1f4b4c4985a12643/quantecon/ivp.py#L48-L66 | [
"def",
"_integrate_fixed_trajectory",
"(",
"self",
",",
"h",
",",
"T",
",",
"step",
",",
"relax",
")",
":",
"# initialize the solution using initial condition",
"solution",
"=",
"np",
".",
"hstack",
"(",
"(",
"self",
".",
"t",
",",
"self",
".",
"y",
")",
"... | 26a66c552f2a73967d7efb6e1f4b4c4985a12643 |
train | IVP._integrate_variable_trajectory | Generates a solution trajectory of variable length. | quantecon/ivp.py | def _integrate_variable_trajectory(self, h, g, tol, step, relax):
"""Generates a solution trajectory of variable length."""
# initialize the solution using initial condition
solution = np.hstack((self.t, self.y))
while self.successful():
self.integrate(self.t + h, step, rel... | def _integrate_variable_trajectory(self, h, g, tol, step, relax):
"""Generates a solution trajectory of variable length."""
# initialize the solution using initial condition
solution = np.hstack((self.t, self.y))
while self.successful():
self.integrate(self.t + h, step, rel... | [
"Generates",
"a",
"solution",
"trajectory",
"of",
"variable",
"length",
"."
] | QuantEcon/QuantEcon.py | python | https://github.com/QuantEcon/QuantEcon.py/blob/26a66c552f2a73967d7efb6e1f4b4c4985a12643/quantecon/ivp.py#L68-L84 | [
"def",
"_integrate_variable_trajectory",
"(",
"self",
",",
"h",
",",
"g",
",",
"tol",
",",
"step",
",",
"relax",
")",
":",
"# initialize the solution using initial condition",
"solution",
"=",
"np",
".",
"hstack",
"(",
"(",
"self",
".",
"t",
",",
"self",
"."... | 26a66c552f2a73967d7efb6e1f4b4c4985a12643 |
train | IVP._initialize_integrator | Initializes the integrator prior to integration. | quantecon/ivp.py | def _initialize_integrator(self, t0, y0, integrator, **kwargs):
"""Initializes the integrator prior to integration."""
# set the initial condition
self.set_initial_value(y0, t0)
# select the integrator
self.set_integrator(integrator, **kwargs) | def _initialize_integrator(self, t0, y0, integrator, **kwargs):
"""Initializes the integrator prior to integration."""
# set the initial condition
self.set_initial_value(y0, t0)
# select the integrator
self.set_integrator(integrator, **kwargs) | [
"Initializes",
"the",
"integrator",
"prior",
"to",
"integration",
"."
] | QuantEcon/QuantEcon.py | python | https://github.com/QuantEcon/QuantEcon.py/blob/26a66c552f2a73967d7efb6e1f4b4c4985a12643/quantecon/ivp.py#L86-L92 | [
"def",
"_initialize_integrator",
"(",
"self",
",",
"t0",
",",
"y0",
",",
"integrator",
",",
"*",
"*",
"kwargs",
")",
":",
"# set the initial condition",
"self",
".",
"set_initial_value",
"(",
"y0",
",",
"t0",
")",
"# select the integrator",
"self",
".",
"set_i... | 26a66c552f2a73967d7efb6e1f4b4c4985a12643 |
train | IVP.compute_residual | r"""
The residual is the difference between the derivative of the B-spline
approximation of the solution trajectory and the right-hand side of the
original ODE evaluated along the approximated solution trajectory.
Parameters
----------
traj : array_like (float)
... | quantecon/ivp.py | def compute_residual(self, traj, ti, k=3, ext=2):
r"""
The residual is the difference between the derivative of the B-spline
approximation of the solution trajectory and the right-hand side of the
original ODE evaluated along the approximated solution trajectory.
Parameters
... | def compute_residual(self, traj, ti, k=3, ext=2):
r"""
The residual is the difference between the derivative of the B-spline
approximation of the solution trajectory and the right-hand side of the
original ODE evaluated along the approximated solution trajectory.
Parameters
... | [
"r",
"The",
"residual",
"is",
"the",
"difference",
"between",
"the",
"derivative",
"of",
"the",
"B",
"-",
"spline",
"approximation",
"of",
"the",
"solution",
"trajectory",
"and",
"the",
"right",
"-",
"hand",
"side",
"of",
"the",
"original",
"ODE",
"evaluated... | QuantEcon/QuantEcon.py | python | https://github.com/QuantEcon/QuantEcon.py/blob/26a66c552f2a73967d7efb6e1f4b4c4985a12643/quantecon/ivp.py#L94-L137 | [
"def",
"compute_residual",
"(",
"self",
",",
"traj",
",",
"ti",
",",
"k",
"=",
"3",
",",
"ext",
"=",
"2",
")",
":",
"# B-spline approximations of the solution and its derivative",
"soln",
"=",
"self",
".",
"interpolate",
"(",
"traj",
",",
"ti",
",",
"k",
"... | 26a66c552f2a73967d7efb6e1f4b4c4985a12643 |
train | IVP.solve | r"""
Solve the IVP by integrating the ODE given some initial condition.
Parameters
----------
t0 : float
Initial condition for the independent variable.
y0 : array_like (float, shape=(n,))
Initial condition for the dependent variables.
h : float, ... | quantecon/ivp.py | def solve(self, t0, y0, h=1.0, T=None, g=None, tol=None,
integrator='dopri5', step=False, relax=False, **kwargs):
r"""
Solve the IVP by integrating the ODE given some initial condition.
Parameters
----------
t0 : float
Initial condition for the independ... | def solve(self, t0, y0, h=1.0, T=None, g=None, tol=None,
integrator='dopri5', step=False, relax=False, **kwargs):
r"""
Solve the IVP by integrating the ODE given some initial condition.
Parameters
----------
t0 : float
Initial condition for the independ... | [
"r",
"Solve",
"the",
"IVP",
"by",
"integrating",
"the",
"ODE",
"given",
"some",
"initial",
"condition",
"."
] | QuantEcon/QuantEcon.py | python | https://github.com/QuantEcon/QuantEcon.py/blob/26a66c552f2a73967d7efb6e1f4b4c4985a12643/quantecon/ivp.py#L139-L191 | [
"def",
"solve",
"(",
"self",
",",
"t0",
",",
"y0",
",",
"h",
"=",
"1.0",
",",
"T",
"=",
"None",
",",
"g",
"=",
"None",
",",
"tol",
"=",
"None",
",",
"integrator",
"=",
"'dopri5'",
",",
"step",
"=",
"False",
",",
"relax",
"=",
"False",
",",
"*... | 26a66c552f2a73967d7efb6e1f4b4c4985a12643 |
train | IVP.interpolate | r"""
Parametric B-spline interpolation in N-dimensions.
Parameters
----------
traj : array_like (float)
Solution trajectory providing the data points for constructing the
B-spline representation.
ti : array_like (float)
Array of values for the... | quantecon/ivp.py | def interpolate(self, traj, ti, k=3, der=0, ext=2):
r"""
Parametric B-spline interpolation in N-dimensions.
Parameters
----------
traj : array_like (float)
Solution trajectory providing the data points for constructing the
B-spline representation.
... | def interpolate(self, traj, ti, k=3, der=0, ext=2):
r"""
Parametric B-spline interpolation in N-dimensions.
Parameters
----------
traj : array_like (float)
Solution trajectory providing the data points for constructing the
B-spline representation.
... | [
"r",
"Parametric",
"B",
"-",
"spline",
"interpolation",
"in",
"N",
"-",
"dimensions",
"."
] | QuantEcon/QuantEcon.py | python | https://github.com/QuantEcon/QuantEcon.py/blob/26a66c552f2a73967d7efb6e1f4b4c4985a12643/quantecon/ivp.py#L193-L238 | [
"def",
"interpolate",
"(",
"self",
",",
"traj",
",",
"ti",
",",
"k",
"=",
"3",
",",
"der",
"=",
"0",
",",
"ext",
"=",
"2",
")",
":",
"# array of parameter values",
"u",
"=",
"traj",
"[",
":",
",",
"0",
"]",
"# build list of input arrays",
"n",
"=",
... | 26a66c552f2a73967d7efb6e1f4b4c4985a12643 |
train | lorenz_curve | Calculates the Lorenz Curve, a graphical representation of the distribution of income
or wealth.
It returns the cumulative share of people (x-axis) and the cumulative share of income earned
Parameters
----------
y : array_like(float or int, ndim=1)
Array of income/wealth for each individua... | quantecon/inequality.py | def lorenz_curve(y):
"""
Calculates the Lorenz Curve, a graphical representation of the distribution of income
or wealth.
It returns the cumulative share of people (x-axis) and the cumulative share of income earned
Parameters
----------
y : array_like(float or int, ndim=1)
Array of... | def lorenz_curve(y):
"""
Calculates the Lorenz Curve, a graphical representation of the distribution of income
or wealth.
It returns the cumulative share of people (x-axis) and the cumulative share of income earned
Parameters
----------
y : array_like(float or int, ndim=1)
Array of... | [
"Calculates",
"the",
"Lorenz",
"Curve",
"a",
"graphical",
"representation",
"of",
"the",
"distribution",
"of",
"income",
"or",
"wealth",
"."
] | QuantEcon/QuantEcon.py | python | https://github.com/QuantEcon/QuantEcon.py/blob/26a66c552f2a73967d7efb6e1f4b4c4985a12643/quantecon/inequality.py#L11-L52 | [
"def",
"lorenz_curve",
"(",
"y",
")",
":",
"n",
"=",
"len",
"(",
"y",
")",
"y",
"=",
"np",
".",
"sort",
"(",
"y",
")",
"s",
"=",
"np",
".",
"zeros",
"(",
"n",
"+",
"1",
")",
"s",
"[",
"1",
":",
"]",
"=",
"np",
".",
"cumsum",
"(",
"y",
... | 26a66c552f2a73967d7efb6e1f4b4c4985a12643 |
train | gini_coefficient | r"""
Implements the Gini inequality index
Parameters
-----------
y : array_like(float)
Array of income/wealth for each individual. Ordered or unordered is fine
Returns
-------
Gini index: float
The gini index describing the inequality of the array of income/wealth
Refe... | quantecon/inequality.py | def gini_coefficient(y):
r"""
Implements the Gini inequality index
Parameters
-----------
y : array_like(float)
Array of income/wealth for each individual. Ordered or unordered is fine
Returns
-------
Gini index: float
The gini index describing the inequality of the arr... | def gini_coefficient(y):
r"""
Implements the Gini inequality index
Parameters
-----------
y : array_like(float)
Array of income/wealth for each individual. Ordered or unordered is fine
Returns
-------
Gini index: float
The gini index describing the inequality of the arr... | [
"r",
"Implements",
"the",
"Gini",
"inequality",
"index"
] | QuantEcon/QuantEcon.py | python | https://github.com/QuantEcon/QuantEcon.py/blob/26a66c552f2a73967d7efb6e1f4b4c4985a12643/quantecon/inequality.py#L56-L80 | [
"def",
"gini_coefficient",
"(",
"y",
")",
":",
"n",
"=",
"len",
"(",
"y",
")",
"i_sum",
"=",
"np",
".",
"zeros",
"(",
"n",
")",
"for",
"i",
"in",
"prange",
"(",
"n",
")",
":",
"for",
"j",
"in",
"range",
"(",
"n",
")",
":",
"i_sum",
"[",
"i"... | 26a66c552f2a73967d7efb6e1f4b4c4985a12643 |
train | shorrocks_index | r"""
Implements Shorrocks mobility index
Parameters
-----------
A : array_like(float)
Square matrix with transition probabilities (mobility matrix) of
dimension m
Returns
--------
Shorrocks index: float
The Shorrocks mobility index calculated as
.. math::
... | quantecon/inequality.py | def shorrocks_index(A):
r"""
Implements Shorrocks mobility index
Parameters
-----------
A : array_like(float)
Square matrix with transition probabilities (mobility matrix) of
dimension m
Returns
--------
Shorrocks index: float
The Shorrocks mobility index calcul... | def shorrocks_index(A):
r"""
Implements Shorrocks mobility index
Parameters
-----------
A : array_like(float)
Square matrix with transition probabilities (mobility matrix) of
dimension m
Returns
--------
Shorrocks index: float
The Shorrocks mobility index calcul... | [
"r",
"Implements",
"Shorrocks",
"mobility",
"index"
] | QuantEcon/QuantEcon.py | python | https://github.com/QuantEcon/QuantEcon.py/blob/26a66c552f2a73967d7efb6e1f4b4c4985a12643/quantecon/inequality.py#L83-L119 | [
"def",
"shorrocks_index",
"(",
"A",
")",
":",
"A",
"=",
"np",
".",
"asarray",
"(",
"A",
")",
"# Convert to array if not already",
"m",
",",
"n",
"=",
"A",
".",
"shape",
"if",
"m",
"!=",
"n",
":",
"raise",
"ValueError",
"(",
"'A must be a square matrix'",
... | 26a66c552f2a73967d7efb6e1f4b4c4985a12643 |
train | DiscreteRV.q | Setter method for q. | quantecon/discrete_rv.py | def q(self, val):
"""
Setter method for q.
"""
self._q = np.asarray(val)
self.Q = cumsum(val) | def q(self, val):
"""
Setter method for q.
"""
self._q = np.asarray(val)
self.Q = cumsum(val) | [
"Setter",
"method",
"for",
"q",
"."
] | QuantEcon/QuantEcon.py | python | https://github.com/QuantEcon/QuantEcon.py/blob/26a66c552f2a73967d7efb6e1f4b4c4985a12643/quantecon/discrete_rv.py#L49-L55 | [
"def",
"q",
"(",
"self",
",",
"val",
")",
":",
"self",
".",
"_q",
"=",
"np",
".",
"asarray",
"(",
"val",
")",
"self",
".",
"Q",
"=",
"cumsum",
"(",
"val",
")"
] | 26a66c552f2a73967d7efb6e1f4b4c4985a12643 |
train | DiscreteRV.draw | Returns k draws from q.
For each such draw, the value i is returned with probability
q[i].
Parameters
-----------
k : scalar(int), optional
Number of draws to be returned
random_state : int or np.random.RandomState, optional
Random seed (integer... | quantecon/discrete_rv.py | def draw(self, k=1, random_state=None):
"""
Returns k draws from q.
For each such draw, the value i is returned with probability
q[i].
Parameters
-----------
k : scalar(int), optional
Number of draws to be returned
random_state : int or np.r... | def draw(self, k=1, random_state=None):
"""
Returns k draws from q.
For each such draw, the value i is returned with probability
q[i].
Parameters
-----------
k : scalar(int), optional
Number of draws to be returned
random_state : int or np.r... | [
"Returns",
"k",
"draws",
"from",
"q",
"."
] | QuantEcon/QuantEcon.py | python | https://github.com/QuantEcon/QuantEcon.py/blob/26a66c552f2a73967d7efb6e1f4b4c4985a12643/quantecon/discrete_rv.py#L57-L84 | [
"def",
"draw",
"(",
"self",
",",
"k",
"=",
"1",
",",
"random_state",
"=",
"None",
")",
":",
"random_state",
"=",
"check_random_state",
"(",
"random_state",
")",
"return",
"self",
".",
"Q",
".",
"searchsorted",
"(",
"random_state",
".",
"uniform",
"(",
"0... | 26a66c552f2a73967d7efb6e1f4b4c4985a12643 |
train | random_markov_chain | Return a randomly sampled MarkovChain instance with n states, where
each state has k states with positive transition probability.
Parameters
----------
n : scalar(int)
Number of states.
k : scalar(int), optional(default=None)
Number of states that may be reached from each state wit... | quantecon/markov/random.py | def random_markov_chain(n, k=None, sparse=False, random_state=None):
"""
Return a randomly sampled MarkovChain instance with n states, where
each state has k states with positive transition probability.
Parameters
----------
n : scalar(int)
Number of states.
k : scalar(int), option... | def random_markov_chain(n, k=None, sparse=False, random_state=None):
"""
Return a randomly sampled MarkovChain instance with n states, where
each state has k states with positive transition probability.
Parameters
----------
n : scalar(int)
Number of states.
k : scalar(int), option... | [
"Return",
"a",
"randomly",
"sampled",
"MarkovChain",
"instance",
"with",
"n",
"states",
"where",
"each",
"state",
"has",
"k",
"states",
"with",
"positive",
"transition",
"probability",
"."
] | QuantEcon/QuantEcon.py | python | https://github.com/QuantEcon/QuantEcon.py/blob/26a66c552f2a73967d7efb6e1f4b4c4985a12643/quantecon/markov/random.py#L15-L60 | [
"def",
"random_markov_chain",
"(",
"n",
",",
"k",
"=",
"None",
",",
"sparse",
"=",
"False",
",",
"random_state",
"=",
"None",
")",
":",
"P",
"=",
"random_stochastic_matrix",
"(",
"n",
",",
"k",
",",
"sparse",
",",
"format",
"=",
"'csr'",
",",
"random_s... | 26a66c552f2a73967d7efb6e1f4b4c4985a12643 |
train | random_stochastic_matrix | Return a randomly sampled n x n stochastic matrix with k nonzero
entries for each row.
Parameters
----------
n : scalar(int)
Number of states.
k : scalar(int), optional(default=None)
Number of nonzero entries in each row of the matrix. Set to n if
not specified.
sparse... | quantecon/markov/random.py | def random_stochastic_matrix(n, k=None, sparse=False, format='csr',
random_state=None):
"""
Return a randomly sampled n x n stochastic matrix with k nonzero
entries for each row.
Parameters
----------
n : scalar(int)
Number of states.
k : scalar(int), o... | def random_stochastic_matrix(n, k=None, sparse=False, format='csr',
random_state=None):
"""
Return a randomly sampled n x n stochastic matrix with k nonzero
entries for each row.
Parameters
----------
n : scalar(int)
Number of states.
k : scalar(int), o... | [
"Return",
"a",
"randomly",
"sampled",
"n",
"x",
"n",
"stochastic",
"matrix",
"with",
"k",
"nonzero",
"entries",
"for",
"each",
"row",
"."
] | QuantEcon/QuantEcon.py | python | https://github.com/QuantEcon/QuantEcon.py/blob/26a66c552f2a73967d7efb6e1f4b4c4985a12643/quantecon/markov/random.py#L63-L103 | [
"def",
"random_stochastic_matrix",
"(",
"n",
",",
"k",
"=",
"None",
",",
"sparse",
"=",
"False",
",",
"format",
"=",
"'csr'",
",",
"random_state",
"=",
"None",
")",
":",
"P",
"=",
"_random_stochastic_matrix",
"(",
"m",
"=",
"n",
",",
"n",
"=",
"n",
"... | 26a66c552f2a73967d7efb6e1f4b4c4985a12643 |
train | _random_stochastic_matrix | Generate a "non-square stochastic matrix" of shape (m, n), which
contains as rows m probability vectors of length n with k nonzero
entries.
For other parameters, see `random_stochastic_matrix`. | quantecon/markov/random.py | def _random_stochastic_matrix(m, n, k=None, sparse=False, format='csr',
random_state=None):
"""
Generate a "non-square stochastic matrix" of shape (m, n), which
contains as rows m probability vectors of length n with k nonzero
entries.
For other parameters, see `random... | def _random_stochastic_matrix(m, n, k=None, sparse=False, format='csr',
random_state=None):
"""
Generate a "non-square stochastic matrix" of shape (m, n), which
contains as rows m probability vectors of length n with k nonzero
entries.
For other parameters, see `random... | [
"Generate",
"a",
"non",
"-",
"square",
"stochastic",
"matrix",
"of",
"shape",
"(",
"m",
"n",
")",
"which",
"contains",
"as",
"rows",
"m",
"probability",
"vectors",
"of",
"length",
"n",
"with",
"k",
"nonzero",
"entries",
"."
] | QuantEcon/QuantEcon.py | python | https://github.com/QuantEcon/QuantEcon.py/blob/26a66c552f2a73967d7efb6e1f4b4c4985a12643/quantecon/markov/random.py#L106-L142 | [
"def",
"_random_stochastic_matrix",
"(",
"m",
",",
"n",
",",
"k",
"=",
"None",
",",
"sparse",
"=",
"False",
",",
"format",
"=",
"'csr'",
",",
"random_state",
"=",
"None",
")",
":",
"if",
"k",
"is",
"None",
":",
"k",
"=",
"n",
"# m prob vectors of dimen... | 26a66c552f2a73967d7efb6e1f4b4c4985a12643 |
train | random_discrete_dp | Generate a DiscreteDP randomly. The reward values are drawn from the
normal distribution with mean 0 and standard deviation `scale`.
Parameters
----------
num_states : scalar(int)
Number of states.
num_actions : scalar(int)
Number of actions.
beta : scalar(float), optional(def... | quantecon/markov/random.py | def random_discrete_dp(num_states, num_actions, beta=None,
k=None, scale=1, sparse=False, sa_pair=False,
random_state=None):
"""
Generate a DiscreteDP randomly. The reward values are drawn from the
normal distribution with mean 0 and standard deviation `scale`.
Parameters
... | def random_discrete_dp(num_states, num_actions, beta=None,
k=None, scale=1, sparse=False, sa_pair=False,
random_state=None):
"""
Generate a DiscreteDP randomly. The reward values are drawn from the
normal distribution with mean 0 and standard deviation `scale`.
Parameters
... | [
"Generate",
"a",
"DiscreteDP",
"randomly",
".",
"The",
"reward",
"values",
"are",
"drawn",
"from",
"the",
"normal",
"distribution",
"with",
"mean",
"0",
"and",
"standard",
"deviation",
"scale",
"."
] | QuantEcon/QuantEcon.py | python | https://github.com/QuantEcon/QuantEcon.py/blob/26a66c552f2a73967d7efb6e1f4b4c4985a12643/quantecon/markov/random.py#L145-L213 | [
"def",
"random_discrete_dp",
"(",
"num_states",
",",
"num_actions",
",",
"beta",
"=",
"None",
",",
"k",
"=",
"None",
",",
"scale",
"=",
"1",
",",
"sparse",
"=",
"False",
",",
"sa_pair",
"=",
"False",
",",
"random_state",
"=",
"None",
")",
":",
"if",
... | 26a66c552f2a73967d7efb6e1f4b4c4985a12643 |
train | RBLQ.d_operator | r"""
The D operator, mapping P into
.. math::
D(P) := P + PC(\theta I - C'PC)^{-1} C'P.
Parameters
----------
P : array_like(float, ndim=2)
A matrix that should be n x n
Returns
-------
dP : array_like(float, ndim=2)
... | quantecon/robustlq.py | def d_operator(self, P):
r"""
The D operator, mapping P into
.. math::
D(P) := P + PC(\theta I - C'PC)^{-1} C'P.
Parameters
----------
P : array_like(float, ndim=2)
A matrix that should be n x n
Returns
-------
dP : arra... | def d_operator(self, P):
r"""
The D operator, mapping P into
.. math::
D(P) := P + PC(\theta I - C'PC)^{-1} C'P.
Parameters
----------
P : array_like(float, ndim=2)
A matrix that should be n x n
Returns
-------
dP : arra... | [
"r",
"The",
"D",
"operator",
"mapping",
"P",
"into"
] | QuantEcon/QuantEcon.py | python | https://github.com/QuantEcon/QuantEcon.py/blob/26a66c552f2a73967d7efb6e1f4b4c4985a12643/quantecon/robustlq.py#L90-L116 | [
"def",
"d_operator",
"(",
"self",
",",
"P",
")",
":",
"C",
",",
"theta",
"=",
"self",
".",
"C",
",",
"self",
".",
"theta",
"I",
"=",
"np",
".",
"identity",
"(",
"self",
".",
"j",
")",
"S1",
"=",
"dot",
"(",
"P",
",",
"C",
")",
"S2",
"=",
... | 26a66c552f2a73967d7efb6e1f4b4c4985a12643 |
train | RBLQ.b_operator | r"""
The B operator, mapping P into
.. math::
B(P) := R - \beta^2 A'PB(Q + \beta B'PB)^{-1}B'PA + \beta A'PA
and also returning
.. math::
F := (Q + \beta B'PB)^{-1} \beta B'PA
Parameters
----------
P : array_like(float, ndim=2)
... | quantecon/robustlq.py | def b_operator(self, P):
r"""
The B operator, mapping P into
.. math::
B(P) := R - \beta^2 A'PB(Q + \beta B'PB)^{-1}B'PA + \beta A'PA
and also returning
.. math::
F := (Q + \beta B'PB)^{-1} \beta B'PA
Parameters
----------
P :... | def b_operator(self, P):
r"""
The B operator, mapping P into
.. math::
B(P) := R - \beta^2 A'PB(Q + \beta B'PB)^{-1}B'PA + \beta A'PA
and also returning
.. math::
F := (Q + \beta B'PB)^{-1} \beta B'PA
Parameters
----------
P :... | [
"r",
"The",
"B",
"operator",
"mapping",
"P",
"into"
] | QuantEcon/QuantEcon.py | python | https://github.com/QuantEcon/QuantEcon.py/blob/26a66c552f2a73967d7efb6e1f4b4c4985a12643/quantecon/robustlq.py#L118-L153 | [
"def",
"b_operator",
"(",
"self",
",",
"P",
")",
":",
"A",
",",
"B",
",",
"Q",
",",
"R",
",",
"beta",
"=",
"self",
".",
"A",
",",
"self",
".",
"B",
",",
"self",
".",
"Q",
",",
"self",
".",
"R",
",",
"self",
".",
"beta",
"S1",
"=",
"Q",
... | 26a66c552f2a73967d7efb6e1f4b4c4985a12643 |
train | RBLQ.robust_rule | This method solves the robust control problem by tricking it
into a stacked LQ problem, as described in chapter 2 of Hansen-
Sargent's text "Robustness." The optimal control with observed
state is
.. math::
u_t = - F x_t
And the value function is :math:`-x'Px`
... | quantecon/robustlq.py | def robust_rule(self, method='doubling'):
"""
This method solves the robust control problem by tricking it
into a stacked LQ problem, as described in chapter 2 of Hansen-
Sargent's text "Robustness." The optimal control with observed
state is
.. math::
u_t ... | def robust_rule(self, method='doubling'):
"""
This method solves the robust control problem by tricking it
into a stacked LQ problem, as described in chapter 2 of Hansen-
Sargent's text "Robustness." The optimal control with observed
state is
.. math::
u_t ... | [
"This",
"method",
"solves",
"the",
"robust",
"control",
"problem",
"by",
"tricking",
"it",
"into",
"a",
"stacked",
"LQ",
"problem",
"as",
"described",
"in",
"chapter",
"2",
"of",
"Hansen",
"-",
"Sargent",
"s",
"text",
"Robustness",
".",
"The",
"optimal",
"... | QuantEcon/QuantEcon.py | python | https://github.com/QuantEcon/QuantEcon.py/blob/26a66c552f2a73967d7efb6e1f4b4c4985a12643/quantecon/robustlq.py#L155-L212 | [
"def",
"robust_rule",
"(",
"self",
",",
"method",
"=",
"'doubling'",
")",
":",
"# == Simplify names == #",
"A",
",",
"B",
",",
"C",
",",
"Q",
",",
"R",
"=",
"self",
".",
"A",
",",
"self",
".",
"B",
",",
"self",
".",
"C",
",",
"self",
".",
"Q",
... | 26a66c552f2a73967d7efb6e1f4b4c4985a12643 |
train | RBLQ.robust_rule_simple | A simple algorithm for computing the robust policy F and the
corresponding value function P, based around straightforward
iteration with the robust Bellman operator. This function is
easier to understand but one or two orders of magnitude slower
than self.robust_rule(). For more inform... | quantecon/robustlq.py | def robust_rule_simple(self, P_init=None, max_iter=80, tol=1e-8):
"""
A simple algorithm for computing the robust policy F and the
corresponding value function P, based around straightforward
iteration with the robust Bellman operator. This function is
easier to understand but o... | def robust_rule_simple(self, P_init=None, max_iter=80, tol=1e-8):
"""
A simple algorithm for computing the robust policy F and the
corresponding value function P, based around straightforward
iteration with the robust Bellman operator. This function is
easier to understand but o... | [
"A",
"simple",
"algorithm",
"for",
"computing",
"the",
"robust",
"policy",
"F",
"and",
"the",
"corresponding",
"value",
"function",
"P",
"based",
"around",
"straightforward",
"iteration",
"with",
"the",
"robust",
"Bellman",
"operator",
".",
"This",
"function",
"... | QuantEcon/QuantEcon.py | python | https://github.com/QuantEcon/QuantEcon.py/blob/26a66c552f2a73967d7efb6e1f4b4c4985a12643/quantecon/robustlq.py#L214-L261 | [
"def",
"robust_rule_simple",
"(",
"self",
",",
"P_init",
"=",
"None",
",",
"max_iter",
"=",
"80",
",",
"tol",
"=",
"1e-8",
")",
":",
"# == Simplify names == #",
"A",
",",
"B",
",",
"C",
",",
"Q",
",",
"R",
"=",
"self",
".",
"A",
",",
"self",
".",
... | 26a66c552f2a73967d7efb6e1f4b4c4985a12643 |
train | RBLQ.F_to_K | Compute agent 2's best cost-minimizing response K, given F.
Parameters
----------
F : array_like(float, ndim=2)
A k x n array
method : str, optional(default='doubling')
Solution method used in solving the associated Riccati
equation, str in {'doubling... | quantecon/robustlq.py | def F_to_K(self, F, method='doubling'):
"""
Compute agent 2's best cost-minimizing response K, given F.
Parameters
----------
F : array_like(float, ndim=2)
A k x n array
method : str, optional(default='doubling')
Solution method used in solving th... | def F_to_K(self, F, method='doubling'):
"""
Compute agent 2's best cost-minimizing response K, given F.
Parameters
----------
F : array_like(float, ndim=2)
A k x n array
method : str, optional(default='doubling')
Solution method used in solving th... | [
"Compute",
"agent",
"2",
"s",
"best",
"cost",
"-",
"minimizing",
"response",
"K",
"given",
"F",
"."
] | QuantEcon/QuantEcon.py | python | https://github.com/QuantEcon/QuantEcon.py/blob/26a66c552f2a73967d7efb6e1f4b4c4985a12643/quantecon/robustlq.py#L263-L290 | [
"def",
"F_to_K",
"(",
"self",
",",
"F",
",",
"method",
"=",
"'doubling'",
")",
":",
"Q2",
"=",
"self",
".",
"beta",
"*",
"self",
".",
"theta",
"R2",
"=",
"-",
"self",
".",
"R",
"-",
"dot",
"(",
"F",
".",
"T",
",",
"dot",
"(",
"self",
".",
"... | 26a66c552f2a73967d7efb6e1f4b4c4985a12643 |
train | RBLQ.K_to_F | Compute agent 1's best value-maximizing response F, given K.
Parameters
----------
K : array_like(float, ndim=2)
A j x n array
method : str, optional(default='doubling')
Solution method used in solving the associated Riccati
equation, str in {'doublin... | quantecon/robustlq.py | def K_to_F(self, K, method='doubling'):
"""
Compute agent 1's best value-maximizing response F, given K.
Parameters
----------
K : array_like(float, ndim=2)
A j x n array
method : str, optional(default='doubling')
Solution method used in solving t... | def K_to_F(self, K, method='doubling'):
"""
Compute agent 1's best value-maximizing response F, given K.
Parameters
----------
K : array_like(float, ndim=2)
A j x n array
method : str, optional(default='doubling')
Solution method used in solving t... | [
"Compute",
"agent",
"1",
"s",
"best",
"value",
"-",
"maximizing",
"response",
"F",
"given",
"K",
"."
] | QuantEcon/QuantEcon.py | python | https://github.com/QuantEcon/QuantEcon.py/blob/26a66c552f2a73967d7efb6e1f4b4c4985a12643/quantecon/robustlq.py#L292-L319 | [
"def",
"K_to_F",
"(",
"self",
",",
"K",
",",
"method",
"=",
"'doubling'",
")",
":",
"A1",
"=",
"self",
".",
"A",
"+",
"dot",
"(",
"self",
".",
"C",
",",
"K",
")",
"B1",
"=",
"self",
".",
"B",
"Q1",
"=",
"self",
".",
"Q",
"R1",
"=",
"self",
... | 26a66c552f2a73967d7efb6e1f4b4c4985a12643 |
train | RBLQ.compute_deterministic_entropy | r"""
Given K and F, compute the value of deterministic entropy, which
is
.. math::
\sum_t \beta^t x_t' K'K x_t`
with
.. math::
x_{t+1} = (A - BF + CK) x_t
Parameters
----------
F : array_like(float, ndim=2)
The po... | quantecon/robustlq.py | def compute_deterministic_entropy(self, F, K, x0):
r"""
Given K and F, compute the value of deterministic entropy, which
is
.. math::
\sum_t \beta^t x_t' K'K x_t`
with
.. math::
x_{t+1} = (A - BF + CK) x_t
Parameters
--------... | def compute_deterministic_entropy(self, F, K, x0):
r"""
Given K and F, compute the value of deterministic entropy, which
is
.. math::
\sum_t \beta^t x_t' K'K x_t`
with
.. math::
x_{t+1} = (A - BF + CK) x_t
Parameters
--------... | [
"r"
] | QuantEcon/QuantEcon.py | python | https://github.com/QuantEcon/QuantEcon.py/blob/26a66c552f2a73967d7efb6e1f4b4c4985a12643/quantecon/robustlq.py#L321-L357 | [
"def",
"compute_deterministic_entropy",
"(",
"self",
",",
"F",
",",
"K",
",",
"x0",
")",
":",
"H0",
"=",
"dot",
"(",
"K",
".",
"T",
",",
"K",
")",
"C0",
"=",
"np",
".",
"zeros",
"(",
"(",
"self",
".",
"n",
",",
"1",
")",
")",
"A0",
"=",
"se... | 26a66c552f2a73967d7efb6e1f4b4c4985a12643 |
train | RBLQ.evaluate_F | Given a fixed policy F, with the interpretation :math:`u = -F x`, this
function computes the matrix :math:`P_F` and constant :math:`d_F`
associated with discounted cost :math:`J_F(x) = x' P_F x + d_F`
Parameters
----------
F : array_like(float, ndim=2)
The policy fun... | quantecon/robustlq.py | def evaluate_F(self, F):
"""
Given a fixed policy F, with the interpretation :math:`u = -F x`, this
function computes the matrix :math:`P_F` and constant :math:`d_F`
associated with discounted cost :math:`J_F(x) = x' P_F x + d_F`
Parameters
----------
F : array_l... | def evaluate_F(self, F):
"""
Given a fixed policy F, with the interpretation :math:`u = -F x`, this
function computes the matrix :math:`P_F` and constant :math:`d_F`
associated with discounted cost :math:`J_F(x) = x' P_F x + d_F`
Parameters
----------
F : array_l... | [
"Given",
"a",
"fixed",
"policy",
"F",
"with",
"the",
"interpretation",
":",
"math",
":",
"u",
"=",
"-",
"F",
"x",
"this",
"function",
"computes",
"the",
"matrix",
":",
"math",
":",
"P_F",
"and",
"constant",
":",
"math",
":",
"d_F",
"associated",
"with"... | QuantEcon/QuantEcon.py | python | https://github.com/QuantEcon/QuantEcon.py/blob/26a66c552f2a73967d7efb6e1f4b4c4985a12643/quantecon/robustlq.py#L359-L402 | [
"def",
"evaluate_F",
"(",
"self",
",",
"F",
")",
":",
"# == Simplify names == #",
"Q",
",",
"R",
",",
"A",
",",
"B",
",",
"C",
"=",
"self",
".",
"Q",
",",
"self",
".",
"R",
",",
"self",
".",
"A",
",",
"self",
".",
"B",
",",
"self",
".",
"C",
... | 26a66c552f2a73967d7efb6e1f4b4c4985a12643 |
train | EmbeddedSphinxShell.process_input_line | process the input, capturing stdout | docs/sphinxext/ipython_directive.py | def process_input_line(self, line, store_history=True):
"""process the input, capturing stdout"""
#print "input='%s'"%self.input
stdout = sys.stdout
splitter = self.IP.input_splitter
try:
sys.stdout = self.cout
splitter.push(line)
more = splitt... | def process_input_line(self, line, store_history=True):
"""process the input, capturing stdout"""
#print "input='%s'"%self.input
stdout = sys.stdout
splitter = self.IP.input_splitter
try:
sys.stdout = self.cout
splitter.push(line)
more = splitt... | [
"process",
"the",
"input",
"capturing",
"stdout"
] | QuantEcon/QuantEcon.py | python | https://github.com/QuantEcon/QuantEcon.py/blob/26a66c552f2a73967d7efb6e1f4b4c4985a12643/docs/sphinxext/ipython_directive.py#L247-L260 | [
"def",
"process_input_line",
"(",
"self",
",",
"line",
",",
"store_history",
"=",
"True",
")",
":",
"#print \"input='%s'\"%self.input",
"stdout",
"=",
"sys",
".",
"stdout",
"splitter",
"=",
"self",
".",
"IP",
".",
"input_splitter",
"try",
":",
"sys",
".",
"s... | 26a66c552f2a73967d7efb6e1f4b4c4985a12643 |
train | EmbeddedSphinxShell.process_image | # build out an image directive like
# .. image:: somefile.png
# :width 4in
#
# from an input like
# savefig somefile.png width=4in | docs/sphinxext/ipython_directive.py | def process_image(self, decorator):
"""
# build out an image directive like
# .. image:: somefile.png
# :width 4in
#
# from an input like
# savefig somefile.png width=4in
"""
savefig_dir = self.savefig_dir
source_dir = self.source_dir
... | def process_image(self, decorator):
"""
# build out an image directive like
# .. image:: somefile.png
# :width 4in
#
# from an input like
# savefig somefile.png width=4in
"""
savefig_dir = self.savefig_dir
source_dir = self.source_dir
... | [
"#",
"build",
"out",
"an",
"image",
"directive",
"like",
"#",
"..",
"image",
"::",
"somefile",
".",
"png",
"#",
":",
"width",
"4in",
"#",
"#",
"from",
"an",
"input",
"like",
"#",
"savefig",
"somefile",
".",
"png",
"width",
"=",
"4in"
] | QuantEcon/QuantEcon.py | python | https://github.com/QuantEcon/QuantEcon.py/blob/26a66c552f2a73967d7efb6e1f4b4c4985a12643/docs/sphinxext/ipython_directive.py#L262-L289 | [
"def",
"process_image",
"(",
"self",
",",
"decorator",
")",
":",
"savefig_dir",
"=",
"self",
".",
"savefig_dir",
"source_dir",
"=",
"self",
".",
"source_dir",
"saveargs",
"=",
"decorator",
".",
"split",
"(",
"' '",
")",
"filename",
"=",
"saveargs",
"[",
"1... | 26a66c552f2a73967d7efb6e1f4b4c4985a12643 |
train | EmbeddedSphinxShell.process_input | Process data block for INPUT token. | docs/sphinxext/ipython_directive.py | def process_input(self, data, input_prompt, lineno):
"""Process data block for INPUT token."""
decorator, input, rest = data
image_file = None
image_directive = None
#print 'INPUT:', data # dbg
is_verbatim = decorator=='@verbatim' or self.is_verbatim
is_doctest =... | def process_input(self, data, input_prompt, lineno):
"""Process data block for INPUT token."""
decorator, input, rest = data
image_file = None
image_directive = None
#print 'INPUT:', data # dbg
is_verbatim = decorator=='@verbatim' or self.is_verbatim
is_doctest =... | [
"Process",
"data",
"block",
"for",
"INPUT",
"token",
"."
] | QuantEcon/QuantEcon.py | python | https://github.com/QuantEcon/QuantEcon.py/blob/26a66c552f2a73967d7efb6e1f4b4c4985a12643/docs/sphinxext/ipython_directive.py#L293-L362 | [
"def",
"process_input",
"(",
"self",
",",
"data",
",",
"input_prompt",
",",
"lineno",
")",
":",
"decorator",
",",
"input",
",",
"rest",
"=",
"data",
"image_file",
"=",
"None",
"image_directive",
"=",
"None",
"#print 'INPUT:', data # dbg",
"is_verbatim",
"=",
... | 26a66c552f2a73967d7efb6e1f4b4c4985a12643 |
train | EmbeddedSphinxShell.process_output | Process data block for OUTPUT token. | docs/sphinxext/ipython_directive.py | def process_output(self, data, output_prompt,
input_lines, output, is_doctest, image_file):
"""Process data block for OUTPUT token."""
if is_doctest:
submitted = data.strip()
found = output
if found is not None:
found = found.str... | def process_output(self, data, output_prompt,
input_lines, output, is_doctest, image_file):
"""Process data block for OUTPUT token."""
if is_doctest:
submitted = data.strip()
found = output
if found is not None:
found = found.str... | [
"Process",
"data",
"block",
"for",
"OUTPUT",
"token",
"."
] | QuantEcon/QuantEcon.py | python | https://github.com/QuantEcon/QuantEcon.py/blob/26a66c552f2a73967d7efb6e1f4b4c4985a12643/docs/sphinxext/ipython_directive.py#L365-L391 | [
"def",
"process_output",
"(",
"self",
",",
"data",
",",
"output_prompt",
",",
"input_lines",
",",
"output",
",",
"is_doctest",
",",
"image_file",
")",
":",
"if",
"is_doctest",
":",
"submitted",
"=",
"data",
".",
"strip",
"(",
")",
"found",
"=",
"output",
... | 26a66c552f2a73967d7efb6e1f4b4c4985a12643 |
train | EmbeddedSphinxShell.process_pure_python | content is a list of strings. it is unedited directive conent
This runs it line by line in the InteractiveShell, prepends
prompts as needed capturing stderr and stdout, then returns
the content as a list as if it were ipython code | docs/sphinxext/ipython_directive.py | def process_pure_python(self, content):
"""
content is a list of strings. it is unedited directive conent
This runs it line by line in the InteractiveShell, prepends
prompts as needed capturing stderr and stdout, then returns
the content as a list as if it were ipython code
... | def process_pure_python(self, content):
"""
content is a list of strings. it is unedited directive conent
This runs it line by line in the InteractiveShell, prepends
prompts as needed capturing stderr and stdout, then returns
the content as a list as if it were ipython code
... | [
"content",
"is",
"a",
"list",
"of",
"strings",
".",
"it",
"is",
"unedited",
"directive",
"conent"
] | QuantEcon/QuantEcon.py | python | https://github.com/QuantEcon/QuantEcon.py/blob/26a66c552f2a73967d7efb6e1f4b4c4985a12643/docs/sphinxext/ipython_directive.py#L456-L533 | [
"def",
"process_pure_python",
"(",
"self",
",",
"content",
")",
":",
"output",
"=",
"[",
"]",
"savefig",
"=",
"False",
"# keep up with this to clear figure",
"multiline",
"=",
"False",
"# to handle line continuation",
"fmtin",
"=",
"self",
".",
"promptin",
"for",
... | 26a66c552f2a73967d7efb6e1f4b4c4985a12643 |
train | EmbeddedSphinxShell.process_pure_python2 | content is a list of strings. it is unedited directive conent
This runs it line by line in the InteractiveShell, prepends
prompts as needed capturing stderr and stdout, then returns
the content as a list as if it were ipython code | docs/sphinxext/ipython_directive.py | def process_pure_python2(self, content):
"""
content is a list of strings. it is unedited directive conent
This runs it line by line in the InteractiveShell, prepends
prompts as needed capturing stderr and stdout, then returns
the content as a list as if it were ipython code
... | def process_pure_python2(self, content):
"""
content is a list of strings. it is unedited directive conent
This runs it line by line in the InteractiveShell, prepends
prompts as needed capturing stderr and stdout, then returns
the content as a list as if it were ipython code
... | [
"content",
"is",
"a",
"list",
"of",
"strings",
".",
"it",
"is",
"unedited",
"directive",
"conent"
] | QuantEcon/QuantEcon.py | python | https://github.com/QuantEcon/QuantEcon.py/blob/26a66c552f2a73967d7efb6e1f4b4c4985a12643/docs/sphinxext/ipython_directive.py#L535-L604 | [
"def",
"process_pure_python2",
"(",
"self",
",",
"content",
")",
":",
"output",
"=",
"[",
"]",
"savefig",
"=",
"False",
"# keep up with this to clear figure",
"multiline",
"=",
"False",
"# to handle line continuation",
"multiline_start",
"=",
"None",
"fmtin",
"=",
"... | 26a66c552f2a73967d7efb6e1f4b4c4985a12643 |
train | simulate_linear_model | r"""
This is a separate function for simulating a vector linear system of
the form
.. math::
x_{t+1} = A x_t + v_t
given :math:`x_0` = x0
Here :math:`x_t` and :math:`v_t` are both n x 1 and :math:`A` is n x n.
The purpose of separating this functionality out is to target it for
... | quantecon/lss.py | def simulate_linear_model(A, x0, v, ts_length):
r"""
This is a separate function for simulating a vector linear system of
the form
.. math::
x_{t+1} = A x_t + v_t
given :math:`x_0` = x0
Here :math:`x_t` and :math:`v_t` are both n x 1 and :math:`A` is n x n.
The purpose of separa... | def simulate_linear_model(A, x0, v, ts_length):
r"""
This is a separate function for simulating a vector linear system of
the form
.. math::
x_{t+1} = A x_t + v_t
given :math:`x_0` = x0
Here :math:`x_t` and :math:`v_t` are both n x 1 and :math:`A` is n x n.
The purpose of separa... | [
"r",
"This",
"is",
"a",
"separate",
"function",
"for",
"simulating",
"a",
"vector",
"linear",
"system",
"of",
"the",
"form"
] | QuantEcon/QuantEcon.py | python | https://github.com/QuantEcon/QuantEcon.py/blob/26a66c552f2a73967d7efb6e1f4b4c4985a12643/quantecon/lss.py#L20-L64 | [
"def",
"simulate_linear_model",
"(",
"A",
",",
"x0",
",",
"v",
",",
"ts_length",
")",
":",
"A",
"=",
"np",
".",
"asarray",
"(",
"A",
")",
"n",
"=",
"A",
".",
"shape",
"[",
"0",
"]",
"x",
"=",
"np",
".",
"empty",
"(",
"(",
"n",
",",
"ts_length... | 26a66c552f2a73967d7efb6e1f4b4c4985a12643 |
train | LinearStateSpace.simulate | r"""
Simulate a time series of length ts_length, first drawing
.. math::
x_0 \sim N(\mu_0, \Sigma_0)
Parameters
----------
ts_length : scalar(int), optional(default=100)
The length of the simulation
random_state : int or np.random.RandomState, o... | quantecon/lss.py | def simulate(self, ts_length=100, random_state=None):
r"""
Simulate a time series of length ts_length, first drawing
.. math::
x_0 \sim N(\mu_0, \Sigma_0)
Parameters
----------
ts_length : scalar(int), optional(default=100)
The length of the sim... | def simulate(self, ts_length=100, random_state=None):
r"""
Simulate a time series of length ts_length, first drawing
.. math::
x_0 \sim N(\mu_0, \Sigma_0)
Parameters
----------
ts_length : scalar(int), optional(default=100)
The length of the sim... | [
"r",
"Simulate",
"a",
"time",
"series",
"of",
"length",
"ts_length",
"first",
"drawing"
] | QuantEcon/QuantEcon.py | python | https://github.com/QuantEcon/QuantEcon.py/blob/26a66c552f2a73967d7efb6e1f4b4c4985a12643/quantecon/lss.py#L160-L200 | [
"def",
"simulate",
"(",
"self",
",",
"ts_length",
"=",
"100",
",",
"random_state",
"=",
"None",
")",
":",
"random_state",
"=",
"check_random_state",
"(",
"random_state",
")",
"x0",
"=",
"multivariate_normal",
"(",
"self",
".",
"mu_0",
".",
"flatten",
"(",
... | 26a66c552f2a73967d7efb6e1f4b4c4985a12643 |
train | LinearStateSpace.replicate | r"""
Simulate num_reps observations of :math:`x_T` and :math:`y_T` given
:math:`x_0 \sim N(\mu_0, \Sigma_0)`.
Parameters
----------
T : scalar(int), optional(default=10)
The period that we want to replicate values for
num_reps : scalar(int), optional(default=... | quantecon/lss.py | def replicate(self, T=10, num_reps=100, random_state=None):
r"""
Simulate num_reps observations of :math:`x_T` and :math:`y_T` given
:math:`x_0 \sim N(\mu_0, \Sigma_0)`.
Parameters
----------
T : scalar(int), optional(default=10)
The period that we want to re... | def replicate(self, T=10, num_reps=100, random_state=None):
r"""
Simulate num_reps observations of :math:`x_T` and :math:`y_T` given
:math:`x_0 \sim N(\mu_0, \Sigma_0)`.
Parameters
----------
T : scalar(int), optional(default=10)
The period that we want to re... | [
"r",
"Simulate",
"num_reps",
"observations",
"of",
":",
"math",
":",
"x_T",
"and",
":",
"math",
":",
"y_T",
"given",
":",
"math",
":",
"x_0",
"\\",
"sim",
"N",
"(",
"\\",
"mu_0",
"\\",
"Sigma_0",
")",
"."
] | QuantEcon/QuantEcon.py | python | https://github.com/QuantEcon/QuantEcon.py/blob/26a66c552f2a73967d7efb6e1f4b4c4985a12643/quantecon/lss.py#L202-L242 | [
"def",
"replicate",
"(",
"self",
",",
"T",
"=",
"10",
",",
"num_reps",
"=",
"100",
",",
"random_state",
"=",
"None",
")",
":",
"random_state",
"=",
"check_random_state",
"(",
"random_state",
")",
"x",
"=",
"np",
".",
"empty",
"(",
"(",
"self",
".",
"... | 26a66c552f2a73967d7efb6e1f4b4c4985a12643 |
train | LinearStateSpace.moment_sequence | r"""
Create a generator to calculate the population mean and
variance-convariance matrix for both :math:`x_t` and :math:`y_t`
starting at the initial condition (self.mu_0, self.Sigma_0).
Each iteration produces a 4-tuple of items (mu_x, mu_y, Sigma_x,
Sigma_y) for the next period... | quantecon/lss.py | def moment_sequence(self):
r"""
Create a generator to calculate the population mean and
variance-convariance matrix for both :math:`x_t` and :math:`y_t`
starting at the initial condition (self.mu_0, self.Sigma_0).
Each iteration produces a 4-tuple of items (mu_x, mu_y, Sigma_x,
... | def moment_sequence(self):
r"""
Create a generator to calculate the population mean and
variance-convariance matrix for both :math:`x_t` and :math:`y_t`
starting at the initial condition (self.mu_0, self.Sigma_0).
Each iteration produces a 4-tuple of items (mu_x, mu_y, Sigma_x,
... | [
"r",
"Create",
"a",
"generator",
"to",
"calculate",
"the",
"population",
"mean",
"and",
"variance",
"-",
"convariance",
"matrix",
"for",
"both",
":",
"math",
":",
"x_t",
"and",
":",
"math",
":",
"y_t",
"starting",
"at",
"the",
"initial",
"condition",
"(",
... | QuantEcon/QuantEcon.py | python | https://github.com/QuantEcon/QuantEcon.py/blob/26a66c552f2a73967d7efb6e1f4b4c4985a12643/quantecon/lss.py#L244-L282 | [
"def",
"moment_sequence",
"(",
"self",
")",
":",
"# == Simplify names == #",
"A",
",",
"C",
",",
"G",
",",
"H",
"=",
"self",
".",
"A",
",",
"self",
".",
"C",
",",
"self",
".",
"G",
",",
"self",
".",
"H",
"# == Initial moments == #",
"mu_x",
",",
"Sig... | 26a66c552f2a73967d7efb6e1f4b4c4985a12643 |
train | LinearStateSpace.stationary_distributions | r"""
Compute the moments of the stationary distributions of :math:`x_t` and
:math:`y_t` if possible. Computation is by iteration, starting from
the initial conditions self.mu_0 and self.Sigma_0
Parameters
----------
max_iter : scalar(int), optional(default=200)
... | quantecon/lss.py | def stationary_distributions(self, max_iter=200, tol=1e-5):
r"""
Compute the moments of the stationary distributions of :math:`x_t` and
:math:`y_t` if possible. Computation is by iteration, starting from
the initial conditions self.mu_0 and self.Sigma_0
Parameters
-----... | def stationary_distributions(self, max_iter=200, tol=1e-5):
r"""
Compute the moments of the stationary distributions of :math:`x_t` and
:math:`y_t` if possible. Computation is by iteration, starting from
the initial conditions self.mu_0 and self.Sigma_0
Parameters
-----... | [
"r",
"Compute",
"the",
"moments",
"of",
"the",
"stationary",
"distributions",
"of",
":",
"math",
":",
"x_t",
"and",
":",
"math",
":",
"y_t",
"if",
"possible",
".",
"Computation",
"is",
"by",
"iteration",
"starting",
"from",
"the",
"initial",
"conditions",
... | QuantEcon/QuantEcon.py | python | https://github.com/QuantEcon/QuantEcon.py/blob/26a66c552f2a73967d7efb6e1f4b4c4985a12643/quantecon/lss.py#L284-L336 | [
"def",
"stationary_distributions",
"(",
"self",
",",
"max_iter",
"=",
"200",
",",
"tol",
"=",
"1e-5",
")",
":",
"# == Initialize iteration == #",
"m",
"=",
"self",
".",
"moment_sequence",
"(",
")",
"mu_x",
",",
"mu_y",
",",
"Sigma_x",
",",
"Sigma_y",
"=",
... | 26a66c552f2a73967d7efb6e1f4b4c4985a12643 |
train | LinearStateSpace.geometric_sums | r"""
Forecast the geometric sums
.. math::
S_x := E \Big[ \sum_{j=0}^{\infty} \beta^j x_{t+j} | x_t \Big]
S_y := E \Big[ \sum_{j=0}^{\infty} \beta^j y_{t+j} | x_t \Big]
Parameters
----------
beta : scalar(float)
Discount factor, in [0, 1)
... | quantecon/lss.py | def geometric_sums(self, beta, x_t):
r"""
Forecast the geometric sums
.. math::
S_x := E \Big[ \sum_{j=0}^{\infty} \beta^j x_{t+j} | x_t \Big]
S_y := E \Big[ \sum_{j=0}^{\infty} \beta^j y_{t+j} | x_t \Big]
Parameters
----------
beta : scalar(fl... | def geometric_sums(self, beta, x_t):
r"""
Forecast the geometric sums
.. math::
S_x := E \Big[ \sum_{j=0}^{\infty} \beta^j x_{t+j} | x_t \Big]
S_y := E \Big[ \sum_{j=0}^{\infty} \beta^j y_{t+j} | x_t \Big]
Parameters
----------
beta : scalar(fl... | [
"r",
"Forecast",
"the",
"geometric",
"sums"
] | QuantEcon/QuantEcon.py | python | https://github.com/QuantEcon/QuantEcon.py/blob/26a66c552f2a73967d7efb6e1f4b4c4985a12643/quantecon/lss.py#L338-L370 | [
"def",
"geometric_sums",
"(",
"self",
",",
"beta",
",",
"x_t",
")",
":",
"I",
"=",
"np",
".",
"identity",
"(",
"self",
".",
"n",
")",
"S_x",
"=",
"solve",
"(",
"I",
"-",
"beta",
"*",
"self",
".",
"A",
",",
"x_t",
")",
"S_y",
"=",
"self",
".",... | 26a66c552f2a73967d7efb6e1f4b4c4985a12643 |
train | LinearStateSpace.impulse_response | r"""
Pulls off the imuplse response coefficients to a shock
in :math:`w_{t}` for :math:`x` and :math:`y`
Important to note: We are uninterested in the shocks to
v for this method
* :math:`x` coefficients are :math:`C, AC, A^2 C...`
* :math:`y` coefficients are :math:`GC... | quantecon/lss.py | def impulse_response(self, j=5):
r"""
Pulls off the imuplse response coefficients to a shock
in :math:`w_{t}` for :math:`x` and :math:`y`
Important to note: We are uninterested in the shocks to
v for this method
* :math:`x` coefficients are :math:`C, AC, A^2 C...`
... | def impulse_response(self, j=5):
r"""
Pulls off the imuplse response coefficients to a shock
in :math:`w_{t}` for :math:`x` and :math:`y`
Important to note: We are uninterested in the shocks to
v for this method
* :math:`x` coefficients are :math:`C, AC, A^2 C...`
... | [
"r",
"Pulls",
"off",
"the",
"imuplse",
"response",
"coefficients",
"to",
"a",
"shock",
"in",
":",
"math",
":",
"w_",
"{",
"t",
"}",
"for",
":",
"math",
":",
"x",
"and",
":",
"math",
":",
"y"
] | QuantEcon/QuantEcon.py | python | https://github.com/QuantEcon/QuantEcon.py/blob/26a66c552f2a73967d7efb6e1f4b4c4985a12643/quantecon/lss.py#L372-L408 | [
"def",
"impulse_response",
"(",
"self",
",",
"j",
"=",
"5",
")",
":",
"# Pull out matrices",
"A",
",",
"C",
",",
"G",
",",
"H",
"=",
"self",
".",
"A",
",",
"self",
".",
"C",
",",
"self",
".",
"G",
",",
"self",
".",
"H",
"Apower",
"=",
"np",
"... | 26a66c552f2a73967d7efb6e1f4b4c4985a12643 |
train | searchsorted | Custom version of np.searchsorted. Return the largest index `i` such
that `a[i-1] <= v < a[i]` (for `i = 0`, `v < a[0]`); if `v[n-1] <=
v`, return `n`, where `n = len(a)`.
Parameters
----------
a : ndarray(float, ndim=1)
Input array. Must be sorted in ascending order.
v : scalar(float)... | quantecon/util/array.py | def searchsorted(a, v):
"""
Custom version of np.searchsorted. Return the largest index `i` such
that `a[i-1] <= v < a[i]` (for `i = 0`, `v < a[0]`); if `v[n-1] <=
v`, return `n`, where `n = len(a)`.
Parameters
----------
a : ndarray(float, ndim=1)
Input array. Must be sorted in asc... | def searchsorted(a, v):
"""
Custom version of np.searchsorted. Return the largest index `i` such
that `a[i-1] <= v < a[i]` (for `i = 0`, `v < a[0]`); if `v[n-1] <=
v`, return `n`, where `n = len(a)`.
Parameters
----------
a : ndarray(float, ndim=1)
Input array. Must be sorted in asc... | [
"Custom",
"version",
"of",
"np",
".",
"searchsorted",
".",
"Return",
"the",
"largest",
"index",
"i",
"such",
"that",
"a",
"[",
"i",
"-",
"1",
"]",
"<",
"=",
"v",
"<",
"a",
"[",
"i",
"]",
"(",
"for",
"i",
"=",
"0",
"v",
"<",
"a",
"[",
"0",
"... | QuantEcon/QuantEcon.py | python | https://github.com/QuantEcon/QuantEcon.py/blob/26a66c552f2a73967d7efb6e1f4b4c4985a12643/quantecon/util/array.py#L18-L62 | [
"def",
"searchsorted",
"(",
"a",
",",
"v",
")",
":",
"lo",
"=",
"-",
"1",
"hi",
"=",
"len",
"(",
"a",
")",
"while",
"(",
"lo",
"<",
"hi",
"-",
"1",
")",
":",
"m",
"=",
"(",
"lo",
"+",
"hi",
")",
"//",
"2",
"if",
"v",
"<",
"a",
"[",
"m... | 26a66c552f2a73967d7efb6e1f4b4c4985a12643 |
train | brent_max | Uses a jitted version of the maximization routine from SciPy's fminbound.
The algorithm is identical except that it's been switched to maximization
rather than minimization, and the tests for convergence have been stripped
out to allow for jit compilation.
Note that the input function `func` must be ji... | quantecon/optimize/scalar_maximization.py | def brent_max(func, a, b, args=(), xtol=1e-5, maxiter=500):
"""
Uses a jitted version of the maximization routine from SciPy's fminbound.
The algorithm is identical except that it's been switched to maximization
rather than minimization, and the tests for convergence have been stripped
out to allow ... | def brent_max(func, a, b, args=(), xtol=1e-5, maxiter=500):
"""
Uses a jitted version of the maximization routine from SciPy's fminbound.
The algorithm is identical except that it's been switched to maximization
rather than minimization, and the tests for convergence have been stripped
out to allow ... | [
"Uses",
"a",
"jitted",
"version",
"of",
"the",
"maximization",
"routine",
"from",
"SciPy",
"s",
"fminbound",
".",
"The",
"algorithm",
"is",
"identical",
"except",
"that",
"it",
"s",
"been",
"switched",
"to",
"maximization",
"rather",
"than",
"minimization",
"a... | QuantEcon/QuantEcon.py | python | https://github.com/QuantEcon/QuantEcon.py/blob/26a66c552f2a73967d7efb6e1f4b4c4985a12643/quantecon/optimize/scalar_maximization.py#L5-L152 | [
"def",
"brent_max",
"(",
"func",
",",
"a",
",",
"b",
",",
"args",
"=",
"(",
")",
",",
"xtol",
"=",
"1e-5",
",",
"maxiter",
"=",
"500",
")",
":",
"if",
"not",
"np",
".",
"isfinite",
"(",
"a",
")",
":",
"raise",
"ValueError",
"(",
"\"a must be fini... | 26a66c552f2a73967d7efb6e1f4b4c4985a12643 |
train | BetaBinomial.mean | mean | quantecon/distributions.py | def mean(self):
"mean"
n, a, b = self.n, self.a, self.b
return n * a / (a + b) | def mean(self):
"mean"
n, a, b = self.n, self.a, self.b
return n * a / (a + b) | [
"mean"
] | QuantEcon/QuantEcon.py | python | https://github.com/QuantEcon/QuantEcon.py/blob/26a66c552f2a73967d7efb6e1f4b4c4985a12643/quantecon/distributions.py#L38-L41 | [
"def",
"mean",
"(",
"self",
")",
":",
"n",
",",
"a",
",",
"b",
"=",
"self",
".",
"n",
",",
"self",
".",
"a",
",",
"self",
".",
"b",
"return",
"n",
"*",
"a",
"/",
"(",
"a",
"+",
"b",
")"
] | 26a66c552f2a73967d7efb6e1f4b4c4985a12643 |
train | BetaBinomial.var | Variance | quantecon/distributions.py | def var(self):
"Variance"
n, a, b = self.n, self.a, self.b
top = n*a*b * (a + b + n)
btm = (a+b)**2.0 * (a+b+1.0)
return top / btm | def var(self):
"Variance"
n, a, b = self.n, self.a, self.b
top = n*a*b * (a + b + n)
btm = (a+b)**2.0 * (a+b+1.0)
return top / btm | [
"Variance"
] | QuantEcon/QuantEcon.py | python | https://github.com/QuantEcon/QuantEcon.py/blob/26a66c552f2a73967d7efb6e1f4b4c4985a12643/quantecon/distributions.py#L49-L54 | [
"def",
"var",
"(",
"self",
")",
":",
"n",
",",
"a",
",",
"b",
"=",
"self",
".",
"n",
",",
"self",
".",
"a",
",",
"self",
".",
"b",
"top",
"=",
"n",
"*",
"a",
"*",
"b",
"*",
"(",
"a",
"+",
"b",
"+",
"n",
")",
"btm",
"=",
"(",
"a",
"+... | 26a66c552f2a73967d7efb6e1f4b4c4985a12643 |
train | BetaBinomial.skew | skewness | quantecon/distributions.py | def skew(self):
"skewness"
n, a, b = self.n, self.a, self.b
t1 = (a+b+2*n) * (b - a) / (a+b+2)
t2 = sqrt((1+a+b) / (n*a*b * (n+a+b)))
return t1 * t2 | def skew(self):
"skewness"
n, a, b = self.n, self.a, self.b
t1 = (a+b+2*n) * (b - a) / (a+b+2)
t2 = sqrt((1+a+b) / (n*a*b * (n+a+b)))
return t1 * t2 | [
"skewness"
] | QuantEcon/QuantEcon.py | python | https://github.com/QuantEcon/QuantEcon.py/blob/26a66c552f2a73967d7efb6e1f4b4c4985a12643/quantecon/distributions.py#L57-L62 | [
"def",
"skew",
"(",
"self",
")",
":",
"n",
",",
"a",
",",
"b",
"=",
"self",
".",
"n",
",",
"self",
".",
"a",
",",
"self",
".",
"b",
"t1",
"=",
"(",
"a",
"+",
"b",
"+",
"2",
"*",
"n",
")",
"*",
"(",
"b",
"-",
"a",
")",
"/",
"(",
"a",... | 26a66c552f2a73967d7efb6e1f4b4c4985a12643 |
train | BetaBinomial.pdf | r"""
Generate the vector of probabilities for the Beta-binomial
(n, a, b) distribution.
The Beta-binomial distribution takes the form
.. math::
p(k \,|\, n, a, b) =
{n \choose k} \frac{B(k + a, n - k + b)}{B(a, b)},
\qquad k = 0, \ldots, n,
... | quantecon/distributions.py | def pdf(self):
r"""
Generate the vector of probabilities for the Beta-binomial
(n, a, b) distribution.
The Beta-binomial distribution takes the form
.. math::
p(k \,|\, n, a, b) =
{n \choose k} \frac{B(k + a, n - k + b)}{B(a, b)},
\qquad k = ... | def pdf(self):
r"""
Generate the vector of probabilities for the Beta-binomial
(n, a, b) distribution.
The Beta-binomial distribution takes the form
.. math::
p(k \,|\, n, a, b) =
{n \choose k} \frac{B(k + a, n - k + b)}{B(a, b)},
\qquad k = ... | [
"r",
"Generate",
"the",
"vector",
"of",
"probabilities",
"for",
"the",
"Beta",
"-",
"binomial",
"(",
"n",
"a",
"b",
")",
"distribution",
"."
] | QuantEcon/QuantEcon.py | python | https://github.com/QuantEcon/QuantEcon.py/blob/26a66c552f2a73967d7efb6e1f4b4c4985a12643/quantecon/distributions.py#L64-L96 | [
"def",
"pdf",
"(",
"self",
")",
":",
"n",
",",
"a",
",",
"b",
"=",
"self",
".",
"n",
",",
"self",
".",
"a",
",",
"self",
".",
"b",
"k",
"=",
"np",
".",
"arange",
"(",
"n",
"+",
"1",
")",
"probs",
"=",
"binom",
"(",
"n",
",",
"k",
")",
... | 26a66c552f2a73967d7efb6e1f4b4c4985a12643 |
train | _equilibrium_payoffs_abreu_sannikov | Using 'abreu_sannikov' algorithm to compute the set of payoff pairs
of all pure-strategy subgame-perfect equilibria with public randomization
for any repeated two-player games with perfect monitoring and
discounting, following Abreu and Sannikov (2014).
Parameters
----------
rpg : RepeatedGame
... | quantecon/game_theory/repeated_game.py | def _equilibrium_payoffs_abreu_sannikov(rpg, tol=1e-12, max_iter=500,
u_init=np.zeros(2)):
"""
Using 'abreu_sannikov' algorithm to compute the set of payoff pairs
of all pure-strategy subgame-perfect equilibria with public randomization
for any repeated two-player... | def _equilibrium_payoffs_abreu_sannikov(rpg, tol=1e-12, max_iter=500,
u_init=np.zeros(2)):
"""
Using 'abreu_sannikov' algorithm to compute the set of payoff pairs
of all pure-strategy subgame-perfect equilibria with public randomization
for any repeated two-player... | [
"Using",
"abreu_sannikov",
"algorithm",
"to",
"compute",
"the",
"set",
"of",
"payoff",
"pairs",
"of",
"all",
"pure",
"-",
"strategy",
"subgame",
"-",
"perfect",
"equilibria",
"with",
"public",
"randomization",
"for",
"any",
"repeated",
"two",
"-",
"player",
"g... | QuantEcon/QuantEcon.py | python | https://github.com/QuantEcon/QuantEcon.py/blob/26a66c552f2a73967d7efb6e1f4b4c4985a12643/quantecon/game_theory/repeated_game.py#L85-L175 | [
"def",
"_equilibrium_payoffs_abreu_sannikov",
"(",
"rpg",
",",
"tol",
"=",
"1e-12",
",",
"max_iter",
"=",
"500",
",",
"u_init",
"=",
"np",
".",
"zeros",
"(",
"2",
")",
")",
":",
"sg",
",",
"delta",
"=",
"rpg",
".",
"sg",
",",
"rpg",
".",
"delta",
"... | 26a66c552f2a73967d7efb6e1f4b4c4985a12643 |
train | _best_dev_gains | Calculate the normalized payoff gains from deviating from the current
action to the best response for each player.
Parameters
----------
rpg : RepeatedGame
Two player repeated game.
Returns
-------
best_dev_gains : tuple(ndarray(float, ndim=2))
The normalized best deviation... | quantecon/game_theory/repeated_game.py | def _best_dev_gains(rpg):
"""
Calculate the normalized payoff gains from deviating from the current
action to the best response for each player.
Parameters
----------
rpg : RepeatedGame
Two player repeated game.
Returns
-------
best_dev_gains : tuple(ndarray(float, ndim=2))... | def _best_dev_gains(rpg):
"""
Calculate the normalized payoff gains from deviating from the current
action to the best response for each player.
Parameters
----------
rpg : RepeatedGame
Two player repeated game.
Returns
-------
best_dev_gains : tuple(ndarray(float, ndim=2))... | [
"Calculate",
"the",
"normalized",
"payoff",
"gains",
"from",
"deviating",
"from",
"the",
"current",
"action",
"to",
"the",
"best",
"response",
"for",
"each",
"player",
"."
] | QuantEcon/QuantEcon.py | python | https://github.com/QuantEcon/QuantEcon.py/blob/26a66c552f2a73967d7efb6e1f4b4c4985a12643/quantecon/game_theory/repeated_game.py#L178-L202 | [
"def",
"_best_dev_gains",
"(",
"rpg",
")",
":",
"sg",
",",
"delta",
"=",
"rpg",
".",
"sg",
",",
"rpg",
".",
"delta",
"best_dev_gains",
"=",
"(",
"(",
"1",
"-",
"delta",
")",
"/",
"delta",
"*",
"(",
"np",
".",
"max",
"(",
"sg",
".",
"payoff_arrays... | 26a66c552f2a73967d7efb6e1f4b4c4985a12643 |
train | _R | Updating the payoff convex hull by iterating all action pairs.
Using the R operator proposed by Abreu and Sannikov 2014.
Parameters
----------
delta : scalar(float)
The common discount rate at which all players discount
the future.
nums_actions : tuple(int)
Tuple of... | quantecon/game_theory/repeated_game.py | def _R(delta, nums_actions, payoff_arrays, best_dev_gains, points,
vertices, equations, u, IC, action_profile_payoff,
extended_payoff, new_pts, W_new, tol=1e-10):
"""
Updating the payoff convex hull by iterating all action pairs.
Using the R operator proposed by Abreu and Sannikov 2014.
P... | def _R(delta, nums_actions, payoff_arrays, best_dev_gains, points,
vertices, equations, u, IC, action_profile_payoff,
extended_payoff, new_pts, W_new, tol=1e-10):
"""
Updating the payoff convex hull by iterating all action pairs.
Using the R operator proposed by Abreu and Sannikov 2014.
P... | [
"Updating",
"the",
"payoff",
"convex",
"hull",
"by",
"iterating",
"all",
"action",
"pairs",
".",
"Using",
"the",
"R",
"operator",
"proposed",
"by",
"Abreu",
"and",
"Sannikov",
"2014",
"."
] | QuantEcon/QuantEcon.py | python | https://github.com/QuantEcon/QuantEcon.py/blob/26a66c552f2a73967d7efb6e1f4b4c4985a12643/quantecon/game_theory/repeated_game.py#L206-L302 | [
"def",
"_R",
"(",
"delta",
",",
"nums_actions",
",",
"payoff_arrays",
",",
"best_dev_gains",
",",
"points",
",",
"vertices",
",",
"equations",
",",
"u",
",",
"IC",
",",
"action_profile_payoff",
",",
"extended_payoff",
",",
"new_pts",
",",
"W_new",
",",
"tol"... | 26a66c552f2a73967d7efb6e1f4b4c4985a12643 |
train | _find_C | Find all the intersection points between the current convex hull
and the two IC constraints. It is done by iterating simplex
counterclockwise.
Parameters
----------
C : ndarray(float, ndim=2)
The 4 by 2 array for storing the generated potential
extreme points of one action profile. ... | quantecon/game_theory/repeated_game.py | def _find_C(C, points, vertices, equations, extended_payoff, IC, tol):
"""
Find all the intersection points between the current convex hull
and the two IC constraints. It is done by iterating simplex
counterclockwise.
Parameters
----------
C : ndarray(float, ndim=2)
The 4 by 2 array... | def _find_C(C, points, vertices, equations, extended_payoff, IC, tol):
"""
Find all the intersection points between the current convex hull
and the two IC constraints. It is done by iterating simplex
counterclockwise.
Parameters
----------
C : ndarray(float, ndim=2)
The 4 by 2 array... | [
"Find",
"all",
"the",
"intersection",
"points",
"between",
"the",
"current",
"convex",
"hull",
"and",
"the",
"two",
"IC",
"constraints",
".",
"It",
"is",
"done",
"by",
"iterating",
"simplex",
"counterclockwise",
"."
] | QuantEcon/QuantEcon.py | python | https://github.com/QuantEcon/QuantEcon.py/blob/26a66c552f2a73967d7efb6e1f4b4c4985a12643/quantecon/game_theory/repeated_game.py#L306-L366 | [
"def",
"_find_C",
"(",
"C",
",",
"points",
",",
"vertices",
",",
"equations",
",",
"extended_payoff",
",",
"IC",
",",
"tol",
")",
":",
"n",
"=",
"0",
"weights",
"=",
"np",
".",
"empty",
"(",
"2",
")",
"# vertices is ordered counterclockwise",
"for",
"i",... | 26a66c552f2a73967d7efb6e1f4b4c4985a12643 |
train | _intersect | Find the intersection points of a half-closed simplex
(pt0, pt1] and IC constraints.
Parameters
----------
C : ndarray(float, ndim=2)
The 4 by 2 array for storing the generated points of
one action profile. One action profile can only
generate at most 4 points.
n : scalar(i... | quantecon/game_theory/repeated_game.py | def _intersect(C, n, weights, IC, pt0, pt1, tol):
"""
Find the intersection points of a half-closed simplex
(pt0, pt1] and IC constraints.
Parameters
----------
C : ndarray(float, ndim=2)
The 4 by 2 array for storing the generated points of
one action profile. One action profile... | def _intersect(C, n, weights, IC, pt0, pt1, tol):
"""
Find the intersection points of a half-closed simplex
(pt0, pt1] and IC constraints.
Parameters
----------
C : ndarray(float, ndim=2)
The 4 by 2 array for storing the generated points of
one action profile. One action profile... | [
"Find",
"the",
"intersection",
"points",
"of",
"a",
"half",
"-",
"closed",
"simplex",
"(",
"pt0",
"pt1",
"]",
"and",
"IC",
"constraints",
"."
] | QuantEcon/QuantEcon.py | python | https://github.com/QuantEcon/QuantEcon.py/blob/26a66c552f2a73967d7efb6e1f4b4c4985a12643/quantecon/game_theory/repeated_game.py#L370-L431 | [
"def",
"_intersect",
"(",
"C",
",",
"n",
",",
"weights",
",",
"IC",
",",
"pt0",
",",
"pt1",
",",
"tol",
")",
":",
"for",
"i",
"in",
"range",
"(",
"2",
")",
":",
"if",
"(",
"abs",
"(",
"pt0",
"[",
"i",
"]",
"-",
"pt1",
"[",
"i",
"]",
")",
... | 26a66c552f2a73967d7efb6e1f4b4c4985a12643 |
train | _update_u | Update the threat points if it not feasible in the new W,
by the minimum of new feasible payoffs.
Parameters
----------
u : ndarray(float, ndim=1)
The threat points.
W : ndarray(float, ndim=1)
The points that construct the feasible payoff convex hull.
Returns
-------
u... | quantecon/game_theory/repeated_game.py | def _update_u(u, W):
"""
Update the threat points if it not feasible in the new W,
by the minimum of new feasible payoffs.
Parameters
----------
u : ndarray(float, ndim=1)
The threat points.
W : ndarray(float, ndim=1)
The points that construct the feasible payoff convex hul... | def _update_u(u, W):
"""
Update the threat points if it not feasible in the new W,
by the minimum of new feasible payoffs.
Parameters
----------
u : ndarray(float, ndim=1)
The threat points.
W : ndarray(float, ndim=1)
The points that construct the feasible payoff convex hul... | [
"Update",
"the",
"threat",
"points",
"if",
"it",
"not",
"feasible",
"in",
"the",
"new",
"W",
"by",
"the",
"minimum",
"of",
"new",
"feasible",
"payoffs",
"."
] | QuantEcon/QuantEcon.py | python | https://github.com/QuantEcon/QuantEcon.py/blob/26a66c552f2a73967d7efb6e1f4b4c4985a12643/quantecon/game_theory/repeated_game.py#L435-L458 | [
"def",
"_update_u",
"(",
"u",
",",
"W",
")",
":",
"for",
"i",
"in",
"range",
"(",
"2",
")",
":",
"W_min",
"=",
"W",
"[",
":",
",",
"i",
"]",
".",
"min",
"(",
")",
"if",
"u",
"[",
"i",
"]",
"<",
"W_min",
":",
"u",
"[",
"i",
"]",
"=",
"... | 26a66c552f2a73967d7efb6e1f4b4c4985a12643 |
train | RepeatedGame.equilibrium_payoffs | Compute the set of payoff pairs of all pure-strategy subgame-perfect
equilibria with public randomization for any repeated two-player games
with perfect monitoring and discounting.
Parameters
----------
method : str, optional
The method for solving the equilibrium pa... | quantecon/game_theory/repeated_game.py | def equilibrium_payoffs(self, method=None, options=None):
"""
Compute the set of payoff pairs of all pure-strategy subgame-perfect
equilibria with public randomization for any repeated two-player games
with perfect monitoring and discounting.
Parameters
----------
... | def equilibrium_payoffs(self, method=None, options=None):
"""
Compute the set of payoff pairs of all pure-strategy subgame-perfect
equilibria with public randomization for any repeated two-player games
with perfect monitoring and discounting.
Parameters
----------
... | [
"Compute",
"the",
"set",
"of",
"payoff",
"pairs",
"of",
"all",
"pure",
"-",
"strategy",
"subgame",
"-",
"perfect",
"equilibria",
"with",
"public",
"randomization",
"for",
"any",
"repeated",
"two",
"-",
"player",
"games",
"with",
"perfect",
"monitoring",
"and",... | QuantEcon/QuantEcon.py | python | https://github.com/QuantEcon/QuantEcon.py/blob/26a66c552f2a73967d7efb6e1f4b4c4985a12643/quantecon/game_theory/repeated_game.py#L43-L82 | [
"def",
"equilibrium_payoffs",
"(",
"self",
",",
"method",
"=",
"None",
",",
"options",
"=",
"None",
")",
":",
"if",
"method",
"is",
"None",
":",
"method",
"=",
"'abreu_sannikov'",
"if",
"options",
"is",
"None",
":",
"options",
"=",
"{",
"}",
"if",
"met... | 26a66c552f2a73967d7efb6e1f4b4c4985a12643 |
train | random_game | Return a random NormalFormGame instance where the payoffs are drawn
independently from the uniform distribution on [0, 1).
Parameters
----------
nums_actions : tuple(int)
Tuple of the numbers of actions, one for each player.
random_state : int or np.random.RandomState, optional
Ran... | quantecon/game_theory/random.py | def random_game(nums_actions, random_state=None):
"""
Return a random NormalFormGame instance where the payoffs are drawn
independently from the uniform distribution on [0, 1).
Parameters
----------
nums_actions : tuple(int)
Tuple of the numbers of actions, one for each player.
ran... | def random_game(nums_actions, random_state=None):
"""
Return a random NormalFormGame instance where the payoffs are drawn
independently from the uniform distribution on [0, 1).
Parameters
----------
nums_actions : tuple(int)
Tuple of the numbers of actions, one for each player.
ran... | [
"Return",
"a",
"random",
"NormalFormGame",
"instance",
"where",
"the",
"payoffs",
"are",
"drawn",
"independently",
"from",
"the",
"uniform",
"distribution",
"on",
"[",
"0",
"1",
")",
"."
] | QuantEcon/QuantEcon.py | python | https://github.com/QuantEcon/QuantEcon.py/blob/26a66c552f2a73967d7efb6e1f4b4c4985a12643/quantecon/game_theory/random.py#L13-L44 | [
"def",
"random_game",
"(",
"nums_actions",
",",
"random_state",
"=",
"None",
")",
":",
"N",
"=",
"len",
"(",
"nums_actions",
")",
"if",
"N",
"==",
"0",
":",
"raise",
"ValueError",
"(",
"'nums_actions must be non-empty'",
")",
"random_state",
"=",
"check_random... | 26a66c552f2a73967d7efb6e1f4b4c4985a12643 |
train | covariance_game | Return a random NormalFormGame instance where the payoff profiles
are drawn independently from the standard multi-normal with the
covariance of any pair of payoffs equal to `rho`, as studied in
[1]_.
Parameters
----------
nums_actions : tuple(int)
Tuple of the numbers of actions, one fo... | quantecon/game_theory/random.py | def covariance_game(nums_actions, rho, random_state=None):
"""
Return a random NormalFormGame instance where the payoff profiles
are drawn independently from the standard multi-normal with the
covariance of any pair of payoffs equal to `rho`, as studied in
[1]_.
Parameters
----------
nu... | def covariance_game(nums_actions, rho, random_state=None):
"""
Return a random NormalFormGame instance where the payoff profiles
are drawn independently from the standard multi-normal with the
covariance of any pair of payoffs equal to `rho`, as studied in
[1]_.
Parameters
----------
nu... | [
"Return",
"a",
"random",
"NormalFormGame",
"instance",
"where",
"the",
"payoff",
"profiles",
"are",
"drawn",
"independently",
"from",
"the",
"standard",
"multi",
"-",
"normal",
"with",
"the",
"covariance",
"of",
"any",
"pair",
"of",
"payoffs",
"equal",
"to",
"... | QuantEcon/QuantEcon.py | python | https://github.com/QuantEcon/QuantEcon.py/blob/26a66c552f2a73967d7efb6e1f4b4c4985a12643/quantecon/game_theory/random.py#L47-L96 | [
"def",
"covariance_game",
"(",
"nums_actions",
",",
"rho",
",",
"random_state",
"=",
"None",
")",
":",
"N",
"=",
"len",
"(",
"nums_actions",
")",
"if",
"N",
"<=",
"1",
":",
"raise",
"ValueError",
"(",
"'length of nums_actions must be at least 2'",
")",
"if",
... | 26a66c552f2a73967d7efb6e1f4b4c4985a12643 |
train | random_pure_actions | Return a tuple of random pure actions (integers).
Parameters
----------
nums_actions : tuple(int)
Tuple of the numbers of actions, one for each player.
random_state : int or np.random.RandomState, optional
Random seed (integer) or np.random.RandomState instance to set
the initi... | quantecon/game_theory/random.py | def random_pure_actions(nums_actions, random_state=None):
"""
Return a tuple of random pure actions (integers).
Parameters
----------
nums_actions : tuple(int)
Tuple of the numbers of actions, one for each player.
random_state : int or np.random.RandomState, optional
Random see... | def random_pure_actions(nums_actions, random_state=None):
"""
Return a tuple of random pure actions (integers).
Parameters
----------
nums_actions : tuple(int)
Tuple of the numbers of actions, one for each player.
random_state : int or np.random.RandomState, optional
Random see... | [
"Return",
"a",
"tuple",
"of",
"random",
"pure",
"actions",
"(",
"integers",
")",
"."
] | QuantEcon/QuantEcon.py | python | https://github.com/QuantEcon/QuantEcon.py/blob/26a66c552f2a73967d7efb6e1f4b4c4985a12643/quantecon/game_theory/random.py#L99-L124 | [
"def",
"random_pure_actions",
"(",
"nums_actions",
",",
"random_state",
"=",
"None",
")",
":",
"random_state",
"=",
"check_random_state",
"(",
"random_state",
")",
"action_profile",
"=",
"tuple",
"(",
"[",
"random_state",
".",
"randint",
"(",
"num_actions",
")",
... | 26a66c552f2a73967d7efb6e1f4b4c4985a12643 |
train | random_mixed_actions | Return a tuple of random mixed actions (vectors of floats).
Parameters
----------
nums_actions : tuple(int)
Tuple of the numbers of actions, one for each player.
random_state : int or np.random.RandomState, optional
Random seed (integer) or np.random.RandomState instance to set
... | quantecon/game_theory/random.py | def random_mixed_actions(nums_actions, random_state=None):
"""
Return a tuple of random mixed actions (vectors of floats).
Parameters
----------
nums_actions : tuple(int)
Tuple of the numbers of actions, one for each player.
random_state : int or np.random.RandomState, optional
... | def random_mixed_actions(nums_actions, random_state=None):
"""
Return a tuple of random mixed actions (vectors of floats).
Parameters
----------
nums_actions : tuple(int)
Tuple of the numbers of actions, one for each player.
random_state : int or np.random.RandomState, optional
... | [
"Return",
"a",
"tuple",
"of",
"random",
"mixed",
"actions",
"(",
"vectors",
"of",
"floats",
")",
"."
] | QuantEcon/QuantEcon.py | python | https://github.com/QuantEcon/QuantEcon.py/blob/26a66c552f2a73967d7efb6e1f4b4c4985a12643/quantecon/game_theory/random.py#L127-L153 | [
"def",
"random_mixed_actions",
"(",
"nums_actions",
",",
"random_state",
"=",
"None",
")",
":",
"random_state",
"=",
"check_random_state",
"(",
"random_state",
")",
"action_profile",
"=",
"tuple",
"(",
"[",
"probvec",
"(",
"1",
",",
"num_actions",
",",
"random_s... | 26a66c552f2a73967d7efb6e1f4b4c4985a12643 |
train | fetch_nb_dependencies | Retrieve raw files from QuantEcon.notebooks or other Github repo
Parameters
----------
file_list list or dict
A list of files to specify a collection of filenames
A dict of dir : list(files) to specify a directory
repo str, optional(default=REPO)
raw ... | quantecon/util/notebooks.py | def fetch_nb_dependencies(files, repo=REPO, raw=RAW, branch=BRANCH, folder=FOLDER, overwrite=False, verbose=True):
"""
Retrieve raw files from QuantEcon.notebooks or other Github repo
Parameters
----------
file_list list or dict
A list of files to specify a collection of filen... | def fetch_nb_dependencies(files, repo=REPO, raw=RAW, branch=BRANCH, folder=FOLDER, overwrite=False, verbose=True):
"""
Retrieve raw files from QuantEcon.notebooks or other Github repo
Parameters
----------
file_list list or dict
A list of files to specify a collection of filen... | [
"Retrieve",
"raw",
"files",
"from",
"QuantEcon",
".",
"notebooks",
"or",
"other",
"Github",
"repo",
"Parameters",
"----------",
"file_list",
"list",
"or",
"dict",
"A",
"list",
"of",
"files",
"to",
"specify",
"a",
"collection",
"of",
"filenames",
"A",
"dict",
... | QuantEcon/QuantEcon.py | python | https://github.com/QuantEcon/QuantEcon.py/blob/26a66c552f2a73967d7efb6e1f4b4c4985a12643/quantecon/util/notebooks.py#L32-L106 | [
"def",
"fetch_nb_dependencies",
"(",
"files",
",",
"repo",
"=",
"REPO",
",",
"raw",
"=",
"RAW",
",",
"branch",
"=",
"BRANCH",
",",
"folder",
"=",
"FOLDER",
",",
"overwrite",
"=",
"False",
",",
"verbose",
"=",
"True",
")",
":",
"import",
"requests",
"#-... | 26a66c552f2a73967d7efb6e1f4b4c4985a12643 |
train | nnash | r"""
Compute the limit of a Nash linear quadratic dynamic game. In this
problem, player i minimizes
.. math::
\sum_{t=0}^{\infty}
\left\{
x_t' r_i x_t + 2 x_t' w_i
u_{it} +u_{it}' q_i u_{it} + u_{jt}' s_i u_{jt} + 2 u_{jt}'
m_i u_{it}
\right\}
... | quantecon/lqnash.py | def nnash(A, B1, B2, R1, R2, Q1, Q2, S1, S2, W1, W2, M1, M2,
beta=1.0, tol=1e-8, max_iter=1000, random_state=None):
r"""
Compute the limit of a Nash linear quadratic dynamic game. In this
problem, player i minimizes
.. math::
\sum_{t=0}^{\infty}
\left\{
x_t' r_i x_... | def nnash(A, B1, B2, R1, R2, Q1, Q2, S1, S2, W1, W2, M1, M2,
beta=1.0, tol=1e-8, max_iter=1000, random_state=None):
r"""
Compute the limit of a Nash linear quadratic dynamic game. In this
problem, player i minimizes
.. math::
\sum_{t=0}^{\infty}
\left\{
x_t' r_i x_... | [
"r",
"Compute",
"the",
"limit",
"of",
"a",
"Nash",
"linear",
"quadratic",
"dynamic",
"game",
".",
"In",
"this",
"problem",
"player",
"i",
"minimizes"
] | QuantEcon/QuantEcon.py | python | https://github.com/QuantEcon/QuantEcon.py/blob/26a66c552f2a73967d7efb6e1f4b4c4985a12643/quantecon/lqnash.py#L7-L154 | [
"def",
"nnash",
"(",
"A",
",",
"B1",
",",
"B2",
",",
"R1",
",",
"R2",
",",
"Q1",
",",
"Q2",
",",
"S1",
",",
"S2",
",",
"W1",
",",
"W2",
",",
"M1",
",",
"M2",
",",
"beta",
"=",
"1.0",
",",
"tol",
"=",
"1e-8",
",",
"max_iter",
"=",
"1000",
... | 26a66c552f2a73967d7efb6e1f4b4c4985a12643 |
train | _results | r"""Select from a tuple of(root, funccalls, iterations, flag) | quantecon/optimize/root_finding.py | def _results(r):
r"""Select from a tuple of(root, funccalls, iterations, flag)"""
x, funcalls, iterations, flag = r
return results(x, funcalls, iterations, flag == 0) | def _results(r):
r"""Select from a tuple of(root, funccalls, iterations, flag)"""
x, funcalls, iterations, flag = r
return results(x, funcalls, iterations, flag == 0) | [
"r",
"Select",
"from",
"a",
"tuple",
"of",
"(",
"root",
"funccalls",
"iterations",
"flag",
")"
] | QuantEcon/QuantEcon.py | python | https://github.com/QuantEcon/QuantEcon.py/blob/26a66c552f2a73967d7efb6e1f4b4c4985a12643/quantecon/optimize/root_finding.py#L18-L21 | [
"def",
"_results",
"(",
"r",
")",
":",
"x",
",",
"funcalls",
",",
"iterations",
",",
"flag",
"=",
"r",
"return",
"results",
"(",
"x",
",",
"funcalls",
",",
"iterations",
",",
"flag",
"==",
"0",
")"
] | 26a66c552f2a73967d7efb6e1f4b4c4985a12643 |
train | newton | Find a zero from the Newton-Raphson method using the jitted version of
Scipy's newton for scalars. Note that this does not provide an alternative
method such as secant. Thus, it is important that `fprime` can be provided.
Note that `func` and `fprime` must be jitted via Numba.
They are recommended to b... | quantecon/optimize/root_finding.py | def newton(func, x0, fprime, args=(), tol=1.48e-8, maxiter=50,
disp=True):
"""
Find a zero from the Newton-Raphson method using the jitted version of
Scipy's newton for scalars. Note that this does not provide an alternative
method such as secant. Thus, it is important that `fprime` can be pr... | def newton(func, x0, fprime, args=(), tol=1.48e-8, maxiter=50,
disp=True):
"""
Find a zero from the Newton-Raphson method using the jitted version of
Scipy's newton for scalars. Note that this does not provide an alternative
method such as secant. Thus, it is important that `fprime` can be pr... | [
"Find",
"a",
"zero",
"from",
"the",
"Newton",
"-",
"Raphson",
"method",
"using",
"the",
"jitted",
"version",
"of",
"Scipy",
"s",
"newton",
"for",
"scalars",
".",
"Note",
"that",
"this",
"does",
"not",
"provide",
"an",
"alternative",
"method",
"such",
"as",... | QuantEcon/QuantEcon.py | python | https://github.com/QuantEcon/QuantEcon.py/blob/26a66c552f2a73967d7efb6e1f4b4c4985a12643/quantecon/optimize/root_finding.py#L25-L107 | [
"def",
"newton",
"(",
"func",
",",
"x0",
",",
"fprime",
",",
"args",
"=",
"(",
")",
",",
"tol",
"=",
"1.48e-8",
",",
"maxiter",
"=",
"50",
",",
"disp",
"=",
"True",
")",
":",
"if",
"tol",
"<=",
"0",
":",
"raise",
"ValueError",
"(",
"\"tol is too ... | 26a66c552f2a73967d7efb6e1f4b4c4985a12643 |
train | newton_secant | Find a zero from the secant method using the jitted version of
Scipy's secant method.
Note that `func` must be jitted via Numba.
Parameters
----------
func : callable and jitted
The function whose zero is wanted. It must be a function of a
single variable of the form f(x,a,b,c...),... | quantecon/optimize/root_finding.py | def newton_secant(func, x0, args=(), tol=1.48e-8, maxiter=50,
disp=True):
"""
Find a zero from the secant method using the jitted version of
Scipy's secant method.
Note that `func` must be jitted via Numba.
Parameters
----------
func : callable and jitted
The func... | def newton_secant(func, x0, args=(), tol=1.48e-8, maxiter=50,
disp=True):
"""
Find a zero from the secant method using the jitted version of
Scipy's secant method.
Note that `func` must be jitted via Numba.
Parameters
----------
func : callable and jitted
The func... | [
"Find",
"a",
"zero",
"from",
"the",
"secant",
"method",
"using",
"the",
"jitted",
"version",
"of",
"Scipy",
"s",
"secant",
"method",
"."
] | QuantEcon/QuantEcon.py | python | https://github.com/QuantEcon/QuantEcon.py/blob/26a66c552f2a73967d7efb6e1f4b4c4985a12643/quantecon/optimize/root_finding.py#L197-L274 | [
"def",
"newton_secant",
"(",
"func",
",",
"x0",
",",
"args",
"=",
"(",
")",
",",
"tol",
"=",
"1.48e-8",
",",
"maxiter",
"=",
"50",
",",
"disp",
"=",
"True",
")",
":",
"if",
"tol",
"<=",
"0",
":",
"raise",
"ValueError",
"(",
"\"tol is too small <= 0\"... | 26a66c552f2a73967d7efb6e1f4b4c4985a12643 |
train | _bisect_interval | Conditional checks for intervals in methods involving bisection | quantecon/optimize/root_finding.py | def _bisect_interval(a, b, fa, fb):
"""Conditional checks for intervals in methods involving bisection"""
if fa*fb > 0:
raise ValueError("f(a) and f(b) must have different signs")
root = 0.0
status = _ECONVERR
# Root found at either end of [a,b]
if fa == 0:
root = a
stat... | def _bisect_interval(a, b, fa, fb):
"""Conditional checks for intervals in methods involving bisection"""
if fa*fb > 0:
raise ValueError("f(a) and f(b) must have different signs")
root = 0.0
status = _ECONVERR
# Root found at either end of [a,b]
if fa == 0:
root = a
stat... | [
"Conditional",
"checks",
"for",
"intervals",
"in",
"methods",
"involving",
"bisection"
] | QuantEcon/QuantEcon.py | python | https://github.com/QuantEcon/QuantEcon.py/blob/26a66c552f2a73967d7efb6e1f4b4c4985a12643/quantecon/optimize/root_finding.py#L278-L293 | [
"def",
"_bisect_interval",
"(",
"a",
",",
"b",
",",
"fa",
",",
"fb",
")",
":",
"if",
"fa",
"*",
"fb",
">",
"0",
":",
"raise",
"ValueError",
"(",
"\"f(a) and f(b) must have different signs\"",
")",
"root",
"=",
"0.0",
"status",
"=",
"_ECONVERR",
"# Root fou... | 26a66c552f2a73967d7efb6e1f4b4c4985a12643 |
train | bisect | Find root of a function within an interval adapted from Scipy's bisect.
Basic bisection routine to find a zero of the function `f` between the
arguments `a` and `b`. `f(a)` and `f(b)` cannot have the same signs.
`f` must be jitted via numba.
Parameters
----------
f : jitted and callable
... | quantecon/optimize/root_finding.py | def bisect(f, a, b, args=(), xtol=_xtol,
rtol=_rtol, maxiter=_iter, disp=True):
"""
Find root of a function within an interval adapted from Scipy's bisect.
Basic bisection routine to find a zero of the function `f` between the
arguments `a` and `b`. `f(a)` and `f(b)` cannot have the same sig... | def bisect(f, a, b, args=(), xtol=_xtol,
rtol=_rtol, maxiter=_iter, disp=True):
"""
Find root of a function within an interval adapted from Scipy's bisect.
Basic bisection routine to find a zero of the function `f` between the
arguments `a` and `b`. `f(a)` and `f(b)` cannot have the same sig... | [
"Find",
"root",
"of",
"a",
"function",
"within",
"an",
"interval",
"adapted",
"from",
"Scipy",
"s",
"bisect",
"."
] | QuantEcon/QuantEcon.py | python | https://github.com/QuantEcon/QuantEcon.py/blob/26a66c552f2a73967d7efb6e1f4b4c4985a12643/quantecon/optimize/root_finding.py#L297-L374 | [
"def",
"bisect",
"(",
"f",
",",
"a",
",",
"b",
",",
"args",
"=",
"(",
")",
",",
"xtol",
"=",
"_xtol",
",",
"rtol",
"=",
"_rtol",
",",
"maxiter",
"=",
"_iter",
",",
"disp",
"=",
"True",
")",
":",
"if",
"xtol",
"<=",
"0",
":",
"raise",
"ValueEr... | 26a66c552f2a73967d7efb6e1f4b4c4985a12643 |
train | brentq | Find a root of a function in a bracketing interval using Brent's method
adapted from Scipy's brentq.
Uses the classic Brent's method to find a zero of the function `f` on
the sign changing interval [a , b].
`f` must be jitted via numba.
Parameters
----------
f : jitted and callable
... | quantecon/optimize/root_finding.py | def brentq(f, a, b, args=(), xtol=_xtol,
rtol=_rtol, maxiter=_iter, disp=True):
"""
Find a root of a function in a bracketing interval using Brent's method
adapted from Scipy's brentq.
Uses the classic Brent's method to find a zero of the function `f` on
the sign changing interval [a , b... | def brentq(f, a, b, args=(), xtol=_xtol,
rtol=_rtol, maxiter=_iter, disp=True):
"""
Find a root of a function in a bracketing interval using Brent's method
adapted from Scipy's brentq.
Uses the classic Brent's method to find a zero of the function `f` on
the sign changing interval [a , b... | [
"Find",
"a",
"root",
"of",
"a",
"function",
"in",
"a",
"bracketing",
"interval",
"using",
"Brent",
"s",
"method",
"adapted",
"from",
"Scipy",
"s",
"brentq",
"."
] | QuantEcon/QuantEcon.py | python | https://github.com/QuantEcon/QuantEcon.py/blob/26a66c552f2a73967d7efb6e1f4b4c4985a12643/quantecon/optimize/root_finding.py#L378-L497 | [
"def",
"brentq",
"(",
"f",
",",
"a",
",",
"b",
",",
"args",
"=",
"(",
")",
",",
"xtol",
"=",
"_xtol",
",",
"rtol",
"=",
"_rtol",
",",
"maxiter",
"=",
"_iter",
",",
"disp",
"=",
"True",
")",
":",
"if",
"xtol",
"<=",
"0",
":",
"raise",
"ValueEr... | 26a66c552f2a73967d7efb6e1f4b4c4985a12643 |
train | compute_fixed_point | r"""
Computes and returns an approximate fixed point of the function `T`.
The default method `'iteration'` simply iterates the function given
an initial condition `v` and returns :math:`T^k v` when the
condition :math:`\lVert T^k v - T^{k-1} v\rVert \leq
\mathrm{error\_tol}` is satisfied or the num... | quantecon/compute_fp.py | def compute_fixed_point(T, v, error_tol=1e-3, max_iter=50, verbose=2,
print_skip=5, method='iteration', *args, **kwargs):
r"""
Computes and returns an approximate fixed point of the function `T`.
The default method `'iteration'` simply iterates the function given
an initial cond... | def compute_fixed_point(T, v, error_tol=1e-3, max_iter=50, verbose=2,
print_skip=5, method='iteration', *args, **kwargs):
r"""
Computes and returns an approximate fixed point of the function `T`.
The default method `'iteration'` simply iterates the function given
an initial cond... | [
"r",
"Computes",
"and",
"returns",
"an",
"approximate",
"fixed",
"point",
"of",
"the",
"function",
"T",
"."
] | QuantEcon/QuantEcon.py | python | https://github.com/QuantEcon/QuantEcon.py/blob/26a66c552f2a73967d7efb6e1f4b4c4985a12643/quantecon/compute_fp.py#L46-L155 | [
"def",
"compute_fixed_point",
"(",
"T",
",",
"v",
",",
"error_tol",
"=",
"1e-3",
",",
"max_iter",
"=",
"50",
",",
"verbose",
"=",
"2",
",",
"print_skip",
"=",
"5",
",",
"method",
"=",
"'iteration'",
",",
"*",
"args",
",",
"*",
"*",
"kwargs",
")",
"... | 26a66c552f2a73967d7efb6e1f4b4c4985a12643 |
train | _compute_fixed_point_ig | Implement the imitation game algorithm by McLennan and Tourky (2006)
for computing an approximate fixed point of `T`.
Parameters
----------
is_approx_fp : callable
A callable with signature `is_approx_fp(v)` which determines
whether `v` is an approximate fixed point with a bool return
... | quantecon/compute_fp.py | def _compute_fixed_point_ig(T, v, max_iter, verbose, print_skip, is_approx_fp,
*args, **kwargs):
"""
Implement the imitation game algorithm by McLennan and Tourky (2006)
for computing an approximate fixed point of `T`.
Parameters
----------
is_approx_fp : callable
... | def _compute_fixed_point_ig(T, v, max_iter, verbose, print_skip, is_approx_fp,
*args, **kwargs):
"""
Implement the imitation game algorithm by McLennan and Tourky (2006)
for computing an approximate fixed point of `T`.
Parameters
----------
is_approx_fp : callable
... | [
"Implement",
"the",
"imitation",
"game",
"algorithm",
"by",
"McLennan",
"and",
"Tourky",
"(",
"2006",
")",
"for",
"computing",
"an",
"approximate",
"fixed",
"point",
"of",
"T",
"."
] | QuantEcon/QuantEcon.py | python | https://github.com/QuantEcon/QuantEcon.py/blob/26a66c552f2a73967d7efb6e1f4b4c4985a12643/quantecon/compute_fp.py#L158-L281 | [
"def",
"_compute_fixed_point_ig",
"(",
"T",
",",
"v",
",",
"max_iter",
",",
"verbose",
",",
"print_skip",
",",
"is_approx_fp",
",",
"*",
"args",
",",
"*",
"*",
"kwargs",
")",
":",
"if",
"verbose",
"==",
"2",
":",
"start_time",
"=",
"time",
".",
"time",... | 26a66c552f2a73967d7efb6e1f4b4c4985a12643 |
train | _initialize_tableaux_ig | Given sequences `X` and `Y` of ndarrays, initialize the tableau and
basis arrays in place for the "geometric" imitation game as defined
in McLennan and Tourky (2006), to be passed to `_lemke_howson_tbl`.
Parameters
----------
X, Y : ndarray(float)
Arrays of the same shape (m, n).
table... | quantecon/compute_fp.py | def _initialize_tableaux_ig(X, Y, tableaux, bases):
"""
Given sequences `X` and `Y` of ndarrays, initialize the tableau and
basis arrays in place for the "geometric" imitation game as defined
in McLennan and Tourky (2006), to be passed to `_lemke_howson_tbl`.
Parameters
----------
X, Y : nd... | def _initialize_tableaux_ig(X, Y, tableaux, bases):
"""
Given sequences `X` and `Y` of ndarrays, initialize the tableau and
basis arrays in place for the "geometric" imitation game as defined
in McLennan and Tourky (2006), to be passed to `_lemke_howson_tbl`.
Parameters
----------
X, Y : nd... | [
"Given",
"sequences",
"X",
"and",
"Y",
"of",
"ndarrays",
"initialize",
"the",
"tableau",
"and",
"basis",
"arrays",
"in",
"place",
"for",
"the",
"geometric",
"imitation",
"game",
"as",
"defined",
"in",
"McLennan",
"and",
"Tourky",
"(",
"2006",
")",
"to",
"b... | QuantEcon/QuantEcon.py | python | https://github.com/QuantEcon/QuantEcon.py/blob/26a66c552f2a73967d7efb6e1f4b4c4985a12643/quantecon/compute_fp.py#L285-L352 | [
"def",
"_initialize_tableaux_ig",
"(",
"X",
",",
"Y",
",",
"tableaux",
",",
"bases",
")",
":",
"m",
"=",
"X",
".",
"shape",
"[",
"0",
"]",
"min_",
"=",
"np",
".",
"zeros",
"(",
"m",
")",
"# Mover",
"for",
"i",
"in",
"range",
"(",
"m",
")",
":",... | 26a66c552f2a73967d7efb6e1f4b4c4985a12643 |
train | BaseManager.get_participants | Return an iterable with the active participants in a room. | socketio/base_manager.py | def get_participants(self, namespace, room):
"""Return an iterable with the active participants in a room."""
for sid, active in six.iteritems(self.rooms[namespace][room].copy()):
yield sid | def get_participants(self, namespace, room):
"""Return an iterable with the active participants in a room."""
for sid, active in six.iteritems(self.rooms[namespace][room].copy()):
yield sid | [
"Return",
"an",
"iterable",
"with",
"the",
"active",
"participants",
"in",
"a",
"room",
"."
] | miguelgrinberg/python-socketio | python | https://github.com/miguelgrinberg/python-socketio/blob/c0c1bf8d21e3597389b18938550a0724dd9676b7/socketio/base_manager.py#L38-L41 | [
"def",
"get_participants",
"(",
"self",
",",
"namespace",
",",
"room",
")",
":",
"for",
"sid",
",",
"active",
"in",
"six",
".",
"iteritems",
"(",
"self",
".",
"rooms",
"[",
"namespace",
"]",
"[",
"room",
"]",
".",
"copy",
"(",
")",
")",
":",
"yield... | c0c1bf8d21e3597389b18938550a0724dd9676b7 |
train | BaseManager.connect | Register a client connection to a namespace. | socketio/base_manager.py | def connect(self, sid, namespace):
"""Register a client connection to a namespace."""
self.enter_room(sid, namespace, None)
self.enter_room(sid, namespace, sid) | def connect(self, sid, namespace):
"""Register a client connection to a namespace."""
self.enter_room(sid, namespace, None)
self.enter_room(sid, namespace, sid) | [
"Register",
"a",
"client",
"connection",
"to",
"a",
"namespace",
"."
] | miguelgrinberg/python-socketio | python | https://github.com/miguelgrinberg/python-socketio/blob/c0c1bf8d21e3597389b18938550a0724dd9676b7/socketio/base_manager.py#L43-L46 | [
"def",
"connect",
"(",
"self",
",",
"sid",
",",
"namespace",
")",
":",
"self",
".",
"enter_room",
"(",
"sid",
",",
"namespace",
",",
"None",
")",
"self",
".",
"enter_room",
"(",
"sid",
",",
"namespace",
",",
"sid",
")"
] | c0c1bf8d21e3597389b18938550a0724dd9676b7 |
train | BaseManager.pre_disconnect | Put the client in the to-be-disconnected list.
This allows the client data structures to be present while the
disconnect handler is invoked, but still recognize the fact that the
client is soon going away. | socketio/base_manager.py | def pre_disconnect(self, sid, namespace):
"""Put the client in the to-be-disconnected list.
This allows the client data structures to be present while the
disconnect handler is invoked, but still recognize the fact that the
client is soon going away.
"""
if namespace not... | def pre_disconnect(self, sid, namespace):
"""Put the client in the to-be-disconnected list.
This allows the client data structures to be present while the
disconnect handler is invoked, but still recognize the fact that the
client is soon going away.
"""
if namespace not... | [
"Put",
"the",
"client",
"in",
"the",
"to",
"-",
"be",
"-",
"disconnected",
"list",
"."
] | miguelgrinberg/python-socketio | python | https://github.com/miguelgrinberg/python-socketio/blob/c0c1bf8d21e3597389b18938550a0724dd9676b7/socketio/base_manager.py#L58-L67 | [
"def",
"pre_disconnect",
"(",
"self",
",",
"sid",
",",
"namespace",
")",
":",
"if",
"namespace",
"not",
"in",
"self",
".",
"pending_disconnect",
":",
"self",
".",
"pending_disconnect",
"[",
"namespace",
"]",
"=",
"[",
"]",
"self",
".",
"pending_disconnect",
... | c0c1bf8d21e3597389b18938550a0724dd9676b7 |
train | BaseManager.disconnect | Register a client disconnect from a namespace. | socketio/base_manager.py | def disconnect(self, sid, namespace):
"""Register a client disconnect from a namespace."""
if namespace not in self.rooms:
return
rooms = []
for room_name, room in six.iteritems(self.rooms[namespace].copy()):
if sid in room:
rooms.append(room_name)... | def disconnect(self, sid, namespace):
"""Register a client disconnect from a namespace."""
if namespace not in self.rooms:
return
rooms = []
for room_name, room in six.iteritems(self.rooms[namespace].copy()):
if sid in room:
rooms.append(room_name)... | [
"Register",
"a",
"client",
"disconnect",
"from",
"a",
"namespace",
"."
] | miguelgrinberg/python-socketio | python | https://github.com/miguelgrinberg/python-socketio/blob/c0c1bf8d21e3597389b18938550a0724dd9676b7/socketio/base_manager.py#L69-L87 | [
"def",
"disconnect",
"(",
"self",
",",
"sid",
",",
"namespace",
")",
":",
"if",
"namespace",
"not",
"in",
"self",
".",
"rooms",
":",
"return",
"rooms",
"=",
"[",
"]",
"for",
"room_name",
",",
"room",
"in",
"six",
".",
"iteritems",
"(",
"self",
".",
... | c0c1bf8d21e3597389b18938550a0724dd9676b7 |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.