Simon gets serious with Linear Regression (Machine Learning)

Simon has been working on a very complicated topic for the past couple of days: Linear Regression. In essence, it is the math behind machine learning.

Simon was watching Daniel Shiffman’s tutorials on Linear Regression that form session 3 of his Spring 2017 ITP “Intelligence and Learning” course (ITP stands for Interactive Telecommunications Program and is a graduate programme at NYU’s Tisch School of the Arts).

Daniel Shiffman’s current weekly live streams are also largely devoted to neural networks, so in a way, Simon has been preoccupied with related stuff for weeks now. This time around, however, he decided to make his own versions of Daniel Shiffman’s lectures (a whole Linear Regression playlist), has been busy with in-camera editing, and has written a resume of one of the Linear Regression tutorials (he actually sat there transcribing what Daniel said) in the form of an interactive webpage! This Linear Regression webpage is online at: https://simon-tiger.github.io/linear-regression/ and the Gragient Descent addendum Simon made later is at:  https://simon-tiger.github.io/linear-regression/gradient_descent/interactive/ and https://simon-tiger.github.io/linear-regression/gradient_descent/random/

And here come the videos from Simon’s Liner Regression playlist, the first one being an older video you may have already seen:

Here Simon shows his interactive Linear Regression webpage:

A lecture of Anscombe’s Quartet (something from statistics):

Then comes a lecture on Scatter Plot and Residual Plot, as well as combining Residual Plot with Anscombe’s Quartet, based upon video 3.3 of Intelligence and Learning. Simon made a mistake graphing he residual plot but corrected himself in an addendum (end of the video):

Polynomial Regression:

And finally, Linear Regression with Gradient Descent algorithm and how the learning works. Based upon Daniel Shiffman’s tutorial 3.4 on Intelligence and Learning:

DSC_0557

 

 

Coding Train

Yesterday Simon got a parcel from the US: Simon’s hero, NYU professor Daniel Shiffman sent him a beautiful gift – a Coding Train shirt! Coding Train is Daniel Shiffman’s channel on YouTube where he records tutorials, coding challenges and live streams. Basically, Coding Train has been Simon’s main learning source in Programming, Math and Physics (and English!) for months.

DSC_0536

DSC_0537

DSC_0538

DSC_0539

Simon explains Linear Regression (Machine Learning)

In the two videos below Simon writes a JavaScript program using Linear Regression in Atom and gives a whiteboard lecture on the Linear Regression algorithm, both following a tutorial on Linear Regression by Daniel Shiffman.

Simon made a mistake in the formula using the sigma operator. He corrected it later. It should be i=1 (not i=0).

DSC_0548

DSC_0549

DSC_0551

 

Magnitude of a 3D vector

Here Simon explains how to calculate the magnitude of a 3D vector. This is something he partially figured out on his own and partially learned from Daniel Shiffman’s tutorial on Trigonometry and Polar Coordinates.

 

DSC_0540

Diffusion-Limited Aggregation translated into Codea

Simon translated Daniel Shiffman’s Diffusion-limited Aggregation Coding Challenge into Codea. The coding challenge explores the generative algorithm “Diffusion-Limited Aggregation”, whose visual pattern is generated from random walkers clustering around a seed (or set of seed) point(s).

Unfortunately, every time the iPad falls asleep the application seems to stop, so we never got a sizable tree.

 

Error with Genetic Algorithm. What is wrong?

Simon was almost done translating Smart Rockets example no. 2 (Smart Rockets Superbasic) from Daniel Shiffman’s The Nature of Code, from Processing (Java) into JavaScript in Cloud9, when he got an error using genetic algorithm: the dna seems to be undefined while Simon did define mom and dad dna.

This is Simon’s translation online in Cloud9: https://ide.c9.io/simontiger/smart-rockets#openfile-README.md

This is when he first discovered the bug and tried different solutions:

And this is the same project before he introduced the genetic algorithm:

In the next video Simon boasts he found two errors in his code and hopes that the problem would be solved, but alas, the rockets still vanish from the canvas after a few seconds:

Simon is officially stuck here.

On the positive side, this project did get us to read more about the actual human DNA and the way it works.

 

Thoughts on Fidget Spinner Simulation

DSC_0420-1
In his recent Live Stream, Daniel Shiffman announced he would make a fidget spinner simulation in the near future. Inspired by this idea, Simon has jotted down some code for the fidget spinner project. The code and part of the code description both come from The Nature of Code, Example 2.6. Simon explains that the code below has a non-static radius, because he is dealing with x and y coordinates and not angles (i.e. not spinning but moving to where the mouse is). He says he is going to use that code as a foundation. The second step will be to rely on angles instead of x and y coordinates. The third step will be to rotate have the fidget spinner keep rotating and to apply a friction force to make it stop eventually.
Simon recorded this video, where he ponders on the possibilities for the fidget spinner code:
Simon wrote the rest of this post:
Description:
This is the code for clicking and dragging an object around the screen.
To do that, you need the following data:
  • mass (radius of the object)
  • location (position of the object)
  • dragging (Is the object being dragged?)
  • rollover (Is the mouse over the object?)
  • dragOffset (offset for when the object is clicked on)

And the following functionality:

  • clicked (checks if the object is hovered over and sets dragging to true)
  • hover (checks if the object is hovered over and sets rollover to true)
  • stopDragging (sets dragging to false)
  • drag (moves the object around the screen according to the mouse)
Code and Pseudocode:
Fidget Spinner Simulation
 – Prepare mouse interaction code
  – Data (mass, location, dragging, rollover, dragOffset)
  – Functionality (clicked, hover, stopDragging, drag)
  – Code (Mover)
   – Variables
float mass;
PVector location;
boolean dragging = false;
boolean rollover = false;
PVector dragOffset;
– Functions
void clicked(int mx, int my) {
  float d = dist(mx,my,location.x,location.y);
  if (d < mass) {
    dragging = true;
    dragOffset.x = location.x-mx;
    dragOffset.y = location.y-my;
  }
}

void hover(int mx, int my) {
  float d = dist(mx,my,location.x,location.y);
  if (d < mass) {
    rollover = true;
  }
  else {
    rollover = false;
  }
}

void stopDragging() {
  dragging = false;
}



void drag() {
  if (dragging) {
    location.x = mouseX + dragOffset.x;
    location.y = mouseY + dragOffset.y;
  }
}
  – Code (Main)
   – Variables
Mover m;
   – Functions
void draw() {
  m.drag();
  m.hover(mouseX,mouseY);
}

void mousePressed() {
  m.clicked(mouseX,mouseY);
}

void mouseReleased() {
  m.stopDragging();
}

For Mom’s birthday 

For my birthday, Simon made me some Fireworks:

He made them look even better the following day, by adding trails:

The code is Simon’s translation into Lua (the language of the Codea app) of Daniel Shiffman’s Fireworks Coding Chalenge (JavaScript).

We’ve also thoroughly enjoyed our birthday weekend at Brugge and especially Knokke. Fine to discover such fabulous beaches in the neighborhood. Simon loves water. Perhaps, because it is somehow related to the fluidity and of his mind and because of the freedom water provides to his body.

Preparing to give Dad some Processing Lessons

Simon has been giving Dad some lessons in Processing (Java), following the chapters in Daniel Shiffman’s book The Nature of Code. The have already finished Chapetr 1 (Vectors) and moved on to Chapetr 2 (Forces). I hadn’t realized until recently however that Simon doesn’t simply download all the examples for the lessons from the Processing website but manually writes them over from the html version of the book instead (to style them the way they are in the book, he said). It’s a amazing how organized he is at doing that and saving his files in separate folders.

Testing his examples Simon actually found a mistake in the book and Daniel Shiffman asked him to create an issue about it on the book’s GitHub’s page: https://github.com/shiffman/The-Nature-of-Code/issues/133

DSC_0120