Note: A few helper functions included in the MATLAB version of the PCIT toolbox are not present here. When it comes to numerical helper functions logsumexp.m
and round_to.m
, this is because a Python version of the function is already included in a required scientific programming library such as scipy
or numpy
. When it comes to visualization helper functions savesamesize.m
and jbfill.m
, it's because equivalent Python functions are either unnecessary or not applicable in the context of matplotlib
's library. In either case, equivalent functionality is achieved without implementation of an additional toolbox function.
This function implements the $\beta_1$ likelihood-ratio test described in Section 4.10 of the P-CIT Toolbox Manual.
If we want to build confidence that this function is an exact reproduction of the MATLAB implementation, we can ask whether our version returns (-20, 1)
for the arguments (l1=10.0, l0=20.0, k1=8.0, k0=5.0)
as the MATLAB version does:
likratiotest(l1=10.0, l0=20.0, k1=8.0, k0=5.0)
(-20.0, 1.0)
As an example, we can generate and visualize the result of applying the function to some arbitrary paremeters:
import matplotlib.pyplot as plt
# generate a sample
sample = truncated_normal(a=.7, b=1.3, mu=1.0, sigma=.1, n=10000.0)
# visualize its distribution
n_bins = 100
plt.hist(sample, bins=n_bins)
plt.title('truncated_normal(a=.7, b=1.3, mu=1.0, sigma=.1, n=10000.0)')
plt.savefig('figures/truncated_normal_example.svg')
plt.show()
sample
array([0.88296168, 1.22801193, 0.8565991 , ..., 0.87280798, 1.09364587,
0.96110738])
As an example we can execute the function with a few arbitrary parameters:
scale_data([8.3256, 1000.0, 23.0, 564.0], 0, 1)
As specified, it returns the vector scaled between 0 and 1.
array([[0. , 1. , 0.0147976 , 0.56033956]])
Notably, the output is 2-dimensional rather than a vector; this enforces consistency in the shape of the function's output regardless of the shape of the input. It also helps ensure compatibility with other code translated from the MATLAB implementation of the toolbox.