Ejemplo n.º 1
0
def plot_vmf_fit(x, mu, kappa, scale, index, title):
    subplot = plt.subplot(3, 1, 1 + index)
    plt.hist(x, bins=8, normed=True, histtype='stepfilled')
    domain = np.linspace(vonmises.ppf(0.01, kappa), vonmises.ppf(0.99, kappa),
                         100)
    plt.plot(domain, vonmises.pdf(domain, kappa=kappa, loc=mu, scale=scale))
    plt.title(title)
Ejemplo n.º 2
0
    def plot(self, output, frame_number):
        if (self.distribution_type == "vonmises"):
            kappa = self.params[0]
            fig, ax = plt.subplots(1, 1)
            x = np.linspace(vonmises.ppf(0.01, kappa),
                            vonmises.ppf(0.99, kappa), 100)
            ax.plot(x,
                    vonmises.pdf(x, kappa),
                    'r-',
                    lw=5,
                    alpha=0.6,
                    label='vonmises pdf')
            ax.set_xlim([-np.pi - 0.1, np.pi + 0.1])
            ax.set_ylim([0.0, 1.0])

            if self.target is not []:
                for target in self.target:
                    angle = target - self.parafoveal if target == min(
                        self.target) else target + self.parafoveal
                    ax.axvline(x=angle, label='line at x = {}'.format(target))
            plt.xlabel("Angles (Degrees)")
            plt.ylabel("Estimated Probability")
            plt.title("Method 3a Distribution")
            plt.show()
Ejemplo n.º 3
0
def bunny2circle2clusters():
    with open('bunny.pickle', mode='r+b') as f:
        bunny_dict = pickle.load(f)

    for i in bunny_dict:
        samples = np.linspace(0, len(bunny_dict[i]), num=200, endpoint=False,
                              dtype=np.int)
        print(i, len(bunny_dict[i]), len(bunny_dict[i][samples]))
        bunny_dict[i] = bunny_dict[i][samples]

    idx_last = max([i for i in bunny_dict])
    last_bunny = bunny_dict[idx_last]
    centroid = np.mean(last_bunny, axis=0, keepdims=True)
    norms = np.linalg.norm(last_bunny - centroid, axis=1)
    r = norms.mean()

    samples_per_cluster = np.linspace(0, 1, endpoint=False,
                                      num=len(last_bunny) // 4 + 1)[1:]

    circle_clustered_dict = {}
    for kappa in range(1, 200):
        print(kappa)
        angles = []
        for theta in [0, 0.5 * np.pi, np.pi, 1.5 * np.pi]:
            angles.extend(vonmises.ppf(samples_per_cluster, kappa, loc=theta))

        # plt.figure()
        # plt.plot(angles)
        # plt.show()

        angles = np.sort(np.mod(angles, 2 * np.pi))

        # plt.figure()
        # plt.plot(angles)
        # plt.show()

        x = r * np.cos(angles) + centroid[0, 0]
        y = r * np.sin(angles) + centroid[0, 1]
        curve = np.vstack((x, y)).T
        circle_clustered_dict[kappa] = curve

    with open('bunny_processed.pickle', mode='w+b') as f:
        pickle.dump(bunny_dict, f)
        pickle.dump(circle_clustered_dict, f)
from scipy.stats import vonmises
import matplotlib.pyplot as plt
fig, ax = plt.subplots(1, 1)

# Calculate a few first moments:

kappa = 3.99
mean, var, skew, kurt = vonmises.stats(kappa, moments='mvsk')

# Display the probability density function (``pdf``):

x = np.linspace(vonmises.ppf(0.01, kappa), vonmises.ppf(0.99, kappa), 100)
ax.plot(x, vonmises.pdf(x, kappa), 'r-', lw=5, alpha=0.6, label='vonmises pdf')

# Alternatively, the distribution object can be called (as a function)
# to fix the shape, location and scale parameters. This returns a "frozen"
# RV object holding the given parameters fixed.

# Freeze the distribution and display the frozen ``pdf``:

rv = vonmises(kappa)
ax.plot(x, rv.pdf(x), 'k-', lw=2, label='frozen pdf')

# Check accuracy of ``cdf`` and ``ppf``:

vals = vonmises.ppf([0.001, 0.5, 0.999], kappa)
np.allclose([0.001, 0.5, 0.999], vonmises.cdf(vals, kappa))
# True

# Generate random numbers:
 def ppf(self, dist, p):
     return vonmises.ppf(p, *self._get_params(dist))