Coding, Community Projects, Contributing, Experiments, JavaScript, live stream, Machine Learning, Milestones, Physics, Simon's Own Code

Simon’s Random Number Generator

This one’s back from mid-October, forgot to post here.

Simon created a random number generator that generates a frequency, and then picks it back up. Then, it calculates the error between the generated frequency and the picked up frequency. This is one of my community contributions for a Coding Train challenge: https://thecodingtrain.com/CodingChallenges/151-ukulele-tuner.html

Link to project: https://editor.p5js.org/simontiger/sketches/eOXdkP7tz
Link to the random number plots: https://www.wolframcloud.com/env/monajune0/ukalele%20tuner%20generated%20random%20number%20analysis.nb
Link to Daniel Shiffman’s live stream featured at the beginning of this vid: https://youtu.be/jKHgVdyC55M

plot of the random numbers generated by Simon’s ukulele tuner random number generator (plotted in Wolfram Mathematica)
Coding, Computer Science, Contributing, Group

Example of Simon contributing an issue on GitHub

Below is Simon’s issue/ topic suggestion he contributed to the Coding Train GitHub yesterday, addressed to Daniel Shiffman:

Function Overloading

Nah.

Operator Overloading

OK, first, we have to understand the valueOf() function. valueOf() is a function, that typically performs on a string, that converts it into a “primitive” data type.

A number is a primitive data type, because it’s not an object. And, you can see that by opening a Terminal window, running node and type:

> 2 + 2 // and get
4

Because JS doesn’t have any “real” overloading, you can’t put + in between two objects, in between two objects, and get an answer!

Well, with one slight exception, which is the valueOf() function. It will tell JS how to interpret an instance of an object as a primitive data type, whenever you want to add them together or something. If you put a valueOf() function into the prototype (or class, if you will) of an object, and it converts it into a number, or some other primitive data type, you can suddenly do arithmetic on these objects!

This does have a limitation, though. Say you write a class:

class Vector {
  constructor(x=0, y=0) {
    this.x = x;
    this.y = y;
  }

  // Maybe you want a valueOf() function to add them together
  valueOf() {
    // TL;DR What goes here???
  }
}

Maybe you want to add the individual components of a vector to add two vectors together.
It turns out, the answer is, nothing can go in the place of the question mark!

Here’s why: There’s no real primitive data type, with further components. That’s because that’s what a primitive data type is! It doesn’t have data, it is it’s own data! A Vector does have further components, however, and so we arrive at a contradiction. Because a vector has further components, and valueOf() must return something without further components, this situation is impossible!

String Overloading

Well, it’s really the same as Operator Overloading, except you need to use the toString() function instead of the valueOf() function. It converts it into a string. I don’t really know why you’d want to do this, maybe you would affect how you print it. I actually don’t even know if toString() can do this.

[TL;DR] Overloading

Look at this messy video about Matrix Math that you made: https://www.youtube.com/watch?v=NgZAIkDcPkI, at 23:15.

Guess what, there’s a way to fix that!

I don’t know how this one is called. When you say this, it’s an object. But, because objects are associative arrays, you can actually treat this as an associative array! Something like this:

class Matrix {
  constructor(rows, cols) {
    this.rows = rows;
    this.cols = cols;
    // this.data = []

    for (let i = 0; i < this.rows; i++) {
      this[i] = []; // OMG
      for (let j = 0; j < this.cols; j++) {
        this[i][j] = 0; // OMG
      }
    }
  }
  // .
  // .
  // .
}

It’s as easy as that!
If you want to, you could even add a this.length variable, and suddenly, you would even be able to iterate over it, with a for..of loop!

Coding, Community Projects, Computer Science, Contributing, Geometry Joys, Group, Milestones, Murderous Maths, Notes on everyday life

More examples of Simon’s chat contributions on math and coding

Simon is always extremely active in the discussions about the current projects made by/ lectures given by NYU’s Asdociate Professor Daniel Shiffman during his live sessions on the Coding Train channel. He also enjoys “initiating discussions” among the channel’s patrons (grown-up programmers) and Daniel. “Mom, the discussion I initiated is still going on!” I couldn’t possibly post all the coding and math comments/ suggestions that Simon makes in the chats on YouTube, Slack and GitHub (and I don’t believe I should either), but every now and then, I like collecting samples of Simon’s contributing to the discussion:

Simon contributing to a discussion prior to a live session on ray tracing
Simon contributing to Daniel Shiffman’s tutorial on the computational geometry “minimum spanning tree” problem

The small font above says:

Correction: The MST problem does not allow any loops (like A->B, B->C, C->D, D->A again.) So the solution at 2:30 is wrong! In fact, _no wonder it does that_, because Prim’s Algorithm will never find a loop. Here’s why:

Let’s suppose that it could find a loop (let’s say, a loop of 4, so A->B, B->C, C->D, D->A again, but this argument would work the same each way.) Ok, so it will start from A, and mark it as reached. It will check A against B, C and D, find B, and mark B as reached. Then, it will check A against C and D, and B against C and D. and it will find that it should connect B and C, and mark C as reached. Then, it will check A, B and C all against D, and find that it should connect C and D, and mark D as reached. But now, we reach a problem. It will not connect D and A, because both are already reached!

Why was it designed like that? Because that’s what the problem says! It’s a Minimum Spanning _Tree_, so it can’t have any loops.

So there you go, that’s why Prim’s algorithm will not find a loop.

Coding, Computer Science, Contributing, Group, Milestones

Simon’s Computer Science Algorithm Suggestions

Simon’s suggestion for the Coding Train on GitHub:

Because I like computer science these days, here are some computer science algorithm suggestions:

  • Data Structures
    • Array
    • Linked List
    • Hash Table
    • Stack
    • Queue
    • Priority Queue (Binary heap)
    • Suffix Array
    • Graph Theory
      • Graph (general)
      • Tree
      • Binary Tree
        • Full vs. Complete
        • BST
        • Binary Heap
        • AVL Tree
        • Red-Black Tree
        • Segment Tree
        • DFA
      • Biparite
      • UFDS
      • Fenwick Tree
      • Min Spanning Tree
      • Suffix Tree
    • Computational Geometry
      • Polygon, etc.
  • Algorithms
    • Shuffling
      • Fisher-Yates Algorithm
    • Sorting
      • Bubble Sort
      • Selection Sort
      • Insertion Sort
      • Merge Sort
      • Quicksort
      • Counting Sort
      • Radix Sort
      • More?
      • Even More? (Scroll down to see a GIANT table)
    • Traversal / Pathfinding / SSSP
      • Basic
        • Pre-order
        • In-order
        • Post-order
        • Depth-first
        • Breadth-first
        • More?
      • Shortest Pathfinding
        • Dijkstra’s Shortest Path
        • A*
      • More?
      • Even More?
    • Substring Finding
    • Min Spanning Tree
      • Brute-force
      • Kruskal’s Algorithm
      • Prim’s Algorithm(s)
    • Max-flow
    • Graph Matching
    • Cycle Finding
    • Convex Hull
      • Gift Wrapping
      • Graham Scan
      • Quickhull
      • “The Ultimate Planar Convex Hull Algorithm”
      • More?
    • Min Vertex Cover
      • Brute-force
      • MVC
      • Approximation
    • Traveling Salesman
      • Brute-force
      • Dynamic Programming
      • Approximation
    • Steiner Tree

If you’re brave, Do you want more even after all of this?
One last note: you’re not going to do all of them (probably!).

Coding, Coding Everywhere, Group, Machine Learning, Milestones, Murderous Maths, Notes on everyday life, Physics

Fluid Dynamics: Laughing and Crying

Simon was watching Daniel Shiffman’s live coding lesson on Wednesday, and when fluid dynamics and Navier-Stokes equations came up (describing the motion of fluid in substances and used to model currents and flow), Simon remarked in the live chat that the Navier–Stokes equations are actually one of the seven most important unsolved math problems and one can get a million dollar prize for solving them, awarded by the Clay Mathematics Institute.

(I looked this up on Wikipedia and saw that it has not yet been proven whether solutions always exist in 3D and, if they do exist, whether they are “smooth” or infinitely differentiable at all points in the domain).

We had read an in-depth history of the Navier–Stokes equations in Ian Stewart’s book several weeks ago, but I must confess I didn’t remember much of what we’d read anymore. “Is it that chapter where Stewart describes how Fourier’s paper got rejected by the French Academy of Sciences because his proof wasn’t rigid enough?” I asked Simon. – “No, Mom, don’t you remember? That was Chapter 9 about Fourier Transform! And the Navier-Stokes equations was Chapter 10!” – “Oh, and the Fourier Transform was also the one where there was a lot about the violin string, right?” – “No!”, – Simon really laughs at me by now, – “That was in Chapter 8, about the Wave Function! You keep being one chapter behind in everything you say!” Simon honestly finds it hilarious how I can’t seem to retain the information about all of these equations after reading it once. I love his laugh, even when he’s laughing at me.

Today though, he was weeping inconsolably and there was nothing I could do. Daniel Shiffman had to cancel the live session about CFD, computer fluid dynamics. Simon had been waiting impatiently for this stream. My guess, because it’s his favourite teacher talking about something interesting from a purely mathematical view, a cocktail of all things he enjoys most. And because he never seems to be able to postpone the joy of learning. He had explained to me once that if he has this drive inside of him to conduct a certain experiment or watch a certain tutorial now, he simply can’t wait, because later he doesn’t seem to get the same kick out of it anymore.

I’m baking Simon’s favourite apple pie to pep him up. Here are a couple more screen shots of him taking part in the Wednesday lesson:

Coding, live stream, Milestones, Murderous Maths, Simon teaching

Daniel Shiffman quotes Simon’s thoughts about complex numbers

NYU’s Associate Professor Daniel Shiffman quotes Simon during a Coding Train live tutorial from New York about Fourier Transform Drawings on 16 January 2019. Simon was participating via the Slack chat. This is just an example of how Simon takes part in the live sessions on a regular basis.

Link to the actual live stream: https://www.youtube.com/watch?v=0b3R8oWffkw

Coding, Community Projects, Contributing, JavaScript, live stream, Machine Learning, Milestones, Murderous Maths, neural networks, Notes on everyday life, Set the beautiful mind free, Simon teaching, Trips

Simon took part in a Coding Train livestream in Paris!

Simon and Daniel Shiffman after the livestream

The video below is part of Daniel Shiffman’s livestream hosted by GROW Le Tank in Paris on 6 January 2019 about KNN, machine learning, transfer learning and image recognition. Daniel kindly allowed Simon to take the stage for a few minutes to make a point about image compression (the algorithm that Daniel used was sort of a compression algorithm):

Here is a different recording (in two parts) of the same moment from a different angle:


Coding, JavaScript, live stream, Living Code, Math Tricks, Murderous Maths, Simon teaching, Simon's Own Code

Live Stream #15. Chapter 6 of Living Code: Particle Systems

Simon’s latest Live Stream about Chapter 6 of his “Living Code” Course (particle systems!), loosely based on Daniel Shiffman’s Nature of Code. “I’m also going to live stream a surprise maths video”, – at the beginning of the stream Simon devoted some time to the magic hexagon problem.