Ivan-Bao / WB-Dynamics

Whistler Blackcomb Matlab simulation
2 stars 2 forks source link

Refactor Latin Hypercube Sampling Code To Be Cleaner #2

Closed william-swy closed 3 years ago

william-swy commented 3 years ago

Currently the code to do the sampling has the basic structure: each variable is hard coded and sampled and after that, each sample is hard coded into a total matrix.

For example, the portion of the code that samples the fuselage length and diameter looks something like this:

% fuse diameter sample - from a normal distribution
fuse_dia_sam = lhsnorm(fuse_dia_mean, fuse_dia_err, NUM_OF_SAMP);
total_sample_mat = fuse_dia_sam;

% fuse length sample - from a normal distribution
fuse_len_sam = lhsnorm(fuse_len_mean, fuse_length_err, NUM_OF_SAMP);
total_sample_mat = [total_sample_mat fuse_len_sam];

This looks rather ugly and it happens to repeat N times where N is the total number of variables being sampled. Also the cleaner code should help improve development speed.

It would be nice if this could all be refactored into one function (SRP!) and also not hard code the sampling of each variable (perhaps a for loop).

william-swy commented 3 years ago

Code now delegates sampling to a helper function.