Skip to content

Instantly share code, notes, and snippets.

@wwwaldo
wwwaldo / knn.py
Created August 6, 2018 19:17
KNN example from Grokking Algorithms.
import numpy as np
import math
import unittest
import sys
import matplotlib.pyplot as plt
import heapq
# k neighbours for oranges and grapefruits. tested function calls before running.
def knn(k, datastore, fruit):
@wwwaldo
wwwaldo / symsolve.mpl
Last active November 10, 2017 01:12
This is a small extension I wrote in the Maple programming language during a summer research project in 2017. Maple is a symbolic and numerical mathematical computation engine, like Mathematica and MATLAB: https://www.maplesoft.com/products/Maple/ .
# Last updated: July 31 2017
# Author: Caroline Lin
# Written for Maple 2016, on Ubuntu Linux 16.04 LTS.
#
# Typical usage
#
# Comments
# * for approximate case, inequalities must be specified in terms of the approximated functions
# e.g. f(u) <> 3 should be replaced by f(v[0][0]) <> 3
# otherwise rifsimp will error later on.
@wwwaldo
wwwaldo / symsolve.mpl
Created November 10, 2017 00:50
This is a small extension I wrote in the Maple programming language during a summer research project in 2017. Maple is a C-like programming language.
# Last updated: July 31 2017
# Author: Caroline Lin
# Written for Maple 2016, on Ubuntu Linux 16.04 LTS.
#
# Typical usage
#
# Comments
# * for approximate case, inequalities must be specified in terms of the approximated functions
# e.g. f(u) <> 3 should be replaced by f(v[0][0]) <> 3
# otherwise rifsimp will error later on.
@wwwaldo
wwwaldo / gist:0e69e568c8910b04e5a2da21744f89aa
Created July 27, 2017 15:29
Get OpenGL up on Ubuntu 16.04 LTS
Two libraries:
* GLUT
* GLUI
* Mesa-utils
**ASIDE**
do
sudo apt-cache search "your search here"
to do a search of the ubuntu repo.
math riddle of the day: Recall that orthogonal matrices are defined to be the (n by n) matrices over R^n for which (A^T A = A A^T = Identity), or equivalently, dotprod(x,y) = dotprod(Ax,Ay) for all x,y in R^n (inner-product preserving).
If A is an orthogonal matrix, we can show that its determinant must be either +-1.
Is the converse true? e.g. do all matrices with det 1 preserve inner products?
if so, prove it, if not, provide a counterexample.
i. Proof. First note that det A = det A^T by a handy theorem in Ch. 4 of FIS. Also det A det B = det AB by the same book.
So that A A^T = I implies (det A)^2 = 1 implies det A = +- 1.
ii. The converse is not true: let A be the matrix [1 1][1 0]. The basis vectors e_1, e_2 are sent to e_1, (1, 1) by this transformation
respectively. The dot product of the former is 0 (yay orthogonality) but the dot product of the latter is 1.