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

Replace chondro with faux_cell in hyperSpec.Rmd: Ran into an error with qr.solve #223

Open
bryanhanson opened this issue Jul 21, 2020 · 1 comment

Comments

@bryanhanson
Copy link
Collaborator

I had to revert my conversion of instances of chondro to faux_cell in hyperSpec.Rmd because this code:

find.max <- function(y, x) {
  pos <- which.max(y) + (-1:1)
  X <- x[pos] - x[pos[2]]
  Y <- y[pos] - y[pos[2]]

  X <- cbind(1, X, X^2)
  coef <- qr.solve(X, Y)

  - coef[2] / coef[3] / 2 + x[pos[2]]
}

bandpos <- apply(chondro[[, , 990 ~ 1020]], 1, find.max, wl(chondro[, , 990 ~ 1020]))
refpos <- find.max(colMeans(chondro[[, , 990 ~ 1020]]),  wl(chondro[, , 990 ~ 1020]))

shift1 <- refpos - bandpos

throws an error from qr.solve. I also changed the relevant wavelengths; here is a failing example:

library("hyperSpec")

find.max <- function(y, x) {
  pos <- which.max(y) + (-1:1)
  X <- x[pos] - x[pos[2]]
  Y <- y[pos] - y[pos[2]]

  X <- cbind(1, X, X^2)
  coef <- qr.solve(X, Y)

  - coef[2] / coef[3] / 2 + x[pos[2]]
}

bandpos <- apply(faux_cell[[, , 1150 ~ 1250]], 1, find.max, wl(faux_cell[, , 1150 ~ 1250]))

Looking around a bit, I think it may have to do with the amplitudes and/or noise in faux_cell but I'm not sure, and a little experimentation did not reveal any insights (we are fitting to only 3 data points). Someone with more experience with qr.solve may need to take a look. There's also a note above the code in the vignette to use vanderMonde; I think this refers to X <- cbind(1, X, X^2) but I don't see how using vanderMonde gives an advantage here, except that one could make a hyperSpec object out of it, but that seems like overkill.

@GegznaV
Copy link
Collaborator

GegznaV commented Aug 4, 2020

Due to this issue, two chunks of code in hyperSpec.Rmd are not functional and are temporary not executed. In the vignette, FIXME tag was added to highlight the issue.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

3 participants