LAPLACE

Overview

The LAPLACE function computes various properties of the Laplace distribution, a continuous probability distribution also known as the double exponential distribution. Named after Pierre-Simon Laplace, who first published it in 1774, the distribution can be thought of as two exponential distributions spliced together back-to-back along the x-axis.

The Laplace distribution is characterized by two parameters: a location parameter \mu that determines the peak of the distribution, and a scale parameter b > 0 (sometimes called “diversity”) that controls the spread. The probability density function (PDF) is defined as:

f(x \mid \mu, b) = \frac{1}{2b} \exp\left(-\frac{|x - \mu|}{b}\right)

Unlike the normal distribution, which uses squared differences from the mean, the Laplace distribution uses the absolute difference. This results in a sharper peak at the mode and heavier tails than the normal distribution, making it particularly useful for modeling data with outliers or extreme values.

The cumulative distribution function (CDF) has a closed-form expression:

F(x) = \frac{1}{2} + \frac{1}{2} \text{sgn}(x - \mu) \left(1 - \exp\left(-\frac{|x - \mu|}{b}\right)\right)

Key statistical properties include: mean and median equal to \mu, variance of 2b^2, and standard deviation of b\sqrt{2}. The distribution has zero skewness and excess kurtosis of 3.

The Laplace distribution has important applications in differential privacy (adding Laplacian noise to protect sensitive data), regression analysis (least absolute deviations estimation), Bayesian statistics (as a prior in LASSO regularization), and signal processing (modeling speech and image compression coefficients). In finance, it addresses skewness and kurtosis issues that arise when using normal distributions for option pricing.

Technical Reference

The Laplace distribution is often called the “double exponential” because it consists of two exponential distributions (one positive, one negative) joined at the location parameter \mu.

Property Formula
Mean \mu
Median \mu
Mode \mu
Variance 2b^2
Skewness 0
Excess Kurtosis 3

Python Example

Using scipy.stats.laplace, you can easily calculate distribution properties and visualize the characteristic “sharp peak” compared to a normal distribution.

import numpy as np
import matplotlib.pyplot as plt
from scipy.stats import laplace, norm

# 1. Define parameters
mu, b = 0, 1
x = np.linspace(-5, 5, 500)

# 2. Compute PDF
pdf_laplace = laplace.pdf(x, loc=mu, scale=b)
pdf_normal = norm.pdf(x, loc=mu, scale=np.sqrt(2*b**2)) # Match variance

# 3. Plot comparison
plt.figure(figsize=(10, 6))
plt.plot(x, pdf_laplace, label=f'Laplace (b={b})', lw=2)
plt.plot(x, pdf_normal, '--', label='Normal (matched variance)', lw=2)
plt.title("Laplace vs. Normal Distribution")
plt.xlabel("x")
plt.ylabel("Probability Density")
plt.legend()
plt.grid(alpha=0.3)
plt.show()

This implementation uses the scipy.stats.laplace module from SciPy and supports multiple calculation methods including PDF, CDF, inverse CDF (quantile function), survival function, mean, median, variance, and standard deviation.

This example function is provided as-is without any representation of accuracy.

Excel Usage

=LAPLACE(value, loc, scale, laplace_method)
  • value (float, optional, default: null): Input value for the distribution. Required for pdf, cdf, icdf, sf, isf methods.
  • loc (float, optional, default: 0): Location parameter of the distribution.
  • scale (float, optional, default: 1): Scale parameter of the distribution. Must be greater than 0.
  • laplace_method (str, optional, default: “pdf”): The method to compute (pdf, cdf, icdf, sf, isf, mean, median, var, std).

Returns (float): Result of the requested method, or str error message if input is invalid.

Example 1: PDF at x=1

Inputs:

value loc scale laplace_method
1 0 1 pdf

Excel formula:

=LAPLACE(1, 0, 1, "pdf")

Expected output:

0.18394

Example 2: CDF at x=1

Inputs:

value loc scale laplace_method
1 0 1 cdf

Excel formula:

=LAPLACE(1, 0, 1, "cdf")

Expected output:

0.81606

Example 3: Inverse CDF at q=0.81606

Inputs:

value loc scale laplace_method
0.81606 0 1 icdf

Excel formula:

=LAPLACE(0.81606, 0, 1, "icdf")

Expected output:

0.999998

Example 4: Mean of the distribution

Inputs:

loc scale laplace_method
0 1 mean

Excel formula:

=LAPLACE(0, 1, "mean")

Expected output:

0

Python Code

Show Code
from scipy.stats import laplace as scipy_laplace
import math

def laplace(value=None, loc=0, scale=1, laplace_method='pdf'):
    """
    Laplace distribution function supporting multiple methods.

    See: https://docs.scipy.org/doc/scipy/reference/generated/scipy.stats.laplace.html

    This example function is provided as-is without any representation of accuracy.

    Args:
        value (float, optional): Input value for the distribution. Required for pdf, cdf, icdf, sf, isf methods. Default is None.
        loc (float, optional): Location parameter of the distribution. Default is 0.
        scale (float, optional): Scale parameter of the distribution. Must be greater than 0. Default is 1.
        laplace_method (str, optional): The method to compute (pdf, cdf, icdf, sf, isf, mean, median, var, std). Valid options: PDF, CDF, ICDF, SF, ISF, Mean, Median, Variance, Std Dev. Default is 'pdf'.

    Returns:
        float: Result of the requested method, or str error message if input is invalid.
    """
    try:
      valid_methods = {'pdf', 'cdf', 'icdf', 'sf', 'isf', 'mean', 'median', 'var', 'std'}

      if not isinstance(laplace_method, str):
        return "Error: laplace_method must be a string."

      method = laplace_method.lower()
      if method not in valid_methods:
        return f"Error: Invalid method: {laplace_method}. Must be one of {', '.join(sorted(valid_methods))}."

      try:
        loc = float(loc)
        scale = float(scale)
      except (ValueError, TypeError):
        return "Error: loc and scale must be numbers."
      if scale <= 0:
        return "Error: scale must be > 0."

      dist = scipy_laplace(loc=loc, scale=scale)
      if method in ['pdf', 'cdf', 'icdf', 'sf', 'isf']:
        if value is None:
          return f"Error: missing required argument 'value' for method '{method}'."
        try:
          value = float(value)
        except (ValueError, TypeError):
          return "Error: value must be a number."
        if method == 'pdf':
          result = dist.pdf(value)
        elif method == 'cdf':
          result = dist.cdf(value)
        elif method == 'sf':
          result = dist.sf(value)
        elif method == 'isf':
          if not (0 <= value <= 1):
            return "Error: value (probability) must be between 0 and 1 for isf."
          result = dist.isf(value)
        elif method == 'icdf':
          if not (0 <= value <= 1):
            return "Error: value (probability) must be between 0 and 1 for icdf."
          result = dist.ppf(value)
      else:
        if method == 'mean':
          result = dist.mean()
        elif method == 'median':
          result = dist.median()
        elif method == 'var':
          result = dist.var()
        elif method == 'std':
          result = dist.std()

      result = float(result)
      if math.isnan(result):
        return "Error: Result is NaN."
      if math.isinf(result):
        return "Error: Result is infinite."

      return result
    except Exception as e:
      return f"Error: {str(e)}"

Online Calculator

Input value for the distribution. Required for pdf, cdf, icdf, sf, isf methods.
Location parameter of the distribution.
Scale parameter of the distribution. Must be greater than 0.
The method to compute (pdf, cdf, icdf, sf, isf, mean, median, var, std).