# Adaptive Solar Power Forecasting based on Machine Learning Methods
## 3 The Algorithms to Realize ASPF
### The Least Angular Regression Algorithm  
A typical regression can be expressed as: \(\hat{\mathbf{n}}=\mathbf{X}\hat{\mathbf{\beta}}\), where \(\hat{\mathbf{n}}\) is the current estimate of the vector of responses \(\mathbf{y}\) with \(M\) predictors, \(\mathbf{X}\) is one matrix with \(N\times M\), \(N\) is the number of sample, and then current correlation will be: \(\hat{\mathbf{c}}_{\sigma}=\mathbf{X}^{{}^{\prime}}(\mathbf{y}-\hat{\mathbf{\mu}})\), and there will exist a \(j\) such that \(|\hat{c}_{\sigma,j}|\) is maximized. Then \(\mu\) will be updated by rule of \(\hat{\mu}_{m+1}=\hat{\mu}_{m}+\hat{\gamma}\text{sign}(\hat{c}_{\sigma,j})X_{j}\), in LARS, \(\hat{\gamma}\) is endogenously chosen so that the algorithm proceeds equiangular between the variables in the most correlated set (hence the 'least angle direction') until the next variable is found. Then the next variable joints the active set, and their coefficient are moved together in a way that keeps their correlations tied and decreasing. This process is continued until all the variables in the model, and end at the full least-squares fit [24].  
Actually, the LARS algorithm begins at \(\hat{\mu}_{0}=0\), supposing \(\hat{\mathbf{n}}\) is current estimate and let \(\hat{c}_{\sigma}=\mathbf{X}^{{}^{\prime}}(\mathbf{y}-\hat{\mathbf{\mu}})\). Define \(\mathcal{A}\) as a subset of the indices corresponding to variable with largest absolute correlations, \(\hat{\mathcal{C}}_{\sigma}=\max\{|\hat{c}_{\sigma,m}|\}\) and \(\mathcal{A}=\{m:|\hat{c}_{\sigma,m}|=\hat{\mathcal{C}}_{\sigma,m}\}\). Defining \(s_{m}=\text{sign}(\hat{c}_{\sigma,m})\), \(m\in\mathcal{A}\) and active matrix corresponding to \(\mathcal{A}\) is \(X_{\mathcal{A}}=(s_{m}X_{m})\). Letting \(\mathcal{G}_{\mathcal{A}}=X_{\mathcal{A}}^{{}^{\prime}}X_{\mathcal{A}}\) and \(A_{\mathcal{A}}=(1_{\mathcal{A}}^{{}^{\prime}}\mathcal{G}_{\mathcal{A}}^{-1} 1_{\mathcal{A}})^{\frac{1}{2}}\), \(1_{\mathcal{A}}\) is a vector of \(1^{\prime}\)s of length equaling \(|\mathcal{A}|\), the size of \(\mathcal{A}\). Then the equiangular vector can be defined as \(\mathbf{u}_{\mathcal{A}}=X_{\mathcal{A}}\)\(\rightarrow\)\(\mathcal{A}\), where \(\rightarrow_{\mathcal{A}}=A_{\mathcal{A}}\mathcal{G}_{\mathcal{A}}^{-1}1_{ \mathcal{A}}\), is the unit vector making equal angles, less than \(90^{\circ}\), with the columns of \(X_{\mathcal{A}}\) which satisfies \(X_{\mathcal{A}}\mathbf{u}_{\mathcal{A}}=A_{\mathcal{A}}1_{\mathcal{A}}\), and \(\parallel\mathbf{u}_{\mathcal{A}}\parallel^{2}=1\), and \(\mathbf{a}=X^{{}^{\prime}}\mathbf{u}_{\mathcal{A}}\). Then the \(\mathbf{\mu}\) will be updated in the next step of the LARS algorithm is:  
\[\hat{\mathbf{n}}_{\mathcal{A}+}=\hat{\mathbf{n}}_{\mathcal{A}}+\hat{\gamma}\mathbf{u}_{ \mathcal{A}} \tag{7}\]  
where  
\[\hat{\gamma}=\underset{m\in\mathcal{A}^{\text{c}}}{\text{min}}+\left\{\frac{ \hat{\mathcal{C}}_{\sigma}-\hat{c}_{\sigma,m}}{A_{\mathcal{A}}-a_{m}},\frac{ \hat{\mathcal{C}}_{\sigma}+\hat{c}_{\sigma,m}}{A_{\mathcal{A}}+a_{m}}\right\} \tag{8}\]  
\(\min^{+}\) indicates that the minimum is taken over only positive components within each choice of \(m\), \(a_{m}\in\mathbf{a}\). Finally, dependency variables are sorted by relevance level, and we can easily get the important predictors by LARS.  
After the dataset \(\mathbb{S}\) is divided in several styles in Section 3.1, and these subsets are defined as \(S_{1},S_{2},\cdots,S_{k^{\prime}}\), respectively. Then each subset is analyzed by LARS to reduce the influence of uninformative predictors, and we can focus on variables which is significant for the differences in prediction.