diff --git a/Project.toml b/Project.toml index ce99bfc..bf180f7 100644 --- a/Project.toml +++ b/Project.toml @@ -1,4 +1,4 @@ -name = "MULTISPATI" +name = "Multispati" uuid = "3ff64760-8a89-40e2-854d-b45336bb1975" authors = ["Niklas Müller-Bötticher "] version = "0.1.0" diff --git a/README.md b/README.md index baa96bb..6558e39 100644 --- a/README.md +++ b/README.md @@ -1,10 +1,10 @@ -# MULTISPATI.jl +# Multispati.jl -[![Stable](https://img.shields.io/badge/docs-stable-blue.svg)](https://niklasmueboe.github.io/MULTISPATI.jl/stable) -[![Dev](https://img.shields.io/badge/docs-dev-blue.svg)](https://niklasmueboe.github.io/MULTISPATI.jl/dev) +[![Stable](https://img.shields.io/badge/docs-stable-blue.svg)](https://niklasmueboe.github.io/Multispati.jl/stable) +[![Dev](https://img.shields.io/badge/docs-dev-blue.svg)](https://niklasmueboe.github.io/Multispati.jl/dev) [![Code Style: Blue](https://img.shields.io/badge/code%20style-blue-4495d1.svg)](https://github.com/invenia/BlueStyle) [![Aqua QA](https://raw.githubusercontent.com/JuliaTesting/Aqua.jl/master/badge.svg)](https://github.com/JuliaTesting/Aqua.jl) -[![CI](https://github.com/niklasmueboe/MULTISPATI.jl/workflows/CI/badge.svg)](https://github.com/niklasmueboe/MULTISPATI.jl/actions?query=workflows:CI) +[![CI](https://github.com/niklasmueboe/Multispati.jl/workflows/CI/badge.svg)](https://github.com/niklasmueboe/Multispati.jl/actions?query=workflows:CI) Julia implementation of [MULTISPATI](https://doi.org/10.3170/2007-8-18312) @@ -14,16 +14,16 @@ The package can be installed with the Julia package manager. From the Julia REPL, type `]` to enter the `Pkg` REPL mode and run: ``` -pkg> add MULTISPATI +pkg> add Multispati ``` Or, alternatively, via the `Pkg` API: ```julia using Pkg -Pkg.add("MULTISPATI") +Pkg.add("Multispati") ``` ## Documentation -The documentation for MULTISPATI.jl is available [here](https://niklasmueboe.github.io/MULTISPATI.jl/stable). +The documentation for Multispati.jl is available [here](https://niklasmueboe.github.io/Multispati.jl/). diff --git a/docs/Project.toml b/docs/Project.toml index 47d7cbc..a65f110 100644 --- a/docs/Project.toml +++ b/docs/Project.toml @@ -1,7 +1,7 @@ [deps] Documenter = "e30172f5-a6a5-5a46-863b-614d45cd2de4" DocumenterInterLinks = "d12716ef-a0f6-4df4-a9f1-a5a34e75c656" -MULTISPATI = "3ff64760-8a89-40e2-854d-b45336bb1975" +Multispati = "3ff64760-8a89-40e2-854d-b45336bb1975" [compat] Documenter = "1.3" diff --git a/docs/make.jl b/docs/make.jl index f476f96..d24a309 100644 --- a/docs/make.jl +++ b/docs/make.jl @@ -1,16 +1,16 @@ using Documenter using DocumenterInterLinks -using MULTISPATI +using Multispati links = InterLinks( # "CategoricalArrays" => "https://categoricalarrays.juliadata.org/stable/", ) makedocs(; - sitename="MULTISPATI.jl", + sitename="Multispati.jl", pages=["Home" => "index.md", "Reference API" => "api.md"], authors="Niklas Müller-Bötticher", plugins=[links], ) -deploydocs(; repo="github.com/niklasmueboe/MULTISPATI.jl.git") +deploydocs(; repo="github.com/niklasmueboe/Multispati.jl.git") diff --git a/docs/src/api.md b/docs/src/api.md index f8441d0..e0e075e 100644 --- a/docs/src/api.md +++ b/docs/src/api.md @@ -1,6 +1,6 @@ # Reference API -Documentation for `MULTISPATI.jl`'s public interface. +Documentation for `Multispati.jl`'s public interface. ## Index @@ -10,19 +10,19 @@ Pages = ["api.md"] ## API -### MULTISPATI +### Multispati ```@docs AbstractMultispati -Multispati -fit(::Type{Multispati}, +MULTISPATI +fit(::Type{MULTISPATI}, X::AbstractMatrix{T}, W::AbstractMatrix{U}, Q::AbstractMatrix{T}=I, D::AbstractMatrix{T}=I / size(X, 2); kwargs ) where {T<:Real,U<:Real} -predict(::Multispati, x::AbstractVecOrMat{T}) where {T<:Real} -reconstruct(::Multispati, y::AbstractVecOrMat{T}) where {T<:Real} +predict(::MULTISPATI, x::AbstractVecOrMat{T}) where {T<:Real} +reconstruct(::MULTISPATI, y::AbstractVecOrMat{T}) where {T<:Real} moransIbounds size(::AbstractMultispati) projection(::AbstractMultispati) diff --git a/docs/src/index.md b/docs/src/index.md index 0412351..1716c36 100644 --- a/docs/src/index.md +++ b/docs/src/index.md @@ -1,4 +1,4 @@ -# MULTISPATI.jl +# Multispati.jl Julia implementation of [MULTISPATI](https://doi.org/10.3170/2007-8-18312) @@ -8,14 +8,14 @@ The package can be installed with the Julia package manager. From the Julia REPL, type `]` to enter the `Pkg` REPL mode and run: ``` -pkg> add MULTISPATI +pkg> add Multispati ``` Or, alternatively, via the `Pkg` API: ```julia using Pkg -Pkg.add("MULTISPATI") +Pkg.add("Multispati") ``` ## Index diff --git a/src/multispati_.jl b/src/MULTISPATI_.jl similarity index 86% rename from src/multispati_.jl rename to src/MULTISPATI_.jl index afd3631..058bdd3 100644 --- a/src/multispati_.jl +++ b/src/MULTISPATI_.jl @@ -1,7 +1,3 @@ -# MULTISPATI - -# TODO: :auto solver -# TODO: centering of Multispati? """ AbstractMultispati @@ -9,9 +5,9 @@ abstract type AbstractMultispati <: LinearDimensionalityReduction end """ - Multispati <: AbstractMultispati + MULTISPATI <: AbstractMultispati """ -struct Multispati{T<:Real} <: AbstractMultispati +struct MULTISPATI{T<:Real} <: AbstractMultispati proj::AbstractMatrix{T} eigvals::AbstractVector{T} W::AbstractMatrix{T} @@ -36,36 +32,36 @@ projection(M::AbstractMultispati) = M.proj """ eigvecs(M::AbstractMultispati) -Get the eigenvectors of the Multispati model `M`. +Get the eigenvectors of the model `M`. """ eigvecs(M::AbstractMultispati) = projection(M) """ eigvals(M::AbstractMultispati) -Get the eigenvalues of the Multispati model `M`. +Get the eigenvalues of the model `M`. """ eigvals(M::AbstractMultispati) = M.eigvals """ - predict(M::Multispati, x::AbstractVecOrMat{<:Real}) + predict(M::MULTISPATI, x::AbstractVecOrMat{<:Real}) -Transform the observations `x` with the Multispati model `M`. +Transform the observations `x` with the model `M`. Here, `x` can be either a vector of length `d` or a matrix where each column is an observation. """ -predict(M::Multispati, x::AbstractVecOrMat{T}) where {T<:Real} = +predict(M::MULTISPATI, x::AbstractVecOrMat{T}) where {T<:Real} = transpose(projection(M)) * x """ - reconstruct(M::Multispati, y::AbstractVecOrMat{<:Real}) + reconstruct(M::MULTISPATI, y::AbstractVecOrMat{<:Real}) -Approximately reconstruct the observations `y` to the original space using the Multispati model `M`. +Approximately reconstruct the observations `y` to the original space using the model `M`. Here, `y` can be either a vector of length `p` or a matrix where each column gives the components for an observation. """ -reconstruct(M::Multispati, y::AbstractVecOrMat{T}) where {T<:Real} = projection(M) * y +reconstruct(M::MULTISPATI, y::AbstractVecOrMat{T}) where {T<:Real} = projection(M) * y """ moransIbounds(M::AbstractMultispati; sparse_approx::Bool=true) @@ -91,24 +87,28 @@ function moransIbounds(M::AbstractMultispati; sparse_approx::Bool=true) doublecenter!(L) end - eigenvals = n / sum(L) * eigs(L; nev=2, which=:BE, ritzvec=false) + eigenvals, _ = eigs(L; nev=2, which=:BE, ritzvec=false) + eigenvals .*= n / sum(L) I0 = -1 / (n - 1) - Imin = min(eigenvals) - Imax = max(eigenvals) + Imin = minimum(eigenvals) + Imax = maximum(eigenvals) return Imin, Imax, I0 end -function show(io::IO, M::Multispati) +function show(io::IO, M::MULTISPATI) idim, odim = size(M) - return print(io, "Multispati(indim = $idim, outdim = $odim)") + return print(io, "MULTISPATI(indim = $idim, outdim = $odim)") end +# TODO: :auto solver +# TODO: centering of MULTISPATI.fit? + """ - fit(Multispati, X, W, Q=I, D=I / size(X, 2); ...) + fit(MULTISPATI, X, W, Q=I, D=I / size(X, 2); ...) -Perform Multispati over the data given a matrix `X`. Each column of `X` is an **observation**. +Perform MULTISPATI over the data given a matrix `X`. Each column of `X` is an **observation**. `W` is a connectivity matrix where ``w_{ij}`` is the connection from j -> i. `Q` is a symmetric matrix of size `n` (or LinearAlgebra.UniformScaling(@ref)) and `D` a symmetric matrix of size `d` (or LinearAlgebra.UniformScaling(@ref)) @@ -131,7 +131,7 @@ multivariate spatial correlation." *Journal of vegetation science* (2008)](https *The annals of applied statistics* (2011)](https://doi.org/10.1214/10-aoas408) """ function fit( - ::Type{Multispati}, + ::Type{MULTISPATI}, X::AbstractMatrix{T}, W::AbstractMatrix{U}, Q=I, @@ -171,7 +171,7 @@ function fit( Symmetric(H), maxoutdim; solver=solver, tol=tol, maxiter=maxiter ) - return Multispati(eigenvecs, eigenvals, W) + return MULTISPATI(eigenvecs, eigenvals, W) end function validate_maxoutdim(d::Integer, n::Integer, maxoutdim) diff --git a/src/MULTISPATI.jl b/src/Multispati.jl similarity index 82% rename from src/MULTISPATI.jl rename to src/Multispati.jl index b2a0e2b..287947f 100644 --- a/src/MULTISPATI.jl +++ b/src/Multispati.jl @@ -1,4 +1,4 @@ -module MULTISPATI +module Multispati import Base: size, show import LinearAlgebra: eigvals, eigvecs, issymmetric @@ -12,7 +12,7 @@ using LinearAlgebra: I, Symmetric, eigen, normalize! using SparseArrays: issparse export AbstractMultispati, - Multispati, + MULTISPATI, SpatialPCA, fit, predict, @@ -24,7 +24,7 @@ export AbstractMultispati, moransIbounds, varianceMoransIdecomposition -include("multispati_.jl") -include("spatialPCA.jl") +include("MULTISPATI_.jl") +include("SpatialPCA.jl") -end # module MULTISPATI +end # module Multispati diff --git a/src/spatialPCA.jl b/src/SpatialPCA.jl similarity index 98% rename from src/spatialPCA.jl rename to src/SpatialPCA.jl index 0b0c500..f1ffd5a 100644 --- a/src/spatialPCA.jl +++ b/src/SpatialPCA.jl @@ -64,7 +64,7 @@ function varianceMoransIdecomposition(M::SpatialPCA, X) laggedX = transformedX * M.W w = 1 / size(M.W, 1) # sum of row_weights but because its normed the sum is n variance = sum(transformedX .* transformedX .* w; dims=2) - moransI = sum(transformedX .* laggedX .* w; dims=2) ./ variance # TODO ? + moransI = sum(transformedX .* laggedX .* w; dims=2) ./ variance return variance, moransI end @@ -76,7 +76,7 @@ end """ fit(SpatialPCA, X, W; ...) -Perform spatialPCA over the data given a matrix `X` and `W`. Each column of `X` is an **observation**. +Perform SpatialPCA over the data given a matrix `X` and `W`. Each column of `X` is an **observation**. `W` is a connectivity matrix where ``w_{ij}`` is the connection from j -> i. **Keyword arguments** diff --git a/test/Aqua.jl b/test/Aqua.jl index b678d18..3d608a0 100644 --- a/test/Aqua.jl +++ b/test/Aqua.jl @@ -1,3 +1,3 @@ using Aqua -Aqua.test_all(MULTISPATI; ambiguities=(recursive = false)) +Aqua.test_all(Multispati; ambiguities=(recursive = false)) diff --git a/test/runtests.jl b/test/runtests.jl index 72de22b..c044c83 100644 --- a/test/runtests.jl +++ b/test/runtests.jl @@ -1,4 +1,4 @@ using Test -using MULTISPATI +using Multispati include("Aqua.jl")