This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| """ | |
| A demonstration of how to deal with object-specific random number | |
| generator states. One application is if you want two objects to | |
| work with the same pseudorandom sequence but don't particularly | |
| want to generate them in advance, or to replicate results after | |
| serializing and de-serializing an object. | |
| By David Warde-Farley, dwf at cs.toronto.edu, January 2010. | |
| Released under BSD license. | |
| """ |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| import numpy as np | |
| def sample_pf_ball(p,b): | |
| """ | |
| Samples N binary variables using the product form distribution given in | |
| the vector b (of length N), where b[n] is the probability that s[n]=1. | |
| However, only K variables may on at a time, where K is the length of | |
| vector b minus 1, and b[k] is a distribution that biases the number of | |
| variables set to 1. | |
| % |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| #!/usr/bin/env python | |
| """ | |
| Draws Hinton diagrams using matplotlib ( http://matplotlib.sf.net/ ). | |
| Hinton diagrams are a handy way of visualizing weight matrices, using | |
| colour to denote sign and area to denote magnitude. | |
| By David Warde-Farley -- user AT cs dot toronto dot edu (user = dwf) | |
| with thanks to Geoffrey Hinton for providing the MATLAB code off of | |
| which this is modeled. |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| #!/usr/bin/env python | |
| """ | |
| NumPy implementation of the classic 'four regions' benchmark. | |
| By David Warde-Farley -- user AT cs dot toronto dot edu (user = dwf) | |
| Redistributable under the terms of the 3-clause BSD license | |
| (see http://www.opensource.org/licenses/bsd-license.php for details) | |
| """ | |
| import numpy as np |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| """ | |
| Simple script I whipped up to dump MSN Messenger logs in XML to a readable | |
| plaintext format. It's not very robust, nor am I sure which versions of MSN | |
| Messenger it's compatible or incompatible with; I just had a specific | |
| conversation I wanted to read, and this was the vehicle to that end. | |
| By David Warde-Farley -- user AT cs dot toronto dot edu (user = dwf) | |
| Redistributable under the terms of the 3-clause BSD license | |
| (see http://www.opensource.org/licenses/bsd-license.php for details) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| function bestclass = knn(train_data, labels, example, k); | |
| %kNN-- do k-nearest neighbours classification | |
| % | |
| % BESTCLASS = knn(TRAIN_DATA, LABELS, EXAMPLE, K) | |
| % | |
| % Takes TRAIN_DATA, a D x N matrix containing N training examples of dimension | |
| % D; LABELS, an N-vector of the (positive integer) classes assigned to each | |
| % column of TRAIN_DATA; EXAMPLE, a D-vector consisting of the example we | |
| % are trying to classify; and K, the number of neighbours to use in | |
| % classifying. |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| ;A bunch of increasingly complex Scheme procedures I wrote while | |
| ;learning Scheme. | |
| ; | |
| ; By David Warde-Farley -- user AT cs dot toronto dot edu (user = dwf) | |
| ; Redistributable under the terms of the 3-clause BSD license | |
| ; (see http://www.opensource.org/licenses/bsd-license.php for details) | |
| ;Increment a value and return it. | |
| (define inc |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| /* Scanner that reads in a Portable Graymap (PGM) file. | |
| * | |
| * By David Warde-Farley -- user AT cs dot toronto dot edu (user = dwf) | |
| * Redistributable under the terms of the 3-clause BSD license | |
| * (see http://www.opensource.org/licenses/bsd-license.php for details) | |
| */ | |
| enum { PRE_START, PARSE_START, GOT_X, GOT_Y, GOT_MAX } parserstate | |
| = PRE_START; |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| /* Demonstrates breaking up a string in much the same manner as is done by | |
| * the standard library function strtok. It's also an actually practical | |
| * occurrence of a triple pointer (char ***). | |
| * | |
| * Prepared for tutorial purposes by David Warde-Farley, CSC209H Winter 2008 | |
| */ | |
| #include <stdio.h> | |
| #include <stdlib.h> | |
| #include <string.h> |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| /* | |
| * Demonstrates the use of fgets() for reading in input, and it's behaviour | |
| * with respect to terminating NULL characters, newlines, etc. | |
| * | |
| * Prepared for tutorial purposes by David Warde-Farley, CSC209H Winter 2008 | |
| */ | |
| #include <stdio.h> | |
| #define BUFSIZE 5 |
OlderNewer