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

Associate Content with input variable #2

Closed
IzaakWN opened this issue Jan 19, 2021 · 1 comment · Fixed by #34
Closed

Associate Content with input variable #2

IzaakWN opened this issue Jan 19, 2021 · 1 comment · Fixed by #34
Milestone

Comments

@IzaakWN
Copy link
Contributor

IzaakWN commented Jan 19, 2021

Right now each Content model is assumed to be in the same order as the given input variables, but in some cases an input variable might not be used, or have a different order.

I would propose to add an input(s) attribute to Binning, MultiBinning and Category, e.g.

class Binning(Model):
    nodetype: Literal["binning"]
    edges: List[float]
    "Edges of the binning, where edges[i] <= x < edges[i+1] => f(x, ...) = content[i](...)"
    content: List[Content]
    input: str

class MultiBinning(Model):
    """N-dimensional rectangular binning"""
    nodetype: Literal["multibinning"]
    edges: List[List[float]]
    "Bin edges for each input"
    content: List[Content]
    inputs: List[str]

class Category(Model):
    nodetype: Literal["category"]
    keys: List[Union[str,int]]
    content: List[Content]
    input: str

such that the evaluator or a human reader knowns which Content block belongs to which input variable, no matter the order.

JSON files would for example look like

{
  'version': 0,
  'name': "test",
  'inputs': [
    {'name': "eta", 'type': "real", 'description': "tau eta"},
    {'name': "pt",  'type': "real", 'description': "tau pt"},
    {'name': "genmatch",  'type': "int", 'description': "genmatch"},
  ],
  'output': {'name': "weight", 'type': "real"},
  'data': {
    'nodetype': "category",
    'input': "genmatch",
    'keys': [1,2],
    'content': [
      { 'nodetype': "binning", # genmatch == 1
         'input': "eta",
         'edges': [0.0,1.5,2.4],
         'content': [0.9,1.1]
      },
      { 'nodetype': "binning", # genmatch == 2
         'input': "pt",
         'edges': [20.0,40.0,100.0],
         'content': [0.9,1.1]
      },
    ],
  },
}
@nsmith- nsmith- added this to the Schema v2 milestone Jan 26, 2021
@nsmith-
Copy link
Collaborator

nsmith- commented Jan 26, 2021

I was initially worried because I expected to pop input arguments in the evaluator as it descends the tree. But instead I decided to pass the whole set of inputs all the way through the tree (since Formula leaf nodes may need an arbitrary input)
So this should be simple. In fact, the Formula node can probably use names instead of indices as well, resolving them in instantiation in the evaluator for speed.

nsmith- added a commit that referenced this issue Feb 16, 2021
* All nodes requiring input now specify the variable name

Closes #2

* Simplify node_evaluate visitor
nsmith- pushed a commit that referenced this issue Mar 24, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Development

Successfully merging a pull request may close this issue.

2 participants