Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ jobs:
with:
version: ${{ matrix.version }}
arch: ${{ matrix.arch }}
- uses: actions/cache@v1
- uses: actions/cache@v3
env:
cache-name: cache-artifacts
with:
Expand Down
11 changes: 11 additions & 0 deletions docs/src/pca.md
Original file line number Diff line number Diff line change
Expand Up @@ -117,6 +117,10 @@ predict(::KernelPCA)
predict(::KernelPCA, ::AbstractVecOrMat{T}) where {T<:Real}
reconstruct(::KernelPCA, ::AbstractVecOrMat{T}) where {T<:Real}
size(::KernelPCA)
```
!!! note
If `reconstruct` is called with an input that is not an `AbstractVecOrMat` of real numbers, an `ArgumentError` is thrown indicating the invalid input type and the expected type.
```
projection(::KernelPCA)
eigvals(::KernelPCA)
eigvecs(::KernelPCA)
Expand Down Expand Up @@ -164,6 +168,10 @@ fit
size(::PPCA)
mean(::PPCA)
var(::PPCA)
```
!!! note
If `reconstruct` is called with an input that is not an `AbstractVecOrMat` of real numbers, an `ArgumentError` is thrown indicating the invalid input type and the expected type.
```
cov(::PPCA)
projection(::PPCA)
loadings(::PPCA)
Expand All @@ -188,6 +196,9 @@ Here, ``\mathbf{W}`` is the factor loadings or weight matrix.
predict(::PPCA, ::AbstractVecOrMat{T}) where {T<:Real}
reconstruct(::PPCA, ::AbstractVecOrMat{T}) where {T<:Real}
```
```
!!! note
If `reconstruct` is called with an input that is not an `AbstractVecOrMat` of real numbers, an `ArgumentError` is thrown indicating the invalid input type and the expected type.

Auxiliary functions:

Expand Down
8 changes: 7 additions & 1 deletion src/types.jl
Original file line number Diff line number Diff line change
Expand Up @@ -23,8 +23,14 @@ projection(model::AbstractDimensionalityReduction) = error("'projection' is not
reconstruct(model::AbstractDimensionalityReduction, y)

Return the model response (a.k.a. the dependent variable).
Throws an `ArgumentError` if `y` is not an `AbstractVecOrMat` of real numbers, indicating the invalid
input type and the expected type.
"""
reconstruct(model::AbstractDimensionalityReduction, y) = error("'reconstruct' is not defined for $(typeof(model)).")
function reconstruct(model::AbstractDimensionalityReduction, y)
throw(ArgumentError("Invalid input type $(typeof(y)) for reconstruct(::$(typeof(model))). " *
"Expected an AbstractVecOrMat of real numbers."
))
end

abstract type LinearDimensionalityReduction <: AbstractDimensionalityReduction end

Expand Down
6 changes: 6 additions & 0 deletions test/pca.jl
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,12 @@ import SparseArrays
@test reconstruct(M, Y[:,1]) ≈ P * Y[:,1]
@test reconstruct(M, Y) ≈ P * Y

@test_throws ArgumentError reconstruct(M, 123)
@test_throws ArgumentError reconstruct(M, Dict())
@test_throws ArgumentError reconstruct(M, "abc")
@test_throws ArgumentError reconstruct(M, 8923.29)
@test_throws ArgumentError reconstruct(M, 1+2im)


## PCA with non-zero mean

Expand Down
Loading