Julep: allow passing an operator to `var`

Open
#29 13 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

Assessment

Difficulty
5/5
Estimated time
Over a week
Newbie friendliness
35/100
Issue type
Feature
Clarity
Needs clarification
Activity status
Stale
Tech stack
julia
Domain
data

Research direction

Start with the var(a) and var(a; dims=1) examples in the issue, then read the linked ColorVectorSpace discussion and consider the coordination with StaticArrays. Done would require an agreed operator-passing API for var and corresponding behavior for dot, elementwise, and outer-product cases.

Written by the indexing model from the issue text.

Description

This is a bit of a cross-post from https://github.com/JuliaGraphics/ColorVectorSpace.jl/issues/126, but let me provide a more succinct summary specialized to this package. Consider the following demo:

julia> using Statistics, StaticArrays

julia> a = rand(SVector{3,Float32}, 3)
3-element Array{SArray{Tuple{3},Float32,1,3},1}:
 [0.46784067, 0.55236137, 0.30518198]
 [0.45679474, 0.8746067, 0.7767879]  
 [0.30195618, 0.48870897, 0.37561262]

julia> var(a)
3-element SArray{Tuple{3},Float32,1,3} with indices SOneTo(3):
 0.008602443
 0.042801797
 0.06471903 

julia> var(a; dims=1)
ERROR: MethodError: no method matching abs2(::SArray{Tuple{3},Float32,1,3})
Closest candidates are:
  abs2(::Missing) at missing.jl:100
  abs2(::Bool) at bool.jl:84
  abs2(::Real) at number.jl:157
  ...
Stacktrace:

There's a sense in which the error is the correct outcome, and the one that returns a vector is a bit of a misnomer; after all, the definition of var as E[(X-μ)^2] requires that one can compute y^2 for objects drawn from X, but * does not mean elementwise multiplication.

Over in ColorVectorSpace we've hit upon the following idea: defining ⋅ (\cdot) as the "dot product", ⊙ operating elementwise (like broadcasting-* but we can't pass that as a function argument and therefore need a different operator), and ⊗ (\otimes) to mean the outer product. In that circumstance, var(⋅, a) becomes the mean-square-error, var(⊙, a) becomes the elementwise variance, and var(⊗, a) is the covariance.

I'd be interested in your thoughts. I also think it makes sense for ColorVectorSpace and maybe StaticArrays (CC @c42f) to synchronize, if possible.

Dominant language
Julia
Stars
93
Forks
51
PR merge metrics
No merged PRs in 30d

Getting set up

This project ships no dev container, Dockerfile or contributing guide, so setting up is up to you: start from its README, and see our first-contribution guide for the general steps.

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

More from JuliaStats/Statistics.jl

All issues in JuliaStats/Statistics.jl

Similar issues

More Julia issues

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.