Skip to content

[Enhancement]: Generalize approximate_kernel_expectation to non-square matrices #563

Description

@ofSingularMind

Feature/Enhancement Description

Considering the current implementation (below), we note that gbar is assumed to be square of dims equal to distribution, but this is not always the case.

function approximate_kernel_expectation(method::AbstractApproximationMethod, g::Function, m::AbstractVector{T}, P::AbstractMatrix{T}) where {T <: Real}
    ndims = length(m)

    weights = getweights(method, m, P)
    points  = getpoints(method, m, P)

    gbar = zeros(ndims, ndims)
    foreach(zip(weights, points)) do (weight, point)
        axpy!(weight, g(point), gbar) # gbar = gbar + weight * g(point)
    end

    return gbar
end

Motivation / Use Case

RxGP.jl forms kernel function expectations that are non-square.

Proposed Solution

Per @HoangMHNguyen's work, the below seems to work well.

function approximate_kernel_expectation(method::AbstractApproximationMethod, g::Function, m::AbstractVector{T}, P::AbstractMatrix{T}) where {T <: Real}
    weights = getweights(method, m, P)
    points  = getpoints(method, m, P)

    gbar = g(m) .* 0.0
    foreach(zip(weights, points)) do (weight, point)
        axpy!(weight, g(point), gbar) # gbar = gbar + weight * g(point)
    end
    return gbar
end

Alternatives Considered

No response

Example Use Cases

No response

Priority (from your perspective)

Critical for my use case

Related Issues / Discussions

No response

Additional Context

No response

Metadata

Metadata

Assignees

No one assigned

    Labels

    enhancementNew feature or request

    Type

    No type

    Fields

    No fields configured for issues without a type.

    Projects

    Status
    Backlog

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions