Skip to content

Instantly share code, notes, and snippets.

Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
@yuzeh
yuzeh / minimal.pgn
Last active April 7, 2019 22:18
Minimal PGN file required for bayeselo to read properly
; bayeselo (https://www.remi-coulom.fr/Bayesian-Elo/) will read this file properly.
;
; Notes
;
; 1. Use typical chess notation for game results:
; - "1-0" for a white win
; - "0-1" for a black win
; 2. It seems like some chess moves are needed for it to parse properly, which is why
; the end of each line has `1. c4 Nf6`.
;
@yuzeh
yuzeh / 2018-07-23-keras-sample_weight.ipynb
Created July 24, 2018 00:30
2018-07-23-Keras-sample_weight.ipynb
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
@yuzeh
yuzeh / feedrandom.js
Last active November 22, 2018 20:11
A small script for recording and feeding values into `Math.random` in JavaScript
// MIT License
//
// Copyright (c) 2018 Yuze Huang ([email protected])
//
// Permission is hereby granted, free of charge, to any person obtaining a copy
// of this software and associated documentation files (the "Software"), to deal
// in the Software without restriction, including without limitation the rights
// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
// copies of the Software, and to permit persons to whom the Software is
// furnished to do so, subject to the following conditions:
@yuzeh
yuzeh / masked_softmax.py
Last active September 14, 2020 15:17
A PyTorch implementation of a softmax function where support of the underlying categorical distribution is given as input. Useful for, e.g., learning discrete policies where certain actions are known a-priori to be invalid.
# MIT License
#
# Copyright (c) 2018 Yuze Huang ([email protected])
#
# Permission is hereby granted, free of charge, to any person obtaining a copy
# of this software and associated documentation files (the "Software"), to deal
# in the Software without restriction, including without limitation the rights
# to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
# copies of the Software, and to permit persons to whom the Software is
# furnished to do so, subject to the following conditions:
@yuzeh
yuzeh / lad_regression.py
Last active September 28, 2017 07:03
LAD Regression
import numpy as np
from cvxopt import matrix, solvers
def solve(X, y, l = 0.0):
'''Solves the LAD regression problem, which can be formulated as:
minimize || X a - y ||_1 + l * || a ||_1
a
X: numpy ndarray with shape (n, m)
@yuzeh
yuzeh / LengauerTarjan.scala
Last active October 23, 2024 21:59
Lengauer-Tarjan Dominator Tree Algorithm
object LengauerTarjan {
// Implement these three yourself
def successors(v: Int): Iterable[Int] = ???
def predecessors(v: Int): Iterable[Int] = ???
def numNodes: Int = ???
// Lifted from "Modern Compiler Implementation in Java", 2nd ed. chapter 19.2
def computeDominatorTree(): Array[Int] = {
var N = 0