Change from random Distribution to Normal/Poisson Distribution
2 vues (au cours des 30 derniers jours)
Afficher commentaires plus anciens
Hello there ,
I have this code which distrbuted values of C and f_i as randome distrbutuons.
I need to change this distrbutuins to :
1- Normal Distrbutions
2- Poission Distrbutions
but any time I tried those it gave me errors.
s_input = struct('V_POSITION_X_INTERVAL',[0 1],... %(km)
'V_POSITION_Y_INTERVAL',[0 1],... %(km)
'V_SPEED_INTERVAL',[0.01 0.1],... %(km/s) originally set to [0.2 2.2]?
'V_PAUSE_INTERVAL',[0 1],... % pause time (s) originally [1 4]
'V_WALK_INTERVAL',[1 5],... % walk time (s)
'V_DIRECTION_INTERVAL',[-180 180],... % (degrees)
'SIMULATION_TIME',20,... %(s) % originally 20
'NB_NODES', 200); % originally 300
global BaseX BaseY
BaseX = 0.5; %(km)
BaseY = 0.5; %(km)
num_users = s_input.NB_NODES;
s_mobility = Generate_Mobility(s_input);
% timeStep is used for interpolating positions of nodes
% within the positions specified in the s_mobility data generated above
timeStep = 0.5; % (s) % originally 1; shouldn't really affect anything
% except to increase number of node time-positions
% generate and display an animated version of the nodes
% using the timeStep to interpolate position data available
% in the s_mobility position data
test_Animate(s_mobility,s_input,timeStep);
%%
% ======================== %
% PARAMETERS %
% ======================== %
% Loss function parameters
alpha = 128.1;
beta = 37.6;
% Computational Latency:
C_i = 5000; % (eventually want C to be) Between C_i and 3*C_i
C_t=69;
% D_i = 1; % Between 5000-10000 bytes
D_i=500; % modified by wdc 01/09/2021 for use below in calc of D
z)
f_i = randi([1500000000, 3000000000], num_users, 1); % give each user her own f value
%Y = mu + sqrt(2)*sigma*erfinv(2*X-1);
eta = 1/10; % Got value from notes (was 1/1000)
Delta = 0.1;
L = 4; % From notes but it should came From hessian
ggamma = 2; % From notes but it should came From hessian
% Uploading Latency:
global B P_i N_0 S
B = 11000000; % bandwidth is 10 MHz = 10,000,000 HZ; trying .1 MHz?
P_i = 10; % dBm; Transmission power
% No idea what the N_0 is supposed to be here. Is ?noise? = N_0?
% Is the following really in bytes and not bits?
S = 1000000;
N_0 = 10^((-104-30)/10); % noise=-104dbm. Noise
% transmit data size, trying 1 Mbit = 1,000,000 bits
% Define Tau
% Tau = 0.00009563
Tau = 1; % originally 0.00009563
Selected = s_mobility;
% Create a vector of all desired time values/steps, in the form
% [0, timeStep, 2*timeStep, ..., SIMULATION_TIME]
v_t = 0:timeStep:s_input.SIMULATION_TIME;
for nodeIndex = 1:Selected.NB_NODES
Selected.VS_NODE2(nodeIndex).v_t = v_t;
Selected.VS_NODE2(nodeIndex).v_x = interp1(Selected.VS_NODE(nodeIndex).V_TIME,Selected.VS_NODE(nodeIndex).V_POSITION_X,v_t);
Selected.VS_NODE2(nodeIndex).v_y = interp1(Selected.VS_NODE(nodeIndex).V_TIME,Selected.VS_NODE(nodeIndex).V_POSITION_Y,v_t);
end
for N = 1:Selected.NB_NODES
% this tlen should actually be the same each time, being the
% number of (x,y) positions created in the previous for loop above
% for each node
tlen = length(Selected.VS_NODE2(N).v_t);
for t = 1:tlen
Selected.VS_NODE2(N).DISTANCE(t) = disFn(Selected.VS_NODE2(N).v_x(t),Selected.VS_NODE2(N).v_y(t));
Selected.VS_NODE2(N).LOSS(t) = lossFn(alpha,beta,Selected.VS_NODE2(N).DISTANCE(t));
Selected.VS_NODE2(N).ULAT(t) = UlatFn(Selected.VS_NODE2(N).LOSS(t));
end
end
C_i = 5000; % (eventually want C to be) Between C_i and 3*C_i
C_t=69;
C = C_i + (C_t*C_i)*rand(Selected.NB_NODES,1);
f_i = randi([1500000000, 3000000000], num_users, 1); % give each user her own f value
function distance=disFn(x,y)
global BaseX BaseY
% distance=sqrt(sum((x-BaseX).^2)+sum((y-BaseY)^2));
% cleaned this up a bit -- was working but the sums were not necessary
distance=sqrt((x-BaseX).^2 + (y-BaseY)^2);
end
function loss=lossFn(alpha,beta,d)
loss=alpha+beta*log10(d);
end
function Ulatency=UlatFn(loss)
global B P_i N_0 S
h2=10.^(-loss/10);
Ulatency = S/(B*log2(1+P_i.*h2./N_0)) ;
end
function RateLat=RatelatFn(loss)
global B P_i N_0
h2=10.^(loss/10);
RateLat = B*log2(1+P_i.*h2./N_0);
end
Any suggestions willl be helpful.
0 commentaires
Réponse acceptée
Image Analyst
le 18 Août 2021
Modifié(e) : Image Analyst
le 18 Août 2021
Well you probably solved it by now, assuming you looked up random in the help, but for what it's worth, here is a solution:
randomNumbers = random('poisson', 5, 1, 100000);
histogram(randomNumbers);
grid on;
fontSize = 15;
title('Poisson Distribution', 'FontSize', fontSize);
xlabel('Value', 'FontSize', fontSize);
ylabel('Count', 'FontSize', fontSize);
30 commentaires
Walter Roberson
le 19 Août 2021
lb = 1500000000; ub = 3000000000;
mu = (ub+lb)/2;
normalized_sigma = 3; %prob would have been in bounds is 99.7%
sigma = (ub-lb)/normalized_sigma;
pdn = makedist('Normal', 'mu', mu, 'sigma', sigma);
tpdn = truncate(pdn, lb, ub);
pdp = makedist('Poisson', 'lambda', mu);
tpdp = truncate(pdp, lb, ub);
f_in = random(tpdn, num_users, 1); %normal
f_ip = random(tpdp, num_users, 1); %poisson
In both cases, the distribution is arranged to peak half way between the upper bound and the lower bound. In both cases, the distribution is truncated in a way that only values between the lower bound and the upper bound can be generated.
Plus de réponses (0)
Voir également
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!