# Parabola: Stan optimization in CmdStanPy and BlackJAXSource: `Parabola/parabola.Rmd`This example maximizes the unnormalized log density$$target(x) = 15 + 10x - 2x^2.$$The analytic optimum is $x = 10/4 = 2.5$.## Plot the target```{python}import numpy as npimport matplotlib.pyplot as pltx = np.linspace(-2, 5, 400)y =15+10*x -2*x**2plt.plot(x, y)plt.axvline(2.5, color="black", linestyle="--", linewidth=1)plt.xlabel("x")plt.ylabel("target")plt.title("target = 15 + 10x - 2x²")```## CmdStanPy optimizationThe Stan model is identical to the original:```stanparameters { real x;}model { target += 15 + 10*x - 2*x^2;}``````{python}from pathlib import Pathfrom cmdstanpy import CmdStanModelstan_file = Path("../../ROS-Examples/Parabola/parabola.stan").resolve()model = CmdStanModel(stan_file=stan_file)opt = model.optimize()print(opt.optimized_params_dict)```## Log-density viewFor this toy example, differentiating the target is more direct than MCMC.```{python}def logdensity(x):return15+10*x -2*x**2def grad_logdensity(x):return10-4*xx0 =0.0print(float(grad_logdensity(x0))) # positive: move rightprint(float(grad_logdensity(2.5))) # zero at optimum```If we sample with NUTS, the implied normalized density is Gaussian:$$15 + 10x - 2x^2 = 27.5 - 2(x - 2.5)^2,$$so $x \sim N(2.5, 1/4)$ after normalization.