# Foundations I: Parameter¶

A parameter is one of the main building blocks in equadratures. Let $$s$$ be a parameter defined on a domain $$\mathcal{D} \subset \mathbb{R}$$. The support of the domain $$\mathcal{D}$$ may be:

• closed $$[a,b]$$;

• semi-infinite $$(-\infty, b)$$ or $$[a, \infty)$$;

• infinite $$(-\infty, \infty)$$.

Further, let us assume that this parameter is characterized by a positive weight function $$\rho(s)$$, which may be interpreted as the probability density function (PDF) of $$s$$, which readily implies that

$\int_{\mathcal{D}}\rho\left(s\right)ds=1.$

We now demonstrate some basic functionality of this parameter. First consider the case where $$\rho(s) = \mathcal{N} (0, 1)$$ is a standard Gaussian distribution with a mean of 0.0 and a variance of 1.0. We then plot its PDF and cumulative density function (CDF) and demonstrate how we can generate random samples from this distribution.

import equadratures as eq
import numpy as np
import matplotlib.pyplot as plt
VALUE = 15
plt.rcParams.update({'font.size': VALUE})

s = eq.Parameter(distribution='normal', shape_parameter_A=0.0, shape_parameter_B=1.0, order=3)


Now for some plots; first let us plot the PDF,

s_values, pdf = s.get_pdf()
s_values, cdf = s.get_cdf()
s_samples = s.get_samples(6000)

fig = plt.figure()
ax.set_axisbelow(True)
plt.plot(s_values, pdf, '-', c='crimson', lw=4)
plt.xlabel('$s$', fontsize=VALUE)
plt.ylabel('PDF', fontsize=VALUE)
plt.fill_between(s_values,  pdf*0.0, pdf, color="crimson", interpolate=True, hatch="\\\\\\\\", edgecolor="grey",  linewidth=0.5, alpha=0.5)
plt.grid()
plt.show()


Figure. PDF of a standard Gaussian variable.

followed by the CDF.

fig = plt.figure()
ax.set_axisbelow(True)
plt.plot(s_values, cdf, '-', c='navy', lw=4)
plt.xlabel('$s$', fontsize=VALUE)
plt.ylabel('CDF', fontsize=VALUE)
plt.grid()
plt.show()


Figure. CDF of a standard Gaussian variable.

Now, we will use the get_samples() functionality to create a histogram.

fig = plt.figure()
n, bins, patches = plt.hist(s_samples, 50, density=True, facecolor='navy', alpha=0.75, edgecolor='w')
plt.xlabel('$s$', fontsize=1)
plt.ylabel('PDF (Histogram)', fontsize=VALUE)
plt.grid()
ax.set_axisbelow(True)
plt.show()


Figure. Histogram of a standard Gaussian variable with 6000 samples.

One can repeat the above for a range of distributions. We provide a few additional definitions below. First, consider the example of a truncated Gaussian distribution,

s = eq.Parameter(distribution='truncated-gaussian', lower=-1.0, upper=2., shape_parameter_A=0.0, shape_parameter_B=1.0, order=3)


Figure. PDF of a truncated Gaussian variable.

followed by that of a custom distribution—based on user supplied data.

param1 = np.random.rand(1000)
param2 = np.random.randn(1200)
param3 = np.random.randn(1300)*0.5 - 0.2
param4 = np.random.randn(300)*0.1 + 3
data = np.hstack([param1, param2, param3, param4])
s = eq.Parameter(distribution='data', weight_function=input_dist, order=3)
s_values, pdf = s.get_pdf()
s_values, cdf = s.get_cdf()
s_samples = s.get_samples(6000)


Figure. PDF of a distribution based on user-provided data.