MyNixOS website logo
Description

The basic geometric type system of Goal.

goal-geometry provides the basic types and classes which drive the manifold/geometry based approach of Goal. Points and manifolds, dual spaces, function spaces and multilayer neural networks, and generic optimization routines are defined here.

In this package we find all the basic types and classes which drive the manifold/geometry based approach of Goal. In particular, points and manifolds, dual spaces, function spaces and multilayer neural networks, and generic optimization routines such as gradient pursuit. What follows is very brief introduction to how we define points on a manifold in Goal.

The fundamental class in Goal is the Manifold

class KnownNat (Dimension x) => Manifold x where
    type Dimension x :: Nat

Manifolds have an associated type, which is the Dimension of the Manifold. The Dimension of a Manifold tells us the size required of vector to represent a 'Point's on the given Manifold. In turn a Point is defined as

newtype Point c x =
    Point { coordinates :: S.Vector (Dimension x) Double }

At the value level, a Point is a wrapper around an S.Vector, which is a storable vector from the vector-sized package, with size Dimension x. In general, numerical operations in Goal are defined in terms of vector-sized and hmatrix, with specific functions for applying operations in bulk. Although I make no promises, Goal should be quite efficient, at least for a CPU-based numerical library.

To continue, a Point is defined at the type-level by a Manifold x, and the mysterious phantom type c. In Goal c is referred to as a coordinate system, or more succinctly as a chart. A coordinate system describes how the abstract elements of a Manifold may be uniquely represented by a vector of numbers. In Goal we usually refer to Points with the following infix type synonym

type (c # x) = Point c x

which we may read as a Point in c coordinates on the x Manifold. I chose the # symbol because it is reminiscent of the grid of a coordinate system.

Finally, with the notion of a coordinate system in hand, we may definition transition functions for re-representing Points in alternative coordinate systems

class Transition c d x where
    transition :: c # x -> d # x

As an example, where we define Euclidean space

data Euclidean (n :: Nat)

instance (KnownNat n) => Manifold (Euclidean n) where
    type Dimension (Euclidean n) = n

and two coordinate systems on Euclidean space with an appropriate transition function

data Cartesian
data Polar

instance Transition Cartesian Polar (Euclidean 2) where
    {-# INLINE transition #-}
    transition p =
        let [x,y] = listCoordinates p
            r = sqrt $ (x*x) + (y*y)
            phi = atan2 y x
         in fromTuple (r,phi)

we may create a Point in Cartesian coordinates an easily convert it to Polar coordinates

xcrt :: Cartesian # Euclidean 2
xcrt = fromTuple (1,2)

xplr :: Polar # Euclidean 2
xplr = transition xcrt

So what has this bought us? Why would we make use of not only one, but essentially two phantom types for describing vectors? Intuitively, the Manifold under investigation is what we care about. If, for example, we consider a Manifold of probability distributions, it is the distributions themselves we care about. But distributions are abstract things, and so we represent them in various coordinate systems (e.g. mean and variance) to handle them numerically.

The charts available for a given Manifold are thus different (but isomorphic) representations of the same thing. In particular, many coordinate systems have a dual coordinate system that describes function differentials, which is critical for numerical optimization. In general, many optimization problems can be greatly simplified by finding the right coordinate system, and many complex optimization problems can be solved by sequence of coordinate transformations and simple numerical operations. Numerically the resulting computation is not trivial, but theoretically it becomes an intuitive thing.

For in-depth tutorials visit my blog.

Metadata

Version

0.20

Platforms (75)

    Darwin
    FreeBSD
    Genode
    GHCJS
    Linux
    MMIXware
    NetBSD
    none
    OpenBSD
    Redox
    Solaris
    WASI
    Windows
Show all
  • aarch64-darwin
  • aarch64-genode
  • aarch64-linux
  • aarch64-netbsd
  • aarch64-none
  • aarch64_be-none
  • arm-none
  • armv5tel-linux
  • armv6l-linux
  • armv6l-netbsd
  • armv6l-none
  • armv7a-darwin
  • armv7a-linux
  • armv7a-netbsd
  • armv7l-linux
  • armv7l-netbsd
  • avr-none
  • i686-cygwin
  • i686-darwin
  • i686-freebsd
  • i686-genode
  • i686-linux
  • i686-netbsd
  • i686-none
  • i686-openbsd
  • i686-windows
  • javascript-ghcjs
  • loongarch64-linux
  • m68k-linux
  • m68k-netbsd
  • m68k-none
  • microblaze-linux
  • microblaze-none
  • microblazeel-linux
  • microblazeel-none
  • mips-linux
  • mips-none
  • mips64-linux
  • mips64-none
  • mips64el-linux
  • mipsel-linux
  • mipsel-netbsd
  • mmix-mmixware
  • msp430-none
  • or1k-none
  • powerpc-netbsd
  • powerpc-none
  • powerpc64-linux
  • powerpc64le-linux
  • powerpcle-none
  • riscv32-linux
  • riscv32-netbsd
  • riscv32-none
  • riscv64-linux
  • riscv64-netbsd
  • riscv64-none
  • rx-none
  • s390-linux
  • s390-none
  • s390x-linux
  • s390x-none
  • vc4-none
  • wasm32-wasi
  • wasm64-wasi
  • x86_64-cygwin
  • x86_64-darwin
  • x86_64-freebsd
  • x86_64-genode
  • x86_64-linux
  • x86_64-netbsd
  • x86_64-none
  • x86_64-openbsd
  • x86_64-redox
  • x86_64-solaris
  • x86_64-windows