What is the appropriate data structure for a matrix with random variables?

I am currently working in a field related to simulation, and am trying to create a data structure that may include random variables in matrices. To motivate this, let me say that I have the following matrix:

[a b; c d]

I want to find a data structure that allows a, b, c, deither to be real numbers or random. As an example, suppose that a = 1, b = -1, c = 2but let d- normally distributed random variable with mean 0 and standard deviation 1.

The data structure that I have in mind will not make any difference d. However, I also want to be able to create a function that can take in a structure, simulate uniform(0,1), get a value for dusing inverse CDF and then spit out the actual matrix.

I have some ideas for this (everything is related to the MATLAB function icdf), but I would like to know how more experienced programmers would do it. In this application, it is important that the structure is "thin", since I will work with very large matrices, and memory will be a problem.

EDIT # 1:

. . , , "".

+3
2

cell, , , . , :

generatorMatrix = {1 -1; 2 @randn};

, , , , :

function numMatrix = create_matrix(generatorMatrix)
  index = cellfun(@(c) isa(c,'function_handle'),...  %# Find function handles
                  generatorMatrix);
  generatorMatrix(index) = cellfun(@feval,...        %# Evaluate functions
                                   generatorMatrix(index),...
                                   'UniformOutput',false);
  numMatrix = cell2mat(generatorMatrix);  %# Change from cell to numeric matrix
end

, , , . , , 5, 9, 9 1, 9 , 5 10:

generatorMatrix = {5 ones(1,9); ones(9,1) @() 5*rand(9)+5};

, create_matrix, 10--10 , 9--9 .


...

( ), .

, , , , , user57368, . : (, NaN), , , , , , . , .

3 3 3 , 2, 4 9, , 5 10 :

matData = struct('numMatrix',[1 nan 3; nan 2 4; 0 5 nan],...
                 'randIndex',[2 4 9],...
                 'randFcns',{{@randn , @() 5*rand+5 , @() -log(rand)/2}});

create_matrix, :

function numMatrix = create_matrix(matData)
  numMatrix = matData.numMatrix;
  numMatrix(matData.randIndex) = cellfun(@feval,matData.randFcns);
end
+3

NumPy, , MATLAB. , , .

, . , . , , (.. 1 , 2 ..).

, , , , .

+1

Source: https://habr.com/ru/post/1784294/


All Articles