Пример #1
0
    def initial_state(self,
                      name,
                      lagged_values,
                      lagged_times,
                      machine_params=None,
                      machine_state=None,
                      **ignore):
        #
        machine = self.machine_type(params=deepcopy(machine_params),
                                    state=deepcopy(machine_state),
                                    hyper_params=deepcopy(
                                        self.machine_hyper_params))

        chronological_values = list(reversed(lagged_values))
        chronological_times = list(reversed(lagged_times))
        as_process = is_process(chronological_values)
        values = list(np.diff(
            [0.] +
            chronological_values)) if as_process else chronological_values
        dts = list(
            np.diff([chronological_times[0] - 1.0] + chronological_times))

        for value, dt in zip(values, dts):
            machine.update(value=value, dt=dt)
        return {
            't': lagged_times[0],
            'machine': machine,
            'as_process': True,
            'dt': approx_dt(lagged_times),
            'name': name
        }
Пример #2
0
 def initial_state(self, name, **ignore):
     """ Decide if it is a process or not, and create initial sketch of CDF of values or changes in values """
     # This is one off. Restarting may change the classification !
     values = self.get_lagged_values(name=name)
     times = self.get_lagged_times(name=name)
     digest = TDigest()
     as_process = is_process(values)
     data = np.diff(list(values) +
                    [0., 0.]) if is_process(values) else values
     for value in data:
         digest.update(value)
     return {
         't': times[0],
         'digest': digest,
         'as_process': as_process,
         'dt': approx_dt(times),
         'name': name
     }
Пример #3
0
    def sample(self,
               lagged_values,
               lagged_times=None,
               name=None,
               delay=None,
               **ignored):
        """ Override default sampler so that we put the stream in the fit queue """

        if is_process(lagged_values):
            if name not in self.stream_state:
                self.stream_state.update({
                    name:
                    self.initial_state(name=name,
                                       lagged_values=lagged_values,
                                       lagged_times=lagged_times,
                                       machine_state=self.machine_state,
                                       machine_params=self.machine_params)
                })
            state = self.stream_state[name]
            state = self.update_state(state=state,
                                      lagged_values=lagged_values,
                                      lagged_times=lagged_times)
            samples = self.sample_using_state(state=state,
                                              lagged_values=lagged_values,
                                              lagged_times=lagged_times,
                                              name=name,
                                              delay=delay)
            self.stream_state[name] = state
            if name not in self.fit_queue:
                self.fit_queue.append(name)
            return samples
        else:
            # Flee cases where it isn't really a process
            for delay in self.DELAYS:
                horizon = self.horizon_name(name=name, delay=delay)
                self.withdraw(horizon=horizon)