def to_samples(self, times, confidence=False):
times = np.asarray(times)<EOL>if times.ndim != <NUM_LIT:1> or np.any(times < <NUM_LIT:0>):<EOL><INDENT>raise ParameterError('<STR_LIT>')<EOL><DEDENT>idx = np.argsort(times)<EOL>samples = times[idx]<EOL>values = [list() for _ in samples]<EOL>confidences = [list() for _ in samples]<EOL>for obs in self.data:<EOL><INDENT>start = np.searchsorted(samples, obs.time)<EOL>end = np.searchsorted(samples, obs.time + obs.duration, side='<STR_LIT:right>')<EOL>for i in range(start, end):<EOL><INDENT>values[idx[i]].append(obs.value)<EOL>confidences[idx[i]].append(obs.confidence)<EOL><DEDENT><DEDENT>if confidence:<EOL><INDENT>return values, confidences<EOL><DEDENT>else:<EOL><INDENT>return values<EOL><DEDENT>
Sample the annotation at specified times.

        Parameters
        ----------
        times : np.ndarray, non-negative, ndim=1
            The times (in seconds) to sample the annotation

        confidence : bool
            If `True`, return both values and confidences.
            If `False` (default) only return values.

        Returns
        -------
        values : list
            `values[i]` is a list of observation values for intervals
            that cover `times[i]`.

        confidence : list (optional)
            `confidence` values corresponding to `values`