g_hav: Haversine distance on sphere

View source: R/spherical_sm.R

g_havR Documentation

Haversine distance on sphere

Description

Calculate great circle distance between a set of points and a boundary, with gradient

Usage

g_hav(z, dV, r = 1)

Arguments

z

matrix of euclidean coordinates

dV

boundary in euclidean coordinates

r

radius of sphere, default 1

Details

This is one possible boundary function g that can be used for truncated score matching on a sphere, used by the "Haversine" argument to sphere_sm.

This function first finds the distance between the truncated dataset z and the boundary dV, using the haversine distance function (from the geosphere package):

d = 2 r arcsin( √{ sin^2 ( (θ_2 - θ_1) / 2 ) + cos (θ_1) cos(θ_2) sin^2( (φ_2 - φ_1)/2 ) } ),

where (φ_1, θ_1) is the longitude and latitude of point 1, and (φ_2, θ_2) is the longitude and latitude of point 2, both in radians, and r is the radius, default r=1. Once the distances are found, the smallest distances between x and the boundary as well as the first derivative of the haversine function are saved and output back to the score matching function.

Note that z and dV are Euclidean coordinates, and this function converts them to spherical coordinates before taking the distance (as required by the Haversine). This is for consistency.

Value

List containing two elements

g

values of function g

grad

matrix of derivatives of g


dannyjameswilliams/truncsm documentation built on Aug. 22, 2022, 3:44 p.m.