Gaussian random function

╄→гoц情女王★ 提交于 2019-12-24 08:56:47

问题


By using normrnd, I would like to create a normal distribution function with mean and sigma values expressed as vectors of size 1x45 varying from 1:45 and plot this simulated PDF with ideal values.

Whenever I create a normrnd like the one expressed below,

Gaussian = normrnd([1 45],[1 45],[1 500],length(c_t));

I am obtaining the following error,

Size information is inconsistent.

The reason for creating this PDF is to compute Chemical kinetics of a tracer with variable gaussian noise model. Basically i have an Ideal characteristics of a Tracer now i would like to add gaussian noise and understand how the chemical kinetics of a tracer vary with changing noise.

Basically there are different computational models for understanding chemical kinetics of tracer, one of which is Three compartmental model ,others are viz shape analysis,constrained shape analysis model.

I currently have ideal curve for all respective models, now i would like to add noise to these models and understand how each particular model behaves with varying noise

This is why i would like to create a variable noise model with normrnd add this model to ideal characteristics and compute Noise(Sigma) Vs Error -This analysis will give me an approximate estimation how different models behave with varying noise and which model is suitable for estimating chemical kinetics of tracer.

function [c_t,c_t_noise] =Noise_ConstrainedK2(t,a1,a2,a3,b1,b2,b3,td,tmax,k1,k2,k3)

    K_1   = (k1*k2)/(k2+k3);
    K_2   = (k1*k3)/(k2+k3);
    %DV_free= k1/(k2+k3);

    c_t = zeros(size(t));
    ind = (t > td) & (t < tmax);
    c_t(ind)= conv(((t(ind) - td) ./ (tmax - td) * (a1 + a2 + a3)),(K_1*exp(-(k2+k3)*t(ind)+K_2)),'same');
    ind = (t >= tmax);

    c_t(ind)=conv((a1 * exp(-b1 * (t(ind) - tmax))+ a2 * exp(-b2 * (t(ind) - tmax))) + a3 * exp(-b3 * (t(ind) - tmax)),(K_1*exp(-(k2+k3)*t(ind)+K_2)),'same');

    meanAndVar = (rand(45,2)-0.5)*2;
    numPoints = 500;
    randSamples = zeros(1,numPoints);
    for ii = 1:numPoints
        idx = mod(ii,size(meanAndVar,1))+1;
        randSamples(ii) = normrnd(meanAndVar(idx,1),meanAndVar(idx,2));
        c_t_noise = c_t + randSamples(ii);
    end
    scatter(1:numPoints,randSamples)

    dg = [0 0.5 0];
    plot(t,c_t,'r');
    hold on;
    plot(t,c_t_noise,'Color',dg);
    hold off; 

    axis([0 50 0 1900]);
    xlabel('Time[mins]');
    ylabel('concentration [Mbq]');
    title('My signal');

    %plot(t,c_tnp);
end

The output characteristics from the above function are as follows,Here i could not visualize any noise


回答1:


The only remotely close thing to what you want to be done can be done as follows, but will involve looping because you can not request 500 data points from only 45 different means and variances, without the assumption that multiple sets can be revisited.

This is my interpretation of what you want, though I am still not entirely sure.

Random Gaussian Function Selection

meanAndVar = rand(45,2);
numPoints = 500;
randSamples = zeros(1,numPoints);
for ii = 1:numPoints
    randMeanVarIdx = randi([1,size(meanAndVar,1)]);
    randSamples(ii) = normrnd(meanAndVar(randMeanVarIdx,1),meanAndVar(randMeanVarIdx,2));
end
scatter(1:numPoints,randSamples)

The above code generates a random 2-D matrix of mean and variance (1st col = mean, 2nd col = variance). We then preallocate some space.

Inside the loop we chose a random set of mean and variance to use (uniformly) and then take that mean and variance, plug it into a random gaussian value function, and store it.

the matrix randSamples will contain a list of random values generated by a random set of gaussian functions chosen in a randomly uniform manner.

Sequential Function Selection

If you do not want to randomly select which function to use, and just want to go sequentially you loop using modulus to get the index of which set of values to use.

meanAndVar = (rand(45,2)-0.5)*2; % zero shift and make bounds [-1,1]
numPoints = 500;
randSamples = zeros(1,numPoints);
for ii = 1:numPoints
    idx = mod(ii,size(meanAndVar,1))+1;
    randSamples(ii) = normrnd(meanAndVar(idx,1),meanAndVar(idx,2));
end
scatter(1:numPoints,randSamples)



回答2:


The problem with this statement

Gaussian = normrnd([1 45],[1 45],[1 500],length(c_t));

is that you supply two mu values and two sigma values, and ask for a matrix of size [1 500] x length(c_t). You need to pass the size in a uniform way, so either

Gaussian = normrnd(mu, sigma,[500 length(c_t)]);

or

Gaussian = normrnd(mu, sigma, 500, length(c_t));

Then you should make sure that the size of the mu/sigma vectors match the size of the matrix you ask for. So if you want a 500 x length(c_t) matrix as output you need to pass 500 x length(c_t) (mu,sigma) pairs. If you only want to vary one of mu or sigma you can pass a single value for the other parameter

To get N values from a normal distribution with fixed mean and steadily increasing sigma you can do

noise = @(mu, s0, s1, n) normrnd(mu, s0:(s1-s0)/(n-1):s1, 1,n)

where s0 is the lowest sigma value and s1 is the largest sigma value. To get 10 values drawn from distributions with mu=0 and sigma increasing from 1 to 5 you can do

noise(0,1,5,10)

If you want to introduce some randomness in the increase of sigma you can do

noise_rand = @(mu, s0, s1, n) normrnd(mu, (s0:(s1-s0)/(n-1):s1) .* rand(1,n), 1,n)


来源:https://stackoverflow.com/questions/23066521/gaussian-random-function

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!