Skip to content

Instantly share code, notes, and snippets.

View kgourgou's full-sized avatar
🪢
Back to tinkering

Kosti kgourgou

🪢
Back to tinkering
View GitHub Profile
@kgourgou
kgourgou / hilary_trump_nyt.py
Created November 9, 2016 02:39
For people that are bored of the sensationalism of the media and just want the cold, hard, fact.
"""
A hilary-endorsing script that loads the predictions from the NYT.
"""
import requests
from dateutil.parser import parse
# election forecast link
url = "https://intf.nyt.com/newsgraphics/2016/11-08-election-forecast/president.json"
req = requests.get(url)
function F = funm_randomized(A,fun)
%FUNM_RANDOMIZED Evaluate general matrix function using
% randomized approximate diagonalization method of Davies (2007).
tol = 8*eps(A(1,1)); % Tolerance for single or double precision A.
E = randn(size(A));
[V,D] = eig(A + (tol*norm(A,'fro')/norm(E,'fro'))*E);
F = V*diag(fun(diag(D)))/V;
@kgourgou
kgourgou / importance-sampling-example.py
Created June 1, 2017 08:22
Quick example demonstrating the importance sampling idea.
#
import scipy as sc
from scipy.stats import norm
N=100
M = 1000
nsamp = sc.zeros(M)
for i in range(M):
data=sc.randn(N)*0.1
@kgourgou
kgourgou / spacemacs-cheshe.md
Last active November 16, 2017 11:07 — forked from robphoenix/spacemacs-cheshe.md
Spacemacs Cheat Sheet

Useful Spacemacs commands

  • SPC q q - quit
  • SPC w / - split window vertically
  • SPC w - - split window horizontally
  • SPC 1 - switch to window 1
  • SPC 2 - switch to window 2
  • SPC w d - delete current window
  • SPC TAB - switch to previous buffer
  • SPC b b - switch buffers
from scipy import clip
def dict_clipper(dictionary):
"""
Clips all the numeric values of a dictionary so
that they lie within [0,1].
It recurses within inner dictionaries,
if any.
@kgourgou
kgourgou / cherry_tree.py
Created March 26, 2018 23:02
Converts a tree to cherry tree -- needs review.
def tree_to_cherry_tree(A):
"""
Given the adj matrix of a tree,
produces a cherry t-tree that includes it.
Arguments:
- adj: numpy array or sparse array, the adjacency matrix of the tree.
Returns:
- new_adj: numpy array or sparse array, the adjacency matrix of the cherry tree.
@kgourgou
kgourgou / .spacemacs
Created June 5, 2019 16:22
spacemacs file
;; -*- mode: emacs-lisp -*-
;; This file is loaded by Spacemacs at startup.
;; It must be stored in your home directory.
(defun dotspacemacs/layers ()
"Configuration Layers declaration.
You should not put any user code in this function besides modifying the variable
values."
(setq-default
;; Base distribution to use. This is a layer contained in the directory
import jax
import jax.numpy as jnp
def ent(X):
"""Calculates the entropy of a dataset X."""
N, D = X.shape # Get the number of samples and dimensions
# Compute pairwise squared distances