gadget-framework / rgadget

Rgadget is a set of useful utilities for gadget
6 stars 12 forks source link

component class overhaul #97

Open lentinj opened 4 years ago

lentinj commented 4 years ago

We want to be able to refer to components by name, this means they should have an actual name in R, not component.

To do this:

And back to the original examples. If "penalty" exists, then...

gadget_update(gl, 'penalty', ...)

...can be equivalent to...

gadget_update(gl$penalty, ...)

Then gadget_update.gadget_penalty_component can manage the validation of ..., which breaks up the unweildy gadget_update functions as exist presently.

If "penalty" doesn't exist, then we can call gadget_update.gadget_penalty_component directly, and add the resulting component to the likelihood file.

If we're using custom names for a component then...

gl <- gadget_update(gl, "frank", weight = 0.2)

...will be equivalent to gadget_update(gl$frank, ...) as above, and just work.

gl <- gadget_update(gl, "frank", invalid_param = 22)

...will work as above and error, since gadget_update.gadget_penalty_component doesn't know what to do with invalid_param.

gl <- gadget_update(gl, "new_frank", weight = 0.2)

...will error, since there's no gadget_update.gadget_new_frank_component(). We could solve this by allowing:

gl <- gadget_update(gl, "new_frank", type = "penalty", weight = 0.2)

Which then gives us a type to go for. If we use this whilst updating, we can error if the types don't match what we expect.