-
Notifications
You must be signed in to change notification settings - Fork 5
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
78 changed files
with
4,398 additions
and
2,449 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,157 @@ | ||
# Design Overview | ||
|
||
## Example | ||
|
||
```cpp | ||
DataView<std::vector<double>, ppl::vec> x(raw_x); | ||
// Data<double, ppl::vec> x({...}); // another option | ||
Param<double> l1; | ||
ParamFixed<double, 3> l2; | ||
// Param<double, ppl::vec> l2(3); // another option | ||
auto model = ( | ||
l1 |= normal(0., 1.), | ||
l2 |= normal(l1, 2.), | ||
x |= normal(l2[0] * l2[1] - l2[2], 1.) | ||
); | ||
l1.storage(ptr); | ||
l2.storage(ptr, i); | ||
ppl::nuts(model); | ||
``` | ||
- `l1` is a scalar that is standard normally distributed | ||
- `l2` is a vector of size 3 that is each independently ~ N(l1, 2) | ||
- `x` is a vector of data ~ N(l2[0]*l2[1]-l2[2], 1.) | ||
- `l2` is subscriptable | ||
## Variable | ||
A variable really is only satisfied by Param, ParamView, Data, DataView, or alike. | ||
Every first variable has a unique ID or views a unique ID. | ||
This is so that we have a way to know which variable that gets referenced | ||
in the model is pointing to the "same" entity. | ||
This can be useful when checking correct construction of model such as: | ||
- no variable gets assigned a distribution more than once | ||
- no variable gets assigned a distribution, which references the same variable | ||
- no distribution uses variables that reference variables below it | ||
### Param | ||
A Param should be a variable expression and also a variable. | ||
The model will only be built using ParamView since Param may own values | ||
that the model should only view. | ||
If Param is multi-dimensional (vec, mat), size of the shape must be known | ||
at construction and cannot change. | ||
The model may reference old size values if changed. | ||
Logically, a parameter denoted by a symbol was defined from fathoming a model. | ||
If it is immediately used in a different model, it's most likely that the parameter | ||
represents the same kind of quantity, but assigned to a different distribution. | ||
## Concepts | ||
### model_expr | ||
Implements: | ||
```cpp | ||
template <class F> | ||
void traverse(F&& elt_f); // + const version | ||
template <class F1, class F2> | ||
void traverse(F1&& elt_f, F2&& combine_f); // + const version | ||
/*...*/ pdf() const; | ||
/*...*/ log_pdf() const; | ||
template <class MapType, class VecType> | ||
/*...*/ ad_log_pdf(const MapType& map, | ||
const VecType& vars) const; | ||
``` | ||
|
||
- map is expected to be a hashmap of: | ||
``` | ||
addresses of unique parameters (const void*) -> | ||
begin idx of corresponding vector of vars | ||
``` | ||
- Ex. | ||
``` | ||
(mu |= normal(0,1), s |= normal(0,1), x |= normal(mu, s)) | ||
addr(mu) -> 0 | ||
addr(s) -> 1 | ||
AD Var vec: [v1, v2] | ||
``` | ||
|
||
## Expression Nodes | ||
|
||
The core of AutoPPL is how we construct expressions. | ||
These expressions and their interaction define a language to express model construction. | ||
|
||
#### Glue Node | ||
|
||
``` | ||
glue_node = (model_expr, model_expr); | ||
``` | ||
|
||
##### Sketch of Interface | ||
|
||
```cpp | ||
struct GlueNode | ||
{ | ||
traverse(elt_f) | ||
traverse(elt_f, combine_f) | ||
pdf() | ||
log_pdf() | ||
ad_log_pdf(map, vars) | ||
}; | ||
``` | ||
Example: | ||
```cpp | ||
// apply log_pdf to get and add them all | ||
double lgpdf = model.traverse(log_pdf, add); | ||
// apply ad_log_pdf to get AD expr and add them all | ||
// if ad_log_pdf or add requires extra parameters, lambdafy them: | ||
// [&](auto& elt) {return ad_log_pdf(elt, other_params...);} | ||
auto ad_expr = model.traverse(ad_log_pdf, add); | ||
// get each "unique quantity" and add them to the mapping | ||
model.traverse(update_map); | ||
``` | ||
|
||
#### Eq Node | ||
|
||
``` | ||
eq_node = (quantity_expr |= dist_expr); | ||
``` | ||
|
||
An eq expression relates a quantity with a distribution. | ||
While the arguments can be generalized further, | ||
we're most motivated by the example when quantity is a parameter/data | ||
of either variable/vector/mat (vvm) form and dist_expr is one such as normal distribution. | ||
|
||
##### Sketch of Interface | ||
|
||
```cpp | ||
struct EqNode | ||
{ | ||
traverse(eq_f); | ||
traverse(eq_f, combine_f); | ||
pdf(); | ||
log_pdf(); | ||
ad_log_pdf(map, vars); | ||
get_variable(); | ||
get_distribution(); | ||
}; | ||
``` | ||
- map is the mapping of addresses of params/data to corresponding | ||
index of a vector of AD vectors. | ||
- Ex. | ||
``` | ||
mu |= normal(0,1), x |= normal(mu, 1) | ||
addr(mu) -> 0 | ||
addr(x) -> 1 | ||
AD Var vec: [v1, v2] | ||
``` |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.