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 | |
------------------------------ | |
require 'torch' | |
require 'nn' | |
require 'cunn' | |
require 'cudnn' |
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
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) |
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
#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); |
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
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 |
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
# = = = = = 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)) |
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
# = = = = = include = = = = = # | |
library(MASS) | |
# = = = = = function = = = = = # | |
obj_func <- function(y, A, x, lambda){ | |
obj_value <- 0.5 * sum((y - A%*%x)^2) + lambda * sum(abs(x)) | |
} |
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
## = = = = = include = = = = = ## | |
library(MASS) | |
## = = = = = function = = = = = ## | |
obj_func <- function(y, A, x, lambda){ | |
obj_value <- 0.5 * sum((y - A%*%x)^2) + lambda * sum(abs(x)) | |
} |
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
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() |
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
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) |