Skip to content

Instantly share code, notes, and snippets.

View angeris's full-sized avatar
😄

guille angeris

😄
View GitHub Profile
@angeris
angeris / Matrix.java
Last active August 31, 2016 17:03
A simple, naive Matrix class with QR factorization, back-substitution, and least squares in Java for use in Hackerrank's easier Statistics/Machine Learning problems
/*
* I threw together this set of classes to work on Hackerrank's stuff at a fairly low level. Of
* course, you are provided with several libraries to do this for you, such as Weka, which makes
* life quite a bit easier than setting up your own feature matrix. But for those who want to
* have the simple stuff such as naive QR using Gram-Schmidt, back-substitution, and school-book
* matrix multiplication, this will work. Even for fairly large datasets within Hackerrank
* the performance is fast enough to give a very wide margin of extra time. Enjoy!
*
* Guille (@Guillean)
*/
@angeris
angeris / estimate_crappy_pi.py
Last active August 31, 2016 17:04
Runs different, crappy ways of estimating Pi
from numpy import *
N, L = 1e8, 10
print("Here's your crappy estimation of pi: {}".format((sum(exp(-(random.rand(N)*2*L-L)**2))*2*L/N)**2))
@angeris
angeris / union_find.py
Last active August 31, 2016 16:54
A simple (but complete) union-find structure in Python.
# Author: Guillermo Angeris (@guillean)
# Simple UnionFind based on https://www.cs.princeton.edu/~rs/AlgsDS07/01UnionFind.pdf
class UnionFind:
def __init__(self):
self.rank = {}
self.parent = {}
def add(self, elem):
self.rank[elem] = 1
@angeris
angeris / domino_counter_example.txt
Last active July 13, 2018 13:32
Greedy Counterexample for Dominos
Initial positions
Player A:
[0-5] [1-3] [1-4] [2-2] [3-4] [4-4] [5-6]
Player B:
[0-0] [0-1] [0-6] [1-1] [1-6] [2-3] [2-6]
Player C:
[0-2] [2-4] [2-5] [3-3] [3-6] [4-5] [4-6]
Player D:
[0-3] [0-4] [1-2] [1-5] [3-5] [5-5] [6-6]
@angeris
angeris / learn_sum.py
Created May 28, 2018 05:35
Learns the sum of two numbers. In response to an hn comment.
import numpy as np
X = np.array([
[1, 4],
[20, 35],
[8, 15]
])
y = np.array([3, 15, 7])
opt_theta = np.linalg.lstsq(X, y)
@angeris
angeris / jump-v.18-sample.jl
Last active April 18, 2019 18:50
MWE for reproducing large performance decrease for JuMP v0.18.5
using JuMP
using ProgressMeter
using LinearAlgebra
using SparseArrays
import Gurobi
# Formulates ‖x‖² ≤ y as an SOC
function quad_cons(m, x, y)
@constraint(m, sum(x.^2) ≤ y )
end
@angeris
angeris / jump-v.19-sample.jl
Last active April 18, 2019 20:06
MWE for reproducing large performance decrease for JuMP v0.19
using JuMP
using LinearAlgebra
using SparseArrays
# Formulates ‖x‖² ≤ y as an SOC
function quad_cons(m, x, y)
@constraint(m, sum(x.^2) ≤ y )
end
const t_min = 1
@angeris
angeris / test_diffcpsdp_example.jl
Created April 21, 2019 00:35
Naïve translation of `cvxpy/tests/test_benchmarks.py` to JuMP.
using JuMP
using LinearAlgebra
using BenchmarkTools
using ProgressMeter
import Random
import SCS
Random.seed!(1234)
function randn_symm(n)

Keybase proof

I hereby claim:

  • I am angeris on github.
  • I am angeris (https://keybase.io/angeris) on keybase.
  • I have a public key ASDT_GHDJohjVhunI0yCpEHqZH_yvzT0KEkNhjkOXA1-LQo

To claim this, I am signing this object:

import numpy as np
import cvxpy as cp
import matplotlib.pyplot as plt
# The idea is that we have two circles, in opposite corners
# that need to move past each other during optimization (in order to minimize
# some simple objective function). The important thing to guarantee
# is that they do not intersect at any point during any iteration.
# Initial/desired positions of circles, radius = 1/4.