Module vickrey.likelihood.plot
Functions to make plots about the likelihood.
Functions
def plot_contour(tt, t_as, par, ax=None, x_bounds=None, y_bounds=None)
-
Expand source code
def plot_contour( tt, t_as, par, ax=None, x_bounds=None, y_bounds=None, ): """Plot a 2-dimensional slice of the likelihood function. Args: tt: Instance of the TravelTime class, containing the travel time function to plot the likelihood for. t_as: Vector of arrival time to plot the likelihood of. par: Parameters with which the likelihood will be plotted. Two entries must be None: the slice will be plotted using the other values, for the dimensions the None values are in. ax: matplotlib.pyplot.Axes instance, on which the contour will be plotted. If no axis is given, the current axis will be used. x_bounds, y_bounds: Bounds of the dimensions that will be plotted. If no value is given, the bounds will be automatically determined from a list of predefined bounds. Returns: contour: The contour, which has been plotted on axis ax. """ indices = [i for i, v in enumerate(par) if not v] if len(indices) != 2: raise ValueError( f"The parameter list must have two None values.\n\ {par} has instead {len(indices)}" ) x_index, y_index = indices bounds = [(0.01, 0.6), (0.01, 0.6), (6.5, 11.0), (0.01, 0.6), (0.1, 2.0)] if not x_bounds: x_bounds = bounds[x_index] if not y_bounds: y_bounds = bounds[y_index] def log_lik(x, y): new_par = par.copy() new_par[x_index] = x new_par[y_index] = y return total_log_lik(tt, t_as)(*new_par) x_contour = jnp.linspace(*x_bounds, 51) y_contour = jnp.linspace(*y_bounds, 50) matrix_actual = vmap(vmap(log_lik, (0, None)), (None, 0))( x_contour, y_contour ) if not ax: ax = plt.gca() contour = ax.contour(x_contour, y_contour, matrix_actual, levels=50) names = [r"\mu_\beta", r"\mu_\gamma", r"\mu_t", r"\sigma", r"\sigma_t"] ax.set_xlabel("$" + names[x_index] + "$") ax.set_ylabel("$" + names[y_index] + "$") return contour
Plot a 2-dimensional slice of the likelihood function.
Args
tt
- Instance of the TravelTime class, containing the travel time function to plot the likelihood for.
t_as
- Vector of arrival time to plot the likelihood of.
par
- Parameters with which the likelihood will be plotted. Two entries must be None: the slice will be plotted using the other values, for the dimensions the None values are in.
ax
- matplotlib.pyplot.Axes instance, on which the contour will be plotted. If no axis is given, the current axis will be used.
x_bounds, y_bounds: Bounds of the dimensions that will be plotted. If no value is given, the bounds will be automatically determined from a list of predefined bounds.
Returns
contour
- The contour, which has been plotted on axis ax.
def plot_hist(tt, t_as, par, ax=None, par2=None, bins=80)
-
Expand source code
def plot_hist(tt, t_as, par, ax=None, par2=None, bins=80): """Plot an histogram of arrival times, with the likelihood of them. Args: tt: Instance of the TravelTime class, containing the travel time function to plot the likelihood for. t_as: Vector of arrival time to plot in the histogram. par: Parameters from which the likelihood function will be plotted. ax: matplotlib.pyplot.Axes instance, on which the histogram will be plotted. If no axis is given, the current axis will be used. par2: Second set of parameters, to compare the likelihoods coming from two different parameter values. bins: Number of bins to use when plotting the histogram. """ if ax is None: ax = plt.gca() hist = ax.hist(t_as, bins, label="Arrival times") x = np.linspace(t_as.min(), t_as.max(), 200) liks = total_liks(tt, x)(*par) mult = hist[0].max() / liks.max() ax.fill_between( x, liks * mult, color="green", alpha=0.3, label="True likelihood value", edgecolor=None, ) if par2 is not None: liks_wrong = total_liks(tt, x)(*par2) ax.fill_between( x, liks_wrong * mult, color="red", alpha=0.3, label="Wrong likelihood value", edgecolor=None, ) ax.legend()
Plot an histogram of arrival times, with the likelihood of them.
Args
tt
- Instance of the TravelTime class, containing the travel time function to plot the likelihood for.
t_as
- Vector of arrival time to plot in the histogram.
par
- Parameters from which the likelihood function will be plotted.
ax
- matplotlib.pyplot.Axes instance, on which the histogram will be plotted. If no axis is given, the current axis will be used.
par2
- Second set of parameters, to compare the likelihoods coming from two different parameter values.
bins
- Number of bins to use when plotting the histogram.