SlideShare a Scribd company logo
1 of 16
Download to read offline
Fast Inversion of Normal CDF
John D. Cook
What we’re computing
Basic assumptions
  Five or six significant figures is
  adequate for many applications
  Memory is fast and plentiful
  Low-level bit operations are faster than
  arithmetic
Basic Approach
  Tabulate values at sample points and
  use low-order approximations to fill in
  Take advantage of binary
  representation of floating point
  numbers to decide where to sample
  Change variables to avoid arithmetic
Big clever idea
  Extract sample points based on the
  exponent and mantissa
  The extraction is extremely fast
  It is biased to sample more frequently
  near zero, exactly where cPhi-1 needs
  more sampling
IEEE Floating Point
Representation (conceptual)

  x = +/- 2e m, 1 <= m < 2
  Bit 1: sign bit +/-
  Bits 2 through 9: exponent e
  Bits 10 through 32: mantissa
IEEE Floating Point
Representation (details)

  Bit 1: 0 for positive, 1 for negative
  Bits 2 through 9: exponent of 2 biased
  by 127
  (values 0 through 255 correspond to
  actual exponents -127 through 128)
  Bits 10 through 32: mantissa minus 1
  (leading bit always 1, so don’t store)
Starting Point for Marsaglia’s
algorithm
  Represent numbers by
  u = 2-k (2-1 + 2-6 j + 2-24 m)
  0 <= k < 32, 0 <= j < 32
  0 <= m < 224
  k = 126 – e, where ‘e’ is the exponent
  representation bits
  j = first five mantissa representation bits
  m = last 18 mantissa representation bits
Sample Points
  Tabulate cPhi-1 at points corresponding
  to m = 0, i.e. at 32 possible values of i
  and j, a total of 1024 points.
  Use quadratic Taylor approximation
  based at these points
  A fixed number samples per exponent
  samples more finely near zero, just
  where cPhi-1 needs more samples
Clever indexing
  Conceptually, we have a matrix A[i][j] of
  tabulated values
  This requires two calculations to find indices –
  one for i and one for j – and two operations
  to lookup values
  Combine into a single index
  n = 992-32k + j
  that can be extracted directly by one bit
  manipulation: bits 2 through 14 minus 3040
Polynomial evaluation
  Taylor approximation:
  t = h B(k,j)
  x = A(k,j) -0.5 t + 0.125 A(k,j)t2
  Rescale B’s by square root of 8:
  t = h B’
  x = A – c t – A t2 [ c = sqrt(2) ]
  Horner’s method:
  x = A – t(c – A t)
C++ Implementation
double NormalCCDFInverse(double x)
{
      float f1 = (float) x;
      unsigned int ui;
      memcpy(&ui, &f1, 4);
      int n = (ui >> 18) - 3008;
      ui &= 0xFFFC0000;
      float f2;
      memcpy(&f2, &ui, 4);
      double v = (f1-f2)*B[n];

     return A[n] - v*(sqrt2 - A[n]*v);
}
Fine Print
  This algorithm only valid for p <= 0.5
  For p > 0.5, use cPhi-1(p) = -cPhi-1(1-p)
  Phi-1(p) = cPhi-1(1-p)
  Algorithm not valid for p < 2-33
  The maximum error is 0.000004,
  which occurs near p = 0.25
Implementation
double PrivateNormalCCDFInverse(double x) …

double NormalCDFInverse(double x) {
    return (x > 0.5)
      ? PrivateNormalCCDFInverse(1.0-x)
      : PrivateNormalCCDFInverse(x);
}

double NormalCCDFInverse(double x) {
    return (x > 0.5)
      ? -PrivateNormalCCDFInverse(1.0-x)
      : PrivateNormalCCDFInverse(x);
}
References
  Rapid evaluation of the inverse of the
  normal distribution function
  by Marsaglia, Zaman, and Marsaglia
  Statistics and Probability Letters
  19 (1994) 259 – 266
Notes
  This talk presented June 6, 2001
  http://www.JohnDCook.com

More Related Content

What's hot

Lab 4 Three-Bit Binary Adder
Lab 4 Three-Bit Binary AdderLab 4 Three-Bit Binary Adder
Lab 4 Three-Bit Binary AdderKatrina Little
 
Jmet Ppt3 Higher Maths
Jmet   Ppt3   Higher MathsJmet   Ppt3   Higher Maths
Jmet Ppt3 Higher Mathskapil1312
 
Polygons - Computer Graphics - Notes
Polygons - Computer Graphics - NotesPolygons - Computer Graphics - Notes
Polygons - Computer Graphics - NotesOmprakash Chauhan
 
BOOTH ALGO, DIVISION(RESTORING _ NON RESTORING) etc etc
BOOTH ALGO, DIVISION(RESTORING _ NON RESTORING) etc etcBOOTH ALGO, DIVISION(RESTORING _ NON RESTORING) etc etc
BOOTH ALGO, DIVISION(RESTORING _ NON RESTORING) etc etcAbhishek Rajpoot
 
Design half ,full Adder and Subtractor
Design half ,full Adder and SubtractorDesign half ,full Adder and Subtractor
Design half ,full Adder and SubtractorJaimin@prt.ltd.
 
Calculus Sections 4.1 and 4.3
Calculus Sections 4.1 and 4.3Calculus Sections 4.1 and 4.3
Calculus Sections 4.1 and 4.3calculusgroup3
 
Presentation(intermediate code generation)
Presentation(intermediate code generation)Presentation(intermediate code generation)
Presentation(intermediate code generation)Sourov Kumar Ron
 
Matrices, Arrays and Vectors in MATLAB
Matrices, Arrays and Vectors in MATLABMatrices, Arrays and Vectors in MATLAB
Matrices, Arrays and Vectors in MATLABAbu Raihan Ibna Ali
 
Three Address code
Three Address code Three Address code
Three Address code Pooja Dixit
 
A lab report on modeling and simulation with python code
A lab report on modeling and simulation with python codeA lab report on modeling and simulation with python code
A lab report on modeling and simulation with python codeAlamgir Hossain
 
Multiplication algorithm, hardware and flowchart
Multiplication algorithm, hardware and flowchartMultiplication algorithm, hardware and flowchart
Multiplication algorithm, hardware and flowchartTanjarul Islam Mishu
 
Newton cotes integration method
Newton cotes integration  methodNewton cotes integration  method
Newton cotes integration methodshashikant pabari
 
AP Calculus Slides February 14, 2008
AP Calculus Slides February 14, 2008AP Calculus Slides February 14, 2008
AP Calculus Slides February 14, 2008Darren Kuropatwa
 
computer operating system:Greedy algorithm
computer operating system:Greedy algorithmcomputer operating system:Greedy algorithm
computer operating system:Greedy algorithmRitaThakkar1
 
Complex Number From Jayant for TV
Complex Number From Jayant for TVComplex Number From Jayant for TV
Complex Number From Jayant for TVJayant Singh
 

What's hot (19)

C++ lab -4
C++ lab -4C++ lab -4
C++ lab -4
 
Polygon filling
Polygon fillingPolygon filling
Polygon filling
 
C++:Lab 2
 C++:Lab 2 C++:Lab 2
C++:Lab 2
 
Subtractor (1)
Subtractor (1)Subtractor (1)
Subtractor (1)
 
Lab 4 Three-Bit Binary Adder
Lab 4 Three-Bit Binary AdderLab 4 Three-Bit Binary Adder
Lab 4 Three-Bit Binary Adder
 
Jmet Ppt3 Higher Maths
Jmet   Ppt3   Higher MathsJmet   Ppt3   Higher Maths
Jmet Ppt3 Higher Maths
 
Polygons - Computer Graphics - Notes
Polygons - Computer Graphics - NotesPolygons - Computer Graphics - Notes
Polygons - Computer Graphics - Notes
 
BOOTH ALGO, DIVISION(RESTORING _ NON RESTORING) etc etc
BOOTH ALGO, DIVISION(RESTORING _ NON RESTORING) etc etcBOOTH ALGO, DIVISION(RESTORING _ NON RESTORING) etc etc
BOOTH ALGO, DIVISION(RESTORING _ NON RESTORING) etc etc
 
Design half ,full Adder and Subtractor
Design half ,full Adder and SubtractorDesign half ,full Adder and Subtractor
Design half ,full Adder and Subtractor
 
Calculus Sections 4.1 and 4.3
Calculus Sections 4.1 and 4.3Calculus Sections 4.1 and 4.3
Calculus Sections 4.1 and 4.3
 
Presentation(intermediate code generation)
Presentation(intermediate code generation)Presentation(intermediate code generation)
Presentation(intermediate code generation)
 
Matrices, Arrays and Vectors in MATLAB
Matrices, Arrays and Vectors in MATLABMatrices, Arrays and Vectors in MATLAB
Matrices, Arrays and Vectors in MATLAB
 
Three Address code
Three Address code Three Address code
Three Address code
 
A lab report on modeling and simulation with python code
A lab report on modeling and simulation with python codeA lab report on modeling and simulation with python code
A lab report on modeling and simulation with python code
 
Multiplication algorithm, hardware and flowchart
Multiplication algorithm, hardware and flowchartMultiplication algorithm, hardware and flowchart
Multiplication algorithm, hardware and flowchart
 
Newton cotes integration method
Newton cotes integration  methodNewton cotes integration  method
Newton cotes integration method
 
AP Calculus Slides February 14, 2008
AP Calculus Slides February 14, 2008AP Calculus Slides February 14, 2008
AP Calculus Slides February 14, 2008
 
computer operating system:Greedy algorithm
computer operating system:Greedy algorithmcomputer operating system:Greedy algorithm
computer operating system:Greedy algorithm
 
Complex Number From Jayant for TV
Complex Number From Jayant for TVComplex Number From Jayant for TV
Complex Number From Jayant for TV
 

Similar to Fast coputation of Phi(x) inverse

Number theory
Number theory Number theory
Number theory tes31
 
Logic Circuits Design - "Chapter 1: Digital Systems and Information"
Logic Circuits Design - "Chapter 1: Digital Systems and Information"Logic Circuits Design - "Chapter 1: Digital Systems and Information"
Logic Circuits Design - "Chapter 1: Digital Systems and Information"Ra'Fat Al-Msie'deen
 
01 - DAA - PPT.pptx
01 - DAA - PPT.pptx01 - DAA - PPT.pptx
01 - DAA - PPT.pptxKokilaK25
 
Efficient Volume and Edge-Skeleton Computation for Polytopes Given by Oracles
Efficient Volume and Edge-Skeleton Computation for Polytopes Given by OraclesEfficient Volume and Edge-Skeleton Computation for Polytopes Given by Oracles
Efficient Volume and Edge-Skeleton Computation for Polytopes Given by OraclesVissarion Fisikopoulos
 
tutorial5.ppt
tutorial5.ppttutorial5.ppt
tutorial5.pptjvjfvvoa
 
Oracle-based algorithms for high-dimensional polytopes.
Oracle-based algorithms for high-dimensional polytopes.Oracle-based algorithms for high-dimensional polytopes.
Oracle-based algorithms for high-dimensional polytopes.Vissarion Fisikopoulos
 
dynamic programming complete by Mumtaz Ali (03154103173)
dynamic programming complete by Mumtaz Ali (03154103173)dynamic programming complete by Mumtaz Ali (03154103173)
dynamic programming complete by Mumtaz Ali (03154103173)Mumtaz Ali
 
Episode 50 : Simulation Problem Solution Approaches Convergence Techniques S...
Episode 50 :  Simulation Problem Solution Approaches Convergence Techniques S...Episode 50 :  Simulation Problem Solution Approaches Convergence Techniques S...
Episode 50 : Simulation Problem Solution Approaches Convergence Techniques S...SAJJAD KHUDHUR ABBAS
 
01 EC 7311-Module IV.pptx
01 EC 7311-Module IV.pptx01 EC 7311-Module IV.pptx
01 EC 7311-Module IV.pptxVSUDHEER4
 
SKuehn_MachineLearningAndOptimization_2015
SKuehn_MachineLearningAndOptimization_2015SKuehn_MachineLearningAndOptimization_2015
SKuehn_MachineLearningAndOptimization_2015Stefan Kühn
 
Binu Siva Singh Final.pptx
Binu Siva Singh Final.pptxBinu Siva Singh Final.pptx
Binu Siva Singh Final.pptxdivisatish
 
Design and Analysis of Algorithm Brute Force 1.ppt
Design and Analysis of Algorithm Brute Force 1.pptDesign and Analysis of Algorithm Brute Force 1.ppt
Design and Analysis of Algorithm Brute Force 1.pptmoiza354
 
International Journal of Engineering Research and Development
International Journal of Engineering Research and DevelopmentInternational Journal of Engineering Research and Development
International Journal of Engineering Research and DevelopmentIJERD Editor
 
openMP loop parallelization
openMP loop parallelizationopenMP loop parallelization
openMP loop parallelizationAlbert DeFusco
 

Similar to Fast coputation of Phi(x) inverse (20)

Number theory
Number theory Number theory
Number theory
 
Logic Circuits Design - "Chapter 1: Digital Systems and Information"
Logic Circuits Design - "Chapter 1: Digital Systems and Information"Logic Circuits Design - "Chapter 1: Digital Systems and Information"
Logic Circuits Design - "Chapter 1: Digital Systems and Information"
 
01 - DAA - PPT.pptx
01 - DAA - PPT.pptx01 - DAA - PPT.pptx
01 - DAA - PPT.pptx
 
Computer graphics 2
Computer graphics 2Computer graphics 2
Computer graphics 2
 
Efficient Volume and Edge-Skeleton Computation for Polytopes Given by Oracles
Efficient Volume and Edge-Skeleton Computation for Polytopes Given by OraclesEfficient Volume and Edge-Skeleton Computation for Polytopes Given by Oracles
Efficient Volume and Edge-Skeleton Computation for Polytopes Given by Oracles
 
Optimization tutorial
Optimization tutorialOptimization tutorial
Optimization tutorial
 
tutorial5.ppt
tutorial5.ppttutorial5.ppt
tutorial5.ppt
 
Oracle-based algorithms for high-dimensional polytopes.
Oracle-based algorithms for high-dimensional polytopes.Oracle-based algorithms for high-dimensional polytopes.
Oracle-based algorithms for high-dimensional polytopes.
 
dynamic programming complete by Mumtaz Ali (03154103173)
dynamic programming complete by Mumtaz Ali (03154103173)dynamic programming complete by Mumtaz Ali (03154103173)
dynamic programming complete by Mumtaz Ali (03154103173)
 
C++ Language
C++ LanguageC++ Language
C++ Language
 
algo_vc_lecture8.ppt
algo_vc_lecture8.pptalgo_vc_lecture8.ppt
algo_vc_lecture8.ppt
 
Episode 50 : Simulation Problem Solution Approaches Convergence Techniques S...
Episode 50 :  Simulation Problem Solution Approaches Convergence Techniques S...Episode 50 :  Simulation Problem Solution Approaches Convergence Techniques S...
Episode 50 : Simulation Problem Solution Approaches Convergence Techniques S...
 
01 EC 7311-Module IV.pptx
01 EC 7311-Module IV.pptx01 EC 7311-Module IV.pptx
01 EC 7311-Module IV.pptx
 
SKuehn_MachineLearningAndOptimization_2015
SKuehn_MachineLearningAndOptimization_2015SKuehn_MachineLearningAndOptimization_2015
SKuehn_MachineLearningAndOptimization_2015
 
Regression
RegressionRegression
Regression
 
Binu Siva Singh Final.pptx
Binu Siva Singh Final.pptxBinu Siva Singh Final.pptx
Binu Siva Singh Final.pptx
 
Design and Analysis of Algorithm Brute Force 1.ppt
Design and Analysis of Algorithm Brute Force 1.pptDesign and Analysis of Algorithm Brute Force 1.ppt
Design and Analysis of Algorithm Brute Force 1.ppt
 
3 analysis.gtm
3 analysis.gtm3 analysis.gtm
3 analysis.gtm
 
International Journal of Engineering Research and Development
International Journal of Engineering Research and DevelopmentInternational Journal of Engineering Research and Development
International Journal of Engineering Research and Development
 
openMP loop parallelization
openMP loop parallelizationopenMP loop parallelization
openMP loop parallelization
 

More from John Cook

Bayesian adaptive clinical trials: Promises and pitfalls
Bayesian adaptive clinical trials: Promises and pitfallsBayesian adaptive clinical trials: Promises and pitfalls
Bayesian adaptive clinical trials: Promises and pitfallsJohn Cook
 
Erasure Coding Costs and Benefits
Erasure Coding Costs and BenefitsErasure Coding Costs and Benefits
Erasure Coding Costs and BenefitsJohn Cook
 
Combining Intuition and Data
Combining Intuition and DataCombining Intuition and Data
Combining Intuition and DataJohn Cook
 
Monte Carlo and quasi-Monte Carlo integration
Monte Carlo and quasi-Monte Carlo integrationMonte Carlo and quasi-Monte Carlo integration
Monte Carlo and quasi-Monte Carlo integrationJohn Cook
 
Bayesian hypothesis testing
Bayesian hypothesis testingBayesian hypothesis testing
Bayesian hypothesis testingJohn Cook
 
Bayesian clinical trials: software and logistics
Bayesian clinical trials: software and logisticsBayesian clinical trials: software and logistics
Bayesian clinical trials: software and logisticsJohn Cook
 

More from John Cook (6)

Bayesian adaptive clinical trials: Promises and pitfalls
Bayesian adaptive clinical trials: Promises and pitfallsBayesian adaptive clinical trials: Promises and pitfalls
Bayesian adaptive clinical trials: Promises and pitfalls
 
Erasure Coding Costs and Benefits
Erasure Coding Costs and BenefitsErasure Coding Costs and Benefits
Erasure Coding Costs and Benefits
 
Combining Intuition and Data
Combining Intuition and DataCombining Intuition and Data
Combining Intuition and Data
 
Monte Carlo and quasi-Monte Carlo integration
Monte Carlo and quasi-Monte Carlo integrationMonte Carlo and quasi-Monte Carlo integration
Monte Carlo and quasi-Monte Carlo integration
 
Bayesian hypothesis testing
Bayesian hypothesis testingBayesian hypothesis testing
Bayesian hypothesis testing
 
Bayesian clinical trials: software and logistics
Bayesian clinical trials: software and logisticsBayesian clinical trials: software and logistics
Bayesian clinical trials: software and logistics
 

Recently uploaded

04-2024-HHUG-Sales-and-Marketing-Alignment.pptx
04-2024-HHUG-Sales-and-Marketing-Alignment.pptx04-2024-HHUG-Sales-and-Marketing-Alignment.pptx
04-2024-HHUG-Sales-and-Marketing-Alignment.pptxHampshireHUG
 
How to Troubleshoot Apps for the Modern Connected Worker
How to Troubleshoot Apps for the Modern Connected WorkerHow to Troubleshoot Apps for the Modern Connected Worker
How to Troubleshoot Apps for the Modern Connected WorkerThousandEyes
 
Salesforce Community Group Quito, Salesforce 101
Salesforce Community Group Quito, Salesforce 101Salesforce Community Group Quito, Salesforce 101
Salesforce Community Group Quito, Salesforce 101Paola De la Torre
 
08448380779 Call Girls In Greater Kailash - I Women Seeking Men
08448380779 Call Girls In Greater Kailash - I Women Seeking Men08448380779 Call Girls In Greater Kailash - I Women Seeking Men
08448380779 Call Girls In Greater Kailash - I Women Seeking MenDelhi Call girls
 
2024: Domino Containers - The Next Step. News from the Domino Container commu...
2024: Domino Containers - The Next Step. News from the Domino Container commu...2024: Domino Containers - The Next Step. News from the Domino Container commu...
2024: Domino Containers - The Next Step. News from the Domino Container commu...Martijn de Jong
 
The Codex of Business Writing Software for Real-World Solutions 2.pptx
The Codex of Business Writing Software for Real-World Solutions 2.pptxThe Codex of Business Writing Software for Real-World Solutions 2.pptx
The Codex of Business Writing Software for Real-World Solutions 2.pptxMalak Abu Hammad
 
WhatsApp 9892124323 ✓Call Girls In Kalyan ( Mumbai ) secure service
WhatsApp 9892124323 ✓Call Girls In Kalyan ( Mumbai ) secure serviceWhatsApp 9892124323 ✓Call Girls In Kalyan ( Mumbai ) secure service
WhatsApp 9892124323 ✓Call Girls In Kalyan ( Mumbai ) secure servicePooja Nehwal
 
Driving Behavioral Change for Information Management through Data-Driven Gree...
Driving Behavioral Change for Information Management through Data-Driven Gree...Driving Behavioral Change for Information Management through Data-Driven Gree...
Driving Behavioral Change for Information Management through Data-Driven Gree...Enterprise Knowledge
 
Injustice - Developers Among Us (SciFiDevCon 2024)
Injustice - Developers Among Us (SciFiDevCon 2024)Injustice - Developers Among Us (SciFiDevCon 2024)
Injustice - Developers Among Us (SciFiDevCon 2024)Allon Mureinik
 
The 7 Things I Know About Cyber Security After 25 Years | April 2024
The 7 Things I Know About Cyber Security After 25 Years | April 2024The 7 Things I Know About Cyber Security After 25 Years | April 2024
The 7 Things I Know About Cyber Security After 25 Years | April 2024Rafal Los
 
08448380779 Call Girls In Diplomatic Enclave Women Seeking Men
08448380779 Call Girls In Diplomatic Enclave Women Seeking Men08448380779 Call Girls In Diplomatic Enclave Women Seeking Men
08448380779 Call Girls In Diplomatic Enclave Women Seeking MenDelhi Call girls
 
Neo4j - How KGs are shaping the future of Generative AI at AWS Summit London ...
Neo4j - How KGs are shaping the future of Generative AI at AWS Summit London ...Neo4j - How KGs are shaping the future of Generative AI at AWS Summit London ...
Neo4j - How KGs are shaping the future of Generative AI at AWS Summit London ...Neo4j
 
Unblocking The Main Thread Solving ANRs and Frozen Frames
Unblocking The Main Thread Solving ANRs and Frozen FramesUnblocking The Main Thread Solving ANRs and Frozen Frames
Unblocking The Main Thread Solving ANRs and Frozen FramesSinan KOZAK
 
Partners Life - Insurer Innovation Award 2024
Partners Life - Insurer Innovation Award 2024Partners Life - Insurer Innovation Award 2024
Partners Life - Insurer Innovation Award 2024The Digital Insurer
 
Handwritten Text Recognition for manuscripts and early printed texts
Handwritten Text Recognition for manuscripts and early printed textsHandwritten Text Recognition for manuscripts and early printed texts
Handwritten Text Recognition for manuscripts and early printed textsMaria Levchenko
 
Workshop - Best of Both Worlds_ Combine KG and Vector search for enhanced R...
Workshop - Best of Both Worlds_ Combine  KG and Vector search for  enhanced R...Workshop - Best of Both Worlds_ Combine  KG and Vector search for  enhanced R...
Workshop - Best of Both Worlds_ Combine KG and Vector search for enhanced R...Neo4j
 
Boost PC performance: How more available memory can improve productivity
Boost PC performance: How more available memory can improve productivityBoost PC performance: How more available memory can improve productivity
Boost PC performance: How more available memory can improve productivityPrincipled Technologies
 
TrustArc Webinar - Stay Ahead of US State Data Privacy Law Developments
TrustArc Webinar - Stay Ahead of US State Data Privacy Law DevelopmentsTrustArc Webinar - Stay Ahead of US State Data Privacy Law Developments
TrustArc Webinar - Stay Ahead of US State Data Privacy Law DevelopmentsTrustArc
 
08448380779 Call Girls In Civil Lines Women Seeking Men
08448380779 Call Girls In Civil Lines Women Seeking Men08448380779 Call Girls In Civil Lines Women Seeking Men
08448380779 Call Girls In Civil Lines Women Seeking MenDelhi Call girls
 
Scaling API-first – The story of a global engineering organization
Scaling API-first – The story of a global engineering organizationScaling API-first – The story of a global engineering organization
Scaling API-first – The story of a global engineering organizationRadu Cotescu
 

Recently uploaded (20)

04-2024-HHUG-Sales-and-Marketing-Alignment.pptx
04-2024-HHUG-Sales-and-Marketing-Alignment.pptx04-2024-HHUG-Sales-and-Marketing-Alignment.pptx
04-2024-HHUG-Sales-and-Marketing-Alignment.pptx
 
How to Troubleshoot Apps for the Modern Connected Worker
How to Troubleshoot Apps for the Modern Connected WorkerHow to Troubleshoot Apps for the Modern Connected Worker
How to Troubleshoot Apps for the Modern Connected Worker
 
Salesforce Community Group Quito, Salesforce 101
Salesforce Community Group Quito, Salesforce 101Salesforce Community Group Quito, Salesforce 101
Salesforce Community Group Quito, Salesforce 101
 
08448380779 Call Girls In Greater Kailash - I Women Seeking Men
08448380779 Call Girls In Greater Kailash - I Women Seeking Men08448380779 Call Girls In Greater Kailash - I Women Seeking Men
08448380779 Call Girls In Greater Kailash - I Women Seeking Men
 
2024: Domino Containers - The Next Step. News from the Domino Container commu...
2024: Domino Containers - The Next Step. News from the Domino Container commu...2024: Domino Containers - The Next Step. News from the Domino Container commu...
2024: Domino Containers - The Next Step. News from the Domino Container commu...
 
The Codex of Business Writing Software for Real-World Solutions 2.pptx
The Codex of Business Writing Software for Real-World Solutions 2.pptxThe Codex of Business Writing Software for Real-World Solutions 2.pptx
The Codex of Business Writing Software for Real-World Solutions 2.pptx
 
WhatsApp 9892124323 ✓Call Girls In Kalyan ( Mumbai ) secure service
WhatsApp 9892124323 ✓Call Girls In Kalyan ( Mumbai ) secure serviceWhatsApp 9892124323 ✓Call Girls In Kalyan ( Mumbai ) secure service
WhatsApp 9892124323 ✓Call Girls In Kalyan ( Mumbai ) secure service
 
Driving Behavioral Change for Information Management through Data-Driven Gree...
Driving Behavioral Change for Information Management through Data-Driven Gree...Driving Behavioral Change for Information Management through Data-Driven Gree...
Driving Behavioral Change for Information Management through Data-Driven Gree...
 
Injustice - Developers Among Us (SciFiDevCon 2024)
Injustice - Developers Among Us (SciFiDevCon 2024)Injustice - Developers Among Us (SciFiDevCon 2024)
Injustice - Developers Among Us (SciFiDevCon 2024)
 
The 7 Things I Know About Cyber Security After 25 Years | April 2024
The 7 Things I Know About Cyber Security After 25 Years | April 2024The 7 Things I Know About Cyber Security After 25 Years | April 2024
The 7 Things I Know About Cyber Security After 25 Years | April 2024
 
08448380779 Call Girls In Diplomatic Enclave Women Seeking Men
08448380779 Call Girls In Diplomatic Enclave Women Seeking Men08448380779 Call Girls In Diplomatic Enclave Women Seeking Men
08448380779 Call Girls In Diplomatic Enclave Women Seeking Men
 
Neo4j - How KGs are shaping the future of Generative AI at AWS Summit London ...
Neo4j - How KGs are shaping the future of Generative AI at AWS Summit London ...Neo4j - How KGs are shaping the future of Generative AI at AWS Summit London ...
Neo4j - How KGs are shaping the future of Generative AI at AWS Summit London ...
 
Unblocking The Main Thread Solving ANRs and Frozen Frames
Unblocking The Main Thread Solving ANRs and Frozen FramesUnblocking The Main Thread Solving ANRs and Frozen Frames
Unblocking The Main Thread Solving ANRs and Frozen Frames
 
Partners Life - Insurer Innovation Award 2024
Partners Life - Insurer Innovation Award 2024Partners Life - Insurer Innovation Award 2024
Partners Life - Insurer Innovation Award 2024
 
Handwritten Text Recognition for manuscripts and early printed texts
Handwritten Text Recognition for manuscripts and early printed textsHandwritten Text Recognition for manuscripts and early printed texts
Handwritten Text Recognition for manuscripts and early printed texts
 
Workshop - Best of Both Worlds_ Combine KG and Vector search for enhanced R...
Workshop - Best of Both Worlds_ Combine  KG and Vector search for  enhanced R...Workshop - Best of Both Worlds_ Combine  KG and Vector search for  enhanced R...
Workshop - Best of Both Worlds_ Combine KG and Vector search for enhanced R...
 
Boost PC performance: How more available memory can improve productivity
Boost PC performance: How more available memory can improve productivityBoost PC performance: How more available memory can improve productivity
Boost PC performance: How more available memory can improve productivity
 
TrustArc Webinar - Stay Ahead of US State Data Privacy Law Developments
TrustArc Webinar - Stay Ahead of US State Data Privacy Law DevelopmentsTrustArc Webinar - Stay Ahead of US State Data Privacy Law Developments
TrustArc Webinar - Stay Ahead of US State Data Privacy Law Developments
 
08448380779 Call Girls In Civil Lines Women Seeking Men
08448380779 Call Girls In Civil Lines Women Seeking Men08448380779 Call Girls In Civil Lines Women Seeking Men
08448380779 Call Girls In Civil Lines Women Seeking Men
 
Scaling API-first – The story of a global engineering organization
Scaling API-first – The story of a global engineering organizationScaling API-first – The story of a global engineering organization
Scaling API-first – The story of a global engineering organization
 

Fast coputation of Phi(x) inverse

  • 1. Fast Inversion of Normal CDF John D. Cook
  • 3. Basic assumptions Five or six significant figures is adequate for many applications Memory is fast and plentiful Low-level bit operations are faster than arithmetic
  • 4. Basic Approach Tabulate values at sample points and use low-order approximations to fill in Take advantage of binary representation of floating point numbers to decide where to sample Change variables to avoid arithmetic
  • 5. Big clever idea Extract sample points based on the exponent and mantissa The extraction is extremely fast It is biased to sample more frequently near zero, exactly where cPhi-1 needs more sampling
  • 6. IEEE Floating Point Representation (conceptual) x = +/- 2e m, 1 <= m < 2 Bit 1: sign bit +/- Bits 2 through 9: exponent e Bits 10 through 32: mantissa
  • 7. IEEE Floating Point Representation (details) Bit 1: 0 for positive, 1 for negative Bits 2 through 9: exponent of 2 biased by 127 (values 0 through 255 correspond to actual exponents -127 through 128) Bits 10 through 32: mantissa minus 1 (leading bit always 1, so don’t store)
  • 8. Starting Point for Marsaglia’s algorithm Represent numbers by u = 2-k (2-1 + 2-6 j + 2-24 m) 0 <= k < 32, 0 <= j < 32 0 <= m < 224 k = 126 – e, where ‘e’ is the exponent representation bits j = first five mantissa representation bits m = last 18 mantissa representation bits
  • 9. Sample Points Tabulate cPhi-1 at points corresponding to m = 0, i.e. at 32 possible values of i and j, a total of 1024 points. Use quadratic Taylor approximation based at these points A fixed number samples per exponent samples more finely near zero, just where cPhi-1 needs more samples
  • 10. Clever indexing Conceptually, we have a matrix A[i][j] of tabulated values This requires two calculations to find indices – one for i and one for j – and two operations to lookup values Combine into a single index n = 992-32k + j that can be extracted directly by one bit manipulation: bits 2 through 14 minus 3040
  • 11. Polynomial evaluation Taylor approximation: t = h B(k,j) x = A(k,j) -0.5 t + 0.125 A(k,j)t2 Rescale B’s by square root of 8: t = h B’ x = A – c t – A t2 [ c = sqrt(2) ] Horner’s method: x = A – t(c – A t)
  • 12. C++ Implementation double NormalCCDFInverse(double x) { float f1 = (float) x; unsigned int ui; memcpy(&ui, &f1, 4); int n = (ui >> 18) - 3008; ui &= 0xFFFC0000; float f2; memcpy(&f2, &ui, 4); double v = (f1-f2)*B[n]; return A[n] - v*(sqrt2 - A[n]*v); }
  • 13. Fine Print This algorithm only valid for p <= 0.5 For p > 0.5, use cPhi-1(p) = -cPhi-1(1-p) Phi-1(p) = cPhi-1(1-p) Algorithm not valid for p < 2-33 The maximum error is 0.000004, which occurs near p = 0.25
  • 14. Implementation double PrivateNormalCCDFInverse(double x) … double NormalCDFInverse(double x) { return (x > 0.5) ? PrivateNormalCCDFInverse(1.0-x) : PrivateNormalCCDFInverse(x); } double NormalCCDFInverse(double x) { return (x > 0.5) ? -PrivateNormalCCDFInverse(1.0-x) : PrivateNormalCCDFInverse(x); }
  • 15. References Rapid evaluation of the inverse of the normal distribution function by Marsaglia, Zaman, and Marsaglia Statistics and Probability Letters 19 (1994) 259 – 266
  • 16. Notes This talk presented June 6, 2001 http://www.JohnDCook.com