repository_name
stringlengths
7
55
func_path_in_repository
stringlengths
4
223
func_name
stringlengths
1
134
whole_func_string
stringlengths
75
104k
language
stringclasses
1 value
func_code_string
stringlengths
75
104k
func_code_tokens
listlengths
19
28.4k
func_documentation_string
stringlengths
1
46.9k
func_documentation_tokens
listlengths
1
1.97k
split_name
stringclasses
1 value
func_code_url
stringlengths
87
315
timothyb0912/pylogit
pylogit/choice_tools.py
create_row_to_some_id_col_mapping
def create_row_to_some_id_col_mapping(id_array): """ Parameters ---------- id_array : 1D ndarray. All elements of the array should be ints representing some id related to the corresponding row. Returns ------- rows_to_ids : 2D scipy sparse array. Will map each row of...
python
def create_row_to_some_id_col_mapping(id_array): """ Parameters ---------- id_array : 1D ndarray. All elements of the array should be ints representing some id related to the corresponding row. Returns ------- rows_to_ids : 2D scipy sparse array. Will map each row of...
[ "def", "create_row_to_some_id_col_mapping", "(", "id_array", ")", ":", "# Get the unique ids, in their original order of appearance", "original_order_unique_ids", "=", "get_original_order_unique_ids", "(", "id_array", ")", "# Create a matrix with the same number of rows as id_array but a s...
Parameters ---------- id_array : 1D ndarray. All elements of the array should be ints representing some id related to the corresponding row. Returns ------- rows_to_ids : 2D scipy sparse array. Will map each row of id_array to the unique values of `id_array`. The col...
[ "Parameters", "----------", "id_array", ":", "1D", "ndarray", ".", "All", "elements", "of", "the", "array", "should", "be", "ints", "representing", "some", "id", "related", "to", "the", "corresponding", "row", "." ]
train
https://github.com/timothyb0912/pylogit/blob/f83b0fd6debaa7358d87c3828428f6d4ead71357/pylogit/choice_tools.py#L748-L773
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...
train
https://github.com/timothyb0912/pylogit/blob/f83b0fd6debaa7358d87c3828428f6d4ead71357/pylogit/choice_tools.py#L776-L832
timothyb0912/pylogit
pylogit/choice_tools.py
create_long_form_mappings
def create_long_form_mappings(long_form, obs_id_col, alt_id_col, choice_col=None, nest_spec=None, mix_id_col=None, dense=False): """ ...
python
def create_long_form_mappings(long_form, obs_id_col, alt_id_col, choice_col=None, nest_spec=None, mix_id_col=None, dense=False): """ ...
[ "def", "create_long_form_mappings", "(", "long_form", ",", "obs_id_col", ",", "alt_id_col", ",", "choice_col", "=", "None", ",", "nest_spec", "=", "None", ",", "mix_id_col", "=", "None", ",", "dense", "=", "False", ")", ":", "# Get the id_values from the long_form...
Parameters ---------- long_form : pandas dataframe. Contains one row for each available alternative for each observation. obs_id_col : str. Denotes the column in `long_form` which contains the choice situation observation ID values for each row of `long_form`. Note each value in ...
[ "Parameters", "----------", "long_form", ":", "pandas", "dataframe", ".", "Contains", "one", "row", "for", "each", "available", "alternative", "for", "each", "observation", ".", "obs_id_col", ":", "str", ".", "Denotes", "the", "column", "in", "long_form", "which...
train
https://github.com/timothyb0912/pylogit/blob/f83b0fd6debaa7358d87c3828428f6d4ead71357/pylogit/choice_tools.py#L840-L975
timothyb0912/pylogit
pylogit/choice_tools.py
convert_long_to_wide
def convert_long_to_wide(long_data, ind_vars, alt_specific_vars, subset_specific_vars, obs_id_col, alt_id_col, choice_col, alt_name_dict=None, ...
python
def convert_long_to_wide(long_data, ind_vars, alt_specific_vars, subset_specific_vars, obs_id_col, alt_id_col, choice_col, alt_name_dict=None, ...
[ "def", "convert_long_to_wide", "(", "long_data", ",", "ind_vars", ",", "alt_specific_vars", ",", "subset_specific_vars", ",", "obs_id_col", ",", "alt_id_col", ",", "choice_col", ",", "alt_name_dict", "=", "None", ",", "null_value", "=", "np", ".", "nan", ")", ":...
Converts a 'long format' dataframe of cross-sectional discrete choice data into a 'wide format' version of the same data. Parameters ---------- long_data : pandas dataframe. Contains one row for each available alternative for each observation. Should have the specified `[obs_id_col, alt...
[ "Converts", "a", "long", "format", "dataframe", "of", "cross", "-", "sectional", "discrete", "choice", "data", "into", "a", "wide", "format", "version", "of", "the", "same", "data", "." ]
train
https://github.com/timothyb0912/pylogit/blob/f83b0fd6debaa7358d87c3828428f6d4ead71357/pylogit/choice_tools.py#L978-L1255
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", "." ]
train
https://github.com/timothyb0912/pylogit/blob/f83b0fd6debaa7358d87c3828428f6d4ead71357/pylogit/choice_tools.py#L1258-L1280
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", "." ]
train
https://github.com/timothyb0912/pylogit/blob/f83b0fd6debaa7358d87c3828428f6d4ead71357/pylogit/choice_tools.py#L1283-L1306
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", "." ]
train
https://github.com/timothyb0912/pylogit/blob/f83b0fd6debaa7358d87c3828428f6d4ead71357/pylogit/choice_tools.py#L1309-L1342
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", "...
train
https://github.com/timothyb0912/pylogit/blob/f83b0fd6debaa7358d87c3828428f6d4ead71357/pylogit/choice_tools.py#L1345-L1397
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", "." ]
train
https://github.com/timothyb0912/pylogit/blob/f83b0fd6debaa7358d87c3828428f6d4ead71357/pylogit/choice_tools.py#L1400-L1428
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...
train
https://github.com/timothyb0912/pylogit/blob/f83b0fd6debaa7358d87c3828428f6d4ead71357/pylogit/choice_tools.py#L1431-L1461
timothyb0912/pylogit
pylogit/choice_tools.py
convert_wide_to_long
def convert_wide_to_long(wide_data, ind_vars, alt_specific_vars, availability_vars, obs_id_col, choice_col, new_alt_id_name=None): """ Will convert a cross-sectio...
python
def convert_wide_to_long(wide_data, ind_vars, alt_specific_vars, availability_vars, obs_id_col, choice_col, new_alt_id_name=None): """ Will convert a cross-sectio...
[ "def", "convert_wide_to_long", "(", "wide_data", ",", "ind_vars", ",", "alt_specific_vars", ",", "availability_vars", ",", "obs_id_col", ",", "choice_col", ",", "new_alt_id_name", "=", "None", ")", ":", "##########", "# Check that all columns of wide_data are being", "# u...
Will convert a cross-sectional dataframe of discrete choice data from wide format to long format. Parameters ---------- wide_data : pandas dataframe. Contains one row for each observation. Should have the specified `[obs_id_col, choice_col] + availability_vars.values()` columns. ind...
[ "Will", "convert", "a", "cross", "-", "sectional", "dataframe", "of", "discrete", "choice", "data", "from", "wide", "format", "to", "long", "format", "." ]
train
https://github.com/timothyb0912/pylogit/blob/f83b0fd6debaa7358d87c3828428f6d4ead71357/pylogit/choice_tools.py#L1464-L1740
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", "." ]
train
https://github.com/timothyb0912/pylogit/blob/f83b0fd6debaa7358d87c3828428f6d4ead71357/pylogit/bootstrap_sampler.py#L13-L55
timothyb0912/pylogit
pylogit/bootstrap_sampler.py
get_num_obs_choosing_each_alternative
def get_num_obs_choosing_each_alternative(obs_per_alt_dict): """ Will create an ordered dictionary that records the number of units of observation that have chosen the given alternative (i.e. the associated dictionary key). Will also determine the total number of unique observations in the dataset. ...
python
def get_num_obs_choosing_each_alternative(obs_per_alt_dict): """ Will create an ordered dictionary that records the number of units of observation that have chosen the given alternative (i.e. the associated dictionary key). Will also determine the total number of unique observations in the dataset. ...
[ "def", "get_num_obs_choosing_each_alternative", "(", "obs_per_alt_dict", ")", ":", "# Initialize the object that is to be returned.", "num_obs_per_group", "=", "OrderedDict", "(", ")", "# Determine the number of unique units of observation per group.", "for", "alt_id", "in", "obs_per...
Will create an ordered dictionary that records the number of units of observation that have chosen the given alternative (i.e. the associated dictionary key). Will also determine the total number of unique observations in the dataset. Parameters ---------- obs_per_alt_dict : dict. Each ...
[ "Will", "create", "an", "ordered", "dictionary", "that", "records", "the", "number", "of", "units", "of", "observation", "that", "have", "chosen", "the", "given", "alternative", "(", "i", ".", "e", ".", "the", "associated", "dictionary", "key", ")", ".", "...
train
https://github.com/timothyb0912/pylogit/blob/f83b0fd6debaa7358d87c3828428f6d4ead71357/pylogit/bootstrap_sampler.py#L58-L92
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", "...
train
https://github.com/timothyb0912/pylogit/blob/f83b0fd6debaa7358d87c3828428f6d4ead71357/pylogit/bootstrap_sampler.py#L95-L177
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", "." ]
train
https://github.com/timothyb0912/pylogit/blob/f83b0fd6debaa7358d87c3828428f6d4ead71357/pylogit/bootstrap_sampler.py#L180-L204
timothyb0912/pylogit
pylogit/bootstrap_sampler.py
create_deepcopied_groupby_dict
def create_deepcopied_groupby_dict(orig_df, obs_id_col): """ Will create a dictionary where each key corresponds to a unique value in `orig_df[obs_id_col]` and each value corresponds to all of the rows of `orig_df` where `orig_df[obs_id_col] == key`. Parameters ---------- orig_df : pandas D...
python
def create_deepcopied_groupby_dict(orig_df, obs_id_col): """ Will create a dictionary where each key corresponds to a unique value in `orig_df[obs_id_col]` and each value corresponds to all of the rows of `orig_df` where `orig_df[obs_id_col] == key`. Parameters ---------- orig_df : pandas D...
[ "def", "create_deepcopied_groupby_dict", "(", "orig_df", ",", "obs_id_col", ")", ":", "# Get the observation id values", "obs_id_vals", "=", "orig_df", "[", "obs_id_col", "]", ".", "values", "# Get the unique observation ids", "unique_obs_ids", "=", "np", ".", "unique", ...
Will create a dictionary where each key corresponds to a unique value in `orig_df[obs_id_col]` and each value corresponds to all of the rows of `orig_df` where `orig_df[obs_id_col] == key`. Parameters ---------- orig_df : pandas DataFrame. Should be long-format dataframe containing the data...
[ "Will", "create", "a", "dictionary", "where", "each", "key", "corresponds", "to", "a", "unique", "value", "in", "orig_df", "[", "obs_id_col", "]", "and", "each", "value", "corresponds", "to", "all", "of", "the", "rows", "of", "orig_df", "where", "orig_df", ...
train
https://github.com/timothyb0912/pylogit/blob/f83b0fd6debaa7358d87c3828428f6d4ead71357/pylogit/bootstrap_sampler.py#L207-L242
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", "." ]
train
https://github.com/timothyb0912/pylogit/blob/f83b0fd6debaa7358d87c3828428f6d4ead71357/pylogit/bootstrap_sampler.py#L245-L273
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", "." ]
train
https://github.com/timothyb0912/pylogit/blob/f83b0fd6debaa7358d87c3828428f6d4ead71357/pylogit/bootstrap_sampler.py#L276-L298
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", "." ]
train
https://github.com/timothyb0912/pylogit/blob/f83b0fd6debaa7358d87c3828428f6d4ead71357/pylogit/bootstrap_sampler.py#L301-L360
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", "." ]
train
https://github.com/timothyb0912/pylogit/blob/f83b0fd6debaa7358d87c3828428f6d4ead71357/pylogit/bootstrap.py#L46-L75
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", "." ]
train
https://github.com/timothyb0912/pylogit/blob/f83b0fd6debaa7358d87c3828428f6d4ead71357/pylogit/bootstrap.py#L78-L135
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", "." ]
train
https://github.com/timothyb0912/pylogit/blob/f83b0fd6debaa7358d87c3828428f6d4ead71357/pylogit/bootstrap.py#L183-L356
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", "." ]
train
https://github.com/timothyb0912/pylogit/blob/f83b0fd6debaa7358d87c3828428f6d4ead71357/pylogit/bootstrap.py#L358-L495
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", "." ]
train
https://github.com/timothyb0912/pylogit/blob/f83b0fd6debaa7358d87c3828428f6d4ead71357/pylogit/bootstrap.py#L497-L591
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", "." ]
train
https://github.com/timothyb0912/pylogit/blob/f83b0fd6debaa7358d87c3828428f6d4ead71357/pylogit/bootstrap.py#L593-L661
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", "." ]
train
https://github.com/timothyb0912/pylogit/blob/f83b0fd6debaa7358d87c3828428f6d4ead71357/pylogit/bootstrap.py#L663-L696
timothyb0912/pylogit
pylogit/bootstrap.py
Boot.calc_bca_interval
def calc_bca_interval(self, conf_percentage): """ Calculates Bias-Corrected and Accelerated (BCa) Bootstrap Confidence Intervals for one's model. Parameters ---------- conf_percentage : scalar in the interval (0.0, 100.0). Denotes the confidence-level for the...
python
def calc_bca_interval(self, conf_percentage): """ Calculates Bias-Corrected and Accelerated (BCa) Bootstrap Confidence Intervals for one's model. Parameters ---------- conf_percentage : scalar in the interval (0.0, 100.0). Denotes the confidence-level for the...
[ "def", "calc_bca_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 dataframe ...
Calculates Bias-Corrected and Accelerated (BCa) 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% ...
[ "Calculates", "Bias", "-", "Corrected", "and", "Accelerated", "(", "BCa", ")", "Bootstrap", "Confidence", "Intervals", "for", "one", "s", "model", "." ]
train
https://github.com/timothyb0912/pylogit/blob/f83b0fd6debaa7358d87c3828428f6d4ead71357/pylogit/bootstrap.py#L698-L735
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", "." ]
train
https://github.com/timothyb0912/pylogit/blob/f83b0fd6debaa7358d87c3828428f6d4ead71357/pylogit/bootstrap.py#L737-L788
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", "." ]
train
https://github.com/timothyb0912/pylogit/blob/f83b0fd6debaa7358d87c3828428f6d4ead71357/pylogit/bootstrap.py#L790-L879
timothyb0912/pylogit
pylogit/clog_log.py
split_param_vec
def split_param_vec(param_vec, rows_to_alts, design, return_all_types=False): """ Parameters ---------- param_vec : 1D ndarray. Elements should all be ints, floats, or longs. Should have as many elements as there are parameters being estimated. rows_to_alts : 2D scipy sparse matrix. ...
python
def split_param_vec(param_vec, rows_to_alts, design, return_all_types=False): """ Parameters ---------- param_vec : 1D ndarray. Elements should all be ints, floats, or longs. Should have as many elements as there are parameters being estimated. rows_to_alts : 2D scipy sparse matrix. ...
[ "def", "split_param_vec", "(", "param_vec", ",", "rows_to_alts", ",", "design", ",", "return_all_types", "=", "False", ")", ":", "# Figure out how many parameters are in the index", "num_index_coefs", "=", "design", ".", "shape", "[", "1", "]", "# Isolate the initial sh...
Parameters ---------- param_vec : 1D ndarray. Elements should all be ints, floats, or longs. Should have as many elements as there are parameters being estimated. rows_to_alts : 2D scipy sparse matrix. There should be one row per observation per available alternative and one ...
[ "Parameters", "----------", "param_vec", ":", "1D", "ndarray", ".", "Elements", "should", "all", "be", "ints", "floats", "or", "longs", ".", "Should", "have", "as", "many", "elements", "as", "there", "are", "parameters", "being", "estimated", ".", "rows_to_alt...
train
https://github.com/timothyb0912/pylogit/blob/f83b0fd6debaa7358d87c3828428f6d4ead71357/pylogit/clog_log.py#L59-L113
timothyb0912/pylogit
pylogit/clog_log.py
_cloglog_utility_transform
def _cloglog_utility_transform(systematic_utilities, alt_IDs, rows_to_alts, shape_params, intercept_params, intercept_ref_pos=None, *a...
python
def _cloglog_utility_transform(systematic_utilities, alt_IDs, rows_to_alts, shape_params, intercept_params, intercept_ref_pos=None, *a...
[ "def", "_cloglog_utility_transform", "(", "systematic_utilities", ",", "alt_IDs", ",", "rows_to_alts", ",", "shape_params", ",", "intercept_params", ",", "intercept_ref_pos", "=", "None", ",", "*", "args", ",", "*", "*", "kwargs", ")", ":", "# Calculate the data dep...
Parameters ---------- systematic_utilities : 1D ndarray. All elements should be ints, floats, or longs. Should contain the systematic utilities of each observation per available alternative. Note that this vector is formed by the dot product of the design matrix with the vector o...
[ "Parameters", "----------", "systematic_utilities", ":", "1D", "ndarray", ".", "All", "elements", "should", "be", "ints", "floats", "or", "longs", ".", "Should", "contain", "the", "systematic", "utilities", "of", "each", "observation", "per", "available", "alterna...
train
https://github.com/timothyb0912/pylogit/blob/f83b0fd6debaa7358d87c3828428f6d4ead71357/pylogit/clog_log.py#L116-L208
timothyb0912/pylogit
pylogit/clog_log.py
_cloglog_transform_deriv_v
def _cloglog_transform_deriv_v(systematic_utilities, alt_IDs, rows_to_alts, shape_params, output_array=None, *args, **kwargs): """ Parameters ---------- ...
python
def _cloglog_transform_deriv_v(systematic_utilities, alt_IDs, rows_to_alts, shape_params, output_array=None, *args, **kwargs): """ Parameters ---------- ...
[ "def", "_cloglog_transform_deriv_v", "(", "systematic_utilities", ",", "alt_IDs", ",", "rows_to_alts", ",", "shape_params", ",", "output_array", "=", "None", ",", "*", "args", ",", "*", "*", "kwargs", ")", ":", "exp_neg_v", "=", "np", ".", "exp", "(", "-", ...
Parameters ---------- systematic_utilities : 1D ndarray. All elements should be ints, floats, or longs. Should contain the systematic utilities of each observation per available alternative. Note that this vector is formed by the dot product of the design matrix with the vector o...
[ "Parameters", "----------", "systematic_utilities", ":", "1D", "ndarray", ".", "All", "elements", "should", "be", "ints", "floats", "or", "longs", ".", "Should", "contain", "the", "systematic", "utilities", "of", "each", "observation", "per", "available", "alterna...
train
https://github.com/timothyb0912/pylogit/blob/f83b0fd6debaa7358d87c3828428f6d4ead71357/pylogit/clog_log.py#L211-L285
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...
train
https://github.com/timothyb0912/pylogit/blob/f83b0fd6debaa7358d87c3828428f6d4ead71357/pylogit/clog_log.py#L374-L415
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", "." ]
train
https://github.com/timothyb0912/pylogit/blob/f83b0fd6debaa7358d87c3828428f6d4ead71357/pylogit/estimation.py#L424-L451
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", "." ]
train
https://github.com/timothyb0912/pylogit/blob/f83b0fd6debaa7358d87c3828428f6d4ead71357/pylogit/estimation.py#L454-L480
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", ...
train
https://github.com/timothyb0912/pylogit/blob/f83b0fd6debaa7358d87c3828428f6d4ead71357/pylogit/estimation.py#L483-L583
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", "." ]
train
https://github.com/timothyb0912/pylogit/blob/f83b0fd6debaa7358d87c3828428f6d4ead71357/pylogit/estimation.py#L586-L713
timothyb0912/pylogit
pylogit/estimation.py
EstimationObj.convenience_split_params
def convenience_split_params(self, params, return_all_types=False): """ Splits parameter vector into shape, intercept, and index parameters. Parameters ---------- params : 1D ndarray. The array of parameters being estimated or used in calculations. return_all...
python
def convenience_split_params(self, params, return_all_types=False): """ Splits parameter vector into shape, intercept, and index parameters. Parameters ---------- params : 1D ndarray. The array of parameters being estimated or used in calculations. return_all...
[ "def", "convenience_split_params", "(", "self", ",", "params", ",", "return_all_types", "=", "False", ")", ":", "return", "self", ".", "split_params", "(", "params", ",", "self", ".", "rows_to_alts", ",", "self", ".", "design", ",", "return_all_types", "=", ...
Splits parameter vector into shape, intercept, and index parameters. Parameters ---------- params : 1D ndarray. The array of parameters being estimated or used in calculations. return_all_types : bool, optional. Determines whether or not a tuple of 4 elements wil...
[ "Splits", "parameter", "vector", "into", "shape", "intercept", "and", "index", "parameters", "." ]
train
https://github.com/timothyb0912/pylogit/blob/f83b0fd6debaa7358d87c3828428f6d4ead71357/pylogit/estimation.py#L150-L172
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", ".", "...
train
https://github.com/timothyb0912/pylogit/blob/f83b0fd6debaa7358d87c3828428f6d4ead71357/pylogit/estimation.py#L211-L223
timothyb0912/pylogit
pylogit/estimation.py
LogitTypeEstimator.convenience_calc_probs
def convenience_calc_probs(self, params): """ Calculates the probabilities of the chosen alternative, and the long format probabilities for this model and dataset. """ shapes, intercepts, betas = self.convenience_split_params(params) prob_args = [betas, ...
python
def convenience_calc_probs(self, params): """ Calculates the probabilities of the chosen alternative, and the long format probabilities for this model and dataset. """ shapes, intercepts, betas = self.convenience_split_params(params) prob_args = [betas, ...
[ "def", "convenience_calc_probs", "(", "self", ",", "params", ")", ":", "shapes", ",", "intercepts", ",", "betas", "=", "self", ".", "convenience_split_params", "(", "params", ")", "prob_args", "=", "[", "betas", ",", "self", ".", "design", ",", "self", "."...
Calculates the probabilities of the chosen alternative, and the long format probabilities for this model and dataset.
[ "Calculates", "the", "probabilities", "of", "the", "chosen", "alternative", "and", "the", "long", "format", "probabilities", "for", "this", "model", "and", "dataset", "." ]
train
https://github.com/timothyb0912/pylogit/blob/f83b0fd6debaa7358d87c3828428f6d4ead71357/pylogit/estimation.py#L309-L329
timothyb0912/pylogit
pylogit/estimation.py
LogitTypeEstimator.convenience_calc_log_likelihood
def convenience_calc_log_likelihood(self, params): """ Calculates the log-likelihood for this model and dataset. """ shapes, intercepts, betas = self.convenience_split_params(params) args = [betas, self.design, self.alt_id_vector, ...
python
def convenience_calc_log_likelihood(self, params): """ Calculates the log-likelihood for this model and dataset. """ shapes, intercepts, betas = self.convenience_split_params(params) args = [betas, self.design, self.alt_id_vector, ...
[ "def", "convenience_calc_log_likelihood", "(", "self", ",", "params", ")", ":", "shapes", ",", "intercepts", ",", "betas", "=", "self", ".", "convenience_split_params", "(", "params", ")", "args", "=", "[", "betas", ",", "self", ".", "design", ",", "self", ...
Calculates the log-likelihood for this model and dataset.
[ "Calculates", "the", "log", "-", "likelihood", "for", "this", "model", "and", "dataset", "." ]
train
https://github.com/timothyb0912/pylogit/blob/f83b0fd6debaa7358d87c3828428f6d4ead71357/pylogit/estimation.py#L331-L351
timothyb0912/pylogit
pylogit/estimation.py
LogitTypeEstimator.convenience_calc_hessian
def convenience_calc_hessian(self, params): """ Calculates the hessian of the log-likelihood for this model / dataset. """ shapes, intercepts, betas = self.convenience_split_params(params) args = [betas, self.design, self.alt_id_vector, ...
python
def convenience_calc_hessian(self, params): """ Calculates the hessian of the log-likelihood for this model / dataset. """ shapes, intercepts, betas = self.convenience_split_params(params) args = [betas, self.design, self.alt_id_vector, ...
[ "def", "convenience_calc_hessian", "(", "self", ",", "params", ")", ":", "shapes", ",", "intercepts", ",", "betas", "=", "self", ".", "convenience_split_params", "(", "params", ")", "args", "=", "[", "betas", ",", "self", ".", "design", ",", "self", ".", ...
Calculates the hessian of the log-likelihood for this model / dataset.
[ "Calculates", "the", "hessian", "of", "the", "log", "-", "likelihood", "for", "this", "model", "/", "dataset", "." ]
train
https://github.com/timothyb0912/pylogit/blob/f83b0fd6debaa7358d87c3828428f6d4ead71357/pylogit/estimation.py#L376-L397
timothyb0912/pylogit
pylogit/estimation.py
LogitTypeEstimator.convenience_calc_fisher_approx
def convenience_calc_fisher_approx(self, params): """ Calculates the BHHH approximation of the Fisher Information Matrix for this model / dataset. """ shapes, intercepts, betas = self.convenience_split_params(params) args = [betas, self.design, ...
python
def convenience_calc_fisher_approx(self, params): """ Calculates the BHHH approximation of the Fisher Information Matrix for this model / dataset. """ shapes, intercepts, betas = self.convenience_split_params(params) args = [betas, self.design, ...
[ "def", "convenience_calc_fisher_approx", "(", "self", ",", "params", ")", ":", "shapes", ",", "intercepts", ",", "betas", "=", "self", ".", "convenience_split_params", "(", "params", ")", "args", "=", "[", "betas", ",", "self", ".", "design", ",", "self", ...
Calculates the BHHH approximation of the Fisher Information Matrix for this model / dataset.
[ "Calculates", "the", "BHHH", "approximation", "of", "the", "Fisher", "Information", "Matrix", "for", "this", "model", "/", "dataset", "." ]
train
https://github.com/timothyb0912/pylogit/blob/f83b0fd6debaa7358d87c3828428f6d4ead71357/pylogit/estimation.py#L399-L421
timothyb0912/pylogit
pylogit/conditional_logit.py
split_param_vec
def split_param_vec(beta, rows_to_alts=None, design=None, return_all_types=False, *args, **kwargs): """ Parameters ---------- beta : 1D ndarray. All elements should by ints, floats, or longs. Should have 1 element ...
python
def split_param_vec(beta, rows_to_alts=None, design=None, return_all_types=False, *args, **kwargs): """ Parameters ---------- beta : 1D ndarray. All elements should by ints, floats, or longs. Should have 1 element ...
[ "def", "split_param_vec", "(", "beta", ",", "rows_to_alts", "=", "None", ",", "design", "=", "None", ",", "return_all_types", "=", "False", ",", "*", "args", ",", "*", "*", "kwargs", ")", ":", "if", "return_all_types", ":", "return", "None", ",", "None",...
Parameters ---------- beta : 1D ndarray. All elements should by ints, floats, or longs. Should have 1 element for each utility coefficient being estimated (i.e. num_features). rows_to_alts : None, Not actually used. Included merely for consistency with other models. design : None...
[ "Parameters", "----------", "beta", ":", "1D", "ndarray", ".", "All", "elements", "should", "by", "ints", "floats", "or", "longs", ".", "Should", "have", "1", "element", "for", "each", "utility", "coefficient", "being", "estimated", "(", "i", ".", "e", "."...
train
https://github.com/timothyb0912/pylogit/blob/f83b0fd6debaa7358d87c3828428f6d4ead71357/pylogit/conditional_logit.py#L44-L81
timothyb0912/pylogit
pylogit/conditional_logit.py
_mnl_utility_transform
def _mnl_utility_transform(systematic_utilities, *args, **kwargs): """ Parameters ---------- systematic_utilities : 1D ndarray. Should contain the systematic utilities for each each available alternative for each observation. Returns ------- `systematic_utilities[:, None]` ...
python
def _mnl_utility_transform(systematic_utilities, *args, **kwargs): """ Parameters ---------- systematic_utilities : 1D ndarray. Should contain the systematic utilities for each each available alternative for each observation. Returns ------- `systematic_utilities[:, None]` ...
[ "def", "_mnl_utility_transform", "(", "systematic_utilities", ",", "*", "args", ",", "*", "*", "kwargs", ")", ":", "# Be sure to return a 2D array since other functions will be expecting this", "if", "len", "(", "systematic_utilities", ".", "shape", ")", "==", "1", ":",...
Parameters ---------- systematic_utilities : 1D ndarray. Should contain the systematic utilities for each each available alternative for each observation. Returns ------- `systematic_utilities[:, None]`
[ "Parameters", "----------", "systematic_utilities", ":", "1D", "ndarray", ".", "Should", "contain", "the", "systematic", "utilities", "for", "each", "each", "available", "alternative", "for", "each", "observation", "." ]
train
https://github.com/timothyb0912/pylogit/blob/f83b0fd6debaa7358d87c3828428f6d4ead71357/pylogit/conditional_logit.py#L84-L100
timothyb0912/pylogit
pylogit/conditional_logit.py
MNLEstimator.check_length_of_initial_values
def check_length_of_initial_values(self, init_values): """ Ensures that `init_values` is of the correct length. Raises a helpful ValueError if otherwise. Parameters ---------- init_values : 1D ndarray. The initial values to start the optimization process with...
python
def check_length_of_initial_values(self, init_values): """ Ensures that `init_values` is of the correct length. Raises a helpful ValueError if otherwise. Parameters ---------- init_values : 1D ndarray. The initial values to start the optimization process with...
[ "def", "check_length_of_initial_values", "(", "self", ",", "init_values", ")", ":", "# Calculate the expected number of index parameters", "num_index_coefs", "=", "self", ".", "design", ".", "shape", "[", "1", "]", "if", "init_values", ".", "shape", "[", "0", "]", ...
Ensures that `init_values` is of the correct length. Raises a helpful ValueError if otherwise. Parameters ---------- init_values : 1D ndarray. The initial values to start the optimization process with. There should be one value for each index coefficient, outside...
[ "Ensures", "that", "init_values", "is", "of", "the", "correct", "length", ".", "Raises", "a", "helpful", "ValueError", "if", "otherwise", "." ]
train
https://github.com/timothyb0912/pylogit/blob/f83b0fd6debaa7358d87c3828428f6d4ead71357/pylogit/conditional_logit.py#L191-L218
timothyb0912/pylogit
pylogit/conditional_logit.py
MNL.fit_mle
def fit_mle(self, init_vals, print_res=True, method="BFGS", loss_tol=1e-06, gradient_tol=1e-06, maxiter=1000, ridge=None, constrained_pos=None, just_point=False, ...
python
def fit_mle(self, init_vals, print_res=True, method="BFGS", loss_tol=1e-06, gradient_tol=1e-06, maxiter=1000, ridge=None, constrained_pos=None, just_point=False, ...
[ "def", "fit_mle", "(", "self", ",", "init_vals", ",", "print_res", "=", "True", ",", "method", "=", "\"BFGS\"", ",", "loss_tol", "=", "1e-06", ",", "gradient_tol", "=", "1e-06", ",", "maxiter", "=", "1000", ",", "ridge", "=", "None", ",", "constrained_po...
Parameters ---------- init_vals : 1D ndarray. The initial values to start the optimization process with. There should be one value for each utility coefficient being estimated. print_res : bool, optional. Determines whether the timing and initial and final log...
[ "Parameters", "----------", "init_vals", ":", "1D", "ndarray", ".", "The", "initial", "values", "to", "start", "the", "optimization", "process", "with", ".", "There", "should", "be", "one", "value", "for", "each", "utility", "coefficient", "being", "estimated", ...
train
https://github.com/timothyb0912/pylogit/blob/f83b0fd6debaa7358d87c3828428f6d4ead71357/pylogit/conditional_logit.py#L305-L409
timothyb0912/pylogit
pylogit/mixed_logit_calcs.py
get_normal_draws
def get_normal_draws(num_mixers, num_draws, num_vars, seed=None): """ Parameters ---------- num_mixers : int. Should be greater than zero. Denotes the number of observations for which we are making draws from a normal distrib...
python
def get_normal_draws(num_mixers, num_draws, num_vars, seed=None): """ Parameters ---------- num_mixers : int. Should be greater than zero. Denotes the number of observations for which we are making draws from a normal distrib...
[ "def", "get_normal_draws", "(", "num_mixers", ",", "num_draws", ",", "num_vars", ",", "seed", "=", "None", ")", ":", "# Check the validity of the input arguments", "assert", "all", "(", "[", "isinstance", "(", "x", ",", "int", ")", "for", "x", "in", "[", "nu...
Parameters ---------- num_mixers : int. Should be greater than zero. Denotes the number of observations for which we are making draws from a normal distribution for. I.e. the number of observations with randomly distributed coefficients. num_draws : int. Should be greater tha...
[ "Parameters", "----------", "num_mixers", ":", "int", ".", "Should", "be", "greater", "than", "zero", ".", "Denotes", "the", "number", "of", "observations", "for", "which", "we", "are", "making", "draws", "from", "a", "normal", "distribution", "for", ".", "I...
train
https://github.com/timothyb0912/pylogit/blob/f83b0fd6debaa7358d87c3828428f6d4ead71357/pylogit/mixed_logit_calcs.py#L46-L87
timothyb0912/pylogit
pylogit/mixed_logit_calcs.py
create_expanded_design_for_mixing
def create_expanded_design_for_mixing(design, draw_list, mixing_pos, rows_to_mixers): """ Parameters ---------- design : 2D ndarray. All elements should be ints, floats, or longs. Ea...
python
def create_expanded_design_for_mixing(design, draw_list, mixing_pos, rows_to_mixers): """ Parameters ---------- design : 2D ndarray. All elements should be ints, floats, or longs. Ea...
[ "def", "create_expanded_design_for_mixing", "(", "design", ",", "draw_list", ",", "mixing_pos", ",", "rows_to_mixers", ")", ":", "if", "len", "(", "mixing_pos", ")", "!=", "len", "(", "draw_list", ")", ":", "msg", "=", "\"mixing_pos == {}\"", ".", "format", "(...
Parameters ---------- design : 2D ndarray. All elements should be ints, floats, or longs. Each row corresponds to an available alternative for a given individual. There should be one column per index coefficient being estimated. draw_list : list of 2D ndarrays. All numpy arra...
[ "Parameters", "----------", "design", ":", "2D", "ndarray", ".", "All", "elements", "should", "be", "ints", "floats", "or", "longs", ".", "Each", "row", "corresponds", "to", "an", "available", "alternative", "for", "a", "given", "individual", ".", "There", "...
train
https://github.com/timothyb0912/pylogit/blob/f83b0fd6debaa7358d87c3828428f6d4ead71357/pylogit/mixed_logit_calcs.py#L108-L177
timothyb0912/pylogit
pylogit/mixed_logit_calcs.py
calc_choice_sequence_probs
def calc_choice_sequence_probs(prob_array, choice_vec, rows_to_mixers, return_type=None): """ Parameters ---------- prob_array : 2D ndarray. All elements should be ints, floats, or longs. All elements sh...
python
def calc_choice_sequence_probs(prob_array, choice_vec, rows_to_mixers, return_type=None): """ Parameters ---------- prob_array : 2D ndarray. All elements should be ints, floats, or longs. All elements sh...
[ "def", "calc_choice_sequence_probs", "(", "prob_array", ",", "choice_vec", ",", "rows_to_mixers", ",", "return_type", "=", "None", ")", ":", "if", "return_type", "not", "in", "[", "None", ",", "'all'", "]", ":", "raise", "ValueError", "(", "\"return_type must be...
Parameters ---------- prob_array : 2D ndarray. All elements should be ints, floats, or longs. All elements should be between zero and one (exclusive). Each element should represent the probability of the corresponding alternative being chosen by the corresponding individual durin...
[ "Parameters", "----------", "prob_array", ":", "2D", "ndarray", ".", "All", "elements", "should", "be", "ints", "floats", "or", "longs", ".", "All", "elements", "should", "be", "between", "zero", "and", "one", "(", "exclusive", ")", ".", "Each", "element", ...
train
https://github.com/timothyb0912/pylogit/blob/f83b0fd6debaa7358d87c3828428f6d4ead71357/pylogit/mixed_logit_calcs.py#L180-L240
timothyb0912/pylogit
pylogit/mixed_logit_calcs.py
calc_mixed_log_likelihood
def calc_mixed_log_likelihood(params, design_3d, alt_IDs, rows_to_obs, rows_to_alts, rows_to_mixers, choice_vector, ...
python
def calc_mixed_log_likelihood(params, design_3d, alt_IDs, rows_to_obs, rows_to_alts, rows_to_mixers, choice_vector, ...
[ "def", "calc_mixed_log_likelihood", "(", "params", ",", "design_3d", ",", "alt_IDs", ",", "rows_to_obs", ",", "rows_to_alts", ",", "rows_to_mixers", ",", "choice_vector", ",", "utility_transform", ",", "ridge", "=", "None", ",", "weights", "=", "None", ")", ":",...
Parameters ---------- params : 1D ndarray. All elements should by ints, floats, or longs. Should have 1 element for each utility coefficient being estimated (i.e. num_features + num_coefs_being_mixed). design_3d : 3D ndarray. All elements should be ints, floats, or longs. Sh...
[ "Parameters", "----------", "params", ":", "1D", "ndarray", ".", "All", "elements", "should", "by", "ints", "floats", "or", "longs", ".", "Should", "have", "1", "element", "for", "each", "utility", "coefficient", "being", "estimated", "(", "i", ".", "e", "...
train
https://github.com/timothyb0912/pylogit/blob/f83b0fd6debaa7358d87c3828428f6d4ead71357/pylogit/mixed_logit_calcs.py#L243-L348
timothyb0912/pylogit
pylogit/mixed_logit_calcs.py
calc_mixed_logit_gradient
def calc_mixed_logit_gradient(params, design_3d, alt_IDs, rows_to_obs, rows_to_alts, rows_to_mixers, choice_vector, ...
python
def calc_mixed_logit_gradient(params, design_3d, alt_IDs, rows_to_obs, rows_to_alts, rows_to_mixers, choice_vector, ...
[ "def", "calc_mixed_logit_gradient", "(", "params", ",", "design_3d", ",", "alt_IDs", ",", "rows_to_obs", ",", "rows_to_alts", ",", "rows_to_mixers", ",", "choice_vector", ",", "utility_transform", ",", "ridge", "=", "None", ",", "weights", "=", "None", ")", ":",...
Parameters ---------- params : 1D ndarray. All elements should by ints, floats, or longs. Should have 1 element for each utility coefficient being estimated (i.e. num_features + num_coefs_being_mixed). design_3d : 3D ndarray. All elements should be ints, floats, or longs. Sh...
[ "Parameters", "----------", "params", ":", "1D", "ndarray", ".", "All", "elements", "should", "by", "ints", "floats", "or", "longs", ".", "Should", "have", "1", "element", "for", "each", "utility", "coefficient", "being", "estimated", "(", "i", ".", "e", "...
train
https://github.com/timothyb0912/pylogit/blob/f83b0fd6debaa7358d87c3828428f6d4ead71357/pylogit/mixed_logit_calcs.py#L351-L475
timothyb0912/pylogit
pylogit/mixed_logit_calcs.py
calc_neg_log_likelihood_and_neg_gradient
def calc_neg_log_likelihood_and_neg_gradient(beta, design_3d, alt_IDs, rows_to_obs, rows_to_alts, ...
python
def calc_neg_log_likelihood_and_neg_gradient(beta, design_3d, alt_IDs, rows_to_obs, rows_to_alts, ...
[ "def", "calc_neg_log_likelihood_and_neg_gradient", "(", "beta", ",", "design_3d", ",", "alt_IDs", ",", "rows_to_obs", ",", "rows_to_alts", ",", "rows_to_mixers", ",", "choice_vector", ",", "utility_transform", ",", "constrained_pos", ",", "ridge", "=", "None", ",", ...
Parameters ---------- beta : 1D ndarray. All elements should by ints, floats, or longs. Should have 1 element for each utility coefficient being estimated (i.e. num_features + num_coefs_being_mixed). design_3d : 3D ndarray. All elements should be ints, floats, or longs. Shou...
[ "Parameters", "----------", "beta", ":", "1D", "ndarray", ".", "All", "elements", "should", "by", "ints", "floats", "or", "longs", ".", "Should", "have", "1", "element", "for", "each", "utility", "coefficient", "being", "estimated", "(", "i", ".", "e", "."...
train
https://github.com/timothyb0912/pylogit/blob/f83b0fd6debaa7358d87c3828428f6d4ead71357/pylogit/mixed_logit_calcs.py#L478-L585
timothyb0912/pylogit
pylogit/mixed_logit_calcs.py
calc_bhhh_hessian_approximation_mixed_logit
def calc_bhhh_hessian_approximation_mixed_logit(params, design_3d, alt_IDs, rows_to_obs, rows_to_alts, ...
python
def calc_bhhh_hessian_approximation_mixed_logit(params, design_3d, alt_IDs, rows_to_obs, rows_to_alts, ...
[ "def", "calc_bhhh_hessian_approximation_mixed_logit", "(", "params", ",", "design_3d", ",", "alt_IDs", ",", "rows_to_obs", ",", "rows_to_alts", ",", "rows_to_mixers", ",", "choice_vector", ",", "utility_transform", ",", "ridge", "=", "None", ",", "weights", "=", "No...
Parameters ---------- params : 1D ndarray. All elements should by ints, floats, or longs. Should have 1 element for each utility coefficient being estimated (i.e. num_features + num_coefs_being_mixed). design_3d : 3D ndarray. All elements should be ints, floats, or longs. Sh...
[ "Parameters", "----------", "params", ":", "1D", "ndarray", ".", "All", "elements", "should", "by", "ints", "floats", "or", "longs", ".", "Should", "have", "1", "element", "for", "each", "utility", "coefficient", "being", "estimated", "(", "i", ".", "e", "...
train
https://github.com/timothyb0912/pylogit/blob/f83b0fd6debaa7358d87c3828428f6d4ead71357/pylogit/mixed_logit_calcs.py#L588-L717
timothyb0912/pylogit
pylogit/bootstrap_utils.py
check_conf_percentage_validity
def check_conf_percentage_validity(conf_percentage): """ Ensures that `conf_percentage` is in (0, 100). Raises a helpful ValueError if otherwise. """ msg = "conf_percentage MUST be a number between 0.0 and 100." condition_1 = isinstance(conf_percentage, Number) if not condition_1: ra...
python
def check_conf_percentage_validity(conf_percentage): """ Ensures that `conf_percentage` is in (0, 100). Raises a helpful ValueError if otherwise. """ msg = "conf_percentage MUST be a number between 0.0 and 100." condition_1 = isinstance(conf_percentage, Number) if not condition_1: ra...
[ "def", "check_conf_percentage_validity", "(", "conf_percentage", ")", ":", "msg", "=", "\"conf_percentage MUST be a number between 0.0 and 100.\"", "condition_1", "=", "isinstance", "(", "conf_percentage", ",", "Number", ")", "if", "not", "condition_1", ":", "raise", "Val...
Ensures that `conf_percentage` is in (0, 100). Raises a helpful ValueError if otherwise.
[ "Ensures", "that", "conf_percentage", "is", "in", "(", "0", "100", ")", ".", "Raises", "a", "helpful", "ValueError", "if", "otherwise", "." ]
train
https://github.com/timothyb0912/pylogit/blob/f83b0fd6debaa7358d87c3828428f6d4ead71357/pylogit/bootstrap_utils.py#L11-L24
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", "." ]
train
https://github.com/timothyb0912/pylogit/blob/f83b0fd6debaa7358d87c3828428f6d4ead71357/pylogit/bootstrap_utils.py#L27-L38
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", "." ]
train
https://github.com/timothyb0912/pylogit/blob/f83b0fd6debaa7358d87c3828428f6d4ead71357/pylogit/construct_estimator.py#L54-L119
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", "." ]
train
https://github.com/timothyb0912/pylogit/blob/f83b0fd6debaa7358d87c3828428f6d4ead71357/pylogit/bootstrap_abc.py#L51-L63
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", "." ]
train
https://github.com/timothyb0912/pylogit/blob/f83b0fd6debaa7358d87c3828428f6d4ead71357/pylogit/bootstrap_abc.py#L66-L76
timothyb0912/pylogit
pylogit/bootstrap_abc.py
create_long_form_weights
def create_long_form_weights(model_obj, wide_weights, rows_to_obs=None): """ Converts an array of weights with one element per observation (wide-format) to an array of weights with one element per observation per available alternative (long-format). Parameters ---------- model_obj : an inst...
python
def create_long_form_weights(model_obj, wide_weights, rows_to_obs=None): """ Converts an array of weights with one element per observation (wide-format) to an array of weights with one element per observation per available alternative (long-format). Parameters ---------- model_obj : an inst...
[ "def", "create_long_form_weights", "(", "model_obj", ",", "wide_weights", ",", "rows_to_obs", "=", "None", ")", ":", "# Ensure argument validity", "check_validity_of_long_form_args", "(", "model_obj", ",", "wide_weights", ",", "rows_to_obs", ")", "# Get a rows_to_obs mappin...
Converts an array of weights with one element per observation (wide-format) to an array of weights with one element per observation per available alternative (long-format). Parameters ---------- model_obj : an instance or sublcass of the MNDC class. Should be the model object that correspon...
[ "Converts", "an", "array", "of", "weights", "with", "one", "element", "per", "observation", "(", "wide", "-", "format", ")", "to", "an", "array", "of", "weights", "with", "one", "element", "per", "observation", "per", "available", "alternative", "(", "long",...
train
https://github.com/timothyb0912/pylogit/blob/f83b0fd6debaa7358d87c3828428f6d4ead71357/pylogit/bootstrap_abc.py#L79-L120
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", "." ]
train
https://github.com/timothyb0912/pylogit/blob/f83b0fd6debaa7358d87c3828428f6d4ead71357/pylogit/bootstrap_abc.py#L123-L222
timothyb0912/pylogit
pylogit/bootstrap_abc.py
calc_empirical_influence_abc
def calc_empirical_influence_abc(term_plus, term_minus, epsilon): """ Calculates the finite difference, midpoint / slope approximation to the empirical influence array needed to compute the approximate boostrap confidence (ABC) intervals....
python
def calc_empirical_influence_abc(term_plus, term_minus, epsilon): """ Calculates the finite difference, midpoint / slope approximation to the empirical influence array needed to compute the approximate boostrap confidence (ABC) intervals....
[ "def", "calc_empirical_influence_abc", "(", "term_plus", ",", "term_minus", ",", "epsilon", ")", ":", "# Calculate the denominator of each row of the second order influence array", "denominator", "=", "2", "*", "epsilon", "# Calculate the empirical influence array.", "empirical_inf...
Calculates the finite difference, midpoint / slope approximation to the empirical influence array needed to compute the approximate boostrap confidence (ABC) intervals. Parameters ---------- term_plus : 2D ndarray. Should have one row for each observation. Should have one column for ...
[ "Calculates", "the", "finite", "difference", "midpoint", "/", "slope", "approximation", "to", "the", "empirical", "influence", "array", "needed", "to", "compute", "the", "approximate", "boostrap", "confidence", "(", "ABC", ")", "intervals", "." ]
train
https://github.com/timothyb0912/pylogit/blob/f83b0fd6debaa7358d87c3828428f6d4ead71357/pylogit/bootstrap_abc.py#L225-L277
timothyb0912/pylogit
pylogit/bootstrap_abc.py
calc_2nd_order_influence_abc
def calc_2nd_order_influence_abc(mle_params, term_plus, term_minus, epsilon): """ Calculates either a 'positive' finite difference approximation or an approximation of a 'positive' finite difference approximat...
python
def calc_2nd_order_influence_abc(mle_params, term_plus, term_minus, epsilon): """ Calculates either a 'positive' finite difference approximation or an approximation of a 'positive' finite difference approximat...
[ "def", "calc_2nd_order_influence_abc", "(", "mle_params", ",", "term_plus", ",", "term_minus", ",", "epsilon", ")", ":", "# Calculate the denominator of each row of the second order influence array", "denominator", "=", "epsilon", "**", "2", "# Initialize the second term used to ...
Calculates either a 'positive' finite difference approximation or an approximation of a 'positive' finite difference approximation to the the 2nd order empirical influence array needed to compute the approximate boostrap confidence (ABC) intervals. See the 'Notes' section for more information on the amb...
[ "Calculates", "either", "a", "positive", "finite", "difference", "approximation", "or", "an", "approximation", "of", "a", "positive", "finite", "difference", "approximation", "to", "the", "the", "2nd", "order", "empirical", "influence", "array", "needed", "to", "c...
train
https://github.com/timothyb0912/pylogit/blob/f83b0fd6debaa7358d87c3828428f6d4ead71357/pylogit/bootstrap_abc.py#L280-L352
timothyb0912/pylogit
pylogit/bootstrap_abc.py
calc_influence_arrays_for_abc
def calc_influence_arrays_for_abc(model_obj, mle_est, init_values, epsilon, **fit_kwargs): """ Calculates the empirical influence array and the 2nd order empirical influenc...
python
def calc_influence_arrays_for_abc(model_obj, mle_est, init_values, epsilon, **fit_kwargs): """ Calculates the empirical influence array and the 2nd order empirical influenc...
[ "def", "calc_influence_arrays_for_abc", "(", "model_obj", ",", "mle_est", ",", "init_values", ",", "epsilon", ",", "*", "*", "fit_kwargs", ")", ":", "# Calculate the two arrays of finite difference terms needed for the", "# various influence arrays that we want to calculate.", "t...
Calculates the empirical influence array and the 2nd order empirical influence array needed to compute the approximate boostrap confidence (ABC) intervals. Parameters ---------- model_obj : an instance or sublcass of the MNDC class. Should be the model object that corresponds to the model w...
[ "Calculates", "the", "empirical", "influence", "array", "and", "the", "2nd", "order", "empirical", "influence", "array", "needed", "to", "compute", "the", "approximate", "boostrap", "confidence", "(", "ABC", ")", "intervals", "." ]
train
https://github.com/timothyb0912/pylogit/blob/f83b0fd6debaa7358d87c3828428f6d4ead71357/pylogit/bootstrap_abc.py#L355-L415
timothyb0912/pylogit
pylogit/bootstrap_abc.py
calc_std_error_abc
def calc_std_error_abc(empirical_influence): """ Calculates the standard error of the MLE estimates for use in calculating the approximate bootstrap confidence (ABC) intervals. Parameters ---------- empirical_influence : 2D ndarray. Should have one row for each observation. Should have ...
python
def calc_std_error_abc(empirical_influence): """ Calculates the standard error of the MLE estimates for use in calculating the approximate bootstrap confidence (ABC) intervals. Parameters ---------- empirical_influence : 2D ndarray. Should have one row for each observation. Should have ...
[ "def", "calc_std_error_abc", "(", "empirical_influence", ")", ":", "num_obs", "=", "empirical_influence", ".", "shape", "[", "0", "]", "std_error", "=", "(", "(", "empirical_influence", "**", "2", ")", ".", "sum", "(", "axis", "=", "0", ")", ")", "**", "...
Calculates the standard error of the MLE estimates for use in calculating the approximate bootstrap confidence (ABC) intervals. Parameters ---------- empirical_influence : 2D ndarray. Should have one row for each observation. Should have one column for each parameter in the parameter ve...
[ "Calculates", "the", "standard", "error", "of", "the", "MLE", "estimates", "for", "use", "in", "calculating", "the", "approximate", "bootstrap", "confidence", "(", "ABC", ")", "intervals", "." ]
train
https://github.com/timothyb0912/pylogit/blob/f83b0fd6debaa7358d87c3828428f6d4ead71357/pylogit/bootstrap_abc.py#L418-L444
timothyb0912/pylogit
pylogit/bootstrap_abc.py
calc_acceleration_abc
def calc_acceleration_abc(empirical_influence): """ Calculates the acceleration constant for the approximate bootstrap confidence (ABC) intervals. Parameters ---------- empirical_influence : 2D ndarray. Should have one row for each observation. Should have one column for each pa...
python
def calc_acceleration_abc(empirical_influence): """ Calculates the acceleration constant for the approximate bootstrap confidence (ABC) intervals. Parameters ---------- empirical_influence : 2D ndarray. Should have one row for each observation. Should have one column for each pa...
[ "def", "calc_acceleration_abc", "(", "empirical_influence", ")", ":", "influence_cubed", "=", "empirical_influence", "**", "3", "influence_squared", "=", "empirical_influence", "**", "2", "numerator", "=", "influence_cubed", ".", "sum", "(", "axis", "=", "0", ")", ...
Calculates the acceleration constant for the approximate bootstrap confidence (ABC) intervals. Parameters ---------- empirical_influence : 2D ndarray. Should have one row for each observation. Should have one column for each parameter in the parameter vector being estimated. Elements sh...
[ "Calculates", "the", "acceleration", "constant", "for", "the", "approximate", "bootstrap", "confidence", "(", "ABC", ")", "intervals", "." ]
train
https://github.com/timothyb0912/pylogit/blob/f83b0fd6debaa7358d87c3828428f6d4ead71357/pylogit/bootstrap_abc.py#L447-L475
timothyb0912/pylogit
pylogit/bootstrap_abc.py
calc_bias_abc
def calc_bias_abc(second_order_influence): """ Calculates the approximate bias of the MLE estimates for use in calculating the approximate bootstrap confidence (ABC) intervals. Parameters ---------- second_order_influence : 2D ndarray. Should have one row for each observation. Should ha...
python
def calc_bias_abc(second_order_influence): """ Calculates the approximate bias of the MLE estimates for use in calculating the approximate bootstrap confidence (ABC) intervals. Parameters ---------- second_order_influence : 2D ndarray. Should have one row for each observation. Should ha...
[ "def", "calc_bias_abc", "(", "second_order_influence", ")", ":", "num_obs", "=", "second_order_influence", ".", "shape", "[", "0", "]", "constant", "=", "2.0", "*", "num_obs", "**", "2", "bias", "=", "second_order_influence", ".", "sum", "(", "axis", "=", "0...
Calculates the approximate bias of the MLE estimates for use in calculating the approximate bootstrap confidence (ABC) intervals. Parameters ---------- second_order_influence : 2D ndarray. Should have one row for each observation. Should have one column for each parameter in the paramet...
[ "Calculates", "the", "approximate", "bias", "of", "the", "MLE", "estimates", "for", "use", "in", "calculating", "the", "approximate", "bootstrap", "confidence", "(", "ABC", ")", "intervals", "." ]
train
https://github.com/timothyb0912/pylogit/blob/f83b0fd6debaa7358d87c3828428f6d4ead71357/pylogit/bootstrap_abc.py#L478-L505
timothyb0912/pylogit
pylogit/bootstrap_abc.py
calc_quadratic_coef_abc
def calc_quadratic_coef_abc(model_object, mle_params, init_vals, empirical_influence, std_error, epsilon, **fit_kwargs): """ Calculates the quad...
python
def calc_quadratic_coef_abc(model_object, mle_params, init_vals, empirical_influence, std_error, epsilon, **fit_kwargs): """ Calculates the quad...
[ "def", "calc_quadratic_coef_abc", "(", "model_object", ",", "mle_params", ",", "init_vals", ",", "empirical_influence", ",", "std_error", ",", "epsilon", ",", "*", "*", "fit_kwargs", ")", ":", "# Determine the number of observations in this dataset.", "num_obs", "=", "f...
Calculates the quadratic coefficient needed to compute the approximate boostrap confidence (ABC) intervals. Parameters ---------- model_object : an instance or sublcass of the MNDC class. Should be the model object that corresponds to the model we are constructing the bootstrap confiden...
[ "Calculates", "the", "quadratic", "coefficient", "needed", "to", "compute", "the", "approximate", "boostrap", "confidence", "(", "ABC", ")", "intervals", "." ]
train
https://github.com/timothyb0912/pylogit/blob/f83b0fd6debaa7358d87c3828428f6d4ead71357/pylogit/bootstrap_abc.py#L508-L622
timothyb0912/pylogit
pylogit/bootstrap_abc.py
calc_bias_correction_abc
def calc_bias_correction_abc(acceleration, total_curvature): """ Calculate the bias correction constant for the approximate bootstrap confidence (ABC) intervals. Parameters ---------- acceleration : 1D ndarray of scalars. Should contain the ABC intervals' estimated acceleration constant...
python
def calc_bias_correction_abc(acceleration, total_curvature): """ Calculate the bias correction constant for the approximate bootstrap confidence (ABC) intervals. Parameters ---------- acceleration : 1D ndarray of scalars. Should contain the ABC intervals' estimated acceleration constant...
[ "def", "calc_bias_correction_abc", "(", "acceleration", ",", "total_curvature", ")", ":", "inner_arg", "=", "2", "*", "norm", ".", "cdf", "(", "acceleration", ")", "*", "norm", ".", "cdf", "(", "-", "1", "*", "total_curvature", ")", "bias_correction", "=", ...
Calculate the bias correction constant for the approximate bootstrap confidence (ABC) intervals. Parameters ---------- acceleration : 1D ndarray of scalars. Should contain the ABC intervals' estimated acceleration constants. total_curvature : 1D ndarray of scalars. Should denote the...
[ "Calculate", "the", "bias", "correction", "constant", "for", "the", "approximate", "bootstrap", "confidence", "(", "ABC", ")", "intervals", "." ]
train
https://github.com/timothyb0912/pylogit/blob/f83b0fd6debaa7358d87c3828428f6d4ead71357/pylogit/bootstrap_abc.py#L779-L804
timothyb0912/pylogit
pylogit/bootstrap_abc.py
calc_endpoint_from_percentile_abc
def calc_endpoint_from_percentile_abc(model_obj, init_vals, percentile, bias_correction, acceleration, std_error, ...
python
def calc_endpoint_from_percentile_abc(model_obj, init_vals, percentile, bias_correction, acceleration, std_error, ...
[ "def", "calc_endpoint_from_percentile_abc", "(", "model_obj", ",", "init_vals", ",", "percentile", ",", "bias_correction", ",", "acceleration", ",", "std_error", ",", "empirical_influence", ",", "*", "*", "fit_kwargs", ")", ":", "# Get the bias corrected standard normal v...
Calculates the endpoint of the 1-tailed, (percentile)% confidence interval. Note this interval spans from negative infinity to the calculated endpoint. Parameters ---------- model_obj : an instance or sublcass of the MNDC class. Should be the model object that corresponds to the model we are ...
[ "Calculates", "the", "endpoint", "of", "the", "1", "-", "tailed", "(", "percentile", ")", "%", "confidence", "interval", ".", "Note", "this", "interval", "spans", "from", "negative", "infinity", "to", "the", "calculated", "endpoint", "." ]
train
https://github.com/timothyb0912/pylogit/blob/f83b0fd6debaa7358d87c3828428f6d4ead71357/pylogit/bootstrap_abc.py#L807-L897
timothyb0912/pylogit
pylogit/bootstrap_abc.py
efron_endpoints_for_abc_confidence_interval
def efron_endpoints_for_abc_confidence_interval(conf_percentage, model_obj, init_vals, bias_correction, acceleration, ...
python
def efron_endpoints_for_abc_confidence_interval(conf_percentage, model_obj, init_vals, bias_correction, acceleration, ...
[ "def", "efron_endpoints_for_abc_confidence_interval", "(", "conf_percentage", ",", "model_obj", ",", "init_vals", ",", "bias_correction", ",", "acceleration", ",", "std_error", ",", "empirical_influence", ",", "*", "*", "fit_kwargs", ")", ":", "# Calculate the percentiles...
Calculates the endpoints of the equal-tailed, `conf_percentage`% approximate bootstrap confidence (ABC) interval. 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% confid...
[ "Calculates", "the", "endpoints", "of", "the", "equal", "-", "tailed", "conf_percentage", "%", "approximate", "bootstrap", "confidence", "(", "ABC", ")", "interval", "." ]
train
https://github.com/timothyb0912/pylogit/blob/f83b0fd6debaa7358d87c3828428f6d4ead71357/pylogit/bootstrap_abc.py#L1075-L1157
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", "." ]
train
https://github.com/timothyb0912/pylogit/blob/f83b0fd6debaa7358d87c3828428f6d4ead71357/pylogit/bootstrap_abc.py#L1160-L1278
timothyb0912/pylogit
pylogit/nested_choice_calcs.py
calc_nested_probs
def calc_nested_probs(nest_coefs, index_coefs, design, rows_to_obs, rows_to_nests, chosen_row_to_obs=None, return_type="long_probs", *args, **kw...
python
def calc_nested_probs(nest_coefs, index_coefs, design, rows_to_obs, rows_to_nests, chosen_row_to_obs=None, return_type="long_probs", *args, **kw...
[ "def", "calc_nested_probs", "(", "nest_coefs", ",", "index_coefs", ",", "design", ",", "rows_to_obs", ",", "rows_to_nests", ",", "chosen_row_to_obs", "=", "None", ",", "return_type", "=", "\"long_probs\"", ",", "*", "args", ",", "*", "*", "kwargs", ")", ":", ...
Parameters ---------- nest_coefs : 1D or 2D ndarray. All elements should by ints, floats, or longs. If 1D, should have 1 element for each nesting coefficient being estimated. If 2D, should have 1 column for each set of nesting coefficients being used to predict the probabilities ...
[ "Parameters", "----------", "nest_coefs", ":", "1D", "or", "2D", "ndarray", ".", "All", "elements", "should", "by", "ints", "floats", "or", "longs", ".", "If", "1D", "should", "have", "1", "element", "for", "each", "nesting", "coefficient", "being", "estimat...
train
https://github.com/timothyb0912/pylogit/blob/f83b0fd6debaa7358d87c3828428f6d4ead71357/pylogit/nested_choice_calcs.py#L22-L263
timothyb0912/pylogit
pylogit/nested_choice_calcs.py
calc_nested_log_likelihood
def calc_nested_log_likelihood(nest_coefs, index_coefs, design, rows_to_obs, rows_to_nests, choice_vector, ridge=None, ...
python
def calc_nested_log_likelihood(nest_coefs, index_coefs, design, rows_to_obs, rows_to_nests, choice_vector, ridge=None, ...
[ "def", "calc_nested_log_likelihood", "(", "nest_coefs", ",", "index_coefs", ",", "design", ",", "rows_to_obs", ",", "rows_to_nests", ",", "choice_vector", ",", "ridge", "=", "None", ",", "weights", "=", "None", ",", "*", "args", ",", "*", "*", "kwargs", ")",...
Parameters ---------- nest_coefs : 1D or 2D ndarray. All elements should by ints, floats, or longs. If 1D, should have 1 element for each nesting coefficient being estimated. If 2D, should have 1 column for each set of nesting coefficients being used to predict the probabilities ...
[ "Parameters", "----------", "nest_coefs", ":", "1D", "or", "2D", "ndarray", ".", "All", "elements", "should", "by", "ints", "floats", "or", "longs", ".", "If", "1D", "should", "have", "1", "element", "for", "each", "nesting", "coefficient", "being", "estimat...
train
https://github.com/timothyb0912/pylogit/blob/f83b0fd6debaa7358d87c3828428f6d4ead71357/pylogit/nested_choice_calcs.py#L266-L350
timothyb0912/pylogit
pylogit/nested_choice_calcs.py
prep_vectors_for_gradient
def prep_vectors_for_gradient(nest_coefs, index_coefs, design, choice_vec, rows_to_obs, rows_to_nests, *args, ...
python
def prep_vectors_for_gradient(nest_coefs, index_coefs, design, choice_vec, rows_to_obs, rows_to_nests, *args, ...
[ "def", "prep_vectors_for_gradient", "(", "nest_coefs", ",", "index_coefs", ",", "design", ",", "choice_vec", ",", "rows_to_obs", ",", "rows_to_nests", ",", "*", "args", ",", "*", "*", "kwargs", ")", ":", "# Create the \"long_nest_parameters\" which is an array with one ...
Parameters ---------- nest_coefs : 1D or 2D ndarray. All elements should by ints, floats, or longs. If 1D, should have 1 element for each nesting coefficient being estimated. If 2D, should have 1 column for each set of nesting coefficients being used to predict the probabilities ...
[ "Parameters", "----------", "nest_coefs", ":", "1D", "or", "2D", "ndarray", ".", "All", "elements", "should", "by", "ints", "floats", "or", "longs", ".", "If", "1D", "should", "have", "1", "element", "for", "each", "nesting", "coefficient", "being", "estimat...
train
https://github.com/timothyb0912/pylogit/blob/f83b0fd6debaa7358d87c3828428f6d4ead71357/pylogit/nested_choice_calcs.py#L355-L460
timothyb0912/pylogit
pylogit/nested_choice_calcs.py
naturalize_nest_coefs
def naturalize_nest_coefs(nest_coef_estimates): """ Parameters ---------- nest_coef_estimates : 1D ndarray. Should contain the estimated logit's (`ln[nest_coefs / (1 - nest_coefs)]`) of the true nest coefficients. All values should be ints, floats, or longs. Returns ----...
python
def naturalize_nest_coefs(nest_coef_estimates): """ Parameters ---------- nest_coef_estimates : 1D ndarray. Should contain the estimated logit's (`ln[nest_coefs / (1 - nest_coefs)]`) of the true nest coefficients. All values should be ints, floats, or longs. Returns ----...
[ "def", "naturalize_nest_coefs", "(", "nest_coef_estimates", ")", ":", "# Calculate the exponential term of the", "# logistic transformation", "exp_term", "=", "np", ".", "exp", "(", "-", "1", "*", "nest_coef_estimates", ")", "# Guard against_overflow", "inf_idx", "=", "np...
Parameters ---------- nest_coef_estimates : 1D ndarray. Should contain the estimated logit's (`ln[nest_coefs / (1 - nest_coefs)]`) of the true nest coefficients. All values should be ints, floats, or longs. Returns ------- nest_coefs : 1D ndarray. Will contain the 'n...
[ "Parameters", "----------", "nest_coef_estimates", ":", "1D", "ndarray", ".", "Should", "contain", "the", "estimated", "logit", "s", "(", "ln", "[", "nest_coefs", "/", "(", "1", "-", "nest_coefs", ")", "]", ")", "of", "the", "true", "nest", "coefficients", ...
train
https://github.com/timothyb0912/pylogit/blob/f83b0fd6debaa7358d87c3828428f6d4ead71357/pylogit/nested_choice_calcs.py#L466-L496
timothyb0912/pylogit
pylogit/nested_choice_calcs.py
calc_nested_gradient
def calc_nested_gradient(orig_nest_coefs, index_coefs, design, choice_vec, rows_to_obs, rows_to_nests, ridge=None, weights=None, ...
python
def calc_nested_gradient(orig_nest_coefs, index_coefs, design, choice_vec, rows_to_obs, rows_to_nests, ridge=None, weights=None, ...
[ "def", "calc_nested_gradient", "(", "orig_nest_coefs", ",", "index_coefs", ",", "design", ",", "choice_vec", ",", "rows_to_obs", ",", "rows_to_nests", ",", "ridge", "=", "None", ",", "weights", "=", "None", ",", "use_jacobian", "=", "True", ",", "*", "args", ...
Parameters ---------- orig_nest_coefs : 1D or 2D ndarray. All elements should by ints, floats, or longs. If 1D, should have 1 element for each nesting coefficient being estimated. If 2D, should have 1 column for each set of nesting coefficients being used to predict the probabili...
[ "Parameters", "----------", "orig_nest_coefs", ":", "1D", "or", "2D", "ndarray", ".", "All", "elements", "should", "by", "ints", "floats", "or", "longs", ".", "If", "1D", "should", "have", "1", "element", "for", "each", "nesting", "coefficient", "being", "es...
train
https://github.com/timothyb0912/pylogit/blob/f83b0fd6debaa7358d87c3828428f6d4ead71357/pylogit/nested_choice_calcs.py#L500-L676
timothyb0912/pylogit
pylogit/nested_choice_calcs.py
calc_bhhh_hessian_approximation
def calc_bhhh_hessian_approximation(orig_nest_coefs, index_coefs, design, choice_vec, rows_to_obs, rows_to_nests, ...
python
def calc_bhhh_hessian_approximation(orig_nest_coefs, index_coefs, design, choice_vec, rows_to_obs, rows_to_nests, ...
[ "def", "calc_bhhh_hessian_approximation", "(", "orig_nest_coefs", ",", "index_coefs", ",", "design", ",", "choice_vec", ",", "rows_to_obs", ",", "rows_to_nests", ",", "ridge", "=", "None", ",", "weights", "=", "None", ",", "use_jacobian", "=", "True", ",", "*", ...
Parameters ---------- orig_nest_coefs : 1D or 2D ndarray. All elements should by ints, floats, or longs. If 1D, should have 1 element for each nesting coefficient being estimated. If 2D, should have 1 column for each set of nesting coefficients being used to predict the probabili...
[ "Parameters", "----------", "orig_nest_coefs", ":", "1D", "or", "2D", "ndarray", ".", "All", "elements", "should", "by", "ints", "floats", "or", "longs", ".", "If", "1D", "should", "have", "1", "element", "for", "each", "nesting", "coefficient", "being", "es...
train
https://github.com/timothyb0912/pylogit/blob/f83b0fd6debaa7358d87c3828428f6d4ead71357/pylogit/nested_choice_calcs.py#L682-L870
timothyb0912/pylogit
pylogit/uneven_logit.py
_uneven_utility_transform
def _uneven_utility_transform(systematic_utilities, alt_IDs, rows_to_alts, shape_params, intercept_params, intercept_ref_pos=None, *args, **...
python
def _uneven_utility_transform(systematic_utilities, alt_IDs, rows_to_alts, shape_params, intercept_params, intercept_ref_pos=None, *args, **...
[ "def", "_uneven_utility_transform", "(", "systematic_utilities", ",", "alt_IDs", ",", "rows_to_alts", ",", "shape_params", ",", "intercept_params", ",", "intercept_ref_pos", "=", "None", ",", "*", "args", ",", "*", "*", "kwargs", ")", ":", "# Convert the shape param...
Parameters ---------- systematic_utilities : 1D ndarray. All elements should be ints, floats, or longs. Should contain the systematic utilities of each observation per available alternative. Note that this vector is formed by the dot product of the design matrix with the vector o...
[ "Parameters", "----------", "systematic_utilities", ":", "1D", "ndarray", ".", "All", "elements", "should", "be", "ints", "floats", "or", "longs", ".", "Should", "contain", "the", "systematic", "utilities", "of", "each", "observation", "per", "available", "alterna...
train
https://github.com/timothyb0912/pylogit/blob/f83b0fd6debaa7358d87c3828428f6d4ead71357/pylogit/uneven_logit.py#L118-L238
timothyb0912/pylogit
pylogit/uneven_logit.py
_uneven_transform_deriv_v
def _uneven_transform_deriv_v(systematic_utilities, alt_IDs, rows_to_alts, shape_params, output_array=None, *args, **kwargs): """ Parameters ---------- sy...
python
def _uneven_transform_deriv_v(systematic_utilities, alt_IDs, rows_to_alts, shape_params, output_array=None, *args, **kwargs): """ Parameters ---------- sy...
[ "def", "_uneven_transform_deriv_v", "(", "systematic_utilities", ",", "alt_IDs", ",", "rows_to_alts", ",", "shape_params", ",", "output_array", "=", "None", ",", "*", "args", ",", "*", "*", "kwargs", ")", ":", "# Convert the shape parameters back into their 'natural par...
Parameters ---------- systematic_utilities : 1D ndarray. All elements should be ints, floats, or longs. Should contain the systematic utilities of each observation per available alternative. Note that this vector is formed by the dot product of the design matrix with the vector o...
[ "Parameters", "----------", "systematic_utilities", ":", "1D", "ndarray", ".", "All", "elements", "should", "be", "ints", "floats", "or", "longs", ".", "Should", "contain", "the", "systematic", "utilities", "of", "each", "observation", "per", "available", "alterna...
train
https://github.com/timothyb0912/pylogit/blob/f83b0fd6debaa7358d87c3828428f6d4ead71357/pylogit/uneven_logit.py#L241-L304
timothyb0912/pylogit
pylogit/uneven_logit.py
_uneven_transform_deriv_shape
def _uneven_transform_deriv_shape(systematic_utilities, alt_IDs, rows_to_alts, shape_params, output_array=None, *args, **kwargs): """ Paramete...
python
def _uneven_transform_deriv_shape(systematic_utilities, alt_IDs, rows_to_alts, shape_params, output_array=None, *args, **kwargs): """ Paramete...
[ "def", "_uneven_transform_deriv_shape", "(", "systematic_utilities", ",", "alt_IDs", ",", "rows_to_alts", ",", "shape_params", ",", "output_array", "=", "None", ",", "*", "args", ",", "*", "*", "kwargs", ")", ":", "# Convert the shape parameters back into their 'natural...
Parameters ---------- systematic_utilities : 1D ndarray. All elements should be ints, floats, or longs. Should contain the systematic utilities of each observation per available alternative. Note that this vector is formed by the dot product of the design matrix with the vector o...
[ "Parameters", "----------", "systematic_utilities", ":", "1D", "ndarray", ".", "All", "elements", "should", "be", "ints", "floats", "or", "longs", ".", "Should", "contain", "the", "systematic", "utilities", "of", "each", "observation", "per", "available", "alterna...
train
https://github.com/timothyb0912/pylogit/blob/f83b0fd6debaa7358d87c3828428f6d4ead71357/pylogit/uneven_logit.py#L307-L374
timothyb0912/pylogit
pylogit/uneven_logit.py
create_calc_dh_dv
def create_calc_dh_dv(estimator): """ Return the function that can be used in the various gradient and hessian calculations to calculate the derivative of the transformation with respect to the index. Parameters ---------- estimator : an instance of the estimation.LogitTypeEstimator class. ...
python
def create_calc_dh_dv(estimator): """ Return the function that can be used in the various gradient and hessian calculations to calculate the derivative of the transformation with respect to the index. Parameters ---------- estimator : an instance of the estimation.LogitTypeEstimator class. ...
[ "def", "create_calc_dh_dv", "(", "estimator", ")", ":", "dh_dv", "=", "diags", "(", "np", ".", "ones", "(", "estimator", ".", "design", ".", "shape", "[", "0", "]", ")", ",", "0", ",", "format", "=", "'csr'", ")", "# Create a function that will take in the...
Return the function that can be used in the various gradient and hessian calculations to calculate the derivative of the transformation with respect to the index. Parameters ---------- estimator : an instance of the estimation.LogitTypeEstimator class. Should contain a `design` attribute th...
[ "Return", "the", "function", "that", "can", "be", "used", "in", "the", "various", "gradient", "and", "hessian", "calculations", "to", "calculate", "the", "derivative", "of", "the", "transformation", "with", "respect", "to", "the", "index", "." ]
train
https://github.com/timothyb0912/pylogit/blob/f83b0fd6debaa7358d87c3828428f6d4ead71357/pylogit/uneven_logit.py#L422-L449
timothyb0912/pylogit
pylogit/uneven_logit.py
create_calc_dh_d_shape
def create_calc_dh_d_shape(estimator): """ Return the function that can be used in the various gradient and hessian calculations to calculate the derivative of the transformation with respect to the shape parameters. Parameters ---------- estimator : an instance of the estimation.LogitTypeE...
python
def create_calc_dh_d_shape(estimator): """ Return the function that can be used in the various gradient and hessian calculations to calculate the derivative of the transformation with respect to the shape parameters. Parameters ---------- estimator : an instance of the estimation.LogitTypeE...
[ "def", "create_calc_dh_d_shape", "(", "estimator", ")", ":", "dh_d_shape", "=", "estimator", ".", "rows_to_alts", ".", "copy", "(", ")", "# Create a function that will take in the pre-formed matrix, replace its", "# data in-place with the new data, and return the correct dh_dshape on...
Return the function that can be used in the various gradient and hessian calculations to calculate the derivative of the transformation with respect to the shape parameters. Parameters ---------- estimator : an instance of the estimation.LogitTypeEstimator class. Should contain a `rows_to_a...
[ "Return", "the", "function", "that", "can", "be", "used", "in", "the", "various", "gradient", "and", "hessian", "calculations", "to", "calculate", "the", "derivative", "of", "the", "transformation", "with", "respect", "to", "the", "shape", "parameters", "." ]
train
https://github.com/timothyb0912/pylogit/blob/f83b0fd6debaa7358d87c3828428f6d4ead71357/pylogit/uneven_logit.py#L452-L481
timothyb0912/pylogit
pylogit/uneven_logit.py
UnevenEstimator.check_length_of_initial_values
def check_length_of_initial_values(self, init_values): """ Ensures that `init_values` is of the correct length. Raises a helpful ValueError if otherwise. Parameters ---------- init_values : 1D ndarray. The initial values to start the optimizatin process with....
python
def check_length_of_initial_values(self, init_values): """ Ensures that `init_values` is of the correct length. Raises a helpful ValueError if otherwise. Parameters ---------- init_values : 1D ndarray. The initial values to start the optimizatin process with....
[ "def", "check_length_of_initial_values", "(", "self", ",", "init_values", ")", ":", "# Calculate the expected number of shape and index parameters", "# Note the uneven logit model has one shape parameter per alternative.", "num_alts", "=", "self", ".", "rows_to_alts", ".", "shape", ...
Ensures that `init_values` is of the correct length. Raises a helpful ValueError if otherwise. Parameters ---------- init_values : 1D ndarray. The initial values to start the optimizatin process with. There should be one value for each index coefficient, outside ...
[ "Ensures", "that", "init_values", "is", "of", "the", "correct", "length", ".", "Raises", "a", "helpful", "ValueError", "if", "otherwise", "." ]
train
https://github.com/timothyb0912/pylogit/blob/f83b0fd6debaa7358d87c3828428f6d4ead71357/pylogit/uneven_logit.py#L583-L617
timothyb0912/pylogit
pylogit/mixed_logit.py
mnl_utility_transform
def mnl_utility_transform(sys_utility_array, *args, **kwargs): """ Parameters ---------- sys_utility_array : ndarray. Should have 1D or 2D. Should have been created by the dot product of a design matrix and an array of index coefficients. Returns ------- systematic_utili...
python
def mnl_utility_transform(sys_utility_array, *args, **kwargs): """ Parameters ---------- sys_utility_array : ndarray. Should have 1D or 2D. Should have been created by the dot product of a design matrix and an array of index coefficients. Returns ------- systematic_utili...
[ "def", "mnl_utility_transform", "(", "sys_utility_array", ",", "*", "args", ",", "*", "*", "kwargs", ")", ":", "# Return a 2D array of systematic utility values", "if", "len", "(", "sys_utility_array", ".", "shape", ")", "==", "1", ":", "systematic_utilities", "=", ...
Parameters ---------- sys_utility_array : ndarray. Should have 1D or 2D. Should have been created by the dot product of a design matrix and an array of index coefficients. Returns ------- systematic_utilities : 2D ndarray. The input systematic utilities. If `sys_util...
[ "Parameters", "----------", "sys_utility_array", ":", "ndarray", ".", "Should", "have", "1D", "or", "2D", ".", "Should", "have", "been", "created", "by", "the", "dot", "product", "of", "a", "design", "matrix", "and", "an", "array", "of", "index", "coefficien...
train
https://github.com/timothyb0912/pylogit/blob/f83b0fd6debaa7358d87c3828428f6d4ead71357/pylogit/mixed_logit.py#L82-L103
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", ...
train
https://github.com/timothyb0912/pylogit/blob/f83b0fd6debaa7358d87c3828428f6d4ead71357/pylogit/mixed_logit.py#L106-L132
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...
train
https://github.com/timothyb0912/pylogit/blob/f83b0fd6debaa7358d87c3828428f6d4ead71357/pylogit/mixed_logit.py#L135-L168
timothyb0912/pylogit
pylogit/mixed_logit.py
MixedEstimator.convenience_split_params
def convenience_split_params(self, params, return_all_types=False): """ Splits parameter vector into shape, intercept, and index parameters. Parameters ---------- params : 1D ndarray. The array of parameters being estimated or used in calculations. return_all...
python
def convenience_split_params(self, params, return_all_types=False): """ Splits parameter vector into shape, intercept, and index parameters. Parameters ---------- params : 1D ndarray. The array of parameters being estimated or used in calculations. return_all...
[ "def", "convenience_split_params", "(", "self", ",", "params", ",", "return_all_types", "=", "False", ")", ":", "return", "self", ".", "split_params", "(", "params", ",", "return_all_types", "=", "return_all_types", ")" ]
Splits parameter vector into shape, intercept, and index parameters. Parameters ---------- params : 1D ndarray. The array of parameters being estimated or used in calculations. return_all_types : bool, optional. Determines whether or not a tuple of 4 elements wil...
[ "Splits", "parameter", "vector", "into", "shape", "intercept", "and", "index", "parameters", "." ]
train
https://github.com/timothyb0912/pylogit/blob/f83b0fd6debaa7358d87c3828428f6d4ead71357/pylogit/mixed_logit.py#L242-L262
timothyb0912/pylogit
pylogit/mixed_logit.py
MixedEstimator.convenience_calc_probs
def convenience_calc_probs(self, params): """ Calculates the probabilities of the chosen alternative, and the long format probabilities for this model and dataset. """ shapes, intercepts, betas = self.convenience_split_params(params) prob_args = (betas, ...
python
def convenience_calc_probs(self, params): """ Calculates the probabilities of the chosen alternative, and the long format probabilities for this model and dataset. """ shapes, intercepts, betas = self.convenience_split_params(params) prob_args = (betas, ...
[ "def", "convenience_calc_probs", "(", "self", ",", "params", ")", ":", "shapes", ",", "intercepts", ",", "betas", "=", "self", ".", "convenience_split_params", "(", "params", ")", "prob_args", "=", "(", "betas", ",", "self", ".", "design_3d", ",", "self", ...
Calculates the probabilities of the chosen alternative, and the long format probabilities for this model and dataset.
[ "Calculates", "the", "probabilities", "of", "the", "chosen", "alternative", "and", "the", "long", "format", "probabilities", "for", "this", "model", "and", "dataset", "." ]
train
https://github.com/timothyb0912/pylogit/blob/f83b0fd6debaa7358d87c3828428f6d4ead71357/pylogit/mixed_logit.py#L270-L288
timothyb0912/pylogit
pylogit/mixed_logit.py
MixedEstimator.convenience_calc_log_likelihood
def convenience_calc_log_likelihood(self, params): """ Calculates the log-likelihood for this model and dataset. """ shapes, intercepts, betas = self.convenience_split_params(params) args = [betas, self.design_3d, self.alt_id_vector, ...
python
def convenience_calc_log_likelihood(self, params): """ Calculates the log-likelihood for this model and dataset. """ shapes, intercepts, betas = self.convenience_split_params(params) args = [betas, self.design_3d, self.alt_id_vector, ...
[ "def", "convenience_calc_log_likelihood", "(", "self", ",", "params", ")", ":", "shapes", ",", "intercepts", ",", "betas", "=", "self", ".", "convenience_split_params", "(", "params", ")", "args", "=", "[", "betas", ",", "self", ".", "design_3d", ",", "self"...
Calculates the log-likelihood for this model and dataset.
[ "Calculates", "the", "log", "-", "likelihood", "for", "this", "model", "and", "dataset", "." ]
train
https://github.com/timothyb0912/pylogit/blob/f83b0fd6debaa7358d87c3828428f6d4ead71357/pylogit/mixed_logit.py#L290-L308
timothyb0912/pylogit
pylogit/mixed_logit.py
MixedEstimator.convenience_calc_gradient
def convenience_calc_gradient(self, params): """ Calculates the gradient of the log-likelihood for this model / dataset. """ shapes, intercepts, betas = self.convenience_split_params(params) args = [betas, self.design_3d, self.alt_id_vector, ...
python
def convenience_calc_gradient(self, params): """ Calculates the gradient of the log-likelihood for this model / dataset. """ shapes, intercepts, betas = self.convenience_split_params(params) args = [betas, self.design_3d, self.alt_id_vector, ...
[ "def", "convenience_calc_gradient", "(", "self", ",", "params", ")", ":", "shapes", ",", "intercepts", ",", "betas", "=", "self", ".", "convenience_split_params", "(", "params", ")", "args", "=", "[", "betas", ",", "self", ".", "design_3d", ",", "self", "....
Calculates the gradient of the log-likelihood for this model / dataset.
[ "Calculates", "the", "gradient", "of", "the", "log", "-", "likelihood", "for", "this", "model", "/", "dataset", "." ]
train
https://github.com/timothyb0912/pylogit/blob/f83b0fd6debaa7358d87c3828428f6d4ead71357/pylogit/mixed_logit.py#L310-L325
timothyb0912/pylogit
pylogit/mixed_logit.py
MixedEstimator.convenience_calc_hessian
def convenience_calc_hessian(self, params): """ Calculates the hessian of the log-likelihood for this model / dataset. Note that this function name is INCORRECT with regard to the actual actions performed. The Mixed Logit model uses the BHHH approximation to the Fisher Informatio...
python
def convenience_calc_hessian(self, params): """ Calculates the hessian of the log-likelihood for this model / dataset. Note that this function name is INCORRECT with regard to the actual actions performed. The Mixed Logit model uses the BHHH approximation to the Fisher Informatio...
[ "def", "convenience_calc_hessian", "(", "self", ",", "params", ")", ":", "shapes", ",", "intercepts", ",", "betas", "=", "self", ".", "convenience_split_params", "(", "params", ")", "args", "=", "[", "betas", ",", "self", ".", "design_3d", ",", "self", "."...
Calculates the hessian of the log-likelihood for this model / dataset. Note that this function name is INCORRECT with regard to the actual actions performed. The Mixed Logit model uses the BHHH approximation to the Fisher Information Matrix in place of the actual hessian.
[ "Calculates", "the", "hessian", "of", "the", "log", "-", "likelihood", "for", "this", "model", "/", "dataset", ".", "Note", "that", "this", "function", "name", "is", "INCORRECT", "with", "regard", "to", "the", "actual", "actions", "performed", ".", "The", ...
train
https://github.com/timothyb0912/pylogit/blob/f83b0fd6debaa7358d87c3828428f6d4ead71357/pylogit/mixed_logit.py#L327-L356
timothyb0912/pylogit
pylogit/mixed_logit.py
MixedEstimator.convenience_calc_fisher_approx
def convenience_calc_fisher_approx(self, params): """ Calculates the BHHH approximation of the Fisher Information Matrix for this model / dataset. Note that this function name is INCORRECT with regard to the actual actions performed. The Mixed Logit model uses a placeholder for t...
python
def convenience_calc_fisher_approx(self, params): """ Calculates the BHHH approximation of the Fisher Information Matrix for this model / dataset. Note that this function name is INCORRECT with regard to the actual actions performed. The Mixed Logit model uses a placeholder for t...
[ "def", "convenience_calc_fisher_approx", "(", "self", ",", "params", ")", ":", "shapes", ",", "intercepts", ",", "betas", "=", "self", ".", "convenience_split_params", "(", "params", ")", "placeholder_bhhh", "=", "np", ".", "diag", "(", "-", "1", "*", "np", ...
Calculates the BHHH approximation of the Fisher Information Matrix for this model / dataset. Note that this function name is INCORRECT with regard to the actual actions performed. The Mixed Logit model uses a placeholder for the BHHH approximation of the Fisher Information Matrix because...
[ "Calculates", "the", "BHHH", "approximation", "of", "the", "Fisher", "Information", "Matrix", "for", "this", "model", "/", "dataset", ".", "Note", "that", "this", "function", "name", "is", "INCORRECT", "with", "regard", "to", "the", "actual", "actions", "perfo...
train
https://github.com/timothyb0912/pylogit/blob/f83b0fd6debaa7358d87c3828428f6d4ead71357/pylogit/mixed_logit.py#L358-L375
timothyb0912/pylogit
pylogit/mixed_logit.py
MixedLogit.fit_mle
def fit_mle(self, init_vals, num_draws, seed=None, constrained_pos=None, print_res=True, method="BFGS", loss_tol=1e-06, gradient_tol=1e-06, maxiter=1000, ridge=...
python
def fit_mle(self, init_vals, num_draws, seed=None, constrained_pos=None, print_res=True, method="BFGS", loss_tol=1e-06, gradient_tol=1e-06, maxiter=1000, ridge=...
[ "def", "fit_mle", "(", "self", ",", "init_vals", ",", "num_draws", ",", "seed", "=", "None", ",", "constrained_pos", "=", "None", ",", "print_res", "=", "True", ",", "method", "=", "\"BFGS\"", ",", "loss_tol", "=", "1e-06", ",", "gradient_tol", "=", "1e-...
Parameters ---------- init_vals : 1D ndarray. Should contain the initial values to start the optimization process with. There should be one value for each utility coefficient and shape parameter being estimated. num_draws : int. Should be greater t...
[ "Parameters", "----------", "init_vals", ":", "1D", "ndarray", ".", "Should", "contain", "the", "initial", "values", "to", "start", "the", "optimization", "process", "with", ".", "There", "should", "be", "one", "value", "for", "each", "utility", "coefficient", ...
train
https://github.com/timothyb0912/pylogit/blob/f83b0fd6debaa7358d87c3828428f6d4ead71357/pylogit/mixed_logit.py#L491-L623
timothyb0912/pylogit
pylogit/mixed_logit.py
MixedLogit.__filter_past_mappings
def __filter_past_mappings(self, past_mappings, long_inclusion_array): """ Parameters ---------- past_mappings : dict. All elements should be None or compressed sparse row matrices from scipy.sparse. Th...
python
def __filter_past_mappings(self, past_mappings, long_inclusion_array): """ Parameters ---------- past_mappings : dict. All elements should be None or compressed sparse row matrices from scipy.sparse. Th...
[ "def", "__filter_past_mappings", "(", "self", ",", "past_mappings", ",", "long_inclusion_array", ")", ":", "new_mappings", "=", "{", "}", "for", "key", "in", "past_mappings", ":", "if", "past_mappings", "[", "key", "]", "is", "None", ":", "new_mappings", "[", ...
Parameters ---------- past_mappings : dict. All elements should be None or compressed sparse row matrices from scipy.sparse. The following keys should be in past_mappings: - "rows_to_obs", - "rows_to_alts", - "chosen_rows_to_obs", ...
[ "Parameters", "----------", "past_mappings", ":", "dict", ".", "All", "elements", "should", "be", "None", "or", "compressed", "sparse", "row", "matrices", "from", "scipy", ".", "sparse", ".", "The", "following", "keys", "should", "be", "in", "past_mappings", "...
train
https://github.com/timothyb0912/pylogit/blob/f83b0fd6debaa7358d87c3828428f6d4ead71357/pylogit/mixed_logit.py#L625-L679
timothyb0912/pylogit
pylogit/mixed_logit.py
MixedLogit.panel_predict
def panel_predict(self, data, num_draws, return_long_probs=True, choice_col=None, seed=None): """ Parameters ---------- data : string or pandas dataframe. If string, ...
python
def panel_predict(self, data, num_draws, return_long_probs=True, choice_col=None, seed=None): """ Parameters ---------- data : string or pandas dataframe. If string, ...
[ "def", "panel_predict", "(", "self", ",", "data", ",", "num_draws", ",", "return_long_probs", "=", "True", ",", "choice_col", "=", "None", ",", "seed", "=", "None", ")", ":", "# Ensure that the function arguments are valid", "if", "choice_col", "is", "None", "an...
Parameters ---------- data : string or pandas dataframe. If string, data should be an absolute or relative path to a CSV file containing the long format data to be predicted with this choice model. Note long format has one row per available alternative for...
[ "Parameters", "----------", "data", ":", "string", "or", "pandas", "dataframe", ".", "If", "string", "data", "should", "be", "an", "absolute", "or", "relative", "path", "to", "a", "CSV", "file", "containing", "the", "long", "format", "data", "to", "be", "p...
train
https://github.com/timothyb0912/pylogit/blob/f83b0fd6debaa7358d87c3828428f6d4ead71357/pylogit/mixed_logit.py#L681-L959
timothyb0912/pylogit
pylogit/asym_logit.py
_convert_eta_to_c
def _convert_eta_to_c(eta, ref_position): """ Parameters ---------- eta : 1D or 2D ndarray. The elements of the array should be this model's 'transformed' shape parameters, i.e. the natural log of (the corresponding shape parameter divided by the reference shape parameter). This ...
python
def _convert_eta_to_c(eta, ref_position): """ Parameters ---------- eta : 1D or 2D ndarray. The elements of the array should be this model's 'transformed' shape parameters, i.e. the natural log of (the corresponding shape parameter divided by the reference shape parameter). This ...
[ "def", "_convert_eta_to_c", "(", "eta", ",", "ref_position", ")", ":", "# Exponentiate eta", "exp_eta", "=", "np", ".", "exp", "(", "eta", ")", "# Guard against overflow", "exp_eta", "[", "np", ".", "isposinf", "(", "exp_eta", ")", "]", "=", "max_comp_value", ...
Parameters ---------- eta : 1D or 2D ndarray. The elements of the array should be this model's 'transformed' shape parameters, i.e. the natural log of (the corresponding shape parameter divided by the reference shape parameter). This array's elements will be real valued. If `eta`...
[ "Parameters", "----------", "eta", ":", "1D", "or", "2D", "ndarray", ".", "The", "elements", "of", "the", "array", "should", "be", "this", "model", "s", "transformed", "shape", "parameters", "i", ".", "e", ".", "the", "natural", "log", "of", "(", "the", ...
train
https://github.com/timothyb0912/pylogit/blob/f83b0fd6debaa7358d87c3828428f6d4ead71357/pylogit/asym_logit.py#L121-L181
timothyb0912/pylogit
pylogit/asym_logit.py
_calc_deriv_c_with_respect_to_eta
def _calc_deriv_c_with_respect_to_eta(natural_shapes, ref_position, output_array=None): """ Parameters ---------- natural_shapes : 1D ndarray. Should have one element per available alternative in the dataset whose ...
python
def _calc_deriv_c_with_respect_to_eta(natural_shapes, ref_position, output_array=None): """ Parameters ---------- natural_shapes : 1D ndarray. Should have one element per available alternative in the dataset whose ...
[ "def", "_calc_deriv_c_with_respect_to_eta", "(", "natural_shapes", ",", "ref_position", ",", "output_array", "=", "None", ")", ":", "# Generate a list of the indices which indicate the columns to be", "# selected from a 2D numpy array of", "# np.diag(natural_shapes) - np.outer(natural_sh...
Parameters ---------- natural_shapes : 1D ndarray. Should have one element per available alternative in the dataset whose choice situations are being modeled. Should have at least `ref_position` elements in it. ref_position : int. Specifies the position in the array of natura...
[ "Parameters", "----------", "natural_shapes", ":", "1D", "ndarray", ".", "Should", "have", "one", "element", "per", "available", "alternative", "in", "the", "dataset", "whose", "choice", "situations", "are", "being", "modeled", ".", "Should", "have", "at", "leas...
train
https://github.com/timothyb0912/pylogit/blob/f83b0fd6debaa7358d87c3828428f6d4ead71357/pylogit/asym_logit.py#L184-L225
timothyb0912/pylogit
pylogit/asym_logit.py
_asym_utility_transform
def _asym_utility_transform(systematic_utilities, alt_IDs, rows_to_alts, eta, intercept_params, shape_ref_position=None, intercept_ref_pos=None, ...
python
def _asym_utility_transform(systematic_utilities, alt_IDs, rows_to_alts, eta, intercept_params, shape_ref_position=None, intercept_ref_pos=None, ...
[ "def", "_asym_utility_transform", "(", "systematic_utilities", ",", "alt_IDs", ",", "rows_to_alts", ",", "eta", ",", "intercept_params", ",", "shape_ref_position", "=", "None", ",", "intercept_ref_pos", "=", "None", ",", "*", "args", ",", "*", "*", "kwargs", ")"...
Parameters ---------- systematic_utilities : 1D ndarray. Contains the systematic utilities for each each available alternative for each observation. All elements should be ints, floats, or longs. alt_IDs : 1D ndarray. All elements should be ints. There should be one row per obervation...
[ "Parameters", "----------", "systematic_utilities", ":", "1D", "ndarray", ".", "Contains", "the", "systematic", "utilities", "for", "each", "each", "available", "alternative", "for", "each", "observation", ".", "All", "elements", "should", "be", "ints", "floats", ...
train
https://github.com/timothyb0912/pylogit/blob/f83b0fd6debaa7358d87c3828428f6d4ead71357/pylogit/asym_logit.py#L228-L347
timothyb0912/pylogit
pylogit/asym_logit.py
_asym_transform_deriv_v
def _asym_transform_deriv_v(systematic_utilities, alt_IDs, rows_to_alts, eta, ref_position=None, output_array=None, *args, **kwargs): """ Parame...
python
def _asym_transform_deriv_v(systematic_utilities, alt_IDs, rows_to_alts, eta, ref_position=None, output_array=None, *args, **kwargs): """ Parame...
[ "def", "_asym_transform_deriv_v", "(", "systematic_utilities", ",", "alt_IDs", ",", "rows_to_alts", ",", "eta", ",", "ref_position", "=", "None", ",", "output_array", "=", "None", ",", "*", "args", ",", "*", "*", "kwargs", ")", ":", "##########", "# Convert th...
Parameters ---------- systematic_utilities : 1D ndarray. Contains the systematic utilities for each each available alternative for each observation. All elements should be ints, floats, or longs. alt_IDs : 1D ndarray. All elements should be ints. There should be one row per obervation...
[ "Parameters", "----------", "systematic_utilities", ":", "1D", "ndarray", ".", "Contains", "the", "systematic", "utilities", "for", "each", "each", "available", "alternative", "for", "each", "observation", ".", "All", "elements", "should", "be", "ints", "floats", ...
train
https://github.com/timothyb0912/pylogit/blob/f83b0fd6debaa7358d87c3828428f6d4ead71357/pylogit/asym_logit.py#L350-L435