Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

NEW Deflation for CCA and LDA #54

Merged
merged 28 commits into from
Aug 23, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
28 commits
Select commit Hold shift + click to select a range
01e1dd9
Change of function name: reset -> set_penalty
Banana1530 Jul 19, 2019
6b71aa0
Extend C++ class `MoMA` to include CCA and LDA
Banana1530 Jul 21, 2019
144b5c0
C++ interface for CCA and LDA
Banana1530 Jul 19, 2019
522f93a
Remove redundancy in `moma_sfpca.R`
Banana1530 Jul 19, 2019
cdd7f39
Add `SFCCA$initialize()` and tests
Banana1530 Jul 19, 2019
308cf0a
Add `SFLDA$initialize()` and tests
Banana1530 Jul 19, 2019
7c63aa3
Update error message
Banana1530 Jul 22, 2019
2c4e5d7
Add PCA deflation schemes on C++ side
Banana1530 Aug 5, 2019
e206112
Expose `deflation_scheme` to R
Banana1530 Aug 5, 2019
e11ace4
Add tests for PCA deflations
Banana1530 Aug 6, 2019
d66193a
Add orthogonality tests
Banana1530 Aug 8, 2019
f25d143
_u/v -> _x/y
Banana1530 Aug 20, 2019
73f7d5a
Change test files' names
Banana1530 Aug 2, 2019
4cfcc24
Update test cases
Banana1530 Aug 13, 2019
f4a344e
Change variables' names
Banana1530 Aug 13, 2019
bfc846b
Refactor SFPCA and update tests
Banana1530 Aug 13, 2019
a0d8b25
Refactor SFLDA and SFCCA
Banana1530 Aug 13, 2019
62b55ca
Add docs
Banana1530 Aug 20, 2019
dcaecf5
Add vignettes
Banana1530 Aug 20, 2019
1b49b8c
a typo
Banana1530 Aug 20, 2019
e2b496e
Give info: use sec-diff-mat as default.
Banana1530 Aug 20, 2019
26e77b0
Set `knitr::opts_chunk$set(cache = FALSE)`
Banana1530 Aug 22, 2019
2b2d916
Response
Banana1530 Aug 22, 2019
8f3e2a3
Update badges
Banana1530 Aug 22, 2019
9a670cf
Enum-fy selection scheme encoding on C++ side
Banana1530 Aug 23, 2019
585beb7
Enum-fy selection scheme encoding on R side
Banana1530 Aug 23, 2019
c861f19
Not use tidytemplate
Banana1530 Aug 23, 2019
03923ee
PCA_Schur_complement -> PCA_Schur_Complement
Banana1530 Aug 23, 2019
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
220 changes: 220 additions & 0 deletions R/moma-R6.R
Original file line number Diff line number Diff line change
@@ -0,0 +1,220 @@
#' R6 objects for storing and accessing the results of SFPCA / SFLDA /
#' SFCCA
#'
#' During initialization of an \code{SFPCA} object, \code{R}
#' calls the \code{C++}-side function, \code{cpp_multirank_BIC_grid_search},
#' and wraps the results returned. The \code{SFPCA} object also records
#' penalty levels and selection schemes of tuning parameters. Several
#' helper methods are provivded to facilitate access to results.
#' Initialization is delegated to \code{\link{moma_sfpca}}.
#'
#' The following table lists the supported methods for
#' R6 objects generated by \code{moma_*pca}, \code{moma_*cca}
#' and \code{moma_*lda} family of functions.
#' \tabular{lccccccc}{
#' \tab \code{get_mat_by_index} \tab \code{interpolate}
#' \tab \code{print} \tab \code{plot} \tab \code{X_project} \tab
#' \code{Y_project} \tab \code{left_project}
#' \cr
#' \code{moma_*pca} \tab Yes \tab Yes
#' \tab Yes \tab Yes \tab \tab \tab Yes
#' \cr
#' \code{moma_*cca} \tab Yes \tab
#' \tab Yes \tab Yes \tab Yes \tab Yes \tab
#' \cr
#' \code{moma_*lda} \tab Yes \tab
#' \tab Yes \tab Yes \tab Yes \tab \tab
#' \cr
#' }
#'
#' @seealso \code{\link{moma_sfpca}},
#' \code{\link{moma_sflda}},
#' \code{\link{moma_sfcca}}
#'
#' @section Members:
#'
#' \describe{
#' \item{
#' \code{center,scale}
#' }{
#' The attributes "\code{scaled:center}" and "\code{scaled:scale}"
#' of function \code{scale}. The numeric centering and scalings
#' used (if any) of the data matrix.
#' }
#'
#' \item{
#' \code{grid_result}
#' }{
#' A 5-D list containing the results evaluated on the parameter grid.
#' }
#'
#' \item{
#' \code{select_scheme_list}
#' }{
#' A list with elements
#' \code{select_scheme_alpha_u}, \code{select_scheme_alpha_v},
#' \code{select_scheme_lambda_u}, \code{select_scheme_lambda_v}.
#' Each of them is either 0 or 1. 0 stands for grid search
#' and 1 stands for BIC search. Please see the \code{select_scheme}
#' argument in the function \code{moma_sfpca}.
#' }
#' }
#'
#' @section Methods:
#' \describe{
#' \item{
#' \code{get_mat_by_index}
#' }{
#' \describe{
#' \item{
#' Arguments
#' }{
#' For \code{moma_*pca}: \code{alpha_u}, \code{alpha_v},
#' \code{lambda_u}, \code{lambda_v}.
#'
#' \cr\cr
#'
#' For \code{moma_*cca} and \code{moma_*lda}: \code{alpha_x},
#' \code{alpha_y}, \code{lambda_x}, \code{lambda_y}.
#'
#' \cr\cr
#'
#' Indices of the parameters in the paramter grid, which have
#' been specified during initialization.
#' }
#' \item{
#' Functionality
#' }{
#' Obtain the right and left penalized sigular vectors
#' located by the set of
#' indices (\code{alpha_u}, \code{alpha_v}, \code{lambda_u},
#' \code{lambda_v}) or (\code{alpha_x},
#' \code{alpha_y}, \code{lambda_x}, \code{lambda_y}). Penalized
#' sigular vectors are packed into matrices \code{U} and \code{V}.
#' }
#' \item{
#' Value
#' }{
#' For \code{moma_*pca}, it is a list containing \code{U},
#' \code{V}, \code{d}, \code{chosen_lambda_u}, \code{chosen_lambda_u},
#' \code{chosen_lambda_v}, \code{chosen_alpha_u},
#' \code{chosen_alpha_v}.
#'
#' \cr\cr
#'
#' For \code{moma_*lda}, it is a list containing \code{X_PC_loadings},
#' \code{Y_group_scores}, \code{d}, \code{chosen_lambda_x},
#' \code{chosen_lambda_y}, \code{chosen_alpha_x},
#' \code{chosen_alpha_y}.
#'
#' \cr\cr
#'
#' For \code{moma_*cca}, it is a list containing \code{X_PC_loadings},
#' \code{Y_PC_loadings}, \code{d}, \code{chosen_lambda_x},
#' \code{chosen_lambda_y}, \code{chosen_alpha_x},
#' \code{chosen_alpha_y}.
#' }
#' }
#' }
#' \item{
#' \code{*_project}
#' }{
#' \describe{
#' \item{
#' Arguments
#' }{
#' For \code{left_project} (available for \code{moma_*pca}):
#' \code{newX}, \code{alpha_u},
#' \code{alpha_v}, \code{lambda_u}, \code{lambda_v}.
#'
#' \cr\cr
#'
#' For \code{X_project} (available for \code{moma_*cca} and
#' \code{moma_*lda})): \code{newX}, \code{alpha_x},
#' \code{alpha_y}, \code{lambda_x}, \code{lambda_y}.
#'
#' \cr\cr
#'
#' For \code{Y_project} (available for \code{moma_*cca}):
#' \code{newY}, \code{alpha_x},
#' \code{alpha_y}, \code{lambda_x}, \code{lambda_y}.
#'
#' \cr\cr
#'
#' \code{newX} or \code{newY} is a new raw data matrix
#' (un-centered and un-scaled) of
#' an appropriate number of columns. (\code{alpha_u},
#' \code{alpha_v}, \code{lambda_u}, \code{lambda_v})
#' or (\code{alpha_x},
#' \code{alpha_y}, \code{lambda_x}, \code{lambda_y}) is the set of
#' indices to locate the penalalized singular vectors used to form
#' the basis of the low dimensional space.
#' }
#' \item{
#' Functionality
#' }{
#' Project the new data into the space spaned by the
#' penalized left singular vectors, after scaling and
#' centering as needed.
#' }
#' \item{
#' Value
#' }{
#' A list containing the scaled and centered data (as needed)
#' \code{scaled_data} and the projected data \code{proj_data}.
#' }
#' }
#' }
#' \item{
#' \code{interpolate}
#' }{
#' \describe{
#' \item{
#' Arguments
#' }{
#' \code{alpha_u}, \code{alpha_v},
#' \code{lambda_u}, \code{lambda_v}, \code{exact}.
#'
#' \cr\cr
#'
#' \code{exact} is a logical scalar. (\code{alpha_u},
#' \code{alpha_v}, \code{lambda_u}, \code{lambda_v}) is the
#' set of new paramters of interest.
#'
#' \cr\cr
#'
#' When \code{exact = TRUE}, a new solution will be calculated
#' exactly with the parameters set to (\code{alpha_u},
#' \code{alpha_v}, \code{lambda_u}, \code{lambda_v}).
#'
#' \cr\cr
#'
#' When \code{exact = FALSE}, an approximate solution
#' will be given by taking the average of two solutions
#' whose parameters' values are "closest" to the ones
#' specified by the user.
#' }
#' \item{
#' Functionality
#' }{
#' For a set of new parameters, give an approximate
#' solution of SFPCA based on
#' pre-calculated solutions, or just perform
#' exact calculation.
#' }
#' \item{
#' Value
#' }{
#' A list containing the exact (if \code{exact = TURE} has been
#' used) or approximate solution (if \code{exact = FALSE} has
#' been used) solution \code{U} and \code{V}.
#' }
#' }
#' }
#' \item{\code{print}}{Display tuning parameters and selection schemes.}
#' \item{\code{plot}}{Start a Shiny application and visualize penalized
#' singular vectors and projected data.}
#'
#' }
#' @name moma_R6
NULL
Loading