RDT icon indicating copy to clipboard operation
RDT copied to clipboard

Add Sigmoid and Logit Transformers

Open amontanez24 opened this issue 4 years ago • 1 comments

Problem Description

The sigmoid and logit transformations are use in SDV to enforce the between constraint. They could also be used in RDT's NumericalTransformer to keep values within the bounds. It would be convenient to pull this code out into it's own transformer.

Expected behavior

For Logit something like

class LogitTransformer:
    def __init__(self, high, low):
        pass

    def transform(data):
        data = (data - low) / (high - low)
        data = data * 0.95 + 0.025
        data = np.log(data / (1.0 - data))
        return data

    def reverse_transform(data):
        data = 1 / (1 + np.exp(-data))
        data = (data - 0.025) / 0.95
        data = data * (high - low) + low
        data = data.clip(low, high)

The sigmoid would just swap the transform and reverse transform functions

amontanez24 avatar Jul 15 '21 22:07 amontanez24

I think the proposal is right, but I have doubts about the 0.95 + 0.025 part, as well as the normalization performed before that.

At most, these could be set as optional arguments, but I would expect a LogitTransformer to just do that: apply a logit function, and then apply a sigmoid when reversing, without anything else.

csala avatar Jul 16 '21 15:07 csala