Code Monkey home page Code Monkey logo

Comments (1)

juliohm avatar juliohm commented on May 27, 2024

Hi @mingtaojia, thank you for reporting the issue.

Recently I have migrated all the distances defined in GeoStats.jl to the package Distances.jl. There is a delay, however; in this final pull request for the Ellipsoidal distance: JuliaStats/Distances.jl#81. That is my fault, I need to find time to finish it.

I will release a hot fix soon introducing the distance back again in GeoStats.jl. Meanwhile, if you need to keep going with your work, you can copy the code below in your session to define the distance locally:

using Distances

struct Ellipsoidal{N,T} <: Metric
    dist::Mahalanobis{T}

    function Ellipsoidal{N,T}(semiaxes, angles) where {N,T<:Real}
        @assert length(semiaxes) == N "number of semiaxes must match spatial dimension"
        @assert all(semiaxes .> zero(T)) "semiaxes must be positive"
        @assert N  [2,3] "dimension must be either 2 or 3"

        # scaling matrix
        Λ = spdiagm(one(T)./semiaxes.^2)

        # rotation matrix
        if N == 2
            θ = angles[1]

            cosθ = cos(θ)
            sinθ = sin(θ)

            P = [cosθ -sinθ
                 sinθ  cosθ]
        end
        if N == 3
            θxy, θyz, θzx = angles

            cosxy = cos(θxy)
            sinxy = sin(θxy)
            cosyz = cos(θyz)
            sinyz = sin(θyz)
            coszx = cos(θzx)
            sinzx = sin(θzx)

            _1 = one(T)
            _0 = zero(T)

            Rxy = [cosxy -sinxy _0
                   sinxy  cosxy _0
                      _0     _0 _1]

            Ryz = [_1    _0     _0
                   _0 cosyz -sinyz
                   _0 sinyz  cosyz]

            Rzx = [ coszx _0 sinzx
                       _0 _1    _0
                   -sinzx _0 coszx]

            P = Rzx*Ryz*Rxy
        end

        # ellipsoid matrix
        Q = P*Λ*P'

        new(Mahalanobis(Q))
    end
end

Ellipsoidal(semiaxes::AbstractVector{T}, angles::AbstractVector{T}) where {T<:Real} =
  Ellipsoidal{length(semiaxes),T}(semiaxes, angles)

result_type(::Ellipsoidal{N,T}, ::AbstractArray, ::AbstractArray) where {N,T} = T

function evaluate(dist::Ellipsoidal{N,T}, a::AbstractVector, b::AbstractVector) where {N,T<:Real}
    evaluate(dist.dist, a, b)
end

ellipsoidal(a::AbstractVector, b::AbstractVector,
            semiaxes::AbstractVector, angles::AbstractVector) = evaluate(Ellipsoidal(semiaxes, angles), a, b)

After the code is pasted in your Julia session, you can proceed with the script as usual.

from geostats.jl.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.