Skip to content

Fix numerical issues in matrix determinants #25

@PhDyellow

Description

@PhDyellow

predict_gfbootstrap.R will occasionally fail when all
determinants come back as 0.

Mathematically that would happen if

  1. The matrix is not full rank: some rows/cols are linear combinations
    of other rows/cols.
  2. Some columns or rows are entirely 0.
  3. The matrix is not invertible for some reason.

It can also happen for numerical reasons.

I have examined a few matricies, and the matrices were full rank, and
no rows or cols were all 0.

I suspect numerical issues.
I increased the numerical resolution to doubles, but the problem remained.

Because I know the matrix is supposed to be symmetric, I can use
linalg_eigh which did succeed in returning the eigenvectors and
eigenvalues.

mat_eig <- torch::linalg_eigh(mat)
inv <- mat_eig[[2]]$multiply(mat_eig[[1]])$multiply(mat_eig[[2]]$transpose(1,2))
det <- mat_eig[[1]]$prod()

However, this is much slower, and not well integrated into the rest of
the code, so for now surveys that have this problem will just return
NA, not fitted.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions