Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 7 additions & 2 deletions analysis/randomSampling.m
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
function [solutions, goodRxns]=randomSampling(model,varargin)
function [solutions, goodRxns, info]=randomSampling(model,varargin)
% randomSampling Sample the flux solution space (entry point for all samplers).
%
% Dispatches to one of three sampling methods via the 'method' argument:
Expand Down Expand Up @@ -75,6 +75,10 @@
% [randomObjective] vector of indexes of those reactions that are not
% involved in loops or always carry zero flux and can be used as random
% objective functions. Empty ([]) for the 'achr' and 'chrr' methods.
% info : struct
% [chrr] the diagnostics from sampleCHRR, including mveConverged (whether
% the maximum-volume ellipsoid rounding reached tolerance). Empty ([])
% for the 'achr' and 'randomObjective' methods.
%
% Notes
% -----
Expand Down Expand Up @@ -111,6 +115,7 @@
method=p.method;
thinning=p.thinning;
nBurnin=p.nBurnin;
info=[]; %only populated by the 'chrr' method
if isempty(nSamples)
nSamples=1000;
end
Expand All @@ -129,7 +134,7 @@
goodRxns = [];
return;
case 'chrr'
solutions = sampleCHRR(model, nSamples, thinning, nBurnin, seed);
[solutions, info] = sampleCHRR(model, nSamples, thinning, nBurnin, seed);
goodRxns = [];
return;
case {'randomobjective', 'objective'}
Expand Down
5 changes: 5 additions & 0 deletions analysis/sampleCHRR.m
Original file line number Diff line number Diff line change
Expand Up @@ -118,6 +118,11 @@
[center, E, converged] = sampleMaxVolEllipse(A_full, b_full, x0);
info.nDimensions = d;
info.mveConverged = converged;
if ~converged
warning('RAVEN:warning', '%s', ['The maximum-volume ellipsoid rounding ' ...
'did not converge; the samples may be poorly mixed. Inspect the ' ...
'mveConverged field of the second output.']);
end

% Rounded polytope {y : A_r*y <= b_r}, which contains the unit ball.
A_r = A_full * E;
Expand Down
8 changes: 8 additions & 0 deletions testing/function_tests/tSampling.m
Original file line number Diff line number Diff line change
Expand Up @@ -109,6 +109,14 @@ function randomSamplingCHRRDispatch(testCase)
testCase.verifyLessThan(max(abs(resid(:))), 1e-6);
end

function randomSamplingCHRRExposesInfo(testCase)
% The CHRR convergence diagnostics must be reachable through the
% documented randomSampling entry point, not only sampleCHRR.
evalc(['[sols, gr, sInfo] = randomSampling(testCase.model, 10, ' ...
'''method'', ''chrr'', ''thinning'', 5, ''nBurnin'', 20, ''seed'', 1);']);
testCase.verifyTrue(isfield(sInfo, 'mveConverged'));
end

function randomSamplingCHRRDeterministic(testCase)
evalc(['s1 = randomSampling(testCase.model, 8, ''method'', ''chrr'', ' ...
'''thinning'', 5, ''nBurnin'', 20, ''seed'', 42);']);
Expand Down