manipulate data to better fit a Gaussian Distribution

前端 未结 2 589
栀梦
栀梦 2021-01-19 02:25

I have got a question concerning normal distribution (with mu = 0 and sigma = 1).

Let say that I firstly call randn or normrnd this way

相关标签:
2条回答
  • 2021-01-19 03:11

    Maybe, you can try to normalize your input data to have mean=0 and sigma=1. Like this:

    y=(x-mean(x))/std(x);
    
    0 讨论(0)
  • 2021-01-19 03:11

    If you are searching for a nonlinear transformation that would make your distribution look normal, you can first estimate the cumulative distribution, then take the function composition with the inverse of standard normal CDF. This way you can transform almost any distribution to a normal through invertible transformation. Take a look at the example code below.

    x = randn(1000, 1) + 4 * (rand(1000, 1) < 0.5); % some funky bimodal distribution
    xr = linspace(-5, 9, 2000);
    cdf = cumsum(ksdensity(x, xr, 'width', 0.5)); cdf = cdf / cdf(end); % you many want to use a better smoother
    c = interp1(xr, cdf, x); % function composition step 1
    y = norminv(c); % function composition step 2
    % take a look at the result
    figure;
    subplot(2,1,1); hist(x, 100);
    subplot(2,1,2); hist(y, 100);
    
    0 讨论(0)
提交回复
热议问题