schalkdaniel / compboost

C++ implementation and R API for componentwise boosting
https://schalkdaniel.github.io/compboost/
GNU Lesser General Public License v3.0
24 stars 3 forks source link

Consistent load method/constructor from JSON #360

Closed schalkdaniel closed 1 year ago

schalkdaniel commented 1 year ago

The Rcpp modules do not allow to have multiple constructors with the same number of arguments. E.g. Rcpp only uses the first constructor when defining two constructors Loss(double) and Loss(json) with one argument. This makes it difficult to load all classes from a constructor ...

Workaround: Have a method $loadFromJson() which resets the internal loss pointer:

loadFromJson (const json& j) { sh_ptr_loss = jsonToLoss(j) };

Drawbacks:

schalkdaniel commented 1 year ago

For now, a mixture is implemented, e.g. the response can be loaded with a constructor while the loss requires to call a method. I like the constructor option more, but if this is not possible for all classes, I would use a consistent member function.

schalkdaniel commented 1 year ago

Another option would be to have a constructor with n + 1 arguments when n is the maximum number of arguments in one of the constructors. Something like:

Loss (json, bool, bool, bool)

Not very pretty but would work.

schalkdaniel commented 1 year ago

removed