id int32 0 252k | repo stringlengths 7 55 | path stringlengths 4 127 | func_name stringlengths 1 88 | original_string stringlengths 75 19.8k | language stringclasses 1
value | code stringlengths 75 19.8k | code_tokens list | docstring stringlengths 3 17.3k | docstring_tokens list | sha stringlengths 40 40 | url stringlengths 87 242 |
|---|---|---|---|---|---|---|---|---|---|---|---|
800 | aegirhall/console-menu | consolemenu/validators/regex.py | RegexValidator.validate | def validate(self, input_string):
"""
Validate input_string against a regex pattern
:return: True if match / False otherwise
"""
validation_result = False
try:
validation_result = bool(match(pattern=self.pattern, string=input_string))
except TypeError... | python | def validate(self, input_string):
"""
Validate input_string against a regex pattern
:return: True if match / False otherwise
"""
validation_result = False
try:
validation_result = bool(match(pattern=self.pattern, string=input_string))
except TypeError... | [
"def",
"validate",
"(",
"self",
",",
"input_string",
")",
":",
"validation_result",
"=",
"False",
"try",
":",
"validation_result",
"=",
"bool",
"(",
"match",
"(",
"pattern",
"=",
"self",
".",
"pattern",
",",
"string",
"=",
"input_string",
")",
")",
"except... | Validate input_string against a regex pattern
:return: True if match / False otherwise | [
"Validate",
"input_string",
"against",
"a",
"regex",
"pattern"
] | 1a28959d6f1dd6ac79c87b11efd8529d05532422 | https://github.com/aegirhall/console-menu/blob/1a28959d6f1dd6ac79c87b11efd8529d05532422/consolemenu/validators/regex.py#L16-L30 |
801 | aegirhall/console-menu | consolemenu/multiselect_menu.py | MultiSelectMenu.process_user_input | def process_user_input(self):
"""
This overrides the method in ConsoleMenu to allow for comma-delimited and range inputs.
Examples:
All of the following inputs would have the same result:
* 1,2,3,4
* 1-4
* 1-2,3-4
* 1 -... | python | def process_user_input(self):
"""
This overrides the method in ConsoleMenu to allow for comma-delimited and range inputs.
Examples:
All of the following inputs would have the same result:
* 1,2,3,4
* 1-4
* 1-2,3-4
* 1 -... | [
"def",
"process_user_input",
"(",
"self",
")",
":",
"user_input",
"=",
"self",
".",
"screen",
".",
"input",
"(",
")",
"try",
":",
"indexes",
"=",
"self",
".",
"__parse_range_list",
"(",
"user_input",
")",
"# Subtract 1 from each number for its actual index number",
... | This overrides the method in ConsoleMenu to allow for comma-delimited and range inputs.
Examples:
All of the following inputs would have the same result:
* 1,2,3,4
* 1-4
* 1-2,3-4
* 1 - 4
* 1, 2, 3, 4
Raises:
... | [
"This",
"overrides",
"the",
"method",
"in",
"ConsoleMenu",
"to",
"allow",
"for",
"comma",
"-",
"delimited",
"and",
"range",
"inputs",
"."
] | 1a28959d6f1dd6ac79c87b11efd8529d05532422 | https://github.com/aegirhall/console-menu/blob/1a28959d6f1dd6ac79c87b11efd8529d05532422/consolemenu/multiselect_menu.py#L43-L67 |
802 | aegirhall/console-menu | consolemenu/console_menu.py | ConsoleMenu.remove_item | def remove_item(self, item):
"""
Remove the specified item from the menu.
Args:
item (MenuItem): the item to be removed.
Returns:
bool: True if the item was removed; False otherwise.
"""
for idx, _item in enumerate(self.items):
if ite... | python | def remove_item(self, item):
"""
Remove the specified item from the menu.
Args:
item (MenuItem): the item to be removed.
Returns:
bool: True if the item was removed; False otherwise.
"""
for idx, _item in enumerate(self.items):
if ite... | [
"def",
"remove_item",
"(",
"self",
",",
"item",
")",
":",
"for",
"idx",
",",
"_item",
"in",
"enumerate",
"(",
"self",
".",
"items",
")",
":",
"if",
"item",
"==",
"_item",
":",
"del",
"self",
".",
"items",
"[",
"idx",
"]",
"return",
"True",
"return"... | Remove the specified item from the menu.
Args:
item (MenuItem): the item to be removed.
Returns:
bool: True if the item was removed; False otherwise. | [
"Remove",
"the",
"specified",
"item",
"from",
"the",
"menu",
"."
] | 1a28959d6f1dd6ac79c87b11efd8529d05532422 | https://github.com/aegirhall/console-menu/blob/1a28959d6f1dd6ac79c87b11efd8529d05532422/consolemenu/console_menu.py#L116-L130 |
803 | aegirhall/console-menu | consolemenu/console_menu.py | ConsoleMenu.remove_exit | def remove_exit(self):
"""
Remove the exit item if necessary. Used to make sure we only remove the exit item, not something else.
Returns:
bool: True if item needed to be removed, False otherwise.
"""
if self.items:
if self.items[-1] is self.exit_item:
... | python | def remove_exit(self):
"""
Remove the exit item if necessary. Used to make sure we only remove the exit item, not something else.
Returns:
bool: True if item needed to be removed, False otherwise.
"""
if self.items:
if self.items[-1] is self.exit_item:
... | [
"def",
"remove_exit",
"(",
"self",
")",
":",
"if",
"self",
".",
"items",
":",
"if",
"self",
".",
"items",
"[",
"-",
"1",
"]",
"is",
"self",
".",
"exit_item",
":",
"del",
"self",
".",
"items",
"[",
"-",
"1",
"]",
"return",
"True",
"return",
"False... | Remove the exit item if necessary. Used to make sure we only remove the exit item, not something else.
Returns:
bool: True if item needed to be removed, False otherwise. | [
"Remove",
"the",
"exit",
"item",
"if",
"necessary",
".",
"Used",
"to",
"make",
"sure",
"we",
"only",
"remove",
"the",
"exit",
"item",
"not",
"something",
"else",
"."
] | 1a28959d6f1dd6ac79c87b11efd8529d05532422 | https://github.com/aegirhall/console-menu/blob/1a28959d6f1dd6ac79c87b11efd8529d05532422/consolemenu/console_menu.py#L144-L155 |
804 | aegirhall/console-menu | consolemenu/console_menu.py | ConsoleMenu.draw | def draw(self):
"""
Refresh the screen and redraw the menu. Should be called whenever something changes that needs to be redrawn.
"""
self.screen.printf(self.formatter.format(title=self.title, subtitle=self.subtitle, items=self.items,
prol... | python | def draw(self):
"""
Refresh the screen and redraw the menu. Should be called whenever something changes that needs to be redrawn.
"""
self.screen.printf(self.formatter.format(title=self.title, subtitle=self.subtitle, items=self.items,
prol... | [
"def",
"draw",
"(",
"self",
")",
":",
"self",
".",
"screen",
".",
"printf",
"(",
"self",
".",
"formatter",
".",
"format",
"(",
"title",
"=",
"self",
".",
"title",
",",
"subtitle",
"=",
"self",
".",
"subtitle",
",",
"items",
"=",
"self",
".",
"items... | Refresh the screen and redraw the menu. Should be called whenever something changes that needs to be redrawn. | [
"Refresh",
"the",
"screen",
"and",
"redraw",
"the",
"menu",
".",
"Should",
"be",
"called",
"whenever",
"something",
"changes",
"that",
"needs",
"to",
"be",
"redrawn",
"."
] | 1a28959d6f1dd6ac79c87b11efd8529d05532422 | https://github.com/aegirhall/console-menu/blob/1a28959d6f1dd6ac79c87b11efd8529d05532422/consolemenu/console_menu.py#L226-L231 |
805 | aegirhall/console-menu | consolemenu/console_menu.py | ConsoleMenu.process_user_input | def process_user_input(self):
"""
Gets the next single character and decides what to do with it
"""
user_input = self.get_input()
try:
num = int(user_input)
except Exception:
return
if 0 < num < len(self.items) + 1:
self.curren... | python | def process_user_input(self):
"""
Gets the next single character and decides what to do with it
"""
user_input = self.get_input()
try:
num = int(user_input)
except Exception:
return
if 0 < num < len(self.items) + 1:
self.curren... | [
"def",
"process_user_input",
"(",
"self",
")",
":",
"user_input",
"=",
"self",
".",
"get_input",
"(",
")",
"try",
":",
"num",
"=",
"int",
"(",
"user_input",
")",
"except",
"Exception",
":",
"return",
"if",
"0",
"<",
"num",
"<",
"len",
"(",
"self",
".... | Gets the next single character and decides what to do with it | [
"Gets",
"the",
"next",
"single",
"character",
"and",
"decides",
"what",
"to",
"do",
"with",
"it"
] | 1a28959d6f1dd6ac79c87b11efd8529d05532422 | https://github.com/aegirhall/console-menu/blob/1a28959d6f1dd6ac79c87b11efd8529d05532422/consolemenu/console_menu.py#L297-L311 |
806 | aegirhall/console-menu | consolemenu/console_menu.py | ConsoleMenu.go_down | def go_down(self):
"""
Go down one, wrap to beginning if necessary
"""
if self.current_option < len(self.items) - 1:
self.current_option += 1
else:
self.current_option = 0
self.draw() | python | def go_down(self):
"""
Go down one, wrap to beginning if necessary
"""
if self.current_option < len(self.items) - 1:
self.current_option += 1
else:
self.current_option = 0
self.draw() | [
"def",
"go_down",
"(",
"self",
")",
":",
"if",
"self",
".",
"current_option",
"<",
"len",
"(",
"self",
".",
"items",
")",
"-",
"1",
":",
"self",
".",
"current_option",
"+=",
"1",
"else",
":",
"self",
".",
"current_option",
"=",
"0",
"self",
".",
"d... | Go down one, wrap to beginning if necessary | [
"Go",
"down",
"one",
"wrap",
"to",
"beginning",
"if",
"necessary"
] | 1a28959d6f1dd6ac79c87b11efd8529d05532422 | https://github.com/aegirhall/console-menu/blob/1a28959d6f1dd6ac79c87b11efd8529d05532422/consolemenu/console_menu.py#L323-L331 |
807 | aegirhall/console-menu | consolemenu/console_menu.py | ConsoleMenu.go_up | def go_up(self):
"""
Go up one, wrap to end if necessary
"""
if self.current_option > 0:
self.current_option += -1
else:
self.current_option = len(self.items) - 1
self.draw() | python | def go_up(self):
"""
Go up one, wrap to end if necessary
"""
if self.current_option > 0:
self.current_option += -1
else:
self.current_option = len(self.items) - 1
self.draw() | [
"def",
"go_up",
"(",
"self",
")",
":",
"if",
"self",
".",
"current_option",
">",
"0",
":",
"self",
".",
"current_option",
"+=",
"-",
"1",
"else",
":",
"self",
".",
"current_option",
"=",
"len",
"(",
"self",
".",
"items",
")",
"-",
"1",
"self",
".",... | Go up one, wrap to end if necessary | [
"Go",
"up",
"one",
"wrap",
"to",
"end",
"if",
"necessary"
] | 1a28959d6f1dd6ac79c87b11efd8529d05532422 | https://github.com/aegirhall/console-menu/blob/1a28959d6f1dd6ac79c87b11efd8529d05532422/consolemenu/console_menu.py#L333-L341 |
808 | aegirhall/console-menu | consolemenu/selection_menu.py | SelectionMenu.get_selection | def get_selection(cls, strings, title="Select an option", subtitle=None, exit_option=True, _menu=None):
"""
Single-method way of getting a selection out of a list of strings.
Args:
strings (:obj:`list` of :obj:`str`): The list of strings this menu should be built from.
... | python | def get_selection(cls, strings, title="Select an option", subtitle=None, exit_option=True, _menu=None):
"""
Single-method way of getting a selection out of a list of strings.
Args:
strings (:obj:`list` of :obj:`str`): The list of strings this menu should be built from.
... | [
"def",
"get_selection",
"(",
"cls",
",",
"strings",
",",
"title",
"=",
"\"Select an option\"",
",",
"subtitle",
"=",
"None",
",",
"exit_option",
"=",
"True",
",",
"_menu",
"=",
"None",
")",
":",
"menu",
"=",
"cls",
"(",
"strings",
",",
"title",
",",
"s... | Single-method way of getting a selection out of a list of strings.
Args:
strings (:obj:`list` of :obj:`str`): The list of strings this menu should be built from.
title (str): The title of the menu.
subtitle (str): The subtitle of the menu.
exit_option (bool): Sp... | [
"Single",
"-",
"method",
"way",
"of",
"getting",
"a",
"selection",
"out",
"of",
"a",
"list",
"of",
"strings",
"."
] | 1a28959d6f1dd6ac79c87b11efd8529d05532422 | https://github.com/aegirhall/console-menu/blob/1a28959d6f1dd6ac79c87b11efd8529d05532422/consolemenu/selection_menu.py#L29-L50 |
809 | timothyb0912/pylogit | pylogit/choice_tools.py | ensure_object_is_ordered_dict | def ensure_object_is_ordered_dict(item, title):
"""
Checks that the item is an OrderedDict. If not, raises ValueError.
"""
assert isinstance(title, str)
if not isinstance(item, OrderedDict):
msg = "{} must be an OrderedDict. {} passed instead."
raise TypeError(msg.format(title, type... | python | def ensure_object_is_ordered_dict(item, title):
"""
Checks that the item is an OrderedDict. If not, raises ValueError.
"""
assert isinstance(title, str)
if not isinstance(item, OrderedDict):
msg = "{} must be an OrderedDict. {} passed instead."
raise TypeError(msg.format(title, type... | [
"def",
"ensure_object_is_ordered_dict",
"(",
"item",
",",
"title",
")",
":",
"assert",
"isinstance",
"(",
"title",
",",
"str",
")",
"if",
"not",
"isinstance",
"(",
"item",
",",
"OrderedDict",
")",
":",
"msg",
"=",
"\"{} must be an OrderedDict. {} passed instead.\"... | Checks that the item is an OrderedDict. If not, raises ValueError. | [
"Checks",
"that",
"the",
"item",
"is",
"an",
"OrderedDict",
".",
"If",
"not",
"raises",
"ValueError",
"."
] | f83b0fd6debaa7358d87c3828428f6d4ead71357 | https://github.com/timothyb0912/pylogit/blob/f83b0fd6debaa7358d87c3828428f6d4ead71357/pylogit/choice_tools.py#L73-L83 |
810 | timothyb0912/pylogit | pylogit/choice_tools.py | ensure_object_is_string | def ensure_object_is_string(item, title):
"""
Checks that the item is a string. If not, raises ValueError.
"""
assert isinstance(title, str)
if not isinstance(item, str):
msg = "{} must be a string. {} passed instead."
raise TypeError(msg.format(title, type(item)))
return None | python | def ensure_object_is_string(item, title):
"""
Checks that the item is a string. If not, raises ValueError.
"""
assert isinstance(title, str)
if not isinstance(item, str):
msg = "{} must be a string. {} passed instead."
raise TypeError(msg.format(title, type(item)))
return None | [
"def",
"ensure_object_is_string",
"(",
"item",
",",
"title",
")",
":",
"assert",
"isinstance",
"(",
"title",
",",
"str",
")",
"if",
"not",
"isinstance",
"(",
"item",
",",
"str",
")",
":",
"msg",
"=",
"\"{} must be a string. {} passed instead.\"",
"raise",
"Typ... | Checks that the item is a string. If not, raises ValueError. | [
"Checks",
"that",
"the",
"item",
"is",
"a",
"string",
".",
"If",
"not",
"raises",
"ValueError",
"."
] | f83b0fd6debaa7358d87c3828428f6d4ead71357 | https://github.com/timothyb0912/pylogit/blob/f83b0fd6debaa7358d87c3828428f6d4ead71357/pylogit/choice_tools.py#L86-L96 |
811 | timothyb0912/pylogit | pylogit/choice_tools.py | ensure_object_is_ndarray | def ensure_object_is_ndarray(item, title):
"""
Ensures that a given mapping matrix is a dense numpy array. Raises a
helpful TypeError if otherwise.
"""
assert isinstance(title, str)
if not isinstance(item, np.ndarray):
msg = "{} must be a np.ndarray. {} passed instead."
raise Ty... | python | def ensure_object_is_ndarray(item, title):
"""
Ensures that a given mapping matrix is a dense numpy array. Raises a
helpful TypeError if otherwise.
"""
assert isinstance(title, str)
if not isinstance(item, np.ndarray):
msg = "{} must be a np.ndarray. {} passed instead."
raise Ty... | [
"def",
"ensure_object_is_ndarray",
"(",
"item",
",",
"title",
")",
":",
"assert",
"isinstance",
"(",
"title",
",",
"str",
")",
"if",
"not",
"isinstance",
"(",
"item",
",",
"np",
".",
"ndarray",
")",
":",
"msg",
"=",
"\"{} must be a np.ndarray. {} passed instea... | Ensures that a given mapping matrix is a dense numpy array. Raises a
helpful TypeError if otherwise. | [
"Ensures",
"that",
"a",
"given",
"mapping",
"matrix",
"is",
"a",
"dense",
"numpy",
"array",
".",
"Raises",
"a",
"helpful",
"TypeError",
"if",
"otherwise",
"."
] | f83b0fd6debaa7358d87c3828428f6d4ead71357 | https://github.com/timothyb0912/pylogit/blob/f83b0fd6debaa7358d87c3828428f6d4ead71357/pylogit/choice_tools.py#L99-L110 |
812 | timothyb0912/pylogit | pylogit/choice_tools.py | ensure_columns_are_in_dataframe | def ensure_columns_are_in_dataframe(columns,
dataframe,
col_title='',
data_title='data'):
"""
Checks whether each column in `columns` is in `dataframe`. Raises
ValueError if any of the columns are not... | python | def ensure_columns_are_in_dataframe(columns,
dataframe,
col_title='',
data_title='data'):
"""
Checks whether each column in `columns` is in `dataframe`. Raises
ValueError if any of the columns are not... | [
"def",
"ensure_columns_are_in_dataframe",
"(",
"columns",
",",
"dataframe",
",",
"col_title",
"=",
"''",
",",
"data_title",
"=",
"'data'",
")",
":",
"# Make sure columns is an iterable",
"assert",
"isinstance",
"(",
"columns",
",",
"Iterable",
")",
"# Make sure datafr... | Checks whether each column in `columns` is in `dataframe`. Raises
ValueError if any of the columns are not in the dataframe.
Parameters
----------
columns : list of strings.
Each string should represent a column heading in dataframe.
dataframe : pandas DataFrame.
Dataframe containin... | [
"Checks",
"whether",
"each",
"column",
"in",
"columns",
"is",
"in",
"dataframe",
".",
"Raises",
"ValueError",
"if",
"any",
"of",
"the",
"columns",
"are",
"not",
"in",
"the",
"dataframe",
"."
] | f83b0fd6debaa7358d87c3828428f6d4ead71357 | https://github.com/timothyb0912/pylogit/blob/f83b0fd6debaa7358d87c3828428f6d4ead71357/pylogit/choice_tools.py#L113-L156 |
813 | timothyb0912/pylogit | pylogit/choice_tools.py | check_argument_type | def check_argument_type(long_form, specification_dict):
"""
Ensures that long_form is a pandas dataframe and that specification_dict
is an OrderedDict, raising a ValueError otherwise.
Parameters
----------
long_form : pandas dataframe.
Contains one row for each available alternative, fo... | python | def check_argument_type(long_form, specification_dict):
"""
Ensures that long_form is a pandas dataframe and that specification_dict
is an OrderedDict, raising a ValueError otherwise.
Parameters
----------
long_form : pandas dataframe.
Contains one row for each available alternative, fo... | [
"def",
"check_argument_type",
"(",
"long_form",
",",
"specification_dict",
")",
":",
"if",
"not",
"isinstance",
"(",
"long_form",
",",
"pd",
".",
"DataFrame",
")",
":",
"msg",
"=",
"\"long_form should be a pandas dataframe. It is a {}\"",
"raise",
"TypeError",
"(",
... | Ensures that long_form is a pandas dataframe and that specification_dict
is an OrderedDict, raising a ValueError otherwise.
Parameters
----------
long_form : pandas dataframe.
Contains one row for each available alternative, for each observation.
specification_dict : OrderedDict.
Ke... | [
"Ensures",
"that",
"long_form",
"is",
"a",
"pandas",
"dataframe",
"and",
"that",
"specification_dict",
"is",
"an",
"OrderedDict",
"raising",
"a",
"ValueError",
"otherwise",
"."
] | f83b0fd6debaa7358d87c3828428f6d4ead71357 | https://github.com/timothyb0912/pylogit/blob/f83b0fd6debaa7358d87c3828428f6d4ead71357/pylogit/choice_tools.py#L159-L194 |
814 | timothyb0912/pylogit | pylogit/choice_tools.py | ensure_alt_id_in_long_form | def ensure_alt_id_in_long_form(alt_id_col, long_form):
"""
Ensures alt_id_col is in long_form, and raises a ValueError if not.
Parameters
----------
alt_id_col : str.
Column name which denotes the column in `long_form` that contains the
alternative ID for each row in `long_form`.
... | python | def ensure_alt_id_in_long_form(alt_id_col, long_form):
"""
Ensures alt_id_col is in long_form, and raises a ValueError if not.
Parameters
----------
alt_id_col : str.
Column name which denotes the column in `long_form` that contains the
alternative ID for each row in `long_form`.
... | [
"def",
"ensure_alt_id_in_long_form",
"(",
"alt_id_col",
",",
"long_form",
")",
":",
"if",
"alt_id_col",
"not",
"in",
"long_form",
".",
"columns",
":",
"msg",
"=",
"\"alt_id_col == {} is not a column in long_form.\"",
"raise",
"ValueError",
"(",
"msg",
".",
"format",
... | Ensures alt_id_col is in long_form, and raises a ValueError if not.
Parameters
----------
alt_id_col : str.
Column name which denotes the column in `long_form` that contains the
alternative ID for each row in `long_form`.
long_form : pandas dataframe.
Contains one row for each a... | [
"Ensures",
"alt_id_col",
"is",
"in",
"long_form",
"and",
"raises",
"a",
"ValueError",
"if",
"not",
"."
] | f83b0fd6debaa7358d87c3828428f6d4ead71357 | https://github.com/timothyb0912/pylogit/blob/f83b0fd6debaa7358d87c3828428f6d4ead71357/pylogit/choice_tools.py#L197-L217 |
815 | timothyb0912/pylogit | pylogit/choice_tools.py | ensure_specification_cols_are_in_dataframe | def ensure_specification_cols_are_in_dataframe(specification, dataframe):
"""
Checks whether each column in `specification` is in `dataframe`. Raises
ValueError if any of the columns are not in the dataframe.
Parameters
----------
specification : OrderedDict.
Keys are a proper subset of... | python | def ensure_specification_cols_are_in_dataframe(specification, dataframe):
"""
Checks whether each column in `specification` is in `dataframe`. Raises
ValueError if any of the columns are not in the dataframe.
Parameters
----------
specification : OrderedDict.
Keys are a proper subset of... | [
"def",
"ensure_specification_cols_are_in_dataframe",
"(",
"specification",
",",
"dataframe",
")",
":",
"# Make sure specification is an OrderedDict",
"try",
":",
"assert",
"isinstance",
"(",
"specification",
",",
"OrderedDict",
")",
"except",
"AssertionError",
":",
"raise",... | Checks whether each column in `specification` is in `dataframe`. Raises
ValueError if any of the columns are not in the dataframe.
Parameters
----------
specification : OrderedDict.
Keys are a proper subset of the columns in `data`. Values are either a
list or a single string, "all_diff... | [
"Checks",
"whether",
"each",
"column",
"in",
"specification",
"is",
"in",
"dataframe",
".",
"Raises",
"ValueError",
"if",
"any",
"of",
"the",
"columns",
"are",
"not",
"in",
"the",
"dataframe",
"."
] | f83b0fd6debaa7358d87c3828428f6d4ead71357 | https://github.com/timothyb0912/pylogit/blob/f83b0fd6debaa7358d87c3828428f6d4ead71357/pylogit/choice_tools.py#L220-L264 |
816 | timothyb0912/pylogit | pylogit/choice_tools.py | check_keys_and_values_of_name_dictionary | def check_keys_and_values_of_name_dictionary(names,
specification_dict,
num_alts):
"""
Check the validity of the keys and values in the names dictionary.
Parameters
----------
names : OrderedDict, optional.
... | python | def check_keys_and_values_of_name_dictionary(names,
specification_dict,
num_alts):
"""
Check the validity of the keys and values in the names dictionary.
Parameters
----------
names : OrderedDict, optional.
... | [
"def",
"check_keys_and_values_of_name_dictionary",
"(",
"names",
",",
"specification_dict",
",",
"num_alts",
")",
":",
"if",
"names",
".",
"keys",
"(",
")",
"!=",
"specification_dict",
".",
"keys",
"(",
")",
":",
"msg",
"=",
"\"names.keys() does not equal specificat... | Check the validity of the keys and values in the names dictionary.
Parameters
----------
names : OrderedDict, optional.
Should have the same keys as `specification_dict`. For each key:
- if the corresponding value in `specification_dict` is "all_same",
then there should b... | [
"Check",
"the",
"validity",
"of",
"the",
"keys",
"and",
"values",
"in",
"the",
"names",
"dictionary",
"."
] | f83b0fd6debaa7358d87c3828428f6d4ead71357 | https://github.com/timothyb0912/pylogit/blob/f83b0fd6debaa7358d87c3828428f6d4ead71357/pylogit/choice_tools.py#L340-L417 |
817 | timothyb0912/pylogit | pylogit/choice_tools.py | ensure_all_columns_are_used | def ensure_all_columns_are_used(num_vars_accounted_for,
dataframe,
data_title='long_data'):
"""
Ensure that all of the columns from dataframe are in the list of used_cols.
Will raise a helpful UserWarning if otherwise.
Parameters
-----... | python | def ensure_all_columns_are_used(num_vars_accounted_for,
dataframe,
data_title='long_data'):
"""
Ensure that all of the columns from dataframe are in the list of used_cols.
Will raise a helpful UserWarning if otherwise.
Parameters
-----... | [
"def",
"ensure_all_columns_are_used",
"(",
"num_vars_accounted_for",
",",
"dataframe",
",",
"data_title",
"=",
"'long_data'",
")",
":",
"dataframe_vars",
"=",
"set",
"(",
"dataframe",
".",
"columns",
".",
"tolist",
"(",
")",
")",
"num_dataframe_vars",
"=",
"len",
... | Ensure that all of the columns from dataframe are in the list of used_cols.
Will raise a helpful UserWarning if otherwise.
Parameters
----------
num_vars_accounted_for : int.
Denotes the number of variables used in one's function.
dataframe : pandas dataframe.
Contains all of the da... | [
"Ensure",
"that",
"all",
"of",
"the",
"columns",
"from",
"dataframe",
"are",
"in",
"the",
"list",
"of",
"used_cols",
".",
"Will",
"raise",
"a",
"helpful",
"UserWarning",
"if",
"otherwise",
"."
] | f83b0fd6debaa7358d87c3828428f6d4ead71357 | https://github.com/timothyb0912/pylogit/blob/f83b0fd6debaa7358d87c3828428f6d4ead71357/pylogit/choice_tools.py#L420-L463 |
818 | timothyb0912/pylogit | pylogit/choice_tools.py | check_dataframe_for_duplicate_records | def check_dataframe_for_duplicate_records(obs_id_col, alt_id_col, df):
"""
Checks a cross-sectional dataframe of long-format data for duplicate
observations. Duplicate observations are defined as rows with the same
observation id value and the same alternative id value.
Parameters
----------
... | python | def check_dataframe_for_duplicate_records(obs_id_col, alt_id_col, df):
"""
Checks a cross-sectional dataframe of long-format data for duplicate
observations. Duplicate observations are defined as rows with the same
observation id value and the same alternative id value.
Parameters
----------
... | [
"def",
"check_dataframe_for_duplicate_records",
"(",
"obs_id_col",
",",
"alt_id_col",
",",
"df",
")",
":",
"if",
"df",
".",
"duplicated",
"(",
"subset",
"=",
"[",
"obs_id_col",
",",
"alt_id_col",
"]",
")",
".",
"any",
"(",
")",
":",
"msg",
"=",
"\"One or m... | Checks a cross-sectional dataframe of long-format data for duplicate
observations. Duplicate observations are defined as rows with the same
observation id value and the same alternative id value.
Parameters
----------
obs_id_col : str.
Denotes the column in `df` that contains the observatio... | [
"Checks",
"a",
"cross",
"-",
"sectional",
"dataframe",
"of",
"long",
"-",
"format",
"data",
"for",
"duplicate",
"observations",
".",
"Duplicate",
"observations",
"are",
"defined",
"as",
"rows",
"with",
"the",
"same",
"observation",
"id",
"value",
"and",
"the",... | f83b0fd6debaa7358d87c3828428f6d4ead71357 | https://github.com/timothyb0912/pylogit/blob/f83b0fd6debaa7358d87c3828428f6d4ead71357/pylogit/choice_tools.py#L466-L491 |
819 | timothyb0912/pylogit | pylogit/choice_tools.py | ensure_num_chosen_alts_equals_num_obs | def ensure_num_chosen_alts_equals_num_obs(obs_id_col, choice_col, df):
"""
Checks that the total number of recorded choices equals the total number of
observations. If this is not the case, raise helpful ValueError messages.
Parameters
----------
obs_id_col : str.
Denotes the column in ... | python | def ensure_num_chosen_alts_equals_num_obs(obs_id_col, choice_col, df):
"""
Checks that the total number of recorded choices equals the total number of
observations. If this is not the case, raise helpful ValueError messages.
Parameters
----------
obs_id_col : str.
Denotes the column in ... | [
"def",
"ensure_num_chosen_alts_equals_num_obs",
"(",
"obs_id_col",
",",
"choice_col",
",",
"df",
")",
":",
"num_obs",
"=",
"df",
"[",
"obs_id_col",
"]",
".",
"unique",
"(",
")",
".",
"shape",
"[",
"0",
"]",
"num_choices",
"=",
"df",
"[",
"choice_col",
"]",... | Checks that the total number of recorded choices equals the total number of
observations. If this is not the case, raise helpful ValueError messages.
Parameters
----------
obs_id_col : str.
Denotes the column in `df` that contains the observation ID values for
each row.
choice_col :... | [
"Checks",
"that",
"the",
"total",
"number",
"of",
"recorded",
"choices",
"equals",
"the",
"total",
"number",
"of",
"observations",
".",
"If",
"this",
"is",
"not",
"the",
"case",
"raise",
"helpful",
"ValueError",
"messages",
"."
] | f83b0fd6debaa7358d87c3828428f6d4ead71357 | https://github.com/timothyb0912/pylogit/blob/f83b0fd6debaa7358d87c3828428f6d4ead71357/pylogit/choice_tools.py#L494-L526 |
820 | timothyb0912/pylogit | pylogit/choice_tools.py | check_type_and_values_of_alt_name_dict | def check_type_and_values_of_alt_name_dict(alt_name_dict, alt_id_col, df):
"""
Ensures that `alt_name_dict` is a dictionary and that its keys are in the
alternative id column of `df`. Raises helpful errors if either condition
is not met.
Parameters
----------
alt_name_dict : dict.
A... | python | def check_type_and_values_of_alt_name_dict(alt_name_dict, alt_id_col, df):
"""
Ensures that `alt_name_dict` is a dictionary and that its keys are in the
alternative id column of `df`. Raises helpful errors if either condition
is not met.
Parameters
----------
alt_name_dict : dict.
A... | [
"def",
"check_type_and_values_of_alt_name_dict",
"(",
"alt_name_dict",
",",
"alt_id_col",
",",
"df",
")",
":",
"if",
"not",
"isinstance",
"(",
"alt_name_dict",
",",
"dict",
")",
":",
"msg",
"=",
"\"alt_name_dict should be a dictionary. Passed value was a {}\"",
"raise",
... | Ensures that `alt_name_dict` is a dictionary and that its keys are in the
alternative id column of `df`. Raises helpful errors if either condition
is not met.
Parameters
----------
alt_name_dict : dict.
A dictionary whose keys are the possible values in
`df[alt_id_col].unique()`. Th... | [
"Ensures",
"that",
"alt_name_dict",
"is",
"a",
"dictionary",
"and",
"that",
"its",
"keys",
"are",
"in",
"the",
"alternative",
"id",
"column",
"of",
"df",
".",
"Raises",
"helpful",
"errors",
"if",
"either",
"condition",
"is",
"not",
"met",
"."
] | f83b0fd6debaa7358d87c3828428f6d4ead71357 | https://github.com/timothyb0912/pylogit/blob/f83b0fd6debaa7358d87c3828428f6d4ead71357/pylogit/choice_tools.py#L529-L560 |
821 | timothyb0912/pylogit | pylogit/choice_tools.py | ensure_ridge_is_scalar_or_none | def ensure_ridge_is_scalar_or_none(ridge):
"""
Ensures that `ridge` is either None or a scalar value. Raises a helpful
TypeError otherwise.
Parameters
----------
ridge : int, float, long, or None.
Scalar value or None, determining the L2-ridge regression penalty.
Returns
------... | python | def ensure_ridge_is_scalar_or_none(ridge):
"""
Ensures that `ridge` is either None or a scalar value. Raises a helpful
TypeError otherwise.
Parameters
----------
ridge : int, float, long, or None.
Scalar value or None, determining the L2-ridge regression penalty.
Returns
------... | [
"def",
"ensure_ridge_is_scalar_or_none",
"(",
"ridge",
")",
":",
"if",
"(",
"ridge",
"is",
"not",
"None",
")",
"and",
"not",
"isinstance",
"(",
"ridge",
",",
"Number",
")",
":",
"msg_1",
"=",
"\"ridge should be None or an int, float, or long.\"",
"msg_2",
"=",
"... | Ensures that `ridge` is either None or a scalar value. Raises a helpful
TypeError otherwise.
Parameters
----------
ridge : int, float, long, or None.
Scalar value or None, determining the L2-ridge regression penalty.
Returns
-------
None. | [
"Ensures",
"that",
"ridge",
"is",
"either",
"None",
"or",
"a",
"scalar",
"value",
".",
"Raises",
"a",
"helpful",
"TypeError",
"otherwise",
"."
] | f83b0fd6debaa7358d87c3828428f6d4ead71357 | https://github.com/timothyb0912/pylogit/blob/f83b0fd6debaa7358d87c3828428f6d4ead71357/pylogit/choice_tools.py#L563-L582 |
822 | timothyb0912/pylogit | pylogit/choice_tools.py | get_original_order_unique_ids | def get_original_order_unique_ids(id_array):
"""
Get the unique id's of id_array, in their original order of appearance.
Parameters
----------
id_array : 1D ndarray.
Should contain the ids that we want to extract the unique values from.
Returns
-------
original_order_unique_ids... | python | def get_original_order_unique_ids(id_array):
"""
Get the unique id's of id_array, in their original order of appearance.
Parameters
----------
id_array : 1D ndarray.
Should contain the ids that we want to extract the unique values from.
Returns
-------
original_order_unique_ids... | [
"def",
"get_original_order_unique_ids",
"(",
"id_array",
")",
":",
"assert",
"isinstance",
"(",
"id_array",
",",
"np",
".",
"ndarray",
")",
"assert",
"len",
"(",
"id_array",
".",
"shape",
")",
"==",
"1",
"# Get the indices of the unique IDs in their order of appearanc... | Get the unique id's of id_array, in their original order of appearance.
Parameters
----------
id_array : 1D ndarray.
Should contain the ids that we want to extract the unique values from.
Returns
-------
original_order_unique_ids : 1D ndarray.
Contains the unique ids from `id_a... | [
"Get",
"the",
"unique",
"id",
"s",
"of",
"id_array",
"in",
"their",
"original",
"order",
"of",
"appearance",
"."
] | f83b0fd6debaa7358d87c3828428f6d4ead71357 | https://github.com/timothyb0912/pylogit/blob/f83b0fd6debaa7358d87c3828428f6d4ead71357/pylogit/choice_tools.py#L718-L745 |
823 | timothyb0912/pylogit | pylogit/choice_tools.py | create_sparse_mapping | def create_sparse_mapping(id_array, unique_ids=None):
"""
Will create a scipy.sparse compressed-sparse-row matrix that maps
each row represented by an element in id_array to the corresponding
value of the unique ids in id_array.
Parameters
----------
id_array : 1D ndarray of ints.
E... | python | def create_sparse_mapping(id_array, unique_ids=None):
"""
Will create a scipy.sparse compressed-sparse-row matrix that maps
each row represented by an element in id_array to the corresponding
value of the unique ids in id_array.
Parameters
----------
id_array : 1D ndarray of ints.
E... | [
"def",
"create_sparse_mapping",
"(",
"id_array",
",",
"unique_ids",
"=",
"None",
")",
":",
"# Create unique_ids if necessary",
"if",
"unique_ids",
"is",
"None",
":",
"unique_ids",
"=",
"get_original_order_unique_ids",
"(",
"id_array",
")",
"# Check function arguments for ... | Will create a scipy.sparse compressed-sparse-row matrix that maps
each row represented by an element in id_array to the corresponding
value of the unique ids in id_array.
Parameters
----------
id_array : 1D ndarray of ints.
Each element should represent some id related to the corresponding ... | [
"Will",
"create",
"a",
"scipy",
".",
"sparse",
"compressed",
"-",
"sparse",
"-",
"row",
"matrix",
"that",
"maps",
"each",
"row",
"represented",
"by",
"an",
"element",
"in",
"id_array",
"to",
"the",
"corresponding",
"value",
"of",
"the",
"unique",
"ids",
"i... | f83b0fd6debaa7358d87c3828428f6d4ead71357 | https://github.com/timothyb0912/pylogit/blob/f83b0fd6debaa7358d87c3828428f6d4ead71357/pylogit/choice_tools.py#L776-L832 |
824 | timothyb0912/pylogit | pylogit/choice_tools.py | check_wide_data_for_blank_choices | def check_wide_data_for_blank_choices(choice_col, wide_data):
"""
Checks `wide_data` for null values in the choice column, and raises a
helpful ValueError if null values are found.
Parameters
----------
choice_col : str.
Denotes the column in `wide_data` that is used to record each
... | python | def check_wide_data_for_blank_choices(choice_col, wide_data):
"""
Checks `wide_data` for null values in the choice column, and raises a
helpful ValueError if null values are found.
Parameters
----------
choice_col : str.
Denotes the column in `wide_data` that is used to record each
... | [
"def",
"check_wide_data_for_blank_choices",
"(",
"choice_col",
",",
"wide_data",
")",
":",
"if",
"wide_data",
"[",
"choice_col",
"]",
".",
"isnull",
"(",
")",
".",
"any",
"(",
")",
":",
"msg_1",
"=",
"\"One or more of the values in wide_data[choice_col] is null.\"",
... | Checks `wide_data` for null values in the choice column, and raises a
helpful ValueError if null values are found.
Parameters
----------
choice_col : str.
Denotes the column in `wide_data` that is used to record each
observation's choice.
wide_data : pandas dataframe.
Contai... | [
"Checks",
"wide_data",
"for",
"null",
"values",
"in",
"the",
"choice",
"column",
"and",
"raises",
"a",
"helpful",
"ValueError",
"if",
"null",
"values",
"are",
"found",
"."
] | f83b0fd6debaa7358d87c3828428f6d4ead71357 | https://github.com/timothyb0912/pylogit/blob/f83b0fd6debaa7358d87c3828428f6d4ead71357/pylogit/choice_tools.py#L1258-L1280 |
825 | timothyb0912/pylogit | pylogit/choice_tools.py | ensure_unique_obs_ids_in_wide_data | def ensure_unique_obs_ids_in_wide_data(obs_id_col, wide_data):
"""
Ensures that there is one observation per row in wide_data. Raises a
helpful ValueError if otherwise.
Parameters
----------
obs_id_col : str.
Denotes the column in `wide_data` that contains the observation ID
val... | python | def ensure_unique_obs_ids_in_wide_data(obs_id_col, wide_data):
"""
Ensures that there is one observation per row in wide_data. Raises a
helpful ValueError if otherwise.
Parameters
----------
obs_id_col : str.
Denotes the column in `wide_data` that contains the observation ID
val... | [
"def",
"ensure_unique_obs_ids_in_wide_data",
"(",
"obs_id_col",
",",
"wide_data",
")",
":",
"if",
"len",
"(",
"wide_data",
"[",
"obs_id_col",
"]",
".",
"unique",
"(",
")",
")",
"!=",
"wide_data",
".",
"shape",
"[",
"0",
"]",
":",
"msg",
"=",
"\"The values ... | Ensures that there is one observation per row in wide_data. Raises a
helpful ValueError if otherwise.
Parameters
----------
obs_id_col : str.
Denotes the column in `wide_data` that contains the observation ID
values for each row.
wide_data : pandas dataframe.
Contains one ro... | [
"Ensures",
"that",
"there",
"is",
"one",
"observation",
"per",
"row",
"in",
"wide_data",
".",
"Raises",
"a",
"helpful",
"ValueError",
"if",
"otherwise",
"."
] | f83b0fd6debaa7358d87c3828428f6d4ead71357 | https://github.com/timothyb0912/pylogit/blob/f83b0fd6debaa7358d87c3828428f6d4ead71357/pylogit/choice_tools.py#L1283-L1306 |
826 | timothyb0912/pylogit | pylogit/choice_tools.py | ensure_chosen_alternatives_are_in_user_alt_ids | def ensure_chosen_alternatives_are_in_user_alt_ids(choice_col,
wide_data,
availability_vars):
"""
Ensures that all chosen alternatives in `wide_df` are present in the
`availability_vars` dict. Raises a help... | python | def ensure_chosen_alternatives_are_in_user_alt_ids(choice_col,
wide_data,
availability_vars):
"""
Ensures that all chosen alternatives in `wide_df` are present in the
`availability_vars` dict. Raises a help... | [
"def",
"ensure_chosen_alternatives_are_in_user_alt_ids",
"(",
"choice_col",
",",
"wide_data",
",",
"availability_vars",
")",
":",
"if",
"not",
"wide_data",
"[",
"choice_col",
"]",
".",
"isin",
"(",
"availability_vars",
".",
"keys",
"(",
")",
")",
".",
"all",
"("... | Ensures that all chosen alternatives in `wide_df` are present in the
`availability_vars` dict. Raises a helpful ValueError if not.
Parameters
----------
choice_col : str.
Denotes the column in `wide_data` that contains a one if the
alternative pertaining to the given row was the observe... | [
"Ensures",
"that",
"all",
"chosen",
"alternatives",
"in",
"wide_df",
"are",
"present",
"in",
"the",
"availability_vars",
"dict",
".",
"Raises",
"a",
"helpful",
"ValueError",
"if",
"not",
"."
] | f83b0fd6debaa7358d87c3828428f6d4ead71357 | https://github.com/timothyb0912/pylogit/blob/f83b0fd6debaa7358d87c3828428f6d4ead71357/pylogit/choice_tools.py#L1309-L1342 |
827 | timothyb0912/pylogit | pylogit/choice_tools.py | ensure_each_wide_obs_chose_an_available_alternative | def ensure_each_wide_obs_chose_an_available_alternative(obs_id_col,
choice_col,
availability_vars,
wide_data):
"""
Checks whether or not each ob... | python | def ensure_each_wide_obs_chose_an_available_alternative(obs_id_col,
choice_col,
availability_vars,
wide_data):
"""
Checks whether or not each ob... | [
"def",
"ensure_each_wide_obs_chose_an_available_alternative",
"(",
"obs_id_col",
",",
"choice_col",
",",
"availability_vars",
",",
"wide_data",
")",
":",
"# Determine the various availability values for each observation",
"wide_availability_values",
"=",
"wide_data",
"[",
"list",
... | Checks whether or not each observation with a restricted choice set chose
an alternative that was personally available to him or her. Will raise a
helpful ValueError if this is not the case.
Parameters
----------
obs_id_col : str.
Denotes the column in `wide_data` that contains the observat... | [
"Checks",
"whether",
"or",
"not",
"each",
"observation",
"with",
"a",
"restricted",
"choice",
"set",
"chose",
"an",
"alternative",
"that",
"was",
"personally",
"available",
"to",
"him",
"or",
"her",
".",
"Will",
"raise",
"a",
"helpful",
"ValueError",
"if",
"... | f83b0fd6debaa7358d87c3828428f6d4ead71357 | https://github.com/timothyb0912/pylogit/blob/f83b0fd6debaa7358d87c3828428f6d4ead71357/pylogit/choice_tools.py#L1345-L1397 |
828 | timothyb0912/pylogit | pylogit/choice_tools.py | ensure_all_wide_alt_ids_are_chosen | def ensure_all_wide_alt_ids_are_chosen(choice_col,
alt_specific_vars,
availability_vars,
wide_data):
"""
Checks to make sure all user-specified alternative id's, both in
`alt_specific_vars` a... | python | def ensure_all_wide_alt_ids_are_chosen(choice_col,
alt_specific_vars,
availability_vars,
wide_data):
"""
Checks to make sure all user-specified alternative id's, both in
`alt_specific_vars` a... | [
"def",
"ensure_all_wide_alt_ids_are_chosen",
"(",
"choice_col",
",",
"alt_specific_vars",
",",
"availability_vars",
",",
"wide_data",
")",
":",
"sorted_alt_ids",
"=",
"np",
".",
"sort",
"(",
"wide_data",
"[",
"choice_col",
"]",
".",
"unique",
"(",
")",
")",
"try... | Checks to make sure all user-specified alternative id's, both in
`alt_specific_vars` and `availability_vars` are observed in the choice
column of `wide_data`. | [
"Checks",
"to",
"make",
"sure",
"all",
"user",
"-",
"specified",
"alternative",
"id",
"s",
"both",
"in",
"alt_specific_vars",
"and",
"availability_vars",
"are",
"observed",
"in",
"the",
"choice",
"column",
"of",
"wide_data",
"."
] | f83b0fd6debaa7358d87c3828428f6d4ead71357 | https://github.com/timothyb0912/pylogit/blob/f83b0fd6debaa7358d87c3828428f6d4ead71357/pylogit/choice_tools.py#L1400-L1428 |
829 | timothyb0912/pylogit | pylogit/choice_tools.py | ensure_contiguity_in_observation_rows | def ensure_contiguity_in_observation_rows(obs_id_vector):
"""
Ensures that all rows pertaining to a given choice situation are located
next to one another. Raises a helpful ValueError otherwise. This check is
needed because the hessian calculation function requires the design matrix
to have contigui... | python | def ensure_contiguity_in_observation_rows(obs_id_vector):
"""
Ensures that all rows pertaining to a given choice situation are located
next to one another. Raises a helpful ValueError otherwise. This check is
needed because the hessian calculation function requires the design matrix
to have contigui... | [
"def",
"ensure_contiguity_in_observation_rows",
"(",
"obs_id_vector",
")",
":",
"# Check that the choice situation id for each row is larger than or equal",
"# to the choice situation id of the preceding row.",
"contiguity_check_array",
"=",
"(",
"obs_id_vector",
"[",
"1",
":",
"]",
... | Ensures that all rows pertaining to a given choice situation are located
next to one another. Raises a helpful ValueError otherwise. This check is
needed because the hessian calculation function requires the design matrix
to have contiguity in rows with the same observation id.
Parameters
---------... | [
"Ensures",
"that",
"all",
"rows",
"pertaining",
"to",
"a",
"given",
"choice",
"situation",
"are",
"located",
"next",
"to",
"one",
"another",
".",
"Raises",
"a",
"helpful",
"ValueError",
"otherwise",
".",
"This",
"check",
"is",
"needed",
"because",
"the",
"he... | f83b0fd6debaa7358d87c3828428f6d4ead71357 | https://github.com/timothyb0912/pylogit/blob/f83b0fd6debaa7358d87c3828428f6d4ead71357/pylogit/choice_tools.py#L1431-L1461 |
830 | timothyb0912/pylogit | pylogit/bootstrap_sampler.py | relate_obs_ids_to_chosen_alts | def relate_obs_ids_to_chosen_alts(obs_id_array,
alt_id_array,
choice_array):
"""
Creates a dictionary that relates each unique alternative id to the set of
observations ids that chose the given alternative.
Parameters
----------
... | python | def relate_obs_ids_to_chosen_alts(obs_id_array,
alt_id_array,
choice_array):
"""
Creates a dictionary that relates each unique alternative id to the set of
observations ids that chose the given alternative.
Parameters
----------
... | [
"def",
"relate_obs_ids_to_chosen_alts",
"(",
"obs_id_array",
",",
"alt_id_array",
",",
"choice_array",
")",
":",
"# Figure out which units of observation chose each alternative.",
"chosen_alts_to_obs_ids",
"=",
"{",
"}",
"for",
"alt_id",
"in",
"np",
".",
"sort",
"(",
"np"... | Creates a dictionary that relates each unique alternative id to the set of
observations ids that chose the given alternative.
Parameters
----------
obs_id_array : 1D ndarray of ints.
Should be a long-format array of observation ids. Each element should
correspond to the unique id of the... | [
"Creates",
"a",
"dictionary",
"that",
"relates",
"each",
"unique",
"alternative",
"id",
"to",
"the",
"set",
"of",
"observations",
"ids",
"that",
"chose",
"the",
"given",
"alternative",
"."
] | f83b0fd6debaa7358d87c3828428f6d4ead71357 | https://github.com/timothyb0912/pylogit/blob/f83b0fd6debaa7358d87c3828428f6d4ead71357/pylogit/bootstrap_sampler.py#L13-L55 |
831 | timothyb0912/pylogit | pylogit/bootstrap_sampler.py | create_cross_sectional_bootstrap_samples | def create_cross_sectional_bootstrap_samples(obs_id_array,
alt_id_array,
choice_array,
num_samples,
seed=None):
"""
Determines the u... | python | def create_cross_sectional_bootstrap_samples(obs_id_array,
alt_id_array,
choice_array,
num_samples,
seed=None):
"""
Determines the u... | [
"def",
"create_cross_sectional_bootstrap_samples",
"(",
"obs_id_array",
",",
"alt_id_array",
",",
"choice_array",
",",
"num_samples",
",",
"seed",
"=",
"None",
")",
":",
"# Determine the units of observation that chose each alternative.",
"chosen_alts_to_obs_ids",
"=",
"relate_... | Determines the unique observations that will be present in each bootstrap
sample. This function DOES NOT create the new design matrices or a new
long-format dataframe for each bootstrap sample. Note that these will be
correct bootstrap samples for cross-sectional datasets. This function will
not work co... | [
"Determines",
"the",
"unique",
"observations",
"that",
"will",
"be",
"present",
"in",
"each",
"bootstrap",
"sample",
".",
"This",
"function",
"DOES",
"NOT",
"create",
"the",
"new",
"design",
"matrices",
"or",
"a",
"new",
"long",
"-",
"format",
"dataframe",
"... | f83b0fd6debaa7358d87c3828428f6d4ead71357 | https://github.com/timothyb0912/pylogit/blob/f83b0fd6debaa7358d87c3828428f6d4ead71357/pylogit/bootstrap_sampler.py#L95-L177 |
832 | timothyb0912/pylogit | pylogit/bootstrap_sampler.py | create_bootstrap_id_array | def create_bootstrap_id_array(obs_id_per_sample):
"""
Creates a 2D ndarray that contains the 'bootstrap ids' for each replication
of each unit of observation that is an the set of bootstrap samples.
Parameters
----------
obs_id_per_sample : 2D ndarray of ints.
Should have one row for ea... | python | def create_bootstrap_id_array(obs_id_per_sample):
"""
Creates a 2D ndarray that contains the 'bootstrap ids' for each replication
of each unit of observation that is an the set of bootstrap samples.
Parameters
----------
obs_id_per_sample : 2D ndarray of ints.
Should have one row for ea... | [
"def",
"create_bootstrap_id_array",
"(",
"obs_id_per_sample",
")",
":",
"# Determine the shape of the object to be returned.",
"n_rows",
",",
"n_cols",
"=",
"obs_id_per_sample",
".",
"shape",
"# Create the array of bootstrap ids.",
"bootstrap_id_array",
"=",
"np",
".",
"tile",
... | Creates a 2D ndarray that contains the 'bootstrap ids' for each replication
of each unit of observation that is an the set of bootstrap samples.
Parameters
----------
obs_id_per_sample : 2D ndarray of ints.
Should have one row for each bootsrap sample. Should have one column
for each ob... | [
"Creates",
"a",
"2D",
"ndarray",
"that",
"contains",
"the",
"bootstrap",
"ids",
"for",
"each",
"replication",
"of",
"each",
"unit",
"of",
"observation",
"that",
"is",
"an",
"the",
"set",
"of",
"bootstrap",
"samples",
"."
] | f83b0fd6debaa7358d87c3828428f6d4ead71357 | https://github.com/timothyb0912/pylogit/blob/f83b0fd6debaa7358d87c3828428f6d4ead71357/pylogit/bootstrap_sampler.py#L180-L204 |
833 | timothyb0912/pylogit | pylogit/bootstrap_sampler.py | check_column_existence | def check_column_existence(col_name, df, presence=True):
"""
Checks whether or not `col_name` is in `df` and raises a helpful error msg
if the desired condition is not met.
Parameters
----------
col_name : str.
Should represent a column whose presence in `df` is to be checked.
df : ... | python | def check_column_existence(col_name, df, presence=True):
"""
Checks whether or not `col_name` is in `df` and raises a helpful error msg
if the desired condition is not met.
Parameters
----------
col_name : str.
Should represent a column whose presence in `df` is to be checked.
df : ... | [
"def",
"check_column_existence",
"(",
"col_name",
",",
"df",
",",
"presence",
"=",
"True",
")",
":",
"if",
"presence",
":",
"if",
"col_name",
"not",
"in",
"df",
".",
"columns",
":",
"msg",
"=",
"\"Ensure that `{}` is in `df.columns`.\"",
"raise",
"ValueError",
... | Checks whether or not `col_name` is in `df` and raises a helpful error msg
if the desired condition is not met.
Parameters
----------
col_name : str.
Should represent a column whose presence in `df` is to be checked.
df : pandas DataFrame.
The dataframe that will be checked for the ... | [
"Checks",
"whether",
"or",
"not",
"col_name",
"is",
"in",
"df",
"and",
"raises",
"a",
"helpful",
"error",
"msg",
"if",
"the",
"desired",
"condition",
"is",
"not",
"met",
"."
] | f83b0fd6debaa7358d87c3828428f6d4ead71357 | https://github.com/timothyb0912/pylogit/blob/f83b0fd6debaa7358d87c3828428f6d4ead71357/pylogit/bootstrap_sampler.py#L245-L273 |
834 | timothyb0912/pylogit | pylogit/bootstrap_sampler.py | ensure_resampled_obs_ids_in_df | def ensure_resampled_obs_ids_in_df(resampled_obs_ids, orig_obs_id_array):
"""
Checks whether all ids in `resampled_obs_ids` are in `orig_obs_id_array`.
Raises a helpful ValueError if not.
Parameters
----------
resampled_obs_ids : 1D ndarray of ints.
Should contain the observation ids of... | python | def ensure_resampled_obs_ids_in_df(resampled_obs_ids, orig_obs_id_array):
"""
Checks whether all ids in `resampled_obs_ids` are in `orig_obs_id_array`.
Raises a helpful ValueError if not.
Parameters
----------
resampled_obs_ids : 1D ndarray of ints.
Should contain the observation ids of... | [
"def",
"ensure_resampled_obs_ids_in_df",
"(",
"resampled_obs_ids",
",",
"orig_obs_id_array",
")",
":",
"if",
"not",
"np",
".",
"in1d",
"(",
"resampled_obs_ids",
",",
"orig_obs_id_array",
")",
".",
"all",
"(",
")",
":",
"msg",
"=",
"\"All values in `resampled_obs_ids... | Checks whether all ids in `resampled_obs_ids` are in `orig_obs_id_array`.
Raises a helpful ValueError if not.
Parameters
----------
resampled_obs_ids : 1D ndarray of ints.
Should contain the observation ids of the observational units that will
be used in the current bootstrap sample.
... | [
"Checks",
"whether",
"all",
"ids",
"in",
"resampled_obs_ids",
"are",
"in",
"orig_obs_id_array",
".",
"Raises",
"a",
"helpful",
"ValueError",
"if",
"not",
"."
] | f83b0fd6debaa7358d87c3828428f6d4ead71357 | https://github.com/timothyb0912/pylogit/blob/f83b0fd6debaa7358d87c3828428f6d4ead71357/pylogit/bootstrap_sampler.py#L276-L298 |
835 | timothyb0912/pylogit | pylogit/bootstrap_sampler.py | create_bootstrap_dataframe | def create_bootstrap_dataframe(orig_df,
obs_id_col,
resampled_obs_ids_1d,
groupby_dict,
boot_id_col="bootstrap_id"):
"""
Will create the altered dataframe of data needed to estimate a choi... | python | def create_bootstrap_dataframe(orig_df,
obs_id_col,
resampled_obs_ids_1d,
groupby_dict,
boot_id_col="bootstrap_id"):
"""
Will create the altered dataframe of data needed to estimate a choi... | [
"def",
"create_bootstrap_dataframe",
"(",
"orig_df",
",",
"obs_id_col",
",",
"resampled_obs_ids_1d",
",",
"groupby_dict",
",",
"boot_id_col",
"=",
"\"bootstrap_id\"",
")",
":",
"# Check the validity of the passed arguments.",
"check_column_existence",
"(",
"obs_id_col",
",",
... | Will create the altered dataframe of data needed to estimate a choice model
with the particular observations that belong to the current bootstrap
sample.
Parameters
----------
orig_df : pandas DataFrame.
Should be long-format dataframe containing the data used to estimate
the desire... | [
"Will",
"create",
"the",
"altered",
"dataframe",
"of",
"data",
"needed",
"to",
"estimate",
"a",
"choice",
"model",
"with",
"the",
"particular",
"observations",
"that",
"belong",
"to",
"the",
"current",
"bootstrap",
"sample",
"."
] | f83b0fd6debaa7358d87c3828428f6d4ead71357 | https://github.com/timothyb0912/pylogit/blob/f83b0fd6debaa7358d87c3828428f6d4ead71357/pylogit/bootstrap_sampler.py#L301-L360 |
836 | timothyb0912/pylogit | pylogit/bootstrap.py | get_param_names | def get_param_names(model_obj):
"""
Extracts all the names to be displayed for the estimated parameters.
Parameters
----------
model_obj : an instance of an MNDC object.
Should have the following attributes:
`['ind_var_names', 'intercept_names', 'shape_names', 'nest_names']`.
R... | python | def get_param_names(model_obj):
"""
Extracts all the names to be displayed for the estimated parameters.
Parameters
----------
model_obj : an instance of an MNDC object.
Should have the following attributes:
`['ind_var_names', 'intercept_names', 'shape_names', 'nest_names']`.
R... | [
"def",
"get_param_names",
"(",
"model_obj",
")",
":",
"# Get the index coefficient names",
"all_names",
"=",
"deepcopy",
"(",
"model_obj",
".",
"ind_var_names",
")",
"# Add the intercept names if any exist",
"if",
"model_obj",
".",
"intercept_names",
"is",
"not",
"None",
... | Extracts all the names to be displayed for the estimated parameters.
Parameters
----------
model_obj : an instance of an MNDC object.
Should have the following attributes:
`['ind_var_names', 'intercept_names', 'shape_names', 'nest_names']`.
Returns
-------
all_names : list of s... | [
"Extracts",
"all",
"the",
"names",
"to",
"be",
"displayed",
"for",
"the",
"estimated",
"parameters",
"."
] | f83b0fd6debaa7358d87c3828428f6d4ead71357 | https://github.com/timothyb0912/pylogit/blob/f83b0fd6debaa7358d87c3828428f6d4ead71357/pylogit/bootstrap.py#L46-L75 |
837 | timothyb0912/pylogit | pylogit/bootstrap.py | get_param_list_for_prediction | def get_param_list_for_prediction(model_obj, replicates):
"""
Create the `param_list` argument for use with `model_obj.predict`.
Parameters
----------
model_obj : an instance of an MNDC object.
Should have the following attributes:
`['ind_var_names', 'intercept_names', 'shape_names'... | python | def get_param_list_for_prediction(model_obj, replicates):
"""
Create the `param_list` argument for use with `model_obj.predict`.
Parameters
----------
model_obj : an instance of an MNDC object.
Should have the following attributes:
`['ind_var_names', 'intercept_names', 'shape_names'... | [
"def",
"get_param_list_for_prediction",
"(",
"model_obj",
",",
"replicates",
")",
":",
"# Check the validity of the passed arguments",
"ensure_samples_is_ndim_ndarray",
"(",
"replicates",
",",
"ndim",
"=",
"2",
",",
"name",
"=",
"'replicates'",
")",
"# Determine the number ... | Create the `param_list` argument for use with `model_obj.predict`.
Parameters
----------
model_obj : an instance of an MNDC object.
Should have the following attributes:
`['ind_var_names', 'intercept_names', 'shape_names', 'nest_names']`.
This model should have already undergone a c... | [
"Create",
"the",
"param_list",
"argument",
"for",
"use",
"with",
"model_obj",
".",
"predict",
"."
] | f83b0fd6debaa7358d87c3828428f6d4ead71357 | https://github.com/timothyb0912/pylogit/blob/f83b0fd6debaa7358d87c3828428f6d4ead71357/pylogit/bootstrap.py#L78-L135 |
838 | timothyb0912/pylogit | pylogit/bootstrap.py | Boot.generate_bootstrap_replicates | def generate_bootstrap_replicates(self,
num_samples,
mnl_obj=None,
mnl_init_vals=None,
mnl_fit_kwargs=None,
extract_init_vals=None... | python | def generate_bootstrap_replicates(self,
num_samples,
mnl_obj=None,
mnl_init_vals=None,
mnl_fit_kwargs=None,
extract_init_vals=None... | [
"def",
"generate_bootstrap_replicates",
"(",
"self",
",",
"num_samples",
",",
"mnl_obj",
"=",
"None",
",",
"mnl_init_vals",
"=",
"None",
",",
"mnl_fit_kwargs",
"=",
"None",
",",
"extract_init_vals",
"=",
"None",
",",
"print_res",
"=",
"False",
",",
"method",
"... | Generates the bootstrap replicates for one's given model and dataset.
Parameters
----------
num_samples : positive int.
Specifies the number of bootstrap samples that are to be drawn.
mnl_obj : an instance of pylogit.MNL or None, optional.
Should be the MNL model... | [
"Generates",
"the",
"bootstrap",
"replicates",
"for",
"one",
"s",
"given",
"model",
"and",
"dataset",
"."
] | f83b0fd6debaa7358d87c3828428f6d4ead71357 | https://github.com/timothyb0912/pylogit/blob/f83b0fd6debaa7358d87c3828428f6d4ead71357/pylogit/bootstrap.py#L183-L356 |
839 | timothyb0912/pylogit | pylogit/bootstrap.py | Boot.generate_jackknife_replicates | def generate_jackknife_replicates(self,
mnl_obj=None,
mnl_init_vals=None,
mnl_fit_kwargs=None,
extract_init_vals=None,
print_res=F... | python | def generate_jackknife_replicates(self,
mnl_obj=None,
mnl_init_vals=None,
mnl_fit_kwargs=None,
extract_init_vals=None,
print_res=F... | [
"def",
"generate_jackknife_replicates",
"(",
"self",
",",
"mnl_obj",
"=",
"None",
",",
"mnl_init_vals",
"=",
"None",
",",
"mnl_fit_kwargs",
"=",
"None",
",",
"extract_init_vals",
"=",
"None",
",",
"print_res",
"=",
"False",
",",
"method",
"=",
"\"BFGS\"",
",",... | Generates the jackknife replicates for one's given model and dataset.
Parameters
----------
mnl_obj : an instance of pylogit.MNL or None, optional.
Should be the MNL model object that is used to provide starting
values for the final model being estimated. If None, then o... | [
"Generates",
"the",
"jackknife",
"replicates",
"for",
"one",
"s",
"given",
"model",
"and",
"dataset",
"."
] | f83b0fd6debaa7358d87c3828428f6d4ead71357 | https://github.com/timothyb0912/pylogit/blob/f83b0fd6debaa7358d87c3828428f6d4ead71357/pylogit/bootstrap.py#L358-L495 |
840 | timothyb0912/pylogit | pylogit/bootstrap.py | Boot.calc_log_likes_for_replicates | def calc_log_likes_for_replicates(self,
replicates='bootstrap',
num_draws=None,
seed=None):
"""
Calculate the log-likelihood value of one's replicates, given one's
dataset.
... | python | def calc_log_likes_for_replicates(self,
replicates='bootstrap',
num_draws=None,
seed=None):
"""
Calculate the log-likelihood value of one's replicates, given one's
dataset.
... | [
"def",
"calc_log_likes_for_replicates",
"(",
"self",
",",
"replicates",
"=",
"'bootstrap'",
",",
"num_draws",
"=",
"None",
",",
"seed",
"=",
"None",
")",
":",
"# Check the validity of the kwargs",
"ensure_replicates_kwarg_validity",
"(",
"replicates",
")",
"# Get the de... | Calculate the log-likelihood value of one's replicates, given one's
dataset.
Parameters
----------
replicates : str in {'bootstrap', 'jackknife'}.
Denotes which set of replicates should have their log-likelihoods
calculated.
num_draws : int greater than z... | [
"Calculate",
"the",
"log",
"-",
"likelihood",
"value",
"of",
"one",
"s",
"replicates",
"given",
"one",
"s",
"dataset",
"."
] | f83b0fd6debaa7358d87c3828428f6d4ead71357 | https://github.com/timothyb0912/pylogit/blob/f83b0fd6debaa7358d87c3828428f6d4ead71357/pylogit/bootstrap.py#L497-L591 |
841 | timothyb0912/pylogit | pylogit/bootstrap.py | Boot.calc_gradient_norm_for_replicates | def calc_gradient_norm_for_replicates(self,
replicates='bootstrap',
ridge=None,
constrained_pos=None,
weights=None):
"""
Calculate the E... | python | def calc_gradient_norm_for_replicates(self,
replicates='bootstrap',
ridge=None,
constrained_pos=None,
weights=None):
"""
Calculate the E... | [
"def",
"calc_gradient_norm_for_replicates",
"(",
"self",
",",
"replicates",
"=",
"'bootstrap'",
",",
"ridge",
"=",
"None",
",",
"constrained_pos",
"=",
"None",
",",
"weights",
"=",
"None",
")",
":",
"# Check the validity of the kwargs",
"ensure_replicates_kwarg_validity... | Calculate the Euclidean-norm of the gradient of one's replicates, given
one's dataset.
Parameters
----------
replicates : str in {'bootstrap', 'jackknife'}.
Denotes which set of replicates should have their log-likelihoods
calculated.
ridge : float or Non... | [
"Calculate",
"the",
"Euclidean",
"-",
"norm",
"of",
"the",
"gradient",
"of",
"one",
"s",
"replicates",
"given",
"one",
"s",
"dataset",
"."
] | f83b0fd6debaa7358d87c3828428f6d4ead71357 | https://github.com/timothyb0912/pylogit/blob/f83b0fd6debaa7358d87c3828428f6d4ead71357/pylogit/bootstrap.py#L593-L661 |
842 | timothyb0912/pylogit | pylogit/bootstrap.py | Boot.calc_percentile_interval | def calc_percentile_interval(self, conf_percentage):
"""
Calculates percentile bootstrap confidence intervals for one's model.
Parameters
----------
conf_percentage : scalar in the interval (0.0, 100.0).
Denotes the confidence-level for the returned endpoints. For
... | python | def calc_percentile_interval(self, conf_percentage):
"""
Calculates percentile bootstrap confidence intervals for one's model.
Parameters
----------
conf_percentage : scalar in the interval (0.0, 100.0).
Denotes the confidence-level for the returned endpoints. For
... | [
"def",
"calc_percentile_interval",
"(",
"self",
",",
"conf_percentage",
")",
":",
"# Get the alpha % that corresponds to the given confidence percentage.",
"alpha",
"=",
"bc",
".",
"get_alpha_from_conf_percentage",
"(",
"conf_percentage",
")",
"# Create the column names for the dat... | Calculates percentile bootstrap confidence intervals for one's model.
Parameters
----------
conf_percentage : scalar in the interval (0.0, 100.0).
Denotes the confidence-level for the returned endpoints. For
instance, to calculate a 95% confidence interval, pass `95`.
... | [
"Calculates",
"percentile",
"bootstrap",
"confidence",
"intervals",
"for",
"one",
"s",
"model",
"."
] | f83b0fd6debaa7358d87c3828428f6d4ead71357 | https://github.com/timothyb0912/pylogit/blob/f83b0fd6debaa7358d87c3828428f6d4ead71357/pylogit/bootstrap.py#L663-L696 |
843 | timothyb0912/pylogit | pylogit/bootstrap.py | Boot.calc_abc_interval | def calc_abc_interval(self,
conf_percentage,
init_vals,
epsilon=0.001,
**fit_kwargs):
"""
Calculates Approximate Bootstrap Confidence Intervals for one's model.
Parameters
----------
... | python | def calc_abc_interval(self,
conf_percentage,
init_vals,
epsilon=0.001,
**fit_kwargs):
"""
Calculates Approximate Bootstrap Confidence Intervals for one's model.
Parameters
----------
... | [
"def",
"calc_abc_interval",
"(",
"self",
",",
"conf_percentage",
",",
"init_vals",
",",
"epsilon",
"=",
"0.001",
",",
"*",
"*",
"fit_kwargs",
")",
":",
"print",
"(",
"\"Calculating Approximate Bootstrap Confidence (ABC) Intervals\"",
")",
"print",
"(",
"time",
".",
... | Calculates Approximate Bootstrap Confidence Intervals for one's model.
Parameters
----------
conf_percentage : scalar in the interval (0.0, 100.0).
Denotes the confidence-level for the returned endpoints. For
instance, to calculate a 95% confidence interval, pass `95`.
... | [
"Calculates",
"Approximate",
"Bootstrap",
"Confidence",
"Intervals",
"for",
"one",
"s",
"model",
"."
] | f83b0fd6debaa7358d87c3828428f6d4ead71357 | https://github.com/timothyb0912/pylogit/blob/f83b0fd6debaa7358d87c3828428f6d4ead71357/pylogit/bootstrap.py#L737-L788 |
844 | timothyb0912/pylogit | pylogit/bootstrap.py | Boot.calc_conf_intervals | def calc_conf_intervals(self,
conf_percentage,
interval_type='all',
init_vals=None,
epsilon=abc.EPSILON,
**fit_kwargs):
"""
Calculates percentile, bias-corrected an... | python | def calc_conf_intervals(self,
conf_percentage,
interval_type='all',
init_vals=None,
epsilon=abc.EPSILON,
**fit_kwargs):
"""
Calculates percentile, bias-corrected an... | [
"def",
"calc_conf_intervals",
"(",
"self",
",",
"conf_percentage",
",",
"interval_type",
"=",
"'all'",
",",
"init_vals",
"=",
"None",
",",
"epsilon",
"=",
"abc",
".",
"EPSILON",
",",
"*",
"*",
"fit_kwargs",
")",
":",
"if",
"interval_type",
"==",
"'pi'",
":... | Calculates percentile, bias-corrected and accelerated, and approximate
bootstrap confidence intervals.
Parameters
----------
conf_percentage : scalar in the interval (0.0, 100.0).
Denotes the confidence-level for the returned endpoints. For
instance, to calculate... | [
"Calculates",
"percentile",
"bias",
"-",
"corrected",
"and",
"accelerated",
"and",
"approximate",
"bootstrap",
"confidence",
"intervals",
"."
] | f83b0fd6debaa7358d87c3828428f6d4ead71357 | https://github.com/timothyb0912/pylogit/blob/f83b0fd6debaa7358d87c3828428f6d4ead71357/pylogit/bootstrap.py#L790-L879 |
845 | timothyb0912/pylogit | pylogit/clog_log.py | create_calc_dh_d_alpha | def create_calc_dh_d_alpha(estimator):
"""
Return the function that can be used in the various gradient and hessian
calculations to calculate the derivative of the transformation with respect
to the outside intercept parameters.
Parameters
----------
estimator : an instance of the estimatio... | python | def create_calc_dh_d_alpha(estimator):
"""
Return the function that can be used in the various gradient and hessian
calculations to calculate the derivative of the transformation with respect
to the outside intercept parameters.
Parameters
----------
estimator : an instance of the estimatio... | [
"def",
"create_calc_dh_d_alpha",
"(",
"estimator",
")",
":",
"if",
"estimator",
".",
"intercept_ref_pos",
"is",
"not",
"None",
":",
"needed_idxs",
"=",
"range",
"(",
"estimator",
".",
"rows_to_alts",
".",
"shape",
"[",
"1",
"]",
")",
"needed_idxs",
".",
"rem... | Return the function that can be used in the various gradient and hessian
calculations to calculate the derivative of the transformation with respect
to the outside intercept parameters.
Parameters
----------
estimator : an instance of the estimation.LogitTypeEstimator class.
Should contain ... | [
"Return",
"the",
"function",
"that",
"can",
"be",
"used",
"in",
"the",
"various",
"gradient",
"and",
"hessian",
"calculations",
"to",
"calculate",
"the",
"derivative",
"of",
"the",
"transformation",
"with",
"respect",
"to",
"the",
"outside",
"intercept",
"parame... | f83b0fd6debaa7358d87c3828428f6d4ead71357 | https://github.com/timothyb0912/pylogit/blob/f83b0fd6debaa7358d87c3828428f6d4ead71357/pylogit/clog_log.py#L374-L415 |
846 | timothyb0912/pylogit | pylogit/estimation.py | calc_individual_chi_squares | def calc_individual_chi_squares(residuals,
long_probabilities,
rows_to_obs):
"""
Calculates individual chi-squared values for each choice situation in the
dataset.
Parameters
----------
residuals : 1D ndarray.
The choice ve... | python | def calc_individual_chi_squares(residuals,
long_probabilities,
rows_to_obs):
"""
Calculates individual chi-squared values for each choice situation in the
dataset.
Parameters
----------
residuals : 1D ndarray.
The choice ve... | [
"def",
"calc_individual_chi_squares",
"(",
"residuals",
",",
"long_probabilities",
",",
"rows_to_obs",
")",
":",
"chi_squared_terms",
"=",
"np",
".",
"square",
"(",
"residuals",
")",
"/",
"long_probabilities",
"return",
"rows_to_obs",
".",
"T",
".",
"dot",
"(",
... | Calculates individual chi-squared values for each choice situation in the
dataset.
Parameters
----------
residuals : 1D ndarray.
The choice vector minus the predicted probability of each alternative
for each observation.
long_probabilities : 1D ndarray.
The probability of ea... | [
"Calculates",
"individual",
"chi",
"-",
"squared",
"values",
"for",
"each",
"choice",
"situation",
"in",
"the",
"dataset",
"."
] | f83b0fd6debaa7358d87c3828428f6d4ead71357 | https://github.com/timothyb0912/pylogit/blob/f83b0fd6debaa7358d87c3828428f6d4ead71357/pylogit/estimation.py#L424-L451 |
847 | timothyb0912/pylogit | pylogit/estimation.py | calc_rho_and_rho_bar_squared | def calc_rho_and_rho_bar_squared(final_log_likelihood,
null_log_likelihood,
num_est_parameters):
"""
Calculates McFadden's rho-squared and rho-bar squared for the given model.
Parameters
----------
final_log_likelihood : float.
... | python | def calc_rho_and_rho_bar_squared(final_log_likelihood,
null_log_likelihood,
num_est_parameters):
"""
Calculates McFadden's rho-squared and rho-bar squared for the given model.
Parameters
----------
final_log_likelihood : float.
... | [
"def",
"calc_rho_and_rho_bar_squared",
"(",
"final_log_likelihood",
",",
"null_log_likelihood",
",",
"num_est_parameters",
")",
":",
"rho_squared",
"=",
"1.0",
"-",
"final_log_likelihood",
"/",
"null_log_likelihood",
"rho_bar_squared",
"=",
"1.0",
"-",
"(",
"(",
"final_... | Calculates McFadden's rho-squared and rho-bar squared for the given model.
Parameters
----------
final_log_likelihood : float.
The final log-likelihood of the model whose rho-squared and rho-bar
squared are being calculated for.
null_log_likelihood : float.
The log-likelihood of... | [
"Calculates",
"McFadden",
"s",
"rho",
"-",
"squared",
"and",
"rho",
"-",
"bar",
"squared",
"for",
"the",
"given",
"model",
"."
] | f83b0fd6debaa7358d87c3828428f6d4ead71357 | https://github.com/timothyb0912/pylogit/blob/f83b0fd6debaa7358d87c3828428f6d4ead71357/pylogit/estimation.py#L454-L480 |
848 | timothyb0912/pylogit | pylogit/estimation.py | calc_and_store_post_estimation_results | def calc_and_store_post_estimation_results(results_dict,
estimator):
"""
Calculates and stores post-estimation results that require the use of the
systematic utility transformation functions or the various derivative
functions. Note that this function is only v... | python | def calc_and_store_post_estimation_results(results_dict,
estimator):
"""
Calculates and stores post-estimation results that require the use of the
systematic utility transformation functions or the various derivative
functions. Note that this function is only v... | [
"def",
"calc_and_store_post_estimation_results",
"(",
"results_dict",
",",
"estimator",
")",
":",
"# Store the final log-likelihood",
"final_log_likelihood",
"=",
"-",
"1",
"*",
"results_dict",
"[",
"\"fun\"",
"]",
"results_dict",
"[",
"\"final_log_likelihood\"",
"]",
"="... | Calculates and stores post-estimation results that require the use of the
systematic utility transformation functions or the various derivative
functions. Note that this function is only valid for logit-type models.
Parameters
----------
results_dict : dict.
This dictionary should be the di... | [
"Calculates",
"and",
"stores",
"post",
"-",
"estimation",
"results",
"that",
"require",
"the",
"use",
"of",
"the",
"systematic",
"utility",
"transformation",
"functions",
"or",
"the",
"various",
"derivative",
"functions",
".",
"Note",
"that",
"this",
"function",
... | f83b0fd6debaa7358d87c3828428f6d4ead71357 | https://github.com/timothyb0912/pylogit/blob/f83b0fd6debaa7358d87c3828428f6d4ead71357/pylogit/estimation.py#L483-L583 |
849 | timothyb0912/pylogit | pylogit/estimation.py | estimate | def estimate(init_values,
estimator,
method,
loss_tol,
gradient_tol,
maxiter,
print_results,
use_hessian=True,
just_point=False,
**kwargs):
"""
Estimate the given choice model that is defined by ... | python | def estimate(init_values,
estimator,
method,
loss_tol,
gradient_tol,
maxiter,
print_results,
use_hessian=True,
just_point=False,
**kwargs):
"""
Estimate the given choice model that is defined by ... | [
"def",
"estimate",
"(",
"init_values",
",",
"estimator",
",",
"method",
",",
"loss_tol",
",",
"gradient_tol",
",",
"maxiter",
",",
"print_results",
",",
"use_hessian",
"=",
"True",
",",
"just_point",
"=",
"False",
",",
"*",
"*",
"kwargs",
")",
":",
"if",
... | Estimate the given choice model that is defined by `estimator`.
Parameters
----------
init_vals : 1D ndarray.
Should contain the initial values to start the optimization process
with.
estimator : an instance of the EstimationObj class.
method : str, optional.
Should be a val... | [
"Estimate",
"the",
"given",
"choice",
"model",
"that",
"is",
"defined",
"by",
"estimator",
"."
] | f83b0fd6debaa7358d87c3828428f6d4ead71357 | https://github.com/timothyb0912/pylogit/blob/f83b0fd6debaa7358d87c3828428f6d4ead71357/pylogit/estimation.py#L586-L713 |
850 | timothyb0912/pylogit | pylogit/estimation.py | EstimationObj.calc_neg_log_likelihood_and_neg_gradient | def calc_neg_log_likelihood_and_neg_gradient(self, params):
"""
Calculates and returns the negative of the log-likelihood and the
negative of the gradient. This function is used as the objective
function in scipy.optimize.minimize.
"""
neg_log_likelihood = -1 * self.conve... | python | def calc_neg_log_likelihood_and_neg_gradient(self, params):
"""
Calculates and returns the negative of the log-likelihood and the
negative of the gradient. This function is used as the objective
function in scipy.optimize.minimize.
"""
neg_log_likelihood = -1 * self.conve... | [
"def",
"calc_neg_log_likelihood_and_neg_gradient",
"(",
"self",
",",
"params",
")",
":",
"neg_log_likelihood",
"=",
"-",
"1",
"*",
"self",
".",
"convenience_calc_log_likelihood",
"(",
"params",
")",
"neg_gradient",
"=",
"-",
"1",
"*",
"self",
".",
"convenience_cal... | Calculates and returns the negative of the log-likelihood and the
negative of the gradient. This function is used as the objective
function in scipy.optimize.minimize. | [
"Calculates",
"and",
"returns",
"the",
"negative",
"of",
"the",
"log",
"-",
"likelihood",
"and",
"the",
"negative",
"of",
"the",
"gradient",
".",
"This",
"function",
"is",
"used",
"as",
"the",
"objective",
"function",
"in",
"scipy",
".",
"optimize",
".",
"... | f83b0fd6debaa7358d87c3828428f6d4ead71357 | https://github.com/timothyb0912/pylogit/blob/f83b0fd6debaa7358d87c3828428f6d4ead71357/pylogit/estimation.py#L211-L223 |
851 | timothyb0912/pylogit | pylogit/bootstrap_utils.py | ensure_samples_is_ndim_ndarray | def ensure_samples_is_ndim_ndarray(samples, name='bootstrap', ndim=2):
"""
Ensures that `samples` is an `ndim` numpy array. Raises a helpful
ValueError if otherwise.
"""
assert isinstance(ndim, int)
assert isinstance(name, str)
if not isinstance(samples, np.ndarray) or not (samples.ndim == n... | python | def ensure_samples_is_ndim_ndarray(samples, name='bootstrap', ndim=2):
"""
Ensures that `samples` is an `ndim` numpy array. Raises a helpful
ValueError if otherwise.
"""
assert isinstance(ndim, int)
assert isinstance(name, str)
if not isinstance(samples, np.ndarray) or not (samples.ndim == n... | [
"def",
"ensure_samples_is_ndim_ndarray",
"(",
"samples",
",",
"name",
"=",
"'bootstrap'",
",",
"ndim",
"=",
"2",
")",
":",
"assert",
"isinstance",
"(",
"ndim",
",",
"int",
")",
"assert",
"isinstance",
"(",
"name",
",",
"str",
")",
"if",
"not",
"isinstance"... | Ensures that `samples` is an `ndim` numpy array. Raises a helpful
ValueError if otherwise. | [
"Ensures",
"that",
"samples",
"is",
"an",
"ndim",
"numpy",
"array",
".",
"Raises",
"a",
"helpful",
"ValueError",
"if",
"otherwise",
"."
] | f83b0fd6debaa7358d87c3828428f6d4ead71357 | https://github.com/timothyb0912/pylogit/blob/f83b0fd6debaa7358d87c3828428f6d4ead71357/pylogit/bootstrap_utils.py#L27-L38 |
852 | timothyb0912/pylogit | pylogit/construct_estimator.py | create_estimation_obj | def create_estimation_obj(model_obj,
init_vals,
mappings=None,
ridge=None,
constrained_pos=None,
weights=None):
"""
Should return a model estimation object corresponding to the model... | python | def create_estimation_obj(model_obj,
init_vals,
mappings=None,
ridge=None,
constrained_pos=None,
weights=None):
"""
Should return a model estimation object corresponding to the model... | [
"def",
"create_estimation_obj",
"(",
"model_obj",
",",
"init_vals",
",",
"mappings",
"=",
"None",
",",
"ridge",
"=",
"None",
",",
"constrained_pos",
"=",
"None",
",",
"weights",
"=",
"None",
")",
":",
"# Get the mapping matrices for each model",
"mapping_matrices",
... | Should return a model estimation object corresponding to the model type of
the `model_obj`.
Parameters
----------
model_obj : an instance or sublcass of the MNDC class.
init_vals : 1D ndarray.
The initial values to start the estimation process with. In the
following order, there sho... | [
"Should",
"return",
"a",
"model",
"estimation",
"object",
"corresponding",
"to",
"the",
"model",
"type",
"of",
"the",
"model_obj",
"."
] | f83b0fd6debaa7358d87c3828428f6d4ead71357 | https://github.com/timothyb0912/pylogit/blob/f83b0fd6debaa7358d87c3828428f6d4ead71357/pylogit/construct_estimator.py#L54-L119 |
853 | timothyb0912/pylogit | pylogit/bootstrap_abc.py | ensure_wide_weights_is_1D_or_2D_ndarray | def ensure_wide_weights_is_1D_or_2D_ndarray(wide_weights):
"""
Ensures that `wide_weights` is a 1D or 2D ndarray. Raises a helpful
ValueError if otherwise.
"""
if not isinstance(wide_weights, np.ndarray):
msg = "wide_weights MUST be a ndarray."
raise ValueError(msg)
ndim = wide_w... | python | def ensure_wide_weights_is_1D_or_2D_ndarray(wide_weights):
"""
Ensures that `wide_weights` is a 1D or 2D ndarray. Raises a helpful
ValueError if otherwise.
"""
if not isinstance(wide_weights, np.ndarray):
msg = "wide_weights MUST be a ndarray."
raise ValueError(msg)
ndim = wide_w... | [
"def",
"ensure_wide_weights_is_1D_or_2D_ndarray",
"(",
"wide_weights",
")",
":",
"if",
"not",
"isinstance",
"(",
"wide_weights",
",",
"np",
".",
"ndarray",
")",
":",
"msg",
"=",
"\"wide_weights MUST be a ndarray.\"",
"raise",
"ValueError",
"(",
"msg",
")",
"ndim",
... | Ensures that `wide_weights` is a 1D or 2D ndarray. Raises a helpful
ValueError if otherwise. | [
"Ensures",
"that",
"wide_weights",
"is",
"a",
"1D",
"or",
"2D",
"ndarray",
".",
"Raises",
"a",
"helpful",
"ValueError",
"if",
"otherwise",
"."
] | f83b0fd6debaa7358d87c3828428f6d4ead71357 | https://github.com/timothyb0912/pylogit/blob/f83b0fd6debaa7358d87c3828428f6d4ead71357/pylogit/bootstrap_abc.py#L51-L63 |
854 | timothyb0912/pylogit | pylogit/bootstrap_abc.py | check_validity_of_long_form_args | def check_validity_of_long_form_args(model_obj, wide_weights, rows_to_obs):
"""
Ensures the args to `create_long_form_weights` have expected properties.
"""
# Ensure model_obj has the necessary method for create_long_form_weights
ensure_model_obj_has_mapping_constructor(model_obj)
# Ensure wide_... | python | def check_validity_of_long_form_args(model_obj, wide_weights, rows_to_obs):
"""
Ensures the args to `create_long_form_weights` have expected properties.
"""
# Ensure model_obj has the necessary method for create_long_form_weights
ensure_model_obj_has_mapping_constructor(model_obj)
# Ensure wide_... | [
"def",
"check_validity_of_long_form_args",
"(",
"model_obj",
",",
"wide_weights",
",",
"rows_to_obs",
")",
":",
"# Ensure model_obj has the necessary method for create_long_form_weights",
"ensure_model_obj_has_mapping_constructor",
"(",
"model_obj",
")",
"# Ensure wide_weights is a 1D ... | Ensures the args to `create_long_form_weights` have expected properties. | [
"Ensures",
"the",
"args",
"to",
"create_long_form_weights",
"have",
"expected",
"properties",
"."
] | f83b0fd6debaa7358d87c3828428f6d4ead71357 | https://github.com/timothyb0912/pylogit/blob/f83b0fd6debaa7358d87c3828428f6d4ead71357/pylogit/bootstrap_abc.py#L66-L76 |
855 | timothyb0912/pylogit | pylogit/bootstrap_abc.py | calc_finite_diff_terms_for_abc | def calc_finite_diff_terms_for_abc(model_obj,
mle_params,
init_vals,
epsilon,
**fit_kwargs):
"""
Calculates the terms needed for the finite difference approximations of
... | python | def calc_finite_diff_terms_for_abc(model_obj,
mle_params,
init_vals,
epsilon,
**fit_kwargs):
"""
Calculates the terms needed for the finite difference approximations of
... | [
"def",
"calc_finite_diff_terms_for_abc",
"(",
"model_obj",
",",
"mle_params",
",",
"init_vals",
",",
"epsilon",
",",
"*",
"*",
"fit_kwargs",
")",
":",
"# Determine the number of observations in this dataset.",
"num_obs",
"=",
"model_obj",
".",
"data",
"[",
"model_obj",
... | Calculates the terms needed for the finite difference approximations of
the empirical influence and second order empirical influence functions.
Parameters
----------
model_obj : an instance or sublcass of the MNDC class.
Should be the model object that corresponds to the model we are
co... | [
"Calculates",
"the",
"terms",
"needed",
"for",
"the",
"finite",
"difference",
"approximations",
"of",
"the",
"empirical",
"influence",
"and",
"second",
"order",
"empirical",
"influence",
"functions",
"."
] | f83b0fd6debaa7358d87c3828428f6d4ead71357 | https://github.com/timothyb0912/pylogit/blob/f83b0fd6debaa7358d87c3828428f6d4ead71357/pylogit/bootstrap_abc.py#L123-L222 |
856 | timothyb0912/pylogit | pylogit/bootstrap_abc.py | calc_abc_interval | def calc_abc_interval(model_obj,
mle_params,
init_vals,
conf_percentage,
epsilon=0.001,
**fit_kwargs):
"""
Calculate 'approximate bootstrap confidence' intervals.
Parameters
----------
mode... | python | def calc_abc_interval(model_obj,
mle_params,
init_vals,
conf_percentage,
epsilon=0.001,
**fit_kwargs):
"""
Calculate 'approximate bootstrap confidence' intervals.
Parameters
----------
mode... | [
"def",
"calc_abc_interval",
"(",
"model_obj",
",",
"mle_params",
",",
"init_vals",
",",
"conf_percentage",
",",
"epsilon",
"=",
"0.001",
",",
"*",
"*",
"fit_kwargs",
")",
":",
"# Check validity of arguments",
"check_conf_percentage_validity",
"(",
"conf_percentage",
"... | Calculate 'approximate bootstrap confidence' intervals.
Parameters
----------
model_obj : an instance or sublcass of the MNDC class.
Should be the model object that corresponds to the model we are
constructing the bootstrap confidence intervals for.
mle_params : 1D ndarray.
Shou... | [
"Calculate",
"approximate",
"bootstrap",
"confidence",
"intervals",
"."
] | f83b0fd6debaa7358d87c3828428f6d4ead71357 | https://github.com/timothyb0912/pylogit/blob/f83b0fd6debaa7358d87c3828428f6d4ead71357/pylogit/bootstrap_abc.py#L1160-L1278 |
857 | timothyb0912/pylogit | pylogit/mixed_logit.py | check_length_of_init_values | def check_length_of_init_values(design_3d, init_values):
"""
Ensures that the initial values are of the correct length, given the design
matrix that they will be dot-producted with. Raises a ValueError if that is
not the case, and provides a useful error message to users.
Parameters
----------
... | python | def check_length_of_init_values(design_3d, init_values):
"""
Ensures that the initial values are of the correct length, given the design
matrix that they will be dot-producted with. Raises a ValueError if that is
not the case, and provides a useful error message to users.
Parameters
----------
... | [
"def",
"check_length_of_init_values",
"(",
"design_3d",
",",
"init_values",
")",
":",
"if",
"init_values",
".",
"shape",
"[",
"0",
"]",
"!=",
"design_3d",
".",
"shape",
"[",
"2",
"]",
":",
"msg_1",
"=",
"\"The initial values are of the wrong dimension. \"",
"msg_2... | Ensures that the initial values are of the correct length, given the design
matrix that they will be dot-producted with. Raises a ValueError if that is
not the case, and provides a useful error message to users.
Parameters
----------
init_values : 1D ndarray.
1D numpy array of the initial v... | [
"Ensures",
"that",
"the",
"initial",
"values",
"are",
"of",
"the",
"correct",
"length",
"given",
"the",
"design",
"matrix",
"that",
"they",
"will",
"be",
"dot",
"-",
"producted",
"with",
".",
"Raises",
"a",
"ValueError",
"if",
"that",
"is",
"not",
"the",
... | f83b0fd6debaa7358d87c3828428f6d4ead71357 | https://github.com/timothyb0912/pylogit/blob/f83b0fd6debaa7358d87c3828428f6d4ead71357/pylogit/mixed_logit.py#L106-L132 |
858 | timothyb0912/pylogit | pylogit/mixed_logit.py | add_mixl_specific_results_to_estimation_res | def add_mixl_specific_results_to_estimation_res(estimator, results_dict):
"""
Stores particular items in the results dictionary that are unique to mixed
logit-type models. In particular, this function calculates and adds
`sequence_probs` and `expanded_sequence_probs` to the results dictionary.
The `... | python | def add_mixl_specific_results_to_estimation_res(estimator, results_dict):
"""
Stores particular items in the results dictionary that are unique to mixed
logit-type models. In particular, this function calculates and adds
`sequence_probs` and `expanded_sequence_probs` to the results dictionary.
The `... | [
"def",
"add_mixl_specific_results_to_estimation_res",
"(",
"estimator",
",",
"results_dict",
")",
":",
"# Get the probability of each sequence of choices, given the draws",
"prob_res",
"=",
"mlc",
".",
"calc_choice_sequence_probs",
"(",
"results_dict",
"[",
"\"long_probs\"",
"]",... | Stores particular items in the results dictionary that are unique to mixed
logit-type models. In particular, this function calculates and adds
`sequence_probs` and `expanded_sequence_probs` to the results dictionary.
The `constrained_pos` object is also stored to the results_dict.
Parameters
------... | [
"Stores",
"particular",
"items",
"in",
"the",
"results",
"dictionary",
"that",
"are",
"unique",
"to",
"mixed",
"logit",
"-",
"type",
"models",
".",
"In",
"particular",
"this",
"function",
"calculates",
"and",
"adds",
"sequence_probs",
"and",
"expanded_sequence_pro... | f83b0fd6debaa7358d87c3828428f6d4ead71357 | https://github.com/timothyb0912/pylogit/blob/f83b0fd6debaa7358d87c3828428f6d4ead71357/pylogit/mixed_logit.py#L135-L168 |
859 | timothyb0912/pylogit | pylogit/nested_logit.py | identify_degenerate_nests | def identify_degenerate_nests(nest_spec):
"""
Identify the nests within nest_spec that are degenerate, i.e. those nests
with only a single alternative within the nest.
Parameters
----------
nest_spec : OrderedDict.
Keys are strings that define the name of the nests. Values are lists
... | python | def identify_degenerate_nests(nest_spec):
"""
Identify the nests within nest_spec that are degenerate, i.e. those nests
with only a single alternative within the nest.
Parameters
----------
nest_spec : OrderedDict.
Keys are strings that define the name of the nests. Values are lists
... | [
"def",
"identify_degenerate_nests",
"(",
"nest_spec",
")",
":",
"degenerate_positions",
"=",
"[",
"]",
"for",
"pos",
",",
"key",
"in",
"enumerate",
"(",
"nest_spec",
")",
":",
"if",
"len",
"(",
"nest_spec",
"[",
"key",
"]",
")",
"==",
"1",
":",
"degenera... | Identify the nests within nest_spec that are degenerate, i.e. those nests
with only a single alternative within the nest.
Parameters
----------
nest_spec : OrderedDict.
Keys are strings that define the name of the nests. Values are lists
of alternative ids, denoting which alternatives b... | [
"Identify",
"the",
"nests",
"within",
"nest_spec",
"that",
"are",
"degenerate",
"i",
".",
"e",
".",
"those",
"nests",
"with",
"only",
"a",
"single",
"alternative",
"within",
"the",
"nest",
"."
] | f83b0fd6debaa7358d87c3828428f6d4ead71357 | https://github.com/timothyb0912/pylogit/blob/f83b0fd6debaa7358d87c3828428f6d4ead71357/pylogit/nested_logit.py#L36-L58 |
860 | timothyb0912/pylogit | pylogit/nested_logit.py | NestedEstimator.check_length_of_initial_values | def check_length_of_initial_values(self, init_values):
"""
Ensures that the initial values are of the correct length.
"""
# Figure out how many shape parameters we should have and how many
# index coefficients we should have
num_nests = self.rows_to_nests.shape[1]
... | python | def check_length_of_initial_values(self, init_values):
"""
Ensures that the initial values are of the correct length.
"""
# Figure out how many shape parameters we should have and how many
# index coefficients we should have
num_nests = self.rows_to_nests.shape[1]
... | [
"def",
"check_length_of_initial_values",
"(",
"self",
",",
"init_values",
")",
":",
"# Figure out how many shape parameters we should have and how many",
"# index coefficients we should have",
"num_nests",
"=",
"self",
".",
"rows_to_nests",
".",
"shape",
"[",
"1",
"]",
"num_i... | Ensures that the initial values are of the correct length. | [
"Ensures",
"that",
"the",
"initial",
"values",
"are",
"of",
"the",
"correct",
"length",
"."
] | f83b0fd6debaa7358d87c3828428f6d4ead71357 | https://github.com/timothyb0912/pylogit/blob/f83b0fd6debaa7358d87c3828428f6d4ead71357/pylogit/nested_logit.py#L177-L195 |
861 | timothyb0912/pylogit | pylogit/nested_logit.py | NestedEstimator.convenience_split_params | def convenience_split_params(self, params, return_all_types=False):
"""
Splits parameter vector into nest parameters and index parameters.
Parameters
----------
all_params : 1D ndarray.
Should contain all of the parameters being estimated (i.e. all the
ne... | python | def convenience_split_params(self, params, return_all_types=False):
"""
Splits parameter vector into nest parameters and index parameters.
Parameters
----------
all_params : 1D ndarray.
Should contain all of the parameters being estimated (i.e. all the
ne... | [
"def",
"convenience_split_params",
"(",
"self",
",",
"params",
",",
"return_all_types",
"=",
"False",
")",
":",
"return",
"split_param_vec",
"(",
"params",
",",
"self",
".",
"rows_to_nests",
",",
"return_all_types",
"=",
"return_all_types",
")"
] | Splits parameter vector into nest parameters and index parameters.
Parameters
----------
all_params : 1D ndarray.
Should contain all of the parameters being estimated (i.e. all the
nest coefficients and all of the index coefficients). All elements
should be i... | [
"Splits",
"parameter",
"vector",
"into",
"nest",
"parameters",
"and",
"index",
"parameters",
"."
] | f83b0fd6debaa7358d87c3828428f6d4ead71357 | https://github.com/timothyb0912/pylogit/blob/f83b0fd6debaa7358d87c3828428f6d4ead71357/pylogit/nested_logit.py#L197-L236 |
862 | timothyb0912/pylogit | pylogit/choice_calcs.py | robust_outer_product | def robust_outer_product(vec_1, vec_2):
"""
Calculates a 'robust' outer product of two vectors that may or may not
contain very small values.
Parameters
----------
vec_1 : 1D ndarray
vec_2 : 1D ndarray
Returns
-------
outer_prod : 2D ndarray. The outer product of vec_1 and vec_... | python | def robust_outer_product(vec_1, vec_2):
"""
Calculates a 'robust' outer product of two vectors that may or may not
contain very small values.
Parameters
----------
vec_1 : 1D ndarray
vec_2 : 1D ndarray
Returns
-------
outer_prod : 2D ndarray. The outer product of vec_1 and vec_... | [
"def",
"robust_outer_product",
"(",
"vec_1",
",",
"vec_2",
")",
":",
"mantissa_1",
",",
"exponents_1",
"=",
"np",
".",
"frexp",
"(",
"vec_1",
")",
"mantissa_2",
",",
"exponents_2",
"=",
"np",
".",
"frexp",
"(",
"vec_2",
")",
"new_mantissas",
"=",
"mantissa... | Calculates a 'robust' outer product of two vectors that may or may not
contain very small values.
Parameters
----------
vec_1 : 1D ndarray
vec_2 : 1D ndarray
Returns
-------
outer_prod : 2D ndarray. The outer product of vec_1 and vec_2 | [
"Calculates",
"a",
"robust",
"outer",
"product",
"of",
"two",
"vectors",
"that",
"may",
"or",
"may",
"not",
"contain",
"very",
"small",
"values",
"."
] | f83b0fd6debaa7358d87c3828428f6d4ead71357 | https://github.com/timothyb0912/pylogit/blob/f83b0fd6debaa7358d87c3828428f6d4ead71357/pylogit/choice_calcs.py#L523-L541 |
863 | timothyb0912/pylogit | pylogit/bootstrap_calcs.py | calc_percentile_interval | def calc_percentile_interval(bootstrap_replicates, conf_percentage):
"""
Calculate bootstrap confidence intervals based on raw percentiles of the
bootstrap distribution of samples.
Parameters
----------
bootstrap_replicates : 2D ndarray.
Each row should correspond to a different bootstr... | python | def calc_percentile_interval(bootstrap_replicates, conf_percentage):
"""
Calculate bootstrap confidence intervals based on raw percentiles of the
bootstrap distribution of samples.
Parameters
----------
bootstrap_replicates : 2D ndarray.
Each row should correspond to a different bootstr... | [
"def",
"calc_percentile_interval",
"(",
"bootstrap_replicates",
",",
"conf_percentage",
")",
":",
"# Check validity of arguments",
"check_conf_percentage_validity",
"(",
"conf_percentage",
")",
"ensure_samples_is_ndim_ndarray",
"(",
"bootstrap_replicates",
",",
"ndim",
"=",
"2"... | Calculate bootstrap confidence intervals based on raw percentiles of the
bootstrap distribution of samples.
Parameters
----------
bootstrap_replicates : 2D ndarray.
Each row should correspond to a different bootstrap parameter sample.
Each column should correspond to an element of the p... | [
"Calculate",
"bootstrap",
"confidence",
"intervals",
"based",
"on",
"raw",
"percentiles",
"of",
"the",
"bootstrap",
"distribution",
"of",
"samples",
"."
] | f83b0fd6debaa7358d87c3828428f6d4ead71357 | https://github.com/timothyb0912/pylogit/blob/f83b0fd6debaa7358d87c3828428f6d4ead71357/pylogit/bootstrap_calcs.py#L20-L83 |
864 | timothyb0912/pylogit | pylogit/bootstrap_calcs.py | calc_bca_interval | def calc_bca_interval(bootstrap_replicates,
jackknife_replicates,
mle_params,
conf_percentage):
"""
Calculate 'bias-corrected and accelerated' bootstrap confidence intervals.
Parameters
----------
bootstrap_replicates : 2D ndarray.
... | python | def calc_bca_interval(bootstrap_replicates,
jackknife_replicates,
mle_params,
conf_percentage):
"""
Calculate 'bias-corrected and accelerated' bootstrap confidence intervals.
Parameters
----------
bootstrap_replicates : 2D ndarray.
... | [
"def",
"calc_bca_interval",
"(",
"bootstrap_replicates",
",",
"jackknife_replicates",
",",
"mle_params",
",",
"conf_percentage",
")",
":",
"# Check validity of arguments",
"check_conf_percentage_validity",
"(",
"conf_percentage",
")",
"ensure_samples_is_ndim_ndarray",
"(",
"boo... | Calculate 'bias-corrected and accelerated' bootstrap confidence intervals.
Parameters
----------
bootstrap_replicates : 2D ndarray.
Each row should correspond to a different bootstrap parameter sample.
Each column should correspond to an element of the parameter vector
being estimat... | [
"Calculate",
"bias",
"-",
"corrected",
"and",
"accelerated",
"bootstrap",
"confidence",
"intervals",
"."
] | f83b0fd6debaa7358d87c3828428f6d4ead71357 | https://github.com/timothyb0912/pylogit/blob/f83b0fd6debaa7358d87c3828428f6d4ead71357/pylogit/bootstrap_calcs.py#L254-L323 |
865 | timothyb0912/pylogit | pylogit/bootstrap_mle.py | extract_default_init_vals | def extract_default_init_vals(orig_model_obj, mnl_point_series, num_params):
"""
Get the default initial values for the desired model type, based on the
point estimate of the MNL model that is 'closest' to the desired model.
Parameters
----------
orig_model_obj : an instance or sublcass of the ... | python | def extract_default_init_vals(orig_model_obj, mnl_point_series, num_params):
"""
Get the default initial values for the desired model type, based on the
point estimate of the MNL model that is 'closest' to the desired model.
Parameters
----------
orig_model_obj : an instance or sublcass of the ... | [
"def",
"extract_default_init_vals",
"(",
"orig_model_obj",
",",
"mnl_point_series",
",",
"num_params",
")",
":",
"# Initialize the initial values",
"init_vals",
"=",
"np",
".",
"zeros",
"(",
"num_params",
",",
"dtype",
"=",
"float",
")",
"# Figure out which values in mn... | Get the default initial values for the desired model type, based on the
point estimate of the MNL model that is 'closest' to the desired model.
Parameters
----------
orig_model_obj : an instance or sublcass of the MNDC class.
Should correspond to the actual model that we want to bootstrap.
... | [
"Get",
"the",
"default",
"initial",
"values",
"for",
"the",
"desired",
"model",
"type",
"based",
"on",
"the",
"point",
"estimate",
"of",
"the",
"MNL",
"model",
"that",
"is",
"closest",
"to",
"the",
"desired",
"model",
"."
] | f83b0fd6debaa7358d87c3828428f6d4ead71357 | https://github.com/timothyb0912/pylogit/blob/f83b0fd6debaa7358d87c3828428f6d4ead71357/pylogit/bootstrap_mle.py#L14-L75 |
866 | timothyb0912/pylogit | pylogit/bootstrap_mle.py | get_model_abbrev | def get_model_abbrev(model_obj):
"""
Extract the string used to specify the model type of this model object in
`pylogit.create_chohice_model`.
Parameters
----------
model_obj : An MNDC_Model instance.
Returns
-------
str. The internal abbreviation used for the particular type of MN... | python | def get_model_abbrev(model_obj):
"""
Extract the string used to specify the model type of this model object in
`pylogit.create_chohice_model`.
Parameters
----------
model_obj : An MNDC_Model instance.
Returns
-------
str. The internal abbreviation used for the particular type of MN... | [
"def",
"get_model_abbrev",
"(",
"model_obj",
")",
":",
"# Get the 'display name' for our model.",
"model_type",
"=",
"model_obj",
".",
"model_type",
"# Find the model abbreviation for this model's display name.",
"for",
"key",
"in",
"model_type_to_display_name",
":",
"if",
"mod... | Extract the string used to specify the model type of this model object in
`pylogit.create_chohice_model`.
Parameters
----------
model_obj : An MNDC_Model instance.
Returns
-------
str. The internal abbreviation used for the particular type of MNDC_Model. | [
"Extract",
"the",
"string",
"used",
"to",
"specify",
"the",
"model",
"type",
"of",
"this",
"model",
"object",
"in",
"pylogit",
".",
"create_chohice_model",
"."
] | f83b0fd6debaa7358d87c3828428f6d4ead71357 | https://github.com/timothyb0912/pylogit/blob/f83b0fd6debaa7358d87c3828428f6d4ead71357/pylogit/bootstrap_mle.py#L78-L100 |
867 | timothyb0912/pylogit | pylogit/bootstrap_mle.py | get_model_creation_kwargs | def get_model_creation_kwargs(model_obj):
"""
Get a dictionary of the keyword arguments needed to create the passed model
object using `pylogit.create_choice_model`.
Parameters
----------
model_obj : An MNDC_Model instance.
Returns
-------
model_kwargs : dict.
Contains the ... | python | def get_model_creation_kwargs(model_obj):
"""
Get a dictionary of the keyword arguments needed to create the passed model
object using `pylogit.create_choice_model`.
Parameters
----------
model_obj : An MNDC_Model instance.
Returns
-------
model_kwargs : dict.
Contains the ... | [
"def",
"get_model_creation_kwargs",
"(",
"model_obj",
")",
":",
"# Extract the model abbreviation for this model",
"model_abbrev",
"=",
"get_model_abbrev",
"(",
"model_obj",
")",
"# Create a dictionary to store the keyword arguments needed to Initialize",
"# the new model object.d",
"m... | Get a dictionary of the keyword arguments needed to create the passed model
object using `pylogit.create_choice_model`.
Parameters
----------
model_obj : An MNDC_Model instance.
Returns
-------
model_kwargs : dict.
Contains the keyword arguments and the required values that are nee... | [
"Get",
"a",
"dictionary",
"of",
"the",
"keyword",
"arguments",
"needed",
"to",
"create",
"the",
"passed",
"model",
"object",
"using",
"pylogit",
".",
"create_choice_model",
"."
] | f83b0fd6debaa7358d87c3828428f6d4ead71357 | https://github.com/timothyb0912/pylogit/blob/f83b0fd6debaa7358d87c3828428f6d4ead71357/pylogit/bootstrap_mle.py#L103-L133 |
868 | timothyb0912/pylogit | pylogit/pylogit.py | ensure_valid_model_type | def ensure_valid_model_type(specified_type, model_type_list):
"""
Checks to make sure that `specified_type` is in `model_type_list` and
raises a helpful error if this is not the case.
Parameters
----------
specified_type : str.
Denotes the user-specified model type that is to be checked... | python | def ensure_valid_model_type(specified_type, model_type_list):
"""
Checks to make sure that `specified_type` is in `model_type_list` and
raises a helpful error if this is not the case.
Parameters
----------
specified_type : str.
Denotes the user-specified model type that is to be checked... | [
"def",
"ensure_valid_model_type",
"(",
"specified_type",
",",
"model_type_list",
")",
":",
"if",
"specified_type",
"not",
"in",
"model_type_list",
":",
"msg_1",
"=",
"\"The specified model_type was not valid.\"",
"msg_2",
"=",
"\"Valid model-types are {}\"",
".",
"format",
... | Checks to make sure that `specified_type` is in `model_type_list` and
raises a helpful error if this is not the case.
Parameters
----------
specified_type : str.
Denotes the user-specified model type that is to be checked.
model_type_list : list of strings.
Contains all of the model... | [
"Checks",
"to",
"make",
"sure",
"that",
"specified_type",
"is",
"in",
"model_type_list",
"and",
"raises",
"a",
"helpful",
"error",
"if",
"this",
"is",
"not",
"the",
"case",
"."
] | f83b0fd6debaa7358d87c3828428f6d4ead71357 | https://github.com/timothyb0912/pylogit/blob/f83b0fd6debaa7358d87c3828428f6d4ead71357/pylogit/pylogit.py#L58-L80 |
869 | timothyb0912/pylogit | pylogit/base_multinomial_cm_v2.py | ensure_valid_nums_in_specification_cols | def ensure_valid_nums_in_specification_cols(specification, dataframe):
"""
Checks whether each column in `specification` contains numeric data,
excluding positive or negative infinity and excluding NaN. Raises
ValueError if any of the columns do not meet these requirements.
Parameters
---------... | python | def ensure_valid_nums_in_specification_cols(specification, dataframe):
"""
Checks whether each column in `specification` contains numeric data,
excluding positive or negative infinity and excluding NaN. Raises
ValueError if any of the columns do not meet these requirements.
Parameters
---------... | [
"def",
"ensure_valid_nums_in_specification_cols",
"(",
"specification",
",",
"dataframe",
")",
":",
"problem_cols",
"=",
"[",
"]",
"for",
"col",
"in",
"specification",
":",
"# The condition below checks for values that are not floats or integers",
"# This will catch values that a... | Checks whether each column in `specification` contains numeric data,
excluding positive or negative infinity and excluding NaN. Raises
ValueError if any of the columns do not meet these requirements.
Parameters
----------
specification : iterable of column headers in `dataframe`.
dataframe : pa... | [
"Checks",
"whether",
"each",
"column",
"in",
"specification",
"contains",
"numeric",
"data",
"excluding",
"positive",
"or",
"negative",
"infinity",
"and",
"excluding",
"NaN",
".",
"Raises",
"ValueError",
"if",
"any",
"of",
"the",
"columns",
"do",
"not",
"meet",
... | f83b0fd6debaa7358d87c3828428f6d4ead71357 | https://github.com/timothyb0912/pylogit/blob/f83b0fd6debaa7358d87c3828428f6d4ead71357/pylogit/base_multinomial_cm_v2.py#L60-L96 |
870 | timothyb0912/pylogit | pylogit/base_multinomial_cm_v2.py | check_length_of_shape_or_intercept_names | def check_length_of_shape_or_intercept_names(name_list,
num_alts,
constrained_param,
list_title):
"""
Ensures that the length of the parameter names matches the number of
pa... | python | def check_length_of_shape_or_intercept_names(name_list,
num_alts,
constrained_param,
list_title):
"""
Ensures that the length of the parameter names matches the number of
pa... | [
"def",
"check_length_of_shape_or_intercept_names",
"(",
"name_list",
",",
"num_alts",
",",
"constrained_param",
",",
"list_title",
")",
":",
"if",
"len",
"(",
"name_list",
")",
"!=",
"(",
"num_alts",
"-",
"constrained_param",
")",
":",
"msg_1",
"=",
"\"{} is of th... | Ensures that the length of the parameter names matches the number of
parameters that will be estimated. Will raise a ValueError otherwise.
Parameters
----------
name_list : list of strings.
Each element should be the name of a parameter that is to be estimated.
num_alts : int.
Shoul... | [
"Ensures",
"that",
"the",
"length",
"of",
"the",
"parameter",
"names",
"matches",
"the",
"number",
"of",
"parameters",
"that",
"will",
"be",
"estimated",
".",
"Will",
"raise",
"a",
"ValueError",
"otherwise",
"."
] | f83b0fd6debaa7358d87c3828428f6d4ead71357 | https://github.com/timothyb0912/pylogit/blob/f83b0fd6debaa7358d87c3828428f6d4ead71357/pylogit/base_multinomial_cm_v2.py#L145-L180 |
871 | timothyb0912/pylogit | pylogit/base_multinomial_cm_v2.py | check_type_of_nest_spec_keys_and_values | def check_type_of_nest_spec_keys_and_values(nest_spec):
"""
Ensures that the keys and values of `nest_spec` are strings and lists.
Raises a helpful ValueError if they are.
Parameters
----------
nest_spec : OrderedDict, or None, optional.
Keys are strings that define the name of the nest... | python | def check_type_of_nest_spec_keys_and_values(nest_spec):
"""
Ensures that the keys and values of `nest_spec` are strings and lists.
Raises a helpful ValueError if they are.
Parameters
----------
nest_spec : OrderedDict, or None, optional.
Keys are strings that define the name of the nest... | [
"def",
"check_type_of_nest_spec_keys_and_values",
"(",
"nest_spec",
")",
":",
"try",
":",
"assert",
"all",
"(",
"[",
"isinstance",
"(",
"k",
",",
"str",
")",
"for",
"k",
"in",
"nest_spec",
"]",
")",
"assert",
"all",
"(",
"[",
"isinstance",
"(",
"nest_spec"... | Ensures that the keys and values of `nest_spec` are strings and lists.
Raises a helpful ValueError if they are.
Parameters
----------
nest_spec : OrderedDict, or None, optional.
Keys are strings that define the name of the nests. Values are lists of
alternative ids, denoting which alter... | [
"Ensures",
"that",
"the",
"keys",
"and",
"values",
"of",
"nest_spec",
"are",
"strings",
"and",
"lists",
".",
"Raises",
"a",
"helpful",
"ValueError",
"if",
"they",
"are",
"."
] | f83b0fd6debaa7358d87c3828428f6d4ead71357 | https://github.com/timothyb0912/pylogit/blob/f83b0fd6debaa7358d87c3828428f6d4ead71357/pylogit/base_multinomial_cm_v2.py#L183-L207 |
872 | timothyb0912/pylogit | pylogit/base_multinomial_cm_v2.py | check_for_empty_nests_in_nest_spec | def check_for_empty_nests_in_nest_spec(nest_spec):
"""
Ensures that the values of `nest_spec` are not empty lists.
Raises a helpful ValueError if they are.
Parameters
----------
nest_spec : OrderedDict, or None, optional.
Keys are strings that define the name of the nests. Values are li... | python | def check_for_empty_nests_in_nest_spec(nest_spec):
"""
Ensures that the values of `nest_spec` are not empty lists.
Raises a helpful ValueError if they are.
Parameters
----------
nest_spec : OrderedDict, or None, optional.
Keys are strings that define the name of the nests. Values are li... | [
"def",
"check_for_empty_nests_in_nest_spec",
"(",
"nest_spec",
")",
":",
"empty_nests",
"=",
"[",
"]",
"for",
"k",
"in",
"nest_spec",
":",
"if",
"len",
"(",
"nest_spec",
"[",
"k",
"]",
")",
"==",
"0",
":",
"empty_nests",
".",
"append",
"(",
"k",
")",
"... | Ensures that the values of `nest_spec` are not empty lists.
Raises a helpful ValueError if they are.
Parameters
----------
nest_spec : OrderedDict, or None, optional.
Keys are strings that define the name of the nests. Values are lists of
alternative ids, denoting which alternatives bel... | [
"Ensures",
"that",
"the",
"values",
"of",
"nest_spec",
"are",
"not",
"empty",
"lists",
".",
"Raises",
"a",
"helpful",
"ValueError",
"if",
"they",
"are",
"."
] | f83b0fd6debaa7358d87c3828428f6d4ead71357 | https://github.com/timothyb0912/pylogit/blob/f83b0fd6debaa7358d87c3828428f6d4ead71357/pylogit/base_multinomial_cm_v2.py#L210-L235 |
873 | timothyb0912/pylogit | pylogit/base_multinomial_cm_v2.py | ensure_alt_ids_in_nest_spec_are_ints | def ensure_alt_ids_in_nest_spec_are_ints(nest_spec, list_elements):
"""
Ensures that the alternative id's in `nest_spec` are integers. Raises a
helpful ValueError if they are not.
Parameters
----------
nest_spec : OrderedDict, or None, optional.
Keys are strings that define the name of ... | python | def ensure_alt_ids_in_nest_spec_are_ints(nest_spec, list_elements):
"""
Ensures that the alternative id's in `nest_spec` are integers. Raises a
helpful ValueError if they are not.
Parameters
----------
nest_spec : OrderedDict, or None, optional.
Keys are strings that define the name of ... | [
"def",
"ensure_alt_ids_in_nest_spec_are_ints",
"(",
"nest_spec",
",",
"list_elements",
")",
":",
"try",
":",
"assert",
"all",
"(",
"[",
"isinstance",
"(",
"x",
",",
"int",
")",
"for",
"x",
"in",
"list_elements",
"]",
")",
"except",
"AssertionError",
":",
"ms... | Ensures that the alternative id's in `nest_spec` are integers. Raises a
helpful ValueError if they are not.
Parameters
----------
nest_spec : OrderedDict, or None, optional.
Keys are strings that define the name of the nests. Values are lists of
alternative ids, denoting which alternati... | [
"Ensures",
"that",
"the",
"alternative",
"id",
"s",
"in",
"nest_spec",
"are",
"integers",
".",
"Raises",
"a",
"helpful",
"ValueError",
"if",
"they",
"are",
"not",
"."
] | f83b0fd6debaa7358d87c3828428f6d4ead71357 | https://github.com/timothyb0912/pylogit/blob/f83b0fd6debaa7358d87c3828428f6d4ead71357/pylogit/base_multinomial_cm_v2.py#L238-L264 |
874 | timothyb0912/pylogit | pylogit/base_multinomial_cm_v2.py | ensure_alt_ids_are_only_in_one_nest | def ensure_alt_ids_are_only_in_one_nest(nest_spec, list_elements):
"""
Ensures that the alternative id's in `nest_spec` are only associated with
a single nest. Raises a helpful ValueError if they are not.
Parameters
----------
nest_spec : OrderedDict, or None, optional.
Keys are strings... | python | def ensure_alt_ids_are_only_in_one_nest(nest_spec, list_elements):
"""
Ensures that the alternative id's in `nest_spec` are only associated with
a single nest. Raises a helpful ValueError if they are not.
Parameters
----------
nest_spec : OrderedDict, or None, optional.
Keys are strings... | [
"def",
"ensure_alt_ids_are_only_in_one_nest",
"(",
"nest_spec",
",",
"list_elements",
")",
":",
"try",
":",
"assert",
"len",
"(",
"set",
"(",
"list_elements",
")",
")",
"==",
"len",
"(",
"list_elements",
")",
"except",
"AssertionError",
":",
"msg",
"=",
"\"Eac... | Ensures that the alternative id's in `nest_spec` are only associated with
a single nest. Raises a helpful ValueError if they are not.
Parameters
----------
nest_spec : OrderedDict, or None, optional.
Keys are strings that define the name of the nests. Values are lists of
alternative ids... | [
"Ensures",
"that",
"the",
"alternative",
"id",
"s",
"in",
"nest_spec",
"are",
"only",
"associated",
"with",
"a",
"single",
"nest",
".",
"Raises",
"a",
"helpful",
"ValueError",
"if",
"they",
"are",
"not",
"."
] | f83b0fd6debaa7358d87c3828428f6d4ead71357 | https://github.com/timothyb0912/pylogit/blob/f83b0fd6debaa7358d87c3828428f6d4ead71357/pylogit/base_multinomial_cm_v2.py#L267-L293 |
875 | timothyb0912/pylogit | pylogit/base_multinomial_cm_v2.py | ensure_all_alt_ids_have_a_nest | def ensure_all_alt_ids_have_a_nest(nest_spec, list_elements, all_ids):
"""
Ensures that the alternative id's in `nest_spec` are all associated with
a nest. Raises a helpful ValueError if they are not.
Parameters
----------
nest_spec : OrderedDict, or None, optional.
Keys are strings tha... | python | def ensure_all_alt_ids_have_a_nest(nest_spec, list_elements, all_ids):
"""
Ensures that the alternative id's in `nest_spec` are all associated with
a nest. Raises a helpful ValueError if they are not.
Parameters
----------
nest_spec : OrderedDict, or None, optional.
Keys are strings tha... | [
"def",
"ensure_all_alt_ids_have_a_nest",
"(",
"nest_spec",
",",
"list_elements",
",",
"all_ids",
")",
":",
"unaccounted_alt_ids",
"=",
"[",
"]",
"for",
"alt_id",
"in",
"all_ids",
":",
"if",
"alt_id",
"not",
"in",
"list_elements",
":",
"unaccounted_alt_ids",
".",
... | Ensures that the alternative id's in `nest_spec` are all associated with
a nest. Raises a helpful ValueError if they are not.
Parameters
----------
nest_spec : OrderedDict, or None, optional.
Keys are strings that define the name of the nests. Values are lists of
alternative ids, denoti... | [
"Ensures",
"that",
"the",
"alternative",
"id",
"s",
"in",
"nest_spec",
"are",
"all",
"associated",
"with",
"a",
"nest",
".",
"Raises",
"a",
"helpful",
"ValueError",
"if",
"they",
"are",
"not",
"."
] | f83b0fd6debaa7358d87c3828428f6d4ead71357 | https://github.com/timothyb0912/pylogit/blob/f83b0fd6debaa7358d87c3828428f6d4ead71357/pylogit/base_multinomial_cm_v2.py#L296-L327 |
876 | timothyb0912/pylogit | pylogit/base_multinomial_cm_v2.py | ensure_nest_alts_are_valid_alts | def ensure_nest_alts_are_valid_alts(nest_spec, list_elements, all_ids):
"""
Ensures that the alternative id's in `nest_spec` are all in the universal
choice set for this dataset. Raises a helpful ValueError if they are not.
Parameters
----------
nest_spec : OrderedDict, or None, optional.
... | python | def ensure_nest_alts_are_valid_alts(nest_spec, list_elements, all_ids):
"""
Ensures that the alternative id's in `nest_spec` are all in the universal
choice set for this dataset. Raises a helpful ValueError if they are not.
Parameters
----------
nest_spec : OrderedDict, or None, optional.
... | [
"def",
"ensure_nest_alts_are_valid_alts",
"(",
"nest_spec",
",",
"list_elements",
",",
"all_ids",
")",
":",
"invalid_alt_ids",
"=",
"[",
"]",
"for",
"x",
"in",
"list_elements",
":",
"if",
"x",
"not",
"in",
"all_ids",
":",
"invalid_alt_ids",
".",
"append",
"(",... | Ensures that the alternative id's in `nest_spec` are all in the universal
choice set for this dataset. Raises a helpful ValueError if they are not.
Parameters
----------
nest_spec : OrderedDict, or None, optional.
Keys are strings that define the name of the nests. Values are lists of
a... | [
"Ensures",
"that",
"the",
"alternative",
"id",
"s",
"in",
"nest_spec",
"are",
"all",
"in",
"the",
"universal",
"choice",
"set",
"for",
"this",
"dataset",
".",
"Raises",
"a",
"helpful",
"ValueError",
"if",
"they",
"are",
"not",
"."
] | f83b0fd6debaa7358d87c3828428f6d4ead71357 | https://github.com/timothyb0912/pylogit/blob/f83b0fd6debaa7358d87c3828428f6d4ead71357/pylogit/base_multinomial_cm_v2.py#L330-L361 |
877 | timothyb0912/pylogit | pylogit/base_multinomial_cm_v2.py | check_type_and_size_of_param_list | def check_type_and_size_of_param_list(param_list, expected_length):
"""
Ensure that param_list is a list with the expected length. Raises a helpful
ValueError if this is not the case.
"""
try:
assert isinstance(param_list, list)
assert len(param_list) == expected_length
except As... | python | def check_type_and_size_of_param_list(param_list, expected_length):
"""
Ensure that param_list is a list with the expected length. Raises a helpful
ValueError if this is not the case.
"""
try:
assert isinstance(param_list, list)
assert len(param_list) == expected_length
except As... | [
"def",
"check_type_and_size_of_param_list",
"(",
"param_list",
",",
"expected_length",
")",
":",
"try",
":",
"assert",
"isinstance",
"(",
"param_list",
",",
"list",
")",
"assert",
"len",
"(",
"param_list",
")",
"==",
"expected_length",
"except",
"AssertionError",
... | Ensure that param_list is a list with the expected length. Raises a helpful
ValueError if this is not the case. | [
"Ensure",
"that",
"param_list",
"is",
"a",
"list",
"with",
"the",
"expected",
"length",
".",
"Raises",
"a",
"helpful",
"ValueError",
"if",
"this",
"is",
"not",
"the",
"case",
"."
] | f83b0fd6debaa7358d87c3828428f6d4ead71357 | https://github.com/timothyb0912/pylogit/blob/f83b0fd6debaa7358d87c3828428f6d4ead71357/pylogit/base_multinomial_cm_v2.py#L410-L422 |
878 | timothyb0912/pylogit | pylogit/base_multinomial_cm_v2.py | check_type_of_param_list_elements | def check_type_of_param_list_elements(param_list):
"""
Ensures that all elements of param_list are ndarrays or None. Raises a
helpful ValueError if otherwise.
"""
try:
assert isinstance(param_list[0], np.ndarray)
assert all([(x is None or isinstance(x, np.ndarray))
... | python | def check_type_of_param_list_elements(param_list):
"""
Ensures that all elements of param_list are ndarrays or None. Raises a
helpful ValueError if otherwise.
"""
try:
assert isinstance(param_list[0], np.ndarray)
assert all([(x is None or isinstance(x, np.ndarray))
... | [
"def",
"check_type_of_param_list_elements",
"(",
"param_list",
")",
":",
"try",
":",
"assert",
"isinstance",
"(",
"param_list",
"[",
"0",
"]",
",",
"np",
".",
"ndarray",
")",
"assert",
"all",
"(",
"[",
"(",
"x",
"is",
"None",
"or",
"isinstance",
"(",
"x"... | Ensures that all elements of param_list are ndarrays or None. Raises a
helpful ValueError if otherwise. | [
"Ensures",
"that",
"all",
"elements",
"of",
"param_list",
"are",
"ndarrays",
"or",
"None",
".",
"Raises",
"a",
"helpful",
"ValueError",
"if",
"otherwise",
"."
] | f83b0fd6debaa7358d87c3828428f6d4ead71357 | https://github.com/timothyb0912/pylogit/blob/f83b0fd6debaa7358d87c3828428f6d4ead71357/pylogit/base_multinomial_cm_v2.py#L425-L440 |
879 | timothyb0912/pylogit | pylogit/base_multinomial_cm_v2.py | check_num_columns_in_param_list_arrays | def check_num_columns_in_param_list_arrays(param_list):
"""
Ensure that each array in param_list, that is not None, has the same number
of columns. Raises a helpful ValueError if otherwise.
Parameters
----------
param_list : list of ndarrays or None.
Returns
-------
None.
"""
... | python | def check_num_columns_in_param_list_arrays(param_list):
"""
Ensure that each array in param_list, that is not None, has the same number
of columns. Raises a helpful ValueError if otherwise.
Parameters
----------
param_list : list of ndarrays or None.
Returns
-------
None.
"""
... | [
"def",
"check_num_columns_in_param_list_arrays",
"(",
"param_list",
")",
":",
"try",
":",
"num_columns",
"=",
"param_list",
"[",
"0",
"]",
".",
"shape",
"[",
"1",
"]",
"assert",
"all",
"(",
"[",
"x",
"is",
"None",
"or",
"(",
"x",
".",
"shape",
"[",
"1"... | Ensure that each array in param_list, that is not None, has the same number
of columns. Raises a helpful ValueError if otherwise.
Parameters
----------
param_list : list of ndarrays or None.
Returns
-------
None. | [
"Ensure",
"that",
"each",
"array",
"in",
"param_list",
"that",
"is",
"not",
"None",
"has",
"the",
"same",
"number",
"of",
"columns",
".",
"Raises",
"a",
"helpful",
"ValueError",
"if",
"otherwise",
"."
] | f83b0fd6debaa7358d87c3828428f6d4ead71357 | https://github.com/timothyb0912/pylogit/blob/f83b0fd6debaa7358d87c3828428f6d4ead71357/pylogit/base_multinomial_cm_v2.py#L443-L464 |
880 | timothyb0912/pylogit | pylogit/base_multinomial_cm_v2.py | ensure_all_mixing_vars_are_in_the_name_dict | def ensure_all_mixing_vars_are_in_the_name_dict(mixing_vars,
name_dict,
ind_var_names):
"""
Ensures that all of the variables listed in `mixing_vars` are present in
`ind_var_names`. Raises a helpful ValueError if... | python | def ensure_all_mixing_vars_are_in_the_name_dict(mixing_vars,
name_dict,
ind_var_names):
"""
Ensures that all of the variables listed in `mixing_vars` are present in
`ind_var_names`. Raises a helpful ValueError if... | [
"def",
"ensure_all_mixing_vars_are_in_the_name_dict",
"(",
"mixing_vars",
",",
"name_dict",
",",
"ind_var_names",
")",
":",
"if",
"mixing_vars",
"is",
"None",
":",
"return",
"None",
"# Determine the strings in mixing_vars that are missing from ind_var_names",
"problem_names",
"... | Ensures that all of the variables listed in `mixing_vars` are present in
`ind_var_names`. Raises a helpful ValueError if otherwise.
Parameters
----------
mixing_vars : list of strings, or None.
Each string denotes a parameter to be treated as a random variable.
name_dict : OrderedDict or No... | [
"Ensures",
"that",
"all",
"of",
"the",
"variables",
"listed",
"in",
"mixing_vars",
"are",
"present",
"in",
"ind_var_names",
".",
"Raises",
"a",
"helpful",
"ValueError",
"if",
"otherwise",
"."
] | f83b0fd6debaa7358d87c3828428f6d4ead71357 | https://github.com/timothyb0912/pylogit/blob/f83b0fd6debaa7358d87c3828428f6d4ead71357/pylogit/base_multinomial_cm_v2.py#L524-L574 |
881 | timothyb0912/pylogit | pylogit/base_multinomial_cm_v2.py | compute_aic | def compute_aic(model_object):
"""
Compute the Akaike Information Criteria for an estimated model.
Parameters
----------
model_object : an MNDC_Model (multinomial discrete choice model) instance.
The model should have already been estimated.
`model_object.log_likelihood` should be a... | python | def compute_aic(model_object):
"""
Compute the Akaike Information Criteria for an estimated model.
Parameters
----------
model_object : an MNDC_Model (multinomial discrete choice model) instance.
The model should have already been estimated.
`model_object.log_likelihood` should be a... | [
"def",
"compute_aic",
"(",
"model_object",
")",
":",
"assert",
"isinstance",
"(",
"model_object",
".",
"params",
",",
"pd",
".",
"Series",
")",
"assert",
"isinstance",
"(",
"model_object",
".",
"log_likelihood",
",",
"Number",
")",
"return",
"-",
"2",
"*",
... | Compute the Akaike Information Criteria for an estimated model.
Parameters
----------
model_object : an MNDC_Model (multinomial discrete choice model) instance.
The model should have already been estimated.
`model_object.log_likelihood` should be a number, and
`model_object.params` ... | [
"Compute",
"the",
"Akaike",
"Information",
"Criteria",
"for",
"an",
"estimated",
"model",
"."
] | f83b0fd6debaa7358d87c3828428f6d4ead71357 | https://github.com/timothyb0912/pylogit/blob/f83b0fd6debaa7358d87c3828428f6d4ead71357/pylogit/base_multinomial_cm_v2.py#L611-L639 |
882 | timothyb0912/pylogit | pylogit/base_multinomial_cm_v2.py | compute_bic | def compute_bic(model_object):
"""
Compute the Bayesian Information Criteria for an estimated model.
Parameters
----------
model_object : an MNDC_Model (multinomial discrete choice model) instance.
The model should have already been estimated.
`model_object.log_likelihood` and `mode... | python | def compute_bic(model_object):
"""
Compute the Bayesian Information Criteria for an estimated model.
Parameters
----------
model_object : an MNDC_Model (multinomial discrete choice model) instance.
The model should have already been estimated.
`model_object.log_likelihood` and `mode... | [
"def",
"compute_bic",
"(",
"model_object",
")",
":",
"assert",
"isinstance",
"(",
"model_object",
".",
"params",
",",
"pd",
".",
"Series",
")",
"assert",
"isinstance",
"(",
"model_object",
".",
"log_likelihood",
",",
"Number",
")",
"assert",
"isinstance",
"(",... | Compute the Bayesian Information Criteria for an estimated model.
Parameters
----------
model_object : an MNDC_Model (multinomial discrete choice model) instance.
The model should have already been estimated.
`model_object.log_likelihood` and `model_object.nobs` should be a
number, ... | [
"Compute",
"the",
"Bayesian",
"Information",
"Criteria",
"for",
"an",
"estimated",
"model",
"."
] | f83b0fd6debaa7358d87c3828428f6d4ead71357 | https://github.com/timothyb0912/pylogit/blob/f83b0fd6debaa7358d87c3828428f6d4ead71357/pylogit/base_multinomial_cm_v2.py#L642-L681 |
883 | timothyb0912/pylogit | pylogit/base_multinomial_cm_v2.py | MNDC_Model._create_results_summary | def _create_results_summary(self):
"""
Create the dataframe that displays the estimation results, and store
it on the model instance.
Returns
-------
None.
"""
# Make sure we have all attributes needed to create the results summary
needed_attribut... | python | def _create_results_summary(self):
"""
Create the dataframe that displays the estimation results, and store
it on the model instance.
Returns
-------
None.
"""
# Make sure we have all attributes needed to create the results summary
needed_attribut... | [
"def",
"_create_results_summary",
"(",
"self",
")",
":",
"# Make sure we have all attributes needed to create the results summary",
"needed_attributes",
"=",
"[",
"\"params\"",
",",
"\"standard_errors\"",
",",
"\"tvalues\"",
",",
"\"pvalues\"",
",",
"\"robust_std_errs\"",
",",
... | Create the dataframe that displays the estimation results, and store
it on the model instance.
Returns
-------
None. | [
"Create",
"the",
"dataframe",
"that",
"displays",
"the",
"estimation",
"results",
"and",
"store",
"it",
"on",
"the",
"model",
"instance",
"."
] | f83b0fd6debaa7358d87c3828428f6d4ead71357 | https://github.com/timothyb0912/pylogit/blob/f83b0fd6debaa7358d87c3828428f6d4ead71357/pylogit/base_multinomial_cm_v2.py#L995-L1029 |
884 | timothyb0912/pylogit | pylogit/base_multinomial_cm_v2.py | MNDC_Model._record_values_for_fit_summary_and_statsmodels | def _record_values_for_fit_summary_and_statsmodels(self):
"""
Store the various estimation results that are used to describe how well
the estimated model fits the given dataset, and record the values that
are needed for the statsmodels estimation results table. All values are
sto... | python | def _record_values_for_fit_summary_and_statsmodels(self):
"""
Store the various estimation results that are used to describe how well
the estimated model fits the given dataset, and record the values that
are needed for the statsmodels estimation results table. All values are
sto... | [
"def",
"_record_values_for_fit_summary_and_statsmodels",
"(",
"self",
")",
":",
"# Make sure we have all attributes needed to create the results summary",
"needed_attributes",
"=",
"[",
"\"fitted_probs\"",
",",
"\"params\"",
",",
"\"log_likelihood\"",
",",
"\"standard_errors\"",
"]... | Store the various estimation results that are used to describe how well
the estimated model fits the given dataset, and record the values that
are needed for the statsmodels estimation results table. All values are
stored on the model instance.
Returns
-------
None. | [
"Store",
"the",
"various",
"estimation",
"results",
"that",
"are",
"used",
"to",
"describe",
"how",
"well",
"the",
"estimated",
"model",
"fits",
"the",
"given",
"dataset",
"and",
"record",
"the",
"values",
"that",
"are",
"needed",
"for",
"the",
"statsmodels",
... | f83b0fd6debaa7358d87c3828428f6d4ead71357 | https://github.com/timothyb0912/pylogit/blob/f83b0fd6debaa7358d87c3828428f6d4ead71357/pylogit/base_multinomial_cm_v2.py#L1031-L1071 |
885 | timothyb0912/pylogit | pylogit/base_multinomial_cm_v2.py | MNDC_Model._store_inferential_results | def _store_inferential_results(self,
value_array,
index_names,
attribute_name,
series_name=None,
column_names=None):
"""
Store th... | python | def _store_inferential_results(self,
value_array,
index_names,
attribute_name,
series_name=None,
column_names=None):
"""
Store th... | [
"def",
"_store_inferential_results",
"(",
"self",
",",
"value_array",
",",
"index_names",
",",
"attribute_name",
",",
"series_name",
"=",
"None",
",",
"column_names",
"=",
"None",
")",
":",
"if",
"len",
"(",
"value_array",
".",
"shape",
")",
"==",
"1",
":",
... | Store the estimation results that relate to statistical inference, such
as parameter estimates, standard errors, p-values, etc.
Parameters
----------
value_array : 1D or 2D ndarray.
Contains the values that are to be stored on the model instance.
index_names : list o... | [
"Store",
"the",
"estimation",
"results",
"that",
"relate",
"to",
"statistical",
"inference",
"such",
"as",
"parameter",
"estimates",
"standard",
"errors",
"p",
"-",
"values",
"etc",
"."
] | f83b0fd6debaa7358d87c3828428f6d4ead71357 | https://github.com/timothyb0912/pylogit/blob/f83b0fd6debaa7358d87c3828428f6d4ead71357/pylogit/base_multinomial_cm_v2.py#L1117-L1164 |
886 | timothyb0912/pylogit | pylogit/base_multinomial_cm_v2.py | MNDC_Model._store_generic_inference_results | def _store_generic_inference_results(self,
results_dict,
all_params,
all_names):
"""
Store the model inference values that are common to all choice models.
This includes thi... | python | def _store_generic_inference_results(self,
results_dict,
all_params,
all_names):
"""
Store the model inference values that are common to all choice models.
This includes thi... | [
"def",
"_store_generic_inference_results",
"(",
"self",
",",
"results_dict",
",",
"all_params",
",",
"all_names",
")",
":",
"# Store the utility coefficients",
"self",
".",
"_store_inferential_results",
"(",
"results_dict",
"[",
"\"utility_coefs\"",
"]",
",",
"index_names... | Store the model inference values that are common to all choice models.
This includes things like index coefficients, gradients, hessians,
asymptotic covariance matrices, t-values, p-values, and robust versions
of these values.
Parameters
----------
results_dict : dict.
... | [
"Store",
"the",
"model",
"inference",
"values",
"that",
"are",
"common",
"to",
"all",
"choice",
"models",
".",
"This",
"includes",
"things",
"like",
"index",
"coefficients",
"gradients",
"hessians",
"asymptotic",
"covariance",
"matrices",
"t",
"-",
"values",
"p"... | f83b0fd6debaa7358d87c3828428f6d4ead71357 | https://github.com/timothyb0912/pylogit/blob/f83b0fd6debaa7358d87c3828428f6d4ead71357/pylogit/base_multinomial_cm_v2.py#L1166-L1275 |
887 | timothyb0912/pylogit | pylogit/base_multinomial_cm_v2.py | MNDC_Model._store_optional_parameters | def _store_optional_parameters(self,
optional_params,
name_list_attr,
default_name_str,
all_names,
all_params,
... | python | def _store_optional_parameters(self,
optional_params,
name_list_attr,
default_name_str,
all_names,
all_params,
... | [
"def",
"_store_optional_parameters",
"(",
"self",
",",
"optional_params",
",",
"name_list_attr",
",",
"default_name_str",
",",
"all_names",
",",
"all_params",
",",
"param_attr_name",
",",
"series_name",
")",
":",
"# Identify the number of optional parameters",
"num_elements... | Extract the optional parameters from the `results_dict`, save them
to the model object, and update the list of all parameters and all
parameter names.
Parameters
----------
optional_params : 1D ndarray.
The optional parameters whose values and names should be stored.... | [
"Extract",
"the",
"optional",
"parameters",
"from",
"the",
"results_dict",
"save",
"them",
"to",
"the",
"model",
"object",
"and",
"update",
"the",
"list",
"of",
"all",
"parameters",
"and",
"all",
"parameter",
"names",
"."
] | f83b0fd6debaa7358d87c3828428f6d4ead71357 | https://github.com/timothyb0912/pylogit/blob/f83b0fd6debaa7358d87c3828428f6d4ead71357/pylogit/base_multinomial_cm_v2.py#L1277-L1339 |
888 | timothyb0912/pylogit | pylogit/base_multinomial_cm_v2.py | MNDC_Model._adjust_inferential_results_for_parameter_constraints | def _adjust_inferential_results_for_parameter_constraints(self,
constraints):
"""
Ensure that parameters that were constrained during estimation do not
have any values showed for inferential results. After all, no inference
wa... | python | def _adjust_inferential_results_for_parameter_constraints(self,
constraints):
"""
Ensure that parameters that were constrained during estimation do not
have any values showed for inferential results. After all, no inference
wa... | [
"def",
"_adjust_inferential_results_for_parameter_constraints",
"(",
"self",
",",
"constraints",
")",
":",
"if",
"constraints",
"is",
"not",
"None",
":",
"# Ensure the model object has inferential results",
"inferential_attributes",
"=",
"[",
"\"standard_errors\"",
",",
"\"tv... | Ensure that parameters that were constrained during estimation do not
have any values showed for inferential results. After all, no inference
was performed.
Parameters
----------
constraints : list of ints, or None.
If list, should contain the positions in the array ... | [
"Ensure",
"that",
"parameters",
"that",
"were",
"constrained",
"during",
"estimation",
"do",
"not",
"have",
"any",
"values",
"showed",
"for",
"inferential",
"results",
".",
"After",
"all",
"no",
"inference",
"was",
"performed",
"."
] | f83b0fd6debaa7358d87c3828428f6d4ead71357 | https://github.com/timothyb0912/pylogit/blob/f83b0fd6debaa7358d87c3828428f6d4ead71357/pylogit/base_multinomial_cm_v2.py#L1341-L1375 |
889 | timothyb0912/pylogit | pylogit/base_multinomial_cm_v2.py | MNDC_Model._check_result_dict_for_needed_keys | def _check_result_dict_for_needed_keys(self, results_dict):
"""
Ensure that `results_dict` has the needed keys to store all the
estimation results. Raise a helpful ValueError otherwise.
"""
missing_cols = [x for x in needed_result_keys if x not in results_dict]
if missing... | python | def _check_result_dict_for_needed_keys(self, results_dict):
"""
Ensure that `results_dict` has the needed keys to store all the
estimation results. Raise a helpful ValueError otherwise.
"""
missing_cols = [x for x in needed_result_keys if x not in results_dict]
if missing... | [
"def",
"_check_result_dict_for_needed_keys",
"(",
"self",
",",
"results_dict",
")",
":",
"missing_cols",
"=",
"[",
"x",
"for",
"x",
"in",
"needed_result_keys",
"if",
"x",
"not",
"in",
"results_dict",
"]",
"if",
"missing_cols",
"!=",
"[",
"]",
":",
"msg",
"="... | Ensure that `results_dict` has the needed keys to store all the
estimation results. Raise a helpful ValueError otherwise. | [
"Ensure",
"that",
"results_dict",
"has",
"the",
"needed",
"keys",
"to",
"store",
"all",
"the",
"estimation",
"results",
".",
"Raise",
"a",
"helpful",
"ValueError",
"otherwise",
"."
] | f83b0fd6debaa7358d87c3828428f6d4ead71357 | https://github.com/timothyb0912/pylogit/blob/f83b0fd6debaa7358d87c3828428f6d4ead71357/pylogit/base_multinomial_cm_v2.py#L1377-L1386 |
890 | timothyb0912/pylogit | pylogit/base_multinomial_cm_v2.py | MNDC_Model._add_mixing_variable_names_to_individual_vars | def _add_mixing_variable_names_to_individual_vars(self):
"""
Ensure that the model objects mixing variables are added to its list of
individual variables.
"""
assert isinstance(self.ind_var_names, list)
# Note that if one estimates a mixed logit model, then the mixing
... | python | def _add_mixing_variable_names_to_individual_vars(self):
"""
Ensure that the model objects mixing variables are added to its list of
individual variables.
"""
assert isinstance(self.ind_var_names, list)
# Note that if one estimates a mixed logit model, then the mixing
... | [
"def",
"_add_mixing_variable_names_to_individual_vars",
"(",
"self",
")",
":",
"assert",
"isinstance",
"(",
"self",
".",
"ind_var_names",
",",
"list",
")",
"# Note that if one estimates a mixed logit model, then the mixing",
"# variables will be added to individual vars. And if one e... | Ensure that the model objects mixing variables are added to its list of
individual variables. | [
"Ensure",
"that",
"the",
"model",
"objects",
"mixing",
"variables",
"are",
"added",
"to",
"its",
"list",
"of",
"individual",
"variables",
"."
] | f83b0fd6debaa7358d87c3828428f6d4ead71357 | https://github.com/timothyb0912/pylogit/blob/f83b0fd6debaa7358d87c3828428f6d4ead71357/pylogit/base_multinomial_cm_v2.py#L1388-L1405 |
891 | timothyb0912/pylogit | pylogit/base_multinomial_cm_v2.py | MNDC_Model.print_summaries | def print_summaries(self):
"""
Returns None. Will print the measures of fit and the estimation results
for the model.
"""
if hasattr(self, "fit_summary") and hasattr(self, "summary"):
print("\n")
print(self.fit_summary)
print("=" * 30)
... | python | def print_summaries(self):
"""
Returns None. Will print the measures of fit and the estimation results
for the model.
"""
if hasattr(self, "fit_summary") and hasattr(self, "summary"):
print("\n")
print(self.fit_summary)
print("=" * 30)
... | [
"def",
"print_summaries",
"(",
"self",
")",
":",
"if",
"hasattr",
"(",
"self",
",",
"\"fit_summary\"",
")",
"and",
"hasattr",
"(",
"self",
",",
"\"summary\"",
")",
":",
"print",
"(",
"\"\\n\"",
")",
"print",
"(",
"self",
".",
"fit_summary",
")",
"print",... | Returns None. Will print the measures of fit and the estimation results
for the model. | [
"Returns",
"None",
".",
"Will",
"print",
"the",
"measures",
"of",
"fit",
"and",
"the",
"estimation",
"results",
"for",
"the",
"model",
"."
] | f83b0fd6debaa7358d87c3828428f6d4ead71357 | https://github.com/timothyb0912/pylogit/blob/f83b0fd6debaa7358d87c3828428f6d4ead71357/pylogit/base_multinomial_cm_v2.py#L1556-L1572 |
892 | taskcluster/json-e | jsone/prattparser.py | prefix | def prefix(*kinds):
"""Decorate a method as handling prefix tokens of the given kinds"""
def wrap(fn):
try:
fn.prefix_kinds.extend(kinds)
except AttributeError:
fn.prefix_kinds = list(kinds)
return fn
return wrap | python | def prefix(*kinds):
"""Decorate a method as handling prefix tokens of the given kinds"""
def wrap(fn):
try:
fn.prefix_kinds.extend(kinds)
except AttributeError:
fn.prefix_kinds = list(kinds)
return fn
return wrap | [
"def",
"prefix",
"(",
"*",
"kinds",
")",
":",
"def",
"wrap",
"(",
"fn",
")",
":",
"try",
":",
"fn",
".",
"prefix_kinds",
".",
"extend",
"(",
"kinds",
")",
"except",
"AttributeError",
":",
"fn",
".",
"prefix_kinds",
"=",
"list",
"(",
"kinds",
")",
"... | Decorate a method as handling prefix tokens of the given kinds | [
"Decorate",
"a",
"method",
"as",
"handling",
"prefix",
"tokens",
"of",
"the",
"given",
"kinds"
] | ac0c9fba1de3ed619f05a64dae929f6687789cbc | https://github.com/taskcluster/json-e/blob/ac0c9fba1de3ed619f05a64dae929f6687789cbc/jsone/prattparser.py#L20-L28 |
893 | taskcluster/json-e | jsone/prattparser.py | infix | def infix(*kinds):
"""Decorate a method as handling infix tokens of the given kinds"""
def wrap(fn):
try:
fn.infix_kinds.extend(kinds)
except AttributeError:
fn.infix_kinds = list(kinds)
return fn
return wrap | python | def infix(*kinds):
"""Decorate a method as handling infix tokens of the given kinds"""
def wrap(fn):
try:
fn.infix_kinds.extend(kinds)
except AttributeError:
fn.infix_kinds = list(kinds)
return fn
return wrap | [
"def",
"infix",
"(",
"*",
"kinds",
")",
":",
"def",
"wrap",
"(",
"fn",
")",
":",
"try",
":",
"fn",
".",
"infix_kinds",
".",
"extend",
"(",
"kinds",
")",
"except",
"AttributeError",
":",
"fn",
".",
"infix_kinds",
"=",
"list",
"(",
"kinds",
")",
"ret... | Decorate a method as handling infix tokens of the given kinds | [
"Decorate",
"a",
"method",
"as",
"handling",
"infix",
"tokens",
"of",
"the",
"given",
"kinds"
] | ac0c9fba1de3ed619f05a64dae929f6687789cbc | https://github.com/taskcluster/json-e/blob/ac0c9fba1de3ed619f05a64dae929f6687789cbc/jsone/prattparser.py#L31-L39 |
894 | taskcluster/json-e | jsone/prattparser.py | ParseContext.attempt | def attempt(self, *kinds):
"""Try to get the next token if it matches one of the kinds given,
otherwise returning None. If no kinds are given, any kind is
accepted."""
if self._error:
raise self._error
token = self.next_token
if not token:
return N... | python | def attempt(self, *kinds):
"""Try to get the next token if it matches one of the kinds given,
otherwise returning None. If no kinds are given, any kind is
accepted."""
if self._error:
raise self._error
token = self.next_token
if not token:
return N... | [
"def",
"attempt",
"(",
"self",
",",
"*",
"kinds",
")",
":",
"if",
"self",
".",
"_error",
":",
"raise",
"self",
".",
"_error",
"token",
"=",
"self",
".",
"next_token",
"if",
"not",
"token",
":",
"return",
"None",
"if",
"kinds",
"and",
"token",
".",
... | Try to get the next token if it matches one of the kinds given,
otherwise returning None. If no kinds are given, any kind is
accepted. | [
"Try",
"to",
"get",
"the",
"next",
"token",
"if",
"it",
"matches",
"one",
"of",
"the",
"kinds",
"given",
"otherwise",
"returning",
"None",
".",
"If",
"no",
"kinds",
"are",
"given",
"any",
"kind",
"is",
"accepted",
"."
] | ac0c9fba1de3ed619f05a64dae929f6687789cbc | https://github.com/taskcluster/json-e/blob/ac0c9fba1de3ed619f05a64dae929f6687789cbc/jsone/prattparser.py#L150-L162 |
895 | taskcluster/json-e | jsone/prattparser.py | ParseContext.require | def require(self, *kinds):
"""Get the next token, raising an exception if it doesn't match one of
the given kinds, or the input ends. If no kinds are given, returns the
next token of any kind."""
token = self.attempt()
if not token:
raise SyntaxError('Unexpected end o... | python | def require(self, *kinds):
"""Get the next token, raising an exception if it doesn't match one of
the given kinds, or the input ends. If no kinds are given, returns the
next token of any kind."""
token = self.attempt()
if not token:
raise SyntaxError('Unexpected end o... | [
"def",
"require",
"(",
"self",
",",
"*",
"kinds",
")",
":",
"token",
"=",
"self",
".",
"attempt",
"(",
")",
"if",
"not",
"token",
":",
"raise",
"SyntaxError",
"(",
"'Unexpected end of input'",
")",
"if",
"kinds",
"and",
"token",
".",
"kind",
"not",
"in... | Get the next token, raising an exception if it doesn't match one of
the given kinds, or the input ends. If no kinds are given, returns the
next token of any kind. | [
"Get",
"the",
"next",
"token",
"raising",
"an",
"exception",
"if",
"it",
"doesn",
"t",
"match",
"one",
"of",
"the",
"given",
"kinds",
"or",
"the",
"input",
"ends",
".",
"If",
"no",
"kinds",
"are",
"given",
"returns",
"the",
"next",
"token",
"of",
"any"... | ac0c9fba1de3ed619f05a64dae929f6687789cbc | https://github.com/taskcluster/json-e/blob/ac0c9fba1de3ed619f05a64dae929f6687789cbc/jsone/prattparser.py#L164-L173 |
896 | amzn/ion-python | amazon/ion/symbols.py | local_symbol_table | def local_symbol_table(imports=None, symbols=()):
"""Constructs a local symbol table.
Args:
imports (Optional[SymbolTable]): Shared symbol tables to import.
symbols (Optional[Iterable[Unicode]]): Initial local symbols to add.
Returns:
SymbolTable: A mutable local symbol table with ... | python | def local_symbol_table(imports=None, symbols=()):
"""Constructs a local symbol table.
Args:
imports (Optional[SymbolTable]): Shared symbol tables to import.
symbols (Optional[Iterable[Unicode]]): Initial local symbols to add.
Returns:
SymbolTable: A mutable local symbol table with ... | [
"def",
"local_symbol_table",
"(",
"imports",
"=",
"None",
",",
"symbols",
"=",
"(",
")",
")",
":",
"return",
"SymbolTable",
"(",
"table_type",
"=",
"LOCAL_TABLE_TYPE",
",",
"symbols",
"=",
"symbols",
",",
"imports",
"=",
"imports",
")"
] | Constructs a local symbol table.
Args:
imports (Optional[SymbolTable]): Shared symbol tables to import.
symbols (Optional[Iterable[Unicode]]): Initial local symbols to add.
Returns:
SymbolTable: A mutable local symbol table with the seeded local symbols. | [
"Constructs",
"a",
"local",
"symbol",
"table",
"."
] | 0b21fa3ba7755f55f745e4aa970d86343b82449d | https://github.com/amzn/ion-python/blob/0b21fa3ba7755f55f745e4aa970d86343b82449d/amazon/ion/symbols.py#L380-L394 |
897 | amzn/ion-python | amazon/ion/symbols.py | shared_symbol_table | def shared_symbol_table(name, version, symbols, imports=None):
"""Constructs a shared symbol table.
Args:
name (unicode): The name of the shared symbol table.
version (int): The version of the shared symbol table.
symbols (Iterable[unicode]): The symbols to associate with the table.
... | python | def shared_symbol_table(name, version, symbols, imports=None):
"""Constructs a shared symbol table.
Args:
name (unicode): The name of the shared symbol table.
version (int): The version of the shared symbol table.
symbols (Iterable[unicode]): The symbols to associate with the table.
... | [
"def",
"shared_symbol_table",
"(",
"name",
",",
"version",
",",
"symbols",
",",
"imports",
"=",
"None",
")",
":",
"return",
"SymbolTable",
"(",
"table_type",
"=",
"SHARED_TABLE_TYPE",
",",
"symbols",
"=",
"symbols",
",",
"name",
"=",
"name",
",",
"version",
... | Constructs a shared symbol table.
Args:
name (unicode): The name of the shared symbol table.
version (int): The version of the shared symbol table.
symbols (Iterable[unicode]): The symbols to associate with the table.
imports (Optional[Iterable[SymbolTable]): The shared symbol table... | [
"Constructs",
"a",
"shared",
"symbol",
"table",
"."
] | 0b21fa3ba7755f55f745e4aa970d86343b82449d | https://github.com/amzn/ion-python/blob/0b21fa3ba7755f55f745e4aa970d86343b82449d/amazon/ion/symbols.py#L397-L415 |
898 | amzn/ion-python | amazon/ion/symbols.py | placeholder_symbol_table | def placeholder_symbol_table(name, version, max_id):
"""Constructs a shared symbol table that consists symbols that all have no known text.
This is generally used for cases where a shared symbol table is not available by the
application.
Args:
name (unicode): The name of the shared symbol tabl... | python | def placeholder_symbol_table(name, version, max_id):
"""Constructs a shared symbol table that consists symbols that all have no known text.
This is generally used for cases where a shared symbol table is not available by the
application.
Args:
name (unicode): The name of the shared symbol tabl... | [
"def",
"placeholder_symbol_table",
"(",
"name",
",",
"version",
",",
"max_id",
")",
":",
"if",
"version",
"<=",
"0",
":",
"raise",
"ValueError",
"(",
"'Version must be grater than or equal to 1: %s'",
"%",
"version",
")",
"if",
"max_id",
"<",
"0",
":",
"raise",
... | Constructs a shared symbol table that consists symbols that all have no known text.
This is generally used for cases where a shared symbol table is not available by the
application.
Args:
name (unicode): The name of the shared symbol table.
version (int): The version of the shared symbol t... | [
"Constructs",
"a",
"shared",
"symbol",
"table",
"that",
"consists",
"symbols",
"that",
"all",
"have",
"no",
"known",
"text",
"."
] | 0b21fa3ba7755f55f745e4aa970d86343b82449d | https://github.com/amzn/ion-python/blob/0b21fa3ba7755f55f745e4aa970d86343b82449d/amazon/ion/symbols.py#L418-L443 |
899 | amzn/ion-python | amazon/ion/symbols.py | substitute_symbol_table | def substitute_symbol_table(table, version, max_id):
"""Substitutes a given shared symbol table for another version.
* If the given table has **more** symbols than the requested substitute, then the generated
symbol table will be a subset of the given table.
* If the given table has **less** symbols ... | python | def substitute_symbol_table(table, version, max_id):
"""Substitutes a given shared symbol table for another version.
* If the given table has **more** symbols than the requested substitute, then the generated
symbol table will be a subset of the given table.
* If the given table has **less** symbols ... | [
"def",
"substitute_symbol_table",
"(",
"table",
",",
"version",
",",
"max_id",
")",
":",
"if",
"not",
"table",
".",
"table_type",
".",
"is_shared",
":",
"raise",
"ValueError",
"(",
"'Symbol table to substitute from must be a shared table'",
")",
"if",
"version",
"<=... | Substitutes a given shared symbol table for another version.
* If the given table has **more** symbols than the requested substitute, then the generated
symbol table will be a subset of the given table.
* If the given table has **less** symbols than the requested substitute, then the generated
symb... | [
"Substitutes",
"a",
"given",
"shared",
"symbol",
"table",
"for",
"another",
"version",
"."
] | 0b21fa3ba7755f55f745e4aa970d86343b82449d | https://github.com/amzn/ion-python/blob/0b21fa3ba7755f55f745e4aa970d86343b82449d/amazon/ion/symbols.py#L446-L484 |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.