This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
archive: stuff you want to archive | |
$(eval DATE := $(shell date +'%F.%R')) | |
@mkdir -p .archive/$(DATE) | |
@rm -f .archive/$(DATE)/options.txt | |
@$(foreach V,$(sort $(.VARIABLES)),$(if $(filter-out environment% default automatic,$(origin $V)),echo '$V=$(value $V)' >> .archive/$(DATE)/options.txt;)) | |
@cp $^ .archive/$(DATE) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import numpy as np | |
def log_sum(X): | |
m = X.max(0) | |
r = np.exp(X - m).sum(0) | |
return m + np.log(r) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
log.sum <- function(x) { | |
m <- max(x) | |
r <- sum(exp(x - m)) | |
return m + log(r) | |
} | |
cdist <- function(X, Z) { | |
nX <- rowSums(X ** 2) | |
nX <- replicate(nrow(Z)) | |
nZ <- rowSums(Z ** 2) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# Script to help understanding of S3 object-oriented programming | |
# in R using classes and methods | |
# Constructor functions for various classes of animal | |
pig <- function() structure(list(), class=c("pig", "animal")) | |
dog <- function() structure(list(), class=c("dog", "animal")) | |
cat <- function() structure(list(), class=c("cat", "animal")) | |
makeSound <- function(x) UseMethod("makeSound") |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# Simple root finding using Newton's method | |
# | |
# Function to be optimized: f(x) = x^2 - 4 * sin(x) | |
import math | |
def objfun(x): | |
'''Compute the value and gradient of our function at x.''' | |
f = x**2 - 4 * math.sin(x) | |
fp = 2 * x - 4 * math.cos(x) |