def fit_vm(self, distribution):
    '\n        computes the best fit of the monovariate von Mises function in the\n        semi-circle.\n        Return a tuple with the orientation preference, in the same range of\n        axis_bounds, the orientation selectivity, and an estimate of the\n        goodness-of-fit, as the variance of the predicted orientation\n        preference. The selectivity is given by the bandwith parameter of the\n        von Mises function, modified for compatibility with other selectivity\n        computations in this class. The bandwith parameter is transposed in\n        logaritmic scale, and is normalized by the maximum value for the number\n        of bins in the distribution, in order to give roughly 1.0 for a\n        distribution with one feature_bin at 1.0 an all the other at 0.0, and 0.0 for\n        uniform distributions. The normalizing factor of the selectivity is fit\n        for the total number of bins, using fit parameters computed offline.\n        There are conditions that prevents apriori the possibility to fit the\n        distribution:\n            * not enough bins, at least 4 are necessary\n            * the distribution is too flat, below the noise level\n        and conditions of aposteriori failures:\n            * "ier" flag returned by leastsq out of ( 1, 2, 3, 4 )\n            * no estimated Jacobian around the solution\n            * negative bandwith (the peak of the distribution is convex)\n        Note that these are the minimal conditions, their fulfillment does not\n        warrant unimodality, is up to the user to check the goodness-of-fit value\n        for an accurate acceptance of the fit.\n        '
    if unavailable_scipy_optimize:
        if (not VonMisesStatisticFn.user_warned_if_unavailable):
            param.Parameterized().warning('scipy.optimize not available, dummy von Mises fit')
            VonMisesStatisticFn.user_warned_if_unavailable = True
        self.fit_exit_code = 3
        return (0, 0, 0)
    to_pi = (np.pi / distribution.axis_range)
    x = (to_pi * np.array(distribution.bins()))
    n = len(x)
    if (n < 5):
        param.Parameterized().warning('No von Mises fit possible with less than 4 bins')
        self.fit_exit_code = (- 1)
        return (0, 0, 0)
    y = np.array(distribution.values())
    if (y.std() < self.noise_level):
        self.fit_exit_code = 1
        return (0, 0, 0)
    rn = (self.noise_level * np.random.random_sample(y.shape))
    p0 = (1.0, 1.0, distribution.max_value_bin())
    r = optimize.leastsq(self.von_mises_res, p0, args=(x, (y + rn)), full_output=True)
    if (not (r[(- 1)] in (1, 2, 3, 4))):
        self.fit_exit_code = (100 + r[(- 1)])
        return (0, 0, 0)
    residuals = r[2]['fvec']
    jacobian = r[1]
    bandwith = r[0][1]
    tuning = r[0][2]
    if (bandwith < 0):
        self.fit_exit_code = 1
        return (0, 0, 0)
    if (jacobian is None):
        self.fit_exit_code = 2
        return (0, 0, 0)
    error = ((residuals ** 2).sum() / (n - len(p0)))
    covariance = (jacobian * error)
    g = covariance[(2, 2)]
    p = (self._in_pi(tuning) / to_pi)
    s = self.norm_sel(bandwith, n)
    self.fit_exit_code = 0
    return (p, s, g)
computes the best fit of the monovariate von Mises function in the
semi-circle.
Return a tuple with the orientation preference, in the same range of
axis_bounds, the orientation selectivity, and an estimate of the
goodness-of-fit, as the variance of the predicted orientation
preference. The selectivity is given by the bandwith parameter of the
von Mises function, modified for compatibility with other selectivity
computations in this class. The bandwith parameter is transposed in
logaritmic scale, and is normalized by the maximum value for the number
of bins in the distribution, in order to give roughly 1.0 for a
distribution with one feature_bin at 1.0 an all the other at 0.0, and 0.0 for
uniform distributions. The normalizing factor of the selectivity is fit
for the total number of bins, using fit parameters computed offline.
There are conditions that prevents apriori the possibility to fit the
distribution:
    * not enough bins, at least 4 are necessary
    * the distribution is too flat, below the noise level
and conditions of aposteriori failures:
    * "ier" flag returned by leastsq out of ( 1, 2, 3, 4 )
    * no estimated Jacobian around the solution
    * negative bandwith (the peak of the distribution is convex)
Note that these are the minimal conditions, their fulfillment does not
warrant unimodality, is up to the user to check the goodness-of-fit value
for an accurate acceptance of the fit.
def fit_vm(self, distribution):
    '\n        computes the best fit of the monovariate von Mises function in the\n        semi-circle.\n        Return a tuple with the orientation preference, in the same range of\n        axis_bounds, the orientation selectivity, and an estimate of the\n        goodness-of-fit, as the variance of the predicted orientation\n        preference. The selectivity is given by the bandwith parameter of the\n        von Mises function, modified for compatibility with other selectivity\n        computations in this class. The bandwith parameter is transposed in\n        logaritmic scale, and is normalized by the maximum value for the number\n        of bins in the distribution, in order to give roughly 1.0 for a\n        distribution with one feature_bin at 1.0 an all the other at 0.0, and 0.0 for\n        uniform distributions. The normalizing factor of the selectivity is fit\n        for the total number of bins, using fit parameters computed offline.\n        There are conditions that prevents apriori the possibility to fit the\n        distribution:\n            * not enough bins, at least 4 are necessary\n            * the distribution is too flat, below the noise level\n        and conditions of aposteriori failures:\n            * "ier" flag returned by leastsq out of ( 1, 2, 3, 4 )\n            * no estimated Jacobian around the solution\n            * negative bandwith (the peak of the distribution is convex)\n        Note that these are the minimal conditions, their fulfillment does not\n        warrant unimodality, is up to the user to check the goodness-of-fit value\n        for an accurate acceptance of the fit.\n        '
    if unavailable_scipy_optimize:
        if (not VonMisesStatisticFn.user_warned_if_unavailable):
            param.Parameterized().warning('scipy.optimize not available, dummy von Mises fit')
            VonMisesStatisticFn.user_warned_if_unavailable = True
        self.fit_exit_code = 3
        return (0, 0, 0)
    to_pi = (np.pi / distribution.axis_range)
    x = (to_pi * np.array(distribution.bins()))
    n = len(x)
    if (n < 5):
        param.Parameterized().warning('No von Mises fit possible with less than 4 bins')
        self.fit_exit_code = (- 1)
        return (0, 0, 0)
    y = np.array(distribution.values())
    if (y.std() < self.noise_level):
        self.fit_exit_code = 1
        return (0, 0, 0)
    rn = (self.noise_level * np.random.random_sample(y.shape))
    p0 = (1.0, 1.0, distribution.max_value_bin())
    r = optimize.leastsq(self.von_mises_res, p0, args=(x, (y + rn)), full_output=True)
    if (not (r[(- 1)] in (1, 2, 3, 4))):
        self.fit_exit_code = (100 + r[(- 1)])
        return (0, 0, 0)
    residuals = r[2]['fvec']
    jacobian = r[1]
    bandwith = r[0][1]
    tuning = r[0][2]
    if (bandwith < 0):
        self.fit_exit_code = 1
        return (0, 0, 0)
    if (jacobian is None):
        self.fit_exit_code = 2
        return (0, 0, 0)
    error = ((residuals ** 2).sum() / (n - len(p0)))
    covariance = (jacobian * error)
    g = covariance[(2, 2)]
    p = (self._in_pi(tuning) / to_pi)
    s = self.norm_sel(bandwith, n)
    self.fit_exit_code = 0
    return (p, s, g)