This is an old revision of the document!

Alan Coelho 2017/08/28 16:43

TOPAS uses the Conjugate Gradient (CG) routine as described at:

`Coelho, A. A. (2005). J. Appl. Cryst. 38, 455-461. "A bound constrained conjugate gradient solution method as applied to crystallographic refinement problems"`

The routine uses min/max limits during the solution to the normal equations. Newton methods such as LU-Decomposition, SVD or Cholsky Decomposition cannot use min/max limits and hence struggle to solve the normal equations due to ill-conditioning. The following are outputs comparing CG with SVD:

```Use of TOPAS Conjugate Gradient routine on PAWLEY1.INP:

TOPAS-32 Version 6 (c) 1992-2017 Alan A. Coelho
Maximum number of threads 8
Time   0.01, INP file pre-processed
Loading xyz's for p-1 from file C:\c\t5\sg\p-1.sg
Number of hkls generated for C:\c\t5\sg\p-1.sg 530
Number of independent parameters : 551
0  Time   0.02  Rwp   92.483    0.000 MC   0.00 0
Sparse matrix methods invoked - 83.0% of the A matrix elements are zero
1  Time   0.03  Rwp   67.173  -25.310 MC   1.00 2
2  Time   0.05  Rwp   37.184  -29.990 MC   1.15 1
3  Time   0.06  Rwp   21.833  -15.351 MC   0.47 1
4  Time   0.07  Rwp   14.298   -7.535 MC   0.16 1
5  Time   0.08  Rwp   10.961   -3.337 MC   0.06 1
6  Time   0.10  Rwp    8.309   -2.653 MC   0.02 1
7  Time   0.11  Rwp    5.847   -2.462 MC   0.00 1
8  Time   0.13  Rwp    4.554   -1.292 MC   0.00 1
9  Time   0.14  Rwp    4.136   -0.418 MC   0.00 1
10  Time   0.16  Rwp    3.966   -0.170 MC   0.00 1
11  Time   0.17  Rwp    3.908   -0.059 MC   0.00 1
12  Time   0.18  Rwp    3.894   -0.014 MC   0.00 1
13  Time   0.19  Rwp    3.891   -0.002 MC   0.00 1
14  Time   0.20  Rwp    3.888   -0.004 MC   0.00 1
15  Time   0.21  Rwp    3.888   -0.000 MC   0.00 1
--- 0.213 seconds ---

*** Parameter(s) close to limit(s).
Check for LIMIT_MIN and LIMIT_MAX in Grid/Text
Errors calculated

File C:\c\t5\test_examples\peak-intensity-extraction\pawley1.out updated
with parameters from last iteration

Process Times (secs)
0.01 = Peak buffer derivatives
0.01 = Ycalc calculation and Penalties
0.10 = A and Y matrix dot products and derivatives
0.06 = Ycalc derivatives
0.04 = A and Y matrix dot products
0.07 = Solution to the normal equations```
```Using Cholsky Decomposition on PAWLEY1.INP:

TOPAS-32 Version 6 (c) 1992-2017 Alan A. Coelho
Maximum number of threads 8
Time   0.02, INP file pre-processed
Loading xyz's for p-1 from file C:\c\t5\sg\p-1.sg
Number of hkls generated for C:\c\t5\sg\p-1.sg 530
Number of independent parameters : 551
0  Time   0.04  Rwp   92.483    0.000 MC   0.00 0
1  Time   0.18  Rwp   61.400  -31.083 MC   1.00 2
2  Time   0.26  Rwp   31.414  -29.986 MC   0.47 1
3  Time   0.33  Rwp   18.986  -12.428 MC   0.16 1
4  Time   0.40  Rwp   16.034   -2.952 MC   0.06 1
5  Time   0.47  Rwp   15.974   -0.060 MC   0.03 1
6  Time   0.54  Rwp   10.716   -5.258 MC   1.60 1
7  Time   0.61  Rwp    8.807   -1.909 MC   0.56 1
8  Time   0.68  Rwp    7.804   -1.003 MC   0.17 1
9  Time   0.74  Rwp    7.694   -0.109 MC   0.05 1
10  Time   0.82  Rwp    6.206   -1.488 MC   1.61 1
11  Time   0.88  Rwp    5.753   -0.453 MC   0.52 1
12  Time   0.99  Rwp    5.414   -0.339 MC   2.50 2
13  Time   1.06  Rwp    5.303   -0.111 MC   0.74 1
14  Time   1.16  Rwp    5.144   -0.159 MC   3.09 2
15  Time   1.23  Rwp    5.097   -0.046 MC   0.89 1
16  Time   1.33  Rwp    4.998   -0.100 MC   3.72 2
17  Time   1.40  Rwp    4.967   -0.030 MC   1.05 1
18  Time   1.51  Rwp    4.900   -0.068 MC   4.15 2
19  Time   1.58  Rwp    4.879   -0.021 MC   1.18 1
20  Time   1.69  Rwp    4.828   -0.050 MC   4.78 2
21  Time   1.76  Rwp    4.811   -0.017 MC   1.35 1
22  Time   1.87  Rwp    4.774   -0.038 MC   5.30 2
23  Time   1.93  Rwp    4.760   -0.014 MC   1.49 1
24  Time   2.03  Rwp    4.730   -0.029 MC   5.80 2
25  Time   2.09  Rwp    4.718   -0.012 MC   1.64 1
26  Time   2.20  Rwp    4.695   -0.023 MC   6.20 2
27  Time   2.26  Rwp    4.685   -0.010 MC   1.76 1
28  Time   2.36  Rwp    4.665   -0.019 MC   6.68 2
29  Time   2.43  Rwp    4.656   -0.009 MC   1.86 1
30  Time   2.52  Rwp    4.639   -0.016 MC   7.02 2
31  Time   2.59  Rwp    4.631   -0.008 MC   1.96 1
32  Time   2.69  Rwp    4.617   -0.014 MC   7.37 2
33  Time   2.75  Rwp    4.609   -0.008 MC   2.08 1
34  Time   2.85  Rwp    4.597   -0.012 MC   7.86 2
35  Time   2.92  Rwp    4.590   -0.007 MC   2.20 1
36  Time   3.03  Rwp    4.580   -0.011 MC   8.18 2
37  Time   3.10  Rwp    4.573   -0.006 MC   2.29 1
38  Time   3.20  Rwp    4.564   -0.009 MC   8.47 2
39  Time   3.26  Rwp    4.558   -0.006 MC   2.38 1
40  Time   3.36  Rwp    4.550   -0.008 MC   8.78 2
41  Time   3.42  Rwp    4.544   -0.006 MC   2.54 1
42  Time   3.52  Rwp    4.537   -0.007 MC   9.03 2
43  Time   3.58  Rwp    4.532   -0.005 MC   2.57 1
44  Time   3.68  Rwp    4.525   -0.007 MC   9.24 2
45  Time   3.75  Rwp    4.520   -0.005 MC   2.58 1
46  Time   3.85  Rwp    4.513   -0.006 MC   9.23 2
47  Time   3.91  Rwp    4.509   -0.005 MC   2.57 1
48  Time   4.01  Rwp    4.502   -0.006 MC   9.06 2
49  Time   4.08  Rwp    4.498   -0.004 MC   2.53 1
50  Time   4.18  Rwp    4.492   -0.006 MC   9.08 2
51  Time   4.24  Rwp    4.488   -0.004 MC   2.51 1
52  Time   4.34  Rwp    4.482   -0.006 MC   8.92 2
53  Time   4.41  Rwp    4.478   -0.004 MC   2.46 1
54  Time   4.50  Rwp    4.473   -0.005 MC   8.92 2
55  Time   4.57  Rwp    4.469   -0.004 MC   2.45 1
56  Time   4.67  Rwp    4.464   -0.005 MC   8.94 2
57  Time   4.73  Rwp    4.460   -0.004 MC   2.46 1
58  Time   4.84  Rwp    4.455   -0.005 MC   8.81 2
59  Time   4.90  Rwp    4.452   -0.003 MC   2.34 1
60  Time   5.00  Rwp    4.446   -0.005 MC   8.74 2
61  Time   5.06  Rwp    4.443   -0.003 MC   2.40 1
62  Time   5.16  Rwp    4.438   -0.005 MC   8.75 2
63  Time   5.22  Rwp    4.435   -0.003 MC   2.39 1
64  Time   5.32  Rwp    4.430   -0.005 MC   8.82 2
65  Time   5.39  Rwp    4.427   -0.003 MC   2.53 1
66  Time   5.49  Rwp    4.423   -0.005 MC   8.48 2
67  Time   5.57  Rwp    4.420   -0.002 MC   2.38 1
68  Time   5.67  Rwp    4.415   -0.005 MC   8.95 2
69  Time   5.73  Rwp    4.413   -0.002 MC   2.38 1
70  Time   5.83  Rwp    4.408   -0.005 MC   9.00 2
71  Time   5.89  Rwp    4.406   -0.002 MC   2.46 1
72  Time   5.99  Rwp    4.401   -0.004 MC   9.36 2
73  Time   6.05  Rwp    4.399   -0.002 MC   2.54 1
74  Time   6.16  Rwp    4.395   -0.004 MC   9.29 2
75  Time   6.22  Rwp    4.393   -0.002 MC   2.55 1
76  Time   6.32  Rwp    4.389   -0.004 MC   9.13 2
77  Time   6.38  Rwp    4.387   -0.002 MC   2.54 1
78  Time   6.48  Rwp    4.383   -0.004 MC   9.21 2
79  Time   6.55  Rwp    4.381   -0.002 MC   2.57 1
80  Time   6.65  Rwp    4.377   -0.004 MC   9.36 2
81  Time   6.72  Rwp    4.375   -0.002 MC   2.65 1
82  Time   6.83  Rwp    4.371   -0.004 MC   9.50 2
83  Time   6.90  Rwp    4.369   -0.002 MC   2.65 1
84  Time   7.00  Rwp    4.366   -0.004 MC   9.63 2
85  Time   7.06  Rwp    4.364   -0.002 MC   2.62 1
86  Time   7.16  Rwp    4.361   -0.003 MC   9.65 2
87  Time   7.22  Rwp    4.359   -0.002 MC   2.63 1
88  Time   7.32  Rwp    4.355   -0.003 MC   9.58 2
89  Time   7.38  Rwp    4.354   -0.002 MC   2.63 1
90  Time   7.48  Rwp    4.350   -0.003 MC   9.55 2
91  Time   7.56  Rwp    4.349   -0.002 MC   2.64 1
92  Time   7.66  Rwp    4.346   -0.003 MC   9.44 2
93  Time   7.74  Rwp    4.344   -0.002 MC   2.65 1
94  Time   7.84  Rwp    4.341   -0.003 MC   9.85 2
95  Time   7.92  Rwp    4.339   -0.001 MC   2.64 1
96  Time   8.02  Rwp    4.336   -0.003 MC  10.16 2
97  Time   8.09  Rwp    4.335   -0.002 MC   2.72 1
98  Time   8.19  Rwp    4.332   -0.003 MC   9.83 2
99  Time   8.25  Rwp    4.330   -0.001 MC   2.70 1
100  Time   8.38  Rwp    4.327   -0.003 MC   9.96 2
101  Time   8.45  Rwp    4.326   -0.002 MC   2.86 1
102  Time   8.56  Rwp    4.323   -0.003 MC   9.99 2
103  Time   8.64  Rwp    4.322   -0.001 MC   2.72 1
104  Time   8.74  Rwp    4.319   -0.003 MC  10.20 2
105  Time   8.81  Rwp    4.317   -0.002 MC   2.91 1
106  Time   8.90  Rwp    4.315   -0.003 MC  10.09 2
107  Time   8.97  Rwp    4.314   -0.001 MC   2.73 1
108  Time   9.07  Rwp    4.311   -0.003 MC  10.33 2
109  Time   9.13  Rwp    4.310   -0.001 MC   2.80 1
110  Time   9.25  Rwp    4.307   -0.003 MC  10.90 2
111  Time   9.31  Rwp    4.306   -0.001 MC   2.71 1
112  Time   9.41  Rwp    4.303   -0.003 MC  11.08 2
113  Time   9.48  Rwp    4.302   -0.001 MC   3.04 1
114  Time   9.58  Rwp    4.299   -0.002 MC  10.32 2
115  Time   9.64  Rwp    4.298   -0.001 MC   2.80 1
116  Time   9.74  Rwp    4.296   -0.002 MC  10.59 2
117  Time   9.80  Rwp    4.295   -0.001 MC   2.90 1
118  Time   9.90  Rwp    4.292   -0.002 MC  10.43 2
119  Time   9.96  Rwp    4.291   -0.001 MC   2.82 1
120  Time  10.06  Rwp    4.289   -0.002 MC  10.48 2
121  Time  10.12  Rwp    4.288   -0.001 MC   2.82 1
122  Time  10.22  Rwp    4.286   -0.002 MC  10.43 2
123  Time  10.29  Rwp    4.285   -0.001 MC   2.79 1
124  Time  10.38  Rwp    4.282   -0.002 MC  10.64 2
125  Time  10.47  Rwp    4.281   -0.001 MC   2.86 1
126  Time  10.57  Rwp    4.279   -0.002 MC  10.38 2
127  Time  10.63  Rwp    4.278   -0.001 MC   2.82 1
--- 10.649 seconds ---

*** Parameter(s) close to limit(s).
Check for LIMIT_MIN and LIMIT_MAX in Grid/Text
Errors calculated

File C:\c\t5\test_examples\peak-intensity-extraction\pawley1.out updated
with parameters from last iteration

Process Times (secs)
0.07 = Peak buffer derivatives
0.20 = Ycalc calculation and Penalties
1.37 = A and Y matrix dot products and derivatives
0.58 = Ycalc derivatives
0.79 = A and Y matrix dot products
6.37 = Solution to the normal equations```
```SVD convergence behavior on PAWLEY1.INP:

0  Time   0.02  Rwp   92.483    0.000 MC   0.00 0
1  Time   2.77  Rwp   61.400  -31.083 MC   1.00 2
2  Time   4.14  Rwp   31.414  -29.986 MC   0.47 1
3  Time   5.50  Rwp   18.986  -12.428 MC   0.16 1
4  Time   6.78  Rwp   16.034   -2.952 MC   0.06 1
5  Time   8.07  Rwp   15.974   -0.060 MC   0.03 1
6  Time   9.48  Rwp   10.716   -5.258 MC   1.60 1
7  Time  10.84  Rwp    8.807   -1.909 MC   0.56 1
8  Time  12.16  Rwp    7.804   -1.003 MC   0.17 1
9  Time  13.46  Rwp    7.694   -0.109 MC   0.05 1
10  Time  14.84  Rwp    6.206   -1.488 MC   1.61 1
11  Time  16.19  Rwp    5.753   -0.453 MC   0.52 1
12  Time  18.93  Rwp    5.414   -0.339 MC   2.50 2
13  Time  20.37  Rwp    5.303   -0.111 MC   0.74 1
14  Time  23.12  Rwp    5.144   -0.159 MC   3.09 2
15  Time  24.54  Rwp    5.097   -0.046 MC   0.89 1
16  Time  27.31  Rwp    4.998   -0.100 MC   3.72 2
17  Time  28.73  Rwp    4.967   -0.030 MC   1.05 1
18  Time  31.48  Rwp    4.900   -0.068 MC   4.15 2
19  Time  32.87  Rwp    4.879   -0.021 MC   1.18 1
20  Time  35.67  Rwp    4.828   -0.050 MC   4.78 2
21  Time  37.10  Rwp    4.811   -0.017 MC   1.35 1
22  Time  39.94  Rwp    4.774   -0.038 MC   5.30 2
23  Time  41.34  Rwp    4.760   -0.014 MC   1.49 1
24  Time  44.12  Rwp    4.730   -0.029 MC   5.80 2
25  Time  45.57  Rwp    4.718   -0.012 MC   1.64 1
26  Time  48.36  Rwp    4.695   -0.023 MC   6.20 2
27  Time  49.82  Rwp    4.685   -0.010 MC   1.76 1
28  Time  52.63  Rwp    4.665   -0.019 MC   6.68 2
29  Time  54.04  Rwp    4.656   -0.009 MC   1.86 1
30  Time  56.93  Rwp    4.639   -0.016 MC   7.02 2
31  Time  58.33  Rwp    4.631   -0.008 MC   1.96 1
32  Time  61.20  Rwp    4.617   -0.014 MC   7.37 2
33  Time  62.63  Rwp    4.609   -0.008 MC   2.08 1
34  Time  65.53  Rwp    4.597   -0.012 MC   7.86 2
35  Time  66.96  Rwp    4.590   -0.007 MC   2.20 1
36  Time  69.81  Rwp    4.580   -0.011 MC   8.18 2
37  Time  71.28  Rwp    4.573   -0.006 MC   2.29 1
38  Time  74.16  Rwp    4.564   -0.009 MC   8.47 2
39  Time  75.58  Rwp    4.558   -0.006 MC   2.38 1
40  Time  78.43  Rwp    4.550   -0.008 MC   8.78 2
41  Time  79.86  Rwp    4.544   -0.006 MC   2.54 1
42  Time  82.68  Rwp    4.537   -0.007 MC   9.03 2
43  Time  84.13  Rwp    4.532   -0.005 MC   2.57 1
44  Time  87.03  Rwp    4.525   -0.007 MC   9.24 2
45  Time  88.46  Rwp    4.520   -0.005 MC   2.58 1
46  Time  91.31  Rwp    4.513   -0.006 MC   9.23 2
47  Time  92.73  Rwp    4.509   -0.005 MC   2.57 1
48  Time  95.57  Rwp    4.502   -0.006 MC   9.06 2
49  Time  97.04  Rwp    4.498   -0.004 MC   2.53 1```

A few points to note:

- Convergence of the CG routine is fast.

- The SVD routine does try and minimize on the residual (A x – b)^2

- The SVD refinement was truncated at 50 iterations to minimize on waiting time.

- On a problem with 551 independent parameters, SVD is 100s of times slower over the whole refinement. Note, the CG routine is threaded.

- The Solution to the normal equations for CG took 0.07s; for LU decomposition its 6.37s.

Using the CG routine without limits

See attached file PAWLEY-CG-NO-INTENSITY-LIMITS.INP

The CG routine in this case is used to solve the normal equations but the limits on the intensity parameter is set to the very large values of -1e40 and 1e40. The macro VV limits the intensity to a positive value after the solution to the normal equations; this is performed using:

`#m_unique i v min = -1e40; max = 1e40; update = Max(Val+Change,0);`

Thus convergence output is as follows:

```TOPAS-32 Version 6 (c) 1992-2017 Alan A. Coelho
Maximum number of threads 8
Time   0.01, INP file pre-processed
Number of independent parameters : 551
0  Time   0.03  Rwp   92.483    0.000 MC   0.00 0
Sparse matrix methods invoked - 83.0% of the A matrix elements are zero
1  Time   0.04  Rwp   37.725  -54.758 MC   0.00 1
2  Time   0.05  Rwp   27.737   -9.988 MC   0.05 1
3  Time   0.07  Rwp   19.533   -8.204 MC   1.27 2
4  Time   0.08  Rwp   14.885   -4.647 MC   0.48 1
5  Time   0.09  Rwp   13.575   -1.311 MC   0.15 1
6  Time   0.10  Rwp   12.636   -0.939 MC   1.63 2
7  Time   0.11  Rwp   12.187   -0.449 MC   0.48 1
8  Time   0.12  Rwp   11.871   -0.316 MC   2.34 2
9  Time   0.13  Rwp   11.660   -0.211 MC   0.66 1
10  Time   0.14  Rwp   11.484   -0.176 MC   2.73 2
11  Time   0.15  Rwp   11.352   -0.132 MC   0.75 1
12  Time   0.16  Rwp   11.228   -0.124 MC   3.00 2
13  Time   0.17  Rwp   11.121   -0.107 MC   0.82 1
14  Time   0.18  Rwp   11.022   -0.099 MC   3.14 2
15  Time   0.19  Rwp   10.915   -0.107 MC   0.85 1
16  Time   0.20  Rwp   10.871   -0.044 MC   0.22 1
17  Time   0.21  Rwp   10.455   -0.416 MC   0.83 1
18  Time   0.21  Rwp   10.133   -0.322 MC   0.22 1
19  Time   0.22  Rwp    9.835   -0.297 MC   0.06 1
20  Time   0.24  Rwp    8.753   -1.082 MC   1.24 2
21  Time   0.24  Rwp    8.026   -0.727 MC   0.38 1
22  Time   0.25  Rwp    7.176   -0.850 MC   0.10 1
23  Time   0.27  Rwp    6.769   -0.407 MC   0.03 1
24  Time   0.27  Rwp    5.443   -1.326 MC   0.28 1
25  Time   0.29  Rwp    5.159   -0.284 MC   0.09 1
26  Time   0.30  Rwp    4.742   -0.417 MC   1.31 2
27  Time   0.31  Rwp    4.645   -0.097 MC   0.39 1
28  Time   0.32  Rwp    4.482   -0.164 MC   2.08 2
29  Time   0.33  Rwp    4.455   -0.027 MC   0.59 1
30  Time   0.34  Rwp    4.362   -0.093 MC   2.71 2
31  Time   0.35  Rwp    4.351   -0.011 MC   0.76 1
32  Time   0.36  Rwp    4.290   -0.061 MC   3.45 2
33  Time   0.36  Rwp    4.282   -0.008 MC   0.96 1
34  Time   0.37  Rwp    4.240   -0.042 MC   3.99 2
35  Time   0.38  Rwp    4.235   -0.005 MC   1.11 1
36  Time   0.39  Rwp    4.205   -0.031 MC   4.71 2
37  Time   0.41  Rwp    4.200   -0.004 MC   1.30 1
38  Time   0.42  Rwp    4.178   -0.023 MC   5.14 2
39  Time   0.42  Rwp    4.175   -0.003 MC   1.40 1
40  Time   0.43  Rwp    4.157   -0.018 MC   5.73 2
41  Time   0.44  Rwp    4.154   -0.003 MC   1.57 1
42  Time   0.45  Rwp    4.139   -0.014 MC   5.86 2
43  Time   0.46  Rwp    4.138   -0.001 MC   1.59 1
44  Time   0.47  Rwp    4.130   -0.009 MC   2.12 1
45  Time   0.47  Rwp    4.118   -0.012 MC   6.46 2
46  Time   0.48  Rwp    4.118   -0.000 MC   1.65 1
--- 0.483 seconds ---

*** Parameter(s) close to limit(s).
Check for LIMIT_MIN and LIMIT_MAX in Grid/Text
File C:\c\t5\test_examples\peak-intensity-extraction\pawley1.out updated
with parameters from last iteration

Process Times (secs)
0.02 = Peak buffer derivatives
0.04 = Ycalc calculation and Penalties
0.22 = A and Y matrix dot products and derivatives
0.15 = Ycalc derivatives
0.07 = A and Y matrix dot products
0.13 = Solution to the normal equations```

As can be seen, not having min/max limits on the intensity parameters leads to slow convergence.

Removing the 'update' attribute by changing the VV macro to:

`          #m_unique i v min = -1e40; max = 1e40; `

results in fast convergence but many of the intensities become negative.