randFixedLinearComb​ination

バージョン 1.1.0.0 (4.95 KB) 作成者: John D'Errico
Uniform random samples over a n-dimensional hyper-rectangle, subject to a linear equality constraint
ダウンロード: 319
更新 2020/9/11

ライセンスの表示

Generation of a uniform random set in n-dimensions subject to a simple sum constraint is nicely handled by Roger Stafford's randfixedsum. But every once in a while, someone wants to sample from a hyper-rectangle, so a set where the bounds are not all the same for each dimension. Or someone might want to sample using some other linear combination of the variables. Then randfixedsum will not suffice, so I decided to write randFixedLinearCombination, which allows a general hyper-rectangle, so you can set any lower and upper bounds. You can also supply a general linear combination. In fact, if you wish to fix one variable to be held constant, you merely set the upper and lower bounds to be the same for that variable.
For example, given the goal to generate 1e7 sets of five uniform random variables, on the hyper-rectangle defined by the set of lower and upper bounds as seen below (variable 4 is fixed at 3). To generate that set took just over 4 seconds.

lb = [-1 0 2 3 -2];
ub = [5 5 3 3 7];
n = 1e7;

tic
X = randFixedLinearCombination(n,12.5,[1 1 1 1 1],lb,ub);
toc
Elapsed time is 4.125535 seconds.

min(sum(X,2))
ans =
12.5

max(sum(X,2))
ans =
12.5

The samples are uniformly distributed over the subspace defined by the constraint plane.

I've tested the code, and will see if I can add a .pdf file as soon as possible to explain the scheme used.

引用

John D'Errico (2024). randFixedLinearCombination (https://www.mathworks.com/matlabcentral/fileexchange/49795-randfixedlinearcombination), MATLAB Central File Exchange. 取得済み .

MATLAB リリースの互換性
作成: R2014b
すべてのリリースと互換性あり
プラットフォームの互換性
Windows macOS Linux
カテゴリ
Help Center および MATLAB AnswersApplications についてさらに検索

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!
バージョン 公開済み リリース ノート
1.1.0.0

Bug fix

1.0.0.0