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 |
|---|---|---|---|---|---|---|---|---|---|---|
tcalmant/python-javaobj | javaobj/core.py | JavaObjectMarshaller._convert_type_to_char | def _convert_type_to_char(self, type_char):
"""
Converts the given type code to an int
:param type_char: A type code character
"""
typecode = type_char
if type(type_char) is int:
typecode = chr(type_char)
if typecode in self.TYPECODES_LIST:
... | python | def _convert_type_to_char(self, type_char):
"""
Converts the given type code to an int
:param type_char: A type code character
"""
typecode = type_char
if type(type_char) is int:
typecode = chr(type_char)
if typecode in self.TYPECODES_LIST:
... | [
"def",
"_convert_type_to_char",
"(",
"self",
",",
"type_char",
")",
":",
"typecode",
"=",
"type_char",
"if",
"type",
"(",
"type_char",
")",
"is",
"int",
":",
"typecode",
"=",
"chr",
"(",
"type_char",
")",
"if",
"typecode",
"in",
"self",
".",
"TYPECODES_LIS... | Converts the given type code to an int
:param type_char: A type code character | [
"Converts",
"the",
"given",
"type",
"code",
"to",
"an",
"int"
] | train | https://github.com/tcalmant/python-javaobj/blob/e042c2cbf1ce9de659b6cb9290b5ccd5442514d1/javaobj/core.py#L1640-L1660 |
tcalmant/python-javaobj | javaobj/core.py | DefaultObjectTransformer.create | def create(self, classdesc, unmarshaller=None):
# type: (JavaClass, JavaObjectUnmarshaller) -> JavaObject
"""
Transforms a deserialized Java object into a Python object
:param classdesc: The description of a Java class
:return: The Python form of the object, or the original Java... | python | def create(self, classdesc, unmarshaller=None):
# type: (JavaClass, JavaObjectUnmarshaller) -> JavaObject
"""
Transforms a deserialized Java object into a Python object
:param classdesc: The description of a Java class
:return: The Python form of the object, or the original Java... | [
"def",
"create",
"(",
"self",
",",
"classdesc",
",",
"unmarshaller",
"=",
"None",
")",
":",
"# type: (JavaClass, JavaObjectUnmarshaller) -> JavaObject",
"try",
":",
"mapped_type",
"=",
"self",
".",
"TYPE_MAPPER",
"[",
"classdesc",
".",
"name",
"]",
"except",
"KeyE... | Transforms a deserialized Java object into a Python object
:param classdesc: The description of a Java class
:return: The Python form of the object, or the original JavaObject | [
"Transforms",
"a",
"deserialized",
"Java",
"object",
"into",
"a",
"Python",
"object"
] | train | https://github.com/tcalmant/python-javaobj/blob/e042c2cbf1ce9de659b6cb9290b5ccd5442514d1/javaobj/core.py#L2002-L2023 |
UDST/urbansim | urbansim/utils/logutil.py | log_start_finish | def log_start_finish(msg, logger, level=logging.DEBUG):
"""
A context manager to log messages with "start: " and "finish: "
prefixes before and after a block.
Parameters
----------
msg : str
Will be prefixed with "start: " and "finish: ".
logger : logging.Logger
level : int, opt... | python | def log_start_finish(msg, logger, level=logging.DEBUG):
"""
A context manager to log messages with "start: " and "finish: "
prefixes before and after a block.
Parameters
----------
msg : str
Will be prefixed with "start: " and "finish: ".
logger : logging.Logger
level : int, opt... | [
"def",
"log_start_finish",
"(",
"msg",
",",
"logger",
",",
"level",
"=",
"logging",
".",
"DEBUG",
")",
":",
"logger",
".",
"log",
"(",
"level",
",",
"'start: '",
"+",
"msg",
")",
"yield",
"logger",
".",
"log",
"(",
"level",
",",
"'finish: '",
"+",
"m... | A context manager to log messages with "start: " and "finish: "
prefixes before and after a block.
Parameters
----------
msg : str
Will be prefixed with "start: " and "finish: ".
logger : logging.Logger
level : int, optional
Level at which to log, passed to ``logger.log``. | [
"A",
"context",
"manager",
"to",
"log",
"messages",
"with",
"start",
":",
"and",
"finish",
":",
"prefixes",
"before",
"and",
"after",
"a",
"block",
"."
] | train | https://github.com/UDST/urbansim/blob/79f815a6503e109f50be270cee92d0f4a34f49ef/urbansim/utils/logutil.py#L11-L27 |
UDST/urbansim | urbansim/utils/logutil.py | log_to_file | def log_to_file(filename, level=None, fmt=None, datefmt=None):
"""
Send log output to the given file.
Parameters
----------
filename : str
level : int, optional
An optional logging level that will apply only to this stream
handler.
fmt : str, optional
An optional for... | python | def log_to_file(filename, level=None, fmt=None, datefmt=None):
"""
Send log output to the given file.
Parameters
----------
filename : str
level : int, optional
An optional logging level that will apply only to this stream
handler.
fmt : str, optional
An optional for... | [
"def",
"log_to_file",
"(",
"filename",
",",
"level",
"=",
"None",
",",
"fmt",
"=",
"None",
",",
"datefmt",
"=",
"None",
")",
":",
"_add_urbansim_handler",
"(",
"logging",
".",
"FileHandler",
"(",
"filename",
")",
",",
"fmt",
"=",
"fmt",
",",
"datefmt",
... | Send log output to the given file.
Parameters
----------
filename : str
level : int, optional
An optional logging level that will apply only to this stream
handler.
fmt : str, optional
An optional format string that will be used for the log
messages.
datefmt : st... | [
"Send",
"log",
"output",
"to",
"the",
"given",
"file",
"."
] | train | https://github.com/UDST/urbansim/blob/79f815a6503e109f50be270cee92d0f4a34f49ef/urbansim/utils/logutil.py#L104-L123 |
UDST/urbansim | urbansim/urbanchoice/mnl.py | mnl_simulate | def mnl_simulate(data, coeff, numalts, GPU=False, returnprobs=True):
"""
Get the probabilities for each chooser choosing between `numalts`
alternatives.
Parameters
----------
data : 2D array
The data are expected to be in "long" form where each row is for
one alternative. Altern... | python | def mnl_simulate(data, coeff, numalts, GPU=False, returnprobs=True):
"""
Get the probabilities for each chooser choosing between `numalts`
alternatives.
Parameters
----------
data : 2D array
The data are expected to be in "long" form where each row is for
one alternative. Altern... | [
"def",
"mnl_simulate",
"(",
"data",
",",
"coeff",
",",
"numalts",
",",
"GPU",
"=",
"False",
",",
"returnprobs",
"=",
"True",
")",
":",
"logger",
".",
"debug",
"(",
"'start: MNL simulation with len(data)={} and numalts={}'",
".",
"format",
"(",
"len",
"(",
"dat... | Get the probabilities for each chooser choosing between `numalts`
alternatives.
Parameters
----------
data : 2D array
The data are expected to be in "long" form where each row is for
one alternative. Alternatives are in groups of `numalts` rows per
choosers. Alternatives must be... | [
"Get",
"the",
"probabilities",
"for",
"each",
"chooser",
"choosing",
"between",
"numalts",
"alternatives",
"."
] | train | https://github.com/UDST/urbansim/blob/79f815a6503e109f50be270cee92d0f4a34f49ef/urbansim/urbanchoice/mnl.py#L124-L175 |
UDST/urbansim | urbansim/urbanchoice/mnl.py | mnl_estimate | def mnl_estimate(data, chosen, numalts, GPU=False, coeffrange=(-3, 3),
weights=None, lcgrad=False, beta=None):
"""
Calculate coefficients of the MNL model.
Parameters
----------
data : 2D array
The data are expected to be in "long" form where each row is for
one alt... | python | def mnl_estimate(data, chosen, numalts, GPU=False, coeffrange=(-3, 3),
weights=None, lcgrad=False, beta=None):
"""
Calculate coefficients of the MNL model.
Parameters
----------
data : 2D array
The data are expected to be in "long" form where each row is for
one alt... | [
"def",
"mnl_estimate",
"(",
"data",
",",
"chosen",
",",
"numalts",
",",
"GPU",
"=",
"False",
",",
"coeffrange",
"=",
"(",
"-",
"3",
",",
"3",
")",
",",
"weights",
"=",
"None",
",",
"lcgrad",
"=",
"False",
",",
"beta",
"=",
"None",
")",
":",
"logg... | Calculate coefficients of the MNL model.
Parameters
----------
data : 2D array
The data are expected to be in "long" form where each row is for
one alternative. Alternatives are in groups of `numalts` rows per
choosers. Alternatives must be in the same order for each chooser.
ch... | [
"Calculate",
"coefficients",
"of",
"the",
"MNL",
"model",
"."
] | train | https://github.com/UDST/urbansim/blob/79f815a6503e109f50be270cee92d0f4a34f49ef/urbansim/urbanchoice/mnl.py#L178-L275 |
UDST/urbansim | urbansim/models/dcm.py | unit_choice | def unit_choice(chooser_ids, alternative_ids, probabilities):
"""
Have a set of choosers choose from among alternatives according
to a probability distribution. Choice is binary: each
alternative can only be chosen once.
Parameters
----------
chooser_ids : 1d array_like
Array of IDs... | python | def unit_choice(chooser_ids, alternative_ids, probabilities):
"""
Have a set of choosers choose from among alternatives according
to a probability distribution. Choice is binary: each
alternative can only be chosen once.
Parameters
----------
chooser_ids : 1d array_like
Array of IDs... | [
"def",
"unit_choice",
"(",
"chooser_ids",
",",
"alternative_ids",
",",
"probabilities",
")",
":",
"chooser_ids",
"=",
"np",
".",
"asanyarray",
"(",
"chooser_ids",
")",
"alternative_ids",
"=",
"np",
".",
"asanyarray",
"(",
"alternative_ids",
")",
"probabilities",
... | Have a set of choosers choose from among alternatives according
to a probability distribution. Choice is binary: each
alternative can only be chosen once.
Parameters
----------
chooser_ids : 1d array_like
Array of IDs of the agents that are making choices.
alternative_ids : 1d array_lik... | [
"Have",
"a",
"set",
"of",
"choosers",
"choose",
"from",
"among",
"alternatives",
"according",
"to",
"a",
"probability",
"distribution",
".",
"Choice",
"is",
"binary",
":",
"each",
"alternative",
"can",
"only",
"be",
"chosen",
"once",
"."
] | train | https://github.com/UDST/urbansim/blob/79f815a6503e109f50be270cee92d0f4a34f49ef/urbansim/models/dcm.py#L26-L85 |
UDST/urbansim | urbansim/models/dcm.py | MNLDiscreteChoiceModel.from_yaml | def from_yaml(cls, yaml_str=None, str_or_buffer=None):
"""
Create a DiscreteChoiceModel instance from a saved YAML configuration.
Arguments are mutally exclusive.
Parameters
----------
yaml_str : str, optional
A YAML string from which to load model.
s... | python | def from_yaml(cls, yaml_str=None, str_or_buffer=None):
"""
Create a DiscreteChoiceModel instance from a saved YAML configuration.
Arguments are mutally exclusive.
Parameters
----------
yaml_str : str, optional
A YAML string from which to load model.
s... | [
"def",
"from_yaml",
"(",
"cls",
",",
"yaml_str",
"=",
"None",
",",
"str_or_buffer",
"=",
"None",
")",
":",
"cfg",
"=",
"yamlio",
".",
"yaml_to_dict",
"(",
"yaml_str",
",",
"str_or_buffer",
")",
"model",
"=",
"cls",
"(",
"cfg",
"[",
"'model_expression'",
... | Create a DiscreteChoiceModel instance from a saved YAML configuration.
Arguments are mutally exclusive.
Parameters
----------
yaml_str : str, optional
A YAML string from which to load model.
str_or_buffer : str or file like, optional
File name or buffer f... | [
"Create",
"a",
"DiscreteChoiceModel",
"instance",
"from",
"a",
"saved",
"YAML",
"configuration",
".",
"Arguments",
"are",
"mutally",
"exclusive",
"."
] | train | https://github.com/UDST/urbansim/blob/79f815a6503e109f50be270cee92d0f4a34f49ef/urbansim/models/dcm.py#L278-L320 |
UDST/urbansim | urbansim/models/dcm.py | MNLDiscreteChoiceModel.apply_fit_filters | def apply_fit_filters(self, choosers, alternatives):
"""
Filter `choosers` and `alternatives` for fitting.
Parameters
----------
choosers : pandas.DataFrame
Table describing the agents making choices, e.g. households.
alternatives : pandas.DataFrame
... | python | def apply_fit_filters(self, choosers, alternatives):
"""
Filter `choosers` and `alternatives` for fitting.
Parameters
----------
choosers : pandas.DataFrame
Table describing the agents making choices, e.g. households.
alternatives : pandas.DataFrame
... | [
"def",
"apply_fit_filters",
"(",
"self",
",",
"choosers",
",",
"alternatives",
")",
":",
"return",
"super",
"(",
"MNLDiscreteChoiceModel",
",",
"self",
")",
".",
"apply_fit_filters",
"(",
"choosers",
",",
"alternatives",
")"
] | Filter `choosers` and `alternatives` for fitting.
Parameters
----------
choosers : pandas.DataFrame
Table describing the agents making choices, e.g. households.
alternatives : pandas.DataFrame
Table describing the things from which agents are choosing,
... | [
"Filter",
"choosers",
"and",
"alternatives",
"for",
"fitting",
"."
] | train | https://github.com/UDST/urbansim/blob/79f815a6503e109f50be270cee92d0f4a34f49ef/urbansim/models/dcm.py#L331-L349 |
UDST/urbansim | urbansim/models/dcm.py | MNLDiscreteChoiceModel.apply_predict_filters | def apply_predict_filters(self, choosers, alternatives):
"""
Filter `choosers` and `alternatives` for prediction.
Parameters
----------
choosers : pandas.DataFrame
Table describing the agents making choices, e.g. households.
alternatives : pandas.DataFrame
... | python | def apply_predict_filters(self, choosers, alternatives):
"""
Filter `choosers` and `alternatives` for prediction.
Parameters
----------
choosers : pandas.DataFrame
Table describing the agents making choices, e.g. households.
alternatives : pandas.DataFrame
... | [
"def",
"apply_predict_filters",
"(",
"self",
",",
"choosers",
",",
"alternatives",
")",
":",
"return",
"super",
"(",
"MNLDiscreteChoiceModel",
",",
"self",
")",
".",
"apply_predict_filters",
"(",
"choosers",
",",
"alternatives",
")"
] | Filter `choosers` and `alternatives` for prediction.
Parameters
----------
choosers : pandas.DataFrame
Table describing the agents making choices, e.g. households.
alternatives : pandas.DataFrame
Table describing the things from which agents are choosing,
... | [
"Filter",
"choosers",
"and",
"alternatives",
"for",
"prediction",
"."
] | train | https://github.com/UDST/urbansim/blob/79f815a6503e109f50be270cee92d0f4a34f49ef/urbansim/models/dcm.py#L351-L369 |
UDST/urbansim | urbansim/models/dcm.py | MNLDiscreteChoiceModel.fit | def fit(self, choosers, alternatives, current_choice):
"""
Fit and save model parameters based on given data.
Parameters
----------
choosers : pandas.DataFrame
Table describing the agents making choices, e.g. households.
alternatives : pandas.DataFrame
... | python | def fit(self, choosers, alternatives, current_choice):
"""
Fit and save model parameters based on given data.
Parameters
----------
choosers : pandas.DataFrame
Table describing the agents making choices, e.g. households.
alternatives : pandas.DataFrame
... | [
"def",
"fit",
"(",
"self",
",",
"choosers",
",",
"alternatives",
",",
"current_choice",
")",
":",
"logger",
".",
"debug",
"(",
"'start: fit LCM model {}'",
".",
"format",
"(",
"self",
".",
"name",
")",
")",
"if",
"not",
"isinstance",
"(",
"current_choice",
... | Fit and save model parameters based on given data.
Parameters
----------
choosers : pandas.DataFrame
Table describing the agents making choices, e.g. households.
alternatives : pandas.DataFrame
Table describing the things from which agents are choosing,
... | [
"Fit",
"and",
"save",
"model",
"parameters",
"based",
"on",
"given",
"data",
"."
] | train | https://github.com/UDST/urbansim/blob/79f815a6503e109f50be270cee92d0f4a34f49ef/urbansim/models/dcm.py#L371-L427 |
UDST/urbansim | urbansim/models/dcm.py | MNLDiscreteChoiceModel.report_fit | def report_fit(self):
"""
Print a report of the fit results.
"""
if not self.fitted:
print('Model not yet fit.')
return
print('Null Log-liklihood: {0:.3f}'.format(
self.log_likelihoods['null']))
print('Log-liklihood at convergence: {0... | python | def report_fit(self):
"""
Print a report of the fit results.
"""
if not self.fitted:
print('Model not yet fit.')
return
print('Null Log-liklihood: {0:.3f}'.format(
self.log_likelihoods['null']))
print('Log-liklihood at convergence: {0... | [
"def",
"report_fit",
"(",
"self",
")",
":",
"if",
"not",
"self",
".",
"fitted",
":",
"print",
"(",
"'Model not yet fit.'",
")",
"return",
"print",
"(",
"'Null Log-liklihood: {0:.3f}'",
".",
"format",
"(",
"self",
".",
"log_likelihoods",
"[",
"'null'",
"]",
"... | Print a report of the fit results. | [
"Print",
"a",
"report",
"of",
"the",
"fit",
"results",
"."
] | train | https://github.com/UDST/urbansim/blob/79f815a6503e109f50be270cee92d0f4a34f49ef/urbansim/models/dcm.py#L445-L472 |
UDST/urbansim | urbansim/models/dcm.py | MNLDiscreteChoiceModel.probabilities | def probabilities(self, choosers, alternatives, filter_tables=True):
"""
Returns the probabilities for a set of choosers to choose
from among a set of alternatives.
Parameters
----------
choosers : pandas.DataFrame
Table describing the agents making choices, ... | python | def probabilities(self, choosers, alternatives, filter_tables=True):
"""
Returns the probabilities for a set of choosers to choose
from among a set of alternatives.
Parameters
----------
choosers : pandas.DataFrame
Table describing the agents making choices, ... | [
"def",
"probabilities",
"(",
"self",
",",
"choosers",
",",
"alternatives",
",",
"filter_tables",
"=",
"True",
")",
":",
"logger",
".",
"debug",
"(",
"'start: calculate probabilities for LCM model {}'",
".",
"format",
"(",
"self",
".",
"name",
")",
")",
"self",
... | Returns the probabilities for a set of choosers to choose
from among a set of alternatives.
Parameters
----------
choosers : pandas.DataFrame
Table describing the agents making choices, e.g. households.
alternatives : pandas.DataFrame
Table describing the... | [
"Returns",
"the",
"probabilities",
"for",
"a",
"set",
"of",
"choosers",
"to",
"choose",
"from",
"among",
"a",
"set",
"of",
"alternatives",
"."
] | train | https://github.com/UDST/urbansim/blob/79f815a6503e109f50be270cee92d0f4a34f49ef/urbansim/models/dcm.py#L474-L560 |
UDST/urbansim | urbansim/models/dcm.py | MNLDiscreteChoiceModel.summed_probabilities | def summed_probabilities(self, choosers, alternatives):
"""
Calculate total probability associated with each alternative.
Parameters
----------
choosers : pandas.DataFrame
Table describing the agents making choices, e.g. households.
alternatives : pandas.Data... | python | def summed_probabilities(self, choosers, alternatives):
"""
Calculate total probability associated with each alternative.
Parameters
----------
choosers : pandas.DataFrame
Table describing the agents making choices, e.g. households.
alternatives : pandas.Data... | [
"def",
"summed_probabilities",
"(",
"self",
",",
"choosers",
",",
"alternatives",
")",
":",
"def",
"normalize",
"(",
"s",
")",
":",
"return",
"s",
"/",
"s",
".",
"sum",
"(",
")",
"choosers",
",",
"alternatives",
"=",
"self",
".",
"apply_predict_filters",
... | Calculate total probability associated with each alternative.
Parameters
----------
choosers : pandas.DataFrame
Table describing the agents making choices, e.g. households.
alternatives : pandas.DataFrame
Table describing the things from which agents are choosing... | [
"Calculate",
"total",
"probability",
"associated",
"with",
"each",
"alternative",
"."
] | train | https://github.com/UDST/urbansim/blob/79f815a6503e109f50be270cee92d0f4a34f49ef/urbansim/models/dcm.py#L562-L597 |
UDST/urbansim | urbansim/models/dcm.py | MNLDiscreteChoiceModel.predict | def predict(self, choosers, alternatives, debug=False):
"""
Choose from among alternatives for a group of agents.
Parameters
----------
choosers : pandas.DataFrame
Table describing the agents making choices, e.g. households.
alternatives : pandas.DataFrame
... | python | def predict(self, choosers, alternatives, debug=False):
"""
Choose from among alternatives for a group of agents.
Parameters
----------
choosers : pandas.DataFrame
Table describing the agents making choices, e.g. households.
alternatives : pandas.DataFrame
... | [
"def",
"predict",
"(",
"self",
",",
"choosers",
",",
"alternatives",
",",
"debug",
"=",
"False",
")",
":",
"self",
".",
"assert_fitted",
"(",
")",
"logger",
".",
"debug",
"(",
"'start: predict LCM model {}'",
".",
"format",
"(",
"self",
".",
"name",
")",
... | Choose from among alternatives for a group of agents.
Parameters
----------
choosers : pandas.DataFrame
Table describing the agents making choices, e.g. households.
alternatives : pandas.DataFrame
Table describing the things from which agents are choosing.
... | [
"Choose",
"from",
"among",
"alternatives",
"for",
"a",
"group",
"of",
"agents",
"."
] | train | https://github.com/UDST/urbansim/blob/79f815a6503e109f50be270cee92d0f4a34f49ef/urbansim/models/dcm.py#L599-L657 |
UDST/urbansim | urbansim/models/dcm.py | MNLDiscreteChoiceModel.to_dict | def to_dict(self):
"""
Return a dict respresentation of an MNLDiscreteChoiceModel
instance.
"""
return {
'model_type': 'discretechoice',
'model_expression': self.model_expression,
'sample_size': self.sample_size,
'name': self.name,... | python | def to_dict(self):
"""
Return a dict respresentation of an MNLDiscreteChoiceModel
instance.
"""
return {
'model_type': 'discretechoice',
'model_expression': self.model_expression,
'sample_size': self.sample_size,
'name': self.name,... | [
"def",
"to_dict",
"(",
"self",
")",
":",
"return",
"{",
"'model_type'",
":",
"'discretechoice'",
",",
"'model_expression'",
":",
"self",
".",
"model_expression",
",",
"'sample_size'",
":",
"self",
".",
"sample_size",
",",
"'name'",
":",
"self",
".",
"name",
... | Return a dict respresentation of an MNLDiscreteChoiceModel
instance. | [
"Return",
"a",
"dict",
"respresentation",
"of",
"an",
"MNLDiscreteChoiceModel",
"instance",
"."
] | train | https://github.com/UDST/urbansim/blob/79f815a6503e109f50be270cee92d0f4a34f49ef/urbansim/models/dcm.py#L659-L684 |
UDST/urbansim | urbansim/models/dcm.py | MNLDiscreteChoiceModel.to_yaml | def to_yaml(self, str_or_buffer=None):
"""
Save a model respresentation to YAML.
Parameters
----------
str_or_buffer : str or file like, optional
By default a YAML string is returned. If a string is
given here the YAML will be written to that file.
... | python | def to_yaml(self, str_or_buffer=None):
"""
Save a model respresentation to YAML.
Parameters
----------
str_or_buffer : str or file like, optional
By default a YAML string is returned. If a string is
given here the YAML will be written to that file.
... | [
"def",
"to_yaml",
"(",
"self",
",",
"str_or_buffer",
"=",
"None",
")",
":",
"logger",
".",
"debug",
"(",
"'serializing LCM model {} to YAML'",
".",
"format",
"(",
"self",
".",
"name",
")",
")",
"if",
"(",
"not",
"isinstance",
"(",
"self",
".",
"probability... | Save a model respresentation to YAML.
Parameters
----------
str_or_buffer : str or file like, optional
By default a YAML string is returned. If a string is
given here the YAML will be written to that file.
If an object with a ``.write`` method is given the
... | [
"Save",
"a",
"model",
"respresentation",
"to",
"YAML",
"."
] | train | https://github.com/UDST/urbansim/blob/79f815a6503e109f50be270cee92d0f4a34f49ef/urbansim/models/dcm.py#L686-L710 |
UDST/urbansim | urbansim/models/dcm.py | MNLDiscreteChoiceModel.choosers_columns_used | def choosers_columns_used(self):
"""
Columns from the choosers table that are used for filtering.
"""
return list(tz.unique(tz.concatv(
util.columns_in_filters(self.choosers_predict_filters),
util.columns_in_filters(self.choosers_fit_filters)))) | python | def choosers_columns_used(self):
"""
Columns from the choosers table that are used for filtering.
"""
return list(tz.unique(tz.concatv(
util.columns_in_filters(self.choosers_predict_filters),
util.columns_in_filters(self.choosers_fit_filters)))) | [
"def",
"choosers_columns_used",
"(",
"self",
")",
":",
"return",
"list",
"(",
"tz",
".",
"unique",
"(",
"tz",
".",
"concatv",
"(",
"util",
".",
"columns_in_filters",
"(",
"self",
".",
"choosers_predict_filters",
")",
",",
"util",
".",
"columns_in_filters",
"... | Columns from the choosers table that are used for filtering. | [
"Columns",
"from",
"the",
"choosers",
"table",
"that",
"are",
"used",
"for",
"filtering",
"."
] | train | https://github.com/UDST/urbansim/blob/79f815a6503e109f50be270cee92d0f4a34f49ef/urbansim/models/dcm.py#L712-L719 |
UDST/urbansim | urbansim/models/dcm.py | MNLDiscreteChoiceModel.alts_columns_used | def alts_columns_used(self):
"""
Columns from the alternatives table that are used for filtering.
"""
return list(tz.unique(tz.concatv(
util.columns_in_filters(self.alts_predict_filters),
util.columns_in_filters(self.alts_fit_filters)))) | python | def alts_columns_used(self):
"""
Columns from the alternatives table that are used for filtering.
"""
return list(tz.unique(tz.concatv(
util.columns_in_filters(self.alts_predict_filters),
util.columns_in_filters(self.alts_fit_filters)))) | [
"def",
"alts_columns_used",
"(",
"self",
")",
":",
"return",
"list",
"(",
"tz",
".",
"unique",
"(",
"tz",
".",
"concatv",
"(",
"util",
".",
"columns_in_filters",
"(",
"self",
".",
"alts_predict_filters",
")",
",",
"util",
".",
"columns_in_filters",
"(",
"s... | Columns from the alternatives table that are used for filtering. | [
"Columns",
"from",
"the",
"alternatives",
"table",
"that",
"are",
"used",
"for",
"filtering",
"."
] | train | https://github.com/UDST/urbansim/blob/79f815a6503e109f50be270cee92d0f4a34f49ef/urbansim/models/dcm.py#L721-L728 |
UDST/urbansim | urbansim/models/dcm.py | MNLDiscreteChoiceModel.interaction_columns_used | def interaction_columns_used(self):
"""
Columns from the interaction dataset used for filtering and in
the model. These may come originally from either the choosers or
alternatives tables.
"""
return list(tz.unique(tz.concatv(
util.columns_in_filters(self.int... | python | def interaction_columns_used(self):
"""
Columns from the interaction dataset used for filtering and in
the model. These may come originally from either the choosers or
alternatives tables.
"""
return list(tz.unique(tz.concatv(
util.columns_in_filters(self.int... | [
"def",
"interaction_columns_used",
"(",
"self",
")",
":",
"return",
"list",
"(",
"tz",
".",
"unique",
"(",
"tz",
".",
"concatv",
"(",
"util",
".",
"columns_in_filters",
"(",
"self",
".",
"interaction_predict_filters",
")",
",",
"util",
".",
"columns_in_formula... | Columns from the interaction dataset used for filtering and in
the model. These may come originally from either the choosers or
alternatives tables. | [
"Columns",
"from",
"the",
"interaction",
"dataset",
"used",
"for",
"filtering",
"and",
"in",
"the",
"model",
".",
"These",
"may",
"come",
"originally",
"from",
"either",
"the",
"choosers",
"or",
"alternatives",
"tables",
"."
] | train | https://github.com/UDST/urbansim/blob/79f815a6503e109f50be270cee92d0f4a34f49ef/urbansim/models/dcm.py#L730-L739 |
UDST/urbansim | urbansim/models/dcm.py | MNLDiscreteChoiceModel.columns_used | def columns_used(self):
"""
Columns from any table used in the model. May come from either
the choosers or alternatives tables.
"""
return list(tz.unique(tz.concatv(
self.choosers_columns_used(),
self.alts_columns_used(),
self.interaction_colu... | python | def columns_used(self):
"""
Columns from any table used in the model. May come from either
the choosers or alternatives tables.
"""
return list(tz.unique(tz.concatv(
self.choosers_columns_used(),
self.alts_columns_used(),
self.interaction_colu... | [
"def",
"columns_used",
"(",
"self",
")",
":",
"return",
"list",
"(",
"tz",
".",
"unique",
"(",
"tz",
".",
"concatv",
"(",
"self",
".",
"choosers_columns_used",
"(",
")",
",",
"self",
".",
"alts_columns_used",
"(",
")",
",",
"self",
".",
"interaction_colu... | Columns from any table used in the model. May come from either
the choosers or alternatives tables. | [
"Columns",
"from",
"any",
"table",
"used",
"in",
"the",
"model",
".",
"May",
"come",
"from",
"either",
"the",
"choosers",
"or",
"alternatives",
"tables",
"."
] | train | https://github.com/UDST/urbansim/blob/79f815a6503e109f50be270cee92d0f4a34f49ef/urbansim/models/dcm.py#L741-L750 |
UDST/urbansim | urbansim/models/dcm.py | MNLDiscreteChoiceModel.fit_from_cfg | def fit_from_cfg(cls, choosers, chosen_fname, alternatives, cfgname, outcfgname=None):
"""
Parameters
----------
choosers : DataFrame
A dataframe in which rows represent choosers.
chosen_fname : string
A string indicating the column in the choosers datafra... | python | def fit_from_cfg(cls, choosers, chosen_fname, alternatives, cfgname, outcfgname=None):
"""
Parameters
----------
choosers : DataFrame
A dataframe in which rows represent choosers.
chosen_fname : string
A string indicating the column in the choosers datafra... | [
"def",
"fit_from_cfg",
"(",
"cls",
",",
"choosers",
",",
"chosen_fname",
",",
"alternatives",
",",
"cfgname",
",",
"outcfgname",
"=",
"None",
")",
":",
"logger",
".",
"debug",
"(",
"'start: fit from configuration {}'",
".",
"format",
"(",
"cfgname",
")",
")",
... | Parameters
----------
choosers : DataFrame
A dataframe in which rows represent choosers.
chosen_fname : string
A string indicating the column in the choosers dataframe which
gives which alternatives the choosers have chosen.
alternatives : DataFrame
... | [
"Parameters",
"----------",
"choosers",
":",
"DataFrame",
"A",
"dataframe",
"in",
"which",
"rows",
"represent",
"choosers",
".",
"chosen_fname",
":",
"string",
"A",
"string",
"indicating",
"the",
"column",
"in",
"the",
"choosers",
"dataframe",
"which",
"gives",
... | train | https://github.com/UDST/urbansim/blob/79f815a6503e109f50be270cee92d0f4a34f49ef/urbansim/models/dcm.py#L753-L784 |
UDST/urbansim | urbansim/models/dcm.py | MNLDiscreteChoiceModel.predict_from_cfg | def predict_from_cfg(cls, choosers, alternatives, cfgname=None, cfg=None,
alternative_ratio=2.0, debug=False):
"""
Simulate choices for the specified choosers
Parameters
----------
choosers : DataFrame
A dataframe of agents doing the choosing... | python | def predict_from_cfg(cls, choosers, alternatives, cfgname=None, cfg=None,
alternative_ratio=2.0, debug=False):
"""
Simulate choices for the specified choosers
Parameters
----------
choosers : DataFrame
A dataframe of agents doing the choosing... | [
"def",
"predict_from_cfg",
"(",
"cls",
",",
"choosers",
",",
"alternatives",
",",
"cfgname",
"=",
"None",
",",
"cfg",
"=",
"None",
",",
"alternative_ratio",
"=",
"2.0",
",",
"debug",
"=",
"False",
")",
":",
"logger",
".",
"debug",
"(",
"'start: predict fro... | Simulate choices for the specified choosers
Parameters
----------
choosers : DataFrame
A dataframe of agents doing the choosing.
alternatives : DataFrame
A dataframe of locations which the choosers are locating in and
which have a supply.
cfgn... | [
"Simulate",
"choices",
"for",
"the",
"specified",
"choosers"
] | train | https://github.com/UDST/urbansim/blob/79f815a6503e109f50be270cee92d0f4a34f49ef/urbansim/models/dcm.py#L787-L847 |
UDST/urbansim | urbansim/models/dcm.py | MNLDiscreteChoiceModelGroup.add_model_from_params | def add_model_from_params(
self, name, model_expression, sample_size,
probability_mode='full_product', choice_mode='individual',
choosers_fit_filters=None, choosers_predict_filters=None,
alts_fit_filters=None, alts_predict_filters=None,
interaction_predict_fil... | python | def add_model_from_params(
self, name, model_expression, sample_size,
probability_mode='full_product', choice_mode='individual',
choosers_fit_filters=None, choosers_predict_filters=None,
alts_fit_filters=None, alts_predict_filters=None,
interaction_predict_fil... | [
"def",
"add_model_from_params",
"(",
"self",
",",
"name",
",",
"model_expression",
",",
"sample_size",
",",
"probability_mode",
"=",
"'full_product'",
",",
"choice_mode",
"=",
"'individual'",
",",
"choosers_fit_filters",
"=",
"None",
",",
"choosers_predict_filters",
"... | Add a model by passing parameters through to MNLDiscreteChoiceModel.
Parameters
----------
name
Must match a segment in the choosers table.
model_expression : str, iterable, or dict
A patsy model expression. Should contain only a right-hand side.
sample_s... | [
"Add",
"a",
"model",
"by",
"passing",
"parameters",
"through",
"to",
"MNLDiscreteChoiceModel",
"."
] | train | https://github.com/UDST/urbansim/blob/79f815a6503e109f50be270cee92d0f4a34f49ef/urbansim/models/dcm.py#L893-L960 |
UDST/urbansim | urbansim/models/dcm.py | MNLDiscreteChoiceModelGroup._iter_groups | def _iter_groups(self, data):
"""
Iterate over the groups in `data` after grouping by
`segmentation_col`. Skips any groups for which there
is no model stored.
Yields tuples of (name, df) where name is the group key
and df is the group DataFrame.
Parameters
... | python | def _iter_groups(self, data):
"""
Iterate over the groups in `data` after grouping by
`segmentation_col`. Skips any groups for which there
is no model stored.
Yields tuples of (name, df) where name is the group key
and df is the group DataFrame.
Parameters
... | [
"def",
"_iter_groups",
"(",
"self",
",",
"data",
")",
":",
"groups",
"=",
"data",
".",
"groupby",
"(",
"self",
".",
"segmentation_col",
")",
"for",
"name",
",",
"group",
"in",
"groups",
":",
"if",
"name",
"not",
"in",
"self",
".",
"models",
":",
"con... | Iterate over the groups in `data` after grouping by
`segmentation_col`. Skips any groups for which there
is no model stored.
Yields tuples of (name, df) where name is the group key
and df is the group DataFrame.
Parameters
----------
data : pandas.DataFrame
... | [
"Iterate",
"over",
"the",
"groups",
"in",
"data",
"after",
"grouping",
"by",
"segmentation_col",
".",
"Skips",
"any",
"groups",
"for",
"which",
"there",
"is",
"no",
"model",
"stored",
"."
] | train | https://github.com/UDST/urbansim/blob/79f815a6503e109f50be270cee92d0f4a34f49ef/urbansim/models/dcm.py#L962-L984 |
UDST/urbansim | urbansim/models/dcm.py | MNLDiscreteChoiceModelGroup.apply_fit_filters | def apply_fit_filters(self, choosers, alternatives):
"""
Filter `choosers` and `alternatives` for fitting.
This is done by filtering each submodel and concatenating
the results.
Parameters
----------
choosers : pandas.DataFrame
Table describing the ag... | python | def apply_fit_filters(self, choosers, alternatives):
"""
Filter `choosers` and `alternatives` for fitting.
This is done by filtering each submodel and concatenating
the results.
Parameters
----------
choosers : pandas.DataFrame
Table describing the ag... | [
"def",
"apply_fit_filters",
"(",
"self",
",",
"choosers",
",",
"alternatives",
")",
":",
"ch",
"=",
"[",
"]",
"alts",
"=",
"[",
"]",
"for",
"name",
",",
"df",
"in",
"self",
".",
"_iter_groups",
"(",
"choosers",
")",
":",
"filtered_choosers",
",",
"filt... | Filter `choosers` and `alternatives` for fitting.
This is done by filtering each submodel and concatenating
the results.
Parameters
----------
choosers : pandas.DataFrame
Table describing the agents making choices, e.g. households.
alternatives : pandas.DataF... | [
"Filter",
"choosers",
"and",
"alternatives",
"for",
"fitting",
".",
"This",
"is",
"done",
"by",
"filtering",
"each",
"submodel",
"and",
"concatenating",
"the",
"results",
"."
] | train | https://github.com/UDST/urbansim/blob/79f815a6503e109f50be270cee92d0f4a34f49ef/urbansim/models/dcm.py#L986-L1014 |
UDST/urbansim | urbansim/models/dcm.py | MNLDiscreteChoiceModelGroup.fit | def fit(self, choosers, alternatives, current_choice):
"""
Fit and save models based on given data after segmenting
the `choosers` table.
Parameters
----------
choosers : pandas.DataFrame
Table describing the agents making choices, e.g. households.
... | python | def fit(self, choosers, alternatives, current_choice):
"""
Fit and save models based on given data after segmenting
the `choosers` table.
Parameters
----------
choosers : pandas.DataFrame
Table describing the agents making choices, e.g. households.
... | [
"def",
"fit",
"(",
"self",
",",
"choosers",
",",
"alternatives",
",",
"current_choice",
")",
":",
"with",
"log_start_finish",
"(",
"'fit models in LCM group {}'",
".",
"format",
"(",
"self",
".",
"name",
")",
",",
"logger",
")",
":",
"return",
"{",
"name",
... | Fit and save models based on given data after segmenting
the `choosers` table.
Parameters
----------
choosers : pandas.DataFrame
Table describing the agents making choices, e.g. households.
Must have a column with the same name as the .segmentation_col
... | [
"Fit",
"and",
"save",
"models",
"based",
"on",
"given",
"data",
"after",
"segmenting",
"the",
"choosers",
"table",
"."
] | train | https://github.com/UDST/urbansim/blob/79f815a6503e109f50be270cee92d0f4a34f49ef/urbansim/models/dcm.py#L1049-L1078 |
UDST/urbansim | urbansim/models/dcm.py | MNLDiscreteChoiceModelGroup.fitted | def fitted(self):
"""
Whether all models in the group have been fitted.
"""
return (all(m.fitted for m in self.models.values())
if self.models else False) | python | def fitted(self):
"""
Whether all models in the group have been fitted.
"""
return (all(m.fitted for m in self.models.values())
if self.models else False) | [
"def",
"fitted",
"(",
"self",
")",
":",
"return",
"(",
"all",
"(",
"m",
".",
"fitted",
"for",
"m",
"in",
"self",
".",
"models",
".",
"values",
"(",
")",
")",
"if",
"self",
".",
"models",
"else",
"False",
")"
] | Whether all models in the group have been fitted. | [
"Whether",
"all",
"models",
"in",
"the",
"group",
"have",
"been",
"fitted",
"."
] | train | https://github.com/UDST/urbansim/blob/79f815a6503e109f50be270cee92d0f4a34f49ef/urbansim/models/dcm.py#L1081-L1087 |
UDST/urbansim | urbansim/models/dcm.py | MNLDiscreteChoiceModelGroup.probabilities | def probabilities(self, choosers, alternatives):
"""
Returns alternative probabilties for each chooser segment as
a dictionary keyed by segment name.
Parameters
----------
choosers : pandas.DataFrame
Table describing the agents making choices, e.g. households... | python | def probabilities(self, choosers, alternatives):
"""
Returns alternative probabilties for each chooser segment as
a dictionary keyed by segment name.
Parameters
----------
choosers : pandas.DataFrame
Table describing the agents making choices, e.g. households... | [
"def",
"probabilities",
"(",
"self",
",",
"choosers",
",",
"alternatives",
")",
":",
"logger",
".",
"debug",
"(",
"'start: calculate probabilities in LCM group {}'",
".",
"format",
"(",
"self",
".",
"name",
")",
")",
"probs",
"=",
"{",
"}",
"for",
"name",
",... | Returns alternative probabilties for each chooser segment as
a dictionary keyed by segment name.
Parameters
----------
choosers : pandas.DataFrame
Table describing the agents making choices, e.g. households.
Must have a column matching the .segmentation_col attri... | [
"Returns",
"alternative",
"probabilties",
"for",
"each",
"chooser",
"segment",
"as",
"a",
"dictionary",
"keyed",
"by",
"segment",
"name",
"."
] | train | https://github.com/UDST/urbansim/blob/79f815a6503e109f50be270cee92d0f4a34f49ef/urbansim/models/dcm.py#L1089-L1117 |
UDST/urbansim | urbansim/models/dcm.py | MNLDiscreteChoiceModelGroup.summed_probabilities | def summed_probabilities(self, choosers, alternatives):
"""
Returns the sum of probabilities for alternatives across all
chooser segments.
Parameters
----------
choosers : pandas.DataFrame
Table describing the agents making choices, e.g. households.
... | python | def summed_probabilities(self, choosers, alternatives):
"""
Returns the sum of probabilities for alternatives across all
chooser segments.
Parameters
----------
choosers : pandas.DataFrame
Table describing the agents making choices, e.g. households.
... | [
"def",
"summed_probabilities",
"(",
"self",
",",
"choosers",
",",
"alternatives",
")",
":",
"if",
"len",
"(",
"alternatives",
")",
"==",
"0",
"or",
"len",
"(",
"choosers",
")",
"==",
"0",
":",
"return",
"pd",
".",
"Series",
"(",
")",
"logger",
".",
"... | Returns the sum of probabilities for alternatives across all
chooser segments.
Parameters
----------
choosers : pandas.DataFrame
Table describing the agents making choices, e.g. households.
Must have a column matching the .segmentation_col attribute.
alte... | [
"Returns",
"the",
"sum",
"of",
"probabilities",
"for",
"alternatives",
"across",
"all",
"chooser",
"segments",
"."
] | train | https://github.com/UDST/urbansim/blob/79f815a6503e109f50be270cee92d0f4a34f49ef/urbansim/models/dcm.py#L1119-L1156 |
UDST/urbansim | urbansim/models/dcm.py | MNLDiscreteChoiceModelGroup.predict | def predict(self, choosers, alternatives, debug=False):
"""
Choose from among alternatives for a group of agents after
segmenting the `choosers` table.
Parameters
----------
choosers : pandas.DataFrame
Table describing the agents making choices, e.g. househol... | python | def predict(self, choosers, alternatives, debug=False):
"""
Choose from among alternatives for a group of agents after
segmenting the `choosers` table.
Parameters
----------
choosers : pandas.DataFrame
Table describing the agents making choices, e.g. househol... | [
"def",
"predict",
"(",
"self",
",",
"choosers",
",",
"alternatives",
",",
"debug",
"=",
"False",
")",
":",
"logger",
".",
"debug",
"(",
"'start: predict models in LCM group {}'",
".",
"format",
"(",
"self",
".",
"name",
")",
")",
"results",
"=",
"[",
"]",
... | Choose from among alternatives for a group of agents after
segmenting the `choosers` table.
Parameters
----------
choosers : pandas.DataFrame
Table describing the agents making choices, e.g. households.
Must have a column matching the .segmentation_col attribute.... | [
"Choose",
"from",
"among",
"alternatives",
"for",
"a",
"group",
"of",
"agents",
"after",
"segmenting",
"the",
"choosers",
"table",
"."
] | train | https://github.com/UDST/urbansim/blob/79f815a6503e109f50be270cee92d0f4a34f49ef/urbansim/models/dcm.py#L1158-L1195 |
UDST/urbansim | urbansim/models/dcm.py | MNLDiscreteChoiceModelGroup.alts_columns_used | def alts_columns_used(self):
"""
Columns from the alternatives table that are used for filtering.
"""
return list(tz.unique(tz.concat(
m.alts_columns_used() for m in self.models.values()))) | python | def alts_columns_used(self):
"""
Columns from the alternatives table that are used for filtering.
"""
return list(tz.unique(tz.concat(
m.alts_columns_used() for m in self.models.values()))) | [
"def",
"alts_columns_used",
"(",
"self",
")",
":",
"return",
"list",
"(",
"tz",
".",
"unique",
"(",
"tz",
".",
"concat",
"(",
"m",
".",
"alts_columns_used",
"(",
")",
"for",
"m",
"in",
"self",
".",
"models",
".",
"values",
"(",
")",
")",
")",
")"
] | Columns from the alternatives table that are used for filtering. | [
"Columns",
"from",
"the",
"alternatives",
"table",
"that",
"are",
"used",
"for",
"filtering",
"."
] | train | https://github.com/UDST/urbansim/blob/79f815a6503e109f50be270cee92d0f4a34f49ef/urbansim/models/dcm.py#L1205-L1211 |
UDST/urbansim | urbansim/models/dcm.py | SegmentedMNLDiscreteChoiceModel.from_yaml | def from_yaml(cls, yaml_str=None, str_or_buffer=None):
"""
Create a SegmentedMNLDiscreteChoiceModel instance from a saved YAML
configuration. Arguments are mutally exclusive.
Parameters
----------
yaml_str : str, optional
A YAML string from which to load mode... | python | def from_yaml(cls, yaml_str=None, str_or_buffer=None):
"""
Create a SegmentedMNLDiscreteChoiceModel instance from a saved YAML
configuration. Arguments are mutally exclusive.
Parameters
----------
yaml_str : str, optional
A YAML string from which to load mode... | [
"def",
"from_yaml",
"(",
"cls",
",",
"yaml_str",
"=",
"None",
",",
"str_or_buffer",
"=",
"None",
")",
":",
"cfg",
"=",
"yamlio",
".",
"yaml_to_dict",
"(",
"yaml_str",
",",
"str_or_buffer",
")",
"default_model_expr",
"=",
"cfg",
"[",
"'default_config'",
"]",
... | Create a SegmentedMNLDiscreteChoiceModel instance from a saved YAML
configuration. Arguments are mutally exclusive.
Parameters
----------
yaml_str : str, optional
A YAML string from which to load model.
str_or_buffer : str or file like, optional
File name... | [
"Create",
"a",
"SegmentedMNLDiscreteChoiceModel",
"instance",
"from",
"a",
"saved",
"YAML",
"configuration",
".",
"Arguments",
"are",
"mutally",
"exclusive",
"."
] | train | https://github.com/UDST/urbansim/blob/79f815a6503e109f50be270cee92d0f4a34f49ef/urbansim/models/dcm.py#L1334-L1397 |
UDST/urbansim | urbansim/models/dcm.py | SegmentedMNLDiscreteChoiceModel.add_segment | def add_segment(self, name, model_expression=None):
"""
Add a new segment with its own model expression.
Parameters
----------
name
Segment name. Must match a segment in the groupby of the data.
model_expression : str or dict, optional
A patsy mod... | python | def add_segment(self, name, model_expression=None):
"""
Add a new segment with its own model expression.
Parameters
----------
name
Segment name. Must match a segment in the groupby of the data.
model_expression : str or dict, optional
A patsy mod... | [
"def",
"add_segment",
"(",
"self",
",",
"name",
",",
"model_expression",
"=",
"None",
")",
":",
"logger",
".",
"debug",
"(",
"'adding LCM model {} to segmented model {}'",
".",
"format",
"(",
"name",
",",
"self",
".",
"name",
")",
")",
"if",
"not",
"model_ex... | Add a new segment with its own model expression.
Parameters
----------
name
Segment name. Must match a segment in the groupby of the data.
model_expression : str or dict, optional
A patsy model expression that can be used with statsmodels.
Should cont... | [
"Add",
"a",
"new",
"segment",
"with",
"its",
"own",
"model",
"expression",
"."
] | train | https://github.com/UDST/urbansim/blob/79f815a6503e109f50be270cee92d0f4a34f49ef/urbansim/models/dcm.py#L1399-L1437 |
UDST/urbansim | urbansim/models/dcm.py | SegmentedMNLDiscreteChoiceModel.apply_fit_filters | def apply_fit_filters(self, choosers, alternatives):
"""
Filter `choosers` and `alternatives` for fitting.
Parameters
----------
choosers : pandas.DataFrame
Table describing the agents making choices, e.g. households.
alternatives : pandas.DataFrame
... | python | def apply_fit_filters(self, choosers, alternatives):
"""
Filter `choosers` and `alternatives` for fitting.
Parameters
----------
choosers : pandas.DataFrame
Table describing the agents making choices, e.g. households.
alternatives : pandas.DataFrame
... | [
"def",
"apply_fit_filters",
"(",
"self",
",",
"choosers",
",",
"alternatives",
")",
":",
"return",
"super",
"(",
"SegmentedMNLDiscreteChoiceModel",
",",
"self",
")",
".",
"apply_fit_filters",
"(",
"choosers",
",",
"alternatives",
")"
] | Filter `choosers` and `alternatives` for fitting.
Parameters
----------
choosers : pandas.DataFrame
Table describing the agents making choices, e.g. households.
alternatives : pandas.DataFrame
Table describing the things from which agents are choosing,
... | [
"Filter",
"choosers",
"and",
"alternatives",
"for",
"fitting",
"."
] | train | https://github.com/UDST/urbansim/blob/79f815a6503e109f50be270cee92d0f4a34f49ef/urbansim/models/dcm.py#L1439-L1457 |
UDST/urbansim | urbansim/models/dcm.py | SegmentedMNLDiscreteChoiceModel.apply_predict_filters | def apply_predict_filters(self, choosers, alternatives):
"""
Filter `choosers` and `alternatives` for prediction.
Parameters
----------
choosers : pandas.DataFrame
Table describing the agents making choices, e.g. households.
alternatives : pandas.DataFrame
... | python | def apply_predict_filters(self, choosers, alternatives):
"""
Filter `choosers` and `alternatives` for prediction.
Parameters
----------
choosers : pandas.DataFrame
Table describing the agents making choices, e.g. households.
alternatives : pandas.DataFrame
... | [
"def",
"apply_predict_filters",
"(",
"self",
",",
"choosers",
",",
"alternatives",
")",
":",
"return",
"super",
"(",
"SegmentedMNLDiscreteChoiceModel",
",",
"self",
")",
".",
"apply_predict_filters",
"(",
"choosers",
",",
"alternatives",
")"
] | Filter `choosers` and `alternatives` for prediction.
Parameters
----------
choosers : pandas.DataFrame
Table describing the agents making choices, e.g. households.
alternatives : pandas.DataFrame
Table describing the things from which agents are choosing,
... | [
"Filter",
"choosers",
"and",
"alternatives",
"for",
"prediction",
"."
] | train | https://github.com/UDST/urbansim/blob/79f815a6503e109f50be270cee92d0f4a34f49ef/urbansim/models/dcm.py#L1459-L1478 |
UDST/urbansim | urbansim/models/dcm.py | SegmentedMNLDiscreteChoiceModel.fit | def fit(self, choosers, alternatives, current_choice):
"""
Fit and save models based on given data after segmenting
the `choosers` table. Segments that have not already been explicitly
added will be automatically added with default model.
Parameters
----------
ch... | python | def fit(self, choosers, alternatives, current_choice):
"""
Fit and save models based on given data after segmenting
the `choosers` table. Segments that have not already been explicitly
added will be automatically added with default model.
Parameters
----------
ch... | [
"def",
"fit",
"(",
"self",
",",
"choosers",
",",
"alternatives",
",",
"current_choice",
")",
":",
"logger",
".",
"debug",
"(",
"'start: fit models in segmented LCM {}'",
".",
"format",
"(",
"self",
".",
"name",
")",
")",
"choosers",
",",
"alternatives",
"=",
... | Fit and save models based on given data after segmenting
the `choosers` table. Segments that have not already been explicitly
added will be automatically added with default model.
Parameters
----------
choosers : pandas.DataFrame
Table describing the agents making ch... | [
"Fit",
"and",
"save",
"models",
"based",
"on",
"given",
"data",
"after",
"segmenting",
"the",
"choosers",
"table",
".",
"Segments",
"that",
"have",
"not",
"already",
"been",
"explicitly",
"added",
"will",
"be",
"automatically",
"added",
"with",
"default",
"mod... | train | https://github.com/UDST/urbansim/blob/79f815a6503e109f50be270cee92d0f4a34f49ef/urbansim/models/dcm.py#L1480-L1526 |
UDST/urbansim | urbansim/models/dcm.py | SegmentedMNLDiscreteChoiceModel._filter_choosers_alts | def _filter_choosers_alts(self, choosers, alternatives):
"""
Apply filters to the choosers and alts tables.
"""
return (
util.apply_filter_query(
choosers, self.choosers_predict_filters),
util.apply_filter_query(
alternatives, self... | python | def _filter_choosers_alts(self, choosers, alternatives):
"""
Apply filters to the choosers and alts tables.
"""
return (
util.apply_filter_query(
choosers, self.choosers_predict_filters),
util.apply_filter_query(
alternatives, self... | [
"def",
"_filter_choosers_alts",
"(",
"self",
",",
"choosers",
",",
"alternatives",
")",
":",
"return",
"(",
"util",
".",
"apply_filter_query",
"(",
"choosers",
",",
"self",
".",
"choosers_predict_filters",
")",
",",
"util",
".",
"apply_filter_query",
"(",
"alter... | Apply filters to the choosers and alts tables. | [
"Apply",
"filters",
"to",
"the",
"choosers",
"and",
"alts",
"tables",
"."
] | train | https://github.com/UDST/urbansim/blob/79f815a6503e109f50be270cee92d0f4a34f49ef/urbansim/models/dcm.py#L1536-L1545 |
UDST/urbansim | urbansim/models/dcm.py | SegmentedMNLDiscreteChoiceModel.probabilities | def probabilities(self, choosers, alternatives):
"""
Returns alternative probabilties for each chooser segment as
a dictionary keyed by segment name.
Parameters
----------
choosers : pandas.DataFrame
Table describing the agents making choices, e.g. households... | python | def probabilities(self, choosers, alternatives):
"""
Returns alternative probabilties for each chooser segment as
a dictionary keyed by segment name.
Parameters
----------
choosers : pandas.DataFrame
Table describing the agents making choices, e.g. households... | [
"def",
"probabilities",
"(",
"self",
",",
"choosers",
",",
"alternatives",
")",
":",
"logger",
".",
"debug",
"(",
"'start: calculate probabilities in segmented LCM {}'",
".",
"format",
"(",
"self",
".",
"name",
")",
")",
"choosers",
",",
"alternatives",
"=",
"se... | Returns alternative probabilties for each chooser segment as
a dictionary keyed by segment name.
Parameters
----------
choosers : pandas.DataFrame
Table describing the agents making choices, e.g. households.
Must have a column matching the .segmentation_col attri... | [
"Returns",
"alternative",
"probabilties",
"for",
"each",
"chooser",
"segment",
"as",
"a",
"dictionary",
"keyed",
"by",
"segment",
"name",
"."
] | train | https://github.com/UDST/urbansim/blob/79f815a6503e109f50be270cee92d0f4a34f49ef/urbansim/models/dcm.py#L1547-L1574 |
UDST/urbansim | urbansim/models/dcm.py | SegmentedMNLDiscreteChoiceModel.predict | def predict(self, choosers, alternatives, debug=False):
"""
Choose from among alternatives for a group of agents after
segmenting the `choosers` table.
Parameters
----------
choosers : pandas.DataFrame
Table describing the agents making choices, e.g. househol... | python | def predict(self, choosers, alternatives, debug=False):
"""
Choose from among alternatives for a group of agents after
segmenting the `choosers` table.
Parameters
----------
choosers : pandas.DataFrame
Table describing the agents making choices, e.g. househol... | [
"def",
"predict",
"(",
"self",
",",
"choosers",
",",
"alternatives",
",",
"debug",
"=",
"False",
")",
":",
"logger",
".",
"debug",
"(",
"'start: predict models in segmented LCM {}'",
".",
"format",
"(",
"self",
".",
"name",
")",
")",
"choosers",
",",
"altern... | Choose from among alternatives for a group of agents after
segmenting the `choosers` table.
Parameters
----------
choosers : pandas.DataFrame
Table describing the agents making choices, e.g. households.
Must have a column matching the .segmentation_col attribute.... | [
"Choose",
"from",
"among",
"alternatives",
"for",
"a",
"group",
"of",
"agents",
"after",
"segmenting",
"the",
"choosers",
"table",
"."
] | train | https://github.com/UDST/urbansim/blob/79f815a6503e109f50be270cee92d0f4a34f49ef/urbansim/models/dcm.py#L1606-L1639 |
UDST/urbansim | urbansim/models/dcm.py | SegmentedMNLDiscreteChoiceModel._process_model_dict | def _process_model_dict(self, d):
"""
Remove redundant items from a model's configuration dict.
Parameters
----------
d : dict
Modified in place.
Returns
-------
dict
Modified `d`.
"""
del d['model_type']
... | python | def _process_model_dict(self, d):
"""
Remove redundant items from a model's configuration dict.
Parameters
----------
d : dict
Modified in place.
Returns
-------
dict
Modified `d`.
"""
del d['model_type']
... | [
"def",
"_process_model_dict",
"(",
"self",
",",
"d",
")",
":",
"del",
"d",
"[",
"'model_type'",
"]",
"del",
"d",
"[",
"'sample_size'",
"]",
"del",
"d",
"[",
"'probability_mode'",
"]",
"del",
"d",
"[",
"'choice_mode'",
"]",
"del",
"d",
"[",
"'choosers_fit... | Remove redundant items from a model's configuration dict.
Parameters
----------
d : dict
Modified in place.
Returns
-------
dict
Modified `d`. | [
"Remove",
"redundant",
"items",
"from",
"a",
"model",
"s",
"configuration",
"dict",
"."
] | train | https://github.com/UDST/urbansim/blob/79f815a6503e109f50be270cee92d0f4a34f49ef/urbansim/models/dcm.py#L1641-L1674 |
UDST/urbansim | urbansim/models/dcm.py | SegmentedMNLDiscreteChoiceModel.to_dict | def to_dict(self):
"""
Returns a dict representation of this instance suitable for
conversion to YAML.
"""
return {
'model_type': 'segmented_discretechoice',
'name': self.name,
'segmentation_col': self.segmentation_col,
'sample_siz... | python | def to_dict(self):
"""
Returns a dict representation of this instance suitable for
conversion to YAML.
"""
return {
'model_type': 'segmented_discretechoice',
'name': self.name,
'segmentation_col': self.segmentation_col,
'sample_siz... | [
"def",
"to_dict",
"(",
"self",
")",
":",
"return",
"{",
"'model_type'",
":",
"'segmented_discretechoice'",
",",
"'name'",
":",
"self",
".",
"name",
",",
"'segmentation_col'",
":",
"self",
".",
"segmentation_col",
",",
"'sample_size'",
":",
"self",
".",
"sample... | Returns a dict representation of this instance suitable for
conversion to YAML. | [
"Returns",
"a",
"dict",
"representation",
"of",
"this",
"instance",
"suitable",
"for",
"conversion",
"to",
"YAML",
"."
] | train | https://github.com/UDST/urbansim/blob/79f815a6503e109f50be270cee92d0f4a34f49ef/urbansim/models/dcm.py#L1676-L1707 |
UDST/urbansim | urbansim/models/dcm.py | SegmentedMNLDiscreteChoiceModel.to_yaml | def to_yaml(self, str_or_buffer=None):
"""
Save a model respresentation to YAML.
Parameters
----------
str_or_buffer : str or file like, optional
By default a YAML string is returned. If a string is
given here the YAML will be written to that file.
... | python | def to_yaml(self, str_or_buffer=None):
"""
Save a model respresentation to YAML.
Parameters
----------
str_or_buffer : str or file like, optional
By default a YAML string is returned. If a string is
given here the YAML will be written to that file.
... | [
"def",
"to_yaml",
"(",
"self",
",",
"str_or_buffer",
"=",
"None",
")",
":",
"logger",
".",
"debug",
"(",
"'serializing segmented LCM {} to YAML'",
".",
"format",
"(",
"self",
".",
"name",
")",
")",
"return",
"yamlio",
".",
"convert_to_yaml",
"(",
"self",
"."... | Save a model respresentation to YAML.
Parameters
----------
str_or_buffer : str or file like, optional
By default a YAML string is returned. If a string is
given here the YAML will be written to that file.
If an object with a ``.write`` method is given the
... | [
"Save",
"a",
"model",
"respresentation",
"to",
"YAML",
"."
] | train | https://github.com/UDST/urbansim/blob/79f815a6503e109f50be270cee92d0f4a34f49ef/urbansim/models/dcm.py#L1709-L1728 |
UDST/urbansim | urbansim/models/dcm.py | SegmentedMNLDiscreteChoiceModel.columns_used | def columns_used(self):
"""
Columns from any table used in the model. May come from either
the choosers or alternatives tables.
"""
return list(tz.unique(tz.concatv(
self.choosers_columns_used(),
self.alts_columns_used(),
self.interaction_colu... | python | def columns_used(self):
"""
Columns from any table used in the model. May come from either
the choosers or alternatives tables.
"""
return list(tz.unique(tz.concatv(
self.choosers_columns_used(),
self.alts_columns_used(),
self.interaction_colu... | [
"def",
"columns_used",
"(",
"self",
")",
":",
"return",
"list",
"(",
"tz",
".",
"unique",
"(",
"tz",
".",
"concatv",
"(",
"self",
".",
"choosers_columns_used",
"(",
")",
",",
"self",
".",
"alts_columns_used",
"(",
")",
",",
"self",
".",
"interaction_colu... | Columns from any table used in the model. May come from either
the choosers or alternatives tables. | [
"Columns",
"from",
"any",
"table",
"used",
"in",
"the",
"model",
".",
"May",
"come",
"from",
"either",
"the",
"choosers",
"or",
"alternatives",
"tables",
"."
] | train | https://github.com/UDST/urbansim/blob/79f815a6503e109f50be270cee92d0f4a34f49ef/urbansim/models/dcm.py#L1757-L1768 |
UDST/urbansim | urbansim/models/dcm.py | SegmentedMNLDiscreteChoiceModel.fit_from_cfg | def fit_from_cfg(cls, choosers, chosen_fname, alternatives, cfgname, outcfgname=None):
"""
Parameters
----------
choosers : DataFrame
A dataframe of rows of agents that have made choices.
chosen_fname : string
A string indicating the column in the choosers... | python | def fit_from_cfg(cls, choosers, chosen_fname, alternatives, cfgname, outcfgname=None):
"""
Parameters
----------
choosers : DataFrame
A dataframe of rows of agents that have made choices.
chosen_fname : string
A string indicating the column in the choosers... | [
"def",
"fit_from_cfg",
"(",
"cls",
",",
"choosers",
",",
"chosen_fname",
",",
"alternatives",
",",
"cfgname",
",",
"outcfgname",
"=",
"None",
")",
":",
"logger",
".",
"debug",
"(",
"'start: fit from configuration {}'",
".",
"format",
"(",
"cfgname",
")",
")",
... | Parameters
----------
choosers : DataFrame
A dataframe of rows of agents that have made choices.
chosen_fname : string
A string indicating the column in the choosers dataframe which
gives which alternative the choosers have chosen.
alternatives : DataF... | [
"Parameters",
"----------",
"choosers",
":",
"DataFrame",
"A",
"dataframe",
"of",
"rows",
"of",
"agents",
"that",
"have",
"made",
"choices",
".",
"chosen_fname",
":",
"string",
"A",
"string",
"indicating",
"the",
"column",
"in",
"the",
"choosers",
"dataframe",
... | train | https://github.com/UDST/urbansim/blob/79f815a6503e109f50be270cee92d0f4a34f49ef/urbansim/models/dcm.py#L1771-L1804 |
UDST/urbansim | scripts/cache_to_hdf5.py | cache_to_df | def cache_to_df(dir_path):
"""
Convert a directory of binary array data files to a Pandas DataFrame.
Parameters
----------
dir_path : str
"""
table = {}
for attrib in glob.glob(os.path.join(dir_path, '*')):
attrib_name, attrib_ext = os.path.splitext(os.path.basename(attrib))
... | python | def cache_to_df(dir_path):
"""
Convert a directory of binary array data files to a Pandas DataFrame.
Parameters
----------
dir_path : str
"""
table = {}
for attrib in glob.glob(os.path.join(dir_path, '*')):
attrib_name, attrib_ext = os.path.splitext(os.path.basename(attrib))
... | [
"def",
"cache_to_df",
"(",
"dir_path",
")",
":",
"table",
"=",
"{",
"}",
"for",
"attrib",
"in",
"glob",
".",
"glob",
"(",
"os",
".",
"path",
".",
"join",
"(",
"dir_path",
",",
"'*'",
")",
")",
":",
"attrib_name",
",",
"attrib_ext",
"=",
"os",
".",
... | Convert a directory of binary array data files to a Pandas DataFrame.
Parameters
----------
dir_path : str | [
"Convert",
"a",
"directory",
"of",
"binary",
"array",
"data",
"files",
"to",
"a",
"Pandas",
"DataFrame",
"."
] | train | https://github.com/UDST/urbansim/blob/79f815a6503e109f50be270cee92d0f4a34f49ef/scripts/cache_to_hdf5.py#L14-L60 |
UDST/urbansim | scripts/cache_to_hdf5.py | convert_dirs | def convert_dirs(base_dir, hdf_name, complib=None, complevel=0):
"""
Convert nested set of directories to
"""
print('Converting directories in {}'.format(base_dir))
dirs = glob.glob(os.path.join(base_dir, '*'))
dirs = {d for d in dirs if os.path.basename(d) in DIRECTORIES}
if not dirs:
... | python | def convert_dirs(base_dir, hdf_name, complib=None, complevel=0):
"""
Convert nested set of directories to
"""
print('Converting directories in {}'.format(base_dir))
dirs = glob.glob(os.path.join(base_dir, '*'))
dirs = {d for d in dirs if os.path.basename(d) in DIRECTORIES}
if not dirs:
... | [
"def",
"convert_dirs",
"(",
"base_dir",
",",
"hdf_name",
",",
"complib",
"=",
"None",
",",
"complevel",
"=",
"0",
")",
":",
"print",
"(",
"'Converting directories in {}'",
".",
"format",
"(",
"base_dir",
")",
")",
"dirs",
"=",
"glob",
".",
"glob",
"(",
"... | Convert nested set of directories to | [
"Convert",
"nested",
"set",
"of",
"directories",
"to"
] | train | https://github.com/UDST/urbansim/blob/79f815a6503e109f50be270cee92d0f4a34f49ef/scripts/cache_to_hdf5.py#L72-L130 |
UDST/urbansim | urbansim/utils/misc.py | get_run_number | def get_run_number():
"""
Get a run number for this execution of the model system, for
identifying the output hdf5 files).
Returns
-------
The integer number for this run of the model system.
"""
try:
f = open(os.path.join(os.getenv('DATA_HOME', "."), 'RUNNUM'), 'r')
num... | python | def get_run_number():
"""
Get a run number for this execution of the model system, for
identifying the output hdf5 files).
Returns
-------
The integer number for this run of the model system.
"""
try:
f = open(os.path.join(os.getenv('DATA_HOME', "."), 'RUNNUM'), 'r')
num... | [
"def",
"get_run_number",
"(",
")",
":",
"try",
":",
"f",
"=",
"open",
"(",
"os",
".",
"path",
".",
"join",
"(",
"os",
".",
"getenv",
"(",
"'DATA_HOME'",
",",
"\".\"",
")",
",",
"'RUNNUM'",
")",
",",
"'r'",
")",
"num",
"=",
"int",
"(",
"f",
".",... | Get a run number for this execution of the model system, for
identifying the output hdf5 files).
Returns
-------
The integer number for this run of the model system. | [
"Get",
"a",
"run",
"number",
"for",
"this",
"execution",
"of",
"the",
"model",
"system",
"for",
"identifying",
"the",
"output",
"hdf5",
"files",
")",
"."
] | train | https://github.com/UDST/urbansim/blob/79f815a6503e109f50be270cee92d0f4a34f49ef/urbansim/utils/misc.py#L97-L115 |
UDST/urbansim | urbansim/utils/misc.py | compute_range | def compute_range(travel_data, attr, travel_time_attr, dist, agg=np.sum):
"""
Compute a zone-based accessibility query using the urbansim format
travel data dataframe.
Parameters
----------
travel_data : dataframe
The dataframe of urbansim format travel data. Has from_zone_id as
... | python | def compute_range(travel_data, attr, travel_time_attr, dist, agg=np.sum):
"""
Compute a zone-based accessibility query using the urbansim format
travel data dataframe.
Parameters
----------
travel_data : dataframe
The dataframe of urbansim format travel data. Has from_zone_id as
... | [
"def",
"compute_range",
"(",
"travel_data",
",",
"attr",
",",
"travel_time_attr",
",",
"dist",
",",
"agg",
"=",
"np",
".",
"sum",
")",
":",
"travel_data",
"=",
"travel_data",
".",
"reset_index",
"(",
"level",
"=",
"1",
")",
"travel_data",
"=",
"travel_data... | Compute a zone-based accessibility query using the urbansim format
travel data dataframe.
Parameters
----------
travel_data : dataframe
The dataframe of urbansim format travel data. Has from_zone_id as
first index, to_zone_id as second index, and different impedances
between zo... | [
"Compute",
"a",
"zone",
"-",
"based",
"accessibility",
"query",
"using",
"the",
"urbansim",
"format",
"travel",
"data",
"dataframe",
"."
] | train | https://github.com/UDST/urbansim/blob/79f815a6503e109f50be270cee92d0f4a34f49ef/urbansim/utils/misc.py#L118-L142 |
UDST/urbansim | urbansim/utils/misc.py | reindex | def reindex(series1, series2):
"""
This reindexes the first series by the second series. This is an extremely
common operation that does not appear to be in Pandas at this time.
If anyone knows of an easier way to do this in Pandas, please inform the
UrbanSim developers.
The canonical example... | python | def reindex(series1, series2):
"""
This reindexes the first series by the second series. This is an extremely
common operation that does not appear to be in Pandas at this time.
If anyone knows of an easier way to do this in Pandas, please inform the
UrbanSim developers.
The canonical example... | [
"def",
"reindex",
"(",
"series1",
",",
"series2",
")",
":",
"# turns out the merge is much faster than the .loc below",
"df",
"=",
"pd",
".",
"merge",
"(",
"pd",
".",
"DataFrame",
"(",
"{",
"\"left\"",
":",
"series2",
"}",
")",
",",
"pd",
".",
"DataFrame",
"... | This reindexes the first series by the second series. This is an extremely
common operation that does not appear to be in Pandas at this time.
If anyone knows of an easier way to do this in Pandas, please inform the
UrbanSim developers.
The canonical example would be a parcel series which has an inde... | [
"This",
"reindexes",
"the",
"first",
"series",
"by",
"the",
"second",
"series",
".",
"This",
"is",
"an",
"extremely",
"common",
"operation",
"that",
"does",
"not",
"appear",
"to",
"be",
"in",
"Pandas",
"at",
"this",
"time",
".",
"If",
"anyone",
"knows",
... | train | https://github.com/UDST/urbansim/blob/79f815a6503e109f50be270cee92d0f4a34f49ef/urbansim/utils/misc.py#L145-L177 |
UDST/urbansim | urbansim/utils/misc.py | fidx | def fidx(right, left, left_fk=None):
"""
Re-indexes a series or data frame (right) to align with
another (left) series or data frame via foreign key relationship.
The index of the right must be unique.
This is similar to misc.reindex, but allows for data frame
re-indexes and supports re-indexin... | python | def fidx(right, left, left_fk=None):
"""
Re-indexes a series or data frame (right) to align with
another (left) series or data frame via foreign key relationship.
The index of the right must be unique.
This is similar to misc.reindex, but allows for data frame
re-indexes and supports re-indexin... | [
"def",
"fidx",
"(",
"right",
",",
"left",
",",
"left_fk",
"=",
"None",
")",
":",
"# ensure that we can align correctly",
"if",
"not",
"right",
".",
"index",
".",
"is_unique",
":",
"raise",
"ValueError",
"(",
"\"The right's index must be unique!\"",
")",
"# simpler... | Re-indexes a series or data frame (right) to align with
another (left) series or data frame via foreign key relationship.
The index of the right must be unique.
This is similar to misc.reindex, but allows for data frame
re-indexes and supports re-indexing data frames or
series with a multi-index.
... | [
"Re",
"-",
"indexes",
"a",
"series",
"or",
"data",
"frame",
"(",
"right",
")",
"to",
"align",
"with",
"another",
"(",
"left",
")",
"series",
"or",
"data",
"frame",
"via",
"foreign",
"key",
"relationship",
".",
"The",
"index",
"of",
"the",
"right",
"mus... | train | https://github.com/UDST/urbansim/blob/79f815a6503e109f50be270cee92d0f4a34f49ef/urbansim/utils/misc.py#L182-L244 |
UDST/urbansim | urbansim/utils/misc.py | numpymat2df | def numpymat2df(mat):
"""
Sometimes (though not very often) it is useful to convert a numpy matrix
which has no column names to a Pandas dataframe for use of the Pandas
functions. This method converts a 2D numpy matrix to Pandas dataframe
with default column headers.
Parameters
----------
... | python | def numpymat2df(mat):
"""
Sometimes (though not very often) it is useful to convert a numpy matrix
which has no column names to a Pandas dataframe for use of the Pandas
functions. This method converts a 2D numpy matrix to Pandas dataframe
with default column headers.
Parameters
----------
... | [
"def",
"numpymat2df",
"(",
"mat",
")",
":",
"return",
"pd",
".",
"DataFrame",
"(",
"dict",
"(",
"(",
"'x%d'",
"%",
"i",
",",
"mat",
"[",
":",
",",
"i",
"]",
")",
"for",
"i",
"in",
"range",
"(",
"mat",
".",
"shape",
"[",
"1",
"]",
")",
")",
... | Sometimes (though not very often) it is useful to convert a numpy matrix
which has no column names to a Pandas dataframe for use of the Pandas
functions. This method converts a 2D numpy matrix to Pandas dataframe
with default column headers.
Parameters
----------
mat : The numpy matrix
Re... | [
"Sometimes",
"(",
"though",
"not",
"very",
"often",
")",
"it",
"is",
"useful",
"to",
"convert",
"a",
"numpy",
"matrix",
"which",
"has",
"no",
"column",
"names",
"to",
"a",
"Pandas",
"dataframe",
"for",
"use",
"of",
"the",
"Pandas",
"functions",
".",
"Thi... | train | https://github.com/UDST/urbansim/blob/79f815a6503e109f50be270cee92d0f4a34f49ef/urbansim/utils/misc.py#L300-L317 |
UDST/urbansim | urbansim/utils/misc.py | df64bitto32bit | def df64bitto32bit(tbl):
"""
Convert a Pandas dataframe from 64 bit types to 32 bit types to save
memory or disk space.
Parameters
----------
tbl : The dataframe to convert
Returns
-------
The converted dataframe
"""
newtbl = pd.DataFrame(index=tbl.index)
for colname in... | python | def df64bitto32bit(tbl):
"""
Convert a Pandas dataframe from 64 bit types to 32 bit types to save
memory or disk space.
Parameters
----------
tbl : The dataframe to convert
Returns
-------
The converted dataframe
"""
newtbl = pd.DataFrame(index=tbl.index)
for colname in... | [
"def",
"df64bitto32bit",
"(",
"tbl",
")",
":",
"newtbl",
"=",
"pd",
".",
"DataFrame",
"(",
"index",
"=",
"tbl",
".",
"index",
")",
"for",
"colname",
"in",
"tbl",
".",
"columns",
":",
"newtbl",
"[",
"colname",
"]",
"=",
"series64bitto32bit",
"(",
"tbl",... | Convert a Pandas dataframe from 64 bit types to 32 bit types to save
memory or disk space.
Parameters
----------
tbl : The dataframe to convert
Returns
-------
The converted dataframe | [
"Convert",
"a",
"Pandas",
"dataframe",
"from",
"64",
"bit",
"types",
"to",
"32",
"bit",
"types",
"to",
"save",
"memory",
"or",
"disk",
"space",
"."
] | train | https://github.com/UDST/urbansim/blob/79f815a6503e109f50be270cee92d0f4a34f49ef/urbansim/utils/misc.py#L320-L336 |
UDST/urbansim | urbansim/utils/misc.py | series64bitto32bit | def series64bitto32bit(s):
"""
Convert a Pandas series from 64 bit types to 32 bit types to save
memory or disk space.
Parameters
----------
s : The series to convert
Returns
-------
The converted series
"""
if s.dtype == np.float64:
return s.astype('float32')
e... | python | def series64bitto32bit(s):
"""
Convert a Pandas series from 64 bit types to 32 bit types to save
memory or disk space.
Parameters
----------
s : The series to convert
Returns
-------
The converted series
"""
if s.dtype == np.float64:
return s.astype('float32')
e... | [
"def",
"series64bitto32bit",
"(",
"s",
")",
":",
"if",
"s",
".",
"dtype",
"==",
"np",
".",
"float64",
":",
"return",
"s",
".",
"astype",
"(",
"'float32'",
")",
"elif",
"s",
".",
"dtype",
"==",
"np",
".",
"int64",
":",
"return",
"s",
".",
"astype",
... | Convert a Pandas series from 64 bit types to 32 bit types to save
memory or disk space.
Parameters
----------
s : The series to convert
Returns
-------
The converted series | [
"Convert",
"a",
"Pandas",
"series",
"from",
"64",
"bit",
"types",
"to",
"32",
"bit",
"types",
"to",
"save",
"memory",
"or",
"disk",
"space",
"."
] | train | https://github.com/UDST/urbansim/blob/79f815a6503e109f50be270cee92d0f4a34f49ef/urbansim/utils/misc.py#L339-L356 |
UDST/urbansim | urbansim/utils/misc.py | pandasdfsummarytojson | def pandasdfsummarytojson(df, ndigits=3):
"""
Convert the result of a
Parameters
----------
df : The result of a Pandas describe operation.
ndigits : int, optional - The number of significant digits to round to.
Returns
-------
A json object which captures the describe. Keys are f... | python | def pandasdfsummarytojson(df, ndigits=3):
"""
Convert the result of a
Parameters
----------
df : The result of a Pandas describe operation.
ndigits : int, optional - The number of significant digits to round to.
Returns
-------
A json object which captures the describe. Keys are f... | [
"def",
"pandasdfsummarytojson",
"(",
"df",
",",
"ndigits",
"=",
"3",
")",
":",
"df",
"=",
"df",
".",
"transpose",
"(",
")",
"return",
"{",
"k",
":",
"_pandassummarytojson",
"(",
"v",
",",
"ndigits",
")",
"for",
"k",
",",
"v",
"in",
"df",
".",
"iter... | Convert the result of a
Parameters
----------
df : The result of a Pandas describe operation.
ndigits : int, optional - The number of significant digits to round to.
Returns
-------
A json object which captures the describe. Keys are field names and
values are dictionaries with all of... | [
"Convert",
"the",
"result",
"of",
"a"
] | train | https://github.com/UDST/urbansim/blob/79f815a6503e109f50be270cee92d0f4a34f49ef/urbansim/utils/misc.py#L363-L379 |
UDST/urbansim | urbansim/utils/misc.py | column_map | def column_map(tables, columns):
"""
Take a list of tables and a list of column names and resolve which
columns come from which table.
Parameters
----------
tables : sequence of _DataFrameWrapper or _TableFuncWrapper
Could also be sequence of modified pandas.DataFrames, the important
... | python | def column_map(tables, columns):
"""
Take a list of tables and a list of column names and resolve which
columns come from which table.
Parameters
----------
tables : sequence of _DataFrameWrapper or _TableFuncWrapper
Could also be sequence of modified pandas.DataFrames, the important
... | [
"def",
"column_map",
"(",
"tables",
",",
"columns",
")",
":",
"if",
"not",
"columns",
":",
"return",
"{",
"t",
".",
"name",
":",
"None",
"for",
"t",
"in",
"tables",
"}",
"columns",
"=",
"set",
"(",
"columns",
")",
"colmap",
"=",
"{",
"t",
".",
"n... | Take a list of tables and a list of column names and resolve which
columns come from which table.
Parameters
----------
tables : sequence of _DataFrameWrapper or _TableFuncWrapper
Could also be sequence of modified pandas.DataFrames, the important
thing is that they have ``.name`` and `... | [
"Take",
"a",
"list",
"of",
"tables",
"and",
"a",
"list",
"of",
"column",
"names",
"and",
"resolve",
"which",
"columns",
"come",
"from",
"which",
"table",
"."
] | train | https://github.com/UDST/urbansim/blob/79f815a6503e109f50be270cee92d0f4a34f49ef/urbansim/utils/misc.py#L382-L410 |
UDST/urbansim | urbansim/utils/misc.py | column_list | def column_list(tables, columns):
"""
Take a list of tables and a list of column names and return the columns
that are present in the tables.
Parameters
----------
tables : sequence of _DataFrameWrapper or _TableFuncWrapper
Could also be sequence of modified pandas.DataFrames, the impor... | python | def column_list(tables, columns):
"""
Take a list of tables and a list of column names and return the columns
that are present in the tables.
Parameters
----------
tables : sequence of _DataFrameWrapper or _TableFuncWrapper
Could also be sequence of modified pandas.DataFrames, the impor... | [
"def",
"column_list",
"(",
"tables",
",",
"columns",
")",
":",
"columns",
"=",
"set",
"(",
"columns",
")",
"foundcols",
"=",
"tz",
".",
"reduce",
"(",
"lambda",
"x",
",",
"y",
":",
"x",
".",
"union",
"(",
"y",
")",
",",
"(",
"set",
"(",
"t",
".... | Take a list of tables and a list of column names and return the columns
that are present in the tables.
Parameters
----------
tables : sequence of _DataFrameWrapper or _TableFuncWrapper
Could also be sequence of modified pandas.DataFrames, the important
thing is that they have ``.name``... | [
"Take",
"a",
"list",
"of",
"tables",
"and",
"a",
"list",
"of",
"column",
"names",
"and",
"return",
"the",
"columns",
"that",
"are",
"present",
"in",
"the",
"tables",
"."
] | train | https://github.com/UDST/urbansim/blob/79f815a6503e109f50be270cee92d0f4a34f49ef/urbansim/utils/misc.py#L413-L434 |
UDST/urbansim | urbansim/utils/sampling.py | get_probs | def get_probs(data, prob_column=None):
"""
Checks for presence of a probability column and returns the result
as a numpy array. If the probabilities are weights (i.e. they don't
sum to 1), then this will be recalculated.
Parameters
----------
data: pandas.DataFrame
Table to sample f... | python | def get_probs(data, prob_column=None):
"""
Checks for presence of a probability column and returns the result
as a numpy array. If the probabilities are weights (i.e. they don't
sum to 1), then this will be recalculated.
Parameters
----------
data: pandas.DataFrame
Table to sample f... | [
"def",
"get_probs",
"(",
"data",
",",
"prob_column",
"=",
"None",
")",
":",
"if",
"prob_column",
"is",
"None",
":",
"p",
"=",
"None",
"else",
":",
"p",
"=",
"data",
"[",
"prob_column",
"]",
".",
"fillna",
"(",
"0",
")",
".",
"values",
"if",
"p",
... | Checks for presence of a probability column and returns the result
as a numpy array. If the probabilities are weights (i.e. they don't
sum to 1), then this will be recalculated.
Parameters
----------
data: pandas.DataFrame
Table to sample from.
prob_column: string, optional, default Non... | [
"Checks",
"for",
"presence",
"of",
"a",
"probability",
"column",
"and",
"returns",
"the",
"result",
"as",
"a",
"numpy",
"array",
".",
"If",
"the",
"probabilities",
"are",
"weights",
"(",
"i",
".",
"e",
".",
"they",
"don",
"t",
"sum",
"to",
"1",
")",
... | train | https://github.com/UDST/urbansim/blob/79f815a6503e109f50be270cee92d0f4a34f49ef/urbansim/utils/sampling.py#L6-L32 |
UDST/urbansim | urbansim/utils/sampling.py | accounting_sample_replace | def accounting_sample_replace(total, data, accounting_column, prob_column=None, max_iterations=50):
"""
Sample rows with accounting with replacement.
Parameters
----------
total : int
The control total the sampled rows will attempt to match.
data: pandas.DataFrame
Table to sampl... | python | def accounting_sample_replace(total, data, accounting_column, prob_column=None, max_iterations=50):
"""
Sample rows with accounting with replacement.
Parameters
----------
total : int
The control total the sampled rows will attempt to match.
data: pandas.DataFrame
Table to sampl... | [
"def",
"accounting_sample_replace",
"(",
"total",
",",
"data",
",",
"accounting_column",
",",
"prob_column",
"=",
"None",
",",
"max_iterations",
"=",
"50",
")",
":",
"# check for probabilities",
"p",
"=",
"get_probs",
"(",
"data",
",",
"prob_column",
")",
"# det... | Sample rows with accounting with replacement.
Parameters
----------
total : int
The control total the sampled rows will attempt to match.
data: pandas.DataFrame
Table to sample from.
accounting_column: string
Name of column with accounting totals/quantities to apply towards ... | [
"Sample",
"rows",
"with",
"accounting",
"with",
"replacement",
"."
] | train | https://github.com/UDST/urbansim/blob/79f815a6503e109f50be270cee92d0f4a34f49ef/urbansim/utils/sampling.py#L35-L105 |
UDST/urbansim | urbansim/utils/sampling.py | accounting_sample_no_replace | def accounting_sample_no_replace(total, data, accounting_column, prob_column=None):
"""
Samples rows with accounting without replacement.
Parameters
----------
total : int
The control total the sampled rows will attempt to match.
data: pandas.DataFrame
Table to sample from.
... | python | def accounting_sample_no_replace(total, data, accounting_column, prob_column=None):
"""
Samples rows with accounting without replacement.
Parameters
----------
total : int
The control total the sampled rows will attempt to match.
data: pandas.DataFrame
Table to sample from.
... | [
"def",
"accounting_sample_no_replace",
"(",
"total",
",",
"data",
",",
"accounting_column",
",",
"prob_column",
"=",
"None",
")",
":",
"# make sure this is even feasible",
"if",
"total",
">",
"data",
"[",
"accounting_column",
"]",
".",
"sum",
"(",
")",
":",
"rai... | Samples rows with accounting without replacement.
Parameters
----------
total : int
The control total the sampled rows will attempt to match.
data: pandas.DataFrame
Table to sample from.
accounting_column: string
Name of column with accounting totals/quantities to apply towa... | [
"Samples",
"rows",
"with",
"accounting",
"without",
"replacement",
"."
] | train | https://github.com/UDST/urbansim/blob/79f815a6503e109f50be270cee92d0f4a34f49ef/urbansim/utils/sampling.py#L108-L172 |
UDST/urbansim | urbansim/utils/sampling.py | sample_rows | def sample_rows(total, data, replace=True, accounting_column=None,
max_iterations=50, prob_column=None, return_status=False):
"""
Samples and returns rows from a data frame while matching a desired control total. The total may
represent a simple row count or may attempt to match a sum/quanti... | python | def sample_rows(total, data, replace=True, accounting_column=None,
max_iterations=50, prob_column=None, return_status=False):
"""
Samples and returns rows from a data frame while matching a desired control total. The total may
represent a simple row count or may attempt to match a sum/quanti... | [
"def",
"sample_rows",
"(",
"total",
",",
"data",
",",
"replace",
"=",
"True",
",",
"accounting_column",
"=",
"None",
",",
"max_iterations",
"=",
"50",
",",
"prob_column",
"=",
"None",
",",
"return_status",
"=",
"False",
")",
":",
"if",
"not",
"data",
"."... | Samples and returns rows from a data frame while matching a desired control total. The total may
represent a simple row count or may attempt to match a sum/quantity from an accounting column.
Parameters
----------
total : int
The control total the sampled rows will attempt to match.
data: p... | [
"Samples",
"and",
"returns",
"rows",
"from",
"a",
"data",
"frame",
"while",
"matching",
"a",
"desired",
"control",
"total",
".",
"The",
"total",
"may",
"represent",
"a",
"simple",
"row",
"count",
"or",
"may",
"attempt",
"to",
"match",
"a",
"sum",
"/",
"q... | train | https://github.com/UDST/urbansim/blob/79f815a6503e109f50be270cee92d0f4a34f49ef/urbansim/utils/sampling.py#L175-L234 |
UDST/urbansim | urbansim/developer/sqftproforma.py | SqFtProFormaConfig._convert_types | def _convert_types(self):
"""
convert lists and dictionaries that are useful for users to
np vectors that are usable by machines
"""
self.fars = np.array(self.fars)
self.parking_rates = np.array([self.parking_rates[use] for use in self.uses])
self.res_ratios = {}... | python | def _convert_types(self):
"""
convert lists and dictionaries that are useful for users to
np vectors that are usable by machines
"""
self.fars = np.array(self.fars)
self.parking_rates = np.array([self.parking_rates[use] for use in self.uses])
self.res_ratios = {}... | [
"def",
"_convert_types",
"(",
"self",
")",
":",
"self",
".",
"fars",
"=",
"np",
".",
"array",
"(",
"self",
".",
"fars",
")",
"self",
".",
"parking_rates",
"=",
"np",
".",
"array",
"(",
"[",
"self",
".",
"parking_rates",
"[",
"use",
"]",
"for",
"use... | convert lists and dictionaries that are useful for users to
np vectors that are usable by machines | [
"convert",
"lists",
"and",
"dictionaries",
"that",
"are",
"useful",
"for",
"users",
"to",
"np",
"vectors",
"that",
"are",
"usable",
"by",
"machines"
] | train | https://github.com/UDST/urbansim/blob/79f815a6503e109f50be270cee92d0f4a34f49ef/urbansim/developer/sqftproforma.py#L192-L207 |
UDST/urbansim | urbansim/developer/sqftproforma.py | SqFtProForma._building_cost | def _building_cost(self, use_mix, stories):
"""
Generate building cost for a set of buildings
Parameters
----------
use_mix : array
The mix of uses for this form
stories : series
A Pandas Series of stories
Returns
-------
... | python | def _building_cost(self, use_mix, stories):
"""
Generate building cost for a set of buildings
Parameters
----------
use_mix : array
The mix of uses for this form
stories : series
A Pandas Series of stories
Returns
-------
... | [
"def",
"_building_cost",
"(",
"self",
",",
"use_mix",
",",
"stories",
")",
":",
"c",
"=",
"self",
".",
"config",
"# stories to heights",
"heights",
"=",
"stories",
"*",
"c",
".",
"height_per_story",
"# cost index for this height",
"costs",
"=",
"np",
".",
"sea... | Generate building cost for a set of buildings
Parameters
----------
use_mix : array
The mix of uses for this form
stories : series
A Pandas Series of stories
Returns
-------
array
The cost per sqft for this unit mix and height... | [
"Generate",
"building",
"cost",
"for",
"a",
"set",
"of",
"buildings"
] | train | https://github.com/UDST/urbansim/blob/79f815a6503e109f50be270cee92d0f4a34f49ef/urbansim/developer/sqftproforma.py#L279-L307 |
UDST/urbansim | urbansim/developer/sqftproforma.py | SqFtProForma._generate_lookup | def _generate_lookup(self):
"""
Run the developer model on all possible inputs specified in the
configuration object - not generally called by the user. This part
computes the final cost per sqft of the building to construct and
then turns it into the yearly rent necessary to ma... | python | def _generate_lookup(self):
"""
Run the developer model on all possible inputs specified in the
configuration object - not generally called by the user. This part
computes the final cost per sqft of the building to construct and
then turns it into the yearly rent necessary to ma... | [
"def",
"_generate_lookup",
"(",
"self",
")",
":",
"c",
"=",
"self",
".",
"config",
"# get all the building forms we can use",
"keys",
"=",
"c",
".",
"forms",
".",
"keys",
"(",
")",
"keys",
"=",
"sorted",
"(",
"keys",
")",
"df_d",
"=",
"{",
"}",
"for",
... | Run the developer model on all possible inputs specified in the
configuration object - not generally called by the user. This part
computes the final cost per sqft of the building to construct and
then turns it into the yearly rent necessary to make break even on
that cost. | [
"Run",
"the",
"developer",
"model",
"on",
"all",
"possible",
"inputs",
"specified",
"in",
"the",
"configuration",
"object",
"-",
"not",
"generally",
"called",
"by",
"the",
"user",
".",
"This",
"part",
"computes",
"the",
"final",
"cost",
"per",
"sqft",
"of",
... | train | https://github.com/UDST/urbansim/blob/79f815a6503e109f50be270cee92d0f4a34f49ef/urbansim/developer/sqftproforma.py#L309-L398 |
UDST/urbansim | urbansim/developer/sqftproforma.py | SqFtProForma.lookup | def lookup(self, form, df, only_built=True, pass_through=None):
"""
This function does the developer model lookups for all the actual input data.
Parameters
----------
form : string
One of the forms specified in the configuration file
df: dataframe
... | python | def lookup(self, form, df, only_built=True, pass_through=None):
"""
This function does the developer model lookups for all the actual input data.
Parameters
----------
form : string
One of the forms specified in the configuration file
df: dataframe
... | [
"def",
"lookup",
"(",
"self",
",",
"form",
",",
"df",
",",
"only_built",
"=",
"True",
",",
"pass_through",
"=",
"None",
")",
":",
"df",
"=",
"pd",
".",
"concat",
"(",
"self",
".",
"_lookup_parking_cfg",
"(",
"form",
",",
"parking_config",
",",
"df",
... | This function does the developer model lookups for all the actual input data.
Parameters
----------
form : string
One of the forms specified in the configuration file
df: dataframe
Pass in a single data frame which is indexed by parcel_id and has the
... | [
"This",
"function",
"does",
"the",
"developer",
"model",
"lookups",
"for",
"all",
"the",
"actual",
"input",
"data",
"."
] | train | https://github.com/UDST/urbansim/blob/79f815a6503e109f50be270cee92d0f4a34f49ef/urbansim/developer/sqftproforma.py#L445-L537 |
UDST/urbansim | urbansim/developer/sqftproforma.py | SqFtProForma._debug_output | def _debug_output(self):
"""
this code creates the debugging plots to understand
the behavior of the hypothetical building model
"""
import matplotlib
matplotlib.use('Agg')
import matplotlib.pyplot as plt
c = self.config
df_d = self.dev_d
... | python | def _debug_output(self):
"""
this code creates the debugging plots to understand
the behavior of the hypothetical building model
"""
import matplotlib
matplotlib.use('Agg')
import matplotlib.pyplot as plt
c = self.config
df_d = self.dev_d
... | [
"def",
"_debug_output",
"(",
"self",
")",
":",
"import",
"matplotlib",
"matplotlib",
".",
"use",
"(",
"'Agg'",
")",
"import",
"matplotlib",
".",
"pyplot",
"as",
"plt",
"c",
"=",
"self",
".",
"config",
"df_d",
"=",
"self",
".",
"dev_d",
"keys",
"=",
"df... | this code creates the debugging plots to understand
the behavior of the hypothetical building model | [
"this",
"code",
"creates",
"the",
"debugging",
"plots",
"to",
"understand",
"the",
"behavior",
"of",
"the",
"hypothetical",
"building",
"model"
] | train | https://github.com/UDST/urbansim/blob/79f815a6503e109f50be270cee92d0f4a34f49ef/urbansim/developer/sqftproforma.py#L666-L716 |
UDST/urbansim | urbansim/models/transition.py | add_rows | def add_rows(data, nrows, starting_index=None, accounting_column=None):
"""
Add rows to data table according to a given nrows.
New rows will have their IDs set to NaN.
Parameters
----------
data : pandas.DataFrame
nrows : int
Number of rows to add.
starting_index : int, optional... | python | def add_rows(data, nrows, starting_index=None, accounting_column=None):
"""
Add rows to data table according to a given nrows.
New rows will have their IDs set to NaN.
Parameters
----------
data : pandas.DataFrame
nrows : int
Number of rows to add.
starting_index : int, optional... | [
"def",
"add_rows",
"(",
"data",
",",
"nrows",
",",
"starting_index",
"=",
"None",
",",
"accounting_column",
"=",
"None",
")",
":",
"logger",
".",
"debug",
"(",
"'start: adding {} rows in transition model'",
".",
"format",
"(",
"nrows",
")",
")",
"if",
"nrows",... | Add rows to data table according to a given nrows.
New rows will have their IDs set to NaN.
Parameters
----------
data : pandas.DataFrame
nrows : int
Number of rows to add.
starting_index : int, optional
The starting index from which to calculate indexes for the new
rows... | [
"Add",
"rows",
"to",
"data",
"table",
"according",
"to",
"a",
"given",
"nrows",
".",
"New",
"rows",
"will",
"have",
"their",
"IDs",
"set",
"to",
"NaN",
"."
] | train | https://github.com/UDST/urbansim/blob/79f815a6503e109f50be270cee92d0f4a34f49ef/urbansim/models/transition.py#L24-L68 |
UDST/urbansim | urbansim/models/transition.py | remove_rows | def remove_rows(data, nrows, accounting_column=None):
"""
Remove a random `nrows` number of rows from a table.
Parameters
----------
data : DataFrame
nrows : float
Number of rows to remove.
accounting_column: string, optional
Name of column with accounting totals/quanties to... | python | def remove_rows(data, nrows, accounting_column=None):
"""
Remove a random `nrows` number of rows from a table.
Parameters
----------
data : DataFrame
nrows : float
Number of rows to remove.
accounting_column: string, optional
Name of column with accounting totals/quanties to... | [
"def",
"remove_rows",
"(",
"data",
",",
"nrows",
",",
"accounting_column",
"=",
"None",
")",
":",
"logger",
".",
"debug",
"(",
"'start: removing {} rows in transition model'",
".",
"format",
"(",
"nrows",
")",
")",
"nrows",
"=",
"abs",
"(",
"nrows",
")",
"# ... | Remove a random `nrows` number of rows from a table.
Parameters
----------
data : DataFrame
nrows : float
Number of rows to remove.
accounting_column: string, optional
Name of column with accounting totals/quanties to apply towards the control. If not provided
then row count... | [
"Remove",
"a",
"random",
"nrows",
"number",
"of",
"rows",
"from",
"a",
"table",
"."
] | train | https://github.com/UDST/urbansim/blob/79f815a6503e109f50be270cee92d0f4a34f49ef/urbansim/models/transition.py#L71-L104 |
UDST/urbansim | urbansim/models/transition.py | add_or_remove_rows | def add_or_remove_rows(data, nrows, starting_index=None, accounting_column=None):
"""
Add or remove rows to/from a table. Rows are added
for positive `nrows` and removed for negative `nrows`.
Parameters
----------
data : DataFrame
nrows : float
Number of rows to add or remove.
s... | python | def add_or_remove_rows(data, nrows, starting_index=None, accounting_column=None):
"""
Add or remove rows to/from a table. Rows are added
for positive `nrows` and removed for negative `nrows`.
Parameters
----------
data : DataFrame
nrows : float
Number of rows to add or remove.
s... | [
"def",
"add_or_remove_rows",
"(",
"data",
",",
"nrows",
",",
"starting_index",
"=",
"None",
",",
"accounting_column",
"=",
"None",
")",
":",
"if",
"nrows",
">",
"0",
":",
"updated",
",",
"added",
",",
"copied",
"=",
"add_rows",
"(",
"data",
",",
"nrows",... | Add or remove rows to/from a table. Rows are added
for positive `nrows` and removed for negative `nrows`.
Parameters
----------
data : DataFrame
nrows : float
Number of rows to add or remove.
starting_index : int, optional
The starting index from which to calculate indexes for n... | [
"Add",
"or",
"remove",
"rows",
"to",
"/",
"from",
"a",
"table",
".",
"Rows",
"are",
"added",
"for",
"positive",
"nrows",
"and",
"removed",
"for",
"negative",
"nrows",
"."
] | train | https://github.com/UDST/urbansim/blob/79f815a6503e109f50be270cee92d0f4a34f49ef/urbansim/models/transition.py#L107-L149 |
UDST/urbansim | urbansim/models/transition.py | _update_linked_table | def _update_linked_table(table, col_name, added, copied, removed):
"""
Copy and update rows in a table that has a column referencing another
table that has had rows added via copying.
Parameters
----------
table : pandas.DataFrame
Table to update with new or removed rows.
col_name :... | python | def _update_linked_table(table, col_name, added, copied, removed):
"""
Copy and update rows in a table that has a column referencing another
table that has had rows added via copying.
Parameters
----------
table : pandas.DataFrame
Table to update with new or removed rows.
col_name :... | [
"def",
"_update_linked_table",
"(",
"table",
",",
"col_name",
",",
"added",
",",
"copied",
",",
"removed",
")",
":",
"logger",
".",
"debug",
"(",
"'start: update linked table after transition'",
")",
"# handle removals",
"table",
"=",
"table",
".",
"loc",
"[",
"... | Copy and update rows in a table that has a column referencing another
table that has had rows added via copying.
Parameters
----------
table : pandas.DataFrame
Table to update with new or removed rows.
col_name : str
Name of column in `table` that corresponds to the index values
... | [
"Copy",
"and",
"update",
"rows",
"in",
"a",
"table",
"that",
"has",
"a",
"column",
"referencing",
"another",
"table",
"that",
"has",
"had",
"rows",
"added",
"via",
"copying",
"."
] | train | https://github.com/UDST/urbansim/blob/79f815a6503e109f50be270cee92d0f4a34f49ef/urbansim/models/transition.py#L424-L468 |
UDST/urbansim | urbansim/models/transition.py | GrowthRateTransition.transition | def transition(self, data, year):
"""
Add or remove rows to/from a table according to the prescribed
growth rate for this model.
Parameters
----------
data : pandas.DataFrame
Rows will be removed from or added to this table.
year : None, optional
... | python | def transition(self, data, year):
"""
Add or remove rows to/from a table according to the prescribed
growth rate for this model.
Parameters
----------
data : pandas.DataFrame
Rows will be removed from or added to this table.
year : None, optional
... | [
"def",
"transition",
"(",
"self",
",",
"data",
",",
"year",
")",
":",
"if",
"self",
".",
"accounting_column",
"is",
"None",
":",
"nrows",
"=",
"int",
"(",
"round",
"(",
"len",
"(",
"data",
")",
"*",
"self",
".",
"growth_rate",
")",
")",
"else",
":"... | Add or remove rows to/from a table according to the prescribed
growth rate for this model.
Parameters
----------
data : pandas.DataFrame
Rows will be removed from or added to this table.
year : None, optional
Here for compatibility with other transition m... | [
"Add",
"or",
"remove",
"rows",
"to",
"/",
"from",
"a",
"table",
"according",
"to",
"the",
"prescribed",
"growth",
"rate",
"for",
"this",
"model",
"."
] | train | https://github.com/UDST/urbansim/blob/79f815a6503e109f50be270cee92d0f4a34f49ef/urbansim/models/transition.py#L167-L201 |
UDST/urbansim | urbansim/models/transition.py | TabularGrowthRateTransition.transition | def transition(self, data, year):
"""
Add or remove rows to/from a table according to the prescribed
growth rate for this model and year.
Parameters
----------
data : pandas.DataFrame
Rows will be removed from or added to this table.
year : None, opti... | python | def transition(self, data, year):
"""
Add or remove rows to/from a table according to the prescribed
growth rate for this model and year.
Parameters
----------
data : pandas.DataFrame
Rows will be removed from or added to this table.
year : None, opti... | [
"def",
"transition",
"(",
"self",
",",
"data",
",",
"year",
")",
":",
"logger",
".",
"debug",
"(",
"'start: tabular transition'",
")",
"if",
"year",
"not",
"in",
"self",
".",
"_config_table",
".",
"index",
":",
"raise",
"ValueError",
"(",
"'No targets for gi... | Add or remove rows to/from a table according to the prescribed
growth rate for this model and year.
Parameters
----------
data : pandas.DataFrame
Rows will be removed from or added to this table.
year : None, optional
Here for compatibility with other tra... | [
"Add",
"or",
"remove",
"rows",
"to",
"/",
"from",
"a",
"table",
"according",
"to",
"the",
"prescribed",
"growth",
"rate",
"for",
"this",
"model",
"and",
"year",
"."
] | train | https://github.com/UDST/urbansim/blob/79f815a6503e109f50be270cee92d0f4a34f49ef/urbansim/models/transition.py#L261-L335 |
UDST/urbansim | urbansim/models/transition.py | TabularTotalsTransition.transition | def transition(self, data, year):
"""
Add or remove rows to/from a table according to the prescribed
totals for this model and year.
Parameters
----------
data : pandas.DataFrame
Rows will be removed from or added to this table.
year : None, optional
... | python | def transition(self, data, year):
"""
Add or remove rows to/from a table according to the prescribed
totals for this model and year.
Parameters
----------
data : pandas.DataFrame
Rows will be removed from or added to this table.
year : None, optional
... | [
"def",
"transition",
"(",
"self",
",",
"data",
",",
"year",
")",
":",
"with",
"log_start_finish",
"(",
"'tabular totals transition'",
",",
"logger",
")",
":",
"return",
"super",
"(",
"TabularTotalsTransition",
",",
"self",
")",
".",
"transition",
"(",
"data",
... | Add or remove rows to/from a table according to the prescribed
totals for this model and year.
Parameters
----------
data : pandas.DataFrame
Rows will be removed from or added to this table.
year : None, optional
Here for compatibility with other transiti... | [
"Add",
"or",
"remove",
"rows",
"to",
"/",
"from",
"a",
"table",
"according",
"to",
"the",
"prescribed",
"totals",
"for",
"this",
"model",
"and",
"year",
"."
] | train | https://github.com/UDST/urbansim/blob/79f815a6503e109f50be270cee92d0f4a34f49ef/urbansim/models/transition.py#L394-L421 |
UDST/urbansim | urbansim/models/transition.py | TransitionModel.transition | def transition(self, data, year, linked_tables=None):
"""
Add or remove rows from a table based on population targets.
Parameters
----------
data : pandas.DataFrame
Rows will be removed from or added to this table.
year : int
Year number that will... | python | def transition(self, data, year, linked_tables=None):
"""
Add or remove rows from a table based on population targets.
Parameters
----------
data : pandas.DataFrame
Rows will be removed from or added to this table.
year : int
Year number that will... | [
"def",
"transition",
"(",
"self",
",",
"data",
",",
"year",
",",
"linked_tables",
"=",
"None",
")",
":",
"logger",
".",
"debug",
"(",
"'start: transition'",
")",
"linked_tables",
"=",
"linked_tables",
"or",
"{",
"}",
"updated_links",
"=",
"{",
"}",
"with",... | Add or remove rows from a table based on population targets.
Parameters
----------
data : pandas.DataFrame
Rows will be removed from or added to this table.
year : int
Year number that will be passed to `transitioner`.
linked_tables : dict of tuple, optio... | [
"Add",
"or",
"remove",
"rows",
"from",
"a",
"table",
"based",
"on",
"population",
"targets",
"."
] | train | https://github.com/UDST/urbansim/blob/79f815a6503e109f50be270cee92d0f4a34f49ef/urbansim/models/transition.py#L486-L525 |
UDST/urbansim | urbansim/utils/yamlio.py | series_to_yaml_safe | def series_to_yaml_safe(series, ordered=False):
"""
Convert a pandas Series to a dict that will survive YAML serialization
and re-conversion back to a Series.
Parameters
----------
series : pandas.Series
ordered: bool, optional, default False
If True, an OrderedDict is returned.
... | python | def series_to_yaml_safe(series, ordered=False):
"""
Convert a pandas Series to a dict that will survive YAML serialization
and re-conversion back to a Series.
Parameters
----------
series : pandas.Series
ordered: bool, optional, default False
If True, an OrderedDict is returned.
... | [
"def",
"series_to_yaml_safe",
"(",
"series",
",",
"ordered",
"=",
"False",
")",
":",
"index",
"=",
"series",
".",
"index",
".",
"to_native_types",
"(",
"quoting",
"=",
"True",
")",
"values",
"=",
"series",
".",
"values",
".",
"tolist",
"(",
")",
"if",
... | Convert a pandas Series to a dict that will survive YAML serialization
and re-conversion back to a Series.
Parameters
----------
series : pandas.Series
ordered: bool, optional, default False
If True, an OrderedDict is returned.
Returns
-------
safe : dict or OrderedDict | [
"Convert",
"a",
"pandas",
"Series",
"to",
"a",
"dict",
"that",
"will",
"survive",
"YAML",
"serialization",
"and",
"re",
"-",
"conversion",
"back",
"to",
"a",
"Series",
"."
] | train | https://github.com/UDST/urbansim/blob/79f815a6503e109f50be270cee92d0f4a34f49ef/urbansim/utils/yamlio.py#L32-L55 |
UDST/urbansim | urbansim/utils/yamlio.py | frame_to_yaml_safe | def frame_to_yaml_safe(frame, ordered=False):
"""
Convert a pandas DataFrame to a dictionary that will survive
YAML serialization and re-conversion back to a DataFrame.
Parameters
----------
frame : pandas.DataFrame
ordered: bool, optional, default False
If True, an OrderedDict is r... | python | def frame_to_yaml_safe(frame, ordered=False):
"""
Convert a pandas DataFrame to a dictionary that will survive
YAML serialization and re-conversion back to a DataFrame.
Parameters
----------
frame : pandas.DataFrame
ordered: bool, optional, default False
If True, an OrderedDict is r... | [
"def",
"frame_to_yaml_safe",
"(",
"frame",
",",
"ordered",
"=",
"False",
")",
":",
"if",
"ordered",
":",
"return",
"OrderedDict",
"(",
"tuple",
"(",
"(",
"col",
",",
"series_to_yaml_safe",
"(",
"series",
",",
"True",
")",
")",
"for",
"col",
",",
"series"... | Convert a pandas DataFrame to a dictionary that will survive
YAML serialization and re-conversion back to a DataFrame.
Parameters
----------
frame : pandas.DataFrame
ordered: bool, optional, default False
If True, an OrderedDict is returned.
Returns
-------
safe : dict or Order... | [
"Convert",
"a",
"pandas",
"DataFrame",
"to",
"a",
"dictionary",
"that",
"will",
"survive",
"YAML",
"serialization",
"and",
"re",
"-",
"conversion",
"back",
"to",
"a",
"DataFrame",
"."
] | train | https://github.com/UDST/urbansim/blob/79f815a6503e109f50be270cee92d0f4a34f49ef/urbansim/utils/yamlio.py#L58-L79 |
UDST/urbansim | urbansim/utils/yamlio.py | ordered_yaml | def ordered_yaml(cfg, order=None):
"""
Convert a dictionary to a YAML string with preferential ordering
for some keys. Converted string is meant to be fairly human readable.
Parameters
----------
cfg : dict
Dictionary to convert to a YAML string.
order: list
If provided, ove... | python | def ordered_yaml(cfg, order=None):
"""
Convert a dictionary to a YAML string with preferential ordering
for some keys. Converted string is meant to be fairly human readable.
Parameters
----------
cfg : dict
Dictionary to convert to a YAML string.
order: list
If provided, ove... | [
"def",
"ordered_yaml",
"(",
"cfg",
",",
"order",
"=",
"None",
")",
":",
"if",
"order",
"is",
"None",
":",
"order",
"=",
"[",
"'name'",
",",
"'model_type'",
",",
"'segmentation_col'",
",",
"'fit_filters'",
",",
"'predict_filters'",
",",
"'choosers_fit_filters'"... | Convert a dictionary to a YAML string with preferential ordering
for some keys. Converted string is meant to be fairly human readable.
Parameters
----------
cfg : dict
Dictionary to convert to a YAML string.
order: list
If provided, overrides the default key ordering.
Returns
... | [
"Convert",
"a",
"dictionary",
"to",
"a",
"YAML",
"string",
"with",
"preferential",
"ordering",
"for",
"some",
"keys",
".",
"Converted",
"string",
"is",
"meant",
"to",
"be",
"fairly",
"human",
"readable",
"."
] | train | https://github.com/UDST/urbansim/blob/79f815a6503e109f50be270cee92d0f4a34f49ef/urbansim/utils/yamlio.py#L92-L134 |
UDST/urbansim | urbansim/utils/yamlio.py | convert_to_yaml | def convert_to_yaml(cfg, str_or_buffer):
"""
Convert a dictionary to YAML and return the string or write it out
depending on the type of `str_or_buffer`.
Parameters
----------
cfg : dict or OrderedDict
Dictionary or OrderedDict to convert.
str_or_buffer : None, str, or buffer
... | python | def convert_to_yaml(cfg, str_or_buffer):
"""
Convert a dictionary to YAML and return the string or write it out
depending on the type of `str_or_buffer`.
Parameters
----------
cfg : dict or OrderedDict
Dictionary or OrderedDict to convert.
str_or_buffer : None, str, or buffer
... | [
"def",
"convert_to_yaml",
"(",
"cfg",
",",
"str_or_buffer",
")",
":",
"order",
"=",
"None",
"if",
"isinstance",
"(",
"cfg",
",",
"OrderedDict",
")",
":",
"order",
"=",
"[",
"]",
"s",
"=",
"ordered_yaml",
"(",
"cfg",
",",
"order",
")",
"if",
"not",
"s... | Convert a dictionary to YAML and return the string or write it out
depending on the type of `str_or_buffer`.
Parameters
----------
cfg : dict or OrderedDict
Dictionary or OrderedDict to convert.
str_or_buffer : None, str, or buffer
If None: the YAML string will be returned.
... | [
"Convert",
"a",
"dictionary",
"to",
"YAML",
"and",
"return",
"the",
"string",
"or",
"write",
"it",
"out",
"depending",
"on",
"the",
"type",
"of",
"str_or_buffer",
"."
] | train | https://github.com/UDST/urbansim/blob/79f815a6503e109f50be270cee92d0f4a34f49ef/urbansim/utils/yamlio.py#L160-L193 |
UDST/urbansim | urbansim/utils/yamlio.py | yaml_to_dict | def yaml_to_dict(yaml_str=None, str_or_buffer=None, ordered=False):
"""
Load YAML from a string, file, or buffer (an object with a .read method).
Parameters are mutually exclusive.
Parameters
----------
yaml_str : str, optional
A string of YAML.
str_or_buffer : str or file like, opt... | python | def yaml_to_dict(yaml_str=None, str_or_buffer=None, ordered=False):
"""
Load YAML from a string, file, or buffer (an object with a .read method).
Parameters are mutually exclusive.
Parameters
----------
yaml_str : str, optional
A string of YAML.
str_or_buffer : str or file like, opt... | [
"def",
"yaml_to_dict",
"(",
"yaml_str",
"=",
"None",
",",
"str_or_buffer",
"=",
"None",
",",
"ordered",
"=",
"False",
")",
":",
"if",
"not",
"yaml_str",
"and",
"not",
"str_or_buffer",
":",
"raise",
"ValueError",
"(",
"'One of yaml_str or str_or_buffer is required.... | Load YAML from a string, file, or buffer (an object with a .read method).
Parameters are mutually exclusive.
Parameters
----------
yaml_str : str, optional
A string of YAML.
str_or_buffer : str or file like, optional
File name or buffer from which to load YAML.
ordered: bool, op... | [
"Load",
"YAML",
"from",
"a",
"string",
"file",
"or",
"buffer",
"(",
"an",
"object",
"with",
"a",
".",
"read",
"method",
")",
".",
"Parameters",
"are",
"mutually",
"exclusive",
"."
] | train | https://github.com/UDST/urbansim/blob/79f815a6503e109f50be270cee92d0f4a34f49ef/urbansim/utils/yamlio.py#L196-L233 |
UDST/urbansim | urbansim/accounts.py | Account.add_transaction | def add_transaction(self, amount, subaccount=None, metadata=None):
"""
Add a new transaction to the account.
Parameters
----------
amount : float
Negative for withdrawls, positive for deposits.
subaccount : object, optional
Any indicator of a suba... | python | def add_transaction(self, amount, subaccount=None, metadata=None):
"""
Add a new transaction to the account.
Parameters
----------
amount : float
Negative for withdrawls, positive for deposits.
subaccount : object, optional
Any indicator of a suba... | [
"def",
"add_transaction",
"(",
"self",
",",
"amount",
",",
"subaccount",
"=",
"None",
",",
"metadata",
"=",
"None",
")",
":",
"metadata",
"=",
"metadata",
"or",
"{",
"}",
"self",
".",
"transactions",
".",
"append",
"(",
"Transaction",
"(",
"amount",
",",... | Add a new transaction to the account.
Parameters
----------
amount : float
Negative for withdrawls, positive for deposits.
subaccount : object, optional
Any indicator of a subaccount to which this transaction applies.
metadata : dict, optional
... | [
"Add",
"a",
"new",
"transaction",
"to",
"the",
"account",
"."
] | train | https://github.com/UDST/urbansim/blob/79f815a6503e109f50be270cee92d0f4a34f49ef/urbansim/accounts.py#L57-L75 |
UDST/urbansim | urbansim/accounts.py | Account.total_transactions_by_subacct | def total_transactions_by_subacct(self, subaccount):
"""
Get the sum of all transactions for a given subaccount.
Parameters
----------
subaccount : object
Identifier of subaccount.
Returns
-------
total : float
"""
return sum... | python | def total_transactions_by_subacct(self, subaccount):
"""
Get the sum of all transactions for a given subaccount.
Parameters
----------
subaccount : object
Identifier of subaccount.
Returns
-------
total : float
"""
return sum... | [
"def",
"total_transactions_by_subacct",
"(",
"self",
",",
"subaccount",
")",
":",
"return",
"sum",
"(",
"t",
".",
"amount",
"for",
"t",
"in",
"self",
".",
"transactions",
"if",
"t",
".",
"subaccount",
"==",
"subaccount",
")"
] | Get the sum of all transactions for a given subaccount.
Parameters
----------
subaccount : object
Identifier of subaccount.
Returns
-------
total : float | [
"Get",
"the",
"sum",
"of",
"all",
"transactions",
"for",
"a",
"given",
"subaccount",
"."
] | train | https://github.com/UDST/urbansim/blob/79f815a6503e109f50be270cee92d0f4a34f49ef/urbansim/accounts.py#L102-L117 |
UDST/urbansim | urbansim/accounts.py | Account.to_frame | def to_frame(self):
"""
Return transactions as a pandas DataFrame.
"""
col_names = _column_names_from_metadata(
t.metadata for t in self.transactions)
def trow(t):
return tz.concatv(
(t.amount, t.subaccount),
(t.metadata.g... | python | def to_frame(self):
"""
Return transactions as a pandas DataFrame.
"""
col_names = _column_names_from_metadata(
t.metadata for t in self.transactions)
def trow(t):
return tz.concatv(
(t.amount, t.subaccount),
(t.metadata.g... | [
"def",
"to_frame",
"(",
"self",
")",
":",
"col_names",
"=",
"_column_names_from_metadata",
"(",
"t",
".",
"metadata",
"for",
"t",
"in",
"self",
".",
"transactions",
")",
"def",
"trow",
"(",
"t",
")",
":",
"return",
"tz",
".",
"concatv",
"(",
"(",
"t",
... | Return transactions as a pandas DataFrame. | [
"Return",
"transactions",
"as",
"a",
"pandas",
"DataFrame",
"."
] | train | https://github.com/UDST/urbansim/blob/79f815a6503e109f50be270cee92d0f4a34f49ef/urbansim/accounts.py#L136-L153 |
UDST/urbansim | urbansim/models/util.py | apply_filter_query | def apply_filter_query(df, filters=None):
"""
Use the DataFrame.query method to filter a table down to the
desired rows.
Parameters
----------
df : pandas.DataFrame
filters : list of str or str, optional
List of filters to apply. Will be joined together with
' and ' and pass... | python | def apply_filter_query(df, filters=None):
"""
Use the DataFrame.query method to filter a table down to the
desired rows.
Parameters
----------
df : pandas.DataFrame
filters : list of str or str, optional
List of filters to apply. Will be joined together with
' and ' and pass... | [
"def",
"apply_filter_query",
"(",
"df",
",",
"filters",
"=",
"None",
")",
":",
"with",
"log_start_finish",
"(",
"'apply filter query: {!r}'",
".",
"format",
"(",
"filters",
")",
",",
"logger",
")",
":",
"if",
"filters",
":",
"if",
"isinstance",
"(",
"filters... | Use the DataFrame.query method to filter a table down to the
desired rows.
Parameters
----------
df : pandas.DataFrame
filters : list of str or str, optional
List of filters to apply. Will be joined together with
' and ' and passed to DataFrame.query. A string will be passed
... | [
"Use",
"the",
"DataFrame",
".",
"query",
"method",
"to",
"filter",
"a",
"table",
"down",
"to",
"the",
"desired",
"rows",
"."
] | train | https://github.com/UDST/urbansim/blob/79f815a6503e109f50be270cee92d0f4a34f49ef/urbansim/models/util.py#L24-L51 |
UDST/urbansim | urbansim/models/util.py | _filterize | def _filterize(name, value):
"""
Turn a `name` and `value` into a string expression compatible
the ``DataFrame.query`` method.
Parameters
----------
name : str
Should be the name of a column in the table to which the
filter will be applied.
A suffix of '_max' will resul... | python | def _filterize(name, value):
"""
Turn a `name` and `value` into a string expression compatible
the ``DataFrame.query`` method.
Parameters
----------
name : str
Should be the name of a column in the table to which the
filter will be applied.
A suffix of '_max' will resul... | [
"def",
"_filterize",
"(",
"name",
",",
"value",
")",
":",
"if",
"name",
".",
"endswith",
"(",
"'_min'",
")",
":",
"name",
"=",
"name",
"[",
":",
"-",
"4",
"]",
"comp",
"=",
"'>='",
"elif",
"name",
".",
"endswith",
"(",
"'_max'",
")",
":",
"name",... | Turn a `name` and `value` into a string expression compatible
the ``DataFrame.query`` method.
Parameters
----------
name : str
Should be the name of a column in the table to which the
filter will be applied.
A suffix of '_max' will result in a "less than" filter,
a suff... | [
"Turn",
"a",
"name",
"and",
"value",
"into",
"a",
"string",
"expression",
"compatible",
"the",
"DataFrame",
".",
"query",
"method",
"."
] | train | https://github.com/UDST/urbansim/blob/79f815a6503e109f50be270cee92d0f4a34f49ef/urbansim/models/util.py#L54-L89 |
UDST/urbansim | urbansim/models/util.py | filter_table | def filter_table(table, filter_series, ignore=None):
"""
Filter a table based on a set of restrictions given in
Series of column name / filter parameter pairs. The column
names can have suffixes `_min` and `_max` to indicate
"less than" and "greater than" constraints.
Parameters
----------
... | python | def filter_table(table, filter_series, ignore=None):
"""
Filter a table based on a set of restrictions given in
Series of column name / filter parameter pairs. The column
names can have suffixes `_min` and `_max` to indicate
"less than" and "greater than" constraints.
Parameters
----------
... | [
"def",
"filter_table",
"(",
"table",
",",
"filter_series",
",",
"ignore",
"=",
"None",
")",
":",
"with",
"log_start_finish",
"(",
"'filter table'",
",",
"logger",
")",
":",
"ignore",
"=",
"ignore",
"if",
"ignore",
"else",
"set",
"(",
")",
"filters",
"=",
... | Filter a table based on a set of restrictions given in
Series of column name / filter parameter pairs. The column
names can have suffixes `_min` and `_max` to indicate
"less than" and "greater than" constraints.
Parameters
----------
table : pandas.DataFrame
Table to filter.
filter_... | [
"Filter",
"a",
"table",
"based",
"on",
"a",
"set",
"of",
"restrictions",
"given",
"in",
"Series",
"of",
"column",
"name",
"/",
"filter",
"parameter",
"pairs",
".",
"The",
"column",
"names",
"can",
"have",
"suffixes",
"_min",
"and",
"_max",
"to",
"indicate"... | train | https://github.com/UDST/urbansim/blob/79f815a6503e109f50be270cee92d0f4a34f49ef/urbansim/models/util.py#L92-L126 |
UDST/urbansim | urbansim/models/util.py | has_constant_expr | def has_constant_expr(expr):
"""
Report whether a model expression has constant specific term.
That is, a term explicitly specying whether the model should or
should not include a constant. (e.g. '+ 1' or '- 1'.)
Parameters
----------
expr : str
Model expression to check.
Retur... | python | def has_constant_expr(expr):
"""
Report whether a model expression has constant specific term.
That is, a term explicitly specying whether the model should or
should not include a constant. (e.g. '+ 1' or '- 1'.)
Parameters
----------
expr : str
Model expression to check.
Retur... | [
"def",
"has_constant_expr",
"(",
"expr",
")",
":",
"def",
"has_constant",
"(",
"node",
")",
":",
"if",
"node",
".",
"type",
"==",
"'ONE'",
":",
"return",
"True",
"for",
"n",
"in",
"node",
".",
"args",
":",
"if",
"has_constant",
"(",
"n",
")",
":",
... | Report whether a model expression has constant specific term.
That is, a term explicitly specying whether the model should or
should not include a constant. (e.g. '+ 1' or '- 1'.)
Parameters
----------
expr : str
Model expression to check.
Returns
-------
has_constant : bool | [
"Report",
"whether",
"a",
"model",
"expression",
"has",
"constant",
"specific",
"term",
".",
"That",
"is",
"a",
"term",
"explicitly",
"specying",
"whether",
"the",
"model",
"should",
"or",
"should",
"not",
"include",
"a",
"constant",
".",
"(",
"e",
".",
"g... | train | https://github.com/UDST/urbansim/blob/79f815a6503e109f50be270cee92d0f4a34f49ef/urbansim/models/util.py#L145-L171 |
UDST/urbansim | urbansim/models/util.py | str_model_expression | def str_model_expression(expr, add_constant=True):
"""
We support specifying model expressions as strings, lists, or dicts;
but for use with patsy and statsmodels we need a string.
This function will take any of those as input and return a string.
Parameters
----------
expr : str, iterable,... | python | def str_model_expression(expr, add_constant=True):
"""
We support specifying model expressions as strings, lists, or dicts;
but for use with patsy and statsmodels we need a string.
This function will take any of those as input and return a string.
Parameters
----------
expr : str, iterable,... | [
"def",
"str_model_expression",
"(",
"expr",
",",
"add_constant",
"=",
"True",
")",
":",
"if",
"not",
"isinstance",
"(",
"expr",
",",
"str",
")",
":",
"if",
"isinstance",
"(",
"expr",
",",
"collections",
".",
"Mapping",
")",
":",
"left_side",
"=",
"expr",... | We support specifying model expressions as strings, lists, or dicts;
but for use with patsy and statsmodels we need a string.
This function will take any of those as input and return a string.
Parameters
----------
expr : str, iterable, or dict
A string will be returned unmodified except to... | [
"We",
"support",
"specifying",
"model",
"expressions",
"as",
"strings",
"lists",
"or",
"dicts",
";",
"but",
"for",
"use",
"with",
"patsy",
"and",
"statsmodels",
"we",
"need",
"a",
"string",
".",
"This",
"function",
"will",
"take",
"any",
"of",
"those",
"as... | train | https://github.com/UDST/urbansim/blob/79f815a6503e109f50be270cee92d0f4a34f49ef/urbansim/models/util.py#L174-L227 |
UDST/urbansim | urbansim/models/util.py | sorted_groupby | def sorted_groupby(df, groupby):
"""
Perform a groupby on a DataFrame using a specific column
and assuming that that column is sorted.
Parameters
----------
df : pandas.DataFrame
groupby : object
Column name on which to groupby. This column must be sorted.
Returns
-------
... | python | def sorted_groupby(df, groupby):
"""
Perform a groupby on a DataFrame using a specific column
and assuming that that column is sorted.
Parameters
----------
df : pandas.DataFrame
groupby : object
Column name on which to groupby. This column must be sorted.
Returns
-------
... | [
"def",
"sorted_groupby",
"(",
"df",
",",
"groupby",
")",
":",
"start",
"=",
"0",
"prev",
"=",
"df",
"[",
"groupby",
"]",
".",
"iloc",
"[",
"start",
"]",
"for",
"i",
",",
"x",
"in",
"enumerate",
"(",
"df",
"[",
"groupby",
"]",
")",
":",
"if",
"x... | Perform a groupby on a DataFrame using a specific column
and assuming that that column is sorted.
Parameters
----------
df : pandas.DataFrame
groupby : object
Column name on which to groupby. This column must be sorted.
Returns
-------
generator
Yields pairs of group_na... | [
"Perform",
"a",
"groupby",
"on",
"a",
"DataFrame",
"using",
"a",
"specific",
"column",
"and",
"assuming",
"that",
"that",
"column",
"is",
"sorted",
"."
] | train | https://github.com/UDST/urbansim/blob/79f815a6503e109f50be270cee92d0f4a34f49ef/urbansim/models/util.py#L230-L255 |
UDST/urbansim | urbansim/models/util.py | columns_in_filters | def columns_in_filters(filters):
"""
Returns a list of the columns used in a set of query filters.
Parameters
----------
filters : list of str or str
List of the filters as passed passed to ``apply_filter_query``.
Returns
-------
columns : list of str
List of all the st... | python | def columns_in_filters(filters):
"""
Returns a list of the columns used in a set of query filters.
Parameters
----------
filters : list of str or str
List of the filters as passed passed to ``apply_filter_query``.
Returns
-------
columns : list of str
List of all the st... | [
"def",
"columns_in_filters",
"(",
"filters",
")",
":",
"if",
"not",
"filters",
":",
"return",
"[",
"]",
"if",
"not",
"isinstance",
"(",
"filters",
",",
"str",
")",
":",
"filters",
"=",
"' '",
".",
"join",
"(",
"filters",
")",
"columns",
"=",
"[",
"]"... | Returns a list of the columns used in a set of query filters.
Parameters
----------
filters : list of str or str
List of the filters as passed passed to ``apply_filter_query``.
Returns
-------
columns : list of str
List of all the strings mentioned in the filters. | [
"Returns",
"a",
"list",
"of",
"the",
"columns",
"used",
"in",
"a",
"set",
"of",
"query",
"filters",
"."
] | train | https://github.com/UDST/urbansim/blob/79f815a6503e109f50be270cee92d0f4a34f49ef/urbansim/models/util.py#L258-L286 |
UDST/urbansim | urbansim/models/util.py | _tokens_from_patsy | def _tokens_from_patsy(node):
"""
Yields all the individual tokens from within a patsy formula
as parsed by patsy.parse_formula.parse_formula.
Parameters
----------
node : patsy.parse_formula.ParseNode
"""
for n in node.args:
for t in _tokens_from_patsy(n):
yield t
... | python | def _tokens_from_patsy(node):
"""
Yields all the individual tokens from within a patsy formula
as parsed by patsy.parse_formula.parse_formula.
Parameters
----------
node : patsy.parse_formula.ParseNode
"""
for n in node.args:
for t in _tokens_from_patsy(n):
yield t
... | [
"def",
"_tokens_from_patsy",
"(",
"node",
")",
":",
"for",
"n",
"in",
"node",
".",
"args",
":",
"for",
"t",
"in",
"_tokens_from_patsy",
"(",
"n",
")",
":",
"yield",
"t",
"if",
"node",
".",
"token",
":",
"yield",
"node",
".",
"token"
] | Yields all the individual tokens from within a patsy formula
as parsed by patsy.parse_formula.parse_formula.
Parameters
----------
node : patsy.parse_formula.ParseNode | [
"Yields",
"all",
"the",
"individual",
"tokens",
"from",
"within",
"a",
"patsy",
"formula",
"as",
"parsed",
"by",
"patsy",
".",
"parse_formula",
".",
"parse_formula",
"."
] | train | https://github.com/UDST/urbansim/blob/79f815a6503e109f50be270cee92d0f4a34f49ef/urbansim/models/util.py#L289-L304 |
UDST/urbansim | urbansim/models/util.py | columns_in_formula | def columns_in_formula(formula):
"""
Returns the names of all the columns used in a patsy formula.
Parameters
----------
formula : str, iterable, or dict
Any formula construction supported by ``str_model_expression``.
Returns
-------
columns : list of str
"""
if formul... | python | def columns_in_formula(formula):
"""
Returns the names of all the columns used in a patsy formula.
Parameters
----------
formula : str, iterable, or dict
Any formula construction supported by ``str_model_expression``.
Returns
-------
columns : list of str
"""
if formul... | [
"def",
"columns_in_formula",
"(",
"formula",
")",
":",
"if",
"formula",
"is",
"None",
":",
"return",
"[",
"]",
"formula",
"=",
"str_model_expression",
"(",
"formula",
",",
"add_constant",
"=",
"False",
")",
"columns",
"=",
"[",
"]",
"tokens",
"=",
"map",
... | Returns the names of all the columns used in a patsy formula.
Parameters
----------
formula : str, iterable, or dict
Any formula construction supported by ``str_model_expression``.
Returns
-------
columns : list of str | [
"Returns",
"the",
"names",
"of",
"all",
"the",
"columns",
"used",
"in",
"a",
"patsy",
"formula",
"."
] | train | https://github.com/UDST/urbansim/blob/79f815a6503e109f50be270cee92d0f4a34f49ef/urbansim/models/util.py#L307-L347 |
UDST/urbansim | urbansim/models/regression.py | fit_model | def fit_model(df, filters, model_expression):
"""
Use statsmodels OLS to construct a model relation.
Parameters
----------
df : pandas.DataFrame
Data to use for fit. Should contain all the columns
referenced in the `model_expression`.
filters : list of str
Any filters to... | python | def fit_model(df, filters, model_expression):
"""
Use statsmodels OLS to construct a model relation.
Parameters
----------
df : pandas.DataFrame
Data to use for fit. Should contain all the columns
referenced in the `model_expression`.
filters : list of str
Any filters to... | [
"def",
"fit_model",
"(",
"df",
",",
"filters",
",",
"model_expression",
")",
":",
"df",
"=",
"util",
".",
"apply_filter_query",
"(",
"df",
",",
"filters",
")",
"model",
"=",
"smf",
".",
"ols",
"(",
"formula",
"=",
"model_expression",
",",
"data",
"=",
... | Use statsmodels OLS to construct a model relation.
Parameters
----------
df : pandas.DataFrame
Data to use for fit. Should contain all the columns
referenced in the `model_expression`.
filters : list of str
Any filters to apply before doing the model fit.
model_expression : ... | [
"Use",
"statsmodels",
"OLS",
"to",
"construct",
"a",
"model",
"relation",
"."
] | train | https://github.com/UDST/urbansim/blob/79f815a6503e109f50be270cee92d0f4a34f49ef/urbansim/models/regression.py#L25-L55 |
UDST/urbansim | urbansim/models/regression.py | predict | def predict(df, filters, model_fit, ytransform=None):
"""
Apply model to new data to predict new dependent values.
Parameters
----------
df : pandas.DataFrame
filters : list of str
Any filters to apply before doing prediction.
model_fit : statsmodels.regression.linear_model.OLSResul... | python | def predict(df, filters, model_fit, ytransform=None):
"""
Apply model to new data to predict new dependent values.
Parameters
----------
df : pandas.DataFrame
filters : list of str
Any filters to apply before doing prediction.
model_fit : statsmodels.regression.linear_model.OLSResul... | [
"def",
"predict",
"(",
"df",
",",
"filters",
",",
"model_fit",
",",
"ytransform",
"=",
"None",
")",
":",
"df",
"=",
"util",
".",
"apply_filter_query",
"(",
"df",
",",
"filters",
")",
"with",
"log_start_finish",
"(",
"'statsmodels predict'",
",",
"logger",
... | Apply model to new data to predict new dependent values.
Parameters
----------
df : pandas.DataFrame
filters : list of str
Any filters to apply before doing prediction.
model_fit : statsmodels.regression.linear_model.OLSResults
Result of model estimation.
ytransform : callable, ... | [
"Apply",
"model",
"to",
"new",
"data",
"to",
"predict",
"new",
"dependent",
"values",
"."
] | train | https://github.com/UDST/urbansim/blob/79f815a6503e109f50be270cee92d0f4a34f49ef/urbansim/models/regression.py#L58-L97 |
UDST/urbansim | urbansim/models/regression.py | _model_fit_to_table | def _model_fit_to_table(fit):
"""
Produce a pandas DataFrame of model fit results from a statsmodels
fit result object.
Parameters
----------
fit : statsmodels.regression.linear_model.RegressionResults
Returns
-------
fit_parameters : pandas.DataFrame
Will have columns 'Coe... | python | def _model_fit_to_table(fit):
"""
Produce a pandas DataFrame of model fit results from a statsmodels
fit result object.
Parameters
----------
fit : statsmodels.regression.linear_model.RegressionResults
Returns
-------
fit_parameters : pandas.DataFrame
Will have columns 'Coe... | [
"def",
"_model_fit_to_table",
"(",
"fit",
")",
":",
"fit_parameters",
"=",
"pd",
".",
"DataFrame",
"(",
"{",
"'Coefficient'",
":",
"fit",
".",
"params",
",",
"'Std. Error'",
":",
"fit",
".",
"bse",
",",
"'T-Score'",
":",
"fit",
".",
"tvalues",
"}",
")",
... | Produce a pandas DataFrame of model fit results from a statsmodels
fit result object.
Parameters
----------
fit : statsmodels.regression.linear_model.RegressionResults
Returns
-------
fit_parameters : pandas.DataFrame
Will have columns 'Coefficient', 'Std. Error', and 'T-Score'.
... | [
"Produce",
"a",
"pandas",
"DataFrame",
"of",
"model",
"fit",
"results",
"from",
"a",
"statsmodels",
"fit",
"result",
"object",
"."
] | train | https://github.com/UDST/urbansim/blob/79f815a6503e109f50be270cee92d0f4a34f49ef/urbansim/models/regression.py#L178-L204 |
UDST/urbansim | urbansim/models/regression.py | _FakeRegressionResults.predict | def predict(self, data):
"""
Predict new values by running data through the fit model.
Parameters
----------
data : pandas.DataFrame
Table with columns corresponding to the RHS of `model_expression`.
Returns
-------
predicted : ndarray
... | python | def predict(self, data):
"""
Predict new values by running data through the fit model.
Parameters
----------
data : pandas.DataFrame
Table with columns corresponding to the RHS of `model_expression`.
Returns
-------
predicted : ndarray
... | [
"def",
"predict",
"(",
"self",
",",
"data",
")",
":",
"with",
"log_start_finish",
"(",
"'_FakeRegressionResults prediction'",
",",
"logger",
")",
":",
"model_design",
"=",
"dmatrix",
"(",
"self",
".",
"_rhs",
",",
"data",
"=",
"data",
",",
"return_type",
"="... | Predict new values by running data through the fit model.
Parameters
----------
data : pandas.DataFrame
Table with columns corresponding to the RHS of `model_expression`.
Returns
-------
predicted : ndarray
Array of predicted values. | [
"Predict",
"new",
"values",
"by",
"running",
"data",
"through",
"the",
"fit",
"model",
"."
] | train | https://github.com/UDST/urbansim/blob/79f815a6503e109f50be270cee92d0f4a34f49ef/urbansim/models/regression.py#L157-L175 |
UDST/urbansim | urbansim/models/regression.py | RegressionModel.from_yaml | def from_yaml(cls, yaml_str=None, str_or_buffer=None):
"""
Create a RegressionModel instance from a saved YAML configuration.
Arguments are mutually exclusive.
Parameters
----------
yaml_str : str, optional
A YAML string from which to load model.
str_... | python | def from_yaml(cls, yaml_str=None, str_or_buffer=None):
"""
Create a RegressionModel instance from a saved YAML configuration.
Arguments are mutually exclusive.
Parameters
----------
yaml_str : str, optional
A YAML string from which to load model.
str_... | [
"def",
"from_yaml",
"(",
"cls",
",",
"yaml_str",
"=",
"None",
",",
"str_or_buffer",
"=",
"None",
")",
":",
"cfg",
"=",
"yamlio",
".",
"yaml_to_dict",
"(",
"yaml_str",
",",
"str_or_buffer",
")",
"model",
"=",
"cls",
"(",
"cfg",
"[",
"'fit_filters'",
"]",
... | Create a RegressionModel instance from a saved YAML configuration.
Arguments are mutually exclusive.
Parameters
----------
yaml_str : str, optional
A YAML string from which to load model.
str_or_buffer : str or file like, optional
File name or buffer from... | [
"Create",
"a",
"RegressionModel",
"instance",
"from",
"a",
"saved",
"YAML",
"configuration",
".",
"Arguments",
"are",
"mutually",
"exclusive",
"."
] | train | https://github.com/UDST/urbansim/blob/79f815a6503e109f50be270cee92d0f4a34f49ef/urbansim/models/regression.py#L260-L298 |
UDST/urbansim | urbansim/models/regression.py | RegressionModel.fit | def fit(self, data, debug=False):
"""
Fit the model to data and store/return the results.
Parameters
----------
data : pandas.DataFrame
Data to use for fitting the model. Must contain all the
columns referenced by the `model_expression`.
debug : b... | python | def fit(self, data, debug=False):
"""
Fit the model to data and store/return the results.
Parameters
----------
data : pandas.DataFrame
Data to use for fitting the model. Must contain all the
columns referenced by the `model_expression`.
debug : b... | [
"def",
"fit",
"(",
"self",
",",
"data",
",",
"debug",
"=",
"False",
")",
":",
"with",
"log_start_finish",
"(",
"'fitting model {}'",
".",
"format",
"(",
"self",
".",
"name",
")",
",",
"logger",
")",
":",
"fit",
"=",
"fit_model",
"(",
"data",
",",
"se... | Fit the model to data and store/return the results.
Parameters
----------
data : pandas.DataFrame
Data to use for fitting the model. Must contain all the
columns referenced by the `model_expression`.
debug : bool
If debug is set to true, this sets the... | [
"Fit",
"the",
"model",
"to",
"data",
"and",
"store",
"/",
"return",
"the",
"results",
"."
] | train | https://github.com/UDST/urbansim/blob/79f815a6503e109f50be270cee92d0f4a34f49ef/urbansim/models/regression.py#L309-L346 |
UDST/urbansim | urbansim/models/regression.py | RegressionModel.report_fit | def report_fit(self):
"""
Print a report of the fit results.
"""
if not self.fitted:
print('Model not yet fit.')
return
print('R-Squared: {0:.3f}'.format(self.model_fit.rsquared))
print('Adj. R-Squared: {0:.3f}'.format(self.model_fit.rsquared_adj... | python | def report_fit(self):
"""
Print a report of the fit results.
"""
if not self.fitted:
print('Model not yet fit.')
return
print('R-Squared: {0:.3f}'.format(self.model_fit.rsquared))
print('Adj. R-Squared: {0:.3f}'.format(self.model_fit.rsquared_adj... | [
"def",
"report_fit",
"(",
"self",
")",
":",
"if",
"not",
"self",
".",
"fitted",
":",
"print",
"(",
"'Model not yet fit.'",
")",
"return",
"print",
"(",
"'R-Squared: {0:.3f}'",
".",
"format",
"(",
"self",
".",
"model_fit",
".",
"rsquared",
")",
")",
"print"... | Print a report of the fit results. | [
"Print",
"a",
"report",
"of",
"the",
"fit",
"results",
"."
] | train | https://github.com/UDST/urbansim/blob/79f815a6503e109f50be270cee92d0f4a34f49ef/urbansim/models/regression.py#L364-L388 |
UDST/urbansim | urbansim/models/regression.py | RegressionModel.predict | def predict(self, data):
"""
Predict a new data set based on an estimated model.
Parameters
----------
data : pandas.DataFrame
Data to use for prediction. Must contain all the columns
referenced by the right-hand side of the `model_expression`.
R... | python | def predict(self, data):
"""
Predict a new data set based on an estimated model.
Parameters
----------
data : pandas.DataFrame
Data to use for prediction. Must contain all the columns
referenced by the right-hand side of the `model_expression`.
R... | [
"def",
"predict",
"(",
"self",
",",
"data",
")",
":",
"self",
".",
"assert_fitted",
"(",
")",
"with",
"log_start_finish",
"(",
"'predicting model {}'",
".",
"format",
"(",
"self",
".",
"name",
")",
",",
"logger",
")",
":",
"return",
"predict",
"(",
"data... | Predict a new data set based on an estimated model.
Parameters
----------
data : pandas.DataFrame
Data to use for prediction. Must contain all the columns
referenced by the right-hand side of the `model_expression`.
Returns
-------
result : panda... | [
"Predict",
"a",
"new",
"data",
"set",
"based",
"on",
"an",
"estimated",
"model",
"."
] | train | https://github.com/UDST/urbansim/blob/79f815a6503e109f50be270cee92d0f4a34f49ef/urbansim/models/regression.py#L390-L410 |
UDST/urbansim | urbansim/models/regression.py | RegressionModel.to_dict | def to_dict(self):
"""
Returns a dictionary representation of a RegressionModel instance.
"""
d = {
'model_type': 'regression',
'name': self.name,
'fit_filters': self.fit_filters,
'predict_filters': self.predict_filters,
'model... | python | def to_dict(self):
"""
Returns a dictionary representation of a RegressionModel instance.
"""
d = {
'model_type': 'regression',
'name': self.name,
'fit_filters': self.fit_filters,
'predict_filters': self.predict_filters,
'model... | [
"def",
"to_dict",
"(",
"self",
")",
":",
"d",
"=",
"{",
"'model_type'",
":",
"'regression'",
",",
"'name'",
":",
"self",
".",
"name",
",",
"'fit_filters'",
":",
"self",
".",
"fit_filters",
",",
"'predict_filters'",
":",
"self",
".",
"predict_filters",
",",... | Returns a dictionary representation of a RegressionModel instance. | [
"Returns",
"a",
"dictionary",
"representation",
"of",
"a",
"RegressionModel",
"instance",
"."
] | train | https://github.com/UDST/urbansim/blob/79f815a6503e109f50be270cee92d0f4a34f49ef/urbansim/models/regression.py#L412-L436 |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.