funsor icon indicating copy to clipboard operation
funsor copied to clipboard

Redesign adjoint / transpose interface and algorithms

Open fritzo opened this issue 4 years ago • 2 comments

Design doc

Reading list

Questions

  1. Linear Types: Funsor metadata includes domains for inputs and output, similar to a type signature a1 * ... * an -> b. Should metadata also indicate which inputs are treated linearly, similar to a type signature a1 * ... * an -> (b1 * ... * bn -o c)?
  2. linearize(): How can we implement a linearize(fn: Funsor, linear_vars: Frozenset[Variable])? Can this introduce new patterns but avoid introducing new Funsor subclasses?
  3. transpose(): How can we implement a transpose(fn:Funsor, ???)? Does this require new Funsor subclasses?
  4. Types: What is the type of backward-marginals? Of backward-sample? Of backward-argmax? Of backward-kbest?
  5. Decomposition: Can we decompose backward-sample into a Monte Carlo interpretation of backward-marginal? Can we decompose backward-argmax into a "maximize" interpretation of backward-marginal?
  6. Can we implement a tape-free adjoint algorithm, as suggested in Elliot's "Simple Essence of AD"?

fritzo avatar Jan 29 '21 22:01 fritzo

Just throwing out an idea here. Another perspective on two different semi-rings (ops.add, ops.mul) and (ops.logaddexp, ops.add) is to view the latter as operations lifted by a Log Functor. In Haskell notation:

instance Functor Log where
    fmap f :: Log a -> Log b
    fmap f (Log a) = Log (f a)

...

fmap (*) (Log (x, y)) = Log (x*y) = Log x + Log y
fmap (+)  = logaddexp

These two different types could be represented by something like Factor and Logfactor funsors which can be used for pattern matching. Not sure if this adds anything new though.

As a side note, can Funsor be used to represent partially applied functions?

ordabayevy avatar Feb 20 '21 06:02 ordabayevy

@ordabayevy yes I think your Log functor relates the semiring pair ((add,mul), (logaddexp,add)) and the pair ((max,mul),(max,add)). However no functor relates e.g. the pair ((add,mul), (max,add)).

Indeed Funsors can represent functions, and funsor substitution represents partially applied functions.

fritzo avatar Feb 21 '21 15:02 fritzo