Skip to content

ModelWrapper - #64

Merged
javdrher merged 13 commits into
masterfrom
model_wrapper_class
Aug 17, 2017
Merged

ModelWrapper#64
javdrher merged 13 commits into
masterfrom
model_wrapper_class

Conversation

@javdrher

Copy link
Copy Markdown
Member

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.

@javdrherjavdrher added this to the 0.1.0 release milestone Aug 9, 2017
@codecov-io

codecov-io commented Aug 9, 2017

Copy link
Copy Markdown

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 FilesCoverage Δ
GPflowOpt/acquisition/ei.py100% <ø> (ø)⬆️
GPflowOpt/transforms.py100% <ø> (ø)⬆️
GPflowOpt/scaling.py100% <100%> (ø)⬆️
GPflowOpt/acquisition/acquisition.py100% <100%> (ø)⬆️
GPflowOpt/__init__.py100% <100%> (ø)⬆️
GPflowOpt/models.py100% <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.

@javdrherjavdrher mentioned this pull request Aug 10, 2017
Open
@javdrher
javdrher requested a review from icouckuyAugust 12, 2017 05:30
Comment threadGPflowOpt/acquisition/acquisition.py Outdated
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
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

space before 'for' :)

Comment threadGPflowOpt/models.py Outdated

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

Copy link
Copy Markdown
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
Copy Markdown
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...

Comment threadGPflowOpt/models.py Outdated

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

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

rename the datascaler?

Comment threadGPflowOpt/models.py Outdated
return self.wrapped == other

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

Copy link
Copy Markdown
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
Copy Markdown
MemberAuthor

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
Copy Markdown
MemberAuthor

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.

Comment threadGPflowOpt/scaling.py Outdated
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
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

oneliner?

Comment threadGPflowOpt/models.py Outdated
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
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

no

Copy link
Copy Markdown
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 masterAug 17, 2017
Sign up for freeto 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.

3 participants

@javdrher@codecov-io@icouckuy