Tuesday, 17 September 2013

Numerical Estimate of the Inverse Error Function

The function that numerically approximates the inverse error (erf) function $[\large \frac{2}{\sqrt{\pi}}\int_0^xe^{-t^2}dt]^{-1}$ is captured in the C function below - it's a fragment of the source code of my (now free) iOS App SciStatCalc. Note the one iteration of Halley's method to refine the result.

Feel free to use it, if you wish to do so.

double inverf(double x)
{   
    double w,p;
    
    w = -log((1.00-x)*(1.00+x));
    
    if ( w < 5.000000 ) {
        w = w - 2.500000;
        p= 2.81022636e-08;
        p= 3.43273939e-07 + p*w;
        p= -3.5233877e-06 + p*w;
        p = -4.39150654e-06 + p*w;
        p = 0.00021858087 + p*w;
        p = -0.00125372503 + p*w;
        p = -0.00417768164 + p*w;
        p = 0.246640727 + p*w;
        p = 1.50140941 + p*w;
    } else
    {
        w = sqrtf(w) - 3.000000;
        p =  -0.000200214257;
        p = 0.000100950558 + p*w;
        p = 0.00134934322 + p*w;
        p = -0.00367342844 + p*w;
        p = 0.00573950773 + p*w;
        p = -0.0076224613 + p*w;
        p = 0.00943887047 + p*w;
        p = 1.00167406 + p*w;
        p = 2.83297682 + p*w;
    }
    
    double res_ra = p*x; // assign to rational estimate variable
    
    // Halley's method to refine estimate of inverse erf
    double res_hm = 0;
    double fx = (erf(res_ra) - x);
    double df = (2.0/sqrt(M_PI))*exp(-(res_ra * res_ra));
    double d2f = -2 * res_ra * df;
    
    res_hm = res_ra - (2*fx*df)/((2*df*df) - (fx*d2f));
    return res_hm;
}

The above function can be used to estimate the inverse cumulative distribution function (quantile) of the Gaussian distribution (mu is the mean, and sig the standard deviation of the distribution), as below:-

double gauss_icdf(double p, double mu, double sig)
{
    double res;
    res = (inverf((2*p) - 1) *sig*sqrt(2.0)) + mu;
    return res;
}


18 comments:

  1. Hello Everyone out there,I am here to give my testimony about a Herbalist doctor who helped me . I was infected with HERPES SIMPLEX VIRUS in 2011, i went to many hospitals for cure but there was no solution, so I was thinking how can I get a solution out so that my body can be okay. One day I was in the river side thinking where I can go to get solution. so a lady walked to me telling me why am I so sad and i open up all to her telling her my problem, she told me that she can help me out, she introduce me to a doctor who uses herbal medication to cure HERPES SIMPLEX VIRUS and gave me his email, so i mail him. He told me all the things I need to do and also give me instructions to take, which I followed properly. Before I knew what is happening after two weeks the HERPES SIMPLEX VIRUS that was in my body got vanished . so if you are also heart broken and also need a help, you can also email him at {oliha.miraclemedicine@gmail.com}
    or whatsapp him number: +2349038382931. or website is https://olihamiraclemedicine.webs.com/
    Contact him today and you will have a testimony...Good luck!

    Dr. OLIHA Also Cures:
    1. HIV/AIDS
    2. HERPES 1/2
    3. CANCER
    4. ALS (Lou Gehrig’s disease)
    5. Hepatitis B
    6. chronic pancreatic
    7. Emphysema
    8. COPD (Chronic Obstructive Pulmonary Disease

    ReplyDelete
    Replies
    1. INDEED DR SAYO HERBAL HEALER HAS THE CURE FOR FOLLOWING HERPES VIRUS, HIV/AIDS, CANCER ALL TYPES, DIABETES, HEPATITIS A/B, PAD, ETC......FOR MORE INFORMATION VISIT HIS WEBSITE: http://sayoherbalhome.com/ I was once a victim of the herpes virus with many symptoms on my body, I was cured of the virus thanks to the help of Dr Sayo herbal medicine. I saw most of his patient testimonials on blogs and social media pages, cured of various disease/virus and illnesses. I contacted him on his email address to which he replied and asked me a few questions and the preparation method for which I paid, he sent me the herbal medicines and instructions on how to take it I apply the herbal medicine for 4 weeks and the symptoms on my body were healed after taking the herbal medicine treatment, I went for test and my result was negative with know trace of virus in my blood and am completely cured. You can also be cured, contact him on his email:  sayoherbalhealer@gmail.com  or WhatsApp him on +2349012175679 or visit his facebook page: https://www.facebook.com/SayoHerbalHealer

      Delete
  2. Am really happy that i have been cured from HSV1&2 DISEASE with the herbal medicine of Dr otaigbe have been suffering from this disease for a long time now without solution until i came across the email of this doctor who have cure so many people with his herbal medicine, i also choose to give him a chance to help me, he told me what to do and i kindly did it, and he gave me his herbal medicine and direct me on how to use it, i also follow his instructions for use and he ask me to go for a check up after 3 months which i did, to my greatest surprise my result came out as negative, i am really happy that there is someone like this doctor who is ready to help anytime any day. To all the readers and viewers that is doubting this testimony stop doubting it and contact this doctor if you have any disease and see if he will not actually help you. I know that there are some people out there who are really suffering and hurting their family just because of these diseases. you can get to him through email:DROTAIGBESPELLHOME@GMAIL. COM or WhatsApp him +2349066103332 .

    ReplyDelete
  3. All thanks to Dr Raymond for helping me to get my penis longer and bigger with his cream in just two week his cream is very active and also it work fast for everyone who have used it, the best thing about his herbal cream is that it does not have side effects and the results is permanent. Note he can also cure the below sicknesses and disease PREMATURE EJACULATIONLOW SPERM COUNTERECTILE DYSFUNCTIONHIV/AIDS CUREHERPES CUREINFECTION CUREPILESTROKEHEART FAILUREYou can email him if you need his help via: drraymondherbalcenter@gmail.com or WhatsApp him via: +2348116744524

    ReplyDelete
  4. I'm here to testify about what DR. OYAGU did for me. I have been suffering from (GENITAL HERPES VIRUS) disease for the past 2 years and had constant pain and inching, especially in my private part. During the first year, I had faith in God that i would be cured someday. This disease started circulating all over my body and I have been taking treatment from my doctor, few weeks ago I came across a testimony of Shayla Bosschart on the internet testifying about a Man called DR. OYAGU on how he cured her from 7 years HSV 2. And she also gave the email address of this man, advise anybody to contact him for help on any kind of diseases that he would be of help, so I emailed him telling him about my (HSV 2) he told me not to worry that I was going to be cured!! Well, I never doubted him I have faith he can cure me too,, DR. OYAGU prepared and sent me Healing Soap, roots and herbs which I took. In the first one week, I started experiencing changes all over me, after two weeks of using his Roots/ Herbs, Oil and Soap, I was totally cured. no more inching , pain on me anymore as DR. OYAGU assured me. After some time I went to my doctor to do another test behold the result came out negative. So friends my advise is if you have such disease or know anyone who suffers from it or any other disease like HPV, HBV, HIV, ALS, HBP, CANCER etc. you can contact DR. OYAGU for help via email} oyaguherbalhome@gmail.com visit his website https://oyaguspellcaster.wixsite.com/oyaguherbalhome whatsapp him through his mobile} +2348101755322. , Thanks once again DR. OYAGU for making me a happy woman again.

    ReplyDelete

  5. Am Here To Give My Testimony About A Doctor Who Helped Me In My Life. I Was Infected With HERPES SIMPLEX VIRUS In 2019, I Went To Many Hospitals For Cure But There Was No Solution, So I Was Thinking How Can I Get A Solution Out So That My Body Can Be Okay. One Day I Was In The River Side Thinking Where I Can Go To Get Solution. So A Lady Walked To Me Telling Me Why Am I So Sad And I Open Up All To Her Telling Her My Problem, She Told Me That She Can Help Me Out, She Introduce Me To A Doctor Who Uses Herbal Medication To Cure HERPES SIMPLEX VIRUS And Gave Me His Email, So I Mail Him. He Told Me All The Things I Need To Do And Also Give Me Instructions To Take, Which I Followed Properly. Before I Knew What Is Happening After Two Weeks The HERPES SIMPLEX VIRUS That Was In My Body Got Vanished . So If You Are Also Heart Broken And Also Need A Help, You Can Also contact Him Through Dr. Oyagu reach him oyaguherbalhome@gmail.com visit his website https://oyaguspellcaster.wixsite.com/oyaguherbalhome Or whatsapp him via +2348101755322

    ReplyDelete
  6. DR OYAGU herbal medicine is a good remedy for herpes simplex virus cure. My name is MIGNON WRIGHT , am from USA,I am here to give my testimony about DR OYAGU who helped me in my life, i want to inform the public how i was cured from (HERPES SIMPLEX VIRUS) by DR OYAGU, i visited different hospital but they gave me list of drugs like Familiar, Zovirax, and Valtrex which is very expensive to treat the symptoms and never cured me. I was browsing through the Internet searching for remedy on HERPES and i saw comment of people talking about how DR OYAGU cured them, when i contacted him he gave me hope and send a Herbal medicine to me that i took and it seriously worked for me, am a free person now without any problem, my HERPES result came out negative, I pray to God to never let me and my family forget you in our life, am now cured permanently, you can also get your self cured my friends if you really need this doctor help, you can reach him on his website ;https://oyaguspellcaster.wixsite.com/oyaguherbalhome Email: oyaguherbalhome@gmail.com or via whatsapp +2348101755322

    ReplyDelete
  7. DR OYAGU herbal medicine is a good remedy for herpes simplex virus cure. My name is MIGNON WRIGHT , am from USA,I am here to give my testimony about DR OYAGU who helped me in my life, i want to inform the public how i was cured from (HERPES SIMPLEX VIRUS) by DR OYAGU, i visited different hospital but they gave me list of drugs like Familiar, Zovirax, and Valtrex which is very expensive to treat the symptoms and never cured me. I was browsing through the Internet searching for remedy on HERPES and i saw comment of people talking about how DR OYAGU cured them, when i contacted him he gave me hope and send a Herbal medicine to me that i took and it seriously worked for me, am a free person now without any problem, my HERPES result came out negative, I pray to God to never let me and my family forget you in our life, am now cured permanently, you can also get your self cured my friends if you really need this doctor help, you can reach him on his website ;https://oyaguspellcaster.wixsite.com/oyaguherbalhome Email: oyaguherbalhome@gmail.com or via whatsapp +2348101755322

    ReplyDelete

  8. I'm 40 years old female I tested genital herpes (HSV1-2) positive in 2016. I was having bad outbreaks. EXTREMELY PAINFUL. I have try different kinds of drugs and treatment by the medical doctors all to know was avail. Six months ago I was desperately online searching for a helpful remedies for genital herpes (HSV1-2) cure, which I come across some helpful remedies on how Dr OYAGU have help so many people in curing genital herpes (HSV1-2) with the help of herbal treatment because I too believe there is someone somewhere in the world who can cure herpes completely. At of the past 2 months, however, I've been following his herpes protocol Via oyaguherbalhome@gmail.com or +2348101755322 and it stopped all outbreaks completely! To my greatest surprise I was cured completely by following the protocol of his herbal medicine . Don't be discouraged by the medical doctors. There is a cure for HSV with the help of herbs and roots by a herbalist Dr call Dr OYAGU he is so kind and truthful with his herbal treatment, kindly contact him for more information Via oyaguherbalhome@gmail.com or WhatsApp DR on +2348101755322 or visit his website https://oyaguspellcaster.wixsite.com/oyaguherbalhome you will be lucky as I am today

    ReplyDelete
  9. I'm here to testify about what DR. OYAGU did for me. I have been suffering from (GENITAL HERPES VIRUS) disease for the past 2 years and had constant pain and inching, especially in my private part. During the first year, I had faith in God that i would be cured someday. This disease started circulating all over my body and I have been taking treatment from my doctor, few weeks ago I came across a testimony of Shayla Bosschart on the internet testifying about a Man called DR. OYAGU on how he cured her from 7 years HSV 2. And she also gave the email address of this man, advise anybody to contact him for help on any kind of diseases that he would be of help, so I emailed him telling him about my (HSV 2) he told me not to worry that I was going to be cured!! Well, I never doubted him I have faith he can cure me too,, DR. OYAGU prepared and sent me Healing Soap, roots and herbs which I took. In the first one week, I started experiencing changes all over me, after two weeks of using his Roots/ Herbs, Oil and Soap, I was totally cured. no more inching , pain on me anymore as DR. OYAGU assured me. After some time I went to my doctor to do another test behold the result came out negative. So friends my advise is if you have such disease or know anyone who suffers from it or any other disease like HPV, HBV, HIV, ALS, HBP, CANCER etc. you can contact DR. OYAGU for help via email} oyaguherbalhome@gmail.com visit his website https://oyaguspellcaster.wixsite.com/oyaguherbalhome whatsapp him through his mobile} +2348101755322. , Thanks once again DR. OYAGU for making me a happy woman again.

    ReplyDelete
  10. It's a pleasure for me to write this testimony about this wonderful thing that happened to me last week on how i got my HIV aids cured, i have been reading so-many post of some people who were cured of HIV, but i never believed them, I was hurt and depressed so I was too curious and wanted to try dr.odoma then i contacted him on his email on drodomasolutionhome20@gmail.com when i contact him, he assured me 100% that he will heal me, i pleaded with him to help me out, it's a great success that he healed just as he promised, he told me that in three days time that i should go and check on my HIV status, I was floored that when i went to the hospital to check of my status that i was HIV negative, i never thought possible that dr.odoma can do miracles, i never really believed in magic but I played along with a little hope and faith and after everything but dr odoma changed my life and made me a true believer you can contact him drodomasolutionhome20@gmail.com or whatsapp Number: +2348100649947..visit his website:
    https://drodomasolutionhome.simdif.com/
    (facebook page https://www.facebook.com/Drodomaherbalmedicine/) he said that he is also specialize on the following diseases: HERPES, HIV, ALS, HPV, DIABETES, HEPATITIS B, CANCER,SICKLE CELL, VIRGINAL DRYNESS, And Bring Back Your Ex back.

    ReplyDelete
  11. INDEED DR SAYO HERBAL HEALER HAS THE CURE FOR FOLLOWING HERPES VIRUS, HIV/AIDS, CANCER ALL TYPES, DIABETES, HEPATITIS A/B, PAD, ETC......FOR MORE INFORMATION VISIT HIS WEBSITE: http://sayoherbalhome.com/ I was once a victim of the herpes virus with many symptoms on my body, I was cured of the virus thanks to the help of Dr Sayo herbal medicine. I saw most of his patient testimonials on blogs and social media pages, cured of various disease/virus and illnesses. I contacted him on his email address to which he replied and asked me a few questions and the preparation method for which I paid, he sent me the herbal medicines and instructions on how to take it I apply the herbal medicine for 4 weeks and the symptoms on my body were healed after taking the herbal medicine treatment, I went for test and my result was negative with know trace of virus in my blood and am completely cured. You can also be cured, contact him on his email:  sayoherbalhealer@gmail.com  or WhatsApp him on +2349012175679 or visit his facebook page: https://www.facebook.com/SayoHerbalHealer

    ReplyDelete
  12. Are you battling with any health related issues or infection is not the end of your life, why not contact a herbal practitioner for cure Dr Oyagu has herbal remedies and permanent solution for all your health related problems. recommend him to you today only because i have also used his herbal medicine and it worked perfectly on my health problem, you can actually save yourself from giving your hard earned money to Scammers if only you can contact Dr Oyagu today for genuine and Permanent cure herbal products . Pls help share this post to save yourself and your love ones. Dr Oyagu is specialize in these areas, Permanent herbal supplements for anxiety and depression, HIV/AIDS, Diabetes, Epilepsy, Blood, Cancer, HPV, ALS, herpes etc. Email: oyaguherbalhome@gmail.com or visit his website https://oyaguspellcaster.wixsite.com/oyaguherbalhome Or Cell Whatsapp Number +2348101755322 thank you

    ReplyDelete
  13. I'm so excited to share my testimonies about the Good Work of Dr odoma who cured my HIV/AIDS with his herbs, I never thought that I would live on earth before the year runs out. I have been suffering from a deadly disease (HIV) for the past (2)years now; I have spent a lot of money going from one Hospital to another looking for ways to get rid of this disease, the hospital has been my home everyday. Constant checks up have been my hobby not until this fateful day, I was searching
    through the internet, I saw a testimony on how Dr Odoma helped someone in curing his HIV disease using his healing
    Herbs, quickly I copied his email just to give him a test I spoke to him, he asked me to a preparation for the herbs items, of which I did exactly what he instructed me to do, he told me that he is going to provide the herbal cure to me, which he
    did, few days after i went back to the same hospital that previously confirmed me as HIV/AIDS positive and this time the result declared me negative to the deadly disease of HIV/AIDS....so I decided to share my testimony, that nothing is impossible with God, God use a man to healed me. No matter what you are passing through, no matter how deadly the sickness is and no matter what the situation is, God that did mine is still going to do yours, suffering from AIDS, ALS, asthma.. Cancer, any kind of disease, you can reach him now via ? Gmail address: (DR odomasolutionhome20@gmail. com) WhatsApp number (+2348100649947)

    ReplyDelete
  14. Greatest thanks to Dr Oyagu for his herbal medicine that he prepared for me and when I start using it in just 2weeks I was completely cured and that ended my HERPES SIMPLEX 1&2 DISEASE i am so happy and grateful to Dr Oyagu . after reading about him on a testimony of Jason Cash on a blogger. I knew suddenly Dr Oyagu was the right Doctor to cure my HERPES SIMPLEX 1&2 DISEASE. I discuss with Dr Oyagu and he prepared a herbal medicine for me and when it got sent to me in south Korean . I used the herbal medicine in 2weeks and i went for check up again. after 15years of suffering from HERPES SIMPLEX 1&2 at last i am smiling once again. Dr Oyagu also has remedy to others disease like COLD SORES,HIV/AIDS,DIABETES.CANCER,HIGH BLOOD PRESSURE AND MANY MORE. I oblige everyone to contact this powerful herbalist Dr Oyagu and be free from your suffering. contact his WhatsApp line: +2348101755322 or visit his Website https://oyaguspellcaster.wixsite.com/oyaguherbalhome Email:Oyaguherbalhome@gmail.com

    ReplyDelete
  15. I got diagnose of herpes virus last year, and i was taking some drugs prescribed for me by my family doc the drugs could not work and the herpes in my system was very terrifying that i was so depressed the good news is that i never gave up in searching for natural cure for herpes virus ,cause i believe so much in herbal medication.. One faithful morning i read a comment from a lady called Destiny Hudson on how she was cured with natural herbs made by DR.OYAGU from somewhere is West Africa, i immediately copied out his contact email via oyaguherbalhome@gmail.com and explain all my herpes problem to him via his email. the big truth is that it took just two week for his herbal medication to cure me completely without side affect. Till date am herpes virus free and all thanks to Dr OYAGU for his good deeds for me, Once again am very happy to share this great testimony of DR OYAGU cure hurry up now and contact him via his email address (oyaguherbalhome@gmail.com Call & WhatsApp him on (+2348101755322 ) and see what he can do

    ReplyDelete
  16. Dear friends online My name is Destiny Hudson And I live in the USA, Dominica I am here today to appreciate the good work of Dr Oyagu, for helping me curing my HSV 1&2 Disease, I contacted the virus from my Partner, i found out he was cheating on me, so i broke up with him, 2 month later i went to test myself in the hospital when i was seeing sore on my mouth and Private areas, i was diagnosed of HSV 1&2. i tried using the acyclovir medicine but it didn't help in curing it, i went on a search and found out Dr Oyagu curing people illness, and so i got his email and i was told how i can get his herbal cure, 3 days later i received his medicine after using it for 2 weeks i was tested again and was confirm negative, today i am totally free. If you are over there looking for solution email: oyaguherbalhome@gmail.com or contact him on whatsapp +2348101755322 or visit his website https://oyaguspellcaster.wixsite.com/oyaguherbalhome today and share your own testimony. And He also has herbal cure for the Following DISEASES, eczema, urethra wart, chronic problems. Herpes, Cancer, Als, Hepatitis, Diabetes, HPV ,Infections, ulcer ETC

    ReplyDelete
  17. Life is always beautiful when you have good health.i have be in pain for almost 1 year had HSV 1&2 and I was lonely and sad, luckily I was directed to a very kind and Great Dr Oliha who helped me cure my HSV 1&2 and today I am free from the virus and very healthy thank you so much Dr Oliha .Email
    oliha.miraclemedicine@gmail.com
    you can also whatsapp/Call him; +2349038382931

    ReplyDelete