Skip to content

Commit ed65b26

Browse files
committed
update vignettes and docs
1 parent ea1d0e5 commit ed65b26

35 files changed

+192
-1033
lines changed

DESCRIPTION

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ Authors@R: as.person(c(
77
))
88
Description: tinyvamp estimates the model described in Clausen & Willis, 2022. Notably, our model allows relative abundances to lie on the boundary of the simplex. We present a stable algorithm for computing parameter estimates, asymptotically valid procedures for inference in this nonstandard problem, and examples of the utility of the method. Our approach can be used to select or compare experimental protocols, design experiments with appropriate control data, analyze mixed-specimen samples, and remove across-sample contamination.
99
URL: https://github.com/statdivlab/tinyvamp, https://statdivlab.github.io/tinyvamp/
10-
License: BSD_3_clause + file LICENSE
10+
License: MIT + file LICENSE
1111
Encoding: UTF-8
1212
LazyData: true
1313
Roxygen: list(markdown = TRUE)

LICENSE

Lines changed: 2 additions & 35 deletions
Original file line numberDiff line numberDiff line change
@@ -1,35 +1,2 @@
1-
=======
2-
License
3-
=======
4-
5-
Files: tinyvamp/*/*.R
6-
Copyright: 2022, The Regents of the University of Washington.
7-
License: BSD-3-Clause
8-
9-
Redistribution and use in source and binary forms, with or without
10-
modification, are permitted provided that the following conditions are
11-
met:
12-
13-
Redistributions of source code must retain the above copyright
14-
notice, this list of conditions and the following disclaimer.
15-
16-
Redistributions in binary form must reproduce the above copyright
17-
notice, this list of conditions and the following disclaimer in
18-
the documentation and/or other materials provided with the
19-
distribution.
20-
21-
Neither the name of the University of Washington nor the names of its
22-
contributors may be used to endorse or promote products derived
23-
from this software without specific prior written permission.
24-
25-
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
26-
"AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
27-
LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
28-
A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
29-
HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
30-
SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
31-
LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
32-
DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
33-
THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
34-
(INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
35-
OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
1+
YEAR: 2023
2+
COPYRIGHT HOLDER: tinyvamp authors

R/fastnnls.R

Lines changed: 0 additions & 180 deletions
Original file line numberDiff line numberDiff line change
@@ -177,183 +177,3 @@ fast_nnls <- function(
177177

178178
return(d)
179179
}
180-
181-
fast_nnls_Matrix <- function(
182-
ZTx,
183-
ZTZ,
184-
active = NULL,
185-
unconstrained = NULL,
186-
tolerance = 1e-10
187-
) {
188-
# store number of covariates
189-
p <- nrow(ZTZ)
190-
191-
if (length(intersect(active, unconstrained)) > 0) {
192-
stop(
193-
"A variable cannot be assigned to the unconstrained set and to the active set."
194-
)
195-
}
196-
### getting stuck in this initial loop for some reason! check it out!
197-
if (!is.null(active)) {
198-
#set d = 0 to start
199-
d <- matrix(0, nrow = p, ncol = 1)
200-
#check appropriateness of initial active set
201-
s <- matrix(0, nrow = p, ncol = 1)
202-
not_active <- !(1:p %in% active)
203-
s_passive <- qr.solve(
204-
ZTZ[not_active, not_active, drop = F],
205-
ZTx[not_active, drop = F],
206-
tol = 1e-14
207-
)
208-
s[not_active, ] <- s_passive
209-
210-
### redefine not_active to excluded unconstrained variables (if included)
211-
if (!is.null(unconstrained)) {
212-
not_active <- !(1:p %in% union(active, unconstrained))
213-
s_passive <- s[not_active]
214-
}
215-
#Enter inner loop
216-
if (length(s_passive) > 0) {
217-
while (ifelse(length(s_passive) > 0, min(s_passive) <= 0, FALSE)) {
218-
alphas <- (-(d[not_active]) / (d[not_active] - s_passive))
219-
alphas <- alphas[s_passive < 0]
220-
alpha <- min(-alphas)
221-
222-
d_archive <- d
223-
d <- d + alpha * (s - d)
224-
stopifnot(sum(is.na(d)) == 0)
225-
226-
if (is.null(unconstrained)) {
227-
active <- (1:p)[d == 0]
228-
not_active <- !(1:p %in% active)
229-
}
230-
if (!is.null(unconstrained)) {
231-
active <- (1:p)[(d == 0) & (!((1:p) %in% unconstrained))]
232-
not_active <- !(1:p %in% active)
233-
}
234-
235-
s <- matrix(0, nrow = p)
236-
if (length(active) > 0) {
237-
s_passive <- qr.solve(
238-
ZTZ[not_active, not_active],
239-
ZTx[not_active, ],
240-
tol = 1e-14
241-
)
242-
s[not_active, ] <- s_passive
243-
} else {
244-
s <- s_passive <- qr.solve(ZTZ, ZTx, tol = 1e-14)
245-
}
246-
247-
if (!is.null(unconstrained)) {
248-
not_active <- !(1:p %in% union(active, unconstrained))
249-
s_passive <- s[not_active]
250-
}
251-
}
252-
}
253-
d <- s
254-
active <- (1:p)[d == 0]
255-
256-
w <- ZTx - ZTZ %*% d
257-
}
258-
if (is.null(active)) {
259-
if (is.null(unconstrained)) {
260-
active <- 1:p
261-
d <- matrix(0, nrow = p, ncol = 1)
262-
w <- ZTx
263-
} else {
264-
active <- (1:p)[!(1:p %in% unconstrained)]
265-
d <- matrix(0, nrow = p, ncol = 1)
266-
d[unconstrained] <-
267-
qr.solve(
268-
ZTZ[unconstrained, unconstrained],
269-
ZTx[unconstrained, ],
270-
tol = 1e-14
271-
)
272-
w <- (ZTx - ZTZ %*% d)
273-
}
274-
}
275-
276-
# counter <- 0
277-
#Enter main loop - ???? are loop conditions correct ???
278-
while ((ifelse(length(active) > 0, max(w[active]), -1) > tolerance)) {
279-
# counter <- counter + 1
280-
# print(counter)
281-
282-
to_remove <- which.max(w[active])
283-
# print(to_remove)
284-
active <- active[-to_remove]
285-
286-
if (length(active) > 0) {
287-
s <- matrix(0, nrow = p)
288-
not_active <- !(1:p %in% active)
289-
290-
s_passive <- qr.solve(
291-
ZTZ[not_active, not_active],
292-
ZTx[not_active, ],
293-
tol = 1e-14
294-
)
295-
s[not_active, ] <- s_passive
296-
} else {
297-
s <- s_passive <- qr.solve(ZTZ, ZTx, tol = 1e-14)
298-
}
299-
300-
### redefine not_active to excluded unconstrained variables (if included)
301-
if (!is.null(unconstrained)) {
302-
not_active <- !(1:p %in% union(active, unconstrained))
303-
s_passive <- s[not_active]
304-
}
305-
306-
#Enter inner loop
307-
if (length(s_passive) > 0) {
308-
while (ifelse(length(s_passive) > 0, min(s_passive) <= 0, FALSE)) {
309-
alphas <- (-(d[not_active]) / (d[not_active] - s_passive))
310-
alphas <- alphas[s_passive < 0]
311-
alpha <- min(-alphas)
312-
313-
d_archive <- d
314-
d <- d + alpha * (s - d)
315-
stopifnot(sum(is.na(d)) == 0)
316-
317-
if (is.null(unconstrained)) {
318-
active <- (1:p)[d == 0]
319-
not_active <- !(1:p %in% active)
320-
}
321-
if (!is.null(unconstrained)) {
322-
active <- (1:p)[(d == 0) & (!((1:p) %in% unconstrained))]
323-
not_active <- !(1:p %in% active)
324-
}
325-
326-
s <- matrix(0, nrow = p)
327-
if (length(active) > 0) {
328-
s_passive <- qr.solve(
329-
ZTZ[not_active, not_active],
330-
ZTx[not_active, ],
331-
tol = 1e-14
332-
)
333-
s[not_active, ] <- s_passive
334-
} else {
335-
s <- s_passive <- qr.solve(ZTZ, ZTx, tol = 1e-14)
336-
}
337-
338-
### redefine not_active to excluded unconstrained variables (if included)
339-
if (!is.null(unconstrained)) {
340-
not_active <- !(1:p %in% union(active, unconstrained))
341-
s_passive <- s[not_active]
342-
}
343-
}
344-
}
345-
346-
d <- s
347-
348-
stopifnot(sum(is.na(d)) == 0)
349-
350-
w <- (ZTx - ZTZ %*% d)
351-
352-
# counter <- counter + 1
353-
354-
# print(counter)
355-
# stopifnot(counter<13)
356-
}
357-
358-
return(d)
359-
}

R/logsum.R

Lines changed: 0 additions & 39 deletions
Original file line numberDiff line numberDiff line change
@@ -35,42 +35,3 @@ sum_of_logs <- function(x, y = NULL) {
3535
}
3636

3737

38-
diff_of_logs <- function(larger, smaller) {
39-
return(larger + log(1 - exp(smaller - larger)))
40-
}
41-
42-
43-
signed_log_sum <- function(log_magnitudes, signs) {
44-
# if no nonzero summands, return zero
45-
if (sum(signs != 0) == 0) {
46-
return(c(0, 0))
47-
}
48-
49-
# if no negative summands, return sum of positive summands
50-
if (sum(signs == -1) == 0) {
51-
return(c(sum_of_logs(log_magnitudes[signs == 1]), 1))
52-
}
53-
54-
# if no positive summands, return sum of negative summands (with sign -1)
55-
if (sum(signs == 1) == 0) {
56-
return(c(sum_of_logs(log_magnitudes[signs == -1]), -1))
57-
}
58-
59-
# otherwise sum positive and negative magnitudes separately
60-
positives <- log_magnitudes[signs == 1]
61-
negatives <- log_magnitudes[signs == -1]
62-
63-
pos_logsum <- sum_of_logs(positives)
64-
neg_logsum <- sum_of_logs(negatives)
65-
66-
# if positive magnitude equals negative magnitude, return zero
67-
if (pos_logsum == neg_logsum) {
68-
return(c(0, 0))
69-
}
70-
71-
# otherwise return difference of positive and negative terms with appropriate sign
72-
return(c(
73-
diff_of_logs(max(pos_logsum, neg_logsum), min(pos_logsum, neg_logsum)),
74-
ifelse(pos_logsum > neg_logsum, 1, -1)
75-
))
76-
}

docs/404.html

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

docs/LICENSE-text.html

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)