Skip to content

Instantly share code, notes, and snippets.

View toshi-k's full-sized avatar

toshi_k toshi-k

View GitHub Profile
@toshi-k
toshi-k / WeightSharing.lua
Created August 29, 2015 11:37
Random Weight Sharing (Torch 7)
local WeightShering, parent = torch.class('nn.WeightSharing','nn.Module')
function WeightShering:__init(inputSize, outputSize, factor)
-- initialize
parent.__init(self)
self.factor = factor
self.inputSize = inputSize
self.outputSize = outputSize
@toshi-k
toshi-k / RLReLU.lua
Last active August 29, 2015 14:25
Randomized LeakyReLU (Torch 7)
local RLReLU, parent = torch.class('nn.RLReLU','nn.Module')
function RLReLU:__init(l, u, version)
parent.__init(self)
self.train = true
self.l = l or 3
self.u = u or 8
self.v = version or 1
self.a = (self.u + self.u) / 2
self.ReLU_p = nn.ReLU()
@toshi-k
toshi-k / BlockPrincipalPivoting.r
Created August 14, 2015 09:12
Block principal pivoting algorithm for the L1-regularized linear regression (R)
# = = = = = include = = = = = #
library(MASS)
# = = = = = function = = = = = #
obj_func <- function(y, A, x, lambda){
obj_value <- 0.5 * sum((y - A%*%x)^2) + lambda * sum(abs(x))
}
@toshi-k
toshi-k / lista.cpp
Created September 6, 2015 11:48
Learned Iterative Shrinkage-Thresholding Algorithm (Rcpp)
#include <RcppArmadillo.h>
// [[Rcpp::depends(RcppArmadillo)]]
using namespace Rcpp;
using namespace arma;
using namespace std;
vec soft(vec x, double theta){
vec vec2 = abs(x) - theta;
uvec oth = uvec(vec2 > 0);
@toshi-k
toshi-k / RandomFeatureExtractor.lua
Last active May 3, 2016 15:23
Random Feature Extractor (Torch 7)
local RandomFeatureExtractor, Parent = torch.class('nn.RandomFeatureExtractor', 'nn.Module')
function RandomFeatureExtractor:__init(inputSize, outputSize, kmin, kmax)
Parent.__init(self)
self.mask = torch.Tensor(outputSize, inputSize):zero()
for i = 1,outputSize do
local num_samp = math.random(kmin, kmax, 1)
local index_samp = torch.randperm(inputSize)
@toshi-k
toshi-k / LReLU.lua
Last active June 6, 2016 11:10
LeakyReLU (Torch 7)
local LReLU, parent = torch.class('nn.LReLU','nn.Module')
function LReLU:__init(a)
parent.__init(self)
self.a = a or 0.1
self.ReLU_p = nn.ReLU()
end
function LReLU:updateOutput(input)
self.output:resizeAs(input)
@toshi-k
toshi-k / unet.lua
Created March 17, 2017 16:54
U-Net (Torch 7)
------------------------------
-- library
------------------------------
require 'torch'
require 'nn'
require 'cunn'
require 'cudnn'
@toshi-k
toshi-k / LagrangeDualDict.r
Last active December 28, 2017 08:45
Learning bases using the Lagrange dual (R)
# = = = = = include = = = = = #
library(MASS)
# = = = = = function = = = = = #
Obj_func <- function(Y,B,A,Lambda){
MAT <- t(Y) %*% Y - Y %*% t(A) %*% solve(A%*%t(A)+Lambda) %*% t(Y%*%t(A)) - Lambda
return <- sum(diag(MAT))
@toshi-k
toshi-k / FeatureSignSearch.r
Last active June 4, 2018 03:05
Feature-sign search algorithm (R)
## = = = = = include = = = = = ##
library(MASS)
## = = = = = function = = = = = ##
obj_func <- function(y, A, x, lambda){
obj_value <- 0.5 * sum((y - A%*%x)^2) + lambda * sum(abs(x))
}