teaching machines

Notes from 5/18/2012

Evaluating field Stripping out complex numbers and NaNs The critical current has some NaNs and complex numbers where we’re finding roots of negative numbers. MATLAB’s visualization functions don’t seem to tolerate these non-real values. I set all non-reals to 0 with: These two lines exploit the fact that find and isnan report the indices of […]


I want you to learn, create, and have free discussions with me. That’s more likely to happen if you avoid certain practices. TODONT #1: Visit me unannounced outside of office hours. You and I both have a lot to do. You can bet my day is scheduled before you even wake up. What’s it busy […]

CS 145 Lecture 27 – Final review

Agenda our own String class indexOf replace startsWith concat a 2-D ripple a bus counter Bingo board Code MyString.java package prefinal; public class MyString { private char[] charries; public MyString(char[] src) { charries = src; } /** * Gets the index of first instance of the * specified character. If character cannot * be found, […]

CS 330 Lecture 40 – Shell scripting, or Why I love Linux

Agenda shell scripting programs are methods speed and terseness caters to file manipulation globbing loops I/O redirection some problems resizing a bunch of images comparing two directories change extensions on a bunch of files checking for new mail sending spam finding big files preparing code for blog posts Code shrinken.sh #!/bin/sh mkdir -p dialup_friendlies for […]

CS 145 Lecture 26 – Sound

Agenda digital music WAV format binary file I/O generate static generate pitches generate chords Code WavIO.java import java.io.DataOutputStream; import java.io.FileNotFoundException; import java.io.FileOutputStream; import java.io.IOException; import java.nio.ByteBuffer; import java.nio.ByteOrder; public class WavIO { /** * The sampling frequency. */ public static final int SAMPLE_RATE = 22050; /** * Write the buffer containing audio samples to the […]

CS 330 Lecture 39 – Logic programming

Agenda atoms and variables facts and rules a path in a graph? Prolog’s DFS algorithm even or odd? member? sorted? notmember? hascycle? Code pdb.pl lang(scheme). lang(c). static(c). staticlang(X) :- lang(X), static(X). /* Graph stuff */ edge(a, b). edge(b, e). edge(b, d). edge(c, d). path(X, Y) :- edge(X, Y). path(X, Y) :- edge(X, Z), path(Z, Y). […]

CS 330 Lecture 38 – Gollygeo, a complete ANTLR/C++ project

Agenda not much for today an extended example! no haiku even Gollygeo We want to write a little geography quizzer. The player is dropped into a country and must identify its capital and neighbors before she can leave. To win (an education), the player must clear all countries. The author/level designer can draft up “maps” […]

CS 145 Lecture 25 – Shape Plotter

Agenda program this a Point class the problem with arrays a growable array of Points ArrayList Program This You have: A list of points/vertices of a polygon. The ability to draw lines. How do you draw the polygon? Code Point.java package prefinal; public class Point { private int x; private int y; public Point(int x, […]

CS 330 Lecture 37 – Sundries

Agenda more on hijacking a language applicative- vs. normal-order evaluation writing an if macro macros in C dangers of normal-order evaluation of expressions with side-effects list ranges list comprehensions lazy evaluation TODO http://www.cse.chalmers.se/~rjmh/Papers/whyfp.pdf http://www.haskell.org/haskellwiki/Why_Haskell_matters Code macros.ss (define myif (lambda (predicate? true-expr false-expr) (cond (predicate? 1) (else 0)))) (define-syntax spiffy (syntax-rules () ((spiffy predicate? true-expr false-expr) […]

CS 145 Lecture 24 – Adding Gravity

Agenda when to create an object you have a clear picture of identity/actor you can multiple instances of set of data revisit to event-driven programming adding gravity to ball dropper canvas composition collaboration graphs in SMC law #31: try local first Code DroppingCircles.java package prefinal; import java.util.Timer; import java.util.TimerTask; import javax.swing.JFrame; public class DroppingCircles { public […]

1 2