示例#1
0
def plot(request):
    x = float(request.POST['x'])

    if  ('clear' in request.POST) or\
        ('x' not in request.session) or\
        x != request.session['x']:
        request.session['x'] = x
        request.session['n_x'] = 0
        request.session['d_x'] = 1

    ax, n = plot_bm_with_last_zero_lt(x)

    request.session['n_x'] += 1
    request.session['d_x'] += n

    output = cStringIO.StringIO()
    plt.savefig(output, bbox_inches='tight')
    img_txt = base64.b64encode(output.getvalue())

    prob_x = arcsine.cdf(x)
    n_x = request.session['n_x']
    d_x = request.session['d_x']

    response = {
        'image': img_txt,
        'prob': '%.4f' % prob_x,
        'frq': '%.4f' % (float(n_x) / d_x),
        'n_x': n_x,
        'd_x': d_x
    }

    return HttpResponse(json.dumps(response), content_type='application/json')
 def getCDF(self, points=None):
     """
     A Chebyshev cumulative density function.
     
     :param Chebyshev self:
         An instance of the Chebyshev class.
     :param points:
         Matrix of points for defining the cumulative density function.
     :return:
         An array of N values over the support of the Chebyshev (arcsine) distribution.
     :return:
         Cumulative density values along the support of the Chebyshev (arcsine) distribution.
     """
     if points is not None:
         return arcsine.cdf(points)
     else:
         raise (ValueError, 'Please digit an input for getCDF method')
 def getCDF(self, points=None):
     """
     A Chebyshev cumulative density function.
     
     :param Chebyshev self:
         An instance of the Chebyshev class.
     :param points:
         Matrix of points for defining the cumulative density function.
     :return:
         An array of N values over the support of the Chebyshev (arcsine) distribution.
     :return:
         Cumulative density values along the support of the Chebyshev (arcsine) distribution.
     """
     if points is not None:
          return arcsine.cdf(points)
     else:
         raise(ValueError, 'Please digit an input for getCDF method')
示例#4
0
x = np.linspace(arcsine.ppf(0.01),
                arcsine.ppf(0.99), 100)
ax.plot(x, arcsine.pdf(x),
       'r-', lw=5, alpha=0.6, label='arcsine 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 = arcsine()
ax.plot(x, rv.pdf(x), 'k-', lw=2, label='frozen pdf')

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

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

# Generate random numbers:

r = arcsine.rvs(size=1000)

# And compare the histogram:

ax.hist(r, density=True, histtype='stepfilled', alpha=0.2)
ax.legend(loc='best', frameon=False)
plt.show()