Skip to content

Commit

Permalink
rename package, fix moransIbounds
Browse files Browse the repository at this point in the history
  • Loading branch information
niklasmueboe committed Aug 25, 2024
1 parent 8996447 commit f8329fe
Show file tree
Hide file tree
Showing 11 changed files with 53 additions and 53 deletions.
2 changes: 1 addition & 1 deletion Project.toml
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
name = "MULTISPATI"
name = "Multispati"
uuid = "3ff64760-8a89-40e2-854d-b45336bb1975"
authors = ["Niklas Müller-Bötticher <[email protected]>"]
version = "0.1.0"
Expand Down
14 changes: 7 additions & 7 deletions README.md
Original file line number Diff line number Diff line change
@@ -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)

Expand All @@ -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/).
2 changes: 1 addition & 1 deletion docs/Project.toml
Original file line number Diff line number Diff line change
@@ -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"
Expand Down
6 changes: 3 additions & 3 deletions docs/make.jl
Original file line number Diff line number Diff line change
@@ -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")
12 changes: 6 additions & 6 deletions docs/src/api.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
# Reference API

Documentation for `MULTISPATI.jl`'s public interface.
Documentation for `Multispati.jl`'s public interface.

## Index

Expand All @@ -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)
Expand Down
6 changes: 3 additions & 3 deletions docs/src/index.md
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
# MULTISPATI.jl
# Multispati.jl

Julia implementation of [MULTISPATI](https://doi.org/10.3170/2007-8-18312)

Expand All @@ -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
Expand Down
46 changes: 23 additions & 23 deletions src/multispati_.jl → src/MULTISPATI_.jl
Original file line number Diff line number Diff line change
@@ -1,17 +1,13 @@
# MULTISPATI

# TODO: :auto solver
# TODO: centering of Multispati?

"""
AbstractMultispati
"""
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}
Expand All @@ -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)
Expand All @@ -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))
Expand All @@ -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,
Expand Down Expand Up @@ -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)
Expand Down
10 changes: 5 additions & 5 deletions src/MULTISPATI.jl → src/Multispati.jl
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
module MULTISPATI
module Multispati

import Base: size, show
import LinearAlgebra: eigvals, eigvecs, issymmetric
Expand All @@ -12,7 +12,7 @@ using LinearAlgebra: I, Symmetric, eigen, normalize!
using SparseArrays: issparse

export AbstractMultispati,
Multispati,
MULTISPATI,
SpatialPCA,
fit,
predict,
Expand All @@ -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
4 changes: 2 additions & 2 deletions src/spatialPCA.jl → src/SpatialPCA.jl
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand All @@ -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**
Expand Down
2 changes: 1 addition & 1 deletion test/Aqua.jl
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
using Aqua

Aqua.test_all(MULTISPATI; ambiguities=(recursive = false))
Aqua.test_all(Multispati; ambiguities=(recursive = false))
2 changes: 1 addition & 1 deletion test/runtests.jl
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
using Test
using MULTISPATI
using Multispati

include("Aqua.jl")

2 comments on commit f8329fe

@niklasmueboe
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@JuliaRegistrator
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Registration pull request created: JuliaRegistries/General/113827

Tip: Release Notes

Did you know you can add release notes too? Just add markdown formatted text underneath the comment after the text
"Release notes:" and it will be added to the registry PR, and if TagBot is installed it will also be added to the
release that TagBot creates. i.e.

@JuliaRegistrator register

Release notes:

## Breaking changes

- blah

To add them here just re-invoke and the PR will be updated.

Tagging

After the above pull request is merged, it is recommended that a tag is created on this repository for the registered package version.

This will be done automatically if the Julia TagBot GitHub Action is installed, or can be done manually through the github interface, or via:

git tag -a v0.1.0 -m "<description of version>" f8329fe6bd680a7a130a70b06411074e891d4f12
git push origin v0.1.0

Please sign in to comment.