def calc_chosenalternative(self, data):
        """
        The method returns the chosen alternaitve among the count choices
        for the choice variable under consideration
        
        Inputs:
        data - DataArray object
        """

        probabilities = DataArray(self.calc_probabilities(data), self.specification.choices)
        prob_model = AbstractProbabilityModel(probabilities, self.specification.seed)
        return prob_model.selected_choice()
    def calc_chosenalternative(self, data, choiceset=None, seed=1):
        """
        The method returns the chosen alternaitve among the count choices
        for the choice variable under consideration

        Inputs:
        data - DataArray object
        """

        probabilities = DataArray(self.calc_probabilities(data),
                                  self.specification.choices)
        prob_model = AbstractProbabilityModel(probabilities, seed)
        return prob_model.selected_choice()
    def sample_choices(self, data, destLocSetInd, zoneLabels, count,
                       sampleVarName, seed):
        destLocSetInd = destLocSetInd[:, 1:]
        #print 'number of choices - ', destLocSetInd.shape
        #raw_input()
        ti = time.time()
        for i in range(count):
            destLocSetIndSum = destLocSetInd.sum(-1)
            #print 'Number of choices', destLocSetIndSum

            probLocSet = (destLocSetInd.transpose() /
                          destLocSetIndSum).transpose()

            zeroChoices = destLocSetIndSum.mask
            #print 'zero choices', zeroChoices
            if (~zeroChoices).sum() == 0:
                continue

            #probLocSet = probLocSet[zeroChoices,:]
            #print probLocSet.shape, len(zoneLabels), 'SHAPES -- <<'
            probDataArray = DataArray(probLocSet, zoneLabels)

            # seed is the count of the sampled destination starting with 1
            probModel = AbstractProbabilityModel(probDataArray,
                                                 self.projectSeed + seed + i)
            res = probModel.selected_choice()

            # Assigning the destination
            # We subtract -1 from the results that were returned because the
            # abstract probability model returns results indexed at 1
            # actual location id = choice returned - 1

            colName = '%s%s' % (sampleVarName, i + 1)
            nonZeroRows = where(res.data <> 0)
            #print 'SELECTED LOCATIONS FOR COUNT - ', i+1
            #print res.data[:,0]
            #actualLocIds = res.data[nonZeroRows]
            #actualLocIds[nonZeroRows] -= 1
            #print actualLocIds
            data.setcolumn(colName, res.data)
            #print data.columns([colName]).data[:,0]
            #raw_input()

            # Retrieving the row indices
            dataCol = data.columns([colName]).data

            rowIndices = array(xrange(dataCol.shape[0]), int)
            #rowIndices = 0
            colIndices = res.data.astype(int)

            destLocSetInd.mask[rowIndices, colIndices - 1] = True
    def calc_chosenalternative(self, data, choiceset=None, seed=1):
        """
        The method returns the selected choice among the available
        alternatives.

        Inputs:
        data = DataArray object
        choiceset = DataArray object
        """
        if choiceset is None:
            choiceset = DataArray()
        probabilities = self.calc_probabilities(data, choiceset)
        prob_model = AbstractProbabilityModel(probabilities, seed)
        return prob_model.selected_choice()
    def sample_choices(self, data, destLocSetInd, zoneLabels, count, sampleVarName, seed):
        destLocSetInd = destLocSetInd[:,1:]
        #print 'number of choices - ', destLocSetInd.shape
        #raw_input()
        ti = time.time()
        for i in range(count):
            destLocSetIndSum = destLocSetInd.sum(-1)
            #print 'Number of choices', destLocSetIndSum


            probLocSet = (destLocSetInd.transpose()/destLocSetIndSum).transpose()

            zeroChoices = destLocSetIndSum.mask
            #print 'zero choices', zeroChoices
            if (~zeroChoices).sum() == 0:
                continue

            #probLocSet = probLocSet[zeroChoices,:]
            #print probLocSet.shape, len(zoneLabels), 'SHAPES -- <<'
            probDataArray = DataArray(probLocSet, zoneLabels)

            # seed is the count of the sampled destination starting with 1
            probModel = AbstractProbabilityModel(probDataArray, self.projectSeed+seed+i)
            res = probModel.selected_choice()

            # Assigning the destination
            # We subtract -1 from the results that were returned because the
            # abstract probability model returns results indexed at 1
            # actual location id = choice returned - 1

            colName = '%s%s' %(sampleVarName, i+1)
            nonZeroRows = where(res.data <> 0)
            #print 'SELECTED LOCATIONS FOR COUNT - ', i+1
            #print res.data[:,0]
            #actualLocIds = res.data[nonZeroRows]
            #actualLocIds[nonZeroRows] -= 1
            #print actualLocIds
            data.setcolumn(colName, res.data)
            #print data.columns([colName]).data[:,0]
            #raw_input()

            # Retrieving the row indices
            dataCol = data.columns([colName]).data

            rowIndices = array(xrange(dataCol.shape[0]), int)
            #rowIndices = 0
            colIndices = res.data.astype(int)

            destLocSetInd.mask[rowIndices, colIndices-1] = True
    def calc_chosenalternative(self, data, choiceset=None, seed=1):
        """
        The method returns the selected choice among the available
        alternatives.

        Inputs:
        data = DataArray object
        """
        #ti = time.time()
        probabilities = DataArray(self.calc_probabilities(data),
                                  self.specification.choices)
        #print "\t\t\tprobabilities calculated in %.4f" %(time.time()-ti)
        prob_model = AbstractProbabilityModel(probabilities, seed)
        #ti = time.time()
        choice = prob_model.selected_choice()
        #print "\t\t\tsimulated completed in %.4f" %(time.time()-ti)

        return choice
    def calc_chosenalternative(self, data, choiceset=None, seed=1):
        """
        The method returns the selected choice among the available
        alternatives.

        Inputs:
        data = DataArray object
        """
        #ti = time.time()
        probabilities = DataArray(self.calc_probabilities(data),
                                  self.specification.choices)
        #print "\t\t\tprobabilities calculated in %.4f" %(time.time()-ti)
        prob_model = AbstractProbabilityModel(probabilities, seed)
        #ti = time.time()
        choice = prob_model.selected_choice()
        #print "\t\t\tsimulated completed in %.4f" %(time.time()-ti)

        return choice
 def calc_chosenalternative(self, data, choiceset=None, seed=1):
     probabilities = DataArray(self.calc_probabilities(data),
                               self.specification.choices)
     prob_model = AbstractProbabilityModel(probabilities, seed)
     return prob_model.selected_choice()
 def calc_chosenalternative(self, data, choiceset=None, seed=1):
     probabilities = DataArray(self.calc_probabilities(data),
                               self.specification.choices)
     prob_model = AbstractProbabilityModel(probabilities, seed)
     return prob_model.selected_choice()