R/RcppExports.R

Defines functions allPairsRcpp restRandMatUnif restRandMatLNorm restRandMatGamma restRandMat vCosSimilarity wtVCosSimilarity sftVCosSimilarity mCosSimilarity wtMCosSimilarity sftMCosSimilarity

Documented in allPairsRcpp mCosSimilarity restRandMat restRandMatGamma restRandMatLNorm restRandMatUnif sftMCosSimilarity sftVCosSimilarity vCosSimilarity wtMCosSimilarity wtVCosSimilarity

# Generated by using Rcpp::compileAttributes() -> do not edit by hand
# Generator token: 10BE3573-1514-4C36-9D1C-5A225CD40393

#' Generate all possible pairs from a vector or a sequence of integer numbers
#'
#' @rdname allPairs
#' @param n maximum number of the sequence
#' @return \code{allPairsRcpp} returns (n*(n-1)/2) x 2 integer matrix all unique combinations (pairs) of numbers from a sequence of integers 1..n 
allPairsRcpp <- function(n) {
    .Call('_RPortfolioSimilarity_allPairsRcpp', PACKAGE = 'RPortfolioSimilarity', n)
}

#' Generate random variation of a matrix keeping rows and cols sums. Deprecated, use restRandMat().
#'
#'@param original_mat the original matrix that will be replicated
#'@param max_iter maximum number of iterations when coverging to the rows and cols sums
#'@return numeric matrix with the same dimensions and (almost) rows' and columns' sums as the input matrix
restRandMatUnif <- function(original_mat, max_iter) {
    .Call('_RPortfolioSimilarity_restRandMatUnif', PACKAGE = 'RPortfolioSimilarity', original_mat, max_iter)
}

#' Generate random variation of a matrix keeping rows and cols sums. Deprecated, use restRandMat().
#'
#'@param original_mat the original matrix that will be replicated
#'@param max_iter maximum number of iterations when coverging to the rows and cols sums
#'@param meanl parameter of the log-normal distribution
#'@param sdl parameter of the log-normal distribution
#'@return numeric matrix with the same dimensions and (almost) rows' and columns' sums as the input matrix
restRandMatLNorm <- function(original_mat, max_iter, meanl = 0, sdl = 1) {
    .Call('_RPortfolioSimilarity_restRandMatLNorm', PACKAGE = 'RPortfolioSimilarity', original_mat, max_iter, meanl, sdl)
}

#' Generate random variation of a matrix keeping rows and cols sums. Deprecated, use restRandMat().
#'
#'@param original_mat the original matrix that will be replicated
#'@param max_iter maximum number of iterations when coverging to the rows and cols sums
#'@param shape parameter of the gamma distribution
#'@param rate parameter of the gamma distribution
#'@return numeric matrix with the same dimensions and (almost) rows' and columns' sums as the input matrix
restRandMatGamma <- function(original_mat, max_iter, shape, rate = 1.0) {
    .Call('_RPortfolioSimilarity_restRandMatGamma', PACKAGE = 'RPortfolioSimilarity', original_mat, max_iter, shape, rate)
}

#' Generate random variation of a matrix keeping rows and cols sums
#'
#'@param original_mat the original matrix that will be replicated
#'@param max_iter maximum number of iterations when coverging to the rows and cols sums
#'@return numeric matrix with the same dimensions and (almost) rows' and columns' sums as the input matrix
restRandMat <- function(original_mat, max_iter, type, par1 = 1.0, par2 = 1.0) {
    .Call('_RPortfolioSimilarity_restRandMat', PACKAGE = 'RPortfolioSimilarity', original_mat, max_iter, type, par1, par2)
}

#' Compute cosine similarity of two numeric vectors
#'
#'@param a numeric vector
#'@param b numeric vector
#'@details
#'\code{a} and \code{b} are expected to have the same length.
#'\deqn{\sum(a*b)/\sqrt(\sum(a^2)\sum(b^2))}
#'@return Numeric value.
vCosSimilarity <- function(a, b) {
    .Call('_RPortfolioSimilarity_vCosSimilarity', PACKAGE = 'RPortfolioSimilarity', a, b)
}

#' Compute weighted cosine similarity of two numeric vectors
#'
#'@param a numeric vector
#'@param b numeric vector
#'@param w numeric vector of weights
#'@details
#'\code{a}, \code{b} and \code{c} are expected to have the same length.
#'\deqn{\sum(a*b*w)/\sqrt\sum(w*a^2)\sqrt\sum(w*b^2)}
#'@return Numeric value of cosine similarity
wtVCosSimilarity <- function(a, b, w) {
    .Call('_RPortfolioSimilarity_wtVCosSimilarity', PACKAGE = 'RPortfolioSimilarity', a, b, w)
}

#' Compute soft weighted cosine similarity of two numeric vectors
#'
#'@param a numeric vector
#'@param b numeric vector
#'@param w numeric matrix of weights
#'
#'@details
#'\code{a}, \code{b} and \code{c} are expected to have the same length.
#'Soft cosine similarity allows accounting for (cor)relations between features. 
#'@return Numeric value of cosine similarity
sftVCosSimilarity <- function(a, b, weights) {
    .Call('_RPortfolioSimilarity_sftVCosSimilarity', PACKAGE = 'RPortfolioSimilarity', a, b, weights)
}

#' Compute cosine similarity for every pair of rows from given matrix
#'
#'@param input_mat numeric input matrix
#'@return Upper triangle matrix where \{i, j\} element is the cosine similarity of i-th and j-th row of the original matrix.
#'@seealso \code{\link{vCosSimilarity}}
mCosSimilarity <- function(input_mat) {
    .Call('_RPortfolioSimilarity_mCosSimilarity', PACKAGE = 'RPortfolioSimilarity', input_mat)
}

#' Compute weighted cosine similarities for each pair of rows from given matrix and given weights
#'
#'@param input_mat numeric input matrix
#'@param weights numeric vector of weights
#'@details
#'\link{wtVCosSimilarity}
#'@return Upper triangle matrix where \{i, j\} element is the cosine similarity of i-th and j-th row of the original matrix.
#'@seealso \code{\link{wtVCosSimilarity}}
wtMCosSimilarity <- function(input_mat, weights) {
    .Call('_RPortfolioSimilarity_wtMCosSimilarity', PACKAGE = 'RPortfolioSimilarity', input_mat, weights)
}

#' Compute soft cosine similarities for each pair of rows from given matrix and given weights
#'
#'@param input_mat numeric input matrix
#'@param weights numeric vector of weights
#'@details
#'Soft cosine similarity allows accounting for (cor)relations between features. 
#'@return Upper triangle matrix where \{i, j\} element is the cosine similarity of i-th and j-th row of the original matrix.
sftMCosSimilarity <- function(input_mat, weights) {
    .Call('_RPortfolioSimilarity_sftMCosSimilarity', PACKAGE = 'RPortfolioSimilarity', input_mat, weights)
}
vh-d/RPortfolioSimilarity documentation built on Oct. 17, 2019, 3:11 a.m.