nodes: 0, module; 1, function_definition; 2, function_name:create_estimation_obj; 3, parameters; 4, block; 5, identifier:model_obj; 6, identifier:init_vals; 7, default_parameter; 8, default_parameter; 9, default_parameter; 10, default_parameter; 11, expression_statement; 12, comment:# Get the mapping matrices for each model; 13, expression_statement; 14, comment:# Create the zero vector for each model.; 15, expression_statement; 16, comment:# Get the internal model name; 17, expression_statement; 18, comment:# Get the split parameter function and estimator class for this model.; 19, expression_statement; 20, comment:# Create the estimator instance that is desired.; 21, expression_statement; 22, comment:# Return the created object; 23, return_statement; 24, identifier:mappings; 25, None; 26, identifier:ridge; 27, None; 28, identifier:constrained_pos; 29, None; 30, identifier:weights; 31, None; 32, comment:"""
      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 should be one value for each nest coefficient,
          shape parameter, outside intercept parameter, or index coefficient that
          is being estimated.
      mappings : OrderedDict or None, optional.
          Keys will be `["rows_to_obs", "rows_to_alts", "chosen_row_to_obs",
          "rows_to_nests"]`. The value for `rows_to_obs` will map the rows of
          the `long_form` to the unique observations (on the columns) in
          their order of appearance. The value for `rows_to_alts` will map
          the rows of the `long_form` to the unique alternatives which are
          possible in the dataset (on the columns), in sorted order--not
          order of appearance. The value for `chosen_row_to_obs`, if not
          None, will map the rows of the `long_form` that contain the chosen
          alternatives to the specific observations those rows are associated
          with (denoted by the columns). The value of `rows_to_nests`, if not
          None, will map the rows of the `long_form` to the nest (denoted by
          the column) that contains the row's alternative. Default == None.
      ridge : int, float, long, or None, optional.
          Determines whether or not ridge regression is performed. If a
          scalar is passed, then that scalar determines the ridge penalty for
          the optimization. The scalar should be greater than or equal to
          zero. Default `== None`.
      constrained_pos : list or None, optional.
          Denotes the positions of the array of estimated parameters that are
          not to change from their initial values. If a list is passed, the
          elements are to be integers where no such integer is greater than
          `init_vals.size.` Default == None.
      weights : 1D ndarray.
          Should contain the weights for each corresponding observation for each
          row of the long format data.
      """; 33, assignment; 34, assignment; 35, assignment; 36, assignment; 37, assignment; 38, identifier:estimation_obj; 39, identifier:mapping_matrices; 40, line_continuation:\; 41, conditional_expression:model_obj.get_mappings_for_fit() if mappings is None else mappings; 42, identifier:zero_vector; 43, call; 44, identifier:internal_model_name; 45, subscript; 46, pattern_list; 47, line_continuation:\; 48, tuple; 49, identifier:estimation_obj; 50, call; 51, call; 52, comparison_operator:mappings is None; 53, identifier:mappings; 54, attribute; 55, argument_list; 56, identifier:display_name_to_model_type; 57, attribute; 58, identifier:estimator_class; 59, identifier:current_split_func; 60, subscript; 61, subscript; 62, identifier:estimator_class; 63, argument_list; 64, attribute; 65, argument_list; 66, identifier:mappings; 67, None; 68, identifier:np; 69, identifier:zeros; 70, subscript; 71, identifier:model_obj; 72, identifier:model_type; 73, subscript; 74, string; 75, subscript; 76, string; 77, identifier:model_obj; 78, identifier:mapping_matrices; 79, identifier:ridge; 80, identifier:zero_vector; 81, identifier:current_split_func; 82, identifier:constrained_pos; 83, keyword_argument; 84, identifier:model_obj; 85, identifier:get_mappings_for_fit; 86, attribute; 87, integer:0; 88, identifier:model_type_to_resources; 89, identifier:internal_model_name; 90, string_content:estimator; 91, identifier:model_type_to_resources; 92, identifier:internal_model_name; 93, string_content:split_func; 94, identifier:weights; 95, identifier:weights; 96, identifier:init_vals; 97, identifier:shape
code: 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 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 should be one value for each nest coefficient,
          shape parameter, outside intercept parameter, or index coefficient that
          is being estimated.
      mappings : OrderedDict or None, optional.
          Keys will be `["rows_to_obs", "rows_to_alts", "chosen_row_to_obs",
          "rows_to_nests"]`. The value for `rows_to_obs` will map the rows of
          the `long_form` to the unique observations (on the columns) in
          their order of appearance. The value for `rows_to_alts` will map
          the rows of the `long_form` to the unique alternatives which are
          possible in the dataset (on the columns), in sorted order--not
          order of appearance. The value for `chosen_row_to_obs`, if not
          None, will map the rows of the `long_form` that contain the chosen
          alternatives to the specific observations those rows are associated
          with (denoted by the columns). The value of `rows_to_nests`, if not
          None, will map the rows of the `long_form` to the nest (denoted by
          the column) that contains the row's alternative. Default == None.
      ridge : int, float, long, or None, optional.
          Determines whether or not ridge regression is performed. If a
          scalar is passed, then that scalar determines the ridge penalty for
          the optimization. The scalar should be greater than or equal to
          zero. Default `== None`.
      constrained_pos : list or None, optional.
          Denotes the positions of the array of estimated parameters that are
          not to change from their initial values. If a list is passed, the
          elements are to be integers where no such integer is greater than
          `init_vals.size.` Default == None.
      weights : 1D ndarray.
          Should contain the weights for each corresponding observation for each
          row of the long format data.
      """
      # Get the mapping matrices for each model
      mapping_matrices =\
          model_obj.get_mappings_for_fit() if mappings is None else mappings
      # Create the zero vector for each model.
      zero_vector = np.zeros(init_vals.shape[0])
      # Get the internal model name
      internal_model_name = display_name_to_model_type[model_obj.model_type]
      # Get the split parameter function and estimator class for this model.
      estimator_class, current_split_func =\
          (model_type_to_resources[internal_model_name]['estimator'],
           model_type_to_resources[internal_model_name]['split_func'])
      # Create the estimator instance that is desired.
      estimation_obj = estimator_class(model_obj,
                                       mapping_matrices,
                                       ridge,
                                       zero_vector,
                                       current_split_func,
                                       constrained_pos,
                                       weights=weights)
      # Return the created object
      return estimation_obj