Skip to content

Instantly share code, notes, and snippets.

View dz1984's full-sized avatar

Donald Zhan dz1984

View GitHub Profile
@dz1984
dz1984 / MLA_errata.md
Last active June 22, 2019 05:09
初探機器學習演算法(Machine Learning Algorithms) 勘誤表
  • P.18 第一段第二行 許多情況下的靜態學習做了相當廣泛的討論,按原文為 there's also a very extensive discussion on statistical learning in many different contexts,因此,靜態學習應修正為統計學習。
@dz1984
dz1984 / Weierstrass_function.r
Created January 24, 2018 14:55
魏爾斯特拉斯函數(Weierstrass function)是一類處處連續而處處不可導的實值函數。 https://imgur.com/w9RNrxO
# Weierstrass function
# Ref - https://zh.wikipedia.org/wiki/魏尔斯特拉斯函数
g = function(x) unlist(Map(function(n) 0.5^n * cos(3^n * pi * x),seq(0,644)))
f = function(x) Reduce(function (x, y) x+y, g(x))
x = seq(-2,2,0.001)
plot(x,lapply(x,f),type='l')
@dz1984
dz1984 / automata_你還跑_errata.md
Last active August 18, 2017 20:57
勘誤表 for AUTOMATA 你還跑!- Automata 及 Formal Language 導論 ISBN: 9789571443782
  • P.73 圖 3-38 {B,C} -> {C} 的移轉字母原為 "0" ,應修正為 "2"。
  • P.79 最後 1 行,"略略" 修正為 "省略"。
  • P.87 Homework 4-1 的 L2 ,因上標 "+" 未定義,可以 "*" 取代。
  • P.164 圖 5-41 Mealy machine 原為 D -> A,應修正為 A -> D。
  • P.165 倒數第 2 行,「且整個電路的輸入是 1」,應修正成 0 。
  • P.166 圖 5-43 原為 C -> B ,應修正為 B -> C 。
  • P.224 倒數第 2 行,「例如當有一句子 a + a 作為...符合推導式」,應修正為 a * a 。
  • P.225 倒數第 1 行,「如此一來...輸入 a + a * a 是...」,應修正為 a * a 。
  • P.275 表 7-1 由下往上數的第6列和第10列,原為 read 3 和 read 2 應修正為 read 2 和 read 3。
  • P.303 圖 8-10 從 STATE A 往下數 第 8 行,原為 E,應修正為 G。
@dz1984
dz1984 / BPN_with_Unity3D.r
Created August 3, 2017 12:51
Try to simulate the BPN in R.
options(digits=6)
active = function(x) 1/ (1+exp(1)^(-x))
mse = function(x) 0.5 * (1.0 - x)^2
p = 0.5
u1 =0
u2 = 1
w31 = 1
w41 = -1.0
@dz1984
dz1984 / lisp_evaluator.rkt
Created July 13, 2017 12:29
A part of code to implement the metacircular evaluator on Chapter 4 of SICP.
#lang racket
(require r5rs)
;;;
(define apply-in-underlying-scheme apply)
;;; ENVIROMENT PART BEGIN
(define (enclosing-enviroment env) (cdr env))
(define (first-frame env) (car env))
@dz1984
dz1984 / church_number.rkt
Created July 4, 2017 13:28
Using Racket to implement operators in the lambda calculus for Church number.
#lang racket
(define zero
(lambda (f)
(lambda (x) x)))
(define (add-1 n)
(lambda (f)
(lambda(x) (f ((n f) x)))))
@dz1984
dz1984 / brainfuck.rkt
Last active June 30, 2017 22:17
A simple brainfuck interpreter in Scheme.
#lang racket
(define-syntax incf
(syntax-rules ()
((_ x) (begin (set! x (+ x 1)) x))
((_ x i) (begin (set! x (+ x i)) x))))
(define-syntax decf
(syntax-rules ()
((_ x) (begin (set! x (- x 1)) x))
@dz1984
dz1984 / brainfuck.c
Last active July 1, 2017 01:23
A simple brainfuck interpreter.
#include <stdio.h>
#include <stdlib.h>
#define MEM_SIZE 3000
void interpret(char* instruction) {
unsigned char* tape = (unsigned char*)malloc(MEM_SIZE * sizeof(char));
unsigned char* ptr = &tape[0];
for (;*instruction; ++instruction) {
(function(){
console.log('script init');
var Vertox = function(label){
var _str = function(label) {
return 'Vectox['+ label + ']';
};
return {
label: label,
@dz1984
dz1984 / Buffer.js
Created June 4, 2015 10:31
Practice to implement the Buffer pattern.
Buffer = {
commands: [],
add: function(fn) {
var commands = this.commands;
var next = function() {
commands.shift();
if (commands.length) commands[0](next);
};