This file contains 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
## Demo | |
set.seed(12321) | |
W_all_test1 = list(matrix(rnorm(1, 0, 0.5), nc = 1), matrix(10, nc = 1)) | |
b_all_test1 = list(matrix(rnorm(1, 0, 0.5), nc = 1), matrix(-5, nc = 1)) | |
X = matrix(rnorm(200, 0, 2), ncol = 1) | |
Y = apply(X, 1, function(x){forward_propagation(x, W_all_test1, b_all_test1)}) | |
X.train = X[1:150,] | |
Y.train = Y[1:150] | |
X.test = X[151:200,] | |
Y.test = Y[151:200] |
This file contains 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
cppFunction(' | |
std::vector<int> c_which(NumericVector x, Function f, List args){ | |
std::vector<int> ind = as< std::vector<int> >(f(x, args)); | |
std::vector<int> out(ind); | |
std::vector<int>::iterator it; | |
int j = 0; | |
it = std::find(ind.begin(), ind.end(), 1); | |
while(it++ != ind.end()){ | |
out[j++] = it - ind.begin(); | |
it = std::find(it, ind.end(), 1); |
This file contains 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
set.seed(1001) | |
x = rbind(cbind(rnorm(50, 1, 0.3), rnorm(50, 2, 0.3)), cbind(rnorm(50, 2, 0.3), rnorm(50, 1, 0.3))) | |
y = c(rep(1, 50), rep(-1, 50)) | |
h <- function(param, C = 1){ | |
b = param[length(param)] | |
w = param[-length(param)] | |
g = y * (x %*% w + b) | |
0.5 * w %*% w + C * sum(1 - g[g < 1]) | |
} |
This file contains 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
library(data.table) | |
library(rbenchmark) | |
library(doMC) | |
registerDoMC(4) | |
set.seed(42) | |
nrows = 1e5 | |
nsearch = 1e3 | |
d = data.frame(a = sample(letters, nrows, rep = T), b = sample(1:nrows, rep = T), c = runif(nrows)) | |
d.dt = data.table(d, key = 'a,b') |
This file contains 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
##+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ | |
## Created by: Hang Zhang, Rutgers University, Email: [email protected] | |
## Modified by Thomas Wolf, HuggingFace Inc., Email: [email protected] | |
## Copyright (c) 2017-2018 | |
## | |
## This source code is licensed under the MIT-style license found in the | |
## LICENSE file in the root directory of this source tree | |
##+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ | |
"""Encoding Data Parallel""" |