MANU_F
August 4, 2022, 3:57pm
1
J += np.square(r * (np.dot(w,x) + b_j - y ) )

In the Hint , the calcuation of the cost function is also including r(i,j) in the Square function., As per the formula, it does not seem right. I am not a Python export, but the hint (as in the line 1 seems incorrect)

the correct code should be as below

```
J += r * np.square((np.dot(w,x) + b_j - y ))
```

Welcome to the community !

Actually, it does not matter…

r = R[i,j] = 1 or 0

And, we only calculate this if r=1 .

Hope this clarifies.

MANU_F
August 4, 2022, 5:02pm
3
Mathematically it does not. I did get distracted and received unrelated errors, until you bought the point out.

I did get distracted and received unrelated errors

Interesting… Did you actually implement the first one ?

Even mathematically,… no difference, of course.

\begin{equation}
r(i,j)*(w^{(j)}x^{(i)} + b^{(j)} - y^{(i,j)})^2=
\begin{cases}
0 & \text{if r(i,j)=0} \\
(w^{(j)}x^{(i)} + b^{(j)} - y^{(i,j)})^2 & \text{if r(i,j)=1}
\end{cases}
\end{equation}

\begin{equation}
(r(i,j)*(w^{(j)}x^{(i)} + b^{(j)} - y^{(i,j)}))^2=
\begin{cases}
0 & \text{if r(i,j)=0} \\
(w^{(j)}x^{(i)} + b^{(j)} - y^{(i,j)})^2 & \text{if r(i,j)=1}
\end{cases}
\end{equation}

What happened in your environment ?