def dutyCycle(self, active=False, readOnly=False):
<EOL>if self.tm.lrnIterationIdx <= self.dutyCycleTiers[<NUM_LIT:1>]:<EOL><INDENT>dutyCycle = float(self.positiveActivations)/ self.tm.lrnIterationIdx<EOL>if not readOnly:<EOL><INDENT>self._lastPosDutyCycleIteration = self.tm.lrnIterationIdx<EOL>self._lastPosDutyCycle = dutyCycle<EOL><DEDENT>return dutyCycle<EOL><DEDENT>age = self.tm.lrnIterationIdx - self._lastPosDutyCycleIteration<EOL>if age == <NUM_LIT:0> and not active:<EOL><INDENT>return self._lastPosDutyCycle<EOL><DEDENT>for tierIdx in range(len(self.dutyCycleTiers)-<NUM_LIT:1>, <NUM_LIT:0>, -<NUM_LIT:1>):<EOL><INDENT>if self.tm.lrnIterationIdx > self.dutyCycleTiers[tierIdx]:<EOL><INDENT>alpha = self.dutyCycleAlphas[tierIdx]<EOL>break<EOL><DEDENT><DEDENT>dutyCycle = pow(<NUM_LIT:1.0>-alpha, age) * self._lastPosDutyCycle<EOL>if active:<EOL><INDENT>dutyCycle += alpha<EOL><DEDENT>if not readOnly:<EOL><INDENT>self._lastPosDutyCycleIteration = self.tm.lrnIterationIdx<EOL>self._lastPosDutyCycle = dutyCycle<EOL><DEDENT>return dutyCycle<EOL>
Compute/update and return the positive activations duty cycle of
        this segment. This is a measure of how often this segment is
        providing good predictions.

        :param active   True if segment just provided a good prediction

        :param readOnly If True, compute the updated duty cycle, but don't change
                   the cached value. This is used by debugging print statements.

        :returns: The duty cycle, a measure of how often this segment is
        providing good predictions.

        **NOTE:** This method relies on different schemes to compute the duty cycle
        based on how much history we have. In order to support this tiered
        approach **IT MUST BE CALLED ON EVERY SEGMENT AT EACH DUTY CYCLE TIER**
        (@ref dutyCycleTiers).

        When we don't have a lot of history yet (first tier), we simply return
        number of positive activations / total number of iterations

        After a certain number of iterations have accumulated, it converts into
        a moving average calculation, which is updated only when requested
        since it can be a bit expensive to compute on every iteration (it uses
        the pow() function).

        The duty cycle is computed as follows:

            dc[t] = (1-alpha) * dc[t-1] + alpha * value[t]

        If the value[t] has been 0 for a number of steps in a row, you can apply
        all of the updates at once using:

            dc[t] = (1-alpha)^(t-lastT) * dc[lastT]

        We use the alphas and tiers as defined in @ref dutyCycleAlphas and
        @ref dutyCycleTiers.