[Edu-sig] "chopsticks" piano notes as ML feed in Intro Course (experimental)

kirby urner kirby.urner at gmail.com
Sun Nov 11 19:21:47 EST 2018


Here's another case where I might have stumbled on an andragogic technique
another Python teacher is already well-known for using.  Or not, we shall
see.

Old technique (for teaching properties):

In an earlier chapter, I stumbled upon having @property decorate a circle
so you could change radius, area or circumference with simple "setattr" dot
notation e.g. c.area = 10, and the other two attributes would change
automatically. [1]

Thanks to how type property uses the Descriptor pattern, that's quite
doable and is a clear demonstration of what properties allow, drawn from
familiar grade school geometry.

Turns out:  Raymond Hettinger was sharing that little dharma already.  Same
karma!  Great minds think alike (if I do say so myself).

Aside:

I've been meaning to do more with triangles and tetrahedrons, using
@property... e.g. make AB longer and watch angles change.  Sticking to
right and/or equi-angular triangles keeps everything simpler. [2]

The new technique (for introducing data structures and machine learning):

So the new thing I might not be first to think of:

lets use the "chopsticks pattern" from the musical score of Chopsticks
(used universally in tutorials, almost a "hello, world" of Piano World) and
call the chopstick note pairs "correct" amidst a myriad "not correct" bytes.

Here's an octave:
C D E F G A B C

Chopsticks begins with

F and G pressed.
Then E and G.
Then D and B.
Then C and C.

The first 22 seconds of this Youtube give the idea:
https://youtu.be/waraNMP0kK8

So in "byte format":

0 0 0 1 1 0 0 0
0 0 1 0 1 0 0 0
0 1 0 0 0 0 1 0
1 0 0 0 0 0 0 1

are the "chopsticks" of interest.

Then have Machine Learning algorithms tease out the pattern.

Feed through 10,000 random strings of 1 and 0. [3]

Mark the chopstick patterns "correct" (1) and the not-chopstick patterns
"incorrect" (0), effectively forming a ninth column (the proverbial y in
machine learning, where all the samples are X).

This way, we get to play with (introduce) numpy.ndarrays and scikit-learn,
but with more familiar thoughts about piano keys in the foreground, and a
melody to boot.

How good are these learning machines, once trained?

Do they get random 10010100 right i.e. "not a chopstick"?  Are they right
every time?

If intrigued and want more code, here's the link to the Jupyter Notebook in
question:

https://github.com/4dsolutions/SAISOFT/blob/master/OrderingData.ipynb

(scroll to very end and come backwards would be my suggestion -- get the ML
part first).

I like how something so early in piano training feeds an intro to ML, given
how piano and "player piano" relate to AI, of which ML is a part.  Punch
cards and all that.

Very Westworld eh?

https://youtu.be/elkHuRROPfk
(not just Chopsticks anymore)

I'm looking for "pathways through Python" that consist of a combination of
"zoomed in" and "zoomed out" topics.  Sometimes we look at nitty gritty,
other times we need overview.

Kirby

[1]  this older version (Oct 2016) doesn't have perimeter (circumference).
Easy to add? (we do that as an exercise in class).

https://github.com/4dsolutions/Python5/blob/master/Descriptors%20and%20Properties.ipynb

[2]  I've got this dynamite volume method, not invented by me, that just
takes the six edge lengths for the arguments.

https://github.com/4dsolutions/Python5/blob/master/tetravolume.py  (used a
lot in my stash)

Lots more in the historical literature.  E.g.:

https://www.mathpages.com/home/kmath424/kmath424.htm

More context:

https://medium.com/@kirbyurner/uncommon-core-87a31b7f75b3

[3]

My current function for doing that is maybe too long-winded as I
concatenate strings.  Why not just convert to binary from random 0-255.  We
could do that.
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.python.org/pipermail/edu-sig/attachments/20181111/a351598a/attachment.html>


More information about the Edu-sig mailing list