ParaMonte Fortran 2.0.0
Parallel Monte Carlo and Machine Learning Library
See the latest version documentation.
pm_mathErf::getErfInv Interface Reference

Generate and return the Inverse Error Function \(\ms{erf}^{-1}(x)\) for an input real value in range \((-1, +1)\) as defined in the details section of pm_mathErf. More...

Detailed Description

Generate and return the Inverse Error Function \(\ms{erf}^{-1}(x)\) for an input real value in range \((-1, +1)\) as defined in the details section of pm_mathErf.

The complementary inverse error function \(\ms{erfc}^{-1}(y), y\in(0, 2)\) can be readily computed as getErfInv(1 - y).
See the documentation of pm_mathErf for more information.

Parameters
[in]x: The input scalar (or array of the same shape as other array-like arguments) of the same type and kind as the output erfinv.
[in]abserr: The input positive scalar (or array of the same shape as other array-like arguments) of the same type and kind as the output erfinv.
If present, the output approximate value for the inverse error function is guaranteed to be at most abserr away from the true value \(\ms{erf}^{-1}(x)\).
This guarantee is currently tested and validated up to \(2\times10^{-26}\).
(optional, default = 100 * epsilon(x))
Returns
erfinv : The output scalar (or array of the same shape as input array-like arguments) of,
  1. type real of kind any supported by the processor (e.g., RK, RK32, RK64, or RK128),
containing the approximate value of the inverse error function at the specified input point x.


Possible calling interfaces

erfinv = getErfInv(x, abserr = abserr)
erfinv(..) = getErfInv(x(..), abserr = abserr(..))
Generate and return the Inverse Error Function for an input real value in range as defined in the d...
Definition: pm_mathErf.F90:191
This module contains classes and procedures for computing the mathematical Inverse Error Function.
Definition: pm_mathErf.F90:110
Warning
The condition 0 < abserr must hold for the corresponding input arguments.
The conditions -1 < x .and. x < 1 must hold for the corresponding input arguments.
These conditions are verified only if the library is built with the preprocessor macro CHECK_ENABLED=1.
The pure procedure(s) documented herein become impure when the ParaMonte library is compiled with preprocessor macro CHECK_ENABLED=1.
By default, these procedures are pure in release build and impure in debug and testing builds.
Remarks
The procedures under discussion are elemental.
See also
getErfInv
setErfInv
getNormCDF
setNormCDF
getNormQuan
setNormQuan
getNormRand
setNormRand
getNormLogPDF
setNormLogPDF


Example usage

1program example
2
3 use pm_kind, only: SK, IK, LK, RKH
4 use pm_mathErf, only: getErfInv
5 use pm_io, only: display_type
6
7 implicit none
8
9 real(RKH), allocatable :: erfinv(:)
10
11 type(display_type) :: disp
12 disp = display_type(file = "main.out.F90")
13
14 call disp%skip()
15 call disp%show("erfinv = [real(RKH) :: getErfInv(0.), getErfInv(0.d0)]")
16 erfinv = [real(RKH) :: getErfInv(0.), getErfInv(0.d0)]
17 call disp%show("erfinv")
18 call disp%show( erfinv )
19 call disp%show("erf(erfinv)")
20 call disp%show( erf(erfinv) )
21 call disp%skip()
22
23 call disp%skip()
24 call disp%show("erfinv = [getErfInv(-1. + epsilon(0.))]")
25 erfinv = [getErfInv(-1. + epsilon(0.))]
26 call disp%show("erfinv")
27 call disp%show( erfinv )
28 call disp%show("erf(erfinv)")
29 call disp%show( erf(erfinv) )
30 call disp%skip()
31
32 call disp%skip()
33 call disp%show("erfinv = [getErfInv(+1. - epsilon(0.))]")
34 erfinv = [getErfInv(+1. - epsilon(0.))]
35 call disp%show("erfinv")
36 call disp%show( erfinv )
37 call disp%show("erf(erfinv)")
38 call disp%show( erf(erfinv) )
39 call disp%skip()
40
41 call disp%skip()
42 call disp%show("erfinv = getErfInv([real :: -.99, -.75, -0.5, -0.1, 0., .1, .5, .75, .99])")
43 erfinv = getErfInv([real :: -.99, -.75, -0.5, -0.1, 0., .1, .5, .75, .99])
44 call disp%show("erfinv")
45 call disp%show( erfinv )
46 call disp%show("erf(erfinv)")
47 call disp%show( erf(erfinv) )
48 call disp%skip()
49
50 !%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
51 ! Output an example array of the regularized Incomplete Beta function for visualization.
52 !%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
53
54 block
55 use pm_kind, only: RKB, RKG => RKH, RKL => RKS, RKS, RKD
56 use pm_arraySpace, only: setLinSpace
57 integer(IK) , parameter :: NP = 2000
58 integer :: fileUnit, i
59 real(RKG) :: erfval(NP)
60 call setLinSpace(erfval, -1._RKG + epsilon(0._RKL), 1._RKG - epsilon(0._RKL))
61 open(newunit = fileUnit, file = "getErfInv.RK.txt")
62 do i = 1, NP
63 write(fileUnit, "(*(g0,:,' '))") real(erfval(i), RKD), getErfInv(real(erfval(i), RKD))
64 end do
65 close(fileUnit)
66 open(newunit = fileUnit, file = "getErfInv.RKS.abserr.txt")
67 do i = 1, NP
68 write(fileUnit, "(*(g0,:,' '))") real(erfval(i), RKS), real(erfval(i), RKS) - erf(real(getErfInv(real(erfval(i), RKS)), RKB))
69 end do
70 close(fileUnit)
71 open(newunit = fileUnit, file = "getErfInv.RKD.abserr.txt")
72 do i = 1, NP
73 write(fileUnit, "(*(g0,:,' '))") real(erfval(i), RKD), real(erfval(i), RKD) - erf(real(getErfInv(real(erfval(i), RKD)), RKB))
74 end do
75 close(fileUnit)
76 open(newunit = fileUnit, file = "getErfInv.RKH.abserr.txt")
77 do i = 1, NP
78 write(fileUnit, "(*(g0,:,' '))") real(erfval(i), RKH), real(erfval(i), RKH) - erf(real(getErfInv(real(erfval(i), RKH)), RKB))
79 end do
80 close(fileUnit)
81 end block
82
83end program example
Return the linSpace output argument with size(linSpace) elements of evenly-spaced values over the int...
This is a generic method of the derived type display_type with pass attribute.
Definition: pm_io.F90:11726
This is a generic method of the derived type display_type with pass attribute.
Definition: pm_io.F90:11508
This module contains procedures and generic interfaces for generating arrays with linear or logarithm...
This module contains classes and procedures for input/output (IO) or generic display operations on st...
Definition: pm_io.F90:252
type(display_type) disp
This is a scalar module variable an object of type display_type for general display.
Definition: pm_io.F90:11393
This module defines the relevant Fortran kind type-parameters frequently used in the ParaMonte librar...
Definition: pm_kind.F90:268
integer, parameter LK
The default logical kind in the ParaMonte library: kind(.true.) in Fortran, kind(....
Definition: pm_kind.F90:541
integer, parameter RKB
The scalar integer constant of intrinsic default kind, representing the Best-precision real kind supp...
Definition: pm_kind.F90:1371
integer, parameter RKL
The scalar integer constant of intrinsic default kind, representing the lowest-precision real kind ty...
Definition: pm_kind.F90:779
integer, parameter IK
The default integer kind in the ParaMonte library: int32 in Fortran, c_int32_t in C-Fortran Interoper...
Definition: pm_kind.F90:540
integer, parameter RKD
The double precision real kind in Fortran mode. On most platforms, this is an 64-bit real kind.
Definition: pm_kind.F90:568
integer, parameter SK
The default character kind in the ParaMonte library: kind("a") in Fortran, c_char in C-Fortran Intero...
Definition: pm_kind.F90:539
integer, parameter RKH
The scalar integer constant of intrinsic default kind, representing the highest-precision real kind t...
Definition: pm_kind.F90:858
integer, parameter RKS
The single-precision real kind in Fortran mode. On most platforms, this is an 32-bit real kind.
Definition: pm_kind.F90:567
Generate and return an object of type display_type.
Definition: pm_io.F90:10282

Example Unix compile command via Intel ifort compiler
1#!/usr/bin/env sh
2rm main.exe
3ifort -fpp -standard-semantics -O3 -Wl,-rpath,../../../lib -I../../../inc main.F90 ../../../lib/libparamonte* -o main.exe
4./main.exe

Example Windows Batch compile command via Intel ifort compiler
1del main.exe
2set PATH=..\..\..\lib;%PATH%
3ifort /fpp /standard-semantics /O3 /I:..\..\..\include main.F90 ..\..\..\lib\libparamonte*.lib /exe:main.exe
4main.exe

Example Unix / MinGW compile command via GNU gfortran compiler
1#!/usr/bin/env sh
2rm main.exe
3gfortran -cpp -ffree-line-length-none -O3 -Wl,-rpath,../../../lib -I../../../inc main.F90 ../../../lib/libparamonte* -o main.exe
4./main.exe

Example output
1
2erfinv = [real(RKH) :: getErfInv(0.), getErfInv(0.d0)]
3erfinv
4+0.00000000000000000000000000000000000, +0.00000000000000000000000000000000000
5erf(erfinv)
6+0.00000000000000000000000000000000000, +0.00000000000000000000000000000000000
7
8
9erfinv = [getErfInv(-1. + epsilon(0.))]
10erfinv
11-3.74392127990722656250000000000000000
12erf(erfinv)
13-0.999999880790818503613783522210309248
14
15
16erfinv = [getErfInv(+1. - epsilon(0.))]
17erfinv
18+3.74392127990722656250000000000000000
19erf(erfinv)
20+0.999999880790818503613783522210309344
21
22
23erfinv = getErfInv([real :: -.99, -.75, -0.5, -0.1, 0., .1, .5, .75, .99])
24erfinv
25-1.82138657569885253906250000000000000, -0.813419818878173828125000000000000000, -0.476936280727386474609375000000000000, -0.888559892773628234863281250000000000E-1, +0.00000000000000000000000000000000000, +0.888559892773628234863281250000000000E-1, +0.476936280727386474609375000000000000, +0.813419818878173828125000000000000000, +1.82138657569885253906250000000000000
26erf(erfinv)
27-0.990000008506047801752279420046811002, -0.749999983278341053252938360742249376, -0.500000004065233062995271124000763142, -0.999999986376798060532971720489789201E-1, +0.00000000000000000000000000000000000, +0.999999986376798060532971720489789201E-1, +0.500000004065233062995271124000763142, +0.749999983278341053252938360742249376, +0.990000008506047801752279420046810906
28
29

Postprocessing of the example output
1#!/usr/bin/env python
2
3import matplotlib.pyplot as plt
4import pandas as pd
5import numpy as np
6import glob
7import sys
8import os
9
10fontsize = 17
11
12parent = os.path.basename(os.path.dirname(__file__))
13pattern = parent + "*.txt"
14
15fileList = glob.glob(pattern)
16for file in fileList:
17
18 df = pd.read_csv(file, delimiter = " ")
19
20 fig = plt.figure(figsize = 1.25 * np.array([6.4, 4.8]), dpi = 200)
21 ax = plt.subplot()
22
23 for i in range(1,len(df.values[0,:]+1)):
24
25 plt.plot( df.values[:, 0]
26 , df.values[:,i]
27 , linewidth = 2
28 )
29
30 plt.xticks(fontsize = fontsize - 2)
31 plt.yticks(fontsize = fontsize - 2)
32 ax.set_xlabel("x", fontsize = fontsize)
33 if "abserr" in file:
34 nbit = file.split(".")[1][2:]
35 label = [r"x - erf(erfinv(x))"]
36 ax.set_ylabel("{}-bits Absolute Error".format(nbit), fontsize = fontsize)
37 else:
38 label = [r"erfinv(x)"]
39 ax.set_ylabel("Inverse Error Function", fontsize = fontsize)
40
41 plt.grid(visible = True, which = "both", axis = "both", color = "0.85", linestyle = "-")
42 ax.tick_params(axis = "y", which = "minor")
43 ax.tick_params(axis = "x", which = "minor")
44
45 ax.legend ( label
46 , fontsize = fontsize
47 #, loc = "center left"
48 #, bbox_to_anchor = (1, 0.5)
49 )
50
51 plt.savefig(file.replace(".txt",".png"))

Visualization of the example output
Test:
test_pm_mathErf


Final Remarks


If you believe this algorithm or its documentation can be improved, we appreciate your contribution and help to edit this page's documentation and source file on GitHub.
For details on the naming abbreviations, see this page.
For details on the naming conventions, see this page.
This software is distributed under the MIT license with additional terms outlined below.

  1. If you use any parts or concepts from this library to any extent, please acknowledge the usage by citing the relevant publications of the ParaMonte library.
  2. If you regenerate any parts/ideas from this library in a programming environment other than those currently supported by this ParaMonte library (i.e., other than C, C++, Fortran, MATLAB, Python, R), please also ask the end users to cite this original ParaMonte library.

This software is available to the public under a highly permissive license.
Help us justify its continued development and maintenance by acknowledging its benefit to society, distributing it, and contributing to it.

Author:
Amir Shahmoradi, Nov 10, 2009, 8:53 PM, Michigan

Definition at line 191 of file pm_mathErf.F90.


The documentation for this interface was generated from the following file: