# sheffieldml/gpy architecture

> Architecture diagram of the GitHub repository sheffieldml/gpy, generated by GitDiagram from its file tree, README and a sample of source files (last updated 2025-10-22). It is an AI-made overview: check details against the source.

- Interactive diagram: https://gitdiagram.com/sheffieldml/gpy
- Repository: https://github.com/sheffieldml/gpy

## Overview

##### Project type and purpose
- GPy is an open-source Python framework (library) for building and running Gaussian process models.
- It provides a unified API for defining models, kernels, likelihoods, mappings, inference algorithms, and plotting utilities.

##### High-level modules and their roles
- Core engine (GPy/core): Parameter management, model abstractions, algebraic routines.
- Inference engine (GPy/inference): Exact, variational, EP, MCMC, stochastic and grid-based Gaussian process inference algorithms.
- Kernel library (GPy/kern): Collection of covariance functions, some in pure Python and some Cython/C for performance.
- Likelihood functions (GPy/likelihoods): Noise models (Gaussian, Bernoulli, Poisson, etc.) and link functions.
- Mappings (GPy/mappings): Input transforms (linear, additive, piecewise, MLP).
- Model API (GPy/models): High-level wrappers combining core, kernels, likelihoods, inference and mappings into ready-to-use GP models (regression, classification, GPLVM, multi‐output, etc.).
- Utilities (GPy/util): Data loading, maths (parallel linear algebra, GPU init), configuration, helper functions.
- Examples, benchmarks, tests: Usage demos, performance evaluation scripts, and unit tests.

##### Relationships and data flow
- A user script or example invokes a GPy.models class (e.g., GPRegression).
- The model constructor pulls in a kernel object (from GPy/kern) and a likelihood object (from GPy/likelihoods).
- Model parameters are managed by the core engine (parametrization and optimization routines).
- When optimize() or infer() is called, the inference engine uses core routines and the chosen algorithm to compute posterior distributions.
- Kernel computations are dispatched to Python or Cython/C implementations depending on performance requirements.
- Utilities support data handling, GPU/parallel ops, and configuration throughout.
- Plotting modules consume model state and inference results to produce visualizations.

##### Architectural patterns and design principles
- Layered architecture: clear separation between API, core computation, inference, and I/O/visualization.
- Plugin pattern: kernels, likelihoods, and mappings are interchangeable components discovered dynamically.
- Performance extensions: use of Cython and native C code for heavy linear algebra and kernel routines.
- Modular testing: each module has corresponding unit tests under GPy/testing.
- Documentation and CI are first-class: Sphinx docs, Travis CI/Appveyor, code coverage.

##### Technologies and external dependencies
- Python 3.9+, NumPy, SciPy, Cython.
- Optional GPU/parallel support via CUDA back ends in utilities.
- Sphinx for docs, pytest/nose for testing.
- Continuous integration configured via GitHub Actions or Travis/Appveyor YAML.

##### Detailed checklist for the principal software engineer
- And place all major directories as components.
- Data flows (model definition → inference → output → plotting) are clear and labeled.

## Diagram (Mermaid)

```mermaid
flowchart TD
    %% External services
    PythonInterp(["Python Interpreter"]):::external
    CythonRuntime(["Cython/C Runtime"]):::external
    CIServer(["CI Server"]):::external
    SphinxSvc(["Sphinx Documentation Service"]):::external

    %% Core Computation Layer
    subgraph "Core Computation Layer"
        direction TB
        CoreEngine["Core Engine"]:::coreLayer
        InferenceEngine["Inference Engine"]:::coreLayer
    end

    %% API Layer
    subgraph "API Layer"
        direction TB
        Models["Model API"]:::apiLayer
        Mappings["Mappings"]:::apiLayer
    end

    %% Plugin Libraries
    subgraph "Plugin Libraries"
        direction TB
        Kern["Kernel Library"]:::pluginLayer
        Likelihoods["Likelihood Functions"]:::pluginLayer
    end

    %% Support Modules
    subgraph "Support Modules"
        direction TB
        Util["Utilities"]:::supportLayer
        Plotting["Plotting Layer"]:::supportLayer
        Tests["Testing Suite"]:::supportLayer
        Docs["Documentation"]:::supportLayer
        CIConfig["CI Config (.github/workflows)"]:::supportLayer
    end

    %% Examples
    Examples["Examples"]:::supportLayer

    %% Relationships
    Models -->|invoke inference| InferenceEngine
    Models -->|kernel evaluations| Kern
    Models -->|likelihood evaluation| Likelihoods
    InferenceEngine -->|use core routines| CoreEngine
    Kern -->|may use Cython| CythonRuntime
    Util -->|shared services| CoreEngine
    Util -->|shared services| InferenceEngine
    Util -->|shared services| Models
    Util -->|shared services| Kern
    Util -->|shared services| Likelihoods
    Util -->|shared services| Mappings
    Util -->|shared services| Plotting
    Plotting -->|visualization input| Models
    Plotting -->|visualization input| InferenceEngine
    PythonInterp -->|executes| CoreEngine
    PythonInterp -->|executes| Models
    PythonInterp -->|executes| Kern
    PythonInterp -->|executes| Likelihoods
    PythonInterp -->|executes| Mappings
    Examples -->|demo usage| Models
    Tests -->|unit tests| CoreEngine
    Tests -->|unit tests| InferenceEngine
    Tests -->|unit tests| Kern
    Tests -->|unit tests| Likelihoods
    Tests -->|unit tests| Models
    Tests -->|unit tests| Util
    Tests -->|unit tests| Plotting
    Tests -->|run CI pipelines| CIServer
    CIConfig -->|defines workflows| CIServer
    Docs -->|source for| SphinxSvc
    Docs -->|updates| CIServer

    %% Click Events
    click CoreEngine "https://github.com/sheffieldml/gpy/tree/devel/GPy/core/"
    click InferenceEngine "https://github.com/sheffieldml/gpy/tree/devel/GPy/inference/"
    click Kern "https://github.com/sheffieldml/gpy/tree/devel/GPy/kern/"
    click Likelihoods "https://github.com/sheffieldml/gpy/tree/devel/GPy/likelihoods/"
    click Mappings "https://github.com/sheffieldml/gpy/tree/devel/GPy/mappings/"
    click Models "https://github.com/sheffieldml/gpy/tree/devel/GPy/models/"
    click Util "https://github.com/sheffieldml/gpy/tree/devel/GPy/util/"
    click Plotting "https://github.com/sheffieldml/gpy/tree/devel/GPy/plotting/"
    click Examples "https://github.com/sheffieldml/gpy/tree/devel/GPy/examples/"
    click Tests "https://github.com/sheffieldml/gpy/tree/devel/GPy/testing/"
    click Docs "https://github.com/sheffieldml/gpy/tree/devel/doc/source/"
    click CIConfig "https://github.com/sheffieldml/gpy/blob/devel/.github/workflows/test-and-deploy.yml"

    %% Styles
    classDef coreLayer fill:#D0E8FF,stroke:#0366D6,color:#0366D6
    classDef apiLayer fill:#E6FFEA,stroke:#0F9D58,color:#0F9D58
    classDef pluginLayer fill:#FFF4E5,stroke:#ED6C02,color:#ED6C02
    classDef supportLayer fill:#F0F0F0,stroke:#888888,color:#555555
    classDef external fill:#FFEAF0,stroke:#D81B60,color:#D81B60,stroke-dasharray: 5 5
```
