code: def _particle_filter_initial_weighted_particles(
      observations,
      observation_fn,
      initial_state_prior,
      initial_state_proposal,
      num_particles,
      particles_dim=0,
      seed=None,
  ):
      """Initialize a set of weighted particles including the first observation."""
      # Propose an initial state.
      if initial_state_proposal is None:
          initial_state = initial_state_prior.sample(
              num_particles, seed=seed
          )
          initial_log_weights = ps.zeros_like(
              initial_state_prior.log_prob(initial_state)
          )
      else:
          initial_state = initial_state_proposal.sample(
              num_particles, seed=seed
          )
          initial_log_weights = initial_state_prior.log_prob(
              initial_state
          ) - initial_state_proposal.log_prob(initial_state)
      if particles_dim != 0:
          initial_state = tf.nest.map_structure(
              lambda x: dist_util.move_dimension(
                  x, source_idx=0, dest_idx=particles_dim
              ),
              initial_state,
          )
          initial_log_weights = dist_util.move_dimension(
              initial_log_weights, source_idx=0, dest_idx=particles_dim
          )
  
      # Normalize the initial weights. If we used a proposal, the weights are
      # normalized in expectation, but actually normalizing them reduces variance.
      initial_log_weights = tf.nn.log_softmax(
          initial_log_weights, axis=particles_dim
      )
  
      # Return particles weighted by the initial observation.
      return smc_kernel.WeightedParticles(
          particles=initial_state,
          log_weights=initial_log_weights
          + _compute_observation_log_weights(
              step=0,
              particles=initial_state,
              observations=observations,
              observation_fn=observation_fn,
              particles_dim=particles_dim,
          ),
      )
  
file_path: probability/tensorflow_probability/python/experimental/mcmc/particle_filter.py
imports: import numpy
  import tensorflow.compat.v2
  from tensorflow_probability.python.experimental.mcmc import sequential_monte_carlo_kernel
  from tensorflow_probability.python.experimental.mcmc import weighted_resampling
  from tensorflow_probability.python.internal import assert_util
  from tensorflow_probability.python.internal import distribution_util
  from tensorflow_probability.python.internal import docstring_util
  from tensorflow_probability.python.internal import loop_util
  from tensorflow_probability.python.internal import prefer_static
  from tensorflow_probability.python.internal import samplers
  from tensorflow_probability.python.mcmc.internal import util
label_desc: Use image node_id 5 for calling a global function with example usage: _particle_filter_initial_weighted_particles(observations, observation_fn, initial_state_prior, initial_state_proposal, num_particles, particles_dim, seed) and returns: smc_kernel