Skip to content

Conversation

@javdrher
Copy link
Member

@javdrher javdrher commented Aug 9, 2017

Following #60 , wrapping any kind of model defined in GPflow and influencing its input/output seems to become a shared use case. So I created a specific parent class which takes care of this, datascaler now is derived from it. This turns it into an actual implementation of the Decorator pattern.

The class is now derived from parameterized again. Deriving from GPmodel introduced a wide range of issues which were all more or less covered but it wasn't very nice. I also noticed that for recompiling models (I tested with the modified GPflow version which is in the PR) there was some annoying split on where certain parameters were set: this is now all covered and solved issues related to using VGP.

Note that deriving from Parameterized is not as bad as it seems at first. Because all method calls not implemented in a wrapper subclass are forwarded, and an assert is placed in the constructor which verifies its actually a model we maintain the assumptions of a model through the proxy.

@javdrher javdrher added this to the 0.1.0 release milestone Aug 9, 2017
@codecov-io
Copy link

codecov-io commented Aug 9, 2017

Codecov Report

Merging #64 into master will increase coverage by <.01%.
The diff coverage is 100%.

Impacted file tree graph

@@            Coverage Diff             @@
##           master      #64      +/-   ##
==========================================
+ Coverage   99.78%   99.79%   +<.01%     
==========================================
  Files          16       17       +1     
  Lines         933      960      +27     
==========================================
+ Hits          931      958      +27     
  Misses          2        2
Impacted Files Coverage Δ
GPflowOpt/acquisition/ei.py 100% <ø> (ø) ⬆️
GPflowOpt/transforms.py 100% <ø> (ø) ⬆️
GPflowOpt/scaling.py 100% <100%> (ø) ⬆️
GPflowOpt/acquisition/acquisition.py 100% <100%> (ø) ⬆️
GPflowOpt/__init__.py 100% <100%> (ø) ⬆️
GPflowOpt/models.py 100% <100%> (ø)

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update bbe9347...35cd171. Read the comment docs.

@javdrher javdrher mentioned this pull request Aug 10, 2017
@javdrher javdrher requested a review from icouckuy August 12, 2017 05:30
super(Acquisition, self).__init__()
self._models = ParamList([DataScaler(m) for m in np.atleast_1d(models).tolist()])
models = np.atleast_1d(models)
assert all(isinstance(model, (Model, ModelWrapper))for model in models)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

space before 'for' :)


class ModelWrapper(Parameterized):
"""
Class for fast implementation of a wrapper for models defined in GPflow. Once wrapped, all lookups for attributes
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

lets make the first paragraph a one liner (so it is listed nicely if it ever becomes in the docs). So "Once..." is a new paragraph

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Base class for fast...


def __setattr__(self, key, value):
"""
1) If setting :attr:`wrapped` attribute, point parent to this object (the datascaler).
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

rename the datascaler?

return self.wrapped == other

def __str__(self, prepend=''):
return self.wrapped.__str__(prepend)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Useful to prepend with 'Wrapper' or something by default?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Doesn't seem necessary, the actual method that is executed is in Parameterized so doesn't mention the model.
In the parameter naming you should see a .wrapped directive though.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actually, that isn't the case yet. fixing.

class DataScaler(GPModel):
class DataScaler(ModelWrapper):
"""
Model-wrapping class, primarily intended to assure the data in GPflow models is scaled. One DataScaler wraps one
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

oneliner?

1) If setting :attr:`wrapped` attribute, point parent to this object (the ModelWrapper).
2) Setting attributes in the right objects. The following rules are processed in order:
(a) If attribute exists in wrapper, set in wrapper.
(b) If not object wrapped yet, set in wrapper.
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

no

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

what's meant with this?
that it will error out if self.wrapper is None

@javdrher javdrher merged commit 811ea4c into master Aug 17, 2017
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants