machine-learningdeep-learningneural-networkgluonmxnet

How do I denormalize L2-Normalized Data in MXNet?


I normalized my Data with the built in L2Normalization from MXNet ndarray. Since I want to know the actual value of the prediction I have to denormalize the data to analyze it properly. For normalization I used:

mx.nd.L2Normalization(x, mode='instance')

It computed me the correct values and I also understand how the calculation works. Now I want to reverse it. Is there a built in method?

My idea would be to swap x and y in the function and to solve for x. However I don't know the sum of the instance nor anything else. So I can't simply do it. Is there a function to denormalize? Or do I have to normalize all by myself? That would sadly make the L2Normalization function useless in many cases.


Solution

  • The answers given here are correct. There is no built in function for L2 Denormalization in MXNet. However it is easy to simply compute and save these values. Here is my approach in Python:

    saved_norm_vals = []
    def l2_normalize(row):
        norm = np.linalg.norm(row)
        saved_norm_vals.append(norm)
        if norm == 0:
            return row
        return row / norm
    
    
    def l2_denormalize(row):
        val = saved_norm_vals.pop(0)
        return row*val
    

    Both function take in the row of a pandas dataframe. You can use this function by using the .apply method. Keep in mind that you have to strictly contain the order for that to work. Or you always need to clear out the list if there are values you don't want to denormalize.