Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
18 commits
Select commit Hold shift + click to select a range
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 7 additions & 2 deletions DESCRIPTION
Original file line number Diff line number Diff line change
@@ -1,10 +1,12 @@
Package: learner
Type: Package
Title: Latent Space-Based Transfer Learning
Version: 0.2.0
Version: 1.0.0
Authors@R: c(person("Sean", "McGrath", role = c("aut", "cre"),
email = "sean.mcgrath514@gmail.com",
comment = c(ORCID = "0000-0002-7281-3516")),
person("Ryan", "ODea", role = c("aut"),
email = "ryanodea@hsph.harvard.edu"),
person("Cenhao", "Zhu", role = c("aut"),
email = "cenhaoz@mit.edu"),
person("Rui", "Duan", role = c("aut"),
Expand All @@ -22,7 +24,10 @@ LazyData: true
RoxygenNote: 7.3.2
URL: https://github.com/stmcg/learner
BugReports: https://github.com/stmcg/learner/issues
Imports: doParallel, foreach, ScreeNOT
Imports: ScreeNOT,
Rcpp (>= 1.0.11),
RcppEigen
LinkingTo: Rcpp, RcppEigen
Suggests:
testthat (>= 3.0.0)
Config/testthat/edition: 3
Expand Down
5 changes: 3 additions & 2 deletions NAMESPACE
Original file line number Diff line number Diff line change
Expand Up @@ -3,5 +3,6 @@
export(cv.learner)
export(dlearner)
export(learner)
import(doParallel)
import(foreach)
import(RcppEigen)
importFrom(Rcpp,sourceCpp)
useDynLib(learner, .registration = TRUE)
3 changes: 2 additions & 1 deletion NEWS.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
### learner version 0.2.0 (TBD)
### learner version 1.0.0 (TBD)

* Implemented the optimization algorithm in Rcpp, resulting in significant computational speed-ups.
* Fixed a bug in `cv.learner` when `Y_target` has missing entries.

### learner version 0.1.0 (2025-01-08)
Expand Down
15 changes: 15 additions & 0 deletions R/RcppExports.R
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
# Generated by using Rcpp::compileAttributes() -> do not edit by hand
# Generator token: 10BE3573-1514-4C36-9D1C-5A225CD40393

learner_cpp <- function(Y_source, Y_target, r, lambda1, lambda2, step_size, max_iter, threshold, max_value) {
.Call(`_learner_learner_cpp`, Y_source, Y_target, r, lambda1, lambda2, step_size, max_iter, threshold, max_value)
}

cv_learner_cpp <- function(Y_source, Y_target, lambda1_all, lambda2_all, step_size, n_folds, max_iter, threshold, n_cores, r, max_value, index_set) {
.Call(`_learner_cv_learner_cpp`, Y_source, Y_target, lambda1_all, lambda2_all, step_size, n_folds, max_iter, threshold, n_cores, r, max_value, index_set)
}

omp_max_threads <- function() {
.Call(`_learner_omp_max_threads`)
}

156 changes: 0 additions & 156 deletions R/cv_learner.R

This file was deleted.

5 changes: 3 additions & 2 deletions R/dlearner.R
Original file line number Diff line number Diff line change
Expand Up @@ -54,8 +54,9 @@ dlearner <- function(Y_source, Y_target, r){
}

svd_source <- svd(Y_source, nu = r, nv = r)
dlearner_estimate <- (svd_source$u %*% t(svd_source$u)) %*%
Y_target %*% (svd_source$v %*% t(svd_source$v))
dlearner_estimate <- svd_source$u %*%
(t(svd_source$u) %*% Y_target %*% svd_source$v) %*%
t(svd_source$v)

colnames(dlearner_estimate) <- colnames(Y_source)
rownames(dlearner_estimate) <- rownames(Y_source)
Expand Down
11 changes: 11 additions & 0 deletions R/globals.R
Original file line number Diff line number Diff line change
Expand Up @@ -2,3 +2,14 @@ if(getRversion() >= "2.15.1"){
# To remove 'no visible binding for global variable ...' notes
utils::globalVariables(c('lambda_1_ind', 'lambda_2_ind'))
}

.onAttach <- function(libname, pkgname) {
max_threads <- tryCatch(omp_max_threads(), error = function(e) 1)
if (max_threads < 2) {
packageStartupMessage("*******\n
This installation of learner has not detected OpenMP support\n
It will still work but will not support multithreading via the `n_cores` argument
If you plan to use multithreading, please ensure you are using R>=3.4.0 and have OpenMP installed\n
*******")
}
}
6 changes: 6 additions & 0 deletions R/learner-package.R
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
## usethis namespace: start
#' @import RcppEigen
#' @importFrom Rcpp sourceCpp
#' @useDynLib learner, .registration = TRUE
## usethis namespace: end
NULL
Loading
Loading