def get_next_design(self, _):
        """return the next design as a tuple of prospects"""

        if self._prob_counter == len(self._PB):
            return None

        logging.info(f'Getting design for trial {self.trial}')
        last_response_chose_B = self.get_last_response_chose_B()

        if self._trial_per_prob_counter is 0:
            self._RA = self._RB * 0.5
            self._post_choice_adjustment = (self._RB - self._RA) * 0.5
        else:
            # update RA depending upon last response
            if last_response_chose_B:
                self._RA += self._post_choice_adjustment
            else:
                self._RA -= self._post_choice_adjustment

            self._post_choice_adjustment *= 0.5

        design = Design(ProspectA=Prospect(reward=self._RA,
                                           delay=self._DA,
                                           prob=self._PA),
                        ProspectB=Prospect(reward=self._RB,
                                           delay=self._DB,
                                           prob=self._PB[self._prob_counter]))

        self._trial_per_prob_counter += 1
        if self._trial_per_prob_counter > self._trials_per_prob - 1:
            # done trials for this prob level, so move on to next
            self._prob_counter += 1
            self._trial_per_prob_counter = 0
        return design
Esempio n. 2
0
    def get_next_design(self, _):

        if self.trial >= self.max_trials:
            return None

        if self.trial == 0:
            ProspectA = Prospect(reward=self._RA,
                                 delay=self._DA,
                                 prob=self._PA)
            ProspectB = Prospect(reward=self._RB,
                                 delay=self._DB[self._delay_index],
                                 prob=self._PB)
            design = Design(ProspectA=ProspectA, ProspectB=ProspectB)
        else:

            if self.get_last_response_chose_B():
                self._delay_index += self._index_increments
            else:
                self._delay_index -= self._index_increments

            # each trial, the increments half, so will be: 8, 4, 2, 1
            self._index_increments = int(max(self._index_increments / 2, 1))

        ProspectA = Prospect(reward=self._RA, delay=self._DA, prob=self._PA)
        ProspectB = Prospect(reward=self._RB,
                             delay=self._DB[self._delay_index],
                             prob=self._PB)
        design = Design(ProspectA=ProspectA, ProspectB=ProspectB)
        return design
def df_to_design_tuple(df):
    ''' Convert 1-row pandas dataframe into named tuple'''
    RA = df.RA.values[0]
    DA = df.DA.values[0]
    PA = df.PA.values[0]
    RB = df.RB.values[0]
    DB = df.DB.values[0]
    PB = df.PB.values[0]
    chosen_design = Design(ProspectA=Prospect(reward=RA, delay=DA, prob=PA),
                           ProspectB=Prospect(reward=RB, delay=DB, prob=PB))
    return chosen_design
 def get_next_design(self, _):
     # NOTE: This is un-Pythonic as we are asking permission... we should just do it, and have a catch ??
     if self.trial < self.max_trials - 1:
         logging.info(f'Getting design for trial {self.trial}')
         design = Design(ProspectA=Prospect(reward=self._RA[self.trial],
                                            delay=self._DA,
                                            prob=self._PA),
                         ProspectB=Prospect(reward=self._RB,
                                            delay=self._DB,
                                            prob=self._PB))
         return design
     else:
         return None