Skip to content

Instantly share code, notes, and snippets.

import numpy as np
from numpy.linalg import norm, solve
from scipy.spatial.distance import cdist
from sklearn.neighbors import kneighbors_graph
def phi(l, mu):
return (mu * (np.sqrt(l) - 1)**2)
@rygorous
rygorous / gist:00b85cd98be3c53e17ab77d931493609
Last active July 29, 2017 01:25
FFT via ring morphisms.
Pick a 2n-element periodic sequence of complex numbers. This is isomorphic to a polynomial p in
C[x] / (x^2n - 1)
(x^2n = 1 = x^0, which encodes the 2n-periodicity).
Computing the 2n-element DFT of the original sequence is just evaluating p at the roots of unity
(\omega_{2n}^0, \omega_{2n}^1, ..., \omega_{2n}^{2n+1}).
Now, (x^2n - 1) = (x^n - 1) (x^n + 1). This implies that the given p mod (x^2n - 1) is uniquely
determined by the remainders p mod (x^n - 1) and p mod (x^n + 1) [via CRT]. That is, there is
an isomorphism between C[x] / (x^2n - 1) and (C[x] / (x^n - 1)) x (C[x] / (x^n + 1)).
@shagunsodhani
shagunsodhani / KeyValueMemNN.md
Last active April 30, 2023 04:13
Summary of paper "Key-Value Memory Networks for Directly Reading Documents"

Key-Value Memory Networks for Directly Reading Documents

Introduction

  • Knowledge Bases (KBs) are effective tools for Question Answering (QA) but are often too restrictive (due to fixed schema) and too sparse (due to limitations of Information Extraction (IE) systems).
  • The paper proposes Key-Value Memory Networks, a neural network architecture based on Memory Networks that can leverage both KBs and raw data for QA.
  • The paper also introduces MOVIEQA, a new QA dataset that can be answered by a perfect KB, by Wikipedia pages and by an imperfect KB obtained using IE techniques thereby allowing a comparison between systems using any of the three sources.
  • Link to the paper.

Related Work

@karpathy
karpathy / pg-pong.py
Created May 30, 2016 22:50
Training a Neural Network ATARI Pong agent with Policy Gradients from raw pixels
""" Trains an agent with (stochastic) Policy Gradients on Pong. Uses OpenAI Gym. """
import numpy as np
import cPickle as pickle
import gym
# hyperparameters
H = 200 # number of hidden layer neurons
batch_size = 10 # every how many episodes to do a param update?
learning_rate = 1e-4
gamma = 0.99 # discount factor for reward
@kylemcdonald
kylemcdonald / Class similarity.ipynb
Last active May 13, 2019 13:58
Finding similarities with a neural network that trained for object classification.
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
@alertedsnake
alertedsnake / gist:7dd9b87e47b1246fab93
Last active August 17, 2020 08:08
Use custom node + npm for Jenkins job
# setup python virtualenv and install nodeenv
virtualenv .python
. .python/bin/activate
pip install nodeenv
# setup nodeenv with the node of your choice, and upgrade npm to latest
nodeenv --node=0.10.37 --prebuilt .node
. .node/bin/activate
npm install -g npm
@yomotsu
yomotsu / gist:d845f21e2e1eb49f647f
Last active September 29, 2023 02:13
Intersection AABB - Plane ,Triangle - AABB, sphere - AABB, sphere - sphere, sphere - triangle, in three.js
var collision = {};
// aabb: <THREE.Box3>
// Plane: <THREE.Plane>
collision.isIntersectionAABBPlane = function ( aabb, Plane ) {
var center = new THREE.Vector3().addVectors( aabb.max, aabb.min ).multiplyScalar( 0.5 ),
extents = new THREE.Vector3().subVectors( aabb.max, center );
@patriciogonzalezvivo
patriciogonzalezvivo / GLSL-Noise.md
Last active June 2, 2024 09:14
GLSL Noise Algorithms

Please consider using http://lygia.xyz instead of copy/pasting this functions. It expand suport for voronoi, voronoise, fbm, noise, worley, noise, derivatives and much more, through simple file dependencies. Take a look to https://github.com/patriciogonzalezvivo/lygia/tree/main/generative

Generic 1,2,3 Noise

float rand(float n){return fract(sin(n) * 43758.5453123);}

float noise(float p){
	float fl = floor(p);
  float fc = fract(p);
@andrewsg
andrewsg / gist:e6c2298a8a9241a40964
Last active June 1, 2024 20:32
ADA talk on programming languages (notes for first half of lecture)

Programming as communication

Programming is about communication. It's communication between a human and a computer, but it's also communication between humans and other humans, and between humans and their own future selves. To program, you have to fully elucidate your ideas and record them so that both computers and humans can understand you.

Languages facilitate this kind of communication. Programming languages have to be designed with the computer in mind, but they should also be designed to accommodate humans.

Of course, using comments and out-of-code documentation, you can and should communicate to humans independently from your code. But the program code also needs to be its own documentation, both because actual code and its documentation frequently disagree and because sometimes program code is itself the most elegant way to express an idea.

Languages themselves are software, and they're made up of specificiations and implementations. Ideally, the specifications d

#!/usr/bin/ruby
# Create display override file to force Mac OS X to use RGB mode for Display
# see http://embdev.net/topic/284710
require 'base64'
data=`ioreg -l -d0 -w 0 -r -c AppleDisplay`
edids=data.scan(/IODisplayEDID.*?<([a-z0-9]+)>/i).flatten
vendorids=data.scan(/DisplayVendorID.*?([0-9]+)/i).flatten