I’m recently working on cs231n. This is the github link and I’ll update the labnotes simultaneously here.

k-NN

The whole process of working on this assignment was quite frustrating and time-consuming. But finally it’s done!! Here’s some notes about it.

The implementation of the distance function

The calculation using one loop and no loop presented to be challenging to me. It’s primarily because I am not familar with the broadcasting in numpy. Click here to orient you to the official document.

  • Broadcasting

    An automatic adjustment when numpy dealing with two arrays that have seemingly unmatched dimensions.

    Below are two useful and legible pictures taken from the official website, which granted me great assitance to understand how it works.

    Operation between matrix and vector

    Operation between two vectors

    Something worth notice in the second pic is that when doing this computation, you are expected to transfer the left one from a row vector into a column vector. A little trick to realize it could be using vector_a[:, np.newaxis].

    Actually, before acquiring knowledge about broadcasting, I thought about using matrix transformations to get the vector into the shape I wanted, but quickly I realized it might be impossible or quite complicated, so I gave up.

Other experiences accumulated

  1. Initially, I forgot to make square root for the distance. Then I got an incrediblely large deviation from the validated computation designed before hand. So I might be more meticulous next time……
  2. When defining variables, be careful to avoid repeating some names previously even though you might think it’s okay to overwrite previous variable because they have similar functions. Or you might be dragged to craziness like me and don’t know what’s wrong with the programme… (sincere advice!!)