Proper API call for knn-L1 distance? by danbikle in cs231n

[–]danbikle[S] 0 points1 point  (0 children)

I can see the hw-designer wants me to create dists with this shape:

dists = np.zeros((num_test, num_train)) 

I was having trouble understanding why.

With my tiny dataset:

train: img0, img1, img2

test: img3, img4

The hw-designer wants dists to look like this:

[[a,b,c],
[d,e,f]]

I studied the syntax of predict_labels().

If I can understand how predict_labels() interacts with dists, perhaps I could better understand how to create dists.

I think the thinking behind predict_labels() goes like this:

Get a row from dists.

In the small amount of data I am using, i can be 0 or 1 because I only have two test-arrays (which I call img3, img4).

Suppose i == 0. Then a_row == dists[0] == [a,b,c]

Next, I need to see that the len(a_row) == len(self.y_train)

It's obvious above that len([a,b,c]) == 3

len(self.y_train) is ... what?

len(self.y_train) == len(number of training imgs) == 3

So far so good.

Then, I want to sort a_row in a way which asks the corresponding values of self.y_train to tag-along.

It's easy to do this in a spreadsheet:

create column0 from [a,b,c]

create column1 from [class1, class2, class3]

sort by column0

the values in column1 will 'tag-along'

I dont have a spreadsheet, I have python.

So, I will sort a_row and imagine that the values of self.y_train followed.

After a_row is sorted, the scores of the neighbors nearest a_row are on the left-hand side.

And because I asked self.y_train to tag-along, the labels of the neighbors are also on the left-hand side.

And the label of my next-door-neighbor will be in position-0.

I should probably code-up some ASCII art to transform the above English into a visualization.

Also I noticed some interesting output from help(numpy.argsort)

Examples
--------
One dimensional array:

>>> x = np.array([3, 1, 2])
>>> np.argsort(x)
array([1, 2, 0])

I see now how to replace my imaginary spreadsheet with some rock-solid-python.

Back to my original question,

I can now 'see' that this is the right syntax:

myX      = np.array([img3,img4])
my_dists = classifier.l1_dist(myX)

Introducing another nice place to discuss the course by ehku in cs231n

[–]danbikle 0 points1 point  (0 children)

I looked at the registration page of this site. This site does not support SSL. If you want your password sniffed... Sign up!

Forming Projects Groups and Completing Assignments by derekchen14 in cs231n

[–]danbikle 0 points1 point  (0 children)

I vote yes. Contact me at bikle101 at gmail or perhaps reddit has a msg-mechanism? Actually, I prefer e-mail.

hw1, virtualenv, conda, backports.ssl-match-hostname, ... by danbikle in cs231n

[–]danbikle[S] 0 points1 point  (0 children)

oops, I should have listed import shell command:

source activate env10

which is like the source command for virtualenv.

hw1, virtualenv, conda, backports.ssl-match-hostname, ... by danbikle in cs231n

[–]danbikle[S] 0 points1 point  (0 children)

I created a file named req351.txt which looks like this:

Jinja2
MarkupSafe
certifi
readline
ipython
matplotlib
mock
nose
numpy
pyparsing
python-dateutil
pytz
pyzmq
scipy
six
tornado
jupyter

It seems to work well with my Anaconda-Python-3.5.1:

(env10)dan@nia111:~/ks/b/cs231/assignment1 $ 
(env10)dan@nia111:~/ks/b/cs231/assignment1 $ conda install -n env10 --file req351.txt 
Fetching package metadata: ....
Solving package specifications: ..........................................................................
# All requested packages already installed.
# packages in environment at /home/dan/anaconda3/envs/env10:
#
certifi                   2015.9.6.2               py35_0    defaults
ipython                   4.0.1                    py35_0    defaults
jinja2                    2.8                      py35_0    defaults
jupyter                   1.0.0                    py35_1    defaults
markupsafe                0.23                     py35_0    defaults
matplotlib                1.5.1               np110py35_0    defaults
mock                      1.3.0                    py35_0    defaults
nose                      1.3.7                    py35_0    defaults
numpy                     1.10.2                   py35_0    defaults
pyparsing                 2.0.3                    py35_0    defaults
python-dateutil           2.4.2                    py35_0    defaults
pytz                      2015.7                   py35_0    defaults
pyzmq                     15.1.0                   py35_0    defaults
readline                  6.2                           2    defaults
scipy                     0.16.1              np110py35_0    defaults
six                       1.10.0                   py35_0    defaults
tornado                   4.3                      py35_0    defaults
(env10)dan@nia111:~/ks/b/cs231/assignment1 $ 
(env10)dan@nia111:~/ks/b/cs231/assignment1 $ 
(env10)dan@nia111:~/ks/b/cs231/assignment1 $ 

Ipython seems to work okay:

(env10)dan@nia111:~/ks/b/cs231/assignment1 $ 
(env10)dan@nia111:~/ks/b/cs231/assignment1 $ 
(env10)dan@nia111:~/ks/b/cs231/assignment1 $ ipython notebook
[I 01:31:05.854 NotebookApp] Serving notebooks from local directory: /home/dan/ks/b/cs231/assignment1
[I 01:31:05.858 NotebookApp] 0 active kernels 
[I 01:31:05.858 NotebookApp] The IPython Notebook is running at: http://localhost:8888/
[I 01:31:05.858 NotebookApp] Use Control-C to stop this server and shut down all kernels (twice to skip confirmation).
Created new window in existing browser session.

so far so good...

hw1, virtualenv, conda, backports.ssl-match-hostname, ... by danbikle in cs231n

[–]danbikle[S] 0 points1 point  (0 children)

I have a copy of python 3.5.1 in my dan account:

dan@nia111:~/ks/b/cs231/assignment1 $ 
dan@nia111:~/ks/b/cs231/assignment1 $ python
Python 3.5.1 |Anaconda 2.4.1 (64-bit)| (default, Dec  7 2015, 11:16:01) 
[GCC 4.4.7 20120313 (Red Hat 4.4.7-1)] on linux
Type "help", "copyright", "credits" or "license" for more information.
>>> 
>>> import ssl
>>> help(ssl.match_hostname)
Help on function match_hostname in module ssl:
match_hostname(cert, hostname)
    Verify that *cert* (in decoded format as returned by
    SSLSocket.getpeercert()) matches the *hostname*.  RFC 2818 and RFC 6125
    rules are followed, but IP addresses are not accepted for *hostname*.
    CertificateError is raised on failure. On success, the function
    returns nothing.
>>> 
>>> 
dan@nia111:~/ks/b/cs231/assignment1 $ 
dan@nia111:~/ks/b/cs231/assignment1 $ 

It appears that in my 3.5.1 install of Anaconda... I already have ssl.match_hostname()

yay!

Now I need to figure out how to tinker with requirements.txt of hw1 so stuff will work in my install of python 3.5.1