Python Scipy stats.halfgennorm.logpdf() Function

Scipy Library in Python:

  • SciPy is a scientific computation package that uses the NumPy library underneath.
  • SciPy is an abbreviation for Scientific Python.
  • It includes additional utility functions for optimization, statistics, and signal processing.
  • SciPy, like NumPy, is open source, so we can freely use it.
  • Travis Olliphant, the developer of NumPy, created SciPy.
  • SciPy has optimized and added/enhanced functions that are often used in NumPy and Data Science.

stats.halfgennorm.logpdf() Function:

We can obtain the log value of the probability density function by using the stats.halfgennorm.logpdf() method.

The formula of probability density function for halfgennorm:

Formula of probability density function for halfgennorm

Syntax:

stats.halfgennorm.logpdf(x, beta)

Return Value:

The log value of the probability density function is returned by the stats.halfgennorm.logpdf() Function.

Scipy stats.halfgennorm.logpdf() Function in Python

Method #1: Using logpdf() Function (Static Input)

Approach:

  • Import halfgennorm() method from stats of scipy module using the import keyword
  • Give the beta value as static input and store it in a variable.
  • Calculate the log value of probability density function using the logpdf() function of halfgennorm by passing some random value(x), given beta value as arguments to it.
  • Store it in another variable.
  • Print the log value of the probability density function for the given beta value.
  • The Exit of the Program.

Below is the implementation:

# Import halfgennorm() method from stats of scipy module using the import keyword
from scipy.stats import halfgennorm

# Give the beta value as static input and store it in a variable.
gvn_beta = 3

# Calculate the log value of probability density function using the logpdf() function
# of halfgennorm by passing some random value(x), given beta value as arguments to it.
# Store it in another variable.
rslt = halfgennorm.logpdf(0.2, gvn_beta)

# Print the log value of probability density function for the given beta value
print("The log value of probability density function for the given beta {", gvn_beta,"} value = ", rslt)

Output:

The log value of probability density function for the given beta { 3 } value = 0.10519164174034268

Method #2: Using logpdf() Function (User Input)

Approach:

  • Import halfgennorm() method from stats of scipy module using the import keyword
  • Give the beta value as user input using the int(input()) function and store it in a variable.
  • Calculate the log value of probability density function using the logpdf() function of halfgennorm by passing some random value(x), given beta value as arguments to it.
  • Store it in another variable.
  • Print the log value of the probability density function for the given beta value.
  • The Exit of the Program.

Below is the implementation:

# Import halfgennorm() method from stats of scipy module using the import keyword
from scipy.stats import halfgennorm

# Give the beta value as user input using the int(input()) function and store it in a variable.
gvn_beta = int(input("Enter some random number = "))

# Calculate the log value of probability density function using the logpdf() function
# of halfgennorm by passing some random value(x), given beta value as arguments to it.
# Store it in another variable.
rslt = halfgennorm.logpdf(0.3, gvn_beta)

# Print the log value of probability density function for the given beta value
print("The log value of probability density function for the given beta {", gvn_beta,"} value = ", rslt)

Output:

Enter some random number = 6
The log value of probability density function for the given beta { 6 } value = 0.07429703414981458