Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Allow parameters to have different data types and shapes #218

Open
alvorithm opened this issue Jun 8, 2020 · 3 comments
Open

Allow parameters to have different data types and shapes #218

alvorithm opened this issue Jun 8, 2020 · 3 comments
Labels
API changes This impacts the public API of the project (e.g. inference class). enhancement New feature or request less-urgent This is beyond the current 2 week horizon

Comments

@alvorithm
Copy link
Contributor

Background

Our current idea of the parameters of a simulator is either something structured (such as a cross-section matrix) or a plurality of scalars and vectors that can be joined into one long vector and whose prior is a set of independent priors over diffferent coordinates (@janfb?).

Goal

It should be possible to have differently-shaped parameters such as e.g. a positive rate, a covariance matrix, and a speed vector passed in, each of them with their own private factor prior (i.e. no need to build an Independent prior to become, formally, a prior over all of them). This is more expressive, and more clear.

Caveats

  • This would require to be able to use lists of tensors instead of now just a single tensor, as input, and correspondingly, conforming (same-length, matching-output-shape) prior distributions.
  • The construction of the neural network, if honoring the structured nature of the inputs, may become complex.
@alvorithm alvorithm added API changes This impacts the public API of the project (e.g. inference class). enhancement New feature or request labels Jun 8, 2020
@alvorithm alvorithm added this to the Sustainable architecture milestone Jun 8, 2020
@janfb
Copy link
Contributor

janfb commented Jun 8, 2020

Actually, I think we cannot handle multi-dimensional parameters yet, e.g., no matrices. If a user wants to define a prior over a matrix she has to implement a prior wrapper that returns a flattened version and then change her simulator such that it takes this flattened vector and reshapes it into a matrix for simulation.

@jan-matthis jan-matthis changed the title Parameter inputs may not conform into a single tensor. Parameter inputs may not conform into a single tensor Jul 2, 2020
@jan-matthis jan-matthis added the less-urgent This is beyond the current 2 week horizon label Jul 2, 2020
@janfb
Copy link
Contributor

janfb commented Feb 28, 2024

Update: we do not require an explicit prior object anymore, at least not for NPE. One can just pass pre-simulated theta and x.

theta must be a tensor though. Thus, if you have differently shaped "sub-priors" you need to take care of how to reshape this into a one-dimensional tensor.

@janfb
Copy link
Contributor

janfb commented Aug 6, 2024

Using pytrees as used in JAX as parameter objects might be an option for adding this feature.

How Pytrees Could Help

  1. Handling Complex Data Structures: Pytrees can easily accommodate complex and nested structures. For your scenario, where parameters might include a positive rate (scalar), a covariance matrix (2D tensor), and a speed vector (1D tensor), Pytrees allow you to organize these into a single nested structure. You can then define operations that will apply uniformly across this structure.
  2. Independent Priors: Each component of the Pytree can have its associated prior distribution. This allows you to manage and manipulate these priors independently, while still treating them as a coherent unit.
  3. Mapping Functions: JAX’s utilities for Pytrees allow you to map functions over the entire structure. This is useful for tasks like computing likelihoods, gradients, or transforming parameters, which can be done in a consistent and automated way without having to manually unpack and repack the structures.
  4. Neural Network Construction: When designing neural networks that process these structured inputs, Pytrees can help manage the complexity. You can define layers or transformations that operate on parts of the Pytree and then combine the results, respecting the structured nature of the inputs.

@janfb janfb changed the title Parameter inputs may not conform into a single tensor Allow parameters to have different data types and shapes Dec 13, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
API changes This impacts the public API of the project (e.g. inference class). enhancement New feature or request less-urgent This is beyond the current 2 week horizon
Projects
None yet
Development

No branches or pull requests

3 participants