def truncated_normal_b_cdf_inv_test(): #*****************************************************************************80 # ## TRUNCATED_NORMAL_B_CDF_INV_TEST tests TRUNCATED_NORMAL_B_CDF_INV. # # Licensing: # # This code is distributed under the GNU LGPL license. # # Modified: # # 09 March 2015 # # Author: # # John Burkardt # import platform from truncated_normal_b_cdf import truncated_normal_b_cdf from truncated_normal_b_sample import truncated_normal_b_sample sample_num = 10 seed = 123456789 b = 150.0 mu = 100.0 sigma = 25.0 print('') print('TRUNCATED_NORMAL_B_CDF_INV_TEST') print(' Python version: %s' % (platform.python_version())) print(' TRUNCATED_NORMAL_B_CDF_INV inverts the CDF of') print(' the Truncated Normal distribution.') print('') print(' The "parent" normal distribution has') print(' mean = %g' % (mu)) print(' standard deviation = %g' % (sigma)) print(' The parent distribution is truncated to') print(' the interval (-oo,%g]' % (b)) print('') print(' X CDF CDF_INV') print('') for i in range(0, sample_num): x, seed = truncated_normal_b_sample(mu, sigma, b, seed) cdf = truncated_normal_b_cdf(x, mu, sigma, b) x2 = truncated_normal_b_cdf_inv(cdf, mu, sigma, b) print(' %14.6g %14.6g %14.6g' % (x, cdf, x2)) # # Terminate. # print('') print('TRUNCATED_NORMAL_B_CDF_INV_TEST') print(' Normal end of execution.') return
def truncated_normal_b_variance_test ( ): #*****************************************************************************80 # ## TRUNCATED_NORMAL_B_VARIANCE_TEST tests TRUNCATED_NORMAL_B_VARIANCE. # # Licensing: # # This code is distributed under the GNU LGPL license. # # Modified: # # 08 March 2015 # # Author: # # John Burkardt # import numpy as np from truncated_normal_b_sample import truncated_normal_b_sample from r8vec_variance import r8vec_variance sample_num = 1000 seed = 123456789 b = 150.0 mu = 100.0 sigma = 25.0 print '' print 'TRUNCATED_NORMAL_B_VARIANCE_TEST' print ' TRUNCATED_NORMAL_B_VARIANCE computes the variance' print ' of the Truncated Normal distribution.' print '' print ' The "parent" normal distribution has' print ' mean = %g' % ( mu ) print ' standard deviation = %g' % ( sigma ) print ' The parent distribution is truncated to' print ' the interval (-oo,%g]' % ( b ) value = truncated_normal_b_variance ( mu, sigma, b ) print '' print ' PDF variance = %g' % ( value ) x = np.zeros ( sample_num ) for i in range ( 0, sample_num ): x[i], seed = truncated_normal_b_sample ( mu, sigma, b, seed ) value = r8vec_variance ( sample_num, x ) print '' print ' Sample size = %d' % ( sample_num ) print ' Sample variance = %g' % ( value ) print '' print 'TRUNCATED_NORMAL_B_VARIANCE_TEST:' print ' Normal end of execution.' return
def truncated_normal_b_cdf_inv_test ( ): #*****************************************************************************80 # ## TRUNCATED_NORMAL_B_CDF_INV_TEST tests TRUNCATED_NORMAL_B_CDF_INV. # # Licensing: # # This code is distributed under the GNU LGPL license. # # Modified: # # 09 March 2015 # # Author: # # John Burkardt # from truncated_normal_b_cdf import truncated_normal_b_cdf from truncated_normal_b_sample import truncated_normal_b_sample sample_num = 10 seed = 123456789 b = 150.0 mu = 100.0 sigma = 25.0 print '' print 'TRUNCATED_NORMAL_B_CDF_INV_TEST' print ' TRUNCATED_NORMAL_B_CDF_INV inverts the CDF of' print ' the Truncated Normal distribution.' print '' print ' The "parent" normal distribution has' print ' mean = %g' % ( mu ) print ' standard deviation = %g' % ( sigma ) print ' The parent distribution is truncated to' print ' the interval (-oo,%g]' % ( b ) print '' print ' X CDF CDF_INV' print '' for i in range ( 0, sample_num ): x, seed = truncated_normal_b_sample ( mu, sigma, b, seed ) cdf = truncated_normal_b_cdf ( x, mu, sigma, b ) x2 = truncated_normal_b_cdf_inv ( cdf, mu, sigma, b ) print ' %14.6g %14.6g %14.6g' % ( x, cdf, x2 ) print '' print 'TRUNCATED_NORMAL_B_CDF_INV_TEST' print ' Normal end of execution.' return
def truncated_normal_b_mean_test ( ): #*****************************************************************************80 # ## TRUNCATED_NORMAL_B_MEAN_TEST tests TRUNCATED_NORMAL_B_MEAN. # # Licensing: # # This code is distributed under the GNU LGPL license. # # Modified: # # 08 March 2015 # # Author: # # John Burkardt # import numpy as np from truncated_normal_b_sample import truncated_normal_b_sample from r8vec_max import r8vec_max from r8vec_mean import r8vec_mean from r8vec_min import r8vec_min sample_num = 1000 seed = 123456789 b = 150.0 mu = 100.0 sigma = 25.0 print '' print 'TRUNCATED_NORMAL_B_MEAN_TEST' print ' TRUNCATED_NORMAL_B_MEAN computes the mean' print ' of the Truncated Normal distribution.' print '' print ' The "parent" normal distribution has' print ' mean = %g' % ( mu ) print ' standard deviation = %g' % ( sigma ) print ' The parent distribution is truncated to' print ' the interval (-oo,%g]' % ( b ) m = truncated_normal_b_mean ( mu, sigma, b ) print '' print ' PDF mean = %g' % ( m ) x = np.zeros ( sample_num ) for i in range ( 0, sample_num ): x[i], seed = truncated_normal_b_sample ( mu, sigma, b, seed ) ms = r8vec_mean ( sample_num, x ) xmax = r8vec_max ( sample_num, x ) xmin = r8vec_min ( sample_num, x ) print '' print ' Sample size = %6d' % ( sample_num ) print ' Sample mean = %14g' % ( ms ) print ' Sample maximum = %14g' % ( xmax ) print ' Sample minimum = %14g' % ( xmin ) print '' print 'TRUNCATED_NORMAL_B_MEAN_TEST:' print ' Normal end of execution.' return
def truncated_normal_b_mean_test(): #*****************************************************************************80 # ## TRUNCATED_NORMAL_B_MEAN_TEST tests TRUNCATED_NORMAL_B_MEAN. # # Licensing: # # This code is distributed under the GNU LGPL license. # # Modified: # # 08 March 2015 # # Author: # # John Burkardt # import numpy as np from truncated_normal_b_sample import truncated_normal_b_sample from r8vec_max import r8vec_max from r8vec_mean import r8vec_mean from r8vec_min import r8vec_min sample_num = 1000 seed = 123456789 b = 150.0 mu = 100.0 sigma = 25.0 print '' print 'TRUNCATED_NORMAL_B_MEAN_TEST' print ' TRUNCATED_NORMAL_B_MEAN computes the mean' print ' of the Truncated Normal distribution.' print '' print ' The "parent" normal distribution has' print ' mean = %g' % (mu) print ' standard deviation = %g' % (sigma) print ' The parent distribution is truncated to' print ' the interval (-oo,%g]' % (b) m = truncated_normal_b_mean(mu, sigma, b) print '' print ' PDF mean = %g' % (m) x = np.zeros(sample_num) for i in range(0, sample_num): x[i], seed = truncated_normal_b_sample(mu, sigma, b, seed) ms = r8vec_mean(sample_num, x) xmax = r8vec_max(sample_num, x) xmin = r8vec_min(sample_num, x) print '' print ' Sample size = %6d' % (sample_num) print ' Sample mean = %14g' % (ms) print ' Sample maximum = %14g' % (xmax) print ' Sample minimum = %14g' % (xmin) print '' print 'TRUNCATED_NORMAL_B_MEAN_TEST:' print ' Normal end of execution.' return