[Python] Note: A self-made function that finds the area of the normal distribution

memorandum

Elementary functions for statistics Just find the area of the graph of the normal distribution according to N (0,1 ^ 2).

image.png ↑ This The formula for this polyp-like curve is $ f_{(x)}=\frac{1}{\sqrt{2x}}e^{(-\frac{x}{2})} $ Given in. Thank you to those who commented.

Source (who gets)

1. Find the area from 0 to x

NORMAL_Dist_S



def NORMAL_Dist_S(a):
    """N(0,1^2)Normal distribution x according to=Returns the area from 0 to a"""
    import numpy as np
    import math
    from scipy import integrate


    f = lambda x: (math.exp(-x**2/2)) / math.sqrt(2*math.pi)
    s,d = integrate.quad(f, 0, abs(a))
    return s

NORMAL_Dist_S is

x = any real number res = NORMAL_Dist_S(x) And write

Returns the value of S (x) in res. image.png

2. Find the area from x = ∞ to x

NORMAL_Dist_S_REST



def NORMAL_Dist_S_REST(a):
    """N(0,1^2)Normal distribution x according to=Area from 0 to a is 0.Returns the value subtracted from 5"""
    import numpy as np
    import math
    from scipy import integrate


    f = lambda x: (math.exp(-x**2/2)) / math.sqrt(2*math.pi)
    s,d = integrate.quad(f, 0, abs(a))
    s=0.5-s
    return s

NORMAL_Dist_S_REST is

x = any real number res = NORMAL_Dist_S_REST(x) And write Returns the value of S (x) in res. image.png

3. Integral at any two points

NORMAL_Dist



def NORMAL_Dist(a,b):
    """N(0,1^2)Returns the area from a to b of the normal distribution according to"""
    import numpy as np
    import math
    from scipy import integrate


    f = lambda x: (math.exp(-x**2/2)) / math.sqrt(2*math.pi)
    s,d = integrate.quad(f, a,b)
    return s

NORMAL_Dist is

x = any real number y = any real number res = NORMAL_Dist(x,y) And write Returns the value of S (x) in res.

image.png

Impressions

Let's call it simpler, clearer and faster Therefore, who gets the function.

I want to increase the number of functions steadily. (Who is the best !! ??) After all, there are quite a few situations where I use it, It's annoying, so take this opportunity to make it a function.

At this level, I think there is something in the python import library. Rather, it cannot be absent.

Source etc.

http://org-technology.com/posts/integrate-function.html https://ja.wikipedia.org/wiki/%E6%AD%A3%E8%A6%8F%E5%88%86%E5%B8%83

Recommended Posts

[Python] Note: A self-made function that finds the area of the normal distribution
A function that measures the processing time of a method in python
Defeat the probability density function of the normal distribution
Get the caller of a function in Python
A note about the python version of python virtualenv
[Python] A program that counts the number of valleys
Steps to calculate the likelihood of a normal distribution
[Python] A program that compares the positions of kangaroos.
Python Note: The mystery of assigning a variable to a variable
[Python] A program that finds the shortest number of steps in a game that crosses clouds
[Note] Import of a file in the parent directory in Python
[Python] A program that finds the most common bird types
A Python script that compares the contents of two directories
[Python] Make the function a lambda function
A story that struggled to handle the Python package of PocketSphinx
Try transcribing the probability mass function of the binomial distribution in Python
[Python3] Define a decorator to measure the execution time of a function
The story of making a module that skips mail with python
[Python] A simple function to find the center coordinates of a circle
[Python] A program that rotates the contents of the list to the left
[Python] A program that finds the maximum number of toys that can be purchased with your money
[Python3] Rewrite the code object of the function
[python] [meta] Is the type of python a type?
The story of blackjack A processing (python)
Python Note: The secret role of commas
[Python] A program that rounds the score
I made a calendar that automatically updates the distribution schedule of Vtuber
[Python] A program that calculates the number of socks to be paired
How to create a wrapper that preserves the signature of the function to wrap
The eval () function that calculates a string as an expression in python
A note about the functions of the Linux standard library that handles time
From a book that makes the programmer's way of thinking interesting (Python)
Python: I want to measure the processing time of a function neatly
I made a function to see the movement of a two-dimensional array (Python)
[Circuit x Python] How to find the transfer function of a circuit using Lcapy
Explain the nature of the multivariate normal distribution graphically
[Note] Export the html of the site with python.
Match the distribution of each group in Python
Create a standard normal distribution graph in Python
Around the authentication of PyDrive2, a package that operates Google Drive with Python
[Python] A program that finds the minimum and maximum values without using methods
[Note] About the role of underscore "_" in Python
[Python] A program that calculates the number of updates of the highest and lowest records
Output in the form of a python array
A discussion of the strengths and weaknesses of Python
A python script that generates a sample dataset for checking the operation of a classification tree
A python script that gets the number of jobs for a specified condition from indeed.com
A regular expression that finds N or more consecutive substrings of the same character
A note on the library implementation that explores hyperparameters using Bayesian optimization in Python
A program that summarizes the transaction history csv data of SBI SECURITIES stocks [Python3]
A memo of misunderstanding when trying to load the entire self-made module with Python3
A note that runs an external program in Python and parses the resulting line
[Python / C] I made a device that wirelessly scrolls the screen of a PC remotely.
I made a calendar that automatically updates the distribution schedule of Vtuber (Google Calendar edition)
Add a function to tell the weather of today to slack bot (made by python)
Find the cumulative distribution function by sorting (Python version)
A story that reduces the effort of operation / maintenance
Recursive function that displays the XML tree structure [Note]
Cut a part of the string using a Python slice
Make a BOT that shortens the URL of Discord
A python implementation of the Bayesian linear regression class