Add new observation to frame stack and infer policy.

    Args:
      ob: array of shape (height, width, channels)

    Returns:
      logits and vf.
187799
def infer(self, ob):
    
    self._add_to_stack(ob)
    logits, vf = self.infer_from_frame_stack(self._frame_stack)
    return logits, vf
212281
def _add_observation(self, x_to_add, y_to_add):
        """"""
        self._add_observation_to_means(x_to_add, y_to_add)
        self._add_observation_to_variances(x_to_add, y_to_add)
        self.window_size += 1
1309523
def adapt_obsres(self, obsres):
        """"""

        _logger.debug('adapt observation result for work dir')
        for f in obsres.images:
            # Remove path components
            f.filename = os.path.basename(f.filename)
        return obsres
768717
def add_from_vla_obs (src, Lband, Cband):
    
    if src in models:
        raise PKError ('already have a model for ' + src)

    fL = np.log10 (1425)
    fC = np.log10 (4860)

    lL = np.log10 (Lband)
    lC = np.log10 (Cband)

    A = (lL - lC) / (fL - fC)
    B = lL - A * fL

    def fluxdens (freq_mhz):
        return 10. ** (A * np.log10 (freq_mhz) + B)

    def spindex (freq_mhz):
        return A

    models[src] = fluxdens
    spindexes[src] = spindex
1308033
<E> Observable<E> addLogging(@NonNull Observable<E> obs, @NonNull Logger log, final String msg) {
        return obs.doOnNext(r -> log(log, (ComapiResult) r, msg))
                .doOnError(t -> log(log, t, msg));
    }
1354832
def _build_obs(self, **kwargs):
        
        logging.debug('Building ObservationTree...')
        tree = ObservationTree()
        for k,v in kwargs.items():
            if k in self.ic.bands:
                if np.size(v) != 2:
                    logging.warning('{}={} ignored.'.format(k,v))
                    # continue
                    v = [v, np.nan]
                o = Observation('', k, 99) #bogus resolution=99
                s = Source(v[0], v[1])
                o.add_source(s)
                logging.debug('Adding {} ({})'.format(s,o))
                tree.add_observation(o)

        self.obs = tree
1233784
def __add_stack(self, span, limit=None):
        
        span.stack = []
        frame_count = 0

        tb = traceback.extract_stack()
        tb.reverse()
        for frame in tb:
            if limit is not None and frame_count >= limit:
                break

            # Exclude Instana frames unless we're in dev mode
            if "INSTANA_DEV" not in os.environ:
                if re_tracer_frame.search(frame[0]) is not None:
                    continue

                if re_with_stan_frame.search(frame[2]) is not None:
                    continue

            span.stack.append({
                "c": frame[0],
                "n": frame[1],
                "m": frame[2]
            })

            if limit is not None:
                frame_count += 1
879373
<E> Observable<E> wrapObservable(Observable<E> obs) {
        return obs.subscribeOn(Schedulers.io()).observeOn(Schedulers.io());
    }
624950
function updateStepAboveIO() {
    io.stepAbove = stepEl.map((el, i) => {
      const marginTop = -offsetMargin + stepOffsetHeight[i];
      const marginBottom = offsetMargin - viewH;
      const rootMargin = `${marginTop}px 0px ${marginBottom}px 0px`;
      const options = { rootMargin };
      // console.log(options);
      const obs = new IntersectionObserver(intersectStepAbove, options);
      obs.observe(el);
      return obs;
    });
  }
282312
def fit(self, obs, pstates, unique_pstates=None):
        
        obs = [np.array(o) for o in obs]
        pstates = [np.array(p) for p in pstates]

        # List or array of observation sequences
        assert len(obs) == len(pstates)
        assert obs[0].ndim == 2
        assert pstates[0].ndim == 1

        if unique_pstates is not None:
            self._init_pstates(unique_pstates)
        else:
            self._init_pstates(list(set(np.concatenate(pstates))))

        # Map the partial states to a unique index
        pstates_idx = [np.array([self.e[p] for p in seq]) for seq in pstates]

        if self.init_method == 'rand':
            self._init_random()
        elif self.init_method == 'obs':
            self._init_from_obs(obs, pstates_idx)

        self._init_pstate_freqs(pstates_idx)
        self._smooth()

        logprob = []
        for i in range(self.max_iter):
            # Expectation step
            stats = self._initialize_sufficient_statistics()
            curr_logprob = 0
            for obs_i, pstates_idx_i in zip(obs, pstates_idx):
                framelogprob = self._compute_log_likelihood(obs_i, pstates_idx_i)
                lpr, fwdlattice = self._do_forward_pass(framelogprob, pstates_idx_i)
                bwdlattice = self._do_backward_pass(framelogprob, pstates_idx_i)
                gamma = fwdlattice + bwdlattice
                posteriors = np.exp(gamma.T - logsumexp(gamma, axis=1)).T
                curr_logprob += lpr

                self._accumulate_sufficient_statistics(stats, obs_i,
                                                       pstates_idx_i, framelogprob, posteriors, fwdlattice, bwdlattice)

            logprob.append(curr_logprob)
            self.logprob_ = curr_logprob

            # Check for convergence.
            self.n_iter_performed_ = i
            if i > 0:
                self.logprob_delta = logprob[-1] - logprob[-2]
                if self.logprob_delta < self.thresh:
                    break

            # Maximization step
            self._do_mstep(stats)

            # Mix the parameters
            self._smooth()

        return self
1147933
def inference(self, observed_arr):
        '''
        
        '''
        if observed_arr.ndim < 4:
            # Add rank for channel.
            observed_arr = np.expand_dims(observed_arr, axis=1)
            self.__add_channel_flag = True
        else:
            self.__add_channel_flag = False

        return super().inference(observed_arr)
198807
def step(self, observations):
        
        q_values = self(observations)

        return {
            'actions': self.q_head.sample(q_values),
            'q': q_values
        }
1077116
def add_or_update_records(cls, tables: I2B2Tables, records: List["ObservationFact"]) -> Tuple[int, int]:
        
        return cls._add_or_update_records(tables.crc_connection, tables.observation_fact, records)
1082301
def _add_observation_to_variances(self, xj, yj):
        
        term1 = (self.window_size + 1.0) / self.window_size * (xj - self._mean_x_in_window)
        self._covariance_in_window += term1 * (yj - self._mean_y_in_window)
        self._variance_in_window += term1 * (xj - self._mean_x_in_window)
716943
def addObserver(self, observer):
        
        with self._lock:
            self._weak_observers.append(weakref.ref(observer))
            if len(self._weak_observers) == 1:
                self.startThread()
250099
def observe(self, C, obs_mesh_new, obs_vals_new, mean_under=None):
        

        self.C = C
        self.obs_mesh = C.obs_mesh
        self.obs_len = C.obs_len

        self.Uo = C.Uo

        # Evaluate the underlying mean function on the new observation mesh.
        if mean_under is None:
            mean_under_new = C._mean_under_new(self, obs_mesh_new)
        else:
            mean_under_new = mean_under

        # If self hasn't been observed yet:
        if not self.observed:

            self.dev = (obs_vals_new - mean_under_new)

            self.reg_mat = C._unobs_reg(self)

        # If self has been observed already:
        elif len(obs_vals_new) > 0:

            # Rank of old observations.
            m_old = len(self.dev)

            # Deviation of new observation from mean without regard to old
            # observations.
            dev_new = (obs_vals_new - mean_under_new)

            # Again, basis covariances get special treatment.
            self.reg_mat = C._obs_reg(self, dev_new, m_old)

            # Stack deviations of old and new observations from unobserved
            # mean.
            self.dev = hstack((self.dev, dev_new))
        self.observed = True
732614
def get_policy(observations, hparams, action_space):
  
  if not isinstance(action_space, gym.spaces.Discrete):
    raise ValueError("Expecting discrete action space.")

  obs_shape = common_layers.shape_list(observations)
  (frame_height, frame_width) = obs_shape[2:4]

  # TODO(afrozm): We have these dummy problems mainly for hparams, so cleanup
  # when possible and do this properly.
  if hparams.policy_problem_name == "dummy_policy_problem_ttt":
    tf.logging.info("Using DummyPolicyProblemTTT for the policy.")
    policy_problem = tic_tac_toe_env.DummyPolicyProblemTTT()
  else:
    tf.logging.info("Using DummyPolicyProblem for the policy.")
    policy_problem = DummyPolicyProblem(action_space, frame_height, frame_width)

  trainer_lib.add_problem_hparams(hparams, policy_problem)
  hparams.force_full_predict = True
  model = registry.model(hparams.policy_network)(
      hparams, tf.estimator.ModeKeys.TRAIN
  )
  try:
    num_target_frames = hparams.video_num_target_frames
  except AttributeError:
    num_target_frames = 1
  features = {
      "inputs": observations,
      "input_action": tf.zeros(obs_shape[:2] + [1], dtype=tf.int32),
      "input_reward": tf.zeros(obs_shape[:2] + [1], dtype=tf.int32),
      "targets": tf.zeros(obs_shape[:1] + [num_target_frames] + obs_shape[2:]),
      "target_action": tf.zeros(
          obs_shape[:1] + [num_target_frames, 1], dtype=tf.int32),
      "target_reward": tf.zeros(
          obs_shape[:1] + [num_target_frames, 1], dtype=tf.int32),
      "target_policy": tf.zeros(
          obs_shape[:1] + [num_target_frames] + [action_space.n]),
      "target_value": tf.zeros(
          obs_shape[:1] + [num_target_frames])
  }
  with tf.variable_scope(tf.get_variable_scope(), reuse=tf.AUTO_REUSE):
    t2t_model.create_dummy_vars()
    (targets, _) = model(features)
  return (targets["target_policy"][:, 0, :], targets["target_value"][:, 0])