MATLAB: Sampling data using contraints

constraintsdatasampling

Hi, I want to sample points uniformly in a multidimensional design space, such that the sampled points follow an
equality constraint. Basically I want to sample 4 mole fractions (Xi) for 4 components in an input stream. I have lower
and upper bounds (inequality constraints) for each Xi as well.
Eg. 0.733<=X1<=0.944, 0.04<=X2<=0.093, 0.04<=X3<=0.094, 0.02<=X4<=0.048, X1+X2+X3+X4=1
Is there any way to use the inbuilt sampling techniques like sobol, LHS etc. while ensuring these constraints?

Best Answer

  • Use my randFixedLinearCombination tool, as found on the file exchange. (I did just post an update today, fixing a bug the code tripped on for this problem.)
    n = 5;
    lb = [0.733 0.04, 0.04, 0.02];
    ub = [0.944, 0.093, 0.094, 0.048];
    A = [1 1 1 1]
    b = 1;
    X = randFixedLinearCombination(n,A,b,lb,ub);
    Does the array X satisfy the requirements? Yes.
    >> X
    X =
    0.80603 0.078998 0.093954 0.021013
    0.86969 0.041981 0.04217 0.046161
    0.82108 0.082301 0.058065 0.038558
    0.84723 0.045193 0.085937 0.021644
    0.81159 0.055575 0.092472 0.040365
    >> sum(X,2)
    ans =
    1
    1
    1
    1
    1
    >> all(X >= lb,2)
    ans =
    5×1 logical array
    1
    1
    1
    1
    1
    >> all(X <= ub,2)
    ans =
    5×1 logical array
    1
    1
    1
    1
    1
    So X has 5 rows, each of which sum to 1. Each column all lies between the given set of bounds.
    It is difficult to prove in a higher number of dimensions they are uniformly distributed in that space, but they are. I'm just too sleepy and too lazy to try to prove that to be true here.
    Download randFixedLinearCombination from the FEX here:
    There are limits on the size of the problem, due to the way the code is written. Depending on the problem, the upper bound might be on the order of 10-25 variables. Beyond that point lie some computationally intensive dragons in this code. The actual limit will be problem dependent though.