64 if ~ischar(targetdims)
66 n = length(targetdims);
69 if nargin < 2 || isempty(k)
74 k = min(k, min(n,m)-
size(Vexclude,2));
83 elseif this.getNumBlocks == 1
85 Bl = Bl(targetdims,:);
88 Bl = Bl - Vexclude*(Vexclude^
t*Bl);
90 [U, S] = svd(Bl,
" econ ");
98 fprintf(
" ABlockedData: Computing %d-partial SVD on %dx%d matrix (%d blocks)...\n ",...
99 k,n,m,this.getNumBlocks);
101 vb =
KerMor.
App.Verbose > 1 && n*m > 50000 && this.getNumBlocks > 2;
104 if ~isempty(Vexclude)
106 opts.v0= v0 - Vexclude*(Vexclude^
t*v0);
108 doparallel = exist(
" matlabpool ",
" file ") == 2 && matlabpool(
" size ") > 1;
109 [U,S] = eigs(@mult,n,k,
" la ",opts);
110 if KerMor.
App.Verbose > 2, fprintf(
" BlockSVD: Finished after %d multiplications.\n ",cnt); end
116 warning(
" KerMor:ABlockedData ",
" Have only %d nonzero singular values instead of %d desired ones. ",...
122 if ~ischar(targetdims)
123 error(
" Fixme: Not correctly implemented yet. ");
124 [nfull,~] =
size(
this);
126 mat(targetdims,targetdims) = (U/S)^
t;
138 pi =
ProcessIndicator(
" ABlockedData: Blockwise multiplication for %d-SVD on %d blocks ",...
143 fprintf(
" ABlockedData: Parallel blockwise multiplication for %d-SVD on %d blocks...\n ",k,nb);
150 if ~isempty(Vexclude)
151 B = B - Vexclude*(Vexclude^
t*B);
160 if ~isempty(Vexclude)
161 B = B - Vexclude*(Vexclude^
t*B);
194 if isa(
matrix,
" data.ABlockedData ")
195 error(
" Must override in subclasses for case ABlockedData*matrix. ");
197 warning(
" KerMor:ABlockedData ",...
198 " If you want the right singular values, you need to override the mtimes method of data.ABlockedData(matrix, this).\nReturning the same instance for V. ");
211 A = zeros(
size(
this));
229 virtual function varargout =
size(dim) = 0;
235 virtual function B =
getBlock(nr) = 0;
251 A = data.FileMatrix(n,m,
" BlockSize ",data.FileMatrix.blockSizeOf(B)/nb);
252 A.subsasgn(
struct(
" type ",[
" () "],
" subs ",[[
" : ",
" : "]]),B);
253 [ub,us] = A.getSVD(ns);
254 [u,s] = svd(B,
" econ ");
255 chk = norm(diag(us)-diag(s(1:ns,1:ns)));
256 res = res && chk < 1e-8;
259 us = sign(u(1,1:ns));
260 chk2 = norm(bsxfun(@times,ub,ubs)-bsxfun(@times,u(:,1:ns),us));
261 res = res & chk2 < 1e-8;
262 fprintf(
" Comparison Block-SVD vs SVD (%d singular values): Singular value vector norm diff: %g, U norm diff: %g\n ",ns,chk,chk2);
virtual function n = getNumBlocks()
ABlockedData: General abstract class that allows computation of and SVD on a large matrix that is sep...
Matlab's base handle class (documentation generation substitute)
virtual function B = getBlock(nr)
function prod = mtimes()
Need left-sided matrix multiplication if RHS singular vectors V should be returned.
double MinRelSingularValueSize
The minimum relative value of singular values that triggers selection of the compared to the largest ...
Global configuration class for all KerMor run-time settings.
static function KerMor theinstance = App()
The singleton KerMor instance.
function A = toMemoryMatrix()
Converts this FileMatrix to a full double matrix.
virtual function varargout = size(dim)
static function res = test_BlockSVD_vs_SVD()
ProcessIndicator: A simple class that indicates process either via waitbar or text output...
function [ matrix< double > U , matrix< double > S , matrix< double > V ] = getSVD(integer k,matrix< double > Vexclude,colvec< integer > targetdims)
Computes an SVD on this blockwise matrix .