# PREPARE THE DATA FOR THE GOODNESS-OF-FIT TESTS: 
# based on populated points for every angle based on its intensity: 
# CAUTION !!!
#   THIS IS THE CORRECT APPROACH !!!
aa = np.sort( p_X )
aad = np.degrees(aa)
fX_t = np.zeros(len(aa),)
cX_t = np.zeros(len(aa),)
for mu, kap, pii in zip(loc_mle, kap_mle, p_mle):
    temp = stats.vonmises( kap, mu, scal_ )
    fX_t += pii*temp.pdf( aa )
    cX_t += pii*temp.cdf( aa )
    #fX_t += pii*stats.vonmises.pdf( aa, kap, mu, scal_ )
    #cX_t += pii*stats.vonmises.cdf( aa, kap, mu, scal_ )

x1, cfX_obs = DFST.ECDF( p_X )
x1d = np.degrees(x1)

if max(cX_t) > 1:
    cX_c = cX_t - (max(cX_t) - 1.)
else:
    cX_c = cX_t

# plot the CDF from populated points: 
fig, ax = plt.subplots(1,1,figsize=(4,3))
ax.set_title('CDF of Mixture Model')
ax.set_xlabel(r'$\theta$ (degrees)', fontsize=12)
ax.set_ylabel('Cumulative distribution', fontsize=12)
ax.plot( x1d, cfX_obs, 'b-', lw=2, alpha=0.6, label='ECDF data')
ax.plot( aad, cX_c, 'r--', label='CDF model')
ax.legend()
Exemple #2
0
ax[1].plot(h, b, label='ppf r.s.')

# -------------------------------------------------------------------- #
# draw the "ECDF Plot" (or empirical distribution function ECDF): 
# a. get ECDF using the cumsum command (1st way): 
dx = np.diff(bins)
cdfX_samp = np.cumsum(n*dx)
#fig, ax = plt.subplots(1, 1, figsize=(9,3))
ax[2].plot(bins[0:-1], cdfX_samp, 'b-.', label='ECDF (cumsum-1)')

# b. get ECDF using the cumsum command (2nd way): 
EEE = (np.cumsum(n))/sum(n)
ax[2].plot(bins[0:-1], EEE, 'g:', label='ECDF, (cumsum-2)')

# c. get ECDF using ECDF() function: 
xx2, ee2 = DFst.ECDF( X_samples )
ax[2].plot(xx2, ee2, 'c:', lw=2, label='ECDF (ECDF.py)')

# -------------------------------------------------------------------- #
# get an instance of the von Mises model: 
fX_i = stats.vonmises( kappas, locs, scal_ )
# get the CDF of the postulated distribution: 
# using the ordered random sample: 
cfX_tot = fX_i.cdf(aa)
ax[2].plot( aa, cfX_tot, 'r', label='CDF model' )
# plot the postulated pdf in the same graph as the histogram: 
ax[0].plot( aa, fX_i.pdf(aa), label='PDF model' )

ax[0].legend()
ax[1].legend()
ax[2].legend()
            label='Mixture fit')
    ax.set_xlabel(r'$\theta$ (degrees)', fontsize=12)
    ax.set_ylabel(r'$f(\theta)$', fontsize=12)
    ax.grid(color='gray', alpha=0.3, linestyle=':', linewidth=1)
    ax.legend(loc=1)
    #ax.legend(loc='upper center', bbox_to_anchor=(0.5, -0.2),
    #          fancybox=True, shadow=True, ncol=3)

    #%% ------------------------------------------------------------------- #
    # create a separate plot for ECDF and CDF:
    # CAUTION !!!!
    # this gives the WRONG ECDGF because the X_samples on which it is based
    #   is not a r.s.; it is the equally-spaced angles over which the
    #   light intensity was measured with the FFT.
    # c. get ECDF using ECDF() function:
    xx2, ee2 = DFST.ECDF(X_samples)

    fig, ax = plt.subplots(1, 1, figsize=(4, 3))
    ax.set_title('CDF of mixture of von Mises distributions (wrong)')
    ax.set_ylabel('Cumulative Probability')
    ax.set_xlabel(r'$\theta$ (rad)', fontsize=12)
    ax.plot(xx2, ee2, 'b-', label='ECDF')
    ax.plot(x_, cXtot - min(cXtot), 'r-.', label='CDF model')
    ax.legend()

    #%% GOF with intensity data:

    Dks = DFST.my_KS_GOF_mvM_I(n_X, dataFrame, alpha=0.05)

    x, cfX_obs = DFST.ECDF_Intensity(angles, values)