Skip to content
Browse files

New shc_lv_eigs for symbolic and numeric SHC eigenvalues/vectors

New shc_lv_eigs for symbolic and numeric SHC eigenvalues/vectors, shc_lv_jacobian fixed to properly handle symbolic input, error messages refined in shc_validatesubnetwork, tested using new version of Java.

Signed-off-by: Andrew D. Horchler <adh9@case.edu>
  • Loading branch information...
1 parent 56d30f3 commit 69d88edf7357eb00fdc334f0a2ade3ffed40670d @horchler committed Apr 6, 2012
Showing with 461 additions and 224 deletions.
  1. +10 −9 README
  2. +29 −28 SHCTools/Contents.m
  3. +153 −155 SHCTools/private/shc_validatesubnetwork.m
  4. +185 −0 SHCTools/shc_lv_eigs.m
  5. +84 −32 SHCTools/shc_lv_jacobian.m
View
19 README
@@ -1,5 +1,5 @@
SHCTOOLS
- Version 1.0, 4-4-12
+ Version 1.0, 4-6-12
SHC network creation, modification, and visualization, and conversion.
buildrho - Create RHO matrix from SHC network structure.
@@ -10,22 +10,23 @@ SHCTOOLS
shc_addnetwork - Insert a sub-network into SHC network structure.
shc_create - RHO matrix from parameters or transition matrix.
shc_deletenetwork - Remove a sub-network and its children.
- shc_initialize - Create required fields for SHC network structure.
+ shc_initialize - Create required fields for SHC network structure.
shc_reset - Reset SHC network structure to default values.
- shc_validatenetwork - Validate SHC network structure.
+ shc_validatenetwork - Validate SHC network structure.
Lotka-Volterra SHC network tools.
+ shc_lv_eigs - Eigenvalues of Lotka-Volterra system.
shc_lv_integrate - Solve stochastic Lotka-Volterra ODEs.
- shc_lv_jacobian - Jacobian of Lotka-Volterra RHO matrix.
- shc_lv_ode - ODEs for N-dimensional Lotka-Volterra system.
+ shc_lv_jacobian - Jacobian of Lotka-Volterra system.
+ shc_lv_ode - ODEs for N-dimensional Lotka-Volterra system.
shc_lv_symequilibria - Symbolic equlibrium points and eigenvalues.
Stone-Holmes distribution.
- stoneholmescdf - Cummulative distribution function.
+ stoneholmescdf - Cummulative distribution function.
stoneholmesfit - Parameter estimates from data.
stoneholmesinv - Inverse cummulative distribution.
stoneholmeslike - Negative log-likelihood.
- stoneholmesmedian - Median of distribution.
+ stoneholmesmedian - Median of distribution.
stoneholmesmode - Mode (maximum value) of distribution.
stoneholmespdf - Probability density function.
stoneholmesrnd - Random number generator.
@@ -35,7 +36,7 @@ SHCTOOLS
shc.xsd - XML Schema.
Tested with Matlab 7.13.0.564 (R2011b)
- Mac OS X 10.6.8 Build: 10K549, Java 1.6.0_29-b11-402-10M3527
+ Mac OS X 10.6.8 (Build: 10K549), Java 1.6.0_31-b04-413-10M3623
Andrew D. Horchler, adh9@case.edu, Created 1-4-12
- Revision: 1.0, 4-4-12
+ Revision: 1.0, 4-6-12
View
57 SHCTools/Contents.m
@@ -1,41 +1,42 @@
%SHCTOOLS
-% Version 1.0, 3-31-12
+% Version 1.0, 4-6-12
%
% SHC network creation, modification, and visualization, and conversion.
-% buildrho - Create RHO matrix from SHC network structure.
-% loadnet - Load SHC network structure from XML or MAT file.
-% plotactivity - Plot simulated SHC network activity.
-% plotnet - Visualization of SHC network topology.
-% savenet - Save SHC network structure as XML or MAT file.
-% shc_addnetwork - Insert a sub-network into SHC network structure.
-% shc_create - RHO matrix from parameters or transition matrix.
-% shc_deletenetwork - Remove a sub-network and its children.
-% shc_initialize - Create required fields for SHC network structure.
-% shc_reset - Reset SHC network structure to default values.
-% shc_validatenetwork - Validate SHC network structure.
+% buildrho - Create RHO matrix from SHC network structure.
+% loadnet - Load SHC network structure from XML or MAT file.
+% plotactivity - Plot simulated SHC network activity.
+% plotnet - Visualization of SHC network topology.
+% savenet - Save SHC network structure as XML or MAT file.
+% shc_addnetwork - Insert a sub-network into SHC network structure.
+% shc_create - RHO matrix from parameters or transition matrix.
+% shc_deletenetwork - Remove a sub-network and its children.
+% shc_initialize - Create required fields for SHC network structure.
+% shc_reset - Reset SHC network structure to default values.
+% shc_validatenetwork - Validate SHC network structure.
%
% Lotka-Volterra SHC network tools.
-% shc_lv_integrate - Solve stochastic Lotka-Volterra ODEs.
-% shc_lv_jacobian - Jacobian of Lotka-Volterra RHO matrix.
-% shc_lv_ode - ODEs for N-dimensional Lotka-Volterra system.
-% shc_lv_symequilibria - Symbolic equlibrium points and eigenvalues.
+% shc_lv_eigs - Eigenvalues of Lotka-Volterra system.
+% shc_lv_integrate - Solve stochastic Lotka-Volterra ODEs.
+% shc_lv_jacobian - Jacobian of Lotka-Volterra system.
+% shc_lv_ode - ODEs for N-dimensional Lotka-Volterra system.
+% shc_lv_symequilibria - Symbolic equlibrium points and eigenvalues.
%
% Stone-Holmes distribution.
-% stoneholmescdf - Cummulative distribution function.
-% stoneholmesfit - Parameter estimates from data.
-% stoneholmesinv - Inverse cummulative distribution.
-% stoneholmeslike - Negative log-likelihood.
-% stoneholmesmedian - Median of distribution.
-% stoneholmesmode - Mode (maximum value) of distribution.
-% stoneholmespdf - Probability density function.
-% stoneholmesrnd - Random number generator.
+% stoneholmescdf - Cummulative distribution function.
+% stoneholmesfit - Parameter estimates from data.
+% stoneholmesinv - Inverse cummulative distribution.
+% stoneholmeslike - Negative log-likelihood.
+% stoneholmesmedian - Median of distribution.
+% stoneholmesmode - Mode (maximum value) of distribution.
+% stoneholmespdf - Probability density function.
+% stoneholmesrnd - Random number generator.
%
% XML validation files.
-% shc.dtd - Document Type Definition.
-% shc.xsd - XML Schema.
+% shc.dtd - Document Type Definition.
+% shc.xsd - XML Schema.
% Tested with Matlab 7.13.0.564 (R2011b)
-% Mac OS X 10.6.8 Build: 10K549, Java 1.6.0_29-b11-402-10M3527
+% Mac OS X 10.6.8 (Build: 10K549), Java 1.6.0_31-b04-413-10M3623
% Andrew D. Horchler, adh9@case.edu, Created 1-4-12
-% Revision: 1.0, 3-31-12
+% Revision: 1.0, 4-6-12
View
308 SHCTools/private/shc_validatesubnetwork.m
@@ -8,41 +8,41 @@ function shc_validatesubnetwork(s,varargin)
%shc_validatesubnetwork(s,num,'strict')
% Andrew D. Horchler, adh9@case.edu, Created 1-15-12
-% Revision: 1.0, 3-28-12
+% Revision: 1.0, 4-6-12
if nargin > 1 && ~ischar(varargin{1})
num = varargin{1};
if ~validateindex(num) || ~isnumeric(num)
- error( 'SHCTools:shc_validatesubnetwork:InvalidNetworkNumber',...
- 'The optional network number must be a real positive integer.');
+ error('SHCTools:shc_validatesubnetwork:InvalidNetworkNumber',...
+ 'The optional network number must be a real positive integer.');
end
i = [' ' int2str(num)];
else
i = '';
end
if ~isstruct(s) || isempty(s)
- error( 'SHCTools:shc_validatesubnetwork:InvalidDataType',...
- 'Invalid datatype: network%s is not a non-empty structure.',i);
+ error('SHCTools:shc_validatesubnetwork:InvalidDataType',...
+ 'Invalid datatype: network%s is not a non-empty structure.',i);
end
% Check for 'strict' mode and validate fields of network if specified
if nargin > 1 && ischar(varargin{end})
if ~strcmpi(varargin{end},'strict')
- error( 'SHCTools:shc_validatesubnetwork:InvalidArgument',...
- ['Second input must be string ''strict'' in order to specify '...
- 'strict mode.']);
+ error('SHCTools:shc_validatesubnetwork:InvalidStrictArgument',...
+ ['Second input must be string ''strict'' in order to specify '...
+ 'strict mode.']);
end
f = fieldnames(s);
v = {'type','parent','node','size','alpha','beta','gamma','delta',...
'direction','children','index','T','childnodes'};
for j = 1:length(f)
if ~any(strcmp(f{j},v))
- error( 'SHCTools:shc_validatesubnetwork:InvalidArgument',...
- ['Invalid field named ''%s'' of network%s found using '...
- '''strict'' mode.'],f{j},i);
+ error('SHCTools:shc_validatesubnetwork:InvalidFieldName',...
+ ['Invalid field named ''%s'' of network%s found using '...
+ '''strict'' mode.'],f{j},i);
end
end
@@ -53,286 +53,284 @@ function shc_validatesubnetwork(s,varargin)
% Check fields of network
if ~isfield(s,'type')
- error( 'SHCTools:shc_validatesubnetwork:InvalidArgument',...
- 'Network%s does not have required field named ''type''.',i);
+ error('SHCTools:shc_validatesubnetwork:MissingTypeField',...
+ 'Network%s does not have required field named ''type''.',i);
end
if ~any(strcmp(s.type,{'contour','channel','cluster','custom'}))
- error( 'SHCTools:shc_validatesubnetwork:InvalidParameter',...
- ['The ''type'' field of network%s must be ''contour'', '...
- '''channel'', ''cluster'', or ''custom''.'],i);
+ error('SHCTools:shc_validatesubnetwork:InvalidType',...
+ ['The ''type'' field of network%s must be ''contour'', '...
+ '''channel'', ''cluster'', or ''custom''.'],i);
end
if ~isfield(s,'size')
- error( 'SHCTools:shc_validatesubnetwork:InvalidArgument',...
- 'Network%s does not have required field named ''size''.',i);
+ error('SHCTools:shc_validatesubnetwork:MissingSizeField',...
+ 'Network%s does not have required field named ''size''.',i);
end
if ~validateindex(s.size) || ~isnumeric(s.size)
- error( 'SHCTools:shc_validatesubnetwork:InvalidParameter',...
- 'The ''size'' field must be a real positive integer.');
+ error('SHCTools:shc_validatesubnetwork:InvalidSize',...
+ 'The ''size'' field must be a real positive integer.');
end
% Contours must have at least 3 nodes
if strcmp(s.type,'contour') && s.size < 3
- error( 'SHCTools:shc_validatesubnetwork:InvalidParameter',...
- ['Network%s is specified as a ''contour'' type, but the ''size'' '...
- 'field is less than the minimum of 3.'],i);
+ error('SHCTools:shc_validatesubnetwork:InvalidContourSize',...
+ ['Network%s is specified as a ''contour'' type, but the ''size'' '...
+ 'field is less than the minimum of 3.'],i);
end
if ~isfield(s,'alpha')
- error( 'SHCTools:shc_validatesubnetwork:InvalidArgument',...
- 'Network%s does not have required field named ''alpha''.',i);
+ error('SHCTools:shc_validatesubnetwork:MissingAlphaField',...
+ 'Network%s does not have required field named ''alpha''.',i);
end
-if ~isscalar(s.alpha) || ~(isnumeric(s.alpha) || isa(s.alpha,'sym'))
- error( 'SHCTools:shc_validatesubnetwork:InvalidParameter',...
- ['The ''alpha'' field of network%s must be a scalar numeric or '...
- 'symbolic value.'],i);
+if ~isscalar(s.alpha) || ~(isfloat(s.alpha) || isa(s.alpha,'sym'))
+ error('SHCTools:shc_validatesubnetwork:InvalidAlpha',...
+ ['The ''alpha'' field of network%s must be a scalar symbolic or '...
+ 'floating-point value.'],i);
end
if ~isreal(s.alpha) || abs(s.alpha) == Inf || isnan(s.alpha)
- error( 'SHCTools:shc_validatesubnetwork:InvalidParameter',...
- 'The ''alpha'' field of network%s must be a real, finite value.',i);
+ error('SHCTools:shc_validatesubnetwork:NonFiniteRealAlpha',...
+ 'The ''alpha'' field of network%s must be a real, finite value.',i);
end
% Beta is optional
if isfield(s,'beta')
- if ~isscalar(s.beta) || ~(isnumeric(s.beta) || isa(s.beta,'sym'))
- error( 'SHCTools:shc_validatesubnetwork:InvalidParameter',...
- ['The optional ''beta'' field of network%s must be a scalar '...
- 'numeric or symbolic value.'],i);
+ if ~isscalar(s.beta) || ~(isfloat(s.beta) || isa(s.beta,'sym'))
+ error('SHCTools:shc_validatesubnetwork:InvalidBeta',...
+ ['The optional ''beta'' field of network%s must be a scalar '...
+ 'symbolic or floating-point value.'],i);
end
if ~isreal(s.beta) || abs(s.beta) == Inf || isnan(s.beta)
- error( 'SHCTools:shc_validatesubnetwork:InvalidParameter',...
- ['The optional ''beta'' field of network%s must be a real, '...
- 'finite value.'],i);
+ error('SHCTools:shc_validatesubnetwork:NonFiniteRealBeta',...
+ ['The optional ''beta'' field of network%s must be a real, '...
+ 'finite value.'],i);
end
end
if ~isfield(s,'gamma')
- error( 'SHCTools:shc_validatesubnetwork:InvalidArgument',...
- 'Network%s does not have required field named ''gamma''.',i);
+ error('SHCTools:shc_validatesubnetwork:MissingGammaField',...
+ 'Network%s does not have required field named ''gamma''.',i);
end
-if ~isscalar(s.gamma) || ~(isnumeric(s.gamma) || isa(s.gamma,'sym'))
- error( 'SHCTools:shc_validatesubnetwork:InvalidParameter',...
- ['The ''gamma'' field of network%s must be a scalar numeric or '...
- 'symbolic value.'],i);
+if ~isscalar(s.gamma) || ~(isfloat(s.gamma) || isa(s.gamma,'sym'))
+ error('SHCTools:shc_validatesubnetwork:InvalidGamma',...
+ ['The ''gamma'' field of network%s must be a scalar symbolic or '...
+ 'floating-point value.'],i);
end
if ~isreal(s.gamma) || abs(s.gamma) == Inf || isnan(s.gamma)
- error( 'SHCTools:shc_validatesubnetwork:InvalidParameter',...
- 'The ''gamma'' field of network%s must be a real, finite value.',i);
+ error('SHCTools:shc_validatesubnetwork:NonFiniteRealGamma',...
+ 'The ''gamma'' field of network%s must be a real, finite value.',i);
end
% Delta is optional is for clusters
if isfield(s,'delta')
- if ~isscalar(s.delta) || ~(isnumeric(s.delta) || isa(s.delta,'sym'))
- error( 'SHCTools:shc_validatesubnetwork:InvalidParameter',...
- ['The ''delta'' field of network%s must be a scalar numeric '...
- 'or symbolic value.'],i);
+ if ~isscalar(s.delta) || ~(isfloat(s.delta) || isa(s.delta,'sym'))
+ error('SHCTools:shc_validatesubnetwork:InvalidDelta',...
+ ['The ''delta'' field of network%s must be a scalar symbolic '...
+ 'or floating-point value.'],i);
end
if ~isreal(s.delta) || abs(s.delta) == Inf || isnan(s.delta)
- error( 'SHCTools:shc_validatesubnetwork:InvalidParameter',...
- ['The optional ''delta'' field of the ''cluster'' type '...
- 'network%s must be a real, finite value.'],i);
+ error('SHCTools:shc_validatesubnetwork:NonFiniteRealDelta',...
+ ['The optional ''delta'' field of the ''cluster'' type '...
+ 'network%s must be a real, finite value.'],i);
end
elseif ~strcmp(s.type,'cluster')
- error( 'SHCTools:shc_validatesubnetwork:InvalidArgument',...
- 'Network%s does not have required field named ''delta''.',i);
+ error('SHCTools:shc_validatesubnetwork:MissingDeltaField',...
+ 'Network%s does not have required field named ''delta''.',i);
end
% Direction is optional, except for channels and contours in 'strict' mode
if isfield(s,'direction')
if ~isscalar(s.direction)
- error( 'SHCTools:shc_validatesubnetwork:InvalidParameter',...
- ['The ''direction'' field of network%s must be a scalar '...
- 'value.'],i);
+ error('SHCTools:shc_validatesubnetwork:NonscalarDirection',...
+ 'The ''direction'' field of network%s must be a scalar value.',i);
end
if ~isnumeric(s.direction) || ~isreal(s.direction) || ~isfinite(s.direction)
- error( 'SHCTools:shc_validatesubnetwork:InvalidParameter',...
- ['The ''direction'' field of network%s must be a real, '...
- 'finite numeric value.'],i);
+ error('SHCTools:shc_validatesubnetwork:NonFiniteRealDirection',...
+ ['The ''direction'' field of network%s must be a real, finite '...
+ 'numeric value.'],i);
end
if s.direction ~= 1 && s.direction ~= -1
- error( 'SHCTools:shc_validatesubnetwork:InvalidParameter',...
- ['The ''direction'' field of network%s must be either 1 '...
- '(clockwise) or -1 (counterclockwise)'],i);
+ error('SHCTools:shc_validatesubnetwork:InvalidDirection',...
+ ['The ''direction'' field of network%s must be either 1 '...
+ '(clockwise) or -1 (counterclockwise)'],i);
end
elseif strict && ~strcmp(s.type,'cluster')
- error( 'SHCTools:shc_validatesubnetwork:InvalidArgument',...
- ['The ''direction'' field of network%s was not specified, but is '...
- 'required when using ''strict'' mode validation of a %s type '...
- 'network.'],i,s.type);
+ error('SHCTools:shc_validatesubnetwork:MissingDirectionField',...
+ ['The ''direction'' field of network%s was not specified, but is '...
+ 'required when using ''strict'' mode validation of a %s type '...
+ 'network.'],i,s.type);
end
% Hand case where no network number passed, much less strict validation possible
if isempty(i)
if isfield(s,'parent')
if ~validateindex(s.parent) || ~isnumeric(s.parent)
- error( 'SHCTools:shc_validatesubnetwork:InvalidParameter',...
- ['The ''parent'' field is specified (optional for root '...
- 'networks), but is not a real positive integer.']);
+ error('SHCTools:shc_validatesubnetwork:InvalidParent',...
+ ['The ''parent'' field is specified (optional for root '...
+ 'networks), but is not a real positive integer.']);
end
elseif strict
- error( 'SHCTools:shc_validatesubnetwork:InvalidArgument',...
- ['The ''parent'' field was not specified (optional for root '...
- 'networks), but is required when using ''strict'' mode '...
- 'validation.']);
+ error('SHCTools:shc_validatesubnetwork:MissingParent',...
+ ['The ''parent'' field was not specified (optional for root '...
+ 'networks), but is required when using ''strict'' mode '...
+ 'validation.']);
end
if isfield(s,'node')
if ~validateindex(s.node) || ~isnumeric(s.node)
- error( 'SHCTools:shc_validatesubnetwork:InvalidParameter',...
- ['The ''node'' field is specified (optional for root '...
- 'networks), but is not a real positive integer.']);
+ error('SHCTools:shc_validatesubnetwork:InvalidNode',...
+ ['The ''node'' field is specified (optional for root '...
+ 'networks), but is not a real positive integer.']);
end
elseif strict
- error( 'SHCTools:shc_validatesubnetwork:InvalidArgument',...
- ['The ''node'' field was not specified (optional for root '...
- 'networks), but is required when using ''strict'' mode '...
- 'validation.']);
+ error('SHCTools:shc_validatesubnetwork:MissingNode',...
+ ['The ''node'' field was not specified (optional for root '...
+ 'networks), but is required when using ''strict'' mode '...
+ 'validation.']);
end
if isfield(s,'children')
if ndims(s.children) ~= 2 || size(s.children,1) > 1
- error( 'SHCTools:shc_validatesubnetwork:InvalidParameter',...
- ['The optional ''children'' field must be a scalar value '...
- 'or a row vector.']);
+ error('SHCTools:shc_validatesubnetwork:InvalidChildren',...
+ ['The optional ''children'' field must be a scalar value '...
+ 'or a row vector.']);
end
if ~isnumeric(s.children) || ~isreal(s.children) ...
|| ~all(isfinite(s.children))
- error( 'SHCTools:shc_validatesubnetwork:InvalidParameter',...
- ['The optional ''children'' field must be a positive real'...
- 'integer or row vector of such values.']);
+ error('SHCTools:shc_validatesubnetwork:NonFiniteRealChildren',...
+ ['The optional ''children'' field must be a positive real'...
+ 'integer or row vector of such values.']);
end
if any(s.children < 2) || any(s.children-floor(s.children) ~= 0)
- error( 'SHCTools:shc_validatesubnetwork:InvalidParameter',...
- ['The optional ''children'' field values must all be '...
- 'real integers >= 2.']);
+ error('SHCTools:shc_validatesubnetwork:NonIntegerChildren',...
+ ['The optional ''children'' field values must all be real '...
+ 'integers >= 2.']);
end
if ~all(diff(s.children) > 0)
- error( 'SHCTools:shc_validatesubnetwork:InvalidParameter',...
- ['Multiple optional ''children'' field values must all '...
- 'be unique and listed in increasing order.'],i);
+ error('SHCTools:shc_validatesubnetwork:NonUniqueChildren',...
+ ['Multiple optional ''children'' field values must all be '...
+ 'unique and listed in increasing order.'],i);
end
end
if isfield(s,'index') && (~validateindex(s.index) || ~isnumeric(s.index))
- error( 'SHCTools:shc_validatesubnetwork:InvalidParameter',...
- ['The ''index'' field is specified (optional for root '...
- 'networks), but is not a real positive integer.']);
+ error('SHCTools:shc_validatesubnetwork:NonIntegerIndex',...
+ ['The ''index'' field is specified (optional for root '...
+ 'networks), but is not a real positive integer.']);
end
else
% Handle special cases for first (root) network of base structure
if num == 1
% Parent field is optional for root network unless 'strict' mode is used
if isfield(s,'parent')
if ~validateindex(s.parent) || ~isnumeric(s.parent) || s.parent ~= 1
- error( 'SHCTools:shc_validatesubnetwork:InvalidParameter',...
- ['The optional ''parent'' field is specified for the '...
- 'first (root) network, but is not a real positive '...
- 'integer equal to 1.'],i);
+ error('SHCTools:shc_validatesubnetwork:InvalidRootParent',...
+ ['The optional ''parent'' field is specified for the '...
+ 'first (root) network, but is not a real positive '...
+ 'integer equal to 1.'],i);
end
elseif strict
- error( 'SHCTools:shc_validatesubnetwork:InvalidArgument',...
- ['The ''parent'' field was not specified for the first '...
- '(root) network, but is required when using ''strict'' '...
- 'mode validation.'],i);
+ error('SHCTools:shc_validatesubnetwork:MissingRootParent',...
+ ['The ''parent'' field was not specified for the first '...
+ '(root) network, but is required when using ''strict'' '...
+ 'mode validation.'],i);
end
% Node field is optional for root network unless 'strict' mode is used
if isfield(s,'node')
if ~validateindex(s.node) || ~isnumeric(s.node) || s.node ~= 1
- error( 'SHCTools:shc_validatesubnetwork:InvalidParameter',...
- ['The optional ''node'' field is specified for the '...
- 'first (root) network, but is not a real positive '...
- 'integer equal to 1.'],i);
+ error('SHCTools:shc_validatesubnetwork:InvalidRootNode',...
+ ['The optional ''node'' field is specified for the '...
+ 'first (root) network, but is not a real positive '...
+ 'integer equal to 1.'],i);
end
elseif strict
- error( 'SHCTools:shc_validatesubnetwork:InvalidArgument',...
- ['The ''node'' field was not specified for the first '...
- '(root) network, but is required when using ''strict'' '...
- 'mode validation.'],i);
+ error('SHCTools:shc_validatesubnetwork:MissingRootNode',...
+ ['The ''node'' field was not specified for the first '...
+ '(root) network, but is required when using ''strict'' '...
+ 'mode validation.'],i);
end
% Index field is optional for root unless set by children
if isfield(s,'index') && (~validateindex(s.index) ...
|| ~isnumeric(s.index) || s.index ~= 1)
- error( 'SHCTools:shc_validatesubnetwork:InvalidParameter',...
- ['The optional ''index'' field is specified for the '...
- 'first (root) network, but is not a real positive '...
- 'integer equal to 1.'],i);
+ error('SHCTools:shc_validatesubnetwork:NonIntegerRootIndex',...
+ ['The optional ''index'' field is specified for the first '...
+ '(root) network, but is not a real positive integer equal '...
+ 'to 1.'],i);
end
else
% Handle non-root (children) subnetworks
if ~isfield(s,'parent')
- error( 'SHCTools:shc_validatesubnetwork:InvalidArgument',...
- 'Network%s does not have required ''parent'' field.',i);
+ error('SHCTools:shc_validatesubnetwork:ChildMissingParent',...
+ 'Network%s does not have required ''parent'' field.',i);
end
if ~validateindex(s.parent) || ~isnumeric(s.parent)
- error( 'SHCTools:shc_validatesubnetwork:InvalidParameter',...
- ['The ''parent'' field of network%s must be a real '...
- 'positive integer.'],i);
+ error('SHCTools:shc_validatesubnetwork:InvalidChildParent',...
+ ['The ''parent'' field of network%s must be a real '...
+ 'positive integer.'],i);
end
if s.parent >= num
- error( 'SHCTools:shc_validatesubnetwork:InvalidParameter',...
- ['The ''parent'' field of network%s must be an integer '...
- 'less than the network number.'],i);
+ error('SHCTools:shc_validatesubnetwork:InvalidParentID',...
+ ['The ''parent'' field of network%s must be an integer '...
+ 'less than the network number.'],i);
end
if ~isfield(s,'node')
- error( 'SHCTools:shc_validatesubnetwork:InvalidArgument',...
- 'Network%s has does not have required ''node'' field.',i);
+ error('SHCTools:shc_validatesubnetwork:ChildMissingNode',...
+ 'Network%s has does not have required ''node'' field.',i);
end
if ~validateindex(s.node) || ~isnumeric(s.node)
- error( 'SHCTools:shc_validatesubnetwork:InvalidParameter',...
- ['The ''node'' field of network%s must be a real '...
- 'positive integer.'],i);
+ error('SHCTools:shc_validatesubnetwork:InvalidChildNode',...
+ ['The ''node'' field of network%s must be a real positive '...
+ 'integer.'],i);
end
% Index field is optional unless it has been set by parent or child
if isfield(s,'index') && (~validateindex(s.index) ...
|| ~isnumeric(s.index))
- error( 'SHCTools:shc_validatesubnetwork:InvalidParameter',...
- ['The ''index'' field of network%s must be a real '...
- 'positive integer.'],i);
+ error('SHCTools:shc_validatesubnetwork:NonIntegerChildIndex',...
+ ['The ''index'' field of network%s must be a real positive '...
+ 'integer.'],i);
end
end
% Children field is optional unless it has been set by parent or child
if isfield(s,'children')
if ndims(s.children) ~= 2 || size(s.children,1) > 1
- error( 'SHCTools:shc_validatesubnetwork:InvalidParameter',...
- ['The ''children'' field of network%s must be a scalar '...
- 'value or a row vector.'],i);
+ error('SHCTools:shc_validatesubnetwork:InvalidChildrenID',...
+ ['The ''children'' field of network%s must be a scalar '...
+ 'value or a row vector.'],i);
end
if ~isnumeric(s.children) || ~isreal(s.children) ...
|| ~all(isfinite(s.children))
- error( 'SHCTools:shc_validatesubnetwork:InvalidParameter',...
- ['The ''children'' field of network%s must be a positive '...
- 'real integer or row vector of such values.'],i);
+ error('SHCTools:shc_validatesubnetwork:NonFiniteRealChildrenID',...
+ ['The ''children'' field of network%s must be a positive '...
+ 'real integer or row vector of such values.'],i);
end
if any(s.children <= num) || any(s.children-floor(s.children) ~= 0)
- error( 'SHCTools:shc_validatesubnetwork:InvalidParameter',...
- ['The ''children'' field values of network%s must all be '...
- 'real integers >= %d.'],i,num+1);
+ error('SHCTools:shc_validatesubnetwork:NonIntegerChildrenID',...
+ ['The ''children'' field values of network%s must all be '...
+ 'real integers >= %d.'],i,num+1);
end
if ~all(diff(s.children) > 0)
- error( 'SHCTools:shc_validatestruct:InvalidParameter',...
- ['Multiple ''children'' field values of network %d must '...
- 'all be unique and listed in increasing order.'],i);
+ error('SHCTools:shc_validatestruct:NonUniqueChildrenID',...
+ ['Multiple ''children'' field values of network %d must '...
+ 'all be unique and listed in increasing order.'],i);
end
end
end
% Check optional T matrix
if isfield(s,'T')
if ndims(s.T) ~= 2 || ~all(size(s.T) == s.size)
- error( 'SHCTools:shc_validatesubnetwork:InvalidParameter',...
- ['The optional ''T'' field of network%s must be a square '...
- 'matrix the same dimension as the network''s ''size'' '...
- 'field.'],i);
+ error('SHCTools:shc_validatesubnetwork:InvalidTMatrix',...
+ ['The optional ''T'' field of network%s must be a square '...
+ 'matrix the same dimension as the network''s ''size'' field.'],i);
end
if ~islogical(s.T)
- error( 'SHCTools:shc_validatesubnetwork:InvalidParameter',...
- ['The optional ''T'' field of network%s must be a logical '...
- '(Boolean) matrix.'],i);
+ error('SHCTools:shc_validatesubnetwork:NonBooleanTMatrix',...
+ ['The optional ''T'' field of network%s must be a logical '...
+ '(Boolean) matrix.'],i);
end
% Create test T matrix to compare
@@ -346,9 +344,9 @@ function shc_validatesubnetwork(s,varargin)
end
end
if ~all(t(:) == s.T(:))
- error( 'SHCTools:shc_validatesubnetwork:InvalidParameter',...
- ['The optional ''T'' field values of network%s do not '...
- 'match those of a ''%s'' type network.'],i,s.type);
+ error('SHCTools:shc_validatesubnetwork:TMatrixTypeMismatch',...
+ ['The optional ''T'' field values of network%s do not '...
+ 'match those of a ''%s'' type network.'],i,s.type);
end
end
end
View
185 SHCTools/shc_lv_eigs.m
@@ -0,0 +1,185 @@
+function varargout=shc_lv_eigs(rho,M)
+%SHC_LV_EIGS Eigenvalues of N-dimensional Lotka-Volterra system.
+% E = SHC_LV_EIGS(RHO,M) returns the N-by-1 vector of eigenvalues for the M-th
+% node of the N-dimensional Lotka-Volterra SHC network described by the
+% connection matrix RHO. RHO is an N-by-N floating-point or symbolic matrix or
+% an SHC network structure. If RHO is a matrix, the amplitude scaling
+% parameters, beta, are asummed to all be equal to one. If RHO is an SHC
+% network structure, arbitrary beta values may be used. M is a scalar integer.
+%
+% [V,D] = SHC_LV_EIGS(RHO,M) produces an N-by-N diagonal matrix D of
+% eigenvalues and a full N-by-N matrix V whose columns are the corresponding
+% eigenvectors so that J*V = V*D, where J is the N-by-N Jacobian matrix for
+% the M-th node of the N-dimensional Lotka-Volterra SHC network described by
+% the connection matrix RHO.
+%
+% E = SHC_LV_EIGS(RHO) returns an N-by-N matrix of eigenvalues for all N nodes
+% of the SHC. The columns of the output matrix correspond to equilibrium point
+% vectors from the columns of an identity matrix of size N.
+%
+% [V,D] = SHC_LV_EIGS(RHO) produces two 1-by-N cell arrays containing diagonal
+% matrices D of eigenvalues and full matrices V whose columns are the
+% corresponding eigenvectors for all N nodes of the SHC. The row elements of
+% each cell array correspond to equilibrium point vectors from the columns of
+% an identity matrix of size N.
+%
+% See also:
+% SHC_LV_JACOBIAN, BUILDRHO, SHC_CREATE, SHC_LV_SYMEQUILIBRIA
+
+% Andrew D. Horchler, adh9@case.edu, Created 4-6-12
+% Revision: 1.0, 4-6-12
+
+
+if nargout > 2
+ error('SHCTools:shc_lv_eigs:TooManyOutputs','Too many output arguments.');
+end
+
+% Check Rho matrix
+if isstruct(rho) && isfield(rho,'rho')
+ if isfield(rho,'alpha')
+ alpv = rho.alpha;
+ if ~isvector(alpv) || ~(isfloat(alpv) || isa(alpv,'sym'))
+ error('SHCTools:shc_lv_eigs:AlphaVectorInvalid',...
+ ['The ''alpha'' field of the SHC network structure must be '...
+ 'a symbolic or floating-point vector.']);
+ end
+ if ~isreal(alpv) || any(abs(alpv) == Inf) || any(isnan(alpv))
+ error('SHCTools:shc_lv_eigs:AlphaVectorNonFiniteReal',...
+ ['The ''alpha'' field of the SHC network structure must be '...
+ 'a finite real symbolic or floating-point vector.']);
+ end
+ p = rho.rho;
+ [m n] = size(p);
+ if size(alpv,1) ~= n
+ error('SHCTools:shc_lv_eigs:AlphaVectorDimensionMismatch',...
+ ['The ''alpha'' field of the SHC network structure must be '...
+ 'a column vector the same dimension as RHO.']);
+ end
+ else
+ p = rho.rho;
+ alpv = diag(p);
+ [m n] = size(p);
+ end
+ if isfield(rho,'beta')
+ betv = rho.beta;
+ if ~isvector(betv) || ~(isfloat(betv) || isa(betv,'sym'))
+ error('SHCTools:shc_lv_eigs:BetaVectorInvalid',...
+ ['The ''beta'' field of the SHC network structure must be '...
+ 'a symbolic or floating-point vector.']);
+ end
+ if ~isreal(betv) || any(abs(betv) == Inf) || any(isnan(betv))
+ error('SHCTools:shc_lv_eigs:BetaVectorNonFiniteReal',...
+ ['The ''beta'' field of the SHC network structure must be '...
+ 'a finite real symbolic or floating-point vector.']);
+ end
+ if size(betv,1) ~= n
+ error('SHCTools:shc_lv_eigs:BetaVectorDimensionMismatch',...
+ ['The ''beta'' field of the SHC network structure must be '...
+ 'a column vector the same dimension as RHO.']);
+ end
+ else
+ betv = ones(n,1);
+ end
+ if ~(isfloat(p) || isa(p,'sym'))
+ error('SHCTools:shc_lv_eigs:InvalidRhoStruct',...
+ ['The ''rho'' field of the SHC network structure must be a '...
+ 'symbolic or floating-point matrix.']);
+ end
+ if ~isreal(p) || any(abs(p(:)) == Inf) || any(isnan(p(:)))
+ error('SHCTools:shc_lv_eigs:RhoStructNonFiniteReal',...
+ ['The ''rho'' field of the SHC network structure must be a '...
+ 'finite real symbolic or floating-point matrix.']);
+ end
+else
+ p = rho;
+ if ~(isfloat(p) || isa(p,'sym'))
+ error('SHCTools:shc_lv_eigs:InvalidRho',...
+ ['The ''rho'' field of the SHC network structure must be a '...
+ 'symbolic or floating-point matrix.']);
+ end
+ if ~isreal(p) || any(abs(p(:)) == Inf) || any(isnan(p(:)))
+ error('SHCTools:shc_lv_jacobian:RhoNonFiniteReal',...
+ ['The ''rho'' field of the SHC network structure must be a '...
+ 'finite real symbolic or floating-point matrix.']);
+ end
+ alpv = diag(p);
+ [m n] = size(p);
+ betv = ones(n,1);
+end
+if isempty(p) || ndims(p) ~= 2 || m ~= n
+ error('SHTools:shc_lv_eigs:RhoDimensionMismatch',...
+ ['RHO must be a non-empty square matrix the same dimension as '...
+ 'the equilibrium point vector.']);
+end
+
+isSym = (isa(p,'sym') || isa(alpv,'sym') || isa(betv,'sym'));
+
+if nargin == 2
+ % Check M
+ if ~validateindex(M) || ~isnumeric(M)
+ error('SHTools:shc_lv_eigs:NonScalarM',...
+ 'M must be a finite real integer greater than or equal to one.');
+ end
+
+ eqpt = zeros(n,1);
+ if isSym
+ eqpt = sym(eqpt);
+ end
+ eqpt(M) = -betv(M);
+
+ % Calculate Jacobian
+ J = p.*eqpt(:,ones(1,n));
+ J(1:n+1:end) = alpv.*(1+eqpt)+p*eqpt;
+
+ % Calculate eigenvalues/eigenvectors
+ if nargout == 2
+ [V D] = eig(J);
+ if isSym
+ V = simplify(V);
+ D = simplify(D);
+ end
+ else
+ E = eig(J);
+ end
+else
+ eqpt = diag(-betv);
+ z = ones(1,n);
+ if nargout == 2
+ V = cell(1,n);
+ D = cell(1,n);
+ else
+ E = zeros(n);
+ if isSym
+ E = sym(E);
+ end
+ end
+
+ for i = 1:n
+ % Calculate Jacobian
+ v = eqpt(:,i);
+ J = p.*v(:,z);
+ J(1:n+1:end) = alpv.*(1+v)+p*v;
+
+ % Calculate eigenvalues/eigenvectors
+ if nargout == 2
+ [V{i} D{i}] = eig(J);
+ if isSym
+ V{i} = simplify(V{i});
+ D{i} = simplify(D{i});
+ end
+ else
+ E(:,i) = eig(J);
+ end
+ end
+end
+
+% Handle variable output
+if nargout == 2
+ varargout{1} = V;
+ varargout{2} = D;
+else
+ if isSym
+ E = simplify(E);
+ end
+ varargout{1} = E;
+end
View
116 SHCTools/shc_lv_jacobian.m
@@ -13,47 +13,64 @@
% equilibrium point vectors from the columns of an identity matrix of size N.
%
% See also:
-% BUILDRHO, SHC_CREATE, SHC_LV_SYMEQUILIBRIA, EIG
+% SHC_LV_EIGS, BUILDRHO, SHC_CREATE, SHC_LV_SYMEQUILIBRIA
% Andrew D. Horchler, adh9@case.edu, Created 12-1-10
-% Revision: 1.0, 3-31-12
+% Revision: 1.0, 4-6-12
% Check Rho matrix
if isstruct(rho) && isfield(rho,'rho')
if isfield(rho,'alpha')
alpv = rho.alpha;
- if ~isfloat(alpv) || ~isreal(alpv) || ~all(isfinite(alpv))
+ if ~isvector(alpv) || ~(isfloat(alpv) || isa(alpv,'sym'))
error('SHCTools:shc_lv_jacobian:AlphaVectorInvalid',...
- ['The ''alpha'' field of the SHC network structure must '...
- 'be a finite real floating-point vector.']);
+ ['The ''alpha'' field of the SHC network structure must be '...
+ 'a symbolic or floating-point vector.']);
end
- rho = rho.rho;
- [m n] = size(rho);
- if ~isvector(alpv) || size(alpv,1) ~= n
+ if ~isreal(alpv) || any(abs(alpv) == Inf) || any(isnan(alpv))
+ error('SHCTools:shc_lv_jacobian:AlphaVectorNonFiniteReal',...
+ ['The ''alpha'' field of the SHC network structure must be '...
+ 'a finite real symbolic or floating-point vector.']);
+ end
+ p = rho.rho;
+ [m n] = size(p);
+ if size(alpv,1) ~= n
error('SHCTools:shc_lv_jacobian:AlphaVectorDimensionMismatch',...
- ['The ''alpha'' field of the SHC network structure must '...
- 'be a column vector the same dimension as RHO.']);
+ ['The ''alpha'' field of the SHC network structure must be '...
+ 'a column vector the same dimension as RHO.']);
end
else
- rho = rho.rho;
- alpv = diag(rho);
- [m n] = size(rho);
+ p = rho.rho;
+ alpv = diag(p);
+ [m n] = size(p);
end
- if ~isfloat(rho) || ~isreal(rho) || ~all(isfinite(rho(:)))
+ if ~(isfloat(p) || isa(p,'sym'))
error('SHCTools:shc_lv_jacobian:InvalidRhoStruct',...
- ['If the input RHO is a SHC network structure, the ''rho'' '...
- 'field must be a finite real floating-point matrix.']);
+ ['The ''rho'' field of the SHC network structure must be a '...
+ 'symbolic or floating-point matrix.']);
+ end
+ if ~isreal(p) || any(abs(p(:)) == Inf) || any(isnan(p(:)))
+ error('SHCTools:shc_lv_jacobian:RhoStructNonFiniteReal',...
+ ['The ''rho'' field of the SHC network structure must be a '...
+ 'finite real symbolic or floating-point matrix.']);
end
else
- if ~isfloat(rho) || ~isreal(rho) || ~all(isfinite(rho(:)))
- error('SHTools:shc_lv_jacobian:RhoInvalidDatatype',...
- 'RHO must be a finite real floating-point matrix.');
+ p = rho;
+ if ~(isfloat(p) || isa(p,'sym'))
+ error('SHCTools:shc_lv_jacobian:InvalidRho',...
+ ['The ''rho'' field of the SHC network structure must be a '...
+ 'symbolic or floating-point matrix.']);
end
- alpv = diag(rho);
- [m n] = size(rho);
+ if ~isreal(p) || any(abs(p(:)) == Inf) || any(isnan(p(:)))
+ error('SHCTools:shc_lv_jacobian:RhoNonFiniteReal',...
+ ['The ''rho'' field of the SHC network structure must be a '...
+ 'finite real symbolic or floating-point matrix.']);
+ end
+ alpv = diag(p);
+ [m n] = size(p);
end
-if isempty(rho) || ndims(rho) ~= 2 || m ~= n
+if isempty(p) || ndims(p) ~= 2 || m ~= n
error('SHTools:shc_lv_jacobian:RhoDimensionMismatch',...
['RHO must be a non-empty square matrix the same dimension as '...
'the equilibrium point vector.']);
@@ -65,23 +82,58 @@
error('SHTools:shc_lv_jacobian:EquilibriumPointDimensionMismatch',...
'Equilibrium point must be a vector the same dimension as RHO.');
end
- if ~isfloat(eqpt) || ~isreal(eqpt) || ~all(isfinite(eqpt))
- error('SHTools:shc_lv_jacobian:EquilibriumPointInvalidDatatype',...
- 'Equilibrium point must be a finite real floating-point vector.');
+ if ~(isfloat(eqpt) || isa(eqpt,'sym'))
+ error('SHCTools:shc_lv_jacobian:InvalidEquilibriumPoint',...
+ 'Equilibrium point must be a symbolic or floating-point vector.');
+ end
+ if ~isreal(eqpt) || any(abs(eqpt) == Inf) || any(isnan(eqpt))
+ error('SHCTools:shc_lv_jacobian:EquilibriumPointNonFiniteReal',...
+ ['Equilibrium point must be a finite real symbolic or '...
+ 'floating-point vector.']);
end
eqpt = -eqpt(:);
% Calculate Jacobian
- J = rho.*eqpt(:,ones(1,n));
- J(1:n+1:end) = alpv.*(1+eqpt)+rho*eqpt;
+ J = p.*eqpt(:,ones(1,n));
+ J(1:n+1:end) = alpv.*(1+eqpt)+p*eqpt;
+
+ if isa(J,'sym')
+ J = simplify(J);
+ end
else
- eqpt = eye(n);
+ if isstruct(rho) && isfield(rho,'rho') && isfield(rho,'beta')
+ betv = rho.beta;
+ if ~isvector(betv) || ~(isfloat(betv) || isa(betv,'sym'))
+ error('SHCTools:shc_lv_jacobian:BetaVectorInvalid',...
+ ['The ''beta'' field of the SHC network structure must be '...
+ 'a symbolic or floating-point vector.']);
+ end
+ if ~isreal(betv) || any(abs(betv) == Inf) || any(isnan(betv))
+ error('SHCTools:shc_lv_jacobian:BetaVectorNonFiniteReal',...
+ ['The ''beta'' field of the SHC network structure must be '...
+ 'a finite real symbolic or floating-point vector.']);
+ end
+ if size(betv,1) ~= n
+ error('SHCTools:shc_lv_jacobian:BetaVectorDimensionMismatch',...
+ ['The ''beta'' field of the SHC network structure must be '...
+ 'a column vector the same dimension as RHO.']);
+ end
+ eqpt = diag(-betv);
+ else
+ eqpt = -eye(n);
+ end
+
J = cell(1,n);
+ isSym = (isa(p,'sym') || isa(alpv,'sym') || isa(eqpt,'sym'));
+ z = ones(1,n);
for i = 1:n
- J{i} = zeros(n);
-
% Calculate Jacobian
- J{i}(i,:) = -rho(i,:);
- J{i}(1:n+1:end) = alpv.*(1-eqpt(:,i))-rho(:,i);
+ v = eqpt(:,i);
+ J{i} = p.*v(:,z);
+ J{i}(1:n+1:end) = alpv.*(1+v)+p*v;
+
+ if isSym
+ J{i} = simplify(J{i});
+ end
end
end

0 comments on commit 69d88ed

Please sign in to comment.
Something went wrong with that request. Please try again.