-
Notifications
You must be signed in to change notification settings - Fork 52
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
Suggestion: Refactoring of Transforms #888
Comments
I think that would be a great way of simplifying the maintenance of the transformations, as we would not need to reimplement all dimension methods to wrap them (like prior_string, cardinality, interval, etc). There could be a major issue with the priors however. If we decide to stick with a small subset of priors like uniform and loguniform it would be fine. We know how to transform them. If we use priors from scipy.stats however it's not clear at all how we could convert them. It could be fine if the transformations are simply turning Real to Integer as we can reuse the prior as is. The opposite would not be possible however. Say we have That being said, supporting all of scipy.stats has not proved useful at all so far, so departing from it in order to simplify the implementation of the transformations may be a good idea. |
I'm revisiting this in order to solve handling of transformed spaces in #832. I think the simplest solution may be to keep the TransformedDimension and TransformedSpace, but only use them for transforming spaces and points instead of behaving like space and dimensions objects. transformer = SpaceTransformer(original_space, requirements)
assert transformer.original == original_space
transformed_space = transformer.target
transformed_point = transformer.transform(original_space.sample()[0])
original_point = transformer.reverse(transformed_point) One reason we cannot dispatch transform/reverse on Dimension class only is that some transformations are across dimensions (namely Reshape). The main difference between this proposed solution with current implementation is that |
I have an idea which I believe could greatly simplify a lot of code related to spaces, transforms, and such.
Here is the current state of things:
type
attribute.build_required_space
function, which gets a Transformer that can map from input to output, and passes it to a newTransformedDimension
.Here is what I suggest we do instead:
TransformedDimension
TransformedSpace
transform
andreverse
attributes into theDimension
class, and make them optional, with default ofNone
.For example:
Where the
register_transform
decorator just registers the function into a dictionary that maps from (in_type, out_type) -> callable, using the type annotations of the function.The
build_required_space
would then be a search over the transforms and transform chains, to find one that maps from input to outputs, then applying those to the dimensions, and returning a regular Space with those transformed dimensions.I'lll add more ideas soon.
The text was updated successfully, but these errors were encountered: