Convolution of two matrixes of PDF values
4 ビュー (過去 30 日間)
古いコメントを表示
Hello,
I'm trying to write a function that looks like something like this: convolved_matrix = convolve_matrixes(matrix1, matrix2), where the matrixes are N x 2 large (N rows and 2 columns). These matrixes is containing PDF values where on the first column contains the indexes and the second column contains the probabilities. So my question is how can i obtain a matrix that contains the correct convolution with correct index values and probability values between the inputed matrixes?
1 件のコメント
John D'Errico
2024 年 5 月 2 日
Is the first column a set of equally spaced values? Or are they scattered, unequally spaced? The answer would be hugely different depending on your response.
回答 (1 件)
Balavignesh
2024 年 5 月 20 日
Hi Daniel,
It is my understanding that you wish to find the convolution of two matrices containing probability distribution values. The convolution of two probability distributions represents the probability distribution of the sum of two independent random variables represented by these distributions.
Assuming your matrices are properly structured with indices and probabilities, the convolution process will involve calculating the sum of all possible pairs of indices and their corresponding products of probabilities. The resulting convolved matrix will have its indices ranging from the sum of the minimum indices to the sum of the maximum indices of the input matrices. Additionally, the probabilities will be the sum of the products of probabilities for each pair of indices that sum to a given index.
Have a look at the following code snippet to better understand this:
% Dummy Matrices
matrix1 = [1 0.2; 2 0.5; 3 0.3];
matrix2 = [1 0.4; 2 0.6];
% Extract indices and probabilities from the input matrices
indices1 = matrix1(:, 1);
probs1 = matrix1(:, 2);
indices2 = matrix2(:, 1);
probs2 = matrix2(:, 2);
% Calculate the range of the convolved indices
minIndex = min(indices1) + min(indices2);
maxIndex = max(indices1) + max(indices2);
convolvedIndices = (minIndex:maxIndex)';
% Initialize the convolved probabilities vector
convolvedProbs = zeros(length(convolvedIndices), 1);
% Perform the convolution operation
for i = 1:length(indices1)
for j = 1:length(indices2)
% Find the convolved index for the current pair of indices
convolvedIndex = indices1(i) + indices2(j);
% Find the position of this index in the convolvedIndices array
position = convolvedIndex - minIndex + 1;
% Add the product of the probabilities to the corresponding position
convolvedProbs(position) = convolvedProbs(position) + probs1(i) * probs2(j);
end
end
% Combine the convolved indices and probabilities into the output matrix
convolvedMatrix = [convolvedIndices, convolvedProbs];
disp(convolvedMatrix)
You might find the below documentation link useful:
- 'conv' function: https://www.mathworks.com/help/fixedpoint/ref/conv.html
Hope that helps!
Balavignesh
0 件のコメント
参考
カテゴリ
Help Center および File Exchange で Creating and Concatenating Matrices についてさらに検索
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!