コード例 #1
0
def normal_01_mean_test():

    #*****************************************************************************80
    #
    ## NORMAL_01_MEAN_TEST tests NORMAL_01_MEAN.
    #
    #  Licensing:
    #
    #    This code is distributed under the GNU LGPL license.
    #
    #  Modified:
    #
    #    03 March 2015
    #
    #  Author:
    #
    #    John Burkardt
    #
    import numpy as np
    import platform
    from normal_01_sample import normal_01_sample
    from r8vec_max import r8vec_max
    from r8vec_mean import r8vec_mean
    from r8vec_min import r8vec_min

    print('')
    print('NORMAL_01_MEAN_TEST')
    print('  Python version: %s' % (platform.python_version()))
    print('  NORMAL_01_MEAN computes the Normal 01 mean;')

    m = normal_01_mean()

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

    nsample = 1000
    seed = 123456789

    x = np.zeros(nsample)
    for i in range(0, nsample):
        x[i], seed = normal_01_sample(seed)

    ms = r8vec_mean(nsample, x)
    xmax = r8vec_max(nsample, x)
    xmin = r8vec_min(nsample, x)

    print('')
    print('  Sample size =     %6d' % (nsample))
    print('  Sample mean =     %14g' % (ms))
    print('  Sample maximum =  %14g' % (xmax))
    print('  Sample minimum =  %14g' % (xmin))
    #
    #  Terminate.
    #
    print('')
    print('NORMAL_01_MEAN_TEST:')
    print('  Normal end of execution.')
    return
コード例 #2
0
def normal_01_mean_test ( ):

#*****************************************************************************80
#
## NORMAL_01_MEAN_TEST tests NORMAL_01_MEAN.
#
#  Licensing:
#
#    This code is distributed under the GNU LGPL license.
#
#  Modified:
#
#    03 March 2015
#
#  Author:
#
#    John Burkardt
#
  import numpy as np
  from normal_01_sample import normal_01_sample
  from r8vec_max import r8vec_max
  from r8vec_mean import r8vec_mean
  from r8vec_min import r8vec_min

  print ''
  print 'NORMAL_01_MEAN_TEST'
  print '  NORMAL_01_MEAN computes the Normal 01 mean;'

  m = normal_01_mean ( )

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

  nsample = 1000
  seed = 123456789

  x = np.zeros ( nsample )
  for i in range ( 0, nsample ):
    x[i], seed = normal_01_sample ( seed )

  ms = r8vec_mean ( nsample, x )
  xmax = r8vec_max ( nsample, x )
  xmin = r8vec_min ( nsample, x )

  print ''
  print '  Sample size =     %6d' % ( nsample )
  print '  Sample mean =     %14g' % ( ms )
  print '  Sample maximum =  %14g' % ( xmax )
  print '  Sample minimum =  %14g' % ( xmin )

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

  return
コード例 #3
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
コード例 #4
0
def beta_sample_test():

    #*****************************************************************************80
    #
    ## BETA_SAMPLE_TEST tests BETA_MEAN, BETA_SAMPLE, BETA_VARIANCE.
    #
    #  Licensing:
    #
    #    This code is distributed under the GNU LGPL license.
    #
    #  Modified:
    #
    #    15 April 2009
    #
    #  Author:
    #
    #    John Burkardt
    #
    import numpy as np
    import platform
    from r8vec_max import r8vec_max
    from r8vec_mean import r8vec_mean
    from r8vec_min import r8vec_min
    from r8vec_variance import r8vec_variance

    nsample = 1000
    seed = 123456789

    print('')
    print('BETA_SAMPLE_TEST')
    print('  Python version: %s' % (platform.python_version()))
    print('  BETA_MEAN computes the Beta mean')
    print('  BETA_SAMPLE samples the Beta distribution')
    print('  BETA_VARIANCE computes the Beta variance.')

    a = 2.0
    b = 3.0

    check = beta_check(a, b)

    if (not check):
        print('')
        print('BETA_SAMPLE_TEST - Fatal error!')
        print('  The parameters are not legal.')
        return

    mean = beta_mean(a, b)
    variance = beta_variance(a, b)

    print('')
    print('  PDF parameter A = %14g' % (a))
    print('  PDF parameter B = %14g' % (b))
    print('  PDF mean =        %14g' % (mean))
    print('  PDF variance =    %14g' % (variance))

    x = np.zeros(nsample)
    for i in range(0, nsample):
        x[i], seed = beta_sample(a, b, seed)

    mean = r8vec_mean(nsample, x)
    variance = r8vec_variance(nsample, x)
    xmax = r8vec_max(nsample, x)
    xmin = r8vec_min(nsample, x)

    print('')
    print('  Sample size =     %6d' % (nsample))
    print('  Sample mean =     %14g' % (mean))
    print('  Sample variance = %14g' % (variance))
    print('  Sample maximum =  %14g' % (xmax))
    print('  Sample minimum =  %14g' % (xmin))
    #
    #  Terminate.
    #
    print('')
    print('BETA_SAMPLE_TEST')
    print('  Normal end of execution.')
    return
コード例 #5
0
def normal_ms_mean_test ( ):

#*****************************************************************************80
#
## NORMAL_MS_MEAN_TEST tests NORMAL_MS_MEAN.
#
#  Licensing:
#
#    This code is distributed under the GNU LGPL license.
#
#  Modified:
#
#    05 March 2015
#
#  Author:
#
#    John Burkardt
#
  import numpy as np
  from normal_ms_sample import normal_ms_sample
  from r8vec_max import r8vec_max
  from r8vec_mean import r8vec_mean
  from r8vec_min import r8vec_min

  print ''
  print 'NORMAL_MS_MEAN_TEST'
  print '  NORMAL_MS_MEAN computes the mean'
  print '  of the Normal MS distribution.'

  mu = 100.0
  sigma = 15.0

  m = normal_ms_mean ( mu, sigma )

  print ''
  print '  PDF parameter MU = %g' % ( mu )
  print '  PDF parameter SIGMA = %g' % ( sigma )
  print '  PDF mean = %g' % ( m )

  nsample = 1000
  seed = 123456789

  x = np.zeros ( nsample )
  for i in range ( 0, nsample ):
    x[i], seed = normal_ms_sample ( mu, sigma, seed )

  ms = r8vec_mean ( nsample, x )
  xmax = r8vec_max ( nsample, x )
  xmin = r8vec_min ( nsample, x )

  print ''
  print '  Sample size =     %6d' % ( nsample )
  print '  Sample mean =     %14g' % ( ms )
  print '  Sample maximum =  %14g' % ( xmax )
  print '  Sample minimum =  %14g' % ( xmin )

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

  return
コード例 #6
0
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
コード例 #7
0
def truncated_normal_ab_mean_test():

    #*****************************************************************************80
    #
    ## TRUNCATED_NORMAL_AB_MEAN_TEST tests TRUNCATED_NORMAL_AB_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_ab_sample import truncated_normal_ab_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
    b = 150.0
    mu = 100.0
    sigma = 25.0

    print ''
    print 'TRUNCATED_NORMAL_AB_MEAN_TEST'
    print '  TRUNCATED_NORMAL_AB_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,%g]' % (a, b)

    m = truncated_normal_ab_mean(mu, sigma, a, b)

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

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

    return