Skip to content

Instantly share code, notes, and snippets.

View yangzhixuan's full-sized avatar

Zhixuan Yang yangzhixuan

  • Imperial College London
  • Web
View GitHub Profile
/**************************************************************
Problem: 1146
User: YangZX
Language: C++
Result: Accepted
Time:7192 ms
Memory:162696 kb
****************************************************************/
int getint(void);
@yangzhixuan
yangzhixuan / blocked_matrix_mul.c
Last active April 16, 2017 05:34
分块矩阵乘法效率的实验
/*
* 执行同等大小的矩阵乘法10次的总时间(gcc version 4.8.1, 64位linux),第一项是取块大小为50的分块乘法,第二项是朴素乘法
*
* 无任何优化选项
* 500*500 8.05s 8.52s
* 1000*1000 64.96s 111.66s
*
* 开启O2
* 500*500 1.78s 1.89s
* 1000*1000 14.46s 88.94s
@yangzhixuan
yangzhixuan / gist:9f19731dffb3c92cf409
Last active August 29, 2015 14:06
YangZX's implementation of red black tree
/* yangzx's red-black tree! */
#include <cstdio>
#include <algorithm>
#include <cstdlib>
using namespace std;
struct RBTree{
struct RBNode{
int val;
@yangzhixuan
yangzhixuan / gp_regression.m
Last active August 29, 2015 14:12
gaussian process
kernel = 2;
switch kernel
case 1; k = @(x, y) 1 * (x'*y + 1);
case 2; k = @(x, y) exp(-1 * (x-y)' * (x-y));
case 3; k = @(x, y) 1 * (x'*y + 1) * (x'*y + 1) + x'*y+1
case 4; k = @(x, y) 1 * min(x, y)
end
x_test = (0:.005:3)';
n_test = length(x_test);
@yangzhixuan
yangzhixuan / gist:5a79453d8f63a25cfac7
Created December 12, 2015 02:20 — forked from karpathy/gist:587454dc0146a6ae21fc
An efficient, batched LSTM.
"""
This is a batched LSTM forward and backward pass
"""
import numpy as np
import code
class LSTM:
@staticmethod
def init(input_size, hidden_size, fancy_forget_bias_init = 3):
@yangzhixuan
yangzhixuan / min-char-rnn.py
Created December 12, 2015 02:22 — forked from karpathy/min-char-rnn.py
Minimal character-level language model with a Vanilla Recurrent Neural Network, in Python/numpy
"""
Minimal character-level Vanilla RNN model. Written by Andrej Karpathy (@karpathy)
BSD License
"""
import numpy as np
# data I/O
data = open('input.txt', 'r').read() # should be simple plain text file
chars = list(set(data))
data_size, vocab_size = len(data), len(chars)
@yangzhixuan
yangzhixuan / categories.agda
Last active April 1, 2020 11:48
Agda formalisation of basic category theory
---
--- An exercise to get myself familiar with Agda by formalising category theory
--- to the extent that Yoneda lemma can be stated and proved.
--- (Agda version 2.6.1 and stdlib 1.3)
import Relation.Binary.PropositionalEquality as Eq
open Eq using (_≡_; refl; trans; sym; cong; cong-app; subst; cong₂)
open Eq.≡-Reasoning using (begin_; _≡⟨⟩_; _∎) renaming (step-≡ to _≡⟨_⟩_)
import Function.Base as Func
@yangzhixuan
yangzhixuan / church.hs
Last active August 23, 2020 09:46
Church encoding of initial algebras
{-# LANGUAGE RankNTypes, DeriveFunctor #-}
-- The usual recursive way of obtaining the initial algebra of a functor f
newtype Mu f = In { inOp :: f (Mu f) }
cata :: Functor f => (f a -> a) -> Mu f -> a
cata alg = alg . fmap (cata alg) . inOp
-- Church encoding of initial algebras
type Mu' f = forall a . (f a -> a) -> a
@yangzhixuan
yangzhixuan / HiParser.hs
Created September 13, 2020 15:03
Higher order parser combinator langauge
{-# LANGUAGE GADTs, TypeFamilies, DataKinds, TypeOperators, RankNTypes, PolyKinds #-}
module HiParser where
import Control.Monad.Trans.State.Lazy
import GHC.Types
-- All types of the parser language:
-- BaseTy: every Haskell type is a base type of the parser language
-- Arrow: function types of the parser language
data Tys = BaseTy GHC.Types.Type | Arrow Tys Tys
@yangzhixuan
yangzhixuan / PHOAS.hs
Created September 22, 2020 07:07
Parametric higher order syntax (PHOAS) for simply typed lambda calculus
{-# LANGUAGE RankNTypes, TypeApplications, DataKinds, KindSignatures, GADTs, TypeFamilies #-}
-- 1. Parametric higher order abstract syntax (PHOAS) of untyped lambda calculus
--------------------
data PTerm p = Var p | Lam (p -> PTerm p) | App (PTerm p) (PTerm p)
type Term = forall p . PTerm p
-- A semantic domain
data Dom = Embed { retract :: Dom -> Dom }