Home > manopt > manifolds > ttfixedrank > TTeMPS_1.1 > examples > ex_newton_1.m

# ex_newton_1

## PURPOSE

Example for the algorithms described in

## SYNOPSIS

This is a script file.

## DESCRIPTION

``` Example for the algorithms described in

D. Kressner, M. Steinlechner, A. Uschmajew:
Low-rank tensor methods with subspace correction for symmetric eigenvalue problems
SIAM J. Sci. Comput., 36(5):A2346-A2368, 2014.

Code to produce Figure 4.1, the smallest eigenvalue of the discretized Newton potential
(without the no-preconditioner graph, as it takes very long to compute and should not be used anyway)
=========================================================================```

## CROSS-REFERENCE INFORMATION

This function calls:
This function is called by:

## SOURCE CODE

```0001 % Example for the algorithms described in
0002 %
0003 %       D. Kressner, M. Steinlechner, A. Uschmajew:
0004 %        Low-rank tensor methods with subspace correction for symmetric eigenvalue problems
0005 %        SIAM J. Sci. Comput., 36(5):A2346-A2368, 2014.
0006 %
0007 % Code to produce Figure 4.1, the smallest eigenvalue of the discretized Newton potential
0008 % (without the no-preconditioner graph, as it takes very long to compute and should not be used anyway)
0009 % =========================================================================
0010
0011 %   TTeMPS Toolbox.
0012 %   Michael Steinlechner, 2013-2016
0013 %   Questions and contact: michael.steinlechner@epfl.ch
0015
0016 clear all
0017 close all
0018
0019 n = 128;
0020 d = 10;
0021 A = newton_potential( n, d );
0022 p = 1;
0023 r = 1;
0024 maxrank = 40;
0025
0026 % Run standard ALS procedure:
0027 % =========================================================================
0028
0029 if ~exist('newt_1_blk.mat','file')
0030     opts = struct( 'maxiter', 3, ...
0031                    'maxrank', maxrank, ...
0032                    'tol', 1e-8, ...
0033                    'tolOP', 1e-3, ...
0034                    'tolLOBPCG', 1e-6, ...
0035                    'maxiterLOBPCG', 2000, ...
0036                    'verbose', 1 , ...
0037                    'precInner', true);
0038
0039     rng(11)
0040     rr = [1, 8 * ones(1, d-1), 1];
0041     [X_blk, C_blk, evalue_blk, residuums_blk, micro_res_blk, objective_blk, t_blk] = block_eigenvalue( A, p, rr, opts);
0042     save('newt_1_blk', 'X_blk', 'C_blk', 'evalue_blk', 'residuums_blk', 'micro_res_blk', 'objective_blk','t_blk');
0043 else
0045 end
0046
0047 % Run EVAMEn:
0048 % =========================================================================
0049
0050 if ~exist('newt_1_evamen.mat','file')
0051     opts = struct( 'maxiter', 3, ...
0052                    'maxrank', maxrank, ...
0053                    'maxrankRes', 0, ...
0054                    'tol', 1e-8, ...
0055                    'tolOP', 1e-3, ...
0056                    'tolLOBPCG', 1e-6, ...
0057                    'maxiterLOBPCG', 2000, ...
0058                    'verbose', 1 , ...
0059                    'precInner', true);
0060     rng(11)
0061     rr = [1, 1 * ones(1, d-1), 1];
0062     [X_evamen, C_evamen, evalue_evamen, residuums_evamen, micro_res_evamen, objective_evamen, t_evamen] = amen_eigenvalue( A, 1, p, rr, opts);
0063     save('newt_1_evamen', 'X_evamen', 'C_evamen', 'evalue_evamen', 'residuums_evamen', 'micro_res_evamen', 'objective_evamen','t_evamen');
0064 else
0066 end
0067
0068
0069 % Prepare data for plotting:
0070 % =========================================================================
0071
0072 evalue_end = repmat(evalue_blk(:,end), [1,size(evalue_blk,2)-1]);
0073 evalue_end = evalue_blk(end);
0074 ev_blk = abs(evalue_blk(:,1:end-1) - evalue_end);
0075 ev_evamen = abs(evalue_evamen(:,1:end-1) - evalue_end);
0076
0077
0078 % Plot vs. Iterations
0079 % =========================================================================
0080
0081 f = figure
0082 set(0,'defaultlinelinewidth',2)
0083 subplot(1,2,1)
0084 semilogy( sqrt(sum(micro_res_blk.^2, 1)), '-b' )
0085 hold on
0086 semilogy( sqrt(sum(micro_res_evamen.^2, 1)), '-k' )
0087 %
0088 semilogy( sum(ev_blk,1), '--b' )
0089 semilogy( sum(ev_evamen,1), '--k' )
0090
0091 res_blk         = sqrt(sum(micro_res_blk.^2, 1))
0092 res_evamen  = sqrt(sum(micro_res_evamen.^2, 1))
0093 %
0094 semilogy((d-1):(d-1):length(micro_res_blk),res_blk(:,(d-1):(d-1):end),'ob')
0095 semilogy((d-1):(d-1):length(micro_res_evamen),res_evamen(:,(d-1):(d-1):end),'ok')
0096 semilogy((d-1):(d-1):length(ev_blk),sum(ev_blk(:,(d-1):(d-1):end),1),'ob')
0097 semilogy((d-1):(d-1):length(ev_evamen),sum(ev_evamen(:,(d-1):(d-1):end),1),'ok')
0098
0099 h_leg = legend('Res. err., Block-ALS',...
0100        'Res. err. EVAMEn, local prec.',...
0101        'EV. err., Block-ALS',...
0102        'EV. err. EVAMEn, local prec.')
0103
0104 set(gca,'fontsize',16)
0105 set(h_leg, 'fontsize',12)
0106 xlabel('Microiterations')
0107 ylabel('Residual and eigenvalue error')
0108
0109
0110 % Plot vs. Time
0111 % =========================================================================
0112
0113 subplot(1,2,2)
0114 semilogy( t_blk, sqrt(sum(micro_res_blk.^2, 1)), '-b' )
0115 hold on
0116 semilogy( t_evamen, sqrt(sum(micro_res_evamen.^2, 1)), '-k' )
0117
0118 semilogy( t_blk, sum(ev_blk,1), '--b' )
0119 semilogy( t_evamen, sum(ev_evamen,1), '--k' )
0120
0121 semilogy(t_blk((d-1):(d-1):end),res_blk(:,(d-1):(d-1):end),'ob')
0122 semilogy(t_evamen((d-1):(d-1):end),res_evamen(:,(d-1):(d-1):end),'ok')
0123
0124 semilogy(t_blk((d-1):(d-1):end),sum(ev_blk(:,(d-1):(d-1):end),1),'ob')
0125 semilogy(t_evamen((d-1):(d-1):end),sum(ev_evamen(:,(d-1):(d-1):end),1),'ok')
0126
0127 semilogy(t_blk((d-1):(d-1):end),        res_blk(:,(d-1):(d-1):end),'ob')
0128 semilogy(t_evamen((d-1):(d-1):end), res_evamen(:,(d-1):(d-1):end),'ok')
0129
0130 semilogy(t_blk((d-1):(d-1):end),        sum(ev_blk(:,(d-1):(d-1):end),1),'ob')
0131 semilogy(t_evamen((d-1):(d-1):end), sum(ev_evamen(:,(d-1):(d-1):end),1),'ok')
0132
0133 xlim([0,t_blk(end)])
0134 h_leg = legend('Res. err., Block-ALS',...
0135        'Res. err. EVAMEn, local prec.',...
0136        'EV. err., Block-ALS',...
0137        'EV. err. EVAMEn, local prec.')
0138 set(gca,'fontsize',16)
0139 set(h_leg, 'fontsize',12)
0140 xlabel('Time [s]')
0141 ylabel('Residual and eigenvalue error')
0142
0143
0144 set(f, 'Position', [0 0 1200 700])```

Generated on Fri 30-Sep-2022 13:18:25 by m2html © 2005