[ellipsoids] r2062 committed - issue #72...

1 view
Skip to first unread message

ellip...@googlecode.com

unread,
Jun 19, 2013, 8:04:25 AM6/19/13
to ellipsoids-change...@googlegroups.com
Revision: 2062
Author: swige.ide
Date: Wed Jun 19 05:04:07 2013
Log: issue #72
BugFix: removed elldistprec as it required no longer.
http://code.google.com/p/ellipsoids/source/detail?r=2062

Deleted:
/branches/issue_72_yadmiralsky/products/+gras/+la/elldistprec.m
Modified:

/branches/issue_72_yadmiralsky/products/+gras/+la/+test/+mlunit/BasicTestCase.m

=======================================
--- /branches/issue_72_yadmiralsky/products/+gras/+la/elldistprec.m Thu Jun
13 10:46:09 2013
+++ /dev/null
@@ -1,156 +0,0 @@
-function prec = elldistprec(qMat, tchVec, nCount, varargin)
-% ELLDISTPREC - calculates the precision of distance function between
-% ellipsoid and vector.
-%
-% The distance function between ellipsoid and vector:
-%
-% f(x | E(q, Q)) = abs(<x - q, Q^{-1} * (x - q)> - 1)
-%
-% We assume that q = 0. In MATLAB the function f(x, E) can be calculated
-% as:
-%
-% f(x | E(0, Q)) = abs(<x, inv(Q) * x> - 1); <inv>
-% f(x | E(0, Q)) = abs(<x, Q \ x> - 1); <mdivide>
-%
-% If the matrix Q is ill-conditioned, then (inv(Q) * x) may be not
-% precise. The result of multiplication may be presented as:
-%
-% inv(Q) * x = Q^{-1} x + x1,
-%
-% where x1 is error vector. The function may be presented as:
-%
-% f(x | E(0, Q)) = abs(<x, Q^{-1} * x> + <x, Q * Q^{-1} * x1> - 1);
-%
-% To find the precision we calculate the first order approximation:
-%
-% f(x | E(0, Q)) = abs(<x, Q^{-1} * x> + <x, inv(Q) * Q * x1> - 1);
-%
-% The error will be ~ abs(<x, inv(Q) * Q * x1>). For convinience we define:
-%
-% v1 = Q * x1 = Q *(inv(Q) * x) - x;
-%
-% So the first order approximation can be presented as
-% abs(<x, inv(Q) * v1). To find the second order approximation we assume
-% that:
-%
-% inv(Q) * v1 = inv(Q) * Q * x1 = x1 + x2,
-%
-% where x2 is error vector for inv(Q) * v1. Then we processing this
-% expression as we did it for inv(Q) * x and get the second order
-% approximation for error:
-%
-% abs(<x, inv(Q) * v1>) + abs(<x, inv(Q) * v2>)
-%
-% Finally we get the whole precision estimation:
-%
-% f(x | E(0, Q)) = abs(<x, Q^{-1} * x> - 1) +-
-% +- (abs(<x, inv(Q) * v1>) + abs(<x, inv(Q) * v2>) + ...)
-%
-% We calculate first N elements of error series. We also can calculate
-% until:
-% abs(<x, inv(Q) * vk>) < minTol,
-% or
-% (abs(<x, inv(Q) * v1>) + ... + abs(<x, inv(Q) * vk>)) > maxTol,
-%
-% where k <= N.
-%
-% Input:
-% regular:
-% qMat: double[nDims, nDims] - ellipsoid shape matrix Q.
-%
-% tchVec: double[n, 1] - good dir support point vector x.
-%
-% nCount: double[1, 1] - positive integer - count (N) of error
-% series elements to calculate.
-%
-% optional:
-% minTol: double[1, 1] - minimal series element value to be
-% calculated.
-%
-% maxTol: double[1, 1] - maximal series sum value to be calculated.
-%
-%
-% Output:
-% prec: double[1, 1] - f(x, E(0, Q)) precision.
-%
-%
-% Example:
-%
-% gras.la.elldistprec(eye(2), [1;1], 1)
-%
-% gras.la.elldistprec(eye(4), [1;0;0;0], 3, 1e-6)
-%
-% gras.la.elldistprec(eye(3), [0;1;0], 5, [], 1e-3)
-%
-%
-% $Authors: Yuri Admiralsky <swig...@gmail.com> $ $Date: 2013-06-10$
-% $Copyright: Moscow State University,
-% Faculty of Computational Mathematics and Computer Science,
-% System Analysis Department 2013 $
-import modgen.common.checkvar;
-import modgen.common.checkmultvar;
-%
-INTEGER_TOL = 1e-10;
-%
-checkvar(qMat, '(size(x,1)==size(x,2))&&(size(x,1)>1)&&ismatrix(x)', ...
- 'errorTag', 'wrongInput:nonSquareqMat', 'ErrorMessage', ...
- 'qMat expected to be a square matrix.');
-%
-checkvar(tchVec, '(size(x,2)==1)&&isvector(x)', 'errorTag', ...
- 'wrongInput:nonVector', 'ErrorMessage', ...
- 'tchVec is expected to be a vector.');
-checkmultvar('size(x1,2)==size(x2,1)', 2, qMat, tchVec, 'errorTag', ...
- 'wrongInput:notConsistent', 'ErrorMessage', ...
- 'qMat and tchVec are not consistent.');
-%
-checkmultvar(['isscalar(x1)&&isnumeric(x1)&&(x1>0)&&', ...
- '(abs(round(x1)-x1)<x2)'], 2, nCount, INTEGER_TOL, 'errorTag', ...
- 'wrongInput:wrongCount', 'ErrorMessage', ...
- 'nCount is expected to be a positive integer.');
-%
-minTol = -Inf;
-maxTol = Inf;
-if nargin > 3
- checkTol(varargin{1}, 'minTol', 0, '0');
- if ~isempty(varargin{1})
- minTol = varargin{1};
- end
-end
-if nargin > 4
- checkGrList = {'0', 'minTol'};
- [maxVal, maxInd] = max([0, minTol]);
- checkTol(varargin{2}, 'maxTol', maxVal, checkGrList{maxInd});
- if ~isempty(varargin{2})
- maxTol = varargin{2};
- end
-end
-%
-prec = 0;
-curVec = tchVec;
-for iSeries = 1:nCount
- invErrVec = qMat * (qMat \ curVec) - curVec;
- addInvPrecision = abs(dot(tchVec, qMat \ invErrVec));
- prec = prec + addInvPrecision;
- curVec = invErrVec;
- if (addInvPrecision < minTol) || (prec > maxTol)
- break;
- end
-end
-
-function checkTol(tol, tolStr, checkGreater, checkGreaterStr)
- import modgen.common.checkvar;
- import modgen.common.checkmultvar;
- %
- errTag = horzcat('wrongInput:wrong', tolStr);
- errMsg = horzcat(tolStr, [' is expected to be a positive scalar', ...
- ' or empty matrix.']);
- errMsg2 = horzcat(tolStr, ' is expected to be greater than ', ...
- checkGreaterStr, '.');
- checkvar(tol, '(isscalar(x)&&isnumeric(x))||isempty(x)', ...
- 'ErrorTag', errTag, 'ErrorMessage', errMsg);
- if ~isempty(tol)
- checkmultvar('(x1>x2)', 2, tol, checkGreater, 'ErrorTag',
errTag, ...
- 'ErrorMessage', errMsg2);
- end
-end
-end
=======================================
---
/branches/issue_72_yadmiralsky/products/+gras/+la/+test/+mlunit/BasicTestCase.m
Mon Jun 10 09:30:47 2013
+++
/branches/issue_72_yadmiralsky/products/+gras/+la/+test/+mlunit/BasicTestCase.m
Wed Jun 19 05:04:07 2013
@@ -317,61 +317,6 @@
'gras.la.regposdefmat(nonSquareMat, REG_TOL)',...
'wrongInput:nonSquareMat');
end
- function self = testEllDistPrec(self)
- import gras.la.elldistprec;
- SERIES_COUNT = 3;
- ABS_TOL = 1e-5;
- EPS_TOL = 1e-8;
- % good tests
- qMat = [1, 0; 0, 1];
- xVec = [1; 0];
- isOk = elldistprec(qMat, xVec, SERIES_COUNT, EPS_TOL) < ...
- EPS_TOL;
- mlunitext.assert(isOk);
- xVec = sqrt(2) ./ 2 * [1; 1];
- isOk = elldistprec(qMat, xVec, SERIES_COUNT, EPS_TOL) < ...
- EPS_TOL;
- mlunitext.assert(isOk);
- % bad tests
- qMat = [1e+6, 0; 0, 1e-6];
- xVec = [1000; 0];
- isOk = elldistprec(qMat, xVec, SERIES_COUNT, EPS_TOL) < ...
- EPS_TOL;
- mlunitext.assert(isOk);
- xVec = [0; 0.001];
- isOk = elldistprec(qMat, xVec, SERIES_COUNT) < ...
- EPS_TOL;
- mlunitext.assert(isOk);
- T = @(x) [cos(x), -sin(x); sin(x), cos(x)];
- xVec = 0.5 * ([1000;0] + [0; 0.001]);
- xVec = xVec ./ realsqrt(dot(xVec, qMat \ xVec));
- xVec = T(1) * xVec;
- qMat = T(1) * qMat * T(1)';
- qMat(2) = qMat(3);
- isOk = elldistprec(qMat, xVec, SERIES_COUNT, [], ABS_TOL) > ...
- ABS_TOL;
- mlunitext.assert(isOk);
- % negative tests
- wrongSerCount = -SERIES_COUNT;
- self.runAndCheckError(...
- 'gras.la.elldistprec(qMat, xVec, wrongSerCount)',...
- 'wrongInput');
- %
- wrongSerCount = [SERIES_COUNT, SERIES_COUNT];
- self.runAndCheckError(...
- 'gras.la.elldistprec(qMat, xVec, wrongSerCount)',...
- 'wrongInput');
- %
- wrongAbsTol = [ABS_TOL, ABS_TOL];
- self.runAndCheckError(...
- ['gras.la.elldistprec(qMat, xVec, SERIES_COUNT, [], ', ...
- 'wrongAbsTol)'], 'wrongInput');
- %
- nonSquareMat = ones(2, 3);
- self.runAndCheckError(...
- 'gras.la.elldistprec(nonSquareMat, xVec, SERIES_COUNT)',...
- 'wrongInput');
- end
end
end

Reply all
Reply to author
Forward
0 new messages