Skip to content

Commit c0b124e

Browse files
committed
Remove MASS Null from nfindr_height
1 parent 36ff229 commit c0b124e

File tree

2 files changed

+14
-14
lines changed

2 files changed

+14
-14
lines changed

pkg/unmixR/DESCRIPTION

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
Package: unmixR
22
Type: Package
33
Title: Hyperspectral Unmixing Methods
4-
Version: 2.3.0
4+
Version: 2.4.0
55
Date: 20025-07-11
66
Authors@R: c(
77
person("Anton", "Belov", role = "aut"),

pkg/unmixR/R/nfindr_height.R

Lines changed: 13 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -5,16 +5,16 @@
55
base <- data[indices[-j],,drop=FALSE]
66

77
# Calculate the null space, generalization of normal vector for an arbitrary dimension
8-
# e.g. for a plain triangle in 3D, a null space will be a 2D hyper plane orthogonal to the base
9-
N <- MASS::Null(t(
10-
# Remove first row from all other rows to move from points to vectors, i.e.
11-
# from [em1, em2, em3, ...] we switch to [(em2-em1), (em3-em1), ...]
12-
sweep(base, 2L, base[1,], check.margin=FALSE)[-1,,drop = FALSE]
13-
))
14-
15-
# Handle a special case, e.g. length(indices) == 2
16-
if (ncol(N) == 0) {
17-
N <- diag(1, nrow = ncol(data), ncol = ncol(data))
8+
# e.g. for a plain triangle in 3D, a null space is a 2D hyper plane orthogonal to the base
9+
10+
# Remove first row from all other rows to move from points to vectors, i.e.
11+
# from [em1, em2, em3, ...] we switch to [(em2-em1), (em3-em1), ...]
12+
Ut <- sweep(base, 2L, base[1,], check.margin=FALSE)[-1,,drop = FALSE]
13+
if (nrow(Ut) == 0) {
14+
# Handle a special case, e.g. length(indices) == 2
15+
P <- diag(ncol(data))
16+
} else {
17+
P <- diag(ncol(data)) - t(Ut) %*% solve(tcrossprod(Ut), Ut)
1818
}
1919

2020
# Project points onto the null space and remove base offset of the base
@@ -24,8 +24,8 @@
2424
# Alternatively, it is possible to do apply same shift before the projection,
2525
# i.e. `sweep(data[...], 2L, base[1,]) %*% N` but we chose to do it after the projection
2626
# because the projected data has smaller dimension.
27-
base_offset <- as.vector(base[1,] %*% N)
28-
proj <- data[new_indices, ] %*% N
27+
base_offset <- as.vector(base[1,] %*% P)
28+
proj <- data[new_indices, ] %*% P
2929
proj <- sweep(proj, 2L, base_offset)
3030

3131
# Calculate height ratios
@@ -34,7 +34,7 @@
3434
if (indices[j] %in% new_indices) {
3535
height_current <- heights[new_indices == indices[j]]
3636
} else {
37-
height_current <- (data[indices[j],] %*% N) - base_offset
37+
height_current <- (data[indices[j],] %*% P) - base_offset
3838
height_current <- sqrt(sum(height_current*height_current))
3939
}
4040

0 commit comments

Comments
 (0)