Statement
Complete the calculateSSE function that accepts arrays, A , b , and w A,\ \bold{b},\ \text{and}\ \bold{w} A , b , and w representing a linear system and computes the Sum of Squared Error for the respective system in given w \bold{w} w .
Example
A = [ 1 − 2 3 1 1 1 ] w = [ 1 1 ] b = [ 9 5 8 ] A = \begin{bmatrix}
1 & -2 \\ 3 & 1 \\ 1 & 1
\end{bmatrix}
\bold w = \begin{bmatrix}
1\\1 \end{bmatrix}
\bold b = \begin{bmatrix}
9\\5\\8 \end{bmatrix} A = ⎣ ⎡ 1 3 1 − 2 1 1 ⎦ ⎤ w = [ 1 1 ] b = ⎣ ⎡ 9 5 8 ⎦ ⎤
d = A w ^ − b = [ 1 − 2 3 1 1 1 ] [ 1 1 ] − [ 9 5 8 ] = [ − 10 − 1 − 6 ] d T d = [ − 10 − 1 − 6 ] [ − 10 − 1 − 6 ] S S E ( 1 , 1 ) = 137 \begin{align*}
\bold d = A\bold{\hat{w}} - \bold b&=\begin{bmatrix}
1 & -2 \\ 3 & 1 \\ 1 & 1
\end{bmatrix}
\begin{bmatrix} 1\\1 \end{bmatrix}
- \begin{bmatrix} 9\\5\\8 \end{bmatrix}
=\begin{bmatrix} -10\\-1\\-6 \end{bmatrix} \\
\bold d^T\bold d&=\begin{bmatrix}
-10 & -1 & -6 \end{bmatrix}
\begin{bmatrix} -10\\-1\\-6 \end{bmatrix} \\
SSE(1,1) &= 137
\end{align*} d = A w ^ − b d T d SSE ( 1 , 1 ) = ⎣ ⎡ 1 3 1 − 2 1 1 ⎦ ⎤ [ 1 1 ] − ⎣ ⎡ 9 5 8 ⎦ ⎤ = ⎣ ⎡ − 10 − 1 − 6 ⎦ ⎤ = [ − 10 − 1 − 6 ] ⎣ ⎡ − 10 − 1 − 6 ⎦ ⎤ = 137
Sample inputs and outputs
The following table provides example inputs and corresponding outputs:
Input
Output
A = [ [ 1 , − 2 ] , [ 3 , 1 ] , [ 1 , 1 ] ] A = [[1 , -2],[3 , 1],[1 , 1]] A = [[ 1 , − 2 ] , [ 3 , 1 ] , [ 1 , 1 ]] w = [ [ 1 ] , [ 1 ] ] \bold{w}=[[1],[1]] w = [[ 1 ] , [ 1 ]] b = [ [ 9 ] , [ 5 ] , [ 8 ] ] \bold{b}=[[9],[5],[8]] b = [[ 9 ] , [ 5 ] , [ 8 ]]
137
A = [ [ 7 , 2 , 5 ] , [ 9 , 7 , 3 ] , [ 6 , 9 , 1 ] ] A = [[7 , 2 , 5],[9,7,3],[6,9,1]] A = [[ 7 , 2 , 5 ] , [ 9 , 7 , 3 ] , [ 6 , 9 , 1 ]] w = [ [ 2 ] , [ − 2 ] , [ 0 ] ] \bold{w}=[[2],[-2],[0]] w = [[ 2 ] , [ − 2 ] , [ 0 ]] b = [ [ 3 ] , [ 3 ] , [ 2 ] ] \bold{b}=[[3],[3],[2]] b = [[ 3 ] , [ 3 ] , [ 2 ]]
114
Try it yourself
The signature of the function is given below: