def run(self, probability, resources=None):
     """ Compute choices according to given probability, where the choices are indices
     that correspond to an index-array given in resources["index"] (1D or 2D array).
     'probability' is a 2D numpy array (nobservation x nequations).
     The returned value is a 1D array of choice indices [0, nequations-1] of length nobservations.
     If the entry 'index' is missing, the returned value is the returned value of 'random_choices'.
     """
     choice_idx = random_choices().run(probability, resources)
     index = resources.get("index", None)
     if index <> None:
         return take_choices(index, choice_idx) # transfer random choices to indices
     return choice_idx
Example #2
0
 def run(self, probability, resources=None):
     """ Compute choices according to given probability, where the choices are indices
     that correspond to an index-array given in resources["index"] (1D or 2D array).
     'probability' is a 2D numpy array (nobservation x nequations).
     The returned value is a 1D array of choice indices [0, nequations-1] of length nobservations.
     If the entry 'index' is missing, the returned value is the returned value of 'random_choices'.
     """
     choice_idx = random_choices().run(probability, resources)
     index = resources.get("index", None)
     if index <> None:
         return take_choices(
             index, choice_idx)  # transfer random choices to indices
     return choice_idx
Example #3
0
 def get_attribute_by_choice(self, name, choices, resources=None):
     """  'name' is an attribute of dataset2, 'choices' is 1D array - choices[i] represents a choice
     (index of attribute 'name' among the values index2[i,]) for individual i of dataset1[index1].
     If name == None, indices belonging to dataset2 are returned.
     The method returns 1D array - the actual values of the choices.
     """
     if choices.size <> self.get_n():
         self._raise_error(StandardError, "get_attribute_by_choice: Argument 'choices' must be the same size as dataset1")
     resources.merge_with_defaults(self.resources)
     if name == None:
         twoDattr = self.get_2d_index()
     else:
         twoDattr = self.get_2d_dataset_attribute(name, resources)
     return take_choices(twoDattr, choices)