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

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

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 call setErfInv(1 - y).
See the documentation of pm_mathErf for more information.

Parameters
[in]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.
[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}\).
A reasonable value could be epsilon(x)**0.66.
The current implementation of this generic interface contains three methods of computing the inverse error function corresponding to three levels of increasing accuracy,
  1. For any 1.e-7 < abserr, the output erfinv will have at most an absolute error 1.e-7 with respect to theoretical value.
  2. For any 2.e-24 < abserr, the output erfinv will have at most an absolute error 2.e-24 with respect to theoretical value.
  3. For any abserr < 2.e-24, the output erfinv is currently verified to have at most an absolute error 2.e-26 with respect to theoretical value.
    For a wide range of input x values, the absolute error is practically orders of magnitude smaller than this verified upper limit for the error.
    See the example illustrations below for more information.


Possible calling interfaces

call setErfInv(erfinv, x, abserr)
call setErfInv(erfinv, x(..), abserr(..))
Return the Inverse Error Function for an input real value in range as defined in the details sectio...
Definition: pm_mathErf.F90:340
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_mathSubAdd, only: operator(.subadd.)
5 use pm_mathErf, only: setErfInv
7 use pm_io, only: display_type
8
9 implicit none
10
11 real(RKH), allocatable :: erfinv(:), x(:)
12
13 type(display_type) :: disp
14 disp = display_type(file = "main.out.F90")
15
16 call disp%skip()
17 call disp%show("x = [real(RKH) :: 0., 0.5]")
18 x = [real(RKH) :: 0., 0.5]
19 call disp%show("x")
20 call disp%show( x )
21 call disp%show("call setResized(erfinv, size(x, 1, IK))")
22 call setResized(erfinv, size(x, 1, IK))
23 call disp%show("call setErfInv(erfinv, x, abserr = epsilon(x))")
24 call setErfInv(erfinv, x, abserr = epsilon(x))
25 call disp%show("erfinv")
26 call disp%show( erfinv )
27 call disp%show("erf(erfinv)")
28 call disp%show( erf(erfinv) )
29 call disp%skip()
30
31 call disp%skip()
32 call disp%show("x = .subadd. 1. - .subadd. epsilon(0.)")
33 x = .subadd. 1. - .subadd. epsilon(0.)
34 call disp%show("x")
35 call disp%show( x )
36 call disp%show("call setResized(erfinv, size(x, 1, IK))")
37 call setResized(erfinv, size(x, 1, IK))
38 call disp%show("call setErfInv(erfinv, x, abserr = epsilon(x))")
39 call setErfInv(erfinv, x, abserr = epsilon(x))
40 call disp%show("erfinv")
41 call disp%show( erfinv )
42 call disp%show("erf(erfinv)")
43 call disp%show( erf(erfinv) )
44 call disp%skip()
45
46 call disp%skip()
47 call disp%show("x = [-.99, -.75, -0.5, -0.1, 0., .1, .5, .75, .99]")
48 x = [-.99, -.75, -0.5, -0.1, 0., .1, .5, .75, .99]
49 call disp%show("x")
50 call disp%show( x )
51 call disp%show("call setResized(erfinv, size(x, 1, IK))")
52 call setResized(erfinv, size(x, 1, IK))
53 call disp%show("call setErfInv(erfinv, x, abserr = epsilon(x))")
54 call setErfInv(erfinv, x, abserr = epsilon(x))
55 call disp%show("erfinv")
56 call disp%show( erfinv )
57 call disp%show("erf(erfinv)")
58 call disp%show( erf(erfinv) )
59 call disp%skip()
60
61 !%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
62 ! Output an example array of the regularized Incomplete Beta function for visualization.
63 !%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
64
65 block
66 use pm_kind, only: RKB, RKG => RKH
67 use pm_arraySpace, only: setLinSpace
68 integer(IK) , parameter :: NP = 2000
69 integer :: fileUnit, i
70 real(RKG) :: erfval(NP), erfinv(NP)
71
72 call setLinSpace(erfval, -1._RKG + sqrt(epsilon(0._RKG)), 1._RKG - sqrt(epsilon(0._RKG)))
73
74 open(newunit = fileUnit, file = "setErfInv.RK.txt")
75 call setErfInv(erfinv, erfval, abserr = 100 * epsilon(0._RKG))
76 do i = 1, NP
77 write(fileUnit, "(*(g0,:,' '))") real(erfval(i), RKG), real(erfinv(i), RKG)
78 end do
79 close(fileUnit)
80
81 block
82 use pm_kind, only: RKG => RKS
83 open(newunit = fileUnit, file = "setErfInv.RKS.abserr.txt")
84 call setErfInv(erfinv, erfval, abserr = real(100 * epsilon(0._RKG), RKH))
85 do i = 1, NP
86 write(fileUnit, "(*(g0,:,' '))") real(erfval(i), RKG), real(erfval(i), RKG) - erf(real(erfinv(i), RKB))
87 end do
88 close(fileUnit)
89 end block
90
91 block
92 use pm_kind, only: RKG => RKD
93 open(newunit = fileUnit, file = "setErfInv.RKD.abserr.txt")
94 call setErfInv(erfinv, erfval, abserr = real(100 * epsilon(0._RKG), RKH))
95 do i = 1, NP
96 write(fileUnit, "(*(g0,:,' '))") real(erfval(i), RKG), real(erfval(i), RKG) - erf(real(erfinv(i), RKB))
97 end do
98 close(fileUnit)
99 end block
100
101 block
102 use pm_kind, only: RKG => RKH
103 open(newunit = fileUnit, file = "setErfInv.RKH.abserr.txt")
104 call setErfInv(erfinv, erfval, abserr = real(100 * epsilon(0._RKG), RKH))
105 do i = 1, NP
106 write(fileUnit, "(*(g0,:,' '))") real(erfval(i), RKG), real(erfval(i), RKG) - erf(real(erfinv(i), RKB))
107 end do
108 close(fileUnit)
109 end block
110
111 end block
112
113end program example
Allocate or resize (shrink or expand) an input allocatable scalar string or array of rank 1....
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 resizing allocatable arrays of various typ...
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 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
This module contains procedures and generic interfaces for evaluating the mathematical operator acti...
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
2x = [real(RKH) :: 0., 0.5]
3x
4+0.00000000000000000000000000000000000, +0.500000000000000000000000000000000000
5call setResized(erfinv, size(x, 1, IK))
6call setErfInv(erfinv, x, abserr = epsilon(x))
7erfinv
8-0.132513883613671435781879776977691272E-34, +0.476936276204469873381418342335513784
9erf(erfinv)
10-0.149525905620586266620169289835968551E-34, +0.499999999999999999999999989836624968
11
12
13x = .subadd. 1. - .subadd. epsilon(0.)
14x
15-0.999999880790710449218750000000000000, +0.999999880790710449218750000000000000
16call setResized(erfinv, size(x, 1, IK))
17call setErfInv(erfinv, x, abserr = epsilon(x))
18erfinv
19-3.74392116277679962488913660265320747, +3.74392116277679962488913660265320747
20erf(erfinv)
21-0.999999880790710449218750000097940664, +0.999999880790710449218750000097940664
22
23
24x = [-.99, -.75, -0.5, -0.1, 0., .1, .5, .75, .99]
25x
26-0.990000009536743164062500000000000000, -0.750000000000000000000000000000000000, -0.500000000000000000000000000000000000, -0.100000001490116119384765625000000000, +0.00000000000000000000000000000000000, +0.100000001490116119384765625000000000, +0.500000000000000000000000000000000000, +0.750000000000000000000000000000000000, +0.990000009536743164062500000000000000
27call setResized(erfinv, size(x, 1, IK))
28call setErfInv(erfinv, x, abserr = epsilon(x))
29erfinv
30-1.82138660090027777498853581706459074, -0.813419847597618541690289359089294846, -0.476936276204469873381418342335513784, -0.888559918253064817186753173353988263E-1, -0.132513883613671435781879776977691272E-34, +0.888559918253064817186753173353988263E-1, +0.476936276204469873381418342335513784, +0.813419847597618541690289359089294846, +1.82138660090027777498853581706459074
31erf(erfinv)
32-0.990000009536743164062500001249670844, -0.749999999999999999999999999531804119, -0.499999999999999999999999989836624968, -0.100000001490116119384765624995815857, -0.149525905620586266620169289835968551E-34, +0.100000001490116119384765624995815857, +0.499999999999999999999999989836624968, +0.749999999999999999999999999531804119, +0.990000009536743164062500001249670844
33
34

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 340 of file pm_mathErf.F90.


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