Skip to content

Commit

Permalink
adjustments for CRAN submission
Browse files Browse the repository at this point in the history
  • Loading branch information
tkonopka committed Jun 25, 2018
1 parent 66d2e97 commit 88dc14b
Show file tree
Hide file tree
Showing 75 changed files with 197 additions and 38 deletions.
2 changes: 1 addition & 1 deletion .Rbuildignore
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
.git

^README
^LICENSE.md

^images$

Expand All @@ -21,4 +22,3 @@
^vignettes/.*html$
^vignettes/.*png$


6 changes: 3 additions & 3 deletions DESCRIPTION
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
Package: umap
Title: Implementation of Uniform Manifold Approximation and Projection in R
Version: 0.1.0.0
Title: Uniform Manifold Approximation and Projection
Version: 0.1.0.3
Authors@R: person("Tomasz", "Konopka", , "[email protected]", role = c("aut", "cre"))
Author: Tomasz Konopka [aut, cre]
Maintainer: Tomasz Konopka <[email protected]>
Description: Uniform Manifold Approximation and Projection is a technique for dimension reduction.
Description: Uniform manifold approximation and projection is a technique for dimension reduction. The algorithm was described by McInnes and Healy (2018) in <arXiv:1802.03426>. This package provides an interface for two implementations. One is written from scratch, including components for nearest-neighbor search and for embedding. The second implementation is a wrapper for 'python' package 'umap-learn' (requires separate installation, see vignette for more details).
Depends:
R (>= 3.1.2)
Imports:
Expand Down
23 changes: 2 additions & 21 deletions LICENSE
Original file line number Diff line number Diff line change
@@ -1,21 +1,2 @@
The MIT License (MIT)

Copyright (c) 2018 Tomasz Konopka

Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.
YEAR: 2018
COPYRIGHT HOLDER: Tomasz Konopka
21 changes: 21 additions & 0 deletions LICENSE.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
The MIT License (MIT)

Copyright (c) 2018 Tomasz Konopka

Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.
9 changes: 9 additions & 0 deletions R/RcppExports.R
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@

#' perform a compound transformation on a vector, including clipping
#'
#' @keywords internal
#' @param x numeric vector
#' @param inner numeric constant
#' @param outer numeric constan
Expand All @@ -14,6 +15,7 @@ clip4 <- function(x, inner, outer) {

#' compute Euclidean distance between two vectors
#'
#' @keywords internal
#' @param x numeric vector
#' @param y numeric vector
#'
Expand All @@ -24,6 +26,7 @@ dEuclidean <- function(x, y) {

#' compute Euclidean distances
#'
#' @keywords internal
#' @param m matrix with raw data
#'
#' @return dEuclidean norms between first row and all other rows
Expand All @@ -33,6 +36,7 @@ mdEuclidean <- function(m) {

#' compute Manhattan distance between two vectors
#'
#' @keywords internal
#' @param x numeric vector
#' @param y numeric vector
#'
Expand All @@ -43,6 +47,7 @@ dManhattan <- function(x, y) {

#' compute Manhattan distances
#'
#' @keywords internal
#' @param m matrix with raw data
#'
#' @return dManhattan norms between origin and targets
Expand All @@ -57,6 +62,7 @@ mdManhattan <- function(m) {
#' Important: this function assumes that data has been centered
#' i.e. that mean(x) = mean(y) = 0
#'
#' @keywords internal
#' @param x numeric vector
#' @param y numeric vector
#'
Expand All @@ -67,6 +73,7 @@ dCenteredPearson <- function(x, y) {

#' compute pearson correlation distances
#'
#' @keywords internal
#' @param m matrix with raw data
#'
#' @return dCenteredPearson norms between first row and all other rows
Expand All @@ -78,6 +85,7 @@ mdCenteredPearson <- function(m) {
#'
#' Note: values output from this function do not satisfy the triangle inequality
#'
#' @keywords internal
#' @param x numeric vector
#' @param y numeric vector
#'
Expand All @@ -88,6 +96,7 @@ dCosine <- function(x, y) {

#' compute cosine distances
#'
#' @keywords internal
#' @param m matrix with raw data
#'
#' @return dCosine norms between first row and all other rows
Expand Down
13 changes: 12 additions & 1 deletion R/coo.R
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@

##' Create a coo representation of a square matrix
##'
##' @keywords internal
##' @param x square matrix
##'
##' @return matrix with three columns (from index, to index, value)
Expand Down Expand Up @@ -36,7 +37,7 @@ coo = function(x) {

##' Helper to construct coo objects
##'
##'
##' @keywords internal
##' @param x coo matrix
##' @param names character vector
##' @param n.elements integer
Expand All @@ -59,6 +60,7 @@ make.coo = function(x, names, n.elements) {

##' Stop execution with a custom message
##'
##' @keywords internal
##' @param msg1 character
##' @param msg2 character
stop.coo = function(msg1, msg2="") {
Expand All @@ -71,6 +73,7 @@ stop.coo = function(msg1, msg2="") {

##' Check class for coo
##'
##' @keywords internal
##' @param x object of class coo
##' @param msg character, message to print alongside error
check.coo = function(x, msg="") {
Expand All @@ -82,6 +85,7 @@ check.coo = function(x, msg="") {

##' Check that two coo objects are compatible for addition, multiplication
##'
##' @keywords internal
##' @param x object of class coo
##' @param y object of class coos
##' @param msg character, message to print alongside error
Expand All @@ -103,6 +107,7 @@ check.compatible.coo = function(x, y, msg="") {

##' Remove some entires in a coo matrix where values are zero
##'
##' @keywords internal
##' @param x coo object
##'
##' @return matrix based on x, perhaps with some lines in original removed
Expand All @@ -119,6 +124,7 @@ reduce.coo = function(x) {

##' Transpose a coo matrix
##'
##' @keywords internal
##' @param x coo object
##'
##' @return another coo object describing a transposed matrix
Expand All @@ -137,6 +143,7 @@ t.coo = function(x) {
##'
##' The two input objects must be compatible (have equivalent names)
##'
##' @keywords internal
##' @param x coo object
##' @param y coo object
##' @param a numeric, scalar for multiplication
Expand Down Expand Up @@ -164,6 +171,7 @@ multiply.coo = function(x, y, a=1) {

##' Add two coo objects element-wise
##'
##' @keywords internal
##' @param x coo object
##' @param y coo object
##' @param a numeric, scalar for addition
Expand All @@ -190,6 +198,7 @@ add.coo = function(x, y, a=1, b=1) {

##' Prepare a coo object by splitting a coo
##'
##' @keywords internal
##' @param x coo object
##'
##' @return list with two components $to and $from
Expand All @@ -207,6 +216,7 @@ multiplicationprep.coo = function(x) {

##' Matrix multiplication of a coo matrix with a vector
##'
##' @keywords internal
##' @param x coo object
##' @param v numeric vector
##' @param xprep list with values in x split using multiplicationprep
Expand Down Expand Up @@ -245,6 +255,7 @@ vectormultiplication.coo = function(x, v, xprep=NULL) {

##' Convert from coo object into conventional matrix
##'
##' @keywords internal
##' @param x coo object
##'
##' @return matrix
Expand Down
6 changes: 6 additions & 0 deletions R/coo_spectral.R
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@

##' Get a set of k eigenvalues and eigenvectors
##'
##' @keywords internal
##' @param x coo object
##' @param k integer, number of eigenvalues/eigenvectors
##' @param m integer, number of lanczos vectors to use
Expand Down Expand Up @@ -40,6 +41,7 @@ spectral.coo = function(x, k, m=2*k+1) {

##' Construct an identity matrix
##'
##' @keywords internal
##' @param n.elements integer, number of elements
##' @param names character vector, names associated with the elements
##'
Expand All @@ -62,6 +64,7 @@ identity.coo = function(n.elements, names=NULL) {

##' Subset a coo
##'
##' @keywords internal
##' @param x coo object
##' @param items items (indexes) to keep
##'
Expand Down Expand Up @@ -109,6 +112,7 @@ subset.coo = function(x, items) {
##' This implementation constructs the laplacian element-by-element.
##' Diagonals: 1, Element_ij = -1/sqrt(deg_i deg_j)
##'
##' @keywords internal
##' @param x coo object encoding a graph
##'
##' @return new coo object
Expand Down Expand Up @@ -150,6 +154,7 @@ laplacian.coo = function(x) {

##' Count the number of connected components in a coo graph
##'
##' @keywords internal
##' @param x coo object
##'
##' @return list with number of connected components and a vector
Expand Down Expand Up @@ -207,6 +212,7 @@ concomp.coo = function(x) {
##'
##' This does not work very well (eigenvectors don't match svd()). Help would be appreciated.
##'
##' @keywords internal
##' @param x coo object
##' @param k integer, number of vectors to optimize
##' @param m integer, number of vectors to use in procedure (set higher than k)
Expand Down
3 changes: 3 additions & 0 deletions R/knn.R
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
##' By definition, the first nearest neighbor to each point is the point itself.
##' Subsequent neighbors are "true" neighbors.
##'
##' @keywords internal
##' @param d dist object or matrix with distances
##' @param k integer, number of neighbors
##'
Expand Down Expand Up @@ -65,6 +66,7 @@ knn.from.dist = function(d, k) {
##' algorithm is roughly inspired by Dong et al, but there are differences.
##' This is a rough implementation and improvements are possible.
##'
##' @keywords internal
##' @param d matrix with data
##' @param k integer, number of neighbors
##' @param metric.function function with signature f(a, b) that returns a metric distance
Expand Down Expand Up @@ -207,6 +209,7 @@ knn.from.data = function(d, k, metric.function, subsample.k=0.5) {

##' Repeat knn.from.data multiple times, pick the best neighbors
##'
##' @keywords internal
##' @param d matrix with data
##' @param k integer, number of neighbors
##' @param metric.function function with signature f(a, b) that returns a metric distance
Expand Down
29 changes: 25 additions & 4 deletions R/umap.R
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ python.umap = NULL

##' Default configuration for umap
##'
##' A list with parameters customizing a UMAP projection. Each component of the
##' A list with parameters customizing a UMAP embedding. Each component of the
##' list is an effective argument for umap().
##'
##' n.neighbors: integer; number of nearest neighbors
Expand Down Expand Up @@ -75,7 +75,7 @@ python.umap = NULL
##' set.op.mix.ratio: numeric in range [0,1]; determines who the knn-graph
##' is used to create a fuzzy simplicial graph
##'
##' local.connectivity: numeric; used during construction of fuzzy simplicail set
##' local.connectivity: numeric; used during construction of fuzzy simplicial set
##'
##' bandwidth: numeric; used during construction of fuzzy simplicial set
##'
Expand All @@ -100,6 +100,15 @@ python.umap = NULL
##'
##' verbose: logical or integer; determines whether to show progress messages
##'
##' @examples
##' # display all default settings
##' umap.defaults
##'
##' # create a new settings object with n.neighbors set to 5
##' custom.settings = umap.defaults
##' custom.settings$n.neighbors = 5
##' custom.settings
##'
##' @export
umap.defaults = list(
n.neighbors=15,
Expand Down Expand Up @@ -132,12 +141,24 @@ class(umap.defaults) = "umap.config"
##' @param d matrix, input data
##' @param config object of class umap.config
##' @param method character, implementation. Available methods are 'naive'
##' (an implementation written in pure R) and 'python' (requires python package 'umap')
##' @param ... list of settings; overwrite settings in config
##' (an implementation written in pure R) and 'python' (requires python package
##' 'umap-learn')
##' @param ... list of settings; overwrite default values from config
##'
##' @return object of class umap, containing at least a component
##' with an embedding and a component with configuration settings
##'
##' @examples
##' # embedd iris dataset
##' # (using default settings, but with reduced number of epochs)
##' iris.umap = umap(iris[,1:4], n.epochs=20)
##'
##' # display object summary
##' iris.umap
##'
##' # display embedding coordinates
##' head(iris.umap$layout)
##'
##' @export
umap = function(d, config=umap.defaults, method=c("naive", "python"), ...) {

Expand Down
3 changes: 3 additions & 0 deletions R/umap_checks.R
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@

##' Validator functions for umap settings
##'
##' @keywords internal
##' @param config list with umap arguments
##' @param ... other arguments
##'
Expand Down Expand Up @@ -70,6 +71,7 @@ umap.check.config = function(config=umap.defaults, ...) {

##' Prep primary input as a data matrix
##'
##' @keywords internal
##' @param d matrix or compatible
##' @param config list with settings
##'
Expand Down Expand Up @@ -100,6 +102,7 @@ umap.prep.input = function(d, config) {

##' stop execution with a custom error message
##'
##' @keywords internal
##' @param ... strings for error message
umap.error = function(...) {
x = paste(..., collapse=" ")
Expand Down
Loading

0 comments on commit 88dc14b

Please sign in to comment.