ACEsuit / Polynomials4ML.jl

Polynomials for ML: fast evaluation, batching, differentiation
MIT License
12 stars 5 forks source link

SINGLE and BATCH #27

Open cortner opened 1 year ago

cortner commented 1 year ago

is there a solution to this ambiguity?

julia> x = @SVector rand(3)
3-element SVector{3, Float64} with indices SOneTo(3):
 0.589586907694296
 0.7260573271521483
 0.22833616024528036

julia> x isa Polynomials4ML.SINGLE
true

julia> x isa Polynomials4ML.BATCH
true

It is maybe not so important because of this:

julia> wii(::Polynomials4ML.SINGLE) = "single"
wii (generic function with 1 method)

julia> wii(::Polynomials4ML.BATCH) = "batch"
wii (generic function with 2 methods)

julia> wii(x)
"single"
cortner commented 1 year ago

In light of some recent changes to the abstract type hierarchy (CC @CheukHinHoJerry ) maybe this can now be re-designed? Basically what happens is that different classes of bases now put different meanings to the term SINGLE and BATCH. This will surely help here.

cortner commented 1 year ago

maybe some meta-programming ... ?

cortner commented 1 year ago

@CheukHinHoJerry -- I was thinking about the following:

A matrix A can be a single input or it can be a batch of inputs. Therefore we need to be able to label what it is. I propose to introduce a wrapper type Batch that identifies when an array is a batch as opposed to a single input. Then the batched evaluation can dispatch on that. E.g.

rr = # Vectors of input radial distances 
Rn = # radial basis
evaluate(Rn, Batch(rr)) 
# output will be a `Batch{Matrix}` rather than a `Matrix`

(or something along those lines) What do you think of this?

How do the most common ML frameworks deal with that?

CheukHinHoJerry commented 1 year ago

Sorry for missing that in early Jun. What you mentioned sounds right. I will mull this over a little while and get back to you tonight.

CheukHinHoJerry commented 1 year ago

Should we also consider this together with what we want to do in https://github.com/ACEsuit/Polynomials4ML.jl/issues/18#issue-1693166039?

Can we at the same time drop all codes that with only single input, reshape PtrArray for free and label the output array as what you have mentioned? This makes a lot of sense to me.

cortner commented 1 year ago

you are right, this is closely related.

cortner commented 1 year ago

Maybe we can add this issue to our discussion with @tjjarvinen

CheukHinHoJerry commented 1 year ago

Before we rewrite anything maybe we should first discuss this?

CC @tjjarvinen