def truncated_normal_a_variance_test ( ):

#*****************************************************************************80
#
## TRUNCATED_NORMAL_A_VARIANCE_TEST tests TRUNCATED_NORMAL_A_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_a_sample import truncated_normal_a_sample
  from r8vec_variance import r8vec_variance

  sample_num = 1000
  seed = 123456789
  a = 50.0
  mu = 100.0
  sigma = 25.0

  print ''
  print 'TRUNCATED_NORMAL_A_VARIANCE_TEST'
  print '  TRUNCATED_NORMAL_A_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 [%g,+oo)' % ( a )

  value = truncated_normal_a_variance ( mu, sigma, a )

  print ''
  print '  PDF variance = %g' % ( value )

  x = np.zeros ( sample_num )
  for i in range ( 0, sample_num ):
    x[i], seed = truncated_normal_a_sample ( mu, sigma, a, seed )

  value = r8vec_variance ( sample_num, x )

  print ''
  print '  Sample size = %d' % ( sample_num )
  print '  Sample variance = %g' % ( value )

  print ''
  print 'TRUNCATED_NORMAL_A_VARIANCE_TEST:'
  print '  Normal end of execution.'

  return
Beispiel #2
0
def truncated_normal_a_cdf_inv_test ( ):

#*****************************************************************************80
#
## TRUNCATED_NORMAL_A_CDF_INV_TEST tests TRUNCATED_NORMAL_A_CDF_INV.
#
#  Licensing:
#
#    This code is distributed under the GNU LGPL license.
#
#  Modified:
#
#    09 March 2015
#
#  Author:
#
#    John Burkardt
#
  import platform
  from truncated_normal_a_cdf import truncated_normal_a_cdf
  from truncated_normal_a_sample import truncated_normal_a_sample

  sample_num = 10
  seed = 123456789
  a = 50.0
  mu = 100.0
  sigma = 25.0

  print ( '' )
  print ( 'TRUNCATED_NORMAL_A_CDF_INV_TEST' )
  print ( '  Python version: %s' % ( platform.python_version ( ) ) )
  print ( '  TRUNCATED_NORMAL_A_CDF_INV inverts the CDF of' )
  print ( '  the lower 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 [%g,+oo)' % ( a ) )

  print ( '' )
  print ( '             X            CDF            CDF_INV' )
  print ( '' )

  for i in range ( 0, sample_num ):
    x, seed = truncated_normal_a_sample ( mu, sigma, a, seed )
    cdf = truncated_normal_a_cdf ( x, mu, sigma, a )
    x2 = truncated_normal_a_cdf_inv ( cdf, mu, sigma, a )
    print ( '  %14.6g  %14.6g  %14.6g' % ( x, cdf, x2 ) )
#
#  Terminate.
#
  print ( '' )
  print ( 'TRUNCATED_NORMAL_A_CDF_INV_TEST' )
  print ( '  Normal end of execution.' )
  return
def truncated_normal_a_cdf_inv_test ( ):

#*****************************************************************************80
#
## TRUNCATED_NORMAL_A_CDF_INV_TEST tests TRUNCATED_NORMAL_A_CDF_INV.
#
#  Licensing:
#
#    This code is distributed under the GNU LGPL license.
#
#  Modified:
#
#    09 March 2015
#
#  Author:
#
#    John Burkardt
#
  from truncated_normal_a_cdf import truncated_normal_a_cdf
  from truncated_normal_a_sample import truncated_normal_a_sample

  sample_num = 10
  seed = 123456789
  a = 50.0
  mu = 100.0
  sigma = 25.0

  print ''
  print 'TRUNCATED_NORMAL_A_CDF_INV_TEST'
  print '  TRUNCATED_NORMAL_A_CDF_INV inverts the CDF of'
  print '  the lower 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 [%g,+oo)' % ( a )

  print ''
  print '             X            CDF            CDF_INV'
  print ''

  for i in range ( 0, sample_num ):
    x, seed = truncated_normal_a_sample ( mu, sigma, a, seed )
    cdf = truncated_normal_a_cdf ( x, mu, sigma, a )
    x2 = truncated_normal_a_cdf_inv ( cdf, mu, sigma, a )
    print '  %14.6g  %14.6g  %14.6g' % ( x, cdf, x2 )

  print ''
  print 'TRUNCATED_NORMAL_A_CDF_INV_TEST'
  print '  Normal end of execution.'

  return
Beispiel #4
0
def truncated_normal_a_mean_test():

    #*****************************************************************************80
    #
    ## TRUNCATED_NORMAL_A_MEAN_TEST tests TRUNCATED_NORMAL_A_MEAN.
    #
    #  Licensing:
    #
    #    This code is distributed under the GNU LGPL license.
    #
    #  Modified:
    #
    #    08 March 2015
    #
    #  Author:
    #
    #    John Burkardt
    #
    import numpy as np
    import platform
    from truncated_normal_a_sample import truncated_normal_a_sample
    from r8vec_max import r8vec_max
    from r8vec_mean import r8vec_mean
    from r8vec_min import r8vec_min

    sample_num = 1000
    seed = 123456789
    a = 50.0
    mu = 100.0
    sigma = 25.0

    print('')
    print('TRUNCATED_NORMAL_A_MEAN_TEST')
    print('  Python version: %s' % (platform.python_version()))
    print('  TRUNCATED_NORMAL_A_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 [%g,+oo)' % (a))

    m = truncated_normal_a_mean(mu, sigma, a)

    print('')
    print('  PDF mean = %g' % (m))

    x = np.zeros(sample_num)
    for i in range(0, sample_num):
        x[i], seed = truncated_normal_a_sample(mu, sigma, a, 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))
    #
    #  Terminate.
    #
    print('')
    print('TRUNCATED_NORMAL_A_MEAN_TEST:')
    print('  Normal end of execution.')
    return
def truncated_normal_a_mean_test ( ):

#*****************************************************************************80
#
## TRUNCATED_NORMAL_A_MEAN_TEST tests TRUNCATED_NORMAL_A_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_a_sample import truncated_normal_a_sample
  from r8vec_max import r8vec_max
  from r8vec_mean import r8vec_mean
  from r8vec_min import r8vec_min

  sample_num = 1000
  seed = 123456789
  a = 50.0
  mu = 100.0
  sigma = 25.0

  print ''
  print 'TRUNCATED_NORMAL_A_MEAN_TEST'
  print '  TRUNCATED_NORMAL_A_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 [%g,+oo)' % ( a )

  m = truncated_normal_a_mean ( mu, sigma, a )

  print ''
  print '  PDF mean = %g' % ( m )

  x = np.zeros ( sample_num )
  for i in range ( 0, sample_num ):
    x[i], seed = truncated_normal_a_sample ( mu, sigma, a, 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_A_MEAN_TEST:'
  print '  Normal end of execution.'

  return