def truncated_normal_ab_cdf_inv ( cdf, mu, sigma, a, b ):

#*****************************************************************************80
#
## TRUNCATED_NORMAL_AB_CDF_INV inverts the truncated Normal CDF.
#
#  Licensing:
#
#    This code is distributed under the GNU LGPL license.
#
#  Modified:
#
#    09 March 2015
#
#  Author:
#
#    John Burkardt
#
#  Parameters:
#
#    Input, real CDF, the value of the CDF.
#    0.0 <= CDF <= 1.0.
#
#    Input, real MU, SIGMA, the mean and standard deviation of the
#    parent Normal distribution.
#
#    Input, real A, B, the lower and upper truncation limits.
#
#    Output, real X, the corresponding argument.
#
  from normal_01_cdf import normal_01_cdf
  from normal_01_cdf_inv import normal_01_cdf_inv
  from sys import exit

  if ( cdf < 0.0 or 1.0 < cdf ):
    print ( '' )
    print ( 'TRUNCATED_NORMAL_AB_CDF_INV - Fatal error!' )
    print ( '  CDF < 0 or 1 < CDF.' )
    exit ( 'TRUNCATED_NORMAL_AB_CDF_INV - Fatal error!' )

  alpha = ( a - mu ) / sigma
  beta = ( b - mu ) / sigma

  alpha_cdf = normal_01_cdf ( alpha )
  beta_cdf = normal_01_cdf ( beta )

  xi_cdf = ( beta_cdf - alpha_cdf ) * cdf + alpha_cdf
  xi = normal_01_cdf_inv ( xi_cdf )

  x = mu + sigma * xi

  return x
def truncated_normal_a_cdf_inv ( cdf, mu, sigma, a ):

#*****************************************************************************80
#
## TRUNCATED_NORMAL_A_CDF_INV inverts the lower truncated Normal CDF.
#
#  Licensing:
#
#    This code is distributed under the GNU LGPL license.
#
#  Modified:
#
#    09 March 2015
#
#  Author:
#
#    John Burkardt
#
#  Parameters:
#
#    Input, real CDF, the value of the CDF.
#    0.0 <= CDF <= 1.0.
#
#    Input, real MU, SIGMA, the mean and standard deviation of the
#    parent Normal distribution.
#
#    Input, real A, the lower truncation limit.
#
#    Output, real X, the corresponding argument.
#
  from normal_01_cdf import normal_01_cdf
  from normal_01_cdf_inv import normal_01_cdf_inv
  from sys import exit

  if ( cdf < 0.0 or 1.0 < cdf ):
    print ''
    print 'TRUNCATED_NORMAL_A_CDF_INV - Fatal error!'
    print '  CDF < 0 or 1 < CDF.'
    exit ( 'TRUNCATED_NORMAL_A_CDF_INV - Fatal error!' )

  alpha = ( a - mu ) / sigma

  alpha_cdf = normal_01_cdf ( alpha )
  beta_cdf = 1.0

  xi_cdf = ( beta_cdf - alpha_cdf ) * cdf + alpha_cdf
  xi = normal_01_cdf_inv ( xi_cdf )

  x = mu + sigma * xi

  return x
def truncated_normal_ab_sample(mu, sigma, a, b, seed):

    #*****************************************************************************80
    #
    ## TRUNCATED_NORMAL_AB_SAMPLE samples the Truncated Normal distribution.
    #
    #  Licensing:
    #
    #    This code is distributed under the GNU LGPL license.
    #
    #  Modified:
    #
    #    08 March 2015
    #
    #  Author:
    #
    #    John Burkardt
    #
    #  Parameters:
    #
    #    Input, real MU, SIGMA, the mean and standard deviation of the
    #    parent Normal distribution.
    #
    #    Input, real A, B, the lower and upper truncation limits.
    #
    #    Input, integer SEED, a seed for the random number generator.
    #
    #    Output, real X, a sample of the PDF.
    #
    #    Output, integer SEED, a seed for the random number generator.
    #
    from normal_01_cdf import normal_01_cdf
    from normal_01_cdf_inv import normal_01_cdf_inv
    from r8_uniform_01 import r8_uniform_01

    alpha = (a - mu) / sigma
    beta = (b - mu) / sigma

    alpha_cdf = normal_01_cdf(alpha)
    beta_cdf = normal_01_cdf(beta)

    u, seed = r8_uniform_01(seed)
    xi_cdf = alpha_cdf + u * (beta_cdf - alpha_cdf)
    xi = normal_01_cdf_inv(xi_cdf)

    x = mu + sigma * xi

    return x, seed
def truncated_normal_ab_sample ( mu, sigma, a, b, seed ):

#*****************************************************************************80
#
## TRUNCATED_NORMAL_AB_SAMPLE samples the Truncated Normal distribution.
#
#  Licensing:
#
#    This code is distributed under the GNU LGPL license.
#
#  Modified:
#
#    08 March 2015
#
#  Author:
#
#    John Burkardt
#
#  Parameters:
#
#    Input, real MU, SIGMA, the mean and standard deviation of the
#    parent Normal distribution.
#
#    Input, real A, B, the lower and upper truncation limits.
#
#    Input, integer SEED, a seed for the random number generator.
#
#    Output, real X, a sample of the PDF.
#
#    Output, integer SEED, a seed for the random number generator.
#
  from normal_01_cdf import normal_01_cdf
  from normal_01_cdf_inv import normal_01_cdf_inv
  from r8_uniform_01 import r8_uniform_01

  alpha = ( a - mu ) / sigma
  beta = ( b - mu ) / sigma

  alpha_cdf = normal_01_cdf ( alpha )
  beta_cdf = normal_01_cdf ( beta )

  u, seed = r8_uniform_01 ( seed )
  xi_cdf = alpha_cdf + u * ( beta_cdf - alpha_cdf )
  xi = normal_01_cdf_inv ( xi_cdf )

  x = mu + sigma * xi

  return x, seed
Пример #5
0
def normal_ms_cdf_inv(cdf, mu, sigma):

    #*****************************************************************************80
    #
    ## NORMAL_MS_CDF_INV inverts the CDF of the Normal MS distribution.
    #
    #  Licensing:
    #
    #    This code is distributed under the GNU LGPL license.
    #
    #  Modified:
    #
    #    05 March 2015
    #
    #  Author:
    #
    #    John Burkardt
    #
    #  Parameters:
    #
    #    Input, real CDF, the value of the CDF.
    #    0.0 <= CDF <= 1.0.
    #
    #    Input, real MU, SIGMA, the parameters of the PDF.
    #    0.0 < SIGMA.
    #
    #    Output, real VALUE, the corresponding argument.
    #
    from normal_01_cdf_inv import normal_01_cdf_inv

    if (cdf < 0.0 or 1.0 < cdf):
        print ''
        print 'NORMAL_MS_CDF_INV - Fatal error!'
        print '  CDF < 0 or 1 < CDF.'
        error('NORMAL_MS_CDF_INV - Fatal error!')

    y = normal_01_cdf_inv(cdf)

    value = mu + sigma * y

    return value
def normal_ms_cdf_inv ( cdf, mu, sigma ):

#*****************************************************************************80
#
## NORMAL_MS_CDF_INV inverts the CDF of the Normal MS distribution.
#
#  Licensing:
#
#    This code is distributed under the GNU LGPL license.
#
#  Modified:
#
#    05 March 2015
#
#  Author:
#
#    John Burkardt
#
#  Parameters:
#
#    Input, real CDF, the value of the CDF.
#    0.0 <= CDF <= 1.0.
#
#    Input, real MU, SIGMA, the parameters of the PDF.
#    0.0 < SIGMA.
#
#    Output, real VALUE, the corresponding argument.
#
  from normal_01_cdf_inv import normal_01_cdf_inv

  if ( cdf < 0.0 or 1.0 < cdf ):
    print ''
    print 'NORMAL_MS_CDF_INV - Fatal error!'
    print '  CDF < 0 or 1 < CDF.'
    error ( 'NORMAL_MS_CDF_INV - Fatal error!' )

  y = normal_01_cdf_inv ( cdf )

  value = mu + sigma * y

  return value