code: def testMarginalLikelihoodGradientIsDefined(self):
      num_particles = 16
      seeds = samplers.split_seed(test_util.test_seed(), n=3)
      initial_state = self.evaluate(
          WeightedParticles(
              particles=samplers.normal([num_particles], seed=seeds[0]),
              log_weights=tf.fill(
                  [num_particles], -tf.math.log(float(num_particles))
              ),
          )
      )
  
      def propose_and_update_log_weights_fn(
          _, weighted_particles, transition_scale, seed=None
      ):
          proposal_dist = normal.Normal(
              loc=weighted_particles.particles, scale=1.0
          )
          transition_dist = normal.Normal(
              loc=weighted_particles.particles, scale=transition_scale
          )
          proposed_particles = proposal_dist.sample(seed=seed)
          return WeightedParticles(
              particles=proposed_particles,
              log_weights=(
                  weighted_particles.log_weights
                  + transition_dist.log_prob(proposed_particles)
                  - proposal_dist.log_prob(proposed_particles)
              ),
          )
  
      def marginal_logprob(transition_scale):
          kernel = SequentialMonteCarlo(
              propose_and_update_log_weights_fn=functools.partial(
                  propose_and_update_log_weights_fn,
                  transition_scale=transition_scale,
              )
          )
          state, results = kernel.one_step(
              state=initial_state,
              kernel_results=kernel.bootstrap_results(initial_state),
              seed=seeds[1],
          )
          state, results = kernel.one_step(
              state=state, kernel_results=results, seed=seeds[2]
          )
          return results.accumulated_log_marginal_likelihood
  
      _, grad_lp = gradient.value_and_gradient(marginal_logprob, 1.5)
      self.assertIsNotNone(grad_lp)
      self.assertNotAllZero(grad_lp)
  
file_path: probability/tensorflow_probability/python/experimental/mcmc/sequential_monte_carlo_kernel_test.py
imports: import functools
  import numpy
  import tensorflow.compat.v2
  from tensorflow_probability.python.distributions import normal
  from tensorflow_probability.python.experimental.mcmc import sequential_monte_carlo_kernel
  from tensorflow_probability.python.experimental.mcmc.sequential_monte_carlo_kernel import SequentialMonteCarlo
  from tensorflow_probability.python.experimental.mcmc.sequential_monte_carlo_kernel import weighted_resampling
  from tensorflow_probability.python.experimental.mcmc.sequential_monte_carlo_kernel import WeightedParticles
  from tensorflow_probability.python.internal import samplers
  from tensorflow_probability.python.internal import test_util
  from tensorflow_probability.python.math import gradient
label_desc: Use image node_id 2 for calling the _SequentialMonteCarloTest obj's underlying member method code with example usage: obj.testMarginalLikelihoodGradientIsDefined() and returns: WeightedParticles, results