Calculate AIC for both linear and non-linear models I have data made of vectors $\textbf{x}$ and $\textbf{y}$. I want to predict $\textbf{y}$ with $\textbf{x}$ and a set of hyperparameters $a_{1, ..., 3}$ to be fitted with a linear and a nonlinear model using a python package (curve_fit function from scipy.optimize):
Linear model (in x):
\begin{equation}\label{equation_linear_model}
  \hat{\textbf{y}}_1 = \text{F}_1(\textbf{x},a_1) = \text{x} \cdot a_1
\end{equation}
Non-linear model (in x):
\begin{equation}\label{equation_non_linear_model}
  \hat{\textbf{y}}_2 = \text{F}_2(\textbf{x},a_2,a_3) = 
  a_2 \cdot \Big(\frac{1}{e^{(-\text{x}\cdot a_3)}+1}\Big)
\end{equation}
$\hat{\textbf{y}}_1$ and $\hat{\textbf{y}}_2$ are the predictions of the respective models which have to be as close as $\textbf{y}$ as possible.
I want then to compare the performance of those two models by calculating the AIC. I used so far the definition of AIC for linear models as follows (for both models including the linear model).
$$
AIC = n \log(\hat{\sigma}^2) + 2k
$$
where
$$
\hat{\sigma}^2 = \frac{\sum \hat{\epsilon}_i^2}{n}
$$
where $n$ is the number of data points, $k$ is the number of parameters, $\epsilon$ is the error of the prediction. What would be the formula to compute the two AIC values (the one from the linear and the one from the non linear model) and a corresponding p-value for significant difference of the two AIC values

The formula
$$
AIC = n \log(\hat{\sigma}^2) + 2k
$$
works because it's proportionate to
$$ AIC = 2k - 2\ln({\hat {L}})$$
where $\hat L$ is the log likelihood for models with a Guassian likelihood
$
\hat L = log(\prod_i \mathcal{N}(y_i | \hat y_i, \hat \sigma))
$
or equivalently, $\epsilon \sim \mathcal{N}(0, \hat \sigma)$.
If both of your models are of this form, all that matters for calculating $AIC$ are a) the number of parameters $k$, and b) the mismatch $\epsilon$ between predicted values $\hat y$ and observed values $y$, summarised either as $n \text{ log}(\hat \sigma^2)$ or as $\hat L$, since they're the same value (with opposite signs). The form of of the function $F$ doesn't matter.
As for comparing $AIC$ values, you can forget about p-values, since $AIC$ and p-values are two different and incompatible approaches to hypothesis testing. Focus instead on the actual difference in AIC scores, as discussed, e.g. in this question or this blog. You might also look at AIC weights, which are a more intuitive way of interpreting AIC differences.

As @SextusEmpiricus points out, $\log\mathcal{L}(\beta ; y_i, x_i)$ and $- n \log(\hat{\sigma})$ are proportionate but differ by a constant value, so you should use one or other equation for all your models rather than mixing and matching.

