Soss.jl icon indicating copy to clipboard operation
Soss.jl copied to clipboard

Implement the TableTraits.jl interface

Open kskyten opened this issue 4 years ago • 2 comments

Ingesting data from the IterableTables interface would open a whole host of data sources from various Julia packages,

kskyten avatar Nov 08 '19 17:11 kskyten

What do you see missing for this to be supported? Can you give an example of how you'd like to use this in a model?

It seems like this could be orthogonal to Soss, once we have #42

cscherrer avatar Nov 09 '19 16:11 cscherrer

It would be nice to use data in other formats than just named tuples in models for convenience. For example:

using Soss
using DataFrames

df = DataFrame((complaints = [1, 2, 3], traps = [1, 2, 3]))

m = @model (alpha, beta, traps) begin
  lambda = alpha .+ beta .* traps
  complaints ~ For(eachindex(traps)) do i
    Poisson(lambda[i])
  end
end

Currently you have to do

params = (alpha = 0.0, beta = 1.0, traps = df.traps)
data = (complaints = df.complaints,)

post = dynamicHMC(m(params), data)

but it would be nice to have something like

post = dynamicHMC(m((alpha = 0.0, beta = 1.0)), df)

where df could be any table like data source. I can't think of a way to implement this externally.

It is actually TableTraits.jl that we want. It contains the IterableTable traits. The IterableTable interface is the lowest common denominator, but you get an iterator of named tuples from it. There is a utility function in TableTraitUtils to turn this into columns as well as a direct column view interface in TableTraits.jl for the data sources that support it.

kskyten avatar Nov 09 '19 18:11 kskyten