code: def _fit_params_from_samples(samples, n_iter):
      assert samples.dim() == 1
      samples_count = samples.size(0)
      samples_cs = samples.cos().sum()
      samples_ss = samples.sin().sum()
      mu = torch.atan2(
          samples_ss / samples_count, samples_cs / samples_count
      )
      samples_r = (
          samples_cs**2 + samples_ss**2
      ).sqrt() / samples_count
      # From Banerjee, Arindam, et al.
      # "Clustering on the unit hypersphere using von Mises-Fisher distributions."
      # Journal of Machine Learning Research 6.Sep (2005): 1345-1382.
      # By mic (https://stats.stackexchange.com/users/67168/mic),
      # Estimating kappa of von Mises distribution, URL (version: 2015-06-12):
      # https://stats.stackexchange.com/q/156692
      kappa = (samples_r * 2 - samples_r**3) / (1 - samples_r**2)
      lr = 1e-2
      kappa.requires_grad = True
      bfgs = optim.LBFGS([kappa], lr=lr)
  
      def bfgs_closure():
          bfgs.zero_grad()
          obj = _log_modified_bessel_fn(
              kappa, order=1
          ) - _log_modified_bessel_fn(kappa, order=0)
          obj = (obj - samples_r.log()).abs()
          obj.backward()
          return obj
  
      for i in range(n_iter):
          bfgs.step(bfgs_closure)
      return mu, kappa.detach()
  
file_path: pyro/tests/distributions/test_von_mises.py
imports: import math
  import os
  import pytest
  import torch
  from torch import optim
  from pyro.distributions import VonMises, VonMises3D
  from pyro.distributions.testing.gof import auto_goodness_of_fit
  from tests.common import TEST_FAILURE_RATE, skipif_param, xfail_if_not_implemented
label_desc: Use image node_id 3 for calling a global function with example usage: _fit_params_from_samples(samples, n_iter) and returns: mu,  kappa, obj