repository_name stringlengths 7 55 | func_path_in_repository stringlengths 4 223 | func_name stringlengths 1 134 | whole_func_string stringlengths 75 104k | language stringclasses 1
value | func_code_string stringlengths 75 104k | func_code_tokens listlengths 19 28.4k | func_documentation_string stringlengths 1 46.9k | func_documentation_tokens listlengths 1 1.97k | split_name stringclasses 1
value | func_code_url stringlengths 87 315 |
|---|---|---|---|---|---|---|---|---|---|---|
timothyb0912/pylogit | pylogit/asym_logit.py | _asym_transform_deriv_shape | def _asym_transform_deriv_shape(systematic_utilities,
alt_IDs,
rows_to_alts,
eta,
ref_position=None,
dh_dc_array=None,
fill_dc_d... | python | def _asym_transform_deriv_shape(systematic_utilities,
alt_IDs,
rows_to_alts,
eta,
ref_position=None,
dh_dc_array=None,
fill_dc_d... | [
"def",
"_asym_transform_deriv_shape",
"(",
"systematic_utilities",
",",
"alt_IDs",
",",
"rows_to_alts",
",",
"eta",
",",
"ref_position",
"=",
"None",
",",
"dh_dc_array",
"=",
"None",
",",
"fill_dc_d_eta",
"=",
"None",
",",
"output_array",
"=",
"None",
",",
"*",
... | Parameters
----------
systematic_utilities : 1D ndarray.
Contains the systematic utilities for each each available alternative
for each observation. All elements should be ints, floats, or longs.
alt_IDs : 1D ndarray.
All elements should be ints. There should be one row per obervation... | [
"Parameters",
"----------",
"systematic_utilities",
":",
"1D",
"ndarray",
".",
"Contains",
"the",
"systematic",
"utilities",
"for",
"each",
"each",
"available",
"alternative",
"for",
"each",
"observation",
".",
"All",
"elements",
"should",
"be",
"ints",
"floats",
... | train | https://github.com/timothyb0912/pylogit/blob/f83b0fd6debaa7358d87c3828428f6d4ead71357/pylogit/asym_logit.py#L438-L541 |
timothyb0912/pylogit | pylogit/asym_logit.py | create_calc_dh_dv | def create_calc_dh_dv(estimator):
"""
Return the function that can be used in the various gradient and hessian
calculations to calculate the derivative of the transformation with respect
to the index.
Parameters
----------
estimator : an instance of the estimation.LogitTypeEstimator class.
... | python | def create_calc_dh_dv(estimator):
"""
Return the function that can be used in the various gradient and hessian
calculations to calculate the derivative of the transformation with respect
to the index.
Parameters
----------
estimator : an instance of the estimation.LogitTypeEstimator class.
... | [
"def",
"create_calc_dh_dv",
"(",
"estimator",
")",
":",
"dh_dv",
"=",
"diags",
"(",
"np",
".",
"ones",
"(",
"estimator",
".",
"design",
".",
"shape",
"[",
"0",
"]",
")",
",",
"0",
",",
"format",
"=",
"'csr'",
")",
"# Create a function that will take in the... | Return the function that can be used in the various gradient and hessian
calculations to calculate the derivative of the transformation with respect
to the index.
Parameters
----------
estimator : an instance of the estimation.LogitTypeEstimator class.
Should contain a `design` attribute th... | [
"Return",
"the",
"function",
"that",
"can",
"be",
"used",
"in",
"the",
"various",
"gradient",
"and",
"hessian",
"calculations",
"to",
"calculate",
"the",
"derivative",
"of",
"the",
"transformation",
"with",
"respect",
"to",
"the",
"index",
"."
] | train | https://github.com/timothyb0912/pylogit/blob/f83b0fd6debaa7358d87c3828428f6d4ead71357/pylogit/asym_logit.py#L589-L618 |
timothyb0912/pylogit | pylogit/asym_logit.py | create_calc_dh_d_shape | def create_calc_dh_d_shape(estimator):
"""
Return the function that can be used in the various gradient and hessian
calculations to calculate the derivative of the transformation with respect
to the shape parameters.
Parameters
----------
estimator : an instance of the estimation.LogitTypeE... | python | def create_calc_dh_d_shape(estimator):
"""
Return the function that can be used in the various gradient and hessian
calculations to calculate the derivative of the transformation with respect
to the shape parameters.
Parameters
----------
estimator : an instance of the estimation.LogitTypeE... | [
"def",
"create_calc_dh_d_shape",
"(",
"estimator",
")",
":",
"num_alts",
"=",
"estimator",
".",
"rows_to_alts",
".",
"shape",
"[",
"1",
"]",
"pre_dc_d_eta",
"=",
"np",
".",
"zeros",
"(",
"(",
"num_alts",
",",
"num_alts",
"-",
"1",
")",
",",
"dtype",
"=",... | Return the function that can be used in the various gradient and hessian
calculations to calculate the derivative of the transformation with respect
to the shape parameters.
Parameters
----------
estimator : an instance of the estimation.LogitTypeEstimator class.
Should contain a `rows_to_a... | [
"Return",
"the",
"function",
"that",
"can",
"be",
"used",
"in",
"the",
"various",
"gradient",
"and",
"hessian",
"calculations",
"to",
"calculate",
"the",
"derivative",
"of",
"the",
"transformation",
"with",
"respect",
"to",
"the",
"shape",
"parameters",
"."
] | train | https://github.com/timothyb0912/pylogit/blob/f83b0fd6debaa7358d87c3828428f6d4ead71357/pylogit/asym_logit.py#L621-L663 |
timothyb0912/pylogit | pylogit/scobit.py | _scobit_utility_transform | def _scobit_utility_transform(systematic_utilities,
alt_IDs,
rows_to_alts,
shape_params,
intercept_params,
intercept_ref_pos=None,
*args, **... | python | def _scobit_utility_transform(systematic_utilities,
alt_IDs,
rows_to_alts,
shape_params,
intercept_params,
intercept_ref_pos=None,
*args, **... | [
"def",
"_scobit_utility_transform",
"(",
"systematic_utilities",
",",
"alt_IDs",
",",
"rows_to_alts",
",",
"shape_params",
",",
"intercept_params",
",",
"intercept_ref_pos",
"=",
"None",
",",
"*",
"args",
",",
"*",
"*",
"kwargs",
")",
":",
"# Figure out what indices... | Parameters
----------
systematic_utilities : 1D ndarray.
All elements should be ints, floats, or longs. Should contain the
systematic utilities of each observation per available alternative.
Note that this vector is formed by the dot product of the design matrix
with the vector o... | [
"Parameters",
"----------",
"systematic_utilities",
":",
"1D",
"ndarray",
".",
"All",
"elements",
"should",
"be",
"ints",
"floats",
"or",
"longs",
".",
"Should",
"contain",
"the",
"systematic",
"utilities",
"of",
"each",
"observation",
"per",
"available",
"alterna... | train | https://github.com/timothyb0912/pylogit/blob/f83b0fd6debaa7358d87c3828428f6d4ead71357/pylogit/scobit.py#L111-L213 |
timothyb0912/pylogit | pylogit/scobit.py | _scobit_transform_deriv_v | def _scobit_transform_deriv_v(systematic_utilities,
alt_IDs,
rows_to_alts,
shape_params,
output_array=None,
*args, **kwargs):
"""
Parameters
----------
sy... | python | def _scobit_transform_deriv_v(systematic_utilities,
alt_IDs,
rows_to_alts,
shape_params,
output_array=None,
*args, **kwargs):
"""
Parameters
----------
sy... | [
"def",
"_scobit_transform_deriv_v",
"(",
"systematic_utilities",
",",
"alt_IDs",
",",
"rows_to_alts",
",",
"shape_params",
",",
"output_array",
"=",
"None",
",",
"*",
"args",
",",
"*",
"*",
"kwargs",
")",
":",
"# Note the np.exp is needed because the raw curvature par... | Parameters
----------
systematic_utilities : 1D ndarray.
All elements should be ints, floats, or longs. Should contain the
systematic utilities of each observation per available alternative.
Note that this vector is formed by the dot product of the design matrix
with the vector o... | [
"Parameters",
"----------",
"systematic_utilities",
":",
"1D",
"ndarray",
".",
"All",
"elements",
"should",
"be",
"ints",
"floats",
"or",
"longs",
".",
"Should",
"contain",
"the",
"systematic",
"utilities",
"of",
"each",
"observation",
"per",
"available",
"alterna... | train | https://github.com/timothyb0912/pylogit/blob/f83b0fd6debaa7358d87c3828428f6d4ead71357/pylogit/scobit.py#L216-L294 |
timothyb0912/pylogit | pylogit/scobit.py | _scobit_transform_deriv_shape | def _scobit_transform_deriv_shape(systematic_utilities,
alt_IDs,
rows_to_alts,
shape_params,
output_array=None,
*args, **kwargs):
"""
Paramete... | python | def _scobit_transform_deriv_shape(systematic_utilities,
alt_IDs,
rows_to_alts,
shape_params,
output_array=None,
*args, **kwargs):
"""
Paramete... | [
"def",
"_scobit_transform_deriv_shape",
"(",
"systematic_utilities",
",",
"alt_IDs",
",",
"rows_to_alts",
",",
"shape_params",
",",
"output_array",
"=",
"None",
",",
"*",
"args",
",",
"*",
"*",
"kwargs",
")",
":",
"# Note the np.exp is needed because the raw curvature p... | Parameters
----------
systematic_utilities : 1D ndarray.
All elements should be ints, floats, or longs. Should contain the
systematic utilities of each observation per available alternative.
Note that this vector is formed by the dot product of the design matrix
with the vector o... | [
"Parameters",
"----------",
"systematic_utilities",
":",
"1D",
"ndarray",
".",
"All",
"elements",
"should",
"be",
"ints",
"floats",
"or",
"longs",
".",
"Should",
"contain",
"the",
"systematic",
"utilities",
"of",
"each",
"observation",
"per",
"available",
"alterna... | train | https://github.com/timothyb0912/pylogit/blob/f83b0fd6debaa7358d87c3828428f6d4ead71357/pylogit/scobit.py#L297-L374 |
timothyb0912/pylogit | pylogit/scobit.py | MNSL.fit_mle | def fit_mle(self,
init_vals,
init_shapes=None,
init_intercepts=None,
init_coefs=None,
print_res=True,
method="BFGS",
loss_tol=1e-06,
gradient_tol=1e-06,
maxiter=1000,
... | python | def fit_mle(self,
init_vals,
init_shapes=None,
init_intercepts=None,
init_coefs=None,
print_res=True,
method="BFGS",
loss_tol=1e-06,
gradient_tol=1e-06,
maxiter=1000,
... | [
"def",
"fit_mle",
"(",
"self",
",",
"init_vals",
",",
"init_shapes",
"=",
"None",
",",
"init_intercepts",
"=",
"None",
",",
"init_coefs",
"=",
"None",
",",
"print_res",
"=",
"True",
",",
"method",
"=",
"\"BFGS\"",
",",
"loss_tol",
"=",
"1e-06",
",",
"gra... | Parameters
----------
init_vals : 1D ndarray.
The initial values to start the optimization process with. There
should be one value for each index coefficient and shape
parameter being estimated. Shape parameters should come before
intercept parameters, whi... | [
"Parameters",
"----------",
"init_vals",
":",
"1D",
"ndarray",
".",
"The",
"initial",
"values",
"to",
"start",
"the",
"optimization",
"process",
"with",
".",
"There",
"should",
"be",
"one",
"value",
"for",
"each",
"index",
"coefficient",
"and",
"shape",
"param... | train | https://github.com/timothyb0912/pylogit/blob/f83b0fd6debaa7358d87c3828428f6d4ead71357/pylogit/scobit.py#L727-L906 |
timothyb0912/pylogit | pylogit/nested_logit.py | identify_degenerate_nests | def identify_degenerate_nests(nest_spec):
"""
Identify the nests within nest_spec that are degenerate, i.e. those nests
with only a single alternative within the nest.
Parameters
----------
nest_spec : OrderedDict.
Keys are strings that define the name of the nests. Values are lists
... | python | def identify_degenerate_nests(nest_spec):
"""
Identify the nests within nest_spec that are degenerate, i.e. those nests
with only a single alternative within the nest.
Parameters
----------
nest_spec : OrderedDict.
Keys are strings that define the name of the nests. Values are lists
... | [
"def",
"identify_degenerate_nests",
"(",
"nest_spec",
")",
":",
"degenerate_positions",
"=",
"[",
"]",
"for",
"pos",
",",
"key",
"in",
"enumerate",
"(",
"nest_spec",
")",
":",
"if",
"len",
"(",
"nest_spec",
"[",
"key",
"]",
")",
"==",
"1",
":",
"degenera... | Identify the nests within nest_spec that are degenerate, i.e. those nests
with only a single alternative within the nest.
Parameters
----------
nest_spec : OrderedDict.
Keys are strings that define the name of the nests. Values are lists
of alternative ids, denoting which alternatives b... | [
"Identify",
"the",
"nests",
"within",
"nest_spec",
"that",
"are",
"degenerate",
"i",
".",
"e",
".",
"those",
"nests",
"with",
"only",
"a",
"single",
"alternative",
"within",
"the",
"nest",
"."
] | train | https://github.com/timothyb0912/pylogit/blob/f83b0fd6debaa7358d87c3828428f6d4ead71357/pylogit/nested_logit.py#L36-L58 |
timothyb0912/pylogit | pylogit/nested_logit.py | split_param_vec | def split_param_vec(all_params, rows_to_nests, return_all_types=False):
"""
Parameters
----------
all_params : 1D ndarray.
Should contain all of the parameters being estimated (i.e. all the
nest coefficients and all of the index coefficients). All elements
should be ints, floats,... | python | def split_param_vec(all_params, rows_to_nests, return_all_types=False):
"""
Parameters
----------
all_params : 1D ndarray.
Should contain all of the parameters being estimated (i.e. all the
nest coefficients and all of the index coefficients). All elements
should be ints, floats,... | [
"def",
"split_param_vec",
"(",
"all_params",
",",
"rows_to_nests",
",",
"return_all_types",
"=",
"False",
")",
":",
"# Split the array of all coefficients",
"num_nests",
"=",
"rows_to_nests",
".",
"shape",
"[",
"1",
"]",
"orig_nest_coefs",
"=",
"all_params",
"[",
":... | Parameters
----------
all_params : 1D ndarray.
Should contain all of the parameters being estimated (i.e. all the
nest coefficients and all of the index coefficients). All elements
should be ints, floats, or longs.
rows_to_nests : 2D scipy sparse array.
There should be one ro... | [
"Parameters",
"----------",
"all_params",
":",
"1D",
"ndarray",
".",
"Should",
"contain",
"all",
"of",
"the",
"parameters",
"being",
"estimated",
"(",
"i",
".",
"e",
".",
"all",
"the",
"nest",
"coefficients",
"and",
"all",
"of",
"the",
"index",
"coefficients... | train | https://github.com/timothyb0912/pylogit/blob/f83b0fd6debaa7358d87c3828428f6d4ead71357/pylogit/nested_logit.py#L63-L106 |
timothyb0912/pylogit | pylogit/nested_logit.py | NestedEstimator.check_length_of_initial_values | def check_length_of_initial_values(self, init_values):
"""
Ensures that the initial values are of the correct length.
"""
# Figure out how many shape parameters we should have and how many
# index coefficients we should have
num_nests = self.rows_to_nests.shape[1]
... | python | def check_length_of_initial_values(self, init_values):
"""
Ensures that the initial values are of the correct length.
"""
# Figure out how many shape parameters we should have and how many
# index coefficients we should have
num_nests = self.rows_to_nests.shape[1]
... | [
"def",
"check_length_of_initial_values",
"(",
"self",
",",
"init_values",
")",
":",
"# Figure out how many shape parameters we should have and how many",
"# index coefficients we should have",
"num_nests",
"=",
"self",
".",
"rows_to_nests",
".",
"shape",
"[",
"1",
"]",
"num_i... | Ensures that the initial values are of the correct length. | [
"Ensures",
"that",
"the",
"initial",
"values",
"are",
"of",
"the",
"correct",
"length",
"."
] | train | https://github.com/timothyb0912/pylogit/blob/f83b0fd6debaa7358d87c3828428f6d4ead71357/pylogit/nested_logit.py#L177-L195 |
timothyb0912/pylogit | pylogit/nested_logit.py | NestedEstimator.convenience_split_params | def convenience_split_params(self, params, return_all_types=False):
"""
Splits parameter vector into nest parameters and index parameters.
Parameters
----------
all_params : 1D ndarray.
Should contain all of the parameters being estimated (i.e. all the
ne... | python | def convenience_split_params(self, params, return_all_types=False):
"""
Splits parameter vector into nest parameters and index parameters.
Parameters
----------
all_params : 1D ndarray.
Should contain all of the parameters being estimated (i.e. all the
ne... | [
"def",
"convenience_split_params",
"(",
"self",
",",
"params",
",",
"return_all_types",
"=",
"False",
")",
":",
"return",
"split_param_vec",
"(",
"params",
",",
"self",
".",
"rows_to_nests",
",",
"return_all_types",
"=",
"return_all_types",
")"
] | Splits parameter vector into nest parameters and index parameters.
Parameters
----------
all_params : 1D ndarray.
Should contain all of the parameters being estimated (i.e. all the
nest coefficients and all of the index coefficients). All elements
should be i... | [
"Splits",
"parameter",
"vector",
"into",
"nest",
"parameters",
"and",
"index",
"parameters",
"."
] | train | https://github.com/timothyb0912/pylogit/blob/f83b0fd6debaa7358d87c3828428f6d4ead71357/pylogit/nested_logit.py#L197-L236 |
timothyb0912/pylogit | pylogit/nested_logit.py | NestedEstimator.convenience_calc_probs | def convenience_calc_probs(self, params):
"""
Calculates the probabilities of the chosen alternative, and the long
format probabilities for this model and dataset.
"""
orig_nest_coefs, betas = self.convenience_split_params(params)
natural_nest_coefs = nc.naturalize_nest_c... | python | def convenience_calc_probs(self, params):
"""
Calculates the probabilities of the chosen alternative, and the long
format probabilities for this model and dataset.
"""
orig_nest_coefs, betas = self.convenience_split_params(params)
natural_nest_coefs = nc.naturalize_nest_c... | [
"def",
"convenience_calc_probs",
"(",
"self",
",",
"params",
")",
":",
"orig_nest_coefs",
",",
"betas",
"=",
"self",
".",
"convenience_split_params",
"(",
"params",
")",
"natural_nest_coefs",
"=",
"nc",
".",
"naturalize_nest_coefs",
"(",
"orig_nest_coefs",
")",
"a... | Calculates the probabilities of the chosen alternative, and the long
format probabilities for this model and dataset. | [
"Calculates",
"the",
"probabilities",
"of",
"the",
"chosen",
"alternative",
"and",
"the",
"long",
"format",
"probabilities",
"for",
"this",
"model",
"and",
"dataset",
"."
] | train | https://github.com/timothyb0912/pylogit/blob/f83b0fd6debaa7358d87c3828428f6d4ead71357/pylogit/nested_logit.py#L238-L256 |
timothyb0912/pylogit | pylogit/nested_logit.py | NestedEstimator.convenience_calc_log_likelihood | def convenience_calc_log_likelihood(self, params):
"""
Calculates the log-likelihood for this model and dataset.
"""
orig_nest_coefs, betas = self.convenience_split_params(params)
natural_nest_coefs = nc.naturalize_nest_coefs(orig_nest_coefs)
args = [natural_nest_coefs,
... | python | def convenience_calc_log_likelihood(self, params):
"""
Calculates the log-likelihood for this model and dataset.
"""
orig_nest_coefs, betas = self.convenience_split_params(params)
natural_nest_coefs = nc.naturalize_nest_coefs(orig_nest_coefs)
args = [natural_nest_coefs,
... | [
"def",
"convenience_calc_log_likelihood",
"(",
"self",
",",
"params",
")",
":",
"orig_nest_coefs",
",",
"betas",
"=",
"self",
".",
"convenience_split_params",
"(",
"params",
")",
"natural_nest_coefs",
"=",
"nc",
".",
"naturalize_nest_coefs",
"(",
"orig_nest_coefs",
... | Calculates the log-likelihood for this model and dataset. | [
"Calculates",
"the",
"log",
"-",
"likelihood",
"for",
"this",
"model",
"and",
"dataset",
"."
] | train | https://github.com/timothyb0912/pylogit/blob/f83b0fd6debaa7358d87c3828428f6d4ead71357/pylogit/nested_logit.py#L258-L275 |
timothyb0912/pylogit | pylogit/nested_logit.py | NestedEstimator.convenience_calc_gradient | def convenience_calc_gradient(self, params):
"""
Calculates the gradient of the log-likelihood for this model / dataset.
"""
orig_nest_coefs, betas = self.convenience_split_params(params)
args = [orig_nest_coefs,
betas,
self.design,
... | python | def convenience_calc_gradient(self, params):
"""
Calculates the gradient of the log-likelihood for this model / dataset.
"""
orig_nest_coefs, betas = self.convenience_split_params(params)
args = [orig_nest_coefs,
betas,
self.design,
... | [
"def",
"convenience_calc_gradient",
"(",
"self",
",",
"params",
")",
":",
"orig_nest_coefs",
",",
"betas",
"=",
"self",
".",
"convenience_split_params",
"(",
"params",
")",
"args",
"=",
"[",
"orig_nest_coefs",
",",
"betas",
",",
"self",
".",
"design",
",",
"... | Calculates the gradient of the log-likelihood for this model / dataset. | [
"Calculates",
"the",
"gradient",
"of",
"the",
"log",
"-",
"likelihood",
"for",
"this",
"model",
"/",
"dataset",
"."
] | train | https://github.com/timothyb0912/pylogit/blob/f83b0fd6debaa7358d87c3828428f6d4ead71357/pylogit/nested_logit.py#L277-L290 |
timothyb0912/pylogit | pylogit/nested_logit.py | NestedEstimator.convenience_calc_hessian | def convenience_calc_hessian(self, params):
"""
Calculates the hessian of the log-likelihood for this model / dataset.
Note that this function name is INCORRECT with regard to the actual
actions performed. The Nested Logit model uses the BHHH approximation
to the Fisher Informati... | python | def convenience_calc_hessian(self, params):
"""
Calculates the hessian of the log-likelihood for this model / dataset.
Note that this function name is INCORRECT with regard to the actual
actions performed. The Nested Logit model uses the BHHH approximation
to the Fisher Informati... | [
"def",
"convenience_calc_hessian",
"(",
"self",
",",
"params",
")",
":",
"orig_nest_coefs",
",",
"betas",
"=",
"self",
".",
"convenience_split_params",
"(",
"params",
")",
"args",
"=",
"[",
"orig_nest_coefs",
",",
"betas",
",",
"self",
".",
"design",
",",
"s... | Calculates the hessian of the log-likelihood for this model / dataset.
Note that this function name is INCORRECT with regard to the actual
actions performed. The Nested Logit model uses the BHHH approximation
to the Fisher Information Matrix in place of the actual hessian. | [
"Calculates",
"the",
"hessian",
"of",
"the",
"log",
"-",
"likelihood",
"for",
"this",
"model",
"/",
"dataset",
".",
"Note",
"that",
"this",
"function",
"name",
"is",
"INCORRECT",
"with",
"regard",
"to",
"the",
"actual",
"actions",
"performed",
".",
"The",
... | train | https://github.com/timothyb0912/pylogit/blob/f83b0fd6debaa7358d87c3828428f6d4ead71357/pylogit/nested_logit.py#L292-L319 |
timothyb0912/pylogit | pylogit/nested_logit.py | NestedEstimator.convenience_calc_fisher_approx | def convenience_calc_fisher_approx(self, params):
"""
Calculates the BHHH approximation of the Fisher Information Matrix for
this model / dataset. Note that this function name is INCORRECT with
regard to the actual actions performed. The Nested Logit model uses a
placeholder for ... | python | def convenience_calc_fisher_approx(self, params):
"""
Calculates the BHHH approximation of the Fisher Information Matrix for
this model / dataset. Note that this function name is INCORRECT with
regard to the actual actions performed. The Nested Logit model uses a
placeholder for ... | [
"def",
"convenience_calc_fisher_approx",
"(",
"self",
",",
"params",
")",
":",
"placeholder_bhhh",
"=",
"np",
".",
"diag",
"(",
"-",
"1",
"*",
"np",
".",
"ones",
"(",
"params",
".",
"shape",
"[",
"0",
"]",
")",
")",
"return",
"placeholder_bhhh"
] | Calculates the BHHH approximation of the Fisher Information Matrix for
this model / dataset. Note that this function name is INCORRECT with
regard to the actual actions performed. The Nested Logit model uses a
placeholder for the BHHH approximation of the Fisher Information Matrix
becaus... | [
"Calculates",
"the",
"BHHH",
"approximation",
"of",
"the",
"Fisher",
"Information",
"Matrix",
"for",
"this",
"model",
"/",
"dataset",
".",
"Note",
"that",
"this",
"function",
"name",
"is",
"INCORRECT",
"with",
"regard",
"to",
"the",
"actual",
"actions",
"perfo... | train | https://github.com/timothyb0912/pylogit/blob/f83b0fd6debaa7358d87c3828428f6d4ead71357/pylogit/nested_logit.py#L321-L336 |
timothyb0912/pylogit | pylogit/nested_logit.py | NestedLogit.fit_mle | def fit_mle(self,
init_vals,
constrained_pos=None,
print_res=True,
method="BFGS",
loss_tol=1e-06,
gradient_tol=1e-06,
maxiter=1000,
ridge=None,
just_point=False,
... | python | def fit_mle(self,
init_vals,
constrained_pos=None,
print_res=True,
method="BFGS",
loss_tol=1e-06,
gradient_tol=1e-06,
maxiter=1000,
ridge=None,
just_point=False,
... | [
"def",
"fit_mle",
"(",
"self",
",",
"init_vals",
",",
"constrained_pos",
"=",
"None",
",",
"print_res",
"=",
"True",
",",
"method",
"=",
"\"BFGS\"",
",",
"loss_tol",
"=",
"1e-06",
",",
"gradient_tol",
"=",
"1e-06",
",",
"maxiter",
"=",
"1000",
",",
"ridg... | Parameters
----------
init_vals : 1D ndarray.
Should containn the initial values to start the optimization
process with. There should be one value for each nest parameter
and utility coefficient. Nest parameters not being estimated
should still be included... | [
"Parameters",
"----------",
"init_vals",
":",
"1D",
"ndarray",
".",
"Should",
"containn",
"the",
"initial",
"values",
"to",
"start",
"the",
"optimization",
"process",
"with",
".",
"There",
"should",
"be",
"one",
"value",
"for",
"each",
"nest",
"parameter",
"an... | train | https://github.com/timothyb0912/pylogit/blob/f83b0fd6debaa7358d87c3828428f6d4ead71357/pylogit/nested_logit.py#L440-L556 |
timothyb0912/pylogit | pylogit/choice_calcs.py | calc_probabilities | def calc_probabilities(beta,
design,
alt_IDs,
rows_to_obs,
rows_to_alts,
utility_transform,
intercept_params=None,
shape_params=None,
ch... | python | def calc_probabilities(beta,
design,
alt_IDs,
rows_to_obs,
rows_to_alts,
utility_transform,
intercept_params=None,
shape_params=None,
ch... | [
"def",
"calc_probabilities",
"(",
"beta",
",",
"design",
",",
"alt_IDs",
",",
"rows_to_obs",
",",
"rows_to_alts",
",",
"utility_transform",
",",
"intercept_params",
"=",
"None",
",",
"shape_params",
"=",
"None",
",",
"chosen_row_to_obs",
"=",
"None",
",",
"retur... | Parameters
----------
beta : 1D or 2D ndarray.
All elements should by ints, floats, or longs. If 1D, should have 1
element for each utility coefficient being estimated (i.e.
num_features). If 2D, should have 1 column for each set of coefficients
being used to predict the probabil... | [
"Parameters",
"----------",
"beta",
":",
"1D",
"or",
"2D",
"ndarray",
".",
"All",
"elements",
"should",
"by",
"ints",
"floats",
"or",
"longs",
".",
"If",
"1D",
"should",
"have",
"1",
"element",
"for",
"each",
"utility",
"coefficient",
"being",
"estimated",
... | train | https://github.com/timothyb0912/pylogit/blob/f83b0fd6debaa7358d87c3828428f6d4ead71357/pylogit/choice_calcs.py#L34-L187 |
timothyb0912/pylogit | pylogit/choice_calcs.py | calc_log_likelihood | def calc_log_likelihood(beta,
design,
alt_IDs,
rows_to_obs,
rows_to_alts,
choice_vector,
utility_transform,
intercept_params=None,
... | python | def calc_log_likelihood(beta,
design,
alt_IDs,
rows_to_obs,
rows_to_alts,
choice_vector,
utility_transform,
intercept_params=None,
... | [
"def",
"calc_log_likelihood",
"(",
"beta",
",",
"design",
",",
"alt_IDs",
",",
"rows_to_obs",
",",
"rows_to_alts",
",",
"choice_vector",
",",
"utility_transform",
",",
"intercept_params",
"=",
"None",
",",
"shape_params",
"=",
"None",
",",
"ridge",
"=",
"None",
... | Parameters
----------
beta : 1D ndarray.
All elements should by ints, floats, or longs. Should have 1 element
for each utility coefficient being estimated (i.e. num_features).
design : 2D ndarray.
There should be one row per observation per available alternative.
There should... | [
"Parameters",
"----------",
"beta",
":",
"1D",
"ndarray",
".",
"All",
"elements",
"should",
"by",
"ints",
"floats",
"or",
"longs",
".",
"Should",
"have",
"1",
"element",
"for",
"each",
"utility",
"coefficient",
"being",
"estimated",
"(",
"i",
".",
"e",
"."... | train | https://github.com/timothyb0912/pylogit/blob/f83b0fd6debaa7358d87c3828428f6d4ead71357/pylogit/choice_calcs.py#L190-L285 |
timothyb0912/pylogit | pylogit/choice_calcs.py | calc_gradient | def calc_gradient(beta,
design,
alt_IDs,
rows_to_obs,
rows_to_alts,
choice_vector,
utility_transform,
transform_first_deriv_c,
transform_first_deriv_v,
transf... | python | def calc_gradient(beta,
design,
alt_IDs,
rows_to_obs,
rows_to_alts,
choice_vector,
utility_transform,
transform_first_deriv_c,
transform_first_deriv_v,
transf... | [
"def",
"calc_gradient",
"(",
"beta",
",",
"design",
",",
"alt_IDs",
",",
"rows_to_obs",
",",
"rows_to_alts",
",",
"choice_vector",
",",
"utility_transform",
",",
"transform_first_deriv_c",
",",
"transform_first_deriv_v",
",",
"transform_deriv_alpha",
",",
"intercept_par... | Parameters
----------
beta : 1D ndarray.
All elements should by ints, floats, or longs. Should have 1 element
for each utility coefficient being estimated (i.e. num_features).
design : 2D ndarray.
Tjere should be one row per observation per available alternative.
There should... | [
"Parameters",
"----------",
"beta",
":",
"1D",
"ndarray",
".",
"All",
"elements",
"should",
"by",
"ints",
"floats",
"or",
"longs",
".",
"Should",
"have",
"1",
"element",
"for",
"each",
"utility",
"coefficient",
"being",
"estimated",
"(",
"i",
".",
"e",
"."... | train | https://github.com/timothyb0912/pylogit/blob/f83b0fd6debaa7358d87c3828428f6d4ead71357/pylogit/choice_calcs.py#L288-L484 |
timothyb0912/pylogit | pylogit/choice_calcs.py | create_matrix_block_indices | def create_matrix_block_indices(row_to_obs):
"""
Parameters
----------
row_to_obs: 2D ndarray.
There should be one row per observation per available alternative and
one column per observation. This matrix maps the rows of the design
matrix to the unique observations (on the colum... | python | def create_matrix_block_indices(row_to_obs):
"""
Parameters
----------
row_to_obs: 2D ndarray.
There should be one row per observation per available alternative and
one column per observation. This matrix maps the rows of the design
matrix to the unique observations (on the colum... | [
"def",
"create_matrix_block_indices",
"(",
"row_to_obs",
")",
":",
"# Initialize the list of index arrays to be returned",
"output_indices",
"=",
"[",
"]",
"# Determine the number of observations in the dataset",
"num_obs",
"=",
"row_to_obs",
".",
"shape",
"[",
"1",
"]",
"# G... | Parameters
----------
row_to_obs: 2D ndarray.
There should be one row per observation per available alternative and
one column per observation. This matrix maps the rows of the design
matrix to the unique observations (on the columns).
Returns
-------
output_indices : list o... | [
"Parameters",
"----------",
"row_to_obs",
":",
"2D",
"ndarray",
".",
"There",
"should",
"be",
"one",
"row",
"per",
"observation",
"per",
"available",
"alternative",
"and",
"one",
"column",
"per",
"observation",
".",
"This",
"matrix",
"maps",
"the",
"rows",
"of... | train | https://github.com/timothyb0912/pylogit/blob/f83b0fd6debaa7358d87c3828428f6d4ead71357/pylogit/choice_calcs.py#L492-L520 |
timothyb0912/pylogit | pylogit/choice_calcs.py | robust_outer_product | def robust_outer_product(vec_1, vec_2):
"""
Calculates a 'robust' outer product of two vectors that may or may not
contain very small values.
Parameters
----------
vec_1 : 1D ndarray
vec_2 : 1D ndarray
Returns
-------
outer_prod : 2D ndarray. The outer product of vec_1 and vec_... | python | def robust_outer_product(vec_1, vec_2):
"""
Calculates a 'robust' outer product of two vectors that may or may not
contain very small values.
Parameters
----------
vec_1 : 1D ndarray
vec_2 : 1D ndarray
Returns
-------
outer_prod : 2D ndarray. The outer product of vec_1 and vec_... | [
"def",
"robust_outer_product",
"(",
"vec_1",
",",
"vec_2",
")",
":",
"mantissa_1",
",",
"exponents_1",
"=",
"np",
".",
"frexp",
"(",
"vec_1",
")",
"mantissa_2",
",",
"exponents_2",
"=",
"np",
".",
"frexp",
"(",
"vec_2",
")",
"new_mantissas",
"=",
"mantissa... | Calculates a 'robust' outer product of two vectors that may or may not
contain very small values.
Parameters
----------
vec_1 : 1D ndarray
vec_2 : 1D ndarray
Returns
-------
outer_prod : 2D ndarray. The outer product of vec_1 and vec_2 | [
"Calculates",
"a",
"robust",
"outer",
"product",
"of",
"two",
"vectors",
"that",
"may",
"or",
"may",
"not",
"contain",
"very",
"small",
"values",
"."
] | train | https://github.com/timothyb0912/pylogit/blob/f83b0fd6debaa7358d87c3828428f6d4ead71357/pylogit/choice_calcs.py#L523-L541 |
timothyb0912/pylogit | pylogit/choice_calcs.py | create_matrix_blocks | def create_matrix_blocks(long_probs, matrix_block_indices):
"""
Parameters
----------
long_probs : 1D ndarray.
There should be one row per observation per available alternative. The
elements of the array will indicate the probability of the alternative
being the outcome associate... | python | def create_matrix_blocks(long_probs, matrix_block_indices):
"""
Parameters
----------
long_probs : 1D ndarray.
There should be one row per observation per available alternative. The
elements of the array will indicate the probability of the alternative
being the outcome associate... | [
"def",
"create_matrix_blocks",
"(",
"long_probs",
",",
"matrix_block_indices",
")",
":",
"# Initialize the list of matrices that is to be returned.",
"output_matrices",
"=",
"[",
"]",
"# Iterate over each observation, i.e. over each list of rows that",
"# corresponds to each observation.... | Parameters
----------
long_probs : 1D ndarray.
There should be one row per observation per available alternative. The
elements of the array will indicate the probability of the alternative
being the outcome associated with the corresponding observation.
matrix_block_indices : list of... | [
"Parameters",
"----------",
"long_probs",
":",
"1D",
"ndarray",
".",
"There",
"should",
"be",
"one",
"row",
"per",
"observation",
"per",
"available",
"alternative",
".",
"The",
"elements",
"of",
"the",
"array",
"will",
"indicate",
"the",
"probability",
"of",
"... | train | https://github.com/timothyb0912/pylogit/blob/f83b0fd6debaa7358d87c3828428f6d4ead71357/pylogit/choice_calcs.py#L544-L598 |
timothyb0912/pylogit | pylogit/choice_calcs.py | calc_hessian | def calc_hessian(beta,
design,
alt_IDs,
rows_to_obs,
rows_to_alts,
utility_transform,
transform_first_deriv_c,
transform_first_deriv_v,
transform_deriv_alpha,
block_ma... | python | def calc_hessian(beta,
design,
alt_IDs,
rows_to_obs,
rows_to_alts,
utility_transform,
transform_first_deriv_c,
transform_first_deriv_v,
transform_deriv_alpha,
block_ma... | [
"def",
"calc_hessian",
"(",
"beta",
",",
"design",
",",
"alt_IDs",
",",
"rows_to_obs",
",",
"rows_to_alts",
",",
"utility_transform",
",",
"transform_first_deriv_c",
",",
"transform_first_deriv_v",
",",
"transform_deriv_alpha",
",",
"block_matrix_idxs",
",",
"intercept_... | Parameters
----------
beta : 1D ndarray.
All elements should by ints, floats, or longs. Should have 1 element
for each utility coefficient being estimated (i.e. num_features).
design : 2D ndarray.
There should be one row per observation per available alternative.
There should... | [
"Parameters",
"----------",
"beta",
":",
"1D",
"ndarray",
".",
"All",
"elements",
"should",
"by",
"ints",
"floats",
"or",
"longs",
".",
"Should",
"have",
"1",
"element",
"for",
"each",
"utility",
"coefficient",
"being",
"estimated",
"(",
"i",
".",
"e",
"."... | train | https://github.com/timothyb0912/pylogit/blob/f83b0fd6debaa7358d87c3828428f6d4ead71357/pylogit/choice_calcs.py#L601-L854 |
timothyb0912/pylogit | pylogit/choice_calcs.py | calc_fisher_info_matrix | def calc_fisher_info_matrix(beta,
design,
alt_IDs,
rows_to_obs,
rows_to_alts,
choice_vector,
utility_transform,
transform_fi... | python | def calc_fisher_info_matrix(beta,
design,
alt_IDs,
rows_to_obs,
rows_to_alts,
choice_vector,
utility_transform,
transform_fi... | [
"def",
"calc_fisher_info_matrix",
"(",
"beta",
",",
"design",
",",
"alt_IDs",
",",
"rows_to_obs",
",",
"rows_to_alts",
",",
"choice_vector",
",",
"utility_transform",
",",
"transform_first_deriv_c",
",",
"transform_first_deriv_v",
",",
"transform_deriv_alpha",
",",
"int... | Parameters
----------
beta : 1D ndarray.
All elements should by ints, floats, or longs. Should have 1 element
for each utility coefficient being estimated (i.e. num_features).
design : 2D ndarray.
There should be one row per observation per available alternative.
There should... | [
"Parameters",
"----------",
"beta",
":",
"1D",
"ndarray",
".",
"All",
"elements",
"should",
"by",
"ints",
"floats",
"or",
"longs",
".",
"Should",
"have",
"1",
"element",
"for",
"each",
"utility",
"coefficient",
"being",
"estimated",
"(",
"i",
".",
"e",
"."... | train | https://github.com/timothyb0912/pylogit/blob/f83b0fd6debaa7358d87c3828428f6d4ead71357/pylogit/choice_calcs.py#L857-L1030 |
timothyb0912/pylogit | pylogit/choice_calcs.py | calc_asymptotic_covariance | def calc_asymptotic_covariance(hessian, fisher_info_matrix):
"""
Parameters
----------
hessian : 2D ndarray.
It should have shape `(num_vars, num_vars)`. It is the matrix of second
derivatives of the total loss across the dataset, with respect to each
pair of coefficients being e... | python | def calc_asymptotic_covariance(hessian, fisher_info_matrix):
"""
Parameters
----------
hessian : 2D ndarray.
It should have shape `(num_vars, num_vars)`. It is the matrix of second
derivatives of the total loss across the dataset, with respect to each
pair of coefficients being e... | [
"def",
"calc_asymptotic_covariance",
"(",
"hessian",
",",
"fisher_info_matrix",
")",
":",
"# Calculate the inverse of the hessian",
"hess_inv",
"=",
"scipy",
".",
"linalg",
".",
"inv",
"(",
"hessian",
")",
"return",
"np",
".",
"dot",
"(",
"hess_inv",
",",
"np",
... | Parameters
----------
hessian : 2D ndarray.
It should have shape `(num_vars, num_vars)`. It is the matrix of second
derivatives of the total loss across the dataset, with respect to each
pair of coefficients being estimated.
fisher_info_matrix : 2D ndarray.
It should have a s... | [
"Parameters",
"----------",
"hessian",
":",
"2D",
"ndarray",
".",
"It",
"should",
"have",
"shape",
"(",
"num_vars",
"num_vars",
")",
".",
"It",
"is",
"the",
"matrix",
"of",
"second",
"derivatives",
"of",
"the",
"total",
"loss",
"across",
"the",
"dataset",
... | train | https://github.com/timothyb0912/pylogit/blob/f83b0fd6debaa7358d87c3828428f6d4ead71357/pylogit/choice_calcs.py#L1033-L1057 |
timothyb0912/pylogit | pylogit/bootstrap_calcs.py | calc_percentile_interval | def calc_percentile_interval(bootstrap_replicates, conf_percentage):
"""
Calculate bootstrap confidence intervals based on raw percentiles of the
bootstrap distribution of samples.
Parameters
----------
bootstrap_replicates : 2D ndarray.
Each row should correspond to a different bootstr... | python | def calc_percentile_interval(bootstrap_replicates, conf_percentage):
"""
Calculate bootstrap confidence intervals based on raw percentiles of the
bootstrap distribution of samples.
Parameters
----------
bootstrap_replicates : 2D ndarray.
Each row should correspond to a different bootstr... | [
"def",
"calc_percentile_interval",
"(",
"bootstrap_replicates",
",",
"conf_percentage",
")",
":",
"# Check validity of arguments",
"check_conf_percentage_validity",
"(",
"conf_percentage",
")",
"ensure_samples_is_ndim_ndarray",
"(",
"bootstrap_replicates",
",",
"ndim",
"=",
"2"... | Calculate bootstrap confidence intervals based on raw percentiles of the
bootstrap distribution of samples.
Parameters
----------
bootstrap_replicates : 2D ndarray.
Each row should correspond to a different bootstrap parameter sample.
Each column should correspond to an element of the p... | [
"Calculate",
"bootstrap",
"confidence",
"intervals",
"based",
"on",
"raw",
"percentiles",
"of",
"the",
"bootstrap",
"distribution",
"of",
"samples",
"."
] | train | https://github.com/timothyb0912/pylogit/blob/f83b0fd6debaa7358d87c3828428f6d4ead71357/pylogit/bootstrap_calcs.py#L20-L83 |
timothyb0912/pylogit | pylogit/bootstrap_calcs.py | calc_bias_correction_bca | def calc_bias_correction_bca(bootstrap_replicates, mle_estimate):
"""
Calculate the bias correction for the Bias Corrected and Accelerated (BCa)
bootstrap confidence intervals.
Parameters
----------
bootstrap_replicates : 2D ndarray.
Each row should correspond to a different bootstrap p... | python | def calc_bias_correction_bca(bootstrap_replicates, mle_estimate):
"""
Calculate the bias correction for the Bias Corrected and Accelerated (BCa)
bootstrap confidence intervals.
Parameters
----------
bootstrap_replicates : 2D ndarray.
Each row should correspond to a different bootstrap p... | [
"def",
"calc_bias_correction_bca",
"(",
"bootstrap_replicates",
",",
"mle_estimate",
")",
":",
"numerator",
"=",
"(",
"bootstrap_replicates",
"<",
"mle_estimate",
"[",
"None",
",",
":",
"]",
")",
".",
"sum",
"(",
"axis",
"=",
"0",
")",
"denominator",
"=",
"f... | Calculate the bias correction for the Bias Corrected and Accelerated (BCa)
bootstrap confidence intervals.
Parameters
----------
bootstrap_replicates : 2D ndarray.
Each row should correspond to a different bootstrap parameter sample.
Each column should correspond to an element of the pa... | [
"Calculate",
"the",
"bias",
"correction",
"for",
"the",
"Bias",
"Corrected",
"and",
"Accelerated",
"(",
"BCa",
")",
"bootstrap",
"confidence",
"intervals",
"."
] | train | https://github.com/timothyb0912/pylogit/blob/f83b0fd6debaa7358d87c3828428f6d4ead71357/pylogit/bootstrap_calcs.py#L86-L116 |
timothyb0912/pylogit | pylogit/bootstrap_calcs.py | calc_acceleration_bca | def calc_acceleration_bca(jackknife_replicates):
"""
Calculate the acceleration constant for the Bias Corrected and Accelerated
(BCa) bootstrap confidence intervals.
Parameters
----------
jackknife_replicates : 2D ndarray.
Each row should correspond to a different jackknife parameter sa... | python | def calc_acceleration_bca(jackknife_replicates):
"""
Calculate the acceleration constant for the Bias Corrected and Accelerated
(BCa) bootstrap confidence intervals.
Parameters
----------
jackknife_replicates : 2D ndarray.
Each row should correspond to a different jackknife parameter sa... | [
"def",
"calc_acceleration_bca",
"(",
"jackknife_replicates",
")",
":",
"# Get the mean of the bootstrapped statistics.",
"jackknife_mean",
"=",
"jackknife_replicates",
".",
"mean",
"(",
"axis",
"=",
"0",
")",
"[",
"None",
",",
":",
"]",
"# Calculate the differences betwee... | Calculate the acceleration constant for the Bias Corrected and Accelerated
(BCa) bootstrap confidence intervals.
Parameters
----------
jackknife_replicates : 2D ndarray.
Each row should correspond to a different jackknife parameter sample,
formed by deleting a particular observation and... | [
"Calculate",
"the",
"acceleration",
"constant",
"for",
"the",
"Bias",
"Corrected",
"and",
"Accelerated",
"(",
"BCa",
")",
"bootstrap",
"confidence",
"intervals",
"."
] | train | https://github.com/timothyb0912/pylogit/blob/f83b0fd6debaa7358d87c3828428f6d4ead71357/pylogit/bootstrap_calcs.py#L119-L157 |
timothyb0912/pylogit | pylogit/bootstrap_calcs.py | calc_lower_bca_percentile | def calc_lower_bca_percentile(alpha_percent, bias_correction, acceleration):
"""
Calculate the lower values of the Bias Corrected and Accelerated (BCa)
bootstrap confidence intervals.
Parameters
----------
alpha_percent : float in (0.0, 100.0).
`100 - confidence_percentage`, where `conf... | python | def calc_lower_bca_percentile(alpha_percent, bias_correction, acceleration):
"""
Calculate the lower values of the Bias Corrected and Accelerated (BCa)
bootstrap confidence intervals.
Parameters
----------
alpha_percent : float in (0.0, 100.0).
`100 - confidence_percentage`, where `conf... | [
"def",
"calc_lower_bca_percentile",
"(",
"alpha_percent",
",",
"bias_correction",
",",
"acceleration",
")",
":",
"z_lower",
"=",
"norm",
".",
"ppf",
"(",
"alpha_percent",
"/",
"(",
"100.0",
"*",
"2",
")",
")",
"numerator",
"=",
"bias_correction",
"+",
"z_lower... | Calculate the lower values of the Bias Corrected and Accelerated (BCa)
bootstrap confidence intervals.
Parameters
----------
alpha_percent : float in (0.0, 100.0).
`100 - confidence_percentage`, where `confidence_percentage` is the
confidence level (such as 95%), expressed as a percent.... | [
"Calculate",
"the",
"lower",
"values",
"of",
"the",
"Bias",
"Corrected",
"and",
"Accelerated",
"(",
"BCa",
")",
"bootstrap",
"confidence",
"intervals",
"."
] | train | https://github.com/timothyb0912/pylogit/blob/f83b0fd6debaa7358d87c3828428f6d4ead71357/pylogit/bootstrap_calcs.py#L160-L204 |
timothyb0912/pylogit | pylogit/bootstrap_calcs.py | calc_upper_bca_percentile | def calc_upper_bca_percentile(alpha_percent, bias_correction, acceleration):
"""
Calculate the lower values of the Bias Corrected and Accelerated (BCa)
bootstrap confidence intervals.
Parameters
----------
alpha_percent : float in (0.0, 100.0).
`100 - confidence_percentage`, where `conf... | python | def calc_upper_bca_percentile(alpha_percent, bias_correction, acceleration):
"""
Calculate the lower values of the Bias Corrected and Accelerated (BCa)
bootstrap confidence intervals.
Parameters
----------
alpha_percent : float in (0.0, 100.0).
`100 - confidence_percentage`, where `conf... | [
"def",
"calc_upper_bca_percentile",
"(",
"alpha_percent",
",",
"bias_correction",
",",
"acceleration",
")",
":",
"z_upper",
"=",
"norm",
".",
"ppf",
"(",
"1",
"-",
"alpha_percent",
"/",
"(",
"100.0",
"*",
"2",
")",
")",
"numerator",
"=",
"bias_correction",
"... | Calculate the lower values of the Bias Corrected and Accelerated (BCa)
bootstrap confidence intervals.
Parameters
----------
alpha_percent : float in (0.0, 100.0).
`100 - confidence_percentage`, where `confidence_percentage` is the
confidence level (such as 95%), expressed as a percent.... | [
"Calculate",
"the",
"lower",
"values",
"of",
"the",
"Bias",
"Corrected",
"and",
"Accelerated",
"(",
"BCa",
")",
"bootstrap",
"confidence",
"intervals",
"."
] | train | https://github.com/timothyb0912/pylogit/blob/f83b0fd6debaa7358d87c3828428f6d4ead71357/pylogit/bootstrap_calcs.py#L207-L251 |
timothyb0912/pylogit | pylogit/bootstrap_calcs.py | calc_bca_interval | def calc_bca_interval(bootstrap_replicates,
jackknife_replicates,
mle_params,
conf_percentage):
"""
Calculate 'bias-corrected and accelerated' bootstrap confidence intervals.
Parameters
----------
bootstrap_replicates : 2D ndarray.
... | python | def calc_bca_interval(bootstrap_replicates,
jackknife_replicates,
mle_params,
conf_percentage):
"""
Calculate 'bias-corrected and accelerated' bootstrap confidence intervals.
Parameters
----------
bootstrap_replicates : 2D ndarray.
... | [
"def",
"calc_bca_interval",
"(",
"bootstrap_replicates",
",",
"jackknife_replicates",
",",
"mle_params",
",",
"conf_percentage",
")",
":",
"# Check validity of arguments",
"check_conf_percentage_validity",
"(",
"conf_percentage",
")",
"ensure_samples_is_ndim_ndarray",
"(",
"boo... | Calculate 'bias-corrected and accelerated' bootstrap confidence intervals.
Parameters
----------
bootstrap_replicates : 2D ndarray.
Each row should correspond to a different bootstrap parameter sample.
Each column should correspond to an element of the parameter vector
being estimat... | [
"Calculate",
"bias",
"-",
"corrected",
"and",
"accelerated",
"bootstrap",
"confidence",
"intervals",
"."
] | train | https://github.com/timothyb0912/pylogit/blob/f83b0fd6debaa7358d87c3828428f6d4ead71357/pylogit/bootstrap_calcs.py#L254-L323 |
timothyb0912/pylogit | pylogit/bootstrap_mle.py | extract_default_init_vals | def extract_default_init_vals(orig_model_obj, mnl_point_series, num_params):
"""
Get the default initial values for the desired model type, based on the
point estimate of the MNL model that is 'closest' to the desired model.
Parameters
----------
orig_model_obj : an instance or sublcass of the ... | python | def extract_default_init_vals(orig_model_obj, mnl_point_series, num_params):
"""
Get the default initial values for the desired model type, based on the
point estimate of the MNL model that is 'closest' to the desired model.
Parameters
----------
orig_model_obj : an instance or sublcass of the ... | [
"def",
"extract_default_init_vals",
"(",
"orig_model_obj",
",",
"mnl_point_series",
",",
"num_params",
")",
":",
"# Initialize the initial values",
"init_vals",
"=",
"np",
".",
"zeros",
"(",
"num_params",
",",
"dtype",
"=",
"float",
")",
"# Figure out which values in mn... | Get the default initial values for the desired model type, based on the
point estimate of the MNL model that is 'closest' to the desired model.
Parameters
----------
orig_model_obj : an instance or sublcass of the MNDC class.
Should correspond to the actual model that we want to bootstrap.
... | [
"Get",
"the",
"default",
"initial",
"values",
"for",
"the",
"desired",
"model",
"type",
"based",
"on",
"the",
"point",
"estimate",
"of",
"the",
"MNL",
"model",
"that",
"is",
"closest",
"to",
"the",
"desired",
"model",
"."
] | train | https://github.com/timothyb0912/pylogit/blob/f83b0fd6debaa7358d87c3828428f6d4ead71357/pylogit/bootstrap_mle.py#L14-L75 |
timothyb0912/pylogit | pylogit/bootstrap_mle.py | get_model_abbrev | def get_model_abbrev(model_obj):
"""
Extract the string used to specify the model type of this model object in
`pylogit.create_chohice_model`.
Parameters
----------
model_obj : An MNDC_Model instance.
Returns
-------
str. The internal abbreviation used for the particular type of MN... | python | def get_model_abbrev(model_obj):
"""
Extract the string used to specify the model type of this model object in
`pylogit.create_chohice_model`.
Parameters
----------
model_obj : An MNDC_Model instance.
Returns
-------
str. The internal abbreviation used for the particular type of MN... | [
"def",
"get_model_abbrev",
"(",
"model_obj",
")",
":",
"# Get the 'display name' for our model.",
"model_type",
"=",
"model_obj",
".",
"model_type",
"# Find the model abbreviation for this model's display name.",
"for",
"key",
"in",
"model_type_to_display_name",
":",
"if",
"mod... | Extract the string used to specify the model type of this model object in
`pylogit.create_chohice_model`.
Parameters
----------
model_obj : An MNDC_Model instance.
Returns
-------
str. The internal abbreviation used for the particular type of MNDC_Model. | [
"Extract",
"the",
"string",
"used",
"to",
"specify",
"the",
"model",
"type",
"of",
"this",
"model",
"object",
"in",
"pylogit",
".",
"create_chohice_model",
"."
] | train | https://github.com/timothyb0912/pylogit/blob/f83b0fd6debaa7358d87c3828428f6d4ead71357/pylogit/bootstrap_mle.py#L78-L100 |
timothyb0912/pylogit | pylogit/bootstrap_mle.py | get_model_creation_kwargs | def get_model_creation_kwargs(model_obj):
"""
Get a dictionary of the keyword arguments needed to create the passed model
object using `pylogit.create_choice_model`.
Parameters
----------
model_obj : An MNDC_Model instance.
Returns
-------
model_kwargs : dict.
Contains the ... | python | def get_model_creation_kwargs(model_obj):
"""
Get a dictionary of the keyword arguments needed to create the passed model
object using `pylogit.create_choice_model`.
Parameters
----------
model_obj : An MNDC_Model instance.
Returns
-------
model_kwargs : dict.
Contains the ... | [
"def",
"get_model_creation_kwargs",
"(",
"model_obj",
")",
":",
"# Extract the model abbreviation for this model",
"model_abbrev",
"=",
"get_model_abbrev",
"(",
"model_obj",
")",
"# Create a dictionary to store the keyword arguments needed to Initialize",
"# the new model object.d",
"m... | Get a dictionary of the keyword arguments needed to create the passed model
object using `pylogit.create_choice_model`.
Parameters
----------
model_obj : An MNDC_Model instance.
Returns
-------
model_kwargs : dict.
Contains the keyword arguments and the required values that are nee... | [
"Get",
"a",
"dictionary",
"of",
"the",
"keyword",
"arguments",
"needed",
"to",
"create",
"the",
"passed",
"model",
"object",
"using",
"pylogit",
".",
"create_choice_model",
"."
] | train | https://github.com/timothyb0912/pylogit/blob/f83b0fd6debaa7358d87c3828428f6d4ead71357/pylogit/bootstrap_mle.py#L103-L133 |
timothyb0912/pylogit | pylogit/bootstrap_mle.py | get_mnl_point_est | def get_mnl_point_est(orig_model_obj,
new_df,
boot_id_col,
num_params,
mnl_spec,
mnl_names,
mnl_init_vals,
mnl_fit_kwargs):
"""
Calculates the MLE for the des... | python | def get_mnl_point_est(orig_model_obj,
new_df,
boot_id_col,
num_params,
mnl_spec,
mnl_names,
mnl_init_vals,
mnl_fit_kwargs):
"""
Calculates the MLE for the des... | [
"def",
"get_mnl_point_est",
"(",
"orig_model_obj",
",",
"new_df",
",",
"boot_id_col",
",",
"num_params",
",",
"mnl_spec",
",",
"mnl_names",
",",
"mnl_init_vals",
",",
"mnl_fit_kwargs",
")",
":",
"# Get specification and name dictionaries for the mnl model, for the case",
"#... | Calculates the MLE for the desired MNL model.
Parameters
----------
orig_model_obj : An MNDC_Model instance.
The object corresponding to the desired model being bootstrapped.
new_df : pandas DataFrame.
The pandas dataframe containing the data to be used to estimate the
MLE of th... | [
"Calculates",
"the",
"MLE",
"for",
"the",
"desired",
"MNL",
"model",
"."
] | train | https://github.com/timothyb0912/pylogit/blob/f83b0fd6debaa7358d87c3828428f6d4ead71357/pylogit/bootstrap_mle.py#L136-L219 |
timothyb0912/pylogit | pylogit/bootstrap_mle.py | retrieve_point_est | def retrieve_point_est(orig_model_obj,
new_df,
new_id_col,
num_params,
mnl_spec,
mnl_names,
mnl_init_vals,
mnl_fit_kwargs,
extract_init_... | python | def retrieve_point_est(orig_model_obj,
new_df,
new_id_col,
num_params,
mnl_spec,
mnl_names,
mnl_init_vals,
mnl_fit_kwargs,
extract_init_... | [
"def",
"retrieve_point_est",
"(",
"orig_model_obj",
",",
"new_df",
",",
"new_id_col",
",",
"num_params",
",",
"mnl_spec",
",",
"mnl_names",
",",
"mnl_init_vals",
",",
"mnl_fit_kwargs",
",",
"extract_init_vals",
"=",
"None",
",",
"*",
"*",
"fit_kwargs",
")",
":",... | Calculates the MLE for the desired MNL model.
Parameters
----------
orig_model_obj : An MNDC_Model instance.
The object corresponding to the desired model being bootstrapped.
new_df : pandas DataFrame.
The pandas dataframe containing the data to be used to estimate the
MLE of th... | [
"Calculates",
"the",
"MLE",
"for",
"the",
"desired",
"MNL",
"model",
"."
] | train | https://github.com/timothyb0912/pylogit/blob/f83b0fd6debaa7358d87c3828428f6d4ead71357/pylogit/bootstrap_mle.py#L222-L335 |
timothyb0912/pylogit | pylogit/pylogit.py | ensure_valid_model_type | def ensure_valid_model_type(specified_type, model_type_list):
"""
Checks to make sure that `specified_type` is in `model_type_list` and
raises a helpful error if this is not the case.
Parameters
----------
specified_type : str.
Denotes the user-specified model type that is to be checked... | python | def ensure_valid_model_type(specified_type, model_type_list):
"""
Checks to make sure that `specified_type` is in `model_type_list` and
raises a helpful error if this is not the case.
Parameters
----------
specified_type : str.
Denotes the user-specified model type that is to be checked... | [
"def",
"ensure_valid_model_type",
"(",
"specified_type",
",",
"model_type_list",
")",
":",
"if",
"specified_type",
"not",
"in",
"model_type_list",
":",
"msg_1",
"=",
"\"The specified model_type was not valid.\"",
"msg_2",
"=",
"\"Valid model-types are {}\"",
".",
"format",
... | Checks to make sure that `specified_type` is in `model_type_list` and
raises a helpful error if this is not the case.
Parameters
----------
specified_type : str.
Denotes the user-specified model type that is to be checked.
model_type_list : list of strings.
Contains all of the model... | [
"Checks",
"to",
"make",
"sure",
"that",
"specified_type",
"is",
"in",
"model_type_list",
"and",
"raises",
"a",
"helpful",
"error",
"if",
"this",
"is",
"not",
"the",
"case",
"."
] | train | https://github.com/timothyb0912/pylogit/blob/f83b0fd6debaa7358d87c3828428f6d4ead71357/pylogit/pylogit.py#L58-L80 |
timothyb0912/pylogit | pylogit/pylogit.py | create_choice_model | def create_choice_model(data,
alt_id_col,
obs_id_col,
choice_col,
specification,
model_type,
intercept_ref_pos=None,
shape_ref_pos=None,
... | python | def create_choice_model(data,
alt_id_col,
obs_id_col,
choice_col,
specification,
model_type,
intercept_ref_pos=None,
shape_ref_pos=None,
... | [
"def",
"create_choice_model",
"(",
"data",
",",
"alt_id_col",
",",
"obs_id_col",
",",
"choice_col",
",",
"specification",
",",
"model_type",
",",
"intercept_ref_pos",
"=",
"None",
",",
"shape_ref_pos",
"=",
"None",
",",
"names",
"=",
"None",
",",
"intercept_name... | Parameters
----------
data : string or pandas dataframe.
If `data` is a string, it should be an absolute or relative path to
a CSV file containing the long format data for this choice model.
Note long format has one row per available alternative for each
observation. If `data` is... | [
"Parameters",
"----------",
"data",
":",
"string",
"or",
"pandas",
"dataframe",
".",
"If",
"data",
"is",
"a",
"string",
"it",
"should",
"be",
"an",
"absolute",
"or",
"relative",
"path",
"to",
"a",
"CSV",
"file",
"containing",
"the",
"long",
"format",
"data... | train | https://github.com/timothyb0912/pylogit/blob/f83b0fd6debaa7358d87c3828428f6d4ead71357/pylogit/pylogit.py#L83-L225 |
timothyb0912/pylogit | pylogit/base_multinomial_cm_v2.py | ensure_valid_nums_in_specification_cols | def ensure_valid_nums_in_specification_cols(specification, dataframe):
"""
Checks whether each column in `specification` contains numeric data,
excluding positive or negative infinity and excluding NaN. Raises
ValueError if any of the columns do not meet these requirements.
Parameters
---------... | python | def ensure_valid_nums_in_specification_cols(specification, dataframe):
"""
Checks whether each column in `specification` contains numeric data,
excluding positive or negative infinity and excluding NaN. Raises
ValueError if any of the columns do not meet these requirements.
Parameters
---------... | [
"def",
"ensure_valid_nums_in_specification_cols",
"(",
"specification",
",",
"dataframe",
")",
":",
"problem_cols",
"=",
"[",
"]",
"for",
"col",
"in",
"specification",
":",
"# The condition below checks for values that are not floats or integers",
"# This will catch values that a... | Checks whether each column in `specification` contains numeric data,
excluding positive or negative infinity and excluding NaN. Raises
ValueError if any of the columns do not meet these requirements.
Parameters
----------
specification : iterable of column headers in `dataframe`.
dataframe : pa... | [
"Checks",
"whether",
"each",
"column",
"in",
"specification",
"contains",
"numeric",
"data",
"excluding",
"positive",
"or",
"negative",
"infinity",
"and",
"excluding",
"NaN",
".",
"Raises",
"ValueError",
"if",
"any",
"of",
"the",
"columns",
"do",
"not",
"meet",
... | train | https://github.com/timothyb0912/pylogit/blob/f83b0fd6debaa7358d87c3828428f6d4ead71357/pylogit/base_multinomial_cm_v2.py#L60-L96 |
timothyb0912/pylogit | pylogit/base_multinomial_cm_v2.py | ensure_ref_position_is_valid | def ensure_ref_position_is_valid(ref_position, num_alts, param_title):
"""
Ensures that `ref_position` is None or an integer that is in the interval
`[0, num_alts - 1]`. If None, ensures that intercepts are not the
parameters being estimated. Raises a helpful ValueError if otherwise.
Parameters
... | python | def ensure_ref_position_is_valid(ref_position, num_alts, param_title):
"""
Ensures that `ref_position` is None or an integer that is in the interval
`[0, num_alts - 1]`. If None, ensures that intercepts are not the
parameters being estimated. Raises a helpful ValueError if otherwise.
Parameters
... | [
"def",
"ensure_ref_position_is_valid",
"(",
"ref_position",
",",
"num_alts",
",",
"param_title",
")",
":",
"assert",
"param_title",
"in",
"[",
"'intercept_names'",
",",
"'shape_names'",
"]",
"try",
":",
"assert",
"ref_position",
"is",
"None",
"or",
"isinstance",
"... | Ensures that `ref_position` is None or an integer that is in the interval
`[0, num_alts - 1]`. If None, ensures that intercepts are not the
parameters being estimated. Raises a helpful ValueError if otherwise.
Parameters
----------
ref_position : int.
An integer denoting the position in an ... | [
"Ensures",
"that",
"ref_position",
"is",
"None",
"or",
"an",
"integer",
"that",
"is",
"in",
"the",
"interval",
"[",
"0",
"num_alts",
"-",
"1",
"]",
".",
"If",
"None",
"ensures",
"that",
"intercepts",
"are",
"not",
"the",
"parameters",
"being",
"estimated",... | train | https://github.com/timothyb0912/pylogit/blob/f83b0fd6debaa7358d87c3828428f6d4ead71357/pylogit/base_multinomial_cm_v2.py#L99-L142 |
timothyb0912/pylogit | pylogit/base_multinomial_cm_v2.py | check_length_of_shape_or_intercept_names | def check_length_of_shape_or_intercept_names(name_list,
num_alts,
constrained_param,
list_title):
"""
Ensures that the length of the parameter names matches the number of
pa... | python | def check_length_of_shape_or_intercept_names(name_list,
num_alts,
constrained_param,
list_title):
"""
Ensures that the length of the parameter names matches the number of
pa... | [
"def",
"check_length_of_shape_or_intercept_names",
"(",
"name_list",
",",
"num_alts",
",",
"constrained_param",
",",
"list_title",
")",
":",
"if",
"len",
"(",
"name_list",
")",
"!=",
"(",
"num_alts",
"-",
"constrained_param",
")",
":",
"msg_1",
"=",
"\"{} is of th... | Ensures that the length of the parameter names matches the number of
parameters that will be estimated. Will raise a ValueError otherwise.
Parameters
----------
name_list : list of strings.
Each element should be the name of a parameter that is to be estimated.
num_alts : int.
Shoul... | [
"Ensures",
"that",
"the",
"length",
"of",
"the",
"parameter",
"names",
"matches",
"the",
"number",
"of",
"parameters",
"that",
"will",
"be",
"estimated",
".",
"Will",
"raise",
"a",
"ValueError",
"otherwise",
"."
] | train | https://github.com/timothyb0912/pylogit/blob/f83b0fd6debaa7358d87c3828428f6d4ead71357/pylogit/base_multinomial_cm_v2.py#L145-L180 |
timothyb0912/pylogit | pylogit/base_multinomial_cm_v2.py | check_type_of_nest_spec_keys_and_values | def check_type_of_nest_spec_keys_and_values(nest_spec):
"""
Ensures that the keys and values of `nest_spec` are strings and lists.
Raises a helpful ValueError if they are.
Parameters
----------
nest_spec : OrderedDict, or None, optional.
Keys are strings that define the name of the nest... | python | def check_type_of_nest_spec_keys_and_values(nest_spec):
"""
Ensures that the keys and values of `nest_spec` are strings and lists.
Raises a helpful ValueError if they are.
Parameters
----------
nest_spec : OrderedDict, or None, optional.
Keys are strings that define the name of the nest... | [
"def",
"check_type_of_nest_spec_keys_and_values",
"(",
"nest_spec",
")",
":",
"try",
":",
"assert",
"all",
"(",
"[",
"isinstance",
"(",
"k",
",",
"str",
")",
"for",
"k",
"in",
"nest_spec",
"]",
")",
"assert",
"all",
"(",
"[",
"isinstance",
"(",
"nest_spec"... | Ensures that the keys and values of `nest_spec` are strings and lists.
Raises a helpful ValueError if they are.
Parameters
----------
nest_spec : OrderedDict, or None, optional.
Keys are strings that define the name of the nests. Values are lists of
alternative ids, denoting which alter... | [
"Ensures",
"that",
"the",
"keys",
"and",
"values",
"of",
"nest_spec",
"are",
"strings",
"and",
"lists",
".",
"Raises",
"a",
"helpful",
"ValueError",
"if",
"they",
"are",
"."
] | train | https://github.com/timothyb0912/pylogit/blob/f83b0fd6debaa7358d87c3828428f6d4ead71357/pylogit/base_multinomial_cm_v2.py#L183-L207 |
timothyb0912/pylogit | pylogit/base_multinomial_cm_v2.py | check_for_empty_nests_in_nest_spec | def check_for_empty_nests_in_nest_spec(nest_spec):
"""
Ensures that the values of `nest_spec` are not empty lists.
Raises a helpful ValueError if they are.
Parameters
----------
nest_spec : OrderedDict, or None, optional.
Keys are strings that define the name of the nests. Values are li... | python | def check_for_empty_nests_in_nest_spec(nest_spec):
"""
Ensures that the values of `nest_spec` are not empty lists.
Raises a helpful ValueError if they are.
Parameters
----------
nest_spec : OrderedDict, or None, optional.
Keys are strings that define the name of the nests. Values are li... | [
"def",
"check_for_empty_nests_in_nest_spec",
"(",
"nest_spec",
")",
":",
"empty_nests",
"=",
"[",
"]",
"for",
"k",
"in",
"nest_spec",
":",
"if",
"len",
"(",
"nest_spec",
"[",
"k",
"]",
")",
"==",
"0",
":",
"empty_nests",
".",
"append",
"(",
"k",
")",
"... | Ensures that the values of `nest_spec` are not empty lists.
Raises a helpful ValueError if they are.
Parameters
----------
nest_spec : OrderedDict, or None, optional.
Keys are strings that define the name of the nests. Values are lists of
alternative ids, denoting which alternatives bel... | [
"Ensures",
"that",
"the",
"values",
"of",
"nest_spec",
"are",
"not",
"empty",
"lists",
".",
"Raises",
"a",
"helpful",
"ValueError",
"if",
"they",
"are",
"."
] | train | https://github.com/timothyb0912/pylogit/blob/f83b0fd6debaa7358d87c3828428f6d4ead71357/pylogit/base_multinomial_cm_v2.py#L210-L235 |
timothyb0912/pylogit | pylogit/base_multinomial_cm_v2.py | ensure_alt_ids_in_nest_spec_are_ints | def ensure_alt_ids_in_nest_spec_are_ints(nest_spec, list_elements):
"""
Ensures that the alternative id's in `nest_spec` are integers. Raises a
helpful ValueError if they are not.
Parameters
----------
nest_spec : OrderedDict, or None, optional.
Keys are strings that define the name of ... | python | def ensure_alt_ids_in_nest_spec_are_ints(nest_spec, list_elements):
"""
Ensures that the alternative id's in `nest_spec` are integers. Raises a
helpful ValueError if they are not.
Parameters
----------
nest_spec : OrderedDict, or None, optional.
Keys are strings that define the name of ... | [
"def",
"ensure_alt_ids_in_nest_spec_are_ints",
"(",
"nest_spec",
",",
"list_elements",
")",
":",
"try",
":",
"assert",
"all",
"(",
"[",
"isinstance",
"(",
"x",
",",
"int",
")",
"for",
"x",
"in",
"list_elements",
"]",
")",
"except",
"AssertionError",
":",
"ms... | Ensures that the alternative id's in `nest_spec` are integers. Raises a
helpful ValueError if they are not.
Parameters
----------
nest_spec : OrderedDict, or None, optional.
Keys are strings that define the name of the nests. Values are lists of
alternative ids, denoting which alternati... | [
"Ensures",
"that",
"the",
"alternative",
"id",
"s",
"in",
"nest_spec",
"are",
"integers",
".",
"Raises",
"a",
"helpful",
"ValueError",
"if",
"they",
"are",
"not",
"."
] | train | https://github.com/timothyb0912/pylogit/blob/f83b0fd6debaa7358d87c3828428f6d4ead71357/pylogit/base_multinomial_cm_v2.py#L238-L264 |
timothyb0912/pylogit | pylogit/base_multinomial_cm_v2.py | ensure_alt_ids_are_only_in_one_nest | def ensure_alt_ids_are_only_in_one_nest(nest_spec, list_elements):
"""
Ensures that the alternative id's in `nest_spec` are only associated with
a single nest. Raises a helpful ValueError if they are not.
Parameters
----------
nest_spec : OrderedDict, or None, optional.
Keys are strings... | python | def ensure_alt_ids_are_only_in_one_nest(nest_spec, list_elements):
"""
Ensures that the alternative id's in `nest_spec` are only associated with
a single nest. Raises a helpful ValueError if they are not.
Parameters
----------
nest_spec : OrderedDict, or None, optional.
Keys are strings... | [
"def",
"ensure_alt_ids_are_only_in_one_nest",
"(",
"nest_spec",
",",
"list_elements",
")",
":",
"try",
":",
"assert",
"len",
"(",
"set",
"(",
"list_elements",
")",
")",
"==",
"len",
"(",
"list_elements",
")",
"except",
"AssertionError",
":",
"msg",
"=",
"\"Eac... | Ensures that the alternative id's in `nest_spec` are only associated with
a single nest. Raises a helpful ValueError if they are not.
Parameters
----------
nest_spec : OrderedDict, or None, optional.
Keys are strings that define the name of the nests. Values are lists of
alternative ids... | [
"Ensures",
"that",
"the",
"alternative",
"id",
"s",
"in",
"nest_spec",
"are",
"only",
"associated",
"with",
"a",
"single",
"nest",
".",
"Raises",
"a",
"helpful",
"ValueError",
"if",
"they",
"are",
"not",
"."
] | train | https://github.com/timothyb0912/pylogit/blob/f83b0fd6debaa7358d87c3828428f6d4ead71357/pylogit/base_multinomial_cm_v2.py#L267-L293 |
timothyb0912/pylogit | pylogit/base_multinomial_cm_v2.py | ensure_all_alt_ids_have_a_nest | def ensure_all_alt_ids_have_a_nest(nest_spec, list_elements, all_ids):
"""
Ensures that the alternative id's in `nest_spec` are all associated with
a nest. Raises a helpful ValueError if they are not.
Parameters
----------
nest_spec : OrderedDict, or None, optional.
Keys are strings tha... | python | def ensure_all_alt_ids_have_a_nest(nest_spec, list_elements, all_ids):
"""
Ensures that the alternative id's in `nest_spec` are all associated with
a nest. Raises a helpful ValueError if they are not.
Parameters
----------
nest_spec : OrderedDict, or None, optional.
Keys are strings tha... | [
"def",
"ensure_all_alt_ids_have_a_nest",
"(",
"nest_spec",
",",
"list_elements",
",",
"all_ids",
")",
":",
"unaccounted_alt_ids",
"=",
"[",
"]",
"for",
"alt_id",
"in",
"all_ids",
":",
"if",
"alt_id",
"not",
"in",
"list_elements",
":",
"unaccounted_alt_ids",
".",
... | Ensures that the alternative id's in `nest_spec` are all associated with
a nest. Raises a helpful ValueError if they are not.
Parameters
----------
nest_spec : OrderedDict, or None, optional.
Keys are strings that define the name of the nests. Values are lists of
alternative ids, denoti... | [
"Ensures",
"that",
"the",
"alternative",
"id",
"s",
"in",
"nest_spec",
"are",
"all",
"associated",
"with",
"a",
"nest",
".",
"Raises",
"a",
"helpful",
"ValueError",
"if",
"they",
"are",
"not",
"."
] | train | https://github.com/timothyb0912/pylogit/blob/f83b0fd6debaa7358d87c3828428f6d4ead71357/pylogit/base_multinomial_cm_v2.py#L296-L327 |
timothyb0912/pylogit | pylogit/base_multinomial_cm_v2.py | ensure_nest_alts_are_valid_alts | def ensure_nest_alts_are_valid_alts(nest_spec, list_elements, all_ids):
"""
Ensures that the alternative id's in `nest_spec` are all in the universal
choice set for this dataset. Raises a helpful ValueError if they are not.
Parameters
----------
nest_spec : OrderedDict, or None, optional.
... | python | def ensure_nest_alts_are_valid_alts(nest_spec, list_elements, all_ids):
"""
Ensures that the alternative id's in `nest_spec` are all in the universal
choice set for this dataset. Raises a helpful ValueError if they are not.
Parameters
----------
nest_spec : OrderedDict, or None, optional.
... | [
"def",
"ensure_nest_alts_are_valid_alts",
"(",
"nest_spec",
",",
"list_elements",
",",
"all_ids",
")",
":",
"invalid_alt_ids",
"=",
"[",
"]",
"for",
"x",
"in",
"list_elements",
":",
"if",
"x",
"not",
"in",
"all_ids",
":",
"invalid_alt_ids",
".",
"append",
"(",... | Ensures that the alternative id's in `nest_spec` are all in the universal
choice set for this dataset. Raises a helpful ValueError if they are not.
Parameters
----------
nest_spec : OrderedDict, or None, optional.
Keys are strings that define the name of the nests. Values are lists of
a... | [
"Ensures",
"that",
"the",
"alternative",
"id",
"s",
"in",
"nest_spec",
"are",
"all",
"in",
"the",
"universal",
"choice",
"set",
"for",
"this",
"dataset",
".",
"Raises",
"a",
"helpful",
"ValueError",
"if",
"they",
"are",
"not",
"."
] | train | https://github.com/timothyb0912/pylogit/blob/f83b0fd6debaa7358d87c3828428f6d4ead71357/pylogit/base_multinomial_cm_v2.py#L330-L361 |
timothyb0912/pylogit | pylogit/base_multinomial_cm_v2.py | check_num_rows_of_parameter_array | def check_num_rows_of_parameter_array(param_array, correct_num_rows, title):
"""
Ensures that `param_array.shape[0]` has the correct magnitude. Raises a
helpful ValueError if otherwise.
Parameters
----------
param_array : ndarray.
correct_num_rows : int.
The int that `param_array.sh... | python | def check_num_rows_of_parameter_array(param_array, correct_num_rows, title):
"""
Ensures that `param_array.shape[0]` has the correct magnitude. Raises a
helpful ValueError if otherwise.
Parameters
----------
param_array : ndarray.
correct_num_rows : int.
The int that `param_array.sh... | [
"def",
"check_num_rows_of_parameter_array",
"(",
"param_array",
",",
"correct_num_rows",
",",
"title",
")",
":",
"if",
"param_array",
".",
"shape",
"[",
"0",
"]",
"!=",
"correct_num_rows",
":",
"msg",
"=",
"\"{}.shape[0] should equal {}, but it does not\"",
"raise",
"... | Ensures that `param_array.shape[0]` has the correct magnitude. Raises a
helpful ValueError if otherwise.
Parameters
----------
param_array : ndarray.
correct_num_rows : int.
The int that `param_array.shape[0]` should equal.
title : str.
The 'name' of the param_array whose shape ... | [
"Ensures",
"that",
"param_array",
".",
"shape",
"[",
"0",
"]",
"has",
"the",
"correct",
"magnitude",
".",
"Raises",
"a",
"helpful",
"ValueError",
"if",
"otherwise",
"."
] | train | https://github.com/timothyb0912/pylogit/blob/f83b0fd6debaa7358d87c3828428f6d4ead71357/pylogit/base_multinomial_cm_v2.py#L386-L407 |
timothyb0912/pylogit | pylogit/base_multinomial_cm_v2.py | check_type_and_size_of_param_list | def check_type_and_size_of_param_list(param_list, expected_length):
"""
Ensure that param_list is a list with the expected length. Raises a helpful
ValueError if this is not the case.
"""
try:
assert isinstance(param_list, list)
assert len(param_list) == expected_length
except As... | python | def check_type_and_size_of_param_list(param_list, expected_length):
"""
Ensure that param_list is a list with the expected length. Raises a helpful
ValueError if this is not the case.
"""
try:
assert isinstance(param_list, list)
assert len(param_list) == expected_length
except As... | [
"def",
"check_type_and_size_of_param_list",
"(",
"param_list",
",",
"expected_length",
")",
":",
"try",
":",
"assert",
"isinstance",
"(",
"param_list",
",",
"list",
")",
"assert",
"len",
"(",
"param_list",
")",
"==",
"expected_length",
"except",
"AssertionError",
... | Ensure that param_list is a list with the expected length. Raises a helpful
ValueError if this is not the case. | [
"Ensure",
"that",
"param_list",
"is",
"a",
"list",
"with",
"the",
"expected",
"length",
".",
"Raises",
"a",
"helpful",
"ValueError",
"if",
"this",
"is",
"not",
"the",
"case",
"."
] | train | https://github.com/timothyb0912/pylogit/blob/f83b0fd6debaa7358d87c3828428f6d4ead71357/pylogit/base_multinomial_cm_v2.py#L410-L422 |
timothyb0912/pylogit | pylogit/base_multinomial_cm_v2.py | check_type_of_param_list_elements | def check_type_of_param_list_elements(param_list):
"""
Ensures that all elements of param_list are ndarrays or None. Raises a
helpful ValueError if otherwise.
"""
try:
assert isinstance(param_list[0], np.ndarray)
assert all([(x is None or isinstance(x, np.ndarray))
... | python | def check_type_of_param_list_elements(param_list):
"""
Ensures that all elements of param_list are ndarrays or None. Raises a
helpful ValueError if otherwise.
"""
try:
assert isinstance(param_list[0], np.ndarray)
assert all([(x is None or isinstance(x, np.ndarray))
... | [
"def",
"check_type_of_param_list_elements",
"(",
"param_list",
")",
":",
"try",
":",
"assert",
"isinstance",
"(",
"param_list",
"[",
"0",
"]",
",",
"np",
".",
"ndarray",
")",
"assert",
"all",
"(",
"[",
"(",
"x",
"is",
"None",
"or",
"isinstance",
"(",
"x"... | Ensures that all elements of param_list are ndarrays or None. Raises a
helpful ValueError if otherwise. | [
"Ensures",
"that",
"all",
"elements",
"of",
"param_list",
"are",
"ndarrays",
"or",
"None",
".",
"Raises",
"a",
"helpful",
"ValueError",
"if",
"otherwise",
"."
] | train | https://github.com/timothyb0912/pylogit/blob/f83b0fd6debaa7358d87c3828428f6d4ead71357/pylogit/base_multinomial_cm_v2.py#L425-L440 |
timothyb0912/pylogit | pylogit/base_multinomial_cm_v2.py | check_num_columns_in_param_list_arrays | def check_num_columns_in_param_list_arrays(param_list):
"""
Ensure that each array in param_list, that is not None, has the same number
of columns. Raises a helpful ValueError if otherwise.
Parameters
----------
param_list : list of ndarrays or None.
Returns
-------
None.
"""
... | python | def check_num_columns_in_param_list_arrays(param_list):
"""
Ensure that each array in param_list, that is not None, has the same number
of columns. Raises a helpful ValueError if otherwise.
Parameters
----------
param_list : list of ndarrays or None.
Returns
-------
None.
"""
... | [
"def",
"check_num_columns_in_param_list_arrays",
"(",
"param_list",
")",
":",
"try",
":",
"num_columns",
"=",
"param_list",
"[",
"0",
"]",
".",
"shape",
"[",
"1",
"]",
"assert",
"all",
"(",
"[",
"x",
"is",
"None",
"or",
"(",
"x",
".",
"shape",
"[",
"1"... | Ensure that each array in param_list, that is not None, has the same number
of columns. Raises a helpful ValueError if otherwise.
Parameters
----------
param_list : list of ndarrays or None.
Returns
-------
None. | [
"Ensure",
"that",
"each",
"array",
"in",
"param_list",
"that",
"is",
"not",
"None",
"has",
"the",
"same",
"number",
"of",
"columns",
".",
"Raises",
"a",
"helpful",
"ValueError",
"if",
"otherwise",
"."
] | train | https://github.com/timothyb0912/pylogit/blob/f83b0fd6debaa7358d87c3828428f6d4ead71357/pylogit/base_multinomial_cm_v2.py#L443-L464 |
timothyb0912/pylogit | pylogit/base_multinomial_cm_v2.py | check_dimensional_equality_of_param_list_arrays | def check_dimensional_equality_of_param_list_arrays(param_list):
"""
Ensures that all arrays in param_list have the same dimension, and that
this dimension is either 1 or 2 (i.e. all arrays are 1D arrays or all
arrays are 2D arrays.) Raises a helpful ValueError if otherwise.
Parameters
--------... | python | def check_dimensional_equality_of_param_list_arrays(param_list):
"""
Ensures that all arrays in param_list have the same dimension, and that
this dimension is either 1 or 2 (i.e. all arrays are 1D arrays or all
arrays are 2D arrays.) Raises a helpful ValueError if otherwise.
Parameters
--------... | [
"def",
"check_dimensional_equality_of_param_list_arrays",
"(",
"param_list",
")",
":",
"try",
":",
"num_dimensions",
"=",
"len",
"(",
"param_list",
"[",
"0",
"]",
".",
"shape",
")",
"assert",
"num_dimensions",
"in",
"[",
"1",
",",
"2",
"]",
"assert",
"all",
... | Ensures that all arrays in param_list have the same dimension, and that
this dimension is either 1 or 2 (i.e. all arrays are 1D arrays or all
arrays are 2D arrays.) Raises a helpful ValueError if otherwise.
Parameters
----------
param_list : list of ndarrays or None.
Returns
-------
No... | [
"Ensures",
"that",
"all",
"arrays",
"in",
"param_list",
"have",
"the",
"same",
"dimension",
"and",
"that",
"this",
"dimension",
"is",
"either",
"1",
"or",
"2",
"(",
"i",
".",
"e",
".",
"all",
"arrays",
"are",
"1D",
"arrays",
"or",
"all",
"arrays",
"are... | train | https://github.com/timothyb0912/pylogit/blob/f83b0fd6debaa7358d87c3828428f6d4ead71357/pylogit/base_multinomial_cm_v2.py#L467-L492 |
timothyb0912/pylogit | pylogit/base_multinomial_cm_v2.py | ensure_all_mixing_vars_are_in_the_name_dict | def ensure_all_mixing_vars_are_in_the_name_dict(mixing_vars,
name_dict,
ind_var_names):
"""
Ensures that all of the variables listed in `mixing_vars` are present in
`ind_var_names`. Raises a helpful ValueError if... | python | def ensure_all_mixing_vars_are_in_the_name_dict(mixing_vars,
name_dict,
ind_var_names):
"""
Ensures that all of the variables listed in `mixing_vars` are present in
`ind_var_names`. Raises a helpful ValueError if... | [
"def",
"ensure_all_mixing_vars_are_in_the_name_dict",
"(",
"mixing_vars",
",",
"name_dict",
",",
"ind_var_names",
")",
":",
"if",
"mixing_vars",
"is",
"None",
":",
"return",
"None",
"# Determine the strings in mixing_vars that are missing from ind_var_names",
"problem_names",
"... | Ensures that all of the variables listed in `mixing_vars` are present in
`ind_var_names`. Raises a helpful ValueError if otherwise.
Parameters
----------
mixing_vars : list of strings, or None.
Each string denotes a parameter to be treated as a random variable.
name_dict : OrderedDict or No... | [
"Ensures",
"that",
"all",
"of",
"the",
"variables",
"listed",
"in",
"mixing_vars",
"are",
"present",
"in",
"ind_var_names",
".",
"Raises",
"a",
"helpful",
"ValueError",
"if",
"otherwise",
"."
] | train | https://github.com/timothyb0912/pylogit/blob/f83b0fd6debaa7358d87c3828428f6d4ead71357/pylogit/base_multinomial_cm_v2.py#L524-L574 |
timothyb0912/pylogit | pylogit/base_multinomial_cm_v2.py | ensure_all_alternatives_are_chosen | def ensure_all_alternatives_are_chosen(alt_id_col, choice_col, dataframe):
"""
Ensures that all of the available alternatives in the dataset are chosen at
least once (for model identification). Raises a ValueError otherwise.
Parameters
----------
alt_id_col : str.
Should denote the colu... | python | def ensure_all_alternatives_are_chosen(alt_id_col, choice_col, dataframe):
"""
Ensures that all of the available alternatives in the dataset are chosen at
least once (for model identification). Raises a ValueError otherwise.
Parameters
----------
alt_id_col : str.
Should denote the colu... | [
"def",
"ensure_all_alternatives_are_chosen",
"(",
"alt_id_col",
",",
"choice_col",
",",
"dataframe",
")",
":",
"all_ids",
"=",
"set",
"(",
"dataframe",
"[",
"alt_id_col",
"]",
".",
"unique",
"(",
")",
")",
"chosen_ids",
"=",
"set",
"(",
"dataframe",
".",
"lo... | Ensures that all of the available alternatives in the dataset are chosen at
least once (for model identification). Raises a ValueError otherwise.
Parameters
----------
alt_id_col : str.
Should denote the column in `dataframe` that contains the alternative
identifiers for each row.
c... | [
"Ensures",
"that",
"all",
"of",
"the",
"available",
"alternatives",
"in",
"the",
"dataset",
"are",
"chosen",
"at",
"least",
"once",
"(",
"for",
"model",
"identification",
")",
".",
"Raises",
"a",
"ValueError",
"otherwise",
"."
] | train | https://github.com/timothyb0912/pylogit/blob/f83b0fd6debaa7358d87c3828428f6d4ead71357/pylogit/base_multinomial_cm_v2.py#L577-L608 |
timothyb0912/pylogit | pylogit/base_multinomial_cm_v2.py | compute_aic | def compute_aic(model_object):
"""
Compute the Akaike Information Criteria for an estimated model.
Parameters
----------
model_object : an MNDC_Model (multinomial discrete choice model) instance.
The model should have already been estimated.
`model_object.log_likelihood` should be a... | python | def compute_aic(model_object):
"""
Compute the Akaike Information Criteria for an estimated model.
Parameters
----------
model_object : an MNDC_Model (multinomial discrete choice model) instance.
The model should have already been estimated.
`model_object.log_likelihood` should be a... | [
"def",
"compute_aic",
"(",
"model_object",
")",
":",
"assert",
"isinstance",
"(",
"model_object",
".",
"params",
",",
"pd",
".",
"Series",
")",
"assert",
"isinstance",
"(",
"model_object",
".",
"log_likelihood",
",",
"Number",
")",
"return",
"-",
"2",
"*",
... | Compute the Akaike Information Criteria for an estimated model.
Parameters
----------
model_object : an MNDC_Model (multinomial discrete choice model) instance.
The model should have already been estimated.
`model_object.log_likelihood` should be a number, and
`model_object.params` ... | [
"Compute",
"the",
"Akaike",
"Information",
"Criteria",
"for",
"an",
"estimated",
"model",
"."
] | train | https://github.com/timothyb0912/pylogit/blob/f83b0fd6debaa7358d87c3828428f6d4ead71357/pylogit/base_multinomial_cm_v2.py#L611-L639 |
timothyb0912/pylogit | pylogit/base_multinomial_cm_v2.py | compute_bic | def compute_bic(model_object):
"""
Compute the Bayesian Information Criteria for an estimated model.
Parameters
----------
model_object : an MNDC_Model (multinomial discrete choice model) instance.
The model should have already been estimated.
`model_object.log_likelihood` and `mode... | python | def compute_bic(model_object):
"""
Compute the Bayesian Information Criteria for an estimated model.
Parameters
----------
model_object : an MNDC_Model (multinomial discrete choice model) instance.
The model should have already been estimated.
`model_object.log_likelihood` and `mode... | [
"def",
"compute_bic",
"(",
"model_object",
")",
":",
"assert",
"isinstance",
"(",
"model_object",
".",
"params",
",",
"pd",
".",
"Series",
")",
"assert",
"isinstance",
"(",
"model_object",
".",
"log_likelihood",
",",
"Number",
")",
"assert",
"isinstance",
"(",... | Compute the Bayesian Information Criteria for an estimated model.
Parameters
----------
model_object : an MNDC_Model (multinomial discrete choice model) instance.
The model should have already been estimated.
`model_object.log_likelihood` and `model_object.nobs` should be a
number, ... | [
"Compute",
"the",
"Bayesian",
"Information",
"Criteria",
"for",
"an",
"estimated",
"model",
"."
] | train | https://github.com/timothyb0912/pylogit/blob/f83b0fd6debaa7358d87c3828428f6d4ead71357/pylogit/base_multinomial_cm_v2.py#L642-L681 |
timothyb0912/pylogit | pylogit/base_multinomial_cm_v2.py | MNDC_Model.get_mappings_for_fit | def get_mappings_for_fit(self, dense=False):
"""
Parameters
----------
dense : bool, optional.
Dictates if sparse matrices will be returned or dense numpy arrays.
Returns
-------
mapping_dict : OrderedDict.
Keys will be `["rows_to_obs", "r... | python | def get_mappings_for_fit(self, dense=False):
"""
Parameters
----------
dense : bool, optional.
Dictates if sparse matrices will be returned or dense numpy arrays.
Returns
-------
mapping_dict : OrderedDict.
Keys will be `["rows_to_obs", "r... | [
"def",
"get_mappings_for_fit",
"(",
"self",
",",
"dense",
"=",
"False",
")",
":",
"return",
"create_long_form_mappings",
"(",
"self",
".",
"data",
",",
"self",
".",
"obs_id_col",
",",
"self",
".",
"alt_id_col",
",",
"choice_col",
"=",
"self",
".",
"choice_co... | Parameters
----------
dense : bool, optional.
Dictates if sparse matrices will be returned or dense numpy arrays.
Returns
-------
mapping_dict : OrderedDict.
Keys will be `["rows_to_obs", "rows_to_alts", "chosen_row_to_obs",
"rows_to_nests"]`.... | [
"Parameters",
"----------",
"dense",
":",
"bool",
"optional",
".",
"Dictates",
"if",
"sparse",
"matrices",
"will",
"be",
"returned",
"or",
"dense",
"numpy",
"arrays",
"."
] | train | https://github.com/timothyb0912/pylogit/blob/f83b0fd6debaa7358d87c3828428f6d4ead71357/pylogit/base_multinomial_cm_v2.py#L920-L951 |
timothyb0912/pylogit | pylogit/base_multinomial_cm_v2.py | MNDC_Model._store_basic_estimation_results | def _store_basic_estimation_results(self, results_dict):
"""
Extracts the basic estimation results (i.e. those that need no further
calculation or logic applied to them) and stores them on the model
object.
Parameters
----------
results_dict : dict.
... | python | def _store_basic_estimation_results(self, results_dict):
"""
Extracts the basic estimation results (i.e. those that need no further
calculation or logic applied to them) and stores them on the model
object.
Parameters
----------
results_dict : dict.
... | [
"def",
"_store_basic_estimation_results",
"(",
"self",
",",
"results_dict",
")",
":",
"# Store the log-likelilhood, fitted probabilities, residuals, and",
"# individual chi-square statistics",
"self",
".",
"log_likelihood",
"=",
"results_dict",
"[",
"\"final_log_likelihood\"",
"]",... | Extracts the basic estimation results (i.e. those that need no further
calculation or logic applied to them) and stores them on the model
object.
Parameters
----------
results_dict : dict.
The estimation result dictionary that is output from
scipy.optimi... | [
"Extracts",
"the",
"basic",
"estimation",
"results",
"(",
"i",
".",
"e",
".",
"those",
"that",
"need",
"no",
"further",
"calculation",
"or",
"logic",
"applied",
"to",
"them",
")",
"and",
"stores",
"them",
"on",
"the",
"model",
"object",
"."
] | train | https://github.com/timothyb0912/pylogit/blob/f83b0fd6debaa7358d87c3828428f6d4ead71357/pylogit/base_multinomial_cm_v2.py#L953-L993 |
timothyb0912/pylogit | pylogit/base_multinomial_cm_v2.py | MNDC_Model._create_results_summary | def _create_results_summary(self):
"""
Create the dataframe that displays the estimation results, and store
it on the model instance.
Returns
-------
None.
"""
# Make sure we have all attributes needed to create the results summary
needed_attribut... | python | def _create_results_summary(self):
"""
Create the dataframe that displays the estimation results, and store
it on the model instance.
Returns
-------
None.
"""
# Make sure we have all attributes needed to create the results summary
needed_attribut... | [
"def",
"_create_results_summary",
"(",
"self",
")",
":",
"# Make sure we have all attributes needed to create the results summary",
"needed_attributes",
"=",
"[",
"\"params\"",
",",
"\"standard_errors\"",
",",
"\"tvalues\"",
",",
"\"pvalues\"",
",",
"\"robust_std_errs\"",
",",
... | Create the dataframe that displays the estimation results, and store
it on the model instance.
Returns
-------
None. | [
"Create",
"the",
"dataframe",
"that",
"displays",
"the",
"estimation",
"results",
"and",
"store",
"it",
"on",
"the",
"model",
"instance",
"."
] | train | https://github.com/timothyb0912/pylogit/blob/f83b0fd6debaa7358d87c3828428f6d4ead71357/pylogit/base_multinomial_cm_v2.py#L995-L1029 |
timothyb0912/pylogit | pylogit/base_multinomial_cm_v2.py | MNDC_Model._record_values_for_fit_summary_and_statsmodels | def _record_values_for_fit_summary_and_statsmodels(self):
"""
Store the various estimation results that are used to describe how well
the estimated model fits the given dataset, and record the values that
are needed for the statsmodels estimation results table. All values are
sto... | python | def _record_values_for_fit_summary_and_statsmodels(self):
"""
Store the various estimation results that are used to describe how well
the estimated model fits the given dataset, and record the values that
are needed for the statsmodels estimation results table. All values are
sto... | [
"def",
"_record_values_for_fit_summary_and_statsmodels",
"(",
"self",
")",
":",
"# Make sure we have all attributes needed to create the results summary",
"needed_attributes",
"=",
"[",
"\"fitted_probs\"",
",",
"\"params\"",
",",
"\"log_likelihood\"",
",",
"\"standard_errors\"",
"]... | Store the various estimation results that are used to describe how well
the estimated model fits the given dataset, and record the values that
are needed for the statsmodels estimation results table. All values are
stored on the model instance.
Returns
-------
None. | [
"Store",
"the",
"various",
"estimation",
"results",
"that",
"are",
"used",
"to",
"describe",
"how",
"well",
"the",
"estimated",
"model",
"fits",
"the",
"given",
"dataset",
"and",
"record",
"the",
"values",
"that",
"are",
"needed",
"for",
"the",
"statsmodels",
... | train | https://github.com/timothyb0912/pylogit/blob/f83b0fd6debaa7358d87c3828428f6d4ead71357/pylogit/base_multinomial_cm_v2.py#L1031-L1071 |
timothyb0912/pylogit | pylogit/base_multinomial_cm_v2.py | MNDC_Model._create_fit_summary | def _create_fit_summary(self):
"""
Create and store a pandas series that will display to users the
various statistics/values that indicate how well the estimated model
fit the given dataset.
Returns
-------
None.
"""
# Make sure we have all attrib... | python | def _create_fit_summary(self):
"""
Create and store a pandas series that will display to users the
various statistics/values that indicate how well the estimated model
fit the given dataset.
Returns
-------
None.
"""
# Make sure we have all attrib... | [
"def",
"_create_fit_summary",
"(",
"self",
")",
":",
"# Make sure we have all attributes needed to create the results summary",
"needed_attributes",
"=",
"[",
"\"df_model\"",
",",
"\"nobs\"",
",",
"\"null_log_likelihood\"",
",",
"\"log_likelihood\"",
",",
"\"rho_squared\"",
","... | Create and store a pandas series that will display to users the
various statistics/values that indicate how well the estimated model
fit the given dataset.
Returns
-------
None. | [
"Create",
"and",
"store",
"a",
"pandas",
"series",
"that",
"will",
"display",
"to",
"users",
"the",
"various",
"statistics",
"/",
"values",
"that",
"indicate",
"how",
"well",
"the",
"estimated",
"model",
"fit",
"the",
"given",
"dataset",
"."
] | train | https://github.com/timothyb0912/pylogit/blob/f83b0fd6debaa7358d87c3828428f6d4ead71357/pylogit/base_multinomial_cm_v2.py#L1073-L1115 |
timothyb0912/pylogit | pylogit/base_multinomial_cm_v2.py | MNDC_Model._store_inferential_results | def _store_inferential_results(self,
value_array,
index_names,
attribute_name,
series_name=None,
column_names=None):
"""
Store th... | python | def _store_inferential_results(self,
value_array,
index_names,
attribute_name,
series_name=None,
column_names=None):
"""
Store th... | [
"def",
"_store_inferential_results",
"(",
"self",
",",
"value_array",
",",
"index_names",
",",
"attribute_name",
",",
"series_name",
"=",
"None",
",",
"column_names",
"=",
"None",
")",
":",
"if",
"len",
"(",
"value_array",
".",
"shape",
")",
"==",
"1",
":",
... | Store the estimation results that relate to statistical inference, such
as parameter estimates, standard errors, p-values, etc.
Parameters
----------
value_array : 1D or 2D ndarray.
Contains the values that are to be stored on the model instance.
index_names : list o... | [
"Store",
"the",
"estimation",
"results",
"that",
"relate",
"to",
"statistical",
"inference",
"such",
"as",
"parameter",
"estimates",
"standard",
"errors",
"p",
"-",
"values",
"etc",
"."
] | train | https://github.com/timothyb0912/pylogit/blob/f83b0fd6debaa7358d87c3828428f6d4ead71357/pylogit/base_multinomial_cm_v2.py#L1117-L1164 |
timothyb0912/pylogit | pylogit/base_multinomial_cm_v2.py | MNDC_Model._store_generic_inference_results | def _store_generic_inference_results(self,
results_dict,
all_params,
all_names):
"""
Store the model inference values that are common to all choice models.
This includes thi... | python | def _store_generic_inference_results(self,
results_dict,
all_params,
all_names):
"""
Store the model inference values that are common to all choice models.
This includes thi... | [
"def",
"_store_generic_inference_results",
"(",
"self",
",",
"results_dict",
",",
"all_params",
",",
"all_names",
")",
":",
"# Store the utility coefficients",
"self",
".",
"_store_inferential_results",
"(",
"results_dict",
"[",
"\"utility_coefs\"",
"]",
",",
"index_names... | Store the model inference values that are common to all choice models.
This includes things like index coefficients, gradients, hessians,
asymptotic covariance matrices, t-values, p-values, and robust versions
of these values.
Parameters
----------
results_dict : dict.
... | [
"Store",
"the",
"model",
"inference",
"values",
"that",
"are",
"common",
"to",
"all",
"choice",
"models",
".",
"This",
"includes",
"things",
"like",
"index",
"coefficients",
"gradients",
"hessians",
"asymptotic",
"covariance",
"matrices",
"t",
"-",
"values",
"p"... | train | https://github.com/timothyb0912/pylogit/blob/f83b0fd6debaa7358d87c3828428f6d4ead71357/pylogit/base_multinomial_cm_v2.py#L1166-L1275 |
timothyb0912/pylogit | pylogit/base_multinomial_cm_v2.py | MNDC_Model._store_optional_parameters | def _store_optional_parameters(self,
optional_params,
name_list_attr,
default_name_str,
all_names,
all_params,
... | python | def _store_optional_parameters(self,
optional_params,
name_list_attr,
default_name_str,
all_names,
all_params,
... | [
"def",
"_store_optional_parameters",
"(",
"self",
",",
"optional_params",
",",
"name_list_attr",
",",
"default_name_str",
",",
"all_names",
",",
"all_params",
",",
"param_attr_name",
",",
"series_name",
")",
":",
"# Identify the number of optional parameters",
"num_elements... | Extract the optional parameters from the `results_dict`, save them
to the model object, and update the list of all parameters and all
parameter names.
Parameters
----------
optional_params : 1D ndarray.
The optional parameters whose values and names should be stored.... | [
"Extract",
"the",
"optional",
"parameters",
"from",
"the",
"results_dict",
"save",
"them",
"to",
"the",
"model",
"object",
"and",
"update",
"the",
"list",
"of",
"all",
"parameters",
"and",
"all",
"parameter",
"names",
"."
] | train | https://github.com/timothyb0912/pylogit/blob/f83b0fd6debaa7358d87c3828428f6d4ead71357/pylogit/base_multinomial_cm_v2.py#L1277-L1339 |
timothyb0912/pylogit | pylogit/base_multinomial_cm_v2.py | MNDC_Model._adjust_inferential_results_for_parameter_constraints | def _adjust_inferential_results_for_parameter_constraints(self,
constraints):
"""
Ensure that parameters that were constrained during estimation do not
have any values showed for inferential results. After all, no inference
wa... | python | def _adjust_inferential_results_for_parameter_constraints(self,
constraints):
"""
Ensure that parameters that were constrained during estimation do not
have any values showed for inferential results. After all, no inference
wa... | [
"def",
"_adjust_inferential_results_for_parameter_constraints",
"(",
"self",
",",
"constraints",
")",
":",
"if",
"constraints",
"is",
"not",
"None",
":",
"# Ensure the model object has inferential results",
"inferential_attributes",
"=",
"[",
"\"standard_errors\"",
",",
"\"tv... | Ensure that parameters that were constrained during estimation do not
have any values showed for inferential results. After all, no inference
was performed.
Parameters
----------
constraints : list of ints, or None.
If list, should contain the positions in the array ... | [
"Ensure",
"that",
"parameters",
"that",
"were",
"constrained",
"during",
"estimation",
"do",
"not",
"have",
"any",
"values",
"showed",
"for",
"inferential",
"results",
".",
"After",
"all",
"no",
"inference",
"was",
"performed",
"."
] | train | https://github.com/timothyb0912/pylogit/blob/f83b0fd6debaa7358d87c3828428f6d4ead71357/pylogit/base_multinomial_cm_v2.py#L1341-L1375 |
timothyb0912/pylogit | pylogit/base_multinomial_cm_v2.py | MNDC_Model._check_result_dict_for_needed_keys | def _check_result_dict_for_needed_keys(self, results_dict):
"""
Ensure that `results_dict` has the needed keys to store all the
estimation results. Raise a helpful ValueError otherwise.
"""
missing_cols = [x for x in needed_result_keys if x not in results_dict]
if missing... | python | def _check_result_dict_for_needed_keys(self, results_dict):
"""
Ensure that `results_dict` has the needed keys to store all the
estimation results. Raise a helpful ValueError otherwise.
"""
missing_cols = [x for x in needed_result_keys if x not in results_dict]
if missing... | [
"def",
"_check_result_dict_for_needed_keys",
"(",
"self",
",",
"results_dict",
")",
":",
"missing_cols",
"=",
"[",
"x",
"for",
"x",
"in",
"needed_result_keys",
"if",
"x",
"not",
"in",
"results_dict",
"]",
"if",
"missing_cols",
"!=",
"[",
"]",
":",
"msg",
"="... | Ensure that `results_dict` has the needed keys to store all the
estimation results. Raise a helpful ValueError otherwise. | [
"Ensure",
"that",
"results_dict",
"has",
"the",
"needed",
"keys",
"to",
"store",
"all",
"the",
"estimation",
"results",
".",
"Raise",
"a",
"helpful",
"ValueError",
"otherwise",
"."
] | train | https://github.com/timothyb0912/pylogit/blob/f83b0fd6debaa7358d87c3828428f6d4ead71357/pylogit/base_multinomial_cm_v2.py#L1377-L1386 |
timothyb0912/pylogit | pylogit/base_multinomial_cm_v2.py | MNDC_Model._add_mixing_variable_names_to_individual_vars | def _add_mixing_variable_names_to_individual_vars(self):
"""
Ensure that the model objects mixing variables are added to its list of
individual variables.
"""
assert isinstance(self.ind_var_names, list)
# Note that if one estimates a mixed logit model, then the mixing
... | python | def _add_mixing_variable_names_to_individual_vars(self):
"""
Ensure that the model objects mixing variables are added to its list of
individual variables.
"""
assert isinstance(self.ind_var_names, list)
# Note that if one estimates a mixed logit model, then the mixing
... | [
"def",
"_add_mixing_variable_names_to_individual_vars",
"(",
"self",
")",
":",
"assert",
"isinstance",
"(",
"self",
".",
"ind_var_names",
",",
"list",
")",
"# Note that if one estimates a mixed logit model, then the mixing",
"# variables will be added to individual vars. And if one e... | Ensure that the model objects mixing variables are added to its list of
individual variables. | [
"Ensure",
"that",
"the",
"model",
"objects",
"mixing",
"variables",
"are",
"added",
"to",
"its",
"list",
"of",
"individual",
"variables",
"."
] | train | https://github.com/timothyb0912/pylogit/blob/f83b0fd6debaa7358d87c3828428f6d4ead71357/pylogit/base_multinomial_cm_v2.py#L1388-L1405 |
timothyb0912/pylogit | pylogit/base_multinomial_cm_v2.py | MNDC_Model.store_fit_results | def store_fit_results(self, results_dict):
"""
Parameters
----------
results_dict : dict.
The estimation result dictionary that is output from
scipy.optimize.minimize. In addition to the standard keys which are
included, it should also contain the foll... | python | def store_fit_results(self, results_dict):
"""
Parameters
----------
results_dict : dict.
The estimation result dictionary that is output from
scipy.optimize.minimize. In addition to the standard keys which are
included, it should also contain the foll... | [
"def",
"store_fit_results",
"(",
"self",
",",
"results_dict",
")",
":",
"# Check to make sure the results_dict has all the needed keys.",
"self",
".",
"_check_result_dict_for_needed_keys",
"(",
"results_dict",
")",
"# Store the basic estimation results that simply need to be transferre... | Parameters
----------
results_dict : dict.
The estimation result dictionary that is output from
scipy.optimize.minimize. In addition to the standard keys which are
included, it should also contain the following keys:
`["final_gradient", "final_hessian", "fi... | [
"Parameters",
"----------",
"results_dict",
":",
"dict",
".",
"The",
"estimation",
"result",
"dictionary",
"that",
"is",
"output",
"from",
"scipy",
".",
"optimize",
".",
"minimize",
".",
"In",
"addition",
"to",
"the",
"standard",
"keys",
"which",
"are",
"inclu... | train | https://github.com/timothyb0912/pylogit/blob/f83b0fd6debaa7358d87c3828428f6d4ead71357/pylogit/base_multinomial_cm_v2.py#L1407-L1509 |
timothyb0912/pylogit | pylogit/base_multinomial_cm_v2.py | MNDC_Model.fit_mle | def fit_mle(self,
init_vals,
print_res=True,
method="BFGS",
loss_tol=1e-06,
gradient_tol=1e-06,
maxiter=1000,
ridge=None,
*args):
"""
Parameters
----------
init... | python | def fit_mle(self,
init_vals,
print_res=True,
method="BFGS",
loss_tol=1e-06,
gradient_tol=1e-06,
maxiter=1000,
ridge=None,
*args):
"""
Parameters
----------
init... | [
"def",
"fit_mle",
"(",
"self",
",",
"init_vals",
",",
"print_res",
"=",
"True",
",",
"method",
"=",
"\"BFGS\"",
",",
"loss_tol",
"=",
"1e-06",
",",
"gradient_tol",
"=",
"1e-06",
",",
"maxiter",
"=",
"1000",
",",
"ridge",
"=",
"None",
",",
"*",
"args",
... | Parameters
----------
init_vals : 1D ndarray.
The initial values to start the optimizatin process with. There
should be one value for each utility coefficient, outside intercept
parameter, shape parameter, and nest parameter being estimated.
print_res : bool, ... | [
"Parameters",
"----------",
"init_vals",
":",
"1D",
"ndarray",
".",
"The",
"initial",
"values",
"to",
"start",
"the",
"optimizatin",
"process",
"with",
".",
"There",
"should",
"be",
"one",
"value",
"for",
"each",
"utility",
"coefficient",
"outside",
"intercept",... | train | https://github.com/timothyb0912/pylogit/blob/f83b0fd6debaa7358d87c3828428f6d4ead71357/pylogit/base_multinomial_cm_v2.py#L1513-L1554 |
timothyb0912/pylogit | pylogit/base_multinomial_cm_v2.py | MNDC_Model.print_summaries | def print_summaries(self):
"""
Returns None. Will print the measures of fit and the estimation results
for the model.
"""
if hasattr(self, "fit_summary") and hasattr(self, "summary"):
print("\n")
print(self.fit_summary)
print("=" * 30)
... | python | def print_summaries(self):
"""
Returns None. Will print the measures of fit and the estimation results
for the model.
"""
if hasattr(self, "fit_summary") and hasattr(self, "summary"):
print("\n")
print(self.fit_summary)
print("=" * 30)
... | [
"def",
"print_summaries",
"(",
"self",
")",
":",
"if",
"hasattr",
"(",
"self",
",",
"\"fit_summary\"",
")",
"and",
"hasattr",
"(",
"self",
",",
"\"summary\"",
")",
":",
"print",
"(",
"\"\\n\"",
")",
"print",
"(",
"self",
".",
"fit_summary",
")",
"print",... | Returns None. Will print the measures of fit and the estimation results
for the model. | [
"Returns",
"None",
".",
"Will",
"print",
"the",
"measures",
"of",
"fit",
"and",
"the",
"estimation",
"results",
"for",
"the",
"model",
"."
] | train | https://github.com/timothyb0912/pylogit/blob/f83b0fd6debaa7358d87c3828428f6d4ead71357/pylogit/base_multinomial_cm_v2.py#L1556-L1572 |
timothyb0912/pylogit | pylogit/base_multinomial_cm_v2.py | MNDC_Model.conf_int | def conf_int(self, alpha=0.05, coefs=None, return_df=False):
"""
Creates the dataframe or array of lower and upper bounds for the
(1-alpha)% confidence interval of the estimated parameters. Used when
creating the statsmodels summary.
Parameters
----------
alpha :... | python | def conf_int(self, alpha=0.05, coefs=None, return_df=False):
"""
Creates the dataframe or array of lower and upper bounds for the
(1-alpha)% confidence interval of the estimated parameters. Used when
creating the statsmodels summary.
Parameters
----------
alpha :... | [
"def",
"conf_int",
"(",
"self",
",",
"alpha",
"=",
"0.05",
",",
"coefs",
"=",
"None",
",",
"return_df",
"=",
"False",
")",
":",
"# Get the critical z-value for alpha / 2",
"z_critical",
"=",
"scipy",
".",
"stats",
".",
"norm",
".",
"ppf",
"(",
"1.0",
"-",
... | Creates the dataframe or array of lower and upper bounds for the
(1-alpha)% confidence interval of the estimated parameters. Used when
creating the statsmodels summary.
Parameters
----------
alpha : float, optional.
Should be between 0.0 and 1.0. Determines the (1-al... | [
"Creates",
"the",
"dataframe",
"or",
"array",
"of",
"lower",
"and",
"upper",
"bounds",
"for",
"the",
"(",
"1",
"-",
"alpha",
")",
"%",
"confidence",
"interval",
"of",
"the",
"estimated",
"parameters",
".",
"Used",
"when",
"creating",
"the",
"statsmodels",
... | train | https://github.com/timothyb0912/pylogit/blob/f83b0fd6debaa7358d87c3828428f6d4ead71357/pylogit/base_multinomial_cm_v2.py#L1574-L1623 |
timothyb0912/pylogit | pylogit/base_multinomial_cm_v2.py | MNDC_Model.get_statsmodels_summary | def get_statsmodels_summary(self,
title=None,
alpha=.05):
"""
Parameters
----------
title : str, or None, optional.
Will be the title of the returned summary. If None, the default
title is used.
... | python | def get_statsmodels_summary(self,
title=None,
alpha=.05):
"""
Parameters
----------
title : str, or None, optional.
Will be the title of the returned summary. If None, the default
title is used.
... | [
"def",
"get_statsmodels_summary",
"(",
"self",
",",
"title",
"=",
"None",
",",
"alpha",
"=",
".05",
")",
":",
"try",
":",
"# Get the statsmodels Summary class",
"from",
"statsmodels",
".",
"iolib",
".",
"summary",
"import",
"Summary",
"except",
"ImportError",
":... | Parameters
----------
title : str, or None, optional.
Will be the title of the returned summary. If None, the default
title is used.
alpha : float, optional.
Should be between 0.0 and 1.0. Determines the width of the
displayed, (1 - alpha)% confide... | [
"Parameters",
"----------",
"title",
":",
"str",
"or",
"None",
"optional",
".",
"Will",
"be",
"the",
"title",
"of",
"the",
"returned",
"summary",
".",
"If",
"None",
"the",
"default",
"title",
"is",
"used",
".",
"alpha",
":",
"float",
"optional",
".",
"Sh... | train | https://github.com/timothyb0912/pylogit/blob/f83b0fd6debaa7358d87c3828428f6d4ead71357/pylogit/base_multinomial_cm_v2.py#L1625-L1706 |
timothyb0912/pylogit | pylogit/base_multinomial_cm_v2.py | MNDC_Model.check_param_list_validity | def check_param_list_validity(self, param_list):
"""
Parameters
----------
param_list : list.
Contains four elements, each being a numpy array. Either all of the
arrays should be 1D or all of the arrays should be 2D. If 2D, the
arrays should have the s... | python | def check_param_list_validity(self, param_list):
"""
Parameters
----------
param_list : list.
Contains four elements, each being a numpy array. Either all of the
arrays should be 1D or all of the arrays should be 2D. If 2D, the
arrays should have the s... | [
"def",
"check_param_list_validity",
"(",
"self",
",",
"param_list",
")",
":",
"if",
"param_list",
"is",
"None",
":",
"return",
"None",
"# Make sure there are four elements in param_list",
"check_type_and_size_of_param_list",
"(",
"param_list",
",",
"4",
")",
"# Make sure ... | Parameters
----------
param_list : list.
Contains four elements, each being a numpy array. Either all of the
arrays should be 1D or all of the arrays should be 2D. If 2D, the
arrays should have the same number of columns. Each column being a
particular set... | [
"Parameters",
"----------",
"param_list",
":",
"list",
".",
"Contains",
"four",
"elements",
"each",
"being",
"a",
"numpy",
"array",
".",
"Either",
"all",
"of",
"the",
"arrays",
"should",
"be",
"1D",
"or",
"all",
"of",
"the",
"arrays",
"should",
"be",
"2D",... | train | https://github.com/timothyb0912/pylogit/blob/f83b0fd6debaa7358d87c3828428f6d4ead71357/pylogit/base_multinomial_cm_v2.py#L1708-L1777 |
timothyb0912/pylogit | pylogit/base_multinomial_cm_v2.py | MNDC_Model.predict | def predict(self,
data,
param_list=None,
return_long_probs=True,
choice_col=None,
num_draws=None,
seed=None):
"""
Parameters
----------
data : string or pandas dataframe.
If string... | python | def predict(self,
data,
param_list=None,
return_long_probs=True,
choice_col=None,
num_draws=None,
seed=None):
"""
Parameters
----------
data : string or pandas dataframe.
If string... | [
"def",
"predict",
"(",
"self",
",",
"data",
",",
"param_list",
"=",
"None",
",",
"return_long_probs",
"=",
"True",
",",
"choice_col",
"=",
"None",
",",
"num_draws",
"=",
"None",
",",
"seed",
"=",
"None",
")",
":",
"# Get the dataframe of observations we'll be ... | Parameters
----------
data : string or pandas dataframe.
If string, data should be an absolute or relative path to a CSV
file containing the long format data for this choice model. Note
long format is has one row per available alternative for each
observat... | [
"Parameters",
"----------",
"data",
":",
"string",
"or",
"pandas",
"dataframe",
".",
"If",
"string",
"data",
"should",
"be",
"an",
"absolute",
"or",
"relative",
"path",
"to",
"a",
"CSV",
"file",
"containing",
"the",
"long",
"format",
"data",
"for",
"this",
... | train | https://github.com/timothyb0912/pylogit/blob/f83b0fd6debaa7358d87c3828428f6d4ead71357/pylogit/base_multinomial_cm_v2.py#L1779-L1972 |
timothyb0912/pylogit | pylogit/base_multinomial_cm_v2.py | MNDC_Model.to_pickle | def to_pickle(self, filepath):
"""
Parameters
----------
filepath : str.
Should end in .pkl. If it does not, ".pkl" will be appended to the
passed string.
Returns
-------
None. Saves the model object to the location specified by `filepath`... | python | def to_pickle(self, filepath):
"""
Parameters
----------
filepath : str.
Should end in .pkl. If it does not, ".pkl" will be appended to the
passed string.
Returns
-------
None. Saves the model object to the location specified by `filepath`... | [
"def",
"to_pickle",
"(",
"self",
",",
"filepath",
")",
":",
"if",
"not",
"isinstance",
"(",
"filepath",
",",
"str",
")",
":",
"raise",
"ValueError",
"(",
"\"filepath must be a string.\"",
")",
"if",
"not",
"filepath",
".",
"endswith",
"(",
"\".pkl\"",
")",
... | Parameters
----------
filepath : str.
Should end in .pkl. If it does not, ".pkl" will be appended to the
passed string.
Returns
-------
None. Saves the model object to the location specified by `filepath`. | [
"Parameters",
"----------",
"filepath",
":",
"str",
".",
"Should",
"end",
"in",
".",
"pkl",
".",
"If",
"it",
"does",
"not",
".",
"pkl",
"will",
"be",
"appended",
"to",
"the",
"passed",
"string",
"."
] | train | https://github.com/timothyb0912/pylogit/blob/f83b0fd6debaa7358d87c3828428f6d4ead71357/pylogit/base_multinomial_cm_v2.py#L1974-L1997 |
taskcluster/json-e | jsone/prattparser.py | prefix | def prefix(*kinds):
"""Decorate a method as handling prefix tokens of the given kinds"""
def wrap(fn):
try:
fn.prefix_kinds.extend(kinds)
except AttributeError:
fn.prefix_kinds = list(kinds)
return fn
return wrap | python | def prefix(*kinds):
"""Decorate a method as handling prefix tokens of the given kinds"""
def wrap(fn):
try:
fn.prefix_kinds.extend(kinds)
except AttributeError:
fn.prefix_kinds = list(kinds)
return fn
return wrap | [
"def",
"prefix",
"(",
"*",
"kinds",
")",
":",
"def",
"wrap",
"(",
"fn",
")",
":",
"try",
":",
"fn",
".",
"prefix_kinds",
".",
"extend",
"(",
"kinds",
")",
"except",
"AttributeError",
":",
"fn",
".",
"prefix_kinds",
"=",
"list",
"(",
"kinds",
")",
"... | Decorate a method as handling prefix tokens of the given kinds | [
"Decorate",
"a",
"method",
"as",
"handling",
"prefix",
"tokens",
"of",
"the",
"given",
"kinds"
] | train | https://github.com/taskcluster/json-e/blob/ac0c9fba1de3ed619f05a64dae929f6687789cbc/jsone/prattparser.py#L20-L28 |
taskcluster/json-e | jsone/prattparser.py | infix | def infix(*kinds):
"""Decorate a method as handling infix tokens of the given kinds"""
def wrap(fn):
try:
fn.infix_kinds.extend(kinds)
except AttributeError:
fn.infix_kinds = list(kinds)
return fn
return wrap | python | def infix(*kinds):
"""Decorate a method as handling infix tokens of the given kinds"""
def wrap(fn):
try:
fn.infix_kinds.extend(kinds)
except AttributeError:
fn.infix_kinds = list(kinds)
return fn
return wrap | [
"def",
"infix",
"(",
"*",
"kinds",
")",
":",
"def",
"wrap",
"(",
"fn",
")",
":",
"try",
":",
"fn",
".",
"infix_kinds",
".",
"extend",
"(",
"kinds",
")",
"except",
"AttributeError",
":",
"fn",
".",
"infix_kinds",
"=",
"list",
"(",
"kinds",
")",
"ret... | Decorate a method as handling infix tokens of the given kinds | [
"Decorate",
"a",
"method",
"as",
"handling",
"infix",
"tokens",
"of",
"the",
"given",
"kinds"
] | train | https://github.com/taskcluster/json-e/blob/ac0c9fba1de3ed619f05a64dae929f6687789cbc/jsone/prattparser.py#L31-L39 |
taskcluster/json-e | jsone/prattparser.py | ParseContext.attempt | def attempt(self, *kinds):
"""Try to get the next token if it matches one of the kinds given,
otherwise returning None. If no kinds are given, any kind is
accepted."""
if self._error:
raise self._error
token = self.next_token
if not token:
return N... | python | def attempt(self, *kinds):
"""Try to get the next token if it matches one of the kinds given,
otherwise returning None. If no kinds are given, any kind is
accepted."""
if self._error:
raise self._error
token = self.next_token
if not token:
return N... | [
"def",
"attempt",
"(",
"self",
",",
"*",
"kinds",
")",
":",
"if",
"self",
".",
"_error",
":",
"raise",
"self",
".",
"_error",
"token",
"=",
"self",
".",
"next_token",
"if",
"not",
"token",
":",
"return",
"None",
"if",
"kinds",
"and",
"token",
".",
... | Try to get the next token if it matches one of the kinds given,
otherwise returning None. If no kinds are given, any kind is
accepted. | [
"Try",
"to",
"get",
"the",
"next",
"token",
"if",
"it",
"matches",
"one",
"of",
"the",
"kinds",
"given",
"otherwise",
"returning",
"None",
".",
"If",
"no",
"kinds",
"are",
"given",
"any",
"kind",
"is",
"accepted",
"."
] | train | https://github.com/taskcluster/json-e/blob/ac0c9fba1de3ed619f05a64dae929f6687789cbc/jsone/prattparser.py#L150-L162 |
taskcluster/json-e | jsone/prattparser.py | ParseContext.require | def require(self, *kinds):
"""Get the next token, raising an exception if it doesn't match one of
the given kinds, or the input ends. If no kinds are given, returns the
next token of any kind."""
token = self.attempt()
if not token:
raise SyntaxError('Unexpected end o... | python | def require(self, *kinds):
"""Get the next token, raising an exception if it doesn't match one of
the given kinds, or the input ends. If no kinds are given, returns the
next token of any kind."""
token = self.attempt()
if not token:
raise SyntaxError('Unexpected end o... | [
"def",
"require",
"(",
"self",
",",
"*",
"kinds",
")",
":",
"token",
"=",
"self",
".",
"attempt",
"(",
")",
"if",
"not",
"token",
":",
"raise",
"SyntaxError",
"(",
"'Unexpected end of input'",
")",
"if",
"kinds",
"and",
"token",
".",
"kind",
"not",
"in... | Get the next token, raising an exception if it doesn't match one of
the given kinds, or the input ends. If no kinds are given, returns the
next token of any kind. | [
"Get",
"the",
"next",
"token",
"raising",
"an",
"exception",
"if",
"it",
"doesn",
"t",
"match",
"one",
"of",
"the",
"given",
"kinds",
"or",
"the",
"input",
"ends",
".",
"If",
"no",
"kinds",
"are",
"given",
"returns",
"the",
"next",
"token",
"of",
"any"... | train | https://github.com/taskcluster/json-e/blob/ac0c9fba1de3ed619f05a64dae929f6687789cbc/jsone/prattparser.py#L164-L173 |
amzn/ion-python | amazon/ion/symbols.py | local_symbol_table | def local_symbol_table(imports=None, symbols=()):
"""Constructs a local symbol table.
Args:
imports (Optional[SymbolTable]): Shared symbol tables to import.
symbols (Optional[Iterable[Unicode]]): Initial local symbols to add.
Returns:
SymbolTable: A mutable local symbol table with ... | python | def local_symbol_table(imports=None, symbols=()):
"""Constructs a local symbol table.
Args:
imports (Optional[SymbolTable]): Shared symbol tables to import.
symbols (Optional[Iterable[Unicode]]): Initial local symbols to add.
Returns:
SymbolTable: A mutable local symbol table with ... | [
"def",
"local_symbol_table",
"(",
"imports",
"=",
"None",
",",
"symbols",
"=",
"(",
")",
")",
":",
"return",
"SymbolTable",
"(",
"table_type",
"=",
"LOCAL_TABLE_TYPE",
",",
"symbols",
"=",
"symbols",
",",
"imports",
"=",
"imports",
")"
] | Constructs a local symbol table.
Args:
imports (Optional[SymbolTable]): Shared symbol tables to import.
symbols (Optional[Iterable[Unicode]]): Initial local symbols to add.
Returns:
SymbolTable: A mutable local symbol table with the seeded local symbols. | [
"Constructs",
"a",
"local",
"symbol",
"table",
"."
] | train | https://github.com/amzn/ion-python/blob/0b21fa3ba7755f55f745e4aa970d86343b82449d/amazon/ion/symbols.py#L380-L394 |
amzn/ion-python | amazon/ion/symbols.py | shared_symbol_table | def shared_symbol_table(name, version, symbols, imports=None):
"""Constructs a shared symbol table.
Args:
name (unicode): The name of the shared symbol table.
version (int): The version of the shared symbol table.
symbols (Iterable[unicode]): The symbols to associate with the table.
... | python | def shared_symbol_table(name, version, symbols, imports=None):
"""Constructs a shared symbol table.
Args:
name (unicode): The name of the shared symbol table.
version (int): The version of the shared symbol table.
symbols (Iterable[unicode]): The symbols to associate with the table.
... | [
"def",
"shared_symbol_table",
"(",
"name",
",",
"version",
",",
"symbols",
",",
"imports",
"=",
"None",
")",
":",
"return",
"SymbolTable",
"(",
"table_type",
"=",
"SHARED_TABLE_TYPE",
",",
"symbols",
"=",
"symbols",
",",
"name",
"=",
"name",
",",
"version",
... | Constructs a shared symbol table.
Args:
name (unicode): The name of the shared symbol table.
version (int): The version of the shared symbol table.
symbols (Iterable[unicode]): The symbols to associate with the table.
imports (Optional[Iterable[SymbolTable]): The shared symbol table... | [
"Constructs",
"a",
"shared",
"symbol",
"table",
"."
] | train | https://github.com/amzn/ion-python/blob/0b21fa3ba7755f55f745e4aa970d86343b82449d/amazon/ion/symbols.py#L397-L415 |
amzn/ion-python | amazon/ion/symbols.py | placeholder_symbol_table | def placeholder_symbol_table(name, version, max_id):
"""Constructs a shared symbol table that consists symbols that all have no known text.
This is generally used for cases where a shared symbol table is not available by the
application.
Args:
name (unicode): The name of the shared symbol tabl... | python | def placeholder_symbol_table(name, version, max_id):
"""Constructs a shared symbol table that consists symbols that all have no known text.
This is generally used for cases where a shared symbol table is not available by the
application.
Args:
name (unicode): The name of the shared symbol tabl... | [
"def",
"placeholder_symbol_table",
"(",
"name",
",",
"version",
",",
"max_id",
")",
":",
"if",
"version",
"<=",
"0",
":",
"raise",
"ValueError",
"(",
"'Version must be grater than or equal to 1: %s'",
"%",
"version",
")",
"if",
"max_id",
"<",
"0",
":",
"raise",
... | Constructs a shared symbol table that consists symbols that all have no known text.
This is generally used for cases where a shared symbol table is not available by the
application.
Args:
name (unicode): The name of the shared symbol table.
version (int): The version of the shared symbol t... | [
"Constructs",
"a",
"shared",
"symbol",
"table",
"that",
"consists",
"symbols",
"that",
"all",
"have",
"no",
"known",
"text",
"."
] | train | https://github.com/amzn/ion-python/blob/0b21fa3ba7755f55f745e4aa970d86343b82449d/amazon/ion/symbols.py#L418-L443 |
amzn/ion-python | amazon/ion/symbols.py | substitute_symbol_table | def substitute_symbol_table(table, version, max_id):
"""Substitutes a given shared symbol table for another version.
* If the given table has **more** symbols than the requested substitute, then the generated
symbol table will be a subset of the given table.
* If the given table has **less** symbols ... | python | def substitute_symbol_table(table, version, max_id):
"""Substitutes a given shared symbol table for another version.
* If the given table has **more** symbols than the requested substitute, then the generated
symbol table will be a subset of the given table.
* If the given table has **less** symbols ... | [
"def",
"substitute_symbol_table",
"(",
"table",
",",
"version",
",",
"max_id",
")",
":",
"if",
"not",
"table",
".",
"table_type",
".",
"is_shared",
":",
"raise",
"ValueError",
"(",
"'Symbol table to substitute from must be a shared table'",
")",
"if",
"version",
"<=... | Substitutes a given shared symbol table for another version.
* If the given table has **more** symbols than the requested substitute, then the generated
symbol table will be a subset of the given table.
* If the given table has **less** symbols than the requested substitute, then the generated
symb... | [
"Substitutes",
"a",
"given",
"shared",
"symbol",
"table",
"for",
"another",
"version",
"."
] | train | https://github.com/amzn/ion-python/blob/0b21fa3ba7755f55f745e4aa970d86343b82449d/amazon/ion/symbols.py#L446-L484 |
amzn/ion-python | amazon/ion/symbols.py | SymbolTable.__add | def __add(self, token):
"""Unconditionally adds a token to the table."""
self.__symbols.append(token)
text = token.text
if text is not None and text not in self.__mapping:
self.__mapping[text] = token | python | def __add(self, token):
"""Unconditionally adds a token to the table."""
self.__symbols.append(token)
text = token.text
if text is not None and text not in self.__mapping:
self.__mapping[text] = token | [
"def",
"__add",
"(",
"self",
",",
"token",
")",
":",
"self",
".",
"__symbols",
".",
"append",
"(",
"token",
")",
"text",
"=",
"token",
".",
"text",
"if",
"text",
"is",
"not",
"None",
"and",
"text",
"not",
"in",
"self",
".",
"__mapping",
":",
"self"... | Unconditionally adds a token to the table. | [
"Unconditionally",
"adds",
"a",
"token",
"to",
"the",
"table",
"."
] | train | https://github.com/amzn/ion-python/blob/0b21fa3ba7755f55f745e4aa970d86343b82449d/amazon/ion/symbols.py#L213-L218 |
amzn/ion-python | amazon/ion/symbols.py | SymbolTable.__add_shared | def __add_shared(self, original_token):
"""Adds a token, normalizing the SID and import reference to this table."""
sid = self.__new_sid()
token = SymbolToken(original_token.text, sid, self.__import_location(sid))
self.__add(token)
return token | python | def __add_shared(self, original_token):
"""Adds a token, normalizing the SID and import reference to this table."""
sid = self.__new_sid()
token = SymbolToken(original_token.text, sid, self.__import_location(sid))
self.__add(token)
return token | [
"def",
"__add_shared",
"(",
"self",
",",
"original_token",
")",
":",
"sid",
"=",
"self",
".",
"__new_sid",
"(",
")",
"token",
"=",
"SymbolToken",
"(",
"original_token",
".",
"text",
",",
"sid",
",",
"self",
".",
"__import_location",
"(",
"sid",
")",
")",... | Adds a token, normalizing the SID and import reference to this table. | [
"Adds",
"a",
"token",
"normalizing",
"the",
"SID",
"and",
"import",
"reference",
"to",
"this",
"table",
"."
] | train | https://github.com/amzn/ion-python/blob/0b21fa3ba7755f55f745e4aa970d86343b82449d/amazon/ion/symbols.py#L220-L225 |
amzn/ion-python | amazon/ion/symbols.py | SymbolTable.__add_import | def __add_import(self, original_token):
"""Adds a token, normalizing only the SID"""
sid = self.__new_sid()
token = SymbolToken(original_token.text, sid, original_token.location)
self.__add(token)
return token | python | def __add_import(self, original_token):
"""Adds a token, normalizing only the SID"""
sid = self.__new_sid()
token = SymbolToken(original_token.text, sid, original_token.location)
self.__add(token)
return token | [
"def",
"__add_import",
"(",
"self",
",",
"original_token",
")",
":",
"sid",
"=",
"self",
".",
"__new_sid",
"(",
")",
"token",
"=",
"SymbolToken",
"(",
"original_token",
".",
"text",
",",
"sid",
",",
"original_token",
".",
"location",
")",
"self",
".",
"_... | Adds a token, normalizing only the SID | [
"Adds",
"a",
"token",
"normalizing",
"only",
"the",
"SID"
] | train | https://github.com/amzn/ion-python/blob/0b21fa3ba7755f55f745e4aa970d86343b82449d/amazon/ion/symbols.py#L227-L232 |
amzn/ion-python | amazon/ion/symbols.py | SymbolTable.__add_text | def __add_text(self, text):
"""Adds the given Unicode text as a locally defined symbol."""
if text is not None and not isinstance(text, six.text_type):
raise TypeError('Local symbol definition must be a Unicode sequence or None: %r' % text)
sid = self.__new_sid()
location = N... | python | def __add_text(self, text):
"""Adds the given Unicode text as a locally defined symbol."""
if text is not None and not isinstance(text, six.text_type):
raise TypeError('Local symbol definition must be a Unicode sequence or None: %r' % text)
sid = self.__new_sid()
location = N... | [
"def",
"__add_text",
"(",
"self",
",",
"text",
")",
":",
"if",
"text",
"is",
"not",
"None",
"and",
"not",
"isinstance",
"(",
"text",
",",
"six",
".",
"text_type",
")",
":",
"raise",
"TypeError",
"(",
"'Local symbol definition must be a Unicode sequence or None: ... | Adds the given Unicode text as a locally defined symbol. | [
"Adds",
"the",
"given",
"Unicode",
"text",
"as",
"a",
"locally",
"defined",
"symbol",
"."
] | train | https://github.com/amzn/ion-python/blob/0b21fa3ba7755f55f745e4aa970d86343b82449d/amazon/ion/symbols.py#L234-L244 |
amzn/ion-python | amazon/ion/symbols.py | SymbolTable.intern | def intern(self, text):
"""Interns the given Unicode sequence into the symbol table.
Note:
This operation is only valid on local symbol tables.
Args:
text (unicode): The target to intern.
Returns:
SymbolToken: The mapped symbol token which may alrea... | python | def intern(self, text):
"""Interns the given Unicode sequence into the symbol table.
Note:
This operation is only valid on local symbol tables.
Args:
text (unicode): The target to intern.
Returns:
SymbolToken: The mapped symbol token which may alrea... | [
"def",
"intern",
"(",
"self",
",",
"text",
")",
":",
"if",
"self",
".",
"table_type",
".",
"is_shared",
":",
"raise",
"TypeError",
"(",
"'Cannot intern on shared symbol table'",
")",
"if",
"not",
"isinstance",
"(",
"text",
",",
"six",
".",
"text_type",
")",
... | Interns the given Unicode sequence into the symbol table.
Note:
This operation is only valid on local symbol tables.
Args:
text (unicode): The target to intern.
Returns:
SymbolToken: The mapped symbol token which may already exist in the table. | [
"Interns",
"the",
"given",
"Unicode",
"sequence",
"into",
"the",
"symbol",
"table",
"."
] | train | https://github.com/amzn/ion-python/blob/0b21fa3ba7755f55f745e4aa970d86343b82449d/amazon/ion/symbols.py#L246-L266 |
amzn/ion-python | amazon/ion/symbols.py | SymbolTable.get | def get(self, key, default=None):
"""Returns a token by text or local ID, with a default.
A given text image may be associated with more than one symbol ID. This will return the first definition.
Note:
User defined symbol IDs are always one-based. Symbol zero is a special symbol ... | python | def get(self, key, default=None):
"""Returns a token by text or local ID, with a default.
A given text image may be associated with more than one symbol ID. This will return the first definition.
Note:
User defined symbol IDs are always one-based. Symbol zero is a special symbol ... | [
"def",
"get",
"(",
"self",
",",
"key",
",",
"default",
"=",
"None",
")",
":",
"if",
"isinstance",
"(",
"key",
",",
"six",
".",
"text_type",
")",
":",
"return",
"self",
".",
"__mapping",
".",
"get",
"(",
"key",
",",
"None",
")",
"if",
"not",
"isin... | Returns a token by text or local ID, with a default.
A given text image may be associated with more than one symbol ID. This will return the first definition.
Note:
User defined symbol IDs are always one-based. Symbol zero is a special symbol that
always has no text.
... | [
"Returns",
"a",
"token",
"by",
"text",
"or",
"local",
"ID",
"with",
"a",
"default",
"."
] | train | https://github.com/amzn/ion-python/blob/0b21fa3ba7755f55f745e4aa970d86343b82449d/amazon/ion/symbols.py#L268-L297 |
amzn/ion-python | amazon/ion/symbols.py | SymbolTableCatalog.register | def register(self, table):
"""Adds a shared table to the catalog.
Args:
table (SymbolTable): A non-system, shared symbol table.
"""
if table.table_type.is_system:
raise ValueError('Cannot add system table to catalog')
if not table.table_type.is_shared:
... | python | def register(self, table):
"""Adds a shared table to the catalog.
Args:
table (SymbolTable): A non-system, shared symbol table.
"""
if table.table_type.is_system:
raise ValueError('Cannot add system table to catalog')
if not table.table_type.is_shared:
... | [
"def",
"register",
"(",
"self",
",",
"table",
")",
":",
"if",
"table",
".",
"table_type",
".",
"is_system",
":",
"raise",
"ValueError",
"(",
"'Cannot add system table to catalog'",
")",
"if",
"not",
"table",
".",
"table_type",
".",
"is_shared",
":",
"raise",
... | Adds a shared table to the catalog.
Args:
table (SymbolTable): A non-system, shared symbol table. | [
"Adds",
"a",
"shared",
"table",
"to",
"the",
"catalog",
"."
] | train | https://github.com/amzn/ion-python/blob/0b21fa3ba7755f55f745e4aa970d86343b82449d/amazon/ion/symbols.py#L499-L516 |
amzn/ion-python | amazon/ion/symbols.py | SymbolTableCatalog.resolve | def resolve(self, name, version, max_id):
"""Resolves the table for a given name and version.
Args:
name (unicode): The name of the table to resolve.
version (int): The version of the table to resolve.
max_id (Optional[int]): The maximum ID of the table requested.
... | python | def resolve(self, name, version, max_id):
"""Resolves the table for a given name and version.
Args:
name (unicode): The name of the table to resolve.
version (int): The version of the table to resolve.
max_id (Optional[int]): The maximum ID of the table requested.
... | [
"def",
"resolve",
"(",
"self",
",",
"name",
",",
"version",
",",
"max_id",
")",
":",
"if",
"not",
"isinstance",
"(",
"name",
",",
"six",
".",
"text_type",
")",
":",
"raise",
"TypeError",
"(",
"'Name must be a Unicode sequence: %r'",
"%",
"name",
")",
"if",... | Resolves the table for a given name and version.
Args:
name (unicode): The name of the table to resolve.
version (int): The version of the table to resolve.
max_id (Optional[int]): The maximum ID of the table requested.
May be ``None`` in which case an exact ... | [
"Resolves",
"the",
"table",
"for",
"a",
"given",
"name",
"and",
"version",
"."
] | train | https://github.com/amzn/ion-python/blob/0b21fa3ba7755f55f745e4aa970d86343b82449d/amazon/ion/symbols.py#L518-L564 |
amzn/ion-python | amazon/ion/writer_buffer.py | BufferTree.start_container | def start_container(self):
"""Add a node to the tree that represents the start of a container.
Until end_container is called, any nodes added through add_scalar_value
or start_container will be children of this new node.
"""
self.__container_lengths.append(self.current_container... | python | def start_container(self):
"""Add a node to the tree that represents the start of a container.
Until end_container is called, any nodes added through add_scalar_value
or start_container will be children of this new node.
"""
self.__container_lengths.append(self.current_container... | [
"def",
"start_container",
"(",
"self",
")",
":",
"self",
".",
"__container_lengths",
".",
"append",
"(",
"self",
".",
"current_container_length",
")",
"self",
".",
"current_container_length",
"=",
"0",
"new_container_node",
"=",
"_Node",
"(",
")",
"self",
".",
... | Add a node to the tree that represents the start of a container.
Until end_container is called, any nodes added through add_scalar_value
or start_container will be children of this new node. | [
"Add",
"a",
"node",
"to",
"the",
"tree",
"that",
"represents",
"the",
"start",
"of",
"a",
"container",
"."
] | train | https://github.com/amzn/ion-python/blob/0b21fa3ba7755f55f745e4aa970d86343b82449d/amazon/ion/writer_buffer.py#L91-L102 |
amzn/ion-python | amazon/ion/writer_buffer.py | BufferTree.end_container | def end_container(self, header_buf):
"""Add a node containing the container's header to the current subtree.
This node will be added as the leftmost leaf of the subtree that was
started by the matching call to start_container.
Args:
header_buf (bytearray): bytearray contain... | python | def end_container(self, header_buf):
"""Add a node containing the container's header to the current subtree.
This node will be added as the leftmost leaf of the subtree that was
started by the matching call to start_container.
Args:
header_buf (bytearray): bytearray contain... | [
"def",
"end_container",
"(",
"self",
",",
"header_buf",
")",
":",
"if",
"not",
"self",
".",
"__container_nodes",
":",
"raise",
"ValueError",
"(",
"\"Attempted to end container with none active.\"",
")",
"# Header needs to be the first node visited on this subtree.",
"self",
... | Add a node containing the container's header to the current subtree.
This node will be added as the leftmost leaf of the subtree that was
started by the matching call to start_container.
Args:
header_buf (bytearray): bytearray containing the container header. | [
"Add",
"a",
"node",
"containing",
"the",
"container",
"s",
"header",
"to",
"the",
"current",
"subtree",
"."
] | train | https://github.com/amzn/ion-python/blob/0b21fa3ba7755f55f745e4aa970d86343b82449d/amazon/ion/writer_buffer.py#L104-L120 |
amzn/ion-python | amazon/ion/writer_buffer.py | BufferTree.add_scalar_value | def add_scalar_value(self, value_buf):
"""Add a node to the tree containing a scalar value.
Args:
value_buf (bytearray): bytearray containing the scalar value.
"""
self.__container_node.add_child(_Node(value_buf))
self.current_container_length += len(value_buf) | python | def add_scalar_value(self, value_buf):
"""Add a node to the tree containing a scalar value.
Args:
value_buf (bytearray): bytearray containing the scalar value.
"""
self.__container_node.add_child(_Node(value_buf))
self.current_container_length += len(value_buf) | [
"def",
"add_scalar_value",
"(",
"self",
",",
"value_buf",
")",
":",
"self",
".",
"__container_node",
".",
"add_child",
"(",
"_Node",
"(",
"value_buf",
")",
")",
"self",
".",
"current_container_length",
"+=",
"len",
"(",
"value_buf",
")"
] | Add a node to the tree containing a scalar value.
Args:
value_buf (bytearray): bytearray containing the scalar value. | [
"Add",
"a",
"node",
"to",
"the",
"tree",
"containing",
"a",
"scalar",
"value",
"."
] | train | https://github.com/amzn/ion-python/blob/0b21fa3ba7755f55f745e4aa970d86343b82449d/amazon/ion/writer_buffer.py#L122-L129 |
amzn/ion-python | amazon/ion/writer_buffer.py | BufferTree.drain | def drain(self):
"""Walk the BufferTree and reset it when finished.
Yields:
any: The current node's value.
"""
if self.__container_nodes:
raise ValueError("Attempted to drain without ending all containers.")
for buf in self.__depth_traverse(self.__root):
... | python | def drain(self):
"""Walk the BufferTree and reset it when finished.
Yields:
any: The current node's value.
"""
if self.__container_nodes:
raise ValueError("Attempted to drain without ending all containers.")
for buf in self.__depth_traverse(self.__root):
... | [
"def",
"drain",
"(",
"self",
")",
":",
"if",
"self",
".",
"__container_nodes",
":",
"raise",
"ValueError",
"(",
"\"Attempted to drain without ending all containers.\"",
")",
"for",
"buf",
"in",
"self",
".",
"__depth_traverse",
"(",
"self",
".",
"__root",
")",
":... | Walk the BufferTree and reset it when finished.
Yields:
any: The current node's value. | [
"Walk",
"the",
"BufferTree",
"and",
"reset",
"it",
"when",
"finished",
"."
] | train | https://github.com/amzn/ion-python/blob/0b21fa3ba7755f55f745e4aa970d86343b82449d/amazon/ion/writer_buffer.py#L131-L142 |
amzn/ion-python | amazon/ion/equivalence.py | ion_equals | def ion_equals(a, b, timestamps_instants_only=False):
"""Tests two objects for equivalence under the Ion data model.
There are three important cases:
* When neither operand specifies its `ion_type` or `annotations`, this method will only return True when the
values of both operands are equiva... | python | def ion_equals(a, b, timestamps_instants_only=False):
"""Tests two objects for equivalence under the Ion data model.
There are three important cases:
* When neither operand specifies its `ion_type` or `annotations`, this method will only return True when the
values of both operands are equiva... | [
"def",
"ion_equals",
"(",
"a",
",",
"b",
",",
"timestamps_instants_only",
"=",
"False",
")",
":",
"if",
"timestamps_instants_only",
":",
"return",
"_ion_equals_timestamps_instants",
"(",
"a",
",",
"b",
")",
"return",
"_ion_equals_timestamps_data_model",
"(",
"a",
... | Tests two objects for equivalence under the Ion data model.
There are three important cases:
* When neither operand specifies its `ion_type` or `annotations`, this method will only return True when the
values of both operands are equivalent under the Ion data model.
* When only one of the... | [
"Tests",
"two",
"objects",
"for",
"equivalence",
"under",
"the",
"Ion",
"data",
"model",
"."
] | train | https://github.com/amzn/ion-python/blob/0b21fa3ba7755f55f745e4aa970d86343b82449d/amazon/ion/equivalence.py#L35-L57 |
amzn/ion-python | amazon/ion/equivalence.py | _ion_equals | def _ion_equals(a, b, timestamp_comparison_func, recursive_comparison_func):
"""Compares a and b according to the description of the ion_equals method."""
for a, b in ((a, b), (b, a)): # Ensures that operand order does not matter.
if isinstance(a, _IonNature):
if isinstance(b, _IonNature):
... | python | def _ion_equals(a, b, timestamp_comparison_func, recursive_comparison_func):
"""Compares a and b according to the description of the ion_equals method."""
for a, b in ((a, b), (b, a)): # Ensures that operand order does not matter.
if isinstance(a, _IonNature):
if isinstance(b, _IonNature):
... | [
"def",
"_ion_equals",
"(",
"a",
",",
"b",
",",
"timestamp_comparison_func",
",",
"recursive_comparison_func",
")",
":",
"for",
"a",
",",
"b",
"in",
"(",
"(",
"a",
",",
"b",
")",
",",
"(",
"b",
",",
"a",
")",
")",
":",
"# Ensures that operand order does n... | Compares a and b according to the description of the ion_equals method. | [
"Compares",
"a",
"and",
"b",
"according",
"to",
"the",
"description",
"of",
"the",
"ion_equals",
"method",
"."
] | train | https://github.com/amzn/ion-python/blob/0b21fa3ba7755f55f745e4aa970d86343b82449d/amazon/ion/equivalence.py#L68-L110 |
amzn/ion-python | amazon/ion/equivalence.py | _timestamps_eq | def _timestamps_eq(a, b):
"""Compares two timestamp operands for equivalence under the Ion data model."""
assert isinstance(a, datetime)
if not isinstance(b, datetime):
return False
# Local offsets must be equivalent.
if (a.tzinfo is None) ^ (b.tzinfo is None):
return False
if a.... | python | def _timestamps_eq(a, b):
"""Compares two timestamp operands for equivalence under the Ion data model."""
assert isinstance(a, datetime)
if not isinstance(b, datetime):
return False
# Local offsets must be equivalent.
if (a.tzinfo is None) ^ (b.tzinfo is None):
return False
if a.... | [
"def",
"_timestamps_eq",
"(",
"a",
",",
"b",
")",
":",
"assert",
"isinstance",
"(",
"a",
",",
"datetime",
")",
"if",
"not",
"isinstance",
"(",
"b",
",",
"datetime",
")",
":",
"return",
"False",
"# Local offsets must be equivalent.",
"if",
"(",
"a",
".",
... | Compares two timestamp operands for equivalence under the Ion data model. | [
"Compares",
"two",
"timestamp",
"operands",
"for",
"equivalence",
"under",
"the",
"Ion",
"data",
"model",
"."
] | train | https://github.com/amzn/ion-python/blob/0b21fa3ba7755f55f745e4aa970d86343b82449d/amazon/ion/equivalence.py#L161-L182 |
amzn/ion-python | amazon/ion/equivalence.py | _timestamp_instants_eq | def _timestamp_instants_eq(a, b):
"""Compares two timestamp operands for point-in-time equivalence only."""
assert isinstance(a, datetime)
if not isinstance(b, datetime):
return False
# datetime's __eq__ can't compare a None offset and a non-None offset. For these equivalence semantics, a None
... | python | def _timestamp_instants_eq(a, b):
"""Compares two timestamp operands for point-in-time equivalence only."""
assert isinstance(a, datetime)
if not isinstance(b, datetime):
return False
# datetime's __eq__ can't compare a None offset and a non-None offset. For these equivalence semantics, a None
... | [
"def",
"_timestamp_instants_eq",
"(",
"a",
",",
"b",
")",
":",
"assert",
"isinstance",
"(",
"a",
",",
"datetime",
")",
"if",
"not",
"isinstance",
"(",
"b",
",",
"datetime",
")",
":",
"return",
"False",
"# datetime's __eq__ can't compare a None offset and a non-Non... | Compares two timestamp operands for point-in-time equivalence only. | [
"Compares",
"two",
"timestamp",
"operands",
"for",
"point",
"-",
"in",
"-",
"time",
"equivalence",
"only",
"."
] | train | https://github.com/amzn/ion-python/blob/0b21fa3ba7755f55f745e4aa970d86343b82449d/amazon/ion/equivalence.py#L185-L197 |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.