/usr/share/doc/libalglib-dev/manual.cpp.html is in libalglib-dev 3.10.0-1.
This file is owned by root:root, with mode 0o644.
The actual contents of the file can be viewed below.
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
1001
1002
1003
1004
1005
1006
1007
1008
1009
1010
1011
1012
1013
1014
1015
1016
1017
1018
1019
1020
1021
1022
1023
1024
1025
1026
1027
1028
1029
1030
1031
1032
1033
1034
1035
1036
1037
1038
1039
1040
1041
1042
1043
1044
1045
1046
1047
1048
1049
1050
1051
1052
1053
1054
1055
1056
1057
1058
1059
1060
1061
1062
1063
1064
1065
1066
1067
1068
1069
1070
1071
1072
1073
1074
1075
1076
1077
1078
1079
1080
1081
1082
1083
1084
1085
1086
1087
1088
1089
1090
1091
1092
1093
1094
1095
1096
1097
1098
1099
1100
1101
1102
1103
1104
1105
1106
1107
1108
1109
1110
1111
1112
1113
1114
1115
1116
1117
1118
1119
1120
1121
1122
1123
1124
1125
1126
1127
1128
1129
1130
1131
1132
1133
1134
1135
1136
1137
1138
1139
1140
1141
1142
1143
1144
1145
1146
1147
1148
1149
1150
1151
1152
1153
1154
1155
1156
1157
1158
1159
1160
1161
1162
1163
1164
1165
1166
1167
1168
1169
1170
1171
1172
1173
1174
1175
1176
1177
1178
1179
1180
1181
1182
1183
1184
1185
1186
1187
1188
1189
1190
1191
1192
1193
1194
1195
1196
1197
1198
1199
1200
1201
1202
1203
1204
1205
1206
1207
1208
1209
1210
1211
1212
1213
1214
1215
1216
1217
1218
1219
1220
1221
1222
1223
1224
1225
1226
1227
1228
1229
1230
1231
1232
1233
1234
1235
1236
1237
1238
1239
1240
1241
1242
1243
1244
1245
1246
1247
1248
1249
1250
1251
1252
1253
1254
1255
1256
1257
1258
1259
1260
1261
1262
1263
1264
1265
1266
1267
1268
1269
1270
1271
1272
1273
1274
1275
1276
1277
1278
1279
1280
1281
1282
1283
1284
1285
1286
1287
1288
1289
1290
1291
1292
1293
1294
1295
1296
1297
1298
1299
1300
1301
1302
1303
1304
1305
1306
1307
1308
1309
1310
1311
1312
1313
1314
1315
1316
1317
1318
1319
1320
1321
1322
1323
1324
1325
1326
1327
1328
1329
1330
1331
1332
1333
1334
1335
1336
1337
1338
1339
1340
1341
1342
1343
1344
1345
1346
1347
1348
1349
1350
1351
1352
1353
1354
1355
1356
1357
1358
1359
1360
1361
1362
1363
1364
1365
1366
1367
1368
1369
1370
1371
1372
1373
1374
1375
1376
1377
1378
1379
1380
1381
1382
1383
1384
1385
1386
1387
1388
1389
1390
1391
1392
1393
1394
1395
1396
1397
1398
1399
1400
1401
1402
1403
1404
1405
1406
1407
1408
1409
1410
1411
1412
1413
1414
1415
1416
1417
1418
1419
1420
1421
1422
1423
1424
1425
1426
1427
1428
1429
1430
1431
1432
1433
1434
1435
1436
1437
1438
1439
1440
1441
1442
1443
1444
1445
1446
1447
1448
1449
1450
1451
1452
1453
1454
1455
1456
1457
1458
1459
1460
1461
1462
1463
1464
1465
1466
1467
1468
1469
1470
1471
1472
1473
1474
1475
1476
1477
1478
1479
1480
1481
1482
1483
1484
1485
1486
1487
1488
1489
1490
1491
1492
1493
1494
1495
1496
1497
1498
1499
1500
1501
1502
1503
1504
1505
1506
1507
1508
1509
1510
1511
1512
1513
1514
1515
1516
1517
1518
1519
1520
1521
1522
1523
1524
1525
1526
1527
1528
1529
1530
1531
1532
1533
1534
1535
1536
1537
1538
1539
1540
1541
1542
1543
1544
1545
1546
1547
1548
1549
1550
1551
1552
1553
1554
1555
1556
1557
1558
1559
1560
1561
1562
1563
1564
1565
1566
1567
1568
1569
1570
1571
1572
1573
1574
1575
1576
1577
1578
1579
1580
1581
1582
1583
1584
1585
1586
1587
1588
1589
1590
1591
1592
1593
1594
1595
1596
1597
1598
1599
1600
1601
1602
1603
1604
1605
1606
1607
1608
1609
1610
1611
1612
1613
1614
1615
1616
1617
1618
1619
1620
1621
1622
1623
1624
1625
1626
1627
1628
1629
1630
1631
1632
1633
1634
1635
1636
1637
1638
1639
1640
1641
1642
1643
1644
1645
1646
1647
1648
1649
1650
1651
1652
1653
1654
1655
1656
1657
1658
1659
1660
1661
1662
1663
1664
1665
1666
1667
1668
1669
1670
1671
1672
1673
1674
1675
1676
1677
1678
1679
1680
1681
1682
1683
1684
1685
1686
1687
1688
1689
1690
1691
1692
1693
1694
1695
1696
1697
1698
1699
1700
1701
1702
1703
1704
1705
1706
1707
1708
1709
1710
1711
1712
1713
1714
1715
1716
1717
1718
1719
1720
1721
1722
1723
1724
1725
1726
1727
1728
1729
1730
1731
1732
1733
1734
1735
1736
1737
1738
1739
1740
1741
1742
1743
1744
1745
1746
1747
1748
1749
1750
1751
1752
1753
1754
1755
1756
1757
1758
1759
1760
1761
1762
1763
1764
1765
1766
1767
1768
1769
1770
1771
1772
1773
1774
1775
1776
1777
1778
1779
1780
1781
1782
1783
1784
1785
1786
1787
1788
1789
1790
1791
1792
1793
1794
1795
1796
1797
1798
1799
1800
1801
1802
1803
1804
1805
1806
1807
1808
1809
1810
1811
1812
1813
1814
1815
1816
1817
1818
1819
1820
1821
1822
1823
1824
1825
1826
1827
1828
1829
1830
1831
1832
1833
1834
1835
1836
1837
1838
1839
1840
1841
1842
1843
1844
1845
1846
1847
1848
1849
1850
1851
1852
1853
1854
1855
1856
1857
1858
1859
1860
1861
1862
1863
1864
1865
1866
1867
1868
1869
1870
1871
1872
1873
1874
1875
1876
1877
1878
1879
1880
1881
1882
1883
1884
1885
1886
1887
1888
1889
1890
1891
1892
1893
1894
1895
1896
1897
1898
1899
1900
1901
1902
1903
1904
1905
1906
1907
1908
1909
1910
1911
1912
1913
1914
1915
1916
1917
1918
1919
1920
1921
1922
1923
1924
1925
1926
1927
1928
1929
1930
1931
1932
1933
1934
1935
1936
1937
1938
1939
1940
1941
1942
1943
1944
1945
1946
1947
1948
1949
1950
1951
1952
1953
1954
1955
1956
1957
1958
1959
1960
1961
1962
1963
1964
1965
1966
1967
1968
1969
1970
1971
1972
1973
1974
1975
1976
1977
1978
1979
1980
1981
1982
1983
1984
1985
1986
1987
1988
1989
1990
1991
1992
1993
1994
1995
1996
1997
1998
1999
2000
2001
2002
2003
2004
2005
2006
2007
2008
2009
2010
2011
2012
2013
2014
2015
2016
2017
2018
2019
2020
2021
2022
2023
2024
2025
2026
2027
2028
2029
2030
2031
2032
2033
2034
2035
2036
2037
2038
2039
2040
2041
2042
2043
2044
2045
2046
2047
2048
2049
2050
2051
2052
2053
2054
2055
2056
2057
2058
2059
2060
2061
2062
2063
2064
2065
2066
2067
2068
2069
2070
2071
2072
2073
2074
2075
2076
2077
2078
2079
2080
2081
2082
2083
2084
2085
2086
2087
2088
2089
2090
2091
2092
2093
2094
2095
2096
2097
2098
2099
2100
2101
2102
2103
2104
2105
2106
2107
2108
2109
2110
2111
2112
2113
2114
2115
2116
2117
2118
2119
2120
2121
2122
2123
2124
2125
2126
2127
2128
2129
2130
2131
2132
2133
2134
2135
2136
2137
2138
2139
2140
2141
2142
2143
2144
2145
2146
2147
2148
2149
2150
2151
2152
2153
2154
2155
2156
2157
2158
2159
2160
2161
2162
2163
2164
2165
2166
2167
2168
2169
2170
2171
2172
2173
2174
2175
2176
2177
2178
2179
2180
2181
2182
2183
2184
2185
2186
2187
2188
2189
2190
2191
2192
2193
2194
2195
2196
2197
2198
2199
2200
2201
2202
2203
2204
2205
2206
2207
2208
2209
2210
2211
2212
2213
2214
2215
2216
2217
2218
2219
2220
2221
2222
2223
2224
2225
2226
2227
2228
2229
2230
2231
2232
2233
2234
2235
2236
2237
2238
2239
2240
2241
2242
2243
2244
2245
2246
2247
2248
2249
2250
2251
2252
2253
2254
2255
2256
2257
2258
2259
2260
2261
2262
2263
2264
2265
2266
2267
2268
2269
2270
2271
2272
2273
2274
2275
2276
2277
2278
2279
2280
2281
2282
2283
2284
2285
2286
2287
2288
2289
2290
2291
2292
2293
2294
2295
2296
2297
2298
2299
2300
2301
2302
2303
2304
2305
2306
2307
2308
2309
2310
2311
2312
2313
2314
2315
2316
2317
2318
2319
2320
2321
2322
2323
2324
2325
2326
2327
2328
2329
2330
2331
2332
2333
2334
2335
2336
2337
2338
2339
2340
2341
2342
2343
2344
2345
2346
2347
2348
2349
2350
2351
2352
2353
2354
2355
2356
2357
2358
2359
2360
2361
2362
2363
2364
2365
2366
2367
2368
2369
2370
2371
2372
2373
2374
2375
2376
2377
2378
2379
2380
2381
2382
2383
2384
2385
2386
2387
2388
2389
2390
2391
2392
2393
2394
2395
2396
2397
2398
2399
2400
2401
2402
2403
2404
2405
2406
2407
2408
2409
2410
2411
2412
2413
2414
2415
2416
2417
2418
2419
2420
2421
2422
2423
2424
2425
2426
2427
2428
2429
2430
2431
2432
2433
2434
2435
2436
2437
2438
2439
2440
2441
2442
2443
2444
2445
2446
2447
2448
2449
2450
2451
2452
2453
2454
2455
2456
2457
2458
2459
2460
2461
2462
2463
2464
2465
2466
2467
2468
2469
2470
2471
2472
2473
2474
2475
2476
2477
2478
2479
2480
2481
2482
2483
2484
2485
2486
2487
2488
2489
2490
2491
2492
2493
2494
2495
2496
2497
2498
2499
2500
2501
2502
2503
2504
2505
2506
2507
2508
2509
2510
2511
2512
2513
2514
2515
2516
2517
2518
2519
2520
2521
2522
2523
2524
2525
2526
2527
2528
2529
2530
2531
2532
2533
2534
2535
2536
2537
2538
2539
2540
2541
2542
2543
2544
2545
2546
2547
2548
2549
2550
2551
2552
2553
2554
2555
2556
2557
2558
2559
2560
2561
2562
2563
2564
2565
2566
2567
2568
2569
2570
2571
2572
2573
2574
2575
2576
2577
2578
2579
2580
2581
2582
2583
2584
2585
2586
2587
2588
2589
2590
2591
2592
2593
2594
2595
2596
2597
2598
2599
2600
2601
2602
2603
2604
2605
2606
2607
2608
2609
2610
2611
2612
2613
2614
2615
2616
2617
2618
2619
2620
2621
2622
2623
2624
2625
2626
2627
2628
2629
2630
2631
2632
2633
2634
2635
2636
2637
2638
2639
2640
2641
2642
2643
2644
2645
2646
2647
2648
2649
2650
2651
2652
2653
2654
2655
2656
2657
2658
2659
2660
2661
2662
2663
2664
2665
2666
2667
2668
2669
2670
2671
2672
2673
2674
2675
2676
2677
2678
2679
2680
2681
2682
2683
2684
2685
2686
2687
2688
2689
2690
2691
2692
2693
2694
2695
2696
2697
2698
2699
2700
2701
2702
2703
2704
2705
2706
2707
2708
2709
2710
2711
2712
2713
2714
2715
2716
2717
2718
2719
2720
2721
2722
2723
2724
2725
2726
2727
2728
2729
2730
2731
2732
2733
2734
2735
2736
2737
2738
2739
2740
2741
2742
2743
2744
2745
2746
2747
2748
2749
2750
2751
2752
2753
2754
2755
2756
2757
2758
2759
2760
2761
2762
2763
2764
2765
2766
2767
2768
2769
2770
2771
2772
2773
2774
2775
2776
2777
2778
2779
2780
2781
2782
2783
2784
2785
2786
2787
2788
2789
2790
2791
2792
2793
2794
2795
2796
2797
2798
2799
2800
2801
2802
2803
2804
2805
2806
2807
2808
2809
2810
2811
2812
2813
2814
2815
2816
2817
2818
2819
2820
2821
2822
2823
2824
2825
2826
2827
2828
2829
2830
2831
2832
2833
2834
2835
2836
2837
2838
2839
2840
2841
2842
2843
2844
2845
2846
2847
2848
2849
2850
2851
2852
2853
2854
2855
2856
2857
2858
2859
2860
2861
2862
2863
2864
2865
2866
2867
2868
2869
2870
2871
2872
2873
2874
2875
2876
2877
2878
2879
2880
2881
2882
2883
2884
2885
2886
2887
2888
2889
2890
2891
2892
2893
2894
2895
2896
2897
2898
2899
2900
2901
2902
2903
2904
2905
2906
2907
2908
2909
2910
2911
2912
2913
2914
2915
2916
2917
2918
2919
2920
2921
2922
2923
2924
2925
2926
2927
2928
2929
2930
2931
2932
2933
2934
2935
2936
2937
2938
2939
2940
2941
2942
2943
2944
2945
2946
2947
2948
2949
2950
2951
2952
2953
2954
2955
2956
2957
2958
2959
2960
2961
2962
2963
2964
2965
2966
2967
2968
2969
2970
2971
2972
2973
2974
2975
2976
2977
2978
2979
2980
2981
2982
2983
2984
2985
2986
2987
2988
2989
2990
2991
2992
2993
2994
2995
2996
2997
2998
2999
3000
3001
3002
3003
3004
3005
3006
3007
3008
3009
3010
3011
3012
3013
3014
3015
3016
3017
3018
3019
3020
3021
3022
3023
3024
3025
3026
3027
3028
3029
3030
3031
3032
3033
3034
3035
3036
3037
3038
3039
3040
3041
3042
3043
3044
3045
3046
3047
3048
3049
3050
3051
3052
3053
3054
3055
3056
3057
3058
3059
3060
3061
3062
3063
3064
3065
3066
3067
3068
3069
3070
3071
3072
3073
3074
3075
3076
3077
3078
3079
3080
3081
3082
3083
3084
3085
3086
3087
3088
3089
3090
3091
3092
3093
3094
3095
3096
3097
3098
3099
3100
3101
3102
3103
3104
3105
3106
3107
3108
3109
3110
3111
3112
3113
3114
3115
3116
3117
3118
3119
3120
3121
3122
3123
3124
3125
3126
3127
3128
3129
3130
3131
3132
3133
3134
3135
3136
3137
3138
3139
3140
3141
3142
3143
3144
3145
3146
3147
3148
3149
3150
3151
3152
3153
3154
3155
3156
3157
3158
3159
3160
3161
3162
3163
3164
3165
3166
3167
3168
3169
3170
3171
3172
3173
3174
3175
3176
3177
3178
3179
3180
3181
3182
3183
3184
3185
3186
3187
3188
3189
3190
3191
3192
3193
3194
3195
3196
3197
3198
3199
3200
3201
3202
3203
3204
3205
3206
3207
3208
3209
3210
3211
3212
3213
3214
3215
3216
3217
3218
3219
3220
3221
3222
3223
3224
3225
3226
3227
3228
3229
3230
3231
3232
3233
3234
3235
3236
3237
3238
3239
3240
3241
3242
3243
3244
3245
3246
3247
3248
3249
3250
3251
3252
3253
3254
3255
3256
3257
3258
3259
3260
3261
3262
3263
3264
3265
3266
3267
3268
3269
3270
3271
3272
3273
3274
3275
3276
3277
3278
3279
3280
3281
3282
3283
3284
3285
3286
3287
3288
3289
3290
3291
3292
3293
3294
3295
3296
3297
3298
3299
3300
3301
3302
3303
3304
3305
3306
3307
3308
3309
3310
3311
3312
3313
3314
3315
3316
3317
3318
3319
3320
3321
3322
3323
3324
3325
3326
3327
3328
3329
3330
3331
3332
3333
3334
3335
3336
3337
3338
3339
3340
3341
3342
3343
3344
3345
3346
3347
3348
3349
3350
3351
3352
3353
3354
3355
3356
3357
3358
3359
3360
3361
3362
3363
3364
3365
3366
3367
3368
3369
3370
3371
3372
3373
3374
3375
3376
3377
3378
3379
3380
3381
3382
3383
3384
3385
3386
3387
3388
3389
3390
3391
3392
3393
3394
3395
3396
3397
3398
3399
3400
3401
3402
3403
3404
3405
3406
3407
3408
3409
3410
3411
3412
3413
3414
3415
3416
3417
3418
3419
3420
3421
3422
3423
3424
3425
3426
3427
3428
3429
3430
3431
3432
3433
3434
3435
3436
3437
3438
3439
3440
3441
3442
3443
3444
3445
3446
3447
3448
3449
3450
3451
3452
3453
3454
3455
3456
3457
3458
3459
3460
3461
3462
3463
3464
3465
3466
3467
3468
3469
3470
3471
3472
3473
3474
3475
3476
3477
3478
3479
3480
3481
3482
3483
3484
3485
3486
3487
3488
3489
3490
3491
3492
3493
3494
3495
3496
3497
3498
3499
3500
3501
3502
3503
3504
3505
3506
3507
3508
3509
3510
3511
3512
3513
3514
3515
3516
3517
3518
3519
3520
3521
3522
3523
3524
3525
3526
3527
3528
3529
3530
3531
3532
3533
3534
3535
3536
3537
3538
3539
3540
3541
3542
3543
3544
3545
3546
3547
3548
3549
3550
3551
3552
3553
3554
3555
3556
3557
3558
3559
3560
3561
3562
3563
3564
3565
3566
3567
3568
3569
3570
3571
3572
3573
3574
3575
3576
3577
3578
3579
3580
3581
3582
3583
3584
3585
3586
3587
3588
3589
3590
3591
3592
3593
3594
3595
3596
3597
3598
3599
3600
3601
3602
3603
3604
3605
3606
3607
3608
3609
3610
3611
3612
3613
3614
3615
3616
3617
3618
3619
3620
3621
3622
3623
3624
3625
3626
3627
3628
3629
3630
3631
3632
3633
3634
3635
3636
3637
3638
3639
3640
3641
3642
3643
3644
3645
3646
3647
3648
3649
3650
3651
3652
3653
3654
3655
3656
3657
3658
3659
3660
3661
3662
3663
3664
3665
3666
3667
3668
3669
3670
3671
3672
3673
3674
3675
3676
3677
3678
3679
3680
3681
3682
3683
3684
3685
3686
3687
3688
3689
3690
3691
3692
3693
3694
3695
3696
3697
3698
3699
3700
3701
3702
3703
3704
3705
3706
3707
3708
3709
3710
3711
3712
3713
3714
3715
3716
3717
3718
3719
3720
3721
3722
3723
3724
3725
3726
3727
3728
3729
3730
3731
3732
3733
3734
3735
3736
3737
3738
3739
3740
3741
3742
3743
3744
3745
3746
3747
3748
3749
3750
3751
3752
3753
3754
3755
3756
3757
3758
3759
3760
3761
3762
3763
3764
3765
3766
3767
3768
3769
3770
3771
3772
3773
3774
3775
3776
3777
3778
3779
3780
3781
3782
3783
3784
3785
3786
3787
3788
3789
3790
3791
3792
3793
3794
3795
3796
3797
3798
3799
3800
3801
3802
3803
3804
3805
3806
3807
3808
3809
3810
3811
3812
3813
3814
3815
3816
3817
3818
3819
3820
3821
3822
3823
3824
3825
3826
3827
3828
3829
3830
3831
3832
3833
3834
3835
3836
3837
3838
3839
3840
3841
3842
3843
3844
3845
3846
3847
3848
3849
3850
3851
3852
3853
3854
3855
3856
3857
3858
3859
3860
3861
3862
3863
3864
3865
3866
3867
3868
3869
3870
3871
3872
3873
3874
3875
3876
3877
3878
3879
3880
3881
3882
3883
3884
3885
3886
3887
3888
3889
3890
3891
3892
3893
3894
3895
3896
3897
3898
3899
3900
3901
3902
3903
3904
3905
3906
3907
3908
3909
3910
3911
3912
3913
3914
3915
3916
3917
3918
3919
3920
3921
3922
3923
3924
3925
3926
3927
3928
3929
3930
3931
3932
3933
3934
3935
3936
3937
3938
3939
3940
3941
3942
3943
3944
3945
3946
3947
3948
3949
3950
3951
3952
3953
3954
3955
3956
3957
3958
3959
3960
3961
3962
3963
3964
3965
3966
3967
3968
3969
3970
3971
3972
3973
3974
3975
3976
3977
3978
3979
3980
3981
3982
3983
3984
3985
3986
3987
3988
3989
3990
3991
3992
3993
3994
3995
3996
3997
3998
3999
4000
4001
4002
4003
4004
4005
4006
4007
4008
4009
4010
4011
4012
4013
4014
4015
4016
4017
4018
4019
4020
4021
4022
4023
4024
4025
4026
4027
4028
4029
4030
4031
4032
4033
4034
4035
4036
4037
4038
4039
4040
4041
4042
4043
4044
4045
4046
4047
4048
4049
4050
4051
4052
4053
4054
4055
4056
4057
4058
4059
4060
4061
4062
4063
4064
4065
4066
4067
4068
4069
4070
4071
4072
4073
4074
4075
4076
4077
4078
4079
4080
4081
4082
4083
4084
4085
4086
4087
4088
4089
4090
4091
4092
4093
4094
4095
4096
4097
4098
4099
4100
4101
4102
4103
4104
4105
4106
4107
4108
4109
4110
4111
4112
4113
4114
4115
4116
4117
4118
4119
4120
4121
4122
4123
4124
4125
4126
4127
4128
4129
4130
4131
4132
4133
4134
4135
4136
4137
4138
4139
4140
4141
4142
4143
4144
4145
4146
4147
4148
4149
4150
4151
4152
4153
4154
4155
4156
4157
4158
4159
4160
4161
4162
4163
4164
4165
4166
4167
4168
4169
4170
4171
4172
4173
4174
4175
4176
4177
4178
4179
4180
4181
4182
4183
4184
4185
4186
4187
4188
4189
4190
4191
4192
4193
4194
4195
4196
4197
4198
4199
4200
4201
4202
4203
4204
4205
4206
4207
4208
4209
4210
4211
4212
4213
4214
4215
4216
4217
4218
4219
4220
4221
4222
4223
4224
4225
4226
4227
4228
4229
4230
4231
4232
4233
4234
4235
4236
4237
4238
4239
4240
4241
4242
4243
4244
4245
4246
4247
4248
4249
4250
4251
4252
4253
4254
4255
4256
4257
4258
4259
4260
4261
4262
4263
4264
4265
4266
4267
4268
4269
4270
4271
4272
4273
4274
4275
4276
4277
4278
4279
4280
4281
4282
4283
4284
4285
4286
4287
4288
4289
4290
4291
4292
4293
4294
4295
4296
4297
4298
4299
4300
4301
4302
4303
4304
4305
4306
4307
4308
4309
4310
4311
4312
4313
4314
4315
4316
4317
4318
4319
4320
4321
4322
4323
4324
4325
4326
4327
4328
4329
4330
4331
4332
4333
4334
4335
4336
4337
4338
4339
4340
4341
4342
4343
4344
4345
4346
4347
4348
4349
4350
4351
4352
4353
4354
4355
4356
4357
4358
4359
4360
4361
4362
4363
4364
4365
4366
4367
4368
4369
4370
4371
4372
4373
4374
4375
4376
4377
4378
4379
4380
4381
4382
4383
4384
4385
4386
4387
4388
4389
4390
4391
4392
4393
4394
4395
4396
4397
4398
4399
4400
4401
4402
4403
4404
4405
4406
4407
4408
4409
4410
4411
4412
4413
4414
4415
4416
4417
4418
4419
4420
4421
4422
4423
4424
4425
4426
4427
4428
4429
4430
4431
4432
4433
4434
4435
4436
4437
4438
4439
4440
4441
4442
4443
4444
4445
4446
4447
4448
4449
4450
4451
4452
4453
4454
4455
4456
4457
4458
4459
4460
4461
4462
4463
4464
4465
4466
4467
4468
4469
4470
4471
4472
4473
4474
4475
4476
4477
4478
4479
4480
4481
4482
4483
4484
4485
4486
4487
4488
4489
4490
4491
4492
4493
4494
4495
4496
4497
4498
4499
4500
4501
4502
4503
4504
4505
4506
4507
4508
4509
4510
4511
4512
4513
4514
4515
4516
4517
4518
4519
4520
4521
4522
4523
4524
4525
4526
4527
4528
4529
4530
4531
4532
4533
4534
4535
4536
4537
4538
4539
4540
4541
4542
4543
4544
4545
4546
4547
4548
4549
4550
4551
4552
4553
4554
4555
4556
4557
4558
4559
4560
4561
4562
4563
4564
4565
4566
4567
4568
4569
4570
4571
4572
4573
4574
4575
4576
4577
4578
4579
4580
4581
4582
4583
4584
4585
4586
4587
4588
4589
4590
4591
4592
4593
4594
4595
4596
4597
4598
4599
4600
4601
4602
4603
4604
4605
4606
4607
4608
4609
4610
4611
4612
4613
4614
4615
4616
4617
4618
4619
4620
4621
4622
4623
4624
4625
4626
4627
4628
4629
4630
4631
4632
4633
4634
4635
4636
4637
4638
4639
4640
4641
4642
4643
4644
4645
4646
4647
4648
4649
4650
4651
4652
4653
4654
4655
4656
4657
4658
4659
4660
4661
4662
4663
4664
4665
4666
4667
4668
4669
4670
4671
4672
4673
4674
4675
4676
4677
4678
4679
4680
4681
4682
4683
4684
4685
4686
4687
4688
4689
4690
4691
4692
4693
4694
4695
4696
4697
4698
4699
4700
4701
4702
4703
4704
4705
4706
4707
4708
4709
4710
4711
4712
4713
4714
4715
4716
4717
4718
4719
4720
4721
4722
4723
4724
4725
4726
4727
4728
4729
4730
4731
4732
4733
4734
4735
4736
4737
4738
4739
4740
4741
4742
4743
4744
4745
4746
4747
4748
4749
4750
4751
4752
4753
4754
4755
4756
4757
4758
4759
4760
4761
4762
4763
4764
4765
4766
4767
4768
4769
4770
4771
4772
4773
4774
4775
4776
4777
4778
4779
4780
4781
4782
4783
4784
4785
4786
4787
4788
4789
4790
4791
4792
4793
4794
4795
4796
4797
4798
4799
4800
4801
4802
4803
4804
4805
4806
4807
4808
4809
4810
4811
4812
4813
4814
4815
4816
4817
4818
4819
4820
4821
4822
4823
4824
4825
4826
4827
4828
4829
4830
4831
4832
4833
4834
4835
4836
4837
4838
4839
4840
4841
4842
4843
4844
4845
4846
4847
4848
4849
4850
4851
4852
4853
4854
4855
4856
4857
4858
4859
4860
4861
4862
4863
4864
4865
4866
4867
4868
4869
4870
4871
4872
4873
4874
4875
4876
4877
4878
4879
4880
4881
4882
4883
4884
4885
4886
4887
4888
4889
4890
4891
4892
4893
4894
4895
4896
4897
4898
4899
4900
4901
4902
4903
4904
4905
4906
4907
4908
4909
4910
4911
4912
4913
4914
4915
4916
4917
4918
4919
4920
4921
4922
4923
4924
4925
4926
4927
4928
4929
4930
4931
4932
4933
4934
4935
4936
4937
4938
4939
4940
4941
4942
4943
4944
4945
4946
4947
4948
4949
4950
4951
4952
4953
4954
4955
4956
4957
4958
4959
4960
4961
4962
4963
4964
4965
4966
4967
4968
4969
4970
4971
4972
4973
4974
4975
4976
4977
4978
4979
4980
4981
4982
4983
4984
4985
4986
4987
4988
4989
4990
4991
4992
4993
4994
4995
4996
4997
4998
4999
5000
5001
5002
5003
5004
5005
5006
5007
5008
5009
5010
5011
5012
5013
5014
5015
5016
5017
5018
5019
5020
5021
5022
5023
5024
5025
5026
5027
5028
5029
5030
5031
5032
5033
5034
5035
5036
5037
5038
5039
5040
5041
5042
5043
5044
5045
5046
5047
5048
5049
5050
5051
5052
5053
5054
5055
5056
5057
5058
5059
5060
5061
5062
5063
5064
5065
5066
5067
5068
5069
5070
5071
5072
5073
5074
5075
5076
5077
5078
5079
5080
5081
5082
5083
5084
5085
5086
5087
5088
5089
5090
5091
5092
5093
5094
5095
5096
5097
5098
5099
5100
5101
5102
5103
5104
5105
5106
5107
5108
5109
5110
5111
5112
5113
5114
5115
5116
5117
5118
5119
5120
5121
5122
5123
5124
5125
5126
5127
5128
5129
5130
5131
5132
5133
5134
5135
5136
5137
5138
5139
5140
5141
5142
5143
5144
5145
5146
5147
5148
5149
5150
5151
5152
5153
5154
5155
5156
5157
5158
5159
5160
5161
5162
5163
5164
5165
5166
5167
5168
5169
5170
5171
5172
5173
5174
5175
5176
5177
5178
5179
5180
5181
5182
5183
5184
5185
5186
5187
5188
5189
5190
5191
5192
5193
5194
5195
5196
5197
5198
5199
5200
5201
5202
5203
5204
5205
5206
5207
5208
5209
5210
5211
5212
5213
5214
5215
5216
5217
5218
5219
5220
5221
5222
5223
5224
5225
5226
5227
5228
5229
5230
5231
5232
5233
5234
5235
5236
5237
5238
5239
5240
5241
5242
5243
5244
5245
5246
5247
5248
5249
5250
5251
5252
5253
5254
5255
5256
5257
5258
5259
5260
5261
5262
5263
5264
5265
5266
5267
5268
5269
5270
5271
5272
5273
5274
5275
5276
5277
5278
5279
5280
5281
5282
5283
5284
5285
5286
5287
5288
5289
5290
5291
5292
5293
5294
5295
5296
5297
5298
5299
5300
5301
5302
5303
5304
5305
5306
5307
5308
5309
5310
5311
5312
5313
5314
5315
5316
5317
5318
5319
5320
5321
5322
5323
5324
5325
5326
5327
5328
5329
5330
5331
5332
5333
5334
5335
5336
5337
5338
5339
5340
5341
5342
5343
5344
5345
5346
5347
5348
5349
5350
5351
5352
5353
5354
5355
5356
5357
5358
5359
5360
5361
5362
5363
5364
5365
5366
5367
5368
5369
5370
5371
5372
5373
5374
5375
5376
5377
5378
5379
5380
5381
5382
5383
5384
5385
5386
5387
5388
5389
5390
5391
5392
5393
5394
5395
5396
5397
5398
5399
5400
5401
5402
5403
5404
5405
5406
5407
5408
5409
5410
5411
5412
5413
5414
5415
5416
5417
5418
5419
5420
5421
5422
5423
5424
5425
5426
5427
5428
5429
5430
5431
5432
5433
5434
5435
5436
5437
5438
5439
5440
5441
5442
5443
5444
5445
5446
5447
5448
5449
5450
5451
5452
5453
5454
5455
5456
5457
5458
5459
5460
5461
5462
5463
5464
5465
5466
5467
5468
5469
5470
5471
5472
5473
5474
5475
5476
5477
5478
5479
5480
5481
5482
5483
5484
5485
5486
5487
5488
5489
5490
5491
5492
5493
5494
5495
5496
5497
5498
5499
5500
5501
5502
5503
5504
5505
5506
5507
5508
5509
5510
5511
5512
5513
5514
5515
5516
5517
5518
5519
5520
5521
5522
5523
5524
5525
5526
5527
5528
5529
5530
5531
5532
5533
5534
5535
5536
5537
5538
5539
5540
5541
5542
5543
5544
5545
5546
5547
5548
5549
5550
5551
5552
5553
5554
5555
5556
5557
5558
5559
5560
5561
5562
5563
5564
5565
5566
5567
5568
5569
5570
5571
5572
5573
5574
5575
5576
5577
5578
5579
5580
5581
5582
5583
5584
5585
5586
5587
5588
5589
5590
5591
5592
5593
5594
5595
5596
5597
5598
5599
5600
5601
5602
5603
5604
5605
5606
5607
5608
5609
5610
5611
5612
5613
5614
5615
5616
5617
5618
5619
5620
5621
5622
5623
5624
5625
5626
5627
5628
5629
5630
5631
5632
5633
5634
5635
5636
5637
5638
5639
5640
5641
5642
5643
5644
5645
5646
5647
5648
5649
5650
5651
5652
5653
5654
5655
5656
5657
5658
5659
5660
5661
5662
5663
5664
5665
5666
5667
5668
5669
5670
5671
5672
5673
5674
5675
5676
5677
5678
5679
5680
5681
5682
5683
5684
5685
5686
5687
5688
5689
5690
5691
5692
5693
5694
5695
5696
5697
5698
5699
5700
5701
5702
5703
5704
5705
5706
5707
5708
5709
5710
5711
5712
5713
5714
5715
5716
5717
5718
5719
5720
5721
5722
5723
5724
5725
5726
5727
5728
5729
5730
5731
5732
5733
5734
5735
5736
5737
5738
5739
5740
5741
5742
5743
5744
5745
5746
5747
5748
5749
5750
5751
5752
5753
5754
5755
5756
5757
5758
5759
5760
5761
5762
5763
5764
5765
5766
5767
5768
5769
5770
5771
5772
5773
5774
5775
5776
5777
5778
5779
5780
5781
5782
5783
5784
5785
5786
5787
5788
5789
5790
5791
5792
5793
5794
5795
5796
5797
5798
5799
5800
5801
5802
5803
5804
5805
5806
5807
5808
5809
5810
5811
5812
5813
5814
5815
5816
5817
5818
5819
5820
5821
5822
5823
5824
5825
5826
5827
5828
5829
5830
5831
5832
5833
5834
5835
5836
5837
5838
5839
5840
5841
5842
5843
5844
5845
5846
5847
5848
5849
5850
5851
5852
5853
5854
5855
5856
5857
5858
5859
5860
5861
5862
5863
5864
5865
5866
5867
5868
5869
5870
5871
5872
5873
5874
5875
5876
5877
5878
5879
5880
5881
5882
5883
5884
5885
5886
5887
5888
5889
5890
5891
5892
5893
5894
5895
5896
5897
5898
5899
5900
5901
5902
5903
5904
5905
5906
5907
5908
5909
5910
5911
5912
5913
5914
5915
5916
5917
5918
5919
5920
5921
5922
5923
5924
5925
5926
5927
5928
5929
5930
5931
5932
5933
5934
5935
5936
5937
5938
5939
5940
5941
5942
5943
5944
5945
5946
5947
5948
5949
5950
5951
5952
5953
5954
5955
5956
5957
5958
5959
5960
5961
5962
5963
5964
5965
5966
5967
5968
5969
5970
5971
5972
5973
5974
5975
5976
5977
5978
5979
5980
5981
5982
5983
5984
5985
5986
5987
5988
5989
5990
5991
5992
5993
5994
5995
5996
5997
5998
5999
6000
6001
6002
6003
6004
6005
6006
6007
6008
6009
6010
6011
6012
6013
6014
6015
6016
6017
6018
6019
6020
6021
6022
6023
6024
6025
6026
6027
6028
6029
6030
6031
6032
6033
6034
6035
6036
6037
6038
6039
6040
6041
6042
6043
6044
6045
6046
6047
6048
6049
6050
6051
6052
6053
6054
6055
6056
6057
6058
6059
6060
6061
6062
6063
6064
6065
6066
6067
6068
6069
6070
6071
6072
6073
6074
6075
6076
6077
6078
6079
6080
6081
6082
6083
6084
6085
6086
6087
6088
6089
6090
6091
6092
6093
6094
6095
6096
6097
6098
6099
6100
6101
6102
6103
6104
6105
6106
6107
6108
6109
6110
6111
6112
6113
6114
6115
6116
6117
6118
6119
6120
6121
6122
6123
6124
6125
6126
6127
6128
6129
6130
6131
6132
6133
6134
6135
6136
6137
6138
6139
6140
6141
6142
6143
6144
6145
6146
6147
6148
6149
6150
6151
6152
6153
6154
6155
6156
6157
6158
6159
6160
6161
6162
6163
6164
6165
6166
6167
6168
6169
6170
6171
6172
6173
6174
6175
6176
6177
6178
6179
6180
6181
6182
6183
6184
6185
6186
6187
6188
6189
6190
6191
6192
6193
6194
6195
6196
6197
6198
6199
6200
6201
6202
6203
6204
6205
6206
6207
6208
6209
6210
6211
6212
6213
6214
6215
6216
6217
6218
6219
6220
6221
6222
6223
6224
6225
6226
6227
6228
6229
6230
6231
6232
6233
6234
6235
6236
6237
6238
6239
6240
6241
6242
6243
6244
6245
6246
6247
6248
6249
6250
6251
6252
6253
6254
6255
6256
6257
6258
6259
6260
6261
6262
6263
6264
6265
6266
6267
6268
6269
6270
6271
6272
6273
6274
6275
6276
6277
6278
6279
6280
6281
6282
6283
6284
6285
6286
6287
6288
6289
6290
6291
6292
6293
6294
6295
6296
6297
6298
6299
6300
6301
6302
6303
6304
6305
6306
6307
6308
6309
6310
6311
6312
6313
6314
6315
6316
6317
6318
6319
6320
6321
6322
6323
6324
6325
6326
6327
6328
6329
6330
6331
6332
6333
6334
6335
6336
6337
6338
6339
6340
6341
6342
6343
6344
6345
6346
6347
6348
6349
6350
6351
6352
6353
6354
6355
6356
6357
6358
6359
6360
6361
6362
6363
6364
6365
6366
6367
6368
6369
6370
6371
6372
6373
6374
6375
6376
6377
6378
6379
6380
6381
6382
6383
6384
6385
6386
6387
6388
6389
6390
6391
6392
6393
6394
6395
6396
6397
6398
6399
6400
6401
6402
6403
6404
6405
6406
6407
6408
6409
6410
6411
6412
6413
6414
6415
6416
6417
6418
6419
6420
6421
6422
6423
6424
6425
6426
6427
6428
6429
6430
6431
6432
6433
6434
6435
6436
6437
6438
6439
6440
6441
6442
6443
6444
6445
6446
6447
6448
6449
6450
6451
6452
6453
6454
6455
6456
6457
6458
6459
6460
6461
6462
6463
6464
6465
6466
6467
6468
6469
6470
6471
6472
6473
6474
6475
6476
6477
6478
6479
6480
6481
6482
6483
6484
6485
6486
6487
6488
6489
6490
6491
6492
6493
6494
6495
6496
6497
6498
6499
6500
6501
6502
6503
6504
6505
6506
6507
6508
6509
6510
6511
6512
6513
6514
6515
6516
6517
6518
6519
6520
6521
6522
6523
6524
6525
6526
6527
6528
6529
6530
6531
6532
6533
6534
6535
6536
6537
6538
6539
6540
6541
6542
6543
6544
6545
6546
6547
6548
6549
6550
6551
6552
6553
6554
6555
6556
6557
6558
6559
6560
6561
6562
6563
6564
6565
6566
6567
6568
6569
6570
6571
6572
6573
6574
6575
6576
6577
6578
6579
6580
6581
6582
6583
6584
6585
6586
6587
6588
6589
6590
6591
6592
6593
6594
6595
6596
6597
6598
6599
6600
6601
6602
6603
6604
6605
6606
6607
6608
6609
6610
6611
6612
6613
6614
6615
6616
6617
6618
6619
6620
6621
6622
6623
6624
6625
6626
6627
6628
6629
6630
6631
6632
6633
6634
6635
6636
6637
6638
6639
6640
6641
6642
6643
6644
6645
6646
6647
6648
6649
6650
6651
6652
6653
6654
6655
6656
6657
6658
6659
6660
6661
6662
6663
6664
6665
6666
6667
6668
6669
6670
6671
6672
6673
6674
6675
6676
6677
6678
6679
6680
6681
6682
6683
6684
6685
6686
6687
6688
6689
6690
6691
6692
6693
6694
6695
6696
6697
6698
6699
6700
6701
6702
6703
6704
6705
6706
6707
6708
6709
6710
6711
6712
6713
6714
6715
6716
6717
6718
6719
6720
6721
6722
6723
6724
6725
6726
6727
6728
6729
6730
6731
6732
6733
6734
6735
6736
6737
6738
6739
6740
6741
6742
6743
6744
6745
6746
6747
6748
6749
6750
6751
6752
6753
6754
6755
6756
6757
6758
6759
6760
6761
6762
6763
6764
6765
6766
6767
6768
6769
6770
6771
6772
6773
6774
6775
6776
6777
6778
6779
6780
6781
6782
6783
6784
6785
6786
6787
6788
6789
6790
6791
6792
6793
6794
6795
6796
6797
6798
6799
6800
6801
6802
6803
6804
6805
6806
6807
6808
6809
6810
6811
6812
6813
6814
6815
6816
6817
6818
6819
6820
6821
6822
6823
6824
6825
6826
6827
6828
6829
6830
6831
6832
6833
6834
6835
6836
6837
6838
6839
6840
6841
6842
6843
6844
6845
6846
6847
6848
6849
6850
6851
6852
6853
6854
6855
6856
6857
6858
6859
6860
6861
6862
6863
6864
6865
6866
6867
6868
6869
6870
6871
6872
6873
6874
6875
6876
6877
6878
6879
6880
6881
6882
6883
6884
6885
6886
6887
6888
6889
6890
6891
6892
6893
6894
6895
6896
6897
6898
6899
6900
6901
6902
6903
6904
6905
6906
6907
6908
6909
6910
6911
6912
6913
6914
6915
6916
6917
6918
6919
6920
6921
6922
6923
6924
6925
6926
6927
6928
6929
6930
6931
6932
6933
6934
6935
6936
6937
6938
6939
6940
6941
6942
6943
6944
6945
6946
6947
6948
6949
6950
6951
6952
6953
6954
6955
6956
6957
6958
6959
6960
6961
6962
6963
6964
6965
6966
6967
6968
6969
6970
6971
6972
6973
6974
6975
6976
6977
6978
6979
6980
6981
6982
6983
6984
6985
6986
6987
6988
6989
6990
6991
6992
6993
6994
6995
6996
6997
6998
6999
7000
7001
7002
7003
7004
7005
7006
7007
7008
7009
7010
7011
7012
7013
7014
7015
7016
7017
7018
7019
7020
7021
7022
7023
7024
7025
7026
7027
7028
7029
7030
7031
7032
7033
7034
7035
7036
7037
7038
7039
7040
7041
7042
7043
7044
7045
7046
7047
7048
7049
7050
7051
7052
7053
7054
7055
7056
7057
7058
7059
7060
7061
7062
7063
7064
7065
7066
7067
7068
7069
7070
7071
7072
7073
7074
7075
7076
7077
7078
7079
7080
7081
7082
7083
7084
7085
7086
7087
7088
7089
7090
7091
7092
7093
7094
7095
7096
7097
7098
7099
7100
7101
7102
7103
7104
7105
7106
7107
7108
7109
7110
7111
7112
7113
7114
7115
7116
7117
7118
7119
7120
7121
7122
7123
7124
7125
7126
7127
7128
7129
7130
7131
7132
7133
7134
7135
7136
7137
7138
7139
7140
7141
7142
7143
7144
7145
7146
7147
7148
7149
7150
7151
7152
7153
7154
7155
7156
7157
7158
7159
7160
7161
7162
7163
7164
7165
7166
7167
7168
7169
7170
7171
7172
7173
7174
7175
7176
7177
7178
7179
7180
7181
7182
7183
7184
7185
7186
7187
7188
7189
7190
7191
7192
7193
7194
7195
7196
7197
7198
7199
7200
7201
7202
7203
7204
7205
7206
7207
7208
7209
7210
7211
7212
7213
7214
7215
7216
7217
7218
7219
7220
7221
7222
7223
7224
7225
7226
7227
7228
7229
7230
7231
7232
7233
7234
7235
7236
7237
7238
7239
7240
7241
7242
7243
7244
7245
7246
7247
7248
7249
7250
7251
7252
7253
7254
7255
7256
7257
7258
7259
7260
7261
7262
7263
7264
7265
7266
7267
7268
7269
7270
7271
7272
7273
7274
7275
7276
7277
7278
7279
7280
7281
7282
7283
7284
7285
7286
7287
7288
7289
7290
7291
7292
7293
7294
7295
7296
7297
7298
7299
7300
7301
7302
7303
7304
7305
7306
7307
7308
7309
7310
7311
7312
7313
7314
7315
7316
7317
7318
7319
7320
7321
7322
7323
7324
7325
7326
7327
7328
7329
7330
7331
7332
7333
7334
7335
7336
7337
7338
7339
7340
7341
7342
7343
7344
7345
7346
7347
7348
7349
7350
7351
7352
7353
7354
7355
7356
7357
7358
7359
7360
7361
7362
7363
7364
7365
7366
7367
7368
7369
7370
7371
7372
7373
7374
7375
7376
7377
7378
7379
7380
7381
7382
7383
7384
7385
7386
7387
7388
7389
7390
7391
7392
7393
7394
7395
7396
7397
7398
7399
7400
7401
7402
7403
7404
7405
7406
7407
7408
7409
7410
7411
7412
7413
7414
7415
7416
7417
7418
7419
7420
7421
7422
7423
7424
7425
7426
7427
7428
7429
7430
7431
7432
7433
7434
7435
7436
7437
7438
7439
7440
7441
7442
7443
7444
7445
7446
7447
7448
7449
7450
7451
7452
7453
7454
7455
7456
7457
7458
7459
7460
7461
7462
7463
7464
7465
7466
7467
7468
7469
7470
7471
7472
7473
7474
7475
7476
7477
7478
7479
7480
7481
7482
7483
7484
7485
7486
7487
7488
7489
7490
7491
7492
7493
7494
7495
7496
7497
7498
7499
7500
7501
7502
7503
7504
7505
7506
7507
7508
7509
7510
7511
7512
7513
7514
7515
7516
7517
7518
7519
7520
7521
7522
7523
7524
7525
7526
7527
7528
7529
7530
7531
7532
7533
7534
7535
7536
7537
7538
7539
7540
7541
7542
7543
7544
7545
7546
7547
7548
7549
7550
7551
7552
7553
7554
7555
7556
7557
7558
7559
7560
7561
7562
7563
7564
7565
7566
7567
7568
7569
7570
7571
7572
7573
7574
7575
7576
7577
7578
7579
7580
7581
7582
7583
7584
7585
7586
7587
7588
7589
7590
7591
7592
7593
7594
7595
7596
7597
7598
7599
7600
7601
7602
7603
7604
7605
7606
7607
7608
7609
7610
7611
7612
7613
7614
7615
7616
7617
7618
7619
7620
7621
7622
7623
7624
7625
7626
7627
7628
7629
7630
7631
7632
7633
7634
7635
7636
7637
7638
7639
7640
7641
7642
7643
7644
7645
7646
7647
7648
7649
7650
7651
7652
7653
7654
7655
7656
7657
7658
7659
7660
7661
7662
7663
7664
7665
7666
7667
7668
7669
7670
7671
7672
7673
7674
7675
7676
7677
7678
7679
7680
7681
7682
7683
7684
7685
7686
7687
7688
7689
7690
7691
7692
7693
7694
7695
7696
7697
7698
7699
7700
7701
7702
7703
7704
7705
7706
7707
7708
7709
7710
7711
7712
7713
7714
7715
7716
7717
7718
7719
7720
7721
7722
7723
7724
7725
7726
7727
7728
7729
7730
7731
7732
7733
7734
7735
7736
7737
7738
7739
7740
7741
7742
7743
7744
7745
7746
7747
7748
7749
7750
7751
7752
7753
7754
7755
7756
7757
7758
7759
7760
7761
7762
7763
7764
7765
7766
7767
7768
7769
7770
7771
7772
7773
7774
7775
7776
7777
7778
7779
7780
7781
7782
7783
7784
7785
7786
7787
7788
7789
7790
7791
7792
7793
7794
7795
7796
7797
7798
7799
7800
7801
7802
7803
7804
7805
7806
7807
7808
7809
7810
7811
7812
7813
7814
7815
7816
7817
7818
7819
7820
7821
7822
7823
7824
7825
7826
7827
7828
7829
7830
7831
7832
7833
7834
7835
7836
7837
7838
7839
7840
7841
7842
7843
7844
7845
7846
7847
7848
7849
7850
7851
7852
7853
7854
7855
7856
7857
7858
7859
7860
7861
7862
7863
7864
7865
7866
7867
7868
7869
7870
7871
7872
7873
7874
7875
7876
7877
7878
7879
7880
7881
7882
7883
7884
7885
7886
7887
7888
7889
7890
7891
7892
7893
7894
7895
7896
7897
7898
7899
7900
7901
7902
7903
7904
7905
7906
7907
7908
7909
7910
7911
7912
7913
7914
7915
7916
7917
7918
7919
7920
7921
7922
7923
7924
7925
7926
7927
7928
7929
7930
7931
7932
7933
7934
7935
7936
7937
7938
7939
7940
7941
7942
7943
7944
7945
7946
7947
7948
7949
7950
7951
7952
7953
7954
7955
7956
7957
7958
7959
7960
7961
7962
7963
7964
7965
7966
7967
7968
7969
7970
7971
7972
7973
7974
7975
7976
7977
7978
7979
7980
7981
7982
7983
7984
7985
7986
7987
7988
7989
7990
7991
7992
7993
7994
7995
7996
7997
7998
7999
8000
8001
8002
8003
8004
8005
8006
8007
8008
8009
8010
8011
8012
8013
8014
8015
8016
8017
8018
8019
8020
8021
8022
8023
8024
8025
8026
8027
8028
8029
8030
8031
8032
8033
8034
8035
8036
8037
8038
8039
8040
8041
8042
8043
8044
8045
8046
8047
8048
8049
8050
8051
8052
8053
8054
8055
8056
8057
8058
8059
8060
8061
8062
8063
8064
8065
8066
8067
8068
8069
8070
8071
8072
8073
8074
8075
8076
8077
8078
8079
8080
8081
8082
8083
8084
8085
8086
8087
8088
8089
8090
8091
8092
8093
8094
8095
8096
8097
8098
8099
8100
8101
8102
8103
8104
8105
8106
8107
8108
8109
8110
8111
8112
8113
8114
8115
8116
8117
8118
8119
8120
8121
8122
8123
8124
8125
8126
8127
8128
8129
8130
8131
8132
8133
8134
8135
8136
8137
8138
8139
8140
8141
8142
8143
8144
8145
8146
8147
8148
8149
8150
8151
8152
8153
8154
8155
8156
8157
8158
8159
8160
8161
8162
8163
8164
8165
8166
8167
8168
8169
8170
8171
8172
8173
8174
8175
8176
8177
8178
8179
8180
8181
8182
8183
8184
8185
8186
8187
8188
8189
8190
8191
8192
8193
8194
8195
8196
8197
8198
8199
8200
8201
8202
8203
8204
8205
8206
8207
8208
8209
8210
8211
8212
8213
8214
8215
8216
8217
8218
8219
8220
8221
8222
8223
8224
8225
8226
8227
8228
8229
8230
8231
8232
8233
8234
8235
8236
8237
8238
8239
8240
8241
8242
8243
8244
8245
8246
8247
8248
8249
8250
8251
8252
8253
8254
8255
8256
8257
8258
8259
8260
8261
8262
8263
8264
8265
8266
8267
8268
8269
8270
8271
8272
8273
8274
8275
8276
8277
8278
8279
8280
8281
8282
8283
8284
8285
8286
8287
8288
8289
8290
8291
8292
8293
8294
8295
8296
8297
8298
8299
8300
8301
8302
8303
8304
8305
8306
8307
8308
8309
8310
8311
8312
8313
8314
8315
8316
8317
8318
8319
8320
8321
8322
8323
8324
8325
8326
8327
8328
8329
8330
8331
8332
8333
8334
8335
8336
8337
8338
8339
8340
8341
8342
8343
8344
8345
8346
8347
8348
8349
8350
8351
8352
8353
8354
8355
8356
8357
8358
8359
8360
8361
8362
8363
8364
8365
8366
8367
8368
8369
8370
8371
8372
8373
8374
8375
8376
8377
8378
8379
8380
8381
8382
8383
8384
8385
8386
8387
8388
8389
8390
8391
8392
8393
8394
8395
8396
8397
8398
8399
8400
8401
8402
8403
8404
8405
8406
8407
8408
8409
8410
8411
8412
8413
8414
8415
8416
8417
8418
8419
8420
8421
8422
8423
8424
8425
8426
8427
8428
8429
8430
8431
8432
8433
8434
8435
8436
8437
8438
8439
8440
8441
8442
8443
8444
8445
8446
8447
8448
8449
8450
8451
8452
8453
8454
8455
8456
8457
8458
8459
8460
8461
8462
8463
8464
8465
8466
8467
8468
8469
8470
8471
8472
8473
8474
8475
8476
8477
8478
8479
8480
8481
8482
8483
8484
8485
8486
8487
8488
8489
8490
8491
8492
8493
8494
8495
8496
8497
8498
8499
8500
8501
8502
8503
8504
8505
8506
8507
8508
8509
8510
8511
8512
8513
8514
8515
8516
8517
8518
8519
8520
8521
8522
8523
8524
8525
8526
8527
8528
8529
8530
8531
8532
8533
8534
8535
8536
8537
8538
8539
8540
8541
8542
8543
8544
8545
8546
8547
8548
8549
8550
8551
8552
8553
8554
8555
8556
8557
8558
8559
8560
8561
8562
8563
8564
8565
8566
8567
8568
8569
8570
8571
8572
8573
8574
8575
8576
8577
8578
8579
8580
8581
8582
8583
8584
8585
8586
8587
8588
8589
8590
8591
8592
8593
8594
8595
8596
8597
8598
8599
8600
8601
8602
8603
8604
8605
8606
8607
8608
8609
8610
8611
8612
8613
8614
8615
8616
8617
8618
8619
8620
8621
8622
8623
8624
8625
8626
8627
8628
8629
8630
8631
8632
8633
8634
8635
8636
8637
8638
8639
8640
8641
8642
8643
8644
8645
8646
8647
8648
8649
8650
8651
8652
8653
8654
8655
8656
8657
8658
8659
8660
8661
8662
8663
8664
8665
8666
8667
8668
8669
8670
8671
8672
8673
8674
8675
8676
8677
8678
8679
8680
8681
8682
8683
8684
8685
8686
8687
8688
8689
8690
8691
8692
8693
8694
8695
8696
8697
8698
8699
8700
8701
8702
8703
8704
8705
8706
8707
8708
8709
8710
8711
8712
8713
8714
8715
8716
8717
8718
8719
8720
8721
8722
8723
8724
8725
8726
8727
8728
8729
8730
8731
8732
8733
8734
8735
8736
8737
8738
8739
8740
8741
8742
8743
8744
8745
8746
8747
8748
8749
8750
8751
8752
8753
8754
8755
8756
8757
8758
8759
8760
8761
8762
8763
8764
8765
8766
8767
8768
8769
8770
8771
8772
8773
8774
8775
8776
8777
8778
8779
8780
8781
8782
8783
8784
8785
8786
8787
8788
8789
8790
8791
8792
8793
8794
8795
8796
8797
8798
8799
8800
8801
8802
8803
8804
8805
8806
8807
8808
8809
8810
8811
8812
8813
8814
8815
8816
8817
8818
8819
8820
8821
8822
8823
8824
8825
8826
8827
8828
8829
8830
8831
8832
8833
8834
8835
8836
8837
8838
8839
8840
8841
8842
8843
8844
8845
8846
8847
8848
8849
8850
8851
8852
8853
8854
8855
8856
8857
8858
8859
8860
8861
8862
8863
8864
8865
8866
8867
8868
8869
8870
8871
8872
8873
8874
8875
8876
8877
8878
8879
8880
8881
8882
8883
8884
8885
8886
8887
8888
8889
8890
8891
8892
8893
8894
8895
8896
8897
8898
8899
8900
8901
8902
8903
8904
8905
8906
8907
8908
8909
8910
8911
8912
8913
8914
8915
8916
8917
8918
8919
8920
8921
8922
8923
8924
8925
8926
8927
8928
8929
8930
8931
8932
8933
8934
8935
8936
8937
8938
8939
8940
8941
8942
8943
8944
8945
8946
8947
8948
8949
8950
8951
8952
8953
8954
8955
8956
8957
8958
8959
8960
8961
8962
8963
8964
8965
8966
8967
8968
8969
8970
8971
8972
8973
8974
8975
8976
8977
8978
8979
8980
8981
8982
8983
8984
8985
8986
8987
8988
8989
8990
8991
8992
8993
8994
8995
8996
8997
8998
8999
9000
9001
9002
9003
9004
9005
9006
9007
9008
9009
9010
9011
9012
9013
9014
9015
9016
9017
9018
9019
9020
9021
9022
9023
9024
9025
9026
9027
9028
9029
9030
9031
9032
9033
9034
9035
9036
9037
9038
9039
9040
9041
9042
9043
9044
9045
9046
9047
9048
9049
9050
9051
9052
9053
9054
9055
9056
9057
9058
9059
9060
9061
9062
9063
9064
9065
9066
9067
9068
9069
9070
9071
9072
9073
9074
9075
9076
9077
9078
9079
9080
9081
9082
9083
9084
9085
9086
9087
9088
9089
9090
9091
9092
9093
9094
9095
9096
9097
9098
9099
9100
9101
9102
9103
9104
9105
9106
9107
9108
9109
9110
9111
9112
9113
9114
9115
9116
9117
9118
9119
9120
9121
9122
9123
9124
9125
9126
9127
9128
9129
9130
9131
9132
9133
9134
9135
9136
9137
9138
9139
9140
9141
9142
9143
9144
9145
9146
9147
9148
9149
9150
9151
9152
9153
9154
9155
9156
9157
9158
9159
9160
9161
9162
9163
9164
9165
9166
9167
9168
9169
9170
9171
9172
9173
9174
9175
9176
9177
9178
9179
9180
9181
9182
9183
9184
9185
9186
9187
9188
9189
9190
9191
9192
9193
9194
9195
9196
9197
9198
9199
9200
9201
9202
9203
9204
9205
9206
9207
9208
9209
9210
9211
9212
9213
9214
9215
9216
9217
9218
9219
9220
9221
9222
9223
9224
9225
9226
9227
9228
9229
9230
9231
9232
9233
9234
9235
9236
9237
9238
9239
9240
9241
9242
9243
9244
9245
9246
9247
9248
9249
9250
9251
9252
9253
9254
9255
9256
9257
9258
9259
9260
9261
9262
9263
9264
9265
9266
9267
9268
9269
9270
9271
9272
9273
9274
9275
9276
9277
9278
9279
9280
9281
9282
9283
9284
9285
9286
9287
9288
9289
9290
9291
9292
9293
9294
9295
9296
9297
9298
9299
9300
9301
9302
9303
9304
9305
9306
9307
9308
9309
9310
9311
9312
9313
9314
9315
9316
9317
9318
9319
9320
9321
9322
9323
9324
9325
9326
9327
9328
9329
9330
9331
9332
9333
9334
9335
9336
9337
9338
9339
9340
9341
9342
9343
9344
9345
9346
9347
9348
9349
9350
9351
9352
9353
9354
9355
9356
9357
9358
9359
9360
9361
9362
9363
9364
9365
9366
9367
9368
9369
9370
9371
9372
9373
9374
9375
9376
9377
9378
9379
9380
9381
9382
9383
9384
9385
9386
9387
9388
9389
9390
9391
9392
9393
9394
9395
9396
9397
9398
9399
9400
9401
9402
9403
9404
9405
9406
9407
9408
9409
9410
9411
9412
9413
9414
9415
9416
9417
9418
9419
9420
9421
9422
9423
9424
9425
9426
9427
9428
9429
9430
9431
9432
9433
9434
9435
9436
9437
9438
9439
9440
9441
9442
9443
9444
9445
9446
9447
9448
9449
9450
9451
9452
9453
9454
9455
9456
9457
9458
9459
9460
9461
9462
9463
9464
9465
9466
9467
9468
9469
9470
9471
9472
9473
9474
9475
9476
9477
9478
9479
9480
9481
9482
9483
9484
9485
9486
9487
9488
9489
9490
9491
9492
9493
9494
9495
9496
9497
9498
9499
9500
9501
9502
9503
9504
9505
9506
9507
9508
9509
9510
9511
9512
9513
9514
9515
9516
9517
9518
9519
9520
9521
9522
9523
9524
9525
9526
9527
9528
9529
9530
9531
9532
9533
9534
9535
9536
9537
9538
9539
9540
9541
9542
9543
9544
9545
9546
9547
9548
9549
9550
9551
9552
9553
9554
9555
9556
9557
9558
9559
9560
9561
9562
9563
9564
9565
9566
9567
9568
9569
9570
9571
9572
9573
9574
9575
9576
9577
9578
9579
9580
9581
9582
9583
9584
9585
9586
9587
9588
9589
9590
9591
9592
9593
9594
9595
9596
9597
9598
9599
9600
9601
9602
9603
9604
9605
9606
9607
9608
9609
9610
9611
9612
9613
9614
9615
9616
9617
9618
9619
9620
9621
9622
9623
9624
9625
9626
9627
9628
9629
9630
9631
9632
9633
9634
9635
9636
9637
9638
9639
9640
9641
9642
9643
9644
9645
9646
9647
9648
9649
9650
9651
9652
9653
9654
9655
9656
9657
9658
9659
9660
9661
9662
9663
9664
9665
9666
9667
9668
9669
9670
9671
9672
9673
9674
9675
9676
9677
9678
9679
9680
9681
9682
9683
9684
9685
9686
9687
9688
9689
9690
9691
9692
9693
9694
9695
9696
9697
9698
9699
9700
9701
9702
9703
9704
9705
9706
9707
9708
9709
9710
9711
9712
9713
9714
9715
9716
9717
9718
9719
9720
9721
9722
9723
9724
9725
9726
9727
9728
9729
9730
9731
9732
9733
9734
9735
9736
9737
9738
9739
9740
9741
9742
9743
9744
9745
9746
9747
9748
9749
9750
9751
9752
9753
9754
9755
9756
9757
9758
9759
9760
9761
9762
9763
9764
9765
9766
9767
9768
9769
9770
9771
9772
9773
9774
9775
9776
9777
9778
9779
9780
9781
9782
9783
9784
9785
9786
9787
9788
9789
9790
9791
9792
9793
9794
9795
9796
9797
9798
9799
9800
9801
9802
9803
9804
9805
9806
9807
9808
9809
9810
9811
9812
9813
9814
9815
9816
9817
9818
9819
9820
9821
9822
9823
9824
9825
9826
9827
9828
9829
9830
9831
9832
9833
9834
9835
9836
9837
9838
9839
9840
9841
9842
9843
9844
9845
9846
9847
9848
9849
9850
9851
9852
9853
9854
9855
9856
9857
9858
9859
9860
9861
9862
9863
9864
9865
9866
9867
9868
9869
9870
9871
9872
9873
9874
9875
9876
9877
9878
9879
9880
9881
9882
9883
9884
9885
9886
9887
9888
9889
9890
9891
9892
9893
9894
9895
9896
9897
9898
9899
9900
9901
9902
9903
9904
9905
9906
9907
9908
9909
9910
9911
9912
9913
9914
9915
9916
9917
9918
9919
9920
9921
9922
9923
9924
9925
9926
9927
9928
9929
9930
9931
9932
9933
9934
9935
9936
9937
9938
9939
9940
9941
9942
9943
9944
9945
9946
9947
9948
9949
9950
9951
9952
9953
9954
9955
9956
9957
9958
9959
9960
9961
9962
9963
9964
9965
9966
9967
9968
9969
9970
9971
9972
9973
9974
9975
9976
9977
9978
9979
9980
9981
9982
9983
9984
9985
9986
9987
9988
9989
9990
9991
9992
9993
9994
9995
9996
9997
9998
9999
10000
10001
10002
10003
10004
10005
10006
10007
10008
10009
10010
10011
10012
10013
10014
10015
10016
10017
10018
10019
10020
10021
10022
10023
10024
10025
10026
10027
10028
10029
10030
10031
10032
10033
10034
10035
10036
10037
10038
10039
10040
10041
10042
10043
10044
10045
10046
10047
10048
10049
10050
10051
10052
10053
10054
10055
10056
10057
10058
10059
10060
10061
10062
10063
10064
10065
10066
10067
10068
10069
10070
10071
10072
10073
10074
10075
10076
10077
10078
10079
10080
10081
10082
10083
10084
10085
10086
10087
10088
10089
10090
10091
10092
10093
10094
10095
10096
10097
10098
10099
10100
10101
10102
10103
10104
10105
10106
10107
10108
10109
10110
10111
10112
10113
10114
10115
10116
10117
10118
10119
10120
10121
10122
10123
10124
10125
10126
10127
10128
10129
10130
10131
10132
10133
10134
10135
10136
10137
10138
10139
10140
10141
10142
10143
10144
10145
10146
10147
10148
10149
10150
10151
10152
10153
10154
10155
10156
10157
10158
10159
10160
10161
10162
10163
10164
10165
10166
10167
10168
10169
10170
10171
10172
10173
10174
10175
10176
10177
10178
10179
10180
10181
10182
10183
10184
10185
10186
10187
10188
10189
10190
10191
10192
10193
10194
10195
10196
10197
10198
10199
10200
10201
10202
10203
10204
10205
10206
10207
10208
10209
10210
10211
10212
10213
10214
10215
10216
10217
10218
10219
10220
10221
10222
10223
10224
10225
10226
10227
10228
10229
10230
10231
10232
10233
10234
10235
10236
10237
10238
10239
10240
10241
10242
10243
10244
10245
10246
10247
10248
10249
10250
10251
10252
10253
10254
10255
10256
10257
10258
10259
10260
10261
10262
10263
10264
10265
10266
10267
10268
10269
10270
10271
10272
10273
10274
10275
10276
10277
10278
10279
10280
10281
10282
10283
10284
10285
10286
10287
10288
10289
10290
10291
10292
10293
10294
10295
10296
10297
10298
10299
10300
10301
10302
10303
10304
10305
10306
10307
10308
10309
10310
10311
10312
10313
10314
10315
10316
10317
10318
10319
10320
10321
10322
10323
10324
10325
10326
10327
10328
10329
10330
10331
10332
10333
10334
10335
10336
10337
10338
10339
10340
10341
10342
10343
10344
10345
10346
10347
10348
10349
10350
10351
10352
10353
10354
10355
10356
10357
10358
10359
10360
10361
10362
10363
10364
10365
10366
10367
10368
10369
10370
10371
10372
10373
10374
10375
10376
10377
10378
10379
10380
10381
10382
10383
10384
10385
10386
10387
10388
10389
10390
10391
10392
10393
10394
10395
10396
10397
10398
10399
10400
10401
10402
10403
10404
10405
10406
10407
10408
10409
10410
10411
10412
10413
10414
10415
10416
10417
10418
10419
10420
10421
10422
10423
10424
10425
10426
10427
10428
10429
10430
10431
10432
10433
10434
10435
10436
10437
10438
10439
10440
10441
10442
10443
10444
10445
10446
10447
10448
10449
10450
10451
10452
10453
10454
10455
10456
10457
10458
10459
10460
10461
10462
10463
10464
10465
10466
10467
10468
10469
10470
10471
10472
10473
10474
10475
10476
10477
10478
10479
10480
10481
10482
10483
10484
10485
10486
10487
10488
10489
10490
10491
10492
10493
10494
10495
10496
10497
10498
10499
10500
10501
10502
10503
10504
10505
10506
10507
10508
10509
10510
10511
10512
10513
10514
10515
10516
10517
10518
10519
10520
10521
10522
10523
10524
10525
10526
10527
10528
10529
10530
10531
10532
10533
10534
10535
10536
10537
10538
10539
10540
10541
10542
10543
10544
10545
10546
10547
10548
10549
10550
10551
10552
10553
10554
10555
10556
10557
10558
10559
10560
10561
10562
10563
10564
10565
10566
10567
10568
10569
10570
10571
10572
10573
10574
10575
10576
10577
10578
10579
10580
10581
10582
10583
10584
10585
10586
10587
10588
10589
10590
10591
10592
10593
10594
10595
10596
10597
10598
10599
10600
10601
10602
10603
10604
10605
10606
10607
10608
10609
10610
10611
10612
10613
10614
10615
10616
10617
10618
10619
10620
10621
10622
10623
10624
10625
10626
10627
10628
10629
10630
10631
10632
10633
10634
10635
10636
10637
10638
10639
10640
10641
10642
10643
10644
10645
10646
10647
10648
10649
10650
10651
10652
10653
10654
10655
10656
10657
10658
10659
10660
10661
10662
10663
10664
10665
10666
10667
10668
10669
10670
10671
10672
10673
10674
10675
10676
10677
10678
10679
10680
10681
10682
10683
10684
10685
10686
10687
10688
10689
10690
10691
10692
10693
10694
10695
10696
10697
10698
10699
10700
10701
10702
10703
10704
10705
10706
10707
10708
10709
10710
10711
10712
10713
10714
10715
10716
10717
10718
10719
10720
10721
10722
10723
10724
10725
10726
10727
10728
10729
10730
10731
10732
10733
10734
10735
10736
10737
10738
10739
10740
10741
10742
10743
10744
10745
10746
10747
10748
10749
10750
10751
10752
10753
10754
10755
10756
10757
10758
10759
10760
10761
10762
10763
10764
10765
10766
10767
10768
10769
10770
10771
10772
10773
10774
10775
10776
10777
10778
10779
10780
10781
10782
10783
10784
10785
10786
10787
10788
10789
10790
10791
10792
10793
10794
10795
10796
10797
10798
10799
10800
10801
10802
10803
10804
10805
10806
10807
10808
10809
10810
10811
10812
10813
10814
10815
10816
10817
10818
10819
10820
10821
10822
10823
10824
10825
10826
10827
10828
10829
10830
10831
10832
10833
10834
10835
10836
10837
10838
10839
10840
10841
10842
10843
10844
10845
10846
10847
10848
10849
10850
10851
10852
10853
10854
10855
10856
10857
10858
10859
10860
10861
10862
10863
10864
10865
10866
10867
10868
10869
10870
10871
10872
10873
10874
10875
10876
10877
10878
10879
10880
10881
10882
10883
10884
10885
10886
10887
10888
10889
10890
10891
10892
10893
10894
10895
10896
10897
10898
10899
10900
10901
10902
10903
10904
10905
10906
10907
10908
10909
10910
10911
10912
10913
10914
10915
10916
10917
10918
10919
10920
10921
10922
10923
10924
10925
10926
10927
10928
10929
10930
10931
10932
10933
10934
10935
10936
10937
10938
10939
10940
10941
10942
10943
10944
10945
10946
10947
10948
10949
10950
10951
10952
10953
10954
10955
10956
10957
10958
10959
10960
10961
10962
10963
10964
10965
10966
10967
10968
10969
10970
10971
10972
10973
10974
10975
10976
10977
10978
10979
10980
10981
10982
10983
10984
10985
10986
10987
10988
10989
10990
10991
10992
10993
10994
10995
10996
10997
10998
10999
11000
11001
11002
11003
11004
11005
11006
11007
11008
11009
11010
11011
11012
11013
11014
11015
11016
11017
11018
11019
11020
11021
11022
11023
11024
11025
11026
11027
11028
11029
11030
11031
11032
11033
11034
11035
11036
11037
11038
11039
11040
11041
11042
11043
11044
11045
11046
11047
11048
11049
11050
11051
11052
11053
11054
11055
11056
11057
11058
11059
11060
11061
11062
11063
11064
11065
11066
11067
11068
11069
11070
11071
11072
11073
11074
11075
11076
11077
11078
11079
11080
11081
11082
11083
11084
11085
11086
11087
11088
11089
11090
11091
11092
11093
11094
11095
11096
11097
11098
11099
11100
11101
11102
11103
11104
11105
11106
11107
11108
11109
11110
11111
11112
11113
11114
11115
11116
11117
11118
11119
11120
11121
11122
11123
11124
11125
11126
11127
11128
11129
11130
11131
11132
11133
11134
11135
11136
11137
11138
11139
11140
11141
11142
11143
11144
11145
11146
11147
11148
11149
11150
11151
11152
11153
11154
11155
11156
11157
11158
11159
11160
11161
11162
11163
11164
11165
11166
11167
11168
11169
11170
11171
11172
11173
11174
11175
11176
11177
11178
11179
11180
11181
11182
11183
11184
11185
11186
11187
11188
11189
11190
11191
11192
11193
11194
11195
11196
11197
11198
11199
11200
11201
11202
11203
11204
11205
11206
11207
11208
11209
11210
11211
11212
11213
11214
11215
11216
11217
11218
11219
11220
11221
11222
11223
11224
11225
11226
11227
11228
11229
11230
11231
11232
11233
11234
11235
11236
11237
11238
11239
11240
11241
11242
11243
11244
11245
11246
11247
11248
11249
11250
11251
11252
11253
11254
11255
11256
11257
11258
11259
11260
11261
11262
11263
11264
11265
11266
11267
11268
11269
11270
11271
11272
11273
11274
11275
11276
11277
11278
11279
11280
11281
11282
11283
11284
11285
11286
11287
11288
11289
11290
11291
11292
11293
11294
11295
11296
11297
11298
11299
11300
11301
11302
11303
11304
11305
11306
11307
11308
11309
11310
11311
11312
11313
11314
11315
11316
11317
11318
11319
11320
11321
11322
11323
11324
11325
11326
11327
11328
11329
11330
11331
11332
11333
11334
11335
11336
11337
11338
11339
11340
11341
11342
11343
11344
11345
11346
11347
11348
11349
11350
11351
11352
11353
11354
11355
11356
11357
11358
11359
11360
11361
11362
11363
11364
11365
11366
11367
11368
11369
11370
11371
11372
11373
11374
11375
11376
11377
11378
11379
11380
11381
11382
11383
11384
11385
11386
11387
11388
11389
11390
11391
11392
11393
11394
11395
11396
11397
11398
11399
11400
11401
11402
11403
11404
11405
11406
11407
11408
11409
11410
11411
11412
11413
11414
11415
11416
11417
11418
11419
11420
11421
11422
11423
11424
11425
11426
11427
11428
11429
11430
11431
11432
11433
11434
11435
11436
11437
11438
11439
11440
11441
11442
11443
11444
11445
11446
11447
11448
11449
11450
11451
11452
11453
11454
11455
11456
11457
11458
11459
11460
11461
11462
11463
11464
11465
11466
11467
11468
11469
11470
11471
11472
11473
11474
11475
11476
11477
11478
11479
11480
11481
11482
11483
11484
11485
11486
11487
11488
11489
11490
11491
11492
11493
11494
11495
11496
11497
11498
11499
11500
11501
11502
11503
11504
11505
11506
11507
11508
11509
11510
11511
11512
11513
11514
11515
11516
11517
11518
11519
11520
11521
11522
11523
11524
11525
11526
11527
11528
11529
11530
11531
11532
11533
11534
11535
11536
11537
11538
11539
11540
11541
11542
11543
11544
11545
11546
11547
11548
11549
11550
11551
11552
11553
11554
11555
11556
11557
11558
11559
11560
11561
11562
11563
11564
11565
11566
11567
11568
11569
11570
11571
11572
11573
11574
11575
11576
11577
11578
11579
11580
11581
11582
11583
11584
11585
11586
11587
11588
11589
11590
11591
11592
11593
11594
11595
11596
11597
11598
11599
11600
11601
11602
11603
11604
11605
11606
11607
11608
11609
11610
11611
11612
11613
11614
11615
11616
11617
11618
11619
11620
11621
11622
11623
11624
11625
11626
11627
11628
11629
11630
11631
11632
11633
11634
11635
11636
11637
11638
11639
11640
11641
11642
11643
11644
11645
11646
11647
11648
11649
11650
11651
11652
11653
11654
11655
11656
11657
11658
11659
11660
11661
11662
11663
11664
11665
11666
11667
11668
11669
11670
11671
11672
11673
11674
11675
11676
11677
11678
11679
11680
11681
11682
11683
11684
11685
11686
11687
11688
11689
11690
11691
11692
11693
11694
11695
11696
11697
11698
11699
11700
11701
11702
11703
11704
11705
11706
11707
11708
11709
11710
11711
11712
11713
11714
11715
11716
11717
11718
11719
11720
11721
11722
11723
11724
11725
11726
11727
11728
11729
11730
11731
11732
11733
11734
11735
11736
11737
11738
11739
11740
11741
11742
11743
11744
11745
11746
11747
11748
11749
11750
11751
11752
11753
11754
11755
11756
11757
11758
11759
11760
11761
11762
11763
11764
11765
11766
11767
11768
11769
11770
11771
11772
11773
11774
11775
11776
11777
11778
11779
11780
11781
11782
11783
11784
11785
11786
11787
11788
11789
11790
11791
11792
11793
11794
11795
11796
11797
11798
11799
11800
11801
11802
11803
11804
11805
11806
11807
11808
11809
11810
11811
11812
11813
11814
11815
11816
11817
11818
11819
11820
11821
11822
11823
11824
11825
11826
11827
11828
11829
11830
11831
11832
11833
11834
11835
11836
11837
11838
11839
11840
11841
11842
11843
11844
11845
11846
11847
11848
11849
11850
11851
11852
11853
11854
11855
11856
11857
11858
11859
11860
11861
11862
11863
11864
11865
11866
11867
11868
11869
11870
11871
11872
11873
11874
11875
11876
11877
11878
11879
11880
11881
11882
11883
11884
11885
11886
11887
11888
11889
11890
11891
11892
11893
11894
11895
11896
11897
11898
11899
11900
11901
11902
11903
11904
11905
11906
11907
11908
11909
11910
11911
11912
11913
11914
11915
11916
11917
11918
11919
11920
11921
11922
11923
11924
11925
11926
11927
11928
11929
11930
11931
11932
11933
11934
11935
11936
11937
11938
11939
11940
11941
11942
11943
11944
11945
11946
11947
11948
11949
11950
11951
11952
11953
11954
11955
11956
11957
11958
11959
11960
11961
11962
11963
11964
11965
11966
11967
11968
11969
11970
11971
11972
11973
11974
11975
11976
11977
11978
11979
11980
11981
11982
11983
11984
11985
11986
11987
11988
11989
11990
11991
11992
11993
11994
11995
11996
11997
11998
11999
12000
12001
12002
12003
12004
12005
12006
12007
12008
12009
12010
12011
12012
12013
12014
12015
12016
12017
12018
12019
12020
12021
12022
12023
12024
12025
12026
12027
12028
12029
12030
12031
12032
12033
12034
12035
12036
12037
12038
12039
12040
12041
12042
12043
12044
12045
12046
12047
12048
12049
12050
12051
12052
12053
12054
12055
12056
12057
12058
12059
12060
12061
12062
12063
12064
12065
12066
12067
12068
12069
12070
12071
12072
12073
12074
12075
12076
12077
12078
12079
12080
12081
12082
12083
12084
12085
12086
12087
12088
12089
12090
12091
12092
12093
12094
12095
12096
12097
12098
12099
12100
12101
12102
12103
12104
12105
12106
12107
12108
12109
12110
12111
12112
12113
12114
12115
12116
12117
12118
12119
12120
12121
12122
12123
12124
12125
12126
12127
12128
12129
12130
12131
12132
12133
12134
12135
12136
12137
12138
12139
12140
12141
12142
12143
12144
12145
12146
12147
12148
12149
12150
12151
12152
12153
12154
12155
12156
12157
12158
12159
12160
12161
12162
12163
12164
12165
12166
12167
12168
12169
12170
12171
12172
12173
12174
12175
12176
12177
12178
12179
12180
12181
12182
12183
12184
12185
12186
12187
12188
12189
12190
12191
12192
12193
12194
12195
12196
12197
12198
12199
12200
12201
12202
12203
12204
12205
12206
12207
12208
12209
12210
12211
12212
12213
12214
12215
12216
12217
12218
12219
12220
12221
12222
12223
12224
12225
12226
12227
12228
12229
12230
12231
12232
12233
12234
12235
12236
12237
12238
12239
12240
12241
12242
12243
12244
12245
12246
12247
12248
12249
12250
12251
12252
12253
12254
12255
12256
12257
12258
12259
12260
12261
12262
12263
12264
12265
12266
12267
12268
12269
12270
12271
12272
12273
12274
12275
12276
12277
12278
12279
12280
12281
12282
12283
12284
12285
12286
12287
12288
12289
12290
12291
12292
12293
12294
12295
12296
12297
12298
12299
12300
12301
12302
12303
12304
12305
12306
12307
12308
12309
12310
12311
12312
12313
12314
12315
12316
12317
12318
12319
12320
12321
12322
12323
12324
12325
12326
12327
12328
12329
12330
12331
12332
12333
12334
12335
12336
12337
12338
12339
12340
12341
12342
12343
12344
12345
12346
12347
12348
12349
12350
12351
12352
12353
12354
12355
12356
12357
12358
12359
12360
12361
12362
12363
12364
12365
12366
12367
12368
12369
12370
12371
12372
12373
12374
12375
12376
12377
12378
12379
12380
12381
12382
12383
12384
12385
12386
12387
12388
12389
12390
12391
12392
12393
12394
12395
12396
12397
12398
12399
12400
12401
12402
12403
12404
12405
12406
12407
12408
12409
12410
12411
12412
12413
12414
12415
12416
12417
12418
12419
12420
12421
12422
12423
12424
12425
12426
12427
12428
12429
12430
12431
12432
12433
12434
12435
12436
12437
12438
12439
12440
12441
12442
12443
12444
12445
12446
12447
12448
12449
12450
12451
12452
12453
12454
12455
12456
12457
12458
12459
12460
12461
12462
12463
12464
12465
12466
12467
12468
12469
12470
12471
12472
12473
12474
12475
12476
12477
12478
12479
12480
12481
12482
12483
12484
12485
12486
12487
12488
12489
12490
12491
12492
12493
12494
12495
12496
12497
12498
12499
12500
12501
12502
12503
12504
12505
12506
12507
12508
12509
12510
12511
12512
12513
12514
12515
12516
12517
12518
12519
12520
12521
12522
12523
12524
12525
12526
12527
12528
12529
12530
12531
12532
12533
12534
12535
12536
12537
12538
12539
12540
12541
12542
12543
12544
12545
12546
12547
12548
12549
12550
12551
12552
12553
12554
12555
12556
12557
12558
12559
12560
12561
12562
12563
12564
12565
12566
12567
12568
12569
12570
12571
12572
12573
12574
12575
12576
12577
12578
12579
12580
12581
12582
12583
12584
12585
12586
12587
12588
12589
12590
12591
12592
12593
12594
12595
12596
12597
12598
12599
12600
12601
12602
12603
12604
12605
12606
12607
12608
12609
12610
12611
12612
12613
12614
12615
12616
12617
12618
12619
12620
12621
12622
12623
12624
12625
12626
12627
12628
12629
12630
12631
12632
12633
12634
12635
12636
12637
12638
12639
12640
12641
12642
12643
12644
12645
12646
12647
12648
12649
12650
12651
12652
12653
12654
12655
12656
12657
12658
12659
12660
12661
12662
12663
12664
12665
12666
12667
12668
12669
12670
12671
12672
12673
12674
12675
12676
12677
12678
12679
12680
12681
12682
12683
12684
12685
12686
12687
12688
12689
12690
12691
12692
12693
12694
12695
12696
12697
12698
12699
12700
12701
12702
12703
12704
12705
12706
12707
12708
12709
12710
12711
12712
12713
12714
12715
12716
12717
12718
12719
12720
12721
12722
12723
12724
12725
12726
12727
12728
12729
12730
12731
12732
12733
12734
12735
12736
12737
12738
12739
12740
12741
12742
12743
12744
12745
12746
12747
12748
12749
12750
12751
12752
12753
12754
12755
12756
12757
12758
12759
12760
12761
12762
12763
12764
12765
12766
12767
12768
12769
12770
12771
12772
12773
12774
12775
12776
12777
12778
12779
12780
12781
12782
12783
12784
12785
12786
12787
12788
12789
12790
12791
12792
12793
12794
12795
12796
12797
12798
12799
12800
12801
12802
12803
12804
12805
12806
12807
12808
12809
12810
12811
12812
12813
12814
12815
12816
12817
12818
12819
12820
12821
12822
12823
12824
12825
12826
12827
12828
12829
12830
12831
12832
12833
12834
12835
12836
12837
12838
12839
12840
12841
12842
12843
12844
12845
12846
12847
12848
12849
12850
12851
12852
12853
12854
12855
12856
12857
12858
12859
12860
12861
12862
12863
12864
12865
12866
12867
12868
12869
12870
12871
12872
12873
12874
12875
12876
12877
12878
12879
12880
12881
12882
12883
12884
12885
12886
12887
12888
12889
12890
12891
12892
12893
12894
12895
12896
12897
12898
12899
12900
12901
12902
12903
12904
12905
12906
12907
12908
12909
12910
12911
12912
12913
12914
12915
12916
12917
12918
12919
12920
12921
12922
12923
12924
12925
12926
12927
12928
12929
12930
12931
12932
12933
12934
12935
12936
12937
12938
12939
12940
12941
12942
12943
12944
12945
12946
12947
12948
12949
12950
12951
12952
12953
12954
12955
12956
12957
12958
12959
12960
12961
12962
12963
12964
12965
12966
12967
12968
12969
12970
12971
12972
12973
12974
12975
12976
12977
12978
12979
12980
12981
12982
12983
12984
12985
12986
12987
12988
12989
12990
12991
12992
12993
12994
12995
12996
12997
12998
12999
13000
13001
13002
13003
13004
13005
13006
13007
13008
13009
13010
13011
13012
13013
13014
13015
13016
13017
13018
13019
13020
13021
13022
13023
13024
13025
13026
13027
13028
13029
13030
13031
13032
13033
13034
13035
13036
13037
13038
13039
13040
13041
13042
13043
13044
13045
13046
13047
13048
13049
13050
13051
13052
13053
13054
13055
13056
13057
13058
13059
13060
13061
13062
13063
13064
13065
13066
13067
13068
13069
13070
13071
13072
13073
13074
13075
13076
13077
13078
13079
13080
13081
13082
13083
13084
13085
13086
13087
13088
13089
13090
13091
13092
13093
13094
13095
13096
13097
13098
13099
13100
13101
13102
13103
13104
13105
13106
13107
13108
13109
13110
13111
13112
13113
13114
13115
13116
13117
13118
13119
13120
13121
13122
13123
13124
13125
13126
13127
13128
13129
13130
13131
13132
13133
13134
13135
13136
13137
13138
13139
13140
13141
13142
13143
13144
13145
13146
13147
13148
13149
13150
13151
13152
13153
13154
13155
13156
13157
13158
13159
13160
13161
13162
13163
13164
13165
13166
13167
13168
13169
13170
13171
13172
13173
13174
13175
13176
13177
13178
13179
13180
13181
13182
13183
13184
13185
13186
13187
13188
13189
13190
13191
13192
13193
13194
13195
13196
13197
13198
13199
13200
13201
13202
13203
13204
13205
13206
13207
13208
13209
13210
13211
13212
13213
13214
13215
13216
13217
13218
13219
13220
13221
13222
13223
13224
13225
13226
13227
13228
13229
13230
13231
13232
13233
13234
13235
13236
13237
13238
13239
13240
13241
13242
13243
13244
13245
13246
13247
13248
13249
13250
13251
13252
13253
13254
13255
13256
13257
13258
13259
13260
13261
13262
13263
13264
13265
13266
13267
13268
13269
13270
13271
13272
13273
13274
13275
13276
13277
13278
13279
13280
13281
13282
13283
13284
13285
13286
13287
13288
13289
13290
13291
13292
13293
13294
13295
13296
13297
13298
13299
13300
13301
13302
13303
13304
13305
13306
13307
13308
13309
13310
13311
13312
13313
13314
13315
13316
13317
13318
13319
13320
13321
13322
13323
13324
13325
13326
13327
13328
13329
13330
13331
13332
13333
13334
13335
13336
13337
13338
13339
13340
13341
13342
13343
13344
13345
13346
13347
13348
13349
13350
13351
13352
13353
13354
13355
13356
13357
13358
13359
13360
13361
13362
13363
13364
13365
13366
13367
13368
13369
13370
13371
13372
13373
13374
13375
13376
13377
13378
13379
13380
13381
13382
13383
13384
13385
13386
13387
13388
13389
13390
13391
13392
13393
13394
13395
13396
13397
13398
13399
13400
13401
13402
13403
13404
13405
13406
13407
13408
13409
13410
13411
13412
13413
13414
13415
13416
13417
13418
13419
13420
13421
13422
13423
13424
13425
13426
13427
13428
13429
13430
13431
13432
13433
13434
13435
13436
13437
13438
13439
13440
13441
13442
13443
13444
13445
13446
13447
13448
13449
13450
13451
13452
13453
13454
13455
13456
13457
13458
13459
13460
13461
13462
13463
13464
13465
13466
13467
13468
13469
13470
13471
13472
13473
13474
13475
13476
13477
13478
13479
13480
13481
13482
13483
13484
13485
13486
13487
13488
13489
13490
13491
13492
13493
13494
13495
13496
13497
13498
13499
13500
13501
13502
13503
13504
13505
13506
13507
13508
13509
13510
13511
13512
13513
13514
13515
13516
13517
13518
13519
13520
13521
13522
13523
13524
13525
13526
13527
13528
13529
13530
13531
13532
13533
13534
13535
13536
13537
13538
13539
13540
13541
13542
13543
13544
13545
13546
13547
13548
13549
13550
13551
13552
13553
13554
13555
13556
13557
13558
13559
13560
13561
13562
13563
13564
13565
13566
13567
13568
13569
13570
13571
13572
13573
13574
13575
13576
13577
13578
13579
13580
13581
13582
13583
13584
13585
13586
13587
13588
13589
13590
13591
13592
13593
13594
13595
13596
13597
13598
13599
13600
13601
13602
13603
13604
13605
13606
13607
13608
13609
13610
13611
13612
13613
13614
13615
13616
13617
13618
13619
13620
13621
13622
13623
13624
13625
13626
13627
13628
13629
13630
13631
13632
13633
13634
13635
13636
13637
13638
13639
13640
13641
13642
13643
13644
13645
13646
13647
13648
13649
13650
13651
13652
13653
13654
13655
13656
13657
13658
13659
13660
13661
13662
13663
13664
13665
13666
13667
13668
13669
13670
13671
13672
13673
13674
13675
13676
13677
13678
13679
13680
13681
13682
13683
13684
13685
13686
13687
13688
13689
13690
13691
13692
13693
13694
13695
13696
13697
13698
13699
13700
13701
13702
13703
13704
13705
13706
13707
13708
13709
13710
13711
13712
13713
13714
13715
13716
13717
13718
13719
13720
13721
13722
13723
13724
13725
13726
13727
13728
13729
13730
13731
13732
13733
13734
13735
13736
13737
13738
13739
13740
13741
13742
13743
13744
13745
13746
13747
13748
13749
13750
13751
13752
13753
13754
13755
13756
13757
13758
13759
13760
13761
13762
13763
13764
13765
13766
13767
13768
13769
13770
13771
13772
13773
13774
13775
13776
13777
13778
13779
13780
13781
13782
13783
13784
13785
13786
13787
13788
13789
13790
13791
13792
13793
13794
13795
13796
13797
13798
13799
13800
13801
13802
13803
13804
13805
13806
13807
13808
13809
13810
13811
13812
13813
13814
13815
13816
13817
13818
13819
13820
13821
13822
13823
13824
13825
13826
13827
13828
13829
13830
13831
13832
13833
13834
13835
13836
13837
13838
13839
13840
13841
13842
13843
13844
13845
13846
13847
13848
13849
13850
13851
13852
13853
13854
13855
13856
13857
13858
13859
13860
13861
13862
13863
13864
13865
13866
13867
13868
13869
13870
13871
13872
13873
13874
13875
13876
13877
13878
13879
13880
13881
13882
13883
13884
13885
13886
13887
13888
13889
13890
13891
13892
13893
13894
13895
13896
13897
13898
13899
13900
13901
13902
13903
13904
13905
13906
13907
13908
13909
13910
13911
13912
13913
13914
13915
13916
13917
13918
13919
13920
13921
13922
13923
13924
13925
13926
13927
13928
13929
13930
13931
13932
13933
13934
13935
13936
13937
13938
13939
13940
13941
13942
13943
13944
13945
13946
13947
13948
13949
13950
13951
13952
13953
13954
13955
13956
13957
13958
13959
13960
13961
13962
13963
13964
13965
13966
13967
13968
13969
13970
13971
13972
13973
13974
13975
13976
13977
13978
13979
13980
13981
13982
13983
13984
13985
13986
13987
13988
13989
13990
13991
13992
13993
13994
13995
13996
13997
13998
13999
14000
14001
14002
14003
14004
14005
14006
14007
14008
14009
14010
14011
14012
14013
14014
14015
14016
14017
14018
14019
14020
14021
14022
14023
14024
14025
14026
14027
14028
14029
14030
14031
14032
14033
14034
14035
14036
14037
14038
14039
14040
14041
14042
14043
14044
14045
14046
14047
14048
14049
14050
14051
14052
14053
14054
14055
14056
14057
14058
14059
14060
14061
14062
14063
14064
14065
14066
14067
14068
14069
14070
14071
14072
14073
14074
14075
14076
14077
14078
14079
14080
14081
14082
14083
14084
14085
14086
14087
14088
14089
14090
14091
14092
14093
14094
14095
14096
14097
14098
14099
14100
14101
14102
14103
14104
14105
14106
14107
14108
14109
14110
14111
14112
14113
14114
14115
14116
14117
14118
14119
14120
14121
14122
14123
14124
14125
14126
14127
14128
14129
14130
14131
14132
14133
14134
14135
14136
14137
14138
14139
14140
14141
14142
14143
14144
14145
14146
14147
14148
14149
14150
14151
14152
14153
14154
14155
14156
14157
14158
14159
14160
14161
14162
14163
14164
14165
14166
14167
14168
14169
14170
14171
14172
14173
14174
14175
14176
14177
14178
14179
14180
14181
14182
14183
14184
14185
14186
14187
14188
14189
14190
14191
14192
14193
14194
14195
14196
14197
14198
14199
14200
14201
14202
14203
14204
14205
14206
14207
14208
14209
14210
14211
14212
14213
14214
14215
14216
14217
14218
14219
14220
14221
14222
14223
14224
14225
14226
14227
14228
14229
14230
14231
14232
14233
14234
14235
14236
14237
14238
14239
14240
14241
14242
14243
14244
14245
14246
14247
14248
14249
14250
14251
14252
14253
14254
14255
14256
14257
14258
14259
14260
14261
14262
14263
14264
14265
14266
14267
14268
14269
14270
14271
14272
14273
14274
14275
14276
14277
14278
14279
14280
14281
14282
14283
14284
14285
14286
14287
14288
14289
14290
14291
14292
14293
14294
14295
14296
14297
14298
14299
14300
14301
14302
14303
14304
14305
14306
14307
14308
14309
14310
14311
14312
14313
14314
14315
14316
14317
14318
14319
14320
14321
14322
14323
14324
14325
14326
14327
14328
14329
14330
14331
14332
14333
14334
14335
14336
14337
14338
14339
14340
14341
14342
14343
14344
14345
14346
14347
14348
14349
14350
14351
14352
14353
14354
14355
14356
14357
14358
14359
14360
14361
14362
14363
14364
14365
14366
14367
14368
14369
14370
14371
14372
14373
14374
14375
14376
14377
14378
14379
14380
14381
14382
14383
14384
14385
14386
14387
14388
14389
14390
14391
14392
14393
14394
14395
14396
14397
14398
14399
14400
14401
14402
14403
14404
14405
14406
14407
14408
14409
14410
14411
14412
14413
14414
14415
14416
14417
14418
14419
14420
14421
14422
14423
14424
14425
14426
14427
14428
14429
14430
14431
14432
14433
14434
14435
14436
14437
14438
14439
14440
14441
14442
14443
14444
14445
14446
14447
14448
14449
14450
14451
14452
14453
14454
14455
14456
14457
14458
14459
14460
14461
14462
14463
14464
14465
14466
14467
14468
14469
14470
14471
14472
14473
14474
14475
14476
14477
14478
14479
14480
14481
14482
14483
14484
14485
14486
14487
14488
14489
14490
14491
14492
14493
14494
14495
14496
14497
14498
14499
14500
14501
14502
14503
14504
14505
14506
14507
14508
14509
14510
14511
14512
14513
14514
14515
14516
14517
14518
14519
14520
14521
14522
14523
14524
14525
14526
14527
14528
14529
14530
14531
14532
14533
14534
14535
14536
14537
14538
14539
14540
14541
14542
14543
14544
14545
14546
14547
14548
14549
14550
14551
14552
14553
14554
14555
14556
14557
14558
14559
14560
14561
14562
14563
14564
14565
14566
14567
14568
14569
14570
14571
14572
14573
14574
14575
14576
14577
14578
14579
14580
14581
14582
14583
14584
14585
14586
14587
14588
14589
14590
14591
14592
14593
14594
14595
14596
14597
14598
14599
14600
14601
14602
14603
14604
14605
14606
14607
14608
14609
14610
14611
14612
14613
14614
14615
14616
14617
14618
14619
14620
14621
14622
14623
14624
14625
14626
14627
14628
14629
14630
14631
14632
14633
14634
14635
14636
14637
14638
14639
14640
14641
14642
14643
14644
14645
14646
14647
14648
14649
14650
14651
14652
14653
14654
14655
14656
14657
14658
14659
14660
14661
14662
14663
14664
14665
14666
14667
14668
14669
14670
14671
14672
14673
14674
14675
14676
14677
14678
14679
14680
14681
14682
14683
14684
14685
14686
14687
14688
14689
14690
14691
14692
14693
14694
14695
14696
14697
14698
14699
14700
14701
14702
14703
14704
14705
14706
14707
14708
14709
14710
14711
14712
14713
14714
14715
14716
14717
14718
14719
14720
14721
14722
14723
14724
14725
14726
14727
14728
14729
14730
14731
14732
14733
14734
14735
14736
14737
14738
14739
14740
14741
14742
14743
14744
14745
14746
14747
14748
14749
14750
14751
14752
14753
14754
14755
14756
14757
14758
14759
14760
14761
14762
14763
14764
14765
14766
14767
14768
14769
14770
14771
14772
14773
14774
14775
14776
14777
14778
14779
14780
14781
14782
14783
14784
14785
14786
14787
14788
14789
14790
14791
14792
14793
14794
14795
14796
14797
14798
14799
14800
14801
14802
14803
14804
14805
14806
14807
14808
14809
14810
14811
14812
14813
14814
14815
14816
14817
14818
14819
14820
14821
14822
14823
14824
14825
14826
14827
14828
14829
14830
14831
14832
14833
14834
14835
14836
14837
14838
14839
14840
14841
14842
14843
14844
14845
14846
14847
14848
14849
14850
14851
14852
14853
14854
14855
14856
14857
14858
14859
14860
14861
14862
14863
14864
14865
14866
14867
14868
14869
14870
14871
14872
14873
14874
14875
14876
14877
14878
14879
14880
14881
14882
14883
14884
14885
14886
14887
14888
14889
14890
14891
14892
14893
14894
14895
14896
14897
14898
14899
14900
14901
14902
14903
14904
14905
14906
14907
14908
14909
14910
14911
14912
14913
14914
14915
14916
14917
14918
14919
14920
14921
14922
14923
14924
14925
14926
14927
14928
14929
14930
14931
14932
14933
14934
14935
14936
14937
14938
14939
14940
14941
14942
14943
14944
14945
14946
14947
14948
14949
14950
14951
14952
14953
14954
14955
14956
14957
14958
14959
14960
14961
14962
14963
14964
14965
14966
14967
14968
14969
14970
14971
14972
14973
14974
14975
14976
14977
14978
14979
14980
14981
14982
14983
14984
14985
14986
14987
14988
14989
14990
14991
14992
14993
14994
14995
14996
14997
14998
14999
15000
15001
15002
15003
15004
15005
15006
15007
15008
15009
15010
15011
15012
15013
15014
15015
15016
15017
15018
15019
15020
15021
15022
15023
15024
15025
15026
15027
15028
15029
15030
15031
15032
15033
15034
15035
15036
15037
15038
15039
15040
15041
15042
15043
15044
15045
15046
15047
15048
15049
15050
15051
15052
15053
15054
15055
15056
15057
15058
15059
15060
15061
15062
15063
15064
15065
15066
15067
15068
15069
15070
15071
15072
15073
15074
15075
15076
15077
15078
15079
15080
15081
15082
15083
15084
15085
15086
15087
15088
15089
15090
15091
15092
15093
15094
15095
15096
15097
15098
15099
15100
15101
15102
15103
15104
15105
15106
15107
15108
15109
15110
15111
15112
15113
15114
15115
15116
15117
15118
15119
15120
15121
15122
15123
15124
15125
15126
15127
15128
15129
15130
15131
15132
15133
15134
15135
15136
15137
15138
15139
15140
15141
15142
15143
15144
15145
15146
15147
15148
15149
15150
15151
15152
15153
15154
15155
15156
15157
15158
15159
15160
15161
15162
15163
15164
15165
15166
15167
15168
15169
15170
15171
15172
15173
15174
15175
15176
15177
15178
15179
15180
15181
15182
15183
15184
15185
15186
15187
15188
15189
15190
15191
15192
15193
15194
15195
15196
15197
15198
15199
15200
15201
15202
15203
15204
15205
15206
15207
15208
15209
15210
15211
15212
15213
15214
15215
15216
15217
15218
15219
15220
15221
15222
15223
15224
15225
15226
15227
15228
15229
15230
15231
15232
15233
15234
15235
15236
15237
15238
15239
15240
15241
15242
15243
15244
15245
15246
15247
15248
15249
15250
15251
15252
15253
15254
15255
15256
15257
15258
15259
15260
15261
15262
15263
15264
15265
15266
15267
15268
15269
15270
15271
15272
15273
15274
15275
15276
15277
15278
15279
15280
15281
15282
15283
15284
15285
15286
15287
15288
15289
15290
15291
15292
15293
15294
15295
15296
15297
15298
15299
15300
15301
15302
15303
15304
15305
15306
15307
15308
15309
15310
15311
15312
15313
15314
15315
15316
15317
15318
15319
15320
15321
15322
15323
15324
15325
15326
15327
15328
15329
15330
15331
15332
15333
15334
15335
15336
15337
15338
15339
15340
15341
15342
15343
15344
15345
15346
15347
15348
15349
15350
15351
15352
15353
15354
15355
15356
15357
15358
15359
15360
15361
15362
15363
15364
15365
15366
15367
15368
15369
15370
15371
15372
15373
15374
15375
15376
15377
15378
15379
15380
15381
15382
15383
15384
15385
15386
15387
15388
15389
15390
15391
15392
15393
15394
15395
15396
15397
15398
15399
15400
15401
15402
15403
15404
15405
15406
15407
15408
15409
15410
15411
15412
15413
15414
15415
15416
15417
15418
15419
15420
15421
15422
15423
15424
15425
15426
15427
15428
15429
15430
15431
15432
15433
15434
15435
15436
15437
15438
15439
15440
15441
15442
15443
15444
15445
15446
15447
15448
15449
15450
15451
15452
15453
15454
15455
15456
15457
15458
15459
15460
15461
15462
15463
15464
15465
15466
15467
15468
15469
15470
15471
15472
15473
15474
15475
15476
15477
15478
15479
15480
15481
15482
15483
15484
15485
15486
15487
15488
15489
15490
15491
15492
15493
15494
15495
15496
15497
15498
15499
15500
15501
15502
15503
15504
15505
15506
15507
15508
15509
15510
15511
15512
15513
15514
15515
15516
15517
15518
15519
15520
15521
15522
15523
15524
15525
15526
15527
15528
15529
15530
15531
15532
15533
15534
15535
15536
15537
15538
15539
15540
15541
15542
15543
15544
15545
15546
15547
15548
15549
15550
15551
15552
15553
15554
15555
15556
15557
15558
15559
15560
15561
15562
15563
15564
15565
15566
15567
15568
15569
15570
15571
15572
15573
15574
15575
15576
15577
15578
15579
15580
15581
15582
15583
15584
15585
15586
15587
15588
15589
15590
15591
15592
15593
15594
15595
15596
15597
15598
15599
15600
15601
15602
15603
15604
15605
15606
15607
15608
15609
15610
15611
15612
15613
15614
15615
15616
15617
15618
15619
15620
15621
15622
15623
15624
15625
15626
15627
15628
15629
15630
15631
15632
15633
15634
15635
15636
15637
15638
15639
15640
15641
15642
15643
15644
15645
15646
15647
15648
15649
15650
15651
15652
15653
15654
15655
15656
15657
15658
15659
15660
15661
15662
15663
15664
15665
15666
15667
15668
15669
15670
15671
15672
15673
15674
15675
15676
15677
15678
15679
15680
15681
15682
15683
15684
15685
15686
15687
15688
15689
15690
15691
15692
15693
15694
15695
15696
15697
15698
15699
15700
15701
15702
15703
15704
15705
15706
15707
15708
15709
15710
15711
15712
15713
15714
15715
15716
15717
15718
15719
15720
15721
15722
15723
15724
15725
15726
15727
15728
15729
15730
15731
15732
15733
15734
15735
15736
15737
15738
15739
15740
15741
15742
15743
15744
15745
15746
15747
15748
15749
15750
15751
15752
15753
15754
15755
15756
15757
15758
15759
15760
15761
15762
15763
15764
15765
15766
15767
15768
15769
15770
15771
15772
15773
15774
15775
15776
15777
15778
15779
15780
15781
15782
15783
15784
15785
15786
15787
15788
15789
15790
15791
15792
15793
15794
15795
15796
15797
15798
15799
15800
15801
15802
15803
15804
15805
15806
15807
15808
15809
15810
15811
15812
15813
15814
15815
15816
15817
15818
15819
15820
15821
15822
15823
15824
15825
15826
15827
15828
15829
15830
15831
15832
15833
15834
15835
15836
15837
15838
15839
15840
15841
15842
15843
15844
15845
15846
15847
15848
15849
15850
15851
15852
15853
15854
15855
15856
15857
15858
15859
15860
15861
15862
15863
15864
15865
15866
15867
15868
15869
15870
15871
15872
15873
15874
15875
15876
15877
15878
15879
15880
15881
15882
15883
15884
15885
15886
15887
15888
15889
15890
15891
15892
15893
15894
15895
15896
15897
15898
15899
15900
15901
15902
15903
15904
15905
15906
15907
15908
15909
15910
15911
15912
15913
15914
15915
15916
15917
15918
15919
15920
15921
15922
15923
15924
15925
15926
15927
15928
15929
15930
15931
15932
15933
15934
15935
15936
15937
15938
15939
15940
15941
15942
15943
15944
15945
15946
15947
15948
15949
15950
15951
15952
15953
15954
15955
15956
15957
15958
15959
15960
15961
15962
15963
15964
15965
15966
15967
15968
15969
15970
15971
15972
15973
15974
15975
15976
15977
15978
15979
15980
15981
15982
15983
15984
15985
15986
15987
15988
15989
15990
15991
15992
15993
15994
15995
15996
15997
15998
15999
16000
16001
16002
16003
16004
16005
16006
16007
16008
16009
16010
16011
16012
16013
16014
16015
16016
16017
16018
16019
16020
16021
16022
16023
16024
16025
16026
16027
16028
16029
16030
16031
16032
16033
16034
16035
16036
16037
16038
16039
16040
16041
16042
16043
16044
16045
16046
16047
16048
16049
16050
16051
16052
16053
16054
16055
16056
16057
16058
16059
16060
16061
16062
16063
16064
16065
16066
16067
16068
16069
16070
16071
16072
16073
16074
16075
16076
16077
16078
16079
16080
16081
16082
16083
16084
16085
16086
16087
16088
16089
16090
16091
16092
16093
16094
16095
16096
16097
16098
16099
16100
16101
16102
16103
16104
16105
16106
16107
16108
16109
16110
16111
16112
16113
16114
16115
16116
16117
16118
16119
16120
16121
16122
16123
16124
16125
16126
16127
16128
16129
16130
16131
16132
16133
16134
16135
16136
16137
16138
16139
16140
16141
16142
16143
16144
16145
16146
16147
16148
16149
16150
16151
16152
16153
16154
16155
16156
16157
16158
16159
16160
16161
16162
16163
16164
16165
16166
16167
16168
16169
16170
16171
16172
16173
16174
16175
16176
16177
16178
16179
16180
16181
16182
16183
16184
16185
16186
16187
16188
16189
16190
16191
16192
16193
16194
16195
16196
16197
16198
16199
16200
16201
16202
16203
16204
16205
16206
16207
16208
16209
16210
16211
16212
16213
16214
16215
16216
16217
16218
16219
16220
16221
16222
16223
16224
16225
16226
16227
16228
16229
16230
16231
16232
16233
16234
16235
16236
16237
16238
16239
16240
16241
16242
16243
16244
16245
16246
16247
16248
16249
16250
16251
16252
16253
16254
16255
16256
16257
16258
16259
16260
16261
16262
16263
16264
16265
16266
16267
16268
16269
16270
16271
16272
16273
16274
16275
16276
16277
16278
16279
16280
16281
16282
16283
16284
16285
16286
16287
16288
16289
16290
16291
16292
16293
16294
16295
16296
16297
16298
16299
16300
16301
16302
16303
16304
16305
16306
16307
16308
16309
16310
16311
16312
16313
16314
16315
16316
16317
16318
16319
16320
16321
16322
16323
16324
16325
16326
16327
16328
16329
16330
16331
16332
16333
16334
16335
16336
16337
16338
16339
16340
16341
16342
16343
16344
16345
16346
16347
16348
16349
16350
16351
16352
16353
16354
16355
16356
16357
16358
16359
16360
16361
16362
16363
16364
16365
16366
16367
16368
16369
16370
16371
16372
16373
16374
16375
16376
16377
16378
16379
16380
16381
16382
16383
16384
16385
16386
16387
16388
16389
16390
16391
16392
16393
16394
16395
16396
16397
16398
16399
16400
16401
16402
16403
16404
16405
16406
16407
16408
16409
16410
16411
16412
16413
16414
16415
16416
16417
16418
16419
16420
16421
16422
16423
16424
16425
16426
16427
16428
16429
16430
16431
16432
16433
16434
16435
16436
16437
16438
16439
16440
16441
16442
16443
16444
16445
16446
16447
16448
16449
16450
16451
16452
16453
16454
16455
16456
16457
16458
16459
16460
16461
16462
16463
16464
16465
16466
16467
16468
16469
16470
16471
16472
16473
16474
16475
16476
16477
16478
16479
16480
16481
16482
16483
16484
16485
16486
16487
16488
16489
16490
16491
16492
16493
16494
16495
16496
16497
16498
16499
16500
16501
16502
16503
16504
16505
16506
16507
16508
16509
16510
16511
16512
16513
16514
16515
16516
16517
16518
16519
16520
16521
16522
16523
16524
16525
16526
16527
16528
16529
16530
16531
16532
16533
16534
16535
16536
16537
16538
16539
16540
16541
16542
16543
16544
16545
16546
16547
16548
16549
16550
16551
16552
16553
16554
16555
16556
16557
16558
16559
16560
16561
16562
16563
16564
16565
16566
16567
16568
16569
16570
16571
16572
16573
16574
16575
16576
16577
16578
16579
16580
16581
16582
16583
16584
16585
16586
16587
16588
16589
16590
16591
16592
16593
16594
16595
16596
16597
16598
16599
16600
16601
16602
16603
16604
16605
16606
16607
16608
16609
16610
16611
16612
16613
16614
16615
16616
16617
16618
16619
16620
16621
16622
16623
16624
16625
16626
16627
16628
16629
16630
16631
16632
16633
16634
16635
16636
16637
16638
16639
16640
16641
16642
16643
16644
16645
16646
16647
16648
16649
16650
16651
16652
16653
16654
16655
16656
16657
16658
16659
16660
16661
16662
16663
16664
16665
16666
16667
16668
16669
16670
16671
16672
16673
16674
16675
16676
16677
16678
16679
16680
16681
16682
16683
16684
16685
16686
16687
16688
16689
16690
16691
16692
16693
16694
16695
16696
16697
16698
16699
16700
16701
16702
16703
16704
16705
16706
16707
16708
16709
16710
16711
16712
16713
16714
16715
16716
16717
16718
16719
16720
16721
16722
16723
16724
16725
16726
16727
16728
16729
16730
16731
16732
16733
16734
16735
16736
16737
16738
16739
16740
16741
16742
16743
16744
16745
16746
16747
16748
16749
16750
16751
16752
16753
16754
16755
16756
16757
16758
16759
16760
16761
16762
16763
16764
16765
16766
16767
16768
16769
16770
16771
16772
16773
16774
16775
16776
16777
16778
16779
16780
16781
16782
16783
16784
16785
16786
16787
16788
16789
16790
16791
16792
16793
16794
16795
16796
16797
16798
16799
16800
16801
16802
16803
16804
16805
16806
16807
16808
16809
16810
16811
16812
16813
16814
16815
16816
16817
16818
16819
16820
16821
16822
16823
16824
16825
16826
16827
16828
16829
16830
16831
16832
16833
16834
16835
16836
16837
16838
16839
16840
16841
16842
16843
16844
16845
16846
16847
16848
16849
16850
16851
16852
16853
16854
16855
16856
16857
16858
16859
16860
16861
16862
16863
16864
16865
16866
16867
16868
16869
16870
16871
16872
16873
16874
16875
16876
16877
16878
16879
16880
16881
16882
16883
16884
16885
16886
16887
16888
16889
16890
16891
16892
16893
16894
16895
16896
16897
16898
16899
16900
16901
16902
16903
16904
16905
16906
16907
16908
16909
16910
16911
16912
16913
16914
16915
16916
16917
16918
16919
16920
16921
16922
16923
16924
16925
16926
16927
16928
16929
16930
16931
16932
16933
16934
16935
16936
16937
16938
16939
16940
16941
16942
16943
16944
16945
16946
16947
16948
16949
16950
16951
16952
16953
16954
16955
16956
16957
16958
16959
16960
16961
16962
16963
16964
16965
16966
16967
16968
16969
16970
16971
16972
16973
16974
16975
16976
16977
16978
16979
16980
16981
16982
16983
16984
16985
16986
16987
16988
16989
16990
16991
16992
16993
16994
16995
16996
16997
16998
16999
17000
17001
17002
17003
17004
17005
17006
17007
17008
17009
17010
17011
17012
17013
17014
17015
17016
17017
17018
17019
17020
17021
17022
17023
17024
17025
17026
17027
17028
17029
17030
17031
17032
17033
17034
17035
17036
17037
17038
17039
17040
17041
17042
17043
17044
17045
17046
17047
17048
17049
17050
17051
17052
17053
17054
17055
17056
17057
17058
17059
17060
17061
17062
17063
17064
17065
17066
17067
17068
17069
17070
17071
17072
17073
17074
17075
17076
17077
17078
17079
17080
17081
17082
17083
17084
17085
17086
17087
17088
17089
17090
17091
17092
17093
17094
17095
17096
17097
17098
17099
17100
17101
17102
17103
17104
17105
17106
17107
17108
17109
17110
17111
17112
17113
17114
17115
17116
17117
17118
17119
17120
17121
17122
17123
17124
17125
17126
17127
17128
17129
17130
17131
17132
17133
17134
17135
17136
17137
17138
17139
17140
17141
17142
17143
17144
17145
17146
17147
17148
17149
17150
17151
17152
17153
17154
17155
17156
17157
17158
17159
17160
17161
17162
17163
17164
17165
17166
17167
17168
17169
17170
17171
17172
17173
17174
17175
17176
17177
17178
17179
17180
17181
17182
17183
17184
17185
17186
17187
17188
17189
17190
17191
17192
17193
17194
17195
17196
17197
17198
17199
17200
17201
17202
17203
17204
17205
17206
17207
17208
17209
17210
17211
17212
17213
17214
17215
17216
17217
17218
17219
17220
17221
17222
17223
17224
17225
17226
17227
17228
17229
17230
17231
17232
17233
17234
17235
17236
17237
17238
17239
17240
17241
17242
17243
17244
17245
17246
17247
17248
17249
17250
17251
17252
17253
17254
17255
17256
17257
17258
17259
17260
17261
17262
17263
17264
17265
17266
17267
17268
17269
17270
17271
17272
17273
17274
17275
17276
17277
17278
17279
17280
17281
17282
17283
17284
17285
17286
17287
17288
17289
17290
17291
17292
17293
17294
17295
17296
17297
17298
17299
17300
17301
17302
17303
17304
17305
17306
17307
17308
17309
17310
17311
17312
17313
17314
17315
17316
17317
17318
17319
17320
17321
17322
17323
17324
17325
17326
17327
17328
17329
17330
17331
17332
17333
17334
17335
17336
17337
17338
17339
17340
17341
17342
17343
17344
17345
17346
17347
17348
17349
17350
17351
17352
17353
17354
17355
17356
17357
17358
17359
17360
17361
17362
17363
17364
17365
17366
17367
17368
17369
17370
17371
17372
17373
17374
17375
17376
17377
17378
17379
17380
17381
17382
17383
17384
17385
17386
17387
17388
17389
17390
17391
17392
17393
17394
17395
17396
17397
17398
17399
17400
17401
17402
17403
17404
17405
17406
17407
17408
17409
17410
17411
17412
17413
17414
17415
17416
17417
17418
17419
17420
17421
17422
17423
17424
17425
17426
17427
17428
17429
17430
17431
17432
17433
17434
17435
17436
17437
17438
17439
17440
17441
17442
17443
17444
17445
17446
17447
17448
17449
17450
17451
17452
17453
17454
17455
17456
17457
17458
17459
17460
17461
17462
17463
17464
17465
17466
17467
17468
17469
17470
17471
17472
17473
17474
17475
17476
17477
17478
17479
17480
17481
17482
17483
17484
17485
17486
17487
17488
17489
17490
17491
17492
17493
17494
17495
17496
17497
17498
17499
17500
17501
17502
17503
17504
17505
17506
17507
17508
17509
17510
17511
17512
17513
17514
17515
17516
17517
17518
17519
17520
17521
17522
17523
17524
17525
17526
17527
17528
17529
17530
17531
17532
17533
17534
17535
17536
17537
17538
17539
17540
17541
17542
17543
17544
17545
17546
17547
17548
17549
17550
17551
17552
17553
17554
17555
17556
17557
17558
17559
17560
17561
17562
17563
17564
17565
17566
17567
17568
17569
17570
17571
17572
17573
17574
17575
17576
17577
17578
17579
17580
17581
17582
17583
17584
17585
17586
17587
17588
17589
17590
17591
17592
17593
17594
17595
17596
17597
17598
17599
17600
17601
17602
17603
17604
17605
17606
17607
17608
17609
17610
17611
17612
17613
17614
17615
17616
17617
17618
17619
17620
17621
17622
17623
17624
17625
17626
17627
17628
17629
17630
17631
17632
17633
17634
17635
17636
17637
17638
17639
17640
17641
17642
17643
17644
17645
17646
17647
17648
17649
17650
17651
17652
17653
17654
17655
17656
17657
17658
17659
17660
17661
17662
17663
17664
17665
17666
17667
17668
17669
17670
17671
17672
17673
17674
17675
17676
17677
17678
17679
17680
17681
17682
17683
17684
17685
17686
17687
17688
17689
17690
17691
17692
17693
17694
17695
17696
17697
17698
17699
17700
17701
17702
17703
17704
17705
17706
17707
17708
17709
17710
17711
17712
17713
17714
17715
17716
17717
17718
17719
17720
17721
17722
17723
17724
17725
17726
17727
17728
17729
17730
17731
17732
17733
17734
17735
17736
17737
17738
17739
17740
17741
17742
17743
17744
17745
17746
17747
17748
17749
17750
17751
17752
17753
17754
17755
17756
17757
17758
17759
17760
17761
17762
17763
17764
17765
17766
17767
17768
17769
17770
17771
17772
17773
17774
17775
17776
17777
17778
17779
17780
17781
17782
17783
17784
17785
17786
17787
17788
17789
17790
17791
17792
17793
17794
17795
17796
17797
17798
17799
17800
17801
17802
17803
17804
17805
17806
17807
17808
17809
17810
17811
17812
17813
17814
17815
17816
17817
17818
17819
17820
17821
17822
17823
17824
17825
17826
17827
17828
17829
17830
17831
17832
17833
17834
17835
17836
17837
17838
17839
17840
17841
17842
17843
17844
17845
17846
17847
17848
17849
17850
17851
17852
17853
17854
17855
17856
17857
17858
17859
17860
17861
17862
17863
17864
17865
17866
17867
17868
17869
17870
17871
17872
17873
17874
17875
17876
17877
17878
17879
17880
17881
17882
17883
17884
17885
17886
17887
17888
17889
17890
17891
17892
17893
17894
17895
17896
17897
17898
17899
17900
17901
17902
17903
17904
17905
17906
17907
17908
17909
17910
17911
17912
17913
17914
17915
17916
17917
17918
17919
17920
17921
17922
17923
17924
17925
17926
17927
17928
17929
17930
17931
17932
17933
17934
17935
17936
17937
17938
17939
17940
17941
17942
17943
17944
17945
17946
17947
17948
17949
17950
17951
17952
17953
17954
17955
17956
17957
17958
17959
17960
17961
17962
17963
17964
17965
17966
17967
17968
17969
17970
17971
17972
17973
17974
17975
17976
17977
17978
17979
17980
17981
17982
17983
17984
17985
17986
17987
17988
17989
17990
17991
17992
17993
17994
17995
17996
17997
17998
17999
18000
18001
18002
18003
18004
18005
18006
18007
18008
18009
18010
18011
18012
18013
18014
18015
18016
18017
18018
18019
18020
18021
18022
18023
18024
18025
18026
18027
18028
18029
18030
18031
18032
18033
18034
18035
18036
18037
18038
18039
18040
18041
18042
18043
18044
18045
18046
18047
18048
18049
18050
18051
18052
18053
18054
18055
18056
18057
18058
18059
18060
18061
18062
18063
18064
18065
18066
18067
18068
18069
18070
18071
18072
18073
18074
18075
18076
18077
18078
18079
18080
18081
18082
18083
18084
18085
18086
18087
18088
18089
18090
18091
18092
18093
18094
18095
18096
18097
18098
18099
18100
18101
18102
18103
18104
18105
18106
18107
18108
18109
18110
18111
18112
18113
18114
18115
18116
18117
18118
18119
18120
18121
18122
18123
18124
18125
18126
18127
18128
18129
18130
18131
18132
18133
18134
18135
18136
18137
18138
18139
18140
18141
18142
18143
18144
18145
18146
18147
18148
18149
18150
18151
18152
18153
18154
18155
18156
18157
18158
18159
18160
18161
18162
18163
18164
18165
18166
18167
18168
18169
18170
18171
18172
18173
18174
18175
18176
18177
18178
18179
18180
18181
18182
18183
18184
18185
18186
18187
18188
18189
18190
18191
18192
18193
18194
18195
18196
18197
18198
18199
18200
18201
18202
18203
18204
18205
18206
18207
18208
18209
18210
18211
18212
18213
18214
18215
18216
18217
18218
18219
18220
18221
18222
18223
18224
18225
18226
18227
18228
18229
18230
18231
18232
18233
18234
18235
18236
18237
18238
18239
18240
18241
18242
18243
18244
18245
18246
18247
18248
18249
18250
18251
18252
18253
18254
18255
18256
18257
18258
18259
18260
18261
18262
18263
18264
18265
18266
18267
18268
18269
18270
18271
18272
18273
18274
18275
18276
18277
18278
18279
18280
18281
18282
18283
18284
18285
18286
18287
18288
18289
18290
18291
18292
18293
18294
18295
18296
18297
18298
18299
18300
18301
18302
18303
18304
18305
18306
18307
18308
18309
18310
18311
18312
18313
18314
18315
18316
18317
18318
18319
18320
18321
18322
18323
18324
18325
18326
18327
18328
18329
18330
18331
18332
18333
18334
18335
18336
18337
18338
18339
18340
18341
18342
18343
18344
18345
18346
18347
18348
18349
18350
18351
18352
18353
18354
18355
18356
18357
18358
18359
18360
18361
18362
18363
18364
18365
18366
18367
18368
18369
18370
18371
18372
18373
18374
18375
18376
18377
18378
18379
18380
18381
18382
18383
18384
18385
18386
18387
18388
18389
18390
18391
18392
18393
18394
18395
18396
18397
18398
18399
18400
18401
18402
18403
18404
18405
18406
18407
18408
18409
18410
18411
18412
18413
18414
18415
18416
18417
18418
18419
18420
18421
18422
18423
18424
18425
18426
18427
18428
18429
18430
18431
18432
18433
18434
18435
18436
18437
18438
18439
18440
18441
18442
18443
18444
18445
18446
18447
18448
18449
18450
18451
18452
18453
18454
18455
18456
18457
18458
18459
18460
18461
18462
18463
18464
18465
18466
18467
18468
18469
18470
18471
18472
18473
18474
18475
18476
18477
18478
18479
18480
18481
18482
18483
18484
18485
18486
18487
18488
18489
18490
18491
18492
18493
18494
18495
18496
18497
18498
18499
18500
18501
18502
18503
18504
18505
18506
18507
18508
18509
18510
18511
18512
18513
18514
18515
18516
18517
18518
18519
18520
18521
18522
18523
18524
18525
18526
18527
18528
18529
18530
18531
18532
18533
18534
18535
18536
18537
18538
18539
18540
18541
18542
18543
18544
18545
18546
18547
18548
18549
18550
18551
18552
18553
18554
18555
18556
18557
18558
18559
18560
18561
18562
18563
18564
18565
18566
18567
18568
18569
18570
18571
18572
18573
18574
18575
18576
18577
18578
18579
18580
18581
18582
18583
18584
18585
18586
18587
18588
18589
18590
18591
18592
18593
18594
18595
18596
18597
18598
18599
18600
18601
18602
18603
18604
18605
18606
18607
18608
18609
18610
18611
18612
18613
18614
18615
18616
18617
18618
18619
18620
18621
18622
18623
18624
18625
18626
18627
18628
18629
18630
18631
18632
18633
18634
18635
18636
18637
18638
18639
18640
18641
18642
18643
18644
18645
18646
18647
18648
18649
18650
18651
18652
18653
18654
18655
18656
18657
18658
18659
18660
18661
18662
18663
18664
18665
18666
18667
18668
18669
18670
18671
18672
18673
18674
18675
18676
18677
18678
18679
18680
18681
18682
18683
18684
18685
18686
18687
18688
18689
18690
18691
18692
18693
18694
18695
18696
18697
18698
18699
18700
18701
18702
18703
18704
18705
18706
18707
18708
18709
18710
18711
18712
18713
18714
18715
18716
18717
18718
18719
18720
18721
18722
18723
18724
18725
18726
18727
18728
18729
18730
18731
18732
18733
18734
18735
18736
18737
18738
18739
18740
18741
18742
18743
18744
18745
18746
18747
18748
18749
18750
18751
18752
18753
18754
18755
18756
18757
18758
18759
18760
18761
18762
18763
18764
18765
18766
18767
18768
18769
18770
18771
18772
18773
18774
18775
18776
18777
18778
18779
18780
18781
18782
18783
18784
18785
18786
18787
18788
18789
18790
18791
18792
18793
18794
18795
18796
18797
18798
18799
18800
18801
18802
18803
18804
18805
18806
18807
18808
18809
18810
18811
18812
18813
18814
18815
18816
18817
18818
18819
18820
18821
18822
18823
18824
18825
18826
18827
18828
18829
18830
18831
18832
18833
18834
18835
18836
18837
18838
18839
18840
18841
18842
18843
18844
18845
18846
18847
18848
18849
18850
18851
18852
18853
18854
18855
18856
18857
18858
18859
18860
18861
18862
18863
18864
18865
18866
18867
18868
18869
18870
18871
18872
18873
18874
18875
18876
18877
18878
18879
18880
18881
18882
18883
18884
18885
18886
18887
18888
18889
18890
18891
18892
18893
18894
18895
18896
18897
18898
18899
18900
18901
18902
18903
18904
18905
18906
18907
18908
18909
18910
18911
18912
18913
18914
18915
18916
18917
18918
18919
18920
18921
18922
18923
18924
18925
18926
18927
18928
18929
18930
18931
18932
18933
18934
18935
18936
18937
18938
18939
18940
18941
18942
18943
18944
18945
18946
18947
18948
18949
18950
18951
18952
18953
18954
18955
18956
18957
18958
18959
18960
18961
18962
18963
18964
18965
18966
18967
18968
18969
18970
18971
18972
18973
18974
18975
18976
18977
18978
18979
18980
18981
18982
18983
18984
18985
18986
18987
18988
18989
18990
18991
18992
18993
18994
18995
18996
18997
18998
18999
19000
19001
19002
19003
19004
19005
19006
19007
19008
19009
19010
19011
19012
19013
19014
19015
19016
19017
19018
19019
19020
19021
19022
19023
19024
19025
19026
19027
19028
19029
19030
19031
19032
19033
19034
19035
19036
19037
19038
19039
19040
19041
19042
19043
19044
19045
19046
19047
19048
19049
19050
19051
19052
19053
19054
19055
19056
19057
19058
19059
19060
19061
19062
19063
19064
19065
19066
19067
19068
19069
19070
19071
19072
19073
19074
19075
19076
19077
19078
19079
19080
19081
19082
19083
19084
19085
19086
19087
19088
19089
19090
19091
19092
19093
19094
19095
19096
19097
19098
19099
19100
19101
19102
19103
19104
19105
19106
19107
19108
19109
19110
19111
19112
19113
19114
19115
19116
19117
19118
19119
19120
19121
19122
19123
19124
19125
19126
19127
19128
19129
19130
19131
19132
19133
19134
19135
19136
19137
19138
19139
19140
19141
19142
19143
19144
19145
19146
19147
19148
19149
19150
19151
19152
19153
19154
19155
19156
19157
19158
19159
19160
19161
19162
19163
19164
19165
19166
19167
19168
19169
19170
19171
19172
19173
19174
19175
19176
19177
19178
19179
19180
19181
19182
19183
19184
19185
19186
19187
19188
19189
19190
19191
19192
19193
19194
19195
19196
19197
19198
19199
19200
19201
19202
19203
19204
19205
19206
19207
19208
19209
19210
19211
19212
19213
19214
19215
19216
19217
19218
19219
19220
19221
19222
19223
19224
19225
19226
19227
19228
19229
19230
19231
19232
19233
19234
19235
19236
19237
19238
19239
19240
19241
19242
19243
19244
19245
19246
19247
19248
19249
19250
19251
19252
19253
19254
19255
19256
19257
19258
19259
19260
19261
19262
19263
19264
19265
19266
19267
19268
19269
19270
19271
19272
19273
19274
19275
19276
19277
19278
19279
19280
19281
19282
19283
19284
19285
19286
19287
19288
19289
19290
19291
19292
19293
19294
19295
19296
19297
19298
19299
19300
19301
19302
19303
19304
19305
19306
19307
19308
19309
19310
19311
19312
19313
19314
19315
19316
19317
19318
19319
19320
19321
19322
19323
19324
19325
19326
19327
19328
19329
19330
19331
19332
19333
19334
19335
19336
19337
19338
19339
19340
19341
19342
19343
19344
19345
19346
19347
19348
19349
19350
19351
19352
19353
19354
19355
19356
19357
19358
19359
19360
19361
19362
19363
19364
19365
19366
19367
19368
19369
19370
19371
19372
19373
19374
19375
19376
19377
19378
19379
19380
19381
19382
19383
19384
19385
19386
19387
19388
19389
19390
19391
19392
19393
19394
19395
19396
19397
19398
19399
19400
19401
19402
19403
19404
19405
19406
19407
19408
19409
19410
19411
19412
19413
19414
19415
19416
19417
19418
19419
19420
19421
19422
19423
19424
19425
19426
19427
19428
19429
19430
19431
19432
19433
19434
19435
19436
19437
19438
19439
19440
19441
19442
19443
19444
19445
19446
19447
19448
19449
19450
19451
19452
19453
19454
19455
19456
19457
19458
19459
19460
19461
19462
19463
19464
19465
19466
19467
19468
19469
19470
19471
19472
19473
19474
19475
19476
19477
19478
19479
19480
19481
19482
19483
19484
19485
19486
19487
19488
19489
19490
19491
19492
19493
19494
19495
19496
19497
19498
19499
19500
19501
19502
19503
19504
19505
19506
19507
19508
19509
19510
19511
19512
19513
19514
19515
19516
19517
19518
19519
19520
19521
19522
19523
19524
19525
19526
19527
19528
19529
19530
19531
19532
19533
19534
19535
19536
19537
19538
19539
19540
19541
19542
19543
19544
19545
19546
19547
19548
19549
19550
19551
19552
19553
19554
19555
19556
19557
19558
19559
19560
19561
19562
19563
19564
19565
19566
19567
19568
19569
19570
19571
19572
19573
19574
19575
19576
19577
19578
19579
19580
19581
19582
19583
19584
19585
19586
19587
19588
19589
19590
19591
19592
19593
19594
19595
19596
19597
19598
19599
19600
19601
19602
19603
19604
19605
19606
19607
19608
19609
19610
19611
19612
19613
19614
19615
19616
19617
19618
19619
19620
19621
19622
19623
19624
19625
19626
19627
19628
19629
19630
19631
19632
19633
19634
19635
19636
19637
19638
19639
19640
19641
19642
19643
19644
19645
19646
19647
19648
19649
19650
19651
19652
19653
19654
19655
19656
19657
19658
19659
19660
19661
19662
19663
19664
19665
19666
19667
19668
19669
19670
19671
19672
19673
19674
19675
19676
19677
19678
19679
19680
19681
19682
19683
19684
19685
19686
19687
19688
19689
19690
19691
19692
19693
19694
19695
19696
19697
19698
19699
19700
19701
19702
19703
19704
19705
19706
19707
19708
19709
19710
19711
19712
19713
19714
19715
19716
19717
19718
19719
19720
19721
19722
19723
19724
19725
19726
19727
19728
19729
19730
19731
19732
19733
19734
19735
19736
19737
19738
19739
19740
19741
19742
19743
19744
19745
19746
19747
19748
19749
19750
19751
19752
19753
19754
19755
19756
19757
19758
19759
19760
19761
19762
19763
19764
19765
19766
19767
19768
19769
19770
19771
19772
19773
19774
19775
19776
19777
19778
19779
19780
19781
19782
19783
19784
19785
19786
19787
19788
19789
19790
19791
19792
19793
19794
19795
19796
19797
19798
19799
19800
19801
19802
19803
19804
19805
19806
19807
19808
19809
19810
19811
19812
19813
19814
19815
19816
19817
19818
19819
19820
19821
19822
19823
19824
19825
19826
19827
19828
19829
19830
19831
19832
19833
19834
19835
19836
19837
19838
19839
19840
19841
19842
19843
19844
19845
19846
19847
19848
19849
19850
19851
19852
19853
19854
19855
19856
19857
19858
19859
19860
19861
19862
19863
19864
19865
19866
19867
19868
19869
19870
19871
19872
19873
19874
19875
19876
19877
19878
19879
19880
19881
19882
19883
19884
19885
19886
19887
19888
19889
19890
19891
19892
19893
19894
19895
19896
19897
19898
19899
19900
19901
19902
19903
19904
19905
19906
19907
19908
19909
19910
19911
19912
19913
19914
19915
19916
19917
19918
19919
19920
19921
19922
19923
19924
19925
19926
19927
19928
19929
19930
19931
19932
19933
19934
19935
19936
19937
19938
19939
19940
19941
19942
19943
19944
19945
19946
19947
19948
19949
19950
19951
19952
19953
19954
19955
19956
19957
19958
19959
19960
19961
19962
19963
19964
19965
19966
19967
19968
19969
19970
19971
19972
19973
19974
19975
19976
19977
19978
19979
19980
19981
19982
19983
19984
19985
19986
19987
19988
19989
19990
19991
19992
19993
19994
19995
19996
19997
19998
19999
20000
20001
20002
20003
20004
20005
20006
20007
20008
20009
20010
20011
20012
20013
20014
20015
20016
20017
20018
20019
20020
20021
20022
20023
20024
20025
20026
20027
20028
20029
20030
20031
20032
20033
20034
20035
20036
20037
20038
20039
20040
20041
20042
20043
20044
20045
20046
20047
20048
20049
20050
20051
20052
20053
20054
20055
20056
20057
20058
20059
20060
20061
20062
20063
20064
20065
20066
20067
20068
20069
20070
20071
20072
20073
20074
20075
20076
20077
20078
20079
20080
20081
20082
20083
20084
20085
20086
20087
20088
20089
20090
20091
20092
20093
20094
20095
20096
20097
20098
20099
20100
20101
20102
20103
20104
20105
20106
20107
20108
20109
20110
20111
20112
20113
20114
20115
20116
20117
20118
20119
20120
20121
20122
20123
20124
20125
20126
20127
20128
20129
20130
20131
20132
20133
20134
20135
20136
20137
20138
20139
20140
20141
20142
20143
20144
20145
20146
20147
20148
20149
20150
20151
20152
20153
20154
20155
20156
20157
20158
20159
20160
20161
20162
20163
20164
20165
20166
20167
20168
20169
20170
20171
20172
20173
20174
20175
20176
20177
20178
20179
20180
20181
20182
20183
20184
20185
20186
20187
20188
20189
20190
20191
20192
20193
20194
20195
20196
20197
20198
20199
20200
20201
20202
20203
20204
20205
20206
20207
20208
20209
20210
20211
20212
20213
20214
20215
20216
20217
20218
20219
20220
20221
20222
20223
20224
20225
20226
20227
20228
20229
20230
20231
20232
20233
20234
20235
20236
20237
20238
20239
20240
20241
20242
20243
20244
20245
20246
20247
20248
20249
20250
20251
20252
20253
20254
20255
20256
20257
20258
20259
20260
20261
20262
20263
20264
20265
20266
20267
20268
20269
20270
20271
20272
20273
20274
20275
20276
20277
20278
20279
20280
20281
20282
20283
20284
20285
20286
20287
20288
20289
20290
20291
20292
20293
20294
20295
20296
20297
20298
20299
20300
20301
20302
20303
20304
20305
20306
20307
20308
20309
20310
20311
20312
20313
20314
20315
20316
20317
20318
20319
20320
20321
20322
20323
20324
20325
20326
20327
20328
20329
20330
20331
20332
20333
20334
20335
20336
20337
20338
20339
20340
20341
20342
20343
20344
20345
20346
20347
20348
20349
20350
20351
20352
20353
20354
20355
20356
20357
20358
20359
20360
20361
20362
20363
20364
20365
20366
20367
20368
20369
20370
20371
20372
20373
20374
20375
20376
20377
20378
20379
20380
20381
20382
20383
20384
20385
20386
20387
20388
20389
20390
20391
20392
20393
20394
20395
20396
20397
20398
20399
20400
20401
20402
20403
20404
20405
20406
20407
20408
20409
20410
20411
20412
20413
20414
20415
20416
20417
20418
20419
20420
20421
20422
20423
20424
20425
20426
20427
20428
20429
20430
20431
20432
20433
20434
20435
20436
20437
20438
20439
20440
20441
20442
20443
20444
20445
20446
20447
20448
20449
20450
20451
20452
20453
20454
20455
20456
20457
20458
20459
20460
20461
20462
20463
20464
20465
20466
20467
20468
20469
20470
20471
20472
20473
20474
20475
20476
20477
20478
20479
20480
20481
20482
20483
20484
20485
20486
20487
20488
20489
20490
20491
20492
20493
20494
20495
20496
20497
20498
20499
20500
20501
20502
20503
20504
20505
20506
20507
20508
20509
20510
20511
20512
20513
20514
20515
20516
20517
20518
20519
20520
20521
20522
20523
20524
20525
20526
20527
20528
20529
20530
20531
20532
20533
20534
20535
20536
20537
20538
20539
20540
20541
20542
20543
20544
20545
20546
20547
20548
20549
20550
20551
20552
20553
20554
20555
20556
20557
20558
20559
20560
20561
20562
20563
20564
20565
20566
20567
20568
20569
20570
20571
20572
20573
20574
20575
20576
20577
20578
20579
20580
20581
20582
20583
20584
20585
20586
20587
20588
20589
20590
20591
20592
20593
20594
20595
20596
20597
20598
20599
20600
20601
20602
20603
20604
20605
20606
20607
20608
20609
20610
20611
20612
20613
20614
20615
20616
20617
20618
20619
20620
20621
20622
20623
20624
20625
20626
20627
20628
20629
20630
20631
20632
20633
20634
20635
20636
20637
20638
20639
20640
20641
20642
20643
20644
20645
20646
20647
20648
20649
20650
20651
20652
20653
20654
20655
20656
20657
20658
20659
20660
20661
20662
20663
20664
20665
20666
20667
20668
20669
20670
20671
20672
20673
20674
20675
20676
20677
20678
20679
20680
20681
20682
20683
20684
20685
20686
20687
20688
20689
20690
20691
20692
20693
20694
20695
20696
20697
20698
20699
20700
20701
20702
20703
20704
20705
20706
20707
20708
20709
20710
20711
20712
20713
20714
20715
20716
20717
20718
20719
20720
20721
20722
20723
20724
20725
20726
20727
20728
20729
20730
20731
20732
20733
20734
20735
20736
20737
20738
20739
20740
20741
20742
20743
20744
20745
20746
20747
20748
20749
20750
20751
20752
20753
20754
20755
20756
20757
20758
20759
20760
20761
20762
20763
20764
20765
20766
20767
20768
20769
20770
20771
20772
20773
20774
20775
20776
20777
20778
20779
20780
20781
20782
20783
20784
20785
20786
20787
20788
20789
20790
20791
20792
20793
20794
20795
20796
20797
20798
20799
20800
20801
20802
20803
20804
20805
20806
20807
20808
20809
20810
20811
20812
20813
20814
20815
20816
20817
20818
20819
20820
20821
20822
20823
20824
20825
20826
20827
20828
20829
20830
20831
20832
20833
20834
20835
20836
20837
20838
20839
20840
20841
20842
20843
20844
20845
20846
20847
20848
20849
20850
20851
20852
20853
20854
20855
20856
20857
20858
20859
20860
20861
20862
20863
20864
20865
20866
20867
20868
20869
20870
20871
20872
20873
20874
20875
20876
20877
20878
20879
20880
20881
20882
20883
20884
20885
20886
20887
20888
20889
20890
20891
20892
20893
20894
20895
20896
20897
20898
20899
20900
20901
20902
20903
20904
20905
20906
20907
20908
20909
20910
20911
20912
20913
20914
20915
20916
20917
20918
20919
20920
20921
20922
20923
20924
20925
20926
20927
20928
20929
20930
20931
20932
20933
20934
20935
20936
20937
20938
20939
20940
20941
20942
20943
20944
20945
20946
20947
20948
20949
20950
20951
20952
20953
20954
20955
20956
20957
20958
20959
20960
20961
20962
20963
20964
20965
20966
20967
20968
20969
20970
20971
20972
20973
20974
20975
20976
20977
20978
20979
20980
20981
20982
20983
20984
20985
20986
20987
20988
20989
20990
20991
20992
20993
20994
20995
20996
20997
20998
20999
21000
21001
21002
21003
21004
21005
21006
21007
21008
21009
21010
21011
21012
21013
21014
21015
21016
21017
21018
21019
21020
21021
21022
21023
21024
21025
21026
21027
21028
21029
21030
21031
21032
21033
21034
21035
21036
21037
21038
21039
21040
21041
21042
21043
21044
21045
21046
21047
21048
21049
21050
21051
21052
21053
21054
21055
21056
21057
21058
21059
21060
21061
21062
21063
21064
21065
21066
21067
21068
21069
21070
21071
21072
21073
21074
21075
21076
21077
21078
21079
21080
21081
21082
21083
21084
21085
21086
21087
21088
21089
21090
21091
21092
21093
21094
21095
21096
21097
21098
21099
21100
21101
21102
21103
21104
21105
21106
21107
21108
21109
21110
21111
21112
21113
21114
21115
21116
21117
21118
21119
21120
21121
21122
21123
21124
21125
21126
21127
21128
21129
21130
21131
21132
21133
21134
21135
21136
21137
21138
21139
21140
21141
21142
21143
21144
21145
21146
21147
21148
21149
21150
21151
21152
21153
21154
21155
21156
21157
21158
21159
21160
21161
21162
21163
21164
21165
21166
21167
21168
21169
21170
21171
21172
21173
21174
21175
21176
21177
21178
21179
21180
21181
21182
21183
21184
21185
21186
21187
21188
21189
21190
21191
21192
21193
21194
21195
21196
21197
21198
21199
21200
21201
21202
21203
21204
21205
21206
21207
21208
21209
21210
21211
21212
21213
21214
21215
21216
21217
21218
21219
21220
21221
21222
21223
21224
21225
21226
21227
21228
21229
21230
21231
21232
21233
21234
21235
21236
21237
21238
21239
21240
21241
21242
21243
21244
21245
21246
21247
21248
21249
21250
21251
21252
21253
21254
21255
21256
21257
21258
21259
21260
21261
21262
21263
21264
21265
21266
21267
21268
21269
21270
21271
21272
21273
21274
21275
21276
21277
21278
21279
21280
21281
21282
21283
21284
21285
21286
21287
21288
21289
21290
21291
21292
21293
21294
21295
21296
21297
21298
21299
21300
21301
21302
21303
21304
21305
21306
21307
21308
21309
21310
21311
21312
21313
21314
21315
21316
21317
21318
21319
21320
21321
21322
21323
21324
21325
21326
21327
21328
21329
21330
21331
21332
21333
21334
21335
21336
21337
21338
21339
21340
21341
21342
21343
21344
21345
21346
21347
21348
21349
21350
21351
21352
21353
21354
21355
21356
21357
21358
21359
21360
21361
21362
21363
21364
21365
21366
21367
21368
21369
21370
21371
21372
21373
21374
21375
21376
21377
21378
21379
21380
21381
21382
21383
21384
21385
21386
21387
21388
21389
21390
21391
21392
21393
21394
21395
21396
21397
21398
21399
21400
21401
21402
21403
21404
21405
21406
21407
21408
21409
21410
21411
21412
21413
21414
21415
21416
21417
21418
21419
21420
21421
21422
21423
21424
21425
21426
21427
21428
21429
21430
21431
21432
21433
21434
21435
21436
21437
21438
21439
21440
21441
21442
21443
21444
21445
21446
21447
21448
21449
21450
21451
21452
21453
21454
21455
21456
21457
21458
21459
21460
21461
21462
21463
21464
21465
21466
21467
21468
21469
21470
21471
21472
21473
21474
21475
21476
21477
21478
21479
21480
21481
21482
21483
21484
21485
21486
21487
21488
21489
21490
21491
21492
21493
21494
21495
21496
21497
21498
21499
21500
21501
21502
21503
21504
21505
21506
21507
21508
21509
21510
21511
21512
21513
21514
21515
21516
21517
21518
21519
21520
21521
21522
21523
21524
21525
21526
21527
21528
21529
21530
21531
21532
21533
21534
21535
21536
21537
21538
21539
21540
21541
21542
21543
21544
21545
21546
21547
21548
21549
21550
21551
21552
21553
21554
21555
21556
21557
21558
21559
21560
21561
21562
21563
21564
21565
21566
21567
21568
21569
21570
21571
21572
21573
21574
21575
21576
21577
21578
21579
21580
21581
21582
21583
21584
21585
21586
21587
21588
21589
21590
21591
21592
21593
21594
21595
21596
21597
21598
21599
21600
21601
21602
21603
21604
21605
21606
21607
21608
21609
21610
21611
21612
21613
21614
21615
21616
21617
21618
21619
21620
21621
21622
21623
21624
21625
21626
21627
21628
21629
21630
21631
21632
21633
21634
21635
21636
21637
21638
21639
21640
21641
21642
21643
21644
21645
21646
21647
21648
21649
21650
21651
21652
21653
21654
21655
21656
21657
21658
21659
21660
21661
21662
21663
21664
21665
21666
21667
21668
21669
21670
21671
21672
21673
21674
21675
21676
21677
21678
21679
21680
21681
21682
21683
21684
21685
21686
21687
21688
21689
21690
21691
21692
21693
21694
21695
21696
21697
21698
21699
21700
21701
21702
21703
21704
21705
21706
21707
21708
21709
21710
21711
21712
21713
21714
21715
21716
21717
21718
21719
21720
21721
21722
21723
21724
21725
21726
21727
21728
21729
21730
21731
21732
21733
21734
21735
21736
21737
21738
21739
21740
21741
21742
21743
21744
21745
21746
21747
21748
21749
21750
21751
21752
21753
21754
21755
21756
21757
21758
21759
21760
21761
21762
21763
21764
21765
21766
21767
21768
21769
21770
21771
21772
21773
21774
21775
21776
21777
21778
21779
21780
21781
21782
21783
21784
21785
21786
21787
21788
21789
21790
21791
21792
21793
21794
21795
21796
21797
21798
21799
21800
21801
21802
21803
21804
21805
21806
21807
21808
21809
21810
21811
21812
21813
21814
21815
21816
21817
21818
21819
21820
21821
21822
21823
21824
21825
21826
21827
21828
21829
21830
21831
21832
21833
21834
21835
21836
21837
21838
21839
21840
21841
21842
21843
21844
21845
21846
21847
21848
21849
21850
21851
21852
21853
21854
21855
21856
21857
21858
21859
21860
21861
21862
21863
21864
21865
21866
21867
21868
21869
21870
21871
21872
21873
21874
21875
21876
21877
21878
21879
21880
21881
21882
21883
21884
21885
21886
21887
21888
21889
21890
21891
21892
21893
21894
21895
21896
21897
21898
21899
21900
21901
21902
21903
21904
21905
21906
21907
21908
21909
21910
21911
21912
21913
21914
21915
21916
21917
21918
21919
21920
21921
21922
21923
21924
21925
21926
21927
21928
21929
21930
21931
21932
21933
21934
21935
21936
21937
21938
21939
21940
21941
21942
21943
21944
21945
21946
21947
21948
21949
21950
21951
21952
21953
21954
21955
21956
21957
21958
21959
21960
21961
21962
21963
21964
21965
21966
21967
21968
21969
21970
21971
21972
21973
21974
21975
21976
21977
21978
21979
21980
21981
21982
21983
21984
21985
21986
21987
21988
21989
21990
21991
21992
21993
21994
21995
21996
21997
21998
21999
22000
22001
22002
22003
22004
22005
22006
22007
22008
22009
22010
22011
22012
22013
22014
22015
22016
22017
22018
22019
22020
22021
22022
22023
22024
22025
22026
22027
22028
22029
22030
22031
22032
22033
22034
22035
22036
22037
22038
22039
22040
22041
22042
22043
22044
22045
22046
22047
22048
22049
22050
22051
22052
22053
22054
22055
22056
22057
22058
22059
22060
22061
22062
22063
22064
22065
22066
22067
22068
22069
22070
22071
22072
22073
22074
22075
22076
22077
22078
22079
22080
22081
22082
22083
22084
22085
22086
22087
22088
22089
22090
22091
22092
22093
22094
22095
22096
22097
22098
22099
22100
22101
22102
22103
22104
22105
22106
22107
22108
22109
22110
22111
22112
22113
22114
22115
22116
22117
22118
22119
22120
22121
22122
22123
22124
22125
22126
22127
22128
22129
22130
22131
22132
22133
22134
22135
22136
22137
22138
22139
22140
22141
22142
22143
22144
22145
22146
22147
22148
22149
22150
22151
22152
22153
22154
22155
22156
22157
22158
22159
22160
22161
22162
22163
22164
22165
22166
22167
22168
22169
22170
22171
22172
22173
22174
22175
22176
22177
22178
22179
22180
22181
22182
22183
22184
22185
22186
22187
22188
22189
22190
22191
22192
22193
22194
22195
22196
22197
22198
22199
22200
22201
22202
22203
22204
22205
22206
22207
22208
22209
22210
22211
22212
22213
22214
22215
22216
22217
22218
22219
22220
22221
22222
22223
22224
22225
22226
22227
22228
22229
22230
22231
22232
22233
22234
22235
22236
22237
22238
22239
22240
22241
22242
22243
22244
22245
22246
22247
22248
22249
22250
22251
22252
22253
22254
22255
22256
22257
22258
22259
22260
22261
22262
22263
22264
22265
22266
22267
22268
22269
22270
22271
22272
22273
22274
22275
22276
22277
22278
22279
22280
22281
22282
22283
22284
22285
22286
22287
22288
22289
22290
22291
22292
22293
22294
22295
22296
22297
22298
22299
22300
22301
22302
22303
22304
22305
22306
22307
22308
22309
22310
22311
22312
22313
22314
22315
22316
22317
22318
22319
22320
22321
22322
22323
22324
22325
22326
22327
22328
22329
22330
22331
22332
22333
22334
22335
22336
22337
22338
22339
22340
22341
22342
22343
22344
22345
22346
22347
22348
22349
22350
22351
22352
22353
22354
22355
22356
22357
22358
22359
22360
22361
22362
22363
22364
22365
22366
22367
22368
22369
22370
22371
22372
22373
22374
22375
22376
22377
22378
22379
22380
22381
22382
22383
22384
22385
22386
22387
22388
22389
22390
22391
22392
22393
22394
22395
22396
22397
22398
22399
22400
22401
22402
22403
22404
22405
22406
22407
22408
22409
22410
22411
22412
22413
22414
22415
22416
22417
22418
22419
22420
22421
22422
22423
22424
22425
22426
22427
22428
22429
22430
22431
22432
22433
22434
22435
22436
22437
22438
22439
22440
22441
22442
22443
22444
22445
22446
22447
22448
22449
22450
22451
22452
22453
22454
22455
22456
22457
22458
22459
22460
22461
22462
22463
22464
22465
22466
22467
22468
22469
22470
22471
22472
22473
22474
22475
22476
22477
22478
22479
22480
22481
22482
22483
22484
22485
22486
22487
22488
22489
22490
22491
22492
22493
22494
22495
22496
22497
22498
22499
22500
22501
22502
22503
22504
22505
22506
22507
22508
22509
22510
22511
22512
22513
22514
22515
22516
22517
22518
22519
22520
22521
22522
22523
22524
22525
22526
22527
22528
22529
22530
22531
22532
22533
22534
22535
22536
22537
22538
22539
22540
22541
22542
22543
22544
22545
22546
22547
22548
22549
22550
22551
22552
22553
22554
22555
22556
22557
22558
22559
22560
22561
22562
22563
22564
22565
22566
22567
22568
22569
22570
22571
22572
22573
22574
22575
22576
22577
22578
22579
22580
22581
22582
22583
22584
22585
22586
22587
22588
22589
22590
22591
22592
22593
22594
22595
22596
22597
22598
22599
22600
22601
22602
22603
22604
22605
22606
22607
22608
22609
22610
22611
22612
22613
22614
22615
22616
22617
22618
22619
22620
22621
22622
22623
22624
22625
22626
22627
22628
22629
22630
22631
22632
22633
22634
22635
22636
22637
22638
22639
22640
22641
22642
22643
22644
22645
22646
22647
22648
22649
22650
22651
22652
22653
22654
22655
22656
22657
22658
22659
22660
22661
22662
22663
22664
22665
22666
22667
22668
22669
22670
22671
22672
22673
22674
22675
22676
22677
22678
22679
22680
22681
22682
22683
22684
22685
22686
22687
22688
22689
22690
22691
22692
22693
22694
22695
22696
22697
22698
22699
22700
22701
22702
22703
22704
22705
22706
22707
22708
22709
22710
22711
22712
22713
22714
22715
22716
22717
22718
22719
22720
22721
22722
22723
22724
22725
22726
22727
22728
22729
22730
22731
22732
22733
22734
22735
22736
22737
22738
22739
22740
22741
22742
22743
22744
22745
22746
22747
22748
22749
22750
22751
22752
22753
22754
22755
22756
22757
22758
22759
22760
22761
22762
22763
22764
22765
22766
22767
22768
22769
22770
22771
22772
22773
22774
22775
22776
22777
22778
22779
22780
22781
22782
22783
22784
22785
22786
22787
22788
22789
22790
22791
22792
22793
22794
22795
22796
22797
22798
22799
22800
22801
22802
22803
22804
22805
22806
22807
22808
22809
22810
22811
22812
22813
22814
22815
22816
22817
22818
22819
22820
22821
22822
22823
22824
22825
22826
22827
22828
22829
22830
22831
22832
22833
22834
22835
22836
22837
22838
22839
22840
22841
22842
22843
22844
22845
22846
22847
22848
22849
22850
22851
22852
22853
22854
22855
22856
22857
22858
22859
22860
22861
22862
22863
22864
22865
22866
22867
22868
22869
22870
22871
22872
22873
22874
22875
22876
22877
22878
22879
22880
22881
22882
22883
22884
22885
22886
22887
22888
22889
22890
22891
22892
22893
22894
22895
22896
22897
22898
22899
22900
22901
22902
22903
22904
22905
22906
22907
22908
22909
22910
22911
22912
22913
22914
22915
22916
22917
22918
22919
22920
22921
22922
22923
22924
22925
22926
22927
22928
22929
22930
22931
22932
22933
22934
22935
22936
22937
22938
22939
22940
22941
22942
22943
22944
22945
22946
22947
22948
22949
22950
22951
22952
22953
22954
22955
22956
22957
22958
22959
22960
22961
22962
22963
22964
22965
22966
22967
22968
22969
22970
22971
22972
22973
22974
22975
22976
22977
22978
22979
22980
22981
22982
22983
22984
22985
22986
22987
22988
22989
22990
22991
22992
22993
22994
22995
22996
22997
22998
22999
23000
23001
23002
23003
23004
23005
23006
23007
23008
23009
23010
23011
23012
23013
23014
23015
23016
23017
23018
23019
23020
23021
23022
23023
23024
23025
23026
23027
23028
23029
23030
23031
23032
23033
23034
23035
23036
23037
23038
23039
23040
23041
23042
23043
23044
23045
23046
23047
23048
23049
23050
23051
23052
23053
23054
23055
23056
23057
23058
23059
23060
23061
23062
23063
23064
23065
23066
23067
23068
23069
23070
23071
23072
23073
23074
23075
23076
23077
23078
23079
23080
23081
23082
23083
23084
23085
23086
23087
23088
23089
23090
23091
23092
23093
23094
23095
23096
23097
23098
23099
23100
23101
23102
23103
23104
23105
23106
23107
23108
23109
23110
23111
23112
23113
23114
23115
23116
23117
23118
23119
23120
23121
23122
23123
23124
23125
23126
23127
23128
23129
23130
23131
23132
23133
23134
23135
23136
23137
23138
23139
23140
23141
23142
23143
23144
23145
23146
23147
23148
23149
23150
23151
23152
23153
23154
23155
23156
23157
23158
23159
23160
23161
23162
23163
23164
23165
23166
23167
23168
23169
23170
23171
23172
23173
23174
23175
23176
23177
23178
23179
23180
23181
23182
23183
23184
23185
23186
23187
23188
23189
23190
23191
23192
23193
23194
23195
23196
23197
23198
23199
23200
23201
23202
23203
23204
23205
23206
23207
23208
23209
23210
23211
23212
23213
23214
23215
23216
23217
23218
23219
23220
23221
23222
23223
23224
23225
23226
23227
23228
23229
23230
23231
23232
23233
23234
23235
23236
23237
23238
23239
23240
23241
23242
23243
23244
23245
23246
23247
23248
23249
23250
23251
23252
23253
23254
23255
23256
23257
23258
23259
23260
23261
23262
23263
23264
23265
23266
23267
23268
23269
23270
23271
23272
23273
23274
23275
23276
23277
23278
23279
23280
23281
23282
23283
23284
23285
23286
23287
23288
23289
23290
23291
23292
23293
23294
23295
23296
23297
23298
23299
23300
23301
23302
23303
23304
23305
23306
23307
23308
23309
23310
23311
23312
23313
23314
23315
23316
23317
23318
23319
23320
23321
23322
23323
23324
23325
23326
23327
23328
23329
23330
23331
23332
23333
23334
23335
23336
23337
23338
23339
23340
23341
23342
23343
23344
23345
23346
23347
23348
23349
23350
23351
23352
23353
23354
23355
23356
23357
23358
23359
23360
23361
23362
23363
23364
23365
23366
23367
23368
23369
23370
23371
23372
23373
23374
23375
23376
23377
23378
23379
23380
23381
23382
23383
23384
23385
23386
23387
23388
23389
23390
23391
23392
23393
23394
23395
23396
23397
23398
23399
23400
23401
23402
23403
23404
23405
23406
23407
23408
23409
23410
23411
23412
23413
23414
23415
23416
23417
23418
23419
23420
23421
23422
23423
23424
23425
23426
23427
23428
23429
23430
23431
23432
23433
23434
23435
23436
23437
23438
23439
23440
23441
23442
23443
23444
23445
23446
23447
23448
23449
23450
23451
23452
23453
23454
23455
23456
23457
23458
23459
23460
23461
23462
23463
23464
23465
23466
23467
23468
23469
23470
23471
23472
23473
23474
23475
23476
23477
23478
23479
23480
23481
23482
23483
23484
23485
23486
23487
23488
23489
23490
23491
23492
23493
23494
23495
23496
23497
23498
23499
23500
23501
23502
23503
23504
23505
23506
23507
23508
23509
23510
23511
23512
23513
23514
23515
23516
23517
23518
23519
23520
23521
23522
23523
23524
23525
23526
23527
23528
23529
23530
23531
23532
23533
23534
23535
23536
23537
23538
23539
23540
23541
23542
23543
23544
23545
23546
23547
23548
23549
23550
23551
23552
23553
23554
23555
23556
23557
23558
23559
23560
23561
23562
23563
23564
23565
23566
23567
23568
23569
23570
23571
23572
23573
23574
23575
23576
23577
23578
23579
23580
23581
23582
23583
23584
23585
23586
23587
23588
23589
23590
23591
23592
23593
23594
23595
23596
23597
23598
23599
23600
23601
23602
23603
23604
23605
23606
23607
23608
23609
23610
23611
23612
23613
23614
23615
23616
23617
23618
23619
23620
23621
23622
23623
23624
23625
23626
23627
23628
23629
23630
23631
23632
23633
23634
23635
23636
23637
23638
23639
23640
23641
23642
23643
23644
23645
23646
23647
23648
23649
23650
23651
23652
23653
23654
23655
23656
23657
23658
23659
23660
23661
23662
23663
23664
23665
23666
23667
23668
23669
23670
23671
23672
23673
23674
23675
23676
23677
23678
23679
23680
23681
23682
23683
23684
23685
23686
23687
23688
23689
23690
23691
23692
23693
23694
23695
23696
23697
23698
23699
23700
23701
23702
23703
23704
23705
23706
23707
23708
23709
23710
23711
23712
23713
23714
23715
23716
23717
23718
23719
23720
23721
23722
23723
23724
23725
23726
23727
23728
23729
23730
23731
23732
23733
23734
23735
23736
23737
23738
23739
23740
23741
23742
23743
23744
23745
23746
23747
23748
23749
23750
23751
23752
23753
23754
23755
23756
23757
23758
23759
23760
23761
23762
23763
23764
23765
23766
23767
23768
23769
23770
23771
23772
23773
23774
23775
23776
23777
23778
23779
23780
23781
23782
23783
23784
23785
23786
23787
23788
23789
23790
23791
23792
23793
23794
23795
23796
23797
23798
23799
23800
23801
23802
23803
23804
23805
23806
23807
23808
23809
23810
23811
23812
23813
23814
23815
23816
23817
23818
23819
23820
23821
23822
23823
23824
23825
23826
23827
23828
23829
23830
23831
23832
23833
23834
23835
23836
23837
23838
23839
23840
23841
23842
23843
23844
23845
23846
23847
23848
23849
23850
23851
23852
23853
23854
23855
23856
23857
23858
23859
23860
23861
23862
23863
23864
23865
23866
23867
23868
23869
23870
23871
23872
23873
23874
23875
23876
23877
23878
23879
23880
23881
23882
23883
23884
23885
23886
23887
23888
23889
23890
23891
23892
23893
23894
23895
23896
23897
23898
23899
23900
23901
23902
23903
23904
23905
23906
23907
23908
23909
23910
23911
23912
23913
23914
23915
23916
23917
23918
23919
23920
23921
23922
23923
23924
23925
23926
23927
23928
23929
23930
23931
23932
23933
23934
23935
23936
23937
23938
23939
23940
23941
23942
23943
23944
23945
23946
23947
23948
23949
23950
23951
23952
23953
23954
23955
23956
23957
23958
23959
23960
23961
23962
23963
23964
23965
23966
23967
23968
23969
23970
23971
23972
23973
23974
23975
23976
23977
23978
23979
23980
23981
23982
23983
23984
23985
23986
23987
23988
23989
23990
23991
23992
23993
23994
23995
23996
23997
23998
23999
24000
24001
24002
24003
24004
24005
24006
24007
24008
24009
24010
24011
24012
24013
24014
24015
24016
24017
24018
24019
24020
24021
24022
24023
24024
24025
24026
24027
24028
24029
24030
24031
24032
24033
24034
24035
24036
24037
24038
24039
24040
24041
24042
24043
24044
24045
24046
24047
24048
24049
24050
24051
24052
24053
24054
24055
24056
24057
24058
24059
24060
24061
24062
24063
24064
24065
24066
24067
24068
24069
24070
24071
24072
24073
24074
24075
24076
24077
24078
24079
24080
24081
24082
24083
24084
24085
24086
24087
24088
24089
24090
24091
24092
24093
24094
24095
24096
24097
24098
24099
24100
24101
24102
24103
24104
24105
24106
24107
24108
24109
24110
24111
24112
24113
24114
24115
24116
24117
24118
24119
24120
24121
24122
24123
24124
24125
24126
24127
24128
24129
24130
24131
24132
24133
24134
24135
24136
24137
24138
24139
24140
24141
24142
24143
24144
24145
24146
24147
24148
24149
24150
24151
24152
24153
24154
24155
24156
24157
24158
24159
24160
24161
24162
24163
24164
24165
24166
24167
24168
24169
24170
24171
24172
24173
24174
24175
24176
24177
24178
24179
24180
24181
24182
24183
24184
24185
24186
24187
24188
24189
24190
24191
24192
24193
24194
24195
24196
24197
24198
24199
24200
24201
24202
24203
24204
24205
24206
24207
24208
24209
24210
24211
24212
24213
24214
24215
24216
24217
24218
24219
24220
24221
24222
24223
24224
24225
24226
24227
24228
24229
24230
24231
24232
24233
24234
24235
24236
24237
24238
24239
24240
24241
24242
24243
24244
24245
24246
24247
24248
24249
24250
24251
24252
24253
24254
24255
24256
24257
24258
24259
24260
24261
24262
24263
24264
24265
24266
24267
24268
24269
24270
24271
24272
24273
24274
24275
24276
24277
24278
24279
24280
24281
24282
24283
24284
24285
24286
24287
24288
24289
24290
24291
24292
24293
24294
24295
24296
24297
24298
24299
24300
24301
24302
24303
24304
24305
24306
24307
24308
24309
24310
24311
24312
24313
24314
24315
24316
24317
24318
24319
24320
24321
24322
24323
24324
24325
24326
24327
24328
24329
24330
24331
24332
24333
24334
24335
24336
24337
24338
24339
24340
24341
24342
24343
24344
24345
24346
24347
24348
24349
24350
24351
24352
24353
24354
24355
24356
24357
24358
24359
24360
24361
24362
24363
24364
24365
24366
24367
24368
24369
24370
24371
24372
24373
24374
24375
24376
24377
24378
24379
24380
24381
24382
24383
24384
24385
24386
24387
24388
24389
24390
24391
24392
24393
24394
24395
24396
24397
24398
24399
24400
24401
24402
24403
24404
24405
24406
24407
24408
24409
24410
24411
24412
24413
24414
24415
24416
24417
24418
24419
24420
24421
24422
24423
24424
24425
24426
24427
24428
24429
24430
24431
24432
24433
24434
24435
24436
24437
24438
24439
24440
24441
24442
24443
24444
24445
24446
24447
24448
24449
24450
24451
24452
24453
24454
24455
24456
24457
24458
24459
24460
24461
24462
24463
24464
24465
24466
24467
24468
24469
24470
24471
24472
24473
24474
24475
24476
24477
24478
24479
24480
24481
24482
24483
24484
24485
24486
24487
24488
24489
24490
24491
24492
24493
24494
24495
24496
24497
24498
24499
24500
24501
24502
24503
24504
24505
24506
24507
24508
24509
24510
24511
24512
24513
24514
24515
24516
24517
24518
24519
24520
24521
24522
24523
24524
24525
24526
24527
24528
24529
24530
24531
24532
24533
24534
24535
24536
24537
24538
24539
24540
24541
24542
24543
24544
24545
24546
24547
24548
24549
24550
24551
24552
24553
24554
24555
24556
24557
24558
24559
24560
24561
24562
24563
24564
24565
24566
24567
24568
24569
24570
24571
24572
24573
24574
24575
24576
24577
24578
24579
24580
24581
24582
24583
24584
24585
24586
24587
24588
24589
24590
24591
24592
24593
24594
24595
24596
24597
24598
24599
24600
24601
24602
24603
24604
24605
24606
24607
24608
24609
24610
24611
24612
24613
24614
24615
24616
24617
24618
24619
24620
24621
24622
24623
24624
24625
24626
24627
24628
24629
24630
24631
24632
24633
24634
24635
24636
24637
24638
24639
24640
24641
24642
24643
24644
24645
24646
24647
24648
24649
24650
24651
24652
24653
24654
24655
24656
24657
24658
24659
24660
24661
24662
24663
24664
24665
24666
24667
24668
24669
24670
24671
24672
24673
24674
24675
24676
24677
24678
24679
24680
24681
24682
24683
24684
24685
24686
24687
24688
24689
24690
24691
24692
24693
24694
24695
24696
24697
24698
24699
24700
24701
24702
24703
24704
24705
24706
24707
24708
24709
24710
24711
24712
24713
24714
24715
24716
24717
24718
24719
24720
24721
24722
24723
24724
24725
24726
24727
24728
24729
24730
24731
24732
24733
24734
24735
24736
24737
24738
24739
24740
24741
24742
24743
24744
24745
24746
24747
24748
24749
24750
24751
24752
24753
24754
24755
24756
24757
24758
24759
24760
24761
24762
24763
24764
24765
24766
24767
24768
24769
24770
24771
24772
24773
24774
24775
24776
24777
24778
24779
24780
24781
24782
24783
24784
24785
24786
24787
24788
24789
24790
24791
24792
24793
24794
24795
24796
24797
24798
24799
24800
24801
24802
24803
24804
24805
24806
24807
24808
24809
24810
24811
24812
24813
24814
24815
24816
24817
24818
24819
24820
24821
24822
24823
24824
24825
24826
24827
24828
24829
24830
24831
24832
24833
24834
24835
24836
24837
24838
24839
24840
24841
24842
24843
24844
24845
24846
24847
24848
24849
24850
24851
24852
24853
24854
24855
24856
24857
24858
24859
24860
24861
24862
24863
24864
24865
24866
24867
24868
24869
24870
24871
24872
24873
24874
24875
24876
24877
24878
24879
24880
24881
24882
24883
24884
24885
24886
24887
24888
24889
24890
24891
24892
24893
24894
24895
24896
24897
24898
24899
24900
24901
24902
24903
24904
24905
24906
24907
24908
24909
24910
24911
24912
24913
24914
24915
24916
24917
24918
24919
24920
24921
24922
24923
24924
24925
24926
24927
24928
24929
24930
24931
24932
24933
24934
24935
24936
24937
24938
24939
24940
24941
24942
24943
24944
24945
24946
24947
24948
24949
24950
24951
24952
24953
24954
24955
24956
24957
24958
24959
24960
24961
24962
24963
24964
24965
24966
24967
24968
24969
24970
24971
24972
24973
24974
24975
24976
24977
24978
24979
24980
24981
24982
24983
24984
24985
24986
24987
24988
24989
24990
24991
24992
24993
24994
24995
24996
24997
24998
24999
25000
25001
25002
25003
25004
25005
25006
25007
25008
25009
25010
25011
25012
25013
25014
25015
25016
25017
25018
25019
25020
25021
25022
25023
25024
25025
25026
25027
25028
25029
25030
25031
25032
25033
25034
25035
25036
25037
25038
25039
25040
25041
25042
25043
25044
25045
25046
25047
25048
25049
25050
25051
25052
25053
25054
25055
25056
25057
25058
25059
25060
25061
25062
25063
25064
25065
25066
25067
25068
25069
25070
25071
25072
25073
25074
25075
25076
25077
25078
25079
25080
25081
25082
25083
25084
25085
25086
25087
25088
25089
25090
25091
25092
25093
25094
25095
25096
25097
25098
25099
25100
25101
25102
25103
25104
25105
25106
25107
25108
25109
25110
25111
25112
25113
25114
25115
25116
25117
25118
25119
25120
25121
25122
25123
25124
25125
25126
25127
25128
25129
25130
25131
25132
25133
25134
25135
25136
25137
25138
25139
25140
25141
25142
25143
25144
25145
25146
25147
25148
25149
25150
25151
25152
25153
25154
25155
25156
25157
25158
25159
25160
25161
25162
25163
25164
25165
25166
25167
25168
25169
25170
25171
25172
25173
25174
25175
25176
25177
25178
25179
25180
25181
25182
25183
25184
25185
25186
25187
25188
25189
25190
25191
25192
25193
25194
25195
25196
25197
25198
25199
25200
25201
25202
25203
25204
25205
25206
25207
25208
25209
25210
25211
25212
25213
25214
25215
25216
25217
25218
25219
25220
25221
25222
25223
25224
25225
25226
25227
25228
25229
25230
25231
25232
25233
25234
25235
25236
25237
25238
25239
25240
25241
25242
25243
25244
25245
25246
25247
25248
25249
25250
25251
25252
25253
25254
25255
25256
25257
25258
25259
25260
25261
25262
25263
25264
25265
25266
25267
25268
25269
25270
25271
25272
25273
25274
25275
25276
25277
25278
25279
25280
25281
25282
25283
25284
25285
25286
25287
25288
25289
25290
25291
25292
25293
25294
25295
25296
25297
25298
25299
25300
25301
25302
25303
25304
25305
25306
25307
25308
25309
25310
25311
25312
25313
25314
25315
25316
25317
25318
25319
25320
25321
25322
25323
25324
25325
25326
25327
25328
25329
25330
25331
25332
25333
25334
25335
25336
25337
25338
25339
25340
25341
25342
25343
25344
25345
25346
25347
25348
25349
25350
25351
25352
25353
25354
25355
25356
25357
25358
25359
25360
25361
25362
25363
25364
25365
25366
25367
25368
25369
25370
25371
25372
25373
25374
25375
25376
25377
25378
25379
25380
25381
25382
25383
25384
25385
25386
25387
25388
25389
25390
25391
25392
25393
25394
25395
25396
25397
25398
25399
25400
25401
25402
25403
25404
25405
25406
25407
25408
25409
25410
25411
25412
25413
25414
25415
25416
25417
25418
25419
25420
25421
25422
25423
25424
25425
25426
25427
25428
25429
25430
25431
25432
25433
25434
25435
25436
25437
25438
25439
25440
25441
25442
25443
25444
25445
25446
25447
25448
25449
25450
25451
25452
25453
25454
25455
25456
25457
25458
25459
25460
25461
25462
25463
25464
25465
25466
25467
25468
25469
25470
25471
25472
25473
25474
25475
25476
25477
25478
25479
25480
25481
25482
25483
25484
25485
25486
25487
25488
25489
25490
25491
25492
25493
25494
25495
25496
25497
25498
25499
25500
25501
25502
25503
25504
25505
25506
25507
25508
25509
25510
25511
25512
25513
25514
25515
25516
25517
25518
25519
25520
25521
25522
25523
25524
25525
25526
25527
25528
25529
25530
25531
25532
25533
25534
25535
25536
25537
25538
25539
25540
25541
25542
25543
25544
25545
25546
25547
25548
25549
25550
25551
25552
25553
25554
25555
25556
25557
25558
25559
25560
25561
25562
25563
25564
25565
25566
25567
25568
25569
25570
25571
25572
25573
25574
25575
25576
25577
25578
25579
25580
25581
25582
25583
25584
25585
25586
25587
25588
25589
25590
25591
25592
25593
25594
25595
25596
25597
25598
25599
25600
25601
25602
25603
25604
25605
25606
25607
25608
25609
25610
25611
25612
25613
25614
25615
25616
25617
25618
25619
25620
25621
25622
25623
25624
25625
25626
25627
25628
25629
25630
25631
25632
25633
25634
25635
25636
25637
25638
25639
25640
25641
25642
25643
25644
25645
25646
25647
25648
25649
25650
25651
25652
25653
25654
25655
25656
25657
25658
25659
25660
25661
25662
25663
25664
25665
25666
25667
25668
25669
25670
25671
25672
25673
25674
25675
25676
25677
25678
25679
25680
25681
25682
25683
25684
25685
25686
25687
25688
25689
25690
25691
25692
25693
25694
25695
25696
25697
25698
25699
25700
25701
25702
25703
25704
25705
25706
25707
25708
25709
25710
25711
25712
25713
25714
25715
25716
25717
25718
25719
25720
25721
25722
25723
25724
25725
25726
25727
25728
25729
25730
25731
25732
25733
25734
25735
25736
25737
25738
25739
25740
25741
25742
25743
25744
25745
25746
25747
25748
25749
25750
25751
25752
25753
25754
25755
25756
25757
25758
25759
25760
25761
25762
25763
25764
25765
25766
25767
25768
25769
25770
25771
25772
25773
25774
25775
25776
25777
25778
25779
25780
25781
25782
25783
25784
25785
25786
25787
25788
25789
25790
25791
25792
25793
25794
25795
25796
25797
25798
25799
25800
25801
25802
25803
25804
25805
25806
25807
25808
25809
25810
25811
25812
25813
25814
25815
25816
25817
25818
25819
25820
25821
25822
25823
25824
25825
25826
25827
25828
25829
25830
25831
25832
25833
25834
25835
25836
25837
25838
25839
25840
25841
25842
25843
25844
25845
25846
25847
25848
25849
25850
25851
25852
25853
25854
25855
25856
25857
25858
25859
25860
25861
25862
25863
25864
25865
25866
25867
25868
25869
25870
25871
25872
25873
25874
25875
25876
25877
25878
25879
25880
25881
25882
25883
25884
25885
25886
25887
25888
25889
25890
25891
25892
25893
25894
25895
25896
25897
25898
25899
25900
25901
25902
25903
25904
25905
25906
25907
25908
25909
25910
25911
25912
25913
25914
25915
25916
25917
25918
25919
25920
25921
25922
25923
25924
25925
25926
25927
25928
25929
25930
25931
25932
25933
25934
25935
25936
25937
25938
25939
25940
25941
25942
25943
25944
25945
25946
25947
25948
25949
25950
25951
25952
25953
25954
25955
25956
25957
25958
25959
25960
25961
25962
25963
25964
25965
25966
25967
25968
25969
25970
25971
25972
25973
25974
25975
25976
25977
25978
25979
25980
25981
25982
25983
25984
25985
25986
25987
25988
25989
25990
25991
25992
25993
25994
25995
25996
25997
25998
25999
26000
26001
26002
26003
26004
26005
26006
26007
26008
26009
26010
26011
26012
26013
26014
26015
26016
26017
26018
26019
26020
26021
26022
26023
26024
26025
26026
26027
26028
26029
26030
26031
26032
26033
26034
26035
26036
26037
26038
26039
26040
26041
26042
26043
26044
26045
26046
26047
26048
26049
26050
26051
26052
26053
26054
26055
26056
26057
26058
26059
26060
26061
26062
26063
26064
26065
26066
26067
26068
26069
26070
26071
26072
26073
26074
26075
26076
26077
26078
26079
26080
26081
26082
26083
26084
26085
26086
26087
26088
26089
26090
26091
26092
26093
26094
26095
26096
26097
26098
26099
26100
26101
26102
26103
26104
26105
26106
26107
26108
26109
26110
26111
26112
26113
26114
26115
26116
26117
26118
26119
26120
26121
26122
26123
26124
26125
26126
26127
26128
26129
26130
26131
26132
26133
26134
26135
26136
26137
26138
26139
26140
26141
26142
26143
26144
26145
26146
26147
26148
26149
26150
26151
26152
26153
26154
26155
26156
26157
26158
26159
26160
26161
26162
26163
26164
26165
26166
26167
26168
26169
26170
26171
26172
26173
26174
26175
26176
26177
26178
26179
26180
26181
26182
26183
26184
26185
26186
26187
26188
26189
26190
26191
26192
26193
26194
26195
26196
26197
26198
26199
26200
26201
26202
26203
26204
26205
26206
26207
26208
26209
26210
26211
26212
26213
26214
26215
26216
26217
26218
26219
26220
26221
26222
26223
26224
26225
26226
26227
26228
26229
26230
26231
26232
26233
26234
26235
26236
26237
26238
26239
26240
26241
26242
26243
26244
26245
26246
26247
26248
26249
26250
26251
26252
26253
26254
26255
26256
26257
26258
26259
26260
26261
26262
26263
26264
26265
26266
26267
26268
26269
26270
26271
26272
26273
26274
26275
26276
26277
26278
26279
26280
26281
26282
26283
26284
26285
26286
26287
26288
26289
26290
26291
26292
26293
26294
26295
26296
26297
26298
26299
26300
26301
26302
26303
26304
26305
26306
26307
26308
26309
26310
26311
26312
26313
26314
26315
26316
26317
26318
26319
26320
26321
26322
26323
26324
26325
26326
26327
26328
26329
26330
26331
26332
26333
26334
26335
26336
26337
26338
26339
26340
26341
26342
26343
26344
26345
26346
26347
26348
26349
26350
26351
26352
26353
26354
26355
26356
26357
26358
26359
26360
26361
26362
26363
26364
26365
26366
26367
26368
26369
26370
26371
26372
26373
26374
26375
26376
26377
26378
26379
26380
26381
26382
26383
26384
26385
26386
26387
26388
26389
26390
26391
26392
26393
26394
26395
26396
26397
26398
26399
26400
26401
26402
26403
26404
26405
26406
26407
26408
26409
26410
26411
26412
26413
26414
26415
26416
26417
26418
26419
26420
26421
26422
26423
26424
26425
26426
26427
26428
26429
26430
26431
26432
26433
26434
26435
26436
26437
26438
26439
26440
26441
26442
26443
26444
26445
26446
26447
26448
26449
26450
26451
26452
26453
26454
26455
26456
26457
26458
26459
26460
26461
26462
26463
26464
26465
26466
26467
26468
26469
26470
26471
26472
26473
26474
26475
26476
26477
26478
26479
26480
26481
26482
26483
26484
26485
26486
26487
26488
26489
26490
26491
26492
26493
26494
26495
26496
26497
26498
26499
26500
26501
26502
26503
26504
26505
26506
26507
26508
26509
26510
26511
26512
26513
26514
26515
26516
26517
26518
26519
26520
26521
26522
26523
26524
26525
26526
26527
26528
26529
26530
26531
26532
26533
26534
26535
26536
26537
26538
26539
26540
26541
26542
26543
26544
26545
26546
26547
26548
26549
26550
26551
26552
26553
26554
26555
26556
26557
26558
26559
26560
26561
26562
26563
26564
26565
26566
26567
26568
26569
26570
26571
26572
26573
26574
26575
26576
26577
26578
26579
26580
26581
26582
26583
26584
26585
26586
26587
26588
26589
26590
26591
26592
26593
26594
26595
26596
26597
26598
26599
26600
26601
26602
26603
26604
26605
26606
26607
26608
26609
26610
26611
26612
26613
26614
26615
26616
26617
26618
26619
26620
26621
26622
26623
26624
26625
26626
26627
26628
26629
26630
26631
26632
26633
26634
26635
26636
26637
26638
26639
26640
26641
26642
26643
26644
26645
26646
26647
26648
26649
26650
26651
26652
26653
26654
26655
26656
26657
26658
26659
26660
26661
26662
26663
26664
26665
26666
26667
26668
26669
26670
26671
26672
26673
26674
26675
26676
26677
26678
26679
26680
26681
26682
26683
26684
26685
26686
26687
26688
26689
26690
26691
26692
26693
26694
26695
26696
26697
26698
26699
26700
26701
26702
26703
26704
26705
26706
26707
26708
26709
26710
26711
26712
26713
26714
26715
26716
26717
26718
26719
26720
26721
26722
26723
26724
26725
26726
26727
26728
26729
26730
26731
26732
26733
26734
26735
26736
26737
26738
26739
26740
26741
26742
26743
26744
26745
26746
26747
26748
26749
26750
26751
26752
26753
26754
26755
26756
26757
26758
26759
26760
26761
26762
26763
26764
26765
26766
26767
26768
26769
26770
26771
26772
26773
26774
26775
26776
26777
26778
26779
26780
26781
26782
26783
26784
26785
26786
26787
26788
26789
26790
26791
26792
26793
26794
26795
26796
26797
26798
26799
26800
26801
26802
26803
26804
26805
26806
26807
26808
26809
26810
26811
26812
26813
26814
26815
26816
26817
26818
26819
26820
26821
26822
26823
26824
26825
26826
26827
26828
26829
26830
26831
26832
26833
26834
26835
26836
26837
26838
26839
26840
26841
26842
26843
26844
26845
26846
26847
26848
26849
26850
26851
26852
26853
26854
26855
26856
26857
26858
26859
26860
26861
26862
26863
26864
26865
26866
26867
26868
26869
26870
26871
26872
26873
26874
26875
26876
26877
26878
26879
26880
26881
26882
26883
26884
26885
26886
26887
26888
26889
26890
26891
26892
26893
26894
26895
26896
26897
26898
26899
26900
26901
26902
26903
26904
26905
26906
26907
26908
26909
26910
26911
26912
26913
26914
26915
26916
26917
26918
26919
26920
26921
26922
26923
26924
26925
26926
26927
26928
26929
26930
26931
26932
26933
26934
26935
26936
26937
26938
26939
26940
26941
26942
26943
26944
26945
26946
26947
26948
26949
26950
26951
26952
26953
26954
26955
26956
26957
26958
26959
26960
26961
26962
26963
26964
26965
26966
26967
26968
26969
26970
26971
26972
26973
26974
26975
26976
26977
26978
26979
26980
26981
26982
26983
26984
26985
26986
26987
26988
26989
26990
26991
26992
26993
26994
26995
26996
26997
26998
26999
27000
27001
27002
27003
27004
27005
27006
27007
27008
27009
27010
27011
27012
27013
27014
27015
27016
27017
27018
27019
27020
27021
27022
27023
27024
27025
27026
27027
27028
27029
27030
27031
27032
27033
27034
27035
27036
27037
27038
27039
27040
27041
27042
27043
27044
27045
27046
27047
27048
27049
27050
27051
27052
27053
27054
27055
27056
27057
27058
27059
27060
27061
27062
27063
27064
27065
27066
27067
27068
27069
27070
27071
27072
27073
27074
27075
27076
27077
27078
27079
27080
27081
27082
27083
27084
27085
27086
27087
27088
27089
27090
27091
27092
27093
27094
27095
27096
27097
27098
27099
27100
27101
27102
27103
27104
27105
27106
27107
27108
27109
27110
27111
27112
27113
27114
27115
27116
27117
27118
27119
27120
27121
27122
27123
27124
27125
27126
27127
27128
27129
27130
27131
27132
27133
27134
27135
27136
27137
27138
27139
27140
27141
27142
27143
27144
27145
27146
27147
27148
27149
27150
27151
27152
27153
27154
27155
27156
27157
27158
27159
27160
27161
27162
27163
27164
27165
27166
27167
27168
27169
27170
27171
27172
27173
27174
27175
27176
27177
27178
27179
27180
27181
27182
27183
27184
27185
27186
27187
27188
27189
27190
27191
27192
27193
27194
27195
27196
27197
27198
27199
27200
27201
27202
27203
27204
27205
27206
27207
27208
27209
27210
27211
27212
27213
27214
27215
27216
27217
27218
27219
27220
27221
27222
27223
27224
27225
27226
27227
27228
27229
27230
27231
27232
27233
27234
27235
27236
27237
27238
27239
27240
27241
27242
27243
27244
27245
27246
27247
27248
27249
27250
27251
27252
27253
27254
27255
27256
27257
27258
27259
27260
27261
27262
27263
27264
27265
27266
27267
27268
27269
27270
27271
27272
27273
27274
27275
27276
27277
27278
27279
27280
27281
27282
27283
27284
27285
27286
27287
27288
27289
27290
27291
27292
27293
27294
27295
27296
27297
27298
27299
27300
27301
27302
27303
27304
27305
27306
27307
27308
27309
27310
27311
27312
27313
27314
27315
27316
27317
27318
27319
27320
27321
27322
27323
27324
27325
27326
27327
27328
27329
27330
27331
27332
27333
27334
27335
27336
27337
27338
27339
27340
27341
27342
27343
27344
27345
27346
27347
27348
27349
27350
27351
27352
27353
27354
27355
27356
27357
27358
27359
27360
27361
27362
27363
27364
27365
27366
27367
27368
27369
27370
27371
27372
27373
27374
27375
27376
27377
27378
27379
27380
27381
27382
27383
27384
27385
27386
27387
27388
27389
27390
27391
27392
27393
27394
27395
27396
27397
27398
27399
27400
27401
27402
27403
27404
27405
27406
27407
27408
27409
27410
27411
27412
27413
27414
27415
27416
27417
27418
27419
27420
27421
27422
27423
27424
27425
27426
27427
27428
27429
27430
27431
27432
27433
27434
27435
27436
27437
27438
27439
27440
27441
27442
27443
27444
27445
27446
27447
27448
27449
27450
27451
27452
27453
27454
27455
27456
27457
27458
27459
27460
27461
27462
27463
27464
27465
27466
27467
27468
27469
27470
27471
27472
27473
27474
27475
27476
27477
27478
27479
27480
27481
27482
27483
27484
27485
27486
27487
27488
27489
27490
27491
27492
27493
27494
27495
27496
27497
27498
27499
27500
27501
27502
27503
27504
27505
27506
27507
27508
27509
27510
27511
27512
27513
27514
27515
27516
27517
27518
27519
27520
27521
27522
27523
27524
27525
27526
27527
27528
27529
27530
27531
27532
27533
27534
27535
27536
27537
27538
27539
27540
27541
27542
27543
27544
27545
27546
27547
27548
27549
27550
27551
27552
27553
27554
27555
27556
27557
27558
27559
27560
27561
27562
27563
27564
27565
27566
27567
27568
27569
27570
27571
27572
27573
27574
27575
27576
27577
27578
27579
27580
27581
27582
27583
27584
27585
27586
27587
27588
27589
27590
27591
27592
27593
27594
27595
27596
27597
27598
27599
27600
27601
27602
27603
27604
27605
27606
27607
27608
27609
27610
27611
27612
27613
27614
27615
27616
27617
27618
27619
27620
27621
27622
27623
27624
27625
27626
27627
27628
27629
27630
27631
27632
27633
27634
27635
27636
27637
27638
27639
27640
27641
27642
27643
27644
27645
27646
27647
27648
27649
27650
27651
27652
27653
27654
27655
27656
27657
27658
27659
27660
27661
27662
27663
27664
27665
27666
27667
27668
27669
27670
27671
27672
27673
27674
27675
27676
27677
27678
27679
27680
27681
27682
27683
27684
27685
27686
27687
27688
27689
27690
27691
27692
27693
27694
27695
27696
27697
27698
27699
27700
27701
27702
27703
27704
27705
27706
27707
27708
27709
27710
27711
27712
27713
27714
27715
27716
27717
27718
27719
27720
27721
27722
27723
27724
27725
27726
27727
27728
27729
27730
27731
27732
27733
27734
27735
27736
27737
27738
27739
27740
27741
27742
27743
27744
27745
27746
27747
27748
27749
27750
27751
27752
27753
27754
27755
27756
27757
27758
27759
27760
27761
27762
27763
27764
27765
27766
27767
27768
27769
27770
27771
27772
27773
27774
27775
27776
27777
27778
27779
27780
27781
27782
27783
27784
27785
27786
27787
27788
27789
27790
27791
27792
27793
27794
27795
27796
27797
27798
27799
27800
27801
27802
27803
27804
27805
27806
27807
27808
27809
27810
27811
27812
27813
27814
27815
27816
27817
27818
27819
27820
27821
27822
27823
27824
27825
27826
27827
27828
27829
27830
27831
27832
27833
27834
27835
27836
27837
27838
27839
27840
27841
27842
27843
27844
27845
27846
27847
27848
27849
27850
27851
27852
27853
27854
27855
27856
27857
27858
27859
27860
27861
27862
27863
27864
27865
27866
27867
27868
27869
27870
27871
27872
27873
27874
27875
27876
27877
27878
27879
27880
27881
27882
27883
27884
27885
27886
27887
27888
27889
27890
27891
27892
27893
27894
27895
27896
27897
27898
27899
27900
27901
27902
27903
27904
27905
27906
27907
27908
27909
27910
27911
27912
27913
27914
27915
27916
27917
27918
27919
27920
27921
27922
27923
27924
27925
27926
27927
27928
27929
27930
27931
27932
27933
27934
27935
27936
27937
27938
27939
27940
27941
27942
27943
27944
27945
27946
27947
27948
27949
27950
27951
27952
27953
27954
27955
27956
27957
27958
27959
27960
27961
27962
27963
27964
27965
27966
27967
27968
27969
27970
27971
27972
27973
27974
27975
27976
27977
27978
27979
27980
27981
27982
27983
27984
27985
27986
27987
27988
27989
27990
27991
27992
27993
27994
27995
27996
27997
27998
27999
28000
28001
28002
28003
28004
28005
28006
28007
28008
28009
28010
28011
28012
28013
28014
28015
28016
28017
28018
28019
28020
28021
28022
28023
28024
28025
28026
28027
28028
28029
28030
28031
28032
28033
28034
28035
28036
28037
28038
28039
28040
28041
28042
28043
28044
28045
28046
28047
28048
28049
28050
28051
28052
28053
28054
28055
28056
28057
28058
28059
28060
28061
28062
28063
28064
28065
28066
28067
28068
28069
28070
28071
28072
28073
28074
28075
28076
28077
28078
28079
28080
28081
28082
28083
28084
28085
28086
28087
28088
28089
28090
28091
28092
28093
28094
28095
28096
28097
28098
28099
28100
28101
28102
28103
28104
28105
28106
28107
28108
28109
28110
28111
28112
28113
28114
28115
28116
28117
28118
28119
28120
28121
28122
28123
28124
28125
28126
28127
28128
28129
28130
28131
28132
28133
28134
28135
28136
28137
28138
28139
28140
28141
28142
28143
28144
28145
28146
28147
28148
28149
28150
28151
28152
28153
28154
28155
28156
28157
28158
28159
28160
28161
28162
28163
28164
28165
28166
28167
28168
28169
28170
28171
28172
28173
28174
28175
28176
28177
28178
28179
28180
28181
28182
28183
28184
28185
28186
28187
28188
28189
28190
28191
28192
28193
28194
28195
28196
28197
28198
28199
28200
28201
28202
28203
28204
28205
28206
28207
28208
28209
28210
28211
28212
28213
28214
28215
28216
28217
28218
28219
28220
28221
28222
28223
28224
28225
28226
28227
28228
28229
28230
28231
28232
28233
28234
28235
28236
28237
28238
28239
28240
28241
28242
28243
28244
28245
28246
28247
28248
28249
28250
28251
28252
28253
28254
28255
28256
28257
28258
28259
28260
28261
28262
28263
28264
28265
28266
28267
28268
28269
28270
28271
28272
28273
28274
28275
28276
28277
28278
28279
28280
28281
28282
28283
28284
28285
28286
28287
28288
28289
28290
28291
28292
28293
28294
28295
28296
28297
28298
28299
28300
28301
28302
28303
28304
28305
28306
28307
28308
28309
28310
28311
28312
28313
28314
28315
28316
28317
28318
28319
28320
28321
28322
28323
28324
28325
28326
28327
28328
28329
28330
28331
28332
28333
28334
28335
28336
28337
28338
28339
28340
28341
28342
28343
28344
28345
28346
28347
28348
28349
28350
28351
28352
28353
28354
28355
28356
28357
28358
28359
28360
28361
28362
28363
28364
28365
28366
28367
28368
28369
28370
28371
28372
28373
28374
28375
28376
28377
28378
28379
28380
28381
28382
28383
28384
28385
28386
28387
28388
28389
28390
28391
28392
28393
28394
28395
28396
28397
28398
28399
28400
28401
28402
28403
28404
28405
28406
28407
28408
28409
28410
28411
28412
28413
28414
28415
28416
28417
28418
28419
28420
28421
28422
28423
28424
28425
28426
28427
28428
28429
28430
28431
28432
28433
28434
28435
28436
28437
28438
28439
28440
28441
28442
28443
28444
28445
28446
28447
28448
28449
28450
28451
28452
28453
28454
28455
28456
28457
28458
28459
28460
28461
28462
28463
28464
28465
28466
28467
28468
28469
28470
28471
28472
28473
28474
28475
28476
28477
28478
28479
28480
28481
28482
28483
28484
28485
28486
28487
28488
28489
28490
28491
28492
28493
28494
28495
28496
28497
28498
28499
28500
28501
28502
28503
28504
28505
28506
28507
28508
28509
28510
28511
28512
28513
28514
28515
28516
28517
28518
28519
28520
28521
28522
28523
28524
28525
28526
28527
28528
28529
28530
28531
28532
28533
28534
28535
28536
28537
28538
28539
28540
28541
28542
28543
28544
28545
28546
28547
28548
28549
28550
28551
28552
28553
28554
28555
28556
28557
28558
28559
28560
28561
28562
28563
28564
28565
28566
28567
28568
28569
28570
28571
28572
28573
28574
28575
28576
28577
28578
28579
28580
28581
28582
28583
28584
28585
28586
28587
28588
28589
28590
28591
28592
28593
28594
28595
28596
28597
28598
28599
28600
28601
28602
28603
28604
28605
28606
28607
28608
28609
28610
28611
28612
28613
28614
28615
28616
28617
28618
28619
28620
28621
28622
28623
28624
28625
28626
28627
28628
28629
28630
28631
28632
28633
28634
28635
28636
28637
28638
28639
28640
28641
28642
28643
28644
28645
28646
28647
28648
28649
28650
28651
28652
28653
28654
28655
28656
28657
28658
28659
28660
28661
28662
28663
28664
28665
28666
28667
28668
28669
28670
28671
28672
28673
28674
28675
28676
28677
28678
28679
28680
28681
28682
28683
28684
28685
28686
28687
28688
28689
28690
28691
28692
28693
28694
28695
28696
28697
28698
28699
28700
28701
28702
28703
28704
28705
28706
28707
28708
28709
28710
28711
28712
28713
28714
28715
28716
28717
28718
28719
28720
28721
28722
28723
28724
28725
28726
28727
28728
28729
28730
28731
28732
28733
28734
28735
28736
28737
28738
28739
28740
28741
28742
28743
28744
28745
28746
28747
28748
28749
28750
28751
28752
28753
28754
28755
28756
28757
28758
28759
28760
28761
28762
28763
28764
28765
28766
28767
28768
28769
28770
28771
28772
28773
28774
28775
28776
28777
28778
28779
28780
28781
28782
28783
28784
28785
28786
28787
28788
28789
28790
28791
28792
28793
28794
28795
28796
28797
28798
28799
28800
28801
28802
28803
28804
28805
28806
28807
28808
28809
28810
28811
28812
28813
28814
28815
28816
28817
28818
28819
28820
28821
28822
28823
28824
28825
28826
28827
28828
28829
28830
28831
28832
28833
28834
28835
28836
28837
28838
28839
28840
28841
28842
28843
28844
28845
28846
28847
28848
28849
28850
28851
28852
28853
28854
28855
28856
28857
28858
28859
28860
28861
28862
28863
28864
28865
28866
28867
28868
28869
28870
28871
28872
28873
28874
28875
28876
28877
28878
28879
28880
28881
28882
28883
28884
28885
28886
28887
28888
28889
28890
28891
28892
28893
28894
28895
28896
28897
28898
28899
28900
28901
28902
28903
28904
28905
28906
28907
28908
28909
28910
28911
28912
28913
28914
28915
28916
28917
28918
28919
28920
28921
28922
28923
28924
28925
28926
28927
28928
28929
28930
28931
28932
28933
28934
28935
28936
28937
28938
28939
28940
28941
28942
28943
28944
28945
28946
28947
28948
28949
28950
28951
28952
28953
28954
28955
28956
28957
28958
28959
28960
28961
28962
28963
28964
28965
28966
28967
28968
28969
28970
28971
28972
28973
28974
28975
28976
28977
28978
28979
28980
28981
28982
28983
28984
28985
28986
28987
28988
28989
28990
28991
28992
28993
28994
28995
28996
28997
28998
28999
29000
29001
29002
29003
29004
29005
29006
29007
29008
29009
29010
29011
29012
29013
29014
29015
29016
29017
29018
29019
29020
29021
29022
29023
29024
29025
29026
29027
29028
29029
29030
29031
29032
29033
29034
29035
29036
29037
29038
29039
29040
29041
29042
29043
29044
29045
29046
29047
29048
29049
29050
29051
29052
29053
29054
29055
29056
29057
29058
29059
29060
29061
29062
29063
29064
29065
29066
29067
29068
29069
29070
29071
29072
29073
29074
29075
29076
29077
29078
29079
29080
29081
29082
29083
29084
29085
29086
29087
29088
29089
29090
29091
29092
29093
29094
29095
29096
29097
29098
29099
29100
29101
29102
29103
29104
29105
29106
29107
29108
29109
29110
29111
29112
29113
29114
29115
29116
29117
29118
29119
29120
29121
29122
29123
29124
29125
29126
29127
29128
29129
29130
29131
29132
29133
29134
29135
29136
29137
29138
29139
29140
29141
29142
29143
29144
29145
29146
29147
29148
29149
29150
29151
29152
29153
29154
29155
29156
29157
29158
29159
29160
29161
29162
29163
29164
29165
29166
29167
29168
29169
29170
29171
29172
29173
29174
29175
29176
29177
29178
29179
29180
29181
29182
29183
29184
29185
29186
29187
29188
29189
29190
29191
29192
29193
29194
29195
29196
29197
29198
29199
29200
29201
29202
29203
29204
29205
29206
29207
29208
29209
29210
29211
29212
29213
29214
29215
29216
29217
29218
29219
29220
29221
29222
29223
29224
29225
29226
29227
29228
29229
29230
29231
29232
29233
29234
29235
29236
29237
29238
29239
29240
29241
29242
29243
29244
29245
29246
29247
29248
29249
29250
29251
29252
29253
29254
29255
29256
29257
29258
29259
29260
29261
29262
29263
29264
29265
29266
29267
29268
29269
29270
29271
29272
29273
29274
29275
29276
29277
29278
29279
29280
29281
29282
29283
29284
29285
29286
29287
29288
29289
29290
29291
29292
29293
29294
29295
29296
29297
29298
29299
29300
29301
29302
29303
29304
29305
29306
29307
29308
29309
29310
29311
29312
29313
29314
29315
29316
29317
29318
29319
29320
29321
29322
29323
29324
29325
29326
29327
29328
29329
29330
29331
29332
29333
29334
29335
29336
29337
29338
29339
29340
29341
29342
29343
29344
29345
29346
29347
29348
29349
29350
29351
29352
29353
29354
29355
29356
29357
29358
29359
29360
29361
29362
29363
29364
29365
29366
29367
29368
29369
29370
29371
29372
29373
29374
29375
29376
29377
29378
29379
29380
29381
29382
29383
29384
29385
29386
29387
29388
29389
29390
29391
29392
29393
29394
29395
29396
29397
29398
29399
29400
29401
29402
29403
29404
29405
29406
29407
29408
29409
29410
29411
29412
29413
29414
29415
29416
29417
29418
29419
29420
29421
29422
29423
29424
29425
29426
29427
29428
29429
29430
29431
29432
29433
29434
29435
29436
29437
29438
29439
29440
29441
29442
29443
29444
29445
29446
29447
29448
29449
29450
29451
29452
29453
29454
29455
29456
29457
29458
29459
29460
29461
29462
29463
29464
29465
29466
29467
29468
29469
29470
29471
29472
29473
29474
29475
29476
29477
29478
29479
29480
29481
29482
29483
29484
29485
29486
29487
29488
29489
29490
29491
29492
29493
29494
29495
29496
29497
29498
29499
29500
29501
29502
29503
29504
29505
29506
29507
29508
29509
29510
29511
29512
29513
29514
29515
29516
29517
29518
29519
29520
29521
29522
29523
29524
29525
29526
29527
29528
29529
29530
29531
29532
29533
29534
29535
29536
29537
29538
29539
29540
29541
29542
29543
29544
29545
29546
29547
29548
29549
29550
29551
29552
29553
29554
29555
29556
29557
29558
29559
29560
29561
29562
29563
29564
29565
29566
29567
29568
29569
29570
29571
29572
29573
29574
29575
29576
29577
29578
29579
29580
29581
29582
29583
29584
29585
29586
29587
29588
29589
29590
29591
29592
29593
29594
29595
29596
29597
29598
29599
29600
29601
29602
29603
29604
29605
29606
29607
29608
29609
29610
29611
29612
29613
29614
29615
29616
29617
29618
29619
29620
29621
29622
29623
29624
29625
29626
29627
29628
29629
29630
29631
29632
29633
29634
29635
29636
29637
29638
29639
29640
29641
29642
29643
29644
29645
29646
29647
29648
29649
29650
29651
29652
29653
29654
29655
29656
29657
29658
29659
29660
29661
29662
29663
29664
29665
29666
29667
29668
29669
29670
29671
29672
29673
29674
29675
29676
29677
29678
29679
29680
29681
29682
29683
29684
29685
29686
29687
29688
29689
29690
29691
29692
29693
29694
29695
29696
29697
29698
29699
29700
29701
29702
29703
29704
29705
29706
29707
29708
29709
29710
29711
29712
29713
29714
29715
29716
29717
29718
29719
29720
29721
29722
29723
29724
29725
29726
29727
29728
29729
29730
29731
29732
29733
29734
29735
29736
29737
29738
29739
29740
29741
29742
29743
29744
29745
29746
29747
29748
29749
29750
29751
29752
29753
29754
29755
29756
29757
29758
29759
29760
29761
29762
29763
29764
29765
29766
29767
29768
29769
29770
29771
29772
29773
29774
29775
29776
29777
29778
29779
29780
29781
29782
29783
29784
29785
29786
29787
29788
29789
29790
29791
29792
29793
29794
29795
29796
29797
29798
29799
29800
29801
29802
29803
29804
29805
29806
29807
29808
29809
29810
29811
29812
29813
29814
29815
29816
29817
29818
29819
29820
29821
29822
29823
29824
29825
29826
29827
29828
29829
29830
29831
29832
29833
29834
29835
29836
29837
29838
29839
29840
29841
29842
29843
29844
29845
29846
29847
29848
29849
29850
29851
29852
29853
29854
29855
29856
29857
29858
29859
29860
29861
29862
29863
29864
29865
29866
29867
29868
29869
29870
29871
29872
29873
29874
29875
29876
29877
29878
29879
29880
29881
29882
29883
29884
29885
29886
29887
29888
29889
29890
29891
29892
29893
29894
29895
29896
29897
29898
29899
29900
29901
29902
29903
29904
29905
29906
29907
29908
29909
29910
29911
29912
29913
29914
29915
29916
29917
29918
29919
29920
29921
29922
29923
29924
29925
29926
29927
29928
29929
29930
29931
29932
29933
29934
29935
29936
29937
29938
29939
29940
29941
29942
29943
29944
29945
29946
29947
29948
29949
29950
29951
29952
29953
29954
29955
29956
29957
29958
29959
29960
29961
29962
29963
29964
29965
29966
29967
29968
29969
29970
29971
29972
29973
29974
29975
29976
29977
29978
29979
29980
29981
29982
29983
29984
29985
29986
29987
29988
29989
29990
29991
29992
29993
29994
29995
29996
29997
29998
29999
30000
30001
30002
30003
30004
30005
30006
30007
30008
30009
30010
30011
30012
30013
30014
30015
30016
30017
30018
30019
30020
30021
30022
30023
30024
30025
30026
30027
30028
30029
30030
30031
30032
30033
30034
30035
30036
30037
30038
30039
30040
30041
30042
30043
30044
30045
30046
30047
30048
30049
30050
30051
30052
30053
30054
30055
30056
30057
30058
30059
30060
30061
30062
30063
30064
30065
30066
30067
30068
30069
30070
30071
30072
30073
30074
30075
30076
30077
30078
30079
30080
30081
30082
30083
30084
30085
30086
30087
30088
30089
30090
30091
30092
30093
30094
30095
30096
30097
30098
30099
30100
30101
30102
30103
30104
30105
30106
30107
30108
30109
30110
30111
30112
30113
30114
30115
30116
30117
30118
30119
30120
30121
30122
30123
30124
30125
30126
30127
30128
30129
30130
30131
30132
30133
30134
30135
30136
30137
30138
30139
30140
30141
30142
30143
30144
30145
30146
30147
30148
30149
30150
30151
30152
30153
30154
30155
30156
30157
30158
30159
30160
30161
30162
30163
30164
30165
30166
30167
30168
30169
30170
30171
30172
30173
30174
30175
30176
30177
30178
30179
30180
30181
30182
30183
30184
30185
30186
30187
30188
30189
30190
30191
30192
30193
30194
30195
30196
30197
30198
30199
30200
30201
30202
30203
30204
30205
30206
30207
30208
30209
30210
30211
30212
30213
30214
30215
30216
30217
30218
30219
30220
30221
30222
30223
30224
30225
30226
30227
30228
30229
30230
30231
30232
30233
30234
30235
30236
30237
30238
30239
30240
30241
30242
30243
30244
30245
30246
30247
30248
30249
30250
30251
30252
30253
30254
30255
30256
30257
30258
30259
30260
30261
30262
30263
30264
30265
30266
30267
30268
30269
30270
30271
30272
30273
30274
30275
30276
30277
30278
30279
30280
30281
30282
30283
30284
30285
30286
30287
30288
30289
30290
30291
30292
30293
30294
30295
30296
30297
30298
30299
30300
30301
30302
30303
30304
30305
30306
30307
30308
30309
30310
30311
30312
30313
30314
30315
30316
30317
30318
30319
30320
30321
30322
30323
30324
30325
30326
30327
30328
30329
30330
30331
30332
30333
30334
30335
30336
30337
30338
30339
30340
30341
30342
30343
30344
30345
30346
30347
30348
30349
30350
30351
30352
30353
30354
30355
30356
30357
30358
30359
30360
30361
30362
30363
30364
30365
30366
30367
30368
30369
30370
30371
30372
30373
30374
30375
30376
30377
30378
30379
30380
30381
30382
30383
30384
30385
30386
30387
30388
30389
30390
30391
30392
30393
30394
30395
30396
30397
30398
30399
30400
30401
30402
30403
30404
30405
30406
30407
30408
30409
30410
30411
30412
30413
30414
30415
30416
30417
30418
30419
30420
30421
30422
30423
30424
30425
30426
30427
30428
30429
30430
30431
30432
30433
30434
30435
30436
30437
30438
30439
30440
30441
30442
30443
30444
30445
30446
30447
30448
30449
30450
30451
30452
30453
30454
30455
30456
30457
30458
30459
30460
30461
30462
30463
30464
30465
30466
30467
30468
30469
30470
30471
30472
30473
30474
30475
30476
30477
30478
30479
30480
30481
30482
30483
30484
30485
30486
30487
30488
30489
30490
30491
30492
30493
30494
30495
30496
30497
30498
30499
30500
30501
30502
30503
30504
30505
30506
30507
30508
30509
30510
30511
30512
30513
30514
30515
30516
30517
30518
30519
30520
30521
30522
30523
30524
30525
30526
30527
30528
30529
30530
30531
30532
30533
30534
30535
30536
30537
30538
30539
30540
30541
30542
30543
30544
30545
30546
30547
30548
30549
30550
30551
30552
30553
30554
30555
30556
30557
30558
30559
30560
30561
30562
30563
30564
30565
30566
30567
30568
30569
30570
30571
30572
30573
30574
30575
30576
30577
30578
30579
30580
30581
30582
30583
30584
30585
30586
30587
30588
30589
30590
30591
30592
30593
30594
30595
30596
30597
30598
30599
30600
30601
30602
30603
30604
30605
30606
30607
30608
30609
30610
30611
30612
30613
30614
30615
30616
30617
30618
30619
30620
30621
30622
30623
30624
30625
30626
30627
30628
30629
30630
30631
30632
30633
30634
30635
30636
30637
30638
30639
30640
30641
30642
30643
30644
30645
30646
30647
30648
30649
30650
30651
30652
30653
30654
30655
30656
30657
30658
30659
30660
30661
30662
30663
30664
30665
30666
30667
30668
30669
30670
30671
30672
30673
30674
30675
30676
30677
30678
30679
30680
30681
30682
30683
30684
30685
30686
30687
30688
30689
30690
30691
30692
30693
30694
30695
30696
30697
30698
30699
30700
30701
30702
30703
30704
30705
30706
30707
30708
30709
30710
30711
30712
30713
30714
30715
30716
30717
30718
30719
30720
30721
30722
30723
30724
30725
30726
30727
30728
30729
30730
30731
30732
30733
30734
30735
30736
30737
30738
30739
30740
30741
30742
30743
30744
30745
30746
30747
30748
30749
30750
30751
30752
30753
30754
30755
30756
30757
30758
30759
30760
30761
30762
30763
30764
30765
30766
30767
30768
30769
30770
30771
30772
30773
30774
30775
30776
30777
30778
30779
30780
30781
30782
30783
30784
30785
30786
30787
30788
30789
30790
30791
30792
30793
30794
30795
30796
30797
30798
30799
30800
30801
30802
30803
30804
30805
30806
30807
30808
30809
30810
30811
30812
30813
30814
30815
30816
30817
30818
30819
30820
30821
30822
30823
30824
30825
30826
30827
30828
30829
30830
30831
30832
30833
30834
30835
30836
30837
30838
30839
30840
30841
30842
30843
30844
30845
30846
30847
30848
30849
30850
30851
30852
30853
30854
30855
30856
30857
30858
30859
30860
30861
30862
30863
30864
30865
30866
30867
30868
30869
30870
30871
30872
30873
30874
30875
30876
30877
30878
30879
30880
30881
30882
30883
30884
30885
30886
30887
30888
30889
30890
30891
30892
30893
30894
30895
30896
30897
30898
30899
30900
30901
30902
30903
30904
30905
30906
30907
30908
30909
30910
30911
30912
30913
30914
30915
30916
30917
30918
30919
30920
30921
30922
30923
30924
30925
30926
30927
30928
30929
30930
30931
30932
30933
30934
30935
30936
30937
30938
30939
30940
30941
30942
30943
30944
30945
30946
30947
30948
30949
30950
30951
30952
30953
30954
30955
30956
30957
30958
30959
30960
30961
30962
30963
30964
30965
30966
30967
30968
30969
30970
30971
30972
30973
30974
30975
30976
30977
30978
30979
30980
30981
30982
30983
30984
30985
30986
30987
30988
30989
30990
30991
30992
30993
30994
30995
30996
30997
30998
30999
31000
31001
31002
31003
31004
31005
31006
31007
31008
31009
31010
31011
31012
31013
31014
31015
31016
31017
31018
31019
31020
31021
31022
31023
31024
31025
31026
31027
31028
31029
31030
31031
31032
31033
31034
31035
31036
31037
31038
31039
31040
31041
31042
31043
31044
31045
31046
31047
31048
31049
31050
31051
31052
31053
31054
31055
31056
31057
31058
31059
31060
31061
31062
31063
31064
31065
31066
31067
31068
31069
31070
31071
31072
31073
31074
31075
31076
31077
31078
31079
31080
31081
31082
31083
31084
31085
31086
31087
31088
31089
31090
31091
31092
31093
31094
31095
31096
31097
31098
31099
31100
31101
31102
31103
31104
31105
31106
31107
31108
31109
31110
31111
31112
31113
31114
31115
31116
31117
31118
31119
31120
31121
31122
31123
31124
31125
31126
31127
31128
31129
31130
31131
31132
31133
31134
31135
31136
31137
31138
31139
31140
31141
31142
31143
31144
31145
31146
31147
31148
31149
31150
31151
31152
31153
31154
31155
31156
31157
31158
31159
31160
31161
31162
31163
31164
31165
31166
31167
31168
31169
31170
31171
31172
31173
31174
31175
31176
31177
31178
31179
31180
31181
31182
31183
31184
31185
31186
31187
31188
31189
31190
31191
31192
31193
31194
31195
31196
31197
31198
31199
31200
31201
31202
31203
31204
31205
31206
31207
31208
31209
31210
31211
31212
31213
31214
31215
31216
31217
31218
31219
31220
31221
31222
31223
31224
31225
31226
31227
31228
31229
31230
31231
31232
31233
31234
31235
31236
31237
31238
31239
31240
31241
31242
31243
31244
31245
31246
31247
31248
31249
31250
31251
31252
31253
31254
31255
31256
31257
31258
31259
31260
31261
31262
31263
31264
31265
31266
31267
31268
31269
31270
31271
31272
31273
31274
31275
31276
31277
31278
31279
31280
31281
31282
31283
31284
31285
31286
31287
31288
31289
31290
31291
31292
31293
31294
31295
31296
31297
31298
31299
31300
31301
31302
31303
31304
31305
31306
31307
31308
31309
31310
31311
31312
31313
31314
31315
31316
31317
31318
31319
31320
31321
31322
31323
31324
31325
31326
31327
31328
31329
31330
31331
31332
31333
31334
31335
31336
31337
31338
31339
31340
31341
31342
31343
31344
31345
31346
31347
31348
31349
31350
31351
31352
31353
31354
31355
31356
31357
31358
31359
31360
31361
31362
31363
31364
31365
31366
31367
31368
31369
31370
31371
31372
31373
31374
31375
31376
31377
31378
31379
31380
31381
31382
31383
31384
31385
31386
31387
31388
31389
31390
31391
31392
31393
31394
31395
31396
31397
31398
31399
31400
31401
31402
31403
31404
31405
31406
31407
31408
31409
31410
31411
31412
31413
31414
31415
31416
31417
31418
31419
31420
31421
31422
31423
31424
31425
31426
31427
31428
31429
31430
31431
31432
31433
31434
31435
31436
31437
31438
31439
31440
31441
31442
31443
31444
31445
31446
31447
31448
31449
31450
31451
31452
31453
31454
31455
31456
31457
31458
31459
31460
31461
31462
31463
31464
31465
31466
31467
31468
31469
31470
31471
31472
31473
31474
31475
31476
31477
31478
31479
31480
31481
31482
31483
31484
31485
31486
31487
31488
31489
31490
31491
31492
31493
31494
31495
31496
31497
31498
31499
31500
31501
31502
31503
31504
31505
31506
31507
31508
31509
31510
31511
31512
31513
31514
31515
31516
31517
31518
31519
31520
31521
31522
31523
31524
31525
31526
31527
31528
31529
31530
31531
31532
31533
31534
31535
31536
31537
31538
31539
31540
31541
31542
31543
31544
31545
31546
31547
31548
31549
31550
31551
31552
31553
31554
31555
31556
31557
31558
31559
31560
31561
31562
31563
31564
31565
31566
31567
31568
31569
31570
31571
31572
31573
31574
31575
31576
31577
31578
31579
31580
31581
31582
31583
31584
31585
31586
31587
31588
31589
31590
31591
31592
31593
31594
31595
31596
31597
31598
31599
31600
31601
31602
31603
31604
31605
31606
31607
31608
31609
31610
31611
31612
31613
31614
31615
31616
31617
31618
31619
31620
31621
31622
31623
31624
31625
31626
31627
31628
31629
31630
31631
31632
31633
31634
31635
31636
31637
31638
31639
31640
31641
31642
31643
31644
31645
31646
31647
31648
31649
31650
31651
31652
31653
31654
31655
31656
31657
31658
31659
31660
31661
31662
31663
31664
31665
31666
31667
31668
31669
31670
31671
31672
31673
31674
31675
31676
31677
31678
31679
31680
31681
31682
31683
31684
31685
31686
31687
31688
31689
31690
31691
31692
31693
31694
31695
31696
31697
31698
31699
31700
31701
31702
31703
31704
31705
31706
31707
31708
31709
31710
31711
31712
31713
31714
31715
31716
31717
31718
31719
31720
31721
31722
31723
31724
31725
31726
31727
31728
31729
31730
31731
31732
31733
31734
31735
31736
31737
31738
31739
31740
31741
31742
31743
31744
31745
31746
31747
31748
31749
31750
31751
31752
31753
31754
31755
31756
31757
31758
31759
31760
31761
31762
31763
31764
31765
31766
31767
31768
31769
31770
31771
31772
31773
31774
31775
31776
31777
31778
31779
31780
31781
31782
31783
31784
31785
31786
31787
31788
31789
31790
31791
31792
31793
31794
31795
31796
31797
31798
31799
31800
31801
31802
31803
31804
31805
31806
31807
31808
31809
31810
31811
31812
31813
31814
31815
31816
31817
31818
31819
31820
31821
31822
31823
31824
31825
31826
31827
31828
31829
31830
31831
31832
31833
31834
31835
31836
31837
31838
31839
31840
31841
31842
31843
31844
31845
31846
31847
31848
31849
31850
31851
31852
31853
31854
31855
31856
31857
31858
31859
31860
31861
31862
31863
31864
31865
31866
31867
31868
31869
31870
31871
31872
31873
31874
31875
31876
31877
31878
31879
31880
31881
31882
31883
31884
31885
31886
31887
31888
31889
31890
31891
31892
31893
31894
31895
31896
31897
31898
31899
31900
31901
31902
31903
31904
31905
31906
31907
31908
31909
31910
31911
31912
31913
31914
31915
31916
31917
31918
31919
31920
31921
31922
31923
31924
31925
31926
31927
31928
31929
31930
31931
31932
31933
31934
31935
31936
31937
31938
31939
31940
31941
31942
31943
31944
31945
31946
31947
31948
31949
31950
31951
31952
31953
31954
31955
31956
31957
31958
31959
31960
31961
31962
31963
31964
31965
31966
31967
31968
31969
31970
31971
31972
31973
31974
31975
31976
31977
31978
31979
31980
31981
31982
31983
31984
31985
31986
31987
31988
31989
31990
31991
31992
31993
31994
31995
31996
31997
31998
31999
32000
32001
32002
32003
32004
32005
32006
32007
32008
32009
32010
32011
32012
32013
32014
32015
32016
32017
32018
32019
32020
32021
32022
32023
32024
32025
32026
32027
32028
32029
32030
32031
32032
32033
32034
32035
32036
32037
32038
32039
32040
32041
32042
32043
32044
32045
32046
32047
32048
32049
32050
32051
32052
32053
32054
32055
32056
32057
32058
32059
32060
32061
32062
32063
32064
32065
32066
32067
32068
32069
32070
32071
32072
32073
32074
32075
32076
32077
32078
32079
32080
32081
32082
32083
32084
32085
32086
32087
32088
32089
32090
32091
32092
32093
32094
32095
32096
32097
32098
32099
32100
32101
32102
32103
32104
32105
32106
32107
32108
32109
32110
32111
32112
32113
32114
32115
32116
32117
32118
32119
32120
32121
32122
32123
32124
32125
32126
32127
32128
32129
32130
32131
32132
32133
32134
32135
32136
32137
32138
32139
32140
32141
32142
32143
32144
32145
32146
32147
32148
32149
32150
32151
32152
32153
32154
32155
32156
32157
32158
32159
32160
32161
32162
32163
32164
32165
32166
32167
32168
32169
32170
32171
32172
32173
32174
32175
32176
32177
32178
32179
32180
32181
32182
32183
32184
32185
32186
32187
32188
32189
32190
32191
32192
32193
32194
32195
32196
32197
32198
32199
32200
32201
32202
32203
32204
32205
32206
32207
32208
32209
32210
32211
32212
32213
32214
32215
32216
32217
32218
32219
32220
32221
32222
32223
32224
32225
32226
32227
32228
32229
32230
32231
32232
32233
32234
32235
32236
32237
32238
32239
32240
32241
32242
32243
32244
32245
32246
32247
32248
32249
32250
32251
32252
32253
32254
32255
32256
32257
32258
32259
32260
32261
32262
32263
32264
32265
32266
32267
32268
32269
32270
32271
32272
32273
32274
32275
32276
32277
32278
32279
32280
32281
32282
32283
32284
32285
32286
32287
32288
32289
32290
32291
32292
32293
32294
32295
32296
32297
32298
32299
32300
32301
32302
32303
32304
32305
32306
32307
32308
32309
32310
32311
32312
32313
32314
32315
32316
32317
32318
32319
32320
32321
32322
32323
32324
32325
32326
32327
32328
32329
32330
32331
32332
32333
32334
32335
32336
32337
32338
32339
32340
32341
32342
32343
32344
32345
32346
32347
32348
32349
32350
32351
32352
32353
32354
32355
32356
32357
32358
32359
32360
32361
32362
32363
32364
32365
32366
32367
32368
32369
32370
32371
32372
32373
32374
32375
32376
32377
32378
32379
32380
32381
32382
32383
32384
32385
32386
32387
32388
32389
32390
32391
32392
32393
32394
32395
32396
32397
32398
32399
32400
32401
32402
32403
32404
32405
32406
32407
32408
32409
32410
32411
32412
32413
32414
32415
32416
32417
32418
32419
32420
32421
32422
32423
32424
32425
32426
32427
32428
32429
32430
32431
32432
32433
32434
32435
32436
32437
32438
32439
32440
32441
32442
32443
32444
32445
32446
32447
32448
32449
32450
32451
32452
32453
32454
32455
32456
32457
32458
32459
32460
32461
32462
32463
32464
32465
32466
32467
32468
32469
32470
32471
32472
32473
32474
32475
32476
32477
32478
32479
32480
32481
32482
32483
32484
32485
32486
32487
32488
32489
32490
32491
32492
32493
32494
32495
32496
32497
32498
32499
32500
32501
32502
32503
32504
32505
32506
32507
32508
32509
32510
32511
32512
32513
32514
32515
32516
32517
32518
32519
32520
32521
32522
32523
32524
32525
32526
32527
32528
32529
32530
32531
32532
32533
32534
32535
32536
32537
32538
32539
32540
32541
32542
32543
32544
32545
32546
32547
32548
32549
32550
32551
32552
32553
32554
32555
32556
32557
32558
32559
32560
32561
32562
32563
32564
32565
32566
32567
32568
32569
32570
32571
32572
32573
32574
32575
32576
32577
32578
32579
32580
32581
32582
32583
32584
32585
32586
32587
32588
32589
32590
32591
32592
32593
32594
32595
32596
32597
32598
32599
32600
32601
32602
32603
32604
32605
32606
32607
32608
32609
32610
32611
32612
32613
32614
32615
32616
32617
32618
32619
32620
32621
32622
32623
32624
32625
32626
32627
32628
32629
32630
32631
32632
32633
32634
32635
32636
32637
32638
32639
32640
32641
32642
32643
32644
32645
32646
32647
32648
32649
32650
32651
32652
32653
32654
32655
32656
32657
32658
32659
32660
32661
32662
32663
32664
32665
32666
32667
32668
32669
32670
32671
32672
32673
32674
32675
32676
32677
32678
32679
32680
32681
32682
32683
32684
32685
32686
32687
32688
32689
32690
32691
32692
32693
32694
32695
32696
32697
32698
32699
32700
32701
32702
32703
32704
32705
32706
32707
32708
32709
32710
32711
32712
32713
32714
32715
32716
32717
32718
32719
32720
32721
32722
32723
32724
32725
32726
32727
32728
32729
32730
32731
32732
32733
32734
32735
32736
32737
32738
32739
32740
32741
32742
32743
32744
32745
32746
32747
32748
32749
32750
32751
32752
32753
32754
32755
32756
32757
32758
32759
32760
32761
32762
32763
32764
32765
32766
32767
32768
32769
32770
32771
32772
32773
32774
32775
32776
32777
32778
32779
32780
32781
32782
32783
32784
32785
32786
32787
32788
32789
32790
32791
32792
32793
32794
32795
32796
32797
32798
32799
32800
32801
32802
32803
32804
32805
32806
32807
32808
32809
32810
32811
32812
32813
32814
32815
32816
32817
32818
32819
32820
32821
32822
32823
32824
32825
32826
32827
32828
32829
32830
32831
32832
32833
32834
32835
32836
32837
32838
32839
32840
32841
32842
32843
32844
32845
32846
32847
32848
32849
32850
32851
32852
32853
32854
32855
32856
32857
32858
32859
32860
32861
32862
32863
32864
32865
32866
32867
32868
32869
32870
32871
32872
32873
32874
32875
32876
32877
32878
32879
32880
32881
32882
32883
32884
32885
32886
32887
32888
32889
32890
32891
32892
32893
32894
32895
32896
32897
32898
32899
32900
32901
32902
32903
32904
32905
32906
32907
32908
32909
32910
32911
32912
32913
32914
32915
32916
32917
32918
32919
32920
32921
32922
32923
32924
32925
32926
32927
32928
32929
32930
32931
32932
32933
32934
32935
32936
32937
32938
32939
32940
32941
32942
32943
32944
32945
32946
32947
32948
32949
32950
32951
32952
32953
32954
32955
32956
32957
32958
32959
32960
32961
32962
32963
32964
32965
32966
32967
32968
32969
32970
32971
32972
32973
32974
32975
32976
32977
32978
32979
32980
32981
32982
32983
32984
32985
32986
32987
32988
32989
32990
32991
32992
32993
32994
32995
32996
32997
32998
32999
33000
33001
33002
33003
33004
33005
33006
33007
33008
33009
33010
33011
33012
33013
33014
33015
33016
33017
33018
33019
33020
33021
33022
33023
33024
33025
33026
33027
33028
33029
33030
33031
33032
33033
33034
33035
33036
33037
33038
33039
33040
33041
33042
33043
33044
33045
33046
33047
33048
33049
33050
33051
33052
33053
33054
33055
33056
33057
33058
33059
33060
33061
33062
33063
33064
33065
33066
33067
33068
33069
33070
33071
33072
33073
33074
33075
33076
33077
33078
33079
33080
33081
33082
33083
33084
33085
33086
33087
33088
33089
33090
33091
33092
33093
33094
33095
33096
33097
33098
33099
33100
33101
33102
33103
33104
33105
33106
33107
33108
33109
33110
33111
33112
33113
33114
33115
33116
33117
33118
33119
33120
33121
33122
33123
33124
33125
33126
33127
33128
33129
33130
33131
33132
33133
33134
33135
33136
33137
33138
33139
33140
33141
33142
33143
33144
33145
33146
33147
33148
33149
33150
33151
33152
33153
33154
33155
33156
33157
33158
33159
33160
33161
33162
33163
33164
33165
33166
33167
33168
33169
33170
33171
33172
33173
33174
33175
33176
33177
33178
33179
33180
33181
33182
33183
33184
33185
33186
33187
33188
33189
33190
33191
33192
33193
33194
33195
33196
33197
33198
33199
33200
33201
33202
33203
33204
33205
33206
33207
33208
33209
33210
33211
33212
33213
33214
33215
33216
33217
33218
33219
33220
33221
33222
33223
33224
33225
33226
33227
33228
33229
33230
33231
33232
33233
33234
33235
33236
33237
33238
33239
33240
33241
33242
33243
33244
33245
33246
33247
33248
33249
33250
33251
33252
33253
33254
33255
33256
33257
33258
33259
33260
33261
33262
33263
33264
33265
33266
33267
33268
33269
33270
33271
33272
33273
33274
33275
33276
33277
33278
33279
33280
33281
33282
33283
33284
33285
33286
33287
33288
33289
33290
33291
33292
33293
33294
33295
33296
33297
33298
33299
33300
33301
33302
33303
33304
33305
33306
33307
33308
33309
33310
33311
33312
33313
33314
33315
33316
33317
33318
33319
33320
33321
33322
33323
33324
33325
33326
33327
33328
33329
33330
33331
33332
33333
33334
33335
33336
33337
33338
33339
33340
33341
33342
33343
33344
33345
33346
33347
33348
33349
33350
33351
33352
33353
33354
33355
33356
33357
33358
33359
33360
33361
33362
33363
33364
33365
33366
33367
33368
33369
33370
33371
33372
33373
33374
33375
33376
33377
33378
33379
33380
33381
33382
33383
33384
33385
33386
33387
33388
33389
33390
33391
33392
33393
33394
33395
33396
33397
33398
33399
33400
33401
33402
33403
33404
33405
33406
33407
33408
33409
33410
33411
33412
33413
33414
33415
33416
33417
33418
33419
33420
33421
33422
33423
33424
33425
33426
33427
33428
33429
33430
33431
33432
33433
33434
33435
33436
33437
33438
33439
33440
33441
33442
33443
33444
33445
33446
33447
33448
33449
33450
33451
33452
33453
33454
33455
33456
33457
33458
33459
33460
33461
33462
33463
33464
33465
33466
33467
33468
33469
33470
33471
33472
33473
33474
33475
33476
33477
33478
33479
33480
33481
33482
33483
33484
33485
33486
33487
33488
33489
33490
33491
33492
33493
33494
33495
33496
33497
33498
33499
33500
33501
33502
33503
33504
33505
33506
33507
33508
33509
33510
33511
33512
33513
33514
33515
33516
33517
33518
33519
33520
33521
33522
33523
33524
33525
33526
33527
33528
33529
33530
33531
33532
33533
33534
33535
33536
33537
33538
33539
33540
33541
33542
33543
33544
33545
33546
33547
33548
33549
33550
33551
33552
33553
33554
33555
33556
33557
33558
33559
33560
33561
33562
33563
33564
33565
33566
33567
33568
33569
33570
33571
33572
33573
33574
33575
33576
33577
33578
33579
33580
33581
33582
33583
33584
33585
33586
33587
33588
33589
33590
33591
33592
33593
33594
33595
33596
33597
33598
33599
33600
33601
33602
33603
33604
33605
33606
33607
33608
33609
33610
33611
33612
33613
33614
33615
33616
33617
33618
33619
33620
33621
33622
33623
33624
33625
33626
33627
33628
33629
33630
33631
33632
33633
33634
33635
33636
33637
33638
33639
33640
33641
33642
33643
33644
33645
33646
33647
33648
33649
33650
33651
33652
33653
33654
33655
33656
33657
33658
33659
33660
33661
33662
33663
33664
33665
33666
33667
33668
33669
33670
33671
33672
33673
33674
33675
33676
33677
33678
33679
33680
33681
33682
33683
33684
33685
33686
33687
33688
33689
33690
33691
33692
33693
33694
33695
33696
33697
33698
33699
33700
33701
33702
33703
33704
33705
33706
33707
33708
33709
33710
33711
33712
33713
33714
33715
33716
33717
33718
33719
33720
33721
33722
33723
33724
33725
33726
33727
33728
33729
33730
33731
33732
33733
33734
33735
33736
33737
33738
33739
33740
33741
33742
33743
33744
33745
33746
33747
33748
33749
33750
33751
33752
33753
33754
33755
33756
33757
33758
33759
33760
33761
33762
33763
33764
33765
33766
33767
33768
33769
33770
33771
33772
33773
33774
33775
33776
33777
33778
33779
33780
33781
33782
33783
33784
33785
33786
33787
33788
33789
33790
33791
33792
33793
33794
33795
33796
33797
33798
33799
33800
33801
33802
33803
33804
33805
33806
33807
33808
33809
33810
33811
33812
33813
33814
33815
33816
33817
33818
33819
33820
33821
33822
33823
33824
33825
33826
33827
33828
33829
33830
33831
33832
33833
33834
33835
33836
33837
33838
33839
33840
33841
33842
33843
33844
33845
33846
33847
33848
33849
33850
33851
33852
33853
33854
33855
33856
33857
33858
33859
33860
33861
33862
33863
33864
33865
33866
33867
33868
33869
33870
33871
33872
33873
33874
33875
33876
33877
33878
33879
33880
33881
33882
33883
33884
33885
33886
33887
33888
33889
33890
33891
33892
33893
33894
33895
33896
33897
33898
33899
33900
33901
33902
33903
33904
33905
33906
33907
33908
33909
33910
33911
33912
33913
33914
33915
33916
33917
33918
33919
33920
33921
33922
33923
33924
33925
33926
33927
33928
33929
33930
33931
33932
33933
33934
33935
33936
33937
33938
33939
33940
33941
33942
33943
33944
33945
33946
33947
33948
33949
33950
33951
33952
33953
33954
33955
33956
33957
33958
33959
33960
33961
33962
33963
33964
33965
33966
33967
33968
33969
33970
33971
33972
33973
33974
33975
33976
33977
33978
33979
33980
33981
33982
33983
33984
33985
33986
33987
33988
33989
33990
33991
33992
33993
33994
33995
33996
33997
33998
33999
34000
34001
34002
34003
34004
34005
34006
34007
34008
34009
34010
34011
34012
34013
34014
34015
34016
34017
34018
34019
34020
34021
34022
34023
34024
34025
34026
34027
34028
34029
34030
34031
34032
34033
34034
34035
34036
34037
34038
34039
34040
34041
34042
34043
34044
34045
34046
34047
34048
34049
34050
34051
34052
34053
34054
34055
34056
34057
34058
34059
34060
34061
34062
34063
34064
34065
34066
34067
34068
34069
34070
34071
34072
34073
34074
34075
34076
34077
34078
34079
34080
34081
34082
34083
34084
34085
34086
34087
34088
34089
34090
34091
34092
34093
34094
34095
34096
34097
34098
34099
34100
34101
34102
34103
34104
34105
34106
34107
34108
34109
34110
34111
34112
34113
34114
34115
34116
34117
34118
34119
34120
34121
34122
34123
34124
34125
34126
34127
34128
34129
34130
34131
34132
34133
34134
34135
34136
34137
34138
34139
34140
34141
34142
34143
34144
34145
34146
34147
34148
34149
34150
34151
34152
34153
34154
34155
34156
34157
34158
34159
34160
34161
34162
34163
34164
34165
34166
34167
34168
34169
34170
34171
34172
34173
34174
34175
34176
34177
34178
34179
34180
34181
34182
34183
34184
34185
34186
34187
34188
34189
34190
34191
34192
34193
34194
34195
34196
34197
34198
34199
34200
34201
34202
34203
34204
34205
34206
34207
34208
34209
34210
34211
34212
34213
34214
34215
34216
34217
34218
34219
34220
34221
34222
34223
34224
34225
34226
34227
34228
34229
34230
34231
34232
34233
34234
34235
34236
34237
34238
34239
34240
34241
34242
34243
34244
34245
34246
34247
34248
34249
34250
34251
34252
34253
34254
34255
34256
34257
34258
34259
34260
34261
34262
34263
34264
34265
34266
34267
34268
34269
34270
34271
34272
34273
34274
34275
34276
34277
34278
34279
34280
34281
34282
34283
34284
34285
34286
34287
34288
34289
34290
34291
34292
34293
34294
34295
34296
34297
34298
34299
34300
34301
34302
34303
34304
34305
34306
34307
34308
34309
34310
34311
34312
34313
34314
34315
34316
34317
34318
34319
34320
34321
34322
34323
34324
34325
34326
34327
34328
34329
34330
34331
34332
34333
34334
34335
34336
34337
34338
34339
34340
34341
34342
34343
34344
34345
34346
34347
34348
34349
34350
34351
34352
34353
34354
34355
34356
34357
34358
34359
34360
34361
34362
34363
34364
34365
34366
34367
34368
34369
34370
34371
34372
34373
34374
34375
34376
34377
34378
34379
34380
34381
34382
34383
34384
34385
34386
34387
34388
34389
34390
34391
34392
34393
34394
34395
34396
34397
34398
34399
34400
34401
34402
34403
34404
34405
34406
34407
34408
34409
34410
34411
34412
34413
34414
34415
34416
34417
34418
34419
34420
34421
34422
34423
34424
34425
34426
34427
34428
34429
34430
34431
34432
34433
34434
34435
34436
34437
34438
34439
34440
34441
34442
34443
34444
34445
34446
34447
34448
34449
34450
34451
34452
34453
34454
34455
34456
34457
34458
34459
34460
34461
34462
34463
34464
34465
34466
34467
34468
34469
34470
34471
34472
34473
34474
34475
34476
34477
34478
34479
34480
34481
34482
34483
34484
34485
34486
34487
34488
34489
34490
34491
34492
34493
34494
34495
34496
34497
34498
34499
34500
34501
34502
34503
34504
34505
34506
34507
34508
34509
34510
34511
34512
34513
34514
34515
34516
34517
34518
34519
34520
34521
34522
34523
34524
34525
34526
34527
34528
34529
34530
34531
34532
34533
34534
34535
34536
34537
34538
34539
34540
34541
34542
34543
34544
34545
34546
34547
34548
34549
34550
34551
34552
34553
34554
34555
34556
34557
34558
34559
34560
34561
34562
34563
34564
34565
34566
34567
34568
34569
34570
34571
34572
34573
34574
34575
34576
34577
34578
34579
34580
34581
34582
34583
34584
34585
34586
34587
34588
34589
34590
34591
34592
34593
34594
34595
34596
34597
34598
34599
34600
34601
34602
34603
34604
34605
34606
34607
34608
34609
34610
34611
34612
34613
34614
34615
34616
34617
34618
34619
34620
34621
34622
34623
34624
34625
34626
34627
34628
34629
34630
34631
34632
34633
34634
34635
34636
34637
34638
34639
34640
34641
34642
34643
34644
34645
34646
34647
34648
34649
34650
34651
34652
34653
34654
34655
34656
34657
34658
34659
34660
34661
34662
34663
34664
34665
34666
34667
34668
34669
34670
34671
34672
34673
34674
34675
34676
34677
34678
34679
34680
34681
34682
34683
34684
34685
34686
34687
34688
34689
34690
34691
34692
34693
34694
34695
34696
34697
34698
34699
34700
34701
34702
34703
34704
34705
34706
34707
34708
34709
34710
34711
34712
34713
34714
34715
34716
34717
34718
34719
34720
34721
34722
34723
34724
34725
34726
34727
34728
34729
34730
34731
34732
34733
34734
34735
34736
34737
34738
34739
34740
34741
34742
34743
34744
34745
34746
34747
34748
34749
34750
34751
34752
34753
34754
34755
34756
34757
34758
34759
34760
34761
34762
34763
34764
34765
34766
34767
34768
34769
34770
34771
34772
34773
34774
34775
34776
34777
34778
34779
34780
34781
34782
34783
34784
34785
34786
34787
34788
34789
34790
34791
34792
34793
34794
34795
34796
34797
34798
34799
34800
34801
34802
34803
34804
34805
34806
34807
34808
34809
34810
34811
34812
34813
34814
34815
34816
34817
34818
34819
34820
34821
34822
34823
34824
34825
34826
34827
34828
34829
34830
34831
34832
34833
34834
34835
34836
34837
34838
34839
34840
34841
34842
34843
34844
34845
34846
34847
34848
34849
34850
34851
34852
34853
34854
34855
34856
34857
34858
34859
34860
34861
34862
34863
34864
34865
34866
34867
34868
34869
34870
34871
34872
34873
34874
34875
34876
34877
34878
34879
34880
34881
34882
34883
34884
34885
34886
34887
34888
34889
34890
34891
34892
34893
34894
34895
34896
34897
34898
34899
34900
34901
34902
34903
34904
34905
34906
34907
34908
34909
34910
34911
34912
34913
34914
34915
34916
34917
34918
34919
34920
34921
34922
34923
34924
34925
34926
34927
34928
34929
34930
34931
34932
34933
34934
34935
34936
34937
34938
34939
34940
34941
34942
34943
34944
34945
34946
34947
34948
34949
34950
34951
34952
34953
34954
34955
34956
34957
34958
34959
34960
34961
34962
34963
34964
34965
34966
34967
34968
34969
34970
34971
34972
34973
34974
34975
34976
34977
34978
34979
34980
34981
34982
34983
34984
34985
34986
34987
34988
34989
34990
34991
34992
34993
34994
34995
34996
34997
34998
34999
35000
35001
35002
35003
35004
35005
35006
35007
35008
35009
35010
35011
35012
35013
35014
35015
35016
35017
35018
35019
35020
35021
35022
35023
35024
35025
35026
35027
35028
35029
35030
35031
35032
35033
35034
35035
35036
35037
35038
35039
35040
35041
35042
35043
35044
35045
35046
35047
35048
35049
35050
35051
35052
35053
35054
35055
35056
35057
35058
35059
35060
35061
35062
35063
35064
35065
35066
35067
35068
35069
35070
35071
35072
35073
35074
35075
35076
35077
35078
35079
35080
35081
35082
35083
35084
35085
35086
35087
35088
35089
35090
35091
35092
35093
35094
35095
35096
35097
35098
35099
35100
35101
35102
35103
35104
35105
35106
35107
35108
35109
35110
35111
35112
35113
35114
35115
35116
35117
35118
35119
35120
35121
35122
35123
35124
35125
35126
35127
35128
35129
35130
35131
35132
35133
35134
35135
35136
35137
35138
35139
35140
35141
35142
35143
35144
35145
35146
35147
35148
35149
35150
35151
35152
35153
35154
35155
35156
35157
35158
35159
35160
35161
35162
35163
35164
35165
35166
35167
35168
35169
35170
35171
35172
35173
35174
35175
35176
35177
35178
35179
35180
35181
35182
35183
35184
35185
35186
35187
35188
35189
35190
35191
35192
35193
35194
35195
35196
35197
35198
35199
35200
35201
35202
35203
35204
35205
35206
35207
35208
35209
35210
35211
35212
35213
35214
35215
35216
35217
35218
35219
35220
35221
35222
35223
35224
35225
35226
35227
35228
35229
35230
35231
35232
35233
35234
35235
35236
35237
35238
35239
35240
35241
35242
35243
35244
35245
35246
35247
35248
35249
35250
35251
35252
35253
35254
35255
35256
35257
35258
35259
35260
35261
35262
35263
35264
35265
35266
35267
35268
35269
35270
35271
35272
35273
35274
35275
35276
35277
35278
35279
35280
35281
35282
35283
35284
35285
35286
35287
35288
35289
35290
35291
35292
35293
35294
35295
35296
35297
35298
35299
35300
35301
35302
35303
35304
35305
35306
35307
35308
35309
35310
35311
35312
35313
35314
35315
35316
35317
35318
35319
35320
35321
35322
35323
35324
35325
35326
35327
35328
35329
35330
35331
35332
35333
35334
35335
35336
35337
35338
35339
35340
35341
35342
35343
35344
35345
35346
35347
35348
35349
35350
35351
35352
35353
35354
35355
35356
35357
35358
35359
35360
35361
35362
35363
35364
35365
35366
35367
35368
35369
35370
35371
35372
35373
35374
35375
35376
35377
35378
35379
35380
35381
35382
35383
35384
35385
35386
35387
35388
35389
35390
35391
35392
35393
35394
35395
35396
35397
35398
35399
35400
35401
35402
35403
35404
35405
35406
35407
35408
35409
35410
35411
35412
35413
35414
35415
35416
35417
35418
35419
35420
35421
35422
35423
35424
35425
35426
35427
35428
35429
35430
35431
35432
35433
35434
35435
35436
35437
35438
35439
35440
35441
35442
35443
35444
35445
35446
35447
35448
35449
35450
35451
35452
35453
35454
35455
35456
35457
35458
35459
35460
35461
35462
35463
35464
35465
35466
35467
35468
35469
35470
35471
35472
35473
35474
35475
35476
35477
35478
35479
35480
35481
35482
35483
35484
35485
35486
35487
35488
35489
35490
35491
35492
35493
35494
35495
35496
35497
35498
35499
35500
35501
35502
35503
35504
35505
35506
35507
35508
35509
35510
35511
35512
35513
35514
35515
35516
35517
35518
35519
35520
35521
35522
35523
35524
35525
35526
35527
35528
35529
35530
35531
35532
35533
35534
35535
35536
35537
35538
35539
35540
35541
35542
35543
35544
35545
35546
35547
35548
35549
35550
35551
35552
35553
35554
35555
35556
35557
35558
35559
35560
35561
35562
35563
35564
35565
35566
35567
35568
35569
35570
35571
35572
35573
35574
35575
35576
35577
35578
35579
35580
35581
35582
35583
35584
35585
35586
35587
35588
35589
35590
35591
35592
35593
35594
35595
35596
35597
35598
35599
35600
35601
35602
35603
35604
35605
35606
35607
35608
35609
35610
35611
35612
35613
35614
35615
35616
35617
35618
35619
35620
35621
35622
35623
35624
35625
35626
35627
35628
35629
35630
35631
35632
35633
35634
35635
35636
35637
35638
35639
35640
35641
35642
35643
35644
35645
35646
35647
35648
35649
35650
35651
35652
35653
35654
35655
35656
35657
35658
35659
35660
35661
35662
35663
35664
35665
35666
35667
35668
35669
35670
35671
35672
35673
35674
35675
35676
35677
35678
35679
35680
35681
35682
35683
35684
35685
35686
35687
35688
35689
35690
35691
35692
35693
35694
35695
35696
35697
35698
35699
35700
35701
35702
35703
35704
35705
35706
35707
35708
35709
35710
35711
35712
35713
35714
35715
35716
35717
35718
35719
35720
35721
35722
35723
35724
35725
35726
35727
35728
35729
35730
35731
35732
35733
35734
35735
35736
35737
35738
35739
35740
35741
35742
35743
35744
35745
35746
35747
35748
35749
35750
35751
35752
35753
35754
35755
35756
35757
35758
35759
35760
35761
35762
35763
35764
35765
35766
35767
35768
35769
35770
35771
35772
35773
35774
35775
35776
35777
35778
35779
35780
35781
35782
35783
35784
35785
35786
35787
35788
35789
35790
35791
35792
35793
35794
35795
35796
35797
35798
35799
35800
35801
35802
35803
35804
35805
35806
35807
35808
35809
35810
35811
35812
35813
35814
35815
35816
35817
35818
35819
35820
35821
35822
35823
35824
35825
35826
35827
35828
35829
35830
35831
35832
35833
35834
35835
35836
35837
35838
35839
35840
35841
35842
35843
35844
35845
35846
35847
35848
35849
35850
35851
35852
35853
35854
35855
35856
35857
35858
35859
35860
35861
35862
35863
35864
35865
35866
35867
35868
35869
35870
35871
35872
35873
35874
35875
35876
35877
35878
35879
35880
35881
35882
35883
35884
35885
35886
35887
35888
35889
35890
35891
35892
35893
35894
35895
35896
35897
35898
35899
35900
35901
35902
35903
35904
35905
35906
35907
35908
35909
35910
35911
35912
35913
35914
35915
35916
35917
35918
35919
35920
35921
35922
35923
35924
35925
35926
35927
35928
35929
35930
35931
35932
35933
35934
35935
35936
35937
35938
35939
35940
35941
35942
35943
35944
35945
35946
35947
35948
35949
35950
35951
35952
35953
35954
35955
35956
35957
35958
35959
35960
35961
35962
35963
35964
35965
35966
35967
35968
35969
35970
35971
35972
35973
35974
35975
35976
35977
35978
35979
35980
35981
35982
35983
35984
35985
35986
35987
35988
35989
35990
35991
35992
35993
35994
35995
35996
35997
35998
35999
36000
36001
36002
36003
36004
36005
36006
36007
36008
36009
36010
36011
36012
36013
36014
36015
36016
36017
36018
36019
36020
36021
36022
36023
36024
36025
36026
36027
36028
36029
36030
36031
36032
36033
36034
36035
36036
36037
36038
36039
36040
36041
36042
36043
36044
36045
36046
36047
36048
36049
36050
36051
36052
36053
36054
36055
36056
36057
36058
36059
36060
36061
36062
36063
36064
36065
36066
36067
36068
36069
36070
36071
36072
36073
36074
36075
36076
36077
36078
36079
36080
36081
36082
36083
36084
36085
36086
36087
36088
36089
36090
36091
36092
36093
36094
36095
36096
36097
36098
36099
36100
36101
36102
36103
36104
36105
36106
36107
36108
36109
36110
36111
36112
36113
36114
36115
36116
36117
36118
36119
36120
36121
36122
36123
36124
36125
36126
36127
36128
36129
36130
36131
36132
36133
36134
36135
36136
36137
36138
36139
36140
36141
36142
36143
36144
36145
36146
36147
36148
36149
36150
36151
36152
36153
36154
36155
36156
36157
36158
36159
36160
36161
36162
36163
36164
36165
36166
36167
36168
36169
36170
36171
36172
36173
36174
36175
36176
36177
36178
36179
36180
36181
36182
36183
36184
36185
36186
36187
36188
36189
36190
36191
36192
36193
36194
36195
36196
36197
36198
36199
36200
36201
36202
36203
36204
36205
36206
36207
36208
36209
36210
36211
36212
36213
36214
36215
36216
36217
36218
36219
36220
36221
36222
36223
36224
36225
36226
36227
36228
36229
36230
36231
36232
36233
36234
36235
36236
36237
36238
36239
36240
36241
36242
36243
36244
36245
36246
36247
36248
36249
36250
36251
36252
36253
36254
36255
36256
36257
36258
36259
36260
36261
36262
36263
36264
36265
36266
36267
36268
36269
36270
36271
36272
36273
36274
36275
36276
36277
36278
36279
36280
36281
36282
36283
36284
36285
36286
36287
36288
36289
36290
36291
36292
36293
36294
36295
36296
36297
36298
36299
36300
36301
36302
36303
36304
36305
36306
36307
36308
36309
36310
36311
36312
36313
36314
36315
36316
36317
36318
36319
36320
36321
36322
36323
36324
36325
36326
36327
36328
36329
36330
36331
36332
36333
36334
36335
36336
36337
36338
36339
36340
36341
36342
36343
36344
36345
36346
36347
36348
36349
36350
36351
36352
36353
36354
36355
36356
36357
36358
36359
36360
36361
36362
36363
36364
36365
36366
36367
36368
36369
36370
36371
36372
36373
36374
36375
36376
36377
36378
36379
36380
36381
36382
36383
36384
36385
36386
36387
36388
36389
36390
36391
36392
36393
36394
36395
36396
36397
36398
36399
36400
36401
36402
36403
36404
36405
36406
36407
36408
36409
36410
36411
36412
36413
36414
36415
36416
36417
36418
36419
36420
36421
36422
36423
36424
36425
36426
36427
36428
36429
36430
36431
36432
36433
36434
36435
36436
36437
36438
36439
36440
36441
36442
36443
36444
36445
36446
36447
36448
36449
36450
36451
36452
36453
36454
36455
36456
36457
36458
36459
36460
36461
36462
36463
36464
36465
36466
36467
36468
36469
36470
36471
36472
36473
36474
36475
36476
36477
36478
36479
36480
36481
36482
36483
36484
36485
36486
36487
36488
36489
36490
36491
36492
36493
36494
36495
36496
36497
36498
36499
36500
36501
36502
36503
36504
36505
36506
36507
36508
36509
36510
36511
36512
36513
36514
36515
36516
36517
36518
36519
36520
36521
36522
36523
36524
36525
36526
36527
36528
36529
36530
36531
36532
36533
36534
36535
36536
36537
36538
36539
36540
36541
36542
36543
36544
36545
36546
36547
36548
36549
36550
36551
36552
36553
36554
36555
36556
36557
36558
36559
36560
36561
36562
36563
36564
36565
36566
36567
36568
36569
36570
36571
36572
36573
36574
36575
36576
36577
36578
36579
36580
36581
36582
36583
36584
36585
36586
36587
36588
36589
36590
36591
36592
36593
36594
36595
36596
36597
36598
36599
36600
36601
36602
36603
36604
36605
36606
36607
36608
36609
36610
36611
36612
36613
36614
36615
36616
36617
36618
36619
36620
36621
36622
36623
36624
36625
36626
36627
36628
36629
36630
36631
36632
36633
36634
36635
36636
36637
36638
36639
36640
36641
36642
36643
36644
36645
36646
36647
36648
36649
36650
36651
36652
36653
36654
36655
36656
36657
36658
36659
36660
36661
36662
36663
36664
36665
36666
36667
36668
36669
36670
36671
36672
36673
36674
36675
36676
36677
36678
36679
36680
36681
36682
36683
36684
36685
36686
36687
36688
36689
36690
36691
36692
36693
36694
36695
36696
36697
36698
36699
36700
36701
36702
36703
36704
36705
36706
36707
36708
36709
36710
36711
36712
36713
36714
36715
36716
36717
36718
36719
36720
36721
36722
36723
36724
36725
36726
36727
36728
36729
36730
36731
36732
36733
36734
36735
36736
36737
36738
36739
36740
36741
36742
36743
36744
36745
36746
36747
36748
36749
36750
36751
36752
36753
36754
36755
36756
36757
36758
36759
36760
36761
36762
36763
36764
36765
36766
36767
36768
36769
36770
36771
36772
36773
36774
36775
36776
36777
36778
36779
36780
36781
36782
36783
36784
36785
36786
36787
36788
36789
36790
36791
36792
36793
36794
36795
36796
36797
36798
36799
36800
36801
36802
36803
36804
36805
36806
36807
36808
36809
36810
36811
36812
36813
36814
36815
36816
36817
36818
36819
36820
36821
36822
36823
36824
36825
36826
36827
36828
36829
36830
36831
36832
36833
36834
36835
36836
36837
36838
36839
36840
36841
36842
36843
36844
36845
36846
36847
36848
36849
36850
36851
36852
36853
36854
36855
36856
36857
36858
36859
36860
36861
36862
36863
36864
36865
36866
36867
36868
36869
36870
36871
36872
36873
36874
36875
36876
36877
36878
36879
36880
36881
36882
36883
36884
36885
36886
36887
36888
36889
36890
36891
36892
36893
36894
36895
36896
36897
36898
36899
36900
36901
36902
36903
36904
36905
36906
36907
36908
36909
36910
36911
36912
36913
36914
36915
36916
36917
36918
36919
36920
36921
36922
36923
36924
36925
36926
36927
36928
36929
36930
36931
36932
36933
36934
36935
36936
36937
36938
36939
36940
36941
36942
36943
36944
36945
36946
36947
36948
36949
36950
36951
36952
36953
36954
36955
36956
36957
36958
36959
36960
36961
36962
36963
36964
36965
36966
36967
36968
36969
36970
36971
36972
36973
36974
36975
36976
36977
36978
36979
36980
36981
36982
36983
36984
36985
36986
36987
36988
36989
36990
36991
36992
36993
36994
36995
36996
36997
36998
36999
37000
37001
37002
37003
37004
37005
37006
37007
37008
37009
37010
37011
37012
37013
37014
37015
37016
37017
37018
37019
37020
37021
37022
37023
37024
37025
37026
37027
37028
37029
37030
37031
37032
37033
37034
37035
37036
37037
37038
37039
37040
37041
37042
37043
37044
37045
37046
37047
37048
37049
37050
37051
37052
37053
37054
37055
37056
37057
37058
37059
37060
37061
37062
37063
37064
37065
37066
37067
37068
37069
37070
37071
37072
37073
37074
37075
37076
37077
37078
37079
37080
37081
37082
37083
37084
37085
37086
37087
37088
37089
37090
37091
37092
37093
37094
37095
37096
37097
37098
37099
37100
37101
37102
37103
37104
37105
37106
37107
37108
37109
37110
37111
37112
37113
37114
37115
37116
37117
37118
37119
37120
37121
37122
37123
37124
37125
37126
37127
37128
37129
37130
37131
37132
37133
37134
37135
37136
37137
37138
37139
37140
37141
37142
37143
37144
37145
37146
37147
37148
37149
37150
37151
37152
37153
37154
37155
37156
37157
37158
37159
37160
37161
37162
37163
37164
37165
37166
37167
37168
37169
37170
37171
37172
37173
37174
37175
37176
37177
37178
37179
37180
37181
37182
37183
37184
37185
37186
37187
37188
37189
37190
37191
37192
37193
37194
37195
37196
37197
37198
37199
37200
37201
37202
37203
37204
37205
37206
37207
37208
37209
37210
37211
37212
37213
37214
37215
37216
37217
37218
37219
37220
37221
37222
37223
37224
37225
37226
37227
37228
37229
37230
37231
37232
37233
37234
37235
37236
37237
37238
37239
37240
37241
37242
37243
37244
37245
37246
37247
37248
37249
37250
37251
37252
37253
37254
37255
37256
37257
37258
37259
37260
37261
37262
37263
37264
37265
37266
37267
37268
37269
37270
37271
37272
37273
37274
37275
37276
37277
37278
37279
37280
37281
37282
37283
37284
37285
37286
37287
37288
37289
37290
37291
37292
37293
37294
37295
37296
37297
37298
37299
37300
37301
37302
37303
37304
37305
37306
37307
37308
37309
37310
37311
37312
37313
37314
37315
37316
37317
37318
37319
37320
37321
37322
37323
37324
37325
37326
37327
37328
37329
37330
37331
37332
37333
37334
37335
37336
37337
37338
37339
37340
37341
37342
37343
37344
37345
37346
37347
37348
37349
37350
37351
37352
37353
37354
37355
37356
37357
37358
37359
37360
37361
37362
37363
37364
37365
37366
37367
37368
37369
37370
37371
37372
37373
37374
37375
37376
37377
37378
37379
37380
37381
37382
37383
37384
37385
37386
37387
37388
37389
37390
37391
37392
37393
37394
37395
37396
37397
37398
37399
37400
37401
37402
37403
37404
37405
37406
37407
37408
37409
37410
37411
37412
37413
37414
37415
37416
37417
37418
37419
37420
37421
37422
37423
37424
37425
37426
37427
37428
37429
37430
37431
37432
37433
37434
37435
37436
37437
37438
37439
37440
37441
37442
37443
37444
37445
37446
37447
37448
37449
37450
37451
37452
37453
37454
37455
37456
37457
37458
37459
37460
37461
37462
37463
37464
37465
37466
37467
37468
37469
37470
37471
37472
37473
37474
37475
37476
37477
37478
37479
37480
37481
37482
37483
37484
37485
37486
37487
37488
37489
37490
37491
37492
37493
37494
37495
37496
37497
37498
37499
37500
37501
37502
37503
37504
37505
37506
37507
37508
37509
37510
37511
37512
37513
37514
37515
37516
37517
37518
37519
37520
37521
37522
37523
37524
37525
37526
37527
37528
37529
37530
37531
37532
37533
37534
37535
37536
37537
37538
37539
37540
37541
37542
37543
37544
37545
37546
37547
37548
37549
37550
37551
37552
37553
37554
37555
37556
37557
37558
37559
37560
37561
37562
37563
37564
37565
37566
37567
37568
37569
37570
37571
37572
37573
37574
37575
37576
37577
37578
37579
37580
37581
37582
37583
37584
37585
37586
37587
37588
37589
37590
37591
37592
37593
37594
37595
37596
37597
37598
37599
37600
37601
37602
37603
37604
37605
37606
37607
37608
37609
37610
37611
37612
37613
37614
37615
37616
37617
37618
37619
37620
37621
37622
37623
37624
37625
37626
37627
37628
37629
37630
37631
37632
37633
37634
37635
37636
37637
37638
37639
37640
37641
37642
37643
37644
37645
37646
37647
37648
37649
37650
37651
37652
37653
37654
37655
37656
37657
37658
37659
37660
37661
37662
37663
37664
37665
37666
37667
37668
37669
37670
37671
37672
37673
37674
37675
37676
37677
37678
37679
37680
37681
37682
37683
37684
37685
37686
37687
37688
37689
37690
37691
37692
37693
37694
37695
37696
37697
37698
37699
37700
37701
37702
37703
37704
37705
37706
37707
37708
37709
37710
37711
37712
37713
37714
37715
37716
37717
37718
37719
37720
37721
37722
37723
37724
37725
37726
37727
37728
37729
37730
37731
37732
37733
37734
37735
37736
37737
37738
37739
37740
37741
37742
37743
37744
37745
37746
37747
37748
37749
37750
37751
37752
37753
37754
37755
37756
37757
37758
37759
37760
37761
37762
37763
37764
37765
37766
37767
37768
37769
37770
37771
37772
37773
37774
37775
37776
37777
37778
37779
37780
37781
37782
37783
37784
37785
37786
37787
37788
37789
37790
37791
37792
37793
37794
37795
37796
37797
37798
37799
37800
37801
37802
37803
37804
37805
37806
37807
37808
37809
37810
37811
37812
37813
37814
37815
37816
37817
37818
37819
37820
37821
37822
37823
37824
37825
37826
37827
37828
37829
37830
37831
37832
37833
37834
37835
37836
37837
37838
37839
37840
37841
37842
37843
37844
37845
37846
37847
37848
37849
37850
37851
37852
37853
37854
37855
37856
37857
37858
37859
37860
37861
37862
37863
37864
37865
37866
37867
37868
37869
37870
37871
37872
37873
37874
37875
37876
37877
37878
37879
37880
37881
37882
37883
37884
37885
37886
37887
37888
37889
37890
37891
37892
37893
37894
37895
37896
37897
37898
37899
37900
37901
37902
37903
37904
37905
37906
37907
37908
37909
37910
37911
37912
37913
37914
37915
37916
37917
37918
37919
37920
37921
37922
37923
37924
37925
37926
37927
37928
37929
37930
37931
37932
37933
37934
37935
37936
37937
37938
37939
37940
37941
37942
37943
37944
37945
37946
37947
37948
37949
37950
37951
37952
37953
37954
37955
37956
37957
37958
37959
37960
37961
37962
37963
37964
37965
37966
37967
37968
37969
37970
37971
37972
37973
37974
37975
37976
37977
37978
37979
37980
37981
37982
37983
37984
37985
37986
37987
37988
37989
37990
37991
37992
37993
37994
37995
37996
37997
37998
37999
38000
38001
38002
38003
38004
38005
38006
38007
38008
38009
38010
38011
38012
38013
38014
38015
38016
38017
38018
38019
38020
38021
38022
38023
38024
38025
38026
38027
38028
38029
38030
38031
38032
38033
38034
38035
38036
38037
38038
38039
38040
38041
38042
38043
38044
38045
38046
38047
38048
38049
38050
38051
38052
38053
38054
38055
38056
38057
38058
38059
38060
38061
38062
38063
38064
38065
38066
38067
38068
38069
38070
38071
38072
38073
38074
38075
38076
38077
38078
38079
38080
38081
38082
38083
38084
38085
38086
38087
38088
38089
38090
38091
38092
38093
38094
38095
38096
38097
38098
38099
38100
38101
38102
38103
38104
38105
38106
38107
38108
38109
38110
38111
38112
38113
38114
38115
38116
38117
38118
38119
38120
38121
38122
38123
38124
38125
38126
38127
38128
38129
38130
38131
38132
38133
38134
38135
38136
38137
38138
38139
38140
38141
38142
38143
38144
38145
38146
38147
38148
38149
38150
38151
38152
38153
38154
38155
38156
38157
38158
38159
38160
38161
38162
38163
38164
38165
38166
38167
38168
38169
38170
38171
38172
38173
38174
38175
38176
38177
38178
38179
38180
38181
38182
38183
38184
38185
38186
38187
38188
38189
38190
38191
38192
38193
38194
38195
38196
38197
38198
38199
38200
38201
38202
38203
38204
38205
38206
38207
38208
38209
38210
38211
38212
38213
38214
38215
38216
38217
38218
38219
38220
38221
38222
38223
38224
38225
38226
38227
38228
38229
38230
38231
38232
38233
38234
38235
38236
38237
38238
38239
38240
38241
38242
38243
38244
38245
38246
38247
38248
38249
38250
38251
38252
38253
38254
38255
38256
38257
38258
38259
38260
38261
38262
38263
38264
38265
38266
38267
38268
38269
38270
38271
38272
38273
38274
38275
38276
38277
38278
38279
38280
38281
38282
38283
38284
38285
38286
38287
38288
38289
38290
38291
38292
38293
38294
38295
38296
38297
38298
38299
38300
38301
38302
38303
38304
38305
38306
38307
38308
38309
38310
38311
38312
38313
38314
38315
38316
38317
38318
38319
38320
38321
38322
38323
38324
38325
38326
38327
38328
38329
38330
38331
38332
38333
38334
38335
38336
38337
38338
38339
38340
38341
38342
38343
38344
38345
38346
38347
38348
38349
38350
38351
38352
38353
38354
38355
38356
38357
38358
38359
38360
38361
38362
38363
38364
38365
38366
38367
38368
38369
38370
38371
38372
38373
38374
38375
38376
38377
38378
38379
38380
38381
38382
38383
38384
38385
38386
38387
38388
38389
38390
38391
38392
38393
38394
38395
38396
38397
38398
38399
38400
38401
38402
38403
38404
38405
38406
38407
38408
38409
38410
38411
38412
38413
38414
38415
38416
38417
38418
38419
38420
38421
38422
38423
38424
38425
38426
38427
38428
38429
38430
38431
38432
38433
38434
38435
38436
38437
38438
38439
38440
38441
38442
38443
38444
38445
38446
38447
38448
38449
38450
38451
38452
38453
38454
38455
38456
38457
38458
38459
38460
38461
38462
38463
38464
38465
38466
38467
38468
38469
38470
38471
38472
38473
38474
38475
38476
38477
38478
38479
38480
38481
38482
38483
38484
38485
38486
38487
38488
38489
38490
38491
38492
38493
38494
38495
38496
38497
38498
38499
38500
38501
38502
38503
38504
38505
38506
38507
38508
38509
38510
38511
38512
38513
38514
38515
38516
38517
38518
38519
38520
38521
38522
38523
38524
38525
38526
38527
38528
38529
38530
38531
38532
38533
38534
38535
38536
38537
38538
38539
38540
38541
38542
38543
38544
38545
38546
38547
38548
38549
38550
38551
38552
38553
38554
38555
38556
38557
38558
38559
38560
38561
38562
38563
38564
38565
38566
38567
38568
38569
38570
38571
38572
38573
38574
38575
38576
38577
38578
38579
38580
38581
38582
38583
38584
38585
38586
38587
38588
38589
38590
38591
38592
38593
38594
38595
38596
38597
38598
38599
38600
38601
38602
38603
38604
38605
38606
38607
38608
38609
38610
38611
38612
38613
38614
38615
38616
38617
38618
38619
38620
38621
38622
38623
38624
38625
38626
38627
38628
38629
38630
38631
38632
38633
38634
38635
38636
38637
38638
38639
38640
38641
38642
38643
38644
38645
38646
38647
38648
38649
38650
38651
38652
38653
38654
38655
38656
38657
38658
38659
38660
38661
38662
38663
38664
38665
38666
38667
38668
38669
38670
38671
38672
38673
38674
38675
38676
38677
38678
38679
38680
38681
38682
38683
38684
38685
38686
38687
38688
38689
38690
38691
38692
38693
38694
38695
38696
38697
38698
38699
38700
38701
38702
38703
38704
38705
38706
38707
38708
38709
38710
38711
38712
38713
38714
38715
38716
38717
38718
38719
38720
38721
38722
38723
38724
38725
38726
38727
38728
38729
38730
38731
38732
38733
38734
38735
38736
38737
38738
38739
38740
38741
38742
38743
38744
38745
38746
38747
38748
38749
38750
38751
38752
38753
38754
38755
38756
38757
38758
38759
38760
38761
38762
38763
38764
38765
38766
38767
38768
38769
38770
38771
38772
38773
38774
38775
38776
38777
38778
38779
38780
38781
38782
38783
38784
38785
38786
38787
38788
38789
38790
38791
38792
38793
38794
38795
38796
38797
38798
38799
38800
38801
38802
38803
38804
38805
38806
38807
38808
38809
38810
38811
38812
38813
38814
38815
38816
38817
38818
38819
38820
38821
38822
38823
38824
38825
38826
38827
38828
38829
38830
38831
38832
38833
38834
38835
38836
38837
38838
38839
38840
38841
38842
38843
38844
38845
38846
38847
38848
38849
38850
38851
38852
38853
38854
38855
38856
38857
38858
38859
38860
38861
38862
38863
38864
38865
38866
38867
38868
38869
38870
38871
38872
38873
38874
38875
38876
38877
38878
38879
38880
38881
38882
38883
38884
38885
38886
38887
38888
38889
38890
38891
38892
38893
38894
38895
38896
38897
38898
38899
38900
38901
38902
38903
38904
38905
38906
38907
38908
38909
38910
38911
38912
38913
38914
38915
38916
38917
38918
38919
38920
38921
38922
38923
38924
38925
38926
38927
38928
38929
38930
38931
38932
38933
38934
38935
38936
38937
38938
38939
38940
38941
38942
38943
38944
38945
38946
38947
38948
38949
38950
38951
38952
38953
38954
38955
38956
38957
38958
38959
38960
38961
38962
38963
38964
38965
38966
38967
38968
38969
38970
38971
38972
38973
38974
38975
38976
38977
38978
38979
38980
38981
38982
38983
38984
38985
38986
38987
38988
38989
38990
38991
38992
38993
38994
38995
38996
38997
38998
38999
39000
39001
39002
39003
39004
39005
39006
39007
39008
39009
39010
39011
39012
39013
39014
39015
39016
39017
39018
39019
39020
39021
39022
39023
39024
39025
39026
39027
39028
39029
39030
39031
39032
39033
39034
39035
39036
39037
39038
39039
39040
39041
39042
39043
39044
39045
39046
39047
39048
39049
39050
39051
39052
39053
39054
39055
39056
39057
39058
39059
39060
39061
39062
39063
39064
39065
39066
39067
39068
39069
39070
39071
39072
39073
39074
39075
39076
39077
39078
39079
39080
39081
39082
39083
39084
39085
39086
39087
39088
39089
39090
39091
39092
39093
39094
39095
39096
39097
39098
39099
39100
39101
39102
39103
39104
39105
39106
39107
39108
39109
39110
39111
39112
39113
39114
39115
39116
39117
39118
39119
39120
39121
39122
39123
39124
39125
39126
39127
39128
39129
39130
39131
39132
39133
39134
39135
39136
39137
39138
39139
39140
39141
39142
39143
39144
39145
39146
39147
39148
39149
39150
39151
39152
39153
39154
39155
39156
39157
39158
39159
39160
39161
39162
39163
39164
39165
39166
39167
39168
39169
39170
39171
39172
39173
39174
39175
39176
39177
39178
39179
39180
39181
39182
39183
39184
39185
39186
39187
39188
39189
39190
39191
39192
39193
39194
39195
39196
39197
39198
39199
39200
39201
39202
39203
39204
39205
39206
39207
39208
39209
39210
39211
39212
39213
39214
39215
39216
39217
39218
39219
39220
39221
39222
39223
39224
39225
39226
39227
39228
39229
39230
39231
39232
39233
39234
39235
39236
39237
39238
39239
39240
39241
39242
39243
39244
39245
39246
39247
39248
39249
39250
39251
39252
39253
39254
39255
39256
39257
39258
39259
39260
39261
39262
39263
39264
39265
39266
39267
39268
39269
39270
39271
39272
39273
39274
39275
39276
39277
39278
39279
39280
39281
39282
39283
39284
39285
39286
39287
39288
39289
39290
39291
39292
39293
39294
39295
39296
39297
39298
39299
39300
39301
39302
39303
39304
39305
39306
39307
39308
39309
39310
39311
39312
39313
39314
39315
39316
39317
39318
39319
39320
39321
39322
39323
39324
39325
39326
39327
39328
39329
39330
39331
39332
39333
39334
39335
39336
39337
39338
39339
39340
39341
39342
39343
39344
39345
39346
39347
39348
39349
39350
39351
39352
39353
39354
39355
39356
39357
39358
39359
39360
39361
39362
39363
39364
39365
39366
39367
39368
39369
39370
39371
39372
39373
39374
39375
39376
39377
39378
39379
39380
39381
39382
39383
39384
39385
39386
39387
39388
39389
39390
39391
39392
39393
39394
39395
39396
39397
39398
39399
39400
39401
39402
39403
39404
39405
39406
39407
39408
39409
39410
39411
39412
39413
39414
39415
39416
39417
39418
39419
39420
39421
39422
39423
39424
39425
39426
39427
39428
39429
39430
39431
39432
39433
39434
39435
39436
39437
39438
39439
39440
39441
39442
39443
39444
39445
39446
39447
39448
39449
39450
39451
39452
39453
39454
39455
39456
39457
39458
39459
39460
39461
39462
39463
39464
39465
39466
39467
39468
39469
39470
39471
39472
39473
39474
39475
39476
39477
39478
39479
39480
39481
39482
39483
39484
39485
39486
39487
39488
39489
39490
39491
39492
39493
39494
39495
39496
39497
39498
39499
39500
39501
39502
39503
39504
39505
39506
39507
39508
39509
39510
39511
39512
39513
39514
39515
39516
39517
39518
39519
39520
39521
39522
39523
39524
39525
39526
39527
39528
39529
39530
39531
39532
39533
39534
39535
39536
39537
39538
39539
39540
39541
39542
39543
39544
39545
39546
39547
39548
39549
39550
39551
39552
39553
39554
39555
39556
39557
39558
39559
39560
39561
39562
39563
39564
39565
39566
39567
39568
39569
39570
39571
39572
39573
39574
39575
39576
39577
39578
39579
39580
39581
39582
39583
39584
39585
39586
39587
39588
39589
39590
39591
39592
39593
39594
39595
39596
39597
39598
39599
39600
39601
39602
39603
39604
39605
39606
39607
39608
39609
39610
39611
39612
39613
39614
39615
39616
39617
39618
39619
39620
39621
39622
39623
39624
39625
39626
39627
39628
39629
39630
39631
39632
39633
39634
39635
39636
39637
39638
39639
39640
39641
39642
39643
39644
39645
39646
39647
39648
39649
39650
39651
39652
39653
39654
39655
39656
39657
39658
39659
39660
39661
39662
39663
39664
39665
39666
39667
39668
39669
39670
39671
39672
39673
39674
39675
39676
39677
39678
39679
39680
39681
39682
39683
39684
39685
39686
39687
39688
39689
39690
39691
39692
39693
39694
39695
39696
39697
39698
39699
39700
39701
39702
39703
39704
39705
39706
39707
39708
39709
39710
39711
39712
39713
39714
39715
39716
39717
39718
39719
39720
39721
39722
39723
39724
39725
39726
39727
39728
39729
39730
39731
39732
39733
39734
39735
39736
39737
39738
39739
39740
39741
39742
39743
39744
39745
39746
39747
39748
39749
39750
39751
39752
39753
39754
39755
39756
39757
39758
39759
39760
39761
39762
39763
39764
39765
39766
39767
39768
39769
39770
39771
39772
39773
39774
39775
39776
39777
39778
39779
39780
39781
39782
39783
39784
39785
39786
39787
39788
39789
39790
39791
39792
39793
39794
39795
39796
39797
39798
39799
39800
39801
39802
39803
39804
39805
39806
39807
39808
39809
39810
39811
39812
39813
39814
39815
39816
39817
39818
39819
39820
39821
39822
39823
39824
39825
39826
39827
39828
39829
39830
39831
39832
39833
39834
39835
39836
39837
39838
39839
39840
39841
39842
39843
39844
39845
39846
39847
39848
39849
39850
39851
39852
39853
39854
39855
39856
39857
39858
39859
39860
39861
39862
39863
39864
39865
39866
39867
39868
39869
39870
39871
39872
39873
39874
39875
39876
39877
39878
39879
39880
39881
39882
39883
39884
39885
39886
39887
39888
39889
39890
39891
39892
39893
39894
39895
39896
39897
39898
39899
39900
39901
39902
39903
39904
39905
39906
39907
39908
39909
39910
39911
39912
39913
39914
39915
39916
39917
39918
39919
39920
39921
39922
39923
39924
39925
39926
39927
39928
39929
39930
39931
39932
39933
39934
39935
39936
39937
39938
39939
39940
39941
39942
39943
39944
39945
39946
39947
39948
39949
39950
39951
39952
39953
39954
39955
39956
39957
39958
39959
39960
39961
39962
39963
39964
39965
39966
39967
39968
39969
39970
39971
39972
39973
39974
39975
39976
39977
39978
39979
39980
39981
39982
39983
39984
39985
39986
39987
39988
39989
39990
39991
39992
39993
39994
39995
39996
39997
39998
39999
40000
40001
40002
40003
40004
40005
40006
40007
40008
40009
40010
40011
40012
40013
40014
40015
40016
40017
40018
40019
40020
40021
40022
40023
40024
40025
40026
40027
40028
40029
40030
40031
40032
40033
40034
40035
40036
40037
40038
40039
40040
40041
40042
40043
40044
40045
40046
40047
40048
40049
40050
40051
40052
40053
40054
40055
40056
40057
40058
40059
40060
40061
40062
40063
40064
40065
40066
40067
40068
40069
40070
40071
40072
40073
40074
40075
40076
40077
40078
40079
40080
40081
40082
40083
40084
40085
40086
40087
40088
40089
40090
40091
40092
40093
40094
40095
40096
40097
40098
40099
40100
40101
40102
40103
40104
40105
40106
40107
40108
40109
40110
40111
40112
40113
40114
40115
40116
40117
40118
40119
40120
40121
40122
40123
40124
40125
40126
40127
40128
40129
40130
40131
40132
40133
40134
40135
40136
40137
40138
40139
40140
40141
40142
40143
40144
40145
40146
40147
40148
40149
40150
40151
40152
40153
40154
40155
40156
40157
40158
40159
40160
40161
40162
40163
40164
40165
40166
40167
40168
40169
40170
40171
40172
40173
40174
40175
40176
40177
40178
40179
40180
40181
40182
40183
40184
40185
40186
40187
40188
40189
40190
40191
40192
40193
40194
40195
40196
40197
40198
40199
40200
40201
40202
40203
40204
40205
40206
40207
40208
40209
40210
40211
40212
40213
40214
40215
40216
40217
40218
40219
40220
40221
40222
40223
40224
40225
40226
40227
40228
40229
40230
40231
40232
40233
40234
40235
40236
40237
40238
40239
40240
40241
40242
40243
40244
40245
40246
40247
40248
40249
40250
40251
40252
40253
40254
40255
40256
40257
40258
40259
40260
40261
40262
40263
40264
40265
40266
40267
40268
40269
40270
40271
40272
40273
40274
40275
40276
40277
40278
40279
40280
40281
40282
40283
40284
40285
40286
40287
40288
40289
40290
40291
40292
40293
40294
40295
40296
40297
40298
40299
40300
40301
40302
40303
40304
40305
40306
40307
40308
40309
40310
40311
40312
40313
40314
40315
40316
40317
40318
40319
40320
40321
40322
40323
40324
40325
40326
40327
40328
40329
40330
40331
40332
40333
40334
40335
40336
40337
40338
40339
40340
40341
40342
40343
40344
40345
40346
40347
40348
40349
40350
40351
40352
40353
40354
40355
40356
40357
40358
40359
40360
40361
40362
40363
40364
40365
40366
40367
40368
40369
40370
40371
40372
40373
40374
40375
40376
40377
40378
40379
40380
40381
40382
40383
40384
40385
40386
40387
40388
40389
40390
40391
40392
40393
40394
40395
40396
40397
40398
40399
40400
40401
40402
40403
40404
40405
40406
40407
40408
40409
40410
40411
40412
40413
40414
40415
40416
40417
40418
40419
40420
40421
40422
40423
40424
40425
40426
40427
40428
40429
40430
40431
40432
40433
40434
40435
40436
40437
40438
40439
40440
40441
40442
40443
40444
40445
40446
40447
40448
40449
40450
40451
40452
40453
40454
40455
40456
40457
40458
40459
40460
40461
40462
40463
40464
40465
40466
40467
40468
40469
40470
40471
40472
40473
40474
40475
40476
40477
40478
40479
40480
40481
40482
40483
40484
40485
40486
40487
40488
40489
40490
40491
40492
40493
40494
40495
40496
40497
40498
40499
40500
40501
40502
40503
40504
40505
40506
40507
40508
40509
40510
40511
40512
40513
40514
40515
40516
40517
40518
40519
40520
40521
40522
40523
40524
40525
40526
40527
40528
40529
40530
40531
40532
40533
40534
40535
40536
40537
40538
40539
40540
40541
40542
40543
40544
40545
40546
40547
40548
40549
40550
40551
40552
40553
40554
40555
40556
40557
40558
40559
40560
40561
40562
40563
40564
40565
40566
40567
40568
40569
40570
40571
40572
40573
40574
40575
40576
40577
40578
40579
40580
40581
40582
40583
40584
40585
40586
40587
40588
40589
40590
40591
40592
40593
40594
40595
40596
40597
40598
40599
40600
40601
40602
40603
40604
40605
40606
40607
40608
40609
40610
40611
40612
40613
40614
40615
40616
40617
40618
40619
40620
40621
40622
40623
40624
40625
40626
40627
40628
40629
40630
40631
40632
40633
40634
40635
40636
40637
40638
40639
40640
40641
40642
40643
40644
40645
40646
40647
40648
40649
40650
40651
40652
40653
40654
40655
40656
40657
40658
40659
40660
40661
40662
40663
40664
40665
40666
40667
40668
40669
40670
40671
40672
40673
40674
40675
40676
40677
40678
40679
40680
40681
40682
40683
40684
40685
40686
40687
40688
40689
40690
40691
40692
40693
40694
40695
40696
40697
40698
40699
40700
40701
40702
40703
40704
40705
40706
40707
40708
40709
40710
40711
40712
40713
40714
40715
40716
40717
40718
40719
40720
40721
40722
40723
40724
40725
40726
40727
40728
40729
40730
40731
40732
40733
40734
40735
40736
40737
40738
40739
40740
40741
40742
40743
40744
40745
40746
40747
40748
40749
40750
40751
40752
40753
40754
40755
40756
40757
40758
40759
40760
40761
40762
40763
40764
40765
40766
40767
40768
40769
40770
40771
40772
40773
40774
40775
40776
40777
40778
40779
40780
40781
40782
40783
40784
40785
40786
40787
40788
40789
40790
40791
40792
40793
40794
40795
40796
40797
40798
40799
40800
40801
40802
40803
40804
40805
40806
40807
40808
40809
40810
40811
40812
40813
40814
40815
40816
40817
40818
40819
40820
40821
40822
40823
40824
40825
40826
40827
40828
40829
40830
40831
40832
40833
40834
40835
40836
40837
40838
40839
40840
40841
40842
40843
40844
40845
40846
40847
40848
40849
40850
40851
40852
40853
40854
40855
40856
40857
40858
40859
40860
40861
40862
40863
40864
40865
40866
40867
40868
40869
40870
40871
40872
40873
40874
40875
40876
40877
40878
40879
40880
40881
40882
40883
40884
40885
40886
40887
40888
40889
40890
40891
40892
40893
40894
40895
40896
40897
40898
40899
40900
40901
40902
40903
40904
40905
40906
40907
40908
40909
40910
40911
40912
40913
40914
40915
40916
40917
40918
40919
40920
40921
40922
40923
40924
40925
40926
40927
40928
40929
40930
40931
40932
40933
40934
40935
40936
40937
40938
40939
40940
40941
40942
40943
40944
40945
40946
40947
40948
40949
40950
40951
40952
40953
40954
40955
40956
40957
40958
40959
40960
40961
40962
40963
40964
40965
40966
40967
40968
40969
40970
40971
40972
40973
40974
40975
40976
40977
40978
40979
40980
40981
40982
40983
40984
40985
40986
40987
40988
40989
40990
40991
40992
40993
40994
40995
40996
40997
40998
40999
41000
41001
41002
41003
41004
41005
41006
41007
41008
41009
41010
41011
41012
41013
41014
41015
41016
41017
41018
41019
41020
41021
41022
41023
41024
41025
41026
41027
41028
41029
41030
41031
41032
41033
41034
41035
41036
41037
41038
41039
41040
41041
41042
41043
41044
41045
41046
41047
41048
41049
41050
41051
41052
41053
41054
41055
41056
41057
41058
41059
41060
41061
41062
41063
41064
41065
41066
41067
41068
41069
41070
41071
41072
41073
41074
41075
41076
41077
41078
41079
41080
41081
41082
41083
41084
41085
41086
41087
41088
41089
41090
41091
41092
41093
41094
41095
41096
41097
41098
41099
41100
41101
41102
41103
41104
41105
41106
41107
41108
41109
41110
41111
41112
41113
41114
41115
41116
41117
41118
41119
41120
41121
41122
41123
41124
41125
41126
41127
41128
41129
41130
41131
41132
41133
41134
41135
41136
41137
41138
41139
41140
41141
41142
41143
41144
41145
41146
41147
41148
41149
41150
41151
41152
41153
41154
41155
41156
41157
41158
41159
41160
41161
41162
41163
41164
41165
41166
41167
41168
41169
41170
41171
41172
41173
41174
41175
41176
41177
41178
41179
41180
41181
41182
41183
41184
41185
41186
41187
41188
41189
41190
41191
41192
41193
41194
41195
41196
41197
41198
41199
41200
41201
41202
41203
41204
41205
41206
41207
41208
41209
41210
41211
41212
41213
41214
41215
41216
41217
41218
41219
41220
41221
41222
41223
41224
41225
41226
41227
41228
41229
41230
41231
41232
41233
41234
41235
41236
41237
41238
41239
41240
41241
41242
41243
41244
41245
41246
41247
41248
41249
41250
41251
41252
41253
41254
41255
41256
41257
41258
41259
41260
41261
41262
41263
41264
41265
41266
41267
41268
41269
41270
41271
41272
41273
41274
41275
41276
41277
41278
41279
41280
41281
41282
41283
41284
41285
41286
41287
41288
41289
41290
41291
41292
41293
41294
41295
41296
41297
41298
41299
41300
41301
41302
41303
41304
41305
41306
41307
41308
41309
41310
41311
41312
41313
41314
41315
41316
41317
41318
41319
41320
41321
41322
41323
41324
41325
41326
41327
41328
41329
41330
41331
41332
41333
41334
41335
41336
41337
41338
41339
41340
41341
41342
41343
41344
41345
41346
41347
41348
41349
41350
41351
41352
41353
41354
41355
41356
41357
41358
41359
41360
41361
41362
41363
41364
41365
41366
41367
41368
41369
41370
41371
41372
41373
41374
41375
41376
41377
41378
41379
41380
41381
41382
41383
41384
41385
41386
41387
41388
41389
41390
41391
41392
41393
41394
41395
41396
41397
41398
41399
41400
41401
41402
41403
41404
41405
41406
41407
41408
41409
41410
41411
41412
41413
41414
41415
41416
41417
41418
41419
41420
41421
41422
41423
41424
41425
41426
41427
41428
41429
41430
41431
41432
41433
41434
41435
41436
41437
41438
41439
41440
41441
41442
41443
41444
41445
41446
41447
41448
41449
41450
41451
41452
41453
41454
41455
41456
41457
41458
41459
41460
41461
41462
41463
41464
41465
41466
41467
41468
41469
41470
41471
41472
41473
41474
41475
41476
41477
41478
41479
41480
41481
41482
41483
41484
41485
41486
41487
41488
41489
41490
41491
41492
41493
41494
41495
41496
41497
41498
41499
41500
41501
41502
41503
41504
41505
41506
41507
41508
41509
41510
41511
41512
41513
41514
41515
41516
41517
41518
41519
41520
41521
41522
41523
41524
41525
41526
41527
41528
41529
41530
41531
41532
41533
41534
41535
41536
41537
41538
41539
41540
41541
41542
41543
41544
41545
41546
41547
41548
41549
41550
41551
41552
41553
41554
41555
41556
41557
41558
41559
41560
41561
41562
41563
41564
41565
41566
41567
41568
41569
41570
41571
41572
41573
41574
41575
41576
41577
41578
41579
41580
41581
41582
41583
41584
41585
41586
41587
41588
41589
41590
41591
41592
41593
41594
41595
41596
41597
41598
41599
41600
41601
41602
41603
41604
41605
41606
41607
41608
41609
41610
41611
41612
41613
41614
41615
41616
41617
41618
41619
41620
41621
41622
41623
41624
41625
41626
41627
41628
41629
41630
41631
41632
41633
41634
41635
41636
41637
41638
41639
41640
41641
41642
41643
41644
41645
41646
41647
41648
41649
41650
41651
41652
41653
41654
41655
41656
41657
41658
41659
41660
41661
41662
41663
41664
41665
41666
41667
41668
41669
41670
41671
41672
41673
41674
41675
41676
41677
41678
41679
41680
41681
41682
41683
41684
41685
41686
41687
41688
41689
41690
41691
41692
41693
41694
41695
41696
41697
41698
41699
41700
41701
41702
41703
41704
41705
41706
41707
41708
41709
41710
41711
41712
41713
41714
41715
41716
41717
41718
41719
41720
41721
41722
41723
41724
41725
41726
41727
41728
41729
41730
41731
41732
41733
41734
41735
41736
41737
41738
41739
41740
41741
41742
41743
41744
41745
41746
41747
41748
41749
41750
41751
41752
41753
41754
41755
41756
41757
41758
41759
41760
41761
41762
41763
41764
41765
41766
41767
41768
41769
41770
41771
41772
41773
41774
41775
41776
41777
41778
41779
41780
41781
41782
41783
41784
41785
41786
41787
41788
41789
41790
41791
41792
41793
41794
41795
41796
41797
41798
41799
41800
41801
41802
41803
41804
41805
41806
41807
41808
41809
41810
41811
41812
41813
41814
41815
41816
41817
41818
41819
41820
41821
41822
41823
41824
41825
41826
41827
41828
41829
41830
41831
41832
41833
41834
41835
41836
41837
41838
41839
41840
41841
41842
41843
41844
41845
41846
41847
41848
41849
41850
41851
41852
41853
41854
41855
41856
41857
41858
41859
41860
41861
41862
41863
41864
41865
41866
41867
41868
41869
41870
41871
41872
41873
41874
41875
41876
41877
41878
41879
41880
41881
41882
41883
41884
41885
41886
41887
41888
41889
41890
41891
41892
41893
41894
41895
41896
41897
41898
41899
41900
41901
41902
41903
41904
41905
41906
41907
41908
41909
41910
41911
41912
41913
41914
41915
41916
41917
41918
41919
41920
41921
41922
41923
41924
41925
41926
41927
41928
41929
41930
41931
41932
41933
41934
41935
41936
41937
41938
41939
41940
41941
41942
41943
41944
41945
41946
41947
41948
41949
41950
41951
41952
41953
41954
41955
41956
41957
41958
41959
41960
41961
41962
41963
41964
41965
41966
41967
41968
41969
41970
41971
41972
41973
41974
41975
41976
41977
41978
41979
41980
41981
41982
41983
41984
41985
41986
41987
41988
41989
41990
41991
41992
41993
41994
41995
41996
41997
41998
41999
42000
42001
42002
42003
42004
42005
42006
42007
42008
42009
42010
42011
42012
42013
42014
42015
42016
42017
42018
42019
42020
42021
42022
42023
42024
42025
42026
42027
42028
42029
42030
42031
42032
42033
42034
42035
42036
42037
42038
42039
42040
42041
42042
42043
42044
42045
42046
42047
42048
42049
42050
42051
42052
42053
42054
42055
42056
42057
42058
42059
42060
42061
42062
42063
42064
42065
42066
42067
42068
42069
42070
42071
42072
42073
42074
42075
42076
42077
42078
42079
42080
42081
42082
42083
42084
42085
42086
42087
42088
42089
42090
42091
42092
42093
42094
42095
42096
42097
42098
42099
42100
42101
42102
42103
42104
42105
42106
42107
42108
42109
42110
42111
42112
42113
42114
42115
42116
42117
42118
42119
42120
42121
42122
42123
42124
42125
42126
42127
42128
42129
42130
42131
42132
42133
42134
42135
42136
42137
42138
42139
42140
42141
42142
42143
42144
42145
42146
42147
42148
42149
42150
42151
42152
42153
42154
42155
42156
42157
42158
42159
42160
42161
42162
42163
42164
42165
42166
42167
42168
42169
42170
42171
42172
42173
42174
42175
42176
42177
42178
42179
42180
42181
42182
42183
42184
42185
42186
42187
42188
42189
42190
42191
42192
42193
42194
42195
42196
42197
42198
42199
42200
42201
42202
42203
42204
42205
42206
42207
42208
42209
42210
42211
42212
42213
42214
42215
42216
42217
42218
42219
42220
42221
42222
42223
42224
42225
42226
42227
42228
42229
42230
42231
42232
42233
42234
42235
42236
42237
42238
42239
42240
42241
42242
42243
42244
42245
42246
42247
42248
42249
42250
42251
42252
42253
42254
42255
42256
42257
42258
42259
42260
42261
42262
42263
42264
42265
42266
42267
42268
42269
42270
42271
42272
42273
42274
42275
42276
42277
42278
42279
42280
42281
42282
42283
42284
42285
42286
42287
42288
42289
42290
42291
42292
42293
42294
42295
42296
42297
42298
42299
42300
42301
42302
42303
42304
42305
42306
42307
42308
42309
42310
42311
42312
42313
42314
42315
42316
42317
42318
42319
42320
42321
42322
42323
42324
42325
42326
42327
42328
42329
42330
42331
42332
42333
42334
42335
42336
42337
42338
42339
42340
42341
42342
42343
42344
42345
42346
42347
42348
42349
42350
42351
42352
42353
42354
42355
42356
42357
42358
42359
42360
42361
42362
42363
42364
42365
42366
42367
42368
42369
42370
42371
42372
42373
42374
42375
42376
42377
42378
42379
42380
42381
42382
42383
42384
42385
42386
42387
42388
42389
42390
42391
42392
42393
42394
42395
42396
42397
42398
42399
42400
42401
42402
42403
42404
42405
42406
42407
42408
42409
42410
42411
42412
42413
42414
42415
42416
42417
42418
42419
42420
42421
42422
42423
42424
42425
42426
42427
42428
42429
42430
42431
42432
42433
42434
42435
42436
42437
42438
42439
42440
42441
42442
42443
42444
42445
42446
42447
42448
42449
42450
42451
42452
42453
42454
42455
42456
42457
42458
42459
42460
42461
42462
42463
42464
42465
42466
42467
42468
42469
42470
42471
42472
42473
42474
42475
42476
42477
42478
42479
42480
42481
42482
42483
42484
42485
42486
42487
42488
42489
42490
42491
42492
42493
42494
42495
42496
42497
42498
42499
42500
42501
42502
42503
42504
42505
42506
42507
42508
42509
42510
42511
42512
42513
42514
42515
42516
42517
42518
42519
42520
42521
42522
42523
42524
42525
42526
42527
42528
42529
42530
42531
42532
42533
42534
42535
42536
42537
42538
42539
42540
42541
42542
42543
42544
42545
42546
42547
42548
42549
42550
42551
42552
42553
42554
42555
42556
42557
42558
42559
42560
42561
42562
42563
42564
42565
42566
42567
42568
42569
42570
42571
42572
42573
42574
42575
42576
42577
42578
42579
42580
42581
42582
42583
42584
42585
42586
42587
42588
42589
42590
42591
42592
42593
42594
42595
42596
42597
42598
42599
42600
42601
42602
42603
42604
42605
42606
42607
42608
42609
42610
42611
42612
42613
42614
42615
42616
42617
42618
42619
42620
42621
42622
42623
42624
42625
42626
42627
42628
42629
42630
42631
42632
42633
42634
42635
42636
42637
42638
42639
42640
42641
42642
42643
42644
42645
42646
42647
42648
42649
42650
42651
42652
42653
42654
42655
42656
42657
42658
42659
42660
42661
42662
42663
42664
42665
42666
42667
42668
42669
42670
42671
42672
42673
42674
42675
42676
42677
42678
42679
42680
42681
42682
42683
42684
42685
42686
42687
42688
42689
42690
42691
42692
42693
42694
42695
42696
42697
42698
42699
42700
42701
42702
42703
42704
42705
42706
42707
42708
42709
42710
42711
42712
42713
42714
42715
42716
42717
42718
42719
42720
42721
42722
42723
42724
42725
42726
42727
42728
42729
42730
42731
42732
42733
42734
42735
42736
42737
42738
42739
42740
42741
42742
42743
42744
42745
42746
42747
42748
42749
42750
42751
42752
42753
42754
42755
42756
42757
42758
42759
42760
42761
42762
42763
42764
42765
42766
42767
42768
42769
42770
42771
42772
42773
42774
42775
42776
42777
42778
42779
42780
42781
42782
42783
42784
42785
42786
42787
42788
42789
42790
42791
42792
42793
42794
42795
42796
42797
42798
42799
42800
42801
42802
42803
42804
42805
42806
42807
42808
42809
42810
42811
42812
42813
42814
42815
42816
42817
42818
42819
42820
42821
42822
42823
42824
42825
42826
42827
42828
42829
42830
42831
42832
42833
42834
42835
42836
42837
42838
42839
42840
42841
42842
42843
42844
42845
42846
42847
42848
42849
42850
42851
42852
42853
42854
42855
42856
42857
42858
42859
42860
42861
42862
42863
42864
42865
42866
42867
42868
42869
42870
42871
42872
42873
42874
42875
42876
42877
42878
42879
42880
42881
42882
42883
42884
42885
42886
42887
42888
42889
42890
42891
42892
42893
42894
42895
42896
42897
42898
42899
42900
42901
42902
42903
42904
42905
42906
42907
42908
42909
42910
42911
42912
42913
42914
42915
42916
42917
42918
42919
42920
42921
42922
42923
42924
42925
42926
42927
42928
42929
42930
42931
42932
42933
42934
42935
42936
42937
42938
42939
42940
42941
42942
42943
42944
42945
42946
42947
42948
42949
42950
42951
42952
42953
42954
42955
42956
42957
42958
42959
42960
42961
42962
42963
42964
42965
42966
42967
42968
42969
42970
42971
42972
42973
42974
42975
42976
42977
42978
42979
42980
42981
42982
42983
42984
42985
42986
42987
42988
42989
42990
42991
42992
42993
42994
42995
42996
42997
42998
42999
43000
43001
43002
43003
43004
43005
43006
43007
43008
43009
43010
43011
43012
43013
43014
43015
43016
43017
43018
43019
43020
43021
43022
43023
43024
43025
43026
43027
43028
43029
43030
43031
43032
43033
43034
43035
43036
43037
43038
43039
43040
43041
43042
43043
43044
43045
43046
43047
43048
43049
43050
43051
43052
43053
43054
43055
43056
43057
43058
43059
43060
43061
43062
43063
43064
43065
43066
43067
43068
43069
43070
43071
43072
43073
43074
43075
43076
43077
43078
43079
43080
43081
43082
43083
43084
43085
43086
43087
43088
43089
43090
43091
43092
43093
43094
43095
43096
43097
43098
43099
43100
43101
43102
43103
43104
43105
43106
43107
43108
43109
43110
43111
43112
43113
43114
43115
43116
43117
43118
43119
43120
43121
43122
43123
43124
43125
43126
43127
43128
43129
43130
43131
43132
43133
43134
43135
43136
43137
43138
43139
43140
43141
43142
43143
43144
43145
43146
43147
43148
43149
43150
43151
43152
43153
43154
43155
43156
43157
43158
43159
43160
43161
43162
43163
43164
43165
43166
43167
43168
43169
43170
43171
43172
43173
43174
43175
43176
43177
43178
43179
43180
43181
43182
43183
43184
43185
43186
43187
43188
43189
43190
43191
43192
43193
43194
43195
43196
43197
43198
43199
43200
43201
43202
43203
43204
43205
43206
43207
43208
43209
43210
43211
43212
43213
43214
43215
43216
43217
43218
43219
43220
43221
43222
43223
43224
43225
43226
43227
43228
43229
43230
43231
43232
43233
43234
43235
43236
43237
43238
43239
43240
43241
43242
43243
43244
43245
43246
43247
43248
43249
43250
43251
43252
43253
43254
43255
43256
43257
43258
43259
43260
43261
43262
43263
43264
43265
43266
43267
43268
43269
43270
43271
43272
43273
43274
43275
43276
43277
43278
43279
43280
43281
43282
43283
43284
43285
43286
43287
43288
43289
43290
43291
43292
43293
43294
43295
43296
43297
43298
43299
43300
43301
43302
43303
43304
43305
43306
43307
43308
43309
43310
43311
43312
43313
43314
43315
43316
43317
43318
43319
43320
43321
43322
43323
43324
43325
43326
43327
43328
43329
43330
43331
43332
43333
43334
43335
43336
43337
43338
43339
43340
43341
43342
43343
43344
43345
43346
43347
43348
43349
43350
43351
43352
43353
43354
43355
43356
43357
43358
43359
43360
43361
43362
43363
43364
43365
43366
43367
43368
43369
43370
43371
43372
43373
43374
43375
43376
43377
43378
43379
43380
43381
43382
43383
43384
43385
43386
43387
43388
43389
43390
43391
43392
43393
43394
43395
43396
43397
43398
43399
43400
43401
43402
43403
43404
43405
43406
43407
43408
43409
43410
43411
43412
43413
43414
43415
43416
43417
43418
43419
43420
43421
43422
43423
43424
43425
43426
43427
43428
43429
43430
43431
43432
43433
43434
43435
43436
43437
43438
43439
43440
43441
43442
43443
43444
43445
43446
43447
43448
43449
43450
43451
43452
43453
43454
43455
43456
43457
43458
43459
43460
43461
43462
43463
43464
43465
43466
43467
43468
43469
43470
43471
43472
43473
43474
43475
43476
43477
43478
43479
43480
43481
43482
43483
43484
43485
43486
43487
43488
43489
43490
43491
43492
43493
43494
43495
43496
43497
43498
43499
43500
43501
43502
43503
43504
43505
43506
43507
43508
43509
43510
43511
43512
43513
43514
43515
43516
43517
43518
43519
43520
43521
43522
43523
43524
43525
43526
43527
43528
43529
43530
43531
43532
43533
43534
43535
43536
43537
43538
43539
43540
43541
43542
43543
43544
43545
43546
43547
43548
43549
43550
43551
43552
43553
43554
43555
43556
43557
43558
43559
43560
43561
43562
43563
43564
43565
43566
43567
43568
43569
43570
43571
43572
43573
43574
43575
43576
43577
43578
43579
43580
43581
43582
43583
43584
43585
43586
43587
43588
43589
43590
43591
43592
43593
43594
43595
43596
43597
43598
43599
43600
43601
43602
43603
43604
43605
43606
43607
43608
43609
43610
43611
43612
43613
43614
43615
43616
43617
43618
43619
43620
43621
43622
43623
43624
43625
43626
43627
43628
43629
43630
43631
43632
43633
43634
43635
43636
43637
43638
43639
43640
43641
43642
43643
43644
43645
43646
43647
43648
43649
43650
43651
43652
43653
43654
43655
43656
43657
43658
43659
43660
43661
43662
43663
43664
43665
43666
43667
43668
43669
43670
43671
43672
43673
43674
43675
43676
43677
43678
43679
43680
43681
43682
43683
43684
43685
43686
43687
43688
43689
43690
43691
43692
43693
43694
43695
43696
43697
43698
43699
43700
43701
43702
43703
43704
43705
43706
43707
43708
43709
43710
43711
43712
43713
43714
43715
43716
43717
43718
43719
43720
43721
43722
43723
43724
43725
43726
43727
43728
43729
43730
43731
43732
43733
43734
43735
43736
43737
43738
43739
43740
43741
43742
43743
43744
43745
43746
43747
43748
43749
43750
43751
43752
43753
43754
43755
43756
43757
43758
43759
43760
43761
43762
43763
43764
43765
43766
43767
43768
43769
43770
43771
43772
43773
43774
43775
43776
43777
43778
43779
43780
43781
43782
43783
43784
43785
43786
43787
43788
43789
43790
43791
43792
43793
43794
43795
43796
43797
43798
43799
43800
43801
43802
43803
43804
43805
43806
43807
43808
43809
43810
43811
43812
43813
43814
43815
43816
43817
43818
43819
43820
43821
43822
43823
43824
43825
43826
43827
43828
43829
43830
43831
43832
43833
43834
43835
43836
43837
43838
43839
43840
43841
43842
43843
43844
43845
43846
43847
43848
43849
43850
43851
43852
43853
43854
43855
43856
43857
43858
43859
43860
43861
43862
43863
43864
43865
43866
43867
43868
43869
43870
43871
43872
43873
43874
43875
43876
43877
43878
43879
43880
43881
43882
43883
43884
43885
43886
43887
43888
43889
43890
43891
43892
43893
43894
43895
43896
43897
43898
43899
43900
43901
43902
43903
43904
43905
43906
43907
43908
43909
43910
43911
43912
43913
43914
43915
43916
43917
43918
43919
43920
43921
43922
43923
43924
43925
43926
43927
43928
43929
43930
43931
43932
43933
43934
43935
43936
43937
43938
43939
43940
43941
43942
43943
43944
43945
43946
43947
43948
43949
43950
43951
43952
43953
43954
43955
43956
43957
43958
43959
43960
43961
43962
43963
43964
43965
43966
43967
43968
43969
43970
43971
43972
43973
43974
43975
43976
43977
43978
43979
43980
43981
43982
43983
43984
43985
43986
43987
43988
43989
43990
43991
43992
43993
43994
43995
43996
43997
43998
43999
44000
44001
44002
44003
44004
44005
44006
44007
44008
44009
44010
44011
44012
44013
44014
44015
44016
44017
44018
44019
44020
44021
44022
44023
44024
44025
44026
44027
44028
44029
44030
44031
44032
44033
44034
44035
44036
44037
44038
44039
44040
44041
44042
44043
44044
44045
44046
44047
44048
44049
44050
44051
44052
44053
44054
44055
44056
44057
44058
44059
44060
44061
44062
44063
44064
44065
44066
44067
44068
44069
44070
44071
44072
44073
44074
44075
44076
44077
44078
44079
44080
44081
44082
44083
44084
44085
44086
44087
44088
44089
44090
44091
44092
44093
44094
44095
44096
44097
44098
44099
44100
44101
44102
44103
44104
44105
44106
44107
44108
44109
44110
44111
44112
44113
44114
44115
44116
44117
44118
44119
44120
44121
44122
44123
44124
44125
44126
44127
44128
44129
44130
44131
44132
44133
44134
44135
44136
44137
44138
44139
44140
44141
44142
44143
44144
44145
44146
44147
44148
44149
44150
44151
44152
44153
44154
44155
44156
44157
44158
44159
44160
44161
44162
44163
44164
44165
44166
44167
44168
44169
44170
44171
44172
44173
44174
44175
44176
44177
44178
44179
44180
44181
44182
44183
44184
44185
44186
44187
44188
44189
44190
44191
44192
44193
44194
44195
44196
44197
44198
44199
44200
44201
44202
44203
44204
44205
44206
44207
44208
44209
44210
44211
44212
44213
44214
44215
44216
44217
44218
44219
44220
44221
44222
44223
44224
44225
44226
44227
44228
44229
44230
44231
44232
44233
44234
44235
44236
44237
44238
44239
44240
44241
44242
44243
44244
44245
44246
44247
44248
44249
44250
44251
44252
44253
44254
44255
44256
44257
44258
44259
44260
44261
44262
44263
44264
44265
44266
44267
44268
44269
44270
44271
44272
44273
44274
44275
44276
44277
44278
44279
44280
44281
44282
44283
44284
44285
44286
44287
44288
44289
44290
44291
44292
44293
44294
44295
44296
44297
44298
44299
44300
44301
44302
44303
44304
44305
44306
44307
44308
44309
44310
44311
44312
44313
44314
44315
44316
44317
44318
44319
44320
44321
44322
44323
44324
44325
44326
44327
44328
44329
44330
44331
44332
44333
44334
44335
44336
44337
44338
44339
44340
44341
44342
44343
44344
44345
44346
44347
44348
44349
44350
44351
44352
44353
44354
44355
44356
44357
44358
44359
44360
44361
44362
44363
44364
44365
44366
44367
44368
44369
44370
44371
44372
44373
44374
44375
44376
44377
44378
44379
44380
44381
44382
44383
44384
44385
44386
44387
44388
44389
44390
44391
44392
44393
44394
44395
44396
44397
44398
44399
44400
44401
44402
44403
44404
44405
44406
44407
44408
44409
44410
44411
44412
44413
44414
44415
44416
44417
44418
44419
44420
44421
44422
44423
44424
44425
44426
44427
44428
44429
44430
44431
44432
44433
44434
44435
44436
44437
44438
44439
44440
44441
44442
44443
44444
44445
44446
44447
44448
44449
44450
44451
44452
44453
44454
44455
44456
44457
44458
44459
44460
44461
44462
44463
44464
44465
44466
44467
44468
44469
44470
44471
44472
44473
44474
44475
44476
44477
44478
44479
44480
44481
44482
44483
44484
44485
44486
44487
44488
44489
44490
44491
44492
44493
44494
44495
44496
44497
44498
44499
44500
44501
44502
44503
44504
44505
44506
44507
44508
44509
44510
44511
44512
44513
44514
44515
44516
44517
44518
44519
44520
44521
44522
44523
44524
44525
44526
44527
44528
44529
44530
44531
44532
44533
44534
44535
44536
44537
44538
44539
44540
44541
44542
44543
44544
44545
44546
44547
44548
44549
44550
44551
44552
44553
44554
44555
44556
44557
44558
44559
44560
44561
44562
44563
44564
44565
44566
44567
44568
44569
44570
44571
44572
44573
44574
44575
44576
44577
44578
44579
44580
44581
44582
44583
44584
44585
44586
44587
44588
44589
44590
44591
44592
44593
44594
44595
44596
44597
44598
44599
44600
44601
44602
44603
44604
44605
44606
44607
44608
44609
44610
44611
44612
44613
44614
44615
44616
44617
44618
44619
44620
44621
44622
44623
44624
44625
44626
44627
44628
44629
44630
44631
44632
44633
44634
44635
44636
44637
44638
44639
44640
44641
44642
44643
44644
44645
44646
44647
44648
44649
44650
44651
44652
44653
44654
44655
44656
44657
44658
44659
44660
44661
44662
44663
44664
44665
44666
44667
44668
44669
44670
44671
44672
44673
44674
44675
44676
44677
44678
44679
44680
44681
44682
44683
44684
44685
44686
44687
44688
44689
44690
44691
44692
44693
44694
44695
44696
44697
44698
44699
44700
44701
44702
44703
44704
44705
44706
44707
44708
44709
44710
44711
44712
44713
44714
44715
44716
44717
44718
44719
44720
44721
44722
44723
44724
44725
44726
44727
44728
44729
44730
44731
44732
44733
44734
44735
44736
44737
44738
44739
44740
44741
44742
44743
44744
44745
44746
44747
44748
44749
44750
44751
44752
44753
44754
44755
44756
44757
44758
44759
44760
44761
44762
44763
44764
44765
44766
44767
44768
44769
44770
44771
44772
44773
44774
44775
44776
44777
44778
44779
44780
44781
44782
44783
44784
44785
44786
44787
44788
44789
44790
44791
44792
44793
44794
44795
44796
44797
44798
44799
44800
44801
44802
44803
44804
44805
44806
44807
44808
44809
44810
44811
44812
44813
44814
44815
44816
44817
44818
44819
44820
44821
44822
44823
44824
44825
44826
44827
44828
44829
44830
44831
44832
44833
44834
44835
44836
44837
44838
44839
44840
44841
44842
44843
44844
44845
44846
44847
44848
44849
44850
44851
44852
44853
44854
44855
44856
44857
44858
44859
44860
44861
44862
44863
44864
44865
44866
44867
44868
44869
44870
44871
44872
44873
44874
44875
44876
44877
44878
44879
44880
44881
44882
44883
44884
44885
44886
44887
44888
44889
44890
44891
44892
44893
44894
44895
44896
44897
44898
44899
44900
44901
44902
44903
44904
44905
44906
44907
44908
44909
44910
44911
44912
44913
44914
44915
44916
44917
44918
44919
44920
44921
44922
44923
44924
44925
44926
44927
44928
44929
44930
44931
44932
44933
44934
44935
44936
44937
44938
44939
44940
44941
44942
44943
44944
44945
44946
44947
44948
44949
44950
44951
44952
44953
44954
44955
44956
44957
44958
44959
44960
44961
44962
44963
44964
44965
44966
44967
44968
44969
44970
44971
44972
44973
44974
44975
44976
44977
44978
44979
44980
44981
44982
44983
44984
44985
44986
44987
44988
44989
44990
44991
44992
44993
44994
44995
44996
44997
44998
44999
45000
45001
45002
45003
45004
45005
45006
45007
45008
45009
45010
45011
45012
45013
45014
45015
45016
45017
45018
45019
45020
45021
45022
45023
45024
45025
45026
45027
45028
45029
45030
45031
45032
45033
45034
45035
45036
45037
45038
45039
45040
45041
45042
45043
45044
45045
45046
45047
45048
45049
45050
45051
45052
45053
45054
45055
45056
45057
45058
45059
45060
45061
45062
45063
45064
45065
45066
45067
45068
45069
45070
45071
45072
45073
45074
45075
45076
45077
45078
45079
45080
45081
45082
45083
45084
45085
45086
45087
45088
45089
45090
45091
45092
45093
45094
45095
45096
45097
45098
45099
45100
45101
45102
45103
45104
45105
45106
45107
45108
45109
45110
45111
45112
45113
45114
45115
45116
45117
45118
45119
45120
45121
45122
45123
45124
45125
45126
45127
45128
45129
45130
45131
45132
45133
45134
45135
45136
45137
45138
45139
45140
45141
45142
45143
45144
45145
45146
45147
45148
45149
45150
45151
45152
45153
45154
45155
45156
45157
45158
45159
45160
45161
45162
45163
45164
45165
45166
45167
45168
45169
45170
45171
45172
45173
45174
45175
45176
45177
45178
45179
45180
45181
45182
45183
45184
45185
45186
45187
45188
45189
45190
45191
45192
45193
45194
45195
45196
45197
45198
45199
45200
45201
45202
45203
45204
45205
45206
45207
45208
45209
45210
45211
45212
45213
45214
45215
45216
45217
45218
45219
45220
45221
45222
45223
45224
45225
45226
45227
45228
45229
45230
45231
45232
45233
45234
45235
45236
45237
45238
45239
45240
45241
45242
45243
45244
45245
45246
45247
45248
45249
45250
45251
45252
45253
45254
45255
45256
45257
45258
45259
45260
45261
45262
45263
45264
45265
45266
45267
45268
45269
45270
45271
45272
45273
45274
45275
45276
45277
45278
45279
45280
45281
45282
45283
45284
45285
45286
45287
45288
45289
45290
45291
45292
45293
45294
45295
45296
45297
45298
45299
45300
45301
45302
45303
45304
45305
45306
45307
45308
45309
45310
45311
45312
45313
45314
45315
45316
45317
45318
45319
45320
45321
45322
45323
45324
45325
45326
45327
45328
45329
45330
45331
45332
45333
45334
45335
45336
45337
45338
45339
45340
45341
45342
45343
45344
45345
45346
45347
45348
45349
45350
45351
45352
45353
45354
45355
45356
45357
45358
45359
45360
45361
45362
45363
45364
45365
45366
45367
45368
45369
45370
45371
45372
45373
45374
45375
45376
45377
45378
45379
45380
45381
45382
45383
45384
45385
45386
45387
45388
45389
45390
45391
45392
45393
45394
45395
45396
45397
45398
45399
45400
45401
45402
45403
45404
45405
45406
45407
45408
45409
45410
45411
45412
45413
45414
45415
45416
45417
45418
45419
45420
45421
45422
45423
45424
45425
45426
45427
45428
45429
45430
45431
45432
45433
45434
45435
45436
45437
45438
45439
45440
45441
45442
45443
45444
45445
45446
45447
45448
45449
45450
45451
45452
45453
45454
45455
45456
45457
45458
45459
45460
45461
45462
45463
45464
45465
45466
45467
45468
45469
45470
45471
45472
45473
45474
45475
45476
45477
45478
45479
45480
45481
45482
45483
45484
45485
45486
45487
45488
45489
45490
45491
45492
45493
45494
45495
45496
45497
45498
45499
45500
45501
45502
45503
45504
45505
45506
45507
45508
45509
45510
45511
45512
45513
45514
45515
45516
45517
45518
45519
45520
45521
45522
45523
45524
45525
45526
45527
45528
45529
45530
45531
45532
45533
45534
45535
45536
45537
45538
45539
45540
45541
45542
45543
45544
45545
45546
45547
45548
45549
45550
45551
45552
45553
45554
45555
45556
45557
45558
45559
45560
45561
45562
45563
45564
45565
45566
45567
45568
45569
45570
45571
45572
45573
45574
45575
45576
45577
45578
45579
45580
45581
45582
45583
45584
45585
45586
45587
45588
45589
45590
45591
45592
45593
45594
45595
45596
45597
45598
45599
45600
45601
45602
45603
45604
45605
45606
45607
45608
45609
45610
45611
45612
45613
45614
45615
45616
45617
45618
45619
45620
45621
45622
45623
45624
45625
45626
45627
45628
45629
45630
45631
45632
45633
45634
45635
45636
45637
45638
45639
45640
45641
45642
45643
45644
45645
45646
45647
45648
45649
45650
45651
45652
45653
45654
45655
45656
45657
45658
45659
45660
45661
45662
45663
45664
45665
45666
45667
45668
45669
45670
45671
45672
45673
45674
45675
45676
45677
45678
45679
45680
45681
45682
45683
45684
45685
45686
45687
45688
45689
45690
45691
45692
45693
45694
45695
45696
45697
45698
45699
45700
45701
45702
45703
45704
45705
45706
45707
45708
45709
45710
45711
45712
45713
45714
45715
45716
45717
45718
45719
45720
45721
45722
45723
45724
45725
45726
45727
45728
45729
45730
45731
45732
45733
45734
45735
45736
45737
45738
45739
45740
45741
45742
45743
45744
45745
45746
45747
45748
45749
45750
45751
45752
45753
45754
45755
45756
45757
45758
45759
45760
45761
45762
45763
45764
45765
45766
45767
45768
45769
45770
45771
45772
45773
45774
45775
45776
45777
45778
45779
45780
45781
45782
45783
45784
45785
45786
45787
45788
45789
45790
45791
45792
45793
45794
45795
45796
45797
45798
45799
45800
45801
45802
45803
45804
45805
45806
45807
45808
45809
45810
45811
45812
45813
45814
45815
45816
45817
45818
45819
45820
45821
45822
45823
45824
45825
45826
45827
45828
45829
45830
45831
45832
45833
45834
45835
45836
45837
45838
45839
45840
45841
45842
45843
45844
45845
45846
45847
45848
45849
45850
45851
45852
45853
45854
45855
45856
45857
45858
45859
45860
45861
45862
45863
45864
45865
45866
45867
45868
45869
45870
45871
45872
45873
45874
45875
45876
45877
45878
45879
45880
45881
45882
45883
45884
45885
45886
45887
45888
45889
45890
45891
45892
45893
45894
45895
45896
45897
45898
45899
45900
45901
45902
45903
45904
45905
45906
45907
45908
45909
45910
45911
45912
45913
45914
45915
45916
45917
45918
45919
45920
45921
45922
45923
45924
45925
45926
45927
45928
45929
45930
45931
45932
45933
45934
45935
45936
45937
45938
45939
45940
45941
45942
45943
45944
45945
45946
45947
45948
45949
45950
45951
45952
45953
45954
45955
45956
45957
45958
45959
45960
45961
45962
45963
45964
45965
45966
45967
45968
45969
45970
45971
45972
45973
45974
45975
45976
45977
45978
45979
45980
45981
45982
45983
45984
45985
45986
45987
45988
45989
45990
45991
45992
45993
45994
45995
45996
45997
45998
45999
46000
46001
46002
46003
46004
46005
46006
46007
46008
46009
46010
46011
46012
46013
46014
46015
46016
46017
46018
46019
46020
46021
46022
46023
46024
46025
46026
46027
46028
46029
46030
46031
46032
46033
46034
46035
46036
46037
46038
46039
46040
46041
46042
46043
46044
46045
46046
46047
46048
46049
46050
46051
46052
46053
46054
46055
46056
46057
46058
46059
46060
46061
46062
46063
46064
46065
46066
46067
46068
46069
46070
46071
46072
46073
46074
46075
46076
46077
46078
46079
46080
46081
46082
46083
46084
46085
46086
46087
46088
46089
46090
46091
46092
46093
46094
46095
46096
46097
46098
46099
46100
46101
46102
46103
46104
46105
46106
46107
46108
46109
46110
46111
46112
46113
46114
46115
46116
46117
46118
46119
46120
46121
46122
46123
46124
46125
46126
46127
46128
46129
46130
46131
46132
46133
46134
46135
46136
46137
46138
46139
46140
46141
46142
46143
46144
46145
46146
46147
46148
46149
46150
46151
46152
46153
46154
46155
46156
46157
46158
46159
46160
46161
46162
46163
46164
46165
46166
46167
46168
46169
46170
46171
46172
46173
46174
46175
46176
46177
46178
46179
46180
46181
46182
46183
46184
46185
46186
46187
46188
46189
46190
46191
46192
46193
46194
46195
46196
46197
46198
46199
46200
46201
46202
46203
46204
46205
46206
46207
46208
46209
46210
46211
46212
46213
46214
46215
46216
46217
46218
46219
46220
46221
46222
46223
46224
46225
46226
46227
46228
46229
46230
46231
46232
46233
46234
46235
46236
46237
46238
46239
46240
46241
46242
46243
46244
46245
46246
46247
46248
46249
46250
46251
46252
46253
46254
46255
46256
46257
46258
46259
46260
46261
46262
46263
46264
46265
46266
46267
46268
46269
46270
46271
46272
46273
46274
46275
46276
46277
46278
46279
46280
46281
46282
46283
46284
46285
46286
46287
46288
46289
46290
46291
46292
46293
46294
46295
46296
46297
46298
46299
46300
46301
46302
46303
46304
46305
46306
46307
46308
46309
46310
46311
46312
46313
46314
46315
46316
46317
46318
46319
46320
46321
46322
46323
46324
46325
46326
46327
46328
46329
46330
46331
46332
46333
46334
46335
46336
46337
46338
46339
46340
46341
46342
46343
46344
46345
46346
46347
46348
46349
46350
46351
46352
46353
46354
46355
46356
46357
46358
46359
46360
46361
46362
46363
46364
46365
46366
46367
46368
46369
46370
46371
46372
46373
46374
46375
46376
46377
46378
46379
46380
46381
46382
46383
46384
46385
46386
46387
46388
46389
46390
46391
46392
46393
46394
46395
46396
46397
46398
46399
46400
46401
46402
46403
46404
46405
46406
46407
46408
46409
46410
46411
46412
46413
46414
46415
46416
46417
46418
46419
46420
46421
46422
46423
46424
46425
46426
46427
46428
46429
46430
46431
46432
46433
46434
46435
46436
46437
46438
46439
46440
46441
46442
46443
46444
46445
46446
46447
46448
46449
46450
46451
46452
46453
46454
46455
46456
46457
46458
46459
46460
46461
46462
46463
46464
46465
46466
46467
46468
46469
46470
46471
46472
46473
46474
46475
46476
46477
46478
46479
46480
46481
46482
46483
46484
46485
46486
46487
46488
46489
46490
46491
46492
46493
46494
46495
46496
46497
46498
46499
46500
46501
46502
46503
46504
46505
46506
46507
46508
46509
46510
46511
46512
46513
46514
46515
46516
46517
46518
46519
46520
46521
46522
46523
46524
46525
46526
46527
46528
46529
46530
46531
46532
46533
46534
46535
46536
46537
46538
46539
46540
46541
46542
46543
46544
46545
46546
46547
46548
46549
46550
46551
46552
46553
46554
46555
46556
46557
46558
46559
46560
46561
46562
46563
46564
46565
46566
46567
46568
46569
46570
46571
46572
46573
46574
46575
46576
46577
46578
46579
46580
46581
46582
46583
46584
46585
46586
46587
46588
46589
46590
46591
46592
46593
46594
46595
46596
46597
46598
46599
46600
46601
46602
46603
46604
46605
46606
46607
46608
46609
46610
46611
46612
46613
46614
46615
46616
46617
46618
46619
46620
46621
46622
46623
46624
46625
46626
46627
46628
46629
46630
46631
46632
46633
46634
46635
46636
46637
46638
46639
46640
46641
46642
46643
46644
46645
46646
46647
46648
46649
46650
46651
46652
46653
46654
46655
46656
46657
46658
46659
46660
46661
46662
46663
46664
46665
46666
46667
46668
46669
46670
46671
46672
46673
46674
46675
46676
46677
46678
46679
46680
46681
46682
46683
46684
46685
46686
46687
46688
46689
46690
46691
46692
46693
46694
46695
46696
46697
46698
46699
46700
46701
46702
46703
46704
46705
46706
46707
46708
46709
46710
46711
46712
46713
46714
46715
46716
46717
46718
46719
46720
46721
46722
46723
46724
46725
46726
46727
46728
46729
46730
46731
46732
46733
46734
46735
46736
46737
46738
46739
46740
46741
46742
46743
46744
46745
46746
46747
46748
46749
46750
46751
46752
46753
46754
46755
46756
46757
46758
46759
46760
46761
46762
46763
46764
46765
46766
46767
46768
46769
46770
46771
46772
46773
46774
46775
46776
46777
46778
46779
46780
46781
46782
46783
46784
46785
46786
46787
46788
46789
46790
46791
46792
46793
46794
46795
46796
46797
46798
46799
46800
46801
46802
46803
46804
46805
46806
46807
46808
46809
46810
46811
46812
46813
46814
46815
46816
46817
46818
46819
46820
46821
46822
46823
46824
46825
46826
46827
46828
46829
46830
46831
46832
46833
46834
46835
46836
46837
46838
46839
46840
46841
46842
46843
46844
46845
46846
46847
46848
46849
46850
46851
46852
46853
46854
46855
46856
46857
46858
46859
46860
46861
46862
46863
46864
46865
46866
46867
46868
46869
46870
46871
46872
46873
46874
46875
46876
46877
46878
46879
46880
46881
46882
46883
46884
46885
46886
46887
46888
46889
46890
46891
46892
46893
46894
46895
46896
46897
46898
46899
46900
46901
46902
46903
46904
46905
46906
46907
46908
46909
46910
46911
46912
46913
46914
46915
46916
46917
46918
46919
46920
46921
46922
46923
46924
46925
46926
46927
46928
46929
46930
46931
46932
46933
46934
46935
46936
46937
46938
46939
46940
46941
46942
46943
46944
46945
46946 | <html>
<head>
<style type="text/css">
h1 { background-color: #808080; padding: 0.2em; }
h2 { background-color: #B0B0B0; padding: 0.2em; }
h3 { background-color: #E0E0E0; padding: 0.2em; }
sheader { }
.inlineheader { background-color: #E8E8E8; padding: 0.1em; font-weight:bold; }
.pagecontent { font-family: Arial; font-size: 10pt; width: 770px; text-align: justify; }
.pageheader { width: 770px; }
.source { font-family: "Courier New"; font-size: 10pt; }
.p_example { margin-left: 4em; }
.p_note { margin-left: 50px; margin-right: 50px; font-size: 80%; }
.p_att { margin-left: 50px; margin-right: 50px; color: red; font-weight: bold; }
.p_code_head { margin-left: 50px; margin-top: 50px; margin-bottom: 0; padding: 5px; width: 720px; font-family: "Courier New", monospace; background-color: navy; font-weight: bold; color: white;}
.p_code_body { margin-left: 50px; margin-top: 0; margin-bottom: 50px; padding: 5px; width: 720px; font-family: "Courier New", monospace; background-color: #F0F0F0; }
.p_code { margin-left: 50px; margin-top: 50px; margin-bottom: 50px; padding: 5px; width: 720px; font-family: "Courier New", monospace; background-color: #F0F0F0; }
.s_code { font-family: "Courier New"; background-color: #F0F0F0; }
.s_str { font-family: "Courier New"; color: blue; font-weight: bold; }
.s_comment { color: navy; font-style: italic; }
.s_preprocessor { color: green; }
a { color:#000077; text-decoration: underline; }
a:visited { color:#000077; text-decoration: underline;}
a:hover { color:#000077; text-decoration: underline; }
a.toc { color:#000077; text-decoration: none; }
a.toc:visited { color:#000077; text-decoration: none;}
a.toc:hover { color:#000077; text-decoration: underline; }
a.nav { color:#000077; font-weight:bold; text-decoration: none; }
a.nav:visited { color:#000077; font-weight:bold; text-decoration: none;}
a.nav:hover { color:#000077; font-weight:bold; text-decoration: underline; }
.cond { color:blue; }
.const { color:#222222; }
.func { color:#111111; }
</style>
</head>
<body>
<pre>
<a href='#int_main'>1 Introduction</a>
<a href='#int_license'>1.1 What is ALGLIB</a>
<a href='#int_license'>1.2 ALGLIB license</a>
<a href='#int_doc_license'>1.3 Documentation license</a>
<a href='#gs_guide'>1.4 Reference Manual and User Guide</a>
<a href='#int_ack'>1.5 Acknowledgements</a>
<a href='#gs_structure'>2 ALGLIB structure</a>
<a href='#gs_packages'>2.1 Packages</a>
<a href='#gs_subpackages'>2.2 Subpackages</a>
<a href='#gs_osscomm'>2.3 Open Source and Commercial versions</a>
<a href='#gs_compatibility'>3 Compatibility</a>
<a href='#gs_compatibility_cpu'>3.1 CPU</a>
<a href='#gs_compatibility_os'>3.2 OS</a>
<a href='#gs_compatibility_compiler'>3.3 Compiler</a>
<a href='#gs_compatibility_opt'>3.4 Optimization settings</a>
<a href='#gs_compiling'>4 Compiling ALGLIB</a>
<a href='#gs_attaching'>4.1 Adding to your project</a>
<a href='#gs_configuring'>4.2 Configuring for your compiler</a>
<a href='#gs_configuring2'>4.3 Improving performance (CPU-specific and OS-specific optimizations)</a>
<a href='#gs_comm'>5 Working with commercial version</a>
<a href='#gs_comm_benefits'>5.1 Benefits of commercial version</a>
<a href='#gs_comm_sse'>5.2 Working with SSE support (Intel/AMD users)</a>
<a href='#gs_comm_smp'>5.3 Using multithreading</a>
<a href='#gs_comm_smp'>5.3.1 SMT (CMT/hyper-threading) issues</a>
<a href='#gs_comm_hpc'>5.4 Linking with Intel MKL</a>
<a href='#gs_comm_mkl_lightweight'>5.4.1 Using lightweight Intel MKL supplied by ALGLIB Project</a>
<a href='#gs_comm_mkl_own'>5.4.2 Using your own installation of Intel MKL</a>
<a href='#gs_comm_examples'>5.5 Examples - compiling commercial edition of ALGLIB</a>
<a href='#gs_comm_examples_set'>5.5.1 Introduction</a>
<a href='#gs_comm_examples_win'>5.5.2 Compiling under Windows</a>
<a href='#gs_using'>6 Using ALGLIB</a>
<a href='#gs_using_threadsafety'>6.1 Thread-safety</a>
<a href='#gs_global'>6.2 Global definitions</a>
<a href='#gs_datatypes'>6.3 Datatypes</a>
<a href='#gs_constants'>6.4 Constants</a>
<a href='#gs_stdfunctions'>6.5 Functions</a>
<a href='#gs_vecmat'>6.6 Working with vectors and matrices</a>
<a href='#gs_functions'>6.7 Using functions: 'expert' and 'friendly' interfaces</a>
<a href='#gs_errors'>6.8 Handling errors</a>
<a href='#gs_blas'>6.9 Working with Level 1 BLAS functions</a>
<a href='#gs_csv'>6.10 Reading data from CSV files</a>
<a href='#gs_advanced'>7 Advanced topics</a>
<a href='#gs_testing'>7.1 Testing ALGLIB</a>
<a href='#alglib_main'>8 ALGLIB packages and subpackages</a>
<a href='#pck_AlglibMisc'>8.1 <code>AlglibMisc</code> package</a>
<a href='#pck_DataAnalysis'>8.2 <code>DataAnalysis</code> package</a>
<a href='#pck_DiffEquations'>8.3 <code>DiffEquations</code> package</a>
<a href='#pck_FastTransforms'>8.4 <code>FastTransforms</code> package</a>
<a href='#pck_Integration'>8.5 <code>Integration</code> package</a>
<a href='#pck_Interpolation'>8.6 <code>Interpolation</code> package</a>
<a href='#pck_LinAlg'>8.7 <code>LinAlg</code> package</a>
<a href='#pck_Optimization'>8.8 <code>Optimization</code> package</a>
<a href='#pck_Solvers'>8.9 <code>Solvers</code> package</a>
<a href='#pck_SpecialFunctions'>8.10 <code>SpecialFunctions</code> package</a>
<a href='#pck_Statistics'>8.11 <code>Statistics</code> package</a>
</pre>
<div class=pagecontent>
<a name='int_main' class='sheader'></a><h1>1 Introduction</h1>
<a name='int_license' class='sheader'></a><h2>1.2 1.1 What is ALGLIB</h2>
<p align=justify>
ALGLIB is a cross-platform numerical analysis and data mining library.
It supports several programming languages (C++, C#, Pascal, VBA) and several operating systems (Windows, *nix family).
</p>
<p align=justify>
ALGLIB features include:
</p>
<ul>
<li>Data analysis (classification/regression, including neural networks)</li>
<li>Optimization and nonlinear solvers</li>
<li>Interpolation and linear/nonlinear least-squares fitting</li>
<li>Linear algebra (direct algorithms, EVD/SVD), direct and iterative linear solvers, Fast Fourier Transform and many other algorithms (numerical integration, ODEs, statistics, special functions)</li>
</ul>
<p align=justify>
ALGLIB Project (the company behind ALGLIB) delivers to you several editions of ALGLIB:
</p>
<ul>
<li><i>ALGLIB Free Edition</i> - full functionality but limited performance</li>
<li><i>ALGLIB Commercial Edition</i> - high-performance version of ALGLIB</li>
</ul>
<p align=justify>
Free Edition is a serial version without multithreading support or extensive low-level optimizations (generic C or C# code).
Commercial Edition is a heavily optimized version of ALGLIB.
It supports multithreading, it was extensively optimized, and (on Intel platforms) -
our commercial users may enjoy precompiled version of ALGLIB which internally calls Intel MKL to accelerate low-level tasks.
We obtained license from Intel corp., which allows us to integrate Intel MKL into ALGLIB, so you don't have to buy separate license from Intel.
</p>
<a name='int_license' class='sheader'></a><h2>1.2 1.1 ALGLIB license</h2>
<p align=justify>
<b>ALGLIB Free Edition</b> is distributed under GPL 2+, GPL license version 2 or at your option any later version.
A copy of the GNU General Public License is available at <a href='http://www.fsf.org/licensing/licenses'>http://www.fsf.org/licensing/licenses</a>
</p>
<p align=justify>
<b>ALGLIB Commercial Edition</b> is distributed under license which is friendly to commericial users.
A copy of the commercial license can be found at <a href='http://www.alglib.net/commercial.php'>http://www.alglib.net/commercial.php</a>.
</p>
<a name='int_doc_license' class='sheader'></a><h2>1.3 Documentation license</h2>
<div style='width: 640px;'>
<p>
<U>This reference manual is licensed under BSD-like documentation license</U>:
</p>
<p>
Copyright 1994-2009 Sergey Bochkanov, ALGLIB Project. All rights reserved.
</p>
<p>
Redistribution and use of this document (ALGLIB Reference Manual) with or without modification,
are permitted provided that such redistributions will retain the above copyright notice,
this condition and the following disclaimer as the first (or last) lines of this file.
</p>
<p>
THIS DOCUMENTATION IS PROVIDED BY THE ALGLIB PROJECT "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES,
INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE ALGLIB PROJECT BE LIABLE FOR ANY DIRECT, INDIRECT,
INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT
OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS DOCUMENTATION, EVEN IF ADVISED
OF THE POSSIBILITY OF SUCH DAMAGE.
</p>
</div>
<a name='gs_guide' class='sheader'></a><h2>1.4 Reference Manual and User Guide</h2>
<p>
ALGLIB Project provides two sources of information: ALGLIB Reference Manual (this document) and <a href="http://www.alglib.net/#book">ALGLIB User Guide</a>.
</p>
<p>
ALGLIB Reference Manual contains full description of all publicly accessible ALGLIB units accompanied with examples.
Reference Manual is focused on the source code: it documents units, functions, structures and so on.
If you want to know what unit <code>YYY</code> can do or what subroutines unit <code>ZZZ</code> contains Reference Manual is a place to go.
Free software needs free documentation - that's why ALGLIB Reference Manual is licensed under BSD-like documentation license.
</p>
<p>
Additionally to the Reference Manual we provide you <a href="http://www.alglib.net/#book">User Guide</a>.
User Guide is focused on more general questions: how fast ALGLIB is? how reliable it is? what are the strong and weak sides of the algorithms used?
We aim to make ALGLIB User Guide an important source of information both about ALGLIB and numerical analysis algorithms in general.
We want it to be a book about algorithms, not just software documentation.
And we want it to be unique - that's why ALGLIB User Guide is distributed under less-permissive <a href="http://alglib.net.localhost/#guide_license">personal-use-only license</a>.
</p>
<a name='int_ack' class='sheader'></a><h2>1.5 Acknowledgements</h2>
<p>
ALGLIB was not possible without contribution of the next open source projects:
</p>
<ul>
<li><a href="http://www.netlib.org/lapack/">LAPACK</a></li>
<li><a href="http://www.moshier.net/">Cephes</a></li>
<li><a href="http://gmplib.org/">GNU MP</a></li>
<li><a href="http://www.mpfr.org/">MPFR</a></li>
</ul>
<p>
We also want to thank developers of the Intel's local development center (Nizhny Novgorod branch)
for their help during MKL integration.
</p>
<a name='gs_structure' class='sheader'></a><h1>2 ALGLIB structure</h1>
<a name='gs_packages' class='sheader'></a><h2>2.1 Packages</h2>
<p>
ALGLIB is a C++ interface to the computational core written in C.
Both C library and C++ wrapper are automatically generated by code generation tools developed within ALGLIB project.
Pre-3.0 versions of ALGLIB included more than 100 units, but it was difficult to work with such large number of files.
Since ALGLIB 3.0 all units are merged into 11 <i>packages</i> and two support units:
</p>
<ul>
<li><b>alglibmisc.cpp</b> - contains different algorithms which are hard to classify</li>
<li><b>dataanalysis.cpp</b> - contains data mining algorithms</li>
<li><b>diffequations.cpp</b> - contains differential equation solvers</li>
<li><b>fasttransforms.cpp</b> - contains FFT and other related algorithms</li>
<li><b>integration.cpp</b> - contains numerical integration algorithms</li>
<li><b>interpolation.cpp</b> - contains interpolation algorithms</li>
<li><b>linalg.cpp</b> - contains linear algebra algorithms</li>
<li><b>optimization.cpp</b> - contains optimization algorithms</li>
<li><b>solvers.cpp</b> - contains linear and nonlinear solvers</li>
<li><b>specialfunctions.cpp</b> - contains special functions</li>
<li><b>statistics.cpp</b> - statistics</li>
<li><i>alglibinternal.cpp</i> - contains internal functions which are used by other packages, but not exposed to the external world</li>
<li><i>ap.cpp</i> - contains publicly accessible vector/matrix classes, most important and general functions and other "basic" functionality</li>
</ul>
<p>
One package may rely on other ones, but we have tried to reduce number of dependencies.
Every package relies on <code>ap.cpp</code> and many packages rely on <code>alglibinternal.cpp</code>.
But many packages require only these two to work, and many other packages need significantly less than 13 packages.
For example, <code>statistics.cpp</code> requires two packages mentioned above and only one additional package - <code>specialfunctions.cpp</code>.
</p>
<a name='gs_subpackages' class='sheader'></a><h2>2.2 Subpackages</h2>
<p>
There is one more concept to learn - <i>subpackages</i>.
Every package was created from several source files.
For example (as of ALGLIB 3.0.0), <code>linalg.cpp</code> was created by merging together 14 .cpp files (C++ interface) and 14 .c files (computational core).
These files provide different functionality: one of them calculates triangular factorizations, another generates random matrices, and so on.
We've merged source code, but what to do with their documentation?
</p>
<p>
Of course, we can merge their documentation (as we've merged units) in one big list of functions and data structures, but such list will be hard to read.
Instead, we have decided to merge <i>source code</i>, but leave <i>documentation</i> separate.
</p>
<p>
If you look at the <a href='#alglib_packages'>list of ALGLIB packages</a>, you will see that each package includes several subpackages.
For example, <code>linalg.cpp</code> includes <code>trfac</code>, <code>svd</code>, <code>evd</code> and other subpackages.
These subpackages do no exist as separate files, namespaces or other entities.
They are just subsets of one large unit which provide significantly different functionality.
They have separate documentation sections, but if you want to use <code>svd</code> subpackage, you have to include <code>linalg.h</code>, not <code>svd.h</code>.
</p>
<a name='gs_osscomm' class='sheader'></a><h2>2.3 Open Source and Commercial versions</h2>
<p>
ALGLIB comes in two versions - open source (GPL-licensed) and commercial (closed source) one.
Both versions have same <i>functionality</i>, i.e. may solve same set of problems.
However, commercial version differs from open source one in following aspects:
</p>
<ul>
<li>
<b>License</b>.
Commercial ALGLIB is licensed under non-copyleft license which is friendly to commercial users.
</li>
<li>
<b>Performance</b>.
Many algorithms in commercial ALGLIB are multi-threaded and SSE-optimized (when used on Intel systems).
Open source ALGLIB is single-threaded and can not efficiently use modern multicore CPU's.<br>
You have to study comments on specific functions if you want to know whether they have multithreaded versions or not.
</li>
</ul>
<p>
This documentation applies to both versions of ALGLIB.
Detailed description of commercial version can be found <a href='#gs_comm'>below</a>.
</p>
<a name='gs_compatibility' class='sheader'></a><h1>3 Compatibility</h1>
<a name='gs_compatibility_cpu' class='sheader'></a><h2>3.1 CPU</h2>
<p>
ALGLIB is compatible with any CPU which:
</p>
<ul>
<li>supports double precision arithmetics</li>
<li>complies with IEEE 754 floating point standard (especially in its handling of IEEE special values)</li>
<li>either big-endian or little-endian (but not mixed-endian)</li>
</ul>
<p>
Most mainstream CPU's (in particular, x86, x86_64, ARM and SPARC) satisfy these requirements.
</p>
<p class='p_note'>
As for Intel architecture, ALGLIB works with both FPU-based and SSE-based implementations of floating point math.
80-bit internal representation used by Intel FPU is not a problem for ALGLIB.
</p>
<a name='gs_compatibility_os' class='sheader'></a><h2>3.2 OS</h2>
<p>
ALGLIB for C++ (both open source and commercial versions) can be compiled in OS-agnostic mode (no OS-specific preprocessor definitions),
when it is compatible with any OS which supports C++98 standard library.
In particular, it will work under any POSIX-compatible OS and under Windows.
</p>
<p>
If you want to use multithreaded capabilities of <i>commercial</i> version of ALGLIB,
you should compile it in OS-specific mode by #defining either <code>AE_OS=AE_WINDOWS</code>
or <code>AE_OS=AE_POSIX</code> at compile time, depending on OS being used.
Former corresponds to any modern OS (32/64-bit Windows XP and later) from Windows family,
while latter means almost any POSIX-compatible OS.
It applies only to commercial version of ALGLIB.
Open source version is always OS-agnostic, even in the presence of OS-specific definitions.
</p>
<a name='gs_compatibility_compiler' class='sheader'></a><h2>3.3 Compiler</h2>
<p>
ALGLIB is compatible with any C++ compiler which:
</p>
<ul>
<li>supports 32-bit and 64-bit signed integer datatypes</li>
<li>emits code which handles <i>comparisons</i> with IEEE special values without raising exception.
We don't require that <code>x/0</code> will return <code>INF</code>.
But at least we must be able to <i>compare</i> double precision value with infinity or NAN without raising exception.</li>
</ul>
<p>
All modern compilers (in particular, reasonably new versions of MSVC, GCC and Sun Studio) satisfy these requirements.
</p>
<p>
However, some <i>very</i> old compilers (ten years old version of Borland C++ Builder, for example) may emit code which does not correctly work with IEEE special values.
If you use one of these old compilers, we recommend you to run ALGLIB test suite to ensure that library works.
</p>
<a name='gs_compatibility_opt' class='sheader'></a><h2>3.4 Optimization settings</h2>
<p>
ALGLIB is compatible with any kind of optimizing compiler as long as:
</p>
<ul>
<li><b>volatile</b> modifier is correctly handled (i.e. compiler does <b>not</b> optimize volatile reads/writes)</li>
<li>optimized code correctly handles IEEE special values</li>
</ul>
<p>
Generally, all kinds of optimization that were marked by compiler vendor as "safe" are possible. For example, ALGLIB can be compiled:
</p>
<ul>
<li>under MSVC: with /O1, /O2, /Og, /Os, /Ox, /Ot, /Oy, /fp:precise, /fp:except, /fp:strict</li>
<li>under GCC: with -O1, -O2, -O3, -Os</li>
</ul>
<p>
From the other side, following "unsafe" optimizations will break ALGLIB:
</p>
<ul>
<li>under MSVC: /fp:fast</li>
<li>under GCC: -Ofast, -ffast-math</li>
</ul>
<a name='gs_compiling' class='sheader'></a><h1>4 Compiling ALGLIB</h1>
<a name='gs_attaching' class='sheader'></a><h2>4.1 Adding to your project</h2>
<p>
Adding ALGLIB to your project is easy - just pick packages you need and... add them to your project!
Under most used compilers (GCC, MSVC, Sun Studio) it will work without any additional settings.
In other cases you will need to define several preprocessor definitions (this topic will be detailed below), but everything will still be simple.
</p>
<p style='margin-left: 30px; font-size: 90%;'>
By "adding to your project" we mean that you should a) <i>compile</i> .cpp files with the rest of your project, and b) <i>include</i> .h files you need.
<u>Do not include .cpp files</u> - these files must be compiled separately, not as part of some larger source file.
The only files you should include are .h files, stored in the /src folder of the ALGLIB distribution.
</p>
<p>
As you see, ALGLIB has no project files or makefiles. Why? There are several reasons:
</p>
<ul>
<li>first, because many ALGLIB users don't need separate static library (which will be created by invoking makefile) - they prefer to integrate source code in their projects.
We have provided script-based build system before, but majority of our users prefer to build ALGLIB themselves.
</li>
<li>
second, because we want ALGLIB to be usable in any programming environment, whether it is Visual Studio, GNU build system or something else.
The best solution is to write package which doesn't depend on any particular programming environment.
</li>
</ul>
<p>
In any case, compiling ALGLIB is so simple that even without project file you can do it in several minutes.
</p>
<a name='gs_configuring' class='sheader'></a><h2>4.2 Configuring for your compiler</h2>
<p>
If you use modern versions of MSVC, GCC or Sun Studio, you don't need to configure ALGLIB at all.
But if you use outdated versions of these compilers (or something else), then you may need to tune definitions of several data types:
</p>
<ul>
<li><b>alglib_impl::ae_int32_t</b> - signed integer which is 32 bits wide</li>
<li><b>alglib_impl::ae_int64_t</b> - signed integer which is 64 bits wide</li>
<li><b>alglib_impl::ae_int_t</b> - signed integer which has same width as pointer</li>
</ul>
<p>
ALGLIB tries to autodetect your compiler and to define these types in compiler-specific manner:
</p>
<ul>
<li><code>ae_int32_t</code> is defined as <code>int</code>, because this type is 32 bits wide in all modern compilers.</li>
<li><code>ae_int64_t</code> is defined as <code>_int64</code> (MSVC) or as <code>signed long long</code> (GCC, Sun Studio).</li>
<li><code>ae_int_t</code> is defined as <code>ptrdiff_t</code>.</li>
</ul>
<p>
In most cases, it is enough. But if anything goes wrong, you have several options:
</p>
<ul>
<li>if your compiler provides <code>stdint.h</code>, you can define <code>AE_HAVE_STDINT</code> conditional symbol</li>
<li>alternatively, you can manually define <code>AE_INT32_T</code> and/or <code>AE_INT64_T</code> and/or <code>AE_INT_T</code> symbols.
Just assign datatype name to them, and ALGLIB will automatically use your definition. You can define only one or two types (those which are not defined automatically).</li>
</ul>
<a name='gs_configuring2' class='sheader'></a><h2>4.3 Improving performance (CPU-specific and OS-specific optimizations)</h2>
<p>
You can improve performance of ALGLIB in a several ways:
</p>
<ul>
<li>by compiling with advanced optimization turned on</li>
<li>by telling ALGLIB about CPU it will run on</li>
</ul>
<p>
ALGLIB has two-layered structure: some set of basic performance-critical primitives is implemented using optimized code,
and the rest of the library is built on top of these primitives.
By default, ALGLIB uses generic C code to implement these primitives (matrix multiplication, decompositions, etc.).
This code works everywhere from Intel to SPARC.
However, you can tell ALGLIB that it will work under particular architecture by defining appropriate macro at the global level:
</p>
<ul>
<li>defining <code>AE_CPU=AE_INTEL</code> - to tell ALGLIB that it will work under Intel</li>
</ul>
<p>
When <code>AE_CPU</code> macro is defined and equals to the <code>AE_INTEL</code>, it enables SSE2 support.
ALGLIB will use <code>cpuid</code> instruction to determine SSE2 presence at run-time and - in case we have SSE2 - to use SSE2-capable code.
ALGLIB uses SSE2 intrinsics which are portable across different compilers and efficient enough for most practical purposes.
As of ALGLIB 3.4, SSE2 support is available for MSVC, GCC and Sun Studio users only.
</p>
<a name='gs_comm' class='sheader'></a><h1>5 Working with commercial version</h1>
<a name='gs_comm_benefits' class='sheader'></a><h2>5.1 Benefits of commercial version</h2>
<p>
Commercial version of ALGLIB for C++ features four important improvements over open source one:
</p>
<ul>
<li>
<b>License</b>.
Commercial license used by ALGLIB is friendly to closed source applications.
Unlike GPL, it does not require you to open source your application.
Thus, almost any commercial software developer is interested in obtaining commercial license.
</li>
<li>
<b>Low-level optimizations</b>.
Commercial version of ALGLIB includes SSE-optimized versions of many computationally intensive functions.
In particular, commercial version of neural networks outperforms open source one with 2-3x increase in speed -
even without multithreading!
It allows to increase performance on Intel/AMD platforms while still being able to use software under non-x86 CPU's.
</li>
<li>
<b>Multithreading</b>.
Commercial version of ALGLIB can utilize multicore capabilities of modern CPU's.
Large computational problems can be automatically split between different cores.
ALGLIB uses its own multithreading framework which <b>does not</b> depend on vendor/compiler support for technologies like OpenMP/MPI/...
It gives ALGLIB unprecedented portability across operating systems and compilers.
</li>
<li>
<b>Integrated Intel MKL</b>.
Commercial version of ALGLIB includes special <i>MKL extensions</i> -
special lightweight distribution of Intel MKL, high-performance numerical analysis library, accompanied by ALGLIB-MKL interface.
We obtained license from Intel which allows us to integrate MKL into ALGLIB distribution.
Linking with MKL accelerates many ALGLIB functions,
however due to license restrictions you can not use MKL directly (i.e. bypass ALGLIB interface between your program and MKL).
</li>
</ul>
<a name='gs_comm_sse' class='sheader'></a><h2>5.2 Working with SSE support (Intel/AMD users)</h2>
<p>
ALGLIB for C++ can utilize SSE2 set of instructions supported by all modern Intel and AMD x86 processors.
This feature is optional and must be explicitly turned on during compile-time.
If you do not activate it, ALGLIB will use generic C code, without <b>any</b> processor-specific assembly/intrinsics.
</p>
<p>
Thus, if you turn on this feature, your code will run faster on x86_32 and x86_64 processors,
but will be unportable to non-x86 platforms (<i>and Intel MIC platform, which is not exactly x86 and does not support SSE!</i>).
From the other side, if you do not activate this feature, your code will be portable to almost any modern CPU (SPARC, ARM, ...).
</p>
<p>
In order to turn on x86-specific optimizations,
you should define <code>AE_CPU=AE_INTEL</code> preprocessor definition at global level.
It will tell ALGLIB to use SSE intrinsics supported by GCC, MSVC and Intel compilers.
Additionally you should tell compiler to generate SSE-capable code.
It can be done in the project settings of your IDE or in the command line:
</p>
<pre class='p_code'>
<span style='color: navy; font-weight: bold;'>GCC example:</span>
> g++ <span style='color: red;'>-msse2</span> -I. <span style='color: red;'>-DAE_CPU=AE_INTEL</span> *.cpp -lm
<span style='color: navy; font-weight: bold;'>MSVC example:</span>
> cl /I. /EHsc <span style='color: red;'>/DAE_CPU=AE_INTEL</span> *.cpp
</pre>
<a name='gs_comm_smp' class='sheader'></a><h2>5.3 Using multithreading</h2>
<p>
Commercial version of ALGLIB includes out-of-the-box support for multithreading.
Many (<i>not all</i>) computationally intensive problems can be solved in multithreaded mode.
You should read comments on specific ALGLIB functions to determine what can be multithreaded and what can not.
</p>
<p>
ALGLIB <b>does not</b> depend on vendor/compiler support for technologies like OpenMP/MPI/...
Under Windows ALGLIB uses OS threads and custom synchronization framework.
Under POSIX-compatible OS (Solaris, Linux, FreeBSD, NetBSD, OpenBSD, ...) ALGLIB uses POSIX Threads
(<i>standard *nix library which is shipped with any POSIX system</i>)
with its threading and synchronization primitives.
It gives ALGLIB unprecedented portability across operating systems and compilers.
ALGLIB does not depend on presence of <b>any</b> custom multithreading library
or compiler support for <b>any</b> multithreading technology.
</p>
<p>
If you want to use multithreaded capabilities of ALGLIB, you should:
</p>
<ol>
<li>compile it in OS-specific mode (ALGLIB have to know what OS it is running on)</li>
<li>tell ALGLIB about number of worker threads to use</li>
<li>call multithreaded versions of computational functions</li>
</ol>
<p>
Let explain it in more details...
</p>
<p>
<b>1</b>.
You should compile ALGLIB in OS-specific mode by #defining either
<code>AE_OS=AE_WINDOWS</code> or <code>AE_OS=AE_POSIX</code> at compile time, depending on OS being used.
Former corresponds to any modern OS (32/64-bit Windows XP and later) from Windows family,
while latter means almost any POSIX-compatible OS.
When compiling on POSIX, do not forget to link ALGLIB with <code>libpthread</code> library.
</p>
<p>
<b>2</b>.
ALGLIB automatically determines number of cores on application startup.
On Windows it is done using <code>GetSystemInfo()</code> call.
On POSIX systems ALGLIB performs <code>sysconf(_SC_NPROCESSORS_ONLN)</code> system call.
This system call is supported by all modern POSIX-compatible systems: Solaris, Linux, FreeBSD, NetBSD, OpenBSD.
</p>
<p>
By default, ALGLIB uses all available cores except for one.
Say, on 4-core system it will use three cores - unless being told to use more or less.
It will keep your system responsive during lengthy computations.
Such behavior may be changed with <code>setnworkers()</code> call:
</p>
<ul>
<li><code>alglib::setnworkers(0)</code> = use all cores</li>
<li><code>alglib::setnworkers(-1)</code> = leave one core unused</li>
<li><code>alglib::setnworkers(-2)</code> = leave two cores unused</li>
<li><code>alglib::setnworkers(+2)</code> = use 2 cores (even if you have more)</li>
</ul>
<p>
You may want to specify maximum number of worker threads during compile time
by means of preprocessor definition <code>AE_NWORKERS=N</code>.
You can add this definition to compiler command line or change corresponding project settings in your IDE.
Here N can be any positive number.
ALGLIB will use exactly N worker threads, unless being told to use less by <code>setnworkers()</code> call.
</p>
<p class='p_note'>
Some old POSIX-compatible operating systems do not support <code>sysconf(_SC_NPROCESSORS_ONLN)</code> system call
which is required in order to automatically determine number of active cores.
On these systems you should specify number of cores manually at compile time.
Without it ALGLIB will run in single-threaded mode.
</p>
<p>
<b>3</b>.
When you use commercial edition of ALGLIB,
you may choose between serial and multithreaded versions of SMP-capable functions:
</p>
<ul>
<li>serial version works as usual, in the context of the calling thread</li>
<li>multithreaded version (with <code>smp_</code> prefix in its name) creates (or wakes up) worker threads,
inserts task in the worker queue, and waits for completion of the task.
All processing is done in context of worker thread(s).</li>
</ul>
<p>
You should carefully decide what version of function to use.
Starting/stopping worker thread costs tens of thousands of CPU cycles.
Thus you won't get multithreading speedup on small computational problems.
</p>
<a name='gs_comm_smp' class='sheader'></a><h3>5.3.1 SMT (CMT/hyper-threading) issues</h3>
<p>
<i>Simultaneous multithreading (SMT)</i> also known as <i>Hyper-threading</i> (Intel)
and <i>Cluster-based Multithreading</i> (AMD)
is a CPU design where several (usually two) <i>logical</i> cores share resources of one <i>physical</i> core.
Say, on dual-core system with 2x HT scale factor you will see 4 logical cores.
Each pair of these 4 cores, however, share same hardware resources.
Thus, you may get only marginal speedup when running highly optimized software which fully utilizes CPU resources.
</p>
<p>
Say, if one thread occupies floating-point unit,
another thread on the same physical core may work with integer numbers at the same time without any performance penalties.
In this case you may get some speedup due to having additional cores.
But if both threads keep FPU unit 100% busy, they won't get <i>any</i> multithreaded speedup.
</p>
<p>
So, if 2 math-intensive threads are dispatched by OS scheduler to different physical cores,
you will get 2x speedup due to use of multithreading.
But if these threads are dispatched to different logical cores - but same physical core - you won't get any speedup at all!
One physical core will be 100% busy, and another one will be 100% idle.
From the other side, if you start four threads instead of two, your system will be 100% utilized independently of thread scheduling details.
</p>
<p>
Let we stress it one more time - multithreading speedup on SMT systems is highly dependent on number of threads you are running and decisions made by OS scheduler.
<b>It is not 100% deterministic!</b>
With "true SMP" when you run 2 threads, you get 2x speedup (or 1.95, or 1.80 - it depends on algorithm, but this factor is always same).
With SMT when you run 2 threads you may get your 2x speedup - or no speedup at all.
Modern OS schedulers do a good job on single-socket hardware,
but even in this "simple" case they give no guarantees of fair distribution of hardware resources.
And things become a bit tricky when you work with multi-socket hardware.
<b>On SMT systems the only guaranteed way to 100% utilize your CPU is to create as many worker threads as there are logical cores</b>.
In this case OS scheduler has no chance to make its work in a wrong way.
</p>
<a name='gs_comm_hpc' class='sheader'></a><h2>5.4 Linking with Intel MKL</h2>
<a name='gs_comm_mkl_lightweight' class='sheader'></a><h3>5.4.1 Using lightweight Intel MKL supplied by ALGLIB Project</h3>
<p>
Commercial edition of ALGLIB includes <i>MKL extensions</i> -
special lightweight distribution of Intel MKL, highly optimized numerical library from Intel - and precompiled ALGLIB-MKL interface libraries.
Linking your programs with MKL extensions allows you to run ALGLIB with maximum performance.
</p>
<p class='p_note'>
Current version of ALGLIB features Windows-only MKL extensions,
but in future ALGLIB releases we will introduce MKL extensions for Linux systems.
</p>
<p>
Unlike the rest of the library, MKL extensions are distributed in binary-only form.
ALGLIB itself is still distributed in source code form, but Intel MKL and ALGLIB-MKL interface are distributed as precompiled dynamic/static libraries.
We can not distribute them in source because of license restrictions associated with Intel MKL.
Also due to license restrictions we can not give you direct access to MKL functionality.
You may use MKL to accelerate ALGLIB - without paying for MKL license - but you may not call its functions directly.
It is technically possible, but strictly prohibited by both MKL's EULA and ALGLIB License Agreement.
If you want to work with MKL, you should buy separate license from Intel.
</p>
<p>
MKL extensions are located in the <code>/cpp/mkl-windows</code> subdirectory of the ALGLIB distribution.
This directory includes:
</p>
<ul>
<li><b>mkl4alglib_32.lib</b> - 32-bit import library for Intel MKL</li>
<li><b>mkl4alglib_32.dll</b> - 32-bit external DLL with Intel MKL</li>
<li><b>mkl4alglib_<span style='color: red;'>64</span>.lib</b> - 64-bit import library for Intel MKL</li>
<li><b>mkl4alglib_<span style='color: red;'>64</span>.dll</b> - 64-bit external DLL with Intel MKL</li>
</ul>
<p>
In order to activate MKL extensions you should:
</p>
<ul>
<li>
compile ALGLIB source files with following preprocessor symbols defined on at global level:<br>
<code>AE_OS=AE_WINDOWS</code> (to activate multithreading capabilities)<br>
<code>AE_CPU=AE_INTEL</code> (to use SSE instructions provided by x86/x64 CPU's)<br>
<code>AE_MKL</code> (to use Intel MKL functions in ALGLIB)<br>
If you compile from command line, you may write <code>"/DAE_OS=AE_WINDOWS /DAE_CPU=AE_INTEL /DAE_MKL"</code>
</li>
<li>
depending on CPU architecture, choose 32-bit or 64-bit LIB file -
<code>mkl4alglib_32/64.lib</code> - and link it with your application.
</li>
<li>
place <code>mkl4alglib_32/64.dll</code> into directory where it can be found during application startup
(usually - application dir)
</li>
</ul>
<p>
Examples on linking from command line can be found in the next section.
</p>
<a name='gs_comm_mkl_own' class='sheader'></a><h3>5.4.2 Using your own installation of Intel MKL</h3>
<p>
If you bought separate license for Intel MKL, and want to use your own
installation of MKL - and not our lightweight distribution - then you
should compile ALGLIB as it was told in the previous section, with all necessary preprocessor definitions.
But instead of linking with <code>mkl4alglib</code> dynamic library,
you should add to your project <code>mkl4alglib.c</code> file from <code>mkl-interface</code> directory
and compile it (as C file) along with the rest of ALGLIB.
</p>
<p>
This C file implements interface between MKL and ALGLIB.
Having this file in your project and defining <code>AE_MKL</code> preprocessor definition
results in ALGLIB using MKL functions.
</p>
<p>
However, this C file is just interface!
It is your responsibility to make sure that C/C++ compiler can find MKL headers,
and appropriate MKL static/dynamic libraries are linked to your application.
</p>
<p class='p_note'>
If you link ALGLIB with your own installation if Intel MKL,
you may do so on any OS where MKL works - Windows or Linux.
</p>
<a name='gs_comm_examples' class='sheader'></a><h2>5.5 Examples - compiling commercial edition of ALGLIB</h2>
<a name='gs_comm_examples_set' class='sheader'></a><h3>5.5.1 Introduction</h3>
<p>
In this section we'll consider different compilation scenarios for commercial version of ALGLIB -
from simple platform-agnostic compilation to linking with MKL extensions.
</p>
<p>
We assume that you unpacked ALGLIB distribution in the current directory and saved here <code>demo.cpp</code> file,
whose code is given below. Thus, in the current directory you should have exactly one file (<code>demo.cpp</code>) and
exactly one subdirectory (<code>cpp</code> folder with ALGLIB distribution).
</p>
<a name='gs_comm_examples_win' class='sheader'></a><h3>5.5.2 Compiling under Windows</h3>
<p>
File listing below contains the very basic program which uses ALGLIB to perform matrix-matrix multiplication.
After that program evaluates performance of <i>GEMM</i> (function being called) and prints result to console.
We'll show how performance of this program continually increases as we add more and more sophisticated compiler options.
</p>
<pre class='p_code_head'>
demo.cpp
</pre>
<pre class='p_code_body'>
#include <stdio.h>
#include <windows.h>
#include "LinAlg.h"
<b>double</b> counter()
{
return 0.001*GetTickCount();
}
<b>int</b> main()
{
alglib::real_2d_array a, b, c;
<b>int</b> n = 2000;
<b>int</b> i, j;
<b>double</b> timeneeded, flops;
// Initialize arrays
a.setlength(n, n);
b.setlength(n, n);
c.setlength(n, n);
<b>for</b>(i=0; i<n; i++)
<b>for</b>(j=0; j<n; j++)
{
a[i][j] = alglib::randomreal()-0.5;
b[i][j] = alglib::randomreal()-0.5;
c[i][j] = 0.0;
}
// Set number of worker threads: "4" means "use 4 cores".
// This line is ignored if AE_OS is UNDEFINED.
alglib::setnworkers(4);
// Perform matrix-matrix product.
// We call function with "smp_" prefix, which means that ALGLIB
// will try to execute it in parallel manner whenever it is possible.
flops = 2*pow((<b>double</b>)n, (<b>double</b>)3);
timeneeded = counter();
alglib::smp_rmatrixgemm(
n, n, n,
1.0,
a, 0, 0, 0,
b, 0, 0, 1,
0.0,
c, 0, 0);
timeneeded = counter()-timeneeded;
// Evaluate performance
printf("Performance is %.1f GFLOPS\n", (<b>double</b>)(1.0E-9*flops/timeneeded));
return 0;
}
</pre>
<p>
Examples below cover Windows compilation from command line with MSVC.
It is very straightforward to adapt them to compilation from MSVC IDE - or to another compilers.
We assume that you already called <code>%VCINSTALLDIR%\bin\amd64\vcvars64.bat</code> batch file
which loads 64-bit build environment (or its 32-bit counterpart).
We also assume that current directory is clean before example is executed
(i.e. it has ONLY <code>demo.cpp</code> file and <code>cpp</code> folder).
We used 3.2 GHz 4-core CPU for this test.
</p>
<p>
First example covers platform-agnostic compilation without optimization settings - the most simple way to compile ALGLIB.
However, in platform-agnostic mode ALGLIB is unable to use all performance related features present in commercial edition.
</p>
<p>
We starts from copying all <code>cpp</code> and <code>h</code> files to current directory,
then we will compile them along with <code>demo.cpp</code>.
In this and following examples we will omit compiler output for the sake of simplicity.
</p>
<pre class='p_code_head'>
OS-agnostic mode, no compiler optimizations
</pre>
<pre class='p_code_body'>
<b>></b> copy cpp\src\*.* .
<b>></b> cl /I. /EHsc /Fedemo.exe *.cpp
<b>></b> demo.exe
Performance is 0.7 GFLOPS
</pre>
<p>
Well, 0.7 GFLOPS is not very impressing for a 3.2GHz CPU... Let's add <code>/Ox</code> to compiler parameters.
</p>
<pre class='p_code_head'>
OS-agnostic mode, /Ox optimization
</pre>
<pre class='p_code_body'>
<b>></b> copy cpp\src\*.* .
<b>></b> cl /I. /EHsc /Fedemo.exe <span style='font-weight: bold; color: red;'>/Ox</span> *.cpp
<b>></b> demo.exe
Performance is 0.9 GFLOPS
</pre>
<p>
Still not impressed. Let's turn on optimizations for x86 architecture: define <code>AE_CPU=AE_INTEL</code>.
</p>
<pre class='p_code_head'>
OS-agnostic mode, ALGLIB knows it is x86/x64
</pre>
<pre class='p_code_body'>
<b>></b> copy cpp\src\*.* .
<b>></b> cl /I. /EHsc /Fedemo.exe /Ox <span style='font-weight: bold; color: red;'>/DAE_CPU=AE_INTEL</span> *.cpp
<b>></b> demo.exe
Performance is 4.5 GFLOPS
</pre>
<p>
It is good, but we have 4 cores - and only one of them was used.
Defining <code>AE_OS=AE_WINDOWS</code> allows ALGLIB to use Windows threads to parallelize execution of some functions.
</p>
<pre class='p_code_head'>
ALGLIB knows it is Windows on x86/x64 CPU
</pre>
<pre class='p_code_body'>
<b>></b> copy cpp\src\*.* .
<b>></b> cl /I. /EHsc /Fedemo.exe /Ox /DAE_CPU=AE_INTEL <span style='font-weight: bold; color: red;'>/DAE_OS=AE_WINDOWS</span> *.cpp
<b>></b> demo.exe
Performance is 16.0 GFLOPS
</pre>
<p>
Not bad.
And now we are ready to the final test - linking with MKL extensions.
</p>
<p>
Linking with MKL extensions differs a bit from standard way of linking with ALGLIB.
ALGLIB itself is compiled with one more preprocessor definition: we define <code>AE_MKL</code> symbol.
We also link ALGLIB with appropriate (32-bit or 64-bit) <code>mkl4alglib</code> static library,
which is import library for special lightweight MKL distribution, shipped with ALGLIB for no additional price.
We also should copy to current directory appropriate <code>mkl4alglib</code> DLL file which contains Intel MKL.
</p>
<pre class='p_code_head'>
Linking with MKL extensions
</pre>
<pre class='p_code_body'>
<b>></b> copy cpp\src\<span style='font-weight: bold; color: red;'>*.*</span> .
<b>></b> copy cpp\mkl-windows\<span style='font-weight: bold; color: red;'>mkl4alglib_64.lib</span> .
<b>></b> copy cpp\mkl-windows\<span style='font-weight: bold; color: red;'>mkl4alglib_64.dll</span> .
<b>></b> cl /I. /EHsc /Fedemo.exe /Ox /DAE_CPU=AE_INTEL /DAE_OS=AE_WINDOWS <span style='font-weight: bold; color: red;'>/DAE_MKL demo.cpp mkl4alglib_64.lib</span>
<b>></b> demo.exe
Performance is 33.1 GFLOPS
</pre>
<p>
From 0.7 GFLOPS to 33.1 GFLOPS - you may see that commercial version of ALGLIB is really worth it!
</p>
<a name='gs_using' class='sheader'></a><h1>6 Using ALGLIB</h1>
<a name='gs_using_threadsafety' class='sheader'></a><h2>6.1 Thread-safety</h2>
<p>
Both open source and commercial versions of ALGLIB are 100% thread-safe
<b>as long as different user threads work with different instances of objects/arrays</b>.
Thread-safety is guaranteed by having no global shared variables.
</p>
<p>
However, <b>any kind</b> of sharing ALGLIB objects/arrays between different threads is potentially hazardous.
Even when this object is <b>seemingly</b> used in read-only mode!
</p>
<p class='p_note'>
Say, you use ALGLIB neural network <i>NET</i> to process two input vectors <i>X0</i> and <i>X1</i>,
and get two output vectors <i>Y0</i> and <i>Y1</i>.
You may decide that neural network is used in read-only mode which does not change state of <i>NET</i>,
because output is written to distinct arrays <i>Y</i>.
Thus, you may want to process these vectors from parallel threads.
<br><br>
But it is <b>not</b> read-only operation, even if it looks like this!
Neural network object <i>NET</i> allocates internal temporary buffers, which are modified by neural processing functions.
Thus, sharing one instance of neural network between two threads is thread-unsafe!
</p>
<a name='gs_global' class='sheader'></a><h2>6.2 Global definitions</h2>
<p>
ALGLIB defines several conditional symbols (all start with "AE_" which means "<b>A</b>LGLIB <b>e</b>nvironment") and two namespaces:
<code>alglib_impl</code> (contains computational core) and <code>alglib</code> (contains C++ interface).
</p>
<p>
Although this manual mentions both <code>alglib_impl</code> and <code>alglib</code> namespaces, only <code>alglib</code> namespace should be used by you.
It contains user-friendly C++ interface with automatic memory management, exception handling and all other nice features.
<code>alglib_impl</code> is less user-friendly, is less documented, and it is too easy to crash your system or cause memory leak if you use it directly.
</p>
<a name='gs_datatypes' class='sheader'></a><h2>6.3 Datatypes</h2>
<p>
ALGLIB (<code>ap.h</code> header) defines several "basic" datatypes (types which are used by all packages) and many package-specific datatypes. "Basic" datatypes are:
</p>
<ul>
<li><code>alglib::ae_int_t</code> - signed integer type used by library</li>
<li><code>alglib::complex</code> - double precision complex datatype, safer replacement for <code>std::complex</code></li>
<li><code>alglib::ap_error</code> - exception which is thrown by library</li>
<li><code>boolean_1d_array</code> - 1-dimensional boolean array</li>
<li><code>integer_1d_array</code> - 1-dimensional integer array</li>
<li><code>real_1d_array</code> - 1-dimensional real (double precision) array</li>
<li><code>complex_1d_array</code> - 1-dimensional complex array</li>
<li><code>boolean_2d_array</code> - 2-dimensional boolean array</li>
<li><code>integer_2d_array</code> - 2-dimensional integer array</li>
<li><code>real_2d_array</code> - 2-dimensional real (double precision) array</li>
<li><code>complex_2d_array</code> - 2-dimensional complex array</li>
</ul>
<p>
Package-specific datatypes are classes which can be divided into two distinct groups:
</p>
<ul>
<li>"struct-like" classes with public fields which you can access directly.</li>
<li>"object-like" classes which have no public fields. You should use ALGLIB functions to work with them.</li>
</ul>
<a name='gs_constants' class='sheader'></a><h2>6.4 Constants</h2>
<p>
The most important constants (defined in the <code>ap.h</code> header) from ALGLIB namespace are:
</p>
<ul>
<li><code>alglib::machineepsilon</code> - small number which is <i>close</i> to the double precision &eps;, but is slightly larger</li>
<li><code>alglib::maxrealnumber</code> - very large number which is <i>close</i> to the maximum real number, but is slightly smaller </li>
<li><code>alglib::minrealnumber</code> - very small number which is <i>close</i> to the minimum nonzero real number, but is slightly larger</li>
<li><code>alglib::fp_nan</code> - NAN (non-signalling under most platforms except for PA-RISC, where it is signalling;
but when PA-RISC CPU is in its default state, it is silently converted to the quiet NAN)</li>
<li><code>alglib::fp_posinf</code> - positive infinity</li>
<li><code>alglib::fp_neginf</code> - negative infinity</li>
</ul>
<a name='gs_stdfunctions' class='sheader'></a><h2>6.5 Functions</h2>
<p>
The most important "basic" functions from ALGLIB namespace (<code>ap.h</code> header) are:
</p>
<ul>
<li><code>alglib::randomreal()</code> - returns random real number from [0,1)</li>
<li><code>alglib::randominteger(mx)</code> - returns random integer number from [0,nx); <i>mx</i> must be less than RAND_MAX</li>
<li><code>alglib::fp_eq(v1,v2)</code> - makes IEEE-compliant comparison of two double precision numbers.
If numbers are represented with greater precision than specified by IEEE 754 (as with Intel 80-bit FPU), this functions converts them to 64 bits before comparing.</li>
<li><code>alglib::fp_neq(v1,v2)</code> - makes IEEE-compliant comparison of two double precision numbers.</li>
<li><code>alglib::fp_less(v1,v2)</code> - makes IEEE-compliant comparison of two double precision numbers.</li>
<li><code>alglib::fp_less_eq(v1,v2)</code> - makes IEEE-compliant comparison of two double precision numbers.</li>
<li><code>alglib::fp_greater(v1,v2)</code> - makes IEEE-compliant comparison of two double precision numbers.</li>
<li><code>alglib::fp_greater_eq(v1,v2)</code> - makes IEEE-compliant comparison of two double precision numbers.</li>
<li><code>alglib::fp_isnan</code> - checks whether number is NAN</li>
<li><code>alglib::fp_isposinf</code> - checks whether number is +INF</li>
<li><code>alglib::fp_isneginf</code> - checks whether number is -INF</li>
<li><code>alglib::fp_isinf</code> - checks whether number is +INF or -INF</li>
<li><code>alglib::fp_isfinite</code> - checks whether number is finite value (possibly subnormalized)</li>
</ul>
<a name='gs_vecmat' class='sheader'></a><h2>6.6 Working with vectors and matrices</h2>
<p>
ALGLIB (<code>ap.h</code> header) supports matrixes and vectors (one-dimensional and two-dimensional arrays) of variable size, with numeration starting from zero.
</p>
<p>
Everything starts from array creation.
You should distinguish the creation of array class instance and the memory allocation for the array.
When creating the class instance, you can use constructor without any parameters, that creates an empty array without any elements.
An attempt to address them may cause the program failure.
</p>
<p>
You can use copy and assignment constructors that copy one array into another.
If, during the copy operation, the source array has no memory allocated for the array elements, destination array will contain no elements either.
If the source array has memory allocated for its elements, destination array will allocate the same amount of memory and copy the elements there.
That is, the copy operation yields into two independent arrays with indentical contents.
</p>
<p>
You can also create array from formatted string like
<span class='s_str'>"[]"</span>,
<span class='s_str'>"[true,FALSE,tRUe]"</span>,
<span class='s_str'>"[[]]]"</span> or
<span class='s_str'>"[[1,2],[3.2,4],[5.2]]"</span> (note: <span class='s_str'>'.'</span> is used as decimal point independently from locale settings).
</p>
<pre class='p_example'>
alglib::boolean_1d_array b1;
b1 = <span class='s_str'>"[true]"</span>;
alglib::real_2d_array r2(<span class='s_str'>"[[2,3],[3,4]]"</span>);
alglib::real_2d_array r2_1(<span class='s_str'>"[[]]"</span>);
alglib::real_2d_array r2_2(r2);
r2_1 = r2;
alglib::complex_1d_array c2;
c2 = <span class='s_str'>"[]"</span>;
c2 = <span class='s_str'>"[0]"</span>;
c2 = <span class='s_str'>"[1,2i]"</span>;
c2 = <span class='s_str'>"[+1-2i,-1+5i]"</span>;
c2 = <span class='s_str'>"[ 4i-2, 8i+2]"</span>;
c2 = <span class='s_str'>"[+4i-2, +8i+2]"</span>;
c2 = <span class='s_str'>"[-4i-2, -8i+2]"</span>;
</pre>
<p>
After an empty array has been created, you can allocate memory for its elements, using the <code>setlength()</code> method.
The content of the created array elements is not defined.
If the <code>setlength</code> method is called for the array with already allocated memory, then, after changing its parameters,
the newly allocated elements also become undefined and the old content is destroyed.
</p>
<pre class='p_example'>
alglib::boolean_1d_array b1;
b1.setlength(2);
alglib::integer_2d_array r2;
r2.setlength(4,3);
</pre>
<p>
Another way to initialize array is to call <code>setcontent()</code> method.
This method accepts pointer to data which are copied into newly allocated array.
Vectors are stored in contiguous order, matrices are stored row by row.
</p>
<pre class='p_example'>
alglib::real_1d_array r1;
double _r1[] = {2, 3};
r1.setcontent(2,_r1);
alglib::real_2d_array r2;
double _r2[] = {11, 12, 13, 21, 22, 23};
r2.setcontent(2,3,_r2);
</pre>
<p>
To access the array elements, an overloaded <code>operator()</code> or <code>operator[]</code> can used.
That is, the code addressing the element of array <code>a</code> with indexes <code>[i,j]</code> can look like <code>a(i,j)</code> or <code>a[i][j]</code>.
</p>
<pre class='p_example'>
alglib::integer_1d_array a(<span class='s_str'>"[1,2,3]"</span>);
alglib::integer_1d_array b(<span class='s_str'>"[3,9,27]"</span>);
a[0] = b(0);
alglib::integer_2d_array c(<span class='s_str'>"[[1,2,3],[9,9,9]]"</span>);
alglib::integer_2d_array d(<span class='s_str'>"[[3,9,27],[8,8,8]]"</span>);
d[1][1] = c(0,0);
</pre>
<p>
You can access contents of 1-dimensional array by calling <code>getcontent()</code> method which returns pointer to the array memory.
For historical reasons 2-dimensional arrays do not provide <code>getcontent()</code> method, but you can use create reference to any element of array.
2-dimensional arrays store data in row-major order with aligned rows (i.e. generally distance between rows is not equal to number of columns).
You can get stride (distance between consequtive elements in different rows) with <code>getstride()</code> call.
</p>
<pre class='p_example'>
alglib::integer_1d_array a(<span class='s_str'>"[1,2]"</span>);
alglib::real_2d_array b(<span class='s_str'>"[[0,1],[10,11]]"</span>);
alglib::ae_int_t *a_row = a.getcontent();
<span class='s_comment'>// all three pointers point to the same location</span>
double *b_row0 = &b[0][0];
double *b_row0_2 = &b(0,0);
double *b_row0_3 = b[0];
<span class='s_comment'>// advancing to the next row of 2-dimensional array</span>
double *b_row1 = b_row0 + b.getstride();
</pre>
<p>
Finally, you can get array size with <code>length()</code>, <code>rows()</code> or <code>cols()</code> methods:
</p>
<pre class='p_example'>
alglib::integer_1d_array a(<span class='s_str'>"[1,2]"</span>);
alglib::real_2d_array b(<span class='s_str'>"[[0,1],[10,11]]"</span>);
printf(<span class='s_str'>"%ld\n"</span>, (long)a.length());
printf(<span class='s_str'>"%ld\n"</span>, (long)b.rows());
printf(<span class='s_str'>"%ld\n"</span>, (long)b.cols());
</pre>
<a name='gs_functions' class='sheader'></a><h2>6.7 Using functions: 'expert' and 'friendly' interfaces</h2>
<p>
Most ALGLIB functions provide two interfaces: 'expert' and 'friendly'. What is the difference between two? When you use 'friendly' interface, ALGLIB:
</p>
<ul>
<li>tries to automatically determine size of input arguments</li>
<li>throws an exception when arguments have inconsistent size (for example, square matrix is expected, but non-square is passed;
another example - two parameters must have same size, but have different size)</li>
<li>if semantics of input parameter assumes that it is symmetric/Hermitian matrix,
checks that lower triangle is equal to upper triangle (conjugate of upper triangle) and throws an exception otherwise</li>
<li>if semantics of output parameter assumes that it is symmetric/Hermitian matrix,
returns full matrix (both upper and lower triangles)</li>
</ul>
<p>
When you use 'expert' interface, ALGLIB:
</p>
<ul>
<li>requires caller to explicitly specify size of input arguments.
If vector/matrix is larger than size being specified (say, N), only N leading elements are used</li>
<li>if semantics of input parameter assumes that it is symmetric/Hermitian matrix,
uses <i>only upper or lower triangle</i> of input matrix and requires caller <i>to specify what triangle to use</i></li>
<li>if semantics of output parameter assumes that it is symmetric/Hermitian matrix, returns only upper or lower triangle
(when you look at specific function, it is clear what triangle is returned)</li>
</ul>
<p>
Here are several examples of 'friendly' and 'expert' interfaces:
</p>
<pre class='p_example'>
<span class='s_preprocessor'>#include "interpolation.h"</span>
<span style='color: gray;'>...</span>
alglib::real_1d_array x(<span class='s_str'>"[0,1,2,3]"</span>);
alglib::real_1d_array y(<span class='s_str'>"[1,5,3,9]"</span>);
alglib::real_1d_array y2(<span class='s_str'>"[1,5,3,9,0]"</span>);
alglib::spline1dinterpolant s;
alglib::spline1dbuildlinear(x, y, 4, s); <span class='s_comment'>// 'expert' interface is used</span>
alglib::spline1dbuildlinear(x, y, s); <span class='s_comment'>// 'friendly' interface - input size is</span>
<span class='s_comment'>// automatically determined</span>
alglib::spline1dbuildlinear(x, y2, 4, s); <span class='s_comment'>// y2.length() is 5, but it will work</span>
alglib::spline1dbuildlinear(x, y2, s); <span class='s_comment'>// it won't work because sizes of x and y2</span>
<span class='s_comment'>// are inconsistent</span>
</pre>
<p>
'Friendly' interface - matrix semantics:
</p>
<pre class='p_example'>
<span class='s_preprocessor'>#include "linalg.h"</span>
<span style='color: gray;'>...</span>
alglib::real_2d_array a;
alglib::matinvreport rep;
alglib::ae_int_t info;
<span class='s_comment'>// </span>
<span class='s_comment'>// 'Friendly' interface: spdmatrixinverse() accepts and returns symmetric matrix</span>
<span class='s_comment'>// </span>
<span class='s_comment'>// symmetric positive definite matrix</span>
a = <span class='s_str'>"[[2,1],[1,2]]"</span>;
<span class='s_comment'>// after this line A will contain [[0.66,-0.33],[-0.33,0.66]]</span>
<span class='s_comment'>// which is symmetric too</span>
alglib::spdmatrixinverse(a, info, rep);
<span class='s_comment'>// you may try to pass nonsymmetric matrix</span>
a = <span class='s_str'>"[[2,1],[0,2]]"</span>;
<span class='s_comment'>// but exception will be thrown in such case</span>
alglib::spdmatrixinverse(a, info, rep);
</pre>
<p>
Same function but with 'expert' interface:
</p>
<pre class='p_example'>
<span class='s_preprocessor'>#include "linalg.h"</span>
<span style='color: gray;'>...</span>
alglib::real_2d_array a;
alglib::matinvreport rep;
alglib::ae_int_t info;
<span class='s_comment'>// </span>
<span class='s_comment'>// 'Expert' interface, spdmatrixinverse()</span>
<span class='s_comment'>// </span>
<span class='s_comment'>// only upper triangle is used; a[1][0] is initialized by NAN,</span>
<span class='s_comment'>// but it can be arbitrary number</span>
a = <span class='s_str'>"[[2,1],[NAN,2]]"</span>;
<span class='s_comment'>// after this line A will contain [[0.66,-0.33],[NAN,0.66]]</span>
<span class='s_comment'>// only upper triangle is modified</span>
alglib::spdmatrixinverse(a, 2 <span class='s_comment'>/* N */</span>, true <span class='s_comment'>/* upper triangle is used */</span>, info, rep);
</pre>
<a name='gs_errors' class='sheader'></a><h2>6.8 Handling errors</h2>
<p>
ALGLIB uses two error handling strategies:
</p>
<ul>
<li>returning error code</li>
<li>throwing exception</li>
</ul>
<p>
What is actually done depends on function being used and error being reported:
</p>
<ol>
<li>if function returns some error code <b>and</b> has corresponding value for this kind of error, ALLGIB returns error code</li>
<li>if function does not return error code (or returns error code, but there is no code for error being reported), ALGLIB throws <code>alglib::ap_error</code> exception.
Exception object has <code>msg</code> parameter which contains short description of error.</li>
</ol>
<p>
To make things clear we consider several examples of error handling.
</p>
<p>
<u>Example 1</u>. <a href="#sub_mincgcreate">mincgreate</a> function creates nonlinear CG optimizer. It accepts problem size <code>N</code> and initial point <code>X</code>.
Several things can go wrong - you may pass array which is too short, filled by NAN's, or otherwise pass incorrect data.
However, this function returns no error code - so it throws an exception in case something goes wrong.
There is no other way to tell caller that something went wrong.
</p>
<p>
<u>Example 2</u>. <a href="#sub_rmatrixinverse">rmatrixinverse</a> function calculates inverse matrix.
It returns error code, which is set to <code>+1</code> when problem is solved and is set to <code>-3</code> if singular matrix was passed to the function.
However, there is no error code for matrix which is non-square or contains infinities.
Well, we could have created corresponding error codes - but we didn't.
So if you pass singular matrix to <code>rmatrixinverse</code>, you will get completion code <code>-3</code>.
But if you pass matrix which contains INF in one of its elements, <code>alglib::ap_error</code> will be thrown.
</p>
<p>
First error handling strategy (error codes) is used to report "frequent" errors, which can occur during normal execution of user program.
Second error handling strategy (exceptions) is used to report "rare" errors which are result of serious flaws in your program (or ALGLIB) -
infinities/NAN's in the inputs, inconsistent inputs, etc.
</p>
<a name='gs_blas' class='sheader'></a><h2>6.9 Working with Level 1 BLAS functions</h2>
<p>
ALGLIB (<code>ap.h</code> header) includes following Level 1 BLAS functions:
</p>
<ul>
<li><code>alglib::vdotproduct()</code> family, which allows to calculate dot product of two real or complex vectors</li>
<li><code>alglib::vmove()</code> family, which allows to copy real/complex vector to another location with optimal multiplication by real/complex value</li>
<li><code>alglib::vmoveneg()</code> family, which allows to copy real/complex vector to another location with multiplication by -1</li>
<li><code>alglib::vadd()</code> and <code>alglib::vsub()</code> families, which allows to add or subtract two real/complex vectors with optimal multiplication by real/complex value</li>
<li><code>alglib::vmul()</code> family, which implements in-place multiplication of real/complex vector by real/complex value</li>
</ul>
<p>
Each Level 1 BLAS function accepts input stride and output stride, which are expected to be positive.
Input and output vectors should not overlap.
Functions operating with complex vectors accept additional parameter <code>conj_src</code>, which specifies whether input vector is conjugated or not.
</p>
<p>
For each real/complex function there exists "simple" companion which accepts no stride or conjugation modifier.
"Simple" function assumes that input/output stride is +1, and no input conjugation is required.
</p>
<pre class='p_example'>
alglib::real_1d_array rvec(<span class='s_str'>"[0,1,2,3]"</span>);
alglib::real_2d_array rmat(<span class='s_str'>"[[1,2],[3,4]]"</span>);
alglib::complex_1d_array cvec(<span class='s_str'>"[0+1i,1+2i,2-1i,3-2i]"</span>);
alglib::complex_2d_array cmat(<span class='s_str'>"[[3i,1],[9,2i]]"</span>);
alglib::vmove(&rvec[0], 1, &rmat[0][0], rmat.getstride(), 2); // now rvec is [1,3,2,3]
alglib::vmove(&cvec[0], 1, &cmat[0][0], rmat.getstride(), "No conj", 2); // now cvec is [3i, 9, 2-1i, 3-2i]
alglib::vmove(&cvec[2], 1, &cmat[0][0], 1, "Conj", 2); // now cvec is [3i, 9, -3i, 1]
</pre>
<p>
Here is full list of Level 1 BLAS functions implemented in ALGLIB:
</p>
<pre>
<b>double</b> vdotproduct(
<b>const</b> <b>double</b> *v0,
ae_int_t stride0,
<b>const</b> <b>double</b> *v1,
ae_int_t stride1,
ae_int_t n);
<b>double</b> vdotproduct(
<b>const</b> <b>double</b> *v1,
<b>const</b> <b>double</b> *v2,
ae_int_t N);
alglib::complex vdotproduct(
<b>const</b> alglib::complex *v0,
ae_int_t stride0,
<b>const</b> char *conj0,
<b>const</b> alglib::complex *v1,
ae_int_t stride1,
<b>const</b> char *conj1,
ae_int_t n);
alglib::complex vdotproduct(
<b>const</b> alglib::complex *v1,
<b>const</b> alglib::complex *v2,
ae_int_t N);
<b>void</b> vmove(
<b>double</b> *vdst,
ae_int_t stride_dst,
<b>const</b> <b>double</b>* vsrc,
ae_int_t stride_src,
ae_int_t n);
<b>void</b> vmove(
<b>double</b> *vdst,
<b>const</b> <b>double</b>* vsrc,
ae_int_t N);
<b>void</b> vmove(
alglib::complex *vdst,
ae_int_t stride_dst,
<b>const</b> alglib::complex* vsrc,
ae_int_t stride_src,
<b>const</b> char *conj_src,
ae_int_t n);
<b>void</b> vmove(
alglib::complex *vdst,
<b>const</b> alglib::complex* vsrc,
ae_int_t N);
<b>void</b> vmoveneg(
<b>double</b> *vdst,
ae_int_t stride_dst,
<b>const</b> <b>double</b>* vsrc,
ae_int_t stride_src,
ae_int_t n);
<b>void</b> vmoveneg(
<b>double</b> *vdst,
<b>const</b> <b>double</b> *vsrc,
ae_int_t N);
<b>void</b> vmoveneg(
alglib::complex *vdst,
ae_int_t stride_dst,
<b>const</b> alglib::complex* vsrc,
ae_int_t stride_src,
<b>const</b> char *conj_src,
ae_int_t n);
<b>void</b> vmoveneg(
alglib::complex *vdst,
<b>const</b> alglib::complex *vsrc,
ae_int_t N);
<b>void</b> vmove(
<b>double</b> *vdst,
ae_int_t stride_dst,
<b>const</b> <b>double</b>* vsrc,
ae_int_t stride_src,
ae_int_t n,
<b>double</b> alpha);
<b>void</b> vmove(
<b>double</b> *vdst,
<b>const</b> <b>double</b> *vsrc,
ae_int_t N,
<b>double</b> alpha);
<b>void</b> vmove(
alglib::complex *vdst,
ae_int_t stride_dst,
<b>const</b> alglib::complex* vsrc,
ae_int_t stride_src,
<b>const</b> char *conj_src,
ae_int_t n,
<b>double</b> alpha);
<b>void</b> vmove(
alglib::complex *vdst,
<b>const</b> alglib::complex *vsrc,
ae_int_t N,
<b>double</b> alpha);
<b>void</b> vmove(
alglib::complex *vdst,
ae_int_t stride_dst,
<b>const</b> alglib::complex* vsrc,
ae_int_t stride_src,
<b>const</b> char *conj_src,
ae_int_t n,
alglib::complex alpha);
<b>void</b> vmove(
alglib::complex *vdst,
<b>const</b> alglib::complex *vsrc,
ae_int_t N,
alglib::complex alpha);
<b>void</b> vadd(
<b>double</b> *vdst,
ae_int_t stride_dst,
<b>const</b> <b>double</b> *vsrc,
ae_int_t stride_src,
ae_int_t n);
<b>void</b> vadd(
<b>double</b> *vdst,
<b>const</b> <b>double</b> *vsrc,
ae_int_t N);
<b>void</b> vadd(
alglib::complex *vdst,
ae_int_t stride_dst,
<b>const</b> alglib::complex *vsrc,
ae_int_t stride_src,
<b>const</b> char *conj_src,
ae_int_t n);
<b>void</b> vadd(
alglib::complex *vdst,
<b>const</b> alglib::complex *vsrc,
ae_int_t N);
<b>void</b> vadd(
<b>double</b> *vdst,
ae_int_t stride_dst,
<b>const</b> <b>double</b> *vsrc,
ae_int_t stride_src,
ae_int_t n,
<b>double</b> alpha);
<b>void</b> vadd(
<b>double</b> *vdst,
<b>const</b> <b>double</b> *vsrc,
ae_int_t N,
<b>double</b> alpha);
<b>void</b> vadd(
alglib::complex *vdst,
ae_int_t stride_dst,
<b>const</b> alglib::complex *vsrc,
ae_int_t stride_src,
<b>const</b> char *conj_src,
ae_int_t n,
<b>double</b> alpha);
<b>void</b> vadd(
alglib::complex *vdst,
<b>const</b> alglib::complex *vsrc,
ae_int_t N,
<b>double</b> alpha);
<b>void</b> vadd(
alglib::complex *vdst,
ae_int_t stride_dst,
<b>const</b> alglib::complex *vsrc,
ae_int_t stride_src,
<b>const</b> char *conj_src,
ae_int_t n,
alglib::complex alpha);
<b>void</b> vadd(
alglib::complex *vdst,
<b>const</b> alglib::complex *vsrc,
ae_int_t N,
alglib::complex alpha);
<b>void</b> vsub(
<b>double</b> *vdst,
ae_int_t stride_dst,
<b>const</b> <b>double</b> *vsrc,
ae_int_t stride_src,
ae_int_t n);
<b>void</b> vsub(
<b>double</b> *vdst,
<b>const</b> <b>double</b> *vsrc,
ae_int_t N);
<b>void</b> vsub(
alglib::complex *vdst,
ae_int_t stride_dst,
<b>const</b> alglib::complex *vsrc,
ae_int_t stride_src,
<b>const</b> char *conj_src,
ae_int_t n);
<b>void</b> vsub(
alglib::complex *vdst,
<b>const</b> alglib::complex *vsrc,
ae_int_t N);
<b>void</b> vsub(
<b>double</b> *vdst,
ae_int_t stride_dst,
<b>const</b> <b>double</b> *vsrc,
ae_int_t stride_src,
ae_int_t n,
<b>double</b> alpha);
<b>void</b> vsub(
<b>double</b> *vdst,
<b>const</b> <b>double</b> *vsrc,
ae_int_t N,
<b>double</b> alpha);
<b>void</b> vsub(
alglib::complex *vdst,
ae_int_t stride_dst,
<b>const</b> alglib::complex *vsrc,
ae_int_t stride_src,
<b>const</b> char *conj_src,
ae_int_t n,
<b>double</b> alpha);
<b>void</b> vsub(
alglib::complex *vdst,
<b>const</b> alglib::complex *vsrc,
ae_int_t N,
<b>double</b> alpha);
<b>void</b> vsub(
alglib::complex *vdst,
ae_int_t stride_dst,
<b>const</b> alglib::complex *vsrc,
ae_int_t stride_src,
<b>const</b> char *conj_src,
ae_int_t n,
alglib::complex alpha);
<b>void</b> vsub(
alglib::complex *vdst,
<b>const</b> alglib::complex *vsrc,
ae_int_t N,
alglib::complex alpha);
<b>void</b> vmul(
<b>double</b> *vdst,
ae_int_t stride_dst,
ae_int_t n,
<b>double</b> alpha);
<b>void</b> vmul(
<b>double</b> *vdst,
ae_int_t N,
<b>double</b> alpha);
<b>void</b> vmul(
alglib::complex *vdst,
ae_int_t stride_dst,
ae_int_t n,
<b>double</b> alpha);
<b>void</b> vmul(
alglib::complex *vdst,
ae_int_t N,
<b>double</b> alpha);
<b>void</b> vmul(
alglib::complex *vdst,
ae_int_t stride_dst,
ae_int_t n,
alglib::complex alpha);
<b>void</b> vmul(
alglib::complex *vdst,
ae_int_t N,
alglib::complex alpha);
</pre>
<a name='gs_csv' class='sheader'></a><h2>6.10 Reading data from CSV files</h2>
<p>
ALGLIB (<code>ap.h</code> header) has <code>alglib::read_csv()</code> function
which allows to read data from CSV file.
Entire file is loaded into memory as double precision 2D array (<code>alglib::real_2d_array</code> object).
This function provides following features:
</p>
<ul>
<li>support for ASCI encoding and UTF-8 without BOM (in header names)</li>
<li>ability to use any character (comma/tab/space) as field separator
(as long as it is distinct from one used for decimal point)</li>
<li>ability to use both comma and full stop as decimal point
(as long is decimal point is distinct from field separator).
<li>support for Unix and Windows text files (CR vs CRLF)</li>
</ul>
<p>
See comments on <code>alglib::read_csv()</code> function for more information about its functionality.
</p>
<a name='gs_advanced' class='sheader'></a><h1>7 Advanced topics</h1>
<a name='gs_testing' class='sheader'></a><h2>7.1 Testing ALGLIB</h2>
<p>
There are two test suites in ALGLIB: computational tests and interface tests.
Computational tests are located in <code>/tests/test_c.cpp</code>.
They are focused on numerical properties of algorithms, stress testing and "deep" tests (large automatically generated problems).
They require significant amount of time to finish (tens of minutes).
</p>
<p>
Interface tests are located in <code>/tests/test_i.cpp</code>.
These tests are focused on ability to correctly pass data between computational core and caller, ability to detect simple problems in inputs,
and on ability to at least compile ALGLIB with your compiler.
They are very fast (about a minute to finish including compilation time).
</p>
<p>
Running test suite is easy - just
</p>
<ol>
<li>compile one of these files (<code>test_c.cpp</code> or <code>test_i.cpp</code>) along with the rest of the library</li>
<li>launch executable you will get. It may take from several seconds (interface tests) to several minutes (computational tests) to get final results</li>
</ol>
<p>
If you want to be sure that ALGLIB will work with some sophisticated optimization settings, set corresponding flags during compile time.
If your compiler/system are not in the list of supported ones, we recommend you to run both test suites. But if you are running out of time, run at least <code>test_i.cpp</code>.
</p>
</div>
<a name='alglib_main' class='sheader'></a><h1>8 ALGLIB packages and subpackages</h1>
<table border=0 cellspacing=0>
<tr align=left valign=top><td colspan=3 bgcolor=#E8E8E8>
<a name='pck_AlglibMisc' class='sheader'></a><h2>8.1 <code>AlglibMisc</code> package</h2>
</td></tr>
<tr align=left valign=top><td><a href='#unit_hqrnd' class=toc>hqrnd</a></td><td width=15> </td><td>High quality random numbers generator</td></tr>
<tr align=left valign=top><td><a href='#unit_nearestneighbor' class=toc>nearestneighbor</a></td><td width=15> </td><td>Nearest neighbor search: approximate and exact</td></tr>
<tr align=left valign=top><td><a href='#unit_xdebug' class=toc>xdebug</a></td><td width=15> </td><td>Debug functions to test ALGLIB interface generator </td></tr>
<tr align=left valign=top><td colspan=2> </td></tr>
<tr align=left valign=top><td colspan=3 bgcolor=#E8E8E8>
<a name='pck_DataAnalysis' class='sheader'></a><h2>8.2 <code>DataAnalysis</code> package</h2>
</td></tr>
<tr align=left valign=top><td><a href='#unit_bdss' class=toc>bdss</a></td><td width=15> </td><td>Basic dataset functions</td></tr>
<tr align=left valign=top><td><a href='#unit_clustering' class=toc>clustering</a></td><td width=15> </td><td>Clustering functions (hierarchical, k-means, k-means++)</td></tr>
<tr align=left valign=top><td><a href='#unit_datacomp' class=toc>datacomp</a></td><td width=15> </td><td>Backward compatibility functions</td></tr>
<tr align=left valign=top><td><a href='#unit_dforest' class=toc>dforest</a></td><td width=15> </td><td>Decision forest classifier (regression model)</td></tr>
<tr align=left valign=top><td><a href='#unit_filters' class=toc>filters</a></td><td width=15> </td><td>Different filters used in data analysis</td></tr>
<tr align=left valign=top><td><a href='#unit_lda' class=toc>lda</a></td><td width=15> </td><td>Linear discriminant analysis</td></tr>
<tr align=left valign=top><td><a href='#unit_linreg' class=toc>linreg</a></td><td width=15> </td><td>Linear models</td></tr>
<tr align=left valign=top><td><a href='#unit_logit' class=toc>logit</a></td><td width=15> </td><td>Logit models</td></tr>
<tr align=left valign=top><td><a href='#unit_mcpd' class=toc>mcpd</a></td><td width=15> </td><td>Markov Chains for Population/proportional Data</td></tr>
<tr align=left valign=top><td><a href='#unit_mlpbase' class=toc>mlpbase</a></td><td width=15> </td><td>Basic functions for neural networks</td></tr>
<tr align=left valign=top><td><a href='#unit_mlpe' class=toc>mlpe</a></td><td width=15> </td><td>Basic functions for neural ensemble models</td></tr>
<tr align=left valign=top><td><a href='#unit_mlptrain' class=toc>mlptrain</a></td><td width=15> </td><td>Neural network training</td></tr>
<tr align=left valign=top><td><a href='#unit_pca' class=toc>pca</a></td><td width=15> </td><td>Principal component analysis</td></tr>
<tr align=left valign=top><td colspan=2> </td></tr>
<tr align=left valign=top><td colspan=3 bgcolor=#E8E8E8>
<a name='pck_DiffEquations' class='sheader'></a><h2>8.3 <code>DiffEquations</code> package</h2>
</td></tr>
<tr align=left valign=top><td><a href='#unit_odesolver' class=toc>odesolver</a></td><td width=15> </td><td>Ordinary differential equation solver</td></tr>
<tr align=left valign=top><td colspan=2> </td></tr>
<tr align=left valign=top><td colspan=3 bgcolor=#E8E8E8>
<a name='pck_FastTransforms' class='sheader'></a><h2>8.4 <code>FastTransforms</code> package</h2>
</td></tr>
<tr align=left valign=top><td><a href='#unit_conv' class=toc>conv</a></td><td width=15> </td><td>Fast real/complex convolution</td></tr>
<tr align=left valign=top><td><a href='#unit_corr' class=toc>corr</a></td><td width=15> </td><td>Fast real/complex cross-correlation</td></tr>
<tr align=left valign=top><td><a href='#unit_fft' class=toc>fft</a></td><td width=15> </td><td>Real/complex FFT</td></tr>
<tr align=left valign=top><td><a href='#unit_fht' class=toc>fht</a></td><td width=15> </td><td>Real Fast Hartley Transform</td></tr>
<tr align=left valign=top><td colspan=2> </td></tr>
<tr align=left valign=top><td colspan=3 bgcolor=#E8E8E8>
<a name='pck_Integration' class='sheader'></a><h2>8.5 <code>Integration</code> package</h2>
</td></tr>
<tr align=left valign=top><td><a href='#unit_autogk' class=toc>autogk</a></td><td width=15> </td><td>Adaptive 1-dimensional integration</td></tr>
<tr align=left valign=top><td><a href='#unit_gkq' class=toc>gkq</a></td><td width=15> </td><td>Gauss-Kronrod quadrature generator</td></tr>
<tr align=left valign=top><td><a href='#unit_gq' class=toc>gq</a></td><td width=15> </td><td>Gaussian quadrature generator</td></tr>
<tr align=left valign=top><td colspan=2> </td></tr>
<tr align=left valign=top><td colspan=3 bgcolor=#E8E8E8>
<a name='pck_Interpolation' class='sheader'></a><h2>8.6 <code>Interpolation</code> package</h2>
</td></tr>
<tr align=left valign=top><td><a href='#unit_idwint' class=toc>idwint</a></td><td width=15> </td><td>Inverse distance weighting: interpolation/fitting</td></tr>
<tr align=left valign=top><td><a href='#unit_lsfit' class=toc>lsfit</a></td><td width=15> </td><td>Linear and nonlinear least-squares solvers</td></tr>
<tr align=left valign=top><td><a href='#unit_parametric' class=toc>parametric</a></td><td width=15> </td><td>Parametric curves</td></tr>
<tr align=left valign=top><td><a href='#unit_polint' class=toc>polint</a></td><td width=15> </td><td>Polynomial interpolation/fitting</td></tr>
<tr align=left valign=top><td><a href='#unit_ratint' class=toc>ratint</a></td><td width=15> </td><td>Rational interpolation/fitting</td></tr>
<tr align=left valign=top><td><a href='#unit_rbf' class=toc>rbf</a></td><td width=15> </td><td>Scattered 2/3-dimensional interpolation with RBF models</td></tr>
<tr align=left valign=top><td><a href='#unit_spline1d' class=toc>spline1d</a></td><td width=15> </td><td>1D spline interpolation/fitting</td></tr>
<tr align=left valign=top><td><a href='#unit_spline2d' class=toc>spline2d</a></td><td width=15> </td><td>2D spline interpolation</td></tr>
<tr align=left valign=top><td><a href='#unit_spline3d' class=toc>spline3d</a></td><td width=15> </td><td>3D spline interpolation</td></tr>
<tr align=left valign=top><td colspan=2> </td></tr>
<tr align=left valign=top><td colspan=3 bgcolor=#E8E8E8>
<a name='pck_LinAlg' class='sheader'></a><h2>8.7 <code>LinAlg</code> package</h2>
</td></tr>
<tr align=left valign=top><td><a href='#unit_ablas' class=toc>ablas</a></td><td width=15> </td><td>Level 2 and Level 3 BLAS operations</td></tr>
<tr align=left valign=top><td><a href='#unit_bdsvd' class=toc>bdsvd</a></td><td width=15> </td><td>Bidiagonal SVD</td></tr>
<tr align=left valign=top><td><a href='#unit_evd' class=toc>evd</a></td><td width=15> </td><td>Eigensolvers</td></tr>
<tr align=left valign=top><td><a href='#unit_inverseupdate' class=toc>inverseupdate</a></td><td width=15> </td><td>Sherman-Morrison update of the inverse matrix</td></tr>
<tr align=left valign=top><td><a href='#unit_matdet' class=toc>matdet</a></td><td width=15> </td><td>Determinant calculation</td></tr>
<tr align=left valign=top><td><a href='#unit_matgen' class=toc>matgen</a></td><td width=15> </td><td>Random matrix generation</td></tr>
<tr align=left valign=top><td><a href='#unit_matinv' class=toc>matinv</a></td><td width=15> </td><td>Matrix inverse</td></tr>
<tr align=left valign=top><td><a href='#unit_normestimator' class=toc>normestimator</a></td><td width=15> </td><td>Estimates norm of the sparse matrix (from below)</td></tr>
<tr align=left valign=top><td><a href='#unit_ortfac' class=toc>ortfac</a></td><td width=15> </td><td>Real/complex QR/LQ, bi(tri)diagonal, Hessenberg decompositions</td></tr>
<tr align=left valign=top><td><a href='#unit_rcond' class=toc>rcond</a></td><td width=15> </td><td>Condition number estimate</td></tr>
<tr align=left valign=top><td><a href='#unit_schur' class=toc>schur</a></td><td width=15> </td><td>Schur decomposition</td></tr>
<tr align=left valign=top><td><a href='#unit_sparse' class=toc>sparse</a></td><td width=15> </td><td>Sparse matrices</td></tr>
<tr align=left valign=top><td><a href='#unit_spdgevd' class=toc>spdgevd</a></td><td width=15> </td><td>Generalized symmetric eigensolver</td></tr>
<tr align=left valign=top><td><a href='#unit_svd' class=toc>svd</a></td><td width=15> </td><td>Singular value decomposition</td></tr>
<tr align=left valign=top><td><a href='#unit_trfac' class=toc>trfac</a></td><td width=15> </td><td>LU and Cholesky decompositions (dense and sparse)</td></tr>
<tr align=left valign=top><td colspan=2> </td></tr>
<tr align=left valign=top><td colspan=3 bgcolor=#E8E8E8>
<a name='pck_Optimization' class='sheader'></a><h2>8.8 <code>Optimization</code> package</h2>
</td></tr>
<tr align=left valign=top><td><a href='#unit_minbleic' class=toc>minbleic</a></td><td width=15> </td><td>Bound constrained optimizer with additional linear equality/inequality constraints </td></tr>
<tr align=left valign=top><td><a href='#unit_mincg' class=toc>mincg</a></td><td width=15> </td><td>Conjugate gradient optimizer</td></tr>
<tr align=left valign=top><td><a href='#unit_mincomp' class=toc>mincomp</a></td><td width=15> </td><td>Backward compatibility functions</td></tr>
<tr align=left valign=top><td><a href='#unit_minlbfgs' class=toc>minlbfgs</a></td><td width=15> </td><td>Limited memory BFGS optimizer</td></tr>
<tr align=left valign=top><td><a href='#unit_minlm' class=toc>minlm</a></td><td width=15> </td><td>Improved Levenberg-Marquardt optimizer</td></tr>
<tr align=left valign=top><td><a href='#unit_minnlc' class=toc>minnlc</a></td><td width=15> </td><td>Nonlinearly constrained optimizer </td></tr>
<tr align=left valign=top><td><a href='#unit_minns' class=toc>minns</a></td><td width=15> </td><td>Nonsmooth constrained optimizer </td></tr>
<tr align=left valign=top><td><a href='#unit_minqp' class=toc>minqp</a></td><td width=15> </td><td>Quadratic programming with bound and linear equality/inequality constraints </td></tr>
<tr align=left valign=top><td colspan=2> </td></tr>
<tr align=left valign=top><td colspan=3 bgcolor=#E8E8E8>
<a name='pck_Solvers' class='sheader'></a><h2>8.9 <code>Solvers</code> package</h2>
</td></tr>
<tr align=left valign=top><td><a href='#unit_densesolver' class=toc>densesolver</a></td><td width=15> </td><td>Dense linear system solver</td></tr>
<tr align=left valign=top><td><a href='#unit_lincg' class=toc>lincg</a></td><td width=15> </td><td>Sparse linear CG solver</td></tr>
<tr align=left valign=top><td><a href='#unit_linlsqr' class=toc>linlsqr</a></td><td width=15> </td><td>Sparse linear LSQR solver</td></tr>
<tr align=left valign=top><td><a href='#unit_nleq' class=toc>nleq</a></td><td width=15> </td><td>Solvers for nonlinear equations</td></tr>
<tr align=left valign=top><td><a href='#unit_polynomialsolver' class=toc>polynomialsolver</a></td><td width=15> </td><td>Polynomial solver</td></tr>
<tr align=left valign=top><td colspan=2> </td></tr>
<tr align=left valign=top><td colspan=3 bgcolor=#E8E8E8>
<a name='pck_SpecialFunctions' class='sheader'></a><h2>8.10 <code>SpecialFunctions</code> package</h2>
</td></tr>
<tr align=left valign=top><td><a href='#unit_airyf' class=toc>airyf</a></td><td width=15> </td><td>Airy functions</td></tr>
<tr align=left valign=top><td><a href='#unit_bessel' class=toc>bessel</a></td><td width=15> </td><td>Bessel functions</td></tr>
<tr align=left valign=top><td><a href='#unit_betaf' class=toc>betaf</a></td><td width=15> </td><td>Beta function</td></tr>
<tr align=left valign=top><td><a href='#unit_binomialdistr' class=toc>binomialdistr</a></td><td width=15> </td><td>Binomial distribution</td></tr>
<tr align=left valign=top><td><a href='#unit_chebyshev' class=toc>chebyshev</a></td><td width=15> </td><td>Chebyshev polynomials</td></tr>
<tr align=left valign=top><td><a href='#unit_chisquaredistr' class=toc>chisquaredistr</a></td><td width=15> </td><td>Chi-Square distribution</td></tr>
<tr align=left valign=top><td><a href='#unit_dawson' class=toc>dawson</a></td><td width=15> </td><td>Dawson integral</td></tr>
<tr align=left valign=top><td><a href='#unit_elliptic' class=toc>elliptic</a></td><td width=15> </td><td>Elliptic integrals</td></tr>
<tr align=left valign=top><td><a href='#unit_expintegrals' class=toc>expintegrals</a></td><td width=15> </td><td>Exponential integrals</td></tr>
<tr align=left valign=top><td><a href='#unit_fdistr' class=toc>fdistr</a></td><td width=15> </td><td>F-distribution</td></tr>
<tr align=left valign=top><td><a href='#unit_fresnel' class=toc>fresnel</a></td><td width=15> </td><td>Fresnel integrals</td></tr>
<tr align=left valign=top><td><a href='#unit_gammafunc' class=toc>gammafunc</a></td><td width=15> </td><td>Gamma function</td></tr>
<tr align=left valign=top><td><a href='#unit_hermite' class=toc>hermite</a></td><td width=15> </td><td>Hermite polynomials</td></tr>
<tr align=left valign=top><td><a href='#unit_ibetaf' class=toc>ibetaf</a></td><td width=15> </td><td>Incomplete beta function</td></tr>
<tr align=left valign=top><td><a href='#unit_igammaf' class=toc>igammaf</a></td><td width=15> </td><td>Incomplete gamma function</td></tr>
<tr align=left valign=top><td><a href='#unit_jacobianelliptic' class=toc>jacobianelliptic</a></td><td width=15> </td><td>Jacobian elliptic functions</td></tr>
<tr align=left valign=top><td><a href='#unit_laguerre' class=toc>laguerre</a></td><td width=15> </td><td>Laguerre polynomials</td></tr>
<tr align=left valign=top><td><a href='#unit_legendre' class=toc>legendre</a></td><td width=15> </td><td>Legendre polynomials</td></tr>
<tr align=left valign=top><td><a href='#unit_normaldistr' class=toc>normaldistr</a></td><td width=15> </td><td>Normal distribution</td></tr>
<tr align=left valign=top><td><a href='#unit_poissondistr' class=toc>poissondistr</a></td><td width=15> </td><td>Poisson distribution</td></tr>
<tr align=left valign=top><td><a href='#unit_psif' class=toc>psif</a></td><td width=15> </td><td>Psi function</td></tr>
<tr align=left valign=top><td><a href='#unit_studenttdistr' class=toc>studenttdistr</a></td><td width=15> </td><td>Student's t-distribution</td></tr>
<tr align=left valign=top><td><a href='#unit_trigintegrals' class=toc>trigintegrals</a></td><td width=15> </td><td>Trigonometric integrals</td></tr>
<tr align=left valign=top><td colspan=2> </td></tr>
<tr align=left valign=top><td colspan=3 bgcolor=#E8E8E8>
<a name='pck_Statistics' class='sheader'></a><h2>8.11 <code>Statistics</code> package</h2>
</td></tr>
<tr align=left valign=top><td><a href='#unit_basestat' class=toc>basestat</a></td><td width=15> </td><td>Mean, variance, covariance, correlation, etc.</td></tr>
<tr align=left valign=top><td><a href='#unit_correlationtests' class=toc>correlationtests</a></td><td width=15> </td><td>Hypothesis testing: correlation tests</td></tr>
<tr align=left valign=top><td><a href='#unit_jarquebera' class=toc>jarquebera</a></td><td width=15> </td><td>Hypothesis testing: Jarque-Bera test</td></tr>
<tr align=left valign=top><td><a href='#unit_mannwhitneyu' class=toc>mannwhitneyu</a></td><td width=15> </td><td>Hypothesis testing: Mann-Whitney-U test</td></tr>
<tr align=left valign=top><td><a href='#unit_stest' class=toc>stest</a></td><td width=15> </td><td>Hypothesis testing: sign test</td></tr>
<tr align=left valign=top><td><a href='#unit_studentttests' class=toc>studentttests</a></td><td width=15> </td><td>Hypothesis testing: Student's t-test</td></tr>
<tr align=left valign=top><td><a href='#unit_variancetests' class=toc>variancetests</a></td><td width=15> </td><td>Hypothesis testing: F-test and one-sample variance test</td></tr>
<tr align=left valign=top><td><a href='#unit_wsr' class=toc>wsr</a></td><td width=15> </td><td>Hypothesis testing: Wilcoxon signed rank test</td></tr>
<tr align=left valign=top><td colspan=2> </td></tr>
</table>
<a name=unit_ablas></a><h2 class=pageheader><code>ablas</code> subpackage</h2>
<div class=pagecontent>
<h3 class=pageheader>Functions</h3>
<a href='#sub_cmatrixcopy' class=toc>cmatrixcopy</a><br>
<a href='#sub_cmatrixgemm' class=toc>cmatrixgemm</a><br>
<a href='#sub_cmatrixherk' class=toc>cmatrixherk</a><br>
<a href='#sub_cmatrixlefttrsm' class=toc>cmatrixlefttrsm</a><br>
<a href='#sub_cmatrixmv' class=toc>cmatrixmv</a><br>
<a href='#sub_cmatrixrank1' class=toc>cmatrixrank1</a><br>
<a href='#sub_cmatrixrighttrsm' class=toc>cmatrixrighttrsm</a><br>
<a href='#sub_cmatrixsyrk' class=toc>cmatrixsyrk</a><br>
<a href='#sub_cmatrixtranspose' class=toc>cmatrixtranspose</a><br>
<a href='#sub_rmatrixcopy' class=toc>rmatrixcopy</a><br>
<a href='#sub_rmatrixenforcesymmetricity' class=toc>rmatrixenforcesymmetricity</a><br>
<a href='#sub_rmatrixgemm' class=toc>rmatrixgemm</a><br>
<a href='#sub_rmatrixlefttrsm' class=toc>rmatrixlefttrsm</a><br>
<a href='#sub_rmatrixmv' class=toc>rmatrixmv</a><br>
<a href='#sub_rmatrixrank1' class=toc>rmatrixrank1</a><br>
<a href='#sub_rmatrixrighttrsm' class=toc>rmatrixrighttrsm</a><br>
<a href='#sub_rmatrixsyrk' class=toc>rmatrixsyrk</a><br>
<a href='#sub_rmatrixtranspose' class=toc>rmatrixtranspose</a><br>
<h3 class=pageheader>Examples</h3>
<table border=0 cellspacing=0 class='pagecontent'>
<tr align=left valign=top><td><a href='#example_ablas_d_gemm' class=toc>ablas_d_gemm</a></td><td width=15> </td><td>Matrix multiplication (single-threaded)</td></tr>
<tr align=left valign=top><td><a href='#example_ablas_d_syrk' class=toc>ablas_d_syrk</a></td><td width=15> </td><td>Symmetric rank-K update (single-threaded)</td></tr>
<tr align=left valign=top><td><a href='#example_ablas_smp_gemm' class=toc>ablas_smp_gemm</a></td><td width=15> </td><td>Matrix multiplication (multithreaded)</td></tr>
<tr align=left valign=top><td><a href='#example_ablas_smp_syrk' class=toc>ablas_smp_syrk</a></td><td width=15> </td><td>Symmetric rank-K update (multithreaded)</td></tr>
</table></div>
<a name='sub_cmatrixcopy'></a><h3 class=pageheader><code>cmatrixcopy</code> function</h3>
<pre class=source>
<div style='color: navy; margin-top: 0; margin-bottom: 0;'>/*************************************************************************
Copy
Input parameters:
M - number of rows
N - number of columns
A - source matrix, MxN submatrix is copied and transposed
IA - submatrix offset (row index)
JA - submatrix offset (column index)
B - destination matrix, must be large enough to store result
IB - submatrix offset (row index)
JB - submatrix offset (column index)
*************************************************************************/
</div><div style='margin-top: 0; margin-bottom: 0;'><b>void</b> alglib::cmatrixcopy(
ae_int_t m,
ae_int_t n,
complex_2d_array a,
ae_int_t ia,
ae_int_t ja,
complex_2d_array& b,
ae_int_t ib,
ae_int_t jb);
</div></pre>
<a name='sub_cmatrixgemm'></a><h3 class=pageheader><code>cmatrixgemm</code> function</h3>
<pre class=source>
<div style='color: navy; margin-top: 0; margin-bottom: 0;'>/*************************************************************************
This subroutine calculates C = alpha*op1(A)*op2(B) +beta*C where:
* C is MxN general matrix
* op1(A) is MxK matrix
* op2(B) is KxN matrix
* "op" may be identity transformation, transposition, conjugate transposition
Additional info:
* cache-oblivious algorithm is used.
* multiplication result replaces C. If Beta=0, C elements are not used in
calculations (not multiplied by zero - just not referenced)
* if Alpha=0, A is not used (not multiplied by zero - just not referenced)
* if both Beta and Alpha are zero, C is filled by zeros.
COMMERCIAL EDITION OF ALGLIB:
! Commercial version of ALGLIB includes two important improvements of
! this function, which can be used from C++ and C#:
! * Intel MKL support (lightweight Intel MKL is shipped with ALGLIB)
! * multicore support
!
! Intel MKL gives approximately constant (with respect to number of
! worker threads) acceleration factor which depends on CPU being used,
! problem size and "baseline" ALGLIB edition which is used for
! comparison.
!
! Say, on SSE2-capable CPU with N=1024, HPC ALGLIB will be:
! * about 2-3x faster than ALGLIB for C++ without MKL
! * about 7-10x faster than "pure C#" edition of ALGLIB
! Difference in performance will be more striking on newer CPU's with
! support for newer SIMD instructions.
!
! Commercial edition of ALGLIB also supports multithreaded acceleration
! of this function. Because starting/stopping worker thread always
! involves some overhead, parallelism starts to be profitable for N's
! larger than 128.
!
! In order to use multicore features you have to:
! * use commercial version of ALGLIB
! * call this function with "smp_" prefix, which indicates that
! multicore code will be used (for multicore support)
!
! We recommend you to read 'Working with commercial version' section of
! ALGLIB Reference Manual in order to find out how to use performance-
! related features provided by commercial edition of ALGLIB.
IMPORTANT:
This function does NOT preallocate output matrix C, it MUST be preallocated
by caller prior to calling this function. In case C does not have enough
space to store result, exception will be generated.
INPUT PARAMETERS
M - matrix size, M>0
N - matrix size, N>0
K - matrix size, K>0
Alpha - coefficient
A - matrix
IA - submatrix offset
JA - submatrix offset
OpTypeA - transformation type:
* 0 - no transformation
* 1 - transposition
* 2 - conjugate transposition
B - matrix
IB - submatrix offset
JB - submatrix offset
OpTypeB - transformation type:
* 0 - no transformation
* 1 - transposition
* 2 - conjugate transposition
Beta - coefficient
C - matrix (PREALLOCATED, large enough to store result)
IC - submatrix offset
JC - submatrix offset
-- ALGLIB routine --
16.12.2009
Bochkanov Sergey
*************************************************************************/
</div><div style='margin-top: 0; margin-bottom: 0;'><b>void</b> alglib::cmatrixgemm(
ae_int_t m,
ae_int_t n,
ae_int_t k,
alglib::complex alpha,
complex_2d_array a,
ae_int_t ia,
ae_int_t ja,
ae_int_t optypea,
complex_2d_array b,
ae_int_t ib,
ae_int_t jb,
ae_int_t optypeb,
alglib::complex beta,
complex_2d_array& c,
ae_int_t ic,
ae_int_t jc);
<b>void</b> alglib::smp_cmatrixgemm(
ae_int_t m,
ae_int_t n,
ae_int_t k,
alglib::smp_complex alpha,
complex_2d_array a,
ae_int_t ia,
ae_int_t ja,
ae_int_t optypea,
complex_2d_array b,
ae_int_t ib,
ae_int_t jb,
ae_int_t optypeb,
alglib::smp_complex beta,
complex_2d_array& c,
ae_int_t ic,
ae_int_t jc);
</div></pre>
<p align=left class=pagecontent><span class=inlineheader>Examples:</span> <a href='#example_ablas_d_gemm' class=nav>[1]</a> <a href='#example_ablas_smp_gemm' class=nav>[2]</a> </p>
<a name='sub_cmatrixherk'></a><h3 class=pageheader><code>cmatrixherk</code> function</h3>
<pre class=source>
<div style='color: navy; margin-top: 0; margin-bottom: 0;'>/*************************************************************************
This subroutine calculates C=alpha*A*A^H+beta*C or C=alpha*A^H*A+beta*C
where:
* C is NxN Hermitian matrix given by its upper/lower triangle
* A is NxK matrix when A*A^H is calculated, KxN matrix otherwise
Additional info:
* cache-oblivious algorithm is used.
* multiplication result replaces C. If Beta=0, C elements are not used in
calculations (not multiplied by zero - just not referenced)
* if Alpha=0, A is not used (not multiplied by zero - just not referenced)
* if both Beta and Alpha are zero, C is filled by zeros.
COMMERCIAL EDITION OF ALGLIB:
! Commercial version of ALGLIB includes two important improvements of
! this function, which can be used from C++ and C#:
! * Intel MKL support (lightweight Intel MKL is shipped with ALGLIB)
! * multicore support
!
! Intel MKL gives approximately constant (with respect to number of
! worker threads) acceleration factor which depends on CPU being used,
! problem size and "baseline" ALGLIB edition which is used for
! comparison.
!
! Say, on SSE2-capable CPU with N=1024, HPC ALGLIB will be:
! * about 2-3x faster than ALGLIB for C++ without MKL
! * about 7-10x faster than "pure C#" edition of ALGLIB
! Difference in performance will be more striking on newer CPU's with
! support for newer SIMD instructions.
!
! Commercial edition of ALGLIB also supports multithreaded acceleration
! of this function. Because starting/stopping worker thread always
! involves some overhead, parallelism starts to be profitable for N's
! larger than 128.
!
! In order to use multicore features you have to:
! * use commercial version of ALGLIB
! * call this function with "smp_" prefix, which indicates that
! multicore code will be used (for multicore support)
!
! We recommend you to read 'Working with commercial version' section of
! ALGLIB Reference Manual in order to find out how to use performance-
! related features provided by commercial edition of ALGLIB.
INPUT PARAMETERS
N - matrix size, N>=0
K - matrix size, K>=0
Alpha - coefficient
A - matrix
IA - submatrix offset (row index)
JA - submatrix offset (column index)
OpTypeA - multiplication type:
* 0 - A*A^H is calculated
* 2 - A^H*A is calculated
Beta - coefficient
C - preallocated input/output matrix
IC - submatrix offset (row index)
JC - submatrix offset (column index)
IsUpper - whether upper or lower triangle of C is updated;
this function updates only one half of C, leaving
other half unchanged (not referenced at all).
-- ALGLIB routine --
16.12.2009
Bochkanov Sergey
*************************************************************************/
</div><div style='margin-top: 0; margin-bottom: 0;'><b>void</b> alglib::cmatrixherk(
ae_int_t n,
ae_int_t k,
<b>double</b> alpha,
complex_2d_array a,
ae_int_t ia,
ae_int_t ja,
ae_int_t optypea,
<b>double</b> beta,
complex_2d_array& c,
ae_int_t ic,
ae_int_t jc,
<b>bool</b> isupper);
<b>void</b> alglib::smp_cmatrixherk(
ae_int_t n,
ae_int_t k,
<b>double</b> alpha,
complex_2d_array a,
ae_int_t ia,
ae_int_t ja,
ae_int_t optypea,
<b>double</b> beta,
complex_2d_array& c,
ae_int_t ic,
ae_int_t jc,
<b>bool</b> isupper);
</div></pre>
<p align=left class=pagecontent><span class=inlineheader>Examples:</span> <a href='#example_ablas_d_syrk' class=nav>[1]</a> <a href='#example_ablas_smp_syrk' class=nav>[2]</a> </p>
<a name='sub_cmatrixlefttrsm'></a><h3 class=pageheader><code>cmatrixlefttrsm</code> function</h3>
<pre class=source>
<div style='color: navy; margin-top: 0; margin-bottom: 0;'>/*************************************************************************
This subroutine calculates op(A^-1)*X where:
* X is MxN general matrix
* A is MxM upper/lower triangular/unitriangular matrix
* "op" may be identity transformation, transposition, conjugate transposition
Multiplication result replaces X.
Cache-oblivious algorithm is used.
COMMERCIAL EDITION OF ALGLIB:
! Commercial version of ALGLIB includes two important improvements of
! this function, which can be used from C++ and C#:
! * Intel MKL support (lightweight Intel MKL is shipped with ALGLIB)
! * multicore support
!
! Intel MKL gives approximately constant (with respect to number of
! worker threads) acceleration factor which depends on CPU being used,
! problem size and "baseline" ALGLIB edition which is used for
! comparison.
!
! Say, on SSE2-capable CPU with N=1024, HPC ALGLIB will be:
! * about 2-3x faster than ALGLIB for C++ without MKL
! * about 7-10x faster than "pure C#" edition of ALGLIB
! Difference in performance will be more striking on newer CPU's with
! support for newer SIMD instructions.
!
! Commercial edition of ALGLIB also supports multithreaded acceleration
! of this function. Because starting/stopping worker thread always
! involves some overhead, parallelism starts to be profitable for N's
! larger than 128.
!
! In order to use multicore features you have to:
! * use commercial version of ALGLIB
! * call this function with "smp_" prefix, which indicates that
! multicore code will be used (for multicore support)
!
! We recommend you to read 'Working with commercial version' section of
! ALGLIB Reference Manual in order to find out how to use performance-
! related features provided by commercial edition of ALGLIB.
INPUT PARAMETERS
N - matrix size, N>=0
M - matrix size, N>=0
A - matrix, actial matrix is stored in A[I1:I1+M-1,J1:J1+M-1]
I1 - submatrix offset
J1 - submatrix offset
IsUpper - whether matrix is upper triangular
IsUnit - whether matrix is unitriangular
OpType - transformation type:
* 0 - no transformation
* 1 - transposition
* 2 - conjugate transposition
X - matrix, actial matrix is stored in X[I2:I2+M-1,J2:J2+N-1]
I2 - submatrix offset
J2 - submatrix offset
-- ALGLIB routine --
15.12.2009
Bochkanov Sergey
*************************************************************************/
</div><div style='margin-top: 0; margin-bottom: 0;'><b>void</b> alglib::cmatrixlefttrsm(
ae_int_t m,
ae_int_t n,
complex_2d_array a,
ae_int_t i1,
ae_int_t j1,
<b>bool</b> isupper,
<b>bool</b> isunit,
ae_int_t optype,
complex_2d_array& x,
ae_int_t i2,
ae_int_t j2);
<b>void</b> alglib::smp_cmatrixlefttrsm(
ae_int_t m,
ae_int_t n,
complex_2d_array a,
ae_int_t i1,
ae_int_t j1,
<b>bool</b> isupper,
<b>bool</b> isunit,
ae_int_t optype,
complex_2d_array& x,
ae_int_t i2,
ae_int_t j2);
</div></pre>
<a name='sub_cmatrixmv'></a><h3 class=pageheader><code>cmatrixmv</code> function</h3>
<pre class=source>
<div style='color: navy; margin-top: 0; margin-bottom: 0;'>/*************************************************************************
Matrix-vector product: y := op(A)*x
INPUT PARAMETERS:
M - number of rows of op(A)
M>=0
N - number of columns of op(A)
N>=0
A - target matrix
IA - submatrix offset (row index)
JA - submatrix offset (column index)
OpA - operation type:
* OpA=0 => op(A) = A
* OpA=1 => op(A) = A^T
* OpA=2 => op(A) = A^H
X - input vector
IX - subvector offset
IY - subvector offset
Y - preallocated matrix, must be large enough to store result
OUTPUT PARAMETERS:
Y - vector which stores result
if M=0, then subroutine does nothing.
if N=0, Y is filled by zeros.
-- ALGLIB routine --
28.01.2010
Bochkanov Sergey
*************************************************************************/
</div><div style='margin-top: 0; margin-bottom: 0;'><b>void</b> alglib::cmatrixmv(
ae_int_t m,
ae_int_t n,
complex_2d_array a,
ae_int_t ia,
ae_int_t ja,
ae_int_t opa,
complex_1d_array x,
ae_int_t ix,
complex_1d_array& y,
ae_int_t iy);
</div></pre>
<a name='sub_cmatrixrank1'></a><h3 class=pageheader><code>cmatrixrank1</code> function</h3>
<pre class=source>
<div style='color: navy; margin-top: 0; margin-bottom: 0;'>/*************************************************************************
Rank-1 correction: A := A + u*v'
INPUT PARAMETERS:
M - number of rows
N - number of columns
A - target matrix, MxN submatrix is updated
IA - submatrix offset (row index)
JA - submatrix offset (column index)
U - vector #1
IU - subvector offset
V - vector #2
IV - subvector offset
*************************************************************************/
</div><div style='margin-top: 0; margin-bottom: 0;'><b>void</b> alglib::cmatrixrank1(
ae_int_t m,
ae_int_t n,
complex_2d_array& a,
ae_int_t ia,
ae_int_t ja,
complex_1d_array& u,
ae_int_t iu,
complex_1d_array& v,
ae_int_t iv);
</div></pre>
<a name='sub_cmatrixrighttrsm'></a><h3 class=pageheader><code>cmatrixrighttrsm</code> function</h3>
<pre class=source>
<div style='color: navy; margin-top: 0; margin-bottom: 0;'>/*************************************************************************
This subroutine calculates X*op(A^-1) where:
* X is MxN general matrix
* A is NxN upper/lower triangular/unitriangular matrix
* "op" may be identity transformation, transposition, conjugate transposition
Multiplication result replaces X.
Cache-oblivious algorithm is used.
COMMERCIAL EDITION OF ALGLIB:
! Commercial version of ALGLIB includes two important improvements of
! this function, which can be used from C++ and C#:
! * Intel MKL support (lightweight Intel MKL is shipped with ALGLIB)
! * multicore support
!
! Intel MKL gives approximately constant (with respect to number of
! worker threads) acceleration factor which depends on CPU being used,
! problem size and "baseline" ALGLIB edition which is used for
! comparison.
!
! Say, on SSE2-capable CPU with N=1024, HPC ALGLIB will be:
! * about 2-3x faster than ALGLIB for C++ without MKL
! * about 7-10x faster than "pure C#" edition of ALGLIB
! Difference in performance will be more striking on newer CPU's with
! support for newer SIMD instructions.
!
! Commercial edition of ALGLIB also supports multithreaded acceleration
! of this function. Because starting/stopping worker thread always
! involves some overhead, parallelism starts to be profitable for N's
! larger than 128.
!
! In order to use multicore features you have to:
! * use commercial version of ALGLIB
! * call this function with "smp_" prefix, which indicates that
! multicore code will be used (for multicore support)
!
! We recommend you to read 'Working with commercial version' section of
! ALGLIB Reference Manual in order to find out how to use performance-
! related features provided by commercial edition of ALGLIB.
INPUT PARAMETERS
N - matrix size, N>=0
M - matrix size, N>=0
A - matrix, actial matrix is stored in A[I1:I1+N-1,J1:J1+N-1]
I1 - submatrix offset
J1 - submatrix offset
IsUpper - whether matrix is upper triangular
IsUnit - whether matrix is unitriangular
OpType - transformation type:
* 0 - no transformation
* 1 - transposition
* 2 - conjugate transposition
X - matrix, actial matrix is stored in X[I2:I2+M-1,J2:J2+N-1]
I2 - submatrix offset
J2 - submatrix offset
-- ALGLIB routine --
15.12.2009
Bochkanov Sergey
*************************************************************************/
</div><div style='margin-top: 0; margin-bottom: 0;'><b>void</b> alglib::cmatrixrighttrsm(
ae_int_t m,
ae_int_t n,
complex_2d_array a,
ae_int_t i1,
ae_int_t j1,
<b>bool</b> isupper,
<b>bool</b> isunit,
ae_int_t optype,
complex_2d_array& x,
ae_int_t i2,
ae_int_t j2);
<b>void</b> alglib::smp_cmatrixrighttrsm(
ae_int_t m,
ae_int_t n,
complex_2d_array a,
ae_int_t i1,
ae_int_t j1,
<b>bool</b> isupper,
<b>bool</b> isunit,
ae_int_t optype,
complex_2d_array& x,
ae_int_t i2,
ae_int_t j2);
</div></pre>
<a name='sub_cmatrixsyrk'></a><h3 class=pageheader><code>cmatrixsyrk</code> function</h3>
<pre class=source>
<div style='color: navy; margin-top: 0; margin-bottom: 0;'>/*************************************************************************
This subroutine is an older version of CMatrixHERK(), one with wrong name
(it is HErmitian update, not SYmmetric). It is left here for backward
compatibility.
-- ALGLIB routine --
16.12.2009
Bochkanov Sergey
*************************************************************************/
</div><div style='margin-top: 0; margin-bottom: 0;'><b>void</b> alglib::cmatrixsyrk(
ae_int_t n,
ae_int_t k,
<b>double</b> alpha,
complex_2d_array a,
ae_int_t ia,
ae_int_t ja,
ae_int_t optypea,
<b>double</b> beta,
complex_2d_array& c,
ae_int_t ic,
ae_int_t jc,
<b>bool</b> isupper);
<b>void</b> alglib::smp_cmatrixsyrk(
ae_int_t n,
ae_int_t k,
<b>double</b> alpha,
complex_2d_array a,
ae_int_t ia,
ae_int_t ja,
ae_int_t optypea,
<b>double</b> beta,
complex_2d_array& c,
ae_int_t ic,
ae_int_t jc,
<b>bool</b> isupper);
</div></pre>
<a name='sub_cmatrixtranspose'></a><h3 class=pageheader><code>cmatrixtranspose</code> function</h3>
<pre class=source>
<div style='color: navy; margin-top: 0; margin-bottom: 0;'>/*************************************************************************
Cache-oblivous complex "copy-and-transpose"
Input parameters:
M - number of rows
N - number of columns
A - source matrix, MxN submatrix is copied and transposed
IA - submatrix offset (row index)
JA - submatrix offset (column index)
B - destination matrix, must be large enough to store result
IB - submatrix offset (row index)
JB - submatrix offset (column index)
*************************************************************************/
</div><div style='margin-top: 0; margin-bottom: 0;'><b>void</b> alglib::cmatrixtranspose(
ae_int_t m,
ae_int_t n,
complex_2d_array a,
ae_int_t ia,
ae_int_t ja,
complex_2d_array& b,
ae_int_t ib,
ae_int_t jb);
</div></pre>
<a name='sub_rmatrixcopy'></a><h3 class=pageheader><code>rmatrixcopy</code> function</h3>
<pre class=source>
<div style='color: navy; margin-top: 0; margin-bottom: 0;'>/*************************************************************************
Copy
Input parameters:
M - number of rows
N - number of columns
A - source matrix, MxN submatrix is copied and transposed
IA - submatrix offset (row index)
JA - submatrix offset (column index)
B - destination matrix, must be large enough to store result
IB - submatrix offset (row index)
JB - submatrix offset (column index)
*************************************************************************/
</div><div style='margin-top: 0; margin-bottom: 0;'><b>void</b> alglib::rmatrixcopy(
ae_int_t m,
ae_int_t n,
real_2d_array a,
ae_int_t ia,
ae_int_t ja,
real_2d_array& b,
ae_int_t ib,
ae_int_t jb);
</div></pre>
<a name='sub_rmatrixenforcesymmetricity'></a><h3 class=pageheader><code>rmatrixenforcesymmetricity</code> function</h3>
<pre class=source>
<div style='color: navy; margin-top: 0; margin-bottom: 0;'>/*************************************************************************
This code enforces symmetricy of the matrix by copying Upper part to lower
one (or vice versa).
INPUT PARAMETERS:
A - matrix
N - number of rows/columns
IsUpper - whether we want to copy upper triangle to lower one (True)
or vice versa (False).
*************************************************************************/
</div><div style='margin-top: 0; margin-bottom: 0;'><b>void</b> alglib::rmatrixenforcesymmetricity(
real_2d_array& a,
ae_int_t n,
<b>bool</b> isupper);
</div></pre>
<a name='sub_rmatrixgemm'></a><h3 class=pageheader><code>rmatrixgemm</code> function</h3>
<pre class=source>
<div style='color: navy; margin-top: 0; margin-bottom: 0;'>/*************************************************************************
This subroutine calculates C = alpha*op1(A)*op2(B) +beta*C where:
* C is MxN general matrix
* op1(A) is MxK matrix
* op2(B) is KxN matrix
* "op" may be identity transformation, transposition
Additional info:
* cache-oblivious algorithm is used.
* multiplication result replaces C. If Beta=0, C elements are not used in
calculations (not multiplied by zero - just not referenced)
* if Alpha=0, A is not used (not multiplied by zero - just not referenced)
* if both Beta and Alpha are zero, C is filled by zeros.
COMMERCIAL EDITION OF ALGLIB:
! Commercial version of ALGLIB includes two important improvements of
! this function, which can be used from C++ and C#:
! * Intel MKL support (lightweight Intel MKL is shipped with ALGLIB)
! * multicore support
!
! Intel MKL gives approximately constant (with respect to number of
! worker threads) acceleration factor which depends on CPU being used,
! problem size and "baseline" ALGLIB edition which is used for
! comparison.
!
! Say, on SSE2-capable CPU with N=1024, HPC ALGLIB will be:
! * about 2-3x faster than ALGLIB for C++ without MKL
! * about 7-10x faster than "pure C#" edition of ALGLIB
! Difference in performance will be more striking on newer CPU's with
! support for newer SIMD instructions.
!
! Commercial edition of ALGLIB also supports multithreaded acceleration
! of this function. Because starting/stopping worker thread always
! involves some overhead, parallelism starts to be profitable for N's
! larger than 128.
!
! In order to use multicore features you have to:
! * use commercial version of ALGLIB
! * call this function with "smp_" prefix, which indicates that
! multicore code will be used (for multicore support)
!
! We recommend you to read 'Working with commercial version' section of
! ALGLIB Reference Manual in order to find out how to use performance-
! related features provided by commercial edition of ALGLIB.
IMPORTANT:
This function does NOT preallocate output matrix C, it MUST be preallocated
by caller prior to calling this function. In case C does not have enough
space to store result, exception will be generated.
INPUT PARAMETERS
M - matrix size, M>0
N - matrix size, N>0
K - matrix size, K>0
Alpha - coefficient
A - matrix
IA - submatrix offset
JA - submatrix offset
OpTypeA - transformation type:
* 0 - no transformation
* 1 - transposition
B - matrix
IB - submatrix offset
JB - submatrix offset
OpTypeB - transformation type:
* 0 - no transformation
* 1 - transposition
Beta - coefficient
C - PREALLOCATED output matrix, large enough to store result
IC - submatrix offset
JC - submatrix offset
-- ALGLIB routine --
2009-2013
Bochkanov Sergey
*************************************************************************/
</div><div style='margin-top: 0; margin-bottom: 0;'><b>void</b> alglib::rmatrixgemm(
ae_int_t m,
ae_int_t n,
ae_int_t k,
<b>double</b> alpha,
real_2d_array a,
ae_int_t ia,
ae_int_t ja,
ae_int_t optypea,
real_2d_array b,
ae_int_t ib,
ae_int_t jb,
ae_int_t optypeb,
<b>double</b> beta,
real_2d_array& c,
ae_int_t ic,
ae_int_t jc);
<b>void</b> alglib::smp_rmatrixgemm(
ae_int_t m,
ae_int_t n,
ae_int_t k,
<b>double</b> alpha,
real_2d_array a,
ae_int_t ia,
ae_int_t ja,
ae_int_t optypea,
real_2d_array b,
ae_int_t ib,
ae_int_t jb,
ae_int_t optypeb,
<b>double</b> beta,
real_2d_array& c,
ae_int_t ic,
ae_int_t jc);
</div></pre>
<p align=left class=pagecontent><span class=inlineheader>Examples:</span> <a href='#example_ablas_d_gemm' class=nav>[1]</a> <a href='#example_ablas_smp_gemm' class=nav>[2]</a> </p>
<a name='sub_rmatrixlefttrsm'></a><h3 class=pageheader><code>rmatrixlefttrsm</code> function</h3>
<pre class=source>
<div style='color: navy; margin-top: 0; margin-bottom: 0;'>/*************************************************************************
This subroutine calculates op(A^-1)*X where:
* X is MxN general matrix
* A is MxM upper/lower triangular/unitriangular matrix
* "op" may be identity transformation, transposition
Multiplication result replaces X.
Cache-oblivious algorithm is used.
COMMERCIAL EDITION OF ALGLIB:
! Commercial version of ALGLIB includes two important improvements of
! this function, which can be used from C++ and C#:
! * Intel MKL support (lightweight Intel MKL is shipped with ALGLIB)
! * multicore support
!
! Intel MKL gives approximately constant (with respect to number of
! worker threads) acceleration factor which depends on CPU being used,
! problem size and "baseline" ALGLIB edition which is used for
! comparison.
!
! Say, on SSE2-capable CPU with N=1024, HPC ALGLIB will be:
! * about 2-3x faster than ALGLIB for C++ without MKL
! * about 7-10x faster than "pure C#" edition of ALGLIB
! Difference in performance will be more striking on newer CPU's with
! support for newer SIMD instructions.
!
! Commercial edition of ALGLIB also supports multithreaded acceleration
! of this function. Because starting/stopping worker thread always
! involves some overhead, parallelism starts to be profitable for N's
! larger than 128.
!
! In order to use multicore features you have to:
! * use commercial version of ALGLIB
! * call this function with "smp_" prefix, which indicates that
! multicore code will be used (for multicore support)
!
! We recommend you to read 'Working with commercial version' section of
! ALGLIB Reference Manual in order to find out how to use performance-
! related features provided by commercial edition of ALGLIB.
INPUT PARAMETERS
N - matrix size, N>=0
M - matrix size, N>=0
A - matrix, actial matrix is stored in A[I1:I1+M-1,J1:J1+M-1]
I1 - submatrix offset
J1 - submatrix offset
IsUpper - whether matrix is upper triangular
IsUnit - whether matrix is unitriangular
OpType - transformation type:
* 0 - no transformation
* 1 - transposition
X - matrix, actial matrix is stored in X[I2:I2+M-1,J2:J2+N-1]
I2 - submatrix offset
J2 - submatrix offset
-- ALGLIB routine --
15.12.2009
Bochkanov Sergey
*************************************************************************/
</div><div style='margin-top: 0; margin-bottom: 0;'><b>void</b> alglib::rmatrixlefttrsm(
ae_int_t m,
ae_int_t n,
real_2d_array a,
ae_int_t i1,
ae_int_t j1,
<b>bool</b> isupper,
<b>bool</b> isunit,
ae_int_t optype,
real_2d_array& x,
ae_int_t i2,
ae_int_t j2);
<b>void</b> alglib::smp_rmatrixlefttrsm(
ae_int_t m,
ae_int_t n,
real_2d_array a,
ae_int_t i1,
ae_int_t j1,
<b>bool</b> isupper,
<b>bool</b> isunit,
ae_int_t optype,
real_2d_array& x,
ae_int_t i2,
ae_int_t j2);
</div></pre>
<a name='sub_rmatrixmv'></a><h3 class=pageheader><code>rmatrixmv</code> function</h3>
<pre class=source>
<div style='color: navy; margin-top: 0; margin-bottom: 0;'>/*************************************************************************
Matrix-vector product: y := op(A)*x
INPUT PARAMETERS:
M - number of rows of op(A)
N - number of columns of op(A)
A - target matrix
IA - submatrix offset (row index)
JA - submatrix offset (column index)
OpA - operation type:
* OpA=0 => op(A) = A
* OpA=1 => op(A) = A^T
X - input vector
IX - subvector offset
IY - subvector offset
Y - preallocated matrix, must be large enough to store result
OUTPUT PARAMETERS:
Y - vector which stores result
if M=0, then subroutine does nothing.
if N=0, Y is filled by zeros.
-- ALGLIB routine --
28.01.2010
Bochkanov Sergey
*************************************************************************/
</div><div style='margin-top: 0; margin-bottom: 0;'><b>void</b> alglib::rmatrixmv(
ae_int_t m,
ae_int_t n,
real_2d_array a,
ae_int_t ia,
ae_int_t ja,
ae_int_t opa,
real_1d_array x,
ae_int_t ix,
real_1d_array& y,
ae_int_t iy);
</div></pre>
<a name='sub_rmatrixrank1'></a><h3 class=pageheader><code>rmatrixrank1</code> function</h3>
<pre class=source>
<div style='color: navy; margin-top: 0; margin-bottom: 0;'>/*************************************************************************
Rank-1 correction: A := A + u*v'
INPUT PARAMETERS:
M - number of rows
N - number of columns
A - target matrix, MxN submatrix is updated
IA - submatrix offset (row index)
JA - submatrix offset (column index)
U - vector #1
IU - subvector offset
V - vector #2
IV - subvector offset
*************************************************************************/
</div><div style='margin-top: 0; margin-bottom: 0;'><b>void</b> alglib::rmatrixrank1(
ae_int_t m,
ae_int_t n,
real_2d_array& a,
ae_int_t ia,
ae_int_t ja,
real_1d_array& u,
ae_int_t iu,
real_1d_array& v,
ae_int_t iv);
</div></pre>
<a name='sub_rmatrixrighttrsm'></a><h3 class=pageheader><code>rmatrixrighttrsm</code> function</h3>
<pre class=source>
<div style='color: navy; margin-top: 0; margin-bottom: 0;'>/*************************************************************************
This subroutine calculates X*op(A^-1) where:
* X is MxN general matrix
* A is NxN upper/lower triangular/unitriangular matrix
* "op" may be identity transformation, transposition
Multiplication result replaces X.
Cache-oblivious algorithm is used.
COMMERCIAL EDITION OF ALGLIB:
! Commercial version of ALGLIB includes two important improvements of
! this function, which can be used from C++ and C#:
! * Intel MKL support (lightweight Intel MKL is shipped with ALGLIB)
! * multicore support
!
! Intel MKL gives approximately constant (with respect to number of
! worker threads) acceleration factor which depends on CPU being used,
! problem size and "baseline" ALGLIB edition which is used for
! comparison.
!
! Say, on SSE2-capable CPU with N=1024, HPC ALGLIB will be:
! * about 2-3x faster than ALGLIB for C++ without MKL
! * about 7-10x faster than "pure C#" edition of ALGLIB
! Difference in performance will be more striking on newer CPU's with
! support for newer SIMD instructions.
!
! Commercial edition of ALGLIB also supports multithreaded acceleration
! of this function. Because starting/stopping worker thread always
! involves some overhead, parallelism starts to be profitable for N's
! larger than 128.
!
! In order to use multicore features you have to:
! * use commercial version of ALGLIB
! * call this function with "smp_" prefix, which indicates that
! multicore code will be used (for multicore support)
!
! We recommend you to read 'Working with commercial version' section of
! ALGLIB Reference Manual in order to find out how to use performance-
! related features provided by commercial edition of ALGLIB.
INPUT PARAMETERS
N - matrix size, N>=0
M - matrix size, N>=0
A - matrix, actial matrix is stored in A[I1:I1+N-1,J1:J1+N-1]
I1 - submatrix offset
J1 - submatrix offset
IsUpper - whether matrix is upper triangular
IsUnit - whether matrix is unitriangular
OpType - transformation type:
* 0 - no transformation
* 1 - transposition
X - matrix, actial matrix is stored in X[I2:I2+M-1,J2:J2+N-1]
I2 - submatrix offset
J2 - submatrix offset
-- ALGLIB routine --
15.12.2009
Bochkanov Sergey
*************************************************************************/
</div><div style='margin-top: 0; margin-bottom: 0;'><b>void</b> alglib::rmatrixrighttrsm(
ae_int_t m,
ae_int_t n,
real_2d_array a,
ae_int_t i1,
ae_int_t j1,
<b>bool</b> isupper,
<b>bool</b> isunit,
ae_int_t optype,
real_2d_array& x,
ae_int_t i2,
ae_int_t j2);
<b>void</b> alglib::smp_rmatrixrighttrsm(
ae_int_t m,
ae_int_t n,
real_2d_array a,
ae_int_t i1,
ae_int_t j1,
<b>bool</b> isupper,
<b>bool</b> isunit,
ae_int_t optype,
real_2d_array& x,
ae_int_t i2,
ae_int_t j2);
</div></pre>
<a name='sub_rmatrixsyrk'></a><h3 class=pageheader><code>rmatrixsyrk</code> function</h3>
<pre class=source>
<div style='color: navy; margin-top: 0; margin-bottom: 0;'>/*************************************************************************
This subroutine calculates C=alpha*A*A^T+beta*C or C=alpha*A^T*A+beta*C
where:
* C is NxN symmetric matrix given by its upper/lower triangle
* A is NxK matrix when A*A^T is calculated, KxN matrix otherwise
Additional info:
* cache-oblivious algorithm is used.
* multiplication result replaces C. If Beta=0, C elements are not used in
calculations (not multiplied by zero - just not referenced)
* if Alpha=0, A is not used (not multiplied by zero - just not referenced)
* if both Beta and Alpha are zero, C is filled by zeros.
COMMERCIAL EDITION OF ALGLIB:
! Commercial version of ALGLIB includes two important improvements of
! this function, which can be used from C++ and C#:
! * Intel MKL support (lightweight Intel MKL is shipped with ALGLIB)
! * multicore support
!
! Intel MKL gives approximately constant (with respect to number of
! worker threads) acceleration factor which depends on CPU being used,
! problem size and "baseline" ALGLIB edition which is used for
! comparison.
!
! Say, on SSE2-capable CPU with N=1024, HPC ALGLIB will be:
! * about 2-3x faster than ALGLIB for C++ without MKL
! * about 7-10x faster than "pure C#" edition of ALGLIB
! Difference in performance will be more striking on newer CPU's with
! support for newer SIMD instructions.
!
! Commercial edition of ALGLIB also supports multithreaded acceleration
! of this function. Because starting/stopping worker thread always
! involves some overhead, parallelism starts to be profitable for N's
! larger than 128.
!
! In order to use multicore features you have to:
! * use commercial version of ALGLIB
! * call this function with "smp_" prefix, which indicates that
! multicore code will be used (for multicore support)
!
! We recommend you to read 'Working with commercial version' section of
! ALGLIB Reference Manual in order to find out how to use performance-
! related features provided by commercial edition of ALGLIB.
INPUT PARAMETERS
N - matrix size, N>=0
K - matrix size, K>=0
Alpha - coefficient
A - matrix
IA - submatrix offset (row index)
JA - submatrix offset (column index)
OpTypeA - multiplication type:
* 0 - A*A^T is calculated
* 2 - A^T*A is calculated
Beta - coefficient
C - preallocated input/output matrix
IC - submatrix offset (row index)
JC - submatrix offset (column index)
IsUpper - whether C is upper triangular or lower triangular
-- ALGLIB routine --
16.12.2009
Bochkanov Sergey
*************************************************************************/
</div><div style='margin-top: 0; margin-bottom: 0;'><b>void</b> alglib::rmatrixsyrk(
ae_int_t n,
ae_int_t k,
<b>double</b> alpha,
real_2d_array a,
ae_int_t ia,
ae_int_t ja,
ae_int_t optypea,
<b>double</b> beta,
real_2d_array& c,
ae_int_t ic,
ae_int_t jc,
<b>bool</b> isupper);
<b>void</b> alglib::smp_rmatrixsyrk(
ae_int_t n,
ae_int_t k,
<b>double</b> alpha,
real_2d_array a,
ae_int_t ia,
ae_int_t ja,
ae_int_t optypea,
<b>double</b> beta,
real_2d_array& c,
ae_int_t ic,
ae_int_t jc,
<b>bool</b> isupper);
</div></pre>
<p align=left class=pagecontent><span class=inlineheader>Examples:</span> <a href='#example_ablas_d_syrk' class=nav>[1]</a> <a href='#example_ablas_smp_syrk' class=nav>[2]</a> </p>
<a name='sub_rmatrixtranspose'></a><h3 class=pageheader><code>rmatrixtranspose</code> function</h3>
<pre class=source>
<div style='color: navy; margin-top: 0; margin-bottom: 0;'>/*************************************************************************
Cache-oblivous real "copy-and-transpose"
Input parameters:
M - number of rows
N - number of columns
A - source matrix, MxN submatrix is copied and transposed
IA - submatrix offset (row index)
JA - submatrix offset (column index)
B - destination matrix, must be large enough to store result
IB - submatrix offset (row index)
JB - submatrix offset (column index)
*************************************************************************/
</div><div style='margin-top: 0; margin-bottom: 0;'><b>void</b> alglib::rmatrixtranspose(
ae_int_t m,
ae_int_t n,
real_2d_array a,
ae_int_t ia,
ae_int_t ja,
real_2d_array& b,
ae_int_t ib,
ae_int_t jb);
</div></pre>
<a name='example_ablas_d_gemm'></a><h3 class=pageheader>ablas_d_gemm example</h3>
<pre class=source>
#include <font color=blue><b>"stdafx.h"</b></font>
#include <stdlib.h>
#include <stdio.h>
#include <math.h>
#include <font color=blue><b>"linalg.h"</b></font>
using namespace alglib;
<b>int</b> main(<b>int</b> argc, char **argv)
{
real_2d_array a = <font color=blue><b>"[[2,1],[1,3]]"</b></font>;
real_2d_array b = <font color=blue><b>"[[2,1],[0,1]]"</b></font>;
real_2d_array c = <font color=blue><b>"[[0,0],[0,0]]"</b></font>;
<font color=navy>//</font>
<font color=navy>// rmatrixgemm() function allows us to calculate matrix product C:=A*B or</font>
<font color=navy>// to perform more general operation, C:=alpha*op1(A)*op2(B)+beta*C,</font>
<font color=navy>// where A, B, C are rectangular matrices, op(X) can be X or X^T,</font>
<font color=navy>// alpha and beta are scalars.</font>
<font color=navy>//</font>
<font color=navy>// This function:</font>
<font color=navy>// * can apply transposition and/or multiplication by scalar to operands</font>
<font color=navy>// * can use arbitrary part of matrices A/B (given by submatrix offset)</font>
<font color=navy>// * can store result into arbitrary part of C</font>
<font color=navy>// * <b>for</b> performance reasons requires C to be preallocated</font>
<font color=navy>//</font>
<font color=navy>// Parameters of this function are:</font>
<font color=navy>// * M, N, K - sizes of op1(A) (which is MxK), op2(B) (which</font>
<font color=navy>// is KxN) and C (which is MxN)</font>
<font color=navy>// * Alpha - coefficient before A*B</font>
<font color=navy>// * A, IA, JA - matrix A and offset of the submatrix</font>
<font color=navy>// * OpTypeA - transformation type:</font>
<font color=navy>// 0 - no transformation</font>
<font color=navy>// 1 - transposition</font>
<font color=navy>// * B, IB, JB - matrix B and offset of the submatrix</font>
<font color=navy>// * OpTypeB - transformation type:</font>
<font color=navy>// 0 - no transformation</font>
<font color=navy>// 1 - transposition</font>
<font color=navy>// * Beta - coefficient before C</font>
<font color=navy>// * C, IC, JC - preallocated matrix C and offset of the submatrix</font>
<font color=navy>//</font>
<font color=navy>// Below we perform simple product C:=A*B (alpha=1, beta=0)</font>
<font color=navy>//</font>
<font color=navy>// IMPORTANT: this function works with preallocated C, which must be large</font>
<font color=navy>// enough to store multiplication result.</font>
<font color=navy>//</font>
ae_int_t m = 2;
ae_int_t n = 2;
ae_int_t k = 2;
<b>double</b> alpha = 1.0;
ae_int_t ia = 0;
ae_int_t ja = 0;
ae_int_t optypea = 0;
ae_int_t ib = 0;
ae_int_t jb = 0;
ae_int_t optypeb = 0;
<b>double</b> beta = 0.0;
ae_int_t ic = 0;
ae_int_t jc = 0;
rmatrixgemm(m, n, k, alpha, a, ia, ja, optypea, b, ib, jb, optypeb, beta, c, ic, jc);
printf(<font color=blue><b>"%s\n"</b></font>, c.tostring(3).c_str()); <font color=navy>// EXPECTED: [[4,3],[2,4]]</font>
<font color=navy>//</font>
<font color=navy>// Now we try to apply some simple transformation to operands: C:=A*B^T</font>
<font color=navy>//</font>
optypeb = 1;
rmatrixgemm(m, n, k, alpha, a, ia, ja, optypea, b, ib, jb, optypeb, beta, c, ic, jc);
printf(<font color=blue><b>"%s\n"</b></font>, c.tostring(3).c_str()); <font color=navy>// EXPECTED: [[5,1],[5,3]]</font>
<b>return</b> 0;
}
</pre><a name='example_ablas_d_syrk'></a><h3 class=pageheader>ablas_d_syrk example</h3>
<pre class=source>
#include <font color=blue><b>"stdafx.h"</b></font>
#include <stdlib.h>
#include <stdio.h>
#include <math.h>
#include <font color=blue><b>"linalg.h"</b></font>
using namespace alglib;
<b>int</b> main(<b>int</b> argc, char **argv)
{
<font color=navy>//</font>
<font color=navy>// rmatrixsyrk() function allows us to calculate symmetric rank-K update</font>
<font color=navy>// C := beta*C + alpha*A'*A, where C is square N*N matrix, A is square K*N</font>
<font color=navy>// matrix, alpha and beta are scalars. It is also possible to update by</font>
<font color=navy>// adding A*A' instead of A'*A.</font>
<font color=navy>//</font>
<font color=navy>// Parameters of this function are:</font>
<font color=navy>// * N, K - matrix size</font>
<font color=navy>// * Alpha - coefficient before A</font>
<font color=navy>// * A, IA, JA - matrix and submatrix offsets</font>
<font color=navy>// * OpTypeA - multiplication type:</font>
<font color=navy>// * 0 - A*A^T is calculated</font>
<font color=navy>// * 2 - A^T*A is calculated</font>
<font color=navy>// * Beta - coefficient before C</font>
<font color=navy>// * C, IC, JC - preallocated input/output matrix and submatrix offsets</font>
<font color=navy>// * IsUpper - whether upper or lower triangle of C is updated;</font>
<font color=navy>// this function updates only one half of C, leaving</font>
<font color=navy>// other half unchanged (not referenced at all).</font>
<font color=navy>//</font>
<font color=navy>// Below we will show how to calculate simple product C:=A'*A</font>
<font color=navy>//</font>
<font color=navy>// NOTE: beta=0 and we <b>do</b> not use previous value of C, but still it</font>
<font color=navy>// MUST be preallocated.</font>
<font color=navy>//</font>
ae_int_t n = 2;
ae_int_t k = 1;
<b>double</b> alpha = 1.0;
ae_int_t ia = 0;
ae_int_t ja = 0;
ae_int_t optypea = 2;
<b>double</b> beta = 0.0;
ae_int_t ic = 0;
ae_int_t jc = 0;
<b>bool</b> isupper = true;
real_2d_array a = <font color=blue><b>"[[1,2]]"</b></font>;
<font color=navy>// preallocate space to store result</font>
real_2d_array c = <font color=blue><b>"[[0,0],[0,0]]"</b></font>;
<font color=navy>// calculate product, store result into upper part of c</font>
rmatrixsyrk(n, k, alpha, a, ia, ja, optypea, beta, c, ic, jc, isupper);
<font color=navy>// output result.</font>
<font color=navy>// IMPORTANT: lower triangle of C was NOT updated!</font>
printf(<font color=blue><b>"%s\n"</b></font>, c.tostring(3).c_str()); <font color=navy>// EXPECTED: [[1,2],[0,4]]</font>
<b>return</b> 0;
}
</pre><a name='example_ablas_smp_gemm'></a><h3 class=pageheader>ablas_smp_gemm example</h3>
<pre class=source>
#include <font color=blue><b>"stdafx.h"</b></font>
#include <stdlib.h>
#include <stdio.h>
#include <math.h>
#include <font color=blue><b>"linalg.h"</b></font>
using namespace alglib;
<b>int</b> main(<b>int</b> argc, char **argv)
{
<font color=navy>//</font>
<font color=navy>// In this example we assume that you already know how to work with</font>
<font color=navy>// rmatrixgemm() function. Below we concentrate on its multithreading</font>
<font color=navy>// capabilities.</font>
<font color=navy>//</font>
<font color=navy>// SMP edition of ALGLIB includes smp_rmatrixgemm() - multithreaded</font>
<font color=navy>// version of rmatrixgemm() function. In the basic edition of ALGLIB</font>
<font color=navy>// (GPL edition or commercial version without SMP support) this function</font>
<font color=navy>// just calls single-threaded stub. So, you may call this function from</font>
<font color=navy>// ANY edition of ALGLIB, but only in SMP edition it will work in really</font>
<font color=navy>// multithreaded mode.</font>
<font color=navy>//</font>
<font color=navy>// In order to use multithreading, you have to:</font>
<font color=navy>// 1) Install SMP edition of ALGLIB.</font>
<font color=navy>// 2) This step is specific <b>for</b> C++ users: you should activate OS-specific</font>
<font color=navy>// capabilities of ALGLIB by defining AE_OS=AE_POSIX (<b>for</b> *nix systems)</font>
<font color=navy>// or AE_OS=AE_WINDOWS (<b>for</b> Windows systems).</font>
<font color=navy>// C# users <b>do</b> not have to perform this step because C# programs are</font>
<font color=navy>// portable across different systems without OS-specific tuning.</font>
<font color=navy>// 3) Allow ALGLIB to know about number of worker threads to use:</font>
<font color=navy>// a) autodetection (C++, C#):</font>
<font color=navy>// ALGLIB will automatically determine number of CPU cores and</font>
<font color=navy>// (by default) will use all cores except <b>for</b> one. Say, on 4-core</font>
<font color=navy>// system it will use three cores - unless you manually told it</font>
<font color=navy>// to use more or less. It will keep your system responsive during</font>
<font color=navy>// lengthy computations.</font>
<font color=navy>// Such behavior may be changed with setnworkers() call:</font>
<font color=navy>// * alglib::setnworkers(0) = use all cores</font>
<font color=navy>// * alglib::setnworkers(-1) = leave one core unused</font>
<font color=navy>// * alglib::setnworkers(-2) = leave two cores unused</font>
<font color=navy>// * alglib::setnworkers(+2) = use 2 cores (even <b>if</b> you have more)</font>
<font color=navy>// b) manual specification (C++, C#):</font>
<font color=navy>// You may want to specify maximum number of worker threads during</font>
<font color=navy>// compile time by means of preprocessor definition AE_NWORKERS.</font>
<font color=navy>// For C++ it will be <font color=blue><b>"AE_NWORKERS=X"</b></font> where X can be any positive number.</font>
<font color=navy>// For C# it is <font color=blue><b>"AE_NWORKERSX"</b></font>, where X should be replaced by number of</font>
<font color=navy>// workers (AE_NWORKERS2, AE_NWORKERS3, AE_NWORKERS4, ...).</font>
<font color=navy>// You can add this definition to compiler command line or change</font>
<font color=navy>// corresponding project settings in your IDE.</font>
<font color=navy>//</font>
<font color=navy>// After you installed and configured SMP edition of ALGLIB, you may choose</font>
<font color=navy>// between serial and multithreaded versions of SMP-capable functions:</font>
<font color=navy>// * serial version works as usual, in the context of the calling thread</font>
<font color=navy>// * multithreaded version (with <font color=blue><b>"smp_"</b></font> prefix) creates (or wakes up) worker</font>
<font color=navy>// threads, inserts task in the worker queue, and waits <b>for</b> completion of</font>
<font color=navy>// the task. All processing is done in context of worker thread(s).</font>
<font color=navy>//</font>
<font color=navy>// NOTE: because starting/stopping worker threads costs thousands of CPU cycles,</font>
<font color=navy>// you should not use multithreading <b>for</b> lightweight computational problems.</font>
<font color=navy>//</font>
<font color=navy>// NOTE: some old POSIX-compatible operating systems <b>do</b> not support</font>
<font color=navy>// sysconf(_SC_NPROCESSORS_ONLN) system call which is required in order</font>
<font color=navy>// to automatically determine number of active cores. On these systems</font>
<font color=navy>// you should specify number of cores manually at compile time.</font>
<font color=navy>// Without it ALGLIB will run in single-threaded mode.</font>
<font color=navy>//</font>
<font color=navy>// Now, back to our example. In this example we will show you:</font>
<font color=navy>// * how to call SMP version of rmatrixgemm(). Because we work with tiny 2x2</font>
<font color=navy>// matrices, we won't expect to see ANY speedup from using multithreading.</font>
<font color=navy>// The only purpose of this demo is to show how to call SMP functions.</font>
<font color=navy>// * how to modify number of worker threads used by ALGLIB</font>
<font color=navy>//</font>
real_2d_array a = <font color=blue><b>"[[2,1],[1,3]]"</b></font>;
real_2d_array b = <font color=blue><b>"[[2,1],[0,1]]"</b></font>;
real_2d_array c = <font color=blue><b>"[[0,0],[0,0]]"</b></font>;
ae_int_t m = 2;
ae_int_t n = 2;
ae_int_t k = 2;
<b>double</b> alpha = 1.0;
ae_int_t ia = 0;
ae_int_t ja = 0;
ae_int_t optypea = 0;
ae_int_t ib = 0;
ae_int_t jb = 0;
ae_int_t optypeb = 0;
<b>double</b> beta = 0.0;
ae_int_t ic = 0;
ae_int_t jc = 0;
<font color=navy>// serial code</font>
c = <font color=blue><b>"[[0,0],[0,0]]"</b></font>;
rmatrixgemm(m, n, k, alpha, a, ia, ja, optypea, b, ib, jb, optypeb, beta, c, ic, jc);
<font color=navy>// SMP code with default number of worker threads</font>
c = <font color=blue><b>"[[0,0],[0,0]]"</b></font>;
smp_rmatrixgemm(m, n, k, alpha, a, ia, ja, optypea, b, ib, jb, optypeb, beta, c, ic, jc);
printf(<font color=blue><b>"%s\n"</b></font>, c.tostring(3).c_str()); <font color=navy>// EXPECTED: [[4,3],[2,4]]</font>
<font color=navy>// override number of worker threads - use two cores</font>
alglib::setnworkers(+2);
c = <font color=blue><b>"[[0,0],[0,0]]"</b></font>;
smp_rmatrixgemm(m, n, k, alpha, a, ia, ja, optypea, b, ib, jb, optypeb, beta, c, ic, jc);
printf(<font color=blue><b>"%s\n"</b></font>, c.tostring(3).c_str()); <font color=navy>// EXPECTED: [[4,3],[2,4]]</font>
<b>return</b> 0;
}
</pre><a name='example_ablas_smp_syrk'></a><h3 class=pageheader>ablas_smp_syrk example</h3>
<pre class=source>
#include <font color=blue><b>"stdafx.h"</b></font>
#include <stdlib.h>
#include <stdio.h>
#include <math.h>
#include <font color=blue><b>"linalg.h"</b></font>
using namespace alglib;
<b>int</b> main(<b>int</b> argc, char **argv)
{
<font color=navy>//</font>
<font color=navy>// In this example we assume that you already know how to work with</font>
<font color=navy>// rmatrixsyrk() function. Below we concentrate on its multithreading</font>
<font color=navy>// capabilities.</font>
<font color=navy>//</font>
<font color=navy>// SMP edition of ALGLIB includes smp_rmatrixsyrk() - multithreaded</font>
<font color=navy>// version of rmatrixsyrk() function. In the basic edition of ALGLIB</font>
<font color=navy>// (GPL edition or commercial version without SMP support) this function</font>
<font color=navy>// just calls single-threaded stub. So, you may call this function from</font>
<font color=navy>// ANY edition of ALGLIB, but only in SMP edition it will work in really</font>
<font color=navy>// multithreaded mode.</font>
<font color=navy>//</font>
<font color=navy>// In order to use multithreading, you have to:</font>
<font color=navy>// 1) Install SMP edition of ALGLIB.</font>
<font color=navy>// 2) This step is specific <b>for</b> C++ users: you should activate OS-specific</font>
<font color=navy>// capabilities of ALGLIB by defining AE_OS=AE_POSIX (<b>for</b> *nix systems)</font>
<font color=navy>// or AE_OS=AE_WINDOWS (<b>for</b> Windows systems).</font>
<font color=navy>// C# users <b>do</b> not have to perform this step because C# programs are</font>
<font color=navy>// portable across different systems without OS-specific tuning.</font>
<font color=navy>// 3) Allow ALGLIB to know about number of worker threads to use:</font>
<font color=navy>// a) autodetection (C++, C#):</font>
<font color=navy>// ALGLIB will automatically determine number of CPU cores and</font>
<font color=navy>// (by default) will use all cores except <b>for</b> one. Say, on 4-core</font>
<font color=navy>// system it will use three cores - unless you manually told it</font>
<font color=navy>// to use more or less. It will keep your system responsive during</font>
<font color=navy>// lengthy computations.</font>
<font color=navy>// Such behavior may be changed with setnworkers() call:</font>
<font color=navy>// * alglib::setnworkers(0) = use all cores</font>
<font color=navy>// * alglib::setnworkers(-1) = leave one core unused</font>
<font color=navy>// * alglib::setnworkers(-2) = leave two cores unused</font>
<font color=navy>// * alglib::setnworkers(+2) = use 2 cores (even <b>if</b> you have more)</font>
<font color=navy>// b) manual specification (C++, C#):</font>
<font color=navy>// You may want to specify maximum number of worker threads during</font>
<font color=navy>// compile time by means of preprocessor definition AE_NWORKERS.</font>
<font color=navy>// For C++ it will be <font color=blue><b>"AE_NWORKERS=X"</b></font> where X can be any positive number.</font>
<font color=navy>// For C# it is <font color=blue><b>"AE_NWORKERSX"</b></font>, where X should be replaced by number of</font>
<font color=navy>// workers (AE_NWORKERS2, AE_NWORKERS3, AE_NWORKERS4, ...).</font>
<font color=navy>// You can add this definition to compiler command line or change</font>
<font color=navy>// corresponding project settings in your IDE.</font>
<font color=navy>//</font>
<font color=navy>// After you installed and configured SMP edition of ALGLIB, you may choose</font>
<font color=navy>// between serial and multithreaded versions of SMP-capable functions:</font>
<font color=navy>// * serial version works as usual, in the context of the calling thread</font>
<font color=navy>// * multithreaded version (with <font color=blue><b>"smp_"</b></font> prefix) creates (or wakes up) worker</font>
<font color=navy>// threads, inserts task in the worker queue, and waits <b>for</b> completion of</font>
<font color=navy>// the task. All processing is done in context of worker thread(s).</font>
<font color=navy>//</font>
<font color=navy>// NOTE: because starting/stopping worker threads costs thousands of CPU cycles,</font>
<font color=navy>// you should not use multithreading <b>for</b> lightweight computational problems.</font>
<font color=navy>//</font>
<font color=navy>// NOTE: some old POSIX-compatible operating systems <b>do</b> not support</font>
<font color=navy>// sysconf(_SC_NPROCESSORS_ONLN) system call which is required in order</font>
<font color=navy>// to automatically determine number of active cores. On these systems</font>
<font color=navy>// you should specify number of cores manually at compile time.</font>
<font color=navy>// Without it ALGLIB will run in single-threaded mode.</font>
<font color=navy>//</font>
<font color=navy>// Now, back to our example. In this example we will show you:</font>
<font color=navy>// * how to call SMP version of rmatrixsyrk(). Because we work with tiny 2x2</font>
<font color=navy>// matrices, we won't expect to see ANY speedup from using multithreading.</font>
<font color=navy>// The only purpose of this demo is to show how to call SMP functions.</font>
<font color=navy>// * how to modify number of worker threads used by ALGLIB</font>
<font color=navy>//</font>
ae_int_t n = 2;
ae_int_t k = 1;
<b>double</b> alpha = 1.0;
ae_int_t ia = 0;
ae_int_t ja = 0;
ae_int_t optypea = 2;
<b>double</b> beta = 0.0;
ae_int_t ic = 0;
ae_int_t jc = 0;
<b>bool</b> isupper = true;
real_2d_array a = <font color=blue><b>"[[1,2]]"</b></font>;
real_2d_array c = <font color=blue><b>"[[]]"</b></font>;
<font color=navy>//</font>
<font color=navy>// Default number of worker threads.</font>
<font color=navy>// Preallocate space to store result, call multithreaded version, test.</font>
<font color=navy>//</font>
<font color=navy>// NOTE: this function updates only one triangular part of C. In our</font>
<font color=navy>// example we choose to update upper triangle.</font>
<font color=navy>//</font>
c = <font color=blue><b>"[[0,0],[0,0]]"</b></font>;
smp_rmatrixsyrk(n, k, alpha, a, ia, ja, optypea, beta, c, ic, jc, isupper);
printf(<font color=blue><b>"%s\n"</b></font>, c.tostring(3).c_str()); <font color=navy>// EXPECTED: [[1,2],[0,4]]</font>
<font color=navy>//</font>
<font color=navy>// Override default number of worker threads (set to 2).</font>
<font color=navy>// Preallocate space to store result, call multithreaded version, test.</font>
<font color=navy>//</font>
<font color=navy>// NOTE: this function updates only one triangular part of C. In our</font>
<font color=navy>// example we choose to update upper triangle.</font>
<font color=navy>//</font>
alglib::setnworkers(+2);
c = <font color=blue><b>"[[0,0],[0,0]]"</b></font>;
smp_rmatrixsyrk(n, k, alpha, a, ia, ja, optypea, beta, c, ic, jc, isupper);
printf(<font color=blue><b>"%s\n"</b></font>, c.tostring(3).c_str()); <font color=navy>// EXPECTED: [[1,2],[0,4]]</font>
<b>return</b> 0;
}
</pre><a name=unit_airyf></a><h2 class=pageheader><code>airyf</code> subpackage</h2>
<div class=pagecontent>
<h3 class=pageheader>Functions</h3>
<a href='#sub_airy' class=toc>airy</a><br>
<h3 class=pageheader>Examples</h3>
<table border=0 cellspacing=0 class='pagecontent'>
</table></div>
<a name='sub_airy'></a><h3 class=pageheader><code>airy</code> function</h3>
<pre class=source>
<div style='color: navy; margin-top: 0; margin-bottom: 0;'>/*************************************************************************
Airy function
Solution of the differential equation
y"(x) = xy.
The function returns the two independent solutions Ai, Bi
and their first derivatives Ai'(x), Bi'(x).
Evaluation is by power series summation for small x,
by rational minimax approximations for large x.
ACCURACY:
Error criterion is absolute when function <= 1, relative
when function > 1, except * denotes relative error criterion.
For large negative x, the absolute error increases as x^1.5.
For large positive x, the relative error increases as x^1.5.
Arithmetic domain function # trials peak rms
IEEE -10, 0 Ai 10000 1.6e-15 2.7e-16
IEEE 0, 10 Ai 10000 2.3e-14* 1.8e-15*
IEEE -10, 0 Ai' 10000 4.6e-15 7.6e-16
IEEE 0, 10 Ai' 10000 1.8e-14* 1.5e-15*
IEEE -10, 10 Bi 30000 4.2e-15 5.3e-16
IEEE -10, 10 Bi' 30000 4.9e-15 7.3e-16
Cephes Math Library Release 2.8: June, 2000
Copyright 1984, 1987, 1989, 2000 by Stephen L. Moshier
*************************************************************************/
</div><div style='margin-top: 0; margin-bottom: 0;'><b>void</b> alglib::airy(
<b>double</b> x,
<b>double</b>& ai,
<b>double</b>& aip,
<b>double</b>& bi,
<b>double</b>& bip);
</div></pre>
<a name=unit_autogk></a><h2 class=pageheader><code>autogk</code> subpackage</h2>
<div class=pagecontent>
<h3 class=pageheader>Classes</h3>
<a href='#struct_autogkreport' class=toc>autogkreport</a><br>
<a href='#struct_autogkstate' class=toc>autogkstate</a><br>
<h3 class=pageheader>Functions</h3>
<a href='#sub_autogkintegrate' class=toc>autogkintegrate</a><br>
<a href='#sub_autogkresults' class=toc>autogkresults</a><br>
<a href='#sub_autogksingular' class=toc>autogksingular</a><br>
<a href='#sub_autogksmooth' class=toc>autogksmooth</a><br>
<a href='#sub_autogksmoothw' class=toc>autogksmoothw</a><br>
<h3 class=pageheader>Examples</h3>
<table border=0 cellspacing=0 class='pagecontent'>
<tr align=left valign=top><td><a href='#example_autogk_d1' class=toc>autogk_d1</a></td><td width=15> </td><td>Integrating f=exp(x) by adaptive integrator</td></tr>
</table></div>
<a name='struct_autogkreport'></a><h3 class=pageheader><code>autogkreport</code> class</h3>
<pre class=source>
<div style='color: navy; margin-top: 0; margin-bottom: 0;'>/*************************************************************************
Integration report:
* TerminationType = completetion code:
* -5 non-convergence of Gauss-Kronrod nodes
calculation subroutine.
* -1 incorrect parameters were specified
* 1 OK
* Rep.NFEV countains number of function calculations
* Rep.NIntervals contains number of intervals [a,b]
was partitioned into.
*************************************************************************/
</div><div style='margin-top: 0; margin-bottom: 0;'><b>class</b> autogkreport
{
ae_int_t terminationtype;
ae_int_t nfev;
ae_int_t nintervals;
};
</div></pre>
<a name='struct_autogkstate'></a><h3 class=pageheader><code>autogkstate</code> class</h3>
<pre class=source>
<div style='color: navy; margin-top: 0; margin-bottom: 0;'>/*************************************************************************
This structure stores state of the integration algorithm.
Although this class has public fields, they are not intended for external
use. You should use ALGLIB functions to work with this class:
* autogksmooth()/AutoGKSmoothW()/... to create objects
* autogkintegrate() to begin integration
* autogkresults() to get results
*************************************************************************/
</div><div style='margin-top: 0; margin-bottom: 0;'><b>class</b> autogkstate
{
};
</div></pre>
<a name='sub_autogkintegrate'></a><h3 class=pageheader><code>autogkintegrate</code> function</h3>
<pre class=source>
<div style='color: navy; margin-top: 0; margin-bottom: 0;'>/*************************************************************************
This function is used to launcn iterations of ODE solver
It accepts following parameters:
diff - callback which calculates dy/dx for given y and x
obj - optional object which is passed to diff; can be NULL
-- ALGLIB --
Copyright 07.05.2009 by Bochkanov Sergey
*************************************************************************/
</div><div style='margin-top: 0; margin-bottom: 0;'><b>void</b> autogkintegrate(autogkstate &state,
<b>void</b> (*func)(<b>double</b> x, <b>double</b> xminusa, <b>double</b> bminusx, <b>double</b> &y, <b>void</b> *ptr),
<b>void</b> *ptr = NULL);
</div></pre>
<p align=left class=pagecontent><span class=inlineheader>Examples:</span> <a href='#example_autogk_d1' class=nav>[1]</a> </p>
<a name='sub_autogkresults'></a><h3 class=pageheader><code>autogkresults</code> function</h3>
<pre class=source>
<div style='color: navy; margin-top: 0; margin-bottom: 0;'>/*************************************************************************
Adaptive integration results
Called after AutoGKIteration returned False.
Input parameters:
State - algorithm state (used by AutoGKIteration).
Output parameters:
V - integral(f(x)dx,a,b)
Rep - optimization report (see AutoGKReport description)
-- ALGLIB --
Copyright 14.11.2007 by Bochkanov Sergey
*************************************************************************/
</div><div style='margin-top: 0; margin-bottom: 0;'><b>void</b> alglib::autogkresults(
autogkstate state,
<b>double</b>& v,
autogkreport& rep);
</div></pre>
<p align=left class=pagecontent><span class=inlineheader>Examples:</span> <a href='#example_autogk_d1' class=nav>[1]</a> </p>
<a name='sub_autogksingular'></a><h3 class=pageheader><code>autogksingular</code> function</h3>
<pre class=source>
<div style='color: navy; margin-top: 0; margin-bottom: 0;'>/*************************************************************************
Integration on a finite interval [A,B].
Integrand have integrable singularities at A/B.
F(X) must diverge as "(x-A)^alpha" at A, as "(B-x)^beta" at B, with known
alpha/beta (alpha>-1, beta>-1). If alpha/beta are not known, estimates
from below can be used (but these estimates should be greater than -1 too).
One of alpha/beta variables (or even both alpha/beta) may be equal to 0,
which means than function F(x) is non-singular at A/B. Anyway (singular at
bounds or not), function F(x) is supposed to be continuous on (A,B).
Fast-convergent algorithm based on a Gauss-Kronrod formula is used. Result
is calculated with accuracy close to the machine precision.
INPUT PARAMETERS:
A, B - interval boundaries (A<B, A=B or A>B)
Alpha - power-law coefficient of the F(x) at A,
Alpha>-1
Beta - power-law coefficient of the F(x) at B,
Beta>-1
OUTPUT PARAMETERS
State - structure which stores algorithm state
SEE ALSO
AutoGKSmooth, AutoGKSmoothW, AutoGKResults.
-- ALGLIB --
Copyright 06.05.2009 by Bochkanov Sergey
*************************************************************************/
</div><div style='margin-top: 0; margin-bottom: 0;'><b>void</b> alglib::autogksingular(
<b>double</b> a,
<b>double</b> b,
<b>double</b> alpha,
<b>double</b> beta,
autogkstate& state);
</div></pre>
<a name='sub_autogksmooth'></a><h3 class=pageheader><code>autogksmooth</code> function</h3>
<pre class=source>
<div style='color: navy; margin-top: 0; margin-bottom: 0;'>/*************************************************************************
Integration of a smooth function F(x) on a finite interval [a,b].
Fast-convergent algorithm based on a Gauss-Kronrod formula is used. Result
is calculated with accuracy close to the machine precision.
Algorithm works well only with smooth integrands. It may be used with
continuous non-smooth integrands, but with less performance.
It should never be used with integrands which have integrable singularities
at lower or upper limits - algorithm may crash. Use AutoGKSingular in such
cases.
INPUT PARAMETERS:
A, B - interval boundaries (A<B, A=B or A>B)
OUTPUT PARAMETERS
State - structure which stores algorithm state
SEE ALSO
AutoGKSmoothW, AutoGKSingular, AutoGKResults.
-- ALGLIB --
Copyright 06.05.2009 by Bochkanov Sergey
*************************************************************************/
</div><div style='margin-top: 0; margin-bottom: 0;'><b>void</b> alglib::autogksmooth(<b>double</b> a, <b>double</b> b, autogkstate& state);
</div></pre>
<p align=left class=pagecontent><span class=inlineheader>Examples:</span> <a href='#example_autogk_d1' class=nav>[1]</a> </p>
<a name='sub_autogksmoothw'></a><h3 class=pageheader><code>autogksmoothw</code> function</h3>
<pre class=source>
<div style='color: navy; margin-top: 0; margin-bottom: 0;'>/*************************************************************************
Integration of a smooth function F(x) on a finite interval [a,b].
This subroutine is same as AutoGKSmooth(), but it guarantees that interval
[a,b] is partitioned into subintervals which have width at most XWidth.
Subroutine can be used when integrating nearly-constant function with
narrow "bumps" (about XWidth wide). If "bumps" are too narrow, AutoGKSmooth
subroutine can overlook them.
INPUT PARAMETERS:
A, B - interval boundaries (A<B, A=B or A>B)
OUTPUT PARAMETERS
State - structure which stores algorithm state
SEE ALSO
AutoGKSmooth, AutoGKSingular, AutoGKResults.
-- ALGLIB --
Copyright 06.05.2009 by Bochkanov Sergey
*************************************************************************/
</div><div style='margin-top: 0; margin-bottom: 0;'><b>void</b> alglib::autogksmoothw(
<b>double</b> a,
<b>double</b> b,
<b>double</b> xwidth,
autogkstate& state);
</div></pre>
<a name='example_autogk_d1'></a><h3 class=pageheader>autogk_d1 example</h3>
<pre class=source>
#include <font color=blue><b>"stdafx.h"</b></font>
#include <stdlib.h>
#include <stdio.h>
#include <math.h>
#include <font color=blue><b>"integration.h"</b></font>
using namespace alglib;
<b>void</b> int_function_1_func(<b>double</b> x, <b>double</b> xminusa, <b>double</b> bminusx, <b>double</b> &y, <b>void</b> *ptr)
{
<font color=navy>// this callback calculates f(x)=exp(x)</font>
y = exp(x);
}
<b>int</b> main(<b>int</b> argc, char **argv)
{
<font color=navy>//</font>
<font color=navy>// This example demonstrates integration of f=exp(x) on [0,1]:</font>
<font color=navy>// * first, autogkstate is initialized</font>
<font color=navy>// * then we call integration function</font>
<font color=navy>// * and finally we obtain results with autogkresults() call</font>
<font color=navy>//</font>
<b>double</b> a = 0;
<b>double</b> b = 1;
autogkstate s;
<b>double</b> v;
autogkreport rep;
autogksmooth(a, b, s);
alglib::autogkintegrate(s, int_function_1_func);
autogkresults(s, v, rep);
printf(<font color=blue><b>"%.2f\n"</b></font>, <b>double</b>(v)); <font color=navy>// EXPECTED: 1.7182</font>
<b>return</b> 0;
}
</pre><a name=unit_basestat></a><h2 class=pageheader><code>basestat</code> subpackage</h2>
<div class=pagecontent>
<h3 class=pageheader>Functions</h3>
<a href='#sub_cov2' class=toc>cov2</a><br>
<a href='#sub_covm' class=toc>covm</a><br>
<a href='#sub_covm2' class=toc>covm2</a><br>
<a href='#sub_pearsoncorr2' class=toc>pearsoncorr2</a><br>
<a href='#sub_pearsoncorrelation' class=toc>pearsoncorrelation</a><br>
<a href='#sub_pearsoncorrm' class=toc>pearsoncorrm</a><br>
<a href='#sub_pearsoncorrm2' class=toc>pearsoncorrm2</a><br>
<a href='#sub_rankdata' class=toc>rankdata</a><br>
<a href='#sub_rankdatacentered' class=toc>rankdatacentered</a><br>
<a href='#sub_sampleadev' class=toc>sampleadev</a><br>
<a href='#sub_samplekurtosis' class=toc>samplekurtosis</a><br>
<a href='#sub_samplemean' class=toc>samplemean</a><br>
<a href='#sub_samplemedian' class=toc>samplemedian</a><br>
<a href='#sub_samplemoments' class=toc>samplemoments</a><br>
<a href='#sub_samplepercentile' class=toc>samplepercentile</a><br>
<a href='#sub_sampleskewness' class=toc>sampleskewness</a><br>
<a href='#sub_samplevariance' class=toc>samplevariance</a><br>
<a href='#sub_spearmancorr2' class=toc>spearmancorr2</a><br>
<a href='#sub_spearmancorrm' class=toc>spearmancorrm</a><br>
<a href='#sub_spearmancorrm2' class=toc>spearmancorrm2</a><br>
<a href='#sub_spearmanrankcorrelation' class=toc>spearmanrankcorrelation</a><br>
<h3 class=pageheader>Examples</h3>
<table border=0 cellspacing=0 class='pagecontent'>
<tr align=left valign=top><td><a href='#example_basestat_d_base' class=toc>basestat_d_base</a></td><td width=15> </td><td>Basic functionality (moments, adev, median, percentile)</td></tr>
<tr align=left valign=top><td><a href='#example_basestat_d_c2' class=toc>basestat_d_c2</a></td><td width=15> </td><td>Correlation (covariance) between two random variables</td></tr>
<tr align=left valign=top><td><a href='#example_basestat_d_cm' class=toc>basestat_d_cm</a></td><td width=15> </td><td>Correlation (covariance) between components of random vector</td></tr>
<tr align=left valign=top><td><a href='#example_basestat_d_cm2' class=toc>basestat_d_cm2</a></td><td width=15> </td><td>Correlation (covariance) between two random vectors</td></tr>
</table></div>
<a name='sub_cov2'></a><h3 class=pageheader><code>cov2</code> function</h3>
<pre class=source>
<div style='color: navy; margin-top: 0; margin-bottom: 0;'>/*************************************************************************
2-sample covariance
Input parameters:
X - sample 1 (array indexes: [0..N-1])
Y - sample 2 (array indexes: [0..N-1])
N - N>=0, sample size:
* if given, only N leading elements of X/Y are processed
* if not given, automatically determined from input sizes
Result:
covariance (zero for N=0 or N=1)
-- ALGLIB --
Copyright 28.10.2010 by Bochkanov Sergey
*************************************************************************/
</div><div style='margin-top: 0; margin-bottom: 0;'><b>double</b> alglib::cov2(real_1d_array x, real_1d_array y);
<b>double</b> alglib::cov2(real_1d_array x, real_1d_array y, ae_int_t n);
</div></pre>
<p align=left class=pagecontent><span class=inlineheader>Examples:</span> <a href='#example_basestat_d_c2' class=nav>[1]</a> </p>
<a name='sub_covm'></a><h3 class=pageheader><code>covm</code> function</h3>
<pre class=source>
<div style='color: navy; margin-top: 0; margin-bottom: 0;'>/*************************************************************************
Covariance matrix
SMP EDITION OF ALGLIB:
! This function can utilize multicore capabilities of your system. In
! order to do this you have to call version with "smp_" prefix, which
! indicates that multicore code will be used.
!
! This note is given for users of SMP edition; if you use GPL edition,
! or commercial edition of ALGLIB without SMP support, you still will
! be able to call smp-version of this function, but all computations
! will be done serially.
!
! We recommend you to carefully read ALGLIB Reference Manual, section
! called 'SMP support', before using parallel version of this function.
!
! You should remember that starting/stopping worker thread always have
! non-zero cost. Although multicore version is pretty efficient on
! large problems, we do not recommend you to use it on small problems -
! with covariance matrices smaller than 128*128.
INPUT PARAMETERS:
X - array[N,M], sample matrix:
* J-th column corresponds to J-th variable
* I-th row corresponds to I-th observation
N - N>=0, number of observations:
* if given, only leading N rows of X are used
* if not given, automatically determined from input size
M - M>0, number of variables:
* if given, only leading M columns of X are used
* if not given, automatically determined from input size
OUTPUT PARAMETERS:
C - array[M,M], covariance matrix (zero if N=0 or N=1)
-- ALGLIB --
Copyright 28.10.2010 by Bochkanov Sergey
*************************************************************************/
</div><div style='margin-top: 0; margin-bottom: 0;'><b>void</b> alglib::covm(real_2d_array x, real_2d_array& c);
<b>void</b> alglib::covm(
real_2d_array x,
ae_int_t n,
ae_int_t m,
real_2d_array& c);
<b>void</b> alglib::smp_covm(real_2d_array x, real_2d_array& c);
<b>void</b> alglib::smp_covm(
real_2d_array x,
ae_int_t n,
ae_int_t m,
real_2d_array& c);
</div></pre>
<p align=left class=pagecontent><span class=inlineheader>Examples:</span> <a href='#example_basestat_d_cm' class=nav>[1]</a> </p>
<a name='sub_covm2'></a><h3 class=pageheader><code>covm2</code> function</h3>
<pre class=source>
<div style='color: navy; margin-top: 0; margin-bottom: 0;'>/*************************************************************************
Cross-covariance matrix
SMP EDITION OF ALGLIB:
! This function can utilize multicore capabilities of your system. In
! order to do this you have to call version with "smp_" prefix, which
! indicates that multicore code will be used.
!
! This note is given for users of SMP edition; if you use GPL edition,
! or commercial edition of ALGLIB without SMP support, you still will
! be able to call smp-version of this function, but all computations
! will be done serially.
!
! We recommend you to carefully read ALGLIB Reference Manual, section
! called 'SMP support', before using parallel version of this function.
!
! You should remember that starting/stopping worker thread always have
! non-zero cost. Although multicore version is pretty efficient on
! large problems, we do not recommend you to use it on small problems -
! with covariance matrices smaller than 128*128.
INPUT PARAMETERS:
X - array[N,M1], sample matrix:
* J-th column corresponds to J-th variable
* I-th row corresponds to I-th observation
Y - array[N,M2], sample matrix:
* J-th column corresponds to J-th variable
* I-th row corresponds to I-th observation
N - N>=0, number of observations:
* if given, only leading N rows of X/Y are used
* if not given, automatically determined from input sizes
M1 - M1>0, number of variables in X:
* if given, only leading M1 columns of X are used
* if not given, automatically determined from input size
M2 - M2>0, number of variables in Y:
* if given, only leading M1 columns of X are used
* if not given, automatically determined from input size
OUTPUT PARAMETERS:
C - array[M1,M2], cross-covariance matrix (zero if N=0 or N=1)
-- ALGLIB --
Copyright 28.10.2010 by Bochkanov Sergey
*************************************************************************/
</div><div style='margin-top: 0; margin-bottom: 0;'><b>void</b> alglib::covm2(real_2d_array x, real_2d_array y, real_2d_array& c);
<b>void</b> alglib::covm2(
real_2d_array x,
real_2d_array y,
ae_int_t n,
ae_int_t m1,
ae_int_t m2,
real_2d_array& c);
<b>void</b> alglib::smp_covm2(real_2d_array x, real_2d_array y, real_2d_array& c);
<b>void</b> alglib::smp_covm2(
real_2d_array x,
real_2d_array y,
ae_int_t n,
ae_int_t m1,
ae_int_t m2,
real_2d_array& c);
</div></pre>
<p align=left class=pagecontent><span class=inlineheader>Examples:</span> <a href='#example_basestat_d_cm2' class=nav>[1]</a> </p>
<a name='sub_pearsoncorr2'></a><h3 class=pageheader><code>pearsoncorr2</code> function</h3>
<pre class=source>
<div style='color: navy; margin-top: 0; margin-bottom: 0;'>/*************************************************************************
Pearson product-moment correlation coefficient
Input parameters:
X - sample 1 (array indexes: [0..N-1])
Y - sample 2 (array indexes: [0..N-1])
N - N>=0, sample size:
* if given, only N leading elements of X/Y are processed
* if not given, automatically determined from input sizes
Result:
Pearson product-moment correlation coefficient
(zero for N=0 or N=1)
-- ALGLIB --
Copyright 28.10.2010 by Bochkanov Sergey
*************************************************************************/
</div><div style='margin-top: 0; margin-bottom: 0;'><b>double</b> alglib::pearsoncorr2(real_1d_array x, real_1d_array y);
<b>double</b> alglib::pearsoncorr2(real_1d_array x, real_1d_array y, ae_int_t n);
</div></pre>
<p align=left class=pagecontent><span class=inlineheader>Examples:</span> <a href='#example_basestat_d_c2' class=nav>[1]</a> </p>
<a name='sub_pearsoncorrelation'></a><h3 class=pageheader><code>pearsoncorrelation</code> function</h3>
<pre class=source>
<div style='color: navy; margin-top: 0; margin-bottom: 0;'>/*************************************************************************
Obsolete function, we recommend to use PearsonCorr2().
-- ALGLIB --
Copyright 09.04.2007 by Bochkanov Sergey
*************************************************************************/
</div><div style='margin-top: 0; margin-bottom: 0;'><b>double</b> alglib::pearsoncorrelation(
real_1d_array x,
real_1d_array y,
ae_int_t n);
</div></pre>
<a name='sub_pearsoncorrm'></a><h3 class=pageheader><code>pearsoncorrm</code> function</h3>
<pre class=source>
<div style='color: navy; margin-top: 0; margin-bottom: 0;'>/*************************************************************************
Pearson product-moment correlation matrix
SMP EDITION OF ALGLIB:
! This function can utilize multicore capabilities of your system. In
! order to do this you have to call version with "smp_" prefix, which
! indicates that multicore code will be used.
!
! This note is given for users of SMP edition; if you use GPL edition,
! or commercial edition of ALGLIB without SMP support, you still will
! be able to call smp-version of this function, but all computations
! will be done serially.
!
! We recommend you to carefully read ALGLIB Reference Manual, section
! called 'SMP support', before using parallel version of this function.
!
! You should remember that starting/stopping worker thread always have
! non-zero cost. Although multicore version is pretty efficient on
! large problems, we do not recommend you to use it on small problems -
! with correlation matrices smaller than 128*128.
INPUT PARAMETERS:
X - array[N,M], sample matrix:
* J-th column corresponds to J-th variable
* I-th row corresponds to I-th observation
N - N>=0, number of observations:
* if given, only leading N rows of X are used
* if not given, automatically determined from input size
M - M>0, number of variables:
* if given, only leading M columns of X are used
* if not given, automatically determined from input size
OUTPUT PARAMETERS:
C - array[M,M], correlation matrix (zero if N=0 or N=1)
-- ALGLIB --
Copyright 28.10.2010 by Bochkanov Sergey
*************************************************************************/
</div><div style='margin-top: 0; margin-bottom: 0;'><b>void</b> alglib::pearsoncorrm(real_2d_array x, real_2d_array& c);
<b>void</b> alglib::pearsoncorrm(
real_2d_array x,
ae_int_t n,
ae_int_t m,
real_2d_array& c);
<b>void</b> alglib::smp_pearsoncorrm(real_2d_array x, real_2d_array& c);
<b>void</b> alglib::smp_pearsoncorrm(
real_2d_array x,
ae_int_t n,
ae_int_t m,
real_2d_array& c);
</div></pre>
<p align=left class=pagecontent><span class=inlineheader>Examples:</span> <a href='#example_basestat_d_cm' class=nav>[1]</a> </p>
<a name='sub_pearsoncorrm2'></a><h3 class=pageheader><code>pearsoncorrm2</code> function</h3>
<pre class=source>
<div style='color: navy; margin-top: 0; margin-bottom: 0;'>/*************************************************************************
Pearson product-moment cross-correlation matrix
SMP EDITION OF ALGLIB:
! This function can utilize multicore capabilities of your system. In
! order to do this you have to call version with "smp_" prefix, which
! indicates that multicore code will be used.
!
! This note is given for users of SMP edition; if you use GPL edition,
! or commercial edition of ALGLIB without SMP support, you still will
! be able to call smp-version of this function, but all computations
! will be done serially.
!
! We recommend you to carefully read ALGLIB Reference Manual, section
! called 'SMP support', before using parallel version of this function.
!
! You should remember that starting/stopping worker thread always have
! non-zero cost. Although multicore version is pretty efficient on
! large problems, we do not recommend you to use it on small problems -
! with correlation matrices smaller than 128*128.
INPUT PARAMETERS:
X - array[N,M1], sample matrix:
* J-th column corresponds to J-th variable
* I-th row corresponds to I-th observation
Y - array[N,M2], sample matrix:
* J-th column corresponds to J-th variable
* I-th row corresponds to I-th observation
N - N>=0, number of observations:
* if given, only leading N rows of X/Y are used
* if not given, automatically determined from input sizes
M1 - M1>0, number of variables in X:
* if given, only leading M1 columns of X are used
* if not given, automatically determined from input size
M2 - M2>0, number of variables in Y:
* if given, only leading M1 columns of X are used
* if not given, automatically determined from input size
OUTPUT PARAMETERS:
C - array[M1,M2], cross-correlation matrix (zero if N=0 or N=1)
-- ALGLIB --
Copyright 28.10.2010 by Bochkanov Sergey
*************************************************************************/
</div><div style='margin-top: 0; margin-bottom: 0;'><b>void</b> alglib::pearsoncorrm2(
real_2d_array x,
real_2d_array y,
real_2d_array& c);
<b>void</b> alglib::pearsoncorrm2(
real_2d_array x,
real_2d_array y,
ae_int_t n,
ae_int_t m1,
ae_int_t m2,
real_2d_array& c);
<b>void</b> alglib::smp_pearsoncorrm2(
real_2d_array x,
real_2d_array y,
real_2d_array& c);
<b>void</b> alglib::smp_pearsoncorrm2(
real_2d_array x,
real_2d_array y,
ae_int_t n,
ae_int_t m1,
ae_int_t m2,
real_2d_array& c);
</div></pre>
<p align=left class=pagecontent><span class=inlineheader>Examples:</span> <a href='#example_basestat_d_cm2' class=nav>[1]</a> </p>
<a name='sub_rankdata'></a><h3 class=pageheader><code>rankdata</code> function</h3>
<pre class=source>
<div style='color: navy; margin-top: 0; margin-bottom: 0;'>/*************************************************************************
This function replaces data in XY by their ranks:
* XY is processed row-by-row
* rows are processed separately
* tied data are correctly handled (tied ranks are calculated)
* ranking starts from 0, ends at NFeatures-1
* sum of within-row values is equal to (NFeatures-1)*NFeatures/2
SMP EDITION OF ALGLIB:
! This function can utilize multicore capabilities of your system. In
! order to do this you have to call version with "smp_" prefix, which
! indicates that multicore code will be used.
!
! This note is given for users of SMP edition; if you use GPL edition,
! or commercial edition of ALGLIB without SMP support, you still will
! be able to call smp-version of this function, but all computations
! will be done serially.
!
! We recommend you to carefully read ALGLIB Reference Manual, section
! called 'SMP support', before using parallel version of this function.
!
! You should remember that starting/stopping worker thread always have
! non-zero cost. Although multicore version is pretty efficient on
! large problems, we do not recommend you to use it on small problems -
! ones where expected operations count is less than 100.000
INPUT PARAMETERS:
XY - array[NPoints,NFeatures], dataset
NPoints - number of points
NFeatures- number of features
OUTPUT PARAMETERS:
XY - data are replaced by their within-row ranks;
ranking starts from 0, ends at NFeatures-1
-- ALGLIB --
Copyright 18.04.2013 by Bochkanov Sergey
*************************************************************************/
</div><div style='margin-top: 0; margin-bottom: 0;'><b>void</b> alglib::rankdata(real_2d_array& xy);
<b>void</b> alglib::rankdata(
real_2d_array& xy,
ae_int_t npoints,
ae_int_t nfeatures);
<b>void</b> alglib::smp_rankdata(real_2d_array& xy);
<b>void</b> alglib::smp_rankdata(
real_2d_array& xy,
ae_int_t npoints,
ae_int_t nfeatures);
</div></pre>
<a name='sub_rankdatacentered'></a><h3 class=pageheader><code>rankdatacentered</code> function</h3>
<pre class=source>
<div style='color: navy; margin-top: 0; margin-bottom: 0;'>/*************************************************************************
This function replaces data in XY by their CENTERED ranks:
* XY is processed row-by-row
* rows are processed separately
* tied data are correctly handled (tied ranks are calculated)
* centered ranks are just usual ranks, but centered in such way that sum
of within-row values is equal to 0.0.
* centering is performed by subtracting mean from each row, i.e it changes
mean value, but does NOT change higher moments
SMP EDITION OF ALGLIB:
! This function can utilize multicore capabilities of your system. In
! order to do this you have to call version with "smp_" prefix, which
! indicates that multicore code will be used.
!
! This note is given for users of SMP edition; if you use GPL edition,
! or commercial edition of ALGLIB without SMP support, you still will
! be able to call smp-version of this function, but all computations
! will be done serially.
!
! We recommend you to carefully read ALGLIB Reference Manual, section
! called 'SMP support', before using parallel version of this function.
!
! You should remember that starting/stopping worker thread always have
! non-zero cost. Although multicore version is pretty efficient on
! large problems, we do not recommend you to use it on small problems -
! ones where expected operations count is less than 100.000
INPUT PARAMETERS:
XY - array[NPoints,NFeatures], dataset
NPoints - number of points
NFeatures- number of features
OUTPUT PARAMETERS:
XY - data are replaced by their within-row ranks;
ranking starts from 0, ends at NFeatures-1
-- ALGLIB --
Copyright 18.04.2013 by Bochkanov Sergey
*************************************************************************/
</div><div style='margin-top: 0; margin-bottom: 0;'><b>void</b> alglib::rankdatacentered(real_2d_array& xy);
<b>void</b> alglib::rankdatacentered(
real_2d_array& xy,
ae_int_t npoints,
ae_int_t nfeatures);
<b>void</b> alglib::smp_rankdatacentered(real_2d_array& xy);
<b>void</b> alglib::smp_rankdatacentered(
real_2d_array& xy,
ae_int_t npoints,
ae_int_t nfeatures);
</div></pre>
<a name='sub_sampleadev'></a><h3 class=pageheader><code>sampleadev</code> function</h3>
<pre class=source>
<div style='color: navy; margin-top: 0; margin-bottom: 0;'>/*************************************************************************
ADev
Input parameters:
X - sample
N - N>=0, sample size:
* if given, only leading N elements of X are processed
* if not given, automatically determined from size of X
Output parameters:
ADev- ADev
-- ALGLIB --
Copyright 06.09.2006 by Bochkanov Sergey
*************************************************************************/
</div><div style='margin-top: 0; margin-bottom: 0;'><b>void</b> alglib::sampleadev(real_1d_array x, <b>double</b>& adev);
<b>void</b> alglib::sampleadev(real_1d_array x, ae_int_t n, <b>double</b>& adev);
</div></pre>
<p align=left class=pagecontent><span class=inlineheader>Examples:</span> <a href='#example_basestat_d_base' class=nav>[1]</a> </p>
<a name='sub_samplekurtosis'></a><h3 class=pageheader><code>samplekurtosis</code> function</h3>
<pre class=source>
<div style='color: navy; margin-top: 0; margin-bottom: 0;'>/*************************************************************************
Calculation of the kurtosis.
INPUT PARAMETERS:
X - sample
N - N>=0, sample size:
* if given, only leading N elements of X are processed
* if not given, automatically determined from size of X
NOTE:
This function return result which calculated by 'SampleMoments' function
and stored at 'Kurtosis' variable.
-- ALGLIB --
Copyright 06.09.2006 by Bochkanov Sergey
*************************************************************************/
</div><div style='margin-top: 0; margin-bottom: 0;'><b>double</b> alglib::samplekurtosis(real_1d_array x);
<b>double</b> alglib::samplekurtosis(real_1d_array x, ae_int_t n);
</div></pre>
<a name='sub_samplemean'></a><h3 class=pageheader><code>samplemean</code> function</h3>
<pre class=source>
<div style='color: navy; margin-top: 0; margin-bottom: 0;'>/*************************************************************************
Calculation of the mean.
INPUT PARAMETERS:
X - sample
N - N>=0, sample size:
* if given, only leading N elements of X are processed
* if not given, automatically determined from size of X
NOTE:
This function return result which calculated by 'SampleMoments' function
and stored at 'Mean' variable.
-- ALGLIB --
Copyright 06.09.2006 by Bochkanov Sergey
*************************************************************************/
</div><div style='margin-top: 0; margin-bottom: 0;'><b>double</b> alglib::samplemean(real_1d_array x);
<b>double</b> alglib::samplemean(real_1d_array x, ae_int_t n);
</div></pre>
<a name='sub_samplemedian'></a><h3 class=pageheader><code>samplemedian</code> function</h3>
<pre class=source>
<div style='color: navy; margin-top: 0; margin-bottom: 0;'>/*************************************************************************
Median calculation.
Input parameters:
X - sample (array indexes: [0..N-1])
N - N>=0, sample size:
* if given, only leading N elements of X are processed
* if not given, automatically determined from size of X
Output parameters:
Median
-- ALGLIB --
Copyright 06.09.2006 by Bochkanov Sergey
*************************************************************************/
</div><div style='margin-top: 0; margin-bottom: 0;'><b>void</b> alglib::samplemedian(real_1d_array x, <b>double</b>& median);
<b>void</b> alglib::samplemedian(real_1d_array x, ae_int_t n, <b>double</b>& median);
</div></pre>
<p align=left class=pagecontent><span class=inlineheader>Examples:</span> <a href='#example_basestat_d_base' class=nav>[1]</a> </p>
<a name='sub_samplemoments'></a><h3 class=pageheader><code>samplemoments</code> function</h3>
<pre class=source>
<div style='color: navy; margin-top: 0; margin-bottom: 0;'>/*************************************************************************
Calculation of the distribution moments: mean, variance, skewness, kurtosis.
INPUT PARAMETERS:
X - sample
N - N>=0, sample size:
* if given, only leading N elements of X are processed
* if not given, automatically determined from size of X
OUTPUT PARAMETERS
Mean - mean.
Variance- variance.
Skewness- skewness (if variance<>0; zero otherwise).
Kurtosis- kurtosis (if variance<>0; zero otherwise).
NOTE: variance is calculated by dividing sum of squares by N-1, not N.
-- ALGLIB --
Copyright 06.09.2006 by Bochkanov Sergey
*************************************************************************/
</div><div style='margin-top: 0; margin-bottom: 0;'><b>void</b> alglib::samplemoments(
real_1d_array x,
<b>double</b>& mean,
<b>double</b>& variance,
<b>double</b>& skewness,
<b>double</b>& kurtosis);
<b>void</b> alglib::samplemoments(
real_1d_array x,
ae_int_t n,
<b>double</b>& mean,
<b>double</b>& variance,
<b>double</b>& skewness,
<b>double</b>& kurtosis);
</div></pre>
<p align=left class=pagecontent><span class=inlineheader>Examples:</span> <a href='#example_basestat_d_base' class=nav>[1]</a> </p>
<a name='sub_samplepercentile'></a><h3 class=pageheader><code>samplepercentile</code> function</h3>
<pre class=source>
<div style='color: navy; margin-top: 0; margin-bottom: 0;'>/*************************************************************************
Percentile calculation.
Input parameters:
X - sample (array indexes: [0..N-1])
N - N>=0, sample size:
* if given, only leading N elements of X are processed
* if not given, automatically determined from size of X
P - percentile (0<=P<=1)
Output parameters:
V - percentile
-- ALGLIB --
Copyright 01.03.2008 by Bochkanov Sergey
*************************************************************************/
</div><div style='margin-top: 0; margin-bottom: 0;'><b>void</b> alglib::samplepercentile(real_1d_array x, <b>double</b> p, <b>double</b>& v);
<b>void</b> alglib::samplepercentile(
real_1d_array x,
ae_int_t n,
<b>double</b> p,
<b>double</b>& v);
</div></pre>
<p align=left class=pagecontent><span class=inlineheader>Examples:</span> <a href='#example_basestat_d_base' class=nav>[1]</a> </p>
<a name='sub_sampleskewness'></a><h3 class=pageheader><code>sampleskewness</code> function</h3>
<pre class=source>
<div style='color: navy; margin-top: 0; margin-bottom: 0;'>/*************************************************************************
Calculation of the skewness.
INPUT PARAMETERS:
X - sample
N - N>=0, sample size:
* if given, only leading N elements of X are processed
* if not given, automatically determined from size of X
NOTE:
This function return result which calculated by 'SampleMoments' function
and stored at 'Skewness' variable.
-- ALGLIB --
Copyright 06.09.2006 by Bochkanov Sergey
*************************************************************************/
</div><div style='margin-top: 0; margin-bottom: 0;'><b>double</b> alglib::sampleskewness(real_1d_array x);
<b>double</b> alglib::sampleskewness(real_1d_array x, ae_int_t n);
</div></pre>
<a name='sub_samplevariance'></a><h3 class=pageheader><code>samplevariance</code> function</h3>
<pre class=source>
<div style='color: navy; margin-top: 0; margin-bottom: 0;'>/*************************************************************************
Calculation of the variance.
INPUT PARAMETERS:
X - sample
N - N>=0, sample size:
* if given, only leading N elements of X are processed
* if not given, automatically determined from size of X
NOTE:
This function return result which calculated by 'SampleMoments' function
and stored at 'Variance' variable.
-- ALGLIB --
Copyright 06.09.2006 by Bochkanov Sergey
*************************************************************************/
</div><div style='margin-top: 0; margin-bottom: 0;'><b>double</b> alglib::samplevariance(real_1d_array x);
<b>double</b> alglib::samplevariance(real_1d_array x, ae_int_t n);
</div></pre>
<a name='sub_spearmancorr2'></a><h3 class=pageheader><code>spearmancorr2</code> function</h3>
<pre class=source>
<div style='color: navy; margin-top: 0; margin-bottom: 0;'>/*************************************************************************
Spearman's rank correlation coefficient
Input parameters:
X - sample 1 (array indexes: [0..N-1])
Y - sample 2 (array indexes: [0..N-1])
N - N>=0, sample size:
* if given, only N leading elements of X/Y are processed
* if not given, automatically determined from input sizes
Result:
Spearman's rank correlation coefficient
(zero for N=0 or N=1)
-- ALGLIB --
Copyright 09.04.2007 by Bochkanov Sergey
*************************************************************************/
</div><div style='margin-top: 0; margin-bottom: 0;'><b>double</b> alglib::spearmancorr2(real_1d_array x, real_1d_array y);
<b>double</b> alglib::spearmancorr2(
real_1d_array x,
real_1d_array y,
ae_int_t n);
</div></pre>
<p align=left class=pagecontent><span class=inlineheader>Examples:</span> <a href='#example_basestat_d_c2' class=nav>[1]</a> </p>
<a name='sub_spearmancorrm'></a><h3 class=pageheader><code>spearmancorrm</code> function</h3>
<pre class=source>
<div style='color: navy; margin-top: 0; margin-bottom: 0;'>/*************************************************************************
Spearman's rank correlation matrix
SMP EDITION OF ALGLIB:
! This function can utilize multicore capabilities of your system. In
! order to do this you have to call version with "smp_" prefix, which
! indicates that multicore code will be used.
!
! This note is given for users of SMP edition; if you use GPL edition,
! or commercial edition of ALGLIB without SMP support, you still will
! be able to call smp-version of this function, but all computations
! will be done serially.
!
! We recommend you to carefully read ALGLIB Reference Manual, section
! called 'SMP support', before using parallel version of this function.
!
! You should remember that starting/stopping worker thread always have
! non-zero cost. Although multicore version is pretty efficient on
! large problems, we do not recommend you to use it on small problems -
! with correlation matrices smaller than 128*128.
INPUT PARAMETERS:
X - array[N,M], sample matrix:
* J-th column corresponds to J-th variable
* I-th row corresponds to I-th observation
N - N>=0, number of observations:
* if given, only leading N rows of X are used
* if not given, automatically determined from input size
M - M>0, number of variables:
* if given, only leading M columns of X are used
* if not given, automatically determined from input size
OUTPUT PARAMETERS:
C - array[M,M], correlation matrix (zero if N=0 or N=1)
-- ALGLIB --
Copyright 28.10.2010 by Bochkanov Sergey
*************************************************************************/
</div><div style='margin-top: 0; margin-bottom: 0;'><b>void</b> alglib::spearmancorrm(real_2d_array x, real_2d_array& c);
<b>void</b> alglib::spearmancorrm(
real_2d_array x,
ae_int_t n,
ae_int_t m,
real_2d_array& c);
<b>void</b> alglib::smp_spearmancorrm(real_2d_array x, real_2d_array& c);
<b>void</b> alglib::smp_spearmancorrm(
real_2d_array x,
ae_int_t n,
ae_int_t m,
real_2d_array& c);
</div></pre>
<p align=left class=pagecontent><span class=inlineheader>Examples:</span> <a href='#example_basestat_d_cm' class=nav>[1]</a> </p>
<a name='sub_spearmancorrm2'></a><h3 class=pageheader><code>spearmancorrm2</code> function</h3>
<pre class=source>
<div style='color: navy; margin-top: 0; margin-bottom: 0;'>/*************************************************************************
Spearman's rank cross-correlation matrix
SMP EDITION OF ALGLIB:
! This function can utilize multicore capabilities of your system. In
! order to do this you have to call version with "smp_" prefix, which
! indicates that multicore code will be used.
!
! This note is given for users of SMP edition; if you use GPL edition,
! or commercial edition of ALGLIB without SMP support, you still will
! be able to call smp-version of this function, but all computations
! will be done serially.
!
! We recommend you to carefully read ALGLIB Reference Manual, section
! called 'SMP support', before using parallel version of this function.
!
! You should remember that starting/stopping worker thread always have
! non-zero cost. Although multicore version is pretty efficient on
! large problems, we do not recommend you to use it on small problems -
! with correlation matrices smaller than 128*128.
INPUT PARAMETERS:
X - array[N,M1], sample matrix:
* J-th column corresponds to J-th variable
* I-th row corresponds to I-th observation
Y - array[N,M2], sample matrix:
* J-th column corresponds to J-th variable
* I-th row corresponds to I-th observation
N - N>=0, number of observations:
* if given, only leading N rows of X/Y are used
* if not given, automatically determined from input sizes
M1 - M1>0, number of variables in X:
* if given, only leading M1 columns of X are used
* if not given, automatically determined from input size
M2 - M2>0, number of variables in Y:
* if given, only leading M1 columns of X are used
* if not given, automatically determined from input size
OUTPUT PARAMETERS:
C - array[M1,M2], cross-correlation matrix (zero if N=0 or N=1)
-- ALGLIB --
Copyright 28.10.2010 by Bochkanov Sergey
*************************************************************************/
</div><div style='margin-top: 0; margin-bottom: 0;'><b>void</b> alglib::spearmancorrm2(
real_2d_array x,
real_2d_array y,
real_2d_array& c);
<b>void</b> alglib::spearmancorrm2(
real_2d_array x,
real_2d_array y,
ae_int_t n,
ae_int_t m1,
ae_int_t m2,
real_2d_array& c);
<b>void</b> alglib::smp_spearmancorrm2(
real_2d_array x,
real_2d_array y,
real_2d_array& c);
<b>void</b> alglib::smp_spearmancorrm2(
real_2d_array x,
real_2d_array y,
ae_int_t n,
ae_int_t m1,
ae_int_t m2,
real_2d_array& c);
</div></pre>
<p align=left class=pagecontent><span class=inlineheader>Examples:</span> <a href='#example_basestat_d_cm2' class=nav>[1]</a> </p>
<a name='sub_spearmanrankcorrelation'></a><h3 class=pageheader><code>spearmanrankcorrelation</code> function</h3>
<pre class=source>
<div style='color: navy; margin-top: 0; margin-bottom: 0;'>/*************************************************************************
Obsolete function, we recommend to use SpearmanCorr2().
-- ALGLIB --
Copyright 09.04.2007 by Bochkanov Sergey
*************************************************************************/
</div><div style='margin-top: 0; margin-bottom: 0;'><b>double</b> alglib::spearmanrankcorrelation(
real_1d_array x,
real_1d_array y,
ae_int_t n);
</div></pre>
<a name='example_basestat_d_base'></a><h3 class=pageheader>basestat_d_base example</h3>
<pre class=source>
#include <font color=blue><b>"stdafx.h"</b></font>
#include <stdlib.h>
#include <stdio.h>
#include <math.h>
#include <font color=blue><b>"statistics.h"</b></font>
using namespace alglib;
<b>int</b> main(<b>int</b> argc, char **argv)
{
real_1d_array x = <font color=blue><b>"[0,1,4,9,16,25,36,49,64,81]"</b></font>;
<b>double</b> mean;
<b>double</b> variance;
<b>double</b> skewness;
<b>double</b> kurtosis;
<b>double</b> adev;
<b>double</b> p;
<b>double</b> v;
<font color=navy>//</font>
<font color=navy>// Here we demonstrate calculation of sample moments</font>
<font color=navy>// (mean, variance, skewness, kurtosis)</font>
<font color=navy>//</font>
samplemoments(x, mean, variance, skewness, kurtosis);
printf(<font color=blue><b>"%.1f\n"</b></font>, <b>double</b>(mean)); <font color=navy>// EXPECTED: 28.5</font>
printf(<font color=blue><b>"%.1f\n"</b></font>, <b>double</b>(variance)); <font color=navy>// EXPECTED: 801.1667</font>
printf(<font color=blue><b>"%.1f\n"</b></font>, <b>double</b>(skewness)); <font color=navy>// EXPECTED: 0.5751</font>
printf(<font color=blue><b>"%.1f\n"</b></font>, <b>double</b>(kurtosis)); <font color=navy>// EXPECTED: -1.2666</font>
<font color=navy>//</font>
<font color=navy>// Average deviation</font>
<font color=navy>//</font>
sampleadev(x, adev);
printf(<font color=blue><b>"%.1f\n"</b></font>, <b>double</b>(adev)); <font color=navy>// EXPECTED: 23.2</font>
<font color=navy>//</font>
<font color=navy>// Median and percentile</font>
<font color=navy>//</font>
samplemedian(x, v);
printf(<font color=blue><b>"%.1f\n"</b></font>, <b>double</b>(v)); <font color=navy>// EXPECTED: 20.5</font>
p = 0.5;
samplepercentile(x, p, v);
printf(<font color=blue><b>"%.1f\n"</b></font>, <b>double</b>(v)); <font color=navy>// EXPECTED: 20.5</font>
<b>return</b> 0;
}
</pre><a name='example_basestat_d_c2'></a><h3 class=pageheader>basestat_d_c2 example</h3>
<pre class=source>
#include <font color=blue><b>"stdafx.h"</b></font>
#include <stdlib.h>
#include <stdio.h>
#include <math.h>
#include <font color=blue><b>"statistics.h"</b></font>
using namespace alglib;
<b>int</b> main(<b>int</b> argc, char **argv)
{
<font color=navy>//</font>
<font color=navy>// We have two samples - x and y, and want to measure dependency between them</font>
<font color=navy>//</font>
real_1d_array x = <font color=blue><b>"[0,1,4,9,16,25,36,49,64,81]"</b></font>;
real_1d_array y = <font color=blue><b>"[0,1,2,3,4,5,6,7,8,9]"</b></font>;
<b>double</b> v;
<font color=navy>//</font>
<font color=navy>// Three dependency measures are calculated:</font>
<font color=navy>// * covariation</font>
<font color=navy>// * Pearson correlation</font>
<font color=navy>// * Spearman rank correlation</font>
<font color=navy>//</font>
v = cov2(x, y);
printf(<font color=blue><b>"%.2f\n"</b></font>, <b>double</b>(v)); <font color=navy>// EXPECTED: 82.5</font>
v = pearsoncorr2(x, y);
printf(<font color=blue><b>"%.2f\n"</b></font>, <b>double</b>(v)); <font color=navy>// EXPECTED: 0.9627</font>
v = spearmancorr2(x, y);
printf(<font color=blue><b>"%.2f\n"</b></font>, <b>double</b>(v)); <font color=navy>// EXPECTED: 1.000</font>
<b>return</b> 0;
}
</pre><a name='example_basestat_d_cm'></a><h3 class=pageheader>basestat_d_cm example</h3>
<pre class=source>
#include <font color=blue><b>"stdafx.h"</b></font>
#include <stdlib.h>
#include <stdio.h>
#include <math.h>
#include <font color=blue><b>"statistics.h"</b></font>
using namespace alglib;
<b>int</b> main(<b>int</b> argc, char **argv)
{
<font color=navy>//</font>
<font color=navy>// X is a sample matrix:</font>
<font color=navy>// * I-th row corresponds to I-th observation</font>
<font color=navy>// * J-th column corresponds to J-th variable</font>
<font color=navy>//</font>
real_2d_array x = <font color=blue><b>"[[1,0,1],[1,1,0],[-1,1,0],[-2,-1,1],[-1,0,9]]"</b></font>;
real_2d_array c;
<font color=navy>//</font>
<font color=navy>// Three dependency measures are calculated:</font>
<font color=navy>// * covariation</font>
<font color=navy>// * Pearson correlation</font>
<font color=navy>// * Spearman rank correlation</font>
<font color=navy>//</font>
<font color=navy>// Result is stored into C, with C[i,j] equal to correlation</font>
<font color=navy>// (covariance) between I-th and J-th variables of X.</font>
<font color=navy>//</font>
covm(x, c);
printf(<font color=blue><b>"%s\n"</b></font>, c.tostring(1).c_str()); <font color=navy>// EXPECTED: [[1.80,0.60,-1.40],[0.60,0.70,-0.80],[-1.40,-0.80,14.70]]</font>
pearsoncorrm(x, c);
printf(<font color=blue><b>"%s\n"</b></font>, c.tostring(1).c_str()); <font color=navy>// EXPECTED: [[1.000,0.535,-0.272],[0.535,1.000,-0.249],[-0.272,-0.249,1.000]]</font>
spearmancorrm(x, c);
printf(<font color=blue><b>"%s\n"</b></font>, c.tostring(1).c_str()); <font color=navy>// EXPECTED: [[1.000,0.556,-0.306],[0.556,1.000,-0.750],[-0.306,-0.750,1.000]]</font>
<b>return</b> 0;
}
</pre><a name='example_basestat_d_cm2'></a><h3 class=pageheader>basestat_d_cm2 example</h3>
<pre class=source>
#include <font color=blue><b>"stdafx.h"</b></font>
#include <stdlib.h>
#include <stdio.h>
#include <math.h>
#include <font color=blue><b>"statistics.h"</b></font>
using namespace alglib;
<b>int</b> main(<b>int</b> argc, char **argv)
{
<font color=navy>//</font>
<font color=navy>// X and Y are sample matrices:</font>
<font color=navy>// * I-th row corresponds to I-th observation</font>
<font color=navy>// * J-th column corresponds to J-th variable</font>
<font color=navy>//</font>
real_2d_array x = <font color=blue><b>"[[1,0,1],[1,1,0],[-1,1,0],[-2,-1,1],[-1,0,9]]"</b></font>;
real_2d_array y = <font color=blue><b>"[[2,3],[2,1],[-1,6],[-9,9],[7,1]]"</b></font>;
real_2d_array c;
<font color=navy>//</font>
<font color=navy>// Three dependency measures are calculated:</font>
<font color=navy>// * covariation</font>
<font color=navy>// * Pearson correlation</font>
<font color=navy>// * Spearman rank correlation</font>
<font color=navy>//</font>
<font color=navy>// Result is stored into C, with C[i,j] equal to correlation</font>
<font color=navy>// (covariance) between I-th variable of X and J-th variable of Y.</font>
<font color=navy>//</font>
covm2(x, y, c);
printf(<font color=blue><b>"%s\n"</b></font>, c.tostring(1).c_str()); <font color=navy>// EXPECTED: [[4.100,-3.250],[2.450,-1.500],[13.450,-5.750]]</font>
pearsoncorrm2(x, y, c);
printf(<font color=blue><b>"%s\n"</b></font>, c.tostring(1).c_str()); <font color=navy>// EXPECTED: [[0.519,-0.699],[0.497,-0.518],[0.596,-0.433]]</font>
spearmancorrm2(x, y, c);
printf(<font color=blue><b>"%s\n"</b></font>, c.tostring(1).c_str()); <font color=navy>// EXPECTED: [[0.541,-0.649],[0.216,-0.433],[0.433,-0.135]]</font>
<b>return</b> 0;
}
</pre><a name=unit_bdss></a><h2 class=pageheader><code>bdss</code> subpackage</h2>
<div class=pagecontent>
<h3 class=pageheader>Functions</h3>
<a href='#sub_dsoptimalsplit2' class=toc>dsoptimalsplit2</a><br>
<a href='#sub_dsoptimalsplit2fast' class=toc>dsoptimalsplit2fast</a><br>
<h3 class=pageheader>Examples</h3>
<table border=0 cellspacing=0 class='pagecontent'>
</table></div>
<a name='sub_dsoptimalsplit2'></a><h3 class=pageheader><code>dsoptimalsplit2</code> function</h3>
<pre class=source>
<div style='color: navy; margin-top: 0; margin-bottom: 0;'>/*************************************************************************
Optimal binary classification
Algorithms finds optimal (=with minimal cross-entropy) binary partition.
Internal subroutine.
INPUT PARAMETERS:
A - array[0..N-1], variable
C - array[0..N-1], class numbers (0 or 1).
N - array size
OUTPUT PARAMETERS:
Info - completetion code:
* -3, all values of A[] are same (partition is impossible)
* -2, one of C[] is incorrect (<0, >1)
* -1, incorrect pararemets were passed (N<=0).
* 1, OK
Threshold- partiton boundary. Left part contains values which are
strictly less than Threshold. Right part contains values
which are greater than or equal to Threshold.
PAL, PBL- probabilities P(0|v<Threshold) and P(1|v<Threshold)
PAR, PBR- probabilities P(0|v>=Threshold) and P(1|v>=Threshold)
CVE - cross-validation estimate of cross-entropy
-- ALGLIB --
Copyright 22.05.2008 by Bochkanov Sergey
*************************************************************************/
</div><div style='margin-top: 0; margin-bottom: 0;'><b>void</b> alglib::dsoptimalsplit2(
real_1d_array a,
integer_1d_array c,
ae_int_t n,
ae_int_t& info,
<b>double</b>& threshold,
<b>double</b>& pal,
<b>double</b>& pbl,
<b>double</b>& par,
<b>double</b>& pbr,
<b>double</b>& cve);
</div></pre>
<a name='sub_dsoptimalsplit2fast'></a><h3 class=pageheader><code>dsoptimalsplit2fast</code> function</h3>
<pre class=source>
<div style='color: navy; margin-top: 0; margin-bottom: 0;'>/*************************************************************************
Optimal partition, internal subroutine. Fast version.
Accepts:
A array[0..N-1] array of attributes array[0..N-1]
C array[0..N-1] array of class labels
TiesBuf array[0..N] temporaries (ties)
CntBuf array[0..2*NC-1] temporaries (counts)
Alpha centering factor (0<=alpha<=1, recommended value - 0.05)
BufR array[0..N-1] temporaries
BufI array[0..N-1] temporaries
Output:
Info error code (">0"=OK, "<0"=bad)
RMS training set RMS error
CVRMS leave-one-out RMS error
Note:
content of all arrays is changed by subroutine;
it doesn't allocate temporaries.
-- ALGLIB --
Copyright 11.12.2008 by Bochkanov Sergey
*************************************************************************/
</div><div style='margin-top: 0; margin-bottom: 0;'><b>void</b> alglib::dsoptimalsplit2fast(
real_1d_array& a,
integer_1d_array& c,
integer_1d_array& tiesbuf,
integer_1d_array& cntbuf,
real_1d_array& bufr,
integer_1d_array& bufi,
ae_int_t n,
ae_int_t nc,
<b>double</b> alpha,
ae_int_t& info,
<b>double</b>& threshold,
<b>double</b>& rms,
<b>double</b>& cvrms);
</div></pre>
<a name=unit_bdsvd></a><h2 class=pageheader><code>bdsvd</code> subpackage</h2>
<div class=pagecontent>
<h3 class=pageheader>Functions</h3>
<a href='#sub_rmatrixbdsvd' class=toc>rmatrixbdsvd</a><br>
<h3 class=pageheader>Examples</h3>
<table border=0 cellspacing=0 class='pagecontent'>
</table></div>
<a name='sub_rmatrixbdsvd'></a><h3 class=pageheader><code>rmatrixbdsvd</code> function</h3>
<pre class=source>
<div style='color: navy; margin-top: 0; margin-bottom: 0;'>/*************************************************************************
Singular value decomposition of a bidiagonal matrix (extended algorithm)
COMMERCIAL EDITION OF ALGLIB:
! Commercial version of ALGLIB includes one important improvement of
! this function, which can be used from C++ and C#:
! * Intel MKL support (lightweight Intel MKL is shipped with ALGLIB)
!
! Intel MKL gives approximately constant (with respect to number of
! worker threads) acceleration factor which depends on CPU being used,
! problem size and "baseline" ALGLIB edition which is used for
! comparison.
!
! Generally, commercial ALGLIB is several times faster than open-source
! generic C edition, and many times faster than open-source C# edition.
!
! Multithreaded acceleration is NOT supported for this function.
!
! We recommend you to read 'Working with commercial version' section of
! ALGLIB Reference Manual in order to find out how to use performance-
! related features provided by commercial edition of ALGLIB.
The algorithm performs the singular value decomposition of a bidiagonal
matrix B (upper or lower) representing it as B = Q*S*P^T, where Q and P -
orthogonal matrices, S - diagonal matrix with non-negative elements on the
main diagonal, in descending order.
The algorithm finds singular values. In addition, the algorithm can
calculate matrices Q and P (more precisely, not the matrices, but their
product with given matrices U and VT - U*Q and (P^T)*VT)). Of course,
matrices U and VT can be of any type, including identity. Furthermore, the
algorithm can calculate Q'*C (this product is calculated more effectively
than U*Q, because this calculation operates with rows instead of matrix
columns).
The feature of the algorithm is its ability to find all singular values
including those which are arbitrarily close to 0 with relative accuracy
close to machine precision. If the parameter IsFractionalAccuracyRequired
is set to True, all singular values will have high relative accuracy close
to machine precision. If the parameter is set to False, only the biggest
singular value will have relative accuracy close to machine precision.
The absolute error of other singular values is equal to the absolute error
of the biggest singular value.
Input parameters:
D - main diagonal of matrix B.
Array whose index ranges within [0..N-1].
E - superdiagonal (or subdiagonal) of matrix B.
Array whose index ranges within [0..N-2].
N - size of matrix B.
IsUpper - True, if the matrix is upper bidiagonal.
IsFractionalAccuracyRequired -
THIS PARAMETER IS IGNORED SINCE ALGLIB 3.5.0
SINGULAR VALUES ARE ALWAYS SEARCHED WITH HIGH ACCURACY.
U - matrix to be multiplied by Q.
Array whose indexes range within [0..NRU-1, 0..N-1].
The matrix can be bigger, in that case only the submatrix
[0..NRU-1, 0..N-1] will be multiplied by Q.
NRU - number of rows in matrix U.
C - matrix to be multiplied by Q'.
Array whose indexes range within [0..N-1, 0..NCC-1].
The matrix can be bigger, in that case only the submatrix
[0..N-1, 0..NCC-1] will be multiplied by Q'.
NCC - number of columns in matrix C.
VT - matrix to be multiplied by P^T.
Array whose indexes range within [0..N-1, 0..NCVT-1].
The matrix can be bigger, in that case only the submatrix
[0..N-1, 0..NCVT-1] will be multiplied by P^T.
NCVT - number of columns in matrix VT.
Output parameters:
D - singular values of matrix B in descending order.
U - if NRU>0, contains matrix U*Q.
VT - if NCVT>0, contains matrix (P^T)*VT.
C - if NCC>0, contains matrix Q'*C.
Result:
True, if the algorithm has converged.
False, if the algorithm hasn't converged (rare case).
NOTE: multiplication U*Q is performed by means of transposition to internal
buffer, multiplication and backward transposition. It helps to avoid
costly columnwise operations and speed-up algorithm.
Additional information:
The type of convergence is controlled by the internal parameter TOL.
If the parameter is greater than 0, the singular values will have
relative accuracy TOL. If TOL<0, the singular values will have
absolute accuracy ABS(TOL)*norm(B).
By default, |TOL| falls within the range of 10*Epsilon and 100*Epsilon,
where Epsilon is the machine precision. It is not recommended to use
TOL less than 10*Epsilon since this will considerably slow down the
algorithm and may not lead to error decreasing.
History:
* 31 March, 2007.
changed MAXITR from 6 to 12.
-- LAPACK routine (version 3.0) --
Univ. of Tennessee, Univ. of California Berkeley, NAG Ltd.,
Courant Institute, Argonne National Lab, and Rice University
October 31, 1999.
*************************************************************************/
</div><div style='margin-top: 0; margin-bottom: 0;'><b>bool</b> alglib::rmatrixbdsvd(
real_1d_array& d,
real_1d_array e,
ae_int_t n,
<b>bool</b> isupper,
<b>bool</b> isfractionalaccuracyrequired,
real_2d_array& u,
ae_int_t nru,
real_2d_array& c,
ae_int_t ncc,
real_2d_array& vt,
ae_int_t ncvt);
</div></pre>
<a name=unit_bessel></a><h2 class=pageheader><code>bessel</code> subpackage</h2>
<div class=pagecontent>
<h3 class=pageheader>Functions</h3>
<a href='#sub_besseli0' class=toc>besseli0</a><br>
<a href='#sub_besseli1' class=toc>besseli1</a><br>
<a href='#sub_besselj0' class=toc>besselj0</a><br>
<a href='#sub_besselj1' class=toc>besselj1</a><br>
<a href='#sub_besseljn' class=toc>besseljn</a><br>
<a href='#sub_besselk0' class=toc>besselk0</a><br>
<a href='#sub_besselk1' class=toc>besselk1</a><br>
<a href='#sub_besselkn' class=toc>besselkn</a><br>
<a href='#sub_bessely0' class=toc>bessely0</a><br>
<a href='#sub_bessely1' class=toc>bessely1</a><br>
<a href='#sub_besselyn' class=toc>besselyn</a><br>
<h3 class=pageheader>Examples</h3>
<table border=0 cellspacing=0 class='pagecontent'>
</table></div>
<a name='sub_besseli0'></a><h3 class=pageheader><code>besseli0</code> function</h3>
<pre class=source>
<div style='color: navy; margin-top: 0; margin-bottom: 0;'>/*************************************************************************
Modified Bessel function of order zero
Returns modified Bessel function of order zero of the
argument.
The function is defined as i0(x) = j0( ix ).
The range is partitioned into the two intervals [0,8] and
(8, infinity). Chebyshev polynomial expansions are employed
in each interval.
ACCURACY:
Relative error:
arithmetic domain # trials peak rms
IEEE 0,30 30000 5.8e-16 1.4e-16
Cephes Math Library Release 2.8: June, 2000
Copyright 1984, 1987, 2000 by Stephen L. Moshier
*************************************************************************/
</div><div style='margin-top: 0; margin-bottom: 0;'><b>double</b> alglib::besseli0(<b>double</b> x);
</div></pre>
<a name='sub_besseli1'></a><h3 class=pageheader><code>besseli1</code> function</h3>
<pre class=source>
<div style='color: navy; margin-top: 0; margin-bottom: 0;'>/*************************************************************************
Modified Bessel function of order one
Returns modified Bessel function of order one of the
argument.
The function is defined as i1(x) = -i j1( ix ).
The range is partitioned into the two intervals [0,8] and
(8, infinity). Chebyshev polynomial expansions are employed
in each interval.
ACCURACY:
Relative error:
arithmetic domain # trials peak rms
IEEE 0, 30 30000 1.9e-15 2.1e-16
Cephes Math Library Release 2.8: June, 2000
Copyright 1985, 1987, 2000 by Stephen L. Moshier
*************************************************************************/
</div><div style='margin-top: 0; margin-bottom: 0;'><b>double</b> alglib::besseli1(<b>double</b> x);
</div></pre>
<a name='sub_besselj0'></a><h3 class=pageheader><code>besselj0</code> function</h3>
<pre class=source>
<div style='color: navy; margin-top: 0; margin-bottom: 0;'>/*************************************************************************
Bessel function of order zero
Returns Bessel function of order zero of the argument.
The domain is divided into the intervals [0, 5] and
(5, infinity). In the first interval the following rational
approximation is used:
2 2
(w - r ) (w - r ) P (w) / Q (w)
1 2 3 8
2
where w = x and the two r's are zeros of the function.
In the second interval, the Hankel asymptotic expansion
is employed with two rational functions of degree 6/6
and 7/7.
ACCURACY:
Absolute error:
arithmetic domain # trials peak rms
IEEE 0, 30 60000 4.2e-16 1.1e-16
Cephes Math Library Release 2.8: June, 2000
Copyright 1984, 1987, 1989, 2000 by Stephen L. Moshier
*************************************************************************/
</div><div style='margin-top: 0; margin-bottom: 0;'><b>double</b> alglib::besselj0(<b>double</b> x);
</div></pre>
<a name='sub_besselj1'></a><h3 class=pageheader><code>besselj1</code> function</h3>
<pre class=source>
<div style='color: navy; margin-top: 0; margin-bottom: 0;'>/*************************************************************************
Bessel function of order one
Returns Bessel function of order one of the argument.
The domain is divided into the intervals [0, 8] and
(8, infinity). In the first interval a 24 term Chebyshev
expansion is used. In the second, the asymptotic
trigonometric representation is employed using two
rational functions of degree 5/5.
ACCURACY:
Absolute error:
arithmetic domain # trials peak rms
IEEE 0, 30 30000 2.6e-16 1.1e-16
Cephes Math Library Release 2.8: June, 2000
Copyright 1984, 1987, 1989, 2000 by Stephen L. Moshier
*************************************************************************/
</div><div style='margin-top: 0; margin-bottom: 0;'><b>double</b> alglib::besselj1(<b>double</b> x);
</div></pre>
<a name='sub_besseljn'></a><h3 class=pageheader><code>besseljn</code> function</h3>
<pre class=source>
<div style='color: navy; margin-top: 0; margin-bottom: 0;'>/*************************************************************************
Bessel function of integer order
Returns Bessel function of order n, where n is a
(possibly negative) integer.
The ratio of jn(x) to j0(x) is computed by backward
recurrence. First the ratio jn/jn-1 is found by a
continued fraction expansion. Then the recurrence
relating successive orders is applied until j0 or j1 is
reached.
If n = 0 or 1 the routine for j0 or j1 is called
directly.
ACCURACY:
Absolute error:
arithmetic range # trials peak rms
IEEE 0, 30 5000 4.4e-16 7.9e-17
Not suitable for large n or x. Use jv() (fractional order) instead.
Cephes Math Library Release 2.8: June, 2000
Copyright 1984, 1987, 2000 by Stephen L. Moshier
*************************************************************************/
</div><div style='margin-top: 0; margin-bottom: 0;'><b>double</b> alglib::besseljn(ae_int_t n, <b>double</b> x);
</div></pre>
<a name='sub_besselk0'></a><h3 class=pageheader><code>besselk0</code> function</h3>
<pre class=source>
<div style='color: navy; margin-top: 0; margin-bottom: 0;'>/*************************************************************************
Modified Bessel function, second kind, order zero
Returns modified Bessel function of the second kind
of order zero of the argument.
The range is partitioned into the two intervals [0,8] and
(8, infinity). Chebyshev polynomial expansions are employed
in each interval.
ACCURACY:
Tested at 2000 random points between 0 and 8. Peak absolute
error (relative when K0 > 1) was 1.46e-14; rms, 4.26e-15.
Relative error:
arithmetic domain # trials peak rms
IEEE 0, 30 30000 1.2e-15 1.6e-16
Cephes Math Library Release 2.8: June, 2000
Copyright 1984, 1987, 2000 by Stephen L. Moshier
*************************************************************************/
</div><div style='margin-top: 0; margin-bottom: 0;'><b>double</b> alglib::besselk0(<b>double</b> x);
</div></pre>
<a name='sub_besselk1'></a><h3 class=pageheader><code>besselk1</code> function</h3>
<pre class=source>
<div style='color: navy; margin-top: 0; margin-bottom: 0;'>/*************************************************************************
Modified Bessel function, second kind, order one
Computes the modified Bessel function of the second kind
of order one of the argument.
The range is partitioned into the two intervals [0,2] and
(2, infinity). Chebyshev polynomial expansions are employed
in each interval.
ACCURACY:
Relative error:
arithmetic domain # trials peak rms
IEEE 0, 30 30000 1.2e-15 1.6e-16
Cephes Math Library Release 2.8: June, 2000
Copyright 1984, 1987, 2000 by Stephen L. Moshier
*************************************************************************/
</div><div style='margin-top: 0; margin-bottom: 0;'><b>double</b> alglib::besselk1(<b>double</b> x);
</div></pre>
<a name='sub_besselkn'></a><h3 class=pageheader><code>besselkn</code> function</h3>
<pre class=source>
<div style='color: navy; margin-top: 0; margin-bottom: 0;'>/*************************************************************************
Modified Bessel function, second kind, integer order
Returns modified Bessel function of the second kind
of order n of the argument.
The range is partitioned into the two intervals [0,9.55] and
(9.55, infinity). An ascending power series is used in the
low range, and an asymptotic expansion in the high range.
ACCURACY:
Relative error:
arithmetic domain # trials peak rms
IEEE 0,30 90000 1.8e-8 3.0e-10
Error is high only near the crossover point x = 9.55
between the two expansions used.
Cephes Math Library Release 2.8: June, 2000
Copyright 1984, 1987, 1988, 2000 by Stephen L. Moshier
*************************************************************************/
</div><div style='margin-top: 0; margin-bottom: 0;'><b>double</b> alglib::besselkn(ae_int_t nn, <b>double</b> x);
</div></pre>
<a name='sub_bessely0'></a><h3 class=pageheader><code>bessely0</code> function</h3>
<pre class=source>
<div style='color: navy; margin-top: 0; margin-bottom: 0;'>/*************************************************************************
Bessel function of the second kind, order zero
Returns Bessel function of the second kind, of order
zero, of the argument.
The domain is divided into the intervals [0, 5] and
(5, infinity). In the first interval a rational approximation
R(x) is employed to compute
y0(x) = R(x) + 2 * log(x) * j0(x) / PI.
Thus a call to j0() is required.
In the second interval, the Hankel asymptotic expansion
is employed with two rational functions of degree 6/6
and 7/7.
ACCURACY:
Absolute error, when y0(x) < 1; else relative error:
arithmetic domain # trials peak rms
IEEE 0, 30 30000 1.3e-15 1.6e-16
Cephes Math Library Release 2.8: June, 2000
Copyright 1984, 1987, 1989, 2000 by Stephen L. Moshier
*************************************************************************/
</div><div style='margin-top: 0; margin-bottom: 0;'><b>double</b> alglib::bessely0(<b>double</b> x);
</div></pre>
<a name='sub_bessely1'></a><h3 class=pageheader><code>bessely1</code> function</h3>
<pre class=source>
<div style='color: navy; margin-top: 0; margin-bottom: 0;'>/*************************************************************************
Bessel function of second kind of order one
Returns Bessel function of the second kind of order one
of the argument.
The domain is divided into the intervals [0, 8] and
(8, infinity). In the first interval a 25 term Chebyshev
expansion is used, and a call to j1() is required.
In the second, the asymptotic trigonometric representation
is employed using two rational functions of degree 5/5.
ACCURACY:
Absolute error:
arithmetic domain # trials peak rms
IEEE 0, 30 30000 1.0e-15 1.3e-16
Cephes Math Library Release 2.8: June, 2000
Copyright 1984, 1987, 1989, 2000 by Stephen L. Moshier
*************************************************************************/
</div><div style='margin-top: 0; margin-bottom: 0;'><b>double</b> alglib::bessely1(<b>double</b> x);
</div></pre>
<a name='sub_besselyn'></a><h3 class=pageheader><code>besselyn</code> function</h3>
<pre class=source>
<div style='color: navy; margin-top: 0; margin-bottom: 0;'>/*************************************************************************
Bessel function of second kind of integer order
Returns Bessel function of order n, where n is a
(possibly negative) integer.
The function is evaluated by forward recurrence on
n, starting with values computed by the routines
y0() and y1().
If n = 0 or 1 the routine for y0 or y1 is called
directly.
ACCURACY:
Absolute error, except relative
when y > 1:
arithmetic domain # trials peak rms
IEEE 0, 30 30000 3.4e-15 4.3e-16
Cephes Math Library Release 2.8: June, 2000
Copyright 1984, 1987, 2000 by Stephen L. Moshier
*************************************************************************/
</div><div style='margin-top: 0; margin-bottom: 0;'><b>double</b> alglib::besselyn(ae_int_t n, <b>double</b> x);
</div></pre>
<a name=unit_betaf></a><h2 class=pageheader><code>betaf</code> subpackage</h2>
<div class=pagecontent>
<h3 class=pageheader>Functions</h3>
<a href='#sub_beta' class=toc>beta</a><br>
<h3 class=pageheader>Examples</h3>
<table border=0 cellspacing=0 class='pagecontent'>
</table></div>
<a name='sub_beta'></a><h3 class=pageheader><code>beta</code> function</h3>
<pre class=source>
<div style='color: navy; margin-top: 0; margin-bottom: 0;'>/*************************************************************************
Beta function
- -
| (a) | (b)
beta( a, b ) = -----------.
-
| (a+b)
For large arguments the logarithm of the function is
evaluated using lgam(), then exponentiated.
ACCURACY:
Relative error:
arithmetic domain # trials peak rms
IEEE 0,30 30000 8.1e-14 1.1e-14
Cephes Math Library Release 2.0: April, 1987
Copyright 1984, 1987 by Stephen L. Moshier
*************************************************************************/
</div><div style='margin-top: 0; margin-bottom: 0;'><b>double</b> alglib::beta(<b>double</b> a, <b>double</b> b);
</div></pre>
<a name=unit_binomialdistr></a><h2 class=pageheader><code>binomialdistr</code> subpackage</h2>
<div class=pagecontent>
<h3 class=pageheader>Functions</h3>
<a href='#sub_binomialcdistribution' class=toc>binomialcdistribution</a><br>
<a href='#sub_binomialdistribution' class=toc>binomialdistribution</a><br>
<a href='#sub_invbinomialdistribution' class=toc>invbinomialdistribution</a><br>
<h3 class=pageheader>Examples</h3>
<table border=0 cellspacing=0 class='pagecontent'>
</table></div>
<a name='sub_binomialcdistribution'></a><h3 class=pageheader><code>binomialcdistribution</code> function</h3>
<pre class=source>
<div style='color: navy; margin-top: 0; margin-bottom: 0;'>/*************************************************************************
Complemented binomial distribution
Returns the sum of the terms k+1 through n of the Binomial
probability density:
n
-- ( n ) j n-j
> ( ) p (1-p)
-- ( j )
j=k+1
The terms are not summed directly; instead the incomplete
beta integral is employed, according to the formula
y = bdtrc( k, n, p ) = incbet( k+1, n-k, p ).
The arguments must be positive, with p ranging from 0 to 1.
ACCURACY:
Tested at random points (a,b,p).
a,b Relative error:
arithmetic domain # trials peak rms
For p between 0.001 and 1:
IEEE 0,100 100000 6.7e-15 8.2e-16
For p between 0 and .001:
IEEE 0,100 100000 1.5e-13 2.7e-15
Cephes Math Library Release 2.8: June, 2000
Copyright 1984, 1987, 1995, 2000 by Stephen L. Moshier
*************************************************************************/
</div><div style='margin-top: 0; margin-bottom: 0;'><b>double</b> alglib::binomialcdistribution(ae_int_t k, ae_int_t n, <b>double</b> p);
</div></pre>
<a name='sub_binomialdistribution'></a><h3 class=pageheader><code>binomialdistribution</code> function</h3>
<pre class=source>
<div style='color: navy; margin-top: 0; margin-bottom: 0;'>/*************************************************************************
Binomial distribution
Returns the sum of the terms 0 through k of the Binomial
probability density:
k
-- ( n ) j n-j
> ( ) p (1-p)
-- ( j )
j=0
The terms are not summed directly; instead the incomplete
beta integral is employed, according to the formula
y = bdtr( k, n, p ) = incbet( n-k, k+1, 1-p ).
The arguments must be positive, with p ranging from 0 to 1.
ACCURACY:
Tested at random points (a,b,p), with p between 0 and 1.
a,b Relative error:
arithmetic domain # trials peak rms
For p between 0.001 and 1:
IEEE 0,100 100000 4.3e-15 2.6e-16
Cephes Math Library Release 2.8: June, 2000
Copyright 1984, 1987, 1995, 2000 by Stephen L. Moshier
*************************************************************************/
</div><div style='margin-top: 0; margin-bottom: 0;'><b>double</b> alglib::binomialdistribution(ae_int_t k, ae_int_t n, <b>double</b> p);
</div></pre>
<a name='sub_invbinomialdistribution'></a><h3 class=pageheader><code>invbinomialdistribution</code> function</h3>
<pre class=source>
<div style='color: navy; margin-top: 0; margin-bottom: 0;'>/*************************************************************************
Inverse binomial distribution
Finds the event probability p such that the sum of the
terms 0 through k of the Binomial probability density
is equal to the given cumulative probability y.
This is accomplished using the inverse beta integral
function and the relation
1 - p = incbi( n-k, k+1, y ).
ACCURACY:
Tested at random points (a,b,p).
a,b Relative error:
arithmetic domain # trials peak rms
For p between 0.001 and 1:
IEEE 0,100 100000 2.3e-14 6.4e-16
IEEE 0,10000 100000 6.6e-12 1.2e-13
For p between 10^-6 and 0.001:
IEEE 0,100 100000 2.0e-12 1.3e-14
IEEE 0,10000 100000 1.5e-12 3.2e-14
Cephes Math Library Release 2.8: June, 2000
Copyright 1984, 1987, 1995, 2000 by Stephen L. Moshier
*************************************************************************/
</div><div style='margin-top: 0; margin-bottom: 0;'><b>double</b> alglib::invbinomialdistribution(ae_int_t k, ae_int_t n, <b>double</b> y);
</div></pre>
<a name=unit_chebyshev></a><h2 class=pageheader><code>chebyshev</code> subpackage</h2>
<div class=pagecontent>
<h3 class=pageheader>Functions</h3>
<a href='#sub_chebyshevcalculate' class=toc>chebyshevcalculate</a><br>
<a href='#sub_chebyshevcoefficients' class=toc>chebyshevcoefficients</a><br>
<a href='#sub_chebyshevsum' class=toc>chebyshevsum</a><br>
<a href='#sub_fromchebyshev' class=toc>fromchebyshev</a><br>
<h3 class=pageheader>Examples</h3>
<table border=0 cellspacing=0 class='pagecontent'>
</table></div>
<a name='sub_chebyshevcalculate'></a><h3 class=pageheader><code>chebyshevcalculate</code> function</h3>
<pre class=source>
<div style='color: navy; margin-top: 0; margin-bottom: 0;'>/*************************************************************************
Calculation of the value of the Chebyshev polynomials of the
first and second kinds.
Parameters:
r - polynomial kind, either 1 or 2.
n - degree, n>=0
x - argument, -1 <= x <= 1
Result:
the value of the Chebyshev polynomial at x
*************************************************************************/
</div><div style='margin-top: 0; margin-bottom: 0;'><b>double</b> alglib::chebyshevcalculate(ae_int_t r, ae_int_t n, <b>double</b> x);
</div></pre>
<a name='sub_chebyshevcoefficients'></a><h3 class=pageheader><code>chebyshevcoefficients</code> function</h3>
<pre class=source>
<div style='color: navy; margin-top: 0; margin-bottom: 0;'>/*************************************************************************
Representation of Tn as C[0] + C[1]*X + ... + C[N]*X^N
Input parameters:
N - polynomial degree, n>=0
Output parameters:
C - coefficients
*************************************************************************/
</div><div style='margin-top: 0; margin-bottom: 0;'><b>void</b> alglib::chebyshevcoefficients(ae_int_t n, real_1d_array& c);
</div></pre>
<a name='sub_chebyshevsum'></a><h3 class=pageheader><code>chebyshevsum</code> function</h3>
<pre class=source>
<div style='color: navy; margin-top: 0; margin-bottom: 0;'>/*************************************************************************
Summation of Chebyshev polynomials using Clenshaw�s recurrence formula.
This routine calculates
c[0]*T0(x) + c[1]*T1(x) + ... + c[N]*TN(x)
or
c[0]*U0(x) + c[1]*U1(x) + ... + c[N]*UN(x)
depending on the R.
Parameters:
r - polynomial kind, either 1 or 2.
n - degree, n>=0
x - argument
Result:
the value of the Chebyshev polynomial at x
*************************************************************************/
</div><div style='margin-top: 0; margin-bottom: 0;'><b>double</b> alglib::chebyshevsum(
real_1d_array c,
ae_int_t r,
ae_int_t n,
<b>double</b> x);
</div></pre>
<a name='sub_fromchebyshev'></a><h3 class=pageheader><code>fromchebyshev</code> function</h3>
<pre class=source>
<div style='color: navy; margin-top: 0; margin-bottom: 0;'>/*************************************************************************
Conversion of a series of Chebyshev polynomials to a power series.
Represents A[0]*T0(x) + A[1]*T1(x) + ... + A[N]*Tn(x) as
B[0] + B[1]*X + ... + B[N]*X^N.
Input parameters:
A - Chebyshev series coefficients
N - degree, N>=0
Output parameters
B - power series coefficients
*************************************************************************/
</div><div style='margin-top: 0; margin-bottom: 0;'><b>void</b> alglib::fromchebyshev(real_1d_array a, ae_int_t n, real_1d_array& b);
</div></pre>
<a name=unit_chisquaredistr></a><h2 class=pageheader><code>chisquaredistr</code> subpackage</h2>
<div class=pagecontent>
<h3 class=pageheader>Functions</h3>
<a href='#sub_chisquarecdistribution' class=toc>chisquarecdistribution</a><br>
<a href='#sub_chisquaredistribution' class=toc>chisquaredistribution</a><br>
<a href='#sub_invchisquaredistribution' class=toc>invchisquaredistribution</a><br>
<h3 class=pageheader>Examples</h3>
<table border=0 cellspacing=0 class='pagecontent'>
</table></div>
<a name='sub_chisquarecdistribution'></a><h3 class=pageheader><code>chisquarecdistribution</code> function</h3>
<pre class=source>
<div style='color: navy; margin-top: 0; margin-bottom: 0;'>/*************************************************************************
Complemented Chi-square distribution
Returns the area under the right hand tail (from x to
infinity) of the Chi square probability density function
with v degrees of freedom:
inf.
-
1 | | v/2-1 -t/2
P( x | v ) = ----------- | t e dt
v/2 - | |
2 | (v/2) -
x
where x is the Chi-square variable.
The incomplete gamma integral is used, according to the
formula
y = chdtr( v, x ) = igamc( v/2.0, x/2.0 ).
The arguments must both be positive.
ACCURACY:
See incomplete gamma function
Cephes Math Library Release 2.8: June, 2000
Copyright 1984, 1987, 2000 by Stephen L. Moshier
*************************************************************************/
</div><div style='margin-top: 0; margin-bottom: 0;'><b>double</b> alglib::chisquarecdistribution(<b>double</b> v, <b>double</b> x);
</div></pre>
<a name='sub_chisquaredistribution'></a><h3 class=pageheader><code>chisquaredistribution</code> function</h3>
<pre class=source>
<div style='color: navy; margin-top: 0; margin-bottom: 0;'>/*************************************************************************
Chi-square distribution
Returns the area under the left hand tail (from 0 to x)
of the Chi square probability density function with
v degrees of freedom.
x
-
1 | | v/2-1 -t/2
P( x | v ) = ----------- | t e dt
v/2 - | |
2 | (v/2) -
0
where x is the Chi-square variable.
The incomplete gamma integral is used, according to the
formula
y = chdtr( v, x ) = igam( v/2.0, x/2.0 ).
The arguments must both be positive.
ACCURACY:
See incomplete gamma function
Cephes Math Library Release 2.8: June, 2000
Copyright 1984, 1987, 2000 by Stephen L. Moshier
*************************************************************************/
</div><div style='margin-top: 0; margin-bottom: 0;'><b>double</b> alglib::chisquaredistribution(<b>double</b> v, <b>double</b> x);
</div></pre>
<a name='sub_invchisquaredistribution'></a><h3 class=pageheader><code>invchisquaredistribution</code> function</h3>
<pre class=source>
<div style='color: navy; margin-top: 0; margin-bottom: 0;'>/*************************************************************************
Inverse of complemented Chi-square distribution
Finds the Chi-square argument x such that the integral
from x to infinity of the Chi-square density is equal
to the given cumulative probability y.
This is accomplished using the inverse gamma integral
function and the relation
x/2 = igami( df/2, y );
ACCURACY:
See inverse incomplete gamma function
Cephes Math Library Release 2.8: June, 2000
Copyright 1984, 1987, 2000 by Stephen L. Moshier
*************************************************************************/
</div><div style='margin-top: 0; margin-bottom: 0;'><b>double</b> alglib::invchisquaredistribution(<b>double</b> v, <b>double</b> y);
</div></pre>
<a name=unit_clustering></a><h2 class=pageheader><code>clustering</code> subpackage</h2>
<div class=pagecontent>
<h3 class=pageheader>Classes</h3>
<a href='#struct_ahcreport' class=toc>ahcreport</a><br>
<a href='#struct_clusterizerstate' class=toc>clusterizerstate</a><br>
<a href='#struct_kmeansreport' class=toc>kmeansreport</a><br>
<h3 class=pageheader>Functions</h3>
<a href='#sub_clusterizercreate' class=toc>clusterizercreate</a><br>
<a href='#sub_clusterizergetdistances' class=toc>clusterizergetdistances</a><br>
<a href='#sub_clusterizergetkclusters' class=toc>clusterizergetkclusters</a><br>
<a href='#sub_clusterizerrunahc' class=toc>clusterizerrunahc</a><br>
<a href='#sub_clusterizerrunkmeans' class=toc>clusterizerrunkmeans</a><br>
<a href='#sub_clusterizerseparatedbycorr' class=toc>clusterizerseparatedbycorr</a><br>
<a href='#sub_clusterizerseparatedbydist' class=toc>clusterizerseparatedbydist</a><br>
<a href='#sub_clusterizersetahcalgo' class=toc>clusterizersetahcalgo</a><br>
<a href='#sub_clusterizersetdistances' class=toc>clusterizersetdistances</a><br>
<a href='#sub_clusterizersetkmeansinit' class=toc>clusterizersetkmeansinit</a><br>
<a href='#sub_clusterizersetkmeanslimits' class=toc>clusterizersetkmeanslimits</a><br>
<a href='#sub_clusterizersetpoints' class=toc>clusterizersetpoints</a><br>
<h3 class=pageheader>Examples</h3>
<table border=0 cellspacing=0 class='pagecontent'>
<tr align=left valign=top><td><a href='#example_clst_ahc' class=toc>clst_ahc</a></td><td width=15> </td><td>Simple hierarchical clusterization with Euclidean distance function</td></tr>
<tr align=left valign=top><td><a href='#example_clst_distance' class=toc>clst_distance</a></td><td width=15> </td><td>Clusterization with different metric types</td></tr>
<tr align=left valign=top><td><a href='#example_clst_kclusters' class=toc>clst_kclusters</a></td><td width=15> </td><td>Obtaining K top clusters from clusterization tree</td></tr>
<tr align=left valign=top><td><a href='#example_clst_kmeans' class=toc>clst_kmeans</a></td><td width=15> </td><td>Simple k-means clusterization</td></tr>
<tr align=left valign=top><td><a href='#example_clst_linkage' class=toc>clst_linkage</a></td><td width=15> </td><td>Clusterization with different linkage types</td></tr>
</table></div>
<a name='struct_ahcreport'></a><h3 class=pageheader><code>ahcreport</code> class</h3>
<pre class=source>
<div style='color: navy; margin-top: 0; margin-bottom: 0;'>/*************************************************************************
This structure is used to store results of the agglomerative hierarchical
clustering (AHC).
Following information is returned:
* TerminationType - completion code:
* 1 for successful completion of algorithm
* -5 inappropriate combination of clustering algorithm and distance
function was used. As for now, it is possible only when Ward's
method is called for dataset with non-Euclidean distance function.
In case negative completion code is returned, other fields of report
structure are invalid and should not be used.
* NPoints contains number of points in the original dataset
* Z contains information about merges performed (see below). Z contains
indexes from the original (unsorted) dataset and it can be used when you
need to know what points were merged. However, it is not convenient when
you want to build a dendrograd (see below).
* if you want to build dendrogram, you can use Z, but it is not good
option, because Z contains indexes from unsorted dataset. Dendrogram
built from such dataset is likely to have intersections. So, you have to
reorder you points before building dendrogram.
Permutation which reorders point is returned in P. Another representation
of merges, which is more convenient for dendorgram construction, is
returned in PM.
* more information on format of Z, P and PM can be found below and in the
examples from ALGLIB Reference Manual.
FORMAL DESCRIPTION OF FIELDS:
NPoints number of points
Z array[NPoints-1,2], contains indexes of clusters
linked in pairs to form clustering tree. I-th row
corresponds to I-th merge:
* Z[I,0] - index of the first cluster to merge
* Z[I,1] - index of the second cluster to merge
* Z[I,0]<Z[I,1]
* clusters are numbered from 0 to 2*NPoints-2, with
indexes from 0 to NPoints-1 corresponding to points
of the original dataset, and indexes from NPoints to
2*NPoints-2 correspond to clusters generated by
subsequent merges (I-th row of Z creates cluster
with index NPoints+I).
IMPORTANT: indexes in Z[] are indexes in the ORIGINAL,
unsorted dataset. In addition to Z algorithm outputs
permutation which rearranges points in such way that
subsequent merges are performed on adjacent points
(such order is needed if you want to build dendrogram).
However, indexes in Z are related to original,
unrearranged sequence of points.
P array[NPoints], permutation which reorders points for
dendrogram construction. P[i] contains index of the
position where we should move I-th point of the
original dataset in order to apply merges PZ/PM.
PZ same as Z, but for permutation of points given by P.
The only thing which changed are indexes of the
original points; indexes of clusters remained same.
MergeDist array[NPoints-1], contains distances between clusters
being merged (MergeDist[i] correspond to merge stored
in Z[i,...]):
* CLINK, SLINK and average linkage algorithms report
"raw", unmodified distance metric.
* Ward's method reports weighted intra-cluster
variance, which is equal to ||Ca-Cb||^2 * Sa*Sb/(Sa+Sb).
Here A and B are clusters being merged, Ca is a
center of A, Cb is a center of B, Sa is a size of A,
Sb is a size of B.
PM array[NPoints-1,6], another representation of merges,
which is suited for dendrogram construction. It deals
with rearranged points (permutation P is applied) and
represents merges in a form which different from one
used by Z.
For each I from 0 to NPoints-2, I-th row of PM represents
merge performed on two clusters C0 and C1. Here:
* C0 contains points with indexes PM[I,0]...PM[I,1]
* C1 contains points with indexes PM[I,2]...PM[I,3]
* indexes stored in PM are given for dataset sorted
according to permutation P
* PM[I,1]=PM[I,2]-1 (only adjacent clusters are merged)
* PM[I,0]<=PM[I,1], PM[I,2]<=PM[I,3], i.e. both
clusters contain at least one point
* heights of "subdendrograms" corresponding to C0/C1
are stored in PM[I,4] and PM[I,5]. Subdendrograms
corresponding to single-point clusters have
height=0. Dendrogram of the merge result has height
H=max(H0,H1)+1.
NOTE: there is one-to-one correspondence between merges described by Z and
PM. I-th row of Z describes same merge of clusters as I-th row of PM,
with "left" cluster from Z corresponding to the "left" one from PM.
-- ALGLIB --
Copyright 10.07.2012 by Bochkanov Sergey
*************************************************************************/
</div><div style='margin-top: 0; margin-bottom: 0;'><b>class</b> ahcreport
{
ae_int_t terminationtype;
ae_int_t npoints;
integer_1d_array p;
integer_2d_array z;
integer_2d_array pz;
integer_2d_array pm;
real_1d_array mergedist;
};
</div></pre>
<a name='struct_clusterizerstate'></a><h3 class=pageheader><code>clusterizerstate</code> class</h3>
<pre class=source>
<div style='color: navy; margin-top: 0; margin-bottom: 0;'>/*************************************************************************
This structure is a clusterization engine.
You should not try to access its fields directly.
Use ALGLIB functions in order to work with this object.
-- ALGLIB --
Copyright 10.07.2012 by Bochkanov Sergey
*************************************************************************/
</div><div style='margin-top: 0; margin-bottom: 0;'><b>class</b> clusterizerstate
{
};
</div></pre>
<a name='struct_kmeansreport'></a><h3 class=pageheader><code>kmeansreport</code> class</h3>
<pre class=source>
<div style='color: navy; margin-top: 0; margin-bottom: 0;'>/*************************************************************************
This structure is used to store results of the k-means clustering
algorithm.
Following information is always returned:
* NPoints contains number of points in the original dataset
* TerminationType contains completion code, negative on failure, positive
on success
* K contains number of clusters
For positive TerminationType we return:
* NFeatures contains number of variables in the original dataset
* C, which contains centers found by algorithm
* CIdx, which maps points of the original dataset to clusters
FORMAL DESCRIPTION OF FIELDS:
NPoints number of points, >=0
NFeatures number of variables, >=1
TerminationType completion code:
* -5 if distance type is anything different from
Euclidean metric
* -3 for degenerate dataset: a) less than K distinct
points, b) K=0 for non-empty dataset.
* +1 for successful completion
K number of clusters
C array[K,NFeatures], rows of the array store centers
CIdx array[NPoints], which contains cluster indexes
IterationsCount actual number of iterations performed by clusterizer.
If algorithm performed more than one random restart,
total number of iterations is returned.
Energy merit function, "energy", sum of squared deviations
from cluster centers
-- ALGLIB --
Copyright 27.11.2012 by Bochkanov Sergey
*************************************************************************/
</div><div style='margin-top: 0; margin-bottom: 0;'><b>class</b> kmeansreport
{
ae_int_t npoints;
ae_int_t nfeatures;
ae_int_t terminationtype;
ae_int_t iterationscount;
<b>double</b> energy;
ae_int_t k;
real_2d_array c;
integer_1d_array cidx;
};
</div></pre>
<a name='sub_clusterizercreate'></a><h3 class=pageheader><code>clusterizercreate</code> function</h3>
<pre class=source>
<div style='color: navy; margin-top: 0; margin-bottom: 0;'>/*************************************************************************
This function initializes clusterizer object. Newly initialized object is
empty, i.e. it does not contain dataset. You should use it as follows:
1. creation
2. dataset is added with ClusterizerSetPoints()
3. additional parameters are set
3. clusterization is performed with one of the clustering functions
-- ALGLIB --
Copyright 10.07.2012 by Bochkanov Sergey
*************************************************************************/
</div><div style='margin-top: 0; margin-bottom: 0;'><b>void</b> alglib::clusterizercreate(clusterizerstate& s);
</div></pre>
<p align=left class=pagecontent><span class=inlineheader>Examples:</span> <a href='#example_clst_ahc' class=nav>[1]</a> <a href='#example_clst_kmeans' class=nav>[2]</a> <a href='#example_clst_linkage' class=nav>[3]</a> <a href='#example_clst_distance' class=nav>[4]</a> <a href='#example_clst_kclusters' class=nav>[5]</a> </p>
<a name='sub_clusterizergetdistances'></a><h3 class=pageheader><code>clusterizergetdistances</code> function</h3>
<pre class=source>
<div style='color: navy; margin-top: 0; margin-bottom: 0;'>/*************************************************************************
This function returns distance matrix for dataset
COMMERCIAL EDITION OF ALGLIB:
! Commercial version of ALGLIB includes two important improvements of
! this function, which can be used from C++ and C#:
! * Intel MKL support (lightweight Intel MKL is shipped with ALGLIB)
! * multicore support
!
! Agglomerative hierarchical clustering algorithm has two phases:
! distance matrix calculation and clustering itself. Only first phase
! (distance matrix calculation) is accelerated by Intel MKL and multi-
! threading. Thus, acceleration is significant only for medium or high-
! dimensional problems.
!
! We recommend you to read 'Working with commercial version' section of
! ALGLIB Reference Manual in order to find out how to use performance-
! related features provided by commercial edition of ALGLIB.
INPUT PARAMETERS:
XY - array[NPoints,NFeatures], dataset
NPoints - number of points, >=0
NFeatures- number of features, >=1
DistType- distance function:
* 0 Chebyshev distance (L-inf norm)
* 1 city block distance (L1 norm)
* 2 Euclidean distance (L2 norm, non-squared)
* 10 Pearson correlation:
dist(a,b) = 1-corr(a,b)
* 11 Absolute Pearson correlation:
dist(a,b) = 1-|corr(a,b)|
* 12 Uncentered Pearson correlation (cosine of the angle):
dist(a,b) = a'*b/(|a|*|b|)
* 13 Absolute uncentered Pearson correlation
dist(a,b) = |a'*b|/(|a|*|b|)
* 20 Spearman rank correlation:
dist(a,b) = 1-rankcorr(a,b)
* 21 Absolute Spearman rank correlation
dist(a,b) = 1-|rankcorr(a,b)|
OUTPUT PARAMETERS:
D - array[NPoints,NPoints], distance matrix
(full matrix is returned, with lower and upper triangles)
NOTE: different distance functions have different performance penalty:
* Euclidean or Pearson correlation distances are the fastest ones
* Spearman correlation distance function is a bit slower
* city block and Chebyshev distances are order of magnitude slower
The reason behing difference in performance is that correlation-based
distance functions are computed using optimized linear algebra kernels,
while Chebyshev and city block distance functions are computed using
simple nested loops with two branches at each iteration.
-- ALGLIB --
Copyright 10.07.2012 by Bochkanov Sergey
*************************************************************************/
</div><div style='margin-top: 0; margin-bottom: 0;'><b>void</b> alglib::clusterizergetdistances(
real_2d_array xy,
ae_int_t npoints,
ae_int_t nfeatures,
ae_int_t disttype,
real_2d_array& d);
<b>void</b> alglib::smp_clusterizergetdistances(
real_2d_array xy,
ae_int_t npoints,
ae_int_t nfeatures,
ae_int_t disttype,
real_2d_array& d);
</div></pre>
<a name='sub_clusterizergetkclusters'></a><h3 class=pageheader><code>clusterizergetkclusters</code> function</h3>
<pre class=source>
<div style='color: navy; margin-top: 0; margin-bottom: 0;'>/*************************************************************************
This function takes as input clusterization report Rep, desired clusters
count K, and builds top K clusters from hierarchical clusterization tree.
It returns assignment of points to clusters (array of cluster indexes).
INPUT PARAMETERS:
Rep - report from ClusterizerRunAHC() performed on XY
K - desired number of clusters, 1<=K<=NPoints.
K can be zero only when NPoints=0.
OUTPUT PARAMETERS:
CIdx - array[NPoints], I-th element contains cluster index (from
0 to K-1) for I-th point of the dataset.
CZ - array[K]. This array allows to convert cluster indexes
returned by this function to indexes used by Rep.Z. J-th
cluster returned by this function corresponds to CZ[J]-th
cluster stored in Rep.Z/PZ/PM.
It is guaranteed that CZ[I]<CZ[I+1].
NOTE: K clusters built by this subroutine are assumed to have no hierarchy.
Although they were obtained by manipulation with top K nodes of
dendrogram (i.e. hierarchical decomposition of dataset), this
function does not return information about hierarchy. Each of the
clusters stand on its own.
NOTE: Cluster indexes returned by this function does not correspond to
indexes returned in Rep.Z/PZ/PM. Either you work with hierarchical
representation of the dataset (dendrogram), or you work with "flat"
representation returned by this function. Each of representations
has its own clusters indexing system (former uses [0, 2*NPoints-2]),
while latter uses [0..K-1]), although it is possible to perform
conversion from one system to another by means of CZ array, returned
by this function, which allows you to convert indexes stored in CIdx
to the numeration system used by Rep.Z.
NOTE: this subroutine is optimized for moderate values of K. Say, for K=5
it will perform many times faster than for K=100. Its worst-case
performance is O(N*K), although in average case it perform better
(up to O(N*log(K))).
-- ALGLIB --
Copyright 10.07.2012 by Bochkanov Sergey
*************************************************************************/
</div><div style='margin-top: 0; margin-bottom: 0;'><b>void</b> alglib::clusterizergetkclusters(
ahcreport rep,
ae_int_t k,
integer_1d_array& cidx,
integer_1d_array& cz);
</div></pre>
<p align=left class=pagecontent><span class=inlineheader>Examples:</span> <a href='#example_clst_linkage' class=nav>[1]</a> <a href='#example_clst_kclusters' class=nav>[2]</a> </p>
<a name='sub_clusterizerrunahc'></a><h3 class=pageheader><code>clusterizerrunahc</code> function</h3>
<pre class=source>
<div style='color: navy; margin-top: 0; margin-bottom: 0;'>/*************************************************************************
This function performs agglomerative hierarchical clustering
COMMERCIAL EDITION OF ALGLIB:
! Commercial version of ALGLIB includes two important improvements of
! this function, which can be used from C++ and C#:
! * Intel MKL support (lightweight Intel MKL is shipped with ALGLIB)
! * multicore support
!
! Agglomerative hierarchical clustering algorithm has two phases:
! distance matrix calculation and clustering itself. Only first phase
! (distance matrix calculation) is accelerated by Intel MKL and multi-
! threading. Thus, acceleration is significant only for medium or high-
! dimensional problems.
!
! We recommend you to read 'Working with commercial version' section of
! ALGLIB Reference Manual in order to find out how to use performance-
! related features provided by commercial edition of ALGLIB.
INPUT PARAMETERS:
S - clusterizer state, initialized by ClusterizerCreate()
OUTPUT PARAMETERS:
Rep - clustering results; see description of AHCReport
structure for more information.
NOTE 1: hierarchical clustering algorithms require large amounts of memory.
In particular, this implementation needs sizeof(double)*NPoints^2
bytes, which are used to store distance matrix. In case we work
with user-supplied matrix, this amount is multiplied by 2 (we have
to store original matrix and to work with its copy).
For example, problem with 10000 points would require 800M of RAM,
even when working in a 1-dimensional space.
-- ALGLIB --
Copyright 10.07.2012 by Bochkanov Sergey
*************************************************************************/
</div><div style='margin-top: 0; margin-bottom: 0;'><b>void</b> alglib::clusterizerrunahc(clusterizerstate s, ahcreport& rep);
<b>void</b> alglib::smp_clusterizerrunahc(clusterizerstate s, ahcreport& rep);
</div></pre>
<p align=left class=pagecontent><span class=inlineheader>Examples:</span> <a href='#example_clst_ahc' class=nav>[1]</a> <a href='#example_clst_kmeans' class=nav>[2]</a> <a href='#example_clst_linkage' class=nav>[3]</a> <a href='#example_clst_distance' class=nav>[4]</a> <a href='#example_clst_kclusters' class=nav>[5]</a> </p>
<a name='sub_clusterizerrunkmeans'></a><h3 class=pageheader><code>clusterizerrunkmeans</code> function</h3>
<pre class=source>
<div style='color: navy; margin-top: 0; margin-bottom: 0;'>/*************************************************************************
This function performs clustering by k-means++ algorithm.
You may change algorithm properties by calling:
* ClusterizerSetKMeansLimits() to change number of restarts or iterations
* ClusterizerSetKMeansInit() to change initialization algorithm
By default, one restart and unlimited number of iterations are used.
Initialization algorithm is chosen automatically.
COMMERCIAL EDITION OF ALGLIB:
! Commercial version of ALGLIB includes two important improvements of
! this function:
! * multicore support (can be used from C# and C++)
! * access to high-performance C++ core (actual for C# users)
!
! K-means clustering algorithm has two phases: selection of initial
! centers and clustering itself. ALGLIB parallelizes both phases.
! Parallel version is optimized for the following scenario: medium or
! high-dimensional problem (20 or more dimensions) with large number of
! points and clusters. However, some speed-up can be obtained even when
! assumptions above are violated.
!
! As for native-vs-managed comparison, working with native core brings
! 30-40% improvement in speed over pure C# version of ALGLIB.
!
! We recommend you to read 'Working with commercial version' section of
! ALGLIB Reference Manual in order to find out how to use performance-
! related features provided by commercial edition of ALGLIB.
INPUT PARAMETERS:
S - clusterizer state, initialized by ClusterizerCreate()
K - number of clusters, K>=0.
K can be zero only when algorithm is called for empty
dataset, in this case completion code is set to
success (+1).
If K=0 and dataset size is non-zero, we can not
meaningfully assign points to some center (there are no
centers because K=0) and return -3 as completion code
(failure).
OUTPUT PARAMETERS:
Rep - clustering results; see description of KMeansReport
structure for more information.
NOTE 1: k-means clustering can be performed only for datasets with
Euclidean distance function. Algorithm will return negative
completion code in Rep.TerminationType in case dataset was added
to clusterizer with DistType other than Euclidean (or dataset was
specified by distance matrix instead of explicitly given points).
-- ALGLIB --
Copyright 10.07.2012 by Bochkanov Sergey
*************************************************************************/
</div><div style='margin-top: 0; margin-bottom: 0;'><b>void</b> alglib::clusterizerrunkmeans(
clusterizerstate s,
ae_int_t k,
kmeansreport& rep);
<b>void</b> alglib::smp_clusterizerrunkmeans(
clusterizerstate s,
ae_int_t k,
kmeansreport& rep);
</div></pre>
<a name='sub_clusterizerseparatedbycorr'></a><h3 class=pageheader><code>clusterizerseparatedbycorr</code> function</h3>
<pre class=source>
<div style='color: navy; margin-top: 0; margin-bottom: 0;'>/*************************************************************************
This function accepts AHC report Rep, desired maximum intercluster
correlation and returns top clusters from hierarchical clusterization tree
which are separated by correlation R or LOWER.
It returns assignment of points to clusters (array of cluster indexes).
There is one more function with similar name - ClusterizerSeparatedByDist,
which returns clusters with intercluster distance equal to R or HIGHER
(note: higher for distance, lower for correlation).
INPUT PARAMETERS:
Rep - report from ClusterizerRunAHC() performed on XY
R - desired maximum intercluster correlation, -1<=R<=+1
OUTPUT PARAMETERS:
K - number of clusters, 1<=K<=NPoints
CIdx - array[NPoints], I-th element contains cluster index (from
0 to K-1) for I-th point of the dataset.
CZ - array[K]. This array allows to convert cluster indexes
returned by this function to indexes used by Rep.Z. J-th
cluster returned by this function corresponds to CZ[J]-th
cluster stored in Rep.Z/PZ/PM.
It is guaranteed that CZ[I]<CZ[I+1].
NOTE: K clusters built by this subroutine are assumed to have no hierarchy.
Although they were obtained by manipulation with top K nodes of
dendrogram (i.e. hierarchical decomposition of dataset), this
function does not return information about hierarchy. Each of the
clusters stand on its own.
NOTE: Cluster indexes returned by this function does not correspond to
indexes returned in Rep.Z/PZ/PM. Either you work with hierarchical
representation of the dataset (dendrogram), or you work with "flat"
representation returned by this function. Each of representations
has its own clusters indexing system (former uses [0, 2*NPoints-2]),
while latter uses [0..K-1]), although it is possible to perform
conversion from one system to another by means of CZ array, returned
by this function, which allows you to convert indexes stored in CIdx
to the numeration system used by Rep.Z.
NOTE: this subroutine is optimized for moderate values of K. Say, for K=5
it will perform many times faster than for K=100. Its worst-case
performance is O(N*K), although in average case it perform better
(up to O(N*log(K))).
-- ALGLIB --
Copyright 10.07.2012 by Bochkanov Sergey
*************************************************************************/
</div><div style='margin-top: 0; margin-bottom: 0;'><b>void</b> alglib::clusterizerseparatedbycorr(
ahcreport rep,
<b>double</b> r,
ae_int_t& k,
integer_1d_array& cidx,
integer_1d_array& cz);
</div></pre>
<a name='sub_clusterizerseparatedbydist'></a><h3 class=pageheader><code>clusterizerseparatedbydist</code> function</h3>
<pre class=source>
<div style='color: navy; margin-top: 0; margin-bottom: 0;'>/*************************************************************************
This function accepts AHC report Rep, desired minimum intercluster
distance and returns top clusters from hierarchical clusterization tree
which are separated by distance R or HIGHER.
It returns assignment of points to clusters (array of cluster indexes).
There is one more function with similar name - ClusterizerSeparatedByCorr,
which returns clusters with intercluster correlation equal to R or LOWER
(note: higher for distance, lower for correlation).
INPUT PARAMETERS:
Rep - report from ClusterizerRunAHC() performed on XY
R - desired minimum intercluster distance, R>=0
OUTPUT PARAMETERS:
K - number of clusters, 1<=K<=NPoints
CIdx - array[NPoints], I-th element contains cluster index (from
0 to K-1) for I-th point of the dataset.
CZ - array[K]. This array allows to convert cluster indexes
returned by this function to indexes used by Rep.Z. J-th
cluster returned by this function corresponds to CZ[J]-th
cluster stored in Rep.Z/PZ/PM.
It is guaranteed that CZ[I]<CZ[I+1].
NOTE: K clusters built by this subroutine are assumed to have no hierarchy.
Although they were obtained by manipulation with top K nodes of
dendrogram (i.e. hierarchical decomposition of dataset), this
function does not return information about hierarchy. Each of the
clusters stand on its own.
NOTE: Cluster indexes returned by this function does not correspond to
indexes returned in Rep.Z/PZ/PM. Either you work with hierarchical
representation of the dataset (dendrogram), or you work with "flat"
representation returned by this function. Each of representations
has its own clusters indexing system (former uses [0, 2*NPoints-2]),
while latter uses [0..K-1]), although it is possible to perform
conversion from one system to another by means of CZ array, returned
by this function, which allows you to convert indexes stored in CIdx
to the numeration system used by Rep.Z.
NOTE: this subroutine is optimized for moderate values of K. Say, for K=5
it will perform many times faster than for K=100. Its worst-case
performance is O(N*K), although in average case it perform better
(up to O(N*log(K))).
-- ALGLIB --
Copyright 10.07.2012 by Bochkanov Sergey
*************************************************************************/
</div><div style='margin-top: 0; margin-bottom: 0;'><b>void</b> alglib::clusterizerseparatedbydist(
ahcreport rep,
<b>double</b> r,
ae_int_t& k,
integer_1d_array& cidx,
integer_1d_array& cz);
</div></pre>
<a name='sub_clusterizersetahcalgo'></a><h3 class=pageheader><code>clusterizersetahcalgo</code> function</h3>
<pre class=source>
<div style='color: navy; margin-top: 0; margin-bottom: 0;'>/*************************************************************************
This function sets agglomerative hierarchical clustering algorithm
INPUT PARAMETERS:
S - clusterizer state, initialized by ClusterizerCreate()
Algo - algorithm type:
* 0 complete linkage (default algorithm)
* 1 single linkage
* 2 unweighted average linkage
* 3 weighted average linkage
* 4 Ward's method
NOTE: Ward's method works correctly only with Euclidean distance, that's
why algorithm will return negative termination code (failure) for
any other distance type.
It is possible, however, to use this method with user-supplied
distance matrix. It is your responsibility to pass one which was
calculated with Euclidean distance function.
-- ALGLIB --
Copyright 10.07.2012 by Bochkanov Sergey
*************************************************************************/
</div><div style='margin-top: 0; margin-bottom: 0;'><b>void</b> alglib::clusterizersetahcalgo(clusterizerstate s, ae_int_t algo);
</div></pre>
<p align=left class=pagecontent><span class=inlineheader>Examples:</span> <a href='#example_clst_ahc' class=nav>[1]</a> <a href='#example_clst_kmeans' class=nav>[2]</a> <a href='#example_clst_linkage' class=nav>[3]</a> <a href='#example_clst_distance' class=nav>[4]</a> <a href='#example_clst_kclusters' class=nav>[5]</a> </p>
<a name='sub_clusterizersetdistances'></a><h3 class=pageheader><code>clusterizersetdistances</code> function</h3>
<pre class=source>
<div style='color: navy; margin-top: 0; margin-bottom: 0;'>/*************************************************************************
This function adds dataset given by distance matrix to the clusterizer
structure. It is important that dataset is not given explicitly - only
distance matrix is given.
This function overrides all previous calls of ClusterizerSetPoints() or
ClusterizerSetDistances().
INPUT PARAMETERS:
S - clusterizer state, initialized by ClusterizerCreate()
D - array[NPoints,NPoints], distance matrix given by its upper
or lower triangle (main diagonal is ignored because its
entries are expected to be zero).
NPoints - number of points
IsUpper - whether upper or lower triangle of D is given.
NOTE 1: different clustering algorithms have different limitations:
* agglomerative hierarchical clustering algorithms may be used with
any kind of distance metric, including one which is given by
distance matrix
* k-means++ clustering algorithm may be used only with Euclidean
distance function and explicitly given points - it can not be
used with dataset given by distance matrix
Thus, if you call this function, you will be unable to use k-means
clustering algorithm to process your problem.
-- ALGLIB --
Copyright 10.07.2012 by Bochkanov Sergey
*************************************************************************/
</div><div style='margin-top: 0; margin-bottom: 0;'><b>void</b> alglib::clusterizersetdistances(
clusterizerstate s,
real_2d_array d,
<b>bool</b> isupper);
<b>void</b> alglib::clusterizersetdistances(
clusterizerstate s,
real_2d_array d,
ae_int_t npoints,
<b>bool</b> isupper);
</div></pre>
<p align=left class=pagecontent><span class=inlineheader>Examples:</span> <a href='#example_clst_distance' class=nav>[1]</a> </p>
<a name='sub_clusterizersetkmeansinit'></a><h3 class=pageheader><code>clusterizersetkmeansinit</code> function</h3>
<pre class=source>
<div style='color: navy; margin-top: 0; margin-bottom: 0;'>/*************************************************************************
This function sets k-means initialization algorithm. Several different
algorithms can be chosen, including k-means++.
INPUT PARAMETERS:
S - clusterizer state, initialized by ClusterizerCreate()
InitAlgo- initialization algorithm:
* 0 automatic selection ( different versions of ALGLIB
may select different algorithms)
* 1 random initialization
* 2 k-means++ initialization (best quality of initial
centers, but long non-parallelizable initialization
phase with bad cache locality)
* 3 "fast-greedy" algorithm with efficient, easy to
parallelize initialization. Quality of initial centers
is somewhat worse than that of k-means++. This
algorithm is a default one in the current version of
ALGLIB.
*-1 "debug" algorithm which always selects first K rows
of dataset; this algorithm is used for debug purposes
only. Do not use it in the industrial code!
-- ALGLIB --
Copyright 21.01.2015 by Bochkanov Sergey
*************************************************************************/
</div><div style='margin-top: 0; margin-bottom: 0;'><b>void</b> alglib::clusterizersetkmeansinit(
clusterizerstate s,
ae_int_t initalgo);
</div></pre>
<a name='sub_clusterizersetkmeanslimits'></a><h3 class=pageheader><code>clusterizersetkmeanslimits</code> function</h3>
<pre class=source>
<div style='color: navy; margin-top: 0; margin-bottom: 0;'>/*************************************************************************
This function sets k-means properties: number of restarts and maximum
number of iterations per one run.
INPUT PARAMETERS:
S - clusterizer state, initialized by ClusterizerCreate()
Restarts- restarts count, >=1.
k-means++ algorithm performs several restarts and chooses
best set of centers (one with minimum squared distance).
MaxIts - maximum number of k-means iterations performed during one
run. >=0, zero value means that algorithm performs unlimited
number of iterations.
-- ALGLIB --
Copyright 10.07.2012 by Bochkanov Sergey
*************************************************************************/
</div><div style='margin-top: 0; margin-bottom: 0;'><b>void</b> alglib::clusterizersetkmeanslimits(
clusterizerstate s,
ae_int_t restarts,
ae_int_t maxits);
</div></pre>
<a name='sub_clusterizersetpoints'></a><h3 class=pageheader><code>clusterizersetpoints</code> function</h3>
<pre class=source>
<div style='color: navy; margin-top: 0; margin-bottom: 0;'>/*************************************************************************
This function adds dataset to the clusterizer structure.
This function overrides all previous calls of ClusterizerSetPoints() or
ClusterizerSetDistances().
INPUT PARAMETERS:
S - clusterizer state, initialized by ClusterizerCreate()
XY - array[NPoints,NFeatures], dataset
NPoints - number of points, >=0
NFeatures- number of features, >=1
DistType- distance function:
* 0 Chebyshev distance (L-inf norm)
* 1 city block distance (L1 norm)
* 2 Euclidean distance (L2 norm), non-squared
* 10 Pearson correlation:
dist(a,b) = 1-corr(a,b)
* 11 Absolute Pearson correlation:
dist(a,b) = 1-|corr(a,b)|
* 12 Uncentered Pearson correlation (cosine of the angle):
dist(a,b) = a'*b/(|a|*|b|)
* 13 Absolute uncentered Pearson correlation
dist(a,b) = |a'*b|/(|a|*|b|)
* 20 Spearman rank correlation:
dist(a,b) = 1-rankcorr(a,b)
* 21 Absolute Spearman rank correlation
dist(a,b) = 1-|rankcorr(a,b)|
NOTE 1: different distance functions have different performance penalty:
* Euclidean or Pearson correlation distances are the fastest ones
* Spearman correlation distance function is a bit slower
* city block and Chebyshev distances are order of magnitude slower
The reason behing difference in performance is that correlation-based
distance functions are computed using optimized linear algebra kernels,
while Chebyshev and city block distance functions are computed using
simple nested loops with two branches at each iteration.
NOTE 2: different clustering algorithms have different limitations:
* agglomerative hierarchical clustering algorithms may be used with
any kind of distance metric
* k-means++ clustering algorithm may be used only with Euclidean
distance function
Thus, list of specific clustering algorithms you may use depends
on distance function you specify when you set your dataset.
-- ALGLIB --
Copyright 10.07.2012 by Bochkanov Sergey
*************************************************************************/
</div><div style='margin-top: 0; margin-bottom: 0;'><b>void</b> alglib::clusterizersetpoints(
clusterizerstate s,
real_2d_array xy,
ae_int_t disttype);
<b>void</b> alglib::clusterizersetpoints(
clusterizerstate s,
real_2d_array xy,
ae_int_t npoints,
ae_int_t nfeatures,
ae_int_t disttype);
</div></pre>
<p align=left class=pagecontent><span class=inlineheader>Examples:</span> <a href='#example_clst_ahc' class=nav>[1]</a> <a href='#example_clst_kmeans' class=nav>[2]</a> <a href='#example_clst_linkage' class=nav>[3]</a> <a href='#example_clst_distance' class=nav>[4]</a> <a href='#example_clst_kclusters' class=nav>[5]</a> </p>
<a name='example_clst_ahc'></a><h3 class=pageheader>clst_ahc example</h3>
<pre class=source>
#include <font color=blue><b>"stdafx.h"</b></font>
#include <stdlib.h>
#include <stdio.h>
#include <math.h>
#include <font color=blue><b>"dataanalysis.h"</b></font>
using namespace alglib;
<b>int</b> main(<b>int</b> argc, char **argv)
{
<font color=navy>//</font>
<font color=navy>// The very simple clusterization example</font>
<font color=navy>//</font>
<font color=navy>// We have a set of points in 2D space:</font>
<font color=navy>// (P0,P1,P2,P3,P4) = ((1,1),(1,2),(4,1),(2,3),(4,1.5))</font>
<font color=navy>//</font>
<font color=navy>// |</font>
<font color=navy>// | P3</font>
<font color=navy>// |</font>
<font color=navy>// | P1 </font>
<font color=navy>// | P4</font>
<font color=navy>// | P0 P2</font>
<font color=navy>// |-------------------------</font>
<font color=navy>//</font>
<font color=navy>// We want to perform Agglomerative Hierarchic Clusterization (AHC),</font>
<font color=navy>// using complete linkage (default algorithm) and Euclidean distance</font>
<font color=navy>// (default metric).</font>
<font color=navy>//</font>
<font color=navy>// In order to <b>do</b> that, we:</font>
<font color=navy>// * create clusterizer with clusterizercreate()</font>
<font color=navy>// * set points XY and metric (2=Euclidean) with clusterizersetpoints()</font>
<font color=navy>// * run AHC algorithm with clusterizerrunahc</font>
<font color=navy>//</font>
<font color=navy>// You may see that clusterization itself is a minor part of the example,</font>
<font color=navy>// most of which is dominated by comments :)</font>
<font color=navy>//</font>
clusterizerstate s;
ahcreport rep;
real_2d_array xy = <font color=blue><b>"[[1,1],[1,2],[4,1],[2,3],[4,1.5]]"</b></font>;
clusterizercreate(s);
clusterizersetpoints(s, xy, 2);
clusterizerrunahc(s, rep);
<font color=navy>//</font>
<font color=navy>// Now we've built our clusterization tree. Rep.z contains information which</font>
<font color=navy>// is required to build dendrogram. I-th row of rep.z represents one merge</font>
<font color=navy>// operation, with first cluster to merge having index rep.z[I,0] and second</font>
<font color=navy>// one having index rep.z[I,1]. Merge result has index NPoints+I.</font>
<font color=navy>//</font>
<font color=navy>// Clusters with indexes less than NPoints are single-point initial clusters,</font>
<font color=navy>// <b>while</b> ones with indexes from NPoints to 2*NPoints-2 are multi-point</font>
<font color=navy>// clusters created during merges.</font>
<font color=navy>//</font>
<font color=navy>// In our example, Z=[[2,4], [0,1], [3,6], [5,7]]</font>
<font color=navy>//</font>
<font color=navy>// It means that:</font>
<font color=navy>// * first, we merge C2=(P2) and C4=(P4), and create C5=(P2,P4)</font>
<font color=navy>// * then, we merge C2=(P0) and C1=(P1), and create C6=(P0,P1)</font>
<font color=navy>// * then, we merge C3=(P3) and C6=(P0,P1), and create C7=(P0,P1,P3)</font>
<font color=navy>// * finally, we merge C5 and C7 and create C8=(P0,P1,P2,P3,P4)</font>
<font color=navy>//</font>
<font color=navy>// Thus, we have following dendrogram:</font>
<font color=navy>// </font>
<font color=navy>// ------8-----</font>
<font color=navy>// | |</font>
<font color=navy>// | ----7----</font>
<font color=navy>// | | |</font>
<font color=navy>// ---5--- | ---6---</font>
<font color=navy>// | | | | |</font>
<font color=navy>// P2 P4 P3 P0 P1</font>
<font color=navy>//</font>
printf(<font color=blue><b>"%s\n"</b></font>, rep.z.tostring().c_str()); <font color=navy>// EXPECTED: [[2,4],[0,1],[3,6],[5,7]]</font>
<font color=navy>//</font>
<font color=navy>// We've built dendrogram above by reordering our dataset.</font>
<font color=navy>//</font>
<font color=navy>// Without such reordering it would be impossible to build dendrogram without</font>
<font color=navy>// intersections. Luckily, ahcreport structure contains two additional fields</font>
<font color=navy>// which help to build dendrogram from your data:</font>
<font color=navy>// * rep.p, which contains permutation applied to dataset</font>
<font color=navy>// * rep.pm, which contains another representation of merges </font>
<font color=navy>//</font>
<font color=navy>// In our example we have:</font>
<font color=navy>// * P=[3,4,0,2,1]</font>
<font color=navy>// * PZ=[[0,0,1,1,0,0],[3,3,4,4,0,0],[2,2,3,4,0,1],[0,1,2,4,1,2]]</font>
<font color=navy>//</font>
<font color=navy>// Permutation array P tells us that P0 should be moved to position 3,</font>
<font color=navy>// P1 moved to position 4, P2 moved to position 0 and so on:</font>
<font color=navy>//</font>
<font color=navy>// (P0 P1 P2 P3 P4) => (P2 P4 P3 P0 P1)</font>
<font color=navy>//</font>
<font color=navy>// Merges array PZ tells us how to perform merges on the sorted dataset.</font>
<font color=navy>// One row of PZ corresponds to one merge operations, with first pair of</font>
<font color=navy>// elements denoting first of the clusters to merge (start index, end</font>
<font color=navy>// index) and next pair of elements denoting second of the clusters to</font>
<font color=navy>// merge. Clusters being merged are always adjacent, with first one on</font>
<font color=navy>// the left and second one on the right.</font>
<font color=navy>//</font>
<font color=navy>// For example, first row of PZ tells us that clusters [0,0] and [1,1] are</font>
<font color=navy>// merged (single-point clusters, with first one containing P2 and second</font>
<font color=navy>// one containing P4). Third row of PZ tells us that we merge one single-</font>
<font color=navy>// point cluster [2,2] with one two-point cluster [3,4].</font>
<font color=navy>//</font>
<font color=navy>// There are two more elements in each row of PZ. These are the helper</font>
<font color=navy>// elements, which denote HEIGHT (not size) of left and right subdendrograms.</font>
<font color=navy>// For example, according to PZ, first two merges are performed on clusterization</font>
<font color=navy>// trees of height 0, <b>while</b> next two merges are performed on 0-1 and 1-2</font>
<font color=navy>// pairs of trees correspondingly.</font>
<font color=navy>//</font>
printf(<font color=blue><b>"%s\n"</b></font>, rep.p.tostring().c_str()); <font color=navy>// EXPECTED: [3,4,0,2,1]</font>
printf(<font color=blue><b>"%s\n"</b></font>, rep.pm.tostring().c_str()); <font color=navy>// EXPECTED: [[0,0,1,1,0,0],[3,3,4,4,0,0],[2,2,3,4,0,1],[0,1,2,4,1,2]]</font>
<b>return</b> 0;
}
</pre><a name='example_clst_distance'></a><h3 class=pageheader>clst_distance example</h3>
<pre class=source>
#include <font color=blue><b>"stdafx.h"</b></font>
#include <stdlib.h>
#include <stdio.h>
#include <math.h>
#include <font color=blue><b>"dataanalysis.h"</b></font>
using namespace alglib;
<b>int</b> main(<b>int</b> argc, char **argv)
{
<font color=navy>//</font>
<font color=navy>// We have three points in 4D space:</font>
<font color=navy>// (P0,P1,P2) = ((1, 2, 1, 2), (6, 7, 6, 7), (7, 6, 7, 6))</font>
<font color=navy>//</font>
<font color=navy>// We want to try clustering them with different distance functions.</font>
<font color=navy>// Distance function is chosen when we add dataset to the clusterizer.</font>
<font color=navy>// We can choose several distance types - Euclidean, city block, Chebyshev,</font>
<font color=navy>// several correlation measures or user-supplied distance matrix.</font>
<font color=navy>//</font>
<font color=navy>// Here we'll try three distances: Euclidean, Pearson correlation,</font>
<font color=navy>// user-supplied distance matrix. Different distance functions lead</font>
<font color=navy>// to different choices being made by algorithm during clustering.</font>
<font color=navy>//</font>
clusterizerstate s;
ahcreport rep;
ae_int_t disttype;
real_2d_array xy = <font color=blue><b>"[[1, 2, 1, 2], [6, 7, 6, 7], [7, 6, 7, 6]]"</b></font>;
clusterizercreate(s);
<font color=navy>// With Euclidean distance function (disttype=2) two closest points</font>
<font color=navy>// are P1 and P2, thus:</font>
<font color=navy>// * first, we merge P1 and P2 to form C3=[P1,P2]</font>
<font color=navy>// * second, we merge P0 and C3 to form C4=[P0,P1,P2]</font>
disttype = 2;
clusterizersetpoints(s, xy, disttype);
clusterizerrunahc(s, rep);
printf(<font color=blue><b>"%s\n"</b></font>, rep.z.tostring().c_str()); <font color=navy>// EXPECTED: [[1,2],[0,3]]</font>
<font color=navy>// With Pearson correlation distance function (disttype=10) situation</font>
<font color=navy>// is different - distance between P0 and P1 is zero, thus:</font>
<font color=navy>// * first, we merge P0 and P1 to form C3=[P0,P1]</font>
<font color=navy>// * second, we merge P2 and C3 to form C4=[P0,P1,P2]</font>
disttype = 10;
clusterizersetpoints(s, xy, disttype);
clusterizerrunahc(s, rep);
printf(<font color=blue><b>"%s\n"</b></font>, rep.z.tostring().c_str()); <font color=navy>// EXPECTED: [[0,1],[2,3]]</font>
<font color=navy>// Finally, we try clustering with user-supplied distance matrix:</font>
<font color=navy>// [ 0 3 1 ]</font>
<font color=navy>// P = [ 3 0 3 ], where P[i,j] = dist(Pi,Pj)</font>
<font color=navy>// [ 1 3 0 ]</font>
<font color=navy>//</font>
<font color=navy>// * first, we merge P0 and P2 to form C3=[P0,P2]</font>
<font color=navy>// * second, we merge P1 and C3 to form C4=[P0,P1,P2]</font>
real_2d_array d = <font color=blue><b>"[[0,3,1],[3,0,3],[1,3,0]]"</b></font>;
clusterizersetdistances(s, d, true);
clusterizerrunahc(s, rep);
printf(<font color=blue><b>"%s\n"</b></font>, rep.z.tostring().c_str()); <font color=navy>// EXPECTED: [[0,2],[1,3]]</font>
<b>return</b> 0;
}
</pre><a name='example_clst_kclusters'></a><h3 class=pageheader>clst_kclusters example</h3>
<pre class=source>
#include <font color=blue><b>"stdafx.h"</b></font>
#include <stdlib.h>
#include <stdio.h>
#include <math.h>
#include <font color=blue><b>"dataanalysis.h"</b></font>
using namespace alglib;
<b>int</b> main(<b>int</b> argc, char **argv)
{
<font color=navy>//</font>
<font color=navy>// We have a set of points in 2D space:</font>
<font color=navy>// (P0,P1,P2,P3,P4) = ((1,1),(1,2),(4,1),(2,3),(4,1.5))</font>
<font color=navy>//</font>
<font color=navy>// |</font>
<font color=navy>// | P3</font>
<font color=navy>// |</font>
<font color=navy>// | P1 </font>
<font color=navy>// | P4</font>
<font color=navy>// | P0 P2</font>
<font color=navy>// |-------------------------</font>
<font color=navy>//</font>
<font color=navy>// We perform Agglomerative Hierarchic Clusterization (AHC) and we want</font>
<font color=navy>// to get top K clusters from clusterization tree <b>for</b> different K.</font>
<font color=navy>//</font>
clusterizerstate s;
ahcreport rep;
real_2d_array xy = <font color=blue><b>"[[1,1],[1,2],[4,1],[2,3],[4,1.5]]"</b></font>;
integer_1d_array cidx;
integer_1d_array cz;
clusterizercreate(s);
clusterizersetpoints(s, xy, 2);
clusterizerrunahc(s, rep);
<font color=navy>// with K=5, every points is assigned to its own cluster:</font>
<font color=navy>// C0=P0, C1=P1 and so on...</font>
clusterizergetkclusters(rep, 5, cidx, cz);
printf(<font color=blue><b>"%s\n"</b></font>, cidx.tostring().c_str()); <font color=navy>// EXPECTED: [0,1,2,3,4]</font>
<font color=navy>// with K=1 we have one large cluster C0=[P0,P1,P2,P3,P4,P5]</font>
clusterizergetkclusters(rep, 1, cidx, cz);
printf(<font color=blue><b>"%s\n"</b></font>, cidx.tostring().c_str()); <font color=navy>// EXPECTED: [0,0,0,0,0]</font>
<font color=navy>// with K=3 we have three clusters C0=[P3], C1=[P2,P4], C2=[P0,P1]</font>
clusterizergetkclusters(rep, 3, cidx, cz);
printf(<font color=blue><b>"%s\n"</b></font>, cidx.tostring().c_str()); <font color=navy>// EXPECTED: [2,2,1,0,1]</font>
<b>return</b> 0;
}
</pre><a name='example_clst_kmeans'></a><h3 class=pageheader>clst_kmeans example</h3>
<pre class=source>
#include <font color=blue><b>"stdafx.h"</b></font>
#include <stdlib.h>
#include <stdio.h>
#include <math.h>
#include <font color=blue><b>"dataanalysis.h"</b></font>
using namespace alglib;
<b>int</b> main(<b>int</b> argc, char **argv)
{
<font color=navy>//</font>
<font color=navy>// The very simple clusterization example</font>
<font color=navy>//</font>
<font color=navy>// We have a set of points in 2D space:</font>
<font color=navy>// (P0,P1,P2,P3,P4) = ((1,1),(1,2),(4,1),(2,3),(4,1.5))</font>
<font color=navy>//</font>
<font color=navy>// |</font>
<font color=navy>// | P3</font>
<font color=navy>// |</font>
<font color=navy>// | P1 </font>
<font color=navy>// | P4</font>
<font color=navy>// | P0 P2</font>
<font color=navy>// |-------------------------</font>
<font color=navy>//</font>
<font color=navy>// We want to perform k-means++ clustering with K=2.</font>
<font color=navy>//</font>
<font color=navy>// In order to <b>do</b> that, we:</font>
<font color=navy>// * create clusterizer with clusterizercreate()</font>
<font color=navy>// * set points XY and metric (must be Euclidean, distype=2) with clusterizersetpoints()</font>
<font color=navy>// * (optional) set number of restarts from random positions to 5</font>
<font color=navy>// * run k-means algorithm with clusterizerrunkmeans()</font>
<font color=navy>//</font>
<font color=navy>// You may see that clusterization itself is a minor part of the example,</font>
<font color=navy>// most of which is dominated by comments :)</font>
<font color=navy>//</font>
clusterizerstate s;
kmeansreport rep;
real_2d_array xy = <font color=blue><b>"[[1,1],[1,2],[4,1],[2,3],[4,1.5]]"</b></font>;
clusterizercreate(s);
clusterizersetpoints(s, xy, 2);
clusterizersetkmeanslimits(s, 5, 0);
clusterizerrunkmeans(s, 2, rep);
<font color=navy>//</font>
<font color=navy>// We've performed clusterization, and it succeeded (completion code is +1).</font>
<font color=navy>//</font>
<font color=navy>// Now first center is stored in the first row of rep.c, second one is stored</font>
<font color=navy>// in the second row. rep.cidx can be used to determine which center is</font>
<font color=navy>// closest to some specific point of the dataset.</font>
<font color=navy>//</font>
printf(<font color=blue><b>"%d\n"</b></font>, <b>int</b>(rep.terminationtype)); <font color=navy>// EXPECTED: 1</font>
<font color=navy>// We called clusterizersetpoints() with disttype=2 because k-means++</font>
<font color=navy>// algorithm does NOT support metrics other than Euclidean. But what <b>if</b> we</font>
<font color=navy>// try to use some other metric?</font>
<font color=navy>//</font>
<font color=navy>// We change metric type by calling clusterizersetpoints() one more time,</font>
<font color=navy>// and try to run k-means algo again. It fails.</font>
<font color=navy>//</font>
clusterizersetpoints(s, xy, 0);
clusterizerrunkmeans(s, 2, rep);
printf(<font color=blue><b>"%d\n"</b></font>, <b>int</b>(rep.terminationtype)); <font color=navy>// EXPECTED: -5</font>
<b>return</b> 0;
}
</pre><a name='example_clst_linkage'></a><h3 class=pageheader>clst_linkage example</h3>
<pre class=source>
#include <font color=blue><b>"stdafx.h"</b></font>
#include <stdlib.h>
#include <stdio.h>
#include <math.h>
#include <font color=blue><b>"dataanalysis.h"</b></font>
using namespace alglib;
<b>int</b> main(<b>int</b> argc, char **argv)
{
<font color=navy>//</font>
<font color=navy>// We have a set of points in 1D space:</font>
<font color=navy>// (P0,P1,P2,P3,P4) = (1, 3, 10, 16, 20)</font>
<font color=navy>//</font>
<font color=navy>// We want to perform Agglomerative Hierarchic Clusterization (AHC),</font>
<font color=navy>// using either complete or single linkage and Euclidean distance</font>
<font color=navy>// (default metric).</font>
<font color=navy>//</font>
<font color=navy>// First two steps merge P0/P1 and P3/P4 independently of the linkage type.</font>
<font color=navy>// However, third step depends on linkage type being used:</font>
<font color=navy>// * in case of complete linkage P2=10 is merged with [P0,P1]</font>
<font color=navy>// * in case of single linkage P2=10 is merged with [P3,P4]</font>
<font color=navy>//</font>
clusterizerstate s;
ahcreport rep;
real_2d_array xy = <font color=blue><b>"[[1],[3],[10],[16],[20]]"</b></font>;
integer_1d_array cidx;
integer_1d_array cz;
clusterizercreate(s);
clusterizersetpoints(s, xy, 2);
<font color=navy>// use complete linkage, reduce set down to 2 clusters.</font>
<font color=navy>// print clusterization with clusterizergetkclusters(2).</font>
<font color=navy>// P2 must belong to [P0,P1]</font>
clusterizersetahcalgo(s, 0);
clusterizerrunahc(s, rep);
clusterizergetkclusters(rep, 2, cidx, cz);
printf(<font color=blue><b>"%s\n"</b></font>, cidx.tostring().c_str()); <font color=navy>// EXPECTED: [1,1,1,0,0]</font>
<font color=navy>// use single linkage, reduce set down to 2 clusters.</font>
<font color=navy>// print clusterization with clusterizergetkclusters(2).</font>
<font color=navy>// P2 must belong to [P2,P3]</font>
clusterizersetahcalgo(s, 1);
clusterizerrunahc(s, rep);
clusterizergetkclusters(rep, 2, cidx, cz);
printf(<font color=blue><b>"%s\n"</b></font>, cidx.tostring().c_str()); <font color=navy>// EXPECTED: [0,0,1,1,1]</font>
<b>return</b> 0;
}
</pre><a name=unit_conv></a><h2 class=pageheader><code>conv</code> subpackage</h2>
<div class=pagecontent>
<h3 class=pageheader>Functions</h3>
<a href='#sub_convc1d' class=toc>convc1d</a><br>
<a href='#sub_convc1dcircular' class=toc>convc1dcircular</a><br>
<a href='#sub_convc1dcircularinv' class=toc>convc1dcircularinv</a><br>
<a href='#sub_convc1dinv' class=toc>convc1dinv</a><br>
<a href='#sub_convr1d' class=toc>convr1d</a><br>
<a href='#sub_convr1dcircular' class=toc>convr1dcircular</a><br>
<a href='#sub_convr1dcircularinv' class=toc>convr1dcircularinv</a><br>
<a href='#sub_convr1dinv' class=toc>convr1dinv</a><br>
<h3 class=pageheader>Examples</h3>
<table border=0 cellspacing=0 class='pagecontent'>
</table></div>
<a name='sub_convc1d'></a><h3 class=pageheader><code>convc1d</code> function</h3>
<pre class=source>
<div style='color: navy; margin-top: 0; margin-bottom: 0;'>/*************************************************************************
1-dimensional complex convolution.
For given A/B returns conv(A,B) (non-circular). Subroutine can automatically
choose between three implementations: straightforward O(M*N) formula for
very small N (or M), overlap-add algorithm for cases where max(M,N) is
significantly larger than min(M,N), but O(M*N) algorithm is too slow, and
general FFT-based formula for cases where two previois algorithms are too
slow.
Algorithm has max(M,N)*log(max(M,N)) complexity for any M/N.
INPUT PARAMETERS
A - array[0..M-1] - complex function to be transformed
M - problem size
B - array[0..N-1] - complex function to be transformed
N - problem size
OUTPUT PARAMETERS
R - convolution: A*B. array[0..N+M-2].
NOTE:
It is assumed that A is zero at T<0, B is zero too. If one or both
functions have non-zero values at negative T's, you can still use this
subroutine - just shift its result correspondingly.
-- ALGLIB --
Copyright 21.07.2009 by Bochkanov Sergey
*************************************************************************/
</div><div style='margin-top: 0; margin-bottom: 0;'><b>void</b> alglib::convc1d(
complex_1d_array a,
ae_int_t m,
complex_1d_array b,
ae_int_t n,
complex_1d_array& r);
</div></pre>
<a name='sub_convc1dcircular'></a><h3 class=pageheader><code>convc1dcircular</code> function</h3>
<pre class=source>
<div style='color: navy; margin-top: 0; margin-bottom: 0;'>/*************************************************************************
1-dimensional circular complex convolution.
For given S/R returns conv(S,R) (circular). Algorithm has linearithmic
complexity for any M/N.
IMPORTANT: normal convolution is commutative, i.e. it is symmetric -
conv(A,B)=conv(B,A). Cyclic convolution IS NOT. One function - S - is a
signal, periodic function, and another - R - is a response, non-periodic
function with limited length.
INPUT PARAMETERS
S - array[0..M-1] - complex periodic signal
M - problem size
B - array[0..N-1] - complex non-periodic response
N - problem size
OUTPUT PARAMETERS
R - convolution: A*B. array[0..M-1].
NOTE:
It is assumed that B is zero at T<0. If it has non-zero values at
negative T's, you can still use this subroutine - just shift its result
correspondingly.
-- ALGLIB --
Copyright 21.07.2009 by Bochkanov Sergey
*************************************************************************/
</div><div style='margin-top: 0; margin-bottom: 0;'><b>void</b> alglib::convc1dcircular(
complex_1d_array s,
ae_int_t m,
complex_1d_array r,
ae_int_t n,
complex_1d_array& c);
</div></pre>
<a name='sub_convc1dcircularinv'></a><h3 class=pageheader><code>convc1dcircularinv</code> function</h3>
<pre class=source>
<div style='color: navy; margin-top: 0; margin-bottom: 0;'>/*************************************************************************
1-dimensional circular complex deconvolution (inverse of ConvC1DCircular()).
Algorithm has M*log(M)) complexity for any M (composite or prime).
INPUT PARAMETERS
A - array[0..M-1] - convolved periodic signal, A = conv(R, B)
M - convolved signal length
B - array[0..N-1] - non-periodic response
N - response length
OUTPUT PARAMETERS
R - deconvolved signal. array[0..M-1].
NOTE:
deconvolution is unstable process and may result in division by zero
(if your response function is degenerate, i.e. has zero Fourier coefficient).
NOTE:
It is assumed that B is zero at T<0. If it has non-zero values at
negative T's, you can still use this subroutine - just shift its result
correspondingly.
-- ALGLIB --
Copyright 21.07.2009 by Bochkanov Sergey
*************************************************************************/
</div><div style='margin-top: 0; margin-bottom: 0;'><b>void</b> alglib::convc1dcircularinv(
complex_1d_array a,
ae_int_t m,
complex_1d_array b,
ae_int_t n,
complex_1d_array& r);
</div></pre>
<a name='sub_convc1dinv'></a><h3 class=pageheader><code>convc1dinv</code> function</h3>
<pre class=source>
<div style='color: navy; margin-top: 0; margin-bottom: 0;'>/*************************************************************************
1-dimensional complex non-circular deconvolution (inverse of ConvC1D()).
Algorithm has M*log(M)) complexity for any M (composite or prime).
INPUT PARAMETERS
A - array[0..M-1] - convolved signal, A = conv(R, B)
M - convolved signal length
B - array[0..N-1] - response
N - response length, N<=M
OUTPUT PARAMETERS
R - deconvolved signal. array[0..M-N].
NOTE:
deconvolution is unstable process and may result in division by zero
(if your response function is degenerate, i.e. has zero Fourier coefficient).
NOTE:
It is assumed that A is zero at T<0, B is zero too. If one or both
functions have non-zero values at negative T's, you can still use this
subroutine - just shift its result correspondingly.
-- ALGLIB --
Copyright 21.07.2009 by Bochkanov Sergey
*************************************************************************/
</div><div style='margin-top: 0; margin-bottom: 0;'><b>void</b> alglib::convc1dinv(
complex_1d_array a,
ae_int_t m,
complex_1d_array b,
ae_int_t n,
complex_1d_array& r);
</div></pre>
<a name='sub_convr1d'></a><h3 class=pageheader><code>convr1d</code> function</h3>
<pre class=source>
<div style='color: navy; margin-top: 0; margin-bottom: 0;'>/*************************************************************************
1-dimensional real convolution.
Analogous to ConvC1D(), see ConvC1D() comments for more details.
INPUT PARAMETERS
A - array[0..M-1] - real function to be transformed
M - problem size
B - array[0..N-1] - real function to be transformed
N - problem size
OUTPUT PARAMETERS
R - convolution: A*B. array[0..N+M-2].
NOTE:
It is assumed that A is zero at T<0, B is zero too. If one or both
functions have non-zero values at negative T's, you can still use this
subroutine - just shift its result correspondingly.
-- ALGLIB --
Copyright 21.07.2009 by Bochkanov Sergey
*************************************************************************/
</div><div style='margin-top: 0; margin-bottom: 0;'><b>void</b> alglib::convr1d(
real_1d_array a,
ae_int_t m,
real_1d_array b,
ae_int_t n,
real_1d_array& r);
</div></pre>
<a name='sub_convr1dcircular'></a><h3 class=pageheader><code>convr1dcircular</code> function</h3>
<pre class=source>
<div style='color: navy; margin-top: 0; margin-bottom: 0;'>/*************************************************************************
1-dimensional circular real convolution.
Analogous to ConvC1DCircular(), see ConvC1DCircular() comments for more details.
INPUT PARAMETERS
S - array[0..M-1] - real signal
M - problem size
B - array[0..N-1] - real response
N - problem size
OUTPUT PARAMETERS
R - convolution: A*B. array[0..M-1].
NOTE:
It is assumed that B is zero at T<0. If it has non-zero values at
negative T's, you can still use this subroutine - just shift its result
correspondingly.
-- ALGLIB --
Copyright 21.07.2009 by Bochkanov Sergey
*************************************************************************/
</div><div style='margin-top: 0; margin-bottom: 0;'><b>void</b> alglib::convr1dcircular(
real_1d_array s,
ae_int_t m,
real_1d_array r,
ae_int_t n,
real_1d_array& c);
</div></pre>
<a name='sub_convr1dcircularinv'></a><h3 class=pageheader><code>convr1dcircularinv</code> function</h3>
<pre class=source>
<div style='color: navy; margin-top: 0; margin-bottom: 0;'>/*************************************************************************
1-dimensional complex deconvolution (inverse of ConvC1D()).
Algorithm has M*log(M)) complexity for any M (composite or prime).
INPUT PARAMETERS
A - array[0..M-1] - convolved signal, A = conv(R, B)
M - convolved signal length
B - array[0..N-1] - response
N - response length
OUTPUT PARAMETERS
R - deconvolved signal. array[0..M-N].
NOTE:
deconvolution is unstable process and may result in division by zero
(if your response function is degenerate, i.e. has zero Fourier coefficient).
NOTE:
It is assumed that B is zero at T<0. If it has non-zero values at
negative T's, you can still use this subroutine - just shift its result
correspondingly.
-- ALGLIB --
Copyright 21.07.2009 by Bochkanov Sergey
*************************************************************************/
</div><div style='margin-top: 0; margin-bottom: 0;'><b>void</b> alglib::convr1dcircularinv(
real_1d_array a,
ae_int_t m,
real_1d_array b,
ae_int_t n,
real_1d_array& r);
</div></pre>
<a name='sub_convr1dinv'></a><h3 class=pageheader><code>convr1dinv</code> function</h3>
<pre class=source>
<div style='color: navy; margin-top: 0; margin-bottom: 0;'>/*************************************************************************
1-dimensional real deconvolution (inverse of ConvC1D()).
Algorithm has M*log(M)) complexity for any M (composite or prime).
INPUT PARAMETERS
A - array[0..M-1] - convolved signal, A = conv(R, B)
M - convolved signal length
B - array[0..N-1] - response
N - response length, N<=M
OUTPUT PARAMETERS
R - deconvolved signal. array[0..M-N].
NOTE:
deconvolution is unstable process and may result in division by zero
(if your response function is degenerate, i.e. has zero Fourier coefficient).
NOTE:
It is assumed that A is zero at T<0, B is zero too. If one or both
functions have non-zero values at negative T's, you can still use this
subroutine - just shift its result correspondingly.
-- ALGLIB --
Copyright 21.07.2009 by Bochkanov Sergey
*************************************************************************/
</div><div style='margin-top: 0; margin-bottom: 0;'><b>void</b> alglib::convr1dinv(
real_1d_array a,
ae_int_t m,
real_1d_array b,
ae_int_t n,
real_1d_array& r);
</div></pre>
<a name=unit_corr></a><h2 class=pageheader><code>corr</code> subpackage</h2>
<div class=pagecontent>
<h3 class=pageheader>Functions</h3>
<a href='#sub_corrc1d' class=toc>corrc1d</a><br>
<a href='#sub_corrc1dcircular' class=toc>corrc1dcircular</a><br>
<a href='#sub_corrr1d' class=toc>corrr1d</a><br>
<a href='#sub_corrr1dcircular' class=toc>corrr1dcircular</a><br>
<h3 class=pageheader>Examples</h3>
<table border=0 cellspacing=0 class='pagecontent'>
</table></div>
<a name='sub_corrc1d'></a><h3 class=pageheader><code>corrc1d</code> function</h3>
<pre class=source>
<div style='color: navy; margin-top: 0; margin-bottom: 0;'>/*************************************************************************
1-dimensional complex cross-correlation.
For given Pattern/Signal returns corr(Pattern,Signal) (non-circular).
Correlation is calculated using reduction to convolution. Algorithm with
max(N,N)*log(max(N,N)) complexity is used (see ConvC1D() for more info
about performance).
IMPORTANT:
for historical reasons subroutine accepts its parameters in reversed
order: CorrC1D(Signal, Pattern) = Pattern x Signal (using traditional
definition of cross-correlation, denoting cross-correlation as "x").
INPUT PARAMETERS
Signal - array[0..N-1] - complex function to be transformed,
signal containing pattern
N - problem size
Pattern - array[0..M-1] - complex function to be transformed,
pattern to search withing signal
M - problem size
OUTPUT PARAMETERS
R - cross-correlation, array[0..N+M-2]:
* positive lags are stored in R[0..N-1],
R[i] = sum(conj(pattern[j])*signal[i+j]
* negative lags are stored in R[N..N+M-2],
R[N+M-1-i] = sum(conj(pattern[j])*signal[-i+j]
NOTE:
It is assumed that pattern domain is [0..M-1]. If Pattern is non-zero
on [-K..M-1], you can still use this subroutine, just shift result by K.
-- ALGLIB --
Copyright 21.07.2009 by Bochkanov Sergey
*************************************************************************/
</div><div style='margin-top: 0; margin-bottom: 0;'><b>void</b> alglib::corrc1d(
complex_1d_array signal,
ae_int_t n,
complex_1d_array pattern,
ae_int_t m,
complex_1d_array& r);
</div></pre>
<a name='sub_corrc1dcircular'></a><h3 class=pageheader><code>corrc1dcircular</code> function</h3>
<pre class=source>
<div style='color: navy; margin-top: 0; margin-bottom: 0;'>/*************************************************************************
1-dimensional circular complex cross-correlation.
For given Pattern/Signal returns corr(Pattern,Signal) (circular).
Algorithm has linearithmic complexity for any M/N.
IMPORTANT:
for historical reasons subroutine accepts its parameters in reversed
order: CorrC1DCircular(Signal, Pattern) = Pattern x Signal (using
traditional definition of cross-correlation, denoting cross-correlation
as "x").
INPUT PARAMETERS
Signal - array[0..N-1] - complex function to be transformed,
periodic signal containing pattern
N - problem size
Pattern - array[0..M-1] - complex function to be transformed,
non-periodic pattern to search withing signal
M - problem size
OUTPUT PARAMETERS
R - convolution: A*B. array[0..M-1].
-- ALGLIB --
Copyright 21.07.2009 by Bochkanov Sergey
*************************************************************************/
</div><div style='margin-top: 0; margin-bottom: 0;'><b>void</b> alglib::corrc1dcircular(
complex_1d_array signal,
ae_int_t m,
complex_1d_array pattern,
ae_int_t n,
complex_1d_array& c);
</div></pre>
<a name='sub_corrr1d'></a><h3 class=pageheader><code>corrr1d</code> function</h3>
<pre class=source>
<div style='color: navy; margin-top: 0; margin-bottom: 0;'>/*************************************************************************
1-dimensional real cross-correlation.
For given Pattern/Signal returns corr(Pattern,Signal) (non-circular).
Correlation is calculated using reduction to convolution. Algorithm with
max(N,N)*log(max(N,N)) complexity is used (see ConvC1D() for more info
about performance).
IMPORTANT:
for historical reasons subroutine accepts its parameters in reversed
order: CorrR1D(Signal, Pattern) = Pattern x Signal (using traditional
definition of cross-correlation, denoting cross-correlation as "x").
INPUT PARAMETERS
Signal - array[0..N-1] - real function to be transformed,
signal containing pattern
N - problem size
Pattern - array[0..M-1] - real function to be transformed,
pattern to search withing signal
M - problem size
OUTPUT PARAMETERS
R - cross-correlation, array[0..N+M-2]:
* positive lags are stored in R[0..N-1],
R[i] = sum(pattern[j]*signal[i+j]
* negative lags are stored in R[N..N+M-2],
R[N+M-1-i] = sum(pattern[j]*signal[-i+j]
NOTE:
It is assumed that pattern domain is [0..M-1]. If Pattern is non-zero
on [-K..M-1], you can still use this subroutine, just shift result by K.
-- ALGLIB --
Copyright 21.07.2009 by Bochkanov Sergey
*************************************************************************/
</div><div style='margin-top: 0; margin-bottom: 0;'><b>void</b> alglib::corrr1d(
real_1d_array signal,
ae_int_t n,
real_1d_array pattern,
ae_int_t m,
real_1d_array& r);
</div></pre>
<a name='sub_corrr1dcircular'></a><h3 class=pageheader><code>corrr1dcircular</code> function</h3>
<pre class=source>
<div style='color: navy; margin-top: 0; margin-bottom: 0;'>/*************************************************************************
1-dimensional circular real cross-correlation.
For given Pattern/Signal returns corr(Pattern,Signal) (circular).
Algorithm has linearithmic complexity for any M/N.
IMPORTANT:
for historical reasons subroutine accepts its parameters in reversed
order: CorrR1DCircular(Signal, Pattern) = Pattern x Signal (using
traditional definition of cross-correlation, denoting cross-correlation
as "x").
INPUT PARAMETERS
Signal - array[0..N-1] - real function to be transformed,
periodic signal containing pattern
N - problem size
Pattern - array[0..M-1] - real function to be transformed,
non-periodic pattern to search withing signal
M - problem size
OUTPUT PARAMETERS
R - convolution: A*B. array[0..M-1].
-- ALGLIB --
Copyright 21.07.2009 by Bochkanov Sergey
*************************************************************************/
</div><div style='margin-top: 0; margin-bottom: 0;'><b>void</b> alglib::corrr1dcircular(
real_1d_array signal,
ae_int_t m,
real_1d_array pattern,
ae_int_t n,
real_1d_array& c);
</div></pre>
<a name=unit_correlationtests></a><h2 class=pageheader><code>correlationtests</code> subpackage</h2>
<div class=pagecontent>
<h3 class=pageheader>Functions</h3>
<a href='#sub_pearsoncorrelationsignificance' class=toc>pearsoncorrelationsignificance</a><br>
<a href='#sub_spearmanrankcorrelationsignificance' class=toc>spearmanrankcorrelationsignificance</a><br>
<h3 class=pageheader>Examples</h3>
<table border=0 cellspacing=0 class='pagecontent'>
</table></div>
<a name='sub_pearsoncorrelationsignificance'></a><h3 class=pageheader><code>pearsoncorrelationsignificance</code> function</h3>
<pre class=source>
<div style='color: navy; margin-top: 0; margin-bottom: 0;'>/*************************************************************************
Pearson's correlation coefficient significance test
This test checks hypotheses about whether X and Y are samples of two
continuous distributions having zero correlation or whether their
correlation is non-zero.
The following tests are performed:
* two-tailed test (null hypothesis - X and Y have zero correlation)
* left-tailed test (null hypothesis - the correlation coefficient is
greater than or equal to 0)
* right-tailed test (null hypothesis - the correlation coefficient is
less than or equal to 0).
Requirements:
* the number of elements in each sample is not less than 5
* normality of distributions of X and Y.
Input parameters:
R - Pearson's correlation coefficient for X and Y
N - number of elements in samples, N>=5.
Output parameters:
BothTails - p-value for two-tailed test.
If BothTails is less than the given significance level
the null hypothesis is rejected.
LeftTail - p-value for left-tailed test.
If LeftTail is less than the given significance level,
the null hypothesis is rejected.
RightTail - p-value for right-tailed test.
If RightTail is less than the given significance level
the null hypothesis is rejected.
-- ALGLIB --
Copyright 09.04.2007 by Bochkanov Sergey
*************************************************************************/
</div><div style='margin-top: 0; margin-bottom: 0;'><b>void</b> alglib::pearsoncorrelationsignificance(
<b>double</b> r,
ae_int_t n,
<b>double</b>& bothtails,
<b>double</b>& lefttail,
<b>double</b>& righttail);
</div></pre>
<a name='sub_spearmanrankcorrelationsignificance'></a><h3 class=pageheader><code>spearmanrankcorrelationsignificance</code> function</h3>
<pre class=source>
<div style='color: navy; margin-top: 0; margin-bottom: 0;'>/*************************************************************************
Spearman's rank correlation coefficient significance test
This test checks hypotheses about whether X and Y are samples of two
continuous distributions having zero correlation or whether their
correlation is non-zero.
The following tests are performed:
* two-tailed test (null hypothesis - X and Y have zero correlation)
* left-tailed test (null hypothesis - the correlation coefficient is
greater than or equal to 0)
* right-tailed test (null hypothesis - the correlation coefficient is
less than or equal to 0).
Requirements:
* the number of elements in each sample is not less than 5.
The test is non-parametric and doesn't require distributions X and Y to be
normal.
Input parameters:
R - Spearman's rank correlation coefficient for X and Y
N - number of elements in samples, N>=5.
Output parameters:
BothTails - p-value for two-tailed test.
If BothTails is less than the given significance level
the null hypothesis is rejected.
LeftTail - p-value for left-tailed test.
If LeftTail is less than the given significance level,
the null hypothesis is rejected.
RightTail - p-value for right-tailed test.
If RightTail is less than the given significance level
the null hypothesis is rejected.
-- ALGLIB --
Copyright 09.04.2007 by Bochkanov Sergey
*************************************************************************/
</div><div style='margin-top: 0; margin-bottom: 0;'><b>void</b> alglib::spearmanrankcorrelationsignificance(
<b>double</b> r,
ae_int_t n,
<b>double</b>& bothtails,
<b>double</b>& lefttail,
<b>double</b>& righttail);
</div></pre>
<a name=unit_datacomp></a><h2 class=pageheader><code>datacomp</code> subpackage</h2>
<div class=pagecontent>
<h3 class=pageheader>Functions</h3>
<a href='#sub_kmeansgenerate' class=toc>kmeansgenerate</a><br>
<h3 class=pageheader>Examples</h3>
<table border=0 cellspacing=0 class='pagecontent'>
</table></div>
<a name='sub_kmeansgenerate'></a><h3 class=pageheader><code>kmeansgenerate</code> function</h3>
<pre class=source>
<div style='color: navy; margin-top: 0; margin-bottom: 0;'>/*************************************************************************
k-means++ clusterization.
Backward compatibility function, we recommend to use CLUSTERING subpackage
as better replacement.
-- ALGLIB --
Copyright 21.03.2009 by Bochkanov Sergey
*************************************************************************/
</div><div style='margin-top: 0; margin-bottom: 0;'><b>void</b> alglib::kmeansgenerate(
real_2d_array xy,
ae_int_t npoints,
ae_int_t nvars,
ae_int_t k,
ae_int_t restarts,
ae_int_t& info,
real_2d_array& c,
integer_1d_array& xyc);
</div></pre>
<a name=unit_dawson></a><h2 class=pageheader><code>dawson</code> subpackage</h2>
<div class=pagecontent>
<h3 class=pageheader>Functions</h3>
<a href='#sub_dawsonintegral' class=toc>dawsonintegral</a><br>
<h3 class=pageheader>Examples</h3>
<table border=0 cellspacing=0 class='pagecontent'>
</table></div>
<a name='sub_dawsonintegral'></a><h3 class=pageheader><code>dawsonintegral</code> function</h3>
<pre class=source>
<div style='color: navy; margin-top: 0; margin-bottom: 0;'>/*************************************************************************
Dawson's Integral
Approximates the integral
x
-
2 | | 2
dawsn(x) = exp( -x ) | exp( t ) dt
| |
-
0
Three different rational approximations are employed, for
the intervals 0 to 3.25; 3.25 to 6.25; and 6.25 up.
ACCURACY:
Relative error:
arithmetic domain # trials peak rms
IEEE 0,10 10000 6.9e-16 1.0e-16
Cephes Math Library Release 2.8: June, 2000
Copyright 1984, 1987, 1989, 2000 by Stephen L. Moshier
*************************************************************************/
</div><div style='margin-top: 0; margin-bottom: 0;'><b>double</b> alglib::dawsonintegral(<b>double</b> x);
</div></pre>
<a name=unit_densesolver></a><h2 class=pageheader><code>densesolver</code> subpackage</h2>
<div class=pagecontent>
<h3 class=pageheader>Classes</h3>
<a href='#struct_densesolverlsreport' class=toc>densesolverlsreport</a><br>
<a href='#struct_densesolverreport' class=toc>densesolverreport</a><br>
<h3 class=pageheader>Functions</h3>
<a href='#sub_cmatrixlusolve' class=toc>cmatrixlusolve</a><br>
<a href='#sub_cmatrixlusolvefast' class=toc>cmatrixlusolvefast</a><br>
<a href='#sub_cmatrixlusolvem' class=toc>cmatrixlusolvem</a><br>
<a href='#sub_cmatrixlusolvemfast' class=toc>cmatrixlusolvemfast</a><br>
<a href='#sub_cmatrixmixedsolve' class=toc>cmatrixmixedsolve</a><br>
<a href='#sub_cmatrixmixedsolvem' class=toc>cmatrixmixedsolvem</a><br>
<a href='#sub_cmatrixsolve' class=toc>cmatrixsolve</a><br>
<a href='#sub_cmatrixsolvefast' class=toc>cmatrixsolvefast</a><br>
<a href='#sub_cmatrixsolvem' class=toc>cmatrixsolvem</a><br>
<a href='#sub_cmatrixsolvemfast' class=toc>cmatrixsolvemfast</a><br>
<a href='#sub_hpdmatrixcholeskysolve' class=toc>hpdmatrixcholeskysolve</a><br>
<a href='#sub_hpdmatrixcholeskysolvefast' class=toc>hpdmatrixcholeskysolvefast</a><br>
<a href='#sub_hpdmatrixcholeskysolvem' class=toc>hpdmatrixcholeskysolvem</a><br>
<a href='#sub_hpdmatrixcholeskysolvemfast' class=toc>hpdmatrixcholeskysolvemfast</a><br>
<a href='#sub_hpdmatrixsolve' class=toc>hpdmatrixsolve</a><br>
<a href='#sub_hpdmatrixsolvefast' class=toc>hpdmatrixsolvefast</a><br>
<a href='#sub_hpdmatrixsolvem' class=toc>hpdmatrixsolvem</a><br>
<a href='#sub_hpdmatrixsolvemfast' class=toc>hpdmatrixsolvemfast</a><br>
<a href='#sub_rmatrixlusolve' class=toc>rmatrixlusolve</a><br>
<a href='#sub_rmatrixlusolvefast' class=toc>rmatrixlusolvefast</a><br>
<a href='#sub_rmatrixlusolvem' class=toc>rmatrixlusolvem</a><br>
<a href='#sub_rmatrixlusolvemfast' class=toc>rmatrixlusolvemfast</a><br>
<a href='#sub_rmatrixmixedsolve' class=toc>rmatrixmixedsolve</a><br>
<a href='#sub_rmatrixmixedsolvem' class=toc>rmatrixmixedsolvem</a><br>
<a href='#sub_rmatrixsolve' class=toc>rmatrixsolve</a><br>
<a href='#sub_rmatrixsolvefast' class=toc>rmatrixsolvefast</a><br>
<a href='#sub_rmatrixsolvels' class=toc>rmatrixsolvels</a><br>
<a href='#sub_rmatrixsolvem' class=toc>rmatrixsolvem</a><br>
<a href='#sub_rmatrixsolvemfast' class=toc>rmatrixsolvemfast</a><br>
<a href='#sub_spdmatrixcholeskysolve' class=toc>spdmatrixcholeskysolve</a><br>
<a href='#sub_spdmatrixcholeskysolvefast' class=toc>spdmatrixcholeskysolvefast</a><br>
<a href='#sub_spdmatrixcholeskysolvem' class=toc>spdmatrixcholeskysolvem</a><br>
<a href='#sub_spdmatrixcholeskysolvemfast' class=toc>spdmatrixcholeskysolvemfast</a><br>
<a href='#sub_spdmatrixsolve' class=toc>spdmatrixsolve</a><br>
<a href='#sub_spdmatrixsolvefast' class=toc>spdmatrixsolvefast</a><br>
<a href='#sub_spdmatrixsolvem' class=toc>spdmatrixsolvem</a><br>
<a href='#sub_spdmatrixsolvemfast' class=toc>spdmatrixsolvemfast</a><br>
<h3 class=pageheader>Examples</h3>
<table border=0 cellspacing=0 class='pagecontent'>
</table></div>
<a name='struct_densesolverlsreport'></a><h3 class=pageheader><code>densesolverlsreport</code> class</h3>
<pre class=source>
<div style='color: navy; margin-top: 0; margin-bottom: 0;'>/*************************************************************************
*************************************************************************/
</div><div style='margin-top: 0; margin-bottom: 0;'><b>class</b> densesolverlsreport
{
<b>double</b> r2;
real_2d_array cx;
ae_int_t n;
ae_int_t k;
};
</div></pre>
<a name='struct_densesolverreport'></a><h3 class=pageheader><code>densesolverreport</code> class</h3>
<pre class=source>
<div style='color: navy; margin-top: 0; margin-bottom: 0;'>/*************************************************************************
*************************************************************************/
</div><div style='margin-top: 0; margin-bottom: 0;'><b>class</b> densesolverreport
{
<b>double</b> r1;
<b>double</b> rinf;
};
</div></pre>
<a name='sub_cmatrixlusolve'></a><h3 class=pageheader><code>cmatrixlusolve</code> function</h3>
<pre class=source>
<div style='color: navy; margin-top: 0; margin-bottom: 0;'>/*************************************************************************
Complex dense linear solver for A*x=b with complex N*N A given by its LU
decomposition and N*1 vectors x and b. This is "slow-but-robust" version
of the complex linear solver with additional features which add
significant performance overhead. Faster version is CMatrixLUSolveFast()
function.
Algorithm features:
* automatic detection of degenerate cases
* O(N^2) complexity
* condition number estimation
No iterative refinement is provided because exact form of original matrix
is not known to subroutine. Use CMatrixSolve or CMatrixMixedSolve if you
need iterative refinement.
IMPORTANT: ! this function is NOT the most efficient linear solver provided
! by ALGLIB. It estimates condition number of linear system,
! which results in 10-15x performance penalty when compared
! with "fast" version which just calls triangular solver.
!
! This performance penalty is insignificant when compared with
! cost of large LU decomposition. However, if you call this
! function many times for the same left side, this overhead
! BECOMES significant. It also becomes significant for small-
! scale problems.
!
! In such cases we strongly recommend you to use faster solver,
! CMatrixLUSolveFast() function.
INPUT PARAMETERS
LUA - array[0..N-1,0..N-1], LU decomposition, CMatrixLU result
P - array[0..N-1], pivots array, CMatrixLU result
N - size of A
B - array[0..N-1], right part
OUTPUT PARAMETERS
Info - return code:
* -3 matrix is very badly conditioned or exactly singular.
* -1 N<=0 was passed
* 1 task is solved (but matrix A may be ill-conditioned,
check R1/RInf parameters for condition numbers).
Rep - additional report, following fields are set:
* rep.r1 condition number in 1-norm
* rep.rinf condition number in inf-norm
X - array[N], it contains:
* info>0 => solution
* info=-3 => filled by zeros
-- ALGLIB --
Copyright 27.01.2010 by Bochkanov Sergey
*************************************************************************/
</div><div style='margin-top: 0; margin-bottom: 0;'><b>void</b> alglib::cmatrixlusolve(
complex_2d_array lua,
integer_1d_array p,
ae_int_t n,
complex_1d_array b,
ae_int_t& info,
densesolverreport& rep,
complex_1d_array& x);
</div></pre>
<a name='sub_cmatrixlusolvefast'></a><h3 class=pageheader><code>cmatrixlusolvefast</code> function</h3>
<pre class=source>
<div style='color: navy; margin-top: 0; margin-bottom: 0;'>/*************************************************************************
Complex dense linear solver for A*x=b with N*N complex A given by its LU
decomposition and N*1 vectors x and b. This is fast lightweight version
of solver, which is significantly faster than CMatrixLUSolve(), but does
not provide additional information (like condition numbers).
Algorithm features:
* O(N^2) complexity
* no additional time-consuming features, just triangular solver
INPUT PARAMETERS
LUA - array[0..N-1,0..N-1], LU decomposition, CMatrixLU result
P - array[0..N-1], pivots array, CMatrixLU result
N - size of A
B - array[0..N-1], right part
OUTPUT PARAMETERS
Info - return code:
* -3 matrix is exactly singular (ill conditioned matrices
are not recognized).
* -1 N<=0 was passed
* 1 task is solved
B - array[N]:
* info>0 => overwritten by solution
* info=-3 => filled by zeros
NOTE: unlike CMatrixLUSolve(), this function does NOT check for
near-degeneracy of input matrix. It checks for EXACT degeneracy,
because this check is easy to do. However, very badly conditioned
matrices may went unnoticed.
-- ALGLIB --
Copyright 27.01.2010 by Bochkanov Sergey
*************************************************************************/
</div><div style='margin-top: 0; margin-bottom: 0;'><b>void</b> alglib::cmatrixlusolvefast(
complex_2d_array lua,
integer_1d_array p,
ae_int_t n,
complex_1d_array& b,
ae_int_t& info);
</div></pre>
<a name='sub_cmatrixlusolvem'></a><h3 class=pageheader><code>cmatrixlusolvem</code> function</h3>
<pre class=source>
<div style='color: navy; margin-top: 0; margin-bottom: 0;'>/*************************************************************************
Dense solver for A*X=B with N*N complex A given by its LU decomposition,
and N*M matrices X and B (multiple right sides). "Slow-but-feature-rich"
version of the solver.
Algorithm features:
* automatic detection of degenerate cases
* O(M*N^2) complexity
* condition number estimation
No iterative refinement is provided because exact form of original matrix
is not known to subroutine. Use CMatrixSolve or CMatrixMixedSolve if you
need iterative refinement.
IMPORTANT: ! this function is NOT the most efficient linear solver provided
! by ALGLIB. It estimates condition number of linear system,
! which results in significant performance penalty when
! compared with "fast" version which just calls triangular
! solver.
!
! This performance penalty is especially apparent when you use
! ALGLIB parallel capabilities (condition number estimation is
! inherently sequential). It also becomes significant for
! small-scale problems.
!
! In such cases we strongly recommend you to use faster solver,
! CMatrixLUSolveMFast() function.
COMMERCIAL EDITION OF ALGLIB:
! Commercial version of ALGLIB includes two important improvements of
! this function, which can be used from C++ and C#:
! * Intel MKL support (lightweight Intel MKL is shipped with ALGLIB)
! * multicore support
!
! Intel MKL gives approximately constant (with respect to number of
! worker threads) acceleration factor which depends on CPU being used,
! problem size and "baseline" ALGLIB edition which is used for
! comparison.
!
! Say, on SSE2-capable CPU with N=1024, HPC ALGLIB will be:
! * about 2-3x faster than ALGLIB for C++ without MKL
! * about 7-10x faster than "pure C#" edition of ALGLIB
! Difference in performance will be more striking on newer CPU's with
! support for newer SIMD instructions. Generally, MKL accelerates any
! problem whose size is at least 128, with best efficiency achieved for
! N's larger than 512.
!
! Commercial edition of ALGLIB also supports multithreaded acceleration
! of this function. Triangular solver is relatively easy to parallelize.
! However, parallelization will be efficient only for large number of
! right parts M.
!
! In order to use multicore features you have to:
! * use commercial version of ALGLIB
! * call this function with "smp_" prefix, which indicates that
! multicore code will be used (for multicore support)
!
! We recommend you to read 'Working with commercial version' section of
! ALGLIB Reference Manual in order to find out how to use performance-
! related features provided by commercial edition of ALGLIB.
INPUT PARAMETERS
LUA - array[0..N-1,0..N-1], LU decomposition, RMatrixLU result
P - array[0..N-1], pivots array, RMatrixLU result
N - size of A
B - array[0..N-1,0..M-1], right part
M - right part size
OUTPUT PARAMETERS
Info - return code:
* -3 matrix is very badly conditioned or exactly singular.
* -1 N<=0 was passed
* 1 task is solved (but matrix A may be ill-conditioned,
check R1/RInf parameters for condition numbers).
Rep - additional report, following fields are set:
* rep.r1 condition number in 1-norm
* rep.rinf condition number in inf-norm
X - array[N,M], it contains:
* info>0 => solution
* info=-3 => filled by zeros
-- ALGLIB --
Copyright 27.01.2010 by Bochkanov Sergey
*************************************************************************/
</div><div style='margin-top: 0; margin-bottom: 0;'><b>void</b> alglib::cmatrixlusolvem(
complex_2d_array lua,
integer_1d_array p,
ae_int_t n,
complex_2d_array b,
ae_int_t m,
ae_int_t& info,
densesolverreport& rep,
complex_2d_array& x);
<b>void</b> alglib::smp_cmatrixlusolvem(
complex_2d_array lua,
integer_1d_array p,
ae_int_t n,
complex_2d_array b,
ae_int_t m,
ae_int_t& info,
densesolverreport& rep,
complex_2d_array& x);
</div></pre>
<a name='sub_cmatrixlusolvemfast'></a><h3 class=pageheader><code>cmatrixlusolvemfast</code> function</h3>
<pre class=source>
<div style='color: navy; margin-top: 0; margin-bottom: 0;'>/*************************************************************************
Dense solver for A*X=B with N*N complex A given by its LU decomposition,
and N*M matrices X and B (multiple right sides). "Fast-but-lightweight"
version of the solver.
Algorithm features:
* O(M*N^2) complexity
* no additional time-consuming features
COMMERCIAL EDITION OF ALGLIB:
! Commercial version of ALGLIB includes two important improvements of
! this function, which can be used from C++ and C#:
! * Intel MKL support (lightweight Intel MKL is shipped with ALGLIB)
! * multicore support
!
! Intel MKL gives approximately constant (with respect to number of
! worker threads) acceleration factor which depends on CPU being used,
! problem size and "baseline" ALGLIB edition which is used for
! comparison.
!
! Say, on SSE2-capable CPU with N=1024, HPC ALGLIB will be:
! * about 2-3x faster than ALGLIB for C++ without MKL
! * about 7-10x faster than "pure C#" edition of ALGLIB
! Difference in performance will be more striking on newer CPU's with
! support for newer SIMD instructions. Generally, MKL accelerates any
! problem whose size is at least 128, with best efficiency achieved for
! N's larger than 512.
!
! Commercial edition of ALGLIB also supports multithreaded acceleration
! of this function. Triangular solver is relatively easy to parallelize.
! However, parallelization will be efficient only for large number of
! right parts M.
!
! In order to use multicore features you have to:
! * use commercial version of ALGLIB
! * call this function with "smp_" prefix, which indicates that
! multicore code will be used (for multicore support)
!
! We recommend you to read 'Working with commercial version' section of
! ALGLIB Reference Manual in order to find out how to use performance-
! related features provided by commercial edition of ALGLIB.
INPUT PARAMETERS
LUA - array[0..N-1,0..N-1], LU decomposition, RMatrixLU result
P - array[0..N-1], pivots array, RMatrixLU result
N - size of A
B - array[0..N-1,0..M-1], right part
M - right part size
OUTPUT PARAMETERS
Info - return code:
* -3 matrix is exactly singular (ill conditioned matrices
are not recognized).
* -1 N<=0 was passed
* 1 task is solved
B - array[N,M]:
* info>0 => overwritten by solution
* info=-3 => filled by zeros
-- ALGLIB --
Copyright 27.01.2010 by Bochkanov Sergey
*************************************************************************/
</div><div style='margin-top: 0; margin-bottom: 0;'><b>void</b> alglib::cmatrixlusolvemfast(
complex_2d_array lua,
integer_1d_array p,
ae_int_t n,
complex_2d_array& b,
ae_int_t m,
ae_int_t& info);
<b>void</b> alglib::smp_cmatrixlusolvemfast(
complex_2d_array lua,
integer_1d_array p,
ae_int_t n,
complex_2d_array& b,
ae_int_t m,
ae_int_t& info);
</div></pre>
<a name='sub_cmatrixmixedsolve'></a><h3 class=pageheader><code>cmatrixmixedsolve</code> function</h3>
<pre class=source>
<div style='color: navy; margin-top: 0; margin-bottom: 0;'>/*************************************************************************
Dense solver. Same as RMatrixMixedSolve(), but for complex matrices.
Algorithm features:
* automatic detection of degenerate cases
* condition number estimation
* iterative refinement
* O(N^2) complexity
INPUT PARAMETERS
A - array[0..N-1,0..N-1], system matrix
LUA - array[0..N-1,0..N-1], LU decomposition, CMatrixLU result
P - array[0..N-1], pivots array, CMatrixLU result
N - size of A
B - array[0..N-1], right part
OUTPUT PARAMETERS
Info - return code:
* -3 matrix is very badly conditioned or exactly singular.
* -1 N<=0 was passed
* 1 task is solved (but matrix A may be ill-conditioned,
check R1/RInf parameters for condition numbers).
Rep - additional report, following fields are set:
* rep.r1 condition number in 1-norm
* rep.rinf condition number in inf-norm
X - array[N], it contains:
* info>0 => solution
* info=-3 => filled by zeros
-- ALGLIB --
Copyright 27.01.2010 by Bochkanov Sergey
*************************************************************************/
</div><div style='margin-top: 0; margin-bottom: 0;'><b>void</b> alglib::cmatrixmixedsolve(
complex_2d_array a,
complex_2d_array lua,
integer_1d_array p,
ae_int_t n,
complex_1d_array b,
ae_int_t& info,
densesolverreport& rep,
complex_1d_array& x);
</div></pre>
<a name='sub_cmatrixmixedsolvem'></a><h3 class=pageheader><code>cmatrixmixedsolvem</code> function</h3>
<pre class=source>
<div style='color: navy; margin-top: 0; margin-bottom: 0;'>/*************************************************************************
Dense solver. Same as RMatrixMixedSolveM(), but for complex matrices.
Algorithm features:
* automatic detection of degenerate cases
* condition number estimation
* iterative refinement
* O(M*N^2) complexity
INPUT PARAMETERS
A - array[0..N-1,0..N-1], system matrix
LUA - array[0..N-1,0..N-1], LU decomposition, CMatrixLU result
P - array[0..N-1], pivots array, CMatrixLU result
N - size of A
B - array[0..N-1,0..M-1], right part
M - right part size
OUTPUT PARAMETERS
Info - return code:
* -3 matrix is very badly conditioned or exactly singular.
* -1 N<=0 was passed
* 1 task is solved (but matrix A may be ill-conditioned,
check R1/RInf parameters for condition numbers).
Rep - additional report, following fields are set:
* rep.r1 condition number in 1-norm
* rep.rinf condition number in inf-norm
X - array[N,M], it contains:
* info>0 => solution
* info=-3 => filled by zeros
-- ALGLIB --
Copyright 27.01.2010 by Bochkanov Sergey
*************************************************************************/
</div><div style='margin-top: 0; margin-bottom: 0;'><b>void</b> alglib::cmatrixmixedsolvem(
complex_2d_array a,
complex_2d_array lua,
integer_1d_array p,
ae_int_t n,
complex_2d_array b,
ae_int_t m,
ae_int_t& info,
densesolverreport& rep,
complex_2d_array& x);
</div></pre>
<a name='sub_cmatrixsolve'></a><h3 class=pageheader><code>cmatrixsolve</code> function</h3>
<pre class=source>
<div style='color: navy; margin-top: 0; margin-bottom: 0;'>/*************************************************************************
Complex dense solver for A*x=B with N*N complex matrix A and N*1 complex
vectors x and b. "Slow-but-feature-rich" version of the solver.
Algorithm features:
* automatic detection of degenerate cases
* condition number estimation
* iterative refinement
* O(N^3) complexity
IMPORTANT: ! this function is NOT the most efficient linear solver provided
! by ALGLIB. It estimates condition number of linear system
! and performs iterative refinement, which results in
! significant performance penalty when compared with "fast"
! version which just performs LU decomposition and calls
! triangular solver.
!
! This performance penalty is especially visible in the
! multithreaded mode, because both condition number estimation
! and iterative refinement are inherently sequential
! calculations.
!
! Thus, if you need high performance and if you are pretty sure
! that your system is well conditioned, we strongly recommend
! you to use faster solver, CMatrixSolveFast() function.
COMMERCIAL EDITION OF ALGLIB:
! Commercial version of ALGLIB includes two important improvements of
! this function, which can be used from C++ and C#:
! * Intel MKL support (lightweight Intel MKL is shipped with ALGLIB)
! * multicore support
!
! Intel MKL gives approximately constant (with respect to number of
! worker threads) acceleration factor which depends on CPU being used,
! problem size and "baseline" ALGLIB edition which is used for
! comparison.
!
! Say, on SSE2-capable CPU with N=1024, HPC ALGLIB will be:
! * about 2-3x faster than ALGLIB for C++ without MKL
! * about 7-10x faster than "pure C#" edition of ALGLIB
! Difference in performance will be more striking on newer CPU's with
! support for newer SIMD instructions. Generally, MKL accelerates any
! problem whose size is at least 128, with best efficiency achieved for
! N's larger than 512.
!
! Commercial edition of ALGLIB also supports multithreaded acceleration
! of this function. We should note that LU decomposition is harder to
! parallelize than, say, matrix-matrix product - this algorithm has
! many internal synchronization points which can not be avoided. However
! parallelism starts to be profitable starting from N=1024, achieving
! near-linear speedup for N=4096 or higher.
!
! In order to use multicore features you have to:
! * use commercial version of ALGLIB
! * call this function with "smp_" prefix, which indicates that
! multicore code will be used (for multicore support)
!
! We recommend you to read 'Working with commercial version' section of
! ALGLIB Reference Manual in order to find out how to use performance-
! related features provided by commercial edition of ALGLIB.
INPUT PARAMETERS
A - array[0..N-1,0..N-1], system matrix
N - size of A
B - array[0..N-1], right part
OUTPUT PARAMETERS
Info - return code:
* -3 matrix is very badly conditioned or exactly singular.
* -1 N<=0 was passed
* 1 task is solved (but matrix A may be ill-conditioned,
check R1/RInf parameters for condition numbers).
Rep - additional report, following fields are set:
* rep.r1 condition number in 1-norm
* rep.rinf condition number in inf-norm
X - array[N], it contains:
* info>0 => solution
* info=-3 => filled by zeros
-- ALGLIB --
Copyright 27.01.2010 by Bochkanov Sergey
*************************************************************************/
</div><div style='margin-top: 0; margin-bottom: 0;'><b>void</b> alglib::cmatrixsolve(
complex_2d_array a,
ae_int_t n,
complex_1d_array b,
ae_int_t& info,
densesolverreport& rep,
complex_1d_array& x);
<b>void</b> alglib::smp_cmatrixsolve(
complex_2d_array a,
ae_int_t n,
complex_1d_array b,
ae_int_t& info,
densesolverreport& rep,
complex_1d_array& x);
</div></pre>
<a name='sub_cmatrixsolvefast'></a><h3 class=pageheader><code>cmatrixsolvefast</code> function</h3>
<pre class=source>
<div style='color: navy; margin-top: 0; margin-bottom: 0;'>/*************************************************************************
Complex dense solver for A*x=B with N*N complex matrix A and N*1 complex
vectors x and b. "Fast-but-lightweight" version of the solver.
Algorithm features:
* O(N^3) complexity
* no additional time consuming features, just triangular solver
COMMERCIAL EDITION OF ALGLIB:
! Commercial version of ALGLIB includes two important improvements of
! this function, which can be used from C++ and C#:
! * Intel MKL support (lightweight Intel MKL is shipped with ALGLIB)
! * multicore support
!
! Intel MKL gives approximately constant (with respect to number of
! worker threads) acceleration factor which depends on CPU being used,
! problem size and "baseline" ALGLIB edition which is used for
! comparison.
!
! Say, on SSE2-capable CPU with N=1024, HPC ALGLIB will be:
! * about 2-3x faster than ALGLIB for C++ without MKL
! * about 7-10x faster than "pure C#" edition of ALGLIB
! Difference in performance will be more striking on newer CPU's with
! support for newer SIMD instructions. Generally, MKL accelerates any
! problem whose size is at least 128, with best efficiency achieved for
! N's larger than 512.
!
! Commercial edition of ALGLIB also supports multithreaded acceleration
! of this function. We should note that LU decomposition is harder to
! parallelize than, say, matrix-matrix product - this algorithm has
! many internal synchronization points which can not be avoided. However
! parallelism starts to be profitable starting from N=1024, achieving
! near-linear speedup for N=4096 or higher.
!
! In order to use multicore features you have to:
! * use commercial version of ALGLIB
! * call this function with "smp_" prefix, which indicates that
! multicore code will be used (for multicore support)
!
! We recommend you to read 'Working with commercial version' section of
! ALGLIB Reference Manual in order to find out how to use performance-
! related features provided by commercial edition of ALGLIB.
INPUT PARAMETERS:
A - array[0..N-1,0..N-1], system matrix
N - size of A
B - array[0..N-1], right part
OUTPUT PARAMETERS:
Info - return code:
* -3 matrix is exactly singular (ill conditioned matrices
are not recognized).
* -1 N<=0 was passed
* 1 task is solved
B - array[N]:
* info>0 => overwritten by solution
* info=-3 => filled by zeros
-- ALGLIB --
Copyright 27.01.2010 by Bochkanov Sergey
*************************************************************************/
</div><div style='margin-top: 0; margin-bottom: 0;'><b>void</b> alglib::cmatrixsolvefast(
complex_2d_array a,
ae_int_t n,
complex_1d_array& b,
ae_int_t& info);
<b>void</b> alglib::smp_cmatrixsolvefast(
complex_2d_array a,
ae_int_t n,
complex_1d_array& b,
ae_int_t& info);
</div></pre>
<a name='sub_cmatrixsolvem'></a><h3 class=pageheader><code>cmatrixsolvem</code> function</h3>
<pre class=source>
<div style='color: navy; margin-top: 0; margin-bottom: 0;'>/*************************************************************************
Complex dense solver for A*X=B with N*N complex matrix A, N*M complex
matrices X and B. "Slow-but-feature-rich" version which provides
additional functions, at the cost of slower performance. Faster version
may be invoked with CMatrixSolveMFast() function.
Algorithm features:
* automatic detection of degenerate cases
* condition number estimation
* iterative refinement
* O(N^3+M*N^2) complexity
IMPORTANT: ! this function is NOT the most efficient linear solver provided
! by ALGLIB. It estimates condition number of linear system
! and performs iterative refinement, which results in
! significant performance penalty when compared with "fast"
! version which just performs LU decomposition and calls
! triangular solver.
!
! This performance penalty is especially visible in the
! multithreaded mode, because both condition number estimation
! and iterative refinement are inherently sequential
! calculations.
!
! Thus, if you need high performance and if you are pretty sure
! that your system is well conditioned, we strongly recommend
! you to use faster solver, CMatrixSolveMFast() function.
COMMERCIAL EDITION OF ALGLIB:
! Commercial version of ALGLIB includes two important improvements of
! this function, which can be used from C++ and C#:
! * Intel MKL support (lightweight Intel MKL is shipped with ALGLIB)
! * multicore support
!
! Intel MKL gives approximately constant (with respect to number of
! worker threads) acceleration factor which depends on CPU being used,
! problem size and "baseline" ALGLIB edition which is used for
! comparison.
!
! Say, on SSE2-capable CPU with N=1024, HPC ALGLIB will be:
! * about 2-3x faster than ALGLIB for C++ without MKL
! * about 7-10x faster than "pure C#" edition of ALGLIB
! Difference in performance will be more striking on newer CPU's with
! support for newer SIMD instructions. Generally, MKL accelerates any
! problem whose size is at least 128, with best efficiency achieved for
! N's larger than 512.
!
! Commercial edition of ALGLIB also supports multithreaded acceleration
! of this function. We should note that LU decomposition is harder to
! parallelize than, say, matrix-matrix product - this algorithm has
! many internal synchronization points which can not be avoided. However
! parallelism starts to be profitable starting from N=1024, achieving
! near-linear speedup for N=4096 or higher.
!
! In order to use multicore features you have to:
! * use commercial version of ALGLIB
! * call this function with "smp_" prefix, which indicates that
! multicore code will be used (for multicore support)
!
! We recommend you to read 'Working with commercial version' section of
! ALGLIB Reference Manual in order to find out how to use performance-
! related features provided by commercial edition of ALGLIB.
INPUT PARAMETERS
A - array[0..N-1,0..N-1], system matrix
N - size of A
B - array[0..N-1,0..M-1], right part
M - right part size
RFS - iterative refinement switch:
* True - refinement is used.
Less performance, more precision.
* False - refinement is not used.
More performance, less precision.
OUTPUT PARAMETERS
Info - return code:
* -3 matrix is very badly conditioned or exactly singular.
X is filled by zeros in such cases.
* -1 N<=0 was passed
* 1 task is solved (but matrix A may be ill-conditioned,
check R1/RInf parameters for condition numbers).
Rep - additional report, following fields are set:
* rep.r1 condition number in 1-norm
* rep.rinf condition number in inf-norm
X - array[N,M], it contains:
* info>0 => solution
* info=-3 => filled by zeros
-- ALGLIB --
Copyright 27.01.2010 by Bochkanov Sergey
*************************************************************************/
</div><div style='margin-top: 0; margin-bottom: 0;'><b>void</b> alglib::cmatrixsolvem(
complex_2d_array a,
ae_int_t n,
complex_2d_array b,
ae_int_t m,
<b>bool</b> rfs,
ae_int_t& info,
densesolverreport& rep,
complex_2d_array& x);
<b>void</b> alglib::smp_cmatrixsolvem(
complex_2d_array a,
ae_int_t n,
complex_2d_array b,
ae_int_t m,
<b>bool</b> rfs,
ae_int_t& info,
densesolverreport& rep,
complex_2d_array& x);
</div></pre>
<a name='sub_cmatrixsolvemfast'></a><h3 class=pageheader><code>cmatrixsolvemfast</code> function</h3>
<pre class=source>
<div style='color: navy; margin-top: 0; margin-bottom: 0;'>/*************************************************************************
Complex dense solver for A*X=B with N*N complex matrix A, N*M complex
matrices X and B. "Fast-but-lightweight" version which provides just
triangular solver - and no additional functions like iterative refinement
or condition number estimation.
Algorithm features:
* O(N^3+M*N^2) complexity
* no additional time consuming functions
COMMERCIAL EDITION OF ALGLIB:
! Commercial version of ALGLIB includes two important improvements of
! this function, which can be used from C++ and C#:
! * Intel MKL support (lightweight Intel MKL is shipped with ALGLIB)
! * multicore support
!
! Intel MKL gives approximately constant (with respect to number of
! worker threads) acceleration factor which depends on CPU being used,
! problem size and "baseline" ALGLIB edition which is used for
! comparison.
!
! Say, on SSE2-capable CPU with N=1024, HPC ALGLIB will be:
! * about 2-3x faster than ALGLIB for C++ without MKL
! * about 7-10x faster than "pure C#" edition of ALGLIB
! Difference in performance will be more striking on newer CPU's with
! support for newer SIMD instructions. Generally, MKL accelerates any
! problem whose size is at least 128, with best efficiency achieved for
! N's larger than 512.
!
! Commercial edition of ALGLIB also supports multithreaded acceleration
! of this function. We should note that LU decomposition is harder to
! parallelize than, say, matrix-matrix product - this algorithm has
! many internal synchronization points which can not be avoided. However
! parallelism starts to be profitable starting from N=1024, achieving
! near-linear speedup for N=4096 or higher.
!
! In order to use multicore features you have to:
! * use commercial version of ALGLIB
! * call this function with "smp_" prefix, which indicates that
! multicore code will be used (for multicore support)
!
! We recommend you to read 'Working with commercial version' section of
! ALGLIB Reference Manual in order to find out how to use performance-
! related features provided by commercial edition of ALGLIB.
INPUT PARAMETERS
A - array[0..N-1,0..N-1], system matrix
N - size of A
B - array[0..N-1,0..M-1], right part
M - right part size
OUTPUT PARAMETERS:
Info - return code:
* -3 matrix is exactly singular (ill conditioned matrices
are not recognized).
* -1 N<=0 was passed
* 1 task is solved
B - array[N,M]:
* info>0 => overwritten by solution
* info=-3 => filled by zeros
-- ALGLIB --
Copyright 16.03.2015 by Bochkanov Sergey
*************************************************************************/
</div><div style='margin-top: 0; margin-bottom: 0;'><b>void</b> alglib::cmatrixsolvemfast(
complex_2d_array a,
ae_int_t n,
complex_2d_array& b,
ae_int_t m,
ae_int_t& info);
<b>void</b> alglib::smp_cmatrixsolvemfast(
complex_2d_array a,
ae_int_t n,
complex_2d_array& b,
ae_int_t m,
ae_int_t& info);
</div></pre>
<a name='sub_hpdmatrixcholeskysolve'></a><h3 class=pageheader><code>hpdmatrixcholeskysolve</code> function</h3>
<pre class=source>
<div style='color: navy; margin-top: 0; margin-bottom: 0;'>/*************************************************************************
Dense solver for A*x=b with N*N Hermitian positive definite matrix A given
by its Cholesky decomposition, and N*1 complex vectors x and b. This is
"slow-but-feature-rich" version of the solver which estimates condition
number of the system.
Algorithm features:
* automatic detection of degenerate cases
* O(N^2) complexity
* condition number estimation
* matrix is represented by its upper or lower triangle
No iterative refinement is provided because such partial representation of
matrix does not allow efficient calculation of extra-precise matrix-vector
products for large matrices. Use RMatrixSolve or RMatrixMixedSolve if you
need iterative refinement.
IMPORTANT: ! this function is NOT the most efficient linear solver provided
! by ALGLIB. It estimates condition number of linear system,
! which results in 10-15x performance penalty when compared
! with "fast" version which just calls triangular solver.
!
! This performance penalty is insignificant when compared with
! cost of large LU decomposition. However, if you call this
! function many times for the same left side, this overhead
! BECOMES significant. It also becomes significant for small-
! scale problems (N<50).
!
! In such cases we strongly recommend you to use faster solver,
! HPDMatrixCholeskySolveFast() function.
INPUT PARAMETERS
CHA - array[0..N-1,0..N-1], Cholesky decomposition,
SPDMatrixCholesky result
N - size of A
IsUpper - what half of CHA is provided
B - array[0..N-1], right part
OUTPUT PARAMETERS
Info - return code:
* -3 A is is exactly singular or ill conditioned
X is filled by zeros in such cases.
* -1 N<=0 was passed
* 1 task is solved
Rep - additional report, following fields are set:
* rep.r1 condition number in 1-norm
* rep.rinf condition number in inf-norm
X - array[N]:
* for info>0 - solution
* for info=-3 - filled by zeros
-- ALGLIB --
Copyright 27.01.2010 by Bochkanov Sergey
*************************************************************************/
</div><div style='margin-top: 0; margin-bottom: 0;'><b>void</b> alglib::hpdmatrixcholeskysolve(
complex_2d_array cha,
ae_int_t n,
<b>bool</b> isupper,
complex_1d_array b,
ae_int_t& info,
densesolverreport& rep,
complex_1d_array& x);
</div></pre>
<a name='sub_hpdmatrixcholeskysolvefast'></a><h3 class=pageheader><code>hpdmatrixcholeskysolvefast</code> function</h3>
<pre class=source>
<div style='color: navy; margin-top: 0; margin-bottom: 0;'>/*************************************************************************
Dense solver for A*x=b with N*N Hermitian positive definite matrix A given
by its Cholesky decomposition, and N*1 complex vectors x and b. This is
"fast-but-lightweight" version of the solver.
Algorithm features:
* O(N^2) complexity
* matrix is represented by its upper or lower triangle
* no additional time-consuming features
INPUT PARAMETERS
CHA - array[0..N-1,0..N-1], Cholesky decomposition,
SPDMatrixCholesky result
N - size of A
IsUpper - what half of CHA is provided
B - array[0..N-1], right part
OUTPUT PARAMETERS
Info - return code:
* -3 A is is exactly singular or ill conditioned
B is filled by zeros in such cases.
* -1 N<=0 was passed
* 1 task is solved
B - array[N]:
* for info>0 - overwritten by solution
* for info=-3 - filled by zeros
-- ALGLIB --
Copyright 18.03.2015 by Bochkanov Sergey
*************************************************************************/
</div><div style='margin-top: 0; margin-bottom: 0;'><b>void</b> alglib::hpdmatrixcholeskysolvefast(
complex_2d_array cha,
ae_int_t n,
<b>bool</b> isupper,
complex_1d_array& b,
ae_int_t& info);
</div></pre>
<a name='sub_hpdmatrixcholeskysolvem'></a><h3 class=pageheader><code>hpdmatrixcholeskysolvem</code> function</h3>
<pre class=source>
<div style='color: navy; margin-top: 0; margin-bottom: 0;'>/*************************************************************************
Dense solver for A*X=B with N*N Hermitian positive definite matrix A given
by its Cholesky decomposition and N*M complex matrices X and B. This is
"slow-but-feature-rich" version of the solver which, in addition to the
solution, estimates condition number of the system.
Algorithm features:
* automatic detection of degenerate cases
* O(M*N^2) complexity
* condition number estimation
* matrix is represented by its upper or lower triangle
No iterative refinement is provided because such partial representation of
matrix does not allow efficient calculation of extra-precise matrix-vector
products for large matrices. Use RMatrixSolve or RMatrixMixedSolve if you
need iterative refinement.
IMPORTANT: ! this function is NOT the most efficient linear solver provided
! by ALGLIB. It estimates condition number of linear system,
! which results in significant performance penalty when
! compared with "fast" version which just calls triangular
! solver. Amount of overhead introduced depends on M (the
! larger - the more efficient).
!
! This performance penalty is insignificant when compared with
! cost of large Cholesky decomposition. However, if you call
! this function many times for the same left side, this
! overhead BECOMES significant. It also becomes significant
! for small-scale problems (N<50).
!
! In such cases we strongly recommend you to use faster solver,
! HPDMatrixCholeskySolveMFast() function.
INPUT PARAMETERS
CHA - array[N,N], Cholesky decomposition,
HPDMatrixCholesky result
N - size of CHA
IsUpper - what half of CHA is provided
B - array[N,M], right part
M - right part size
OUTPUT PARAMETERS:
Info - return code:
* -3 A is singular, or VERY close to singular.
X is filled by zeros in such cases.
* -1 N<=0 was passed
* 1 task was solved
Rep - additional report, following fields are set:
* rep.r1 condition number in 1-norm
* rep.rinf condition number in inf-norm
X - array[N]:
* for info>0 contains solution
* for info=-3 filled by zeros
-- ALGLIB --
Copyright 27.01.2010 by Bochkanov Sergey
*************************************************************************/
</div><div style='margin-top: 0; margin-bottom: 0;'><b>void</b> alglib::hpdmatrixcholeskysolvem(
complex_2d_array cha,
ae_int_t n,
<b>bool</b> isupper,
complex_2d_array b,
ae_int_t m,
ae_int_t& info,
densesolverreport& rep,
complex_2d_array& x);
<b>void</b> alglib::smp_hpdmatrixcholeskysolvem(
complex_2d_array cha,
ae_int_t n,
<b>bool</b> isupper,
complex_2d_array b,
ae_int_t m,
ae_int_t& info,
densesolverreport& rep,
complex_2d_array& x);
</div></pre>
<a name='sub_hpdmatrixcholeskysolvemfast'></a><h3 class=pageheader><code>hpdmatrixcholeskysolvemfast</code> function</h3>
<pre class=source>
<div style='color: navy; margin-top: 0; margin-bottom: 0;'>/*************************************************************************
Dense solver for A*X=B with N*N Hermitian positive definite matrix A given
by its Cholesky decomposition and N*M complex matrices X and B. This is
"fast-but-lightweight" version of the solver.
Algorithm features:
* O(M*N^2) complexity
* matrix is represented by its upper or lower triangle
* no additional time-consuming features
INPUT PARAMETERS
CHA - array[N,N], Cholesky decomposition,
HPDMatrixCholesky result
N - size of CHA
IsUpper - what half of CHA is provided
B - array[N,M], right part
M - right part size
OUTPUT PARAMETERS:
Info - return code:
* -3 A is singular, or VERY close to singular.
X is filled by zeros in such cases.
* -1 N<=0 was passed
* 1 task was solved
B - array[N]:
* for info>0 overwritten by solution
* for info=-3 filled by zeros
-- ALGLIB --
Copyright 18.03.2015 by Bochkanov Sergey
*************************************************************************/
</div><div style='margin-top: 0; margin-bottom: 0;'><b>void</b> alglib::hpdmatrixcholeskysolvemfast(
complex_2d_array cha,
ae_int_t n,
<b>bool</b> isupper,
complex_2d_array& b,
ae_int_t m,
ae_int_t& info);
<b>void</b> alglib::smp_hpdmatrixcholeskysolvemfast(
complex_2d_array cha,
ae_int_t n,
<b>bool</b> isupper,
complex_2d_array& b,
ae_int_t m,
ae_int_t& info);
</div></pre>
<a name='sub_hpdmatrixsolve'></a><h3 class=pageheader><code>hpdmatrixsolve</code> function</h3>
<pre class=source>
<div style='color: navy; margin-top: 0; margin-bottom: 0;'>/*************************************************************************
Dense solver for A*x=b, with N*N Hermitian positive definite matrix A, and
N*1 complex vectors x and b. "Slow-but-feature-rich" version of the
solver.
Algorithm features:
* automatic detection of degenerate cases
* condition number estimation
* O(N^3) complexity
* matrix is represented by its upper or lower triangle
No iterative refinement is provided because such partial representation of
matrix does not allow efficient calculation of extra-precise matrix-vector
products for large matrices. Use RMatrixSolve or RMatrixMixedSolve if you
need iterative refinement.
IMPORTANT: ! this function is NOT the most efficient linear solver provided
! by ALGLIB. It estimates condition number of linear system,
! which results in significant performance penalty when
! compared with "fast" version which just performs Cholesky
! decomposition and calls triangular solver.
!
! This performance penalty is especially visible in the
! multithreaded mode, because both condition number estimation
! and iterative refinement are inherently sequential
! calculations.
!
! Thus, if you need high performance and if you are pretty sure
! that your system is well conditioned, we strongly recommend
! you to use faster solver, HPDMatrixSolveFast() function.
COMMERCIAL EDITION OF ALGLIB:
! Commercial version of ALGLIB includes two important improvements of
! this function, which can be used from C++ and C#:
! * Intel MKL support (lightweight Intel MKL is shipped with ALGLIB)
! * multicore support
!
! Intel MKL gives approximately constant (with respect to number of
! worker threads) acceleration factor which depends on CPU being used,
! problem size and "baseline" ALGLIB edition which is used for
! comparison.
!
! Say, on SSE2-capable CPU with N=1024, HPC ALGLIB will be:
! * about 2-3x faster than ALGLIB for C++ without MKL
! * about 7-10x faster than "pure C#" edition of ALGLIB
! Difference in performance will be more striking on newer CPU's with
! support for newer SIMD instructions. Generally, MKL accelerates any
! problem whose size is at least 128, with best efficiency achieved for
! N's larger than 512.
!
! Commercial edition of ALGLIB also supports multithreaded acceleration
! of this function. We should note that Cholesky decomposition is harder
! to parallelize than, say, matrix-matrix product - this algorithm has
! several synchronization points which can not be avoided. However,
! parallelism starts to be profitable starting from N=500.
!
! In order to use multicore features you have to:
! * use commercial version of ALGLIB
! * call this function with "smp_" prefix, which indicates that
! multicore code will be used (for multicore support)
!
! We recommend you to read 'Working with commercial version' section of
! ALGLIB Reference Manual in order to find out how to use performance-
! related features provided by commercial edition of ALGLIB.
INPUT PARAMETERS
A - array[0..N-1,0..N-1], system matrix
N - size of A
IsUpper - what half of A is provided
B - array[0..N-1], right part
OUTPUT PARAMETERS
Info - same as in RMatrixSolve
Returns -3 for non-HPD matrices.
Rep - same as in RMatrixSolve
X - same as in RMatrixSolve
-- ALGLIB --
Copyright 27.01.2010 by Bochkanov Sergey
*************************************************************************/
</div><div style='margin-top: 0; margin-bottom: 0;'><b>void</b> alglib::hpdmatrixsolve(
complex_2d_array a,
ae_int_t n,
<b>bool</b> isupper,
complex_1d_array b,
ae_int_t& info,
densesolverreport& rep,
complex_1d_array& x);
<b>void</b> alglib::smp_hpdmatrixsolve(
complex_2d_array a,
ae_int_t n,
<b>bool</b> isupper,
complex_1d_array b,
ae_int_t& info,
densesolverreport& rep,
complex_1d_array& x);
</div></pre>
<a name='sub_hpdmatrixsolvefast'></a><h3 class=pageheader><code>hpdmatrixsolvefast</code> function</h3>
<pre class=source>
<div style='color: navy; margin-top: 0; margin-bottom: 0;'>/*************************************************************************
Dense solver for A*x=b, with N*N Hermitian positive definite matrix A, and
N*1 complex vectors x and b. "Fast-but-lightweight" version of the
solver without additional functions.
Algorithm features:
* O(N^3) complexity
* matrix is represented by its upper or lower triangle
* no additional time consuming functions
COMMERCIAL EDITION OF ALGLIB:
! Commercial version of ALGLIB includes two important improvements of
! this function, which can be used from C++ and C#:
! * Intel MKL support (lightweight Intel MKL is shipped with ALGLIB)
! * multicore support
!
! Intel MKL gives approximately constant (with respect to number of
! worker threads) acceleration factor which depends on CPU being used,
! problem size and "baseline" ALGLIB edition which is used for
! comparison.
!
! Say, on SSE2-capable CPU with N=1024, HPC ALGLIB will be:
! * about 2-3x faster than ALGLIB for C++ without MKL
! * about 7-10x faster than "pure C#" edition of ALGLIB
! Difference in performance will be more striking on newer CPU's with
! support for newer SIMD instructions. Generally, MKL accelerates any
! problem whose size is at least 128, with best efficiency achieved for
! N's larger than 512.
!
! Commercial edition of ALGLIB also supports multithreaded acceleration
! of this function. We should note that Cholesky decomposition is harder
! to parallelize than, say, matrix-matrix product - this algorithm has
! several synchronization points which can not be avoided. However,
! parallelism starts to be profitable starting from N=500.
!
! In order to use multicore features you have to:
! * use commercial version of ALGLIB
! * call this function with "smp_" prefix, which indicates that
! multicore code will be used (for multicore support)
!
! We recommend you to read 'Working with commercial version' section of
! ALGLIB Reference Manual in order to find out how to use performance-
! related features provided by commercial edition of ALGLIB.
INPUT PARAMETERS
A - array[0..N-1,0..N-1], system matrix
N - size of A
IsUpper - what half of A is provided
B - array[0..N-1], right part
OUTPUT PARAMETERS
Info - return code:
* -3 A is is exactly singular or not positive definite
X is filled by zeros in such cases.
* -1 N<=0 was passed
* 1 task was solved
B - array[0..N-1]:
* overwritten by solution
* zeros, if A is exactly singular (diagonal of its LU
decomposition has exact zeros).
-- ALGLIB --
Copyright 17.03.2015 by Bochkanov Sergey
*************************************************************************/
</div><div style='margin-top: 0; margin-bottom: 0;'><b>void</b> alglib::hpdmatrixsolvefast(
complex_2d_array a,
ae_int_t n,
<b>bool</b> isupper,
complex_1d_array& b,
ae_int_t& info);
<b>void</b> alglib::smp_hpdmatrixsolvefast(
complex_2d_array a,
ae_int_t n,
<b>bool</b> isupper,
complex_1d_array& b,
ae_int_t& info);
</div></pre>
<a name='sub_hpdmatrixsolvem'></a><h3 class=pageheader><code>hpdmatrixsolvem</code> function</h3>
<pre class=source>
<div style='color: navy; margin-top: 0; margin-bottom: 0;'>/*************************************************************************
Dense solver for A*X=B, with N*N Hermitian positive definite matrix A and
N*M complex matrices X and B. "Slow-but-feature-rich" version of the
solver.
Algorithm features:
* automatic detection of degenerate cases
* condition number estimation
* O(N^3+M*N^2) complexity
* matrix is represented by its upper or lower triangle
No iterative refinement is provided because such partial representation of
matrix does not allow efficient calculation of extra-precise matrix-vector
products for large matrices. Use RMatrixSolve or RMatrixMixedSolve if you
need iterative refinement.
IMPORTANT: ! this function is NOT the most efficient linear solver provided
! by ALGLIB. It estimates condition number of linear system,
! which results in significant performance penalty when
! compared with "fast" version which just calls triangular
! solver.
!
! This performance penalty is especially apparent when you use
! ALGLIB parallel capabilities (condition number estimation is
! inherently sequential). It also becomes significant for
! small-scale problems (N<100).
!
! In such cases we strongly recommend you to use faster solver,
! HPDMatrixSolveMFast() function.
COMMERCIAL EDITION OF ALGLIB:
! Commercial version of ALGLIB includes two important improvements of
! this function, which can be used from C++ and C#:
! * Intel MKL support (lightweight Intel MKL is shipped with ALGLIB)
! * multicore support
!
! Intel MKL gives approximately constant (with respect to number of
! worker threads) acceleration factor which depends on CPU being used,
! problem size and "baseline" ALGLIB edition which is used for
! comparison.
!
! Say, on SSE2-capable CPU with N=1024, HPC ALGLIB will be:
! * about 2-3x faster than ALGLIB for C++ without MKL
! * about 7-10x faster than "pure C#" edition of ALGLIB
! Difference in performance will be more striking on newer CPU's with
! support for newer SIMD instructions. Generally, MKL accelerates any
! problem whose size is at least 128, with best efficiency achieved for
! N's larger than 512.
!
! Commercial edition of ALGLIB also supports multithreaded acceleration
! of this function. We should note that Cholesky decomposition is harder
! to parallelize than, say, matrix-matrix product - this algorithm has
! several synchronization points which can not be avoided. However,
! parallelism starts to be profitable starting from N=500.
!
! In order to use multicore features you have to:
! * use commercial version of ALGLIB
! * call this function with "smp_" prefix, which indicates that
! multicore code will be used (for multicore support)
!
! We recommend you to read 'Working with commercial version' section of
! ALGLIB Reference Manual in order to find out how to use performance-
! related features provided by commercial edition of ALGLIB.
INPUT PARAMETERS
A - array[0..N-1,0..N-1], system matrix
N - size of A
IsUpper - what half of A is provided
B - array[0..N-1,0..M-1], right part
M - right part size
OUTPUT PARAMETERS
Info - same as in RMatrixSolve.
Returns -3 for non-HPD matrices.
Rep - same as in RMatrixSolve
X - same as in RMatrixSolve
-- ALGLIB --
Copyright 27.01.2010 by Bochkanov Sergey
*************************************************************************/
</div><div style='margin-top: 0; margin-bottom: 0;'><b>void</b> alglib::hpdmatrixsolvem(
complex_2d_array a,
ae_int_t n,
<b>bool</b> isupper,
complex_2d_array b,
ae_int_t m,
ae_int_t& info,
densesolverreport& rep,
complex_2d_array& x);
<b>void</b> alglib::smp_hpdmatrixsolvem(
complex_2d_array a,
ae_int_t n,
<b>bool</b> isupper,
complex_2d_array b,
ae_int_t m,
ae_int_t& info,
densesolverreport& rep,
complex_2d_array& x);
</div></pre>
<a name='sub_hpdmatrixsolvemfast'></a><h3 class=pageheader><code>hpdmatrixsolvemfast</code> function</h3>
<pre class=source>
<div style='color: navy; margin-top: 0; margin-bottom: 0;'>/*************************************************************************
Dense solver for A*X=B, with N*N Hermitian positive definite matrix A and
N*M complex matrices X and B. "Fast-but-lightweight" version of the solver.
Algorithm features:
* O(N^3+M*N^2) complexity
* matrix is represented by its upper or lower triangle
* no additional time consuming features like condition number estimation
COMMERCIAL EDITION OF ALGLIB:
! Commercial version of ALGLIB includes two important improvements of
! this function, which can be used from C++ and C#:
! * Intel MKL support (lightweight Intel MKL is shipped with ALGLIB)
! * multicore support
!
! Intel MKL gives approximately constant (with respect to number of
! worker threads) acceleration factor which depends on CPU being used,
! problem size and "baseline" ALGLIB edition which is used for
! comparison.
!
! Say, on SSE2-capable CPU with N=1024, HPC ALGLIB will be:
! * about 2-3x faster than ALGLIB for C++ without MKL
! * about 7-10x faster than "pure C#" edition of ALGLIB
! Difference in performance will be more striking on newer CPU's with
! support for newer SIMD instructions. Generally, MKL accelerates any
! problem whose size is at least 128, with best efficiency achieved for
! N's larger than 512.
!
! Commercial edition of ALGLIB also supports multithreaded acceleration
! of this function. We should note that Cholesky decomposition is harder
! to parallelize than, say, matrix-matrix product - this algorithm has
! several synchronization points which can not be avoided. However,
! parallelism starts to be profitable starting from N=500.
!
! In order to use multicore features you have to:
! * use commercial version of ALGLIB
! * call this function with "smp_" prefix, which indicates that
! multicore code will be used (for multicore support)
!
! We recommend you to read 'Working with commercial version' section of
! ALGLIB Reference Manual in order to find out how to use performance-
! related features provided by commercial edition of ALGLIB.
INPUT PARAMETERS
A - array[0..N-1,0..N-1], system matrix
N - size of A
IsUpper - what half of A is provided
B - array[0..N-1,0..M-1], right part
M - right part size
OUTPUT PARAMETERS
Info - return code:
* -3 A is is exactly singular or is not positive definite.
B is filled by zeros in such cases.
* -1 N<=0 was passed
* 1 task is solved
B - array[0..N-1]:
* overwritten by solution
* zeros, if problem was not solved
-- ALGLIB --
Copyright 17.03.2015 by Bochkanov Sergey
*************************************************************************/
</div><div style='margin-top: 0; margin-bottom: 0;'><b>void</b> alglib::hpdmatrixsolvemfast(
complex_2d_array a,
ae_int_t n,
<b>bool</b> isupper,
complex_2d_array& b,
ae_int_t m,
ae_int_t& info);
<b>void</b> alglib::smp_hpdmatrixsolvemfast(
complex_2d_array a,
ae_int_t n,
<b>bool</b> isupper,
complex_2d_array& b,
ae_int_t m,
ae_int_t& info);
</div></pre>
<a name='sub_rmatrixlusolve'></a><h3 class=pageheader><code>rmatrixlusolve</code> function</h3>
<pre class=source>
<div style='color: navy; margin-top: 0; margin-bottom: 0;'>/*************************************************************************
Dense solver.
This subroutine solves a system A*x=b, where A is NxN non-denegerate
real matrix given by its LU decomposition, x and b are real vectors. This
is "slow-but-robust" version of the linear LU-based solver. Faster version
is RMatrixLUSolveFast() function.
Algorithm features:
* automatic detection of degenerate cases
* O(N^2) complexity
* condition number estimation
No iterative refinement is provided because exact form of original matrix
is not known to subroutine. Use RMatrixSolve or RMatrixMixedSolve if you
need iterative refinement.
IMPORTANT: ! this function is NOT the most efficient linear solver provided
! by ALGLIB. It estimates condition number of linear system,
! which results in 10-15x performance penalty when compared
! with "fast" version which just calls triangular solver.
!
! This performance penalty is insignificant when compared with
! cost of large LU decomposition. However, if you call this
! function many times for the same left side, this overhead
! BECOMES significant. It also becomes significant for small-
! scale problems.
!
! In such cases we strongly recommend you to use faster solver,
! RMatrixLUSolveFast() function.
INPUT PARAMETERS
LUA - array[N,N], LU decomposition, RMatrixLU result
P - array[N], pivots array, RMatrixLU result
N - size of A
B - array[N], right part
OUTPUT PARAMETERS
Info - return code:
* -3 matrix is very badly conditioned or exactly singular.
* -1 N<=0 was passed
* 1 task is solved (but matrix A may be ill-conditioned,
check R1/RInf parameters for condition numbers).
Rep - additional report, following fields are set:
* rep.r1 condition number in 1-norm
* rep.rinf condition number in inf-norm
X - array[N], it contains:
* info>0 => solution
* info=-3 => filled by zeros
-- ALGLIB --
Copyright 27.01.2010 by Bochkanov Sergey
*************************************************************************/
</div><div style='margin-top: 0; margin-bottom: 0;'><b>void</b> alglib::rmatrixlusolve(
real_2d_array lua,
integer_1d_array p,
ae_int_t n,
real_1d_array b,
ae_int_t& info,
densesolverreport& rep,
real_1d_array& x);
</div></pre>
<a name='sub_rmatrixlusolvefast'></a><h3 class=pageheader><code>rmatrixlusolvefast</code> function</h3>
<pre class=source>
<div style='color: navy; margin-top: 0; margin-bottom: 0;'>/*************************************************************************
Dense solver.
This subroutine solves a system A*x=b, where A is NxN non-denegerate
real matrix given by its LU decomposition, x and b are real vectors. This
is "fast-without-any-checks" version of the linear LU-based solver. Slower
but more robust version is RMatrixLUSolve() function.
Algorithm features:
* O(N^2) complexity
* fast algorithm without ANY additional checks, just triangular solver
INPUT PARAMETERS
LUA - array[0..N-1,0..N-1], LU decomposition, RMatrixLU result
P - array[0..N-1], pivots array, RMatrixLU result
N - size of A
B - array[0..N-1], right part
OUTPUT PARAMETERS
Info - return code:
* -3 matrix is exactly singular (ill conditioned matrices
are not recognized).
X is filled by zeros in such cases.
* -1 N<=0 was passed
* 1 task is solved
B - array[N]:
* info>0 => overwritten by solution
* info=-3 => filled by zeros
-- ALGLIB --
Copyright 18.03.2015 by Bochkanov Sergey
*************************************************************************/
</div><div style='margin-top: 0; margin-bottom: 0;'><b>void</b> alglib::rmatrixlusolvefast(
real_2d_array lua,
integer_1d_array p,
ae_int_t n,
real_1d_array& b,
ae_int_t& info);
</div></pre>
<a name='sub_rmatrixlusolvem'></a><h3 class=pageheader><code>rmatrixlusolvem</code> function</h3>
<pre class=source>
<div style='color: navy; margin-top: 0; margin-bottom: 0;'>/*************************************************************************
Dense solver.
Similar to RMatrixLUSolve() but solves task with multiple right parts
(where b and x are NxM matrices). This is "robust-but-slow" version of
LU-based solver which performs additional checks for non-degeneracy of
inputs (condition number estimation). If you need best performance, use
"fast-without-any-checks" version, RMatrixLUSolveMFast().
Algorithm features:
* automatic detection of degenerate cases
* O(M*N^2) complexity
* condition number estimation
No iterative refinement is provided because exact form of original matrix
is not known to subroutine. Use RMatrixSolve or RMatrixMixedSolve if you
need iterative refinement.
IMPORTANT: ! this function is NOT the most efficient linear solver provided
! by ALGLIB. It estimates condition number of linear system,
! which results in significant performance penalty when
! compared with "fast" version which just calls triangular
! solver.
!
! This performance penalty is especially apparent when you use
! ALGLIB parallel capabilities (condition number estimation is
! inherently sequential). It also becomes significant for
! small-scale problems.
!
! In such cases we strongly recommend you to use faster solver,
! RMatrixLUSolveMFast() function.
COMMERCIAL EDITION OF ALGLIB:
! Commercial version of ALGLIB includes two important improvements of
! this function, which can be used from C++ and C#:
! * Intel MKL support (lightweight Intel MKL is shipped with ALGLIB)
! * multicore support
!
! Intel MKL gives approximately constant (with respect to number of
! worker threads) acceleration factor which depends on CPU being used,
! problem size and "baseline" ALGLIB edition which is used for
! comparison.
!
! Say, on SSE2-capable CPU with N=1024, HPC ALGLIB will be:
! * about 2-3x faster than ALGLIB for C++ without MKL
! * about 7-10x faster than "pure C#" edition of ALGLIB
! Difference in performance will be more striking on newer CPU's with
! support for newer SIMD instructions. Generally, MKL accelerates any
! problem whose size is at least 128, with best efficiency achieved for
! N's larger than 512.
!
! Commercial edition of ALGLIB also supports multithreaded acceleration
! of this function. Triangular solver is relatively easy to parallelize.
! However, parallelization will be efficient only for large number of
! right parts M.
!
! In order to use multicore features you have to:
! * use commercial version of ALGLIB
! * call this function with "smp_" prefix, which indicates that
! multicore code will be used (for multicore support)
!
! We recommend you to read 'Working with commercial version' section of
! ALGLIB Reference Manual in order to find out how to use performance-
! related features provided by commercial edition of ALGLIB.
INPUT PARAMETERS
LUA - array[N,N], LU decomposition, RMatrixLU result
P - array[N], pivots array, RMatrixLU result
N - size of A
B - array[0..N-1,0..M-1], right part
M - right part size
OUTPUT PARAMETERS
Info - return code:
* -3 matrix is very badly conditioned or exactly singular.
X is filled by zeros in such cases.
* -1 N<=0 was passed
* 1 task is solved (but matrix A may be ill-conditioned,
check R1/RInf parameters for condition numbers).
Rep - additional report, following fields are set:
* rep.r1 condition number in 1-norm
* rep.rinf condition number in inf-norm
X - array[N,M], it contains:
* info>0 => solution
* info=-3 => filled by zeros
-- ALGLIB --
Copyright 27.01.2010 by Bochkanov Sergey
*************************************************************************/
</div><div style='margin-top: 0; margin-bottom: 0;'><b>void</b> alglib::rmatrixlusolvem(
real_2d_array lua,
integer_1d_array p,
ae_int_t n,
real_2d_array b,
ae_int_t m,
ae_int_t& info,
densesolverreport& rep,
real_2d_array& x);
<b>void</b> alglib::smp_rmatrixlusolvem(
real_2d_array lua,
integer_1d_array p,
ae_int_t n,
real_2d_array b,
ae_int_t m,
ae_int_t& info,
densesolverreport& rep,
real_2d_array& x);
</div></pre>
<a name='sub_rmatrixlusolvemfast'></a><h3 class=pageheader><code>rmatrixlusolvemfast</code> function</h3>
<pre class=source>
<div style='color: navy; margin-top: 0; margin-bottom: 0;'>/*************************************************************************
Dense solver.
Similar to RMatrixLUSolve() but solves task with multiple right parts,
where b and x are NxM matrices. This is "fast-without-any-checks" version
of LU-based solver. It does not estimate condition number of a system,
so it is extremely fast. If you need better detection of near-degenerate
cases, use RMatrixLUSolveM() function.
Algorithm features:
* O(M*N^2) complexity
* fast algorithm without ANY additional checks, just triangular solver
COMMERCIAL EDITION OF ALGLIB:
! Commercial version of ALGLIB includes two important improvements of
! this function, which can be used from C++ and C#:
! * Intel MKL support (lightweight Intel MKL is shipped with ALGLIB)
! * multicore support
!
! Intel MKL gives approximately constant (with respect to number of
! worker threads) acceleration factor which depends on CPU being used,
! problem size and "baseline" ALGLIB edition which is used for
! comparison.
!
! Say, on SSE2-capable CPU with N=1024, HPC ALGLIB will be:
! * about 2-3x faster than ALGLIB for C++ without MKL
! * about 7-10x faster than "pure C#" edition of ALGLIB
! Difference in performance will be more striking on newer CPU's with
! support for newer SIMD instructions. Generally, MKL accelerates any
! problem whose size is at least 128, with best efficiency achieved for
! N's larger than 512.
!
! Commercial edition of ALGLIB also supports multithreaded acceleration
! of this function. Triangular solver is relatively easy to parallelize.
! However, parallelization will be efficient only for large number of
! right parts M.
!
! In order to use multicore features you have to:
! * use commercial version of ALGLIB
! * call this function with "smp_" prefix, which indicates that
! multicore code will be used (for multicore support)
!
! We recommend you to read 'Working with commercial version' section of
! ALGLIB Reference Manual in order to find out how to use performance-
! related features provided by commercial edition of ALGLIB.
INPUT PARAMETERS:
LUA - array[0..N-1,0..N-1], LU decomposition, RMatrixLU result
P - array[0..N-1], pivots array, RMatrixLU result
N - size of A
B - array[0..N-1,0..M-1], right part
M - right part size
OUTPUT PARAMETERS:
Info - return code:
* -3 matrix is exactly singular (ill conditioned matrices
are not recognized).
* -1 N<=0 was passed
* 1 task is solved
B - array[N,M]:
* info>0 => overwritten by solution
* info=-3 => filled by zeros
-- ALGLIB --
Copyright 18.03.2015 by Bochkanov Sergey
*************************************************************************/
</div><div style='margin-top: 0; margin-bottom: 0;'><b>void</b> alglib::rmatrixlusolvemfast(
real_2d_array lua,
integer_1d_array p,
ae_int_t n,
real_2d_array& b,
ae_int_t m,
ae_int_t& info);
<b>void</b> alglib::smp_rmatrixlusolvemfast(
real_2d_array lua,
integer_1d_array p,
ae_int_t n,
real_2d_array& b,
ae_int_t m,
ae_int_t& info);
</div></pre>
<a name='sub_rmatrixmixedsolve'></a><h3 class=pageheader><code>rmatrixmixedsolve</code> function</h3>
<pre class=source>
<div style='color: navy; margin-top: 0; margin-bottom: 0;'>/*************************************************************************
Dense solver.
This subroutine solves a system A*x=b, where BOTH ORIGINAL A AND ITS
LU DECOMPOSITION ARE KNOWN. You can use it if for some reasons you have
both A and its LU decomposition.
Algorithm features:
* automatic detection of degenerate cases
* condition number estimation
* iterative refinement
* O(N^2) complexity
INPUT PARAMETERS
A - array[0..N-1,0..N-1], system matrix
LUA - array[0..N-1,0..N-1], LU decomposition, RMatrixLU result
P - array[0..N-1], pivots array, RMatrixLU result
N - size of A
B - array[0..N-1], right part
OUTPUT PARAMETERS
Info - return code:
* -3 matrix is very badly conditioned or exactly singular.
* -1 N<=0 was passed
* 1 task is solved (but matrix A may be ill-conditioned,
check R1/RInf parameters for condition numbers).
Rep - additional report, following fields are set:
* rep.r1 condition number in 1-norm
* rep.rinf condition number in inf-norm
X - array[N], it contains:
* info>0 => solution
* info=-3 => filled by zeros
-- ALGLIB --
Copyright 27.01.2010 by Bochkanov Sergey
*************************************************************************/
</div><div style='margin-top: 0; margin-bottom: 0;'><b>void</b> alglib::rmatrixmixedsolve(
real_2d_array a,
real_2d_array lua,
integer_1d_array p,
ae_int_t n,
real_1d_array b,
ae_int_t& info,
densesolverreport& rep,
real_1d_array& x);
</div></pre>
<a name='sub_rmatrixmixedsolvem'></a><h3 class=pageheader><code>rmatrixmixedsolvem</code> function</h3>
<pre class=source>
<div style='color: navy; margin-top: 0; margin-bottom: 0;'>/*************************************************************************
Dense solver.
Similar to RMatrixMixedSolve() but solves task with multiple right parts
(where b and x are NxM matrices).
Algorithm features:
* automatic detection of degenerate cases
* condition number estimation
* iterative refinement
* O(M*N^2) complexity
INPUT PARAMETERS
A - array[0..N-1,0..N-1], system matrix
LUA - array[0..N-1,0..N-1], LU decomposition, RMatrixLU result
P - array[0..N-1], pivots array, RMatrixLU result
N - size of A
B - array[0..N-1,0..M-1], right part
M - right part size
OUTPUT PARAMETERS
Info - return code:
* -3 matrix is very badly conditioned or exactly singular.
* -1 N<=0 was passed
* 1 task is solved (but matrix A may be ill-conditioned,
check R1/RInf parameters for condition numbers).
Rep - additional report, following fields are set:
* rep.r1 condition number in 1-norm
* rep.rinf condition number in inf-norm
X - array[N,M], it contains:
* info>0 => solution
* info=-3 => filled by zeros
-- ALGLIB --
Copyright 27.01.2010 by Bochkanov Sergey
*************************************************************************/
</div><div style='margin-top: 0; margin-bottom: 0;'><b>void</b> alglib::rmatrixmixedsolvem(
real_2d_array a,
real_2d_array lua,
integer_1d_array p,
ae_int_t n,
real_2d_array b,
ae_int_t m,
ae_int_t& info,
densesolverreport& rep,
real_2d_array& x);
</div></pre>
<a name='sub_rmatrixsolve'></a><h3 class=pageheader><code>rmatrixsolve</code> function</h3>
<pre class=source>
<div style='color: navy; margin-top: 0; margin-bottom: 0;'>/*************************************************************************
Dense solver for A*x=b with N*N real matrix A and N*1 real vectorx x and
b. This is "slow-but-feature rich" version of the linear solver. Faster
version is RMatrixSolveFast() function.
Algorithm features:
* automatic detection of degenerate cases
* condition number estimation
* iterative refinement
* O(N^3) complexity
IMPORTANT: ! this function is NOT the most efficient linear solver provided
! by ALGLIB. It estimates condition number of linear system
! and performs iterative refinement, which results in
! significant performance penalty when compared with "fast"
! version which just performs LU decomposition and calls
! triangular solver.
!
! This performance penalty is especially visible in the
! multithreaded mode, because both condition number estimation
! and iterative refinement are inherently sequential
! calculations. It also very significant on small matrices.
!
! Thus, if you need high performance and if you are pretty sure
! that your system is well conditioned, we strongly recommend
! you to use faster solver, RMatrixSolveFast() function.
COMMERCIAL EDITION OF ALGLIB:
! Commercial version of ALGLIB includes two important improvements of
! this function, which can be used from C++ and C#:
! * Intel MKL support (lightweight Intel MKL is shipped with ALGLIB)
! * multicore support
!
! Intel MKL gives approximately constant (with respect to number of
! worker threads) acceleration factor which depends on CPU being used,
! problem size and "baseline" ALGLIB edition which is used for
! comparison.
!
! Say, on SSE2-capable CPU with N=1024, HPC ALGLIB will be:
! * about 2-3x faster than ALGLIB for C++ without MKL
! * about 7-10x faster than "pure C#" edition of ALGLIB
! Difference in performance will be more striking on newer CPU's with
! support for newer SIMD instructions. Generally, MKL accelerates any
! problem whose size is at least 128, with best efficiency achieved for
! N's larger than 512.
!
! Commercial edition of ALGLIB also supports multithreaded acceleration
! of this function. We should note that LU decomposition is harder to
! parallelize than, say, matrix-matrix product - this algorithm has
! many internal synchronization points which can not be avoided. However
! parallelism starts to be profitable starting from N=1024, achieving
! near-linear speedup for N=4096 or higher.
!
! In order to use multicore features you have to:
! * use commercial version of ALGLIB
! * call this function with "smp_" prefix, which indicates that
! multicore code will be used (for multicore support)
!
! We recommend you to read 'Working with commercial version' section of
! ALGLIB Reference Manual in order to find out how to use performance-
! related features provided by commercial edition of ALGLIB.
INPUT PARAMETERS
A - array[0..N-1,0..N-1], system matrix
N - size of A
B - array[0..N-1], right part
OUTPUT PARAMETERS
Info - return code:
* -3 matrix is very badly conditioned or exactly singular.
* -1 N<=0 was passed
* 1 task is solved (but matrix A may be ill-conditioned,
check R1/RInf parameters for condition numbers).
Rep - additional report, following fields are set:
* rep.r1 condition number in 1-norm
* rep.rinf condition number in inf-norm
X - array[N], it contains:
* info>0 => solution
* info=-3 => filled by zeros
-- ALGLIB --
Copyright 27.01.2010 by Bochkanov Sergey
*************************************************************************/
</div><div style='margin-top: 0; margin-bottom: 0;'><b>void</b> alglib::rmatrixsolve(
real_2d_array a,
ae_int_t n,
real_1d_array b,
ae_int_t& info,
densesolverreport& rep,
real_1d_array& x);
<b>void</b> alglib::smp_rmatrixsolve(
real_2d_array a,
ae_int_t n,
real_1d_array b,
ae_int_t& info,
densesolverreport& rep,
real_1d_array& x);
</div></pre>
<a name='sub_rmatrixsolvefast'></a><h3 class=pageheader><code>rmatrixsolvefast</code> function</h3>
<pre class=source>
<div style='color: navy; margin-top: 0; margin-bottom: 0;'>/*************************************************************************
Dense solver.
This subroutine solves a system A*x=b, where A is NxN non-denegerate
real matrix, x and b are vectors. This is a "fast" version of linear
solver which does NOT provide any additional functions like condition
number estimation or iterative refinement.
Algorithm features:
* efficient algorithm O(N^3) complexity
* no performance overhead from additional functionality
If you need condition number estimation or iterative refinement, use more
feature-rich version - RMatrixSolve().
COMMERCIAL EDITION OF ALGLIB:
! Commercial version of ALGLIB includes two important improvements of
! this function, which can be used from C++ and C#:
! * Intel MKL support (lightweight Intel MKL is shipped with ALGLIB)
! * multicore support
!
! Intel MKL gives approximately constant (with respect to number of
! worker threads) acceleration factor which depends on CPU being used,
! problem size and "baseline" ALGLIB edition which is used for
! comparison.
!
! Say, on SSE2-capable CPU with N=1024, HPC ALGLIB will be:
! * about 2-3x faster than ALGLIB for C++ without MKL
! * about 7-10x faster than "pure C#" edition of ALGLIB
! Difference in performance will be more striking on newer CPU's with
! support for newer SIMD instructions. Generally, MKL accelerates any
! problem whose size is at least 128, with best efficiency achieved for
! N's larger than 512.
!
! Commercial edition of ALGLIB also supports multithreaded acceleration
! of this function. We should note that LU decomposition is harder to
! parallelize than, say, matrix-matrix product - this algorithm has
! many internal synchronization points which can not be avoided. However
! parallelism starts to be profitable starting from N=1024, achieving
! near-linear speedup for N=4096 or higher.
!
! In order to use multicore features you have to:
! * use commercial version of ALGLIB
! * call this function with "smp_" prefix, which indicates that
! multicore code will be used (for multicore support)
!
! We recommend you to read 'Working with commercial version' section of
! ALGLIB Reference Manual in order to find out how to use performance-
! related features provided by commercial edition of ALGLIB.
INPUT PARAMETERS
A - array[0..N-1,0..N-1], system matrix
N - size of A
B - array[0..N-1], right part
OUTPUT PARAMETERS
Info - return code:
* -3 matrix is exactly singular (ill conditioned matrices
are not recognized).
* -1 N<=0 was passed
* 1 task is solved
B - array[N]:
* info>0 => overwritten by solution
* info=-3 => filled by zeros
-- ALGLIB --
Copyright 16.03.2015 by Bochkanov Sergey
*************************************************************************/
</div><div style='margin-top: 0; margin-bottom: 0;'><b>void</b> alglib::rmatrixsolvefast(
real_2d_array a,
ae_int_t n,
real_1d_array& b,
ae_int_t& info);
<b>void</b> alglib::smp_rmatrixsolvefast(
real_2d_array a,
ae_int_t n,
real_1d_array& b,
ae_int_t& info);
</div></pre>
<a name='sub_rmatrixsolvels'></a><h3 class=pageheader><code>rmatrixsolvels</code> function</h3>
<pre class=source>
<div style='color: navy; margin-top: 0; margin-bottom: 0;'>/*************************************************************************
Dense solver.
This subroutine finds solution of the linear system A*X=B with non-square,
possibly degenerate A. System is solved in the least squares sense, and
general least squares solution X = X0 + CX*y which minimizes |A*X-B| is
returned. If A is non-degenerate, solution in the usual sense is returned.
Algorithm features:
* automatic detection (and correct handling!) of degenerate cases
* iterative refinement
* O(N^3) complexity
COMMERCIAL EDITION OF ALGLIB:
! Commercial version of ALGLIB includes one important improvement of
! this function, which can be used from C++ and C#:
! * Intel MKL support (lightweight Intel MKL is shipped with ALGLIB)
!
! Intel MKL gives approximately constant (with respect to number of
! worker threads) acceleration factor which depends on CPU being used,
! problem size and "baseline" ALGLIB edition which is used for
! comparison.
!
! Generally, commercial ALGLIB is several times faster than open-source
! generic C edition, and many times faster than open-source C# edition.
!
! Multithreaded acceleration is only partially supported (some parts are
! optimized, but most - are not).
!
! We recommend you to read 'Working with commercial version' section of
! ALGLIB Reference Manual in order to find out how to use performance-
! related features provided by commercial edition of ALGLIB.
INPUT PARAMETERS
A - array[0..NRows-1,0..NCols-1], system matrix
NRows - vertical size of A
NCols - horizontal size of A
B - array[0..NCols-1], right part
Threshold- a number in [0,1]. Singular values beyond Threshold are
considered zero. Set it to 0.0, if you don't understand
what it means, so the solver will choose good value on its
own.
OUTPUT PARAMETERS
Info - return code:
* -4 SVD subroutine failed
* -1 if NRows<=0 or NCols<=0 or Threshold<0 was passed
* 1 if task is solved
Rep - solver report, see below for more info
X - array[0..N-1,0..M-1], it contains:
* solution of A*X=B (even for singular A)
* zeros, if SVD subroutine failed
SOLVER REPORT
Subroutine sets following fields of the Rep structure:
* R2 reciprocal of condition number: 1/cond(A), 2-norm.
* N = NCols
* K dim(Null(A))
* CX array[0..N-1,0..K-1], kernel of A.
Columns of CX store such vectors that A*CX[i]=0.
-- ALGLIB --
Copyright 24.08.2009 by Bochkanov Sergey
*************************************************************************/
</div><div style='margin-top: 0; margin-bottom: 0;'><b>void</b> alglib::rmatrixsolvels(
real_2d_array a,
ae_int_t nrows,
ae_int_t ncols,
real_1d_array b,
<b>double</b> threshold,
ae_int_t& info,
densesolverlsreport& rep,
real_1d_array& x);
<b>void</b> alglib::smp_rmatrixsolvels(
real_2d_array a,
ae_int_t nrows,
ae_int_t ncols,
real_1d_array b,
<b>double</b> threshold,
ae_int_t& info,
densesolverlsreport& rep,
real_1d_array& x);
</div></pre>
<a name='sub_rmatrixsolvem'></a><h3 class=pageheader><code>rmatrixsolvem</code> function</h3>
<pre class=source>
<div style='color: navy; margin-top: 0; margin-bottom: 0;'>/*************************************************************************
Dense solver.
Similar to RMatrixSolve() but solves task with multiple right parts (where
b and x are NxM matrices). This is "slow-but-robust" version of linear
solver with additional functionality like condition number estimation.
There also exists faster version - RMatrixSolveMFast().
Algorithm features:
* automatic detection of degenerate cases
* condition number estimation
* optional iterative refinement
* O(N^3+M*N^2) complexity
IMPORTANT: ! this function is NOT the most efficient linear solver provided
! by ALGLIB. It estimates condition number of linear system
! and performs iterative refinement, which results in
! significant performance penalty when compared with "fast"
! version which just performs LU decomposition and calls
! triangular solver.
!
! This performance penalty is especially visible in the
! multithreaded mode, because both condition number estimation
! and iterative refinement are inherently sequential
! calculations. It also very significant on small matrices.
!
! Thus, if you need high performance and if you are pretty sure
! that your system is well conditioned, we strongly recommend
! you to use faster solver, RMatrixSolveMFast() function.
COMMERCIAL EDITION OF ALGLIB:
! Commercial version of ALGLIB includes two important improvements of
! this function, which can be used from C++ and C#:
! * Intel MKL support (lightweight Intel MKL is shipped with ALGLIB)
! * multicore support
!
! Intel MKL gives approximately constant (with respect to number of
! worker threads) acceleration factor which depends on CPU being used,
! problem size and "baseline" ALGLIB edition which is used for
! comparison.
!
! Say, on SSE2-capable CPU with N=1024, HPC ALGLIB will be:
! * about 2-3x faster than ALGLIB for C++ without MKL
! * about 7-10x faster than "pure C#" edition of ALGLIB
! Difference in performance will be more striking on newer CPU's with
! support for newer SIMD instructions. Generally, MKL accelerates any
! problem whose size is at least 128, with best efficiency achieved for
! N's larger than 512.
!
! Commercial edition of ALGLIB also supports multithreaded acceleration
! of this function. We should note that LU decomposition is harder to
! parallelize than, say, matrix-matrix product - this algorithm has
! many internal synchronization points which can not be avoided. However
! parallelism starts to be profitable starting from N=1024, achieving
! near-linear speedup for N=4096 or higher.
!
! In order to use multicore features you have to:
! * use commercial version of ALGLIB
! * call this function with "smp_" prefix, which indicates that
! multicore code will be used (for multicore support)
!
! We recommend you to read 'Working with commercial version' section of
! ALGLIB Reference Manual in order to find out how to use performance-
! related features provided by commercial edition of ALGLIB.
INPUT PARAMETERS
A - array[0..N-1,0..N-1], system matrix
N - size of A
B - array[0..N-1,0..M-1], right part
M - right part size
RFS - iterative refinement switch:
* True - refinement is used.
Less performance, more precision.
* False - refinement is not used.
More performance, less precision.
OUTPUT PARAMETERS
Info - return code:
* -3 A is ill conditioned or singular.
X is filled by zeros in such cases.
* -1 N<=0 was passed
* 1 task is solved (but matrix A may be ill-conditioned,
check R1/RInf parameters for condition numbers).
Rep - additional report, following fields are set:
* rep.r1 condition number in 1-norm
* rep.rinf condition number in inf-norm
X - array[N], it contains:
* info>0 => solution
* info=-3 => filled by zeros
-- ALGLIB --
Copyright 27.01.2010 by Bochkanov Sergey
*************************************************************************/
</div><div style='margin-top: 0; margin-bottom: 0;'><b>void</b> alglib::rmatrixsolvem(
real_2d_array a,
ae_int_t n,
real_2d_array b,
ae_int_t m,
<b>bool</b> rfs,
ae_int_t& info,
densesolverreport& rep,
real_2d_array& x);
<b>void</b> alglib::smp_rmatrixsolvem(
real_2d_array a,
ae_int_t n,
real_2d_array b,
ae_int_t m,
<b>bool</b> rfs,
ae_int_t& info,
densesolverreport& rep,
real_2d_array& x);
</div></pre>
<a name='sub_rmatrixsolvemfast'></a><h3 class=pageheader><code>rmatrixsolvemfast</code> function</h3>
<pre class=source>
<div style='color: navy; margin-top: 0; margin-bottom: 0;'>/*************************************************************************
Dense solver.
Similar to RMatrixSolve() but solves task with multiple right parts (where
b and x are NxM matrices). This is "fast" version of linear solver which
does NOT offer additional functions like condition number estimation or
iterative refinement.
Algorithm features:
* O(N^3+M*N^2) complexity
* no additional functionality, highest performance
COMMERCIAL EDITION OF ALGLIB:
! Commercial version of ALGLIB includes two important improvements of
! this function, which can be used from C++ and C#:
! * Intel MKL support (lightweight Intel MKL is shipped with ALGLIB)
! * multicore support
!
! Intel MKL gives approximately constant (with respect to number of
! worker threads) acceleration factor which depends on CPU being used,
! problem size and "baseline" ALGLIB edition which is used for
! comparison.
!
! Say, on SSE2-capable CPU with N=1024, HPC ALGLIB will be:
! * about 2-3x faster than ALGLIB for C++ without MKL
! * about 7-10x faster than "pure C#" edition of ALGLIB
! Difference in performance will be more striking on newer CPU's with
! support for newer SIMD instructions. Generally, MKL accelerates any
! problem whose size is at least 128, with best efficiency achieved for
! N's larger than 512.
!
! Commercial edition of ALGLIB also supports multithreaded acceleration
! of this function. We should note that LU decomposition is harder to
! parallelize than, say, matrix-matrix product - this algorithm has
! many internal synchronization points which can not be avoided. However
! parallelism starts to be profitable starting from N=1024, achieving
! near-linear speedup for N=4096 or higher.
!
! In order to use multicore features you have to:
! * use commercial version of ALGLIB
! * call this function with "smp_" prefix, which indicates that
! multicore code will be used (for multicore support)
!
! We recommend you to read 'Working with commercial version' section of
! ALGLIB Reference Manual in order to find out how to use performance-
! related features provided by commercial edition of ALGLIB.
INPUT PARAMETERS
A - array[0..N-1,0..N-1], system matrix
N - size of A
B - array[0..N-1,0..M-1], right part
M - right part size
RFS - iterative refinement switch:
* True - refinement is used.
Less performance, more precision.
* False - refinement is not used.
More performance, less precision.
OUTPUT PARAMETERS
Info - return code:
* -3 matrix is exactly singular (ill conditioned matrices
are not recognized).
X is filled by zeros in such cases.
* -1 N<=0 was passed
* 1 task is solved
Rep - additional report, following fields are set:
* rep.r1 condition number in 1-norm
* rep.rinf condition number in inf-norm
B - array[N]:
* info>0 => overwritten by solution
* info=-3 => filled by zeros
-- ALGLIB --
Copyright 27.01.2010 by Bochkanov Sergey
*************************************************************************/
</div><div style='margin-top: 0; margin-bottom: 0;'><b>void</b> alglib::rmatrixsolvemfast(
real_2d_array a,
ae_int_t n,
real_2d_array& b,
ae_int_t m,
ae_int_t& info);
<b>void</b> alglib::smp_rmatrixsolvemfast(
real_2d_array a,
ae_int_t n,
real_2d_array& b,
ae_int_t m,
ae_int_t& info);
</div></pre>
<a name='sub_spdmatrixcholeskysolve'></a><h3 class=pageheader><code>spdmatrixcholeskysolve</code> function</h3>
<pre class=source>
<div style='color: navy; margin-top: 0; margin-bottom: 0;'>/*************************************************************************
Dense solver for A*x=b with N*N symmetric positive definite matrix A given
by its Cholesky decomposition, and N*1 real vectors x and b. This is "slow-
but-feature-rich" version of the solver which, in addition to the
solution, performs condition number estimation.
Algorithm features:
* automatic detection of degenerate cases
* O(N^2) complexity
* condition number estimation
* matrix is represented by its upper or lower triangle
No iterative refinement is provided because such partial representation of
matrix does not allow efficient calculation of extra-precise matrix-vector
products for large matrices. Use RMatrixSolve or RMatrixMixedSolve if you
need iterative refinement.
IMPORTANT: ! this function is NOT the most efficient linear solver provided
! by ALGLIB. It estimates condition number of linear system,
! which results in 10-15x performance penalty when compared
! with "fast" version which just calls triangular solver.
!
! This performance penalty is insignificant when compared with
! cost of large LU decomposition. However, if you call this
! function many times for the same left side, this overhead
! BECOMES significant. It also becomes significant for small-
! scale problems (N<50).
!
! In such cases we strongly recommend you to use faster solver,
! SPDMatrixCholeskySolveFast() function.
INPUT PARAMETERS
CHA - array[N,N], Cholesky decomposition,
SPDMatrixCholesky result
N - size of A
IsUpper - what half of CHA is provided
B - array[N], right part
OUTPUT PARAMETERS
Info - return code:
* -3 A is is exactly singular or ill conditioned
X is filled by zeros in such cases.
* -1 N<=0 was passed
* 1 task is solved
Rep - additional report, following fields are set:
* rep.r1 condition number in 1-norm
* rep.rinf condition number in inf-norm
X - array[N]:
* for info>0 - solution
* for info=-3 - filled by zeros
-- ALGLIB --
Copyright 27.01.2010 by Bochkanov Sergey
*************************************************************************/
</div><div style='margin-top: 0; margin-bottom: 0;'><b>void</b> alglib::spdmatrixcholeskysolve(
real_2d_array cha,
ae_int_t n,
<b>bool</b> isupper,
real_1d_array b,
ae_int_t& info,
densesolverreport& rep,
real_1d_array& x);
</div></pre>
<a name='sub_spdmatrixcholeskysolvefast'></a><h3 class=pageheader><code>spdmatrixcholeskysolvefast</code> function</h3>
<pre class=source>
<div style='color: navy; margin-top: 0; margin-bottom: 0;'>/*************************************************************************
Dense solver for A*x=b with N*N symmetric positive definite matrix A given
by its Cholesky decomposition, and N*1 real vectors x and b. This is "fast-
but-lightweight" version of the solver.
Algorithm features:
* O(N^2) complexity
* matrix is represented by its upper or lower triangle
* no additional features
INPUT PARAMETERS
CHA - array[N,N], Cholesky decomposition,
SPDMatrixCholesky result
N - size of A
IsUpper - what half of CHA is provided
B - array[N], right part
OUTPUT PARAMETERS
Info - return code:
* -3 A is is exactly singular or ill conditioned
X is filled by zeros in such cases.
* -1 N<=0 was passed
* 1 task is solved
B - array[N]:
* for info>0 - overwritten by solution
* for info=-3 - filled by zeros
-- ALGLIB --
Copyright 27.01.2010 by Bochkanov Sergey
*************************************************************************/
</div><div style='margin-top: 0; margin-bottom: 0;'><b>void</b> alglib::spdmatrixcholeskysolvefast(
real_2d_array cha,
ae_int_t n,
<b>bool</b> isupper,
real_1d_array& b,
ae_int_t& info);
</div></pre>
<a name='sub_spdmatrixcholeskysolvem'></a><h3 class=pageheader><code>spdmatrixcholeskysolvem</code> function</h3>
<pre class=source>
<div style='color: navy; margin-top: 0; margin-bottom: 0;'>/*************************************************************************
Dense solver for A*X=B with N*N symmetric positive definite matrix A given
by its Cholesky decomposition, and N*M vectors X and B. It is "slow-but-
feature-rich" version of the solver which estimates condition number of
the system.
Algorithm features:
* automatic detection of degenerate cases
* O(M*N^2) complexity
* condition number estimation
* matrix is represented by its upper or lower triangle
No iterative refinement is provided because such partial representation of
matrix does not allow efficient calculation of extra-precise matrix-vector
products for large matrices. Use RMatrixSolve or RMatrixMixedSolve if you
need iterative refinement.
IMPORTANT: ! this function is NOT the most efficient linear solver provided
! by ALGLIB. It estimates condition number of linear system,
! which results in significant performance penalty when
! compared with "fast" version which just calls triangular
! solver. Amount of overhead introduced depends on M (the
! larger - the more efficient).
!
! This performance penalty is insignificant when compared with
! cost of large LU decomposition. However, if you call this
! function many times for the same left side, this overhead
! BECOMES significant. It also becomes significant for small-
! scale problems (N<50).
!
! In such cases we strongly recommend you to use faster solver,
! SPDMatrixCholeskySolveMFast() function.
INPUT PARAMETERS
CHA - array[0..N-1,0..N-1], Cholesky decomposition,
SPDMatrixCholesky result
N - size of CHA
IsUpper - what half of CHA is provided
B - array[0..N-1,0..M-1], right part
M - right part size
OUTPUT PARAMETERS
Info - return code:
* -3 A is is exactly singular or badly conditioned
X is filled by zeros in such cases.
* -1 N<=0 was passed
* 1 task was solved
Rep - additional report, following fields are set:
* rep.r1 condition number in 1-norm
* rep.rinf condition number in inf-norm
X - array[N]:
* for info>0 contains solution
* for info=-3 filled by zeros
-- ALGLIB --
Copyright 27.01.2010 by Bochkanov Sergey
*************************************************************************/
</div><div style='margin-top: 0; margin-bottom: 0;'><b>void</b> alglib::spdmatrixcholeskysolvem(
real_2d_array cha,
ae_int_t n,
<b>bool</b> isupper,
real_2d_array b,
ae_int_t m,
ae_int_t& info,
densesolverreport& rep,
real_2d_array& x);
<b>void</b> alglib::smp_spdmatrixcholeskysolvem(
real_2d_array cha,
ae_int_t n,
<b>bool</b> isupper,
real_2d_array b,
ae_int_t m,
ae_int_t& info,
densesolverreport& rep,
real_2d_array& x);
</div></pre>
<a name='sub_spdmatrixcholeskysolvemfast'></a><h3 class=pageheader><code>spdmatrixcholeskysolvemfast</code> function</h3>
<pre class=source>
<div style='color: navy; margin-top: 0; margin-bottom: 0;'>/*************************************************************************
Dense solver for A*X=B with N*N symmetric positive definite matrix A given
by its Cholesky decomposition, and N*M vectors X and B. It is "fast-but-
lightweight" version of the solver which just solves linear system,
without any additional functions.
Algorithm features:
* O(M*N^2) complexity
* matrix is represented by its upper or lower triangle
* no additional functionality
INPUT PARAMETERS
CHA - array[N,N], Cholesky decomposition,
SPDMatrixCholesky result
N - size of CHA
IsUpper - what half of CHA is provided
B - array[N,M], right part
M - right part size
OUTPUT PARAMETERS
Info - return code:
* -3 A is is exactly singular or badly conditioned
X is filled by zeros in such cases.
* -1 N<=0 was passed
* 1 task was solved
B - array[N]:
* for info>0 overwritten by solution
* for info=-3 filled by zeros
-- ALGLIB --
Copyright 18.03.2015 by Bochkanov Sergey
*************************************************************************/
</div><div style='margin-top: 0; margin-bottom: 0;'><b>void</b> alglib::spdmatrixcholeskysolvemfast(
real_2d_array cha,
ae_int_t n,
<b>bool</b> isupper,
real_2d_array& b,
ae_int_t m,
ae_int_t& info);
<b>void</b> alglib::smp_spdmatrixcholeskysolvemfast(
real_2d_array cha,
ae_int_t n,
<b>bool</b> isupper,
real_2d_array& b,
ae_int_t m,
ae_int_t& info);
</div></pre>
<a name='sub_spdmatrixsolve'></a><h3 class=pageheader><code>spdmatrixsolve</code> function</h3>
<pre class=source>
<div style='color: navy; margin-top: 0; margin-bottom: 0;'>/*************************************************************************
Dense linear solver for A*x=b with N*N real symmetric positive definite
matrix A, N*1 vectors x and b. "Slow-but-feature-rich" version of the
solver.
Algorithm features:
* automatic detection of degenerate cases
* condition number estimation
* O(N^3) complexity
* matrix is represented by its upper or lower triangle
No iterative refinement is provided because such partial representation of
matrix does not allow efficient calculation of extra-precise matrix-vector
products for large matrices. Use RMatrixSolve or RMatrixMixedSolve if you
need iterative refinement.
IMPORTANT: ! this function is NOT the most efficient linear solver provided
! by ALGLIB. It estimates condition number of linear system,
! which results in significant performance penalty when
! compared with "fast" version which just performs Cholesky
! decomposition and calls triangular solver.
!
! This performance penalty is especially visible in the
! multithreaded mode, because both condition number estimation
! and iterative refinement are inherently sequential
! calculations.
!
! Thus, if you need high performance and if you are pretty sure
! that your system is well conditioned, we strongly recommend
! you to use faster solver, SPDMatrixSolveFast() function.
COMMERCIAL EDITION OF ALGLIB:
! Commercial version of ALGLIB includes two important improvements of
! this function, which can be used from C++ and C#:
! * Intel MKL support (lightweight Intel MKL is shipped with ALGLIB)
! * multicore support
!
! Intel MKL gives approximately constant (with respect to number of
! worker threads) acceleration factor which depends on CPU being used,
! problem size and "baseline" ALGLIB edition which is used for
! comparison.
!
! Say, on SSE2-capable CPU with N=1024, HPC ALGLIB will be:
! * about 2-3x faster than ALGLIB for C++ without MKL
! * about 7-10x faster than "pure C#" edition of ALGLIB
! Difference in performance will be more striking on newer CPU's with
! support for newer SIMD instructions. Generally, MKL accelerates any
! problem whose size is at least 128, with best efficiency achieved for
! N's larger than 512.
!
! Commercial edition of ALGLIB also supports multithreaded acceleration
! of this function. We should note that Cholesky decomposition is harder
! to parallelize than, say, matrix-matrix product - this algorithm has
! several synchronization points which can not be avoided. However,
! parallelism starts to be profitable starting from N=500.
!
! In order to use multicore features you have to:
! * use commercial version of ALGLIB
! * call this function with "smp_" prefix, which indicates that
! multicore code will be used (for multicore support)
!
! We recommend you to read 'Working with commercial version' section of
! ALGLIB Reference Manual in order to find out how to use performance-
! related features provided by commercial edition of ALGLIB.
INPUT PARAMETERS
A - array[0..N-1,0..N-1], system matrix
N - size of A
IsUpper - what half of A is provided
B - array[0..N-1], right part
OUTPUT PARAMETERS
Info - return code:
* -3 matrix is very badly conditioned or non-SPD.
* -1 N<=0 was passed
* 1 task is solved (but matrix A may be ill-conditioned,
check R1/RInf parameters for condition numbers).
Rep - additional report, following fields are set:
* rep.r1 condition number in 1-norm
* rep.rinf condition number in inf-norm
X - array[N], it contains:
* info>0 => solution
* info=-3 => filled by zeros
-- ALGLIB --
Copyright 27.01.2010 by Bochkanov Sergey
*************************************************************************/
</div><div style='margin-top: 0; margin-bottom: 0;'><b>void</b> alglib::spdmatrixsolve(
real_2d_array a,
ae_int_t n,
<b>bool</b> isupper,
real_1d_array b,
ae_int_t& info,
densesolverreport& rep,
real_1d_array& x);
<b>void</b> alglib::smp_spdmatrixsolve(
real_2d_array a,
ae_int_t n,
<b>bool</b> isupper,
real_1d_array b,
ae_int_t& info,
densesolverreport& rep,
real_1d_array& x);
</div></pre>
<a name='sub_spdmatrixsolvefast'></a><h3 class=pageheader><code>spdmatrixsolvefast</code> function</h3>
<pre class=source>
<div style='color: navy; margin-top: 0; margin-bottom: 0;'>/*************************************************************************
Dense linear solver for A*x=b with N*N real symmetric positive definite
matrix A, N*1 vectors x and b. "Fast-but-lightweight" version of the
solver.
Algorithm features:
* O(N^3) complexity
* matrix is represented by its upper or lower triangle
* no additional time consuming features like condition number estimation
COMMERCIAL EDITION OF ALGLIB:
! Commercial version of ALGLIB includes two important improvements of
! this function, which can be used from C++ and C#:
! * Intel MKL support (lightweight Intel MKL is shipped with ALGLIB)
! * multicore support
!
! Intel MKL gives approximately constant (with respect to number of
! worker threads) acceleration factor which depends on CPU being used,
! problem size and "baseline" ALGLIB edition which is used for
! comparison.
!
! Say, on SSE2-capable CPU with N=1024, HPC ALGLIB will be:
! * about 2-3x faster than ALGLIB for C++ without MKL
! * about 7-10x faster than "pure C#" edition of ALGLIB
! Difference in performance will be more striking on newer CPU's with
! support for newer SIMD instructions. Generally, MKL accelerates any
! problem whose size is at least 128, with best efficiency achieved for
! N's larger than 512.
!
! Commercial edition of ALGLIB also supports multithreaded acceleration
! of this function. We should note that Cholesky decomposition is harder
! to parallelize than, say, matrix-matrix product - this algorithm has
! several synchronization points which can not be avoided. However,
! parallelism starts to be profitable starting from N=500.
!
! In order to use multicore features you have to:
! * use commercial version of ALGLIB
! * call this function with "smp_" prefix, which indicates that
! multicore code will be used (for multicore support)
!
! We recommend you to read 'Working with commercial version' section of
! ALGLIB Reference Manual in order to find out how to use performance-
! related features provided by commercial edition of ALGLIB.
INPUT PARAMETERS
A - array[0..N-1,0..N-1], system matrix
N - size of A
IsUpper - what half of A is provided
B - array[0..N-1], right part
OUTPUT PARAMETERS
Info - return code:
* -3 A is is exactly singular or non-SPD
* -1 N<=0 was passed
* 1 task was solved
B - array[N], it contains:
* info>0 => solution
* info=-3 => filled by zeros
-- ALGLIB --
Copyright 17.03.2015 by Bochkanov Sergey
*************************************************************************/
</div><div style='margin-top: 0; margin-bottom: 0;'><b>void</b> alglib::spdmatrixsolvefast(
real_2d_array a,
ae_int_t n,
<b>bool</b> isupper,
real_1d_array& b,
ae_int_t& info);
<b>void</b> alglib::smp_spdmatrixsolvefast(
real_2d_array a,
ae_int_t n,
<b>bool</b> isupper,
real_1d_array& b,
ae_int_t& info);
</div></pre>
<a name='sub_spdmatrixsolvem'></a><h3 class=pageheader><code>spdmatrixsolvem</code> function</h3>
<pre class=source>
<div style='color: navy; margin-top: 0; margin-bottom: 0;'>/*************************************************************************
Dense solver for A*X=B with N*N symmetric positive definite matrix A, and
N*M vectors X and B. It is "slow-but-feature-rich" version of the solver.
Algorithm features:
* automatic detection of degenerate cases
* condition number estimation
* O(N^3+M*N^2) complexity
* matrix is represented by its upper or lower triangle
No iterative refinement is provided because such partial representation of
matrix does not allow efficient calculation of extra-precise matrix-vector
products for large matrices. Use RMatrixSolve or RMatrixMixedSolve if you
need iterative refinement.
IMPORTANT: ! this function is NOT the most efficient linear solver provided
! by ALGLIB. It estimates condition number of linear system,
! which results in significant performance penalty when
! compared with "fast" version which just performs Cholesky
! decomposition and calls triangular solver.
!
! This performance penalty is especially visible in the
! multithreaded mode, because both condition number estimation
! and iterative refinement are inherently sequential
! calculations.
!
! Thus, if you need high performance and if you are pretty sure
! that your system is well conditioned, we strongly recommend
! you to use faster solver, SPDMatrixSolveMFast() function.
COMMERCIAL EDITION OF ALGLIB:
! Commercial version of ALGLIB includes two important improvements of
! this function, which can be used from C++ and C#:
! * Intel MKL support (lightweight Intel MKL is shipped with ALGLIB)
! * multicore support
!
! Intel MKL gives approximately constant (with respect to number of
! worker threads) acceleration factor which depends on CPU being used,
! problem size and "baseline" ALGLIB edition which is used for
! comparison.
!
! Say, on SSE2-capable CPU with N=1024, HPC ALGLIB will be:
! * about 2-3x faster than ALGLIB for C++ without MKL
! * about 7-10x faster than "pure C#" edition of ALGLIB
! Difference in performance will be more striking on newer CPU's with
! support for newer SIMD instructions. Generally, MKL accelerates any
! problem whose size is at least 128, with best efficiency achieved for
! N's larger than 512.
!
! Commercial edition of ALGLIB also supports multithreaded acceleration
! of this function. We should note that Cholesky decomposition is harder
! to parallelize than, say, matrix-matrix product - this algorithm has
! several synchronization points which can not be avoided. However,
! parallelism starts to be profitable starting from N=500.
!
! In order to use multicore features you have to:
! * use commercial version of ALGLIB
! * call this function with "smp_" prefix, which indicates that
! multicore code will be used (for multicore support)
!
! We recommend you to read 'Working with commercial version' section of
! ALGLIB Reference Manual in order to find out how to use performance-
! related features provided by commercial edition of ALGLIB.
INPUT PARAMETERS
A - array[0..N-1,0..N-1], system matrix
N - size of A
IsUpper - what half of A is provided
B - array[0..N-1,0..M-1], right part
M - right part size
OUTPUT PARAMETERS
Info - return code:
* -3 matrix is very badly conditioned or non-SPD.
* -1 N<=0 was passed
* 1 task is solved (but matrix A may be ill-conditioned,
check R1/RInf parameters for condition numbers).
Rep - additional report, following fields are set:
* rep.r1 condition number in 1-norm
* rep.rinf condition number in inf-norm
X - array[N,M], it contains:
* info>0 => solution
* info=-3 => filled by zeros
-- ALGLIB --
Copyright 27.01.2010 by Bochkanov Sergey
*************************************************************************/
</div><div style='margin-top: 0; margin-bottom: 0;'><b>void</b> alglib::spdmatrixsolvem(
real_2d_array a,
ae_int_t n,
<b>bool</b> isupper,
real_2d_array b,
ae_int_t m,
ae_int_t& info,
densesolverreport& rep,
real_2d_array& x);
<b>void</b> alglib::smp_spdmatrixsolvem(
real_2d_array a,
ae_int_t n,
<b>bool</b> isupper,
real_2d_array b,
ae_int_t m,
ae_int_t& info,
densesolverreport& rep,
real_2d_array& x);
</div></pre>
<a name='sub_spdmatrixsolvemfast'></a><h3 class=pageheader><code>spdmatrixsolvemfast</code> function</h3>
<pre class=source>
<div style='color: navy; margin-top: 0; margin-bottom: 0;'>/*************************************************************************
Dense solver for A*X=B with N*N symmetric positive definite matrix A, and
N*M vectors X and B. It is "fast-but-lightweight" version of the solver.
Algorithm features:
* O(N^3+M*N^2) complexity
* matrix is represented by its upper or lower triangle
* no additional time consuming features
COMMERCIAL EDITION OF ALGLIB:
! Commercial version of ALGLIB includes two important improvements of
! this function, which can be used from C++ and C#:
! * Intel MKL support (lightweight Intel MKL is shipped with ALGLIB)
! * multicore support
!
! Intel MKL gives approximately constant (with respect to number of
! worker threads) acceleration factor which depends on CPU being used,
! problem size and "baseline" ALGLIB edition which is used for
! comparison.
!
! Say, on SSE2-capable CPU with N=1024, HPC ALGLIB will be:
! * about 2-3x faster than ALGLIB for C++ without MKL
! * about 7-10x faster than "pure C#" edition of ALGLIB
! Difference in performance will be more striking on newer CPU's with
! support for newer SIMD instructions. Generally, MKL accelerates any
! problem whose size is at least 128, with best efficiency achieved for
! N's larger than 512.
!
! Commercial edition of ALGLIB also supports multithreaded acceleration
! of this function. We should note that Cholesky decomposition is harder
! to parallelize than, say, matrix-matrix product - this algorithm has
! several synchronization points which can not be avoided. However,
! parallelism starts to be profitable starting from N=500.
!
! In order to use multicore features you have to:
! * use commercial version of ALGLIB
! * call this function with "smp_" prefix, which indicates that
! multicore code will be used (for multicore support)
!
! We recommend you to read 'Working with commercial version' section of
! ALGLIB Reference Manual in order to find out how to use performance-
! related features provided by commercial edition of ALGLIB.
INPUT PARAMETERS
A - array[0..N-1,0..N-1], system matrix
N - size of A
IsUpper - what half of A is provided
B - array[0..N-1,0..M-1], right part
M - right part size
OUTPUT PARAMETERS
Info - return code:
* -3 A is is exactly singular
* -1 N<=0 was passed
* 1 task was solved
B - array[N,M], it contains:
* info>0 => solution
* info=-3 => filled by zeros
-- ALGLIB --
Copyright 17.03.2015 by Bochkanov Sergey
*************************************************************************/
</div><div style='margin-top: 0; margin-bottom: 0;'><b>void</b> alglib::spdmatrixsolvemfast(
real_2d_array a,
ae_int_t n,
<b>bool</b> isupper,
real_2d_array& b,
ae_int_t m,
ae_int_t& info);
<b>void</b> alglib::smp_spdmatrixsolvemfast(
real_2d_array a,
ae_int_t n,
<b>bool</b> isupper,
real_2d_array& b,
ae_int_t m,
ae_int_t& info);
</div></pre>
<a name=unit_dforest></a><h2 class=pageheader><code>dforest</code> subpackage</h2>
<div class=pagecontent>
<h3 class=pageheader>Classes</h3>
<a href='#struct_decisionforest' class=toc>decisionforest</a><br>
<a href='#struct_dfreport' class=toc>dfreport</a><br>
<h3 class=pageheader>Functions</h3>
<a href='#sub_dfavgce' class=toc>dfavgce</a><br>
<a href='#sub_dfavgerror' class=toc>dfavgerror</a><br>
<a href='#sub_dfavgrelerror' class=toc>dfavgrelerror</a><br>
<a href='#sub_dfbuildrandomdecisionforest' class=toc>dfbuildrandomdecisionforest</a><br>
<a href='#sub_dfbuildrandomdecisionforestx1' class=toc>dfbuildrandomdecisionforestx1</a><br>
<a href='#sub_dfprocess' class=toc>dfprocess</a><br>
<a href='#sub_dfprocessi' class=toc>dfprocessi</a><br>
<a href='#sub_dfrelclserror' class=toc>dfrelclserror</a><br>
<a href='#sub_dfrmserror' class=toc>dfrmserror</a><br>
<a href='#sub_dfserialize' class=toc>dfserialize</a><br>
<a href='#sub_dfunserialize' class=toc>dfunserialize</a><br>
<h3 class=pageheader>Examples</h3>
<table border=0 cellspacing=0 class='pagecontent'>
</table></div>
<a name='struct_decisionforest'></a><h3 class=pageheader><code>decisionforest</code> class</h3>
<pre class=source>
<div style='color: navy; margin-top: 0; margin-bottom: 0;'>/*************************************************************************
*************************************************************************/
</div><div style='margin-top: 0; margin-bottom: 0;'><b>class</b> decisionforest
{
};
</div></pre>
<a name='struct_dfreport'></a><h3 class=pageheader><code>dfreport</code> class</h3>
<pre class=source>
<div style='color: navy; margin-top: 0; margin-bottom: 0;'>/*************************************************************************
*************************************************************************/
</div><div style='margin-top: 0; margin-bottom: 0;'><b>class</b> dfreport
{
<b>double</b> relclserror;
<b>double</b> avgce;
<b>double</b> rmserror;
<b>double</b> avgerror;
<b>double</b> avgrelerror;
<b>double</b> oobrelclserror;
<b>double</b> oobavgce;
<b>double</b> oobrmserror;
<b>double</b> oobavgerror;
<b>double</b> oobavgrelerror;
};
</div></pre>
<a name='sub_dfavgce'></a><h3 class=pageheader><code>dfavgce</code> function</h3>
<pre class=source>
<div style='color: navy; margin-top: 0; margin-bottom: 0;'>/*************************************************************************
Average cross-entropy (in bits per element) on the test set
INPUT PARAMETERS:
DF - decision forest model
XY - test set
NPoints - test set size
RESULT:
CrossEntropy/(NPoints*LN(2)).
Zero if model solves regression task.
-- ALGLIB --
Copyright 16.02.2009 by Bochkanov Sergey
*************************************************************************/
</div><div style='margin-top: 0; margin-bottom: 0;'><b>double</b> alglib::dfavgce(
decisionforest df,
real_2d_array xy,
ae_int_t npoints);
</div></pre>
<a name='sub_dfavgerror'></a><h3 class=pageheader><code>dfavgerror</code> function</h3>
<pre class=source>
<div style='color: navy; margin-top: 0; margin-bottom: 0;'>/*************************************************************************
Average error on the test set
INPUT PARAMETERS:
DF - decision forest model
XY - test set
NPoints - test set size
RESULT:
Its meaning for regression task is obvious. As for
classification task, it means average error when estimating posterior
probabilities.
-- ALGLIB --
Copyright 16.02.2009 by Bochkanov Sergey
*************************************************************************/
</div><div style='margin-top: 0; margin-bottom: 0;'><b>double</b> alglib::dfavgerror(
decisionforest df,
real_2d_array xy,
ae_int_t npoints);
</div></pre>
<a name='sub_dfavgrelerror'></a><h3 class=pageheader><code>dfavgrelerror</code> function</h3>
<pre class=source>
<div style='color: navy; margin-top: 0; margin-bottom: 0;'>/*************************************************************************
Average relative error on the test set
INPUT PARAMETERS:
DF - decision forest model
XY - test set
NPoints - test set size
RESULT:
Its meaning for regression task is obvious. As for
classification task, it means average relative error when estimating
posterior probability of belonging to the correct class.
-- ALGLIB --
Copyright 16.02.2009 by Bochkanov Sergey
*************************************************************************/
</div><div style='margin-top: 0; margin-bottom: 0;'><b>double</b> alglib::dfavgrelerror(
decisionforest df,
real_2d_array xy,
ae_int_t npoints);
</div></pre>
<a name='sub_dfbuildrandomdecisionforest'></a><h3 class=pageheader><code>dfbuildrandomdecisionforest</code> function</h3>
<pre class=source>
<div style='color: navy; margin-top: 0; margin-bottom: 0;'>/*************************************************************************
This subroutine builds random decision forest.
INPUT PARAMETERS:
XY - training set
NPoints - training set size, NPoints>=1
NVars - number of independent variables, NVars>=1
NClasses - task type:
* NClasses=1 - regression task with one
dependent variable
* NClasses>1 - classification task with
NClasses classes.
NTrees - number of trees in a forest, NTrees>=1.
recommended values: 50-100.
R - percent of a training set used to build
individual trees. 0<R<=1.
recommended values: 0.1 <= R <= 0.66.
OUTPUT PARAMETERS:
Info - return code:
* -2, if there is a point with class number
outside of [0..NClasses-1].
* -1, if incorrect parameters was passed
(NPoints<1, NVars<1, NClasses<1, NTrees<1, R<=0
or R>1).
* 1, if task has been solved
DF - model built
Rep - training report, contains error on a training set
and out-of-bag estimates of generalization error.
-- ALGLIB --
Copyright 19.02.2009 by Bochkanov Sergey
*************************************************************************/
</div><div style='margin-top: 0; margin-bottom: 0;'><b>void</b> alglib::dfbuildrandomdecisionforest(
real_2d_array xy,
ae_int_t npoints,
ae_int_t nvars,
ae_int_t nclasses,
ae_int_t ntrees,
<b>double</b> r,
ae_int_t& info,
decisionforest& df,
dfreport& rep);
</div></pre>
<a name='sub_dfbuildrandomdecisionforestx1'></a><h3 class=pageheader><code>dfbuildrandomdecisionforestx1</code> function</h3>
<pre class=source>
<div style='color: navy; margin-top: 0; margin-bottom: 0;'>/*************************************************************************
This subroutine builds random decision forest.
This function gives ability to tune number of variables used when choosing
best split.
INPUT PARAMETERS:
XY - training set
NPoints - training set size, NPoints>=1
NVars - number of independent variables, NVars>=1
NClasses - task type:
* NClasses=1 - regression task with one
dependent variable
* NClasses>1 - classification task with
NClasses classes.
NTrees - number of trees in a forest, NTrees>=1.
recommended values: 50-100.
NRndVars - number of variables used when choosing best split
R - percent of a training set used to build
individual trees. 0<R<=1.
recommended values: 0.1 <= R <= 0.66.
OUTPUT PARAMETERS:
Info - return code:
* -2, if there is a point with class number
outside of [0..NClasses-1].
* -1, if incorrect parameters was passed
(NPoints<1, NVars<1, NClasses<1, NTrees<1, R<=0
or R>1).
* 1, if task has been solved
DF - model built
Rep - training report, contains error on a training set
and out-of-bag estimates of generalization error.
-- ALGLIB --
Copyright 19.02.2009 by Bochkanov Sergey
*************************************************************************/
</div><div style='margin-top: 0; margin-bottom: 0;'><b>void</b> alglib::dfbuildrandomdecisionforestx1(
real_2d_array xy,
ae_int_t npoints,
ae_int_t nvars,
ae_int_t nclasses,
ae_int_t ntrees,
ae_int_t nrndvars,
<b>double</b> r,
ae_int_t& info,
decisionforest& df,
dfreport& rep);
</div></pre>
<a name='sub_dfprocess'></a><h3 class=pageheader><code>dfprocess</code> function</h3>
<pre class=source>
<div style='color: navy; margin-top: 0; margin-bottom: 0;'>/*************************************************************************
Procesing
INPUT PARAMETERS:
DF - decision forest model
X - input vector, array[0..NVars-1].
OUTPUT PARAMETERS:
Y - result. Regression estimate when solving regression task,
vector of posterior probabilities for classification task.
See also DFProcessI.
-- ALGLIB --
Copyright 16.02.2009 by Bochkanov Sergey
*************************************************************************/
</div><div style='margin-top: 0; margin-bottom: 0;'><b>void</b> alglib::dfprocess(
decisionforest df,
real_1d_array x,
real_1d_array& y);
</div></pre>
<a name='sub_dfprocessi'></a><h3 class=pageheader><code>dfprocessi</code> function</h3>
<pre class=source>
<div style='color: navy; margin-top: 0; margin-bottom: 0;'>/*************************************************************************
'interactive' variant of DFProcess for languages like Python which support
constructs like "Y = DFProcessI(DF,X)" and interactive mode of interpreter
This function allocates new array on each call, so it is significantly
slower than its 'non-interactive' counterpart, but it is more convenient
when you call it from command line.
-- ALGLIB --
Copyright 28.02.2010 by Bochkanov Sergey
*************************************************************************/
</div><div style='margin-top: 0; margin-bottom: 0;'><b>void</b> alglib::dfprocessi(
decisionforest df,
real_1d_array x,
real_1d_array& y);
</div></pre>
<a name='sub_dfrelclserror'></a><h3 class=pageheader><code>dfrelclserror</code> function</h3>
<pre class=source>
<div style='color: navy; margin-top: 0; margin-bottom: 0;'>/*************************************************************************
Relative classification error on the test set
INPUT PARAMETERS:
DF - decision forest model
XY - test set
NPoints - test set size
RESULT:
percent of incorrectly classified cases.
Zero if model solves regression task.
-- ALGLIB --
Copyright 16.02.2009 by Bochkanov Sergey
*************************************************************************/
</div><div style='margin-top: 0; margin-bottom: 0;'><b>double</b> alglib::dfrelclserror(
decisionforest df,
real_2d_array xy,
ae_int_t npoints);
</div></pre>
<a name='sub_dfrmserror'></a><h3 class=pageheader><code>dfrmserror</code> function</h3>
<pre class=source>
<div style='color: navy; margin-top: 0; margin-bottom: 0;'>/*************************************************************************
RMS error on the test set
INPUT PARAMETERS:
DF - decision forest model
XY - test set
NPoints - test set size
RESULT:
root mean square error.
Its meaning for regression task is obvious. As for
classification task, RMS error means error when estimating posterior
probabilities.
-- ALGLIB --
Copyright 16.02.2009 by Bochkanov Sergey
*************************************************************************/
</div><div style='margin-top: 0; margin-bottom: 0;'><b>double</b> alglib::dfrmserror(
decisionforest df,
real_2d_array xy,
ae_int_t npoints);
</div></pre>
<a name='sub_dfserialize'></a><h3 class=pageheader><code>dfserialize</code> function</h3>
<pre class=source>
<div style='color: navy; margin-top: 0; margin-bottom: 0;'>/*************************************************************************
This function serializes data structure to string.
Important properties of s_out:
* it contains alphanumeric characters, dots, underscores, minus signs
* these symbols are grouped into words, which are separated by spaces
and Windows-style (CR+LF) newlines
* although serializer uses spaces and CR+LF as separators, you can
replace any separator character by arbitrary combination of spaces,
tabs, Windows or Unix newlines. It allows flexible reformatting of
the string in case you want to include it into text or XML file.
But you should not insert separators into the middle of the "words"
nor you should change case of letters.
* s_out can be freely moved between 32-bit and 64-bit systems, little
and big endian machines, and so on. You can serialize structure on
32-bit machine and unserialize it on 64-bit one (or vice versa), or
serialize it on SPARC and unserialize on x86. You can also
serialize it in C++ version of ALGLIB and unserialize in C# one,
and vice versa.
*************************************************************************/
</div><div style='margin-top: 0; margin-bottom: 0;'><b>void</b> dfserialize(decisionforest &obj, std::string &s_out);
</div></pre>
<a name='sub_dfunserialize'></a><h3 class=pageheader><code>dfunserialize</code> function</h3>
<pre class=source>
<div style='color: navy; margin-top: 0; margin-bottom: 0;'>/*************************************************************************
This function unserializes data structure from string.
*************************************************************************/
</div><div style='margin-top: 0; margin-bottom: 0;'><b>void</b> dfunserialize(std::string &s_in, decisionforest &obj);
</div></pre>
<a name=unit_elliptic></a><h2 class=pageheader><code>elliptic</code> subpackage</h2>
<div class=pagecontent>
<h3 class=pageheader>Functions</h3>
<a href='#sub_ellipticintegrale' class=toc>ellipticintegrale</a><br>
<a href='#sub_ellipticintegralk' class=toc>ellipticintegralk</a><br>
<a href='#sub_ellipticintegralkhighprecision' class=toc>ellipticintegralkhighprecision</a><br>
<a href='#sub_incompleteellipticintegrale' class=toc>incompleteellipticintegrale</a><br>
<a href='#sub_incompleteellipticintegralk' class=toc>incompleteellipticintegralk</a><br>
<h3 class=pageheader>Examples</h3>
<table border=0 cellspacing=0 class='pagecontent'>
</table></div>
<a name='sub_ellipticintegrale'></a><h3 class=pageheader><code>ellipticintegrale</code> function</h3>
<pre class=source>
<div style='color: navy; margin-top: 0; margin-bottom: 0;'>/*************************************************************************
Complete elliptic integral of the second kind
Approximates the integral
pi/2
-
| | 2
E(m) = | sqrt( 1 - m sin t ) dt
| |
-
0
using the approximation
P(x) - x log x Q(x).
ACCURACY:
Relative error:
arithmetic domain # trials peak rms
IEEE 0, 1 10000 2.1e-16 7.3e-17
Cephes Math Library, Release 2.8: June, 2000
Copyright 1984, 1987, 1989, 2000 by Stephen L. Moshier
*************************************************************************/
</div><div style='margin-top: 0; margin-bottom: 0;'><b>double</b> alglib::ellipticintegrale(<b>double</b> m);
</div></pre>
<a name='sub_ellipticintegralk'></a><h3 class=pageheader><code>ellipticintegralk</code> function</h3>
<pre class=source>
<div style='color: navy; margin-top: 0; margin-bottom: 0;'>/*************************************************************************
Complete elliptic integral of the first kind
Approximates the integral
pi/2
-
| |
| dt
K(m) = | ------------------
| 2
| | sqrt( 1 - m sin t )
-
0
using the approximation
P(x) - log x Q(x).
ACCURACY:
Relative error:
arithmetic domain # trials peak rms
IEEE 0,1 30000 2.5e-16 6.8e-17
Cephes Math Library, Release 2.8: June, 2000
Copyright 1984, 1987, 2000 by Stephen L. Moshier
*************************************************************************/
</div><div style='margin-top: 0; margin-bottom: 0;'><b>double</b> alglib::ellipticintegralk(<b>double</b> m);
</div></pre>
<a name='sub_ellipticintegralkhighprecision'></a><h3 class=pageheader><code>ellipticintegralkhighprecision</code> function</h3>
<pre class=source>
<div style='color: navy; margin-top: 0; margin-bottom: 0;'>/*************************************************************************
Complete elliptic integral of the first kind
Approximates the integral
pi/2
-
| |
| dt
K(m) = | ------------------
| 2
| | sqrt( 1 - m sin t )
-
0
where m = 1 - m1, using the approximation
P(x) - log x Q(x).
The argument m1 is used rather than m so that the logarithmic
singularity at m = 1 will be shifted to the origin; this
preserves maximum accuracy.
K(0) = pi/2.
ACCURACY:
Relative error:
arithmetic domain # trials peak rms
IEEE 0,1 30000 2.5e-16 6.8e-17
Cephes Math Library, Release 2.8: June, 2000
Copyright 1984, 1987, 2000 by Stephen L. Moshier
*************************************************************************/
</div><div style='margin-top: 0; margin-bottom: 0;'><b>double</b> alglib::ellipticintegralkhighprecision(<b>double</b> m1);
</div></pre>
<a name='sub_incompleteellipticintegrale'></a><h3 class=pageheader><code>incompleteellipticintegrale</code> function</h3>
<pre class=source>
<div style='color: navy; margin-top: 0; margin-bottom: 0;'>/*************************************************************************
Incomplete elliptic integral of the second kind
Approximates the integral
phi
-
| |
| 2
E(phi_\m) = | sqrt( 1 - m sin t ) dt
|
| |
-
0
of amplitude phi and modulus m, using the arithmetic -
geometric mean algorithm.
ACCURACY:
Tested at random arguments with phi in [-10, 10] and m in
[0, 1].
Relative error:
arithmetic domain # trials peak rms
IEEE -10,10 150000 3.3e-15 1.4e-16
Cephes Math Library Release 2.8: June, 2000
Copyright 1984, 1987, 1993, 2000 by Stephen L. Moshier
*************************************************************************/
</div><div style='margin-top: 0; margin-bottom: 0;'><b>double</b> alglib::incompleteellipticintegrale(<b>double</b> phi, <b>double</b> m);
</div></pre>
<a name='sub_incompleteellipticintegralk'></a><h3 class=pageheader><code>incompleteellipticintegralk</code> function</h3>
<pre class=source>
<div style='color: navy; margin-top: 0; margin-bottom: 0;'>/*************************************************************************
Incomplete elliptic integral of the first kind F(phi|m)
Approximates the integral
phi
-
| |
| dt
F(phi_\m) = | ------------------
| 2
| | sqrt( 1 - m sin t )
-
0
of amplitude phi and modulus m, using the arithmetic -
geometric mean algorithm.
ACCURACY:
Tested at random points with m in [0, 1] and phi as indicated.
Relative error:
arithmetic domain # trials peak rms
IEEE -10,10 200000 7.4e-16 1.0e-16
Cephes Math Library Release 2.8: June, 2000
Copyright 1984, 1987, 2000 by Stephen L. Moshier
*************************************************************************/
</div><div style='margin-top: 0; margin-bottom: 0;'><b>double</b> alglib::incompleteellipticintegralk(<b>double</b> phi, <b>double</b> m);
</div></pre>
<a name=unit_evd></a><h2 class=pageheader><code>evd</code> subpackage</h2>
<div class=pagecontent>
<h3 class=pageheader>Functions</h3>
<a href='#sub_hmatrixevd' class=toc>hmatrixevd</a><br>
<a href='#sub_hmatrixevdi' class=toc>hmatrixevdi</a><br>
<a href='#sub_hmatrixevdr' class=toc>hmatrixevdr</a><br>
<a href='#sub_rmatrixevd' class=toc>rmatrixevd</a><br>
<a href='#sub_smatrixevd' class=toc>smatrixevd</a><br>
<a href='#sub_smatrixevdi' class=toc>smatrixevdi</a><br>
<a href='#sub_smatrixevdr' class=toc>smatrixevdr</a><br>
<a href='#sub_smatrixtdevd' class=toc>smatrixtdevd</a><br>
<a href='#sub_smatrixtdevdi' class=toc>smatrixtdevdi</a><br>
<a href='#sub_smatrixtdevdr' class=toc>smatrixtdevdr</a><br>
<h3 class=pageheader>Examples</h3>
<table border=0 cellspacing=0 class='pagecontent'>
</table></div>
<a name='sub_hmatrixevd'></a><h3 class=pageheader><code>hmatrixevd</code> function</h3>
<pre class=source>
<div style='color: navy; margin-top: 0; margin-bottom: 0;'>/*************************************************************************
Finding the eigenvalues and eigenvectors of a Hermitian matrix
The algorithm finds eigen pairs of a Hermitian matrix by reducing it to
real tridiagonal form and using the QL/QR algorithm.
COMMERCIAL EDITION OF ALGLIB:
! Commercial version of ALGLIB includes one important improvement of
! this function, which can be used from C++ and C#:
! * Intel MKL support (lightweight Intel MKL is shipped with ALGLIB)
!
! Intel MKL gives approximately constant (with respect to number of
! worker threads) acceleration factor which depends on CPU being used,
! problem size and "baseline" ALGLIB edition which is used for
! comparison.
!
! Generally, commercial ALGLIB is several times faster than open-source
! generic C edition, and many times faster than open-source C# edition.
!
! Multithreaded acceleration is NOT supported for this function.
!
! We recommend you to read 'Working with commercial version' section of
! ALGLIB Reference Manual in order to find out how to use performance-
! related features provided by commercial edition of ALGLIB.
Input parameters:
A - Hermitian matrix which is given by its upper or lower
triangular part.
Array whose indexes range within [0..N-1, 0..N-1].
N - size of matrix A.
IsUpper - storage format.
ZNeeded - flag controlling whether the eigenvectors are needed or
not. If ZNeeded is equal to:
* 0, the eigenvectors are not returned;
* 1, the eigenvectors are returned.
Output parameters:
D - eigenvalues in ascending order.
Array whose index ranges within [0..N-1].
Z - if ZNeeded is equal to:
* 0, Z hasn�t changed;
* 1, Z contains the eigenvectors.
Array whose indexes range within [0..N-1, 0..N-1].
The eigenvectors are stored in the matrix columns.
Result:
True, if the algorithm has converged.
False, if the algorithm hasn't converged (rare case).
Note:
eigenvectors of Hermitian matrix are defined up to multiplication by
a complex number L, such that |L|=1.
-- ALGLIB --
Copyright 2005, 23 March 2007 by Bochkanov Sergey
*************************************************************************/
</div><div style='margin-top: 0; margin-bottom: 0;'><b>bool</b> alglib::hmatrixevd(
complex_2d_array a,
ae_int_t n,
ae_int_t zneeded,
<b>bool</b> isupper,
real_1d_array& d,
complex_2d_array& z);
</div></pre>
<a name='sub_hmatrixevdi'></a><h3 class=pageheader><code>hmatrixevdi</code> function</h3>
<pre class=source>
<div style='color: navy; margin-top: 0; margin-bottom: 0;'>/*************************************************************************
Subroutine for finding the eigenvalues and eigenvectors of a Hermitian
matrix with given indexes by using bisection and inverse iteration methods
Input parameters:
A - Hermitian matrix which is given by its upper or lower
triangular part.
Array whose indexes range within [0..N-1, 0..N-1].
N - size of matrix A.
ZNeeded - flag controlling whether the eigenvectors are needed or
not. If ZNeeded is equal to:
* 0, the eigenvectors are not returned;
* 1, the eigenvectors are returned.
IsUpperA - storage format of matrix A.
I1, I2 - index interval for searching (from I1 to I2).
0 <= I1 <= I2 <= N-1.
Output parameters:
W - array of the eigenvalues found.
Array whose index ranges within [0..I2-I1].
Z - if ZNeeded is equal to:
* 0, Z hasn�t changed;
* 1, Z contains eigenvectors.
Array whose indexes range within [0..N-1, 0..I2-I1].
In that case, the eigenvectors are stored in the matrix
columns.
Result:
True, if successful. W contains the eigenvalues, Z contains the
eigenvectors (if needed).
False, if the bisection method subroutine wasn't able to find the
eigenvalues in the given interval or if the inverse iteration
subroutine wasn't able to find all the corresponding eigenvectors.
In that case, the eigenvalues and eigenvectors are not returned.
Note:
eigen vectors of Hermitian matrix are defined up to multiplication by
a complex number L, such as |L|=1.
-- ALGLIB --
Copyright 07.01.2006, 24.03.2007 by Bochkanov Sergey.
*************************************************************************/
</div><div style='margin-top: 0; margin-bottom: 0;'><b>bool</b> alglib::hmatrixevdi(
complex_2d_array a,
ae_int_t n,
ae_int_t zneeded,
<b>bool</b> isupper,
ae_int_t i1,
ae_int_t i2,
real_1d_array& w,
complex_2d_array& z);
</div></pre>
<a name='sub_hmatrixevdr'></a><h3 class=pageheader><code>hmatrixevdr</code> function</h3>
<pre class=source>
<div style='color: navy; margin-top: 0; margin-bottom: 0;'>/*************************************************************************
Subroutine for finding the eigenvalues (and eigenvectors) of a Hermitian
matrix in a given half-interval (A, B] by using a bisection and inverse
iteration
Input parameters:
A - Hermitian matrix which is given by its upper or lower
triangular part. Array whose indexes range within
[0..N-1, 0..N-1].
N - size of matrix A.
ZNeeded - flag controlling whether the eigenvectors are needed or
not. If ZNeeded is equal to:
* 0, the eigenvectors are not returned;
* 1, the eigenvectors are returned.
IsUpperA - storage format of matrix A.
B1, B2 - half-interval (B1, B2] to search eigenvalues in.
Output parameters:
M - number of eigenvalues found in a given half-interval, M>=0
W - array of the eigenvalues found.
Array whose index ranges within [0..M-1].
Z - if ZNeeded is equal to:
* 0, Z hasn�t changed;
* 1, Z contains eigenvectors.
Array whose indexes range within [0..N-1, 0..M-1].
The eigenvectors are stored in the matrix columns.
Result:
True, if successful. M contains the number of eigenvalues in the given
half-interval (could be equal to 0), W contains the eigenvalues,
Z contains the eigenvectors (if needed).
False, if the bisection method subroutine wasn't able to find the
eigenvalues in the given interval or if the inverse iteration
subroutine wasn't able to find all the corresponding eigenvectors.
In that case, the eigenvalues and eigenvectors are not returned, M is
equal to 0.
Note:
eigen vectors of Hermitian matrix are defined up to multiplication by
a complex number L, such as |L|=1.
-- ALGLIB --
Copyright 07.01.2006, 24.03.2007 by Bochkanov Sergey.
*************************************************************************/
</div><div style='margin-top: 0; margin-bottom: 0;'><b>bool</b> alglib::hmatrixevdr(
complex_2d_array a,
ae_int_t n,
ae_int_t zneeded,
<b>bool</b> isupper,
<b>double</b> b1,
<b>double</b> b2,
ae_int_t& m,
real_1d_array& w,
complex_2d_array& z);
</div></pre>
<a name='sub_rmatrixevd'></a><h3 class=pageheader><code>rmatrixevd</code> function</h3>
<pre class=source>
<div style='color: navy; margin-top: 0; margin-bottom: 0;'>/*************************************************************************
Finding eigenvalues and eigenvectors of a general (unsymmetric) matrix
COMMERCIAL EDITION OF ALGLIB:
! Commercial version of ALGLIB includes one important improvement of
! this function, which can be used from C++ and C#:
! * Intel MKL support (lightweight Intel MKL is shipped with ALGLIB)
!
! Intel MKL gives approximately constant (with respect to number of
! worker threads) acceleration factor which depends on CPU being used,
! problem size and "baseline" ALGLIB edition which is used for
! comparison. Speed-up provided by MKL for this particular problem (EVD)
! is really high, because MKL uses combination of (a) better low-level
! optimizations, and (b) better EVD algorithms.
!
! On one particular SSE-capable machine for N=1024, commercial MKL-
! -capable ALGLIB was:
! * 7-10 times faster than open source "generic C" version
! * 15-18 times faster than "pure C#" version
!
! Multithreaded acceleration is NOT supported for this function.
!
! We recommend you to read 'Working with commercial version' section of
! ALGLIB Reference Manual in order to find out how to use performance-
! related features provided by commercial edition of ALGLIB.
The algorithm finds eigenvalues and eigenvectors of a general matrix by
using the QR algorithm with multiple shifts. The algorithm can find
eigenvalues and both left and right eigenvectors.
The right eigenvector is a vector x such that A*x = w*x, and the left
eigenvector is a vector y such that y'*A = w*y' (here y' implies a complex
conjugate transposition of vector y).
Input parameters:
A - matrix. Array whose indexes range within [0..N-1, 0..N-1].
N - size of matrix A.
VNeeded - flag controlling whether eigenvectors are needed or not.
If VNeeded is equal to:
* 0, eigenvectors are not returned;
* 1, right eigenvectors are returned;
* 2, left eigenvectors are returned;
* 3, both left and right eigenvectors are returned.
Output parameters:
WR - real parts of eigenvalues.
Array whose index ranges within [0..N-1].
WR - imaginary parts of eigenvalues.
Array whose index ranges within [0..N-1].
VL, VR - arrays of left and right eigenvectors (if they are needed).
If WI[i]=0, the respective eigenvalue is a real number,
and it corresponds to the column number I of matrices VL/VR.
If WI[i]>0, we have a pair of complex conjugate numbers with
positive and negative imaginary parts:
the first eigenvalue WR[i] + sqrt(-1)*WI[i];
the second eigenvalue WR[i+1] + sqrt(-1)*WI[i+1];
WI[i]>0
WI[i+1] = -WI[i] < 0
In that case, the eigenvector corresponding to the first
eigenvalue is located in i and i+1 columns of matrices
VL/VR (the column number i contains the real part, and the
column number i+1 contains the imaginary part), and the vector
corresponding to the second eigenvalue is a complex conjugate to
the first vector.
Arrays whose indexes range within [0..N-1, 0..N-1].
Result:
True, if the algorithm has converged.
False, if the algorithm has not converged.
Note 1:
Some users may ask the following question: what if WI[N-1]>0?
WI[N] must contain an eigenvalue which is complex conjugate to the
N-th eigenvalue, but the array has only size N?
The answer is as follows: such a situation cannot occur because the
algorithm finds a pairs of eigenvalues, therefore, if WI[i]>0, I is
strictly less than N-1.
Note 2:
The algorithm performance depends on the value of the internal parameter
NS of the InternalSchurDecomposition subroutine which defines the number
of shifts in the QR algorithm (similarly to the block width in block-matrix
algorithms of linear algebra). If you require maximum performance
on your machine, it is recommended to adjust this parameter manually.
See also the InternalTREVC subroutine.
The algorithm is based on the LAPACK 3.0 library.
*************************************************************************/
</div><div style='margin-top: 0; margin-bottom: 0;'><b>bool</b> alglib::rmatrixevd(
real_2d_array a,
ae_int_t n,
ae_int_t vneeded,
real_1d_array& wr,
real_1d_array& wi,
real_2d_array& vl,
real_2d_array& vr);
</div></pre>
<a name='sub_smatrixevd'></a><h3 class=pageheader><code>smatrixevd</code> function</h3>
<pre class=source>
<div style='color: navy; margin-top: 0; margin-bottom: 0;'>/*************************************************************************
Finding the eigenvalues and eigenvectors of a symmetric matrix
The algorithm finds eigen pairs of a symmetric matrix by reducing it to
tridiagonal form and using the QL/QR algorithm.
COMMERCIAL EDITION OF ALGLIB:
! Commercial version of ALGLIB includes one important improvement of
! this function, which can be used from C++ and C#:
! * Intel MKL support (lightweight Intel MKL is shipped with ALGLIB)
!
! Intel MKL gives approximately constant (with respect to number of
! worker threads) acceleration factor which depends on CPU being used,
! problem size and "baseline" ALGLIB edition which is used for
! comparison.
!
! Generally, commercial ALGLIB is several times faster than open-source
! generic C edition, and many times faster than open-source C# edition.
!
! Multithreaded acceleration is NOT supported for this function.
!
! We recommend you to read 'Working with commercial version' section of
! ALGLIB Reference Manual in order to find out how to use performance-
! related features provided by commercial edition of ALGLIB.
Input parameters:
A - symmetric matrix which is given by its upper or lower
triangular part.
Array whose indexes range within [0..N-1, 0..N-1].
N - size of matrix A.
ZNeeded - flag controlling whether the eigenvectors are needed or not.
If ZNeeded is equal to:
* 0, the eigenvectors are not returned;
* 1, the eigenvectors are returned.
IsUpper - storage format.
Output parameters:
D - eigenvalues in ascending order.
Array whose index ranges within [0..N-1].
Z - if ZNeeded is equal to:
* 0, Z hasn�t changed;
* 1, Z contains the eigenvectors.
Array whose indexes range within [0..N-1, 0..N-1].
The eigenvectors are stored in the matrix columns.
Result:
True, if the algorithm has converged.
False, if the algorithm hasn't converged (rare case).
-- ALGLIB --
Copyright 2005-2008 by Bochkanov Sergey
*************************************************************************/
</div><div style='margin-top: 0; margin-bottom: 0;'><b>bool</b> alglib::smatrixevd(
real_2d_array a,
ae_int_t n,
ae_int_t zneeded,
<b>bool</b> isupper,
real_1d_array& d,
real_2d_array& z);
</div></pre>
<a name='sub_smatrixevdi'></a><h3 class=pageheader><code>smatrixevdi</code> function</h3>
<pre class=source>
<div style='color: navy; margin-top: 0; margin-bottom: 0;'>/*************************************************************************
Subroutine for finding the eigenvalues and eigenvectors of a symmetric
matrix with given indexes by using bisection and inverse iteration methods.
Input parameters:
A - symmetric matrix which is given by its upper or lower
triangular part. Array whose indexes range within [0..N-1, 0..N-1].
N - size of matrix A.
ZNeeded - flag controlling whether the eigenvectors are needed or not.
If ZNeeded is equal to:
* 0, the eigenvectors are not returned;
* 1, the eigenvectors are returned.
IsUpperA - storage format of matrix A.
I1, I2 - index interval for searching (from I1 to I2).
0 <= I1 <= I2 <= N-1.
Output parameters:
W - array of the eigenvalues found.
Array whose index ranges within [0..I2-I1].
Z - if ZNeeded is equal to:
* 0, Z hasn�t changed;
* 1, Z contains eigenvectors.
Array whose indexes range within [0..N-1, 0..I2-I1].
In that case, the eigenvectors are stored in the matrix columns.
Result:
True, if successful. W contains the eigenvalues, Z contains the
eigenvectors (if needed).
False, if the bisection method subroutine wasn't able to find the
eigenvalues in the given interval or if the inverse iteration subroutine
wasn't able to find all the corresponding eigenvectors.
In that case, the eigenvalues and eigenvectors are not returned.
-- ALGLIB --
Copyright 07.01.2006 by Bochkanov Sergey
*************************************************************************/
</div><div style='margin-top: 0; margin-bottom: 0;'><b>bool</b> alglib::smatrixevdi(
real_2d_array a,
ae_int_t n,
ae_int_t zneeded,
<b>bool</b> isupper,
ae_int_t i1,
ae_int_t i2,
real_1d_array& w,
real_2d_array& z);
</div></pre>
<a name='sub_smatrixevdr'></a><h3 class=pageheader><code>smatrixevdr</code> function</h3>
<pre class=source>
<div style='color: navy; margin-top: 0; margin-bottom: 0;'>/*************************************************************************
Subroutine for finding the eigenvalues (and eigenvectors) of a symmetric
matrix in a given half open interval (A, B] by using a bisection and
inverse iteration
Input parameters:
A - symmetric matrix which is given by its upper or lower
triangular part. Array [0..N-1, 0..N-1].
N - size of matrix A.
ZNeeded - flag controlling whether the eigenvectors are needed or not.
If ZNeeded is equal to:
* 0, the eigenvectors are not returned;
* 1, the eigenvectors are returned.
IsUpperA - storage format of matrix A.
B1, B2 - half open interval (B1, B2] to search eigenvalues in.
Output parameters:
M - number of eigenvalues found in a given half-interval (M>=0).
W - array of the eigenvalues found.
Array whose index ranges within [0..M-1].
Z - if ZNeeded is equal to:
* 0, Z hasn�t changed;
* 1, Z contains eigenvectors.
Array whose indexes range within [0..N-1, 0..M-1].
The eigenvectors are stored in the matrix columns.
Result:
True, if successful. M contains the number of eigenvalues in the given
half-interval (could be equal to 0), W contains the eigenvalues,
Z contains the eigenvectors (if needed).
False, if the bisection method subroutine wasn't able to find the
eigenvalues in the given interval or if the inverse iteration subroutine
wasn't able to find all the corresponding eigenvectors.
In that case, the eigenvalues and eigenvectors are not returned,
M is equal to 0.
-- ALGLIB --
Copyright 07.01.2006 by Bochkanov Sergey
*************************************************************************/
</div><div style='margin-top: 0; margin-bottom: 0;'><b>bool</b> alglib::smatrixevdr(
real_2d_array a,
ae_int_t n,
ae_int_t zneeded,
<b>bool</b> isupper,
<b>double</b> b1,
<b>double</b> b2,
ae_int_t& m,
real_1d_array& w,
real_2d_array& z);
</div></pre>
<a name='sub_smatrixtdevd'></a><h3 class=pageheader><code>smatrixtdevd</code> function</h3>
<pre class=source>
<div style='color: navy; margin-top: 0; margin-bottom: 0;'>/*************************************************************************
Finding the eigenvalues and eigenvectors of a tridiagonal symmetric matrix
The algorithm finds the eigen pairs of a tridiagonal symmetric matrix by
using an QL/QR algorithm with implicit shifts.
COMMERCIAL EDITION OF ALGLIB:
! Commercial version of ALGLIB includes one important improvement of
! this function, which can be used from C++ and C#:
! * Intel MKL support (lightweight Intel MKL is shipped with ALGLIB)
!
! Intel MKL gives approximately constant (with respect to number of
! worker threads) acceleration factor which depends on CPU being used,
! problem size and "baseline" ALGLIB edition which is used for
! comparison.
!
! Generally, commercial ALGLIB is several times faster than open-source
! generic C edition, and many times faster than open-source C# edition.
!
! Multithreaded acceleration is NOT supported for this function.
!
! We recommend you to read 'Working with commercial version' section of
! ALGLIB Reference Manual in order to find out how to use performance-
! related features provided by commercial edition of ALGLIB.
Input parameters:
D - the main diagonal of a tridiagonal matrix.
Array whose index ranges within [0..N-1].
E - the secondary diagonal of a tridiagonal matrix.
Array whose index ranges within [0..N-2].
N - size of matrix A.
ZNeeded - flag controlling whether the eigenvectors are needed or not.
If ZNeeded is equal to:
* 0, the eigenvectors are not needed;
* 1, the eigenvectors of a tridiagonal matrix
are multiplied by the square matrix Z. It is used if the
tridiagonal matrix is obtained by the similarity
transformation of a symmetric matrix;
* 2, the eigenvectors of a tridiagonal matrix replace the
square matrix Z;
* 3, matrix Z contains the first row of the eigenvectors
matrix.
Z - if ZNeeded=1, Z contains the square matrix by which the
eigenvectors are multiplied.
Array whose indexes range within [0..N-1, 0..N-1].
Output parameters:
D - eigenvalues in ascending order.
Array whose index ranges within [0..N-1].
Z - if ZNeeded is equal to:
* 0, Z hasn�t changed;
* 1, Z contains the product of a given matrix (from the left)
and the eigenvectors matrix (from the right);
* 2, Z contains the eigenvectors.
* 3, Z contains the first row of the eigenvectors matrix.
If ZNeeded<3, Z is the array whose indexes range within [0..N-1, 0..N-1].
In that case, the eigenvectors are stored in the matrix columns.
If ZNeeded=3, Z is the array whose indexes range within [0..0, 0..N-1].
Result:
True, if the algorithm has converged.
False, if the algorithm hasn't converged.
-- LAPACK routine (version 3.0) --
Univ. of Tennessee, Univ. of California Berkeley, NAG Ltd.,
Courant Institute, Argonne National Lab, and Rice University
September 30, 1994
*************************************************************************/
</div><div style='margin-top: 0; margin-bottom: 0;'><b>bool</b> alglib::smatrixtdevd(
real_1d_array& d,
real_1d_array e,
ae_int_t n,
ae_int_t zneeded,
real_2d_array& z);
</div></pre>
<a name='sub_smatrixtdevdi'></a><h3 class=pageheader><code>smatrixtdevdi</code> function</h3>
<pre class=source>
<div style='color: navy; margin-top: 0; margin-bottom: 0;'>/*************************************************************************
Subroutine for finding tridiagonal matrix eigenvalues/vectors with given
indexes (in ascending order) by using the bisection and inverse iteraion.
Input parameters:
D - the main diagonal of a tridiagonal matrix.
Array whose index ranges within [0..N-1].
E - the secondary diagonal of a tridiagonal matrix.
Array whose index ranges within [0..N-2].
N - size of matrix. N>=0.
ZNeeded - flag controlling whether the eigenvectors are needed or not.
If ZNeeded is equal to:
* 0, the eigenvectors are not needed;
* 1, the eigenvectors of a tridiagonal matrix are multiplied
by the square matrix Z. It is used if the
tridiagonal matrix is obtained by the similarity transformation
of a symmetric matrix.
* 2, the eigenvectors of a tridiagonal matrix replace
matrix Z.
I1, I2 - index interval for searching (from I1 to I2).
0 <= I1 <= I2 <= N-1.
Z - if ZNeeded is equal to:
* 0, Z isn't used and remains unchanged;
* 1, Z contains the square matrix (array whose indexes range within [0..N-1, 0..N-1])
which reduces the given symmetric matrix to tridiagonal form;
* 2, Z isn't used (but changed on the exit).
Output parameters:
D - array of the eigenvalues found.
Array whose index ranges within [0..I2-I1].
Z - if ZNeeded is equal to:
* 0, doesn't contain any information;
* 1, contains the product of a given NxN matrix Z (from the left) and
Nx(I2-I1) matrix of the eigenvectors found (from the right).
Array whose indexes range within [0..N-1, 0..I2-I1].
* 2, contains the matrix of the eigenvalues found.
Array whose indexes range within [0..N-1, 0..I2-I1].
Result:
True, if successful. In that case, D contains the eigenvalues,
Z contains the eigenvectors (if needed).
It should be noted that the subroutine changes the size of arrays D and Z.
False, if the bisection method subroutine wasn't able to find the eigenvalues
in the given interval or if the inverse iteration subroutine wasn't able
to find all the corresponding eigenvectors. In that case, the eigenvalues
and eigenvectors are not returned.
-- ALGLIB --
Copyright 25.12.2005 by Bochkanov Sergey
*************************************************************************/
</div><div style='margin-top: 0; margin-bottom: 0;'><b>bool</b> alglib::smatrixtdevdi(
real_1d_array& d,
real_1d_array e,
ae_int_t n,
ae_int_t zneeded,
ae_int_t i1,
ae_int_t i2,
real_2d_array& z);
</div></pre>
<a name='sub_smatrixtdevdr'></a><h3 class=pageheader><code>smatrixtdevdr</code> function</h3>
<pre class=source>
<div style='color: navy; margin-top: 0; margin-bottom: 0;'>/*************************************************************************
Subroutine for finding the tridiagonal matrix eigenvalues/vectors in a
given half-interval (A, B] by using bisection and inverse iteration.
Input parameters:
D - the main diagonal of a tridiagonal matrix.
Array whose index ranges within [0..N-1].
E - the secondary diagonal of a tridiagonal matrix.
Array whose index ranges within [0..N-2].
N - size of matrix, N>=0.
ZNeeded - flag controlling whether the eigenvectors are needed or not.
If ZNeeded is equal to:
* 0, the eigenvectors are not needed;
* 1, the eigenvectors of a tridiagonal matrix are multiplied
by the square matrix Z. It is used if the tridiagonal
matrix is obtained by the similarity transformation
of a symmetric matrix.
* 2, the eigenvectors of a tridiagonal matrix replace matrix Z.
A, B - half-interval (A, B] to search eigenvalues in.
Z - if ZNeeded is equal to:
* 0, Z isn't used and remains unchanged;
* 1, Z contains the square matrix (array whose indexes range
within [0..N-1, 0..N-1]) which reduces the given symmetric
matrix to tridiagonal form;
* 2, Z isn't used (but changed on the exit).
Output parameters:
D - array of the eigenvalues found.
Array whose index ranges within [0..M-1].
M - number of eigenvalues found in the given half-interval (M>=0).
Z - if ZNeeded is equal to:
* 0, doesn't contain any information;
* 1, contains the product of a given NxN matrix Z (from the
left) and NxM matrix of the eigenvectors found (from the
right). Array whose indexes range within [0..N-1, 0..M-1].
* 2, contains the matrix of the eigenvectors found.
Array whose indexes range within [0..N-1, 0..M-1].
Result:
True, if successful. In that case, M contains the number of eigenvalues
in the given half-interval (could be equal to 0), D contains the eigenvalues,
Z contains the eigenvectors (if needed).
It should be noted that the subroutine changes the size of arrays D and Z.
False, if the bisection method subroutine wasn't able to find the
eigenvalues in the given interval or if the inverse iteration subroutine
wasn't able to find all the corresponding eigenvectors. In that case,
the eigenvalues and eigenvectors are not returned, M is equal to 0.
-- ALGLIB --
Copyright 31.03.2008 by Bochkanov Sergey
*************************************************************************/
</div><div style='margin-top: 0; margin-bottom: 0;'><b>bool</b> alglib::smatrixtdevdr(
real_1d_array& d,
real_1d_array e,
ae_int_t n,
ae_int_t zneeded,
<b>double</b> a,
<b>double</b> b,
ae_int_t& m,
real_2d_array& z);
</div></pre>
<a name=unit_expintegrals></a><h2 class=pageheader><code>expintegrals</code> subpackage</h2>
<div class=pagecontent>
<h3 class=pageheader>Functions</h3>
<a href='#sub_exponentialintegralei' class=toc>exponentialintegralei</a><br>
<a href='#sub_exponentialintegralen' class=toc>exponentialintegralen</a><br>
<h3 class=pageheader>Examples</h3>
<table border=0 cellspacing=0 class='pagecontent'>
</table></div>
<a name='sub_exponentialintegralei'></a><h3 class=pageheader><code>exponentialintegralei</code> function</h3>
<pre class=source>
<div style='color: navy; margin-top: 0; margin-bottom: 0;'>/*************************************************************************
Exponential integral Ei(x)
x
- t
| | e
Ei(x) = -|- --- dt .
| | t
-
-inf
Not defined for x <= 0.
See also expn.c.
ACCURACY:
Relative error:
arithmetic domain # trials peak rms
IEEE 0,100 50000 8.6e-16 1.3e-16
Cephes Math Library Release 2.8: May, 1999
Copyright 1999 by Stephen L. Moshier
*************************************************************************/
</div><div style='margin-top: 0; margin-bottom: 0;'><b>double</b> alglib::exponentialintegralei(<b>double</b> x);
</div></pre>
<a name='sub_exponentialintegralen'></a><h3 class=pageheader><code>exponentialintegralen</code> function</h3>
<pre class=source>
<div style='color: navy; margin-top: 0; margin-bottom: 0;'>/*************************************************************************
Exponential integral En(x)
Evaluates the exponential integral
inf.
-
| | -xt
| e
E (x) = | ---- dt.
n | n
| | t
-
1
Both n and x must be nonnegative.
The routine employs either a power series, a continued
fraction, or an asymptotic formula depending on the
relative values of n and x.
ACCURACY:
Relative error:
arithmetic domain # trials peak rms
IEEE 0, 30 10000 1.7e-15 3.6e-16
Cephes Math Library Release 2.8: June, 2000
Copyright 1985, 2000 by Stephen L. Moshier
*************************************************************************/
</div><div style='margin-top: 0; margin-bottom: 0;'><b>double</b> alglib::exponentialintegralen(<b>double</b> x, ae_int_t n);
</div></pre>
<a name=unit_fdistr></a><h2 class=pageheader><code>fdistr</code> subpackage</h2>
<div class=pagecontent>
<h3 class=pageheader>Functions</h3>
<a href='#sub_fcdistribution' class=toc>fcdistribution</a><br>
<a href='#sub_fdistribution' class=toc>fdistribution</a><br>
<a href='#sub_invfdistribution' class=toc>invfdistribution</a><br>
<h3 class=pageheader>Examples</h3>
<table border=0 cellspacing=0 class='pagecontent'>
</table></div>
<a name='sub_fcdistribution'></a><h3 class=pageheader><code>fcdistribution</code> function</h3>
<pre class=source>
<div style='color: navy; margin-top: 0; margin-bottom: 0;'>/*************************************************************************
Complemented F distribution
Returns the area from x to infinity under the F density
function (also known as Snedcor's density or the
variance ratio density).
inf.
-
1 | | a-1 b-1
1-P(x) = ------ | t (1-t) dt
B(a,b) | |
-
x
The incomplete beta integral is used, according to the
formula
P(x) = incbet( df2/2, df1/2, (df2/(df2 + df1*x) ).
ACCURACY:
Tested at random points (a,b,x) in the indicated intervals.
x a,b Relative error:
arithmetic domain domain # trials peak rms
IEEE 0,1 1,100 100000 3.7e-14 5.9e-16
IEEE 1,5 1,100 100000 8.0e-15 1.6e-15
IEEE 0,1 1,10000 100000 1.8e-11 3.5e-13
IEEE 1,5 1,10000 100000 2.0e-11 3.0e-12
Cephes Math Library Release 2.8: June, 2000
Copyright 1984, 1987, 1995, 2000 by Stephen L. Moshier
*************************************************************************/
</div><div style='margin-top: 0; margin-bottom: 0;'><b>double</b> alglib::fcdistribution(ae_int_t a, ae_int_t b, <b>double</b> x);
</div></pre>
<a name='sub_fdistribution'></a><h3 class=pageheader><code>fdistribution</code> function</h3>
<pre class=source>
<div style='color: navy; margin-top: 0; margin-bottom: 0;'>/*************************************************************************
F distribution
Returns the area from zero to x under the F density
function (also known as Snedcor's density or the
variance ratio density). This is the density
of x = (u1/df1)/(u2/df2), where u1 and u2 are random
variables having Chi square distributions with df1
and df2 degrees of freedom, respectively.
The incomplete beta integral is used, according to the
formula
P(x) = incbet( df1/2, df2/2, (df1*x/(df2 + df1*x) ).
The arguments a and b are greater than zero, and x is
nonnegative.
ACCURACY:
Tested at random points (a,b,x).
x a,b Relative error:
arithmetic domain domain # trials peak rms
IEEE 0,1 0,100 100000 9.8e-15 1.7e-15
IEEE 1,5 0,100 100000 6.5e-15 3.5e-16
IEEE 0,1 1,10000 100000 2.2e-11 3.3e-12
IEEE 1,5 1,10000 100000 1.1e-11 1.7e-13
Cephes Math Library Release 2.8: June, 2000
Copyright 1984, 1987, 1995, 2000 by Stephen L. Moshier
*************************************************************************/
</div><div style='margin-top: 0; margin-bottom: 0;'><b>double</b> alglib::fdistribution(ae_int_t a, ae_int_t b, <b>double</b> x);
</div></pre>
<a name='sub_invfdistribution'></a><h3 class=pageheader><code>invfdistribution</code> function</h3>
<pre class=source>
<div style='color: navy; margin-top: 0; margin-bottom: 0;'>/*************************************************************************
Inverse of complemented F distribution
Finds the F density argument x such that the integral
from x to infinity of the F density is equal to the
given probability p.
This is accomplished using the inverse beta integral
function and the relations
z = incbi( df2/2, df1/2, p )
x = df2 (1-z) / (df1 z).
Note: the following relations hold for the inverse of
the uncomplemented F distribution:
z = incbi( df1/2, df2/2, p )
x = df2 z / (df1 (1-z)).
ACCURACY:
Tested at random points (a,b,p).
a,b Relative error:
arithmetic domain # trials peak rms
For p between .001 and 1:
IEEE 1,100 100000 8.3e-15 4.7e-16
IEEE 1,10000 100000 2.1e-11 1.4e-13
For p between 10^-6 and 10^-3:
IEEE 1,100 50000 1.3e-12 8.4e-15
IEEE 1,10000 50000 3.0e-12 4.8e-14
Cephes Math Library Release 2.8: June, 2000
Copyright 1984, 1987, 1995, 2000 by Stephen L. Moshier
*************************************************************************/
</div><div style='margin-top: 0; margin-bottom: 0;'><b>double</b> alglib::invfdistribution(ae_int_t a, ae_int_t b, <b>double</b> y);
</div></pre>
<a name=unit_fft></a><h2 class=pageheader><code>fft</code> subpackage</h2>
<div class=pagecontent>
<h3 class=pageheader>Functions</h3>
<a href='#sub_fftc1d' class=toc>fftc1d</a><br>
<a href='#sub_fftc1dinv' class=toc>fftc1dinv</a><br>
<a href='#sub_fftr1d' class=toc>fftr1d</a><br>
<a href='#sub_fftr1dinv' class=toc>fftr1dinv</a><br>
<h3 class=pageheader>Examples</h3>
<table border=0 cellspacing=0 class='pagecontent'>
<tr align=left valign=top><td><a href='#example_fft_complex_d1' class=toc>fft_complex_d1</a></td><td width=15> </td><td>Complex FFT: simple example</td></tr>
<tr align=left valign=top><td><a href='#example_fft_complex_d2' class=toc>fft_complex_d2</a></td><td width=15> </td><td>Complex FFT: advanced example</td></tr>
<tr align=left valign=top><td><a href='#example_fft_real_d1' class=toc>fft_real_d1</a></td><td width=15> </td><td>Real FFT: simple example</td></tr>
<tr align=left valign=top><td><a href='#example_fft_real_d2' class=toc>fft_real_d2</a></td><td width=15> </td><td>Real FFT: advanced example</td></tr>
</table></div>
<a name='sub_fftc1d'></a><h3 class=pageheader><code>fftc1d</code> function</h3>
<pre class=source>
<div style='color: navy; margin-top: 0; margin-bottom: 0;'>/*************************************************************************
1-dimensional complex FFT.
Array size N may be arbitrary number (composite or prime). Composite N's
are handled with cache-oblivious variation of a Cooley-Tukey algorithm.
Small prime-factors are transformed using hard coded codelets (similar to
FFTW codelets, but without low-level optimization), large prime-factors
are handled with Bluestein's algorithm.
Fastests transforms are for smooth N's (prime factors are 2, 3, 5 only),
most fast for powers of 2. When N have prime factors larger than these,
but orders of magnitude smaller than N, computations will be about 4 times
slower than for nearby highly composite N's. When N itself is prime, speed
will be 6 times lower.
Algorithm has O(N*logN) complexity for any N (composite or prime).
INPUT PARAMETERS
A - array[0..N-1] - complex function to be transformed
N - problem size
OUTPUT PARAMETERS
A - DFT of a input array, array[0..N-1]
A_out[j] = SUM(A_in[k]*exp(-2*pi*sqrt(-1)*j*k/N), k = 0..N-1)
-- ALGLIB --
Copyright 29.05.2009 by Bochkanov Sergey
*************************************************************************/
</div><div style='margin-top: 0; margin-bottom: 0;'><b>void</b> alglib::fftc1d(complex_1d_array& a);
<b>void</b> alglib::fftc1d(complex_1d_array& a, ae_int_t n);
</div></pre>
<p align=left class=pagecontent><span class=inlineheader>Examples:</span> <a href='#example_fft_complex_d1' class=nav>[1]</a> <a href='#example_fft_complex_d2' class=nav>[2]</a> </p>
<a name='sub_fftc1dinv'></a><h3 class=pageheader><code>fftc1dinv</code> function</h3>
<pre class=source>
<div style='color: navy; margin-top: 0; margin-bottom: 0;'>/*************************************************************************
1-dimensional complex inverse FFT.
Array size N may be arbitrary number (composite or prime). Algorithm has
O(N*logN) complexity for any N (composite or prime).
See FFTC1D() description for more information about algorithm performance.
INPUT PARAMETERS
A - array[0..N-1] - complex array to be transformed
N - problem size
OUTPUT PARAMETERS
A - inverse DFT of a input array, array[0..N-1]
A_out[j] = SUM(A_in[k]/N*exp(+2*pi*sqrt(-1)*j*k/N), k = 0..N-1)
-- ALGLIB --
Copyright 29.05.2009 by Bochkanov Sergey
*************************************************************************/
</div><div style='margin-top: 0; margin-bottom: 0;'><b>void</b> alglib::fftc1dinv(complex_1d_array& a);
<b>void</b> alglib::fftc1dinv(complex_1d_array& a, ae_int_t n);
</div></pre>
<p align=left class=pagecontent><span class=inlineheader>Examples:</span> <a href='#example_fft_complex_d1' class=nav>[1]</a> <a href='#example_fft_complex_d2' class=nav>[2]</a> </p>
<a name='sub_fftr1d'></a><h3 class=pageheader><code>fftr1d</code> function</h3>
<pre class=source>
<div style='color: navy; margin-top: 0; margin-bottom: 0;'>/*************************************************************************
1-dimensional real FFT.
Algorithm has O(N*logN) complexity for any N (composite or prime).
INPUT PARAMETERS
A - array[0..N-1] - real function to be transformed
N - problem size
OUTPUT PARAMETERS
F - DFT of a input array, array[0..N-1]
F[j] = SUM(A[k]*exp(-2*pi*sqrt(-1)*j*k/N), k = 0..N-1)
NOTE:
F[] satisfies symmetry property F[k] = conj(F[N-k]), so just one half
of array is usually needed. But for convinience subroutine returns full
complex array (with frequencies above N/2), so its result may be used by
other FFT-related subroutines.
-- ALGLIB --
Copyright 01.06.2009 by Bochkanov Sergey
*************************************************************************/
</div><div style='margin-top: 0; margin-bottom: 0;'><b>void</b> alglib::fftr1d(real_1d_array a, complex_1d_array& f);
<b>void</b> alglib::fftr1d(real_1d_array a, ae_int_t n, complex_1d_array& f);
</div></pre>
<p align=left class=pagecontent><span class=inlineheader>Examples:</span> <a href='#example_fft_real_d1' class=nav>[1]</a> <a href='#example_fft_real_d2' class=nav>[2]</a> </p>
<a name='sub_fftr1dinv'></a><h3 class=pageheader><code>fftr1dinv</code> function</h3>
<pre class=source>
<div style='color: navy; margin-top: 0; margin-bottom: 0;'>/*************************************************************************
1-dimensional real inverse FFT.
Algorithm has O(N*logN) complexity for any N (composite or prime).
INPUT PARAMETERS
F - array[0..floor(N/2)] - frequencies from forward real FFT
N - problem size
OUTPUT PARAMETERS
A - inverse DFT of a input array, array[0..N-1]
NOTE:
F[] should satisfy symmetry property F[k] = conj(F[N-k]), so just one
half of frequencies array is needed - elements from 0 to floor(N/2). F[0]
is ALWAYS real. If N is even F[floor(N/2)] is real too. If N is odd, then
F[floor(N/2)] has no special properties.
Relying on properties noted above, FFTR1DInv subroutine uses only elements
from 0th to floor(N/2)-th. It ignores imaginary part of F[0], and in case
N is even it ignores imaginary part of F[floor(N/2)] too.
When you call this function using full arguments list - "FFTR1DInv(F,N,A)"
- you can pass either either frequencies array with N elements or reduced
array with roughly N/2 elements - subroutine will successfully transform
both.
If you call this function using reduced arguments list - "FFTR1DInv(F,A)"
- you must pass FULL array with N elements (although higher N/2 are still
not used) because array size is used to automatically determine FFT length
-- ALGLIB --
Copyright 01.06.2009 by Bochkanov Sergey
*************************************************************************/
</div><div style='margin-top: 0; margin-bottom: 0;'><b>void</b> alglib::fftr1dinv(complex_1d_array f, real_1d_array& a);
<b>void</b> alglib::fftr1dinv(complex_1d_array f, ae_int_t n, real_1d_array& a);
</div></pre>
<p align=left class=pagecontent><span class=inlineheader>Examples:</span> <a href='#example_fft_real_d1' class=nav>[1]</a> <a href='#example_fft_real_d2' class=nav>[2]</a> </p>
<a name='example_fft_complex_d1'></a><h3 class=pageheader>fft_complex_d1 example</h3>
<pre class=source>
#include <font color=blue><b>"stdafx.h"</b></font>
#include <stdlib.h>
#include <stdio.h>
#include <math.h>
#include <font color=blue><b>"fasttransforms.h"</b></font>
using namespace alglib;
<b>int</b> main(<b>int</b> argc, char **argv)
{
<font color=navy>//</font>
<font color=navy>// first we demonstrate forward FFT:</font>
<font color=navy>// [1i,1i,1i,1i] is converted to [4i, 0, 0, 0]</font>
<font color=navy>//</font>
complex_1d_array z = <font color=blue><b>"[1i,1i,1i,1i]"</b></font>;
fftc1d(z);
printf(<font color=blue><b>"%s\n"</b></font>, z.tostring(3).c_str()); <font color=navy>// EXPECTED: [4i,0,0,0]</font>
<font color=navy>//</font>
<font color=navy>// now we convert [4i, 0, 0, 0] back to [1i,1i,1i,1i]</font>
<font color=navy>// with backward FFT</font>
<font color=navy>//</font>
fftc1dinv(z);
printf(<font color=blue><b>"%s\n"</b></font>, z.tostring(3).c_str()); <font color=navy>// EXPECTED: [1i,1i,1i,1i]</font>
<b>return</b> 0;
}
</pre><a name='example_fft_complex_d2'></a><h3 class=pageheader>fft_complex_d2 example</h3>
<pre class=source>
#include <font color=blue><b>"stdafx.h"</b></font>
#include <stdlib.h>
#include <stdio.h>
#include <math.h>
#include <font color=blue><b>"fasttransforms.h"</b></font>
using namespace alglib;
<b>int</b> main(<b>int</b> argc, char **argv)
{
<font color=navy>//</font>
<font color=navy>// first we demonstrate forward FFT:</font>
<font color=navy>// [0,1,0,1i] is converted to [1+1i, -1-1i, -1-1i, 1+1i]</font>
<font color=navy>//</font>
complex_1d_array z = <font color=blue><b>"[0,1,0,1i]"</b></font>;
fftc1d(z);
printf(<font color=blue><b>"%s\n"</b></font>, z.tostring(3).c_str()); <font color=navy>// EXPECTED: [1+1i, -1-1i, -1-1i, 1+1i]</font>
<font color=navy>//</font>
<font color=navy>// now we convert result back with backward FFT</font>
<font color=navy>//</font>
fftc1dinv(z);
printf(<font color=blue><b>"%s\n"</b></font>, z.tostring(3).c_str()); <font color=navy>// EXPECTED: [0,1,0,1i]</font>
<b>return</b> 0;
}
</pre><a name='example_fft_real_d1'></a><h3 class=pageheader>fft_real_d1 example</h3>
<pre class=source>
#include <font color=blue><b>"stdafx.h"</b></font>
#include <stdlib.h>
#include <stdio.h>
#include <math.h>
#include <font color=blue><b>"fasttransforms.h"</b></font>
using namespace alglib;
<b>int</b> main(<b>int</b> argc, char **argv)
{
<font color=navy>//</font>
<font color=navy>// first we demonstrate forward FFT:</font>
<font color=navy>// [1,1,1,1] is converted to [4, 0, 0, 0]</font>
<font color=navy>//</font>
real_1d_array x = <font color=blue><b>"[1,1,1,1]"</b></font>;
complex_1d_array f;
real_1d_array x2;
fftr1d(x, f);
printf(<font color=blue><b>"%s\n"</b></font>, f.tostring(3).c_str()); <font color=navy>// EXPECTED: [4,0,0,0]</font>
<font color=navy>//</font>
<font color=navy>// now we convert [4, 0, 0, 0] back to [1,1,1,1]</font>
<font color=navy>// with backward FFT</font>
<font color=navy>//</font>
fftr1dinv(f, x2);
printf(<font color=blue><b>"%s\n"</b></font>, x2.tostring(3).c_str()); <font color=navy>// EXPECTED: [1,1,1,1]</font>
<b>return</b> 0;
}
</pre><a name='example_fft_real_d2'></a><h3 class=pageheader>fft_real_d2 example</h3>
<pre class=source>
#include <font color=blue><b>"stdafx.h"</b></font>
#include <stdlib.h>
#include <stdio.h>
#include <math.h>
#include <font color=blue><b>"fasttransforms.h"</b></font>
using namespace alglib;
<b>int</b> main(<b>int</b> argc, char **argv)
{
<font color=navy>//</font>
<font color=navy>// first we demonstrate forward FFT:</font>
<font color=navy>// [1,2,3,4] is converted to [10, -2+2i, -2, -2-2i]</font>
<font color=navy>//</font>
<font color=navy>// note that output array is self-adjoint:</font>
<font color=navy>// * f[0] = conj(f[0])</font>
<font color=navy>// * f[1] = conj(f[3])</font>
<font color=navy>// * f[2] = conj(f[2])</font>
<font color=navy>//</font>
real_1d_array x = <font color=blue><b>"[1,2,3,4]"</b></font>;
complex_1d_array f;
real_1d_array x2;
fftr1d(x, f);
printf(<font color=blue><b>"%s\n"</b></font>, f.tostring(3).c_str()); <font color=navy>// EXPECTED: [10, -2+2i, -2, -2-2i]</font>
<font color=navy>//</font>
<font color=navy>// now we convert [10, -2+2i, -2, -2-2i] back to [1,2,3,4]</font>
<font color=navy>//</font>
fftr1dinv(f, x2);
printf(<font color=blue><b>"%s\n"</b></font>, x2.tostring(3).c_str()); <font color=navy>// EXPECTED: [1,2,3,4]</font>
<font color=navy>//</font>
<font color=navy>// remember that F is self-adjoint? It means that we can pass just half</font>
<font color=navy>// (slightly larger than half) of F to inverse real FFT and still get our result.</font>
<font color=navy>//</font>
<font color=navy>// I.e. instead [10, -2+2i, -2, -2-2i] we pass just [10, -2+2i, -2] and everything works!</font>
<font color=navy>//</font>
<font color=navy>// NOTE: in this case we should explicitly pass array length (which is 4) to ALGLIB;</font>
<font color=navy>// <b>if</b> not, it will automatically use array length to determine FFT size and</font>
<font color=navy>// will erroneously make half-length FFT.</font>
<font color=navy>//</font>
f = <font color=blue><b>"[10, -2+2i, -2]"</b></font>;
fftr1dinv(f, 4, x2);
printf(<font color=blue><b>"%s\n"</b></font>, x2.tostring(3).c_str()); <font color=navy>// EXPECTED: [1,2,3,4]</font>
<b>return</b> 0;
}
</pre><a name=unit_fht></a><h2 class=pageheader><code>fht</code> subpackage</h2>
<div class=pagecontent>
<h3 class=pageheader>Functions</h3>
<a href='#sub_fhtr1d' class=toc>fhtr1d</a><br>
<a href='#sub_fhtr1dinv' class=toc>fhtr1dinv</a><br>
<h3 class=pageheader>Examples</h3>
<table border=0 cellspacing=0 class='pagecontent'>
</table></div>
<a name='sub_fhtr1d'></a><h3 class=pageheader><code>fhtr1d</code> function</h3>
<pre class=source>
<div style='color: navy; margin-top: 0; margin-bottom: 0;'>/*************************************************************************
1-dimensional Fast Hartley Transform.
Algorithm has O(N*logN) complexity for any N (composite or prime).
INPUT PARAMETERS
A - array[0..N-1] - real function to be transformed
N - problem size
OUTPUT PARAMETERS
A - FHT of a input array, array[0..N-1],
A_out[k] = sum(A_in[j]*(cos(2*pi*j*k/N)+sin(2*pi*j*k/N)), j=0..N-1)
-- ALGLIB --
Copyright 04.06.2009 by Bochkanov Sergey
*************************************************************************/
</div><div style='margin-top: 0; margin-bottom: 0;'><b>void</b> alglib::fhtr1d(real_1d_array& a, ae_int_t n);
</div></pre>
<a name='sub_fhtr1dinv'></a><h3 class=pageheader><code>fhtr1dinv</code> function</h3>
<pre class=source>
<div style='color: navy; margin-top: 0; margin-bottom: 0;'>/*************************************************************************
1-dimensional inverse FHT.
Algorithm has O(N*logN) complexity for any N (composite or prime).
INPUT PARAMETERS
A - array[0..N-1] - complex array to be transformed
N - problem size
OUTPUT PARAMETERS
A - inverse FHT of a input array, array[0..N-1]
-- ALGLIB --
Copyright 29.05.2009 by Bochkanov Sergey
*************************************************************************/
</div><div style='margin-top: 0; margin-bottom: 0;'><b>void</b> alglib::fhtr1dinv(real_1d_array& a, ae_int_t n);
</div></pre>
<a name=unit_filters></a><h2 class=pageheader><code>filters</code> subpackage</h2>
<div class=pagecontent>
<h3 class=pageheader>Functions</h3>
<a href='#sub_filterema' class=toc>filterema</a><br>
<a href='#sub_filterlrma' class=toc>filterlrma</a><br>
<a href='#sub_filtersma' class=toc>filtersma</a><br>
<h3 class=pageheader>Examples</h3>
<table border=0 cellspacing=0 class='pagecontent'>
<tr align=left valign=top><td><a href='#example_filters_d_ema' class=toc>filters_d_ema</a></td><td width=15> </td><td>EMA(alpha) filter</td></tr>
<tr align=left valign=top><td><a href='#example_filters_d_lrma' class=toc>filters_d_lrma</a></td><td width=15> </td><td>LRMA(k) filter</td></tr>
<tr align=left valign=top><td><a href='#example_filters_d_sma' class=toc>filters_d_sma</a></td><td width=15> </td><td>SMA(k) filter</td></tr>
</table></div>
<a name='sub_filterema'></a><h3 class=pageheader><code>filterema</code> function</h3>
<pre class=source>
<div style='color: navy; margin-top: 0; margin-bottom: 0;'>/*************************************************************************
Filters: exponential moving averages.
This filter replaces array by results of EMA(alpha) filter. EMA(alpha) is
defined as filter which replaces X[] by S[]:
S[0] = X[0]
S[t] = alpha*X[t] + (1-alpha)*S[t-1]
INPUT PARAMETERS:
X - array[N], array to process. It can be larger than N,
in this case only first N points are processed.
N - points count, N>=0
alpha - 0<alpha<=1, smoothing parameter.
OUTPUT PARAMETERS:
X - array, whose first N elements were processed
with EMA(alpha)
NOTE 1: this function uses efficient in-place algorithm which does not
allocate temporary arrays.
NOTE 2: this algorithm uses BOTH previous points and current one, i.e.
new value of X[i] depends on BOTH previous point and X[i] itself.
NOTE 3: technical analytis users quite often work with EMA coefficient
expressed in DAYS instead of fractions. If you want to calculate
EMA(N), where N is a number of days, you can use alpha=2/(N+1).
-- ALGLIB --
Copyright 25.10.2011 by Bochkanov Sergey
*************************************************************************/
</div><div style='margin-top: 0; margin-bottom: 0;'><b>void</b> alglib::filterema(real_1d_array& x, <b>double</b> alpha);
<b>void</b> alglib::filterema(real_1d_array& x, ae_int_t n, <b>double</b> alpha);
</div></pre>
<p align=left class=pagecontent><span class=inlineheader>Examples:</span> <a href='#example_filters_d_ema' class=nav>[1]</a> </p>
<a name='sub_filterlrma'></a><h3 class=pageheader><code>filterlrma</code> function</h3>
<pre class=source>
<div style='color: navy; margin-top: 0; margin-bottom: 0;'>/*************************************************************************
Filters: linear regression moving averages.
This filter replaces array by results of LRMA(K) filter.
LRMA(K) is defined as filter which, for each data point, builds linear
regression model using K prevous points (point itself is included in
these K points) and calculates value of this linear model at the point in
question.
INPUT PARAMETERS:
X - array[N], array to process. It can be larger than N,
in this case only first N points are processed.
N - points count, N>=0
K - K>=1 (K can be larger than N , such cases will be
correctly handled). Window width. K=1 corresponds to
identity transformation (nothing changes).
OUTPUT PARAMETERS:
X - array, whose first N elements were processed with SMA(K)
NOTE 1: this function uses efficient in-place algorithm which does not
allocate temporary arrays.
NOTE 2: this algorithm makes only one pass through array and uses running
sum to speed-up calculation of the averages. Additional measures
are taken to ensure that running sum on a long sequence of zero
elements will be correctly reset to zero even in the presence of
round-off error.
NOTE 3: this is unsymmetric version of the algorithm, which does NOT
averages points after the current one. Only X[i], X[i-1], ... are
used when calculating new value of X[i]. We should also note that
this algorithm uses BOTH previous points and current one, i.e.
new value of X[i] depends on BOTH previous point and X[i] itself.
-- ALGLIB --
Copyright 25.10.2011 by Bochkanov Sergey
*************************************************************************/
</div><div style='margin-top: 0; margin-bottom: 0;'><b>void</b> alglib::filterlrma(real_1d_array& x, ae_int_t k);
<b>void</b> alglib::filterlrma(real_1d_array& x, ae_int_t n, ae_int_t k);
</div></pre>
<p align=left class=pagecontent><span class=inlineheader>Examples:</span> <a href='#example_filters_d_lrma' class=nav>[1]</a> </p>
<a name='sub_filtersma'></a><h3 class=pageheader><code>filtersma</code> function</h3>
<pre class=source>
<div style='color: navy; margin-top: 0; margin-bottom: 0;'>/*************************************************************************
Filters: simple moving averages (unsymmetric).
This filter replaces array by results of SMA(K) filter. SMA(K) is defined
as filter which averages at most K previous points (previous - not points
AROUND central point) - or less, in case of the first K-1 points.
INPUT PARAMETERS:
X - array[N], array to process. It can be larger than N,
in this case only first N points are processed.
N - points count, N>=0
K - K>=1 (K can be larger than N , such cases will be
correctly handled). Window width. K=1 corresponds to
identity transformation (nothing changes).
OUTPUT PARAMETERS:
X - array, whose first N elements were processed with SMA(K)
NOTE 1: this function uses efficient in-place algorithm which does not
allocate temporary arrays.
NOTE 2: this algorithm makes only one pass through array and uses running
sum to speed-up calculation of the averages. Additional measures
are taken to ensure that running sum on a long sequence of zero
elements will be correctly reset to zero even in the presence of
round-off error.
NOTE 3: this is unsymmetric version of the algorithm, which does NOT
averages points after the current one. Only X[i], X[i-1], ... are
used when calculating new value of X[i]. We should also note that
this algorithm uses BOTH previous points and current one, i.e.
new value of X[i] depends on BOTH previous point and X[i] itself.
-- ALGLIB --
Copyright 25.10.2011 by Bochkanov Sergey
*************************************************************************/
</div><div style='margin-top: 0; margin-bottom: 0;'><b>void</b> alglib::filtersma(real_1d_array& x, ae_int_t k);
<b>void</b> alglib::filtersma(real_1d_array& x, ae_int_t n, ae_int_t k);
</div></pre>
<p align=left class=pagecontent><span class=inlineheader>Examples:</span> <a href='#example_filters_d_sma' class=nav>[1]</a> </p>
<a name='example_filters_d_ema'></a><h3 class=pageheader>filters_d_ema example</h3>
<pre class=source>
#include <font color=blue><b>"stdafx.h"</b></font>
#include <stdlib.h>
#include <stdio.h>
#include <math.h>
#include <font color=blue><b>"dataanalysis.h"</b></font>
using namespace alglib;
<b>int</b> main(<b>int</b> argc, char **argv)
{
<font color=navy>//</font>
<font color=navy>// Here we demonstrate EMA(0.5) filtering <b>for</b> time series.</font>
<font color=navy>//</font>
real_1d_array x = <font color=blue><b>"[5,6,7,8]"</b></font>;
<font color=navy>//</font>
<font color=navy>// Apply filter.</font>
<font color=navy>// We should get [5, 5.5, 6.25, 7.125] as result</font>
<font color=navy>//</font>
filterema(x, 0.5);
printf(<font color=blue><b>"%s\n"</b></font>, x.tostring(4).c_str()); <font color=navy>// EXPECTED: [5,5.5,6.25,7.125]</font>
<b>return</b> 0;
}
</pre><a name='example_filters_d_lrma'></a><h3 class=pageheader>filters_d_lrma example</h3>
<pre class=source>
#include <font color=blue><b>"stdafx.h"</b></font>
#include <stdlib.h>
#include <stdio.h>
#include <math.h>
#include <font color=blue><b>"dataanalysis.h"</b></font>
using namespace alglib;
<b>int</b> main(<b>int</b> argc, char **argv)
{
<font color=navy>//</font>
<font color=navy>// Here we demonstrate LRMA(3) filtering <b>for</b> time series.</font>
<font color=navy>//</font>
real_1d_array x = <font color=blue><b>"[7,8,8,9,12,12]"</b></font>;
<font color=navy>//</font>
<font color=navy>// Apply filter.</font>
<font color=navy>// We should get [7.0000, 8.0000, 8.1667, 8.8333, 11.6667, 12.5000] as result</font>
<font color=navy>// </font>
filterlrma(x, 3);
printf(<font color=blue><b>"%s\n"</b></font>, x.tostring(4).c_str()); <font color=navy>// EXPECTED: [7.0000,8.0000,8.1667,8.8333,11.6667,12.5000]</font>
<b>return</b> 0;
}
</pre><a name='example_filters_d_sma'></a><h3 class=pageheader>filters_d_sma example</h3>
<pre class=source>
#include <font color=blue><b>"stdafx.h"</b></font>
#include <stdlib.h>
#include <stdio.h>
#include <math.h>
#include <font color=blue><b>"dataanalysis.h"</b></font>
using namespace alglib;
<b>int</b> main(<b>int</b> argc, char **argv)
{
<font color=navy>//</font>
<font color=navy>// Here we demonstrate SMA(k) filtering <b>for</b> time series.</font>
<font color=navy>//</font>
real_1d_array x = <font color=blue><b>"[5,6,7,8]"</b></font>;
<font color=navy>//</font>
<font color=navy>// Apply filter.</font>
<font color=navy>// We should get [5, 5.5, 6.5, 7.5] as result</font>
<font color=navy>//</font>
filtersma(x, 2);
printf(<font color=blue><b>"%s\n"</b></font>, x.tostring(4).c_str()); <font color=navy>// EXPECTED: [5,5.5,6.5,7.5]</font>
<b>return</b> 0;
}
</pre><a name=unit_fresnel></a><h2 class=pageheader><code>fresnel</code> subpackage</h2>
<div class=pagecontent>
<h3 class=pageheader>Functions</h3>
<a href='#sub_fresnelintegral' class=toc>fresnelintegral</a><br>
<h3 class=pageheader>Examples</h3>
<table border=0 cellspacing=0 class='pagecontent'>
</table></div>
<a name='sub_fresnelintegral'></a><h3 class=pageheader><code>fresnelintegral</code> function</h3>
<pre class=source>
<div style='color: navy; margin-top: 0; margin-bottom: 0;'>/*************************************************************************
Fresnel integral
Evaluates the Fresnel integrals
x
-
| |
C(x) = | cos(pi/2 t**2) dt,
| |
-
0
x
-
| |
S(x) = | sin(pi/2 t**2) dt.
| |
-
0
The integrals are evaluated by a power series for x < 1.
For x >= 1 auxiliary functions f(x) and g(x) are employed
such that
C(x) = 0.5 + f(x) sin( pi/2 x**2 ) - g(x) cos( pi/2 x**2 )
S(x) = 0.5 - f(x) cos( pi/2 x**2 ) - g(x) sin( pi/2 x**2 )
ACCURACY:
Relative error.
Arithmetic function domain # trials peak rms
IEEE S(x) 0, 10 10000 2.0e-15 3.2e-16
IEEE C(x) 0, 10 10000 1.8e-15 3.3e-16
Cephes Math Library Release 2.8: June, 2000
Copyright 1984, 1987, 1989, 2000 by Stephen L. Moshier
*************************************************************************/
</div><div style='margin-top: 0; margin-bottom: 0;'><b>void</b> alglib::fresnelintegral(<b>double</b> x, <b>double</b>& c, <b>double</b>& s);
</div></pre>
<a name=unit_gammafunc></a><h2 class=pageheader><code>gammafunc</code> subpackage</h2>
<div class=pagecontent>
<h3 class=pageheader>Functions</h3>
<a href='#sub_gammafunction' class=toc>gammafunction</a><br>
<a href='#sub_lngamma' class=toc>lngamma</a><br>
<h3 class=pageheader>Examples</h3>
<table border=0 cellspacing=0 class='pagecontent'>
</table></div>
<a name='sub_gammafunction'></a><h3 class=pageheader><code>gammafunction</code> function</h3>
<pre class=source>
<div style='color: navy; margin-top: 0; margin-bottom: 0;'>/*************************************************************************
Gamma function
Input parameters:
X - argument
Domain:
0 < X < 171.6
-170 < X < 0, X is not an integer.
Relative error:
arithmetic domain # trials peak rms
IEEE -170,-33 20000 2.3e-15 3.3e-16
IEEE -33, 33 20000 9.4e-16 2.2e-16
IEEE 33, 171.6 20000 2.3e-15 3.2e-16
Cephes Math Library Release 2.8: June, 2000
Original copyright 1984, 1987, 1989, 1992, 2000 by Stephen L. Moshier
Translated to AlgoPascal by Bochkanov Sergey (2005, 2006, 2007).
*************************************************************************/
</div><div style='margin-top: 0; margin-bottom: 0;'><b>double</b> alglib::gammafunction(<b>double</b> x);
</div></pre>
<a name='sub_lngamma'></a><h3 class=pageheader><code>lngamma</code> function</h3>
<pre class=source>
<div style='color: navy; margin-top: 0; margin-bottom: 0;'>/*************************************************************************
Natural logarithm of gamma function
Input parameters:
X - argument
Result:
logarithm of the absolute value of the Gamma(X).
Output parameters:
SgnGam - sign(Gamma(X))
Domain:
0 < X < 2.55e305
-2.55e305 < X < 0, X is not an integer.
ACCURACY:
arithmetic domain # trials peak rms
IEEE 0, 3 28000 5.4e-16 1.1e-16
IEEE 2.718, 2.556e305 40000 3.5e-16 8.3e-17
The error criterion was relative when the function magnitude
was greater than one but absolute when it was less than one.
The following test used the relative error criterion, though
at certain points the relative error could be much higher than
indicated.
IEEE -200, -4 10000 4.8e-16 1.3e-16
Cephes Math Library Release 2.8: June, 2000
Copyright 1984, 1987, 1989, 1992, 2000 by Stephen L. Moshier
Translated to AlgoPascal by Bochkanov Sergey (2005, 2006, 2007).
*************************************************************************/
</div><div style='margin-top: 0; margin-bottom: 0;'><b>double</b> alglib::lngamma(<b>double</b> x, <b>double</b>& sgngam);
</div></pre>
<a name=unit_gkq></a><h2 class=pageheader><code>gkq</code> subpackage</h2>
<div class=pagecontent>
<h3 class=pageheader>Functions</h3>
<a href='#sub_gkqgenerategaussjacobi' class=toc>gkqgenerategaussjacobi</a><br>
<a href='#sub_gkqgenerategausslegendre' class=toc>gkqgenerategausslegendre</a><br>
<a href='#sub_gkqgeneraterec' class=toc>gkqgeneraterec</a><br>
<a href='#sub_gkqlegendrecalc' class=toc>gkqlegendrecalc</a><br>
<a href='#sub_gkqlegendretbl' class=toc>gkqlegendretbl</a><br>
<h3 class=pageheader>Examples</h3>
<table border=0 cellspacing=0 class='pagecontent'>
</table></div>
<a name='sub_gkqgenerategaussjacobi'></a><h3 class=pageheader><code>gkqgenerategaussjacobi</code> function</h3>
<pre class=source>
<div style='color: navy; margin-top: 0; margin-bottom: 0;'>/*************************************************************************
Returns Gauss and Gauss-Kronrod nodes/weights for Gauss-Jacobi
quadrature on [-1,1] with weight function
W(x)=Power(1-x,Alpha)*Power(1+x,Beta).
INPUT PARAMETERS:
N - number of Kronrod nodes, must be odd number, >=3.
Alpha - power-law coefficient, Alpha>-1
Beta - power-law coefficient, Beta>-1
OUTPUT PARAMETERS:
Info - error code:
* -5 no real and positive Gauss-Kronrod formula can
be created for such a weight function with a
given number of nodes.
* -4 an error was detected when calculating
weights/nodes. Alpha or Beta are too close
to -1 to obtain weights/nodes with high enough
accuracy, or, may be, N is too large. Try to
use multiple precision version.
* -3 internal eigenproblem solver hasn't converged
* -1 incorrect N was passed
* +1 OK
* +2 OK, but quadrature rule have exterior nodes,
x[0]<-1 or x[n-1]>+1
X - array[0..N-1] - array of quadrature nodes, ordered in
ascending order.
WKronrod - array[0..N-1] - Kronrod weights
WGauss - array[0..N-1] - Gauss weights (interleaved with zeros
corresponding to extended Kronrod nodes).
-- ALGLIB --
Copyright 12.05.2009 by Bochkanov Sergey
*************************************************************************/
</div><div style='margin-top: 0; margin-bottom: 0;'><b>void</b> alglib::gkqgenerategaussjacobi(
ae_int_t n,
<b>double</b> alpha,
<b>double</b> beta,
ae_int_t& info,
real_1d_array& x,
real_1d_array& wkronrod,
real_1d_array& wgauss);
</div></pre>
<a name='sub_gkqgenerategausslegendre'></a><h3 class=pageheader><code>gkqgenerategausslegendre</code> function</h3>
<pre class=source>
<div style='color: navy; margin-top: 0; margin-bottom: 0;'>/*************************************************************************
Returns Gauss and Gauss-Kronrod nodes/weights for Gauss-Legendre
quadrature with N points.
GKQLegendreCalc (calculation) or GKQLegendreTbl (precomputed table) is
used depending on machine precision and number of nodes.
INPUT PARAMETERS:
N - number of Kronrod nodes, must be odd number, >=3.
OUTPUT PARAMETERS:
Info - error code:
* -4 an error was detected when calculating
weights/nodes. N is too large to obtain
weights/nodes with high enough accuracy.
Try to use multiple precision version.
* -3 internal eigenproblem solver hasn't converged
* -1 incorrect N was passed
* +1 OK
X - array[0..N-1] - array of quadrature nodes, ordered in
ascending order.
WKronrod - array[0..N-1] - Kronrod weights
WGauss - array[0..N-1] - Gauss weights (interleaved with zeros
corresponding to extended Kronrod nodes).
-- ALGLIB --
Copyright 12.05.2009 by Bochkanov Sergey
*************************************************************************/
</div><div style='margin-top: 0; margin-bottom: 0;'><b>void</b> alglib::gkqgenerategausslegendre(
ae_int_t n,
ae_int_t& info,
real_1d_array& x,
real_1d_array& wkronrod,
real_1d_array& wgauss);
</div></pre>
<a name='sub_gkqgeneraterec'></a><h3 class=pageheader><code>gkqgeneraterec</code> function</h3>
<pre class=source>
<div style='color: navy; margin-top: 0; margin-bottom: 0;'>/*************************************************************************
Computation of nodes and weights of a Gauss-Kronrod quadrature formula
The algorithm generates the N-point Gauss-Kronrod quadrature formula with
weight function given by coefficients alpha and beta of a recurrence
relation which generates a system of orthogonal polynomials:
P-1(x) = 0
P0(x) = 1
Pn+1(x) = (x-alpha(n))*Pn(x) - beta(n)*Pn-1(x)
and zero moment Mu0
Mu0 = integral(W(x)dx,a,b)
INPUT PARAMETERS:
Alpha � alpha coefficients, array[0..floor(3*K/2)].
Beta � beta coefficients, array[0..ceil(3*K/2)].
Beta[0] is not used and may be arbitrary.
Beta[I]>0.
Mu0 � zeroth moment of the weight function.
N � number of nodes of the Gauss-Kronrod quadrature formula,
N >= 3,
N = 2*K+1.
OUTPUT PARAMETERS:
Info - error code:
* -5 no real and positive Gauss-Kronrod formula can
be created for such a weight function with a
given number of nodes.
* -4 N is too large, task may be ill conditioned -
x[i]=x[i+1] found.
* -3 internal eigenproblem solver hasn't converged
* -2 Beta[i]<=0
* -1 incorrect N was passed
* +1 OK
X - array[0..N-1] - array of quadrature nodes,
in ascending order.
WKronrod - array[0..N-1] - Kronrod weights
WGauss - array[0..N-1] - Gauss weights (interleaved with zeros
corresponding to extended Kronrod nodes).
-- ALGLIB --
Copyright 08.05.2009 by Bochkanov Sergey
*************************************************************************/
</div><div style='margin-top: 0; margin-bottom: 0;'><b>void</b> alglib::gkqgeneraterec(
real_1d_array alpha,
real_1d_array beta,
<b>double</b> mu0,
ae_int_t n,
ae_int_t& info,
real_1d_array& x,
real_1d_array& wkronrod,
real_1d_array& wgauss);
</div></pre>
<a name='sub_gkqlegendrecalc'></a><h3 class=pageheader><code>gkqlegendrecalc</code> function</h3>
<pre class=source>
<div style='color: navy; margin-top: 0; margin-bottom: 0;'>/*************************************************************************
Returns Gauss and Gauss-Kronrod nodes for quadrature with N points.
Reduction to tridiagonal eigenproblem is used.
INPUT PARAMETERS:
N - number of Kronrod nodes, must be odd number, >=3.
OUTPUT PARAMETERS:
Info - error code:
* -4 an error was detected when calculating
weights/nodes. N is too large to obtain
weights/nodes with high enough accuracy.
Try to use multiple precision version.
* -3 internal eigenproblem solver hasn't converged
* -1 incorrect N was passed
* +1 OK
X - array[0..N-1] - array of quadrature nodes, ordered in
ascending order.
WKronrod - array[0..N-1] - Kronrod weights
WGauss - array[0..N-1] - Gauss weights (interleaved with zeros
corresponding to extended Kronrod nodes).
-- ALGLIB --
Copyright 12.05.2009 by Bochkanov Sergey
*************************************************************************/
</div><div style='margin-top: 0; margin-bottom: 0;'><b>void</b> alglib::gkqlegendrecalc(
ae_int_t n,
ae_int_t& info,
real_1d_array& x,
real_1d_array& wkronrod,
real_1d_array& wgauss);
</div></pre>
<a name='sub_gkqlegendretbl'></a><h3 class=pageheader><code>gkqlegendretbl</code> function</h3>
<pre class=source>
<div style='color: navy; margin-top: 0; margin-bottom: 0;'>/*************************************************************************
Returns Gauss and Gauss-Kronrod nodes for quadrature with N points using
pre-calculated table. Nodes/weights were computed with accuracy up to
1.0E-32 (if MPFR version of ALGLIB is used). In standard double precision
accuracy reduces to something about 2.0E-16 (depending on your compiler's
handling of long floating point constants).
INPUT PARAMETERS:
N - number of Kronrod nodes.
N can be 15, 21, 31, 41, 51, 61.
OUTPUT PARAMETERS:
X - array[0..N-1] - array of quadrature nodes, ordered in
ascending order.
WKronrod - array[0..N-1] - Kronrod weights
WGauss - array[0..N-1] - Gauss weights (interleaved with zeros
corresponding to extended Kronrod nodes).
-- ALGLIB --
Copyright 12.05.2009 by Bochkanov Sergey
*************************************************************************/
</div><div style='margin-top: 0; margin-bottom: 0;'><b>void</b> alglib::gkqlegendretbl(
ae_int_t n,
real_1d_array& x,
real_1d_array& wkronrod,
real_1d_array& wgauss,
<b>double</b>& eps);
</div></pre>
<a name=unit_gq></a><h2 class=pageheader><code>gq</code> subpackage</h2>
<div class=pagecontent>
<h3 class=pageheader>Functions</h3>
<a href='#sub_gqgenerategausshermite' class=toc>gqgenerategausshermite</a><br>
<a href='#sub_gqgenerategaussjacobi' class=toc>gqgenerategaussjacobi</a><br>
<a href='#sub_gqgenerategausslaguerre' class=toc>gqgenerategausslaguerre</a><br>
<a href='#sub_gqgenerategausslegendre' class=toc>gqgenerategausslegendre</a><br>
<a href='#sub_gqgenerategausslobattorec' class=toc>gqgenerategausslobattorec</a><br>
<a href='#sub_gqgenerategaussradaurec' class=toc>gqgenerategaussradaurec</a><br>
<a href='#sub_gqgeneraterec' class=toc>gqgeneraterec</a><br>
<h3 class=pageheader>Examples</h3>
<table border=0 cellspacing=0 class='pagecontent'>
</table></div>
<a name='sub_gqgenerategausshermite'></a><h3 class=pageheader><code>gqgenerategausshermite</code> function</h3>
<pre class=source>
<div style='color: navy; margin-top: 0; margin-bottom: 0;'>/*************************************************************************
Returns nodes/weights for Gauss-Hermite quadrature on (-inf,+inf) with
weight function W(x)=Exp(-x*x)
INPUT PARAMETERS:
N - number of nodes, >=1
OUTPUT PARAMETERS:
Info - error code:
* -4 an error was detected when calculating
weights/nodes. May be, N is too large. Try to
use multiple precision version.
* -3 internal eigenproblem solver hasn't converged
* -1 incorrect N/Alpha was passed
* +1 OK
X - array[0..N-1] - array of quadrature nodes,
in ascending order.
W - array[0..N-1] - array of quadrature weights.
-- ALGLIB --
Copyright 12.05.2009 by Bochkanov Sergey
*************************************************************************/
</div><div style='margin-top: 0; margin-bottom: 0;'><b>void</b> alglib::gqgenerategausshermite(
ae_int_t n,
ae_int_t& info,
real_1d_array& x,
real_1d_array& w);
</div></pre>
<a name='sub_gqgenerategaussjacobi'></a><h3 class=pageheader><code>gqgenerategaussjacobi</code> function</h3>
<pre class=source>
<div style='color: navy; margin-top: 0; margin-bottom: 0;'>/*************************************************************************
Returns nodes/weights for Gauss-Jacobi quadrature on [-1,1] with weight
function W(x)=Power(1-x,Alpha)*Power(1+x,Beta).
INPUT PARAMETERS:
N - number of nodes, >=1
Alpha - power-law coefficient, Alpha>-1
Beta - power-law coefficient, Beta>-1
OUTPUT PARAMETERS:
Info - error code:
* -4 an error was detected when calculating
weights/nodes. Alpha or Beta are too close
to -1 to obtain weights/nodes with high enough
accuracy, or, may be, N is too large. Try to
use multiple precision version.
* -3 internal eigenproblem solver hasn't converged
* -1 incorrect N/Alpha/Beta was passed
* +1 OK
X - array[0..N-1] - array of quadrature nodes,
in ascending order.
W - array[0..N-1] - array of quadrature weights.
-- ALGLIB --
Copyright 12.05.2009 by Bochkanov Sergey
*************************************************************************/
</div><div style='margin-top: 0; margin-bottom: 0;'><b>void</b> alglib::gqgenerategaussjacobi(
ae_int_t n,
<b>double</b> alpha,
<b>double</b> beta,
ae_int_t& info,
real_1d_array& x,
real_1d_array& w);
</div></pre>
<a name='sub_gqgenerategausslaguerre'></a><h3 class=pageheader><code>gqgenerategausslaguerre</code> function</h3>
<pre class=source>
<div style='color: navy; margin-top: 0; margin-bottom: 0;'>/*************************************************************************
Returns nodes/weights for Gauss-Laguerre quadrature on [0,+inf) with
weight function W(x)=Power(x,Alpha)*Exp(-x)
INPUT PARAMETERS:
N - number of nodes, >=1
Alpha - power-law coefficient, Alpha>-1
OUTPUT PARAMETERS:
Info - error code:
* -4 an error was detected when calculating
weights/nodes. Alpha is too close to -1 to
obtain weights/nodes with high enough accuracy
or, may be, N is too large. Try to use
multiple precision version.
* -3 internal eigenproblem solver hasn't converged
* -1 incorrect N/Alpha was passed
* +1 OK
X - array[0..N-1] - array of quadrature nodes,
in ascending order.
W - array[0..N-1] - array of quadrature weights.
-- ALGLIB --
Copyright 12.05.2009 by Bochkanov Sergey
*************************************************************************/
</div><div style='margin-top: 0; margin-bottom: 0;'><b>void</b> alglib::gqgenerategausslaguerre(
ae_int_t n,
<b>double</b> alpha,
ae_int_t& info,
real_1d_array& x,
real_1d_array& w);
</div></pre>
<a name='sub_gqgenerategausslegendre'></a><h3 class=pageheader><code>gqgenerategausslegendre</code> function</h3>
<pre class=source>
<div style='color: navy; margin-top: 0; margin-bottom: 0;'>/*************************************************************************
Returns nodes/weights for Gauss-Legendre quadrature on [-1,1] with N
nodes.
INPUT PARAMETERS:
N - number of nodes, >=1
OUTPUT PARAMETERS:
Info - error code:
* -4 an error was detected when calculating
weights/nodes. N is too large to obtain
weights/nodes with high enough accuracy.
Try to use multiple precision version.
* -3 internal eigenproblem solver hasn't converged
* -1 incorrect N was passed
* +1 OK
X - array[0..N-1] - array of quadrature nodes,
in ascending order.
W - array[0..N-1] - array of quadrature weights.
-- ALGLIB --
Copyright 12.05.2009 by Bochkanov Sergey
*************************************************************************/
</div><div style='margin-top: 0; margin-bottom: 0;'><b>void</b> alglib::gqgenerategausslegendre(
ae_int_t n,
ae_int_t& info,
real_1d_array& x,
real_1d_array& w);
</div></pre>
<a name='sub_gqgenerategausslobattorec'></a><h3 class=pageheader><code>gqgenerategausslobattorec</code> function</h3>
<pre class=source>
<div style='color: navy; margin-top: 0; margin-bottom: 0;'>/*************************************************************************
Computation of nodes and weights for a Gauss-Lobatto quadrature formula
The algorithm generates the N-point Gauss-Lobatto quadrature formula with
weight function given by coefficients alpha and beta of a recurrence which
generates a system of orthogonal polynomials.
P-1(x) = 0
P0(x) = 1
Pn+1(x) = (x-alpha(n))*Pn(x) - beta(n)*Pn-1(x)
and zeroth moment Mu0
Mu0 = integral(W(x)dx,a,b)
INPUT PARAMETERS:
Alpha � array[0..N-2], alpha coefficients
Beta � array[0..N-2], beta coefficients.
Zero-indexed element is not used, may be arbitrary.
Beta[I]>0
Mu0 � zeroth moment of the weighting function.
A � left boundary of the integration interval.
B � right boundary of the integration interval.
N � number of nodes of the quadrature formula, N>=3
(including the left and right boundary nodes).
OUTPUT PARAMETERS:
Info - error code:
* -3 internal eigenproblem solver hasn't converged
* -2 Beta[i]<=0
* -1 incorrect N was passed
* 1 OK
X - array[0..N-1] - array of quadrature nodes,
in ascending order.
W - array[0..N-1] - array of quadrature weights.
-- ALGLIB --
Copyright 2005-2009 by Bochkanov Sergey
*************************************************************************/
</div><div style='margin-top: 0; margin-bottom: 0;'><b>void</b> alglib::gqgenerategausslobattorec(
real_1d_array alpha,
real_1d_array beta,
<b>double</b> mu0,
<b>double</b> a,
<b>double</b> b,
ae_int_t n,
ae_int_t& info,
real_1d_array& x,
real_1d_array& w);
</div></pre>
<a name='sub_gqgenerategaussradaurec'></a><h3 class=pageheader><code>gqgenerategaussradaurec</code> function</h3>
<pre class=source>
<div style='color: navy; margin-top: 0; margin-bottom: 0;'>/*************************************************************************
Computation of nodes and weights for a Gauss-Radau quadrature formula
The algorithm generates the N-point Gauss-Radau quadrature formula with
weight function given by the coefficients alpha and beta of a recurrence
which generates a system of orthogonal polynomials.
P-1(x) = 0
P0(x) = 1
Pn+1(x) = (x-alpha(n))*Pn(x) - beta(n)*Pn-1(x)
and zeroth moment Mu0
Mu0 = integral(W(x)dx,a,b)
INPUT PARAMETERS:
Alpha � array[0..N-2], alpha coefficients.
Beta � array[0..N-1], beta coefficients
Zero-indexed element is not used.
Beta[I]>0
Mu0 � zeroth moment of the weighting function.
A � left boundary of the integration interval.
N � number of nodes of the quadrature formula, N>=2
(including the left boundary node).
OUTPUT PARAMETERS:
Info - error code:
* -3 internal eigenproblem solver hasn't converged
* -2 Beta[i]<=0
* -1 incorrect N was passed
* 1 OK
X - array[0..N-1] - array of quadrature nodes,
in ascending order.
W - array[0..N-1] - array of quadrature weights.
-- ALGLIB --
Copyright 2005-2009 by Bochkanov Sergey
*************************************************************************/
</div><div style='margin-top: 0; margin-bottom: 0;'><b>void</b> alglib::gqgenerategaussradaurec(
real_1d_array alpha,
real_1d_array beta,
<b>double</b> mu0,
<b>double</b> a,
ae_int_t n,
ae_int_t& info,
real_1d_array& x,
real_1d_array& w);
</div></pre>
<a name='sub_gqgeneraterec'></a><h3 class=pageheader><code>gqgeneraterec</code> function</h3>
<pre class=source>
<div style='color: navy; margin-top: 0; margin-bottom: 0;'>/*************************************************************************
Computation of nodes and weights for a Gauss quadrature formula
The algorithm generates the N-point Gauss quadrature formula with weight
function given by coefficients alpha and beta of a recurrence relation
which generates a system of orthogonal polynomials:
P-1(x) = 0
P0(x) = 1
Pn+1(x) = (x-alpha(n))*Pn(x) - beta(n)*Pn-1(x)
and zeroth moment Mu0
Mu0 = integral(W(x)dx,a,b)
INPUT PARAMETERS:
Alpha � array[0..N-1], alpha coefficients
Beta � array[0..N-1], beta coefficients
Zero-indexed element is not used and may be arbitrary.
Beta[I]>0.
Mu0 � zeroth moment of the weight function.
N � number of nodes of the quadrature formula, N>=1
OUTPUT PARAMETERS:
Info - error code:
* -3 internal eigenproblem solver hasn't converged
* -2 Beta[i]<=0
* -1 incorrect N was passed
* 1 OK
X - array[0..N-1] - array of quadrature nodes,
in ascending order.
W - array[0..N-1] - array of quadrature weights.
-- ALGLIB --
Copyright 2005-2009 by Bochkanov Sergey
*************************************************************************/
</div><div style='margin-top: 0; margin-bottom: 0;'><b>void</b> alglib::gqgeneraterec(
real_1d_array alpha,
real_1d_array beta,
<b>double</b> mu0,
ae_int_t n,
ae_int_t& info,
real_1d_array& x,
real_1d_array& w);
</div></pre>
<a name=unit_hermite></a><h2 class=pageheader><code>hermite</code> subpackage</h2>
<div class=pagecontent>
<h3 class=pageheader>Functions</h3>
<a href='#sub_hermitecalculate' class=toc>hermitecalculate</a><br>
<a href='#sub_hermitecoefficients' class=toc>hermitecoefficients</a><br>
<a href='#sub_hermitesum' class=toc>hermitesum</a><br>
<h3 class=pageheader>Examples</h3>
<table border=0 cellspacing=0 class='pagecontent'>
</table></div>
<a name='sub_hermitecalculate'></a><h3 class=pageheader><code>hermitecalculate</code> function</h3>
<pre class=source>
<div style='color: navy; margin-top: 0; margin-bottom: 0;'>/*************************************************************************
Calculation of the value of the Hermite polynomial.
Parameters:
n - degree, n>=0
x - argument
Result:
the value of the Hermite polynomial Hn at x
*************************************************************************/
</div><div style='margin-top: 0; margin-bottom: 0;'><b>double</b> alglib::hermitecalculate(ae_int_t n, <b>double</b> x);
</div></pre>
<a name='sub_hermitecoefficients'></a><h3 class=pageheader><code>hermitecoefficients</code> function</h3>
<pre class=source>
<div style='color: navy; margin-top: 0; margin-bottom: 0;'>/*************************************************************************
Representation of Hn as C[0] + C[1]*X + ... + C[N]*X^N
Input parameters:
N - polynomial degree, n>=0
Output parameters:
C - coefficients
*************************************************************************/
</div><div style='margin-top: 0; margin-bottom: 0;'><b>void</b> alglib::hermitecoefficients(ae_int_t n, real_1d_array& c);
</div></pre>
<a name='sub_hermitesum'></a><h3 class=pageheader><code>hermitesum</code> function</h3>
<pre class=source>
<div style='color: navy; margin-top: 0; margin-bottom: 0;'>/*************************************************************************
Summation of Hermite polynomials using Clenshaw�s recurrence formula.
This routine calculates
c[0]*H0(x) + c[1]*H1(x) + ... + c[N]*HN(x)
Parameters:
n - degree, n>=0
x - argument
Result:
the value of the Hermite polynomial at x
*************************************************************************/
</div><div style='margin-top: 0; margin-bottom: 0;'><b>double</b> alglib::hermitesum(real_1d_array c, ae_int_t n, <b>double</b> x);
</div></pre>
<a name=unit_hqrnd></a><h2 class=pageheader><code>hqrnd</code> subpackage</h2>
<div class=pagecontent>
<h3 class=pageheader>Classes</h3>
<a href='#struct_hqrndstate' class=toc>hqrndstate</a><br>
<h3 class=pageheader>Functions</h3>
<a href='#sub_hqrndcontinuous' class=toc>hqrndcontinuous</a><br>
<a href='#sub_hqrnddiscrete' class=toc>hqrnddiscrete</a><br>
<a href='#sub_hqrndexponential' class=toc>hqrndexponential</a><br>
<a href='#sub_hqrndnormal' class=toc>hqrndnormal</a><br>
<a href='#sub_hqrndnormal2' class=toc>hqrndnormal2</a><br>
<a href='#sub_hqrndrandomize' class=toc>hqrndrandomize</a><br>
<a href='#sub_hqrndseed' class=toc>hqrndseed</a><br>
<a href='#sub_hqrnduniformi' class=toc>hqrnduniformi</a><br>
<a href='#sub_hqrnduniformr' class=toc>hqrnduniformr</a><br>
<a href='#sub_hqrndunit2' class=toc>hqrndunit2</a><br>
<h3 class=pageheader>Examples</h3>
<table border=0 cellspacing=0 class='pagecontent'>
</table></div>
<a name='struct_hqrndstate'></a><h3 class=pageheader><code>hqrndstate</code> class</h3>
<pre class=source>
<div style='color: navy; margin-top: 0; margin-bottom: 0;'>/*************************************************************************
Portable high quality random number generator state.
Initialized with HQRNDRandomize() or HQRNDSeed().
Fields:
S1, S2 - seed values
V - precomputed value
MagicV - 'magic' value used to determine whether State structure
was correctly initialized.
*************************************************************************/
</div><div style='margin-top: 0; margin-bottom: 0;'><b>class</b> hqrndstate
{
};
</div></pre>
<a name='sub_hqrndcontinuous'></a><h3 class=pageheader><code>hqrndcontinuous</code> function</h3>
<pre class=source>
<div style='color: navy; margin-top: 0; margin-bottom: 0;'>/*************************************************************************
This function generates random number from continuous distribution given
by finite sample X.
INPUT PARAMETERS
State - high quality random number generator, must be
initialized with HQRNDRandomize() or HQRNDSeed().
X - finite sample, array[N] (can be larger, in this case only
leading N elements are used). THIS ARRAY MUST BE SORTED BY
ASCENDING.
N - number of elements to use, N>=1
RESULT
this function returns random number from continuous distribution which
tries to approximate X as mush as possible. min(X)<=Result<=max(X).
-- ALGLIB --
Copyright 08.11.2011 by Bochkanov Sergey
*************************************************************************/
</div><div style='margin-top: 0; margin-bottom: 0;'><b>double</b> alglib::hqrndcontinuous(
hqrndstate state,
real_1d_array x,
ae_int_t n);
</div></pre>
<a name='sub_hqrnddiscrete'></a><h3 class=pageheader><code>hqrnddiscrete</code> function</h3>
<pre class=source>
<div style='color: navy; margin-top: 0; margin-bottom: 0;'>/*************************************************************************
This function generates random number from discrete distribution given by
finite sample X.
INPUT PARAMETERS
State - high quality random number generator, must be
initialized with HQRNDRandomize() or HQRNDSeed().
X - finite sample
N - number of elements to use, N>=1
RESULT
this function returns one of the X[i] for random i=0..N-1
-- ALGLIB --
Copyright 08.11.2011 by Bochkanov Sergey
*************************************************************************/
</div><div style='margin-top: 0; margin-bottom: 0;'><b>double</b> alglib::hqrnddiscrete(
hqrndstate state,
real_1d_array x,
ae_int_t n);
</div></pre>
<a name='sub_hqrndexponential'></a><h3 class=pageheader><code>hqrndexponential</code> function</h3>
<pre class=source>
<div style='color: navy; margin-top: 0; margin-bottom: 0;'>/*************************************************************************
Random number generator: exponential distribution
State structure must be initialized with HQRNDRandomize() or HQRNDSeed().
-- ALGLIB --
Copyright 11.08.2007 by Bochkanov Sergey
*************************************************************************/
</div><div style='margin-top: 0; margin-bottom: 0;'><b>double</b> alglib::hqrndexponential(hqrndstate state, <b>double</b> lambdav);
</div></pre>
<a name='sub_hqrndnormal'></a><h3 class=pageheader><code>hqrndnormal</code> function</h3>
<pre class=source>
<div style='color: navy; margin-top: 0; margin-bottom: 0;'>/*************************************************************************
Random number generator: normal numbers
This function generates one random number from normal distribution.
Its performance is equal to that of HQRNDNormal2()
State structure must be initialized with HQRNDRandomize() or HQRNDSeed().
-- ALGLIB --
Copyright 02.12.2009 by Bochkanov Sergey
*************************************************************************/
</div><div style='margin-top: 0; margin-bottom: 0;'><b>double</b> alglib::hqrndnormal(hqrndstate state);
</div></pre>
<a name='sub_hqrndnormal2'></a><h3 class=pageheader><code>hqrndnormal2</code> function</h3>
<pre class=source>
<div style='color: navy; margin-top: 0; margin-bottom: 0;'>/*************************************************************************
Random number generator: normal numbers
This function generates two independent random numbers from normal
distribution. Its performance is equal to that of HQRNDNormal()
State structure must be initialized with HQRNDRandomize() or HQRNDSeed().
-- ALGLIB --
Copyright 02.12.2009 by Bochkanov Sergey
*************************************************************************/
</div><div style='margin-top: 0; margin-bottom: 0;'><b>void</b> alglib::hqrndnormal2(hqrndstate state, <b>double</b>& x1, <b>double</b>& x2);
</div></pre>
<a name='sub_hqrndrandomize'></a><h3 class=pageheader><code>hqrndrandomize</code> function</h3>
<pre class=source>
<div style='color: navy; margin-top: 0; margin-bottom: 0;'>/*************************************************************************
HQRNDState initialization with random values which come from standard
RNG.
-- ALGLIB --
Copyright 02.12.2009 by Bochkanov Sergey
*************************************************************************/
</div><div style='margin-top: 0; margin-bottom: 0;'><b>void</b> alglib::hqrndrandomize(hqrndstate& state);
</div></pre>
<a name='sub_hqrndseed'></a><h3 class=pageheader><code>hqrndseed</code> function</h3>
<pre class=source>
<div style='color: navy; margin-top: 0; margin-bottom: 0;'>/*************************************************************************
HQRNDState initialization with seed values
-- ALGLIB --
Copyright 02.12.2009 by Bochkanov Sergey
*************************************************************************/
</div><div style='margin-top: 0; margin-bottom: 0;'><b>void</b> alglib::hqrndseed(ae_int_t s1, ae_int_t s2, hqrndstate& state);
</div></pre>
<a name='sub_hqrnduniformi'></a><h3 class=pageheader><code>hqrnduniformi</code> function</h3>
<pre class=source>
<div style='color: navy; margin-top: 0; margin-bottom: 0;'>/*************************************************************************
This function generates random integer number in [0, N)
1. State structure must be initialized with HQRNDRandomize() or HQRNDSeed()
2. N can be any positive number except for very large numbers:
* close to 2^31 on 32-bit systems
* close to 2^62 on 64-bit systems
An exception will be generated if N is too large.
-- ALGLIB --
Copyright 02.12.2009 by Bochkanov Sergey
*************************************************************************/
</div><div style='margin-top: 0; margin-bottom: 0;'>ae_int_t alglib::hqrnduniformi(hqrndstate state, ae_int_t n);
</div></pre>
<a name='sub_hqrnduniformr'></a><h3 class=pageheader><code>hqrnduniformr</code> function</h3>
<pre class=source>
<div style='color: navy; margin-top: 0; margin-bottom: 0;'>/*************************************************************************
This function generates random real number in (0,1),
not including interval boundaries
State structure must be initialized with HQRNDRandomize() or HQRNDSeed().
-- ALGLIB --
Copyright 02.12.2009 by Bochkanov Sergey
*************************************************************************/
</div><div style='margin-top: 0; margin-bottom: 0;'><b>double</b> alglib::hqrnduniformr(hqrndstate state);
</div></pre>
<a name='sub_hqrndunit2'></a><h3 class=pageheader><code>hqrndunit2</code> function</h3>
<pre class=source>
<div style='color: navy; margin-top: 0; margin-bottom: 0;'>/*************************************************************************
Random number generator: random X and Y such that X^2+Y^2=1
State structure must be initialized with HQRNDRandomize() or HQRNDSeed().
-- ALGLIB --
Copyright 02.12.2009 by Bochkanov Sergey
*************************************************************************/
</div><div style='margin-top: 0; margin-bottom: 0;'><b>void</b> alglib::hqrndunit2(hqrndstate state, <b>double</b>& x, <b>double</b>& y);
</div></pre>
<a name=unit_ibetaf></a><h2 class=pageheader><code>ibetaf</code> subpackage</h2>
<div class=pagecontent>
<h3 class=pageheader>Functions</h3>
<a href='#sub_incompletebeta' class=toc>incompletebeta</a><br>
<a href='#sub_invincompletebeta' class=toc>invincompletebeta</a><br>
<h3 class=pageheader>Examples</h3>
<table border=0 cellspacing=0 class='pagecontent'>
</table></div>
<a name='sub_incompletebeta'></a><h3 class=pageheader><code>incompletebeta</code> function</h3>
<pre class=source>
<div style='color: navy; margin-top: 0; margin-bottom: 0;'>/*************************************************************************
Incomplete beta integral
Returns incomplete beta integral of the arguments, evaluated
from zero to x. The function is defined as
x
- -
| (a+b) | | a-1 b-1
----------- | t (1-t) dt.
- - | |
| (a) | (b) -
0
The domain of definition is 0 <= x <= 1. In this
implementation a and b are restricted to positive values.
The integral from x to 1 may be obtained by the symmetry
relation
1 - incbet( a, b, x ) = incbet( b, a, 1-x ).
The integral is evaluated by a continued fraction expansion
or, when b*x is small, by a power series.
ACCURACY:
Tested at uniformly distributed random points (a,b,x) with a and b
in "domain" and x between 0 and 1.
Relative error
arithmetic domain # trials peak rms
IEEE 0,5 10000 6.9e-15 4.5e-16
IEEE 0,85 250000 2.2e-13 1.7e-14
IEEE 0,1000 30000 5.3e-12 6.3e-13
IEEE 0,10000 250000 9.3e-11 7.1e-12
IEEE 0,100000 10000 8.7e-10 4.8e-11
Outputs smaller than the IEEE gradual underflow threshold
were excluded from these statistics.
Cephes Math Library, Release 2.8: June, 2000
Copyright 1984, 1995, 2000 by Stephen L. Moshier
*************************************************************************/
</div><div style='margin-top: 0; margin-bottom: 0;'><b>double</b> alglib::incompletebeta(<b>double</b> a, <b>double</b> b, <b>double</b> x);
</div></pre>
<a name='sub_invincompletebeta'></a><h3 class=pageheader><code>invincompletebeta</code> function</h3>
<pre class=source>
<div style='color: navy; margin-top: 0; margin-bottom: 0;'>/*************************************************************************
Inverse of imcomplete beta integral
Given y, the function finds x such that
incbet( a, b, x ) = y .
The routine performs interval halving or Newton iterations to find the
root of incbet(a,b,x) - y = 0.
ACCURACY:
Relative error:
x a,b
arithmetic domain domain # trials peak rms
IEEE 0,1 .5,10000 50000 5.8e-12 1.3e-13
IEEE 0,1 .25,100 100000 1.8e-13 3.9e-15
IEEE 0,1 0,5 50000 1.1e-12 5.5e-15
With a and b constrained to half-integer or integer values:
IEEE 0,1 .5,10000 50000 5.8e-12 1.1e-13
IEEE 0,1 .5,100 100000 1.7e-14 7.9e-16
With a = .5, b constrained to half-integer or integer values:
IEEE 0,1 .5,10000 10000 8.3e-11 1.0e-11
Cephes Math Library Release 2.8: June, 2000
Copyright 1984, 1996, 2000 by Stephen L. Moshier
*************************************************************************/
</div><div style='margin-top: 0; margin-bottom: 0;'><b>double</b> alglib::invincompletebeta(<b>double</b> a, <b>double</b> b, <b>double</b> y);
</div></pre>
<a name=unit_idwint></a><h2 class=pageheader><code>idwint</code> subpackage</h2>
<div class=pagecontent>
<h3 class=pageheader>Classes</h3>
<a href='#struct_idwinterpolant' class=toc>idwinterpolant</a><br>
<h3 class=pageheader>Functions</h3>
<a href='#sub_idwbuildmodifiedshepard' class=toc>idwbuildmodifiedshepard</a><br>
<a href='#sub_idwbuildmodifiedshepardr' class=toc>idwbuildmodifiedshepardr</a><br>
<a href='#sub_idwbuildnoisy' class=toc>idwbuildnoisy</a><br>
<a href='#sub_idwcalc' class=toc>idwcalc</a><br>
<h3 class=pageheader>Examples</h3>
<table border=0 cellspacing=0 class='pagecontent'>
</table></div>
<a name='struct_idwinterpolant'></a><h3 class=pageheader><code>idwinterpolant</code> class</h3>
<pre class=source>
<div style='color: navy; margin-top: 0; margin-bottom: 0;'>/*************************************************************************
IDW interpolant.
*************************************************************************/
</div><div style='margin-top: 0; margin-bottom: 0;'><b>class</b> idwinterpolant
{
};
</div></pre>
<a name='sub_idwbuildmodifiedshepard'></a><h3 class=pageheader><code>idwbuildmodifiedshepard</code> function</h3>
<pre class=source>
<div style='color: navy; margin-top: 0; margin-bottom: 0;'>/*************************************************************************
IDW interpolant using modified Shepard method for uniform point
distributions.
INPUT PARAMETERS:
XY - X and Y values, array[0..N-1,0..NX].
First NX columns contain X-values, last column contain
Y-values.
N - number of nodes, N>0.
NX - space dimension, NX>=1.
D - nodal function type, either:
* 0 constant model. Just for demonstration only, worst
model ever.
* 1 linear model, least squares fitting. Simpe model for
datasets too small for quadratic models
* 2 quadratic model, least squares fitting. Best model
available (if your dataset is large enough).
* -1 "fast" linear model, use with caution!!! It is
significantly faster than linear/quadratic and better
than constant model. But it is less robust (especially
in the presence of noise).
NQ - number of points used to calculate nodal functions (ignored
for constant models). NQ should be LARGER than:
* max(1.5*(1+NX),2^NX+1) for linear model,
* max(3/4*(NX+2)*(NX+1),2^NX+1) for quadratic model.
Values less than this threshold will be silently increased.
NW - number of points used to calculate weights and to interpolate.
Required: >=2^NX+1, values less than this threshold will be
silently increased.
Recommended value: about 2*NQ
OUTPUT PARAMETERS:
Z - IDW interpolant.
NOTES:
* best results are obtained with quadratic models, worst - with constant
models
* when N is large, NQ and NW must be significantly smaller than N both
to obtain optimal performance and to obtain optimal accuracy. In 2 or
3-dimensional tasks NQ=15 and NW=25 are good values to start with.
* NQ and NW may be greater than N. In such cases they will be
automatically decreased.
* this subroutine is always succeeds (as long as correct parameters are
passed).
* see 'Multivariate Interpolation of Large Sets of Scattered Data' by
Robert J. Renka for more information on this algorithm.
* this subroutine assumes that point distribution is uniform at the small
scales. If it isn't - for example, points are concentrated along
"lines", but "lines" distribution is uniform at the larger scale - then
you should use IDWBuildModifiedShepardR()
-- ALGLIB PROJECT --
Copyright 02.03.2010 by Bochkanov Sergey
*************************************************************************/
</div><div style='margin-top: 0; margin-bottom: 0;'><b>void</b> alglib::idwbuildmodifiedshepard(
real_2d_array xy,
ae_int_t n,
ae_int_t nx,
ae_int_t d,
ae_int_t nq,
ae_int_t nw,
idwinterpolant& z);
</div></pre>
<a name='sub_idwbuildmodifiedshepardr'></a><h3 class=pageheader><code>idwbuildmodifiedshepardr</code> function</h3>
<pre class=source>
<div style='color: navy; margin-top: 0; margin-bottom: 0;'>/*************************************************************************
IDW interpolant using modified Shepard method for non-uniform datasets.
This type of model uses constant nodal functions and interpolates using
all nodes which are closer than user-specified radius R. It may be used
when points distribution is non-uniform at the small scale, but it is at
the distances as large as R.
INPUT PARAMETERS:
XY - X and Y values, array[0..N-1,0..NX].
First NX columns contain X-values, last column contain
Y-values.
N - number of nodes, N>0.
NX - space dimension, NX>=1.
R - radius, R>0
OUTPUT PARAMETERS:
Z - IDW interpolant.
NOTES:
* if there is less than IDWKMin points within R-ball, algorithm selects
IDWKMin closest ones, so that continuity properties of interpolant are
preserved even far from points.
-- ALGLIB PROJECT --
Copyright 11.04.2010 by Bochkanov Sergey
*************************************************************************/
</div><div style='margin-top: 0; margin-bottom: 0;'><b>void</b> alglib::idwbuildmodifiedshepardr(
real_2d_array xy,
ae_int_t n,
ae_int_t nx,
<b>double</b> r,
idwinterpolant& z);
</div></pre>
<a name='sub_idwbuildnoisy'></a><h3 class=pageheader><code>idwbuildnoisy</code> function</h3>
<pre class=source>
<div style='color: navy; margin-top: 0; margin-bottom: 0;'>/*************************************************************************
IDW model for noisy data.
This subroutine may be used to handle noisy data, i.e. data with noise in
OUTPUT values. It differs from IDWBuildModifiedShepard() in the following
aspects:
* nodal functions are not constrained to pass through nodes: Qi(xi)<>yi,
i.e. we have fitting instead of interpolation.
* weights which are used during least squares fitting stage are all equal
to 1.0 (independently of distance)
* "fast"-linear or constant nodal functions are not supported (either not
robust enough or too rigid)
This problem require far more complex tuning than interpolation problems.
Below you can find some recommendations regarding this problem:
* focus on tuning NQ; it controls noise reduction. As for NW, you can just
make it equal to 2*NQ.
* you can use cross-validation to determine optimal NQ.
* optimal NQ is a result of complex tradeoff between noise level (more
noise = larger NQ required) and underlying function complexity (given
fixed N, larger NQ means smoothing of compex features in the data). For
example, NQ=N will reduce noise to the minimum level possible, but you
will end up with just constant/linear/quadratic (depending on D) least
squares model for the whole dataset.
INPUT PARAMETERS:
XY - X and Y values, array[0..N-1,0..NX].
First NX columns contain X-values, last column contain
Y-values.
N - number of nodes, N>0.
NX - space dimension, NX>=1.
D - nodal function degree, either:
* 1 linear model, least squares fitting. Simpe model for
datasets too small for quadratic models (or for very
noisy problems).
* 2 quadratic model, least squares fitting. Best model
available (if your dataset is large enough).
NQ - number of points used to calculate nodal functions. NQ should
be significantly larger than 1.5 times the number of
coefficients in a nodal function to overcome effects of noise:
* larger than 1.5*(1+NX) for linear model,
* larger than 3/4*(NX+2)*(NX+1) for quadratic model.
Values less than this threshold will be silently increased.
NW - number of points used to calculate weights and to interpolate.
Required: >=2^NX+1, values less than this threshold will be
silently increased.
Recommended value: about 2*NQ or larger
OUTPUT PARAMETERS:
Z - IDW interpolant.
NOTES:
* best results are obtained with quadratic models, linear models are not
recommended to use unless you are pretty sure that it is what you want
* this subroutine is always succeeds (as long as correct parameters are
passed).
* see 'Multivariate Interpolation of Large Sets of Scattered Data' by
Robert J. Renka for more information on this algorithm.
-- ALGLIB PROJECT --
Copyright 02.03.2010 by Bochkanov Sergey
*************************************************************************/
</div><div style='margin-top: 0; margin-bottom: 0;'><b>void</b> alglib::idwbuildnoisy(
real_2d_array xy,
ae_int_t n,
ae_int_t nx,
ae_int_t d,
ae_int_t nq,
ae_int_t nw,
idwinterpolant& z);
</div></pre>
<a name='sub_idwcalc'></a><h3 class=pageheader><code>idwcalc</code> function</h3>
<pre class=source>
<div style='color: navy; margin-top: 0; margin-bottom: 0;'>/*************************************************************************
IDW interpolation
INPUT PARAMETERS:
Z - IDW interpolant built with one of model building
subroutines.
X - array[0..NX-1], interpolation point
Result:
IDW interpolant Z(X)
-- ALGLIB --
Copyright 02.03.2010 by Bochkanov Sergey
*************************************************************************/
</div><div style='margin-top: 0; margin-bottom: 0;'><b>double</b> alglib::idwcalc(idwinterpolant z, real_1d_array x);
</div></pre>
<a name=unit_igammaf></a><h2 class=pageheader><code>igammaf</code> subpackage</h2>
<div class=pagecontent>
<h3 class=pageheader>Functions</h3>
<a href='#sub_incompletegamma' class=toc>incompletegamma</a><br>
<a href='#sub_incompletegammac' class=toc>incompletegammac</a><br>
<a href='#sub_invincompletegammac' class=toc>invincompletegammac</a><br>
<h3 class=pageheader>Examples</h3>
<table border=0 cellspacing=0 class='pagecontent'>
</table></div>
<a name='sub_incompletegamma'></a><h3 class=pageheader><code>incompletegamma</code> function</h3>
<pre class=source>
<div style='color: navy; margin-top: 0; margin-bottom: 0;'>/*************************************************************************
Incomplete gamma integral
The function is defined by
x
-
1 | | -t a-1
igam(a,x) = ----- | e t dt.
- | |
| (a) -
0
In this implementation both arguments must be positive.
The integral is evaluated by either a power series or
continued fraction expansion, depending on the relative
values of a and x.
ACCURACY:
Relative error:
arithmetic domain # trials peak rms
IEEE 0,30 200000 3.6e-14 2.9e-15
IEEE 0,100 300000 9.9e-14 1.5e-14
Cephes Math Library Release 2.8: June, 2000
Copyright 1985, 1987, 2000 by Stephen L. Moshier
*************************************************************************/
</div><div style='margin-top: 0; margin-bottom: 0;'><b>double</b> alglib::incompletegamma(<b>double</b> a, <b>double</b> x);
</div></pre>
<a name='sub_incompletegammac'></a><h3 class=pageheader><code>incompletegammac</code> function</h3>
<pre class=source>
<div style='color: navy; margin-top: 0; margin-bottom: 0;'>/*************************************************************************
Complemented incomplete gamma integral
The function is defined by
igamc(a,x) = 1 - igam(a,x)
inf.
-
1 | | -t a-1
= ----- | e t dt.
- | |
| (a) -
x
In this implementation both arguments must be positive.
The integral is evaluated by either a power series or
continued fraction expansion, depending on the relative
values of a and x.
ACCURACY:
Tested at random a, x.
a x Relative error:
arithmetic domain domain # trials peak rms
IEEE 0.5,100 0,100 200000 1.9e-14 1.7e-15
IEEE 0.01,0.5 0,100 200000 1.4e-13 1.6e-15
Cephes Math Library Release 2.8: June, 2000
Copyright 1985, 1987, 2000 by Stephen L. Moshier
*************************************************************************/
</div><div style='margin-top: 0; margin-bottom: 0;'><b>double</b> alglib::incompletegammac(<b>double</b> a, <b>double</b> x);
</div></pre>
<a name='sub_invincompletegammac'></a><h3 class=pageheader><code>invincompletegammac</code> function</h3>
<pre class=source>
<div style='color: navy; margin-top: 0; margin-bottom: 0;'>/*************************************************************************
Inverse of complemented imcomplete gamma integral
Given p, the function finds x such that
igamc( a, x ) = p.
Starting with the approximate value
3
x = a t
where
t = 1 - d - ndtri(p) sqrt(d)
and
d = 1/9a,
the routine performs up to 10 Newton iterations to find the
root of igamc(a,x) - p = 0.
ACCURACY:
Tested at random a, p in the intervals indicated.
a p Relative error:
arithmetic domain domain # trials peak rms
IEEE 0.5,100 0,0.5 100000 1.0e-14 1.7e-15
IEEE 0.01,0.5 0,0.5 100000 9.0e-14 3.4e-15
IEEE 0.5,10000 0,0.5 20000 2.3e-13 3.8e-14
Cephes Math Library Release 2.8: June, 2000
Copyright 1984, 1987, 1995, 2000 by Stephen L. Moshier
*************************************************************************/
</div><div style='margin-top: 0; margin-bottom: 0;'><b>double</b> alglib::invincompletegammac(<b>double</b> a, <b>double</b> y0);
</div></pre>
<a name=unit_inverseupdate></a><h2 class=pageheader><code>inverseupdate</code> subpackage</h2>
<div class=pagecontent>
<h3 class=pageheader>Functions</h3>
<a href='#sub_rmatrixinvupdatecolumn' class=toc>rmatrixinvupdatecolumn</a><br>
<a href='#sub_rmatrixinvupdaterow' class=toc>rmatrixinvupdaterow</a><br>
<a href='#sub_rmatrixinvupdatesimple' class=toc>rmatrixinvupdatesimple</a><br>
<a href='#sub_rmatrixinvupdateuv' class=toc>rmatrixinvupdateuv</a><br>
<h3 class=pageheader>Examples</h3>
<table border=0 cellspacing=0 class='pagecontent'>
</table></div>
<a name='sub_rmatrixinvupdatecolumn'></a><h3 class=pageheader><code>rmatrixinvupdatecolumn</code> function</h3>
<pre class=source>
<div style='color: navy; margin-top: 0; margin-bottom: 0;'>/*************************************************************************
Inverse matrix update by the Sherman-Morrison formula
The algorithm updates matrix A^-1 when adding a vector to a column
of matrix A.
Input parameters:
InvA - inverse of matrix A.
Array whose indexes range within [0..N-1, 0..N-1].
N - size of matrix A.
UpdColumn - the column of A whose vector U was added.
0 <= UpdColumn <= N-1
U - the vector to be added to a column.
Array whose index ranges within [0..N-1].
Output parameters:
InvA - inverse of modified matrix A.
-- ALGLIB --
Copyright 2005 by Bochkanov Sergey
*************************************************************************/
</div><div style='margin-top: 0; margin-bottom: 0;'><b>void</b> alglib::rmatrixinvupdatecolumn(
real_2d_array& inva,
ae_int_t n,
ae_int_t updcolumn,
real_1d_array u);
</div></pre>
<a name='sub_rmatrixinvupdaterow'></a><h3 class=pageheader><code>rmatrixinvupdaterow</code> function</h3>
<pre class=source>
<div style='color: navy; margin-top: 0; margin-bottom: 0;'>/*************************************************************************
Inverse matrix update by the Sherman-Morrison formula
The algorithm updates matrix A^-1 when adding a vector to a row
of matrix A.
Input parameters:
InvA - inverse of matrix A.
Array whose indexes range within [0..N-1, 0..N-1].
N - size of matrix A.
UpdRow - the row of A whose vector V was added.
0 <= Row <= N-1
V - the vector to be added to a row.
Array whose index ranges within [0..N-1].
Output parameters:
InvA - inverse of modified matrix A.
-- ALGLIB --
Copyright 2005 by Bochkanov Sergey
*************************************************************************/
</div><div style='margin-top: 0; margin-bottom: 0;'><b>void</b> alglib::rmatrixinvupdaterow(
real_2d_array& inva,
ae_int_t n,
ae_int_t updrow,
real_1d_array v);
</div></pre>
<a name='sub_rmatrixinvupdatesimple'></a><h3 class=pageheader><code>rmatrixinvupdatesimple</code> function</h3>
<pre class=source>
<div style='color: navy; margin-top: 0; margin-bottom: 0;'>/*************************************************************************
Inverse matrix update by the Sherman-Morrison formula
The algorithm updates matrix A^-1 when adding a number to an element
of matrix A.
Input parameters:
InvA - inverse of matrix A.
Array whose indexes range within [0..N-1, 0..N-1].
N - size of matrix A.
UpdRow - row where the element to be updated is stored.
UpdColumn - column where the element to be updated is stored.
UpdVal - a number to be added to the element.
Output parameters:
InvA - inverse of modified matrix A.
-- ALGLIB --
Copyright 2005 by Bochkanov Sergey
*************************************************************************/
</div><div style='margin-top: 0; margin-bottom: 0;'><b>void</b> alglib::rmatrixinvupdatesimple(
real_2d_array& inva,
ae_int_t n,
ae_int_t updrow,
ae_int_t updcolumn,
<b>double</b> updval);
</div></pre>
<a name='sub_rmatrixinvupdateuv'></a><h3 class=pageheader><code>rmatrixinvupdateuv</code> function</h3>
<pre class=source>
<div style='color: navy; margin-top: 0; margin-bottom: 0;'>/*************************************************************************
Inverse matrix update by the Sherman-Morrison formula
The algorithm computes the inverse of matrix A+u*v� by using the given matrix
A^-1 and the vectors u and v.
Input parameters:
InvA - inverse of matrix A.
Array whose indexes range within [0..N-1, 0..N-1].
N - size of matrix A.
U - the vector modifying the matrix.
Array whose index ranges within [0..N-1].
V - the vector modifying the matrix.
Array whose index ranges within [0..N-1].
Output parameters:
InvA - inverse of matrix A + u*v'.
-- ALGLIB --
Copyright 2005 by Bochkanov Sergey
*************************************************************************/
</div><div style='margin-top: 0; margin-bottom: 0;'><b>void</b> alglib::rmatrixinvupdateuv(
real_2d_array& inva,
ae_int_t n,
real_1d_array u,
real_1d_array v);
</div></pre>
<a name=unit_jacobianelliptic></a><h2 class=pageheader><code>jacobianelliptic</code> subpackage</h2>
<div class=pagecontent>
<h3 class=pageheader>Functions</h3>
<a href='#sub_jacobianellipticfunctions' class=toc>jacobianellipticfunctions</a><br>
<h3 class=pageheader>Examples</h3>
<table border=0 cellspacing=0 class='pagecontent'>
</table></div>
<a name='sub_jacobianellipticfunctions'></a><h3 class=pageheader><code>jacobianellipticfunctions</code> function</h3>
<pre class=source>
<div style='color: navy; margin-top: 0; margin-bottom: 0;'>/*************************************************************************
Jacobian Elliptic Functions
Evaluates the Jacobian elliptic functions sn(u|m), cn(u|m),
and dn(u|m) of parameter m between 0 and 1, and real
argument u.
These functions are periodic, with quarter-period on the
real axis equal to the complete elliptic integral
ellpk(1.0-m).
Relation to incomplete elliptic integral:
If u = ellik(phi,m), then sn(u|m) = sin(phi),
and cn(u|m) = cos(phi). Phi is called the amplitude of u.
Computation is by means of the arithmetic-geometric mean
algorithm, except when m is within 1e-9 of 0 or 1. In the
latter case with m close to 1, the approximation applies
only for phi < pi/2.
ACCURACY:
Tested at random points with u between 0 and 10, m between
0 and 1.
Absolute error (* = relative error):
arithmetic function # trials peak rms
IEEE phi 10000 9.2e-16* 1.4e-16*
IEEE sn 50000 4.1e-15 4.6e-16
IEEE cn 40000 3.6e-15 4.4e-16
IEEE dn 10000 1.3e-12 1.8e-14
Peak error observed in consistency check using addition
theorem for sn(u+v) was 4e-16 (absolute). Also tested by
the above relation to the incomplete elliptic integral.
Accuracy deteriorates when u is large.
Cephes Math Library Release 2.8: June, 2000
Copyright 1984, 1987, 2000 by Stephen L. Moshier
*************************************************************************/
</div><div style='margin-top: 0; margin-bottom: 0;'><b>void</b> alglib::jacobianellipticfunctions(
<b>double</b> u,
<b>double</b> m,
<b>double</b>& sn,
<b>double</b>& cn,
<b>double</b>& dn,
<b>double</b>& ph);
</div></pre>
<a name=unit_jarquebera></a><h2 class=pageheader><code>jarquebera</code> subpackage</h2>
<div class=pagecontent>
<h3 class=pageheader>Functions</h3>
<a href='#sub_jarqueberatest' class=toc>jarqueberatest</a><br>
<h3 class=pageheader>Examples</h3>
<table border=0 cellspacing=0 class='pagecontent'>
</table></div>
<a name='sub_jarqueberatest'></a><h3 class=pageheader><code>jarqueberatest</code> function</h3>
<pre class=source>
<div style='color: navy; margin-top: 0; margin-bottom: 0;'>/*************************************************************************
Jarque-Bera test
This test checks hypotheses about the fact that a given sample X is a
sample of normal random variable.
Requirements:
* the number of elements in the sample is not less than 5.
Input parameters:
X - sample. Array whose index goes from 0 to N-1.
N - size of the sample. N>=5
Output parameters:
P - p-value for the test
Accuracy of the approximation used (5<=N<=1951):
p-value relative error (5<=N<=1951)
[1, 0.1] < 1%
[0.1, 0.01] < 2%
[0.01, 0.001] < 6%
[0.001, 0] wasn't measured
For N>1951 accuracy wasn't measured but it shouldn't be sharply different
from table values.
-- ALGLIB --
Copyright 09.04.2007 by Bochkanov Sergey
*************************************************************************/
</div><div style='margin-top: 0; margin-bottom: 0;'><b>void</b> alglib::jarqueberatest(real_1d_array x, ae_int_t n, <b>double</b>& p);
</div></pre>
<a name=unit_laguerre></a><h2 class=pageheader><code>laguerre</code> subpackage</h2>
<div class=pagecontent>
<h3 class=pageheader>Functions</h3>
<a href='#sub_laguerrecalculate' class=toc>laguerrecalculate</a><br>
<a href='#sub_laguerrecoefficients' class=toc>laguerrecoefficients</a><br>
<a href='#sub_laguerresum' class=toc>laguerresum</a><br>
<h3 class=pageheader>Examples</h3>
<table border=0 cellspacing=0 class='pagecontent'>
</table></div>
<a name='sub_laguerrecalculate'></a><h3 class=pageheader><code>laguerrecalculate</code> function</h3>
<pre class=source>
<div style='color: navy; margin-top: 0; margin-bottom: 0;'>/*************************************************************************
Calculation of the value of the Laguerre polynomial.
Parameters:
n - degree, n>=0
x - argument
Result:
the value of the Laguerre polynomial Ln at x
*************************************************************************/
</div><div style='margin-top: 0; margin-bottom: 0;'><b>double</b> alglib::laguerrecalculate(ae_int_t n, <b>double</b> x);
</div></pre>
<a name='sub_laguerrecoefficients'></a><h3 class=pageheader><code>laguerrecoefficients</code> function</h3>
<pre class=source>
<div style='color: navy; margin-top: 0; margin-bottom: 0;'>/*************************************************************************
Representation of Ln as C[0] + C[1]*X + ... + C[N]*X^N
Input parameters:
N - polynomial degree, n>=0
Output parameters:
C - coefficients
*************************************************************************/
</div><div style='margin-top: 0; margin-bottom: 0;'><b>void</b> alglib::laguerrecoefficients(ae_int_t n, real_1d_array& c);
</div></pre>
<a name='sub_laguerresum'></a><h3 class=pageheader><code>laguerresum</code> function</h3>
<pre class=source>
<div style='color: navy; margin-top: 0; margin-bottom: 0;'>/*************************************************************************
Summation of Laguerre polynomials using Clenshaw�s recurrence formula.
This routine calculates c[0]*L0(x) + c[1]*L1(x) + ... + c[N]*LN(x)
Parameters:
n - degree, n>=0
x - argument
Result:
the value of the Laguerre polynomial at x
*************************************************************************/
</div><div style='margin-top: 0; margin-bottom: 0;'><b>double</b> alglib::laguerresum(real_1d_array c, ae_int_t n, <b>double</b> x);
</div></pre>
<a name=unit_lda></a><h2 class=pageheader><code>lda</code> subpackage</h2>
<div class=pagecontent>
<h3 class=pageheader>Functions</h3>
<a href='#sub_fisherlda' class=toc>fisherlda</a><br>
<a href='#sub_fisherldan' class=toc>fisherldan</a><br>
<h3 class=pageheader>Examples</h3>
<table border=0 cellspacing=0 class='pagecontent'>
</table></div>
<a name='sub_fisherlda'></a><h3 class=pageheader><code>fisherlda</code> function</h3>
<pre class=source>
<div style='color: navy; margin-top: 0; margin-bottom: 0;'>/*************************************************************************
Multiclass Fisher LDA
Subroutine finds coefficients of linear combination which optimally separates
training set on classes.
COMMERCIAL EDITION OF ALGLIB:
! Commercial version of ALGLIB includes two important improvements of
! this function, which can be used from C++ and C#:
! * Intel MKL support (lightweight Intel MKL is shipped with ALGLIB)
! * multithreading support
!
! Intel MKL gives approximately constant (with respect to number of
! worker threads) acceleration factor which depends on CPU being used,
! problem size and "baseline" ALGLIB edition which is used for
! comparison. Best results are achieved for high-dimensional problems
! (NVars is at least 256).
!
! Multithreading is used to accelerate initial phase of LDA, which
! includes calculation of products of large matrices. Again, for best
! efficiency problem must be high-dimensional.
!
! Generally, commercial ALGLIB is several times faster than open-source
! generic C edition, and many times faster than open-source C# edition.
!
! We recommend you to read 'Working with commercial version' section of
! ALGLIB Reference Manual in order to find out how to use performance-
! related features provided by commercial edition of ALGLIB.
INPUT PARAMETERS:
XY - training set, array[0..NPoints-1,0..NVars].
First NVars columns store values of independent
variables, next column stores number of class (from 0
to NClasses-1) which dataset element belongs to. Fractional
values are rounded to nearest integer.
NPoints - training set size, NPoints>=0
NVars - number of independent variables, NVars>=1
NClasses - number of classes, NClasses>=2
OUTPUT PARAMETERS:
Info - return code:
* -4, if internal EVD subroutine hasn't converged
* -2, if there is a point with class number
outside of [0..NClasses-1].
* -1, if incorrect parameters was passed (NPoints<0,
NVars<1, NClasses<2)
* 1, if task has been solved
* 2, if there was a multicollinearity in training set,
but task has been solved.
W - linear combination coefficients, array[0..NVars-1]
-- ALGLIB --
Copyright 31.05.2008 by Bochkanov Sergey
*************************************************************************/
</div><div style='margin-top: 0; margin-bottom: 0;'><b>void</b> alglib::fisherlda(
real_2d_array xy,
ae_int_t npoints,
ae_int_t nvars,
ae_int_t nclasses,
ae_int_t& info,
real_1d_array& w);
</div></pre>
<a name='sub_fisherldan'></a><h3 class=pageheader><code>fisherldan</code> function</h3>
<pre class=source>
<div style='color: navy; margin-top: 0; margin-bottom: 0;'>/*************************************************************************
N-dimensional multiclass Fisher LDA
Subroutine finds coefficients of linear combinations which optimally separates
training set on classes. It returns N-dimensional basis whose vector are sorted
by quality of training set separation (in descending order).
COMMERCIAL EDITION OF ALGLIB:
! Commercial version of ALGLIB includes two important improvements of
! this function, which can be used from C++ and C#:
! * Intel MKL support (lightweight Intel MKL is shipped with ALGLIB)
! * multithreading support
!
! Intel MKL gives approximately constant (with respect to number of
! worker threads) acceleration factor which depends on CPU being used,
! problem size and "baseline" ALGLIB edition which is used for
! comparison. Best results are achieved for high-dimensional problems
! (NVars is at least 256).
!
! Multithreading is used to accelerate initial phase of LDA, which
! includes calculation of products of large matrices. Again, for best
! efficiency problem must be high-dimensional.
!
! Generally, commercial ALGLIB is several times faster than open-source
! generic C edition, and many times faster than open-source C# edition.
!
! We recommend you to read 'Working with commercial version' section of
! ALGLIB Reference Manual in order to find out how to use performance-
! related features provided by commercial edition of ALGLIB.
INPUT PARAMETERS:
XY - training set, array[0..NPoints-1,0..NVars].
First NVars columns store values of independent
variables, next column stores number of class (from 0
to NClasses-1) which dataset element belongs to. Fractional
values are rounded to nearest integer.
NPoints - training set size, NPoints>=0
NVars - number of independent variables, NVars>=1
NClasses - number of classes, NClasses>=2
OUTPUT PARAMETERS:
Info - return code:
* -4, if internal EVD subroutine hasn't converged
* -2, if there is a point with class number
outside of [0..NClasses-1].
* -1, if incorrect parameters was passed (NPoints<0,
NVars<1, NClasses<2)
* 1, if task has been solved
* 2, if there was a multicollinearity in training set,
but task has been solved.
W - basis, array[0..NVars-1,0..NVars-1]
columns of matrix stores basis vectors, sorted by
quality of training set separation (in descending order)
-- ALGLIB --
Copyright 31.05.2008 by Bochkanov Sergey
*************************************************************************/
</div><div style='margin-top: 0; margin-bottom: 0;'><b>void</b> alglib::fisherldan(
real_2d_array xy,
ae_int_t npoints,
ae_int_t nvars,
ae_int_t nclasses,
ae_int_t& info,
real_2d_array& w);
<b>void</b> alglib::smp_fisherldan(
real_2d_array xy,
ae_int_t npoints,
ae_int_t nvars,
ae_int_t nclasses,
ae_int_t& info,
real_2d_array& w);
</div></pre>
<a name=unit_legendre></a><h2 class=pageheader><code>legendre</code> subpackage</h2>
<div class=pagecontent>
<h3 class=pageheader>Functions</h3>
<a href='#sub_legendrecalculate' class=toc>legendrecalculate</a><br>
<a href='#sub_legendrecoefficients' class=toc>legendrecoefficients</a><br>
<a href='#sub_legendresum' class=toc>legendresum</a><br>
<h3 class=pageheader>Examples</h3>
<table border=0 cellspacing=0 class='pagecontent'>
</table></div>
<a name='sub_legendrecalculate'></a><h3 class=pageheader><code>legendrecalculate</code> function</h3>
<pre class=source>
<div style='color: navy; margin-top: 0; margin-bottom: 0;'>/*************************************************************************
Calculation of the value of the Legendre polynomial Pn.
Parameters:
n - degree, n>=0
x - argument
Result:
the value of the Legendre polynomial Pn at x
*************************************************************************/
</div><div style='margin-top: 0; margin-bottom: 0;'><b>double</b> alglib::legendrecalculate(ae_int_t n, <b>double</b> x);
</div></pre>
<a name='sub_legendrecoefficients'></a><h3 class=pageheader><code>legendrecoefficients</code> function</h3>
<pre class=source>
<div style='color: navy; margin-top: 0; margin-bottom: 0;'>/*************************************************************************
Representation of Pn as C[0] + C[1]*X + ... + C[N]*X^N
Input parameters:
N - polynomial degree, n>=0
Output parameters:
C - coefficients
*************************************************************************/
</div><div style='margin-top: 0; margin-bottom: 0;'><b>void</b> alglib::legendrecoefficients(ae_int_t n, real_1d_array& c);
</div></pre>
<a name='sub_legendresum'></a><h3 class=pageheader><code>legendresum</code> function</h3>
<pre class=source>
<div style='color: navy; margin-top: 0; margin-bottom: 0;'>/*************************************************************************
Summation of Legendre polynomials using Clenshaw�s recurrence formula.
This routine calculates
c[0]*P0(x) + c[1]*P1(x) + ... + c[N]*PN(x)
Parameters:
n - degree, n>=0
x - argument
Result:
the value of the Legendre polynomial at x
*************************************************************************/
</div><div style='margin-top: 0; margin-bottom: 0;'><b>double</b> alglib::legendresum(real_1d_array c, ae_int_t n, <b>double</b> x);
</div></pre>
<a name=unit_lincg></a><h2 class=pageheader><code>lincg</code> subpackage</h2>
<div class=pagecontent>
<h3 class=pageheader>Classes</h3>
<a href='#struct_lincgreport' class=toc>lincgreport</a><br>
<a href='#struct_lincgstate' class=toc>lincgstate</a><br>
<h3 class=pageheader>Functions</h3>
<a href='#sub_lincgcreate' class=toc>lincgcreate</a><br>
<a href='#sub_lincgresults' class=toc>lincgresults</a><br>
<a href='#sub_lincgsetcond' class=toc>lincgsetcond</a><br>
<a href='#sub_lincgsetprecdiag' class=toc>lincgsetprecdiag</a><br>
<a href='#sub_lincgsetprecunit' class=toc>lincgsetprecunit</a><br>
<a href='#sub_lincgsetrestartfreq' class=toc>lincgsetrestartfreq</a><br>
<a href='#sub_lincgsetrupdatefreq' class=toc>lincgsetrupdatefreq</a><br>
<a href='#sub_lincgsetstartingpoint' class=toc>lincgsetstartingpoint</a><br>
<a href='#sub_lincgsetxrep' class=toc>lincgsetxrep</a><br>
<a href='#sub_lincgsolvesparse' class=toc>lincgsolvesparse</a><br>
<h3 class=pageheader>Examples</h3>
<table border=0 cellspacing=0 class='pagecontent'>
<tr align=left valign=top><td><a href='#example_lincg_d_1' class=toc>lincg_d_1</a></td><td width=15> </td><td>Solution of sparse linear systems with CG</td></tr>
</table></div>
<a name='struct_lincgreport'></a><h3 class=pageheader><code>lincgreport</code> class</h3>
<pre class=source>
<div style='color: navy; margin-top: 0; margin-bottom: 0;'>/*************************************************************************
*************************************************************************/
</div><div style='margin-top: 0; margin-bottom: 0;'><b>class</b> lincgreport
{
ae_int_t iterationscount;
ae_int_t nmv;
ae_int_t terminationtype;
<b>double</b> r2;
};
</div></pre>
<a name='struct_lincgstate'></a><h3 class=pageheader><code>lincgstate</code> class</h3>
<pre class=source>
<div style='color: navy; margin-top: 0; margin-bottom: 0;'>/*************************************************************************
This object stores state of the linear CG method.
You should use ALGLIB functions to work with this object.
Never try to access its fields directly!
*************************************************************************/
</div><div style='margin-top: 0; margin-bottom: 0;'><b>class</b> lincgstate
{
};
</div></pre>
<a name='sub_lincgcreate'></a><h3 class=pageheader><code>lincgcreate</code> function</h3>
<pre class=source>
<div style='color: navy; margin-top: 0; margin-bottom: 0;'>/*************************************************************************
This function initializes linear CG Solver. This solver is used to solve
symmetric positive definite problems. If you want to solve nonsymmetric
(or non-positive definite) problem you may use LinLSQR solver provided by
ALGLIB.
USAGE:
1. User initializes algorithm state with LinCGCreate() call
2. User tunes solver parameters with LinCGSetCond() and other functions
3. Optionally, user sets starting point with LinCGSetStartingPoint()
4. User calls LinCGSolveSparse() function which takes algorithm state and
SparseMatrix object.
5. User calls LinCGResults() to get solution
6. Optionally, user may call LinCGSolveSparse() again to solve another
problem with different matrix and/or right part without reinitializing
LinCGState structure.
INPUT PARAMETERS:
N - problem dimension, N>0
OUTPUT PARAMETERS:
State - structure which stores algorithm state
-- ALGLIB --
Copyright 14.11.2011 by Bochkanov Sergey
*************************************************************************/
</div><div style='margin-top: 0; margin-bottom: 0;'><b>void</b> alglib::lincgcreate(ae_int_t n, lincgstate& state);
</div></pre>
<p align=left class=pagecontent><span class=inlineheader>Examples:</span> <a href='#example_lincg_d_1' class=nav>[1]</a> </p>
<a name='sub_lincgresults'></a><h3 class=pageheader><code>lincgresults</code> function</h3>
<pre class=source>
<div style='color: navy; margin-top: 0; margin-bottom: 0;'>/*************************************************************************
CG-solver: results.
This function must be called after LinCGSolve
INPUT PARAMETERS:
State - algorithm state
OUTPUT PARAMETERS:
X - array[N], solution
Rep - optimization report:
* Rep.TerminationType completetion code:
* -5 input matrix is either not positive definite,
too large or too small
* -4 overflow/underflow during solution
(ill conditioned problem)
* 1 ||residual||<=EpsF*||b||
* 5 MaxIts steps was taken
* 7 rounding errors prevent further progress,
best point found is returned
* Rep.IterationsCount contains iterations count
* NMV countains number of matrix-vector calculations
-- ALGLIB --
Copyright 14.11.2011 by Bochkanov Sergey
*************************************************************************/
</div><div style='margin-top: 0; margin-bottom: 0;'><b>void</b> alglib::lincgresults(
lincgstate state,
real_1d_array& x,
lincgreport& rep);
</div></pre>
<p align=left class=pagecontent><span class=inlineheader>Examples:</span> <a href='#example_lincg_d_1' class=nav>[1]</a> </p>
<a name='sub_lincgsetcond'></a><h3 class=pageheader><code>lincgsetcond</code> function</h3>
<pre class=source>
<div style='color: navy; margin-top: 0; margin-bottom: 0;'>/*************************************************************************
This function sets stopping criteria.
INPUT PARAMETERS:
EpsF - algorithm will be stopped if norm of residual is less than
EpsF*||b||.
MaxIts - algorithm will be stopped if number of iterations is more
than MaxIts.
OUTPUT PARAMETERS:
State - structure which stores algorithm state
NOTES:
If both EpsF and MaxIts are zero then small EpsF will be set to small
value.
-- ALGLIB --
Copyright 14.11.2011 by Bochkanov Sergey
*************************************************************************/
</div><div style='margin-top: 0; margin-bottom: 0;'><b>void</b> alglib::lincgsetcond(lincgstate state, <b>double</b> epsf, ae_int_t maxits);
</div></pre>
<a name='sub_lincgsetprecdiag'></a><h3 class=pageheader><code>lincgsetprecdiag</code> function</h3>
<pre class=source>
<div style='color: navy; margin-top: 0; margin-bottom: 0;'>/*************************************************************************
This function changes preconditioning settings of LinCGSolveSparse()
function. LinCGSolveSparse() will use diagonal of the system matrix as
preconditioner. This preconditioning mode is active by default.
INPUT PARAMETERS:
State - structure which stores algorithm state
-- ALGLIB --
Copyright 19.11.2012 by Bochkanov Sergey
*************************************************************************/
</div><div style='margin-top: 0; margin-bottom: 0;'><b>void</b> alglib::lincgsetprecdiag(lincgstate state);
</div></pre>
<a name='sub_lincgsetprecunit'></a><h3 class=pageheader><code>lincgsetprecunit</code> function</h3>
<pre class=source>
<div style='color: navy; margin-top: 0; margin-bottom: 0;'>/*************************************************************************
This function changes preconditioning settings of LinCGSolveSparse()
function. By default, SolveSparse() uses diagonal preconditioner, but if
you want to use solver without preconditioning, you can call this function
which forces solver to use unit matrix for preconditioning.
INPUT PARAMETERS:
State - structure which stores algorithm state
-- ALGLIB --
Copyright 19.11.2012 by Bochkanov Sergey
*************************************************************************/
</div><div style='margin-top: 0; margin-bottom: 0;'><b>void</b> alglib::lincgsetprecunit(lincgstate state);
</div></pre>
<a name='sub_lincgsetrestartfreq'></a><h3 class=pageheader><code>lincgsetrestartfreq</code> function</h3>
<pre class=source>
<div style='color: navy; margin-top: 0; margin-bottom: 0;'>/*************************************************************************
This function sets restart frequency. By default, algorithm is restarted
after N subsequent iterations.
-- ALGLIB --
Copyright 14.11.2011 by Bochkanov Sergey
*************************************************************************/
</div><div style='margin-top: 0; margin-bottom: 0;'><b>void</b> alglib::lincgsetrestartfreq(lincgstate state, ae_int_t srf);
</div></pre>
<a name='sub_lincgsetrupdatefreq'></a><h3 class=pageheader><code>lincgsetrupdatefreq</code> function</h3>
<pre class=source>
<div style='color: navy; margin-top: 0; margin-bottom: 0;'>/*************************************************************************
This function sets frequency of residual recalculations.
Algorithm updates residual r_k using iterative formula, but recalculates
it from scratch after each 10 iterations. It is done to avoid accumulation
of numerical errors and to stop algorithm when r_k starts to grow.
Such low update frequence (1/10) gives very little overhead, but makes
algorithm a bit more robust against numerical errors. However, you may
change it
INPUT PARAMETERS:
Freq - desired update frequency, Freq>=0.
Zero value means that no updates will be done.
-- ALGLIB --
Copyright 14.11.2011 by Bochkanov Sergey
*************************************************************************/
</div><div style='margin-top: 0; margin-bottom: 0;'><b>void</b> alglib::lincgsetrupdatefreq(lincgstate state, ae_int_t freq);
</div></pre>
<a name='sub_lincgsetstartingpoint'></a><h3 class=pageheader><code>lincgsetstartingpoint</code> function</h3>
<pre class=source>
<div style='color: navy; margin-top: 0; margin-bottom: 0;'>/*************************************************************************
This function sets starting point.
By default, zero starting point is used.
INPUT PARAMETERS:
X - starting point, array[N]
OUTPUT PARAMETERS:
State - structure which stores algorithm state
-- ALGLIB --
Copyright 14.11.2011 by Bochkanov Sergey
*************************************************************************/
</div><div style='margin-top: 0; margin-bottom: 0;'><b>void</b> alglib::lincgsetstartingpoint(lincgstate state, real_1d_array x);
</div></pre>
<a name='sub_lincgsetxrep'></a><h3 class=pageheader><code>lincgsetxrep</code> function</h3>
<pre class=source>
<div style='color: navy; margin-top: 0; margin-bottom: 0;'>/*************************************************************************
This function turns on/off reporting.
INPUT PARAMETERS:
State - structure which stores algorithm state
NeedXRep- whether iteration reports are needed or not
If NeedXRep is True, algorithm will call rep() callback function if it is
provided to MinCGOptimize().
-- ALGLIB --
Copyright 14.11.2011 by Bochkanov Sergey
*************************************************************************/
</div><div style='margin-top: 0; margin-bottom: 0;'><b>void</b> alglib::lincgsetxrep(lincgstate state, <b>bool</b> needxrep);
</div></pre>
<a name='sub_lincgsolvesparse'></a><h3 class=pageheader><code>lincgsolvesparse</code> function</h3>
<pre class=source>
<div style='color: navy; margin-top: 0; margin-bottom: 0;'>/*************************************************************************
Procedure for solution of A*x=b with sparse A.
INPUT PARAMETERS:
State - algorithm state
A - sparse matrix in the CRS format (you MUST contvert it to
CRS format by calling SparseConvertToCRS() function).
IsUpper - whether upper or lower triangle of A is used:
* IsUpper=True => only upper triangle is used and lower
triangle is not referenced at all
* IsUpper=False => only lower triangle is used and upper
triangle is not referenced at all
B - right part, array[N]
RESULT:
This function returns no result.
You can get solution by calling LinCGResults()
NOTE: this function uses lightweight preconditioning - multiplication by
inverse of diag(A). If you want, you can turn preconditioning off by
calling LinCGSetPrecUnit(). However, preconditioning cost is low and
preconditioner is very important for solution of badly scaled
problems.
-- ALGLIB --
Copyright 14.11.2011 by Bochkanov Sergey
*************************************************************************/
</div><div style='margin-top: 0; margin-bottom: 0;'><b>void</b> alglib::lincgsolvesparse(
lincgstate state,
sparsematrix a,
<b>bool</b> isupper,
real_1d_array b);
</div></pre>
<p align=left class=pagecontent><span class=inlineheader>Examples:</span> <a href='#example_lincg_d_1' class=nav>[1]</a> </p>
<a name='example_lincg_d_1'></a><h3 class=pageheader>lincg_d_1 example</h3>
<pre class=source>
#include <font color=blue><b>"stdafx.h"</b></font>
#include <stdlib.h>
#include <stdio.h>
#include <math.h>
#include <font color=blue><b>"solvers.h"</b></font>
using namespace alglib;
<b>int</b> main(<b>int</b> argc, char **argv)
{
<font color=navy>//</font>
<font color=navy>// This example illustrates solution of sparse linear systems with</font>
<font color=navy>// conjugate gradient method.</font>
<font color=navy>// </font>
<font color=navy>// Suppose that we have linear system A*x=b with sparse symmetric</font>
<font color=navy>// positive definite A (represented by sparsematrix object)</font>
<font color=navy>// [ 5 1 ]</font>
<font color=navy>// [ 1 7 2 ]</font>
<font color=navy>// A = [ 2 8 1 ]</font>
<font color=navy>// [ 1 4 1 ]</font>
<font color=navy>// [ 1 4 ]</font>
<font color=navy>// and right part b</font>
<font color=navy>// [ 7 ]</font>
<font color=navy>// [ 17 ]</font>
<font color=navy>// b = [ 14 ]</font>
<font color=navy>// [ 10 ]</font>
<font color=navy>// [ 6 ]</font>
<font color=navy>// and we want to solve this system using sparse linear CG. In order</font>
<font color=navy>// to <b>do</b> so, we have to create left part (sparsematrix object) and</font>
<font color=navy>// right part (dense array).</font>
<font color=navy>//</font>
<font color=navy>// Initially, sparse matrix is created in the Hash-Table format,</font>
<font color=navy>// which allows easy initialization, but <b>do</b> not allow matrix to be</font>
<font color=navy>// used in the linear solvers. So after construction you should convert</font>
<font color=navy>// sparse matrix to CRS format (one suited <b>for</b> linear operations).</font>
<font color=navy>//</font>
<font color=navy>// It is important to note that in our example we initialize full</font>
<font color=navy>// matrix A, both lower and upper triangles. However, it is symmetric</font>
<font color=navy>// and sparse solver needs just one half of the matrix. So you may</font>
<font color=navy>// save about half of the space by filling only one of the triangles.</font>
<font color=navy>//</font>
sparsematrix a;
sparsecreate(5, 5, a);
sparseset(a, 0, 0, 5.0);
sparseset(a, 0, 1, 1.0);
sparseset(a, 1, 0, 1.0);
sparseset(a, 1, 1, 7.0);
sparseset(a, 1, 2, 2.0);
sparseset(a, 2, 1, 2.0);
sparseset(a, 2, 2, 8.0);
sparseset(a, 2, 3, 1.0);
sparseset(a, 3, 2, 1.0);
sparseset(a, 3, 3, 4.0);
sparseset(a, 3, 4, 1.0);
sparseset(a, 4, 3, 1.0);
sparseset(a, 4, 4, 4.0);
<font color=navy>//</font>
<font color=navy>// Now our matrix is fully initialized, but we have to <b>do</b> one more</font>
<font color=navy>// step - convert it from Hash-Table format to CRS format (see</font>
<font color=navy>// documentation on sparse matrices <b>for</b> more information about these</font>
<font color=navy>// formats).</font>
<font color=navy>//</font>
<font color=navy>// If you omit this call, ALGLIB will generate exception on the first</font>
<font color=navy>// attempt to use A in linear operations. </font>
<font color=navy>//</font>
sparseconverttocrs(a);
<font color=navy>//</font>
<font color=navy>// Initialization of the right part</font>
<font color=navy>//</font>
real_1d_array b = <font color=blue><b>"[7,17,14,10,6]"</b></font>;
<font color=navy>//</font>
<font color=navy>// Now we have to create linear solver object and to use it <b>for</b> the</font>
<font color=navy>// solution of the linear system.</font>
<font color=navy>//</font>
<font color=navy>// NOTE: lincgsolvesparse() accepts additional parameter which tells</font>
<font color=navy>// what triangle of the symmetric matrix should be used - upper</font>
<font color=navy>// or lower. Because we've filled both parts of the matrix, we</font>
<font color=navy>// can use any part - upper or lower.</font>
<font color=navy>//</font>
lincgstate s;
lincgreport rep;
real_1d_array x;
lincgcreate(5, s);
lincgsolvesparse(s, a, true, b);
lincgresults(s, x, rep);
printf(<font color=blue><b>"%d\n"</b></font>, <b>int</b>(rep.terminationtype)); <font color=navy>// EXPECTED: 1</font>
printf(<font color=blue><b>"%s\n"</b></font>, x.tostring(2).c_str()); <font color=navy>// EXPECTED: [1.000,2.000,1.000,2.000,1.000]</font>
<b>return</b> 0;
}
</pre><a name=unit_linlsqr></a><h2 class=pageheader><code>linlsqr</code> subpackage</h2>
<div class=pagecontent>
<h3 class=pageheader>Classes</h3>
<a href='#struct_linlsqrreport' class=toc>linlsqrreport</a><br>
<a href='#struct_linlsqrstate' class=toc>linlsqrstate</a><br>
<h3 class=pageheader>Functions</h3>
<a href='#sub_linlsqrcreate' class=toc>linlsqrcreate</a><br>
<a href='#sub_linlsqrresults' class=toc>linlsqrresults</a><br>
<a href='#sub_linlsqrsetcond' class=toc>linlsqrsetcond</a><br>
<a href='#sub_linlsqrsetlambdai' class=toc>linlsqrsetlambdai</a><br>
<a href='#sub_linlsqrsetprecdiag' class=toc>linlsqrsetprecdiag</a><br>
<a href='#sub_linlsqrsetprecunit' class=toc>linlsqrsetprecunit</a><br>
<a href='#sub_linlsqrsetxrep' class=toc>linlsqrsetxrep</a><br>
<a href='#sub_linlsqrsolvesparse' class=toc>linlsqrsolvesparse</a><br>
<h3 class=pageheader>Examples</h3>
<table border=0 cellspacing=0 class='pagecontent'>
<tr align=left valign=top><td><a href='#example_linlsqr_d_1' class=toc>linlsqr_d_1</a></td><td width=15> </td><td>Solution of sparse linear systems with CG</td></tr>
</table></div>
<a name='struct_linlsqrreport'></a><h3 class=pageheader><code>linlsqrreport</code> class</h3>
<pre class=source>
<div style='color: navy; margin-top: 0; margin-bottom: 0;'>/*************************************************************************
*************************************************************************/
</div><div style='margin-top: 0; margin-bottom: 0;'><b>class</b> linlsqrreport
{
ae_int_t iterationscount;
ae_int_t nmv;
ae_int_t terminationtype;
};
</div></pre>
<a name='struct_linlsqrstate'></a><h3 class=pageheader><code>linlsqrstate</code> class</h3>
<pre class=source>
<div style='color: navy; margin-top: 0; margin-bottom: 0;'>/*************************************************************************
This object stores state of the LinLSQR method.
You should use ALGLIB functions to work with this object.
*************************************************************************/
</div><div style='margin-top: 0; margin-bottom: 0;'><b>class</b> linlsqrstate
{
};
</div></pre>
<a name='sub_linlsqrcreate'></a><h3 class=pageheader><code>linlsqrcreate</code> function</h3>
<pre class=source>
<div style='color: navy; margin-top: 0; margin-bottom: 0;'>/*************************************************************************
This function initializes linear LSQR Solver. This solver is used to solve
non-symmetric (and, possibly, non-square) problems. Least squares solution
is returned for non-compatible systems.
USAGE:
1. User initializes algorithm state with LinLSQRCreate() call
2. User tunes solver parameters with LinLSQRSetCond() and other functions
3. User calls LinLSQRSolveSparse() function which takes algorithm state
and SparseMatrix object.
4. User calls LinLSQRResults() to get solution
5. Optionally, user may call LinLSQRSolveSparse() again to solve another
problem with different matrix and/or right part without reinitializing
LinLSQRState structure.
INPUT PARAMETERS:
M - number of rows in A
N - number of variables, N>0
OUTPUT PARAMETERS:
State - structure which stores algorithm state
-- ALGLIB --
Copyright 30.11.2011 by Bochkanov Sergey
*************************************************************************/
</div><div style='margin-top: 0; margin-bottom: 0;'><b>void</b> alglib::linlsqrcreate(ae_int_t m, ae_int_t n, linlsqrstate& state);
</div></pre>
<p align=left class=pagecontent><span class=inlineheader>Examples:</span> <a href='#example_linlsqr_d_1' class=nav>[1]</a> </p>
<a name='sub_linlsqrresults'></a><h3 class=pageheader><code>linlsqrresults</code> function</h3>
<pre class=source>
<div style='color: navy; margin-top: 0; margin-bottom: 0;'>/*************************************************************************
LSQR solver: results.
This function must be called after LinLSQRSolve
INPUT PARAMETERS:
State - algorithm state
OUTPUT PARAMETERS:
X - array[N], solution
Rep - optimization report:
* Rep.TerminationType completetion code:
* 1 ||Rk||<=EpsB*||B||
* 4 ||A^T*Rk||/(||A||*||Rk||)<=EpsA
* 5 MaxIts steps was taken
* 7 rounding errors prevent further progress,
X contains best point found so far.
(sometimes returned on singular systems)
* Rep.IterationsCount contains iterations count
* NMV countains number of matrix-vector calculations
-- ALGLIB --
Copyright 30.11.2011 by Bochkanov Sergey
*************************************************************************/
</div><div style='margin-top: 0; margin-bottom: 0;'><b>void</b> alglib::linlsqrresults(
linlsqrstate state,
real_1d_array& x,
linlsqrreport& rep);
</div></pre>
<p align=left class=pagecontent><span class=inlineheader>Examples:</span> <a href='#example_linlsqr_d_1' class=nav>[1]</a> </p>
<a name='sub_linlsqrsetcond'></a><h3 class=pageheader><code>linlsqrsetcond</code> function</h3>
<pre class=source>
<div style='color: navy; margin-top: 0; margin-bottom: 0;'>/*************************************************************************
This function sets stopping criteria.
INPUT PARAMETERS:
EpsA - algorithm will be stopped if ||A^T*Rk||/(||A||*||Rk||)<=EpsA.
EpsB - algorithm will be stopped if ||Rk||<=EpsB*||B||
MaxIts - algorithm will be stopped if number of iterations
more than MaxIts.
OUTPUT PARAMETERS:
State - structure which stores algorithm state
NOTE: if EpsA,EpsB,EpsC and MaxIts are zero then these variables will
be setted as default values.
-- ALGLIB --
Copyright 30.11.2011 by Bochkanov Sergey
*************************************************************************/
</div><div style='margin-top: 0; margin-bottom: 0;'><b>void</b> alglib::linlsqrsetcond(
linlsqrstate state,
<b>double</b> epsa,
<b>double</b> epsb,
ae_int_t maxits);
</div></pre>
<a name='sub_linlsqrsetlambdai'></a><h3 class=pageheader><code>linlsqrsetlambdai</code> function</h3>
<pre class=source>
<div style='color: navy; margin-top: 0; margin-bottom: 0;'>/*************************************************************************
This function sets optional Tikhonov regularization coefficient.
It is zero by default.
INPUT PARAMETERS:
LambdaI - regularization factor, LambdaI>=0
OUTPUT PARAMETERS:
State - structure which stores algorithm state
-- ALGLIB --
Copyright 30.11.2011 by Bochkanov Sergey
*************************************************************************/
</div><div style='margin-top: 0; margin-bottom: 0;'><b>void</b> alglib::linlsqrsetlambdai(linlsqrstate state, <b>double</b> lambdai);
</div></pre>
<a name='sub_linlsqrsetprecdiag'></a><h3 class=pageheader><code>linlsqrsetprecdiag</code> function</h3>
<pre class=source>
<div style='color: navy; margin-top: 0; margin-bottom: 0;'>/*************************************************************************
This function changes preconditioning settings of LinCGSolveSparse()
function. LinCGSolveSparse() will use diagonal of the system matrix as
preconditioner. This preconditioning mode is active by default.
INPUT PARAMETERS:
State - structure which stores algorithm state
-- ALGLIB --
Copyright 19.11.2012 by Bochkanov Sergey
*************************************************************************/
</div><div style='margin-top: 0; margin-bottom: 0;'><b>void</b> alglib::linlsqrsetprecdiag(linlsqrstate state);
</div></pre>
<a name='sub_linlsqrsetprecunit'></a><h3 class=pageheader><code>linlsqrsetprecunit</code> function</h3>
<pre class=source>
<div style='color: navy; margin-top: 0; margin-bottom: 0;'>/*************************************************************************
This function changes preconditioning settings of LinLSQQSolveSparse()
function. By default, SolveSparse() uses diagonal preconditioner, but if
you want to use solver without preconditioning, you can call this function
which forces solver to use unit matrix for preconditioning.
INPUT PARAMETERS:
State - structure which stores algorithm state
-- ALGLIB --
Copyright 19.11.2012 by Bochkanov Sergey
*************************************************************************/
</div><div style='margin-top: 0; margin-bottom: 0;'><b>void</b> alglib::linlsqrsetprecunit(linlsqrstate state);
</div></pre>
<a name='sub_linlsqrsetxrep'></a><h3 class=pageheader><code>linlsqrsetxrep</code> function</h3>
<pre class=source>
<div style='color: navy; margin-top: 0; margin-bottom: 0;'>/*************************************************************************
This function turns on/off reporting.
INPUT PARAMETERS:
State - structure which stores algorithm state
NeedXRep- whether iteration reports are needed or not
If NeedXRep is True, algorithm will call rep() callback function if it is
provided to MinCGOptimize().
-- ALGLIB --
Copyright 30.11.2011 by Bochkanov Sergey
*************************************************************************/
</div><div style='margin-top: 0; margin-bottom: 0;'><b>void</b> alglib::linlsqrsetxrep(linlsqrstate state, <b>bool</b> needxrep);
</div></pre>
<a name='sub_linlsqrsolvesparse'></a><h3 class=pageheader><code>linlsqrsolvesparse</code> function</h3>
<pre class=source>
<div style='color: navy; margin-top: 0; margin-bottom: 0;'>/*************************************************************************
Procedure for solution of A*x=b with sparse A.
INPUT PARAMETERS:
State - algorithm state
A - sparse M*N matrix in the CRS format (you MUST contvert it
to CRS format by calling SparseConvertToCRS() function
BEFORE you pass it to this function).
B - right part, array[M]
RESULT:
This function returns no result.
You can get solution by calling LinCGResults()
NOTE: this function uses lightweight preconditioning - multiplication by
inverse of diag(A). If you want, you can turn preconditioning off by
calling LinLSQRSetPrecUnit(). However, preconditioning cost is low
and preconditioner is very important for solution of badly scaled
problems.
-- ALGLIB --
Copyright 30.11.2011 by Bochkanov Sergey
*************************************************************************/
</div><div style='margin-top: 0; margin-bottom: 0;'><b>void</b> alglib::linlsqrsolvesparse(
linlsqrstate state,
sparsematrix a,
real_1d_array b);
</div></pre>
<p align=left class=pagecontent><span class=inlineheader>Examples:</span> <a href='#example_linlsqr_d_1' class=nav>[1]</a> </p>
<a name='example_linlsqr_d_1'></a><h3 class=pageheader>linlsqr_d_1 example</h3>
<pre class=source>
#include <font color=blue><b>"stdafx.h"</b></font>
#include <stdlib.h>
#include <stdio.h>
#include <math.h>
#include <font color=blue><b>"solvers.h"</b></font>
using namespace alglib;
<b>int</b> main(<b>int</b> argc, char **argv)
{
<font color=navy>//</font>
<font color=navy>// This example illustrates solution of sparse linear least squares problem</font>
<font color=navy>// with LSQR algorithm.</font>
<font color=navy>// </font>
<font color=navy>// Suppose that we have least squares problem min|A*x-b| with sparse A</font>
<font color=navy>// represented by sparsematrix object</font>
<font color=navy>// [ 1 1 ]</font>
<font color=navy>// [ 1 1 ]</font>
<font color=navy>// A = [ 2 1 ]</font>
<font color=navy>// [ 1 ]</font>
<font color=navy>// [ 1 ]</font>
<font color=navy>// and right part b</font>
<font color=navy>// [ 4 ]</font>
<font color=navy>// [ 2 ]</font>
<font color=navy>// b = [ 4 ]</font>
<font color=navy>// [ 1 ]</font>
<font color=navy>// [ 2 ]</font>
<font color=navy>// and we want to solve this system in the least squares sense using</font>
<font color=navy>// LSQR algorithm. In order to <b>do</b> so, we have to create left part</font>
<font color=navy>// (sparsematrix object) and right part (dense array).</font>
<font color=navy>//</font>
<font color=navy>// Initially, sparse matrix is created in the Hash-Table format,</font>
<font color=navy>// which allows easy initialization, but <b>do</b> not allow matrix to be</font>
<font color=navy>// used in the linear solvers. So after construction you should convert</font>
<font color=navy>// sparse matrix to CRS format (one suited <b>for</b> linear operations).</font>
<font color=navy>//</font>
sparsematrix a;
sparsecreate(5, 2, a);
sparseset(a, 0, 0, 1.0);
sparseset(a, 0, 1, 1.0);
sparseset(a, 1, 0, 1.0);
sparseset(a, 1, 1, 1.0);
sparseset(a, 2, 0, 2.0);
sparseset(a, 2, 1, 1.0);
sparseset(a, 3, 0, 1.0);
sparseset(a, 4, 1, 1.0);
<font color=navy>//</font>
<font color=navy>// Now our matrix is fully initialized, but we have to <b>do</b> one more</font>
<font color=navy>// step - convert it from Hash-Table format to CRS format (see</font>
<font color=navy>// documentation on sparse matrices <b>for</b> more information about these</font>
<font color=navy>// formats).</font>
<font color=navy>//</font>
<font color=navy>// If you omit this call, ALGLIB will generate exception on the first</font>
<font color=navy>// attempt to use A in linear operations. </font>
<font color=navy>//</font>
sparseconverttocrs(a);
<font color=navy>//</font>
<font color=navy>// Initialization of the right part</font>
<font color=navy>//</font>
real_1d_array b = <font color=blue><b>"[4,2,4,1,2]"</b></font>;
<font color=navy>//</font>
<font color=navy>// Now we have to create linear solver object and to use it <b>for</b> the</font>
<font color=navy>// solution of the linear system.</font>
<font color=navy>//</font>
linlsqrstate s;
linlsqrreport rep;
real_1d_array x;
linlsqrcreate(5, 2, s);
linlsqrsolvesparse(s, a, b);
linlsqrresults(s, x, rep);
printf(<font color=blue><b>"%d\n"</b></font>, <b>int</b>(rep.terminationtype)); <font color=navy>// EXPECTED: 4</font>
printf(<font color=blue><b>"%s\n"</b></font>, x.tostring(2).c_str()); <font color=navy>// EXPECTED: [1.000,2.000]</font>
<b>return</b> 0;
}
</pre><a name=unit_linreg></a><h2 class=pageheader><code>linreg</code> subpackage</h2>
<div class=pagecontent>
<h3 class=pageheader>Classes</h3>
<a href='#struct_linearmodel' class=toc>linearmodel</a><br>
<a href='#struct_lrreport' class=toc>lrreport</a><br>
<h3 class=pageheader>Functions</h3>
<a href='#sub_lravgerror' class=toc>lravgerror</a><br>
<a href='#sub_lravgrelerror' class=toc>lravgrelerror</a><br>
<a href='#sub_lrbuild' class=toc>lrbuild</a><br>
<a href='#sub_lrbuilds' class=toc>lrbuilds</a><br>
<a href='#sub_lrbuildz' class=toc>lrbuildz</a><br>
<a href='#sub_lrbuildzs' class=toc>lrbuildzs</a><br>
<a href='#sub_lrpack' class=toc>lrpack</a><br>
<a href='#sub_lrprocess' class=toc>lrprocess</a><br>
<a href='#sub_lrrmserror' class=toc>lrrmserror</a><br>
<a href='#sub_lrunpack' class=toc>lrunpack</a><br>
<h3 class=pageheader>Examples</h3>
<table border=0 cellspacing=0 class='pagecontent'>
<tr align=left valign=top><td><a href='#example_linreg_d_basic' class=toc>linreg_d_basic</a></td><td width=15> </td><td>Linear regression used to build the very basic model and unpack coefficients</td></tr>
</table></div>
<a name='struct_linearmodel'></a><h3 class=pageheader><code>linearmodel</code> class</h3>
<pre class=source>
<div style='color: navy; margin-top: 0; margin-bottom: 0;'>/*************************************************************************
*************************************************************************/
</div><div style='margin-top: 0; margin-bottom: 0;'><b>class</b> linearmodel
{
};
</div></pre>
<a name='struct_lrreport'></a><h3 class=pageheader><code>lrreport</code> class</h3>
<pre class=source>
<div style='color: navy; margin-top: 0; margin-bottom: 0;'>/*************************************************************************
LRReport structure contains additional information about linear model:
* C - covariation matrix, array[0..NVars,0..NVars].
C[i,j] = Cov(A[i],A[j])
* RMSError - root mean square error on a training set
* AvgError - average error on a training set
* AvgRelError - average relative error on a training set (excluding
observations with zero function value).
* CVRMSError - leave-one-out cross-validation estimate of
generalization error. Calculated using fast algorithm
with O(NVars*NPoints) complexity.
* CVAvgError - cross-validation estimate of average error
* CVAvgRelError - cross-validation estimate of average relative error
All other fields of the structure are intended for internal use and should
not be used outside ALGLIB.
*************************************************************************/
</div><div style='margin-top: 0; margin-bottom: 0;'><b>class</b> lrreport
{
real_2d_array c;
<b>double</b> rmserror;
<b>double</b> avgerror;
<b>double</b> avgrelerror;
<b>double</b> cvrmserror;
<b>double</b> cvavgerror;
<b>double</b> cvavgrelerror;
ae_int_t ncvdefects;
integer_1d_array cvdefects;
};
</div></pre>
<a name='sub_lravgerror'></a><h3 class=pageheader><code>lravgerror</code> function</h3>
<pre class=source>
<div style='color: navy; margin-top: 0; margin-bottom: 0;'>/*************************************************************************
Average error on the test set
INPUT PARAMETERS:
LM - linear model
XY - test set
NPoints - test set size
RESULT:
average error.
-- ALGLIB --
Copyright 30.08.2008 by Bochkanov Sergey
*************************************************************************/
</div><div style='margin-top: 0; margin-bottom: 0;'><b>double</b> alglib::lravgerror(
linearmodel lm,
real_2d_array xy,
ae_int_t npoints);
</div></pre>
<a name='sub_lravgrelerror'></a><h3 class=pageheader><code>lravgrelerror</code> function</h3>
<pre class=source>
<div style='color: navy; margin-top: 0; margin-bottom: 0;'>/*************************************************************************
RMS error on the test set
INPUT PARAMETERS:
LM - linear model
XY - test set
NPoints - test set size
RESULT:
average relative error.
-- ALGLIB --
Copyright 30.08.2008 by Bochkanov Sergey
*************************************************************************/
</div><div style='margin-top: 0; margin-bottom: 0;'><b>double</b> alglib::lravgrelerror(
linearmodel lm,
real_2d_array xy,
ae_int_t npoints);
</div></pre>
<a name='sub_lrbuild'></a><h3 class=pageheader><code>lrbuild</code> function</h3>
<pre class=source>
<div style='color: navy; margin-top: 0; margin-bottom: 0;'>/*************************************************************************
Linear regression
Subroutine builds model:
Y = A(0)*X[0] + ... + A(N-1)*X[N-1] + A(N)
and model found in ALGLIB format, covariation matrix, training set errors
(rms, average, average relative) and leave-one-out cross-validation
estimate of the generalization error. CV estimate calculated using fast
algorithm with O(NPoints*NVars) complexity.
When covariation matrix is calculated standard deviations of function
values are assumed to be equal to RMS error on the training set.
INPUT PARAMETERS:
XY - training set, array [0..NPoints-1,0..NVars]:
* NVars columns - independent variables
* last column - dependent variable
NPoints - training set size, NPoints>NVars+1
NVars - number of independent variables
OUTPUT PARAMETERS:
Info - return code:
* -255, in case of unknown internal error
* -4, if internal SVD subroutine haven't converged
* -1, if incorrect parameters was passed (NPoints<NVars+2, NVars<1).
* 1, if subroutine successfully finished
LM - linear model in the ALGLIB format. Use subroutines of
this unit to work with the model.
AR - additional results
-- ALGLIB --
Copyright 02.08.2008 by Bochkanov Sergey
*************************************************************************/
</div><div style='margin-top: 0; margin-bottom: 0;'><b>void</b> alglib::lrbuild(
real_2d_array xy,
ae_int_t npoints,
ae_int_t nvars,
ae_int_t& info,
linearmodel& lm,
lrreport& ar);
</div></pre>
<p align=left class=pagecontent><span class=inlineheader>Examples:</span> <a href='#example_linreg_d_basic' class=nav>[1]</a> </p>
<a name='sub_lrbuilds'></a><h3 class=pageheader><code>lrbuilds</code> function</h3>
<pre class=source>
<div style='color: navy; margin-top: 0; margin-bottom: 0;'>/*************************************************************************
Linear regression
Variant of LRBuild which uses vector of standatd deviations (errors in
function values).
INPUT PARAMETERS:
XY - training set, array [0..NPoints-1,0..NVars]:
* NVars columns - independent variables
* last column - dependent variable
S - standard deviations (errors in function values)
array[0..NPoints-1], S[i]>0.
NPoints - training set size, NPoints>NVars+1
NVars - number of independent variables
OUTPUT PARAMETERS:
Info - return code:
* -255, in case of unknown internal error
* -4, if internal SVD subroutine haven't converged
* -1, if incorrect parameters was passed (NPoints<NVars+2, NVars<1).
* -2, if S[I]<=0
* 1, if subroutine successfully finished
LM - linear model in the ALGLIB format. Use subroutines of
this unit to work with the model.
AR - additional results
-- ALGLIB --
Copyright 02.08.2008 by Bochkanov Sergey
*************************************************************************/
</div><div style='margin-top: 0; margin-bottom: 0;'><b>void</b> alglib::lrbuilds(
real_2d_array xy,
real_1d_array s,
ae_int_t npoints,
ae_int_t nvars,
ae_int_t& info,
linearmodel& lm,
lrreport& ar);
</div></pre>
<a name='sub_lrbuildz'></a><h3 class=pageheader><code>lrbuildz</code> function</h3>
<pre class=source>
<div style='color: navy; margin-top: 0; margin-bottom: 0;'>/*************************************************************************
Like LRBuild but builds model
Y = A(0)*X[0] + ... + A(N-1)*X[N-1]
i.e. with zero constant term.
-- ALGLIB --
Copyright 30.10.2008 by Bochkanov Sergey
*************************************************************************/
</div><div style='margin-top: 0; margin-bottom: 0;'><b>void</b> alglib::lrbuildz(
real_2d_array xy,
ae_int_t npoints,
ae_int_t nvars,
ae_int_t& info,
linearmodel& lm,
lrreport& ar);
</div></pre>
<a name='sub_lrbuildzs'></a><h3 class=pageheader><code>lrbuildzs</code> function</h3>
<pre class=source>
<div style='color: navy; margin-top: 0; margin-bottom: 0;'>/*************************************************************************
Like LRBuildS, but builds model
Y = A(0)*X[0] + ... + A(N-1)*X[N-1]
i.e. with zero constant term.
-- ALGLIB --
Copyright 30.10.2008 by Bochkanov Sergey
*************************************************************************/
</div><div style='margin-top: 0; margin-bottom: 0;'><b>void</b> alglib::lrbuildzs(
real_2d_array xy,
real_1d_array s,
ae_int_t npoints,
ae_int_t nvars,
ae_int_t& info,
linearmodel& lm,
lrreport& ar);
</div></pre>
<a name='sub_lrpack'></a><h3 class=pageheader><code>lrpack</code> function</h3>
<pre class=source>
<div style='color: navy; margin-top: 0; margin-bottom: 0;'>/*************************************************************************
"Packs" coefficients and creates linear model in ALGLIB format (LRUnpack
reversed).
INPUT PARAMETERS:
V - coefficients, array[0..NVars]
NVars - number of independent variables
OUTPUT PAREMETERS:
LM - linear model.
-- ALGLIB --
Copyright 30.08.2008 by Bochkanov Sergey
*************************************************************************/
</div><div style='margin-top: 0; margin-bottom: 0;'><b>void</b> alglib::lrpack(real_1d_array v, ae_int_t nvars, linearmodel& lm);
</div></pre>
<a name='sub_lrprocess'></a><h3 class=pageheader><code>lrprocess</code> function</h3>
<pre class=source>
<div style='color: navy; margin-top: 0; margin-bottom: 0;'>/*************************************************************************
Procesing
INPUT PARAMETERS:
LM - linear model
X - input vector, array[0..NVars-1].
Result:
value of linear model regression estimate
-- ALGLIB --
Copyright 03.09.2008 by Bochkanov Sergey
*************************************************************************/
</div><div style='margin-top: 0; margin-bottom: 0;'><b>double</b> alglib::lrprocess(linearmodel lm, real_1d_array x);
</div></pre>
<a name='sub_lrrmserror'></a><h3 class=pageheader><code>lrrmserror</code> function</h3>
<pre class=source>
<div style='color: navy; margin-top: 0; margin-bottom: 0;'>/*************************************************************************
RMS error on the test set
INPUT PARAMETERS:
LM - linear model
XY - test set
NPoints - test set size
RESULT:
root mean square error.
-- ALGLIB --
Copyright 30.08.2008 by Bochkanov Sergey
*************************************************************************/
</div><div style='margin-top: 0; margin-bottom: 0;'><b>double</b> alglib::lrrmserror(
linearmodel lm,
real_2d_array xy,
ae_int_t npoints);
</div></pre>
<a name='sub_lrunpack'></a><h3 class=pageheader><code>lrunpack</code> function</h3>
<pre class=source>
<div style='color: navy; margin-top: 0; margin-bottom: 0;'>/*************************************************************************
Unpacks coefficients of linear model.
INPUT PARAMETERS:
LM - linear model in ALGLIB format
OUTPUT PARAMETERS:
V - coefficients, array[0..NVars]
constant term (intercept) is stored in the V[NVars].
NVars - number of independent variables (one less than number
of coefficients)
-- ALGLIB --
Copyright 30.08.2008 by Bochkanov Sergey
*************************************************************************/
</div><div style='margin-top: 0; margin-bottom: 0;'><b>void</b> alglib::lrunpack(linearmodel lm, real_1d_array& v, ae_int_t& nvars);
</div></pre>
<p align=left class=pagecontent><span class=inlineheader>Examples:</span> <a href='#example_linreg_d_basic' class=nav>[1]</a> </p>
<a name='example_linreg_d_basic'></a><h3 class=pageheader>linreg_d_basic example</h3>
<pre class=source>
#include <font color=blue><b>"stdafx.h"</b></font>
#include <stdlib.h>
#include <stdio.h>
#include <math.h>
#include <font color=blue><b>"dataanalysis.h"</b></font>
using namespace alglib;
<b>int</b> main(<b>int</b> argc, char **argv)
{
<font color=navy>//</font>
<font color=navy>// In this example we demonstrate linear fitting by f(x|a) = a*exp(0.5*x).</font>
<font color=navy>//</font>
<font color=navy>// We have:</font>
<font color=navy>// * xy - matrix of basic function values (exp(0.5*x)) and expected values</font>
<font color=navy>//</font>
real_2d_array xy = <font color=blue><b>"[[0.606531,1.133719],[0.670320,1.306522],[0.740818,1.504604],[0.818731,1.554663],[0.904837,1.884638],[1.000000,2.072436],[1.105171,2.257285],[1.221403,2.534068],[1.349859,2.622017],[1.491825,2.897713],[1.648721,3.219371]]"</b></font>;
ae_int_t info;
ae_int_t nvars;
linearmodel model;
lrreport rep;
real_1d_array c;
lrbuildz(xy, 11, 1, info, model, rep);
printf(<font color=blue><b>"%d\n"</b></font>, <b>int</b>(info)); <font color=navy>// EXPECTED: 1</font>
lrunpack(model, c, nvars);
printf(<font color=blue><b>"%s\n"</b></font>, c.tostring(4).c_str()); <font color=navy>// EXPECTED: [1.98650,0.00000]</font>
<b>return</b> 0;
}
</pre><a name=unit_logit></a><h2 class=pageheader><code>logit</code> subpackage</h2>
<div class=pagecontent>
<h3 class=pageheader>Classes</h3>
<a href='#struct_logitmodel' class=toc>logitmodel</a><br>
<a href='#struct_mnlreport' class=toc>mnlreport</a><br>
<h3 class=pageheader>Functions</h3>
<a href='#sub_mnlavgce' class=toc>mnlavgce</a><br>
<a href='#sub_mnlavgerror' class=toc>mnlavgerror</a><br>
<a href='#sub_mnlavgrelerror' class=toc>mnlavgrelerror</a><br>
<a href='#sub_mnlclserror' class=toc>mnlclserror</a><br>
<a href='#sub_mnlpack' class=toc>mnlpack</a><br>
<a href='#sub_mnlprocess' class=toc>mnlprocess</a><br>
<a href='#sub_mnlprocessi' class=toc>mnlprocessi</a><br>
<a href='#sub_mnlrelclserror' class=toc>mnlrelclserror</a><br>
<a href='#sub_mnlrmserror' class=toc>mnlrmserror</a><br>
<a href='#sub_mnltrainh' class=toc>mnltrainh</a><br>
<a href='#sub_mnlunpack' class=toc>mnlunpack</a><br>
<h3 class=pageheader>Examples</h3>
<table border=0 cellspacing=0 class='pagecontent'>
</table></div>
<a name='struct_logitmodel'></a><h3 class=pageheader><code>logitmodel</code> class</h3>
<pre class=source>
<div style='color: navy; margin-top: 0; margin-bottom: 0;'>/*************************************************************************
*************************************************************************/
</div><div style='margin-top: 0; margin-bottom: 0;'><b>class</b> logitmodel
{
};
</div></pre>
<a name='struct_mnlreport'></a><h3 class=pageheader><code>mnlreport</code> class</h3>
<pre class=source>
<div style='color: navy; margin-top: 0; margin-bottom: 0;'>/*************************************************************************
MNLReport structure contains information about training process:
* NGrad - number of gradient calculations
* NHess - number of Hessian calculations
*************************************************************************/
</div><div style='margin-top: 0; margin-bottom: 0;'><b>class</b> mnlreport
{
ae_int_t ngrad;
ae_int_t nhess;
};
</div></pre>
<a name='sub_mnlavgce'></a><h3 class=pageheader><code>mnlavgce</code> function</h3>
<pre class=source>
<div style='color: navy; margin-top: 0; margin-bottom: 0;'>/*************************************************************************
Average cross-entropy (in bits per element) on the test set
INPUT PARAMETERS:
LM - logit model
XY - test set
NPoints - test set size
RESULT:
CrossEntropy/(NPoints*ln(2)).
-- ALGLIB --
Copyright 10.09.2008 by Bochkanov Sergey
*************************************************************************/
</div><div style='margin-top: 0; margin-bottom: 0;'><b>double</b> alglib::mnlavgce(
logitmodel lm,
real_2d_array xy,
ae_int_t npoints);
</div></pre>
<a name='sub_mnlavgerror'></a><h3 class=pageheader><code>mnlavgerror</code> function</h3>
<pre class=source>
<div style='color: navy; margin-top: 0; margin-bottom: 0;'>/*************************************************************************
Average error on the test set
INPUT PARAMETERS:
LM - logit model
XY - test set
NPoints - test set size
RESULT:
average error (error when estimating posterior probabilities).
-- ALGLIB --
Copyright 30.08.2008 by Bochkanov Sergey
*************************************************************************/
</div><div style='margin-top: 0; margin-bottom: 0;'><b>double</b> alglib::mnlavgerror(
logitmodel lm,
real_2d_array xy,
ae_int_t npoints);
</div></pre>
<a name='sub_mnlavgrelerror'></a><h3 class=pageheader><code>mnlavgrelerror</code> function</h3>
<pre class=source>
<div style='color: navy; margin-top: 0; margin-bottom: 0;'>/*************************************************************************
Average relative error on the test set
INPUT PARAMETERS:
LM - logit model
XY - test set
NPoints - test set size
RESULT:
average relative error (error when estimating posterior probabilities).
-- ALGLIB --
Copyright 30.08.2008 by Bochkanov Sergey
*************************************************************************/
</div><div style='margin-top: 0; margin-bottom: 0;'><b>double</b> alglib::mnlavgrelerror(
logitmodel lm,
real_2d_array xy,
ae_int_t ssize);
</div></pre>
<a name='sub_mnlclserror'></a><h3 class=pageheader><code>mnlclserror</code> function</h3>
<pre class=source>
<div style='color: navy; margin-top: 0; margin-bottom: 0;'>/*************************************************************************
Classification error on test set = MNLRelClsError*NPoints
-- ALGLIB --
Copyright 10.09.2008 by Bochkanov Sergey
*************************************************************************/
</div><div style='margin-top: 0; margin-bottom: 0;'>ae_int_t alglib::mnlclserror(
logitmodel lm,
real_2d_array xy,
ae_int_t npoints);
</div></pre>
<a name='sub_mnlpack'></a><h3 class=pageheader><code>mnlpack</code> function</h3>
<pre class=source>
<div style='color: navy; margin-top: 0; margin-bottom: 0;'>/*************************************************************************
"Packs" coefficients and creates logit model in ALGLIB format (MNLUnpack
reversed).
INPUT PARAMETERS:
A - model (see MNLUnpack)
NVars - number of independent variables
NClasses - number of classes
OUTPUT PARAMETERS:
LM - logit model.
-- ALGLIB --
Copyright 10.09.2008 by Bochkanov Sergey
*************************************************************************/
</div><div style='margin-top: 0; margin-bottom: 0;'><b>void</b> alglib::mnlpack(
real_2d_array a,
ae_int_t nvars,
ae_int_t nclasses,
logitmodel& lm);
</div></pre>
<a name='sub_mnlprocess'></a><h3 class=pageheader><code>mnlprocess</code> function</h3>
<pre class=source>
<div style='color: navy; margin-top: 0; margin-bottom: 0;'>/*************************************************************************
Procesing
INPUT PARAMETERS:
LM - logit model, passed by non-constant reference
(some fields of structure are used as temporaries
when calculating model output).
X - input vector, array[0..NVars-1].
Y - (possibly) preallocated buffer; if size of Y is less than
NClasses, it will be reallocated.If it is large enough, it
is NOT reallocated, so we can save some time on reallocation.
OUTPUT PARAMETERS:
Y - result, array[0..NClasses-1]
Vector of posterior probabilities for classification task.
-- ALGLIB --
Copyright 10.09.2008 by Bochkanov Sergey
*************************************************************************/
</div><div style='margin-top: 0; margin-bottom: 0;'><b>void</b> alglib::mnlprocess(logitmodel lm, real_1d_array x, real_1d_array& y);
</div></pre>
<a name='sub_mnlprocessi'></a><h3 class=pageheader><code>mnlprocessi</code> function</h3>
<pre class=source>
<div style='color: navy; margin-top: 0; margin-bottom: 0;'>/*************************************************************************
'interactive' variant of MNLProcess for languages like Python which
support constructs like "Y = MNLProcess(LM,X)" and interactive mode of the
interpreter
This function allocates new array on each call, so it is significantly
slower than its 'non-interactive' counterpart, but it is more convenient
when you call it from command line.
-- ALGLIB --
Copyright 10.09.2008 by Bochkanov Sergey
*************************************************************************/
</div><div style='margin-top: 0; margin-bottom: 0;'><b>void</b> alglib::mnlprocessi(
logitmodel lm,
real_1d_array x,
real_1d_array& y);
</div></pre>
<a name='sub_mnlrelclserror'></a><h3 class=pageheader><code>mnlrelclserror</code> function</h3>
<pre class=source>
<div style='color: navy; margin-top: 0; margin-bottom: 0;'>/*************************************************************************
Relative classification error on the test set
INPUT PARAMETERS:
LM - logit model
XY - test set
NPoints - test set size
RESULT:
percent of incorrectly classified cases.
-- ALGLIB --
Copyright 10.09.2008 by Bochkanov Sergey
*************************************************************************/
</div><div style='margin-top: 0; margin-bottom: 0;'><b>double</b> alglib::mnlrelclserror(
logitmodel lm,
real_2d_array xy,
ae_int_t npoints);
</div></pre>
<a name='sub_mnlrmserror'></a><h3 class=pageheader><code>mnlrmserror</code> function</h3>
<pre class=source>
<div style='color: navy; margin-top: 0; margin-bottom: 0;'>/*************************************************************************
RMS error on the test set
INPUT PARAMETERS:
LM - logit model
XY - test set
NPoints - test set size
RESULT:
root mean square error (error when estimating posterior probabilities).
-- ALGLIB --
Copyright 30.08.2008 by Bochkanov Sergey
*************************************************************************/
</div><div style='margin-top: 0; margin-bottom: 0;'><b>double</b> alglib::mnlrmserror(
logitmodel lm,
real_2d_array xy,
ae_int_t npoints);
</div></pre>
<a name='sub_mnltrainh'></a><h3 class=pageheader><code>mnltrainh</code> function</h3>
<pre class=source>
<div style='color: navy; margin-top: 0; margin-bottom: 0;'>/*************************************************************************
This subroutine trains logit model.
INPUT PARAMETERS:
XY - training set, array[0..NPoints-1,0..NVars]
First NVars columns store values of independent
variables, next column stores number of class (from 0
to NClasses-1) which dataset element belongs to. Fractional
values are rounded to nearest integer.
NPoints - training set size, NPoints>=1
NVars - number of independent variables, NVars>=1
NClasses - number of classes, NClasses>=2
OUTPUT PARAMETERS:
Info - return code:
* -2, if there is a point with class number
outside of [0..NClasses-1].
* -1, if incorrect parameters was passed
(NPoints<NVars+2, NVars<1, NClasses<2).
* 1, if task has been solved
LM - model built
Rep - training report
-- ALGLIB --
Copyright 10.09.2008 by Bochkanov Sergey
*************************************************************************/
</div><div style='margin-top: 0; margin-bottom: 0;'><b>void</b> alglib::mnltrainh(
real_2d_array xy,
ae_int_t npoints,
ae_int_t nvars,
ae_int_t nclasses,
ae_int_t& info,
logitmodel& lm,
mnlreport& rep);
</div></pre>
<a name='sub_mnlunpack'></a><h3 class=pageheader><code>mnlunpack</code> function</h3>
<pre class=source>
<div style='color: navy; margin-top: 0; margin-bottom: 0;'>/*************************************************************************
Unpacks coefficients of logit model. Logit model have form:
P(class=i) = S(i) / (S(0) + S(1) + ... +S(M-1))
S(i) = Exp(A[i,0]*X[0] + ... + A[i,N-1]*X[N-1] + A[i,N]), when i<M-1
S(M-1) = 1
INPUT PARAMETERS:
LM - logit model in ALGLIB format
OUTPUT PARAMETERS:
V - coefficients, array[0..NClasses-2,0..NVars]
NVars - number of independent variables
NClasses - number of classes
-- ALGLIB --
Copyright 10.09.2008 by Bochkanov Sergey
*************************************************************************/
</div><div style='margin-top: 0; margin-bottom: 0;'><b>void</b> alglib::mnlunpack(
logitmodel lm,
real_2d_array& a,
ae_int_t& nvars,
ae_int_t& nclasses);
</div></pre>
<a name=unit_lsfit></a><h2 class=pageheader><code>lsfit</code> subpackage</h2>
<div class=pagecontent>
<h3 class=pageheader>Classes</h3>
<a href='#struct_barycentricfitreport' class=toc>barycentricfitreport</a><br>
<a href='#struct_lsfitreport' class=toc>lsfitreport</a><br>
<a href='#struct_lsfitstate' class=toc>lsfitstate</a><br>
<a href='#struct_polynomialfitreport' class=toc>polynomialfitreport</a><br>
<a href='#struct_spline1dfitreport' class=toc>spline1dfitreport</a><br>
<h3 class=pageheader>Functions</h3>
<a href='#sub_barycentricfitfloaterhormann' class=toc>barycentricfitfloaterhormann</a><br>
<a href='#sub_barycentricfitfloaterhormannwc' class=toc>barycentricfitfloaterhormannwc</a><br>
<a href='#sub_logisticcalc4' class=toc>logisticcalc4</a><br>
<a href='#sub_logisticcalc5' class=toc>logisticcalc5</a><br>
<a href='#sub_logisticfit4' class=toc>logisticfit4</a><br>
<a href='#sub_logisticfit45x' class=toc>logisticfit45x</a><br>
<a href='#sub_logisticfit4ec' class=toc>logisticfit4ec</a><br>
<a href='#sub_logisticfit5' class=toc>logisticfit5</a><br>
<a href='#sub_logisticfit5ec' class=toc>logisticfit5ec</a><br>
<a href='#sub_lsfitcreatef' class=toc>lsfitcreatef</a><br>
<a href='#sub_lsfitcreatefg' class=toc>lsfitcreatefg</a><br>
<a href='#sub_lsfitcreatefgh' class=toc>lsfitcreatefgh</a><br>
<a href='#sub_lsfitcreatewf' class=toc>lsfitcreatewf</a><br>
<a href='#sub_lsfitcreatewfg' class=toc>lsfitcreatewfg</a><br>
<a href='#sub_lsfitcreatewfgh' class=toc>lsfitcreatewfgh</a><br>
<a href='#sub_lsfitfit' class=toc>lsfitfit</a><br>
<a href='#sub_lsfitlinear' class=toc>lsfitlinear</a><br>
<a href='#sub_lsfitlinearc' class=toc>lsfitlinearc</a><br>
<a href='#sub_lsfitlinearw' class=toc>lsfitlinearw</a><br>
<a href='#sub_lsfitlinearwc' class=toc>lsfitlinearwc</a><br>
<a href='#sub_lsfitresults' class=toc>lsfitresults</a><br>
<a href='#sub_lsfitsetbc' class=toc>lsfitsetbc</a><br>
<a href='#sub_lsfitsetcond' class=toc>lsfitsetcond</a><br>
<a href='#sub_lsfitsetgradientcheck' class=toc>lsfitsetgradientcheck</a><br>
<a href='#sub_lsfitsetscale' class=toc>lsfitsetscale</a><br>
<a href='#sub_lsfitsetstpmax' class=toc>lsfitsetstpmax</a><br>
<a href='#sub_lsfitsetxrep' class=toc>lsfitsetxrep</a><br>
<a href='#sub_lstfitpiecewiselinearrdp' class=toc>lstfitpiecewiselinearrdp</a><br>
<a href='#sub_lstfitpiecewiselinearrdpfixed' class=toc>lstfitpiecewiselinearrdpfixed</a><br>
<a href='#sub_polynomialfit' class=toc>polynomialfit</a><br>
<a href='#sub_polynomialfitwc' class=toc>polynomialfitwc</a><br>
<a href='#sub_spline1dfitcubic' class=toc>spline1dfitcubic</a><br>
<a href='#sub_spline1dfitcubicwc' class=toc>spline1dfitcubicwc</a><br>
<a href='#sub_spline1dfithermite' class=toc>spline1dfithermite</a><br>
<a href='#sub_spline1dfithermitewc' class=toc>spline1dfithermitewc</a><br>
<a href='#sub_spline1dfitpenalized' class=toc>spline1dfitpenalized</a><br>
<a href='#sub_spline1dfitpenalizedw' class=toc>spline1dfitpenalizedw</a><br>
<h3 class=pageheader>Examples</h3>
<table border=0 cellspacing=0 class='pagecontent'>
<tr align=left valign=top><td><a href='#example_lsfit_d_lin' class=toc>lsfit_d_lin</a></td><td width=15> </td><td>Unconstrained (general) linear least squares fitting with and without weights</td></tr>
<tr align=left valign=top><td><a href='#example_lsfit_d_linc' class=toc>lsfit_d_linc</a></td><td width=15> </td><td>Constrained (general) linear least squares fitting with and without weights</td></tr>
<tr align=left valign=top><td><a href='#example_lsfit_d_nlf' class=toc>lsfit_d_nlf</a></td><td width=15> </td><td>Nonlinear fitting using function value only</td></tr>
<tr align=left valign=top><td><a href='#example_lsfit_d_nlfb' class=toc>lsfit_d_nlfb</a></td><td width=15> </td><td>Bound contstrained nonlinear fitting using function value only</td></tr>
<tr align=left valign=top><td><a href='#example_lsfit_d_nlfg' class=toc>lsfit_d_nlfg</a></td><td width=15> </td><td>Nonlinear fitting using gradient</td></tr>
<tr align=left valign=top><td><a href='#example_lsfit_d_nlfgh' class=toc>lsfit_d_nlfgh</a></td><td width=15> </td><td>Nonlinear fitting using gradient and Hessian</td></tr>
<tr align=left valign=top><td><a href='#example_lsfit_d_nlscale' class=toc>lsfit_d_nlscale</a></td><td width=15> </td><td>Nonlinear fitting with custom scaling and bound constraints</td></tr>
<tr align=left valign=top><td><a href='#example_lsfit_d_pol' class=toc>lsfit_d_pol</a></td><td width=15> </td><td>Unconstrained polynomial fitting</td></tr>
<tr align=left valign=top><td><a href='#example_lsfit_d_polc' class=toc>lsfit_d_polc</a></td><td width=15> </td><td>Constrained polynomial fitting</td></tr>
<tr align=left valign=top><td><a href='#example_lsfit_d_spline' class=toc>lsfit_d_spline</a></td><td width=15> </td><td>Unconstrained fitting by penalized regression spline</td></tr>
<tr align=left valign=top><td><a href='#example_lsfit_t_4pl' class=toc>lsfit_t_4pl</a></td><td width=15> </td><td>4-parameter logistic fitting</td></tr>
<tr align=left valign=top><td><a href='#example_lsfit_t_5pl' class=toc>lsfit_t_5pl</a></td><td width=15> </td><td>5-parameter logistic fitting</td></tr>
</table></div>
<a name='struct_barycentricfitreport'></a><h3 class=pageheader><code>barycentricfitreport</code> class</h3>
<pre class=source>
<div style='color: navy; margin-top: 0; margin-bottom: 0;'>/*************************************************************************
Barycentric fitting report:
RMSError RMS error
AvgError average error
AvgRelError average relative error (for non-zero Y[I])
MaxError maximum error
TaskRCond reciprocal of task's condition number
*************************************************************************/
</div><div style='margin-top: 0; margin-bottom: 0;'><b>class</b> barycentricfitreport
{
<b>double</b> taskrcond;
ae_int_t dbest;
<b>double</b> rmserror;
<b>double</b> avgerror;
<b>double</b> avgrelerror;
<b>double</b> maxerror;
};
</div></pre>
<a name='struct_lsfitreport'></a><h3 class=pageheader><code>lsfitreport</code> class</h3>
<pre class=source>
<div style='color: navy; margin-top: 0; margin-bottom: 0;'>/*************************************************************************
Least squares fitting report. This structure contains informational fields
which are set by fitting functions provided by this unit.
Different functions initialize different sets of fields, so you should
read documentation on specific function you used in order to know which
fields are initialized.
TaskRCond reciprocal of task's condition number
IterationsCount number of internal iterations
VarIdx if user-supplied gradient contains errors which were
detected by nonlinear fitter, this field is set to
index of the first component of gradient which is
suspected to be spoiled by bugs.
RMSError RMS error
AvgError average error
AvgRelError average relative error (for non-zero Y[I])
MaxError maximum error
WRMSError weighted RMS error
CovPar covariance matrix for parameters, filled by some solvers
ErrPar vector of errors in parameters, filled by some solvers
ErrCurve vector of fit errors - variability of the best-fit
curve, filled by some solvers.
Noise vector of per-point noise estimates, filled by
some solvers.
R2 coefficient of determination (non-weighted, non-adjusted),
filled by some solvers.
*************************************************************************/
</div><div style='margin-top: 0; margin-bottom: 0;'><b>class</b> lsfitreport
{
<b>double</b> taskrcond;
ae_int_t iterationscount;
ae_int_t varidx;
<b>double</b> rmserror;
<b>double</b> avgerror;
<b>double</b> avgrelerror;
<b>double</b> maxerror;
<b>double</b> wrmserror;
real_2d_array covpar;
real_1d_array errpar;
real_1d_array errcurve;
real_1d_array noise;
<b>double</b> r2;
};
</div></pre>
<a name='struct_lsfitstate'></a><h3 class=pageheader><code>lsfitstate</code> class</h3>
<pre class=source>
<div style='color: navy; margin-top: 0; margin-bottom: 0;'>/*************************************************************************
Nonlinear fitter.
You should use ALGLIB functions to work with fitter.
Never try to access its fields directly!
*************************************************************************/
</div><div style='margin-top: 0; margin-bottom: 0;'><b>class</b> lsfitstate
{
};
</div></pre>
<a name='struct_polynomialfitreport'></a><h3 class=pageheader><code>polynomialfitreport</code> class</h3>
<pre class=source>
<div style='color: navy; margin-top: 0; margin-bottom: 0;'>/*************************************************************************
Polynomial fitting report:
TaskRCond reciprocal of task's condition number
RMSError RMS error
AvgError average error
AvgRelError average relative error (for non-zero Y[I])
MaxError maximum error
*************************************************************************/
</div><div style='margin-top: 0; margin-bottom: 0;'><b>class</b> polynomialfitreport
{
<b>double</b> taskrcond;
<b>double</b> rmserror;
<b>double</b> avgerror;
<b>double</b> avgrelerror;
<b>double</b> maxerror;
};
</div></pre>
<a name='struct_spline1dfitreport'></a><h3 class=pageheader><code>spline1dfitreport</code> class</h3>
<pre class=source>
<div style='color: navy; margin-top: 0; margin-bottom: 0;'>/*************************************************************************
Spline fitting report:
RMSError RMS error
AvgError average error
AvgRelError average relative error (for non-zero Y[I])
MaxError maximum error
Fields below are filled by obsolete functions (Spline1DFitCubic,
Spline1DFitHermite). Modern fitting functions do NOT fill these fields:
TaskRCond reciprocal of task's condition number
*************************************************************************/
</div><div style='margin-top: 0; margin-bottom: 0;'><b>class</b> spline1dfitreport
{
<b>double</b> taskrcond;
<b>double</b> rmserror;
<b>double</b> avgerror;
<b>double</b> avgrelerror;
<b>double</b> maxerror;
};
</div></pre>
<a name='sub_barycentricfitfloaterhormann'></a><h3 class=pageheader><code>barycentricfitfloaterhormann</code> function</h3>
<pre class=source>
<div style='color: navy; margin-top: 0; margin-bottom: 0;'>/*************************************************************************
Rational least squares fitting using Floater-Hormann rational functions
with optimal D chosen from [0,9].
Equidistant grid with M node on [min(x),max(x)] is used to build basis
functions. Different values of D are tried, optimal D (least root mean
square error) is chosen. Task is linear, so linear least squares solver
is used. Complexity of this computational scheme is O(N*M^2) (mostly
dominated by the least squares solver).
COMMERCIAL EDITION OF ALGLIB:
! Commercial version of ALGLIB includes two important improvements of
! this function, which can be used from C++ and C#:
! * Intel MKL support (lightweight Intel MKL is shipped with ALGLIB)
! * multithreading support
!
! Intel MKL gives approximately constant (with respect to number of
! worker threads) acceleration factor which depends on CPU being used,
! problem size and "baseline" ALGLIB edition which is used for
! comparison.
!
! Speed-up provided by multithreading greatly depends on problem size
! - only large problems (number of coefficients is more than 500) can be
! efficiently multithreaded.
!
! Generally, commercial ALGLIB is several times faster than open-source
! generic C edition, and many times faster than open-source C# edition.
!
! We recommend you to read 'Working with commercial version' section of
! ALGLIB Reference Manual in order to find out how to use performance-
! related features provided by commercial edition of ALGLIB.
INPUT PARAMETERS:
X - points, array[0..N-1].
Y - function values, array[0..N-1].
N - number of points, N>0.
M - number of basis functions ( = number_of_nodes), M>=2.
OUTPUT PARAMETERS:
Info- same format as in LSFitLinearWC() subroutine.
* Info>0 task is solved
* Info<=0 an error occured:
-4 means inconvergence of internal SVD
-3 means inconsistent constraints
B - barycentric interpolant.
Rep - report, same format as in LSFitLinearWC() subroutine.
Following fields are set:
* DBest best value of the D parameter
* RMSError rms error on the (X,Y).
* AvgError average error on the (X,Y).
* AvgRelError average relative error on the non-zero Y
* MaxError maximum error
NON-WEIGHTED ERRORS ARE CALCULATED
-- ALGLIB PROJECT --
Copyright 18.08.2009 by Bochkanov Sergey
*************************************************************************/
</div><div style='margin-top: 0; margin-bottom: 0;'><b>void</b> alglib::barycentricfitfloaterhormann(
real_1d_array x,
real_1d_array y,
ae_int_t n,
ae_int_t m,
ae_int_t& info,
barycentricinterpolant& b,
barycentricfitreport& rep);
<b>void</b> alglib::smp_barycentricfitfloaterhormann(
real_1d_array x,
real_1d_array y,
ae_int_t n,
ae_int_t m,
ae_int_t& info,
barycentricinterpolant& b,
barycentricfitreport& rep);
</div></pre>
<a name='sub_barycentricfitfloaterhormannwc'></a><h3 class=pageheader><code>barycentricfitfloaterhormannwc</code> function</h3>
<pre class=source>
<div style='color: navy; margin-top: 0; margin-bottom: 0;'>/*************************************************************************
Weghted rational least squares fitting using Floater-Hormann rational
functions with optimal D chosen from [0,9], with constraints and
individual weights.
Equidistant grid with M node on [min(x),max(x)] is used to build basis
functions. Different values of D are tried, optimal D (least WEIGHTED root
mean square error) is chosen. Task is linear, so linear least squares
solver is used. Complexity of this computational scheme is O(N*M^2)
(mostly dominated by the least squares solver).
SEE ALSO
* BarycentricFitFloaterHormann(), "lightweight" fitting without invididual
weights and constraints.
COMMERCIAL EDITION OF ALGLIB:
! Commercial version of ALGLIB includes two important improvements of
! this function, which can be used from C++ and C#:
! * Intel MKL support (lightweight Intel MKL is shipped with ALGLIB)
! * multithreading support
!
! Intel MKL gives approximately constant (with respect to number of
! worker threads) acceleration factor which depends on CPU being used,
! problem size and "baseline" ALGLIB edition which is used for
! comparison.
!
! Speed-up provided by multithreading greatly depends on problem size
! - only large problems (number of coefficients is more than 500) can be
! efficiently multithreaded.
!
! Generally, commercial ALGLIB is several times faster than open-source
! generic C edition, and many times faster than open-source C# edition.
!
! We recommend you to read 'Working with commercial version' section of
! ALGLIB Reference Manual in order to find out how to use performance-
! related features provided by commercial edition of ALGLIB.
INPUT PARAMETERS:
X - points, array[0..N-1].
Y - function values, array[0..N-1].
W - weights, array[0..N-1]
Each summand in square sum of approximation deviations from
given values is multiplied by the square of corresponding
weight. Fill it by 1's if you don't want to solve weighted
task.
N - number of points, N>0.
XC - points where function values/derivatives are constrained,
array[0..K-1].
YC - values of constraints, array[0..K-1]
DC - array[0..K-1], types of constraints:
* DC[i]=0 means that S(XC[i])=YC[i]
* DC[i]=1 means that S'(XC[i])=YC[i]
SEE BELOW FOR IMPORTANT INFORMATION ON CONSTRAINTS
K - number of constraints, 0<=K<M.
K=0 means no constraints (XC/YC/DC are not used in such cases)
M - number of basis functions ( = number_of_nodes), M>=2.
OUTPUT PARAMETERS:
Info- same format as in LSFitLinearWC() subroutine.
* Info>0 task is solved
* Info<=0 an error occured:
-4 means inconvergence of internal SVD
-3 means inconsistent constraints
-1 means another errors in parameters passed
(N<=0, for example)
B - barycentric interpolant.
Rep - report, same format as in LSFitLinearWC() subroutine.
Following fields are set:
* DBest best value of the D parameter
* RMSError rms error on the (X,Y).
* AvgError average error on the (X,Y).
* AvgRelError average relative error on the non-zero Y
* MaxError maximum error
NON-WEIGHTED ERRORS ARE CALCULATED
IMPORTANT:
this subroutine doesn't calculate task's condition number for K<>0.
SETTING CONSTRAINTS - DANGERS AND OPPORTUNITIES:
Setting constraints can lead to undesired results, like ill-conditioned
behavior, or inconsistency being detected. From the other side, it allows
us to improve quality of the fit. Here we summarize our experience with
constrained barycentric interpolants:
* excessive constraints can be inconsistent. Floater-Hormann basis
functions aren't as flexible as splines (although they are very smooth).
* the more evenly constraints are spread across [min(x),max(x)], the more
chances that they will be consistent
* the greater is M (given fixed constraints), the more chances that
constraints will be consistent
* in the general case, consistency of constraints IS NOT GUARANTEED.
* in the several special cases, however, we CAN guarantee consistency.
* one of this cases is constraints on the function VALUES at the interval
boundaries. Note that consustency of the constraints on the function
DERIVATIVES is NOT guaranteed (you can use in such cases cubic splines
which are more flexible).
* another special case is ONE constraint on the function value (OR, but
not AND, derivative) anywhere in the interval
Our final recommendation is to use constraints WHEN AND ONLY WHEN you
can't solve your task without them. Anything beyond special cases given
above is not guaranteed and may result in inconsistency.
-- ALGLIB PROJECT --
Copyright 18.08.2009 by Bochkanov Sergey
*************************************************************************/
</div><div style='margin-top: 0; margin-bottom: 0;'><b>void</b> alglib::barycentricfitfloaterhormannwc(
real_1d_array x,
real_1d_array y,
real_1d_array w,
ae_int_t n,
real_1d_array xc,
real_1d_array yc,
integer_1d_array dc,
ae_int_t k,
ae_int_t m,
ae_int_t& info,
barycentricinterpolant& b,
barycentricfitreport& rep);
<b>void</b> alglib::smp_barycentricfitfloaterhormannwc(
real_1d_array x,
real_1d_array y,
real_1d_array w,
ae_int_t n,
real_1d_array xc,
real_1d_array yc,
integer_1d_array dc,
ae_int_t k,
ae_int_t m,
ae_int_t& info,
barycentricinterpolant& b,
barycentricfitreport& rep);
</div></pre>
<a name='sub_logisticcalc4'></a><h3 class=pageheader><code>logisticcalc4</code> function</h3>
<pre class=source>
<div style='color: navy; margin-top: 0; margin-bottom: 0;'>/*************************************************************************
This function calculates value of four-parameter logistic (4PL) model at
specified point X. 4PL model has following form:
F(x|A,B,C,D) = D+(A-D)/(1+Power(x/C,B))
INPUT PARAMETERS:
X - current point, X>=0:
* zero X is correctly handled even for B<=0
* negative X results in exception.
A, B, C, D- parameters of 4PL model:
* A is unconstrained
* B is unconstrained; zero or negative values are handled
correctly.
* C>0, non-positive value results in exception
* D is unconstrained
RESULT:
model value at X
NOTE: if B=0, denominator is assumed to be equal to 2.0 even for zero X
(strictly speaking, 0^0 is undefined).
NOTE: this function also throws exception if all input parameters are
correct, but overflow was detected during calculations.
NOTE: this function performs a lot of checks; if you need really high
performance, consider evaluating model yourself, without checking
for degenerate cases.
-- ALGLIB PROJECT --
Copyright 14.05.2014 by Bochkanov Sergey
*************************************************************************/
</div><div style='margin-top: 0; margin-bottom: 0;'><b>double</b> alglib::logisticcalc4(
<b>double</b> x,
<b>double</b> a,
<b>double</b> b,
<b>double</b> c,
<b>double</b> d);
</div></pre>
<p align=left class=pagecontent><span class=inlineheader>Examples:</span> <a href='#example_lsfit_t_4pl' class=nav>[1]</a> </p>
<a name='sub_logisticcalc5'></a><h3 class=pageheader><code>logisticcalc5</code> function</h3>
<pre class=source>
<div style='color: navy; margin-top: 0; margin-bottom: 0;'>/*************************************************************************
This function calculates value of five-parameter logistic (5PL) model at
specified point X. 5PL model has following form:
F(x|A,B,C,D,G) = D+(A-D)/Power(1+Power(x/C,B),G)
INPUT PARAMETERS:
X - current point, X>=0:
* zero X is correctly handled even for B<=0
* negative X results in exception.
A, B, C, D, G- parameters of 5PL model:
* A is unconstrained
* B is unconstrained; zero or negative values are handled
correctly.
* C>0, non-positive value results in exception
* D is unconstrained
* G>0, non-positive value results in exception
RESULT:
model value at X
NOTE: if B=0, denominator is assumed to be equal to Power(2.0,G) even for
zero X (strictly speaking, 0^0 is undefined).
NOTE: this function also throws exception if all input parameters are
correct, but overflow was detected during calculations.
NOTE: this function performs a lot of checks; if you need really high
performance, consider evaluating model yourself, without checking
for degenerate cases.
-- ALGLIB PROJECT --
Copyright 14.05.2014 by Bochkanov Sergey
*************************************************************************/
</div><div style='margin-top: 0; margin-bottom: 0;'><b>double</b> alglib::logisticcalc5(
<b>double</b> x,
<b>double</b> a,
<b>double</b> b,
<b>double</b> c,
<b>double</b> d,
<b>double</b> g);
</div></pre>
<p align=left class=pagecontent><span class=inlineheader>Examples:</span> <a href='#example_lsfit_t_5pl' class=nav>[1]</a> </p>
<a name='sub_logisticfit4'></a><h3 class=pageheader><code>logisticfit4</code> function</h3>
<pre class=source>
<div style='color: navy; margin-top: 0; margin-bottom: 0;'>/*************************************************************************
This function fits four-parameter logistic (4PL) model to data provided
by user. 4PL model has following form:
F(x|A,B,C,D) = D+(A-D)/(1+Power(x/C,B))
Here:
* A, D - unconstrained (see LogisticFit4EC() for constrained 4PL)
* B>=0
* C>0
IMPORTANT: output of this function is constrained in such way that B>0.
Because 4PL model is symmetric with respect to B, there is no
need to explore B<0. Constraining B makes algorithm easier
to stabilize and debug.
Users who for some reason prefer to work with negative B's
should transform output themselves (swap A and D, replace B by
-B).
4PL fitting is implemented as follows:
* we perform small number of restarts from random locations which helps to
solve problem of bad local extrema. Locations are only partially random
- we use input data to determine good initial guess, but we include
controlled amount of randomness.
* we perform Levenberg-Marquardt fitting with very tight constraints on
parameters B and C - it allows us to find good initial guess for the
second stage without risk of running into "flat spot".
* second Levenberg-Marquardt round is performed without excessive
constraints. Results from the previous round are used as initial guess.
* after fitting is done, we compare results with best values found so far,
rewrite "best solution" if needed, and move to next random location.
Overall algorithm is very stable and is not prone to bad local extrema.
Furthermore, it automatically scales when input data have very large or
very small range.
INPUT PARAMETERS:
X - array[N], stores X-values.
MUST include only non-negative numbers (but may include
zero values). Can be unsorted.
Y - array[N], values to fit.
N - number of points. If N is less than length of X/Y, only
leading N elements are used.
OUTPUT PARAMETERS:
A, B, C, D- parameters of 4PL model
Rep - fitting report. This structure has many fields, but ONLY
ONES LISTED BELOW ARE SET:
* Rep.IterationsCount - number of iterations performed
* Rep.RMSError - root-mean-square error
* Rep.AvgError - average absolute error
* Rep.AvgRelError - average relative error (calculated for
non-zero Y-values)
* Rep.MaxError - maximum absolute error
* Rep.R2 - coefficient of determination, R-squared. This
coefficient is calculated as R2=1-RSS/TSS (in case
of nonlinear regression there are multiple ways to
define R2, each of them giving different results).
NOTE: after you obtained coefficients, you can evaluate model with
LogisticCalc4() function.
NOTE: if you need better control over fitting process than provided by this
function, you may use LogisticFit45X().
NOTE: step is automatically scaled according to scale of parameters being
fitted before we compare its length with EpsX. Thus, this function
can be used to fit data with very small or very large values without
changing EpsX.
-- ALGLIB PROJECT --
Copyright 14.02.2014 by Bochkanov Sergey
*************************************************************************/
</div><div style='margin-top: 0; margin-bottom: 0;'><b>void</b> alglib::logisticfit4(
real_1d_array x,
real_1d_array y,
ae_int_t n,
<b>double</b>& a,
<b>double</b>& b,
<b>double</b>& c,
<b>double</b>& d,
lsfitreport& rep);
</div></pre>
<p align=left class=pagecontent><span class=inlineheader>Examples:</span> <a href='#example_lsfit_t_4pl' class=nav>[1]</a> </p>
<a name='sub_logisticfit45x'></a><h3 class=pageheader><code>logisticfit45x</code> function</h3>
<pre class=source>
<div style='color: navy; margin-top: 0; margin-bottom: 0;'>/*************************************************************************
This is "expert" 4PL/5PL fitting function, which can be used if you need
better control over fitting process than provided by LogisticFit4() or
LogisticFit5().
This function fits model of the form
F(x|A,B,C,D) = D+(A-D)/(1+Power(x/C,B)) (4PL model)
or
F(x|A,B,C,D,G) = D+(A-D)/Power(1+Power(x/C,B),G) (5PL model)
Here:
* A, D - unconstrained
* B>=0 for 4PL, unconstrained for 5PL
* C>0
* G>0 (if present)
INPUT PARAMETERS:
X - array[N], stores X-values.
MUST include only non-negative numbers (but may include
zero values). Can be unsorted.
Y - array[N], values to fit.
N - number of points. If N is less than length of X/Y, only
leading N elements are used.
CnstrLeft- optional equality constraint for model value at the left
boundary (at X=0). Specify NAN (Not-a-Number) if you do
not need constraint on the model value at X=0 (in C++ you
can pass alglib::fp_nan as parameter, in C# it will be
Double.NaN).
See below, section "EQUALITY CONSTRAINTS" for more
information about constraints.
CnstrRight- optional equality constraint for model value at X=infinity.
Specify NAN (Not-a-Number) if you do not need constraint
on the model value (in C++ you can pass alglib::fp_nan as
parameter, in C# it will be Double.NaN).
See below, section "EQUALITY CONSTRAINTS" for more
information about constraints.
Is4PL - whether 4PL or 5PL models are fitted
LambdaV - regularization coefficient, LambdaV>=0.
Set it to zero unless you know what you are doing.
EpsX - stopping condition (step size), EpsX>=0.
Zero value means that small step is automatically chosen.
See notes below for more information.
RsCnt - number of repeated restarts from random points. 4PL/5PL
models are prone to problem of bad local extrema. Utilizing
multiple random restarts allows us to improve algorithm
convergence.
RsCnt>=0.
Zero value means that function automatically choose small
amount of restarts (recommended).
OUTPUT PARAMETERS:
A, B, C, D- parameters of 4PL model
G - parameter of 5PL model; for Is4PL=True, G=1 is returned.
Rep - fitting report. This structure has many fields, but ONLY
ONES LISTED BELOW ARE SET:
* Rep.IterationsCount - number of iterations performed
* Rep.RMSError - root-mean-square error
* Rep.AvgError - average absolute error
* Rep.AvgRelError - average relative error (calculated for
non-zero Y-values)
* Rep.MaxError - maximum absolute error
* Rep.R2 - coefficient of determination, R-squared. This
coefficient is calculated as R2=1-RSS/TSS (in case
of nonlinear regression there are multiple ways to
define R2, each of them giving different results).
NOTE: after you obtained coefficients, you can evaluate model with
LogisticCalc5() function.
NOTE: step is automatically scaled according to scale of parameters being
fitted before we compare its length with EpsX. Thus, this function
can be used to fit data with very small or very large values without
changing EpsX.
EQUALITY CONSTRAINTS ON PARAMETERS
4PL/5PL solver supports equality constraints on model values at the left
boundary (X=0) and right boundary (X=infinity). These constraints are
completely optional and you can specify both of them, only one - or no
constraints at all.
Parameter CnstrLeft contains left constraint (or NAN for unconstrained
fitting), and CnstrRight contains right one. For 4PL, left constraint
ALWAYS corresponds to parameter A, and right one is ALWAYS constraint on
D. That's because 4PL model is normalized in such way that B>=0.
For 5PL model things are different. Unlike 4PL one, 5PL model is NOT
symmetric with respect to change in sign of B. Thus, negative B's are
possible, and left constraint may constrain parameter A (for positive B's)
- or parameter D (for negative B's). Similarly changes meaning of right
constraint.
You do not have to decide what parameter to constrain - algorithm will
automatically determine correct parameters as fitting progresses. However,
question highlighted above is important when you interpret fitting results.
-- ALGLIB PROJECT --
Copyright 14.02.2014 by Bochkanov Sergey
*************************************************************************/
</div><div style='margin-top: 0; margin-bottom: 0;'><b>void</b> alglib::logisticfit45x(
real_1d_array x,
real_1d_array y,
ae_int_t n,
<b>double</b> cnstrleft,
<b>double</b> cnstrright,
<b>bool</b> is4pl,
<b>double</b> lambdav,
<b>double</b> epsx,
ae_int_t rscnt,
<b>double</b>& a,
<b>double</b>& b,
<b>double</b>& c,
<b>double</b>& d,
<b>double</b>& g,
lsfitreport& rep);
</div></pre>
<a name='sub_logisticfit4ec'></a><h3 class=pageheader><code>logisticfit4ec</code> function</h3>
<pre class=source>
<div style='color: navy; margin-top: 0; margin-bottom: 0;'>/*************************************************************************
This function fits four-parameter logistic (4PL) model to data provided
by user, with optional constraints on parameters A and D. 4PL model has
following form:
F(x|A,B,C,D) = D+(A-D)/(1+Power(x/C,B))
Here:
* A, D - with optional equality constraints
* B>=0
* C>0
IMPORTANT: output of this function is constrained in such way that B>0.
Because 4PL model is symmetric with respect to B, there is no
need to explore B<0. Constraining B makes algorithm easier
to stabilize and debug.
Users who for some reason prefer to work with negative B's
should transform output themselves (swap A and D, replace B by
-B).
4PL fitting is implemented as follows:
* we perform small number of restarts from random locations which helps to
solve problem of bad local extrema. Locations are only partially random
- we use input data to determine good initial guess, but we include
controlled amount of randomness.
* we perform Levenberg-Marquardt fitting with very tight constraints on
parameters B and C - it allows us to find good initial guess for the
second stage without risk of running into "flat spot".
* second Levenberg-Marquardt round is performed without excessive
constraints. Results from the previous round are used as initial guess.
* after fitting is done, we compare results with best values found so far,
rewrite "best solution" if needed, and move to next random location.
Overall algorithm is very stable and is not prone to bad local extrema.
Furthermore, it automatically scales when input data have very large or
very small range.
INPUT PARAMETERS:
X - array[N], stores X-values.
MUST include only non-negative numbers (but may include
zero values). Can be unsorted.
Y - array[N], values to fit.
N - number of points. If N is less than length of X/Y, only
leading N elements are used.
CnstrLeft- optional equality constraint for model value at the left
boundary (at X=0). Specify NAN (Not-a-Number) if you do
not need constraint on the model value at X=0 (in C++ you
can pass alglib::fp_nan as parameter, in C# it will be
Double.NaN).
See below, section "EQUALITY CONSTRAINTS" for more
information about constraints.
CnstrRight- optional equality constraint for model value at X=infinity.
Specify NAN (Not-a-Number) if you do not need constraint
on the model value (in C++ you can pass alglib::fp_nan as
parameter, in C# it will be Double.NaN).
See below, section "EQUALITY CONSTRAINTS" for more
information about constraints.
OUTPUT PARAMETERS:
A, B, C, D- parameters of 4PL model
Rep - fitting report. This structure has many fields, but ONLY
ONES LISTED BELOW ARE SET:
* Rep.IterationsCount - number of iterations performed
* Rep.RMSError - root-mean-square error
* Rep.AvgError - average absolute error
* Rep.AvgRelError - average relative error (calculated for
non-zero Y-values)
* Rep.MaxError - maximum absolute error
* Rep.R2 - coefficient of determination, R-squared. This
coefficient is calculated as R2=1-RSS/TSS (in case
of nonlinear regression there are multiple ways to
define R2, each of them giving different results).
NOTE: after you obtained coefficients, you can evaluate model with
LogisticCalc4() function.
NOTE: if you need better control over fitting process than provided by this
function, you may use LogisticFit45X().
NOTE: step is automatically scaled according to scale of parameters being
fitted before we compare its length with EpsX. Thus, this function
can be used to fit data with very small or very large values without
changing EpsX.
EQUALITY CONSTRAINTS ON PARAMETERS
4PL/5PL solver supports equality constraints on model values at the left
boundary (X=0) and right boundary (X=infinity). These constraints are
completely optional and you can specify both of them, only one - or no
constraints at all.
Parameter CnstrLeft contains left constraint (or NAN for unconstrained
fitting), and CnstrRight contains right one. For 4PL, left constraint
ALWAYS corresponds to parameter A, and right one is ALWAYS constraint on
D. That's because 4PL model is normalized in such way that B>=0.
-- ALGLIB PROJECT --
Copyright 14.02.2014 by Bochkanov Sergey
*************************************************************************/
</div><div style='margin-top: 0; margin-bottom: 0;'><b>void</b> alglib::logisticfit4ec(
real_1d_array x,
real_1d_array y,
ae_int_t n,
<b>double</b> cnstrleft,
<b>double</b> cnstrright,
<b>double</b>& a,
<b>double</b>& b,
<b>double</b>& c,
<b>double</b>& d,
lsfitreport& rep);
</div></pre>
<a name='sub_logisticfit5'></a><h3 class=pageheader><code>logisticfit5</code> function</h3>
<pre class=source>
<div style='color: navy; margin-top: 0; margin-bottom: 0;'>/*************************************************************************
This function fits five-parameter logistic (5PL) model to data provided
by user. 5PL model has following form:
F(x|A,B,C,D,G) = D+(A-D)/Power(1+Power(x/C,B),G)
Here:
* A, D - unconstrained
* B - unconstrained
* C>0
* G>0
IMPORTANT: unlike in 4PL fitting, output of this function is NOT
constrained in such way that B is guaranteed to be positive.
Furthermore, unlike 4PL, 5PL model is NOT symmetric with
respect to B, so you can NOT transform model to equivalent one,
with B having desired sign (>0 or <0).
5PL fitting is implemented as follows:
* we perform small number of restarts from random locations which helps to
solve problem of bad local extrema. Locations are only partially random
- we use input data to determine good initial guess, but we include
controlled amount of randomness.
* we perform Levenberg-Marquardt fitting with very tight constraints on
parameters B and C - it allows us to find good initial guess for the
second stage without risk of running into "flat spot". Parameter G is
fixed at G=1.
* second Levenberg-Marquardt round is performed without excessive
constraints on B and C, but with G still equal to 1. Results from the
previous round are used as initial guess.
* third Levenberg-Marquardt round relaxes constraints on G and tries two
different models - one with B>0 and one with B<0.
* after fitting is done, we compare results with best values found so far,
rewrite "best solution" if needed, and move to next random location.
Overall algorithm is very stable and is not prone to bad local extrema.
Furthermore, it automatically scales when input data have very large or
very small range.
INPUT PARAMETERS:
X - array[N], stores X-values.
MUST include only non-negative numbers (but may include
zero values). Can be unsorted.
Y - array[N], values to fit.
N - number of points. If N is less than length of X/Y, only
leading N elements are used.
OUTPUT PARAMETERS:
A,B,C,D,G- parameters of 5PL model
Rep - fitting report. This structure has many fields, but ONLY
ONES LISTED BELOW ARE SET:
* Rep.IterationsCount - number of iterations performed
* Rep.RMSError - root-mean-square error
* Rep.AvgError - average absolute error
* Rep.AvgRelError - average relative error (calculated for
non-zero Y-values)
* Rep.MaxError - maximum absolute error
* Rep.R2 - coefficient of determination, R-squared. This
coefficient is calculated as R2=1-RSS/TSS (in case
of nonlinear regression there are multiple ways to
define R2, each of them giving different results).
NOTE: after you obtained coefficients, you can evaluate model with
LogisticCalc5() function.
NOTE: if you need better control over fitting process than provided by this
function, you may use LogisticFit45X().
NOTE: step is automatically scaled according to scale of parameters being
fitted before we compare its length with EpsX. Thus, this function
can be used to fit data with very small or very large values without
changing EpsX.
-- ALGLIB PROJECT --
Copyright 14.02.2014 by Bochkanov Sergey
*************************************************************************/
</div><div style='margin-top: 0; margin-bottom: 0;'><b>void</b> alglib::logisticfit5(
real_1d_array x,
real_1d_array y,
ae_int_t n,
<b>double</b>& a,
<b>double</b>& b,
<b>double</b>& c,
<b>double</b>& d,
<b>double</b>& g,
lsfitreport& rep);
</div></pre>
<p align=left class=pagecontent><span class=inlineheader>Examples:</span> <a href='#example_lsfit_t_5pl' class=nav>[1]</a> </p>
<a name='sub_logisticfit5ec'></a><h3 class=pageheader><code>logisticfit5ec</code> function</h3>
<pre class=source>
<div style='color: navy; margin-top: 0; margin-bottom: 0;'>/*************************************************************************
This function fits five-parameter logistic (5PL) model to data provided
by user, subject to optional equality constraints on parameters A and D.
5PL model has following form:
F(x|A,B,C,D,G) = D+(A-D)/Power(1+Power(x/C,B),G)
Here:
* A, D - with optional equality constraints
* B - unconstrained
* C>0
* G>0
IMPORTANT: unlike in 4PL fitting, output of this function is NOT
constrained in such way that B is guaranteed to be positive.
Furthermore, unlike 4PL, 5PL model is NOT symmetric with
respect to B, so you can NOT transform model to equivalent one,
with B having desired sign (>0 or <0).
5PL fitting is implemented as follows:
* we perform small number of restarts from random locations which helps to
solve problem of bad local extrema. Locations are only partially random
- we use input data to determine good initial guess, but we include
controlled amount of randomness.
* we perform Levenberg-Marquardt fitting with very tight constraints on
parameters B and C - it allows us to find good initial guess for the
second stage without risk of running into "flat spot". Parameter G is
fixed at G=1.
* second Levenberg-Marquardt round is performed without excessive
constraints on B and C, but with G still equal to 1. Results from the
previous round are used as initial guess.
* third Levenberg-Marquardt round relaxes constraints on G and tries two
different models - one with B>0 and one with B<0.
* after fitting is done, we compare results with best values found so far,
rewrite "best solution" if needed, and move to next random location.
Overall algorithm is very stable and is not prone to bad local extrema.
Furthermore, it automatically scales when input data have very large or
very small range.
INPUT PARAMETERS:
X - array[N], stores X-values.
MUST include only non-negative numbers (but may include
zero values). Can be unsorted.
Y - array[N], values to fit.
N - number of points. If N is less than length of X/Y, only
leading N elements are used.
CnstrLeft- optional equality constraint for model value at the left
boundary (at X=0). Specify NAN (Not-a-Number) if you do
not need constraint on the model value at X=0 (in C++ you
can pass alglib::fp_nan as parameter, in C# it will be
Double.NaN).
See below, section "EQUALITY CONSTRAINTS" for more
information about constraints.
CnstrRight- optional equality constraint for model value at X=infinity.
Specify NAN (Not-a-Number) if you do not need constraint
on the model value (in C++ you can pass alglib::fp_nan as
parameter, in C# it will be Double.NaN).
See below, section "EQUALITY CONSTRAINTS" for more
information about constraints.
OUTPUT PARAMETERS:
A,B,C,D,G- parameters of 5PL model
Rep - fitting report. This structure has many fields, but ONLY
ONES LISTED BELOW ARE SET:
* Rep.IterationsCount - number of iterations performed
* Rep.RMSError - root-mean-square error
* Rep.AvgError - average absolute error
* Rep.AvgRelError - average relative error (calculated for
non-zero Y-values)
* Rep.MaxError - maximum absolute error
* Rep.R2 - coefficient of determination, R-squared. This
coefficient is calculated as R2=1-RSS/TSS (in case
of nonlinear regression there are multiple ways to
define R2, each of them giving different results).
NOTE: after you obtained coefficients, you can evaluate model with
LogisticCalc5() function.
NOTE: if you need better control over fitting process than provided by this
function, you may use LogisticFit45X().
NOTE: step is automatically scaled according to scale of parameters being
fitted before we compare its length with EpsX. Thus, this function
can be used to fit data with very small or very large values without
changing EpsX.
EQUALITY CONSTRAINTS ON PARAMETERS
5PL solver supports equality constraints on model values at the left
boundary (X=0) and right boundary (X=infinity). These constraints are
completely optional and you can specify both of them, only one - or no
constraints at all.
Parameter CnstrLeft contains left constraint (or NAN for unconstrained
fitting), and CnstrRight contains right one.
Unlike 4PL one, 5PL model is NOT symmetric with respect to change in sign
of B. Thus, negative B's are possible, and left constraint may constrain
parameter A (for positive B's) - or parameter D (for negative B's).
Similarly changes meaning of right constraint.
You do not have to decide what parameter to constrain - algorithm will
automatically determine correct parameters as fitting progresses. However,
question highlighted above is important when you interpret fitting results.
-- ALGLIB PROJECT --
Copyright 14.02.2014 by Bochkanov Sergey
*************************************************************************/
</div><div style='margin-top: 0; margin-bottom: 0;'><b>void</b> alglib::logisticfit5ec(
real_1d_array x,
real_1d_array y,
ae_int_t n,
<b>double</b> cnstrleft,
<b>double</b> cnstrright,
<b>double</b>& a,
<b>double</b>& b,
<b>double</b>& c,
<b>double</b>& d,
<b>double</b>& g,
lsfitreport& rep);
</div></pre>
<a name='sub_lsfitcreatef'></a><h3 class=pageheader><code>lsfitcreatef</code> function</h3>
<pre class=source>
<div style='color: navy; margin-top: 0; margin-bottom: 0;'>/*************************************************************************
Nonlinear least squares fitting using function values only.
Combination of numerical differentiation and secant updates is used to
obtain function Jacobian.
Nonlinear task min(F(c)) is solved, where
F(c) = (f(c,x[0])-y[0])^2 + ... + (f(c,x[n-1])-y[n-1])^2,
* N is a number of points,
* M is a dimension of a space points belong to,
* K is a dimension of a space of parameters being fitted,
* w is an N-dimensional vector of weight coefficients,
* x is a set of N points, each of them is an M-dimensional vector,
* c is a K-dimensional vector of parameters being fitted
This subroutine uses only f(c,x[i]).
INPUT PARAMETERS:
X - array[0..N-1,0..M-1], points (one row = one point)
Y - array[0..N-1], function values.
C - array[0..K-1], initial approximation to the solution,
N - number of points, N>1
M - dimension of space
K - number of parameters being fitted
DiffStep- numerical differentiation step;
should not be very small or large;
large = loss of accuracy
small = growth of round-off errors
OUTPUT PARAMETERS:
State - structure which stores algorithm state
-- ALGLIB --
Copyright 18.10.2008 by Bochkanov Sergey
*************************************************************************/
</div><div style='margin-top: 0; margin-bottom: 0;'><b>void</b> alglib::lsfitcreatef(
real_2d_array x,
real_1d_array y,
real_1d_array c,
<b>double</b> diffstep,
lsfitstate& state);
<b>void</b> alglib::lsfitcreatef(
real_2d_array x,
real_1d_array y,
real_1d_array c,
ae_int_t n,
ae_int_t m,
ae_int_t k,
<b>double</b> diffstep,
lsfitstate& state);
</div></pre>
<p align=left class=pagecontent><span class=inlineheader>Examples:</span> <a href='#example_lsfit_d_nlf' class=nav>[1]</a> <a href='#example_lsfit_d_nlfb' class=nav>[2]</a> <a href='#example_lsfit_d_nlscale' class=nav>[3]</a> </p>
<a name='sub_lsfitcreatefg'></a><h3 class=pageheader><code>lsfitcreatefg</code> function</h3>
<pre class=source>
<div style='color: navy; margin-top: 0; margin-bottom: 0;'>/*************************************************************************
Nonlinear least squares fitting using gradient only, without individual
weights.
Nonlinear task min(F(c)) is solved, where
F(c) = ((f(c,x[0])-y[0]))^2 + ... + ((f(c,x[n-1])-y[n-1]))^2,
* N is a number of points,
* M is a dimension of a space points belong to,
* K is a dimension of a space of parameters being fitted,
* x is a set of N points, each of them is an M-dimensional vector,
* c is a K-dimensional vector of parameters being fitted
This subroutine uses only f(c,x[i]) and its gradient.
INPUT PARAMETERS:
X - array[0..N-1,0..M-1], points (one row = one point)
Y - array[0..N-1], function values.
C - array[0..K-1], initial approximation to the solution,
N - number of points, N>1
M - dimension of space
K - number of parameters being fitted
CheapFG - boolean flag, which is:
* True if both function and gradient calculation complexity
are less than O(M^2). An improved algorithm can
be used which corresponds to FGJ scheme from
MINLM unit.
* False otherwise.
Standard Jacibian-bases Levenberg-Marquardt algo
will be used (FJ scheme).
OUTPUT PARAMETERS:
State - structure which stores algorithm state
-- ALGLIB --
Copyright 17.08.2009 by Bochkanov Sergey
*************************************************************************/
</div><div style='margin-top: 0; margin-bottom: 0;'><b>void</b> alglib::lsfitcreatefg(
real_2d_array x,
real_1d_array y,
real_1d_array c,
<b>bool</b> cheapfg,
lsfitstate& state);
<b>void</b> alglib::lsfitcreatefg(
real_2d_array x,
real_1d_array y,
real_1d_array c,
ae_int_t n,
ae_int_t m,
ae_int_t k,
<b>bool</b> cheapfg,
lsfitstate& state);
</div></pre>
<p align=left class=pagecontent><span class=inlineheader>Examples:</span> <a href='#example_lsfit_d_nlfg' class=nav>[1]</a> </p>
<a name='sub_lsfitcreatefgh'></a><h3 class=pageheader><code>lsfitcreatefgh</code> function</h3>
<pre class=source>
<div style='color: navy; margin-top: 0; margin-bottom: 0;'>/*************************************************************************
Nonlinear least squares fitting using gradient/Hessian, without individial
weights.
Nonlinear task min(F(c)) is solved, where
F(c) = ((f(c,x[0])-y[0]))^2 + ... + ((f(c,x[n-1])-y[n-1]))^2,
* N is a number of points,
* M is a dimension of a space points belong to,
* K is a dimension of a space of parameters being fitted,
* x is a set of N points, each of them is an M-dimensional vector,
* c is a K-dimensional vector of parameters being fitted
This subroutine uses f(c,x[i]), its gradient and its Hessian.
INPUT PARAMETERS:
X - array[0..N-1,0..M-1], points (one row = one point)
Y - array[0..N-1], function values.
C - array[0..K-1], initial approximation to the solution,
N - number of points, N>1
M - dimension of space
K - number of parameters being fitted
OUTPUT PARAMETERS:
State - structure which stores algorithm state
-- ALGLIB --
Copyright 17.08.2009 by Bochkanov Sergey
*************************************************************************/
</div><div style='margin-top: 0; margin-bottom: 0;'><b>void</b> alglib::lsfitcreatefgh(
real_2d_array x,
real_1d_array y,
real_1d_array c,
lsfitstate& state);
<b>void</b> alglib::lsfitcreatefgh(
real_2d_array x,
real_1d_array y,
real_1d_array c,
ae_int_t n,
ae_int_t m,
ae_int_t k,
lsfitstate& state);
</div></pre>
<p align=left class=pagecontent><span class=inlineheader>Examples:</span> <a href='#example_lsfit_d_nlfgh' class=nav>[1]</a> </p>
<a name='sub_lsfitcreatewf'></a><h3 class=pageheader><code>lsfitcreatewf</code> function</h3>
<pre class=source>
<div style='color: navy; margin-top: 0; margin-bottom: 0;'>/*************************************************************************
Weighted nonlinear least squares fitting using function values only.
Combination of numerical differentiation and secant updates is used to
obtain function Jacobian.
Nonlinear task min(F(c)) is solved, where
F(c) = (w[0]*(f(c,x[0])-y[0]))^2 + ... + (w[n-1]*(f(c,x[n-1])-y[n-1]))^2,
* N is a number of points,
* M is a dimension of a space points belong to,
* K is a dimension of a space of parameters being fitted,
* w is an N-dimensional vector of weight coefficients,
* x is a set of N points, each of them is an M-dimensional vector,
* c is a K-dimensional vector of parameters being fitted
This subroutine uses only f(c,x[i]).
INPUT PARAMETERS:
X - array[0..N-1,0..M-1], points (one row = one point)
Y - array[0..N-1], function values.
W - weights, array[0..N-1]
C - array[0..K-1], initial approximation to the solution,
N - number of points, N>1
M - dimension of space
K - number of parameters being fitted
DiffStep- numerical differentiation step;
should not be very small or large;
large = loss of accuracy
small = growth of round-off errors
OUTPUT PARAMETERS:
State - structure which stores algorithm state
-- ALGLIB --
Copyright 18.10.2008 by Bochkanov Sergey
*************************************************************************/
</div><div style='margin-top: 0; margin-bottom: 0;'><b>void</b> alglib::lsfitcreatewf(
real_2d_array x,
real_1d_array y,
real_1d_array w,
real_1d_array c,
<b>double</b> diffstep,
lsfitstate& state);
<b>void</b> alglib::lsfitcreatewf(
real_2d_array x,
real_1d_array y,
real_1d_array w,
real_1d_array c,
ae_int_t n,
ae_int_t m,
ae_int_t k,
<b>double</b> diffstep,
lsfitstate& state);
</div></pre>
<p align=left class=pagecontent><span class=inlineheader>Examples:</span> <a href='#example_lsfit_d_nlf' class=nav>[1]</a> <a href='#example_lsfit_d_nlfb' class=nav>[2]</a> </p>
<a name='sub_lsfitcreatewfg'></a><h3 class=pageheader><code>lsfitcreatewfg</code> function</h3>
<pre class=source>
<div style='color: navy; margin-top: 0; margin-bottom: 0;'>/*************************************************************************
Weighted nonlinear least squares fitting using gradient only.
Nonlinear task min(F(c)) is solved, where
F(c) = (w[0]*(f(c,x[0])-y[0]))^2 + ... + (w[n-1]*(f(c,x[n-1])-y[n-1]))^2,
* N is a number of points,
* M is a dimension of a space points belong to,
* K is a dimension of a space of parameters being fitted,
* w is an N-dimensional vector of weight coefficients,
* x is a set of N points, each of them is an M-dimensional vector,
* c is a K-dimensional vector of parameters being fitted
This subroutine uses only f(c,x[i]) and its gradient.
INPUT PARAMETERS:
X - array[0..N-1,0..M-1], points (one row = one point)
Y - array[0..N-1], function values.
W - weights, array[0..N-1]
C - array[0..K-1], initial approximation to the solution,
N - number of points, N>1
M - dimension of space
K - number of parameters being fitted
CheapFG - boolean flag, which is:
* True if both function and gradient calculation complexity
are less than O(M^2). An improved algorithm can
be used which corresponds to FGJ scheme from
MINLM unit.
* False otherwise.
Standard Jacibian-bases Levenberg-Marquardt algo
will be used (FJ scheme).
OUTPUT PARAMETERS:
State - structure which stores algorithm state
See also:
LSFitResults
LSFitCreateFG (fitting without weights)
LSFitCreateWFGH (fitting using Hessian)
LSFitCreateFGH (fitting using Hessian, without weights)
-- ALGLIB --
Copyright 17.08.2009 by Bochkanov Sergey
*************************************************************************/
</div><div style='margin-top: 0; margin-bottom: 0;'><b>void</b> alglib::lsfitcreatewfg(
real_2d_array x,
real_1d_array y,
real_1d_array w,
real_1d_array c,
<b>bool</b> cheapfg,
lsfitstate& state);
<b>void</b> alglib::lsfitcreatewfg(
real_2d_array x,
real_1d_array y,
real_1d_array w,
real_1d_array c,
ae_int_t n,
ae_int_t m,
ae_int_t k,
<b>bool</b> cheapfg,
lsfitstate& state);
</div></pre>
<p align=left class=pagecontent><span class=inlineheader>Examples:</span> <a href='#example_lsfit_d_nlfg' class=nav>[1]</a> </p>
<a name='sub_lsfitcreatewfgh'></a><h3 class=pageheader><code>lsfitcreatewfgh</code> function</h3>
<pre class=source>
<div style='color: navy; margin-top: 0; margin-bottom: 0;'>/*************************************************************************
Weighted nonlinear least squares fitting using gradient/Hessian.
Nonlinear task min(F(c)) is solved, where
F(c) = (w[0]*(f(c,x[0])-y[0]))^2 + ... + (w[n-1]*(f(c,x[n-1])-y[n-1]))^2,
* N is a number of points,
* M is a dimension of a space points belong to,
* K is a dimension of a space of parameters being fitted,
* w is an N-dimensional vector of weight coefficients,
* x is a set of N points, each of them is an M-dimensional vector,
* c is a K-dimensional vector of parameters being fitted
This subroutine uses f(c,x[i]), its gradient and its Hessian.
INPUT PARAMETERS:
X - array[0..N-1,0..M-1], points (one row = one point)
Y - array[0..N-1], function values.
W - weights, array[0..N-1]
C - array[0..K-1], initial approximation to the solution,
N - number of points, N>1
M - dimension of space
K - number of parameters being fitted
OUTPUT PARAMETERS:
State - structure which stores algorithm state
-- ALGLIB --
Copyright 17.08.2009 by Bochkanov Sergey
*************************************************************************/
</div><div style='margin-top: 0; margin-bottom: 0;'><b>void</b> alglib::lsfitcreatewfgh(
real_2d_array x,
real_1d_array y,
real_1d_array w,
real_1d_array c,
lsfitstate& state);
<b>void</b> alglib::lsfitcreatewfgh(
real_2d_array x,
real_1d_array y,
real_1d_array w,
real_1d_array c,
ae_int_t n,
ae_int_t m,
ae_int_t k,
lsfitstate& state);
</div></pre>
<p align=left class=pagecontent><span class=inlineheader>Examples:</span> <a href='#example_lsfit_d_nlfgh' class=nav>[1]</a> </p>
<a name='sub_lsfitfit'></a><h3 class=pageheader><code>lsfitfit</code> function</h3>
<pre class=source>
<div style='color: navy; margin-top: 0; margin-bottom: 0;'>/*************************************************************************
This family of functions is used to launcn iterations of nonlinear fitter
These functions accept following parameters:
state - algorithm state
func - callback which calculates function (or merit function)
value func at given point x
grad - callback which calculates function (or merit function)
value func and gradient grad at given point x
hess - callback which calculates function (or merit function)
value func, gradient grad and Hessian hess at given point x
rep - optional callback which is called after each iteration
can be NULL
ptr - optional pointer which is passed to func/grad/hess/jac/rep
can be NULL
NOTES:
1. this algorithm is somewhat unusual because it works with parameterized
function f(C,X), where X is a function argument (we have many points
which are characterized by different argument values), and C is a
parameter to fit.
For example, if we want to do linear fit by f(c0,c1,x) = c0*x+c1, then
x will be argument, and {c0,c1} will be parameters.
It is important to understand that this algorithm finds minimum in the
space of function PARAMETERS (not arguments), so it needs derivatives
of f() with respect to C, not X.
In the example above it will need f=c0*x+c1 and {df/dc0,df/dc1} = {x,1}
instead of {df/dx} = {c0}.
2. Callback functions accept C as the first parameter, and X as the second
3. If state was created with LSFitCreateFG(), algorithm needs just
function and its gradient, but if state was created with
LSFitCreateFGH(), algorithm will need function, gradient and Hessian.
According to the said above, there ase several versions of this
function, which accept different sets of callbacks.
This flexibility opens way to subtle errors - you may create state with
LSFitCreateFGH() (optimization using Hessian), but call function which
does not accept Hessian. So when algorithm will request Hessian, there
will be no callback to call. In this case exception will be thrown.
Be careful to avoid such errors because there is no way to find them at
compile time - you can see them at runtime only.
-- ALGLIB --
Copyright 17.08.2009 by Bochkanov Sergey
*************************************************************************/
</div><div style='margin-top: 0; margin-bottom: 0;'><b>void</b> lsfitfit(lsfitstate &state,
<b>void</b> (*func)(<b>const</b> real_1d_array &c, <b>const</b> real_1d_array &x, <b>double</b> &func, <b>void</b> *ptr),
<b>void</b> (*rep)(<b>const</b> real_1d_array &c, <b>double</b> func, <b>void</b> *ptr) = NULL,
<b>void</b> *ptr = NULL);
<b>void</b> lsfitfit(lsfitstate &state,
<b>void</b> (*func)(<b>const</b> real_1d_array &c, <b>const</b> real_1d_array &x, <b>double</b> &func, <b>void</b> *ptr),
<b>void</b> (*grad)(<b>const</b> real_1d_array &c, <b>const</b> real_1d_array &x, <b>double</b> &func, real_1d_array &grad, <b>void</b> *ptr),
<b>void</b> (*rep)(<b>const</b> real_1d_array &c, <b>double</b> func, <b>void</b> *ptr) = NULL,
<b>void</b> *ptr = NULL);
<b>void</b> lsfitfit(lsfitstate &state,
<b>void</b> (*func)(<b>const</b> real_1d_array &c, <b>const</b> real_1d_array &x, <b>double</b> &func, <b>void</b> *ptr),
<b>void</b> (*grad)(<b>const</b> real_1d_array &c, <b>const</b> real_1d_array &x, <b>double</b> &func, real_1d_array &grad, <b>void</b> *ptr),
<b>void</b> (*hess)(<b>const</b> real_1d_array &c, <b>const</b> real_1d_array &x, <b>double</b> &func, real_1d_array &grad, real_2d_array &hess, <b>void</b> *ptr),
<b>void</b> (*rep)(<b>const</b> real_1d_array &c, <b>double</b> func, <b>void</b> *ptr) = NULL,
<b>void</b> *ptr = NULL);
</div></pre>
<p align=left class=pagecontent><span class=inlineheader>Examples:</span> <a href='#example_lsfit_d_nlf' class=nav>[1]</a> <a href='#example_lsfit_d_nlfg' class=nav>[2]</a> <a href='#example_lsfit_d_nlfgh' class=nav>[3]</a> <a href='#example_lsfit_d_nlfb' class=nav>[4]</a> <a href='#example_lsfit_d_nlscale' class=nav>[5]</a> </p>
<a name='sub_lsfitlinear'></a><h3 class=pageheader><code>lsfitlinear</code> function</h3>
<pre class=source>
<div style='color: navy; margin-top: 0; margin-bottom: 0;'>/*************************************************************************
Linear least squares fitting.
QR decomposition is used to reduce task to MxM, then triangular solver or
SVD-based solver is used depending on condition number of the system. It
allows to maximize speed and retain decent accuracy.
IMPORTANT: if you want to perform polynomial fitting, it may be more
convenient to use PolynomialFit() function. This function gives
best results on polynomial problems and solves numerical
stability issues which arise when you fit high-degree
polynomials to your data.
COMMERCIAL EDITION OF ALGLIB:
! Commercial version of ALGLIB includes two important improvements of
! this function, which can be used from C++ and C#:
! * Intel MKL support (lightweight Intel MKL is shipped with ALGLIB)
! * multithreading support
!
! Intel MKL gives approximately constant (with respect to number of
! worker threads) acceleration factor which depends on CPU being used,
! problem size and "baseline" ALGLIB edition which is used for
! comparison.
!
! Speed-up provided by multithreading greatly depends on problem size
! - only large problems (number of coefficients is more than 500) can be
! efficiently multithreaded.
!
! Generally, commercial ALGLIB is several times faster than open-source
! generic C edition, and many times faster than open-source C# edition.
!
! We recommend you to read 'Working with commercial version' section of
! ALGLIB Reference Manual in order to find out how to use performance-
! related features provided by commercial edition of ALGLIB.
INPUT PARAMETERS:
Y - array[0..N-1] Function values in N points.
FMatrix - a table of basis functions values, array[0..N-1, 0..M-1].
FMatrix[I, J] - value of J-th basis function in I-th point.
N - number of points used. N>=1.
M - number of basis functions, M>=1.
OUTPUT PARAMETERS:
Info - error code:
* -4 internal SVD decomposition subroutine failed (very
rare and for degenerate systems only)
* 1 task is solved
C - decomposition coefficients, array[0..M-1]
Rep - fitting report. Following fields are set:
* Rep.TaskRCond reciprocal of condition number
* R2 non-adjusted coefficient of determination
(non-weighted)
* RMSError rms error on the (X,Y).
* AvgError average error on the (X,Y).
* AvgRelError average relative error on the non-zero Y
* MaxError maximum error
NON-WEIGHTED ERRORS ARE CALCULATED
ERRORS IN PARAMETERS
This solver also calculates different kinds of errors in parameters and
fills corresponding fields of report:
* Rep.CovPar covariance matrix for parameters, array[K,K].
* Rep.ErrPar errors in parameters, array[K],
errpar = sqrt(diag(CovPar))
* Rep.ErrCurve vector of fit errors - standard deviations of empirical
best-fit curve from "ideal" best-fit curve built with
infinite number of samples, array[N].
errcurve = sqrt(diag(F*CovPar*F')),
where F is functions matrix.
* Rep.Noise vector of per-point estimates of noise, array[N]
NOTE: noise in the data is estimated as follows:
* for fitting without user-supplied weights all points are
assumed to have same level of noise, which is estimated from
the data
* for fitting with user-supplied weights we assume that noise
level in I-th point is inversely proportional to Ith weight.
Coefficient of proportionality is estimated from the data.
NOTE: we apply small amount of regularization when we invert squared
Jacobian and calculate covariance matrix. It guarantees that
algorithm won't divide by zero during inversion, but skews
error estimates a bit (fractional error is about 10^-9).
However, we believe that this difference is insignificant for
all practical purposes except for the situation when you want
to compare ALGLIB results with "reference" implementation up
to the last significant digit.
NOTE: covariance matrix is estimated using correction for degrees
of freedom (covariances are divided by N-M instead of dividing
by N).
-- ALGLIB --
Copyright 17.08.2009 by Bochkanov Sergey
*************************************************************************/
</div><div style='margin-top: 0; margin-bottom: 0;'><b>void</b> alglib::lsfitlinear(
real_1d_array y,
real_2d_array fmatrix,
ae_int_t& info,
real_1d_array& c,
lsfitreport& rep);
<b>void</b> alglib::lsfitlinear(
real_1d_array y,
real_2d_array fmatrix,
ae_int_t n,
ae_int_t m,
ae_int_t& info,
real_1d_array& c,
lsfitreport& rep);
<b>void</b> alglib::smp_lsfitlinear(
real_1d_array y,
real_2d_array fmatrix,
ae_int_t& info,
real_1d_array& c,
lsfitreport& rep);
<b>void</b> alglib::smp_lsfitlinear(
real_1d_array y,
real_2d_array fmatrix,
ae_int_t n,
ae_int_t m,
ae_int_t& info,
real_1d_array& c,
lsfitreport& rep);
</div></pre>
<p align=left class=pagecontent><span class=inlineheader>Examples:</span> <a href='#example_lsfit_d_lin' class=nav>[1]</a> </p>
<a name='sub_lsfitlinearc'></a><h3 class=pageheader><code>lsfitlinearc</code> function</h3>
<pre class=source>
<div style='color: navy; margin-top: 0; margin-bottom: 0;'>/*************************************************************************
Constained linear least squares fitting.
This is variation of LSFitLinear(), which searchs for min|A*x=b| given
that K additional constaints C*x=bc are satisfied. It reduces original
task to modified one: min|B*y-d| WITHOUT constraints, then LSFitLinear()
is called.
IMPORTANT: if you want to perform polynomial fitting, it may be more
convenient to use PolynomialFit() function. This function gives
best results on polynomial problems and solves numerical
stability issues which arise when you fit high-degree
polynomials to your data.
COMMERCIAL EDITION OF ALGLIB:
! Commercial version of ALGLIB includes two important improvements of
! this function, which can be used from C++ and C#:
! * Intel MKL support (lightweight Intel MKL is shipped with ALGLIB)
! * multithreading support
!
! Intel MKL gives approximately constant (with respect to number of
! worker threads) acceleration factor which depends on CPU being used,
! problem size and "baseline" ALGLIB edition which is used for
! comparison.
!
! Speed-up provided by multithreading greatly depends on problem size
! - only large problems (number of coefficients is more than 500) can be
! efficiently multithreaded.
!
! Generally, commercial ALGLIB is several times faster than open-source
! generic C edition, and many times faster than open-source C# edition.
!
! We recommend you to read 'Working with commercial version' section of
! ALGLIB Reference Manual in order to find out how to use performance-
! related features provided by commercial edition of ALGLIB.
INPUT PARAMETERS:
Y - array[0..N-1] Function values in N points.
FMatrix - a table of basis functions values, array[0..N-1, 0..M-1].
FMatrix[I,J] - value of J-th basis function in I-th point.
CMatrix - a table of constaints, array[0..K-1,0..M].
I-th row of CMatrix corresponds to I-th linear constraint:
CMatrix[I,0]*C[0] + ... + CMatrix[I,M-1]*C[M-1] = CMatrix[I,M]
N - number of points used. N>=1.
M - number of basis functions, M>=1.
K - number of constraints, 0 <= K < M
K=0 corresponds to absence of constraints.
OUTPUT PARAMETERS:
Info - error code:
* -4 internal SVD decomposition subroutine failed (very
rare and for degenerate systems only)
* -3 either too many constraints (M or more),
degenerate constraints (some constraints are
repetead twice) or inconsistent constraints were
specified.
* 1 task is solved
C - decomposition coefficients, array[0..M-1]
Rep - fitting report. Following fields are set:
* R2 non-adjusted coefficient of determination
(non-weighted)
* RMSError rms error on the (X,Y).
* AvgError average error on the (X,Y).
* AvgRelError average relative error on the non-zero Y
* MaxError maximum error
NON-WEIGHTED ERRORS ARE CALCULATED
IMPORTANT:
this subroitine doesn't calculate task's condition number for K<>0.
ERRORS IN PARAMETERS
This solver also calculates different kinds of errors in parameters and
fills corresponding fields of report:
* Rep.CovPar covariance matrix for parameters, array[K,K].
* Rep.ErrPar errors in parameters, array[K],
errpar = sqrt(diag(CovPar))
* Rep.ErrCurve vector of fit errors - standard deviations of empirical
best-fit curve from "ideal" best-fit curve built with
infinite number of samples, array[N].
errcurve = sqrt(diag(F*CovPar*F')),
where F is functions matrix.
* Rep.Noise vector of per-point estimates of noise, array[N]
IMPORTANT: errors in parameters are calculated without taking into
account boundary/linear constraints! Presence of constraints
changes distribution of errors, but there is no easy way to
account for constraints when you calculate covariance matrix.
NOTE: noise in the data is estimated as follows:
* for fitting without user-supplied weights all points are
assumed to have same level of noise, which is estimated from
the data
* for fitting with user-supplied weights we assume that noise
level in I-th point is inversely proportional to Ith weight.
Coefficient of proportionality is estimated from the data.
NOTE: we apply small amount of regularization when we invert squared
Jacobian and calculate covariance matrix. It guarantees that
algorithm won't divide by zero during inversion, but skews
error estimates a bit (fractional error is about 10^-9).
However, we believe that this difference is insignificant for
all practical purposes except for the situation when you want
to compare ALGLIB results with "reference" implementation up
to the last significant digit.
NOTE: covariance matrix is estimated using correction for degrees
of freedom (covariances are divided by N-M instead of dividing
by N).
-- ALGLIB --
Copyright 07.09.2009 by Bochkanov Sergey
*************************************************************************/
</div><div style='margin-top: 0; margin-bottom: 0;'><b>void</b> alglib::lsfitlinearc(
real_1d_array y,
real_2d_array fmatrix,
real_2d_array cmatrix,
ae_int_t& info,
real_1d_array& c,
lsfitreport& rep);
<b>void</b> alglib::lsfitlinearc(
real_1d_array y,
real_2d_array fmatrix,
real_2d_array cmatrix,
ae_int_t n,
ae_int_t m,
ae_int_t k,
ae_int_t& info,
real_1d_array& c,
lsfitreport& rep);
<b>void</b> alglib::smp_lsfitlinearc(
real_1d_array y,
real_2d_array fmatrix,
real_2d_array cmatrix,
ae_int_t& info,
real_1d_array& c,
lsfitreport& rep);
<b>void</b> alglib::smp_lsfitlinearc(
real_1d_array y,
real_2d_array fmatrix,
real_2d_array cmatrix,
ae_int_t n,
ae_int_t m,
ae_int_t k,
ae_int_t& info,
real_1d_array& c,
lsfitreport& rep);
</div></pre>
<p align=left class=pagecontent><span class=inlineheader>Examples:</span> <a href='#example_lsfit_d_linc' class=nav>[1]</a> </p>
<a name='sub_lsfitlinearw'></a><h3 class=pageheader><code>lsfitlinearw</code> function</h3>
<pre class=source>
<div style='color: navy; margin-top: 0; margin-bottom: 0;'>/*************************************************************************
Weighted linear least squares fitting.
QR decomposition is used to reduce task to MxM, then triangular solver or
SVD-based solver is used depending on condition number of the system. It
allows to maximize speed and retain decent accuracy.
IMPORTANT: if you want to perform polynomial fitting, it may be more
convenient to use PolynomialFit() function. This function gives
best results on polynomial problems and solves numerical
stability issues which arise when you fit high-degree
polynomials to your data.
COMMERCIAL EDITION OF ALGLIB:
! Commercial version of ALGLIB includes two important improvements of
! this function, which can be used from C++ and C#:
! * Intel MKL support (lightweight Intel MKL is shipped with ALGLIB)
! * multithreading support
!
! Intel MKL gives approximately constant (with respect to number of
! worker threads) acceleration factor which depends on CPU being used,
! problem size and "baseline" ALGLIB edition which is used for
! comparison.
!
! Speed-up provided by multithreading greatly depends on problem size
! - only large problems (number of coefficients is more than 500) can be
! efficiently multithreaded.
!
! Generally, commercial ALGLIB is several times faster than open-source
! generic C edition, and many times faster than open-source C# edition.
!
! We recommend you to read 'Working with commercial version' section of
! ALGLIB Reference Manual in order to find out how to use performance-
! related features provided by commercial edition of ALGLIB.
INPUT PARAMETERS:
Y - array[0..N-1] Function values in N points.
W - array[0..N-1] Weights corresponding to function values.
Each summand in square sum of approximation deviations
from given values is multiplied by the square of
corresponding weight.
FMatrix - a table of basis functions values, array[0..N-1, 0..M-1].
FMatrix[I, J] - value of J-th basis function in I-th point.
N - number of points used. N>=1.
M - number of basis functions, M>=1.
OUTPUT PARAMETERS:
Info - error code:
* -4 internal SVD decomposition subroutine failed (very
rare and for degenerate systems only)
* -1 incorrect N/M were specified
* 1 task is solved
C - decomposition coefficients, array[0..M-1]
Rep - fitting report. Following fields are set:
* Rep.TaskRCond reciprocal of condition number
* R2 non-adjusted coefficient of determination
(non-weighted)
* RMSError rms error on the (X,Y).
* AvgError average error on the (X,Y).
* AvgRelError average relative error on the non-zero Y
* MaxError maximum error
NON-WEIGHTED ERRORS ARE CALCULATED
ERRORS IN PARAMETERS
This solver also calculates different kinds of errors in parameters and
fills corresponding fields of report:
* Rep.CovPar covariance matrix for parameters, array[K,K].
* Rep.ErrPar errors in parameters, array[K],
errpar = sqrt(diag(CovPar))
* Rep.ErrCurve vector of fit errors - standard deviations of empirical
best-fit curve from "ideal" best-fit curve built with
infinite number of samples, array[N].
errcurve = sqrt(diag(F*CovPar*F')),
where F is functions matrix.
* Rep.Noise vector of per-point estimates of noise, array[N]
NOTE: noise in the data is estimated as follows:
* for fitting without user-supplied weights all points are
assumed to have same level of noise, which is estimated from
the data
* for fitting with user-supplied weights we assume that noise
level in I-th point is inversely proportional to Ith weight.
Coefficient of proportionality is estimated from the data.
NOTE: we apply small amount of regularization when we invert squared
Jacobian and calculate covariance matrix. It guarantees that
algorithm won't divide by zero during inversion, but skews
error estimates a bit (fractional error is about 10^-9).
However, we believe that this difference is insignificant for
all practical purposes except for the situation when you want
to compare ALGLIB results with "reference" implementation up
to the last significant digit.
NOTE: covariance matrix is estimated using correction for degrees
of freedom (covariances are divided by N-M instead of dividing
by N).
-- ALGLIB --
Copyright 17.08.2009 by Bochkanov Sergey
*************************************************************************/
</div><div style='margin-top: 0; margin-bottom: 0;'><b>void</b> alglib::lsfitlinearw(
real_1d_array y,
real_1d_array w,
real_2d_array fmatrix,
ae_int_t& info,
real_1d_array& c,
lsfitreport& rep);
<b>void</b> alglib::lsfitlinearw(
real_1d_array y,
real_1d_array w,
real_2d_array fmatrix,
ae_int_t n,
ae_int_t m,
ae_int_t& info,
real_1d_array& c,
lsfitreport& rep);
<b>void</b> alglib::smp_lsfitlinearw(
real_1d_array y,
real_1d_array w,
real_2d_array fmatrix,
ae_int_t& info,
real_1d_array& c,
lsfitreport& rep);
<b>void</b> alglib::smp_lsfitlinearw(
real_1d_array y,
real_1d_array w,
real_2d_array fmatrix,
ae_int_t n,
ae_int_t m,
ae_int_t& info,
real_1d_array& c,
lsfitreport& rep);
</div></pre>
<p align=left class=pagecontent><span class=inlineheader>Examples:</span> <a href='#example_lsfit_d_lin' class=nav>[1]</a> </p>
<a name='sub_lsfitlinearwc'></a><h3 class=pageheader><code>lsfitlinearwc</code> function</h3>
<pre class=source>
<div style='color: navy; margin-top: 0; margin-bottom: 0;'>/*************************************************************************
Weighted constained linear least squares fitting.
This is variation of LSFitLinearW(), which searchs for min|A*x=b| given
that K additional constaints C*x=bc are satisfied. It reduces original
task to modified one: min|B*y-d| WITHOUT constraints, then LSFitLinearW()
is called.
IMPORTANT: if you want to perform polynomial fitting, it may be more
convenient to use PolynomialFit() function. This function gives
best results on polynomial problems and solves numerical
stability issues which arise when you fit high-degree
polynomials to your data.
COMMERCIAL EDITION OF ALGLIB:
! Commercial version of ALGLIB includes two important improvements of
! this function, which can be used from C++ and C#:
! * Intel MKL support (lightweight Intel MKL is shipped with ALGLIB)
! * multithreading support
!
! Intel MKL gives approximately constant (with respect to number of
! worker threads) acceleration factor which depends on CPU being used,
! problem size and "baseline" ALGLIB edition which is used for
! comparison.
!
! Speed-up provided by multithreading greatly depends on problem size
! - only large problems (number of coefficients is more than 500) can be
! efficiently multithreaded.
!
! Generally, commercial ALGLIB is several times faster than open-source
! generic C edition, and many times faster than open-source C# edition.
!
! We recommend you to read 'Working with commercial version' section of
! ALGLIB Reference Manual in order to find out how to use performance-
! related features provided by commercial edition of ALGLIB.
INPUT PARAMETERS:
Y - array[0..N-1] Function values in N points.
W - array[0..N-1] Weights corresponding to function values.
Each summand in square sum of approximation deviations
from given values is multiplied by the square of
corresponding weight.
FMatrix - a table of basis functions values, array[0..N-1, 0..M-1].
FMatrix[I,J] - value of J-th basis function in I-th point.
CMatrix - a table of constaints, array[0..K-1,0..M].
I-th row of CMatrix corresponds to I-th linear constraint:
CMatrix[I,0]*C[0] + ... + CMatrix[I,M-1]*C[M-1] = CMatrix[I,M]
N - number of points used. N>=1.
M - number of basis functions, M>=1.
K - number of constraints, 0 <= K < M
K=0 corresponds to absence of constraints.
OUTPUT PARAMETERS:
Info - error code:
* -4 internal SVD decomposition subroutine failed (very
rare and for degenerate systems only)
* -3 either too many constraints (M or more),
degenerate constraints (some constraints are
repetead twice) or inconsistent constraints were
specified.
* 1 task is solved
C - decomposition coefficients, array[0..M-1]
Rep - fitting report. Following fields are set:
* R2 non-adjusted coefficient of determination
(non-weighted)
* RMSError rms error on the (X,Y).
* AvgError average error on the (X,Y).
* AvgRelError average relative error on the non-zero Y
* MaxError maximum error
NON-WEIGHTED ERRORS ARE CALCULATED
IMPORTANT:
this subroitine doesn't calculate task's condition number for K<>0.
ERRORS IN PARAMETERS
This solver also calculates different kinds of errors in parameters and
fills corresponding fields of report:
* Rep.CovPar covariance matrix for parameters, array[K,K].
* Rep.ErrPar errors in parameters, array[K],
errpar = sqrt(diag(CovPar))
* Rep.ErrCurve vector of fit errors - standard deviations of empirical
best-fit curve from "ideal" best-fit curve built with
infinite number of samples, array[N].
errcurve = sqrt(diag(F*CovPar*F')),
where F is functions matrix.
* Rep.Noise vector of per-point estimates of noise, array[N]
IMPORTANT: errors in parameters are calculated without taking into
account boundary/linear constraints! Presence of constraints
changes distribution of errors, but there is no easy way to
account for constraints when you calculate covariance matrix.
NOTE: noise in the data is estimated as follows:
* for fitting without user-supplied weights all points are
assumed to have same level of noise, which is estimated from
the data
* for fitting with user-supplied weights we assume that noise
level in I-th point is inversely proportional to Ith weight.
Coefficient of proportionality is estimated from the data.
NOTE: we apply small amount of regularization when we invert squared
Jacobian and calculate covariance matrix. It guarantees that
algorithm won't divide by zero during inversion, but skews
error estimates a bit (fractional error is about 10^-9).
However, we believe that this difference is insignificant for
all practical purposes except for the situation when you want
to compare ALGLIB results with "reference" implementation up
to the last significant digit.
NOTE: covariance matrix is estimated using correction for degrees
of freedom (covariances are divided by N-M instead of dividing
by N).
-- ALGLIB --
Copyright 07.09.2009 by Bochkanov Sergey
*************************************************************************/
</div><div style='margin-top: 0; margin-bottom: 0;'><b>void</b> alglib::lsfitlinearwc(
real_1d_array y,
real_1d_array w,
real_2d_array fmatrix,
real_2d_array cmatrix,
ae_int_t& info,
real_1d_array& c,
lsfitreport& rep);
<b>void</b> alglib::lsfitlinearwc(
real_1d_array y,
real_1d_array w,
real_2d_array fmatrix,
real_2d_array cmatrix,
ae_int_t n,
ae_int_t m,
ae_int_t k,
ae_int_t& info,
real_1d_array& c,
lsfitreport& rep);
<b>void</b> alglib::smp_lsfitlinearwc(
real_1d_array y,
real_1d_array w,
real_2d_array fmatrix,
real_2d_array cmatrix,
ae_int_t& info,
real_1d_array& c,
lsfitreport& rep);
<b>void</b> alglib::smp_lsfitlinearwc(
real_1d_array y,
real_1d_array w,
real_2d_array fmatrix,
real_2d_array cmatrix,
ae_int_t n,
ae_int_t m,
ae_int_t k,
ae_int_t& info,
real_1d_array& c,
lsfitreport& rep);
</div></pre>
<p align=left class=pagecontent><span class=inlineheader>Examples:</span> <a href='#example_lsfit_d_linc' class=nav>[1]</a> </p>
<a name='sub_lsfitresults'></a><h3 class=pageheader><code>lsfitresults</code> function</h3>
<pre class=source>
<div style='color: navy; margin-top: 0; margin-bottom: 0;'>/*************************************************************************
Nonlinear least squares fitting results.
Called after return from LSFitFit().
INPUT PARAMETERS:
State - algorithm state
OUTPUT PARAMETERS:
Info - completion code:
* -7 gradient verification failed.
See LSFitSetGradientCheck() for more information.
* 1 relative function improvement is no more than
EpsF.
* 2 relative step is no more than EpsX.
* 4 gradient norm is no more than EpsG
* 5 MaxIts steps was taken
* 7 stopping conditions are too stringent,
further improvement is impossible
C - array[0..K-1], solution
Rep - optimization report. On success following fields are set:
* R2 non-adjusted coefficient of determination
(non-weighted)
* RMSError rms error on the (X,Y).
* AvgError average error on the (X,Y).
* AvgRelError average relative error on the non-zero Y
* MaxError maximum error
NON-WEIGHTED ERRORS ARE CALCULATED
* WRMSError weighted rms error on the (X,Y).
ERRORS IN PARAMETERS
This solver also calculates different kinds of errors in parameters and
fills corresponding fields of report:
* Rep.CovPar covariance matrix for parameters, array[K,K].
* Rep.ErrPar errors in parameters, array[K],
errpar = sqrt(diag(CovPar))
* Rep.ErrCurve vector of fit errors - standard deviations of empirical
best-fit curve from "ideal" best-fit curve built with
infinite number of samples, array[N].
errcurve = sqrt(diag(J*CovPar*J')),
where J is Jacobian matrix.
* Rep.Noise vector of per-point estimates of noise, array[N]
IMPORTANT: errors in parameters are calculated without taking into
account boundary/linear constraints! Presence of constraints
changes distribution of errors, but there is no easy way to
account for constraints when you calculate covariance matrix.
NOTE: noise in the data is estimated as follows:
* for fitting without user-supplied weights all points are
assumed to have same level of noise, which is estimated from
the data
* for fitting with user-supplied weights we assume that noise
level in I-th point is inversely proportional to Ith weight.
Coefficient of proportionality is estimated from the data.
NOTE: we apply small amount of regularization when we invert squared
Jacobian and calculate covariance matrix. It guarantees that
algorithm won't divide by zero during inversion, but skews
error estimates a bit (fractional error is about 10^-9).
However, we believe that this difference is insignificant for
all practical purposes except for the situation when you want
to compare ALGLIB results with "reference" implementation up
to the last significant digit.
NOTE: covariance matrix is estimated using correction for degrees
of freedom (covariances are divided by N-M instead of dividing
by N).
-- ALGLIB --
Copyright 17.08.2009 by Bochkanov Sergey
*************************************************************************/
</div><div style='margin-top: 0; margin-bottom: 0;'><b>void</b> alglib::lsfitresults(
lsfitstate state,
ae_int_t& info,
real_1d_array& c,
lsfitreport& rep);
</div></pre>
<p align=left class=pagecontent><span class=inlineheader>Examples:</span> <a href='#example_lsfit_d_nlf' class=nav>[1]</a> <a href='#example_lsfit_d_nlfg' class=nav>[2]</a> <a href='#example_lsfit_d_nlfgh' class=nav>[3]</a> <a href='#example_lsfit_d_nlfb' class=nav>[4]</a> <a href='#example_lsfit_d_nlscale' class=nav>[5]</a> </p>
<a name='sub_lsfitsetbc'></a><h3 class=pageheader><code>lsfitsetbc</code> function</h3>
<pre class=source>
<div style='color: navy; margin-top: 0; margin-bottom: 0;'>/*************************************************************************
This function sets boundary constraints for underlying optimizer
Boundary constraints are inactive by default (after initial creation).
They are preserved until explicitly turned off with another SetBC() call.
INPUT PARAMETERS:
State - structure stores algorithm state
BndL - lower bounds, array[K].
If some (all) variables are unbounded, you may specify
very small number or -INF (latter is recommended because
it will allow solver to use better algorithm).
BndU - upper bounds, array[K].
If some (all) variables are unbounded, you may specify
very large number or +INF (latter is recommended because
it will allow solver to use better algorithm).
NOTE 1: it is possible to specify BndL[i]=BndU[i]. In this case I-th
variable will be "frozen" at X[i]=BndL[i]=BndU[i].
NOTE 2: unlike other constrained optimization algorithms, this solver has
following useful properties:
* bound constraints are always satisfied exactly
* function is evaluated only INSIDE area specified by bound constraints
-- ALGLIB --
Copyright 14.01.2011 by Bochkanov Sergey
*************************************************************************/
</div><div style='margin-top: 0; margin-bottom: 0;'><b>void</b> alglib::lsfitsetbc(
lsfitstate state,
real_1d_array bndl,
real_1d_array bndu);
</div></pre>
<a name='sub_lsfitsetcond'></a><h3 class=pageheader><code>lsfitsetcond</code> function</h3>
<pre class=source>
<div style='color: navy; margin-top: 0; margin-bottom: 0;'>/*************************************************************************
Stopping conditions for nonlinear least squares fitting.
INPUT PARAMETERS:
State - structure which stores algorithm state
EpsF - stopping criterion. Algorithm stops if
|F(k+1)-F(k)| <= EpsF*max{|F(k)|, |F(k+1)|, 1}
EpsX - >=0
The subroutine finishes its work if on k+1-th iteration
the condition |v|<=EpsX is fulfilled, where:
* |.| means Euclidian norm
* v - scaled step vector, v[i]=dx[i]/s[i]
* dx - ste pvector, dx=X(k+1)-X(k)
* s - scaling coefficients set by LSFitSetScale()
MaxIts - maximum number of iterations. If MaxIts=0, the number of
iterations is unlimited. Only Levenberg-Marquardt
iterations are counted (L-BFGS/CG iterations are NOT
counted because their cost is very low compared to that of
LM).
NOTE
Passing EpsF=0, EpsX=0 and MaxIts=0 (simultaneously) will lead to automatic
stopping criterion selection (according to the scheme used by MINLM unit).
-- ALGLIB --
Copyright 17.08.2009 by Bochkanov Sergey
*************************************************************************/
</div><div style='margin-top: 0; margin-bottom: 0;'><b>void</b> alglib::lsfitsetcond(
lsfitstate state,
<b>double</b> epsf,
<b>double</b> epsx,
ae_int_t maxits);
</div></pre>
<p align=left class=pagecontent><span class=inlineheader>Examples:</span> <a href='#example_lsfit_d_nlf' class=nav>[1]</a> <a href='#example_lsfit_d_nlfg' class=nav>[2]</a> <a href='#example_lsfit_d_nlfgh' class=nav>[3]</a> <a href='#example_lsfit_d_nlfb' class=nav>[4]</a> <a href='#example_lsfit_d_nlscale' class=nav>[5]</a> </p>
<a name='sub_lsfitsetgradientcheck'></a><h3 class=pageheader><code>lsfitsetgradientcheck</code> function</h3>
<pre class=source>
<div style='color: navy; margin-top: 0; margin-bottom: 0;'>/*************************************************************************
This subroutine turns on verification of the user-supplied analytic
gradient:
* user calls this subroutine before fitting begins
* LSFitFit() is called
* prior to actual fitting, for each point in data set X_i and each
component of parameters being fited C_j algorithm performs following
steps:
* two trial steps are made to C_j-TestStep*S[j] and C_j+TestStep*S[j],
where C_j is j-th parameter and S[j] is a scale of j-th parameter
* if needed, steps are bounded with respect to constraints on C[]
* F(X_i|C) is evaluated at these trial points
* we perform one more evaluation in the middle point of the interval
* we build cubic model using function values and derivatives at trial
points and we compare its prediction with actual value in the middle
point
* in case difference between prediction and actual value is higher than
some predetermined threshold, algorithm stops with completion code -7;
Rep.VarIdx is set to index of the parameter with incorrect derivative.
* after verification is over, algorithm proceeds to the actual optimization.
NOTE 1: verification needs N*K (points count * parameters count) gradient
evaluations. It is very costly and you should use it only for low
dimensional problems, when you want to be sure that you've
correctly calculated analytic derivatives. You should not use it
in the production code (unless you want to check derivatives
provided by some third party).
NOTE 2: you should carefully choose TestStep. Value which is too large
(so large that function behaviour is significantly non-cubic) will
lead to false alarms. You may use different step for different
parameters by means of setting scale with LSFitSetScale().
NOTE 3: this function may lead to false positives. In case it reports that
I-th derivative was calculated incorrectly, you may decrease test
step and try one more time - maybe your function changes too
sharply and your step is too large for such rapidly chanding
function.
NOTE 4: this function works only for optimizers created with LSFitCreateWFG()
or LSFitCreateFG() constructors.
INPUT PARAMETERS:
State - structure used to store algorithm state
TestStep - verification step:
* TestStep=0 turns verification off
* TestStep>0 activates verification
-- ALGLIB --
Copyright 15.06.2012 by Bochkanov Sergey
*************************************************************************/
</div><div style='margin-top: 0; margin-bottom: 0;'><b>void</b> alglib::lsfitsetgradientcheck(lsfitstate state, <b>double</b> teststep);
</div></pre>
<a name='sub_lsfitsetscale'></a><h3 class=pageheader><code>lsfitsetscale</code> function</h3>
<pre class=source>
<div style='color: navy; margin-top: 0; margin-bottom: 0;'>/*************************************************************************
This function sets scaling coefficients for underlying optimizer.
ALGLIB optimizers use scaling matrices to test stopping conditions (step
size and gradient are scaled before comparison with tolerances). Scale of
the I-th variable is a translation invariant measure of:
a) "how large" the variable is
b) how large the step should be to make significant changes in the function
Generally, scale is NOT considered to be a form of preconditioner. But LM
optimizer is unique in that it uses scaling matrix both in the stopping
condition tests and as Marquardt damping factor.
Proper scaling is very important for the algorithm performance. It is less
important for the quality of results, but still has some influence (it is
easier to converge when variables are properly scaled, so premature
stopping is possible when very badly scalled variables are combined with
relaxed stopping conditions).
INPUT PARAMETERS:
State - structure stores algorithm state
S - array[N], non-zero scaling coefficients
S[i] may be negative, sign doesn't matter.
-- ALGLIB --
Copyright 14.01.2011 by Bochkanov Sergey
*************************************************************************/
</div><div style='margin-top: 0; margin-bottom: 0;'><b>void</b> alglib::lsfitsetscale(lsfitstate state, real_1d_array s);
</div></pre>
<p align=left class=pagecontent><span class=inlineheader>Examples:</span> <a href='#example_lsfit_d_nlscale' class=nav>[1]</a> </p>
<a name='sub_lsfitsetstpmax'></a><h3 class=pageheader><code>lsfitsetstpmax</code> function</h3>
<pre class=source>
<div style='color: navy; margin-top: 0; margin-bottom: 0;'>/*************************************************************************
This function sets maximum step length
INPUT PARAMETERS:
State - structure which stores algorithm state
StpMax - maximum step length, >=0. Set StpMax to 0.0, if you don't
want to limit step length.
Use this subroutine when you optimize target function which contains exp()
or other fast growing functions, and optimization algorithm makes too
large steps which leads to overflow. This function allows us to reject
steps that are too large (and therefore expose us to the possible
overflow) without actually calculating function value at the x+stp*d.
NOTE: non-zero StpMax leads to moderate performance degradation because
intermediate step of preconditioned L-BFGS optimization is incompatible
with limits on step size.
-- ALGLIB --
Copyright 02.04.2010 by Bochkanov Sergey
*************************************************************************/
</div><div style='margin-top: 0; margin-bottom: 0;'><b>void</b> alglib::lsfitsetstpmax(lsfitstate state, <b>double</b> stpmax);
</div></pre>
<a name='sub_lsfitsetxrep'></a><h3 class=pageheader><code>lsfitsetxrep</code> function</h3>
<pre class=source>
<div style='color: navy; margin-top: 0; margin-bottom: 0;'>/*************************************************************************
This function turns on/off reporting.
INPUT PARAMETERS:
State - structure which stores algorithm state
NeedXRep- whether iteration reports are needed or not
When reports are needed, State.C (current parameters) and State.F (current
value of fitting function) are reported.
-- ALGLIB --
Copyright 15.08.2010 by Bochkanov Sergey
*************************************************************************/
</div><div style='margin-top: 0; margin-bottom: 0;'><b>void</b> alglib::lsfitsetxrep(lsfitstate state, <b>bool</b> needxrep);
</div></pre>
<a name='sub_lstfitpiecewiselinearrdp'></a><h3 class=pageheader><code>lstfitpiecewiselinearrdp</code> function</h3>
<pre class=source>
<div style='color: navy; margin-top: 0; margin-bottom: 0;'>/*************************************************************************
This subroutine fits piecewise linear curve to points with Ramer-Douglas-
Peucker algorithm, which stops after achieving desired precision.
IMPORTANT:
* it performs non-least-squares fitting; it builds curve, but this curve
does not minimize some least squares metric. See description of RDP
algorithm (say, in Wikipedia) for more details on WHAT is performed.
* this function does NOT work with parametric curves (i.e. curves which
can be represented as {X(t),Y(t)}. It works with curves which can be
represented as Y(X). Thus, it is impossible to model figures like circles
with this functions.
If you want to work with parametric curves, you should use
ParametricRDPFixed() function provided by "Parametric" subpackage of
"Interpolation" package.
INPUT PARAMETERS:
X - array of X-coordinates:
* at least N elements
* can be unordered (points are automatically sorted)
* this function may accept non-distinct X (see below for
more information on handling of such inputs)
Y - array of Y-coordinates:
* at least N elements
N - number of elements in X/Y
Eps - positive number, desired precision.
OUTPUT PARAMETERS:
X2 - X-values of corner points for piecewise approximation,
has length NSections+1 or zero (for NSections=0).
Y2 - Y-values of corner points,
has length NSections+1 or zero (for NSections=0).
NSections- number of sections found by algorithm,
NSections can be zero for degenerate datasets
(N<=1 or all X[] are non-distinct).
NOTE: X2/Y2 are ordered arrays, i.e. (X2[0],Y2[0]) is a first point of
curve, (X2[NSection-1],Y2[NSection-1]) is the last point.
-- ALGLIB --
Copyright 02.10.2014 by Bochkanov Sergey
*************************************************************************/
</div><div style='margin-top: 0; margin-bottom: 0;'><b>void</b> alglib::lstfitpiecewiselinearrdp(
real_1d_array x,
real_1d_array y,
ae_int_t n,
<b>double</b> eps,
real_1d_array& x2,
real_1d_array& y2,
ae_int_t& nsections);
</div></pre>
<a name='sub_lstfitpiecewiselinearrdpfixed'></a><h3 class=pageheader><code>lstfitpiecewiselinearrdpfixed</code> function</h3>
<pre class=source>
<div style='color: navy; margin-top: 0; margin-bottom: 0;'>/*************************************************************************
This subroutine fits piecewise linear curve to points with Ramer-Douglas-
Peucker algorithm, which stops after generating specified number of linear
sections.
IMPORTANT:
* it does NOT perform least-squares fitting; it builds curve, but this
curve does not minimize some least squares metric. See description of
RDP algorithm (say, in Wikipedia) for more details on WHAT is performed.
* this function does NOT work with parametric curves (i.e. curves which
can be represented as {X(t),Y(t)}. It works with curves which can be
represented as Y(X). Thus, it is impossible to model figures like
circles with this functions.
If you want to work with parametric curves, you should use
ParametricRDPFixed() function provided by "Parametric" subpackage of
"Interpolation" package.
INPUT PARAMETERS:
X - array of X-coordinates:
* at least N elements
* can be unordered (points are automatically sorted)
* this function may accept non-distinct X (see below for
more information on handling of such inputs)
Y - array of Y-coordinates:
* at least N elements
N - number of elements in X/Y
M - desired number of sections:
* at most M sections are generated by this function
* less than M sections can be generated if we have N<M
(or some X are non-distinct).
OUTPUT PARAMETERS:
X2 - X-values of corner points for piecewise approximation,
has length NSections+1 or zero (for NSections=0).
Y2 - Y-values of corner points,
has length NSections+1 or zero (for NSections=0).
NSections- number of sections found by algorithm, NSections<=M,
NSections can be zero for degenerate datasets
(N<=1 or all X[] are non-distinct).
NOTE: X2/Y2 are ordered arrays, i.e. (X2[0],Y2[0]) is a first point of
curve, (X2[NSection-1],Y2[NSection-1]) is the last point.
-- ALGLIB --
Copyright 02.10.2014 by Bochkanov Sergey
*************************************************************************/
</div><div style='margin-top: 0; margin-bottom: 0;'><b>void</b> alglib::lstfitpiecewiselinearrdpfixed(
real_1d_array x,
real_1d_array y,
ae_int_t n,
ae_int_t m,
real_1d_array& x2,
real_1d_array& y2,
ae_int_t& nsections);
</div></pre>
<a name='sub_polynomialfit'></a><h3 class=pageheader><code>polynomialfit</code> function</h3>
<pre class=source>
<div style='color: navy; margin-top: 0; margin-bottom: 0;'>/*************************************************************************
Fitting by polynomials in barycentric form. This function provides simple
unterface for unconstrained unweighted fitting. See PolynomialFitWC() if
you need constrained fitting.
Task is linear, so linear least squares solver is used. Complexity of this
computational scheme is O(N*M^2), mostly dominated by least squares solver
SEE ALSO:
PolynomialFitWC()
COMMERCIAL EDITION OF ALGLIB:
! Commercial version of ALGLIB includes two important improvements of
! this function, which can be used from C++ and C#:
! * Intel MKL support (lightweight Intel MKL is shipped with ALGLIB)
! * multithreading support
!
! Intel MKL gives approximately constant (with respect to number of
! worker threads) acceleration factor which depends on CPU being used,
! problem size and "baseline" ALGLIB edition which is used for
! comparison.
!
! Speed-up provided by multithreading greatly depends on problem size
! - only large problems (number of coefficients is more than 500) can be
! efficiently multithreaded.
!
! Generally, commercial ALGLIB is several times faster than open-source
! generic C edition, and many times faster than open-source C# edition.
!
! We recommend you to read 'Working with commercial version' section of
! ALGLIB Reference Manual in order to find out how to use performance-
! related features provided by commercial edition of ALGLIB.
INPUT PARAMETERS:
X - points, array[0..N-1].
Y - function values, array[0..N-1].
N - number of points, N>0
* if given, only leading N elements of X/Y are used
* if not given, automatically determined from sizes of X/Y
M - number of basis functions (= polynomial_degree + 1), M>=1
OUTPUT PARAMETERS:
Info- same format as in LSFitLinearW() subroutine:
* Info>0 task is solved
* Info<=0 an error occured:
-4 means inconvergence of internal SVD
P - interpolant in barycentric form.
Rep - report, same format as in LSFitLinearW() subroutine.
Following fields are set:
* RMSError rms error on the (X,Y).
* AvgError average error on the (X,Y).
* AvgRelError average relative error on the non-zero Y
* MaxError maximum error
NON-WEIGHTED ERRORS ARE CALCULATED
NOTES:
you can convert P from barycentric form to the power or Chebyshev
basis with PolynomialBar2Pow() or PolynomialBar2Cheb() functions from
POLINT subpackage.
-- ALGLIB PROJECT --
Copyright 10.12.2009 by Bochkanov Sergey
*************************************************************************/
</div><div style='margin-top: 0; margin-bottom: 0;'><b>void</b> alglib::polynomialfit(
real_1d_array x,
real_1d_array y,
ae_int_t m,
ae_int_t& info,
barycentricinterpolant& p,
polynomialfitreport& rep);
<b>void</b> alglib::polynomialfit(
real_1d_array x,
real_1d_array y,
ae_int_t n,
ae_int_t m,
ae_int_t& info,
barycentricinterpolant& p,
polynomialfitreport& rep);
<b>void</b> alglib::smp_polynomialfit(
real_1d_array x,
real_1d_array y,
ae_int_t m,
ae_int_t& info,
barycentricinterpolant& p,
polynomialfitreport& rep);
<b>void</b> alglib::smp_polynomialfit(
real_1d_array x,
real_1d_array y,
ae_int_t n,
ae_int_t m,
ae_int_t& info,
barycentricinterpolant& p,
polynomialfitreport& rep);
</div></pre>
<p align=left class=pagecontent><span class=inlineheader>Examples:</span> <a href='#example_lsfit_d_pol' class=nav>[1]</a> </p>
<a name='sub_polynomialfitwc'></a><h3 class=pageheader><code>polynomialfitwc</code> function</h3>
<pre class=source>
<div style='color: navy; margin-top: 0; margin-bottom: 0;'>/*************************************************************************
Weighted fitting by polynomials in barycentric form, with constraints on
function values or first derivatives.
Small regularizing term is used when solving constrained tasks (to improve
stability).
Task is linear, so linear least squares solver is used. Complexity of this
computational scheme is O(N*M^2), mostly dominated by least squares solver
SEE ALSO:
PolynomialFit()
COMMERCIAL EDITION OF ALGLIB:
! Commercial version of ALGLIB includes two important improvements of
! this function, which can be used from C++ and C#:
! * Intel MKL support (lightweight Intel MKL is shipped with ALGLIB)
! * multithreading support
!
! Intel MKL gives approximately constant (with respect to number of
! worker threads) acceleration factor which depends on CPU being used,
! problem size and "baseline" ALGLIB edition which is used for
! comparison.
!
! Speed-up provided by multithreading greatly depends on problem size
! - only large problems (number of coefficients is more than 500) can be
! efficiently multithreaded.
!
! Generally, commercial ALGLIB is several times faster than open-source
! generic C edition, and many times faster than open-source C# edition.
!
! We recommend you to read 'Working with commercial version' section of
! ALGLIB Reference Manual in order to find out how to use performance-
! related features provided by commercial edition of ALGLIB.
INPUT PARAMETERS:
X - points, array[0..N-1].
Y - function values, array[0..N-1].
W - weights, array[0..N-1]
Each summand in square sum of approximation deviations from
given values is multiplied by the square of corresponding
weight. Fill it by 1's if you don't want to solve weighted
task.
N - number of points, N>0.
* if given, only leading N elements of X/Y/W are used
* if not given, automatically determined from sizes of X/Y/W
XC - points where polynomial values/derivatives are constrained,
array[0..K-1].
YC - values of constraints, array[0..K-1]
DC - array[0..K-1], types of constraints:
* DC[i]=0 means that P(XC[i])=YC[i]
* DC[i]=1 means that P'(XC[i])=YC[i]
SEE BELOW FOR IMPORTANT INFORMATION ON CONSTRAINTS
K - number of constraints, 0<=K<M.
K=0 means no constraints (XC/YC/DC are not used in such cases)
M - number of basis functions (= polynomial_degree + 1), M>=1
OUTPUT PARAMETERS:
Info- same format as in LSFitLinearW() subroutine:
* Info>0 task is solved
* Info<=0 an error occured:
-4 means inconvergence of internal SVD
-3 means inconsistent constraints
P - interpolant in barycentric form.
Rep - report, same format as in LSFitLinearW() subroutine.
Following fields are set:
* RMSError rms error on the (X,Y).
* AvgError average error on the (X,Y).
* AvgRelError average relative error on the non-zero Y
* MaxError maximum error
NON-WEIGHTED ERRORS ARE CALCULATED
IMPORTANT:
this subroitine doesn't calculate task's condition number for K<>0.
NOTES:
you can convert P from barycentric form to the power or Chebyshev
basis with PolynomialBar2Pow() or PolynomialBar2Cheb() functions from
POLINT subpackage.
SETTING CONSTRAINTS - DANGERS AND OPPORTUNITIES:
Setting constraints can lead to undesired results, like ill-conditioned
behavior, or inconsistency being detected. From the other side, it allows
us to improve quality of the fit. Here we summarize our experience with
constrained regression splines:
* even simple constraints can be inconsistent, see Wikipedia article on
this subject: http://en.wikipedia.org/wiki/Birkhoff_interpolation
* the greater is M (given fixed constraints), the more chances that
constraints will be consistent
* in the general case, consistency of constraints is NOT GUARANTEED.
* in the one special cases, however, we can guarantee consistency. This
case is: M>1 and constraints on the function values (NOT DERIVATIVES)
Our final recommendation is to use constraints WHEN AND ONLY when you
can't solve your task without them. Anything beyond special cases given
above is not guaranteed and may result in inconsistency.
-- ALGLIB PROJECT --
Copyright 10.12.2009 by Bochkanov Sergey
*************************************************************************/
</div><div style='margin-top: 0; margin-bottom: 0;'><b>void</b> alglib::polynomialfitwc(
real_1d_array x,
real_1d_array y,
real_1d_array w,
real_1d_array xc,
real_1d_array yc,
integer_1d_array dc,
ae_int_t m,
ae_int_t& info,
barycentricinterpolant& p,
polynomialfitreport& rep);
<b>void</b> alglib::polynomialfitwc(
real_1d_array x,
real_1d_array y,
real_1d_array w,
ae_int_t n,
real_1d_array xc,
real_1d_array yc,
integer_1d_array dc,
ae_int_t k,
ae_int_t m,
ae_int_t& info,
barycentricinterpolant& p,
polynomialfitreport& rep);
<b>void</b> alglib::smp_polynomialfitwc(
real_1d_array x,
real_1d_array y,
real_1d_array w,
real_1d_array xc,
real_1d_array yc,
integer_1d_array dc,
ae_int_t m,
ae_int_t& info,
barycentricinterpolant& p,
polynomialfitreport& rep);
<b>void</b> alglib::smp_polynomialfitwc(
real_1d_array x,
real_1d_array y,
real_1d_array w,
ae_int_t n,
real_1d_array xc,
real_1d_array yc,
integer_1d_array dc,
ae_int_t k,
ae_int_t m,
ae_int_t& info,
barycentricinterpolant& p,
polynomialfitreport& rep);
</div></pre>
<p align=left class=pagecontent><span class=inlineheader>Examples:</span> <a href='#example_lsfit_d_polc' class=nav>[1]</a> </p>
<a name='sub_spline1dfitcubic'></a><h3 class=pageheader><code>spline1dfitcubic</code> function</h3>
<pre class=source>
<div style='color: navy; margin-top: 0; margin-bottom: 0;'>/*************************************************************************
Least squares fitting by cubic spline.
This subroutine is "lightweight" alternative for more complex and feature-
rich Spline1DFitCubicWC(). See Spline1DFitCubicWC() for more information
about subroutine parameters (we don't duplicate it here because of length)
COMMERCIAL EDITION OF ALGLIB:
! Commercial version of ALGLIB includes two important improvements of
! this function, which can be used from C++ and C#:
! * Intel MKL support (lightweight Intel MKL is shipped with ALGLIB)
! * multithreading support
!
! Intel MKL gives approximately constant (with respect to number of
! worker threads) acceleration factor which depends on CPU being used,
! problem size and "baseline" ALGLIB edition which is used for
! comparison.
!
! Speed-up provided by multithreading greatly depends on problem size
! - only large problems (number of coefficients is more than 500) can be
! efficiently multithreaded.
!
! Generally, commercial ALGLIB is several times faster than open-source
! generic C edition, and many times faster than open-source C# edition.
!
! We recommend you to read 'Working with commercial version' section of
! ALGLIB Reference Manual in order to find out how to use performance-
! related features provided by commercial edition of ALGLIB.
-- ALGLIB PROJECT --
Copyright 18.08.2009 by Bochkanov Sergey
*************************************************************************/
</div><div style='margin-top: 0; margin-bottom: 0;'><b>void</b> alglib::spline1dfitcubic(
real_1d_array x,
real_1d_array y,
ae_int_t m,
ae_int_t& info,
spline1dinterpolant& s,
spline1dfitreport& rep);
<b>void</b> alglib::spline1dfitcubic(
real_1d_array x,
real_1d_array y,
ae_int_t n,
ae_int_t m,
ae_int_t& info,
spline1dinterpolant& s,
spline1dfitreport& rep);
<b>void</b> alglib::smp_spline1dfitcubic(
real_1d_array x,
real_1d_array y,
ae_int_t m,
ae_int_t& info,
spline1dinterpolant& s,
spline1dfitreport& rep);
<b>void</b> alglib::smp_spline1dfitcubic(
real_1d_array x,
real_1d_array y,
ae_int_t n,
ae_int_t m,
ae_int_t& info,
spline1dinterpolant& s,
spline1dfitreport& rep);
</div></pre>
<a name='sub_spline1dfitcubicwc'></a><h3 class=pageheader><code>spline1dfitcubicwc</code> function</h3>
<pre class=source>
<div style='color: navy; margin-top: 0; margin-bottom: 0;'>/*************************************************************************
Weighted fitting by cubic spline, with constraints on function values or
derivatives.
Equidistant grid with M-2 nodes on [min(x,xc),max(x,xc)] is used to build
basis functions. Basis functions are cubic splines with continuous second
derivatives and non-fixed first derivatives at interval ends. Small
regularizing term is used when solving constrained tasks (to improve
stability).
Task is linear, so linear least squares solver is used. Complexity of this
computational scheme is O(N*M^2), mostly dominated by least squares solver
SEE ALSO
Spline1DFitHermiteWC() - fitting by Hermite splines (more flexible,
less smooth)
Spline1DFitCubic() - "lightweight" fitting by cubic splines,
without invididual weights and constraints
COMMERCIAL EDITION OF ALGLIB:
! Commercial version of ALGLIB includes two important improvements of
! this function, which can be used from C++ and C#:
! * Intel MKL support (lightweight Intel MKL is shipped with ALGLIB)
! * multithreading support
!
! Intel MKL gives approximately constant (with respect to number of
! worker threads) acceleration factor which depends on CPU being used,
! problem size and "baseline" ALGLIB edition which is used for
! comparison.
!
! Speed-up provided by multithreading greatly depends on problem size
! - only large problems (number of coefficients is more than 500) can be
! efficiently multithreaded.
!
! Generally, commercial ALGLIB is several times faster than open-source
! generic C edition, and many times faster than open-source C# edition.
!
! We recommend you to read 'Working with commercial version' section of
! ALGLIB Reference Manual in order to find out how to use performance-
! related features provided by commercial edition of ALGLIB.
INPUT PARAMETERS:
X - points, array[0..N-1].
Y - function values, array[0..N-1].
W - weights, array[0..N-1]
Each summand in square sum of approximation deviations from
given values is multiplied by the square of corresponding
weight. Fill it by 1's if you don't want to solve weighted
task.
N - number of points (optional):
* N>0
* if given, only first N elements of X/Y/W are processed
* if not given, automatically determined from X/Y/W sizes
XC - points where spline values/derivatives are constrained,
array[0..K-1].
YC - values of constraints, array[0..K-1]
DC - array[0..K-1], types of constraints:
* DC[i]=0 means that S(XC[i])=YC[i]
* DC[i]=1 means that S'(XC[i])=YC[i]
SEE BELOW FOR IMPORTANT INFORMATION ON CONSTRAINTS
K - number of constraints (optional):
* 0<=K<M.
* K=0 means no constraints (XC/YC/DC are not used)
* if given, only first K elements of XC/YC/DC are used
* if not given, automatically determined from XC/YC/DC
M - number of basis functions ( = number_of_nodes+2), M>=4.
OUTPUT PARAMETERS:
Info- same format as in LSFitLinearWC() subroutine.
* Info>0 task is solved
* Info<=0 an error occured:
-4 means inconvergence of internal SVD
-3 means inconsistent constraints
S - spline interpolant.
Rep - report, same format as in LSFitLinearWC() subroutine.
Following fields are set:
* RMSError rms error on the (X,Y).
* AvgError average error on the (X,Y).
* AvgRelError average relative error on the non-zero Y
* MaxError maximum error
NON-WEIGHTED ERRORS ARE CALCULATED
IMPORTANT:
this subroitine doesn't calculate task's condition number for K<>0.
ORDER OF POINTS
Subroutine automatically sorts points, so caller may pass unsorted array.
SETTING CONSTRAINTS - DANGERS AND OPPORTUNITIES:
Setting constraints can lead to undesired results, like ill-conditioned
behavior, or inconsistency being detected. From the other side, it allows
us to improve quality of the fit. Here we summarize our experience with
constrained regression splines:
* excessive constraints can be inconsistent. Splines are piecewise cubic
functions, and it is easy to create an example, where large number of
constraints concentrated in small area will result in inconsistency.
Just because spline is not flexible enough to satisfy all of them. And
same constraints spread across the [min(x),max(x)] will be perfectly
consistent.
* the more evenly constraints are spread across [min(x),max(x)], the more
chances that they will be consistent
* the greater is M (given fixed constraints), the more chances that
constraints will be consistent
* in the general case, consistency of constraints IS NOT GUARANTEED.
* in the several special cases, however, we CAN guarantee consistency.
* one of this cases is constraints on the function values AND/OR its
derivatives at the interval boundaries.
* another special case is ONE constraint on the function value (OR, but
not AND, derivative) anywhere in the interval
Our final recommendation is to use constraints WHEN AND ONLY WHEN you
can't solve your task without them. Anything beyond special cases given
above is not guaranteed and may result in inconsistency.
-- ALGLIB PROJECT --
Copyright 18.08.2009 by Bochkanov Sergey
*************************************************************************/
</div><div style='margin-top: 0; margin-bottom: 0;'><b>void</b> alglib::spline1dfitcubicwc(
real_1d_array x,
real_1d_array y,
real_1d_array w,
real_1d_array xc,
real_1d_array yc,
integer_1d_array dc,
ae_int_t m,
ae_int_t& info,
spline1dinterpolant& s,
spline1dfitreport& rep);
<b>void</b> alglib::spline1dfitcubicwc(
real_1d_array x,
real_1d_array y,
real_1d_array w,
ae_int_t n,
real_1d_array xc,
real_1d_array yc,
integer_1d_array dc,
ae_int_t k,
ae_int_t m,
ae_int_t& info,
spline1dinterpolant& s,
spline1dfitreport& rep);
<b>void</b> alglib::smp_spline1dfitcubicwc(
real_1d_array x,
real_1d_array y,
real_1d_array w,
real_1d_array xc,
real_1d_array yc,
integer_1d_array dc,
ae_int_t m,
ae_int_t& info,
spline1dinterpolant& s,
spline1dfitreport& rep);
<b>void</b> alglib::smp_spline1dfitcubicwc(
real_1d_array x,
real_1d_array y,
real_1d_array w,
ae_int_t n,
real_1d_array xc,
real_1d_array yc,
integer_1d_array dc,
ae_int_t k,
ae_int_t m,
ae_int_t& info,
spline1dinterpolant& s,
spline1dfitreport& rep);
</div></pre>
<a name='sub_spline1dfithermite'></a><h3 class=pageheader><code>spline1dfithermite</code> function</h3>
<pre class=source>
<div style='color: navy; margin-top: 0; margin-bottom: 0;'>/*************************************************************************
Least squares fitting by Hermite spline.
This subroutine is "lightweight" alternative for more complex and feature-
rich Spline1DFitHermiteWC(). See Spline1DFitHermiteWC() description for
more information about subroutine parameters (we don't duplicate it here
because of length).
COMMERCIAL EDITION OF ALGLIB:
! Commercial version of ALGLIB includes two important improvements of
! this function, which can be used from C++ and C#:
! * Intel MKL support (lightweight Intel MKL is shipped with ALGLIB)
! * multithreading support
!
! Intel MKL gives approximately constant (with respect to number of
! worker threads) acceleration factor which depends on CPU being used,
! problem size and "baseline" ALGLIB edition which is used for
! comparison.
!
! Speed-up provided by multithreading greatly depends on problem size
! - only large problems (number of coefficients is more than 500) can be
! efficiently multithreaded.
!
! Generally, commercial ALGLIB is several times faster than open-source
! generic C edition, and many times faster than open-source C# edition.
!
! We recommend you to read 'Working with commercial version' section of
! ALGLIB Reference Manual in order to find out how to use performance-
! related features provided by commercial edition of ALGLIB.
-- ALGLIB PROJECT --
Copyright 18.08.2009 by Bochkanov Sergey
*************************************************************************/
</div><div style='margin-top: 0; margin-bottom: 0;'><b>void</b> alglib::spline1dfithermite(
real_1d_array x,
real_1d_array y,
ae_int_t m,
ae_int_t& info,
spline1dinterpolant& s,
spline1dfitreport& rep);
<b>void</b> alglib::spline1dfithermite(
real_1d_array x,
real_1d_array y,
ae_int_t n,
ae_int_t m,
ae_int_t& info,
spline1dinterpolant& s,
spline1dfitreport& rep);
<b>void</b> alglib::smp_spline1dfithermite(
real_1d_array x,
real_1d_array y,
ae_int_t m,
ae_int_t& info,
spline1dinterpolant& s,
spline1dfitreport& rep);
<b>void</b> alglib::smp_spline1dfithermite(
real_1d_array x,
real_1d_array y,
ae_int_t n,
ae_int_t m,
ae_int_t& info,
spline1dinterpolant& s,
spline1dfitreport& rep);
</div></pre>
<a name='sub_spline1dfithermitewc'></a><h3 class=pageheader><code>spline1dfithermitewc</code> function</h3>
<pre class=source>
<div style='color: navy; margin-top: 0; margin-bottom: 0;'>/*************************************************************************
Weighted fitting by Hermite spline, with constraints on function values
or first derivatives.
Equidistant grid with M nodes on [min(x,xc),max(x,xc)] is used to build
basis functions. Basis functions are Hermite splines. Small regularizing
term is used when solving constrained tasks (to improve stability).
Task is linear, so linear least squares solver is used. Complexity of this
computational scheme is O(N*M^2), mostly dominated by least squares solver
SEE ALSO
Spline1DFitCubicWC() - fitting by Cubic splines (less flexible,
more smooth)
Spline1DFitHermite() - "lightweight" Hermite fitting, without
invididual weights and constraints
COMMERCIAL EDITION OF ALGLIB:
! Commercial version of ALGLIB includes two important improvements of
! this function, which can be used from C++ and C#:
! * Intel MKL support (lightweight Intel MKL is shipped with ALGLIB)
! * multithreading support
!
! Intel MKL gives approximately constant (with respect to number of
! worker threads) acceleration factor which depends on CPU being used,
! problem size and "baseline" ALGLIB edition which is used for
! comparison.
!
! Speed-up provided by multithreading greatly depends on problem size
! - only large problems (number of coefficients is more than 500) can be
! efficiently multithreaded.
!
! Generally, commercial ALGLIB is several times faster than open-source
! generic C edition, and many times faster than open-source C# edition.
!
! We recommend you to read 'Working with commercial version' section of
! ALGLIB Reference Manual in order to find out how to use performance-
! related features provided by commercial edition of ALGLIB.
INPUT PARAMETERS:
X - points, array[0..N-1].
Y - function values, array[0..N-1].
W - weights, array[0..N-1]
Each summand in square sum of approximation deviations from
given values is multiplied by the square of corresponding
weight. Fill it by 1's if you don't want to solve weighted
task.
N - number of points (optional):
* N>0
* if given, only first N elements of X/Y/W are processed
* if not given, automatically determined from X/Y/W sizes
XC - points where spline values/derivatives are constrained,
array[0..K-1].
YC - values of constraints, array[0..K-1]
DC - array[0..K-1], types of constraints:
* DC[i]=0 means that S(XC[i])=YC[i]
* DC[i]=1 means that S'(XC[i])=YC[i]
SEE BELOW FOR IMPORTANT INFORMATION ON CONSTRAINTS
K - number of constraints (optional):
* 0<=K<M.
* K=0 means no constraints (XC/YC/DC are not used)
* if given, only first K elements of XC/YC/DC are used
* if not given, automatically determined from XC/YC/DC
M - number of basis functions (= 2 * number of nodes),
M>=4,
M IS EVEN!
OUTPUT PARAMETERS:
Info- same format as in LSFitLinearW() subroutine:
* Info>0 task is solved
* Info<=0 an error occured:
-4 means inconvergence of internal SVD
-3 means inconsistent constraints
-2 means odd M was passed (which is not supported)
-1 means another errors in parameters passed
(N<=0, for example)
S - spline interpolant.
Rep - report, same format as in LSFitLinearW() subroutine.
Following fields are set:
* RMSError rms error on the (X,Y).
* AvgError average error on the (X,Y).
* AvgRelError average relative error on the non-zero Y
* MaxError maximum error
NON-WEIGHTED ERRORS ARE CALCULATED
IMPORTANT:
this subroitine doesn't calculate task's condition number for K<>0.
IMPORTANT:
this subroitine supports only even M's
ORDER OF POINTS
Subroutine automatically sorts points, so caller may pass unsorted array.
SETTING CONSTRAINTS - DANGERS AND OPPORTUNITIES:
Setting constraints can lead to undesired results, like ill-conditioned
behavior, or inconsistency being detected. From the other side, it allows
us to improve quality of the fit. Here we summarize our experience with
constrained regression splines:
* excessive constraints can be inconsistent. Splines are piecewise cubic
functions, and it is easy to create an example, where large number of
constraints concentrated in small area will result in inconsistency.
Just because spline is not flexible enough to satisfy all of them. And
same constraints spread across the [min(x),max(x)] will be perfectly
consistent.
* the more evenly constraints are spread across [min(x),max(x)], the more
chances that they will be consistent
* the greater is M (given fixed constraints), the more chances that
constraints will be consistent
* in the general case, consistency of constraints is NOT GUARANTEED.
* in the several special cases, however, we can guarantee consistency.
* one of this cases is M>=4 and constraints on the function value
(AND/OR its derivative) at the interval boundaries.
* another special case is M>=4 and ONE constraint on the function value
(OR, BUT NOT AND, derivative) anywhere in [min(x),max(x)]
Our final recommendation is to use constraints WHEN AND ONLY when you
can't solve your task without them. Anything beyond special cases given
above is not guaranteed and may result in inconsistency.
-- ALGLIB PROJECT --
Copyright 18.08.2009 by Bochkanov Sergey
*************************************************************************/
</div><div style='margin-top: 0; margin-bottom: 0;'><b>void</b> alglib::spline1dfithermitewc(
real_1d_array x,
real_1d_array y,
real_1d_array w,
real_1d_array xc,
real_1d_array yc,
integer_1d_array dc,
ae_int_t m,
ae_int_t& info,
spline1dinterpolant& s,
spline1dfitreport& rep);
<b>void</b> alglib::spline1dfithermitewc(
real_1d_array x,
real_1d_array y,
real_1d_array w,
ae_int_t n,
real_1d_array xc,
real_1d_array yc,
integer_1d_array dc,
ae_int_t k,
ae_int_t m,
ae_int_t& info,
spline1dinterpolant& s,
spline1dfitreport& rep);
<b>void</b> alglib::smp_spline1dfithermitewc(
real_1d_array x,
real_1d_array y,
real_1d_array w,
real_1d_array xc,
real_1d_array yc,
integer_1d_array dc,
ae_int_t m,
ae_int_t& info,
spline1dinterpolant& s,
spline1dfitreport& rep);
<b>void</b> alglib::smp_spline1dfithermitewc(
real_1d_array x,
real_1d_array y,
real_1d_array w,
ae_int_t n,
real_1d_array xc,
real_1d_array yc,
integer_1d_array dc,
ae_int_t k,
ae_int_t m,
ae_int_t& info,
spline1dinterpolant& s,
spline1dfitreport& rep);
</div></pre>
<a name='sub_spline1dfitpenalized'></a><h3 class=pageheader><code>spline1dfitpenalized</code> function</h3>
<pre class=source>
<div style='color: navy; margin-top: 0; margin-bottom: 0;'>/*************************************************************************
Fitting by penalized cubic spline.
Equidistant grid with M nodes on [min(x,xc),max(x,xc)] is used to build
basis functions. Basis functions are cubic splines with natural boundary
conditions. Problem is regularized by adding non-linearity penalty to the
usual least squares penalty function:
S(x) = arg min { LS + P }, where
LS = SUM { w[i]^2*(y[i] - S(x[i]))^2 } - least squares penalty
P = C*10^rho*integral{ S''(x)^2*dx } - non-linearity penalty
rho - tunable constant given by user
C - automatically determined scale parameter,
makes penalty invariant with respect to scaling of X, Y, W.
COMMERCIAL EDITION OF ALGLIB:
! Commercial version of ALGLIB includes two important improvements of
! this function, which can be used from C++ and C#:
! * Intel MKL support (lightweight Intel MKL is shipped with ALGLIB)
! * multithreading support
!
! Intel MKL gives approximately constant (with respect to number of
! worker threads) acceleration factor which depends on CPU being used,
! problem size and "baseline" ALGLIB edition which is used for
! comparison.
!
! Speed-up provided by multithreading greatly depends on problem size
! - only large problems (number of coefficients is more than 500) can be
! efficiently multithreaded.
!
! Generally, commercial ALGLIB is several times faster than open-source
! generic C edition, and many times faster than open-source C# edition.
!
! We recommend you to read 'Working with commercial version' section of
! ALGLIB Reference Manual in order to find out how to use performance-
! related features provided by commercial edition of ALGLIB.
INPUT PARAMETERS:
X - points, array[0..N-1].
Y - function values, array[0..N-1].
N - number of points (optional):
* N>0
* if given, only first N elements of X/Y are processed
* if not given, automatically determined from X/Y sizes
M - number of basis functions ( = number_of_nodes), M>=4.
Rho - regularization constant passed by user. It penalizes
nonlinearity in the regression spline. It is logarithmically
scaled, i.e. actual value of regularization constant is
calculated as 10^Rho. It is automatically scaled so that:
* Rho=2.0 corresponds to moderate amount of nonlinearity
* generally, it should be somewhere in the [-8.0,+8.0]
If you do not want to penalize nonlineary,
pass small Rho. Values as low as -15 should work.
OUTPUT PARAMETERS:
Info- same format as in LSFitLinearWC() subroutine.
* Info>0 task is solved
* Info<=0 an error occured:
-4 means inconvergence of internal SVD or
Cholesky decomposition; problem may be
too ill-conditioned (very rare)
S - spline interpolant.
Rep - Following fields are set:
* RMSError rms error on the (X,Y).
* AvgError average error on the (X,Y).
* AvgRelError average relative error on the non-zero Y
* MaxError maximum error
NON-WEIGHTED ERRORS ARE CALCULATED
IMPORTANT:
this subroitine doesn't calculate task's condition number for K<>0.
NOTE 1: additional nodes are added to the spline outside of the fitting
interval to force linearity when x<min(x,xc) or x>max(x,xc). It is done
for consistency - we penalize non-linearity at [min(x,xc),max(x,xc)], so
it is natural to force linearity outside of this interval.
NOTE 2: function automatically sorts points, so caller may pass unsorted
array.
-- ALGLIB PROJECT --
Copyright 18.08.2009 by Bochkanov Sergey
*************************************************************************/
</div><div style='margin-top: 0; margin-bottom: 0;'><b>void</b> alglib::spline1dfitpenalized(
real_1d_array x,
real_1d_array y,
ae_int_t m,
<b>double</b> rho,
ae_int_t& info,
spline1dinterpolant& s,
spline1dfitreport& rep);
<b>void</b> alglib::spline1dfitpenalized(
real_1d_array x,
real_1d_array y,
ae_int_t n,
ae_int_t m,
<b>double</b> rho,
ae_int_t& info,
spline1dinterpolant& s,
spline1dfitreport& rep);
<b>void</b> alglib::smp_spline1dfitpenalized(
real_1d_array x,
real_1d_array y,
ae_int_t m,
<b>double</b> rho,
ae_int_t& info,
spline1dinterpolant& s,
spline1dfitreport& rep);
<b>void</b> alglib::smp_spline1dfitpenalized(
real_1d_array x,
real_1d_array y,
ae_int_t n,
ae_int_t m,
<b>double</b> rho,
ae_int_t& info,
spline1dinterpolant& s,
spline1dfitreport& rep);
</div></pre>
<p align=left class=pagecontent><span class=inlineheader>Examples:</span> <a href='#example_lsfit_d_spline' class=nav>[1]</a> </p>
<a name='sub_spline1dfitpenalizedw'></a><h3 class=pageheader><code>spline1dfitpenalizedw</code> function</h3>
<pre class=source>
<div style='color: navy; margin-top: 0; margin-bottom: 0;'>/*************************************************************************
Weighted fitting by penalized cubic spline.
Equidistant grid with M nodes on [min(x,xc),max(x,xc)] is used to build
basis functions. Basis functions are cubic splines with natural boundary
conditions. Problem is regularized by adding non-linearity penalty to the
usual least squares penalty function:
S(x) = arg min { LS + P }, where
LS = SUM { w[i]^2*(y[i] - S(x[i]))^2 } - least squares penalty
P = C*10^rho*integral{ S''(x)^2*dx } - non-linearity penalty
rho - tunable constant given by user
C - automatically determined scale parameter,
makes penalty invariant with respect to scaling of X, Y, W.
COMMERCIAL EDITION OF ALGLIB:
! Commercial version of ALGLIB includes two important improvements of
! this function, which can be used from C++ and C#:
! * Intel MKL support (lightweight Intel MKL is shipped with ALGLIB)
! * multithreading support
!
! Intel MKL gives approximately constant (with respect to number of
! worker threads) acceleration factor which depends on CPU being used,
! problem size and "baseline" ALGLIB edition which is used for
! comparison.
!
! Speed-up provided by multithreading greatly depends on problem size
! - only large problems (number of coefficients is more than 500) can be
! efficiently multithreaded.
!
! Generally, commercial ALGLIB is several times faster than open-source
! generic C edition, and many times faster than open-source C# edition.
!
! We recommend you to read 'Working with commercial version' section of
! ALGLIB Reference Manual in order to find out how to use performance-
! related features provided by commercial edition of ALGLIB.
INPUT PARAMETERS:
X - points, array[0..N-1].
Y - function values, array[0..N-1].
W - weights, array[0..N-1]
Each summand in square sum of approximation deviations from
given values is multiplied by the square of corresponding
weight. Fill it by 1's if you don't want to solve weighted
problem.
N - number of points (optional):
* N>0
* if given, only first N elements of X/Y/W are processed
* if not given, automatically determined from X/Y/W sizes
M - number of basis functions ( = number_of_nodes), M>=4.
Rho - regularization constant passed by user. It penalizes
nonlinearity in the regression spline. It is logarithmically
scaled, i.e. actual value of regularization constant is
calculated as 10^Rho. It is automatically scaled so that:
* Rho=2.0 corresponds to moderate amount of nonlinearity
* generally, it should be somewhere in the [-8.0,+8.0]
If you do not want to penalize nonlineary,
pass small Rho. Values as low as -15 should work.
OUTPUT PARAMETERS:
Info- same format as in LSFitLinearWC() subroutine.
* Info>0 task is solved
* Info<=0 an error occured:
-4 means inconvergence of internal SVD or
Cholesky decomposition; problem may be
too ill-conditioned (very rare)
S - spline interpolant.
Rep - Following fields are set:
* RMSError rms error on the (X,Y).
* AvgError average error on the (X,Y).
* AvgRelError average relative error on the non-zero Y
* MaxError maximum error
NON-WEIGHTED ERRORS ARE CALCULATED
IMPORTANT:
this subroitine doesn't calculate task's condition number for K<>0.
NOTE 1: additional nodes are added to the spline outside of the fitting
interval to force linearity when x<min(x,xc) or x>max(x,xc). It is done
for consistency - we penalize non-linearity at [min(x,xc),max(x,xc)], so
it is natural to force linearity outside of this interval.
NOTE 2: function automatically sorts points, so caller may pass unsorted
array.
-- ALGLIB PROJECT --
Copyright 19.10.2010 by Bochkanov Sergey
*************************************************************************/
</div><div style='margin-top: 0; margin-bottom: 0;'><b>void</b> alglib::spline1dfitpenalizedw(
real_1d_array x,
real_1d_array y,
real_1d_array w,
ae_int_t m,
<b>double</b> rho,
ae_int_t& info,
spline1dinterpolant& s,
spline1dfitreport& rep);
<b>void</b> alglib::spline1dfitpenalizedw(
real_1d_array x,
real_1d_array y,
real_1d_array w,
ae_int_t n,
ae_int_t m,
<b>double</b> rho,
ae_int_t& info,
spline1dinterpolant& s,
spline1dfitreport& rep);
<b>void</b> alglib::smp_spline1dfitpenalizedw(
real_1d_array x,
real_1d_array y,
real_1d_array w,
ae_int_t m,
<b>double</b> rho,
ae_int_t& info,
spline1dinterpolant& s,
spline1dfitreport& rep);
<b>void</b> alglib::smp_spline1dfitpenalizedw(
real_1d_array x,
real_1d_array y,
real_1d_array w,
ae_int_t n,
ae_int_t m,
<b>double</b> rho,
ae_int_t& info,
spline1dinterpolant& s,
spline1dfitreport& rep);
</div></pre>
<p align=left class=pagecontent><span class=inlineheader>Examples:</span> <a href='#example_lsfit_d_spline' class=nav>[1]</a> </p>
<a name='example_lsfit_d_lin'></a><h3 class=pageheader>lsfit_d_lin example</h3>
<pre class=source>
#include <font color=blue><b>"stdafx.h"</b></font>
#include <stdlib.h>
#include <stdio.h>
#include <math.h>
#include <font color=blue><b>"interpolation.h"</b></font>
using namespace alglib;
<b>int</b> main(<b>int</b> argc, char **argv)
{
<font color=navy>//</font>
<font color=navy>// In this example we demonstrate linear fitting by f(x|a) = a*exp(0.5*x).</font>
<font color=navy>//</font>
<font color=navy>// We have:</font>
<font color=navy>// * y - vector of experimental data</font>
<font color=navy>// * fmatrix - matrix of basis functions calculated at sample points</font>
<font color=navy>// Actually, we have only one basis function F0 = exp(0.5*x).</font>
<font color=navy>//</font>
real_2d_array fmatrix = <font color=blue><b>"[[0.606531],[0.670320],[0.740818],[0.818731],[0.904837],[1.000000],[1.105171],[1.221403],[1.349859],[1.491825],[1.648721]]"</b></font>;
real_1d_array y = <font color=blue><b>"[1.133719, 1.306522, 1.504604, 1.554663, 1.884638, 2.072436, 2.257285, 2.534068, 2.622017, 2.897713, 3.219371]"</b></font>;
ae_int_t info;
real_1d_array c;
lsfitreport rep;
<font color=navy>//</font>
<font color=navy>// Linear fitting without weights</font>
<font color=navy>//</font>
lsfitlinear(y, fmatrix, info, c, rep);
printf(<font color=blue><b>"%d\n"</b></font>, <b>int</b>(info)); <font color=navy>// EXPECTED: 1</font>
printf(<font color=blue><b>"%s\n"</b></font>, c.tostring(4).c_str()); <font color=navy>// EXPECTED: [1.98650]</font>
<font color=navy>//</font>
<font color=navy>// Linear fitting with individual weights.</font>
<font color=navy>// Slightly different result is returned.</font>
<font color=navy>//</font>
real_1d_array w = <font color=blue><b>"[1.414213, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1]"</b></font>;
lsfitlinearw(y, w, fmatrix, info, c, rep);
printf(<font color=blue><b>"%d\n"</b></font>, <b>int</b>(info)); <font color=navy>// EXPECTED: 1</font>
printf(<font color=blue><b>"%s\n"</b></font>, c.tostring(4).c_str()); <font color=navy>// EXPECTED: [1.983354]</font>
<b>return</b> 0;
}
</pre><a name='example_lsfit_d_linc'></a><h3 class=pageheader>lsfit_d_linc example</h3>
<pre class=source>
#include <font color=blue><b>"stdafx.h"</b></font>
#include <stdlib.h>
#include <stdio.h>
#include <math.h>
#include <font color=blue><b>"interpolation.h"</b></font>
using namespace alglib;
<b>int</b> main(<b>int</b> argc, char **argv)
{
<font color=navy>//</font>
<font color=navy>// In this example we demonstrate linear fitting by f(x|a,b) = a*x+b</font>
<font color=navy>// with simple constraint f(0)=0.</font>
<font color=navy>//</font>
<font color=navy>// We have:</font>
<font color=navy>// * y - vector of experimental data</font>
<font color=navy>// * fmatrix - matrix of basis functions sampled at [0,1] with step 0.2:</font>
<font color=navy>// [ 1.0 0.0 ]</font>
<font color=navy>// [ 1.0 0.2 ]</font>
<font color=navy>// [ 1.0 0.4 ]</font>
<font color=navy>// [ 1.0 0.6 ]</font>
<font color=navy>// [ 1.0 0.8 ]</font>
<font color=navy>// [ 1.0 1.0 ]</font>
<font color=navy>// first column contains value of first basis function (constant term)</font>
<font color=navy>// second column contains second basis function (linear term)</font>
<font color=navy>// * cmatrix - matrix of linear constraints:</font>
<font color=navy>// [ 1.0 0.0 0.0 ]</font>
<font color=navy>// first two columns contain coefficients before basis functions,</font>
<font color=navy>// last column contains desired value of their sum.</font>
<font color=navy>// So [1,0,0] means <font color=blue><b>"1*constant_term + 0*linear_term = 0"</b></font> </font>
<font color=navy>//</font>
real_1d_array y = <font color=blue><b>"[0.072436,0.246944,0.491263,0.522300,0.714064,0.921929]"</b></font>;
real_2d_array fmatrix = <font color=blue><b>"[[1,0.0],[1,0.2],[1,0.4],[1,0.6],[1,0.8],[1,1.0]]"</b></font>;
real_2d_array cmatrix = <font color=blue><b>"[[1,0,0]]"</b></font>;
ae_int_t info;
real_1d_array c;
lsfitreport rep;
<font color=navy>//</font>
<font color=navy>// Constrained fitting without weights</font>
<font color=navy>//</font>
lsfitlinearc(y, fmatrix, cmatrix, info, c, rep);
printf(<font color=blue><b>"%d\n"</b></font>, <b>int</b>(info)); <font color=navy>// EXPECTED: 1</font>
printf(<font color=blue><b>"%s\n"</b></font>, c.tostring(3).c_str()); <font color=navy>// EXPECTED: [0,0.932933]</font>
<font color=navy>//</font>
<font color=navy>// Constrained fitting with individual weights</font>
<font color=navy>//</font>
real_1d_array w = <font color=blue><b>"[1, 1.414213, 1, 1, 1, 1]"</b></font>;
lsfitlinearwc(y, w, fmatrix, cmatrix, info, c, rep);
printf(<font color=blue><b>"%d\n"</b></font>, <b>int</b>(info)); <font color=navy>// EXPECTED: 1</font>
printf(<font color=blue><b>"%s\n"</b></font>, c.tostring(3).c_str()); <font color=navy>// EXPECTED: [0,0.938322]</font>
<b>return</b> 0;
}
</pre><a name='example_lsfit_d_nlf'></a><h3 class=pageheader>lsfit_d_nlf example</h3>
<pre class=source>
#include <font color=blue><b>"stdafx.h"</b></font>
#include <stdlib.h>
#include <stdio.h>
#include <math.h>
#include <font color=blue><b>"interpolation.h"</b></font>
using namespace alglib;
<b>void</b> function_cx_1_func(<b>const</b> real_1d_array &c, <b>const</b> real_1d_array &x, <b>double</b> &func, <b>void</b> *ptr)
{
<font color=navy>// this callback calculates f(c,x)=exp(-c0*sqr(x0))</font>
<font color=navy>// where x is a position on X-axis and c is adjustable parameter</font>
func = exp(-c[0]*pow(x[0],2));
}
<b>int</b> main(<b>int</b> argc, char **argv)
{
<font color=navy>//</font>
<font color=navy>// In this example we demonstrate exponential fitting</font>
<font color=navy>// by f(x) = exp(-c*x^2)</font>
<font color=navy>// using function value only.</font>
<font color=navy>//</font>
<font color=navy>// Gradient is estimated using combination of numerical differences</font>
<font color=navy>// and secant updates. diffstep variable stores differentiation step </font>
<font color=navy>// (we have to tell algorithm what step to use).</font>
<font color=navy>//</font>
real_2d_array x = <font color=blue><b>"[[-1],[-0.8],[-0.6],[-0.4],[-0.2],[0],[0.2],[0.4],[0.6],[0.8],[1.0]]"</b></font>;
real_1d_array y = <font color=blue><b>"[0.223130, 0.382893, 0.582748, 0.786628, 0.941765, 1.000000, 0.941765, 0.786628, 0.582748, 0.382893, 0.223130]"</b></font>;
real_1d_array c = <font color=blue><b>"[0.3]"</b></font>;
<b>double</b> epsf = 0;
<b>double</b> epsx = 0.000001;
ae_int_t maxits = 0;
ae_int_t info;
lsfitstate state;
lsfitreport rep;
<b>double</b> diffstep = 0.0001;
<font color=navy>//</font>
<font color=navy>// Fitting without weights</font>
<font color=navy>//</font>
lsfitcreatef(x, y, c, diffstep, state);
lsfitsetcond(state, epsf, epsx, maxits);
alglib::lsfitfit(state, function_cx_1_func);
lsfitresults(state, info, c, rep);
printf(<font color=blue><b>"%d\n"</b></font>, <b>int</b>(info)); <font color=navy>// EXPECTED: 2</font>
printf(<font color=blue><b>"%s\n"</b></font>, c.tostring(1).c_str()); <font color=navy>// EXPECTED: [1.5]</font>
<font color=navy>//</font>
<font color=navy>// Fitting with weights</font>
<font color=navy>// (you can change weights and see how it changes result)</font>
<font color=navy>//</font>
real_1d_array w = <font color=blue><b>"[1,1,1,1,1,1,1,1,1,1,1]"</b></font>;
lsfitcreatewf(x, y, w, c, diffstep, state);
lsfitsetcond(state, epsf, epsx, maxits);
alglib::lsfitfit(state, function_cx_1_func);
lsfitresults(state, info, c, rep);
printf(<font color=blue><b>"%d\n"</b></font>, <b>int</b>(info)); <font color=navy>// EXPECTED: 2</font>
printf(<font color=blue><b>"%s\n"</b></font>, c.tostring(1).c_str()); <font color=navy>// EXPECTED: [1.5]</font>
<b>return</b> 0;
}
</pre><a name='example_lsfit_d_nlfb'></a><h3 class=pageheader>lsfit_d_nlfb example</h3>
<pre class=source>
#include <font color=blue><b>"stdafx.h"</b></font>
#include <stdlib.h>
#include <stdio.h>
#include <math.h>
#include <font color=blue><b>"interpolation.h"</b></font>
using namespace alglib;
<b>void</b> function_cx_1_func(<b>const</b> real_1d_array &c, <b>const</b> real_1d_array &x, <b>double</b> &func, <b>void</b> *ptr)
{
<font color=navy>// this callback calculates f(c,x)=exp(-c0*sqr(x0))</font>
<font color=navy>// where x is a position on X-axis and c is adjustable parameter</font>
func = exp(-c[0]*pow(x[0],2));
}
<b>int</b> main(<b>int</b> argc, char **argv)
{
<font color=navy>//</font>
<font color=navy>// In this example we demonstrate exponential fitting by</font>
<font color=navy>// f(x) = exp(-c*x^2)</font>
<font color=navy>// subject to bound constraints</font>
<font color=navy>// 0.0 <= c <= 1.0</font>
<font color=navy>// using function value only.</font>
<font color=navy>//</font>
<font color=navy>// Gradient is estimated using combination of numerical differences</font>
<font color=navy>// and secant updates. diffstep variable stores differentiation step </font>
<font color=navy>// (we have to tell algorithm what step to use).</font>
<font color=navy>//</font>
<font color=navy>// Unconstrained solution is c=1.5, but because of constraints we should</font>
<font color=navy>// get c=1.0 (at the boundary).</font>
<font color=navy>//</font>
real_2d_array x = <font color=blue><b>"[[-1],[-0.8],[-0.6],[-0.4],[-0.2],[0],[0.2],[0.4],[0.6],[0.8],[1.0]]"</b></font>;
real_1d_array y = <font color=blue><b>"[0.223130, 0.382893, 0.582748, 0.786628, 0.941765, 1.000000, 0.941765, 0.786628, 0.582748, 0.382893, 0.223130]"</b></font>;
real_1d_array c = <font color=blue><b>"[0.3]"</b></font>;
real_1d_array bndl = <font color=blue><b>"[0.0]"</b></font>;
real_1d_array bndu = <font color=blue><b>"[1.0]"</b></font>;
<b>double</b> epsf = 0;
<b>double</b> epsx = 0.000001;
ae_int_t maxits = 0;
ae_int_t info;
lsfitstate state;
lsfitreport rep;
<b>double</b> diffstep = 0.0001;
lsfitcreatef(x, y, c, diffstep, state);
lsfitsetbc(state, bndl, bndu);
lsfitsetcond(state, epsf, epsx, maxits);
alglib::lsfitfit(state, function_cx_1_func);
lsfitresults(state, info, c, rep);
printf(<font color=blue><b>"%s\n"</b></font>, c.tostring(1).c_str()); <font color=navy>// EXPECTED: [1.0]</font>
<b>return</b> 0;
}
</pre><a name='example_lsfit_d_nlfg'></a><h3 class=pageheader>lsfit_d_nlfg example</h3>
<pre class=source>
#include <font color=blue><b>"stdafx.h"</b></font>
#include <stdlib.h>
#include <stdio.h>
#include <math.h>
#include <font color=blue><b>"interpolation.h"</b></font>
using namespace alglib;
<b>void</b> function_cx_1_func(<b>const</b> real_1d_array &c, <b>const</b> real_1d_array &x, <b>double</b> &func, <b>void</b> *ptr)
{
<font color=navy>// this callback calculates f(c,x)=exp(-c0*sqr(x0))</font>
<font color=navy>// where x is a position on X-axis and c is adjustable parameter</font>
func = exp(-c[0]*pow(x[0],2));
}
<b>void</b> function_cx_1_grad(<b>const</b> real_1d_array &c, <b>const</b> real_1d_array &x, <b>double</b> &func, real_1d_array &grad, <b>void</b> *ptr)
{
<font color=navy>// this callback calculates f(c,x)=exp(-c0*sqr(x0)) and gradient G={df/dc[i]}</font>
<font color=navy>// where x is a position on X-axis and c is adjustable parameter.</font>
<font color=navy>// IMPORTANT: gradient is calculated with respect to C, not to X</font>
func = exp(-c[0]*pow(x[0],2));
grad[0] = -pow(x[0],2)*func;
}
<b>int</b> main(<b>int</b> argc, char **argv)
{
<font color=navy>//</font>
<font color=navy>// In this example we demonstrate exponential fitting</font>
<font color=navy>// by f(x) = exp(-c*x^2)</font>
<font color=navy>// using function value and gradient (with respect to c).</font>
<font color=navy>//</font>
real_2d_array x = <font color=blue><b>"[[-1],[-0.8],[-0.6],[-0.4],[-0.2],[0],[0.2],[0.4],[0.6],[0.8],[1.0]]"</b></font>;
real_1d_array y = <font color=blue><b>"[0.223130, 0.382893, 0.582748, 0.786628, 0.941765, 1.000000, 0.941765, 0.786628, 0.582748, 0.382893, 0.223130]"</b></font>;
real_1d_array c = <font color=blue><b>"[0.3]"</b></font>;
<b>double</b> epsf = 0;
<b>double</b> epsx = 0.000001;
ae_int_t maxits = 0;
ae_int_t info;
lsfitstate state;
lsfitreport rep;
<font color=navy>//</font>
<font color=navy>// Fitting without weights</font>
<font color=navy>//</font>
lsfitcreatefg(x, y, c, true, state);
lsfitsetcond(state, epsf, epsx, maxits);
alglib::lsfitfit(state, function_cx_1_func, function_cx_1_grad);
lsfitresults(state, info, c, rep);
printf(<font color=blue><b>"%d\n"</b></font>, <b>int</b>(info)); <font color=navy>// EXPECTED: 2</font>
printf(<font color=blue><b>"%s\n"</b></font>, c.tostring(1).c_str()); <font color=navy>// EXPECTED: [1.5]</font>
<font color=navy>//</font>
<font color=navy>// Fitting with weights</font>
<font color=navy>// (you can change weights and see how it changes result)</font>
<font color=navy>//</font>
real_1d_array w = <font color=blue><b>"[1,1,1,1,1,1,1,1,1,1,1]"</b></font>;
lsfitcreatewfg(x, y, w, c, true, state);
lsfitsetcond(state, epsf, epsx, maxits);
alglib::lsfitfit(state, function_cx_1_func, function_cx_1_grad);
lsfitresults(state, info, c, rep);
printf(<font color=blue><b>"%d\n"</b></font>, <b>int</b>(info)); <font color=navy>// EXPECTED: 2</font>
printf(<font color=blue><b>"%s\n"</b></font>, c.tostring(1).c_str()); <font color=navy>// EXPECTED: [1.5]</font>
<b>return</b> 0;
}
</pre><a name='example_lsfit_d_nlfgh'></a><h3 class=pageheader>lsfit_d_nlfgh example</h3>
<pre class=source>
#include <font color=blue><b>"stdafx.h"</b></font>
#include <stdlib.h>
#include <stdio.h>
#include <math.h>
#include <font color=blue><b>"interpolation.h"</b></font>
using namespace alglib;
<b>void</b> function_cx_1_func(<b>const</b> real_1d_array &c, <b>const</b> real_1d_array &x, <b>double</b> &func, <b>void</b> *ptr)
{
<font color=navy>// this callback calculates f(c,x)=exp(-c0*sqr(x0))</font>
<font color=navy>// where x is a position on X-axis and c is adjustable parameter</font>
func = exp(-c[0]*pow(x[0],2));
}
<b>void</b> function_cx_1_grad(<b>const</b> real_1d_array &c, <b>const</b> real_1d_array &x, <b>double</b> &func, real_1d_array &grad, <b>void</b> *ptr)
{
<font color=navy>// this callback calculates f(c,x)=exp(-c0*sqr(x0)) and gradient G={df/dc[i]}</font>
<font color=navy>// where x is a position on X-axis and c is adjustable parameter.</font>
<font color=navy>// IMPORTANT: gradient is calculated with respect to C, not to X</font>
func = exp(-c[0]*pow(x[0],2));
grad[0] = -pow(x[0],2)*func;
}
<b>void</b> function_cx_1_hess(<b>const</b> real_1d_array &c, <b>const</b> real_1d_array &x, <b>double</b> &func, real_1d_array &grad, real_2d_array &hess, <b>void</b> *ptr)
{
<font color=navy>// this callback calculates f(c,x)=exp(-c0*sqr(x0)), gradient G={df/dc[i]} and Hessian H={d2f/(dc[i]*dc[j])}</font>
<font color=navy>// where x is a position on X-axis and c is adjustable parameter.</font>
<font color=navy>// IMPORTANT: gradient/Hessian are calculated with respect to C, not to X</font>
func = exp(-c[0]*pow(x[0],2));
grad[0] = -pow(x[0],2)*func;
hess[0][0] = pow(x[0],4)*func;
}
<b>int</b> main(<b>int</b> argc, char **argv)
{
<font color=navy>//</font>
<font color=navy>// In this example we demonstrate exponential fitting</font>
<font color=navy>// by f(x) = exp(-c*x^2)</font>
<font color=navy>// using function value, gradient and Hessian (with respect to c)</font>
<font color=navy>//</font>
real_2d_array x = <font color=blue><b>"[[-1],[-0.8],[-0.6],[-0.4],[-0.2],[0],[0.2],[0.4],[0.6],[0.8],[1.0]]"</b></font>;
real_1d_array y = <font color=blue><b>"[0.223130, 0.382893, 0.582748, 0.786628, 0.941765, 1.000000, 0.941765, 0.786628, 0.582748, 0.382893, 0.223130]"</b></font>;
real_1d_array c = <font color=blue><b>"[0.3]"</b></font>;
<b>double</b> epsf = 0;
<b>double</b> epsx = 0.000001;
ae_int_t maxits = 0;
ae_int_t info;
lsfitstate state;
lsfitreport rep;
<font color=navy>//</font>
<font color=navy>// Fitting without weights</font>
<font color=navy>//</font>
lsfitcreatefgh(x, y, c, state);
lsfitsetcond(state, epsf, epsx, maxits);
alglib::lsfitfit(state, function_cx_1_func, function_cx_1_grad, function_cx_1_hess);
lsfitresults(state, info, c, rep);
printf(<font color=blue><b>"%d\n"</b></font>, <b>int</b>(info)); <font color=navy>// EXPECTED: 2</font>
printf(<font color=blue><b>"%s\n"</b></font>, c.tostring(1).c_str()); <font color=navy>// EXPECTED: [1.5]</font>
<font color=navy>//</font>
<font color=navy>// Fitting with weights</font>
<font color=navy>// (you can change weights and see how it changes result)</font>
<font color=navy>//</font>
real_1d_array w = <font color=blue><b>"[1,1,1,1,1,1,1,1,1,1,1]"</b></font>;
lsfitcreatewfgh(x, y, w, c, state);
lsfitsetcond(state, epsf, epsx, maxits);
alglib::lsfitfit(state, function_cx_1_func, function_cx_1_grad, function_cx_1_hess);
lsfitresults(state, info, c, rep);
printf(<font color=blue><b>"%d\n"</b></font>, <b>int</b>(info)); <font color=navy>// EXPECTED: 2</font>
printf(<font color=blue><b>"%s\n"</b></font>, c.tostring(1).c_str()); <font color=navy>// EXPECTED: [1.5]</font>
<b>return</b> 0;
}
</pre><a name='example_lsfit_d_nlscale'></a><h3 class=pageheader>lsfit_d_nlscale example</h3>
<pre class=source>
#include <font color=blue><b>"stdafx.h"</b></font>
#include <stdlib.h>
#include <stdio.h>
#include <math.h>
#include <font color=blue><b>"interpolation.h"</b></font>
using namespace alglib;
<b>void</b> function_debt_func(<b>const</b> real_1d_array &c, <b>const</b> real_1d_array &x, <b>double</b> &func, <b>void</b> *ptr)
{
<font color=navy>//</font>
<font color=navy>// this callback calculates f(c,x)=c[0]*(1+c[1]*(pow(x[0]-1999,c[2])-1))</font>
<font color=navy>//</font>
func = c[0]*(1+c[1]*(pow(x[0]-1999,c[2])-1));
}
<b>int</b> main(<b>int</b> argc, char **argv)
{
<font color=navy>//</font>
<font color=navy>// In this example we demonstrate fitting by</font>
<font color=navy>// f(x) = c[0]*(1+c[1]*((x-1999)^c[2]-1))</font>
<font color=navy>// subject to bound constraints</font>
<font color=navy>// -INF < c[0] < +INF</font>
<font color=navy>// -10 <= c[1] <= +10</font>
<font color=navy>// 0.1 <= c[2] <= 2.0</font>
<font color=navy>// Data we want to fit are time series of Japan national debt</font>
<font color=navy>// collected from 2000 to 2008 measured in USD (dollars, not</font>
<font color=navy>// millions of dollars).</font>
<font color=navy>//</font>
<font color=navy>// Our variables are:</font>
<font color=navy>// c[0] - debt value at initial moment (2000),</font>
<font color=navy>// c[1] - direction coefficient (growth or decrease),</font>
<font color=navy>// c[2] - curvature coefficient.</font>
<font color=navy>// You may see that our variables are badly scaled - first one </font>
<font color=navy>// is order of 10^12, and next two are somewhere about 1 in </font>
<font color=navy>// magnitude. Such problem is difficult to solve without some</font>
<font color=navy>// kind of scaling.</font>
<font color=navy>// That is exactly where lsfitsetscale() function can be used.</font>
<font color=navy>// We set scale of our variables to [1.0E12, 1, 1], which allows</font>
<font color=navy>// us to easily solve this problem.</font>
<font color=navy>//</font>
<font color=navy>// You can try commenting out lsfitsetscale() call - and you will </font>
<font color=navy>// see that algorithm will fail to converge.</font>
<font color=navy>//</font>
real_2d_array x = <font color=blue><b>"[[2000],[2001],[2002],[2003],[2004],[2005],[2006],[2007],[2008]]"</b></font>;
real_1d_array y = <font color=blue><b>"[4323239600000.0, 4560913100000.0, 5564091500000.0, 6743189300000.0, 7284064600000.0, 7050129600000.0, 7092221500000.0, 8483907600000.0, 8625804400000.0]"</b></font>;
real_1d_array c = <font color=blue><b>"[1.0e+13, 1, 1]"</b></font>;
<b>double</b> epsf = 0;
<b>double</b> epsx = 1.0e-5;
real_1d_array bndl = <font color=blue><b>"[-inf, -10, 0.1]"</b></font>;
real_1d_array bndu = <font color=blue><b>"[+inf, +10, 2.0]"</b></font>;
real_1d_array s = <font color=blue><b>"[1.0e+12, 1, 1]"</b></font>;
ae_int_t maxits = 0;
ae_int_t info;
lsfitstate state;
lsfitreport rep;
<b>double</b> diffstep = 1.0e-5;
lsfitcreatef(x, y, c, diffstep, state);
lsfitsetcond(state, epsf, epsx, maxits);
lsfitsetbc(state, bndl, bndu);
lsfitsetscale(state, s);
alglib::lsfitfit(state, function_debt_func);
lsfitresults(state, info, c, rep);
printf(<font color=blue><b>"%d\n"</b></font>, <b>int</b>(info)); <font color=navy>// EXPECTED: 2</font>
printf(<font color=blue><b>"%s\n"</b></font>, c.tostring(-2).c_str()); <font color=navy>// EXPECTED: [4.142560E+12, 0.434240, 0.565376]</font>
<b>return</b> 0;
}
</pre><a name='example_lsfit_d_pol'></a><h3 class=pageheader>lsfit_d_pol example</h3>
<pre class=source>
#include <font color=blue><b>"stdafx.h"</b></font>
#include <stdlib.h>
#include <stdio.h>
#include <math.h>
#include <font color=blue><b>"interpolation.h"</b></font>
using namespace alglib;
<b>int</b> main(<b>int</b> argc, char **argv)
{
<font color=navy>//</font>
<font color=navy>// This example demonstrates polynomial fitting.</font>
<font color=navy>//</font>
<font color=navy>// Fitting is done by two (M=2) functions from polynomial basis:</font>
<font color=navy>// f0 = 1</font>
<font color=navy>// f1 = x</font>
<font color=navy>// Basically, it just a linear fit; more complex polynomials may be used</font>
<font color=navy>// (e.g. parabolas with M=3, cubic with M=4), but even such simple fit allows</font>
<font color=navy>// us to demonstrate polynomialfit() function in action.</font>
<font color=navy>//</font>
<font color=navy>// We have:</font>
<font color=navy>// * x set of abscissas</font>
<font color=navy>// * y experimental data</font>
<font color=navy>//</font>
<font color=navy>// Additionally we demonstrate weighted fitting, where second point has</font>
<font color=navy>// more weight than other ones.</font>
<font color=navy>//</font>
real_1d_array x = <font color=blue><b>"[0.0,0.1,0.2,0.3,0.4,0.5,0.6,0.7,0.8,0.9,1.0]"</b></font>;
real_1d_array y = <font color=blue><b>"[0.00,0.05,0.26,0.32,0.33,0.43,0.60,0.60,0.77,0.98,1.02]"</b></font>;
ae_int_t m = 2;
<b>double</b> t = 2;
ae_int_t info;
barycentricinterpolant p;
polynomialfitreport rep;
<b>double</b> v;
<font color=navy>//</font>
<font color=navy>// Fitting without individual weights</font>
<font color=navy>//</font>
<font color=navy>// NOTE: result is returned as barycentricinterpolant structure.</font>
<font color=navy>// <b>if</b> you want to get representation in the power basis,</font>
<font color=navy>// you can use barycentricbar2pow() function to convert</font>
<font color=navy>// from barycentric to power representation (see docs <b>for</b> </font>
<font color=navy>// POLINT subpackage <b>for</b> more info).</font>
<font color=navy>//</font>
polynomialfit(x, y, m, info, p, rep);
v = barycentriccalc(p, t);
printf(<font color=blue><b>"%.2f\n"</b></font>, <b>double</b>(v)); <font color=navy>// EXPECTED: 2.011</font>
<font color=navy>//</font>
<font color=navy>// Fitting with individual weights</font>
<font color=navy>//</font>
<font color=navy>// NOTE: slightly different result is returned</font>
<font color=navy>//</font>
real_1d_array w = <font color=blue><b>"[1,1.414213562,1,1,1,1,1,1,1,1,1]"</b></font>;
real_1d_array xc = <font color=blue><b>"[]"</b></font>;
real_1d_array yc = <font color=blue><b>"[]"</b></font>;
integer_1d_array dc = <font color=blue><b>"[]"</b></font>;
polynomialfitwc(x, y, w, xc, yc, dc, m, info, p, rep);
v = barycentriccalc(p, t);
printf(<font color=blue><b>"%.2f\n"</b></font>, <b>double</b>(v)); <font color=navy>// EXPECTED: 2.023</font>
<b>return</b> 0;
}
</pre><a name='example_lsfit_d_polc'></a><h3 class=pageheader>lsfit_d_polc example</h3>
<pre class=source>
#include <font color=blue><b>"stdafx.h"</b></font>
#include <stdlib.h>
#include <stdio.h>
#include <math.h>
#include <font color=blue><b>"interpolation.h"</b></font>
using namespace alglib;
<b>int</b> main(<b>int</b> argc, char **argv)
{
<font color=navy>//</font>
<font color=navy>// This example demonstrates polynomial fitting.</font>
<font color=navy>//</font>
<font color=navy>// Fitting is done by two (M=2) functions from polynomial basis:</font>
<font color=navy>// f0 = 1</font>
<font color=navy>// f1 = x</font>
<font color=navy>// with simple constraint on function value</font>
<font color=navy>// f(0) = 0</font>
<font color=navy>// Basically, it just a linear fit; more complex polynomials may be used</font>
<font color=navy>// (e.g. parabolas with M=3, cubic with M=4), but even such simple fit allows</font>
<font color=navy>// us to demonstrate polynomialfit() function in action.</font>
<font color=navy>//</font>
<font color=navy>// We have:</font>
<font color=navy>// * x set of abscissas</font>
<font color=navy>// * y experimental data</font>
<font color=navy>// * xc points where constraints are placed</font>
<font color=navy>// * yc constraints on derivatives</font>
<font color=navy>// * dc derivative indices</font>
<font color=navy>// (0 means function itself, 1 means first derivative)</font>
<font color=navy>//</font>
real_1d_array x = <font color=blue><b>"[1.0,1.0]"</b></font>;
real_1d_array y = <font color=blue><b>"[0.9,1.1]"</b></font>;
real_1d_array w = <font color=blue><b>"[1,1]"</b></font>;
real_1d_array xc = <font color=blue><b>"[0]"</b></font>;
real_1d_array yc = <font color=blue><b>"[0]"</b></font>;
integer_1d_array dc = <font color=blue><b>"[0]"</b></font>;
<b>double</b> t = 2;
ae_int_t m = 2;
ae_int_t info;
barycentricinterpolant p;
polynomialfitreport rep;
<b>double</b> v;
polynomialfitwc(x, y, w, xc, yc, dc, m, info, p, rep);
v = barycentriccalc(p, t);
printf(<font color=blue><b>"%.2f\n"</b></font>, <b>double</b>(v)); <font color=navy>// EXPECTED: 2.000</font>
<b>return</b> 0;
}
</pre><a name='example_lsfit_d_spline'></a><h3 class=pageheader>lsfit_d_spline example</h3>
<pre class=source>
#include <font color=blue><b>"stdafx.h"</b></font>
#include <stdlib.h>
#include <stdio.h>
#include <math.h>
#include <font color=blue><b>"interpolation.h"</b></font>
using namespace alglib;
<b>int</b> main(<b>int</b> argc, char **argv)
{
<font color=navy>//</font>
<font color=navy>// In this example we demonstrate penalized spline fitting of noisy data</font>
<font color=navy>//</font>
<font color=navy>// We have:</font>
<font color=navy>// * x - abscissas</font>
<font color=navy>// * y - vector of experimental data, straight line with small noise</font>
<font color=navy>//</font>
real_1d_array x = <font color=blue><b>"[0.00,0.10,0.20,0.30,0.40,0.50,0.60,0.70,0.80,0.90]"</b></font>;
real_1d_array y = <font color=blue><b>"[0.10,0.00,0.30,0.40,0.30,0.40,0.62,0.68,0.75,0.95]"</b></font>;
ae_int_t info;
<b>double</b> v;
spline1dinterpolant s;
spline1dfitreport rep;
<b>double</b> rho;
<font color=navy>//</font>
<font color=navy>// Fit with VERY small amount of smoothing (rho = -5.0)</font>
<font color=navy>// and large number of basis functions (M=50).</font>
<font color=navy>//</font>
<font color=navy>// With such small regularization penalized spline almost fully reproduces function values</font>
<font color=navy>//</font>
rho = -5.0;
spline1dfitpenalized(x, y, 50, rho, info, s, rep);
printf(<font color=blue><b>"%d\n"</b></font>, <b>int</b>(info)); <font color=navy>// EXPECTED: 1</font>
v = spline1dcalc(s, 0.0);
printf(<font color=blue><b>"%.1f\n"</b></font>, <b>double</b>(v)); <font color=navy>// EXPECTED: 0.10</font>
<font color=navy>//</font>
<font color=navy>// Fit with VERY large amount of smoothing (rho = 10.0)</font>
<font color=navy>// and large number of basis functions (M=50).</font>
<font color=navy>//</font>
<font color=navy>// With such regularization our spline should become close to the straight line fit.</font>
<font color=navy>// We will compare its value in x=1.0 with results obtained from such fit.</font>
<font color=navy>//</font>
rho = +10.0;
spline1dfitpenalized(x, y, 50, rho, info, s, rep);
printf(<font color=blue><b>"%d\n"</b></font>, <b>int</b>(info)); <font color=navy>// EXPECTED: 1</font>
v = spline1dcalc(s, 1.0);
printf(<font color=blue><b>"%.2f\n"</b></font>, <b>double</b>(v)); <font color=navy>// EXPECTED: 0.969</font>
<font color=navy>//</font>
<font color=navy>// In real life applications you may need some moderate degree of fitting,</font>
<font color=navy>// so we try to fit once more with rho=3.0.</font>
<font color=navy>//</font>
rho = +3.0;
spline1dfitpenalized(x, y, 50, rho, info, s, rep);
printf(<font color=blue><b>"%d\n"</b></font>, <b>int</b>(info)); <font color=navy>// EXPECTED: 1</font>
<b>return</b> 0;
}
</pre><a name='example_lsfit_t_4pl'></a><h3 class=pageheader>lsfit_t_4pl example</h3>
<pre class=source>
#include <font color=blue><b>"stdafx.h"</b></font>
#include <stdlib.h>
#include <stdio.h>
#include <math.h>
#include <font color=blue><b>"interpolation.h"</b></font>
using namespace alglib;
<b>int</b> main(<b>int</b> argc, char **argv)
{
real_1d_array x = <font color=blue><b>"[1,2,3,4,5,6,7,8]"</b></font>;
real_1d_array y = <font color=blue><b>"[0.06313223,0.44552624,0.61838364,0.71385108,0.77345838,0.81383140,0.84280033,0.86449822]"</b></font>;
ae_int_t n = 8;
<b>double</b> a;
<b>double</b> b;
<b>double</b> c;
<b>double</b> d;
lsfitreport rep;
<font color=navy>//</font>
<font color=navy>// Test logisticfit4() on carefully designed data with a priori known answer.</font>
<font color=navy>//</font>
logisticfit4(x, y, n, a, b, c, d, rep);
printf(<font color=blue><b>"%.1f\n"</b></font>, <b>double</b>(a)); <font color=navy>// EXPECTED: -1.000</font>
printf(<font color=blue><b>"%.1f\n"</b></font>, <b>double</b>(b)); <font color=navy>// EXPECTED: 1.200</font>
printf(<font color=blue><b>"%.1f\n"</b></font>, <b>double</b>(c)); <font color=navy>// EXPECTED: 0.900</font>
printf(<font color=blue><b>"%.1f\n"</b></font>, <b>double</b>(d)); <font color=navy>// EXPECTED: 1.000</font>
<font color=navy>//</font>
<font color=navy>// Evaluate model at point x=0.5</font>
<font color=navy>//</font>
<b>double</b> v;
v = logisticcalc4(0.5, a, b, c, d);
printf(<font color=blue><b>"%.2f\n"</b></font>, <b>double</b>(v)); <font color=navy>// EXPECTED: -0.33874308</font>
<b>return</b> 0;
}
</pre><a name='example_lsfit_t_5pl'></a><h3 class=pageheader>lsfit_t_5pl example</h3>
<pre class=source>
#include <font color=blue><b>"stdafx.h"</b></font>
#include <stdlib.h>
#include <stdio.h>
#include <math.h>
#include <font color=blue><b>"interpolation.h"</b></font>
using namespace alglib;
<b>int</b> main(<b>int</b> argc, char **argv)
{
real_1d_array x = <font color=blue><b>"[1,2,3,4,5,6,7,8]"</b></font>;
real_1d_array y = <font color=blue><b>"[0.1949776139,0.5710060208,0.726002637,0.8060434158,0.8534547965,0.8842071579,0.9054773317,0.9209088299]"</b></font>;
ae_int_t n = 8;
<b>double</b> a;
<b>double</b> b;
<b>double</b> c;
<b>double</b> d;
<b>double</b> g;
lsfitreport rep;
<font color=navy>//</font>
<font color=navy>// Test logisticfit5() on carefully designed data with a priori known answer.</font>
<font color=navy>//</font>
logisticfit5(x, y, n, a, b, c, d, g, rep);
printf(<font color=blue><b>"%.1f\n"</b></font>, <b>double</b>(a)); <font color=navy>// EXPECTED: -1.000</font>
printf(<font color=blue><b>"%.1f\n"</b></font>, <b>double</b>(b)); <font color=navy>// EXPECTED: 1.200</font>
printf(<font color=blue><b>"%.1f\n"</b></font>, <b>double</b>(c)); <font color=navy>// EXPECTED: 0.900</font>
printf(<font color=blue><b>"%.1f\n"</b></font>, <b>double</b>(d)); <font color=navy>// EXPECTED: 1.000</font>
printf(<font color=blue><b>"%.1f\n"</b></font>, <b>double</b>(g)); <font color=navy>// EXPECTED: 1.200</font>
<font color=navy>//</font>
<font color=navy>// Evaluate model at point x=0.5</font>
<font color=navy>//</font>
<b>double</b> v;
v = logisticcalc5(0.5, a, b, c, d, g);
printf(<font color=blue><b>"%.2f\n"</b></font>, <b>double</b>(v)); <font color=navy>// EXPECTED: -0.2354656824</font>
<b>return</b> 0;
}
</pre><a name=unit_mannwhitneyu></a><h2 class=pageheader><code>mannwhitneyu</code> subpackage</h2>
<div class=pagecontent>
<h3 class=pageheader>Functions</h3>
<a href='#sub_mannwhitneyutest' class=toc>mannwhitneyutest</a><br>
<h3 class=pageheader>Examples</h3>
<table border=0 cellspacing=0 class='pagecontent'>
</table></div>
<a name='sub_mannwhitneyutest'></a><h3 class=pageheader><code>mannwhitneyutest</code> function</h3>
<pre class=source>
<div style='color: navy; margin-top: 0; margin-bottom: 0;'>/*************************************************************************
Mann-Whitney U-test
This test checks hypotheses about whether X and Y are samples of two
continuous distributions of the same shape and same median or whether
their medians are different.
The following tests are performed:
* two-tailed test (null hypothesis - the medians are equal)
* left-tailed test (null hypothesis - the median of the first sample
is greater than or equal to the median of the second sample)
* right-tailed test (null hypothesis - the median of the first sample
is less than or equal to the median of the second sample).
Requirements:
* the samples are independent
* X and Y are continuous distributions (or discrete distributions well-
approximating continuous distributions)
* distributions of X and Y have the same shape. The only possible
difference is their position (i.e. the value of the median)
* the number of elements in each sample is not less than 5
* the scale of measurement should be ordinal, interval or ratio (i.e.
the test could not be applied to nominal variables).
The test is non-parametric and doesn't require distributions to be normal.
Input parameters:
X - sample 1. Array whose index goes from 0 to N-1.
N - size of the sample. N>=5
Y - sample 2. Array whose index goes from 0 to M-1.
M - size of the sample. M>=5
Output parameters:
BothTails - p-value for two-tailed test.
If BothTails is less than the given significance level
the null hypothesis is rejected.
LeftTail - p-value for left-tailed test.
If LeftTail is less than the given significance level,
the null hypothesis is rejected.
RightTail - p-value for right-tailed test.
If RightTail is less than the given significance level
the null hypothesis is rejected.
To calculate p-values, special approximation is used. This method lets us
calculate p-values with satisfactory accuracy in interval [0.0001, 1].
There is no approximation outside the [0.0001, 1] interval. Therefore, if
the significance level outlies this interval, the test returns 0.0001.
Relative precision of approximation of p-value:
N M Max.err. Rms.err.
5..10 N..10 1.4e-02 6.0e-04
5..10 N..100 2.2e-02 5.3e-06
10..15 N..15 1.0e-02 3.2e-04
10..15 N..100 1.0e-02 2.2e-05
15..100 N..100 6.1e-03 2.7e-06
For N,M>100 accuracy checks weren't put into practice, but taking into
account characteristics of asymptotic approximation used, precision should
not be sharply different from the values for interval [5, 100].
NOTE: P-value approximation was optimized for 0.0001<=p<=0.2500. Thus,
P's outside of this interval are enforced to these bounds. Say, you
may quite often get P equal to exactly 0.25 or 0.0001.
-- ALGLIB --
Copyright 09.04.2007 by Bochkanov Sergey
*************************************************************************/
</div><div style='margin-top: 0; margin-bottom: 0;'><b>void</b> alglib::mannwhitneyutest(
real_1d_array x,
ae_int_t n,
real_1d_array y,
ae_int_t m,
<b>double</b>& bothtails,
<b>double</b>& lefttail,
<b>double</b>& righttail);
</div></pre>
<a name=unit_matdet></a><h2 class=pageheader><code>matdet</code> subpackage</h2>
<div class=pagecontent>
<h3 class=pageheader>Functions</h3>
<a href='#sub_cmatrixdet' class=toc>cmatrixdet</a><br>
<a href='#sub_cmatrixludet' class=toc>cmatrixludet</a><br>
<a href='#sub_rmatrixdet' class=toc>rmatrixdet</a><br>
<a href='#sub_rmatrixludet' class=toc>rmatrixludet</a><br>
<a href='#sub_spdmatrixcholeskydet' class=toc>spdmatrixcholeskydet</a><br>
<a href='#sub_spdmatrixdet' class=toc>spdmatrixdet</a><br>
<h3 class=pageheader>Examples</h3>
<table border=0 cellspacing=0 class='pagecontent'>
<tr align=left valign=top><td><a href='#example_matdet_d_1' class=toc>matdet_d_1</a></td><td width=15> </td><td>Determinant calculation, real matrix, short form</td></tr>
<tr align=left valign=top><td><a href='#example_matdet_d_2' class=toc>matdet_d_2</a></td><td width=15> </td><td>Determinant calculation, real matrix, full form</td></tr>
<tr align=left valign=top><td><a href='#example_matdet_d_3' class=toc>matdet_d_3</a></td><td width=15> </td><td>Determinant calculation, complex matrix, short form</td></tr>
<tr align=left valign=top><td><a href='#example_matdet_d_4' class=toc>matdet_d_4</a></td><td width=15> </td><td>Determinant calculation, complex matrix, full form</td></tr>
<tr align=left valign=top><td><a href='#example_matdet_d_5' class=toc>matdet_d_5</a></td><td width=15> </td><td>Determinant calculation, complex matrix with zero imaginary part, short form</td></tr>
</table></div>
<a name='sub_cmatrixdet'></a><h3 class=pageheader><code>cmatrixdet</code> function</h3>
<pre class=source>
<div style='color: navy; margin-top: 0; margin-bottom: 0;'>/*************************************************************************
Calculation of the determinant of a general matrix
Input parameters:
A - matrix, array[0..N-1, 0..N-1]
N - (optional) size of matrix A:
* if given, only principal NxN submatrix is processed and
overwritten. other elements are unchanged.
* if not given, automatically determined from matrix size
(A must be square matrix)
Result: determinant of matrix A.
-- ALGLIB --
Copyright 2005 by Bochkanov Sergey
*************************************************************************/
</div><div style='margin-top: 0; margin-bottom: 0;'>alglib::complex alglib::cmatrixdet(complex_2d_array a);
alglib::complex alglib::cmatrixdet(complex_2d_array a, ae_int_t n);
</div></pre>
<p align=left class=pagecontent><span class=inlineheader>Examples:</span> <a href='#example_matdet_d_3' class=nav>[1]</a> <a href='#example_matdet_d_4' class=nav>[2]</a> <a href='#example_matdet_d_5' class=nav>[3]</a> </p>
<a name='sub_cmatrixludet'></a><h3 class=pageheader><code>cmatrixludet</code> function</h3>
<pre class=source>
<div style='color: navy; margin-top: 0; margin-bottom: 0;'>/*************************************************************************
Determinant calculation of the matrix given by its LU decomposition.
Input parameters:
A - LU decomposition of the matrix (output of
RMatrixLU subroutine).
Pivots - table of permutations which were made during
the LU decomposition.
Output of RMatrixLU subroutine.
N - (optional) size of matrix A:
* if given, only principal NxN submatrix is processed and
overwritten. other elements are unchanged.
* if not given, automatically determined from matrix size
(A must be square matrix)
Result: matrix determinant.
-- ALGLIB --
Copyright 2005 by Bochkanov Sergey
*************************************************************************/
</div><div style='margin-top: 0; margin-bottom: 0;'>alglib::complex alglib::cmatrixludet(
complex_2d_array a,
integer_1d_array pivots);
alglib::complex alglib::cmatrixludet(
complex_2d_array a,
integer_1d_array pivots,
ae_int_t n);
</div></pre>
<a name='sub_rmatrixdet'></a><h3 class=pageheader><code>rmatrixdet</code> function</h3>
<pre class=source>
<div style='color: navy; margin-top: 0; margin-bottom: 0;'>/*************************************************************************
Calculation of the determinant of a general matrix
Input parameters:
A - matrix, array[0..N-1, 0..N-1]
N - (optional) size of matrix A:
* if given, only principal NxN submatrix is processed and
overwritten. other elements are unchanged.
* if not given, automatically determined from matrix size
(A must be square matrix)
Result: determinant of matrix A.
-- ALGLIB --
Copyright 2005 by Bochkanov Sergey
*************************************************************************/
</div><div style='margin-top: 0; margin-bottom: 0;'><b>double</b> alglib::rmatrixdet(real_2d_array a);
<b>double</b> alglib::rmatrixdet(real_2d_array a, ae_int_t n);
</div></pre>
<p align=left class=pagecontent><span class=inlineheader>Examples:</span> <a href='#example_matdet_d_1' class=nav>[1]</a> <a href='#example_matdet_d_2' class=nav>[2]</a> </p>
<a name='sub_rmatrixludet'></a><h3 class=pageheader><code>rmatrixludet</code> function</h3>
<pre class=source>
<div style='color: navy; margin-top: 0; margin-bottom: 0;'>/*************************************************************************
Determinant calculation of the matrix given by its LU decomposition.
Input parameters:
A - LU decomposition of the matrix (output of
RMatrixLU subroutine).
Pivots - table of permutations which were made during
the LU decomposition.
Output of RMatrixLU subroutine.
N - (optional) size of matrix A:
* if given, only principal NxN submatrix is processed and
overwritten. other elements are unchanged.
* if not given, automatically determined from matrix size
(A must be square matrix)
Result: matrix determinant.
-- ALGLIB --
Copyright 2005 by Bochkanov Sergey
*************************************************************************/
</div><div style='margin-top: 0; margin-bottom: 0;'><b>double</b> alglib::rmatrixludet(real_2d_array a, integer_1d_array pivots);
<b>double</b> alglib::rmatrixludet(
real_2d_array a,
integer_1d_array pivots,
ae_int_t n);
</div></pre>
<a name='sub_spdmatrixcholeskydet'></a><h3 class=pageheader><code>spdmatrixcholeskydet</code> function</h3>
<pre class=source>
<div style='color: navy; margin-top: 0; margin-bottom: 0;'>/*************************************************************************
Determinant calculation of the matrix given by the Cholesky decomposition.
Input parameters:
A - Cholesky decomposition,
output of SMatrixCholesky subroutine.
N - (optional) size of matrix A:
* if given, only principal NxN submatrix is processed and
overwritten. other elements are unchanged.
* if not given, automatically determined from matrix size
(A must be square matrix)
As the determinant is equal to the product of squares of diagonal elements,
it�s not necessary to specify which triangle - lower or upper - the matrix
is stored in.
Result:
matrix determinant.
-- ALGLIB --
Copyright 2005-2008 by Bochkanov Sergey
*************************************************************************/
</div><div style='margin-top: 0; margin-bottom: 0;'><b>double</b> alglib::spdmatrixcholeskydet(real_2d_array a);
<b>double</b> alglib::spdmatrixcholeskydet(real_2d_array a, ae_int_t n);
</div></pre>
<a name='sub_spdmatrixdet'></a><h3 class=pageheader><code>spdmatrixdet</code> function</h3>
<pre class=source>
<div style='color: navy; margin-top: 0; margin-bottom: 0;'>/*************************************************************************
Determinant calculation of the symmetric positive definite matrix.
Input parameters:
A - matrix. Array with elements [0..N-1, 0..N-1].
N - (optional) size of matrix A:
* if given, only principal NxN submatrix is processed and
overwritten. other elements are unchanged.
* if not given, automatically determined from matrix size
(A must be square matrix)
IsUpper - (optional) storage type:
* if True, symmetric matrix A is given by its upper
triangle, and the lower triangle isn�t used/changed by
function
* if False, symmetric matrix A is given by its lower
triangle, and the upper triangle isn�t used/changed by
function
* if not given, both lower and upper triangles must be
filled.
Result:
determinant of matrix A.
If matrix A is not positive definite, exception is thrown.
-- ALGLIB --
Copyright 2005-2008 by Bochkanov Sergey
*************************************************************************/
</div><div style='margin-top: 0; margin-bottom: 0;'><b>double</b> alglib::spdmatrixdet(real_2d_array a);
<b>double</b> alglib::spdmatrixdet(real_2d_array a, ae_int_t n, <b>bool</b> isupper);
</div></pre>
<a name='example_matdet_d_1'></a><h3 class=pageheader>matdet_d_1 example</h3>
<pre class=source>
#include <font color=blue><b>"stdafx.h"</b></font>
#include <stdlib.h>
#include <stdio.h>
#include <math.h>
#include <font color=blue><b>"linalg.h"</b></font>
using namespace alglib;
<b>int</b> main(<b>int</b> argc, char **argv)
{
real_2d_array b = <font color=blue><b>"[[1,2],[2,1]]"</b></font>;
<b>double</b> a;
a = rmatrixdet(b);
printf(<font color=blue><b>"%.3f\n"</b></font>, <b>double</b>(a)); <font color=navy>// EXPECTED: -3</font>
<b>return</b> 0;
}
</pre><a name='example_matdet_d_2'></a><h3 class=pageheader>matdet_d_2 example</h3>
<pre class=source>
#include <font color=blue><b>"stdafx.h"</b></font>
#include <stdlib.h>
#include <stdio.h>
#include <math.h>
#include <font color=blue><b>"linalg.h"</b></font>
using namespace alglib;
<b>int</b> main(<b>int</b> argc, char **argv)
{
real_2d_array b = <font color=blue><b>"[[5,4],[4,5]]"</b></font>;
<b>double</b> a;
a = rmatrixdet(b, 2);
printf(<font color=blue><b>"%.3f\n"</b></font>, <b>double</b>(a)); <font color=navy>// EXPECTED: 9</font>
<b>return</b> 0;
}
</pre><a name='example_matdet_d_3'></a><h3 class=pageheader>matdet_d_3 example</h3>
<pre class=source>
#include <font color=blue><b>"stdafx.h"</b></font>
#include <stdlib.h>
#include <stdio.h>
#include <math.h>
#include <font color=blue><b>"linalg.h"</b></font>
using namespace alglib;
<b>int</b> main(<b>int</b> argc, char **argv)
{
complex_2d_array b = <font color=blue><b>"[[1+1i,2],[2,1-1i]]"</b></font>;
alglib::complex a;
a = cmatrixdet(b);
printf(<font color=blue><b>"%s\n"</b></font>, a.tostring(3).c_str()); <font color=navy>// EXPECTED: -2</font>
<b>return</b> 0;
}
</pre><a name='example_matdet_d_4'></a><h3 class=pageheader>matdet_d_4 example</h3>
<pre class=source>
#include <font color=blue><b>"stdafx.h"</b></font>
#include <stdlib.h>
#include <stdio.h>
#include <math.h>
#include <font color=blue><b>"linalg.h"</b></font>
using namespace alglib;
<b>int</b> main(<b>int</b> argc, char **argv)
{
alglib::complex a;
complex_2d_array b = <font color=blue><b>"[[5i,4],[4i,5]]"</b></font>;
a = cmatrixdet(b, 2);
printf(<font color=blue><b>"%s\n"</b></font>, a.tostring(3).c_str()); <font color=navy>// EXPECTED: 9i</font>
<b>return</b> 0;
}
</pre><a name='example_matdet_d_5'></a><h3 class=pageheader>matdet_d_5 example</h3>
<pre class=source>
#include <font color=blue><b>"stdafx.h"</b></font>
#include <stdlib.h>
#include <stdio.h>
#include <math.h>
#include <font color=blue><b>"linalg.h"</b></font>
using namespace alglib;
<b>int</b> main(<b>int</b> argc, char **argv)
{
alglib::complex a;
complex_2d_array b = <font color=blue><b>"[[9,1],[2,1]]"</b></font>;
a = cmatrixdet(b);
printf(<font color=blue><b>"%s\n"</b></font>, a.tostring(3).c_str()); <font color=navy>// EXPECTED: 7</font>
<b>return</b> 0;
}
</pre><a name=unit_matgen></a><h2 class=pageheader><code>matgen</code> subpackage</h2>
<div class=pagecontent>
<h3 class=pageheader>Functions</h3>
<a href='#sub_cmatrixrndcond' class=toc>cmatrixrndcond</a><br>
<a href='#sub_cmatrixrndorthogonal' class=toc>cmatrixrndorthogonal</a><br>
<a href='#sub_cmatrixrndorthogonalfromtheleft' class=toc>cmatrixrndorthogonalfromtheleft</a><br>
<a href='#sub_cmatrixrndorthogonalfromtheright' class=toc>cmatrixrndorthogonalfromtheright</a><br>
<a href='#sub_hmatrixrndcond' class=toc>hmatrixrndcond</a><br>
<a href='#sub_hmatrixrndmultiply' class=toc>hmatrixrndmultiply</a><br>
<a href='#sub_hpdmatrixrndcond' class=toc>hpdmatrixrndcond</a><br>
<a href='#sub_rmatrixrndcond' class=toc>rmatrixrndcond</a><br>
<a href='#sub_rmatrixrndorthogonal' class=toc>rmatrixrndorthogonal</a><br>
<a href='#sub_rmatrixrndorthogonalfromtheleft' class=toc>rmatrixrndorthogonalfromtheleft</a><br>
<a href='#sub_rmatrixrndorthogonalfromtheright' class=toc>rmatrixrndorthogonalfromtheright</a><br>
<a href='#sub_smatrixrndcond' class=toc>smatrixrndcond</a><br>
<a href='#sub_smatrixrndmultiply' class=toc>smatrixrndmultiply</a><br>
<a href='#sub_spdmatrixrndcond' class=toc>spdmatrixrndcond</a><br>
<h3 class=pageheader>Examples</h3>
<table border=0 cellspacing=0 class='pagecontent'>
</table></div>
<a name='sub_cmatrixrndcond'></a><h3 class=pageheader><code>cmatrixrndcond</code> function</h3>
<pre class=source>
<div style='color: navy; margin-top: 0; margin-bottom: 0;'>/*************************************************************************
Generation of random NxN complex matrix with given condition number C and
norm2(A)=1
INPUT PARAMETERS:
N - matrix size
C - condition number (in 2-norm)
OUTPUT PARAMETERS:
A - random matrix with norm2(A)=1 and cond(A)=C
-- ALGLIB routine --
04.12.2009
Bochkanov Sergey
*************************************************************************/
</div><div style='margin-top: 0; margin-bottom: 0;'><b>void</b> alglib::cmatrixrndcond(ae_int_t n, <b>double</b> c, complex_2d_array& a);
</div></pre>
<a name='sub_cmatrixrndorthogonal'></a><h3 class=pageheader><code>cmatrixrndorthogonal</code> function</h3>
<pre class=source>
<div style='color: navy; margin-top: 0; margin-bottom: 0;'>/*************************************************************************
Generation of a random Haar distributed orthogonal complex matrix
INPUT PARAMETERS:
N - matrix size, N>=1
OUTPUT PARAMETERS:
A - orthogonal NxN matrix, array[0..N-1,0..N-1]
NOTE: this function uses algorithm described in Stewart, G. W. (1980),
"The Efficient Generation of Random Orthogonal Matrices with an
Application to Condition Estimators".
Speaking short, to generate an (N+1)x(N+1) orthogonal matrix, it:
* takes an NxN one
* takes uniformly distributed unit vector of dimension N+1.
* constructs a Householder reflection from the vector, then applies
it to the smaller matrix (embedded in the larger size with a 1 at
the bottom right corner).
-- ALGLIB routine --
04.12.2009
Bochkanov Sergey
*************************************************************************/
</div><div style='margin-top: 0; margin-bottom: 0;'><b>void</b> alglib::cmatrixrndorthogonal(ae_int_t n, complex_2d_array& a);
</div></pre>
<a name='sub_cmatrixrndorthogonalfromtheleft'></a><h3 class=pageheader><code>cmatrixrndorthogonalfromtheleft</code> function</h3>
<pre class=source>
<div style='color: navy; margin-top: 0; margin-bottom: 0;'>/*************************************************************************
Multiplication of MxN complex matrix by MxM random Haar distributed
complex orthogonal matrix
INPUT PARAMETERS:
A - matrix, array[0..M-1, 0..N-1]
M, N- matrix size
OUTPUT PARAMETERS:
A - Q*A, where Q is random MxM orthogonal matrix
-- ALGLIB routine --
04.12.2009
Bochkanov Sergey
*************************************************************************/
</div><div style='margin-top: 0; margin-bottom: 0;'><b>void</b> alglib::cmatrixrndorthogonalfromtheleft(
complex_2d_array& a,
ae_int_t m,
ae_int_t n);
</div></pre>
<a name='sub_cmatrixrndorthogonalfromtheright'></a><h3 class=pageheader><code>cmatrixrndorthogonalfromtheright</code> function</h3>
<pre class=source>
<div style='color: navy; margin-top: 0; margin-bottom: 0;'>/*************************************************************************
Multiplication of MxN complex matrix by NxN random Haar distributed
complex orthogonal matrix
INPUT PARAMETERS:
A - matrix, array[0..M-1, 0..N-1]
M, N- matrix size
OUTPUT PARAMETERS:
A - A*Q, where Q is random NxN orthogonal matrix
-- ALGLIB routine --
04.12.2009
Bochkanov Sergey
*************************************************************************/
</div><div style='margin-top: 0; margin-bottom: 0;'><b>void</b> alglib::cmatrixrndorthogonalfromtheright(
complex_2d_array& a,
ae_int_t m,
ae_int_t n);
</div></pre>
<a name='sub_hmatrixrndcond'></a><h3 class=pageheader><code>hmatrixrndcond</code> function</h3>
<pre class=source>
<div style='color: navy; margin-top: 0; margin-bottom: 0;'>/*************************************************************************
Generation of random NxN Hermitian matrix with given condition number and
norm2(A)=1
INPUT PARAMETERS:
N - matrix size
C - condition number (in 2-norm)
OUTPUT PARAMETERS:
A - random matrix with norm2(A)=1 and cond(A)=C
-- ALGLIB routine --
04.12.2009
Bochkanov Sergey
*************************************************************************/
</div><div style='margin-top: 0; margin-bottom: 0;'><b>void</b> alglib::hmatrixrndcond(ae_int_t n, <b>double</b> c, complex_2d_array& a);
</div></pre>
<a name='sub_hmatrixrndmultiply'></a><h3 class=pageheader><code>hmatrixrndmultiply</code> function</h3>
<pre class=source>
<div style='color: navy; margin-top: 0; margin-bottom: 0;'>/*************************************************************************
Hermitian multiplication of NxN matrix by random Haar distributed
complex orthogonal matrix
INPUT PARAMETERS:
A - matrix, array[0..N-1, 0..N-1]
N - matrix size
OUTPUT PARAMETERS:
A - Q^H*A*Q, where Q is random NxN orthogonal matrix
-- ALGLIB routine --
04.12.2009
Bochkanov Sergey
*************************************************************************/
</div><div style='margin-top: 0; margin-bottom: 0;'><b>void</b> alglib::hmatrixrndmultiply(complex_2d_array& a, ae_int_t n);
</div></pre>
<a name='sub_hpdmatrixrndcond'></a><h3 class=pageheader><code>hpdmatrixrndcond</code> function</h3>
<pre class=source>
<div style='color: navy; margin-top: 0; margin-bottom: 0;'>/*************************************************************************
Generation of random NxN Hermitian positive definite matrix with given
condition number and norm2(A)=1
INPUT PARAMETERS:
N - matrix size
C - condition number (in 2-norm)
OUTPUT PARAMETERS:
A - random HPD matrix with norm2(A)=1 and cond(A)=C
-- ALGLIB routine --
04.12.2009
Bochkanov Sergey
*************************************************************************/
</div><div style='margin-top: 0; margin-bottom: 0;'><b>void</b> alglib::hpdmatrixrndcond(ae_int_t n, <b>double</b> c, complex_2d_array& a);
</div></pre>
<a name='sub_rmatrixrndcond'></a><h3 class=pageheader><code>rmatrixrndcond</code> function</h3>
<pre class=source>
<div style='color: navy; margin-top: 0; margin-bottom: 0;'>/*************************************************************************
Generation of random NxN matrix with given condition number and norm2(A)=1
INPUT PARAMETERS:
N - matrix size
C - condition number (in 2-norm)
OUTPUT PARAMETERS:
A - random matrix with norm2(A)=1 and cond(A)=C
-- ALGLIB routine --
04.12.2009
Bochkanov Sergey
*************************************************************************/
</div><div style='margin-top: 0; margin-bottom: 0;'><b>void</b> alglib::rmatrixrndcond(ae_int_t n, <b>double</b> c, real_2d_array& a);
</div></pre>
<a name='sub_rmatrixrndorthogonal'></a><h3 class=pageheader><code>rmatrixrndorthogonal</code> function</h3>
<pre class=source>
<div style='color: navy; margin-top: 0; margin-bottom: 0;'>/*************************************************************************
Generation of a random uniformly distributed (Haar) orthogonal matrix
INPUT PARAMETERS:
N - matrix size, N>=1
OUTPUT PARAMETERS:
A - orthogonal NxN matrix, array[0..N-1,0..N-1]
NOTE: this function uses algorithm described in Stewart, G. W. (1980),
"The Efficient Generation of Random Orthogonal Matrices with an
Application to Condition Estimators".
Speaking short, to generate an (N+1)x(N+1) orthogonal matrix, it:
* takes an NxN one
* takes uniformly distributed unit vector of dimension N+1.
* constructs a Householder reflection from the vector, then applies
it to the smaller matrix (embedded in the larger size with a 1 at
the bottom right corner).
-- ALGLIB routine --
04.12.2009
Bochkanov Sergey
*************************************************************************/
</div><div style='margin-top: 0; margin-bottom: 0;'><b>void</b> alglib::rmatrixrndorthogonal(ae_int_t n, real_2d_array& a);
</div></pre>
<a name='sub_rmatrixrndorthogonalfromtheleft'></a><h3 class=pageheader><code>rmatrixrndorthogonalfromtheleft</code> function</h3>
<pre class=source>
<div style='color: navy; margin-top: 0; margin-bottom: 0;'>/*************************************************************************
Multiplication of MxN matrix by MxM random Haar distributed orthogonal matrix
INPUT PARAMETERS:
A - matrix, array[0..M-1, 0..N-1]
M, N- matrix size
OUTPUT PARAMETERS:
A - Q*A, where Q is random MxM orthogonal matrix
-- ALGLIB routine --
04.12.2009
Bochkanov Sergey
*************************************************************************/
</div><div style='margin-top: 0; margin-bottom: 0;'><b>void</b> alglib::rmatrixrndorthogonalfromtheleft(
real_2d_array& a,
ae_int_t m,
ae_int_t n);
</div></pre>
<a name='sub_rmatrixrndorthogonalfromtheright'></a><h3 class=pageheader><code>rmatrixrndorthogonalfromtheright</code> function</h3>
<pre class=source>
<div style='color: navy; margin-top: 0; margin-bottom: 0;'>/*************************************************************************
Multiplication of MxN matrix by NxN random Haar distributed orthogonal matrix
INPUT PARAMETERS:
A - matrix, array[0..M-1, 0..N-1]
M, N- matrix size
OUTPUT PARAMETERS:
A - A*Q, where Q is random NxN orthogonal matrix
-- ALGLIB routine --
04.12.2009
Bochkanov Sergey
*************************************************************************/
</div><div style='margin-top: 0; margin-bottom: 0;'><b>void</b> alglib::rmatrixrndorthogonalfromtheright(
real_2d_array& a,
ae_int_t m,
ae_int_t n);
</div></pre>
<a name='sub_smatrixrndcond'></a><h3 class=pageheader><code>smatrixrndcond</code> function</h3>
<pre class=source>
<div style='color: navy; margin-top: 0; margin-bottom: 0;'>/*************************************************************************
Generation of random NxN symmetric matrix with given condition number and
norm2(A)=1
INPUT PARAMETERS:
N - matrix size
C - condition number (in 2-norm)
OUTPUT PARAMETERS:
A - random matrix with norm2(A)=1 and cond(A)=C
-- ALGLIB routine --
04.12.2009
Bochkanov Sergey
*************************************************************************/
</div><div style='margin-top: 0; margin-bottom: 0;'><b>void</b> alglib::smatrixrndcond(ae_int_t n, <b>double</b> c, real_2d_array& a);
</div></pre>
<a name='sub_smatrixrndmultiply'></a><h3 class=pageheader><code>smatrixrndmultiply</code> function</h3>
<pre class=source>
<div style='color: navy; margin-top: 0; margin-bottom: 0;'>/*************************************************************************
Symmetric multiplication of NxN matrix by random Haar distributed
orthogonal matrix
INPUT PARAMETERS:
A - matrix, array[0..N-1, 0..N-1]
N - matrix size
OUTPUT PARAMETERS:
A - Q'*A*Q, where Q is random NxN orthogonal matrix
-- ALGLIB routine --
04.12.2009
Bochkanov Sergey
*************************************************************************/
</div><div style='margin-top: 0; margin-bottom: 0;'><b>void</b> alglib::smatrixrndmultiply(real_2d_array& a, ae_int_t n);
</div></pre>
<a name='sub_spdmatrixrndcond'></a><h3 class=pageheader><code>spdmatrixrndcond</code> function</h3>
<pre class=source>
<div style='color: navy; margin-top: 0; margin-bottom: 0;'>/*************************************************************************
Generation of random NxN symmetric positive definite matrix with given
condition number and norm2(A)=1
INPUT PARAMETERS:
N - matrix size
C - condition number (in 2-norm)
OUTPUT PARAMETERS:
A - random SPD matrix with norm2(A)=1 and cond(A)=C
-- ALGLIB routine --
04.12.2009
Bochkanov Sergey
*************************************************************************/
</div><div style='margin-top: 0; margin-bottom: 0;'><b>void</b> alglib::spdmatrixrndcond(ae_int_t n, <b>double</b> c, real_2d_array& a);
</div></pre>
<a name=unit_matinv></a><h2 class=pageheader><code>matinv</code> subpackage</h2>
<div class=pagecontent>
<h3 class=pageheader>Classes</h3>
<a href='#struct_matinvreport' class=toc>matinvreport</a><br>
<h3 class=pageheader>Functions</h3>
<a href='#sub_cmatrixinverse' class=toc>cmatrixinverse</a><br>
<a href='#sub_cmatrixluinverse' class=toc>cmatrixluinverse</a><br>
<a href='#sub_cmatrixtrinverse' class=toc>cmatrixtrinverse</a><br>
<a href='#sub_hpdmatrixcholeskyinverse' class=toc>hpdmatrixcholeskyinverse</a><br>
<a href='#sub_hpdmatrixinverse' class=toc>hpdmatrixinverse</a><br>
<a href='#sub_rmatrixinverse' class=toc>rmatrixinverse</a><br>
<a href='#sub_rmatrixluinverse' class=toc>rmatrixluinverse</a><br>
<a href='#sub_rmatrixtrinverse' class=toc>rmatrixtrinverse</a><br>
<a href='#sub_spdmatrixcholeskyinverse' class=toc>spdmatrixcholeskyinverse</a><br>
<a href='#sub_spdmatrixinverse' class=toc>spdmatrixinverse</a><br>
<h3 class=pageheader>Examples</h3>
<table border=0 cellspacing=0 class='pagecontent'>
<tr align=left valign=top><td><a href='#example_matinv_d_c1' class=toc>matinv_d_c1</a></td><td width=15> </td><td>Complex matrix inverse</td></tr>
<tr align=left valign=top><td><a href='#example_matinv_d_hpd1' class=toc>matinv_d_hpd1</a></td><td width=15> </td><td>HPD matrix inverse</td></tr>
<tr align=left valign=top><td><a href='#example_matinv_d_r1' class=toc>matinv_d_r1</a></td><td width=15> </td><td>Real matrix inverse</td></tr>
<tr align=left valign=top><td><a href='#example_matinv_d_spd1' class=toc>matinv_d_spd1</a></td><td width=15> </td><td>SPD matrix inverse</td></tr>
</table></div>
<a name='struct_matinvreport'></a><h3 class=pageheader><code>matinvreport</code> class</h3>
<pre class=source>
<div style='color: navy; margin-top: 0; margin-bottom: 0;'>/*************************************************************************
Matrix inverse report:
* R1 reciprocal of condition number in 1-norm
* RInf reciprocal of condition number in inf-norm
*************************************************************************/
</div><div style='margin-top: 0; margin-bottom: 0;'><b>class</b> matinvreport
{
<b>double</b> r1;
<b>double</b> rinf;
};
</div></pre>
<a name='sub_cmatrixinverse'></a><h3 class=pageheader><code>cmatrixinverse</code> function</h3>
<pre class=source>
<div style='color: navy; margin-top: 0; margin-bottom: 0;'>/*************************************************************************
Inversion of a general matrix.
COMMERCIAL EDITION OF ALGLIB:
! Commercial version of ALGLIB includes two important improvements of
! this function, which can be used from C++ and C#:
! * Intel MKL support (lightweight Intel MKL is shipped with ALGLIB)
! * multicore support
!
! Intel MKL gives approximately constant (with respect to number of
! worker threads) acceleration factor which depends on CPU being used,
! problem size and "baseline" ALGLIB edition which is used for
! comparison.
!
! Say, on SSE2-capable CPU with N=1024, HPC ALGLIB will be:
! * about 2-3x faster than ALGLIB for C++ without MKL
! * about 7-10x faster than "pure C#" edition of ALGLIB
! Difference in performance will be more striking on newer CPU's with
! support for newer SIMD instructions. Generally, MKL accelerates any
! problem whose size is at least 128, with best efficiency achieved for
! N's larger than 512.
!
! Commercial edition of ALGLIB also supports multithreaded acceleration
! of this function. We should note that matrix inversion is harder to
! parallelize than, say, matrix-matrix product - this algorithm has
! many internal synchronization points which can not be avoided. However
! parallelism starts to be profitable starting from N=1024, achieving
! near-linear speedup for N=4096 or higher.
!
! In order to use multicore features you have to:
! * use commercial version of ALGLIB
! * call this function with "smp_" prefix, which indicates that
! multicore code will be used (for multicore support)
!
! We recommend you to read 'Working with commercial version' section of
! ALGLIB Reference Manual in order to find out how to use performance-
! related features provided by commercial edition of ALGLIB.
Input parameters:
A - matrix
N - size of matrix A (optional) :
* if given, only principal NxN submatrix is processed and
overwritten. other elements are unchanged.
* if not given, size is automatically determined from
matrix size (A must be square matrix)
Output parameters:
Info - return code, same as in RMatrixLUInverse
Rep - solver report, same as in RMatrixLUInverse
A - inverse of matrix A, same as in RMatrixLUInverse
-- ALGLIB --
Copyright 2005 by Bochkanov Sergey
*************************************************************************/
</div><div style='margin-top: 0; margin-bottom: 0;'><b>void</b> alglib::cmatrixinverse(
complex_2d_array& a,
ae_int_t& info,
matinvreport& rep);
<b>void</b> alglib::cmatrixinverse(
complex_2d_array& a,
ae_int_t n,
ae_int_t& info,
matinvreport& rep);
<b>void</b> alglib::smp_cmatrixinverse(
complex_2d_array& a,
ae_int_t& info,
matinvreport& rep);
<b>void</b> alglib::smp_cmatrixinverse(
complex_2d_array& a,
ae_int_t n,
ae_int_t& info,
matinvreport& rep);
</div></pre>
<p align=left class=pagecontent><span class=inlineheader>Examples:</span> <a href='#example_matinv_d_c1' class=nav>[1]</a> </p>
<a name='sub_cmatrixluinverse'></a><h3 class=pageheader><code>cmatrixluinverse</code> function</h3>
<pre class=source>
<div style='color: navy; margin-top: 0; margin-bottom: 0;'>/*************************************************************************
Inversion of a matrix given by its LU decomposition.
COMMERCIAL EDITION OF ALGLIB:
! Commercial version of ALGLIB includes two important improvements of
! this function, which can be used from C++ and C#:
! * Intel MKL support (lightweight Intel MKL is shipped with ALGLIB)
! * multicore support
!
! Intel MKL gives approximately constant (with respect to number of
! worker threads) acceleration factor which depends on CPU being used,
! problem size and "baseline" ALGLIB edition which is used for
! comparison.
!
! Say, on SSE2-capable CPU with N=1024, HPC ALGLIB will be:
! * about 2-3x faster than ALGLIB for C++ without MKL
! * about 7-10x faster than "pure C#" edition of ALGLIB
! Difference in performance will be more striking on newer CPU's with
! support for newer SIMD instructions. Generally, MKL accelerates any
! problem whose size is at least 128, with best efficiency achieved for
! N's larger than 512.
!
! Commercial edition of ALGLIB also supports multithreaded acceleration
! of this function. We should note that matrix inversion is harder to
! parallelize than, say, matrix-matrix product - this algorithm has
! many internal synchronization points which can not be avoided. However
! parallelism starts to be profitable starting from N=1024, achieving
! near-linear speedup for N=4096 or higher.
!
! In order to use multicore features you have to:
! * use commercial version of ALGLIB
! * call this function with "smp_" prefix, which indicates that
! multicore code will be used (for multicore support)
!
! We recommend you to read 'Working with commercial version' section of
! ALGLIB Reference Manual in order to find out how to use performance-
! related features provided by commercial edition of ALGLIB.
INPUT PARAMETERS:
A - LU decomposition of the matrix
(output of CMatrixLU subroutine).
Pivots - table of permutations
(the output of CMatrixLU subroutine).
N - size of matrix A (optional) :
* if given, only principal NxN submatrix is processed and
overwritten. other elements are unchanged.
* if not given, size is automatically determined from
matrix size (A must be square matrix)
OUTPUT PARAMETERS:
Info - return code, same as in RMatrixLUInverse
Rep - solver report, same as in RMatrixLUInverse
A - inverse of matrix A, same as in RMatrixLUInverse
-- ALGLIB routine --
05.02.2010
Bochkanov Sergey
*************************************************************************/
</div><div style='margin-top: 0; margin-bottom: 0;'><b>void</b> alglib::cmatrixluinverse(
complex_2d_array& a,
integer_1d_array pivots,
ae_int_t& info,
matinvreport& rep);
<b>void</b> alglib::cmatrixluinverse(
complex_2d_array& a,
integer_1d_array pivots,
ae_int_t n,
ae_int_t& info,
matinvreport& rep);
<b>void</b> alglib::smp_cmatrixluinverse(
complex_2d_array& a,
integer_1d_array pivots,
ae_int_t& info,
matinvreport& rep);
<b>void</b> alglib::smp_cmatrixluinverse(
complex_2d_array& a,
integer_1d_array pivots,
ae_int_t n,
ae_int_t& info,
matinvreport& rep);
</div></pre>
<a name='sub_cmatrixtrinverse'></a><h3 class=pageheader><code>cmatrixtrinverse</code> function</h3>
<pre class=source>
<div style='color: navy; margin-top: 0; margin-bottom: 0;'>/*************************************************************************
Triangular matrix inverse (complex)
The subroutine inverts the following types of matrices:
* upper triangular
* upper triangular with unit diagonal
* lower triangular
* lower triangular with unit diagonal
In case of an upper (lower) triangular matrix, the inverse matrix will
also be upper (lower) triangular, and after the end of the algorithm, the
inverse matrix replaces the source matrix. The elements below (above) the
main diagonal are not changed by the algorithm.
If the matrix has a unit diagonal, the inverse matrix also has a unit
diagonal, and the diagonal elements are not passed to the algorithm.
COMMERCIAL EDITION OF ALGLIB:
! Commercial version of ALGLIB includes two important improvements of
! this function, which can be used from C++ and C#:
! * Intel MKL support (lightweight Intel MKL is shipped with ALGLIB)
! * multicore support
!
! Intel MKL gives approximately constant (with respect to number of
! worker threads) acceleration factor which depends on CPU being used,
! problem size and "baseline" ALGLIB edition which is used for
! comparison.
!
! Say, on SSE2-capable CPU with N=1024, HPC ALGLIB will be:
! * about 2-3x faster than ALGLIB for C++ without MKL
! * about 7-10x faster than "pure C#" edition of ALGLIB
! Difference in performance will be more striking on newer CPU's with
! support for newer SIMD instructions. Generally, MKL accelerates any
! problem whose size is at least 128, with best efficiency achieved for
! N's larger than 512.
!
! Commercial edition of ALGLIB also supports multithreaded acceleration
! of this function. We should note that triangular inverse is harder to
! parallelize than, say, matrix-matrix product - this algorithm has
! many internal synchronization points which can not be avoided. However
! parallelism starts to be profitable starting from N=1024, achieving
! near-linear speedup for N=4096 or higher.
!
! In order to use multicore features you have to:
! * use commercial version of ALGLIB
! * call this function with "smp_" prefix, which indicates that
! multicore code will be used (for multicore support)
!
! We recommend you to read 'Working with commercial version' section of
! ALGLIB Reference Manual in order to find out how to use performance-
! related features provided by commercial edition of ALGLIB.
Input parameters:
A - matrix, array[0..N-1, 0..N-1].
N - size of matrix A (optional) :
* if given, only principal NxN submatrix is processed and
overwritten. other elements are unchanged.
* if not given, size is automatically determined from
matrix size (A must be square matrix)
IsUpper - True, if the matrix is upper triangular.
IsUnit - diagonal type (optional):
* if True, matrix has unit diagonal (a[i,i] are NOT used)
* if False, matrix diagonal is arbitrary
* if not given, False is assumed
Output parameters:
Info - same as for RMatrixLUInverse
Rep - same as for RMatrixLUInverse
A - same as for RMatrixLUInverse.
-- ALGLIB --
Copyright 05.02.2010 by Bochkanov Sergey
*************************************************************************/
</div><div style='margin-top: 0; margin-bottom: 0;'><b>void</b> alglib::cmatrixtrinverse(
complex_2d_array& a,
<b>bool</b> isupper,
ae_int_t& info,
matinvreport& rep);
<b>void</b> alglib::cmatrixtrinverse(
complex_2d_array& a,
ae_int_t n,
<b>bool</b> isupper,
<b>bool</b> isunit,
ae_int_t& info,
matinvreport& rep);
<b>void</b> alglib::smp_cmatrixtrinverse(
complex_2d_array& a,
<b>bool</b> isupper,
ae_int_t& info,
matinvreport& rep);
<b>void</b> alglib::smp_cmatrixtrinverse(
complex_2d_array& a,
ae_int_t n,
<b>bool</b> isupper,
<b>bool</b> isunit,
ae_int_t& info,
matinvreport& rep);
</div></pre>
<a name='sub_hpdmatrixcholeskyinverse'></a><h3 class=pageheader><code>hpdmatrixcholeskyinverse</code> function</h3>
<pre class=source>
<div style='color: navy; margin-top: 0; margin-bottom: 0;'>/*************************************************************************
Inversion of a Hermitian positive definite matrix which is given
by Cholesky decomposition.
COMMERCIAL EDITION OF ALGLIB:
! Commercial version of ALGLIB includes two important improvements of
! this function, which can be used from C++ and C#:
! * Intel MKL support (lightweight Intel MKL is shipped with ALGLIB)
! * multicore support
!
! Intel MKL gives approximately constant (with respect to number of
! worker threads) acceleration factor which depends on CPU being used,
! problem size and "baseline" ALGLIB edition which is used for
! comparison.
!
! Say, on SSE2-capable CPU with N=1024, HPC ALGLIB will be:
! * about 2-3x faster than ALGLIB for C++ without MKL
! * about 7-10x faster than "pure C#" edition of ALGLIB
! Difference in performance will be more striking on newer CPU's with
! support for newer SIMD instructions. Generally, MKL accelerates any
! problem whose size is at least 128, with best efficiency achieved for
! N's larger than 512.
!
! Commercial edition of ALGLIB also supports multithreaded acceleration
! of this function. However, Cholesky inversion is a "difficult"
! algorithm - it has lots of internal synchronization points which
! prevents efficient parallelization of algorithm. Only very large
! problems (N=thousands) can be efficiently parallelized.
!
! We recommend you to read 'Working with commercial version' section of
! ALGLIB Reference Manual in order to find out how to use performance-
! related features provided by commercial edition of ALGLIB.
Input parameters:
A - Cholesky decomposition of the matrix to be inverted:
A=U�*U or A = L*L'.
Output of HPDMatrixCholesky subroutine.
N - size of matrix A (optional) :
* if given, only principal NxN submatrix is processed and
overwritten. other elements are unchanged.
* if not given, size is automatically determined from
matrix size (A must be square matrix)
IsUpper - storage type (optional):
* if True, symmetric matrix A is given by its upper
triangle, and the lower triangle isn�t used/changed by
function
* if False, symmetric matrix A is given by its lower
triangle, and the upper triangle isn�t used/changed by
function
* if not given, lower half is used.
Output parameters:
Info - return code, same as in RMatrixLUInverse
Rep - solver report, same as in RMatrixLUInverse
A - inverse of matrix A, same as in RMatrixLUInverse
-- ALGLIB routine --
10.02.2010
Bochkanov Sergey
*************************************************************************/
</div><div style='margin-top: 0; margin-bottom: 0;'><b>void</b> alglib::hpdmatrixcholeskyinverse(
complex_2d_array& a,
ae_int_t& info,
matinvreport& rep);
<b>void</b> alglib::hpdmatrixcholeskyinverse(
complex_2d_array& a,
ae_int_t n,
<b>bool</b> isupper,
ae_int_t& info,
matinvreport& rep);
<b>void</b> alglib::smp_hpdmatrixcholeskyinverse(
complex_2d_array& a,
ae_int_t& info,
matinvreport& rep);
<b>void</b> alglib::smp_hpdmatrixcholeskyinverse(
complex_2d_array& a,
ae_int_t n,
<b>bool</b> isupper,
ae_int_t& info,
matinvreport& rep);
</div></pre>
<a name='sub_hpdmatrixinverse'></a><h3 class=pageheader><code>hpdmatrixinverse</code> function</h3>
<pre class=source>
<div style='color: navy; margin-top: 0; margin-bottom: 0;'>/*************************************************************************
Inversion of a Hermitian positive definite matrix.
Given an upper or lower triangle of a Hermitian positive definite matrix,
the algorithm generates matrix A^-1 and saves the upper or lower triangle
depending on the input.
COMMERCIAL EDITION OF ALGLIB:
! Commercial version of ALGLIB includes two important improvements of
! this function, which can be used from C++ and C#:
! * Intel MKL support (lightweight Intel MKL is shipped with ALGLIB)
! * multicore support
!
! Intel MKL gives approximately constant (with respect to number of
! worker threads) acceleration factor which depends on CPU being used,
! problem size and "baseline" ALGLIB edition which is used for
! comparison.
!
! Say, on SSE2-capable CPU with N=1024, HPC ALGLIB will be:
! * about 2-3x faster than ALGLIB for C++ without MKL
! * about 7-10x faster than "pure C#" edition of ALGLIB
! Difference in performance will be more striking on newer CPU's with
! support for newer SIMD instructions. Generally, MKL accelerates any
! problem whose size is at least 128, with best efficiency achieved for
! N's larger than 512.
!
! Commercial edition of ALGLIB also supports multithreaded acceleration
! of this function. However, Cholesky inversion is a "difficult"
! algorithm - it has lots of internal synchronization points which
! prevents efficient parallelization of algorithm. Only very large
! problems (N=thousands) can be efficiently parallelized.
!
! We recommend you to read 'Working with commercial version' section of
! ALGLIB Reference Manual in order to find out how to use performance-
! related features provided by commercial edition of ALGLIB.
Input parameters:
A - matrix to be inverted (upper or lower triangle).
Array with elements [0..N-1,0..N-1].
N - size of matrix A (optional) :
* if given, only principal NxN submatrix is processed and
overwritten. other elements are unchanged.
* if not given, size is automatically determined from
matrix size (A must be square matrix)
IsUpper - storage type (optional):
* if True, symmetric matrix A is given by its upper
triangle, and the lower triangle isn�t used/changed by
function
* if False, symmetric matrix A is given by its lower
triangle, and the upper triangle isn�t used/changed by
function
* if not given, both lower and upper triangles must be
filled.
Output parameters:
Info - return code, same as in RMatrixLUInverse
Rep - solver report, same as in RMatrixLUInverse
A - inverse of matrix A, same as in RMatrixLUInverse
-- ALGLIB routine --
10.02.2010
Bochkanov Sergey
*************************************************************************/
</div><div style='margin-top: 0; margin-bottom: 0;'><b>void</b> alglib::hpdmatrixinverse(
complex_2d_array& a,
ae_int_t& info,
matinvreport& rep);
<b>void</b> alglib::hpdmatrixinverse(
complex_2d_array& a,
ae_int_t n,
<b>bool</b> isupper,
ae_int_t& info,
matinvreport& rep);
<b>void</b> alglib::smp_hpdmatrixinverse(
complex_2d_array& a,
ae_int_t& info,
matinvreport& rep);
<b>void</b> alglib::smp_hpdmatrixinverse(
complex_2d_array& a,
ae_int_t n,
<b>bool</b> isupper,
ae_int_t& info,
matinvreport& rep);
</div></pre>
<p align=left class=pagecontent><span class=inlineheader>Examples:</span> <a href='#example_matinv_d_hpd1' class=nav>[1]</a> </p>
<a name='sub_rmatrixinverse'></a><h3 class=pageheader><code>rmatrixinverse</code> function</h3>
<pre class=source>
<div style='color: navy; margin-top: 0; margin-bottom: 0;'>/*************************************************************************
Inversion of a general matrix.
COMMERCIAL EDITION OF ALGLIB:
! Commercial version of ALGLIB includes two important improvements of
! this function, which can be used from C++ and C#:
! * Intel MKL support (lightweight Intel MKL is shipped with ALGLIB)
! * multicore support
!
! Intel MKL gives approximately constant (with respect to number of
! worker threads) acceleration factor which depends on CPU being used,
! problem size and "baseline" ALGLIB edition which is used for
! comparison.
!
! Say, on SSE2-capable CPU with N=1024, HPC ALGLIB will be:
! * about 2-3x faster than ALGLIB for C++ without MKL
! * about 7-10x faster than "pure C#" edition of ALGLIB
! Difference in performance will be more striking on newer CPU's with
! support for newer SIMD instructions. Generally, MKL accelerates any
! problem whose size is at least 128, with best efficiency achieved for
! N's larger than 512.
!
! Commercial edition of ALGLIB also supports multithreaded acceleration
! of this function. We should note that matrix inversion is harder to
! parallelize than, say, matrix-matrix product - this algorithm has
! many internal synchronization points which can not be avoided. However
! parallelism starts to be profitable starting from N=1024, achieving
! near-linear speedup for N=4096 or higher.
!
! In order to use multicore features you have to:
! * use commercial version of ALGLIB
! * call this function with "smp_" prefix, which indicates that
! multicore code will be used (for multicore support)
!
! We recommend you to read 'Working with commercial version' section of
! ALGLIB Reference Manual in order to find out how to use performance-
! related features provided by commercial edition of ALGLIB.
Input parameters:
A - matrix.
N - size of matrix A (optional) :
* if given, only principal NxN submatrix is processed and
overwritten. other elements are unchanged.
* if not given, size is automatically determined from
matrix size (A must be square matrix)
Output parameters:
Info - return code, same as in RMatrixLUInverse
Rep - solver report, same as in RMatrixLUInverse
A - inverse of matrix A, same as in RMatrixLUInverse
Result:
True, if the matrix is not singular.
False, if the matrix is singular.
-- ALGLIB --
Copyright 2005-2010 by Bochkanov Sergey
*************************************************************************/
</div><div style='margin-top: 0; margin-bottom: 0;'><b>void</b> alglib::rmatrixinverse(
real_2d_array& a,
ae_int_t& info,
matinvreport& rep);
<b>void</b> alglib::rmatrixinverse(
real_2d_array& a,
ae_int_t n,
ae_int_t& info,
matinvreport& rep);
<b>void</b> alglib::smp_rmatrixinverse(
real_2d_array& a,
ae_int_t& info,
matinvreport& rep);
<b>void</b> alglib::smp_rmatrixinverse(
real_2d_array& a,
ae_int_t n,
ae_int_t& info,
matinvreport& rep);
</div></pre>
<p align=left class=pagecontent><span class=inlineheader>Examples:</span> <a href='#example_matinv_d_r1' class=nav>[1]</a> </p>
<a name='sub_rmatrixluinverse'></a><h3 class=pageheader><code>rmatrixluinverse</code> function</h3>
<pre class=source>
<div style='color: navy; margin-top: 0; margin-bottom: 0;'>/*************************************************************************
Inversion of a matrix given by its LU decomposition.
COMMERCIAL EDITION OF ALGLIB:
! Commercial version of ALGLIB includes two important improvements of
! this function, which can be used from C++ and C#:
! * Intel MKL support (lightweight Intel MKL is shipped with ALGLIB)
! * multicore support
!
! Intel MKL gives approximately constant (with respect to number of
! worker threads) acceleration factor which depends on CPU being used,
! problem size and "baseline" ALGLIB edition which is used for
! comparison.
!
! Say, on SSE2-capable CPU with N=1024, HPC ALGLIB will be:
! * about 2-3x faster than ALGLIB for C++ without MKL
! * about 7-10x faster than "pure C#" edition of ALGLIB
! Difference in performance will be more striking on newer CPU's with
! support for newer SIMD instructions. Generally, MKL accelerates any
! problem whose size is at least 128, with best efficiency achieved for
! N's larger than 512.
!
! Commercial edition of ALGLIB also supports multithreaded acceleration
! of this function. We should note that matrix inversion is harder to
! parallelize than, say, matrix-matrix product - this algorithm has
! many internal synchronization points which can not be avoided. However
! parallelism starts to be profitable starting from N=1024, achieving
! near-linear speedup for N=4096 or higher.
!
! In order to use multicore features you have to:
! * use commercial version of ALGLIB
! * call this function with "smp_" prefix, which indicates that
! multicore code will be used (for multicore support)
!
! We recommend you to read 'Working with commercial version' section of
! ALGLIB Reference Manual in order to find out how to use performance-
! related features provided by commercial edition of ALGLIB.
INPUT PARAMETERS:
A - LU decomposition of the matrix
(output of RMatrixLU subroutine).
Pivots - table of permutations
(the output of RMatrixLU subroutine).
N - size of matrix A (optional) :
* if given, only principal NxN submatrix is processed and
overwritten. other elements are unchanged.
* if not given, size is automatically determined from
matrix size (A must be square matrix)
OUTPUT PARAMETERS:
Info - return code:
* -3 A is singular, or VERY close to singular.
it is filled by zeros in such cases.
* 1 task is solved (but matrix A may be ill-conditioned,
check R1/RInf parameters for condition numbers).
Rep - solver report, see below for more info
A - inverse of matrix A.
Array whose indexes range within [0..N-1, 0..N-1].
SOLVER REPORT
Subroutine sets following fields of the Rep structure:
* R1 reciprocal of condition number: 1/cond(A), 1-norm.
* RInf reciprocal of condition number: 1/cond(A), inf-norm.
-- ALGLIB routine --
05.02.2010
Bochkanov Sergey
*************************************************************************/
</div><div style='margin-top: 0; margin-bottom: 0;'><b>void</b> alglib::rmatrixluinverse(
real_2d_array& a,
integer_1d_array pivots,
ae_int_t& info,
matinvreport& rep);
<b>void</b> alglib::rmatrixluinverse(
real_2d_array& a,
integer_1d_array pivots,
ae_int_t n,
ae_int_t& info,
matinvreport& rep);
<b>void</b> alglib::smp_rmatrixluinverse(
real_2d_array& a,
integer_1d_array pivots,
ae_int_t& info,
matinvreport& rep);
<b>void</b> alglib::smp_rmatrixluinverse(
real_2d_array& a,
integer_1d_array pivots,
ae_int_t n,
ae_int_t& info,
matinvreport& rep);
</div></pre>
<a name='sub_rmatrixtrinverse'></a><h3 class=pageheader><code>rmatrixtrinverse</code> function</h3>
<pre class=source>
<div style='color: navy; margin-top: 0; margin-bottom: 0;'>/*************************************************************************
Triangular matrix inverse (real)
The subroutine inverts the following types of matrices:
* upper triangular
* upper triangular with unit diagonal
* lower triangular
* lower triangular with unit diagonal
In case of an upper (lower) triangular matrix, the inverse matrix will
also be upper (lower) triangular, and after the end of the algorithm, the
inverse matrix replaces the source matrix. The elements below (above) the
main diagonal are not changed by the algorithm.
If the matrix has a unit diagonal, the inverse matrix also has a unit
diagonal, and the diagonal elements are not passed to the algorithm.
COMMERCIAL EDITION OF ALGLIB:
! Commercial version of ALGLIB includes two important improvements of
! this function, which can be used from C++ and C#:
! * Intel MKL support (lightweight Intel MKL is shipped with ALGLIB)
! * multicore support
!
! Intel MKL gives approximately constant (with respect to number of
! worker threads) acceleration factor which depends on CPU being used,
! problem size and "baseline" ALGLIB edition which is used for
! comparison.
!
! Say, on SSE2-capable CPU with N=1024, HPC ALGLIB will be:
! * about 2-3x faster than ALGLIB for C++ without MKL
! * about 7-10x faster than "pure C#" edition of ALGLIB
! Difference in performance will be more striking on newer CPU's with
! support for newer SIMD instructions. Generally, MKL accelerates any
! problem whose size is at least 128, with best efficiency achieved for
! N's larger than 512.
!
! Commercial edition of ALGLIB also supports multithreaded acceleration
! of this function. We should note that triangular inverse is harder to
! parallelize than, say, matrix-matrix product - this algorithm has
! many internal synchronization points which can not be avoided. However
! parallelism starts to be profitable starting from N=1024, achieving
! near-linear speedup for N=4096 or higher.
!
! In order to use multicore features you have to:
! * use commercial version of ALGLIB
! * call this function with "smp_" prefix, which indicates that
! multicore code will be used (for multicore support)
!
! We recommend you to read 'Working with commercial version' section of
! ALGLIB Reference Manual in order to find out how to use performance-
! related features provided by commercial edition of ALGLIB.
Input parameters:
A - matrix, array[0..N-1, 0..N-1].
N - size of matrix A (optional) :
* if given, only principal NxN submatrix is processed and
overwritten. other elements are unchanged.
* if not given, size is automatically determined from
matrix size (A must be square matrix)
IsUpper - True, if the matrix is upper triangular.
IsUnit - diagonal type (optional):
* if True, matrix has unit diagonal (a[i,i] are NOT used)
* if False, matrix diagonal is arbitrary
* if not given, False is assumed
Output parameters:
Info - same as for RMatrixLUInverse
Rep - same as for RMatrixLUInverse
A - same as for RMatrixLUInverse.
-- ALGLIB --
Copyright 05.02.2010 by Bochkanov Sergey
*************************************************************************/
</div><div style='margin-top: 0; margin-bottom: 0;'><b>void</b> alglib::rmatrixtrinverse(
real_2d_array& a,
<b>bool</b> isupper,
ae_int_t& info,
matinvreport& rep);
<b>void</b> alglib::rmatrixtrinverse(
real_2d_array& a,
ae_int_t n,
<b>bool</b> isupper,
<b>bool</b> isunit,
ae_int_t& info,
matinvreport& rep);
<b>void</b> alglib::smp_rmatrixtrinverse(
real_2d_array& a,
<b>bool</b> isupper,
ae_int_t& info,
matinvreport& rep);
<b>void</b> alglib::smp_rmatrixtrinverse(
real_2d_array& a,
ae_int_t n,
<b>bool</b> isupper,
<b>bool</b> isunit,
ae_int_t& info,
matinvreport& rep);
</div></pre>
<a name='sub_spdmatrixcholeskyinverse'></a><h3 class=pageheader><code>spdmatrixcholeskyinverse</code> function</h3>
<pre class=source>
<div style='color: navy; margin-top: 0; margin-bottom: 0;'>/*************************************************************************
Inversion of a symmetric positive definite matrix which is given
by Cholesky decomposition.
COMMERCIAL EDITION OF ALGLIB:
! Commercial version of ALGLIB includes two important improvements of
! this function, which can be used from C++ and C#:
! * Intel MKL support (lightweight Intel MKL is shipped with ALGLIB)
! * multicore support
!
! Intel MKL gives approximately constant (with respect to number of
! worker threads) acceleration factor which depends on CPU being used,
! problem size and "baseline" ALGLIB edition which is used for
! comparison.
!
! Say, on SSE2-capable CPU with N=1024, HPC ALGLIB will be:
! * about 2-3x faster than ALGLIB for C++ without MKL
! * about 7-10x faster than "pure C#" edition of ALGLIB
! Difference in performance will be more striking on newer CPU's with
! support for newer SIMD instructions. Generally, MKL accelerates any
! problem whose size is at least 128, with best efficiency achieved for
! N's larger than 512.
!
! Commercial edition of ALGLIB also supports multithreaded acceleration
! of this function. However, Cholesky inversion is a "difficult"
! algorithm - it has lots of internal synchronization points which
! prevents efficient parallelization of algorithm. Only very large
! problems (N=thousands) can be efficiently parallelized.
!
! We recommend you to read 'Working with commercial version' section of
! ALGLIB Reference Manual in order to find out how to use performance-
! related features provided by commercial edition of ALGLIB.
Input parameters:
A - Cholesky decomposition of the matrix to be inverted:
A=U�*U or A = L*L'.
Output of SPDMatrixCholesky subroutine.
N - size of matrix A (optional) :
* if given, only principal NxN submatrix is processed and
overwritten. other elements are unchanged.
* if not given, size is automatically determined from
matrix size (A must be square matrix)
IsUpper - storage type (optional):
* if True, symmetric matrix A is given by its upper
triangle, and the lower triangle isn�t used/changed by
function
* if False, symmetric matrix A is given by its lower
triangle, and the upper triangle isn�t used/changed by
function
* if not given, lower half is used.
Output parameters:
Info - return code, same as in RMatrixLUInverse
Rep - solver report, same as in RMatrixLUInverse
A - inverse of matrix A, same as in RMatrixLUInverse
-- ALGLIB routine --
10.02.2010
Bochkanov Sergey
*************************************************************************/
</div><div style='margin-top: 0; margin-bottom: 0;'><b>void</b> alglib::spdmatrixcholeskyinverse(
real_2d_array& a,
ae_int_t& info,
matinvreport& rep);
<b>void</b> alglib::spdmatrixcholeskyinverse(
real_2d_array& a,
ae_int_t n,
<b>bool</b> isupper,
ae_int_t& info,
matinvreport& rep);
<b>void</b> alglib::smp_spdmatrixcholeskyinverse(
real_2d_array& a,
ae_int_t& info,
matinvreport& rep);
<b>void</b> alglib::smp_spdmatrixcholeskyinverse(
real_2d_array& a,
ae_int_t n,
<b>bool</b> isupper,
ae_int_t& info,
matinvreport& rep);
</div></pre>
<a name='sub_spdmatrixinverse'></a><h3 class=pageheader><code>spdmatrixinverse</code> function</h3>
<pre class=source>
<div style='color: navy; margin-top: 0; margin-bottom: 0;'>/*************************************************************************
Inversion of a symmetric positive definite matrix.
Given an upper or lower triangle of a symmetric positive definite matrix,
the algorithm generates matrix A^-1 and saves the upper or lower triangle
depending on the input.
COMMERCIAL EDITION OF ALGLIB:
! Commercial version of ALGLIB includes two important improvements of
! this function, which can be used from C++ and C#:
! * Intel MKL support (lightweight Intel MKL is shipped with ALGLIB)
! * multicore support
!
! Intel MKL gives approximately constant (with respect to number of
! worker threads) acceleration factor which depends on CPU being used,
! problem size and "baseline" ALGLIB edition which is used for
! comparison.
!
! Say, on SSE2-capable CPU with N=1024, HPC ALGLIB will be:
! * about 2-3x faster than ALGLIB for C++ without MKL
! * about 7-10x faster than "pure C#" edition of ALGLIB
! Difference in performance will be more striking on newer CPU's with
! support for newer SIMD instructions. Generally, MKL accelerates any
! problem whose size is at least 128, with best efficiency achieved for
! N's larger than 512.
!
! Commercial edition of ALGLIB also supports multithreaded acceleration
! of this function. However, Cholesky inversion is a "difficult"
! algorithm - it has lots of internal synchronization points which
! prevents efficient parallelization of algorithm. Only very large
! problems (N=thousands) can be efficiently parallelized.
!
! We recommend you to read 'Working with commercial version' section of
! ALGLIB Reference Manual in order to find out how to use performance-
! related features provided by commercial edition of ALGLIB.
Input parameters:
A - matrix to be inverted (upper or lower triangle).
Array with elements [0..N-1,0..N-1].
N - size of matrix A (optional) :
* if given, only principal NxN submatrix is processed and
overwritten. other elements are unchanged.
* if not given, size is automatically determined from
matrix size (A must be square matrix)
IsUpper - storage type (optional):
* if True, symmetric matrix A is given by its upper
triangle, and the lower triangle isn�t used/changed by
function
* if False, symmetric matrix A is given by its lower
triangle, and the upper triangle isn�t used/changed by
function
* if not given, both lower and upper triangles must be
filled.
Output parameters:
Info - return code, same as in RMatrixLUInverse
Rep - solver report, same as in RMatrixLUInverse
A - inverse of matrix A, same as in RMatrixLUInverse
-- ALGLIB routine --
10.02.2010
Bochkanov Sergey
*************************************************************************/
</div><div style='margin-top: 0; margin-bottom: 0;'><b>void</b> alglib::spdmatrixinverse(
real_2d_array& a,
ae_int_t& info,
matinvreport& rep);
<b>void</b> alglib::spdmatrixinverse(
real_2d_array& a,
ae_int_t n,
<b>bool</b> isupper,
ae_int_t& info,
matinvreport& rep);
<b>void</b> alglib::smp_spdmatrixinverse(
real_2d_array& a,
ae_int_t& info,
matinvreport& rep);
<b>void</b> alglib::smp_spdmatrixinverse(
real_2d_array& a,
ae_int_t n,
<b>bool</b> isupper,
ae_int_t& info,
matinvreport& rep);
</div></pre>
<p align=left class=pagecontent><span class=inlineheader>Examples:</span> <a href='#example_matinv_d_spd1' class=nav>[1]</a> </p>
<a name='example_matinv_d_c1'></a><h3 class=pageheader>matinv_d_c1 example</h3>
<pre class=source>
#include <font color=blue><b>"stdafx.h"</b></font>
#include <stdlib.h>
#include <stdio.h>
#include <math.h>
#include <font color=blue><b>"linalg.h"</b></font>
using namespace alglib;
<b>int</b> main(<b>int</b> argc, char **argv)
{
complex_2d_array a = <font color=blue><b>"[[1i,-1],[1i,1]]"</b></font>;
ae_int_t info;
matinvreport rep;
cmatrixinverse(a, info, rep);
printf(<font color=blue><b>"%d\n"</b></font>, <b>int</b>(info)); <font color=navy>// EXPECTED: 1</font>
printf(<font color=blue><b>"%s\n"</b></font>, a.tostring(4).c_str()); <font color=navy>// EXPECTED: [[-0.5i,-0.5i],[-0.5,0.5]]</font>
printf(<font color=blue><b>"%.4f\n"</b></font>, <b>double</b>(rep.r1)); <font color=navy>// EXPECTED: 0.5</font>
printf(<font color=blue><b>"%.4f\n"</b></font>, <b>double</b>(rep.rinf)); <font color=navy>// EXPECTED: 0.5</font>
<b>return</b> 0;
}
</pre><a name='example_matinv_d_hpd1'></a><h3 class=pageheader>matinv_d_hpd1 example</h3>
<pre class=source>
#include <font color=blue><b>"stdafx.h"</b></font>
#include <stdlib.h>
#include <stdio.h>
#include <math.h>
#include <font color=blue><b>"linalg.h"</b></font>
using namespace alglib;
<b>int</b> main(<b>int</b> argc, char **argv)
{
complex_2d_array a = <font color=blue><b>"[[2,1],[1,2]]"</b></font>;
ae_int_t info;
matinvreport rep;
hpdmatrixinverse(a, info, rep);
printf(<font color=blue><b>"%d\n"</b></font>, <b>int</b>(info)); <font color=navy>// EXPECTED: 1</font>
printf(<font color=blue><b>"%s\n"</b></font>, a.tostring(4).c_str()); <font color=navy>// EXPECTED: [[0.666666,-0.333333],[-0.333333,0.666666]]</font>
<b>return</b> 0;
}
</pre><a name='example_matinv_d_r1'></a><h3 class=pageheader>matinv_d_r1 example</h3>
<pre class=source>
#include <font color=blue><b>"stdafx.h"</b></font>
#include <stdlib.h>
#include <stdio.h>
#include <math.h>
#include <font color=blue><b>"linalg.h"</b></font>
using namespace alglib;
<b>int</b> main(<b>int</b> argc, char **argv)
{
real_2d_array a = <font color=blue><b>"[[1,-1],[1,1]]"</b></font>;
ae_int_t info;
matinvreport rep;
rmatrixinverse(a, info, rep);
printf(<font color=blue><b>"%d\n"</b></font>, <b>int</b>(info)); <font color=navy>// EXPECTED: 1</font>
printf(<font color=blue><b>"%s\n"</b></font>, a.tostring(4).c_str()); <font color=navy>// EXPECTED: [[0.5,0.5],[-0.5,0.5]]</font>
printf(<font color=blue><b>"%.4f\n"</b></font>, <b>double</b>(rep.r1)); <font color=navy>// EXPECTED: 0.5</font>
printf(<font color=blue><b>"%.4f\n"</b></font>, <b>double</b>(rep.rinf)); <font color=navy>// EXPECTED: 0.5</font>
<b>return</b> 0;
}
</pre><a name='example_matinv_d_spd1'></a><h3 class=pageheader>matinv_d_spd1 example</h3>
<pre class=source>
#include <font color=blue><b>"stdafx.h"</b></font>
#include <stdlib.h>
#include <stdio.h>
#include <math.h>
#include <font color=blue><b>"linalg.h"</b></font>
using namespace alglib;
<b>int</b> main(<b>int</b> argc, char **argv)
{
real_2d_array a = <font color=blue><b>"[[2,1],[1,2]]"</b></font>;
ae_int_t info;
matinvreport rep;
spdmatrixinverse(a, info, rep);
printf(<font color=blue><b>"%d\n"</b></font>, <b>int</b>(info)); <font color=navy>// EXPECTED: 1</font>
printf(<font color=blue><b>"%s\n"</b></font>, a.tostring(4).c_str()); <font color=navy>// EXPECTED: [[0.666666,-0.333333],[-0.333333,0.666666]]</font>
<b>return</b> 0;
}
</pre><a name=unit_mcpd></a><h2 class=pageheader><code>mcpd</code> subpackage</h2>
<div class=pagecontent>
<h3 class=pageheader>Classes</h3>
<a href='#struct_mcpdreport' class=toc>mcpdreport</a><br>
<a href='#struct_mcpdstate' class=toc>mcpdstate</a><br>
<h3 class=pageheader>Functions</h3>
<a href='#sub_mcpdaddbc' class=toc>mcpdaddbc</a><br>
<a href='#sub_mcpdaddec' class=toc>mcpdaddec</a><br>
<a href='#sub_mcpdaddtrack' class=toc>mcpdaddtrack</a><br>
<a href='#sub_mcpdcreate' class=toc>mcpdcreate</a><br>
<a href='#sub_mcpdcreateentry' class=toc>mcpdcreateentry</a><br>
<a href='#sub_mcpdcreateentryexit' class=toc>mcpdcreateentryexit</a><br>
<a href='#sub_mcpdcreateexit' class=toc>mcpdcreateexit</a><br>
<a href='#sub_mcpdresults' class=toc>mcpdresults</a><br>
<a href='#sub_mcpdsetbc' class=toc>mcpdsetbc</a><br>
<a href='#sub_mcpdsetec' class=toc>mcpdsetec</a><br>
<a href='#sub_mcpdsetlc' class=toc>mcpdsetlc</a><br>
<a href='#sub_mcpdsetpredictionweights' class=toc>mcpdsetpredictionweights</a><br>
<a href='#sub_mcpdsetprior' class=toc>mcpdsetprior</a><br>
<a href='#sub_mcpdsettikhonovregularizer' class=toc>mcpdsettikhonovregularizer</a><br>
<a href='#sub_mcpdsolve' class=toc>mcpdsolve</a><br>
<h3 class=pageheader>Examples</h3>
<table border=0 cellspacing=0 class='pagecontent'>
<tr align=left valign=top><td><a href='#example_mcpd_simple1' class=toc>mcpd_simple1</a></td><td width=15> </td><td>Simple unconstrained MCPD model (no entry/exit states)</td></tr>
<tr align=left valign=top><td><a href='#example_mcpd_simple2' class=toc>mcpd_simple2</a></td><td width=15> </td><td>Simple MCPD model (no entry/exit states) with equality constraints</td></tr>
</table></div>
<a name='struct_mcpdreport'></a><h3 class=pageheader><code>mcpdreport</code> class</h3>
<pre class=source>
<div style='color: navy; margin-top: 0; margin-bottom: 0;'>/*************************************************************************
This structure is a MCPD training report:
InnerIterationsCount - number of inner iterations of the
underlying optimization algorithm
OuterIterationsCount - number of outer iterations of the
underlying optimization algorithm
NFEV - number of merit function evaluations
TerminationType - termination type
(same as for MinBLEIC optimizer, positive
values denote success, negative ones -
failure)
-- ALGLIB --
Copyright 23.05.2010 by Bochkanov Sergey
*************************************************************************/
</div><div style='margin-top: 0; margin-bottom: 0;'><b>class</b> mcpdreport
{
ae_int_t inneriterationscount;
ae_int_t outeriterationscount;
ae_int_t nfev;
ae_int_t terminationtype;
};
</div></pre>
<a name='struct_mcpdstate'></a><h3 class=pageheader><code>mcpdstate</code> class</h3>
<pre class=source>
<div style='color: navy; margin-top: 0; margin-bottom: 0;'>/*************************************************************************
This structure is a MCPD (Markov Chains for Population Data) solver.
You should use ALGLIB functions in order to work with this object.
-- ALGLIB --
Copyright 23.05.2010 by Bochkanov Sergey
*************************************************************************/
</div><div style='margin-top: 0; margin-bottom: 0;'><b>class</b> mcpdstate
{
};
</div></pre>
<a name='sub_mcpdaddbc'></a><h3 class=pageheader><code>mcpdaddbc</code> function</h3>
<pre class=source>
<div style='color: navy; margin-top: 0; margin-bottom: 0;'>/*************************************************************************
This function is used to add bound constraints on the elements of the
transition matrix P.
MCPD solver has four types of constraints which can be placed on P:
* user-specified equality constraints (optional)
* user-specified bound constraints (optional)
* user-specified general linear constraints (optional)
* basic constraints (always present):
* non-negativity: P[i,j]>=0
* consistency: every column of P sums to 1.0
Final constraints which are passed to the underlying optimizer are
calculated as intersection of all present constraints. For example, you
may specify boundary constraint on P[0,0] and equality one:
0.1<=P[0,0]<=0.9
P[0,0]=0.5
Such combination of constraints will be silently reduced to their
intersection, which is P[0,0]=0.5.
This function can be used to ADD bound constraint for one element of P
without changing constraints for other elements.
You can also use MCPDSetBC() function which allows to place bound
constraints on arbitrary subset of elements of P. Set of constraints is
specified by BndL/BndU matrices, which may contain arbitrary combination
of finite numbers or infinities (like -INF<x<=0.5 or 0.1<=x<+INF).
These functions (MCPDSetBC and MCPDAddBC) interact as follows:
* there is internal matrix of bound constraints which is stored in the
MCPD solver
* MCPDSetBC() replaces this matrix by another one (SET)
* MCPDAddBC() modifies one element of this matrix and leaves other ones
unchanged (ADD)
* thus MCPDAddBC() call preserves all modifications done by previous
calls, while MCPDSetBC() completely discards all changes done to the
equality constraints.
INPUT PARAMETERS:
S - solver
I - row index of element being constrained
J - column index of element being constrained
BndL - lower bound
BndU - upper bound
-- ALGLIB --
Copyright 23.05.2010 by Bochkanov Sergey
*************************************************************************/
</div><div style='margin-top: 0; margin-bottom: 0;'><b>void</b> alglib::mcpdaddbc(
mcpdstate s,
ae_int_t i,
ae_int_t j,
<b>double</b> bndl,
<b>double</b> bndu);
</div></pre>
<a name='sub_mcpdaddec'></a><h3 class=pageheader><code>mcpdaddec</code> function</h3>
<pre class=source>
<div style='color: navy; margin-top: 0; margin-bottom: 0;'>/*************************************************************************
This function is used to add equality constraints on the elements of the
transition matrix P.
MCPD solver has four types of constraints which can be placed on P:
* user-specified equality constraints (optional)
* user-specified bound constraints (optional)
* user-specified general linear constraints (optional)
* basic constraints (always present):
* non-negativity: P[i,j]>=0
* consistency: every column of P sums to 1.0
Final constraints which are passed to the underlying optimizer are
calculated as intersection of all present constraints. For example, you
may specify boundary constraint on P[0,0] and equality one:
0.1<=P[0,0]<=0.9
P[0,0]=0.5
Such combination of constraints will be silently reduced to their
intersection, which is P[0,0]=0.5.
This function can be used to ADD equality constraint for one element of P
without changing constraints for other elements.
You can also use MCPDSetEC() function which allows you to specify
arbitrary set of equality constraints in one call.
These functions (MCPDSetEC and MCPDAddEC) interact as follows:
* there is internal matrix of equality constraints which is stored in the
MCPD solver
* MCPDSetEC() replaces this matrix by another one (SET)
* MCPDAddEC() modifies one element of this matrix and leaves other ones
unchanged (ADD)
* thus MCPDAddEC() call preserves all modifications done by previous
calls, while MCPDSetEC() completely discards all changes done to the
equality constraints.
INPUT PARAMETERS:
S - solver
I - row index of element being constrained
J - column index of element being constrained
C - value (constraint for P[I,J]). Can be either NAN (no
constraint) or finite value from [0,1].
NOTES:
1. infinite values of C will lead to exception being thrown. Values less
than 0.0 or greater than 1.0 will lead to error code being returned after
call to MCPDSolve().
-- ALGLIB --
Copyright 23.05.2010 by Bochkanov Sergey
*************************************************************************/
</div><div style='margin-top: 0; margin-bottom: 0;'><b>void</b> alglib::mcpdaddec(mcpdstate s, ae_int_t i, ae_int_t j, <b>double</b> c);
</div></pre>
<p align=left class=pagecontent><span class=inlineheader>Examples:</span> <a href='#example_mcpd_simple2' class=nav>[1]</a> </p>
<a name='sub_mcpdaddtrack'></a><h3 class=pageheader><code>mcpdaddtrack</code> function</h3>
<pre class=source>
<div style='color: navy; margin-top: 0; margin-bottom: 0;'>/*************************************************************************
This function is used to add a track - sequence of system states at the
different moments of its evolution.
You may add one or several tracks to the MCPD solver. In case you have
several tracks, they won't overwrite each other. For example, if you pass
two tracks, A1-A2-A3 (system at t=A+1, t=A+2 and t=A+3) and B1-B2-B3, then
solver will try to model transitions from t=A+1 to t=A+2, t=A+2 to t=A+3,
t=B+1 to t=B+2, t=B+2 to t=B+3. But it WONT mix these two tracks - i.e. it
wont try to model transition from t=A+3 to t=B+1.
INPUT PARAMETERS:
S - solver
XY - track, array[K,N]:
* I-th row is a state at t=I
* elements of XY must be non-negative (exception will be
thrown on negative elements)
K - number of points in a track
* if given, only leading K rows of XY are used
* if not given, automatically determined from size of XY
NOTES:
1. Track may contain either proportional or population data:
* with proportional data all rows of XY must sum to 1.0, i.e. we have
proportions instead of absolute population values
* with population data rows of XY contain population counts and generally
do not sum to 1.0 (although they still must be non-negative)
-- ALGLIB --
Copyright 23.05.2010 by Bochkanov Sergey
*************************************************************************/
</div><div style='margin-top: 0; margin-bottom: 0;'><b>void</b> alglib::mcpdaddtrack(mcpdstate s, real_2d_array xy);
<b>void</b> alglib::mcpdaddtrack(mcpdstate s, real_2d_array xy, ae_int_t k);
</div></pre>
<p align=left class=pagecontent><span class=inlineheader>Examples:</span> <a href='#example_mcpd_simple1' class=nav>[1]</a> <a href='#example_mcpd_simple2' class=nav>[2]</a> </p>
<a name='sub_mcpdcreate'></a><h3 class=pageheader><code>mcpdcreate</code> function</h3>
<pre class=source>
<div style='color: navy; margin-top: 0; margin-bottom: 0;'>/*************************************************************************
DESCRIPTION:
This function creates MCPD (Markov Chains for Population Data) solver.
This solver can be used to find transition matrix P for N-dimensional
prediction problem where transition from X[i] to X[i+1] is modelled as
X[i+1] = P*X[i]
where X[i] and X[i+1] are N-dimensional population vectors (components of
each X are non-negative), and P is a N*N transition matrix (elements of P
are non-negative, each column sums to 1.0).
Such models arise when when:
* there is some population of individuals
* individuals can have different states
* individuals can transit from one state to another
* population size is constant, i.e. there is no new individuals and no one
leaves population
* you want to model transitions of individuals from one state into another
USAGE:
Here we give very brief outline of the MCPD. We strongly recommend you to
read examples in the ALGLIB Reference Manual and to read ALGLIB User Guide
on data analysis which is available at http://www.alglib.net/dataanalysis/
1. User initializes algorithm state with MCPDCreate() call
2. User adds one or more tracks - sequences of states which describe
evolution of a system being modelled from different starting conditions
3. User may add optional boundary, equality and/or linear constraints on
the coefficients of P by calling one of the following functions:
* MCPDSetEC() to set equality constraints
* MCPDSetBC() to set bound constraints
* MCPDSetLC() to set linear constraints
4. Optionally, user may set custom weights for prediction errors (by
default, algorithm assigns non-equal, automatically chosen weights for
errors in the prediction of different components of X). It can be done
with a call of MCPDSetPredictionWeights() function.
5. User calls MCPDSolve() function which takes algorithm state and
pointer (delegate, etc.) to callback function which calculates F/G.
6. User calls MCPDResults() to get solution
INPUT PARAMETERS:
N - problem dimension, N>=1
OUTPUT PARAMETERS:
State - structure stores algorithm state
-- ALGLIB --
Copyright 23.05.2010 by Bochkanov Sergey
*************************************************************************/
</div><div style='margin-top: 0; margin-bottom: 0;'><b>void</b> alglib::mcpdcreate(ae_int_t n, mcpdstate& s);
</div></pre>
<p align=left class=pagecontent><span class=inlineheader>Examples:</span> <a href='#example_mcpd_simple1' class=nav>[1]</a> <a href='#example_mcpd_simple2' class=nav>[2]</a> </p>
<a name='sub_mcpdcreateentry'></a><h3 class=pageheader><code>mcpdcreateentry</code> function</h3>
<pre class=source>
<div style='color: navy; margin-top: 0; margin-bottom: 0;'>/*************************************************************************
DESCRIPTION:
This function is a specialized version of MCPDCreate() function, and we
recommend you to read comments for this function for general information
about MCPD solver.
This function creates MCPD (Markov Chains for Population Data) solver
for "Entry-state" model, i.e. model where transition from X[i] to X[i+1]
is modelled as
X[i+1] = P*X[i]
where
X[i] and X[i+1] are N-dimensional state vectors
P is a N*N transition matrix
and one selected component of X[] is called "entry" state and is treated
in a special way:
system state always transits from "entry" state to some another state
system state can not transit from any state into "entry" state
Such conditions basically mean that row of P which corresponds to "entry"
state is zero.
Such models arise when:
* there is some population of individuals
* individuals can have different states
* individuals can transit from one state to another
* population size is NOT constant - at every moment of time there is some
(unpredictable) amount of "new" individuals, which can transit into one
of the states at the next turn, but still no one leaves population
* you want to model transitions of individuals from one state into another
* but you do NOT want to predict amount of "new" individuals because it
does not depends on individuals already present (hence system can not
transit INTO entry state - it can only transit FROM it).
This model is discussed in more details in the ALGLIB User Guide (see
http://www.alglib.net/dataanalysis/ for more data).
INPUT PARAMETERS:
N - problem dimension, N>=2
EntryState- index of entry state, in 0..N-1
OUTPUT PARAMETERS:
State - structure stores algorithm state
-- ALGLIB --
Copyright 23.05.2010 by Bochkanov Sergey
*************************************************************************/
</div><div style='margin-top: 0; margin-bottom: 0;'><b>void</b> alglib::mcpdcreateentry(
ae_int_t n,
ae_int_t entrystate,
mcpdstate& s);
</div></pre>
<a name='sub_mcpdcreateentryexit'></a><h3 class=pageheader><code>mcpdcreateentryexit</code> function</h3>
<pre class=source>
<div style='color: navy; margin-top: 0; margin-bottom: 0;'>/*************************************************************************
DESCRIPTION:
This function is a specialized version of MCPDCreate() function, and we
recommend you to read comments for this function for general information
about MCPD solver.
This function creates MCPD (Markov Chains for Population Data) solver
for "Entry-Exit-states" model, i.e. model where transition from X[i] to
X[i+1] is modelled as
X[i+1] = P*X[i]
where
X[i] and X[i+1] are N-dimensional state vectors
P is a N*N transition matrix
one selected component of X[] is called "entry" state and is treated in a
special way:
system state always transits from "entry" state to some another state
system state can not transit from any state into "entry" state
and another one component of X[] is called "exit" state and is treated in
a special way too:
system state can transit from any state into "exit" state
system state can not transit from "exit" state into any other state
transition operator discards "exit" state (makes it zero at each turn)
Such conditions basically mean that:
row of P which corresponds to "entry" state is zero
column of P which corresponds to "exit" state is zero
Multiplication by such P may decrease sum of vector components.
Such models arise when:
* there is some population of individuals
* individuals can have different states
* individuals can transit from one state to another
* population size is NOT constant
* at every moment of time there is some (unpredictable) amount of "new"
individuals, which can transit into one of the states at the next turn
* some individuals can move (predictably) into "exit" state and leave
population at the next turn
* you want to model transitions of individuals from one state into another,
including transitions from the "entry" state and into the "exit" state.
* but you do NOT want to predict amount of "new" individuals because it
does not depends on individuals already present (hence system can not
transit INTO entry state - it can only transit FROM it).
This model is discussed in more details in the ALGLIB User Guide (see
http://www.alglib.net/dataanalysis/ for more data).
INPUT PARAMETERS:
N - problem dimension, N>=2
EntryState- index of entry state, in 0..N-1
ExitState- index of exit state, in 0..N-1
OUTPUT PARAMETERS:
State - structure stores algorithm state
-- ALGLIB --
Copyright 23.05.2010 by Bochkanov Sergey
*************************************************************************/
</div><div style='margin-top: 0; margin-bottom: 0;'><b>void</b> alglib::mcpdcreateentryexit(
ae_int_t n,
ae_int_t entrystate,
ae_int_t exitstate,
mcpdstate& s);
</div></pre>
<a name='sub_mcpdcreateexit'></a><h3 class=pageheader><code>mcpdcreateexit</code> function</h3>
<pre class=source>
<div style='color: navy; margin-top: 0; margin-bottom: 0;'>/*************************************************************************
DESCRIPTION:
This function is a specialized version of MCPDCreate() function, and we
recommend you to read comments for this function for general information
about MCPD solver.
This function creates MCPD (Markov Chains for Population Data) solver
for "Exit-state" model, i.e. model where transition from X[i] to X[i+1]
is modelled as
X[i+1] = P*X[i]
where
X[i] and X[i+1] are N-dimensional state vectors
P is a N*N transition matrix
and one selected component of X[] is called "exit" state and is treated
in a special way:
system state can transit from any state into "exit" state
system state can not transit from "exit" state into any other state
transition operator discards "exit" state (makes it zero at each turn)
Such conditions basically mean that column of P which corresponds to
"exit" state is zero. Multiplication by such P may decrease sum of vector
components.
Such models arise when:
* there is some population of individuals
* individuals can have different states
* individuals can transit from one state to another
* population size is NOT constant - individuals can move into "exit" state
and leave population at the next turn, but there are no new individuals
* amount of individuals which leave population can be predicted
* you want to model transitions of individuals from one state into another
(including transitions into the "exit" state)
This model is discussed in more details in the ALGLIB User Guide (see
http://www.alglib.net/dataanalysis/ for more data).
INPUT PARAMETERS:
N - problem dimension, N>=2
ExitState- index of exit state, in 0..N-1
OUTPUT PARAMETERS:
State - structure stores algorithm state
-- ALGLIB --
Copyright 23.05.2010 by Bochkanov Sergey
*************************************************************************/
</div><div style='margin-top: 0; margin-bottom: 0;'><b>void</b> alglib::mcpdcreateexit(ae_int_t n, ae_int_t exitstate, mcpdstate& s);
</div></pre>
<a name='sub_mcpdresults'></a><h3 class=pageheader><code>mcpdresults</code> function</h3>
<pre class=source>
<div style='color: navy; margin-top: 0; margin-bottom: 0;'>/*************************************************************************
MCPD results
INPUT PARAMETERS:
State - algorithm state
OUTPUT PARAMETERS:
P - array[N,N], transition matrix
Rep - optimization report. You should check Rep.TerminationType
in order to distinguish successful termination from
unsuccessful one. Speaking short, positive values denote
success, negative ones are failures.
More information about fields of this structure can be
found in the comments on MCPDReport datatype.
-- ALGLIB --
Copyright 23.05.2010 by Bochkanov Sergey
*************************************************************************/
</div><div style='margin-top: 0; margin-bottom: 0;'><b>void</b> alglib::mcpdresults(mcpdstate s, real_2d_array& p, mcpdreport& rep);
</div></pre>
<p align=left class=pagecontent><span class=inlineheader>Examples:</span> <a href='#example_mcpd_simple1' class=nav>[1]</a> <a href='#example_mcpd_simple2' class=nav>[2]</a> </p>
<a name='sub_mcpdsetbc'></a><h3 class=pageheader><code>mcpdsetbc</code> function</h3>
<pre class=source>
<div style='color: navy; margin-top: 0; margin-bottom: 0;'>/*************************************************************************
This function is used to add bound constraints on the elements of the
transition matrix P.
MCPD solver has four types of constraints which can be placed on P:
* user-specified equality constraints (optional)
* user-specified bound constraints (optional)
* user-specified general linear constraints (optional)
* basic constraints (always present):
* non-negativity: P[i,j]>=0
* consistency: every column of P sums to 1.0
Final constraints which are passed to the underlying optimizer are
calculated as intersection of all present constraints. For example, you
may specify boundary constraint on P[0,0] and equality one:
0.1<=P[0,0]<=0.9
P[0,0]=0.5
Such combination of constraints will be silently reduced to their
intersection, which is P[0,0]=0.5.
This function can be used to place bound constraints on arbitrary
subset of elements of P. Set of constraints is specified by BndL/BndU
matrices, which may contain arbitrary combination of finite numbers or
infinities (like -INF<x<=0.5 or 0.1<=x<+INF).
You can also use MCPDAddBC() function which allows to ADD bound constraint
for one element of P without changing constraints for other elements.
These functions (MCPDSetBC and MCPDAddBC) interact as follows:
* there is internal matrix of bound constraints which is stored in the
MCPD solver
* MCPDSetBC() replaces this matrix by another one (SET)
* MCPDAddBC() modifies one element of this matrix and leaves other ones
unchanged (ADD)
* thus MCPDAddBC() call preserves all modifications done by previous
calls, while MCPDSetBC() completely discards all changes done to the
equality constraints.
INPUT PARAMETERS:
S - solver
BndL - lower bounds constraints, array[N,N]. Elements of BndL can
be finite numbers or -INF.
BndU - upper bounds constraints, array[N,N]. Elements of BndU can
be finite numbers or +INF.
-- ALGLIB --
Copyright 23.05.2010 by Bochkanov Sergey
*************************************************************************/
</div><div style='margin-top: 0; margin-bottom: 0;'><b>void</b> alglib::mcpdsetbc(
mcpdstate s,
real_2d_array bndl,
real_2d_array bndu);
</div></pre>
<a name='sub_mcpdsetec'></a><h3 class=pageheader><code>mcpdsetec</code> function</h3>
<pre class=source>
<div style='color: navy; margin-top: 0; margin-bottom: 0;'>/*************************************************************************
This function is used to add equality constraints on the elements of the
transition matrix P.
MCPD solver has four types of constraints which can be placed on P:
* user-specified equality constraints (optional)
* user-specified bound constraints (optional)
* user-specified general linear constraints (optional)
* basic constraints (always present):
* non-negativity: P[i,j]>=0
* consistency: every column of P sums to 1.0
Final constraints which are passed to the underlying optimizer are
calculated as intersection of all present constraints. For example, you
may specify boundary constraint on P[0,0] and equality one:
0.1<=P[0,0]<=0.9
P[0,0]=0.5
Such combination of constraints will be silently reduced to their
intersection, which is P[0,0]=0.5.
This function can be used to place equality constraints on arbitrary
subset of elements of P. Set of constraints is specified by EC, which may
contain either NAN's or finite numbers from [0,1]. NAN denotes absence of
constraint, finite number denotes equality constraint on specific element
of P.
You can also use MCPDAddEC() function which allows to ADD equality
constraint for one element of P without changing constraints for other
elements.
These functions (MCPDSetEC and MCPDAddEC) interact as follows:
* there is internal matrix of equality constraints which is stored in the
MCPD solver
* MCPDSetEC() replaces this matrix by another one (SET)
* MCPDAddEC() modifies one element of this matrix and leaves other ones
unchanged (ADD)
* thus MCPDAddEC() call preserves all modifications done by previous
calls, while MCPDSetEC() completely discards all changes done to the
equality constraints.
INPUT PARAMETERS:
S - solver
EC - equality constraints, array[N,N]. Elements of EC can be
either NAN's or finite numbers from [0,1]. NAN denotes
absence of constraints, while finite value denotes
equality constraint on the corresponding element of P.
NOTES:
1. infinite values of EC will lead to exception being thrown. Values less
than 0.0 or greater than 1.0 will lead to error code being returned after
call to MCPDSolve().
-- ALGLIB --
Copyright 23.05.2010 by Bochkanov Sergey
*************************************************************************/
</div><div style='margin-top: 0; margin-bottom: 0;'><b>void</b> alglib::mcpdsetec(mcpdstate s, real_2d_array ec);
</div></pre>
<a name='sub_mcpdsetlc'></a><h3 class=pageheader><code>mcpdsetlc</code> function</h3>
<pre class=source>
<div style='color: navy; margin-top: 0; margin-bottom: 0;'>/*************************************************************************
This function is used to set linear equality/inequality constraints on the
elements of the transition matrix P.
This function can be used to set one or several general linear constraints
on the elements of P. Two types of constraints are supported:
* equality constraints
* inequality constraints (both less-or-equal and greater-or-equal)
Coefficients of constraints are specified by matrix C (one of the
parameters). One row of C corresponds to one constraint. Because
transition matrix P has N*N elements, we need N*N columns to store all
coefficients (they are stored row by row), and one more column to store
right part - hence C has N*N+1 columns. Constraint kind is stored in the
CT array.
Thus, I-th linear constraint is
P[0,0]*C[I,0] + P[0,1]*C[I,1] + .. + P[0,N-1]*C[I,N-1] +
+ P[1,0]*C[I,N] + P[1,1]*C[I,N+1] + ... +
+ P[N-1,N-1]*C[I,N*N-1] ?=? C[I,N*N]
where ?=? can be either "=" (CT[i]=0), "<=" (CT[i]<0) or ">=" (CT[i]>0).
Your constraint may involve only some subset of P (less than N*N elements).
For example it can be something like
P[0,0] + P[0,1] = 0.5
In this case you still should pass matrix with N*N+1 columns, but all its
elements (except for C[0,0], C[0,1] and C[0,N*N-1]) will be zero.
INPUT PARAMETERS:
S - solver
C - array[K,N*N+1] - coefficients of constraints
(see above for complete description)
CT - array[K] - constraint types
(see above for complete description)
K - number of equality/inequality constraints, K>=0:
* if given, only leading K elements of C/CT are used
* if not given, automatically determined from sizes of C/CT
-- ALGLIB --
Copyright 23.05.2010 by Bochkanov Sergey
*************************************************************************/
</div><div style='margin-top: 0; margin-bottom: 0;'><b>void</b> alglib::mcpdsetlc(mcpdstate s, real_2d_array c, integer_1d_array ct);
<b>void</b> alglib::mcpdsetlc(
mcpdstate s,
real_2d_array c,
integer_1d_array ct,
ae_int_t k);
</div></pre>
<a name='sub_mcpdsetpredictionweights'></a><h3 class=pageheader><code>mcpdsetpredictionweights</code> function</h3>
<pre class=source>
<div style='color: navy; margin-top: 0; margin-bottom: 0;'>/*************************************************************************
This function is used to change prediction weights
MCPD solver scales prediction errors as follows
Error(P) = ||W*(y-P*x)||^2
where
x is a system state at time t
y is a system state at time t+1
P is a transition matrix
W is a diagonal scaling matrix
By default, weights are chosen in order to minimize relative prediction
error instead of absolute one. For example, if one component of state is
about 0.5 in magnitude and another one is about 0.05, then algorithm will
make corresponding weights equal to 2.0 and 20.0.
INPUT PARAMETERS:
S - solver
PW - array[N], weights:
* must be non-negative values (exception will be thrown otherwise)
* zero values will be replaced by automatically chosen values
-- ALGLIB --
Copyright 23.05.2010 by Bochkanov Sergey
*************************************************************************/
</div><div style='margin-top: 0; margin-bottom: 0;'><b>void</b> alglib::mcpdsetpredictionweights(mcpdstate s, real_1d_array pw);
</div></pre>
<a name='sub_mcpdsetprior'></a><h3 class=pageheader><code>mcpdsetprior</code> function</h3>
<pre class=source>
<div style='color: navy; margin-top: 0; margin-bottom: 0;'>/*************************************************************************
This function allows to set prior values used for regularization of your
problem.
By default, regularizing term is equal to r*||P-prior_P||^2, where r is a
small non-zero value, P is transition matrix, prior_P is identity matrix,
||X||^2 is a sum of squared elements of X.
This function allows you to change prior values prior_P. You can also
change r with MCPDSetTikhonovRegularizer() function.
INPUT PARAMETERS:
S - solver
PP - array[N,N], matrix of prior values:
1. elements must be real numbers from [0,1]
2. columns must sum to 1.0.
First property is checked (exception is thrown otherwise),
while second one is not checked/enforced.
-- ALGLIB --
Copyright 23.05.2010 by Bochkanov Sergey
*************************************************************************/
</div><div style='margin-top: 0; margin-bottom: 0;'><b>void</b> alglib::mcpdsetprior(mcpdstate s, real_2d_array pp);
</div></pre>
<a name='sub_mcpdsettikhonovregularizer'></a><h3 class=pageheader><code>mcpdsettikhonovregularizer</code> function</h3>
<pre class=source>
<div style='color: navy; margin-top: 0; margin-bottom: 0;'>/*************************************************************************
This function allows to tune amount of Tikhonov regularization being
applied to your problem.
By default, regularizing term is equal to r*||P-prior_P||^2, where r is a
small non-zero value, P is transition matrix, prior_P is identity matrix,
||X||^2 is a sum of squared elements of X.
This function allows you to change coefficient r. You can also change
prior values with MCPDSetPrior() function.
INPUT PARAMETERS:
S - solver
V - regularization coefficient, finite non-negative value. It
is not recommended to specify zero value unless you are
pretty sure that you want it.
-- ALGLIB --
Copyright 23.05.2010 by Bochkanov Sergey
*************************************************************************/
</div><div style='margin-top: 0; margin-bottom: 0;'><b>void</b> alglib::mcpdsettikhonovregularizer(mcpdstate s, <b>double</b> v);
</div></pre>
<a name='sub_mcpdsolve'></a><h3 class=pageheader><code>mcpdsolve</code> function</h3>
<pre class=source>
<div style='color: navy; margin-top: 0; margin-bottom: 0;'>/*************************************************************************
This function is used to start solution of the MCPD problem.
After return from this function, you can use MCPDResults() to get solution
and completion code.
-- ALGLIB --
Copyright 23.05.2010 by Bochkanov Sergey
*************************************************************************/
</div><div style='margin-top: 0; margin-bottom: 0;'><b>void</b> alglib::mcpdsolve(mcpdstate s);
</div></pre>
<p align=left class=pagecontent><span class=inlineheader>Examples:</span> <a href='#example_mcpd_simple1' class=nav>[1]</a> <a href='#example_mcpd_simple2' class=nav>[2]</a> </p>
<a name='example_mcpd_simple1'></a><h3 class=pageheader>mcpd_simple1 example</h3>
<pre class=source>
#include <font color=blue><b>"stdafx.h"</b></font>
#include <stdlib.h>
#include <stdio.h>
#include <math.h>
#include <font color=blue><b>"dataanalysis.h"</b></font>
using namespace alglib;
<b>int</b> main(<b>int</b> argc, char **argv)
{
<font color=navy>//</font>
<font color=navy>// The very simple MCPD example</font>
<font color=navy>//</font>
<font color=navy>// We have a loan portfolio. Our loans can be in one of two states:</font>
<font color=navy>// * normal loans (<font color=blue><b>"good"</b></font> ones)</font>
<font color=navy>// * past due loans (<font color=blue><b>"bad"</b></font> ones)</font>
<font color=navy>//</font>
<font color=navy>// We assume that:</font>
<font color=navy>// * loans can transition from any state to any other state. In </font>
<font color=navy>// particular, past due loan can become <font color=blue><b>"good"</b></font> one at any moment </font>
<font color=navy>// with same (fixed) probability. Not realistic, but it is toy example :)</font>
<font color=navy>// * portfolio size does not change over time</font>
<font color=navy>//</font>
<font color=navy>// Thus, we have following model</font>
<font color=navy>// state_new = P*state_old</font>
<font color=navy>// where</font>
<font color=navy>// ( p00 p01 )</font>
<font color=navy>// P = ( )</font>
<font color=navy>// ( p10 p11 )</font>
<font color=navy>//</font>
<font color=navy>// We want to model transitions between these two states using MCPD</font>
<font color=navy>// approach (Markov Chains <b>for</b> Proportional/Population Data), i.e.</font>
<font color=navy>// to restore hidden transition matrix P using actual portfolio data.</font>
<font color=navy>// We have:</font>
<font color=navy>// * poportional data, i.e. proportion of loans in the normal and past </font>
<font color=navy>// due states (not portfolio size measured in some currency, although </font>
<font color=navy>// it is possible to work with population data too)</font>
<font color=navy>// * two tracks, i.e. two sequences which describe portfolio</font>
<font color=navy>// evolution from two different starting states: [1,0] (all loans </font>
<font color=navy>// are <font color=blue><b>"good"</b></font>) and [0.8,0.2] (only 80% of portfolio is in the <font color=blue><b>"good"</b></font></font>
<font color=navy>// state)</font>
<font color=navy>//</font>
mcpdstate s;
mcpdreport rep;
real_2d_array p;
real_2d_array track0 = <font color=blue><b>"[[1.00000,0.00000],[0.95000,0.05000],[0.92750,0.07250],[0.91738,0.08263],[0.91282,0.08718]]"</b></font>;
real_2d_array track1 = <font color=blue><b>"[[0.80000,0.20000],[0.86000,0.14000],[0.88700,0.11300],[0.89915,0.10085]]"</b></font>;
mcpdcreate(2, s);
mcpdaddtrack(s, track0);
mcpdaddtrack(s, track1);
mcpdsolve(s);
mcpdresults(s, p, rep);
<font color=navy>//</font>
<font color=navy>// Hidden matrix P is equal to</font>
<font color=navy>// ( 0.95 0.50 )</font>
<font color=navy>// ( )</font>
<font color=navy>// ( 0.05 0.50 )</font>
<font color=navy>// which means that <font color=blue><b>"good"</b></font> loans can become <font color=blue><b>"bad"</b></font> with 5% probability, </font>
<font color=navy>// <b>while</b> <font color=blue><b>"bad"</b></font> loans will <b>return</b> to good state with 50% probability.</font>
<font color=navy>//</font>
printf(<font color=blue><b>"%s\n"</b></font>, p.tostring(2).c_str()); <font color=navy>// EXPECTED: [[0.95,0.50],[0.05,0.50]]</font>
<b>return</b> 0;
}
</pre><a name='example_mcpd_simple2'></a><h3 class=pageheader>mcpd_simple2 example</h3>
<pre class=source>
#include <font color=blue><b>"stdafx.h"</b></font>
#include <stdlib.h>
#include <stdio.h>
#include <math.h>
#include <font color=blue><b>"dataanalysis.h"</b></font>
using namespace alglib;
<b>int</b> main(<b>int</b> argc, char **argv)
{
<font color=navy>//</font>
<font color=navy>// Simple MCPD example</font>
<font color=navy>//</font>
<font color=navy>// We have a loan portfolio. Our loans can be in one of three states:</font>
<font color=navy>// * normal loans</font>
<font color=navy>// * past due loans</font>
<font color=navy>// * charged off loans</font>
<font color=navy>//</font>
<font color=navy>// We assume that:</font>
<font color=navy>// * normal loan can stay normal or become past due (but not charged off)</font>
<font color=navy>// * past due loan can stay past due, become normal or charged off</font>
<font color=navy>// * charged off loan will stay charged off <b>for</b> the rest of eternity</font>
<font color=navy>// * portfolio size does not change over time</font>
<font color=navy>// Not realistic, but it is toy example :)</font>
<font color=navy>//</font>
<font color=navy>// Thus, we have following model</font>
<font color=navy>// state_new = P*state_old</font>
<font color=navy>// where</font>
<font color=navy>// ( p00 p01 )</font>
<font color=navy>// P = ( p10 p11 )</font>
<font color=navy>// ( p21 1 )</font>
<font color=navy>// i.e. four elements of P are known a priori.</font>
<font color=navy>//</font>
<font color=navy>// Although it is possible (given enough data) to In order to enforce </font>
<font color=navy>// this property we set equality constraints on these elements.</font>
<font color=navy>//</font>
<font color=navy>// We want to model transitions between these two states using MCPD</font>
<font color=navy>// approach (Markov Chains <b>for</b> Proportional/Population Data), i.e.</font>
<font color=navy>// to restore hidden transition matrix P using actual portfolio data.</font>
<font color=navy>// We have:</font>
<font color=navy>// * poportional data, i.e. proportion of loans in the current and past </font>
<font color=navy>// due states (not portfolio size measured in some currency, although </font>
<font color=navy>// it is possible to work with population data too)</font>
<font color=navy>// * two tracks, i.e. two sequences which describe portfolio</font>
<font color=navy>// evolution from two different starting states: [1,0,0] (all loans </font>
<font color=navy>// are <font color=blue><b>"good"</b></font>) and [0.8,0.2,0.0] (only 80% of portfolio is in the <font color=blue><b>"good"</b></font></font>
<font color=navy>// state)</font>
<font color=navy>//</font>
mcpdstate s;
mcpdreport rep;
real_2d_array p;
real_2d_array track0 = <font color=blue><b>"[[1.000000,0.000000,0.000000],[0.950000,0.050000,0.000000],[0.927500,0.060000,0.012500],[0.911125,0.061375,0.027500],[0.896256,0.060900,0.042844]]"</b></font>;
real_2d_array track1 = <font color=blue><b>"[[0.800000,0.200000,0.000000],[0.860000,0.090000,0.050000],[0.862000,0.065500,0.072500],[0.851650,0.059475,0.088875],[0.838805,0.057451,0.103744]]"</b></font>;
mcpdcreate(3, s);
mcpdaddtrack(s, track0);
mcpdaddtrack(s, track1);
mcpdaddec(s, 0, 2, 0.0);
mcpdaddec(s, 1, 2, 0.0);
mcpdaddec(s, 2, 2, 1.0);
mcpdaddec(s, 2, 0, 0.0);
mcpdsolve(s);
mcpdresults(s, p, rep);
<font color=navy>//</font>
<font color=navy>// Hidden matrix P is equal to</font>
<font color=navy>// ( 0.95 0.50 )</font>
<font color=navy>// ( 0.05 0.25 )</font>
<font color=navy>// ( 0.25 1.00 ) </font>
<font color=navy>// which means that <font color=blue><b>"good"</b></font> loans can become past due with 5% probability, </font>
<font color=navy>// <b>while</b> past due loans will become charged off with 25% probability or</font>
<font color=navy>// <b>return</b> back to normal state with 50% probability.</font>
<font color=navy>//</font>
printf(<font color=blue><b>"%s\n"</b></font>, p.tostring(2).c_str()); <font color=navy>// EXPECTED: [[0.95,0.50,0.00],[0.05,0.25,0.00],[0.00,0.25,1.00]]</font>
<b>return</b> 0;
}
</pre><a name=unit_minbleic></a><h2 class=pageheader><code>minbleic</code> subpackage</h2>
<div class=pagecontent>
<h3 class=pageheader>Classes</h3>
<a href='#struct_minbleicreport' class=toc>minbleicreport</a><br>
<a href='#struct_minbleicstate' class=toc>minbleicstate</a><br>
<h3 class=pageheader>Functions</h3>
<a href='#sub_minbleiccreate' class=toc>minbleiccreate</a><br>
<a href='#sub_minbleiccreatef' class=toc>minbleiccreatef</a><br>
<a href='#sub_minbleicoptimize' class=toc>minbleicoptimize</a><br>
<a href='#sub_minbleicrequesttermination' class=toc>minbleicrequesttermination</a><br>
<a href='#sub_minbleicrestartfrom' class=toc>minbleicrestartfrom</a><br>
<a href='#sub_minbleicresults' class=toc>minbleicresults</a><br>
<a href='#sub_minbleicresultsbuf' class=toc>minbleicresultsbuf</a><br>
<a href='#sub_minbleicsetbc' class=toc>minbleicsetbc</a><br>
<a href='#sub_minbleicsetcond' class=toc>minbleicsetcond</a><br>
<a href='#sub_minbleicsetgradientcheck' class=toc>minbleicsetgradientcheck</a><br>
<a href='#sub_minbleicsetlc' class=toc>minbleicsetlc</a><br>
<a href='#sub_minbleicsetprecdefault' class=toc>minbleicsetprecdefault</a><br>
<a href='#sub_minbleicsetprecdiag' class=toc>minbleicsetprecdiag</a><br>
<a href='#sub_minbleicsetprecscale' class=toc>minbleicsetprecscale</a><br>
<a href='#sub_minbleicsetscale' class=toc>minbleicsetscale</a><br>
<a href='#sub_minbleicsetstpmax' class=toc>minbleicsetstpmax</a><br>
<a href='#sub_minbleicsetxrep' class=toc>minbleicsetxrep</a><br>
<h3 class=pageheader>Examples</h3>
<table border=0 cellspacing=0 class='pagecontent'>
<tr align=left valign=top><td><a href='#example_minbleic_d_1' class=toc>minbleic_d_1</a></td><td width=15> </td><td>Nonlinear optimization with bound constraints</td></tr>
<tr align=left valign=top><td><a href='#example_minbleic_d_2' class=toc>minbleic_d_2</a></td><td width=15> </td><td>Nonlinear optimization with linear inequality constraints</td></tr>
<tr align=left valign=top><td><a href='#example_minbleic_ftrim' class=toc>minbleic_ftrim</a></td><td width=15> </td><td>Nonlinear optimization by BLEIC, function with singularities</td></tr>
<tr align=left valign=top><td><a href='#example_minbleic_numdiff' class=toc>minbleic_numdiff</a></td><td width=15> </td><td>Nonlinear optimization with bound constraints and numerical differentiation</td></tr>
</table></div>
<a name='struct_minbleicreport'></a><h3 class=pageheader><code>minbleicreport</code> class</h3>
<pre class=source>
<div style='color: navy; margin-top: 0; margin-bottom: 0;'>/*************************************************************************
This structure stores optimization report:
* IterationsCount number of iterations
* NFEV number of gradient evaluations
* TerminationType termination type (see below)
TERMINATION CODES
TerminationType field contains completion code, which can be:
-8 internal integrity control detected infinite or NAN values in
function/gradient. Abnormal termination signalled.
-7 gradient verification failed.
See MinBLEICSetGradientCheck() for more information.
-3 inconsistent constraints. Feasible point is
either nonexistent or too hard to find. Try to
restart optimizer with better initial approximation
1 relative function improvement is no more than EpsF.
2 relative step is no more than EpsX.
4 gradient norm is no more than EpsG
5 MaxIts steps was taken
7 stopping conditions are too stringent,
further improvement is impossible,
X contains best point found so far.
8 terminated by user who called minbleicrequesttermination(). X contains
point which was "current accepted" when termination request was
submitted.
ADDITIONAL FIELDS
There are additional fields which can be used for debugging:
* DebugEqErr error in the equality constraints (2-norm)
* DebugFS f, calculated at projection of initial point
to the feasible set
* DebugFF f, calculated at the final point
* DebugDX |X_start-X_final|
*************************************************************************/
</div><div style='margin-top: 0; margin-bottom: 0;'><b>class</b> minbleicreport
{
ae_int_t iterationscount;
ae_int_t nfev;
ae_int_t varidx;
ae_int_t terminationtype;
<b>double</b> debugeqerr;
<b>double</b> debugfs;
<b>double</b> debugff;
<b>double</b> debugdx;
ae_int_t debugfeasqpits;
ae_int_t debugfeasgpaits;
ae_int_t inneriterationscount;
ae_int_t outeriterationscount;
};
</div></pre>
<a name='struct_minbleicstate'></a><h3 class=pageheader><code>minbleicstate</code> class</h3>
<pre class=source>
<div style='color: navy; margin-top: 0; margin-bottom: 0;'>/*************************************************************************
This object stores nonlinear optimizer state.
You should use functions provided by MinBLEIC subpackage to work with this
object
*************************************************************************/
</div><div style='margin-top: 0; margin-bottom: 0;'><b>class</b> minbleicstate
{
};
</div></pre>
<a name='sub_minbleiccreate'></a><h3 class=pageheader><code>minbleiccreate</code> function</h3>
<pre class=source>
<div style='color: navy; margin-top: 0; margin-bottom: 0;'>/*************************************************************************
BOUND CONSTRAINED OPTIMIZATION
WITH ADDITIONAL LINEAR EQUALITY AND INEQUALITY CONSTRAINTS
DESCRIPTION:
The subroutine minimizes function F(x) of N arguments subject to any
combination of:
* bound constraints
* linear inequality constraints
* linear equality constraints
REQUIREMENTS:
* user must provide function value and gradient
* starting point X0 must be feasible or
not too far away from the feasible set
* grad(f) must be Lipschitz continuous on a level set:
L = { x : f(x)<=f(x0) }
* function must be defined everywhere on the feasible set F
USAGE:
Constrained optimization if far more complex than the unconstrained one.
Here we give very brief outline of the BLEIC optimizer. We strongly recommend
you to read examples in the ALGLIB Reference Manual and to read ALGLIB User Guide
on optimization, which is available at http://www.alglib.net/optimization/
1. User initializes algorithm state with MinBLEICCreate() call
2. USer adds boundary and/or linear constraints by calling
MinBLEICSetBC() and MinBLEICSetLC() functions.
3. User sets stopping conditions with MinBLEICSetCond().
4. User calls MinBLEICOptimize() function which takes algorithm state and
pointer (delegate, etc.) to callback function which calculates F/G.
5. User calls MinBLEICResults() to get solution
6. Optionally user may call MinBLEICRestartFrom() to solve another problem
with same N but another starting point.
MinBLEICRestartFrom() allows to reuse already initialized structure.
INPUT PARAMETERS:
N - problem dimension, N>0:
* if given, only leading N elements of X are used
* if not given, automatically determined from size ofX
X - starting point, array[N]:
* it is better to set X to a feasible point
* but X can be infeasible, in which case algorithm will try
to find feasible point first, using X as initial
approximation.
OUTPUT PARAMETERS:
State - structure stores algorithm state
-- ALGLIB --
Copyright 28.11.2010 by Bochkanov Sergey
*************************************************************************/
</div><div style='margin-top: 0; margin-bottom: 0;'><b>void</b> alglib::minbleiccreate(real_1d_array x, minbleicstate& state);
<b>void</b> alglib::minbleiccreate(
ae_int_t n,
real_1d_array x,
minbleicstate& state);
</div></pre>
<p align=left class=pagecontent><span class=inlineheader>Examples:</span> <a href='#example_minbleic_d_1' class=nav>[1]</a> <a href='#example_minbleic_d_2' class=nav>[2]</a> <a href='#example_minbleic_ftrim' class=nav>[3]</a> </p>
<a name='sub_minbleiccreatef'></a><h3 class=pageheader><code>minbleiccreatef</code> function</h3>
<pre class=source>
<div style='color: navy; margin-top: 0; margin-bottom: 0;'>/*************************************************************************
The subroutine is finite difference variant of MinBLEICCreate(). It uses
finite differences in order to differentiate target function.
Description below contains information which is specific to this function
only. We recommend to read comments on MinBLEICCreate() in order to get
more information about creation of BLEIC optimizer.
INPUT PARAMETERS:
N - problem dimension, N>0:
* if given, only leading N elements of X are used
* if not given, automatically determined from size of X
X - starting point, array[0..N-1].
DiffStep- differentiation step, >0
OUTPUT PARAMETERS:
State - structure which stores algorithm state
NOTES:
1. algorithm uses 4-point central formula for differentiation.
2. differentiation step along I-th axis is equal to DiffStep*S[I] where
S[] is scaling vector which can be set by MinBLEICSetScale() call.
3. we recommend you to use moderate values of differentiation step. Too
large step will result in too large truncation errors, while too small
step will result in too large numerical errors. 1.0E-6 can be good
value to start with.
4. Numerical differentiation is very inefficient - one gradient
calculation needs 4*N function evaluations. This function will work for
any N - either small (1...10), moderate (10...100) or large (100...).
However, performance penalty will be too severe for any N's except for
small ones.
We should also say that code which relies on numerical differentiation
is less robust and precise. CG needs exact gradient values. Imprecise
gradient may slow down convergence, especially on highly nonlinear
problems.
Thus we recommend to use this function for fast prototyping on small-
dimensional problems only, and to implement analytical gradient as soon
as possible.
-- ALGLIB --
Copyright 16.05.2011 by Bochkanov Sergey
*************************************************************************/
</div><div style='margin-top: 0; margin-bottom: 0;'><b>void</b> alglib::minbleiccreatef(
real_1d_array x,
<b>double</b> diffstep,
minbleicstate& state);
<b>void</b> alglib::minbleiccreatef(
ae_int_t n,
real_1d_array x,
<b>double</b> diffstep,
minbleicstate& state);
</div></pre>
<p align=left class=pagecontent><span class=inlineheader>Examples:</span> <a href='#example_minbleic_numdiff' class=nav>[1]</a> </p>
<a name='sub_minbleicoptimize'></a><h3 class=pageheader><code>minbleicoptimize</code> function</h3>
<pre class=source>
<div style='color: navy; margin-top: 0; margin-bottom: 0;'>/*************************************************************************
This family of functions is used to launcn iterations of nonlinear optimizer
These functions accept following parameters:
state - algorithm state
func - callback which calculates function (or merit function)
value func at given point x
grad - callback which calculates function (or merit function)
value func and gradient grad at given point x
rep - optional callback which is called after each iteration
can be NULL
ptr - optional pointer which is passed to func/grad/hess/jac/rep
can be NULL
NOTES:
1. This function has two different implementations: one which uses exact
(analytical) user-supplied gradient, and one which uses function value
only and numerically differentiates function in order to obtain
gradient.
Depending on the specific function used to create optimizer object
(either MinBLEICCreate() for analytical gradient or MinBLEICCreateF()
for numerical differentiation) you should choose appropriate variant of
MinBLEICOptimize() - one which accepts function AND gradient or one
which accepts function ONLY.
Be careful to choose variant of MinBLEICOptimize() which corresponds to
your optimization scheme! Table below lists different combinations of
callback (function/gradient) passed to MinBLEICOptimize() and specific
function used to create optimizer.
| USER PASSED TO MinBLEICOptimize()
CREATED WITH | function only | function and gradient
------------------------------------------------------------
MinBLEICCreateF() | work FAIL
MinBLEICCreate() | FAIL work
Here "FAIL" denotes inappropriate combinations of optimizer creation
function and MinBLEICOptimize() version. Attemps to use such
combination (for example, to create optimizer with MinBLEICCreateF()
and to pass gradient information to MinCGOptimize()) will lead to
exception being thrown. Either you did not pass gradient when it WAS
needed or you passed gradient when it was NOT needed.
-- ALGLIB --
Copyright 28.11.2010 by Bochkanov Sergey
*************************************************************************/
</div><div style='margin-top: 0; margin-bottom: 0;'><b>void</b> minbleicoptimize(minbleicstate &state,
<b>void</b> (*func)(<b>const</b> real_1d_array &x, <b>double</b> &func, <b>void</b> *ptr),
<b>void</b> (*rep)(<b>const</b> real_1d_array &x, <b>double</b> func, <b>void</b> *ptr) = NULL,
<b>void</b> *ptr = NULL);
<b>void</b> minbleicoptimize(minbleicstate &state,
<b>void</b> (*grad)(<b>const</b> real_1d_array &x, <b>double</b> &func, real_1d_array &grad, <b>void</b> *ptr),
<b>void</b> (*rep)(<b>const</b> real_1d_array &x, <b>double</b> func, <b>void</b> *ptr) = NULL,
<b>void</b> *ptr = NULL);
</div></pre>
<p align=left class=pagecontent><span class=inlineheader>Examples:</span> <a href='#example_minbleic_d_1' class=nav>[1]</a> <a href='#example_minbleic_d_2' class=nav>[2]</a> <a href='#example_minbleic_numdiff' class=nav>[3]</a> <a href='#example_minbleic_ftrim' class=nav>[4]</a> </p>
<a name='sub_minbleicrequesttermination'></a><h3 class=pageheader><code>minbleicrequesttermination</code> function</h3>
<pre class=source>
<div style='color: navy; margin-top: 0; margin-bottom: 0;'>/*************************************************************************
This subroutine submits request for termination of running optimizer. It
should be called from user-supplied callback when user decides that it is
time to "smoothly" terminate optimization process. As result, optimizer
stops at point which was "current accepted" when termination request was
submitted and returns error code 8 (successful termination).
INPUT PARAMETERS:
State - optimizer structure
NOTE: after request for termination optimizer may perform several
additional calls to user-supplied callbacks. It does NOT guarantee
to stop immediately - it just guarantees that these additional calls
will be discarded later.
NOTE: calling this function on optimizer which is NOT running will have no
effect.
NOTE: multiple calls to this function are possible. First call is counted,
subsequent calls are silently ignored.
-- ALGLIB --
Copyright 08.10.2014 by Bochkanov Sergey
*************************************************************************/
</div><div style='margin-top: 0; margin-bottom: 0;'><b>void</b> alglib::minbleicrequesttermination(minbleicstate state);
</div></pre>
<a name='sub_minbleicrestartfrom'></a><h3 class=pageheader><code>minbleicrestartfrom</code> function</h3>
<pre class=source>
<div style='color: navy; margin-top: 0; margin-bottom: 0;'>/*************************************************************************
This subroutine restarts algorithm from new point.
All optimization parameters (including constraints) are left unchanged.
This function allows to solve multiple optimization problems (which
must have same number of dimensions) without object reallocation penalty.
INPUT PARAMETERS:
State - structure previously allocated with MinBLEICCreate call.
X - new starting point.
-- ALGLIB --
Copyright 28.11.2010 by Bochkanov Sergey
*************************************************************************/
</div><div style='margin-top: 0; margin-bottom: 0;'><b>void</b> alglib::minbleicrestartfrom(minbleicstate state, real_1d_array x);
</div></pre>
<a name='sub_minbleicresults'></a><h3 class=pageheader><code>minbleicresults</code> function</h3>
<pre class=source>
<div style='color: navy; margin-top: 0; margin-bottom: 0;'>/*************************************************************************
BLEIC results
INPUT PARAMETERS:
State - algorithm state
OUTPUT PARAMETERS:
X - array[0..N-1], solution
Rep - optimization report. You should check Rep.TerminationType
in order to distinguish successful termination from
unsuccessful one:
* -8 internal integrity control detected infinite or
NAN values in function/gradient. Abnormal
termination signalled.
* -7 gradient verification failed.
See MinBLEICSetGradientCheck() for more information.
* -3 inconsistent constraints. Feasible point is
either nonexistent or too hard to find. Try to
restart optimizer with better initial approximation
* 1 relative function improvement is no more than EpsF.
* 2 scaled step is no more than EpsX.
* 4 scaled gradient norm is no more than EpsG.
* 5 MaxIts steps was taken
* 8 terminated by user who called minbleicrequesttermination().
X contains point which was "current accepted" when
termination request was submitted.
More information about fields of this structure can be
found in the comments on MinBLEICReport datatype.
-- ALGLIB --
Copyright 28.11.2010 by Bochkanov Sergey
*************************************************************************/
</div><div style='margin-top: 0; margin-bottom: 0;'><b>void</b> alglib::minbleicresults(
minbleicstate state,
real_1d_array& x,
minbleicreport& rep);
</div></pre>
<p align=left class=pagecontent><span class=inlineheader>Examples:</span> <a href='#example_minbleic_d_1' class=nav>[1]</a> <a href='#example_minbleic_d_2' class=nav>[2]</a> <a href='#example_minbleic_numdiff' class=nav>[3]</a> <a href='#example_minbleic_ftrim' class=nav>[4]</a> </p>
<a name='sub_minbleicresultsbuf'></a><h3 class=pageheader><code>minbleicresultsbuf</code> function</h3>
<pre class=source>
<div style='color: navy; margin-top: 0; margin-bottom: 0;'>/*************************************************************************
BLEIC results
Buffered implementation of MinBLEICResults() which uses pre-allocated buffer
to store X[]. If buffer size is too small, it resizes buffer. It is
intended to be used in the inner cycles of performance critical algorithms
where array reallocation penalty is too large to be ignored.
-- ALGLIB --
Copyright 28.11.2010 by Bochkanov Sergey
*************************************************************************/
</div><div style='margin-top: 0; margin-bottom: 0;'><b>void</b> alglib::minbleicresultsbuf(
minbleicstate state,
real_1d_array& x,
minbleicreport& rep);
</div></pre>
<a name='sub_minbleicsetbc'></a><h3 class=pageheader><code>minbleicsetbc</code> function</h3>
<pre class=source>
<div style='color: navy; margin-top: 0; margin-bottom: 0;'>/*************************************************************************
This function sets boundary constraints for BLEIC optimizer.
Boundary constraints are inactive by default (after initial creation).
They are preserved after algorithm restart with MinBLEICRestartFrom().
INPUT PARAMETERS:
State - structure stores algorithm state
BndL - lower bounds, array[N].
If some (all) variables are unbounded, you may specify
very small number or -INF.
BndU - upper bounds, array[N].
If some (all) variables are unbounded, you may specify
very large number or +INF.
NOTE 1: it is possible to specify BndL[i]=BndU[i]. In this case I-th
variable will be "frozen" at X[i]=BndL[i]=BndU[i].
NOTE 2: this solver has following useful properties:
* bound constraints are always satisfied exactly
* function is evaluated only INSIDE area specified by bound constraints,
even when numerical differentiation is used (algorithm adjusts nodes
according to boundary constraints)
-- ALGLIB --
Copyright 28.11.2010 by Bochkanov Sergey
*************************************************************************/
</div><div style='margin-top: 0; margin-bottom: 0;'><b>void</b> alglib::minbleicsetbc(
minbleicstate state,
real_1d_array bndl,
real_1d_array bndu);
</div></pre>
<p align=left class=pagecontent><span class=inlineheader>Examples:</span> <a href='#example_minbleic_d_1' class=nav>[1]</a> <a href='#example_minbleic_numdiff' class=nav>[2]</a> </p>
<a name='sub_minbleicsetcond'></a><h3 class=pageheader><code>minbleicsetcond</code> function</h3>
<pre class=source>
<div style='color: navy; margin-top: 0; margin-bottom: 0;'>/*************************************************************************
This function sets stopping conditions for the optimizer.
INPUT PARAMETERS:
State - structure which stores algorithm state
EpsG - >=0
The subroutine finishes its work if the condition
|v|<EpsG is satisfied, where:
* |.| means Euclidian norm
* v - scaled gradient vector, v[i]=g[i]*s[i]
* g - gradient
* s - scaling coefficients set by MinBLEICSetScale()
EpsF - >=0
The subroutine finishes its work if on k+1-th iteration
the condition |F(k+1)-F(k)|<=EpsF*max{|F(k)|,|F(k+1)|,1}
is satisfied.
EpsX - >=0
The subroutine finishes its work if on k+1-th iteration
the condition |v|<=EpsX is fulfilled, where:
* |.| means Euclidian norm
* v - scaled step vector, v[i]=dx[i]/s[i]
* dx - step vector, dx=X(k+1)-X(k)
* s - scaling coefficients set by MinBLEICSetScale()
MaxIts - maximum number of iterations. If MaxIts=0, the number of
iterations is unlimited.
Passing EpsG=0, EpsF=0 and EpsX=0 and MaxIts=0 (simultaneously) will lead
to automatic stopping criterion selection.
NOTE: when SetCond() called with non-zero MaxIts, BLEIC solver may perform
slightly more than MaxIts iterations. I.e., MaxIts sets non-strict
limit on iterations count.
-- ALGLIB --
Copyright 28.11.2010 by Bochkanov Sergey
*************************************************************************/
</div><div style='margin-top: 0; margin-bottom: 0;'><b>void</b> alglib::minbleicsetcond(
minbleicstate state,
<b>double</b> epsg,
<b>double</b> epsf,
<b>double</b> epsx,
ae_int_t maxits);
</div></pre>
<p align=left class=pagecontent><span class=inlineheader>Examples:</span> <a href='#example_minbleic_d_1' class=nav>[1]</a> <a href='#example_minbleic_d_2' class=nav>[2]</a> <a href='#example_minbleic_numdiff' class=nav>[3]</a> </p>
<a name='sub_minbleicsetgradientcheck'></a><h3 class=pageheader><code>minbleicsetgradientcheck</code> function</h3>
<pre class=source>
<div style='color: navy; margin-top: 0; margin-bottom: 0;'>/*************************************************************************
This subroutine turns on verification of the user-supplied analytic
gradient:
* user calls this subroutine before optimization begins
* MinBLEICOptimize() is called
* prior to actual optimization, for each component of parameters being
optimized X[i] algorithm performs following steps:
* two trial steps are made to X[i]-TestStep*S[i] and X[i]+TestStep*S[i],
where X[i] is i-th component of the initial point and S[i] is a scale
of i-th parameter
* if needed, steps are bounded with respect to constraints on X[]
* F(X) is evaluated at these trial points
* we perform one more evaluation in the middle point of the interval
* we build cubic model using function values and derivatives at trial
points and we compare its prediction with actual value in the middle
point
* in case difference between prediction and actual value is higher than
some predetermined threshold, algorithm stops with completion code -7;
Rep.VarIdx is set to index of the parameter with incorrect derivative.
* after verification is over, algorithm proceeds to the actual optimization.
NOTE 1: verification needs N (parameters count) gradient evaluations. It
is very costly and you should use it only for low dimensional
problems, when you want to be sure that you've correctly
calculated analytic derivatives. You should not use it in the
production code (unless you want to check derivatives provided by
some third party).
NOTE 2: you should carefully choose TestStep. Value which is too large
(so large that function behaviour is significantly non-cubic) will
lead to false alarms. You may use different step for different
parameters by means of setting scale with MinBLEICSetScale().
NOTE 3: this function may lead to false positives. In case it reports that
I-th derivative was calculated incorrectly, you may decrease test
step and try one more time - maybe your function changes too
sharply and your step is too large for such rapidly chanding
function.
INPUT PARAMETERS:
State - structure used to store algorithm state
TestStep - verification step:
* TestStep=0 turns verification off
* TestStep>0 activates verification
-- ALGLIB --
Copyright 15.06.2012 by Bochkanov Sergey
*************************************************************************/
</div><div style='margin-top: 0; margin-bottom: 0;'><b>void</b> alglib::minbleicsetgradientcheck(
minbleicstate state,
<b>double</b> teststep);
</div></pre>
<a name='sub_minbleicsetlc'></a><h3 class=pageheader><code>minbleicsetlc</code> function</h3>
<pre class=source>
<div style='color: navy; margin-top: 0; margin-bottom: 0;'>/*************************************************************************
This function sets linear constraints for BLEIC optimizer.
Linear constraints are inactive by default (after initial creation).
They are preserved after algorithm restart with MinBLEICRestartFrom().
INPUT PARAMETERS:
State - structure previously allocated with MinBLEICCreate call.
C - linear constraints, array[K,N+1].
Each row of C represents one constraint, either equality
or inequality (see below):
* first N elements correspond to coefficients,
* last element corresponds to the right part.
All elements of C (including right part) must be finite.
CT - type of constraints, array[K]:
* if CT[i]>0, then I-th constraint is C[i,*]*x >= C[i,n+1]
* if CT[i]=0, then I-th constraint is C[i,*]*x = C[i,n+1]
* if CT[i]<0, then I-th constraint is C[i,*]*x <= C[i,n+1]
K - number of equality/inequality constraints, K>=0:
* if given, only leading K elements of C/CT are used
* if not given, automatically determined from sizes of C/CT
NOTE 1: linear (non-bound) constraints are satisfied only approximately:
* there always exists some minor violation (about Epsilon in magnitude)
due to rounding errors
* numerical differentiation, if used, may lead to function evaluations
outside of the feasible area, because algorithm does NOT change
numerical differentiation formula according to linear constraints.
If you want constraints to be satisfied exactly, try to reformulate your
problem in such manner that all constraints will become boundary ones
(this kind of constraints is always satisfied exactly, both in the final
solution and in all intermediate points).
-- ALGLIB --
Copyright 28.11.2010 by Bochkanov Sergey
*************************************************************************/
</div><div style='margin-top: 0; margin-bottom: 0;'><b>void</b> alglib::minbleicsetlc(
minbleicstate state,
real_2d_array c,
integer_1d_array ct);
<b>void</b> alglib::minbleicsetlc(
minbleicstate state,
real_2d_array c,
integer_1d_array ct,
ae_int_t k);
</div></pre>
<p align=left class=pagecontent><span class=inlineheader>Examples:</span> <a href='#example_minbleic_d_2' class=nav>[1]</a> </p>
<a name='sub_minbleicsetprecdefault'></a><h3 class=pageheader><code>minbleicsetprecdefault</code> function</h3>
<pre class=source>
<div style='color: navy; margin-top: 0; margin-bottom: 0;'>/*************************************************************************
Modification of the preconditioner: preconditioning is turned off.
INPUT PARAMETERS:
State - structure which stores algorithm state
-- ALGLIB --
Copyright 13.10.2010 by Bochkanov Sergey
*************************************************************************/
</div><div style='margin-top: 0; margin-bottom: 0;'><b>void</b> alglib::minbleicsetprecdefault(minbleicstate state);
</div></pre>
<a name='sub_minbleicsetprecdiag'></a><h3 class=pageheader><code>minbleicsetprecdiag</code> function</h3>
<pre class=source>
<div style='color: navy; margin-top: 0; margin-bottom: 0;'>/*************************************************************************
Modification of the preconditioner: diagonal of approximate Hessian is
used.
INPUT PARAMETERS:
State - structure which stores algorithm state
D - diagonal of the approximate Hessian, array[0..N-1],
(if larger, only leading N elements are used).
NOTE 1: D[i] should be positive. Exception will be thrown otherwise.
NOTE 2: you should pass diagonal of approximate Hessian - NOT ITS INVERSE.
-- ALGLIB --
Copyright 13.10.2010 by Bochkanov Sergey
*************************************************************************/
</div><div style='margin-top: 0; margin-bottom: 0;'><b>void</b> alglib::minbleicsetprecdiag(minbleicstate state, real_1d_array d);
</div></pre>
<a name='sub_minbleicsetprecscale'></a><h3 class=pageheader><code>minbleicsetprecscale</code> function</h3>
<pre class=source>
<div style='color: navy; margin-top: 0; margin-bottom: 0;'>/*************************************************************************
Modification of the preconditioner: scale-based diagonal preconditioning.
This preconditioning mode can be useful when you don't have approximate
diagonal of Hessian, but you know that your variables are badly scaled
(for example, one variable is in [1,10], and another in [1000,100000]),
and most part of the ill-conditioning comes from different scales of vars.
In this case simple scale-based preconditioner, with H[i] = 1/(s[i]^2),
can greatly improve convergence.
IMPRTANT: you should set scale of your variables with MinBLEICSetScale()
call (before or after MinBLEICSetPrecScale() call). Without knowledge of
the scale of your variables scale-based preconditioner will be just unit
matrix.
INPUT PARAMETERS:
State - structure which stores algorithm state
-- ALGLIB --
Copyright 13.10.2010 by Bochkanov Sergey
*************************************************************************/
</div><div style='margin-top: 0; margin-bottom: 0;'><b>void</b> alglib::minbleicsetprecscale(minbleicstate state);
</div></pre>
<a name='sub_minbleicsetscale'></a><h3 class=pageheader><code>minbleicsetscale</code> function</h3>
<pre class=source>
<div style='color: navy; margin-top: 0; margin-bottom: 0;'>/*************************************************************************
This function sets scaling coefficients for BLEIC optimizer.
ALGLIB optimizers use scaling matrices to test stopping conditions (step
size and gradient are scaled before comparison with tolerances). Scale of
the I-th variable is a translation invariant measure of:
a) "how large" the variable is
b) how large the step should be to make significant changes in the function
Scaling is also used by finite difference variant of the optimizer - step
along I-th axis is equal to DiffStep*S[I].
In most optimizers (and in the BLEIC too) scaling is NOT a form of
preconditioning. It just affects stopping conditions. You should set
preconditioner by separate call to one of the MinBLEICSetPrec...()
functions.
There is a special preconditioning mode, however, which uses scaling
coefficients to form diagonal preconditioning matrix. You can turn this
mode on, if you want. But you should understand that scaling is not the
same thing as preconditioning - these are two different, although related
forms of tuning solver.
INPUT PARAMETERS:
State - structure stores algorithm state
S - array[N], non-zero scaling coefficients
S[i] may be negative, sign doesn't matter.
-- ALGLIB --
Copyright 14.01.2011 by Bochkanov Sergey
*************************************************************************/
</div><div style='margin-top: 0; margin-bottom: 0;'><b>void</b> alglib::minbleicsetscale(minbleicstate state, real_1d_array s);
</div></pre>
<a name='sub_minbleicsetstpmax'></a><h3 class=pageheader><code>minbleicsetstpmax</code> function</h3>
<pre class=source>
<div style='color: navy; margin-top: 0; margin-bottom: 0;'>/*************************************************************************
This function sets maximum step length
IMPORTANT: this feature is hard to combine with preconditioning. You can't
set upper limit on step length, when you solve optimization problem with
linear (non-boundary) constraints AND preconditioner turned on.
When non-boundary constraints are present, you have to either a) use
preconditioner, or b) use upper limit on step length. YOU CAN'T USE BOTH!
In this case algorithm will terminate with appropriate error code.
INPUT PARAMETERS:
State - structure which stores algorithm state
StpMax - maximum step length, >=0. Set StpMax to 0.0, if you don't
want to limit step length.
Use this subroutine when you optimize target function which contains exp()
or other fast growing functions, and optimization algorithm makes too
large steps which lead to overflow. This function allows us to reject
steps that are too large (and therefore expose us to the possible
overflow) without actually calculating function value at the x+stp*d.
-- ALGLIB --
Copyright 02.04.2010 by Bochkanov Sergey
*************************************************************************/
</div><div style='margin-top: 0; margin-bottom: 0;'><b>void</b> alglib::minbleicsetstpmax(minbleicstate state, <b>double</b> stpmax);
</div></pre>
<a name='sub_minbleicsetxrep'></a><h3 class=pageheader><code>minbleicsetxrep</code> function</h3>
<pre class=source>
<div style='color: navy; margin-top: 0; margin-bottom: 0;'>/*************************************************************************
This function turns on/off reporting.
INPUT PARAMETERS:
State - structure which stores algorithm state
NeedXRep- whether iteration reports are needed or not
If NeedXRep is True, algorithm will call rep() callback function if it is
provided to MinBLEICOptimize().
-- ALGLIB --
Copyright 28.11.2010 by Bochkanov Sergey
*************************************************************************/
</div><div style='margin-top: 0; margin-bottom: 0;'><b>void</b> alglib::minbleicsetxrep(minbleicstate state, <b>bool</b> needxrep);
</div></pre>
<a name='example_minbleic_d_1'></a><h3 class=pageheader>minbleic_d_1 example</h3>
<pre class=source>
#include <font color=blue><b>"stdafx.h"</b></font>
#include <stdlib.h>
#include <stdio.h>
#include <math.h>
#include <font color=blue><b>"optimization.h"</b></font>
using namespace alglib;
<b>void</b> function1_grad(<b>const</b> real_1d_array &x, <b>double</b> &func, real_1d_array &grad, <b>void</b> *ptr)
{
<font color=navy>//</font>
<font color=navy>// this callback calculates f(x0,x1) = 100*(x0+3)^4 + (x1-3)^4</font>
<font color=navy>// and its derivatives df/d0 and df/dx1</font>
<font color=navy>//</font>
func = 100*pow(x[0]+3,4) + pow(x[1]-3,4);
grad[0] = 400*pow(x[0]+3,3);
grad[1] = 4*pow(x[1]-3,3);
}
<b>int</b> main(<b>int</b> argc, char **argv)
{
<font color=navy>//</font>
<font color=navy>// This example demonstrates minimization of f(x,y) = 100*(x+3)^4+(y-3)^4</font>
<font color=navy>// subject to bound constraints -1<=x<=+1, -1<=y<=+1, using BLEIC optimizer.</font>
<font color=navy>//</font>
real_1d_array x = <font color=blue><b>"[0,0]"</b></font>;
real_1d_array bndl = <font color=blue><b>"[-1,-1]"</b></font>;
real_1d_array bndu = <font color=blue><b>"[+1,+1]"</b></font>;
minbleicstate state;
minbleicreport rep;
<font color=navy>//</font>
<font color=navy>// These variables define stopping conditions <b>for</b> the optimizer.</font>
<font color=navy>//</font>
<font color=navy>// We use very simple condition - |g|<=epsg</font>
<font color=navy>//</font>
<b>double</b> epsg = 0.000001;
<b>double</b> epsf = 0;
<b>double</b> epsx = 0;
ae_int_t maxits = 0;
<font color=navy>//</font>
<font color=navy>// Now we are ready to actually optimize something:</font>
<font color=navy>// * first we create optimizer</font>
<font color=navy>// * we add boundary constraints</font>
<font color=navy>// * we tune stopping conditions</font>
<font color=navy>// * and, finally, optimize and obtain results...</font>
<font color=navy>//</font>
minbleiccreate(x, state);
minbleicsetbc(state, bndl, bndu);
minbleicsetcond(state, epsg, epsf, epsx, maxits);
alglib::minbleicoptimize(state, function1_grad);
minbleicresults(state, x, rep);
<font color=navy>//</font>
<font color=navy>// ...and evaluate these results</font>
<font color=navy>//</font>
printf(<font color=blue><b>"%d\n"</b></font>, <b>int</b>(rep.terminationtype)); <font color=navy>// EXPECTED: 4</font>
printf(<font color=blue><b>"%s\n"</b></font>, x.tostring(2).c_str()); <font color=navy>// EXPECTED: [-1,1]</font>
<b>return</b> 0;
}
</pre><a name='example_minbleic_d_2'></a><h3 class=pageheader>minbleic_d_2 example</h3>
<pre class=source>
#include <font color=blue><b>"stdafx.h"</b></font>
#include <stdlib.h>
#include <stdio.h>
#include <math.h>
#include <font color=blue><b>"optimization.h"</b></font>
using namespace alglib;
<b>void</b> function1_grad(<b>const</b> real_1d_array &x, <b>double</b> &func, real_1d_array &grad, <b>void</b> *ptr)
{
<font color=navy>//</font>
<font color=navy>// this callback calculates f(x0,x1) = 100*(x0+3)^4 + (x1-3)^4</font>
<font color=navy>// and its derivatives df/d0 and df/dx1</font>
<font color=navy>//</font>
func = 100*pow(x[0]+3,4) + pow(x[1]-3,4);
grad[0] = 400*pow(x[0]+3,3);
grad[1] = 4*pow(x[1]-3,3);
}
<b>int</b> main(<b>int</b> argc, char **argv)
{
<font color=navy>//</font>
<font color=navy>// This example demonstrates minimization of f(x,y) = 100*(x+3)^4+(y-3)^4</font>
<font color=navy>// subject to inequality constraints:</font>
<font color=navy>// * x>=2 (posed as general linear constraint),</font>
<font color=navy>// * x+y>=6</font>
<font color=navy>// using BLEIC optimizer.</font>
<font color=navy>//</font>
real_1d_array x = <font color=blue><b>"[5,5]"</b></font>;
real_2d_array c = <font color=blue><b>"[[1,0,2],[1,1,6]]"</b></font>;
integer_1d_array ct = <font color=blue><b>"[1,1]"</b></font>;
minbleicstate state;
minbleicreport rep;
<font color=navy>//</font>
<font color=navy>// These variables define stopping conditions <b>for</b> the optimizer.</font>
<font color=navy>//</font>
<font color=navy>// We use very simple condition - |g|<=epsg</font>
<font color=navy>//</font>
<b>double</b> epsg = 0.000001;
<b>double</b> epsf = 0;
<b>double</b> epsx = 0;
ae_int_t maxits = 0;
<font color=navy>//</font>
<font color=navy>// Now we are ready to actually optimize something:</font>
<font color=navy>// * first we create optimizer</font>
<font color=navy>// * we add linear constraints</font>
<font color=navy>// * we tune stopping conditions</font>
<font color=navy>// * and, finally, optimize and obtain results...</font>
<font color=navy>//</font>
minbleiccreate(x, state);
minbleicsetlc(state, c, ct);
minbleicsetcond(state, epsg, epsf, epsx, maxits);
alglib::minbleicoptimize(state, function1_grad);
minbleicresults(state, x, rep);
<font color=navy>//</font>
<font color=navy>// ...and evaluate these results</font>
<font color=navy>//</font>
printf(<font color=blue><b>"%d\n"</b></font>, <b>int</b>(rep.terminationtype)); <font color=navy>// EXPECTED: 4</font>
printf(<font color=blue><b>"%s\n"</b></font>, x.tostring(2).c_str()); <font color=navy>// EXPECTED: [2,4]</font>
<b>return</b> 0;
}
</pre><a name='example_minbleic_ftrim'></a><h3 class=pageheader>minbleic_ftrim example</h3>
<pre class=source>
#include <font color=blue><b>"stdafx.h"</b></font>
#include <stdlib.h>
#include <stdio.h>
#include <math.h>
#include <font color=blue><b>"optimization.h"</b></font>
using namespace alglib;
<b>void</b> s1_grad(<b>const</b> real_1d_array &x, <b>double</b> &func, real_1d_array &grad, <b>void</b> *ptr)
{
<font color=navy>//</font>
<font color=navy>// this callback calculates f(x) = (1+x)^(-0.2) + (1-x)^(-0.3) + 1000*x and its gradient.</font>
<font color=navy>//</font>
<font color=navy>// function is trimmed when we calculate it near the singular points or outside of the [-1,+1].</font>
<font color=navy>// Note that we <b>do</b> NOT calculate gradient in this case.</font>
<font color=navy>//</font>
<b>if</b>( (x[0]<=-0.999999999999) || (x[0]>=+0.999999999999) )
{
func = 1.0E+300;
<b>return</b>;
}
func = pow(1+x[0],-0.2) + pow(1-x[0],-0.3) + 1000*x[0];
grad[0] = -0.2*pow(1+x[0],-1.2) +0.3*pow(1-x[0],-1.3) + 1000;
}
<b>int</b> main(<b>int</b> argc, char **argv)
{
<font color=navy>//</font>
<font color=navy>// This example demonstrates minimization of f(x) = (1+x)^(-0.2) + (1-x)^(-0.3) + 1000*x.</font>
<font color=navy>//</font>
<font color=navy>// This function is undefined outside of (-1,+1) and has singularities at x=-1 and x=+1.</font>
<font color=navy>// Special technique called <font color=blue><b>"function trimming"</b></font> allows us to solve this optimization problem </font>
<font color=navy>// - without using boundary constraints!</font>
<font color=navy>//</font>
<font color=navy>// See http://www.alglib.net/optimization/tipsandtricks.php#ftrimming <b>for</b> more information</font>
<font color=navy>// on this subject.</font>
<font color=navy>//</font>
real_1d_array x = <font color=blue><b>"[0]"</b></font>;
<b>double</b> epsg = 1.0e-6;
<b>double</b> epsf = 0;
<b>double</b> epsx = 0;
ae_int_t maxits = 0;
minbleicstate state;
minbleicreport rep;
minbleiccreate(x, state);
minbleicsetcond(state, epsg, epsf, epsx, maxits);
alglib::minbleicoptimize(state, s1_grad);
minbleicresults(state, x, rep);
printf(<font color=blue><b>"%s\n"</b></font>, x.tostring(5).c_str()); <font color=navy>// EXPECTED: [-0.99917305]</font>
<b>return</b> 0;
}
</pre><a name='example_minbleic_numdiff'></a><h3 class=pageheader>minbleic_numdiff example</h3>
<pre class=source>
#include <font color=blue><b>"stdafx.h"</b></font>
#include <stdlib.h>
#include <stdio.h>
#include <math.h>
#include <font color=blue><b>"optimization.h"</b></font>
using namespace alglib;
<b>void</b> function1_func(<b>const</b> real_1d_array &x, <b>double</b> &func, <b>void</b> *ptr)
{
<font color=navy>//</font>
<font color=navy>// this callback calculates f(x0,x1) = 100*(x0+3)^4 + (x1-3)^4</font>
<font color=navy>//</font>
func = 100*pow(x[0]+3,4) + pow(x[1]-3,4);
}
<b>int</b> main(<b>int</b> argc, char **argv)
{
<font color=navy>//</font>
<font color=navy>// This example demonstrates minimization of f(x,y) = 100*(x+3)^4+(y-3)^4</font>
<font color=navy>// subject to bound constraints -1<=x<=+1, -1<=y<=+1, using BLEIC optimizer.</font>
<font color=navy>//</font>
real_1d_array x = <font color=blue><b>"[0,0]"</b></font>;
real_1d_array bndl = <font color=blue><b>"[-1,-1]"</b></font>;
real_1d_array bndu = <font color=blue><b>"[+1,+1]"</b></font>;
minbleicstate state;
minbleicreport rep;
<font color=navy>//</font>
<font color=navy>// These variables define stopping conditions <b>for</b> the optimizer.</font>
<font color=navy>//</font>
<font color=navy>// We use very simple condition - |g|<=epsg</font>
<font color=navy>//</font>
<b>double</b> epsg = 0.000001;
<b>double</b> epsf = 0;
<b>double</b> epsx = 0;
ae_int_t maxits = 0;
<font color=navy>//</font>
<font color=navy>// This variable contains differentiation step</font>
<font color=navy>//</font>
<b>double</b> diffstep = 1.0e-6;
<font color=navy>//</font>
<font color=navy>// Now we are ready to actually optimize something:</font>
<font color=navy>// * first we create optimizer</font>
<font color=navy>// * we add boundary constraints</font>
<font color=navy>// * we tune stopping conditions</font>
<font color=navy>// * and, finally, optimize and obtain results...</font>
<font color=navy>//</font>
minbleiccreatef(x, diffstep, state);
minbleicsetbc(state, bndl, bndu);
minbleicsetcond(state, epsg, epsf, epsx, maxits);
alglib::minbleicoptimize(state, function1_func);
minbleicresults(state, x, rep);
<font color=navy>//</font>
<font color=navy>// ...and evaluate these results</font>
<font color=navy>//</font>
printf(<font color=blue><b>"%d\n"</b></font>, <b>int</b>(rep.terminationtype)); <font color=navy>// EXPECTED: 4</font>
printf(<font color=blue><b>"%s\n"</b></font>, x.tostring(2).c_str()); <font color=navy>// EXPECTED: [-1,1]</font>
<b>return</b> 0;
}
</pre><a name=unit_mincg></a><h2 class=pageheader><code>mincg</code> subpackage</h2>
<div class=pagecontent>
<h3 class=pageheader>Classes</h3>
<a href='#struct_mincgreport' class=toc>mincgreport</a><br>
<a href='#struct_mincgstate' class=toc>mincgstate</a><br>
<h3 class=pageheader>Functions</h3>
<a href='#sub_mincgcreate' class=toc>mincgcreate</a><br>
<a href='#sub_mincgcreatef' class=toc>mincgcreatef</a><br>
<a href='#sub_mincgoptimize' class=toc>mincgoptimize</a><br>
<a href='#sub_mincgrequesttermination' class=toc>mincgrequesttermination</a><br>
<a href='#sub_mincgrestartfrom' class=toc>mincgrestartfrom</a><br>
<a href='#sub_mincgresults' class=toc>mincgresults</a><br>
<a href='#sub_mincgresultsbuf' class=toc>mincgresultsbuf</a><br>
<a href='#sub_mincgsetcgtype' class=toc>mincgsetcgtype</a><br>
<a href='#sub_mincgsetcond' class=toc>mincgsetcond</a><br>
<a href='#sub_mincgsetgradientcheck' class=toc>mincgsetgradientcheck</a><br>
<a href='#sub_mincgsetprecdefault' class=toc>mincgsetprecdefault</a><br>
<a href='#sub_mincgsetprecdiag' class=toc>mincgsetprecdiag</a><br>
<a href='#sub_mincgsetprecscale' class=toc>mincgsetprecscale</a><br>
<a href='#sub_mincgsetscale' class=toc>mincgsetscale</a><br>
<a href='#sub_mincgsetstpmax' class=toc>mincgsetstpmax</a><br>
<a href='#sub_mincgsetxrep' class=toc>mincgsetxrep</a><br>
<a href='#sub_mincgsuggeststep' class=toc>mincgsuggeststep</a><br>
<h3 class=pageheader>Examples</h3>
<table border=0 cellspacing=0 class='pagecontent'>
<tr align=left valign=top><td><a href='#example_mincg_d_1' class=toc>mincg_d_1</a></td><td width=15> </td><td>Nonlinear optimization by CG</td></tr>
<tr align=left valign=top><td><a href='#example_mincg_d_2' class=toc>mincg_d_2</a></td><td width=15> </td><td>Nonlinear optimization with additional settings and restarts</td></tr>
<tr align=left valign=top><td><a href='#example_mincg_ftrim' class=toc>mincg_ftrim</a></td><td width=15> </td><td>Nonlinear optimization by CG, function with singularities</td></tr>
<tr align=left valign=top><td><a href='#example_mincg_numdiff' class=toc>mincg_numdiff</a></td><td width=15> </td><td>Nonlinear optimization by CG with numerical differentiation</td></tr>
</table></div>
<a name='struct_mincgreport'></a><h3 class=pageheader><code>mincgreport</code> class</h3>
<pre class=source>
<div style='color: navy; margin-top: 0; margin-bottom: 0;'>/*************************************************************************
This structure stores optimization report:
* IterationsCount total number of inner iterations
* NFEV number of gradient evaluations
* TerminationType termination type (see below)
TERMINATION CODES
TerminationType field contains completion code, which can be:
-8 internal integrity control detected infinite or NAN values in
function/gradient. Abnormal termination signalled.
-7 gradient verification failed.
See MinCGSetGradientCheck() for more information.
1 relative function improvement is no more than EpsF.
2 relative step is no more than EpsX.
4 gradient norm is no more than EpsG
5 MaxIts steps was taken
7 stopping conditions are too stringent,
further improvement is impossible,
X contains best point found so far.
8 terminated by user who called mincgrequesttermination(). X contains
point which was "current accepted" when termination request was
submitted.
Other fields of this structure are not documented and should not be used!
*************************************************************************/
</div><div style='margin-top: 0; margin-bottom: 0;'><b>class</b> mincgreport
{
ae_int_t iterationscount;
ae_int_t nfev;
ae_int_t varidx;
ae_int_t terminationtype;
};
</div></pre>
<a name='struct_mincgstate'></a><h3 class=pageheader><code>mincgstate</code> class</h3>
<pre class=source>
<div style='color: navy; margin-top: 0; margin-bottom: 0;'>/*************************************************************************
This object stores state of the nonlinear CG optimizer.
You should use ALGLIB functions to work with this object.
*************************************************************************/
</div><div style='margin-top: 0; margin-bottom: 0;'><b>class</b> mincgstate
{
};
</div></pre>
<a name='sub_mincgcreate'></a><h3 class=pageheader><code>mincgcreate</code> function</h3>
<pre class=source>
<div style='color: navy; margin-top: 0; margin-bottom: 0;'>/*************************************************************************
NONLINEAR CONJUGATE GRADIENT METHOD
DESCRIPTION:
The subroutine minimizes function F(x) of N arguments by using one of the
nonlinear conjugate gradient methods.
These CG methods are globally convergent (even on non-convex functions) as
long as grad(f) is Lipschitz continuous in a some neighborhood of the
L = { x : f(x)<=f(x0) }.
REQUIREMENTS:
Algorithm will request following information during its operation:
* function value F and its gradient G (simultaneously) at given point X
USAGE:
1. User initializes algorithm state with MinCGCreate() call
2. User tunes solver parameters with MinCGSetCond(), MinCGSetStpMax() and
other functions
3. User calls MinCGOptimize() function which takes algorithm state and
pointer (delegate, etc.) to callback function which calculates F/G.
4. User calls MinCGResults() to get solution
5. Optionally, user may call MinCGRestartFrom() to solve another problem
with same N but another starting point and/or another function.
MinCGRestartFrom() allows to reuse already initialized structure.
INPUT PARAMETERS:
N - problem dimension, N>0:
* if given, only leading N elements of X are used
* if not given, automatically determined from size of X
X - starting point, array[0..N-1].
OUTPUT PARAMETERS:
State - structure which stores algorithm state
-- ALGLIB --
Copyright 25.03.2010 by Bochkanov Sergey
*************************************************************************/
</div><div style='margin-top: 0; margin-bottom: 0;'><b>void</b> alglib::mincgcreate(real_1d_array x, mincgstate& state);
<b>void</b> alglib::mincgcreate(ae_int_t n, real_1d_array x, mincgstate& state);
</div></pre>
<p align=left class=pagecontent><span class=inlineheader>Examples:</span> <a href='#example_mincg_d_1' class=nav>[1]</a> <a href='#example_mincg_d_2' class=nav>[2]</a> <a href='#example_mincg_ftrim' class=nav>[3]</a> </p>
<a name='sub_mincgcreatef'></a><h3 class=pageheader><code>mincgcreatef</code> function</h3>
<pre class=source>
<div style='color: navy; margin-top: 0; margin-bottom: 0;'>/*************************************************************************
The subroutine is finite difference variant of MinCGCreate(). It uses
finite differences in order to differentiate target function.
Description below contains information which is specific to this function
only. We recommend to read comments on MinCGCreate() in order to get more
information about creation of CG optimizer.
INPUT PARAMETERS:
N - problem dimension, N>0:
* if given, only leading N elements of X are used
* if not given, automatically determined from size of X
X - starting point, array[0..N-1].
DiffStep- differentiation step, >0
OUTPUT PARAMETERS:
State - structure which stores algorithm state
NOTES:
1. algorithm uses 4-point central formula for differentiation.
2. differentiation step along I-th axis is equal to DiffStep*S[I] where
S[] is scaling vector which can be set by MinCGSetScale() call.
3. we recommend you to use moderate values of differentiation step. Too
large step will result in too large truncation errors, while too small
step will result in too large numerical errors. 1.0E-6 can be good
value to start with.
4. Numerical differentiation is very inefficient - one gradient
calculation needs 4*N function evaluations. This function will work for
any N - either small (1...10), moderate (10...100) or large (100...).
However, performance penalty will be too severe for any N's except for
small ones.
We should also say that code which relies on numerical differentiation
is less robust and precise. L-BFGS needs exact gradient values.
Imprecise gradient may slow down convergence, especially on highly
nonlinear problems.
Thus we recommend to use this function for fast prototyping on small-
dimensional problems only, and to implement analytical gradient as soon
as possible.
-- ALGLIB --
Copyright 16.05.2011 by Bochkanov Sergey
*************************************************************************/
</div><div style='margin-top: 0; margin-bottom: 0;'><b>void</b> alglib::mincgcreatef(
real_1d_array x,
<b>double</b> diffstep,
mincgstate& state);
<b>void</b> alglib::mincgcreatef(
ae_int_t n,
real_1d_array x,
<b>double</b> diffstep,
mincgstate& state);
</div></pre>
<p align=left class=pagecontent><span class=inlineheader>Examples:</span> <a href='#example_mincg_numdiff' class=nav>[1]</a> </p>
<a name='sub_mincgoptimize'></a><h3 class=pageheader><code>mincgoptimize</code> function</h3>
<pre class=source>
<div style='color: navy; margin-top: 0; margin-bottom: 0;'>/*************************************************************************
This family of functions is used to launcn iterations of nonlinear optimizer
These functions accept following parameters:
state - algorithm state
func - callback which calculates function (or merit function)
value func at given point x
grad - callback which calculates function (or merit function)
value func and gradient grad at given point x
rep - optional callback which is called after each iteration
can be NULL
ptr - optional pointer which is passed to func/grad/hess/jac/rep
can be NULL
NOTES:
1. This function has two different implementations: one which uses exact
(analytical) user-supplied gradient, and one which uses function value
only and numerically differentiates function in order to obtain
gradient.
Depending on the specific function used to create optimizer object
(either MinCGCreate() for analytical gradient or MinCGCreateF() for
numerical differentiation) you should choose appropriate variant of
MinCGOptimize() - one which accepts function AND gradient or one which
accepts function ONLY.
Be careful to choose variant of MinCGOptimize() which corresponds to
your optimization scheme! Table below lists different combinations of
callback (function/gradient) passed to MinCGOptimize() and specific
function used to create optimizer.
| USER PASSED TO MinCGOptimize()
CREATED WITH | function only | function and gradient
------------------------------------------------------------
MinCGCreateF() | work FAIL
MinCGCreate() | FAIL work
Here "FAIL" denotes inappropriate combinations of optimizer creation
function and MinCGOptimize() version. Attemps to use such combination
(for example, to create optimizer with MinCGCreateF() and to pass
gradient information to MinCGOptimize()) will lead to exception being
thrown. Either you did not pass gradient when it WAS needed or you
passed gradient when it was NOT needed.
-- ALGLIB --
Copyright 20.04.2009 by Bochkanov Sergey
*************************************************************************/
</div><div style='margin-top: 0; margin-bottom: 0;'><b>void</b> mincgoptimize(mincgstate &state,
<b>void</b> (*func)(<b>const</b> real_1d_array &x, <b>double</b> &func, <b>void</b> *ptr),
<b>void</b> (*rep)(<b>const</b> real_1d_array &x, <b>double</b> func, <b>void</b> *ptr) = NULL,
<b>void</b> *ptr = NULL);
<b>void</b> mincgoptimize(mincgstate &state,
<b>void</b> (*grad)(<b>const</b> real_1d_array &x, <b>double</b> &func, real_1d_array &grad, <b>void</b> *ptr),
<b>void</b> (*rep)(<b>const</b> real_1d_array &x, <b>double</b> func, <b>void</b> *ptr) = NULL,
<b>void</b> *ptr = NULL);
</div></pre>
<p align=left class=pagecontent><span class=inlineheader>Examples:</span> <a href='#example_mincg_d_1' class=nav>[1]</a> <a href='#example_mincg_d_2' class=nav>[2]</a> <a href='#example_mincg_numdiff' class=nav>[3]</a> <a href='#example_mincg_ftrim' class=nav>[4]</a> </p>
<a name='sub_mincgrequesttermination'></a><h3 class=pageheader><code>mincgrequesttermination</code> function</h3>
<pre class=source>
<div style='color: navy; margin-top: 0; margin-bottom: 0;'>/*************************************************************************
This subroutine submits request for termination of running optimizer. It
should be called from user-supplied callback when user decides that it is
time to "smoothly" terminate optimization process. As result, optimizer
stops at point which was "current accepted" when termination request was
submitted and returns error code 8 (successful termination).
INPUT PARAMETERS:
State - optimizer structure
NOTE: after request for termination optimizer may perform several
additional calls to user-supplied callbacks. It does NOT guarantee
to stop immediately - it just guarantees that these additional calls
will be discarded later.
NOTE: calling this function on optimizer which is NOT running will have no
effect.
NOTE: multiple calls to this function are possible. First call is counted,
subsequent calls are silently ignored.
-- ALGLIB --
Copyright 08.10.2014 by Bochkanov Sergey
*************************************************************************/
</div><div style='margin-top: 0; margin-bottom: 0;'><b>void</b> alglib::mincgrequesttermination(mincgstate state);
</div></pre>
<a name='sub_mincgrestartfrom'></a><h3 class=pageheader><code>mincgrestartfrom</code> function</h3>
<pre class=source>
<div style='color: navy; margin-top: 0; margin-bottom: 0;'>/*************************************************************************
This subroutine restarts CG algorithm from new point. All optimization
parameters are left unchanged.
This function allows to solve multiple optimization problems (which
must have same number of dimensions) without object reallocation penalty.
INPUT PARAMETERS:
State - structure used to store algorithm state.
X - new starting point.
-- ALGLIB --
Copyright 30.07.2010 by Bochkanov Sergey
*************************************************************************/
</div><div style='margin-top: 0; margin-bottom: 0;'><b>void</b> alglib::mincgrestartfrom(mincgstate state, real_1d_array x);
</div></pre>
<p align=left class=pagecontent><span class=inlineheader>Examples:</span> <a href='#example_mincg_d_2' class=nav>[1]</a> </p>
<a name='sub_mincgresults'></a><h3 class=pageheader><code>mincgresults</code> function</h3>
<pre class=source>
<div style='color: navy; margin-top: 0; margin-bottom: 0;'>/*************************************************************************
Conjugate gradient results
INPUT PARAMETERS:
State - algorithm state
OUTPUT PARAMETERS:
X - array[0..N-1], solution
Rep - optimization report:
* Rep.TerminationType completetion code:
* -8 internal integrity control detected infinite
or NAN values in function/gradient. Abnormal
termination signalled.
* -7 gradient verification failed.
See MinCGSetGradientCheck() for more information.
* 1 relative function improvement is no more than
EpsF.
* 2 relative step is no more than EpsX.
* 4 gradient norm is no more than EpsG
* 5 MaxIts steps was taken
* 7 stopping conditions are too stringent,
further improvement is impossible,
we return best X found so far
* 8 terminated by user
* Rep.IterationsCount contains iterations count
* NFEV countains number of function calculations
-- ALGLIB --
Copyright 20.04.2009 by Bochkanov Sergey
*************************************************************************/
</div><div style='margin-top: 0; margin-bottom: 0;'><b>void</b> alglib::mincgresults(
mincgstate state,
real_1d_array& x,
mincgreport& rep);
</div></pre>
<p align=left class=pagecontent><span class=inlineheader>Examples:</span> <a href='#example_mincg_d_1' class=nav>[1]</a> <a href='#example_mincg_d_2' class=nav>[2]</a> <a href='#example_mincg_numdiff' class=nav>[3]</a> <a href='#example_mincg_ftrim' class=nav>[4]</a> </p>
<a name='sub_mincgresultsbuf'></a><h3 class=pageheader><code>mincgresultsbuf</code> function</h3>
<pre class=source>
<div style='color: navy; margin-top: 0; margin-bottom: 0;'>/*************************************************************************
Conjugate gradient results
Buffered implementation of MinCGResults(), which uses pre-allocated buffer
to store X[]. If buffer size is too small, it resizes buffer. It is
intended to be used in the inner cycles of performance critical algorithms
where array reallocation penalty is too large to be ignored.
-- ALGLIB --
Copyright 20.04.2009 by Bochkanov Sergey
*************************************************************************/
</div><div style='margin-top: 0; margin-bottom: 0;'><b>void</b> alglib::mincgresultsbuf(
mincgstate state,
real_1d_array& x,
mincgreport& rep);
</div></pre>
<a name='sub_mincgsetcgtype'></a><h3 class=pageheader><code>mincgsetcgtype</code> function</h3>
<pre class=source>
<div style='color: navy; margin-top: 0; margin-bottom: 0;'>/*************************************************************************
This function sets CG algorithm.
INPUT PARAMETERS:
State - structure which stores algorithm state
CGType - algorithm type:
* -1 automatic selection of the best algorithm
* 0 DY (Dai and Yuan) algorithm
* 1 Hybrid DY-HS algorithm
-- ALGLIB --
Copyright 02.04.2010 by Bochkanov Sergey
*************************************************************************/
</div><div style='margin-top: 0; margin-bottom: 0;'><b>void</b> alglib::mincgsetcgtype(mincgstate state, ae_int_t cgtype);
</div></pre>
<a name='sub_mincgsetcond'></a><h3 class=pageheader><code>mincgsetcond</code> function</h3>
<pre class=source>
<div style='color: navy; margin-top: 0; margin-bottom: 0;'>/*************************************************************************
This function sets stopping conditions for CG optimization algorithm.
INPUT PARAMETERS:
State - structure which stores algorithm state
EpsG - >=0
The subroutine finishes its work if the condition
|v|<EpsG is satisfied, where:
* |.| means Euclidian norm
* v - scaled gradient vector, v[i]=g[i]*s[i]
* g - gradient
* s - scaling coefficients set by MinCGSetScale()
EpsF - >=0
The subroutine finishes its work if on k+1-th iteration
the condition |F(k+1)-F(k)|<=EpsF*max{|F(k)|,|F(k+1)|,1}
is satisfied.
EpsX - >=0
The subroutine finishes its work if on k+1-th iteration
the condition |v|<=EpsX is fulfilled, where:
* |.| means Euclidian norm
* v - scaled step vector, v[i]=dx[i]/s[i]
* dx - ste pvector, dx=X(k+1)-X(k)
* s - scaling coefficients set by MinCGSetScale()
MaxIts - maximum number of iterations. If MaxIts=0, the number of
iterations is unlimited.
Passing EpsG=0, EpsF=0, EpsX=0 and MaxIts=0 (simultaneously) will lead to
automatic stopping criterion selection (small EpsX).
-- ALGLIB --
Copyright 02.04.2010 by Bochkanov Sergey
*************************************************************************/
</div><div style='margin-top: 0; margin-bottom: 0;'><b>void</b> alglib::mincgsetcond(
mincgstate state,
<b>double</b> epsg,
<b>double</b> epsf,
<b>double</b> epsx,
ae_int_t maxits);
</div></pre>
<p align=left class=pagecontent><span class=inlineheader>Examples:</span> <a href='#example_mincg_d_1' class=nav>[1]</a> <a href='#example_mincg_d_2' class=nav>[2]</a> <a href='#example_mincg_numdiff' class=nav>[3]</a> </p>
<a name='sub_mincgsetgradientcheck'></a><h3 class=pageheader><code>mincgsetgradientcheck</code> function</h3>
<pre class=source>
<div style='color: navy; margin-top: 0; margin-bottom: 0;'>/*************************************************************************
This subroutine turns on verification of the user-supplied analytic
gradient:
* user calls this subroutine before optimization begins
* MinCGOptimize() is called
* prior to actual optimization, for each component of parameters being
optimized X[i] algorithm performs following steps:
* two trial steps are made to X[i]-TestStep*S[i] and X[i]+TestStep*S[i],
where X[i] is i-th component of the initial point and S[i] is a scale
of i-th parameter
* F(X) is evaluated at these trial points
* we perform one more evaluation in the middle point of the interval
* we build cubic model using function values and derivatives at trial
points and we compare its prediction with actual value in the middle
point
* in case difference between prediction and actual value is higher than
some predetermined threshold, algorithm stops with completion code -7;
Rep.VarIdx is set to index of the parameter with incorrect derivative.
* after verification is over, algorithm proceeds to the actual optimization.
NOTE 1: verification needs N (parameters count) gradient evaluations. It
is very costly and you should use it only for low dimensional
problems, when you want to be sure that you've correctly
calculated analytic derivatives. You should not use it in the
production code (unless you want to check derivatives provided by
some third party).
NOTE 2: you should carefully choose TestStep. Value which is too large
(so large that function behaviour is significantly non-cubic) will
lead to false alarms. You may use different step for different
parameters by means of setting scale with MinCGSetScale().
NOTE 3: this function may lead to false positives. In case it reports that
I-th derivative was calculated incorrectly, you may decrease test
step and try one more time - maybe your function changes too
sharply and your step is too large for such rapidly chanding
function.
INPUT PARAMETERS:
State - structure used to store algorithm state
TestStep - verification step:
* TestStep=0 turns verification off
* TestStep>0 activates verification
-- ALGLIB --
Copyright 31.05.2012 by Bochkanov Sergey
*************************************************************************/
</div><div style='margin-top: 0; margin-bottom: 0;'><b>void</b> alglib::mincgsetgradientcheck(mincgstate state, <b>double</b> teststep);
</div></pre>
<a name='sub_mincgsetprecdefault'></a><h3 class=pageheader><code>mincgsetprecdefault</code> function</h3>
<pre class=source>
<div style='color: navy; margin-top: 0; margin-bottom: 0;'>/*************************************************************************
Modification of the preconditioner: preconditioning is turned off.
INPUT PARAMETERS:
State - structure which stores algorithm state
NOTE: you can change preconditioner "on the fly", during algorithm
iterations.
-- ALGLIB --
Copyright 13.10.2010 by Bochkanov Sergey
*************************************************************************/
</div><div style='margin-top: 0; margin-bottom: 0;'><b>void</b> alglib::mincgsetprecdefault(mincgstate state);
</div></pre>
<a name='sub_mincgsetprecdiag'></a><h3 class=pageheader><code>mincgsetprecdiag</code> function</h3>
<pre class=source>
<div style='color: navy; margin-top: 0; margin-bottom: 0;'>/*************************************************************************
Modification of the preconditioner: diagonal of approximate Hessian is
used.
INPUT PARAMETERS:
State - structure which stores algorithm state
D - diagonal of the approximate Hessian, array[0..N-1],
(if larger, only leading N elements are used).
NOTE: you can change preconditioner "on the fly", during algorithm
iterations.
NOTE 2: D[i] should be positive. Exception will be thrown otherwise.
NOTE 3: you should pass diagonal of approximate Hessian - NOT ITS INVERSE.
-- ALGLIB --
Copyright 13.10.2010 by Bochkanov Sergey
*************************************************************************/
</div><div style='margin-top: 0; margin-bottom: 0;'><b>void</b> alglib::mincgsetprecdiag(mincgstate state, real_1d_array d);
</div></pre>
<a name='sub_mincgsetprecscale'></a><h3 class=pageheader><code>mincgsetprecscale</code> function</h3>
<pre class=source>
<div style='color: navy; margin-top: 0; margin-bottom: 0;'>/*************************************************************************
Modification of the preconditioner: scale-based diagonal preconditioning.
This preconditioning mode can be useful when you don't have approximate
diagonal of Hessian, but you know that your variables are badly scaled
(for example, one variable is in [1,10], and another in [1000,100000]),
and most part of the ill-conditioning comes from different scales of vars.
In this case simple scale-based preconditioner, with H[i] = 1/(s[i]^2),
can greatly improve convergence.
IMPRTANT: you should set scale of your variables with MinCGSetScale() call
(before or after MinCGSetPrecScale() call). Without knowledge of the scale
of your variables scale-based preconditioner will be just unit matrix.
INPUT PARAMETERS:
State - structure which stores algorithm state
NOTE: you can change preconditioner "on the fly", during algorithm
iterations.
-- ALGLIB --
Copyright 13.10.2010 by Bochkanov Sergey
*************************************************************************/
</div><div style='margin-top: 0; margin-bottom: 0;'><b>void</b> alglib::mincgsetprecscale(mincgstate state);
</div></pre>
<a name='sub_mincgsetscale'></a><h3 class=pageheader><code>mincgsetscale</code> function</h3>
<pre class=source>
<div style='color: navy; margin-top: 0; margin-bottom: 0;'>/*************************************************************************
This function sets scaling coefficients for CG optimizer.
ALGLIB optimizers use scaling matrices to test stopping conditions (step
size and gradient are scaled before comparison with tolerances). Scale of
the I-th variable is a translation invariant measure of:
a) "how large" the variable is
b) how large the step should be to make significant changes in the function
Scaling is also used by finite difference variant of CG optimizer - step
along I-th axis is equal to DiffStep*S[I].
In most optimizers (and in the CG too) scaling is NOT a form of
preconditioning. It just affects stopping conditions. You should set
preconditioner by separate call to one of the MinCGSetPrec...() functions.
There is special preconditioning mode, however, which uses scaling
coefficients to form diagonal preconditioning matrix. You can turn this
mode on, if you want. But you should understand that scaling is not the
same thing as preconditioning - these are two different, although related
forms of tuning solver.
INPUT PARAMETERS:
State - structure stores algorithm state
S - array[N], non-zero scaling coefficients
S[i] may be negative, sign doesn't matter.
-- ALGLIB --
Copyright 14.01.2011 by Bochkanov Sergey
*************************************************************************/
</div><div style='margin-top: 0; margin-bottom: 0;'><b>void</b> alglib::mincgsetscale(mincgstate state, real_1d_array s);
</div></pre>
<a name='sub_mincgsetstpmax'></a><h3 class=pageheader><code>mincgsetstpmax</code> function</h3>
<pre class=source>
<div style='color: navy; margin-top: 0; margin-bottom: 0;'>/*************************************************************************
This function sets maximum step length
INPUT PARAMETERS:
State - structure which stores algorithm state
StpMax - maximum step length, >=0. Set StpMax to 0.0, if you don't
want to limit step length.
Use this subroutine when you optimize target function which contains exp()
or other fast growing functions, and optimization algorithm makes too
large steps which leads to overflow. This function allows us to reject
steps that are too large (and therefore expose us to the possible
overflow) without actually calculating function value at the x+stp*d.
-- ALGLIB --
Copyright 02.04.2010 by Bochkanov Sergey
*************************************************************************/
</div><div style='margin-top: 0; margin-bottom: 0;'><b>void</b> alglib::mincgsetstpmax(mincgstate state, <b>double</b> stpmax);
</div></pre>
<a name='sub_mincgsetxrep'></a><h3 class=pageheader><code>mincgsetxrep</code> function</h3>
<pre class=source>
<div style='color: navy; margin-top: 0; margin-bottom: 0;'>/*************************************************************************
This function turns on/off reporting.
INPUT PARAMETERS:
State - structure which stores algorithm state
NeedXRep- whether iteration reports are needed or not
If NeedXRep is True, algorithm will call rep() callback function if it is
provided to MinCGOptimize().
-- ALGLIB --
Copyright 02.04.2010 by Bochkanov Sergey
*************************************************************************/
</div><div style='margin-top: 0; margin-bottom: 0;'><b>void</b> alglib::mincgsetxrep(mincgstate state, <b>bool</b> needxrep);
</div></pre>
<a name='sub_mincgsuggeststep'></a><h3 class=pageheader><code>mincgsuggeststep</code> function</h3>
<pre class=source>
<div style='color: navy; margin-top: 0; margin-bottom: 0;'>/*************************************************************************
This function allows to suggest initial step length to the CG algorithm.
Suggested step length is used as starting point for the line search. It
can be useful when you have badly scaled problem, i.e. when ||grad||
(which is used as initial estimate for the first step) is many orders of
magnitude different from the desired step.
Line search may fail on such problems without good estimate of initial
step length. Imagine, for example, problem with ||grad||=10^50 and desired
step equal to 0.1 Line search function will use 10^50 as initial step,
then it will decrease step length by 2 (up to 20 attempts) and will get
10^44, which is still too large.
This function allows us to tell than line search should be started from
some moderate step length, like 1.0, so algorithm will be able to detect
desired step length in a several searches.
Default behavior (when no step is suggested) is to use preconditioner, if
it is available, to generate initial estimate of step length.
This function influences only first iteration of algorithm. It should be
called between MinCGCreate/MinCGRestartFrom() call and MinCGOptimize call.
Suggested step is ignored if you have preconditioner.
INPUT PARAMETERS:
State - structure used to store algorithm state.
Stp - initial estimate of the step length.
Can be zero (no estimate).
-- ALGLIB --
Copyright 30.07.2010 by Bochkanov Sergey
*************************************************************************/
</div><div style='margin-top: 0; margin-bottom: 0;'><b>void</b> alglib::mincgsuggeststep(mincgstate state, <b>double</b> stp);
</div></pre>
<a name='example_mincg_d_1'></a><h3 class=pageheader>mincg_d_1 example</h3>
<pre class=source>
#include <font color=blue><b>"stdafx.h"</b></font>
#include <stdlib.h>
#include <stdio.h>
#include <math.h>
#include <font color=blue><b>"optimization.h"</b></font>
using namespace alglib;
<b>void</b> function1_grad(<b>const</b> real_1d_array &x, <b>double</b> &func, real_1d_array &grad, <b>void</b> *ptr)
{
<font color=navy>//</font>
<font color=navy>// this callback calculates f(x0,x1) = 100*(x0+3)^4 + (x1-3)^4</font>
<font color=navy>// and its derivatives df/d0 and df/dx1</font>
<font color=navy>//</font>
func = 100*pow(x[0]+3,4) + pow(x[1]-3,4);
grad[0] = 400*pow(x[0]+3,3);
grad[1] = 4*pow(x[1]-3,3);
}
<b>int</b> main(<b>int</b> argc, char **argv)
{
<font color=navy>//</font>
<font color=navy>// This example demonstrates minimization of f(x,y) = 100*(x+3)^4+(y-3)^4</font>
<font color=navy>// with nonlinear conjugate gradient method.</font>
<font color=navy>//</font>
real_1d_array x = <font color=blue><b>"[0,0]"</b></font>;
<b>double</b> epsg = 0.0000000001;
<b>double</b> epsf = 0;
<b>double</b> epsx = 0;
ae_int_t maxits = 0;
mincgstate state;
mincgreport rep;
mincgcreate(x, state);
mincgsetcond(state, epsg, epsf, epsx, maxits);
alglib::mincgoptimize(state, function1_grad);
mincgresults(state, x, rep);
printf(<font color=blue><b>"%d\n"</b></font>, <b>int</b>(rep.terminationtype)); <font color=navy>// EXPECTED: 4</font>
printf(<font color=blue><b>"%s\n"</b></font>, x.tostring(2).c_str()); <font color=navy>// EXPECTED: [-3,3]</font>
<b>return</b> 0;
}
</pre><a name='example_mincg_d_2'></a><h3 class=pageheader>mincg_d_2 example</h3>
<pre class=source>
#include <font color=blue><b>"stdafx.h"</b></font>
#include <stdlib.h>
#include <stdio.h>
#include <math.h>
#include <font color=blue><b>"optimization.h"</b></font>
using namespace alglib;
<b>void</b> function1_grad(<b>const</b> real_1d_array &x, <b>double</b> &func, real_1d_array &grad, <b>void</b> *ptr)
{
<font color=navy>//</font>
<font color=navy>// this callback calculates f(x0,x1) = 100*(x0+3)^4 + (x1-3)^4</font>
<font color=navy>// and its derivatives df/d0 and df/dx1</font>
<font color=navy>//</font>
func = 100*pow(x[0]+3,4) + pow(x[1]-3,4);
grad[0] = 400*pow(x[0]+3,3);
grad[1] = 4*pow(x[1]-3,3);
}
<b>int</b> main(<b>int</b> argc, char **argv)
{
<font color=navy>//</font>
<font color=navy>// This example demonstrates minimization of f(x,y) = 100*(x+3)^4+(y-3)^4</font>
<font color=navy>// with nonlinear conjugate gradient method.</font>
<font color=navy>//</font>
<font color=navy>// Several advanced techniques are demonstrated:</font>
<font color=navy>// * upper limit on step size</font>
<font color=navy>// * restart from new point</font>
<font color=navy>//</font>
real_1d_array x = <font color=blue><b>"[0,0]"</b></font>;
<b>double</b> epsg = 0.0000000001;
<b>double</b> epsf = 0;
<b>double</b> epsx = 0;
<b>double</b> stpmax = 0.1;
ae_int_t maxits = 0;
mincgstate state;
mincgreport rep;
<font color=navy>// first run</font>
mincgcreate(x, state);
mincgsetcond(state, epsg, epsf, epsx, maxits);
mincgsetstpmax(state, stpmax);
alglib::mincgoptimize(state, function1_grad);
mincgresults(state, x, rep);
printf(<font color=blue><b>"%s\n"</b></font>, x.tostring(2).c_str()); <font color=navy>// EXPECTED: [-3,3]</font>
<font color=navy>// second run - algorithm is restarted with mincgrestartfrom()</font>
x = <font color=blue><b>"[10,10]"</b></font>;
mincgrestartfrom(state, x);
alglib::mincgoptimize(state, function1_grad);
mincgresults(state, x, rep);
printf(<font color=blue><b>"%d\n"</b></font>, <b>int</b>(rep.terminationtype)); <font color=navy>// EXPECTED: 4</font>
printf(<font color=blue><b>"%s\n"</b></font>, x.tostring(2).c_str()); <font color=navy>// EXPECTED: [-3,3]</font>
<b>return</b> 0;
}
</pre><a name='example_mincg_ftrim'></a><h3 class=pageheader>mincg_ftrim example</h3>
<pre class=source>
#include <font color=blue><b>"stdafx.h"</b></font>
#include <stdlib.h>
#include <stdio.h>
#include <math.h>
#include <font color=blue><b>"optimization.h"</b></font>
using namespace alglib;
<b>void</b> s1_grad(<b>const</b> real_1d_array &x, <b>double</b> &func, real_1d_array &grad, <b>void</b> *ptr)
{
<font color=navy>//</font>
<font color=navy>// this callback calculates f(x) = (1+x)^(-0.2) + (1-x)^(-0.3) + 1000*x and its gradient.</font>
<font color=navy>//</font>
<font color=navy>// function is trimmed when we calculate it near the singular points or outside of the [-1,+1].</font>
<font color=navy>// Note that we <b>do</b> NOT calculate gradient in this case.</font>
<font color=navy>//</font>
<b>if</b>( (x[0]<=-0.999999999999) || (x[0]>=+0.999999999999) )
{
func = 1.0E+300;
<b>return</b>;
}
func = pow(1+x[0],-0.2) + pow(1-x[0],-0.3) + 1000*x[0];
grad[0] = -0.2*pow(1+x[0],-1.2) +0.3*pow(1-x[0],-1.3) + 1000;
}
<b>int</b> main(<b>int</b> argc, char **argv)
{
<font color=navy>//</font>
<font color=navy>// This example demonstrates minimization of f(x) = (1+x)^(-0.2) + (1-x)^(-0.3) + 1000*x.</font>
<font color=navy>// This function has singularities at the boundary of the [-1,+1], but technique called</font>
<font color=navy>// <font color=blue><b>"function trimming"</b></font> allows us to solve this optimization problem.</font>
<font color=navy>//</font>
<font color=navy>// See http://www.alglib.net/optimization/tipsandtricks.php#ftrimming <b>for</b> more information</font>
<font color=navy>// on this subject.</font>
<font color=navy>//</font>
real_1d_array x = <font color=blue><b>"[0]"</b></font>;
<b>double</b> epsg = 1.0e-6;
<b>double</b> epsf = 0;
<b>double</b> epsx = 0;
ae_int_t maxits = 0;
mincgstate state;
mincgreport rep;
mincgcreate(x, state);
mincgsetcond(state, epsg, epsf, epsx, maxits);
alglib::mincgoptimize(state, s1_grad);
mincgresults(state, x, rep);
printf(<font color=blue><b>"%s\n"</b></font>, x.tostring(5).c_str()); <font color=navy>// EXPECTED: [-0.99917305]</font>
<b>return</b> 0;
}
</pre><a name='example_mincg_numdiff'></a><h3 class=pageheader>mincg_numdiff example</h3>
<pre class=source>
#include <font color=blue><b>"stdafx.h"</b></font>
#include <stdlib.h>
#include <stdio.h>
#include <math.h>
#include <font color=blue><b>"optimization.h"</b></font>
using namespace alglib;
<b>void</b> function1_func(<b>const</b> real_1d_array &x, <b>double</b> &func, <b>void</b> *ptr)
{
<font color=navy>//</font>
<font color=navy>// this callback calculates f(x0,x1) = 100*(x0+3)^4 + (x1-3)^4</font>
<font color=navy>//</font>
func = 100*pow(x[0]+3,4) + pow(x[1]-3,4);
}
<b>int</b> main(<b>int</b> argc, char **argv)
{
<font color=navy>//</font>
<font color=navy>// This example demonstrates minimization of f(x,y) = 100*(x+3)^4+(y-3)^4</font>
<font color=navy>// using numerical differentiation to calculate gradient.</font>
<font color=navy>//</font>
real_1d_array x = <font color=blue><b>"[0,0]"</b></font>;
<b>double</b> epsg = 0.0000000001;
<b>double</b> epsf = 0;
<b>double</b> epsx = 0;
<b>double</b> diffstep = 1.0e-6;
ae_int_t maxits = 0;
mincgstate state;
mincgreport rep;
mincgcreatef(x, diffstep, state);
mincgsetcond(state, epsg, epsf, epsx, maxits);
alglib::mincgoptimize(state, function1_func);
mincgresults(state, x, rep);
printf(<font color=blue><b>"%d\n"</b></font>, <b>int</b>(rep.terminationtype)); <font color=navy>// EXPECTED: 4</font>
printf(<font color=blue><b>"%s\n"</b></font>, x.tostring(2).c_str()); <font color=navy>// EXPECTED: [-3,3]</font>
<b>return</b> 0;
}
</pre><a name=unit_mincomp></a><h2 class=pageheader><code>mincomp</code> subpackage</h2>
<div class=pagecontent>
<h3 class=pageheader>Classes</h3>
<a href='#struct_minasareport' class=toc>minasareport</a><br>
<a href='#struct_minasastate' class=toc>minasastate</a><br>
<h3 class=pageheader>Functions</h3>
<a href='#sub_minasacreate' class=toc>minasacreate</a><br>
<a href='#sub_minasaoptimize' class=toc>minasaoptimize</a><br>
<a href='#sub_minasarestartfrom' class=toc>minasarestartfrom</a><br>
<a href='#sub_minasaresults' class=toc>minasaresults</a><br>
<a href='#sub_minasaresultsbuf' class=toc>minasaresultsbuf</a><br>
<a href='#sub_minasasetalgorithm' class=toc>minasasetalgorithm</a><br>
<a href='#sub_minasasetcond' class=toc>minasasetcond</a><br>
<a href='#sub_minasasetstpmax' class=toc>minasasetstpmax</a><br>
<a href='#sub_minasasetxrep' class=toc>minasasetxrep</a><br>
<a href='#sub_minbleicsetbarrierdecay' class=toc>minbleicsetbarrierdecay</a><br>
<a href='#sub_minbleicsetbarrierwidth' class=toc>minbleicsetbarrierwidth</a><br>
<a href='#sub_minlbfgssetcholeskypreconditioner' class=toc>minlbfgssetcholeskypreconditioner</a><br>
<a href='#sub_minlbfgssetdefaultpreconditioner' class=toc>minlbfgssetdefaultpreconditioner</a><br>
<h3 class=pageheader>Examples</h3>
<table border=0 cellspacing=0 class='pagecontent'>
</table></div>
<a name='struct_minasareport'></a><h3 class=pageheader><code>minasareport</code> class</h3>
<pre class=source>
<div style='color: navy; margin-top: 0; margin-bottom: 0;'>/*************************************************************************
*************************************************************************/
</div><div style='margin-top: 0; margin-bottom: 0;'><b>class</b> minasareport
{
ae_int_t iterationscount;
ae_int_t nfev;
ae_int_t terminationtype;
ae_int_t activeconstraints;
};
</div></pre>
<a name='struct_minasastate'></a><h3 class=pageheader><code>minasastate</code> class</h3>
<pre class=source>
<div style='color: navy; margin-top: 0; margin-bottom: 0;'>/*************************************************************************
*************************************************************************/
</div><div style='margin-top: 0; margin-bottom: 0;'><b>class</b> minasastate
{
};
</div></pre>
<a name='sub_minasacreate'></a><h3 class=pageheader><code>minasacreate</code> function</h3>
<pre class=source>
<div style='color: navy; margin-top: 0; margin-bottom: 0;'>/*************************************************************************
Obsolete optimization algorithm.
Was replaced by MinBLEIC subpackage.
-- ALGLIB --
Copyright 25.03.2010 by Bochkanov Sergey
*************************************************************************/
</div><div style='margin-top: 0; margin-bottom: 0;'><b>void</b> alglib::minasacreate(
real_1d_array x,
real_1d_array bndl,
real_1d_array bndu,
minasastate& state);
<b>void</b> alglib::minasacreate(
ae_int_t n,
real_1d_array x,
real_1d_array bndl,
real_1d_array bndu,
minasastate& state);
</div></pre>
<a name='sub_minasaoptimize'></a><h3 class=pageheader><code>minasaoptimize</code> function</h3>
<pre class=source>
<div style='color: navy; margin-top: 0; margin-bottom: 0;'>/*************************************************************************
This family of functions is used to launcn iterations of nonlinear optimizer
These functions accept following parameters:
state - algorithm state
grad - callback which calculates function (or merit function)
value func and gradient grad at given point x
rep - optional callback which is called after each iteration
can be NULL
ptr - optional pointer which is passed to func/grad/hess/jac/rep
can be NULL
-- ALGLIB --
Copyright 20.03.2009 by Bochkanov Sergey
*************************************************************************/
</div><div style='margin-top: 0; margin-bottom: 0;'><b>void</b> minasaoptimize(minasastate &state,
<b>void</b> (*grad)(<b>const</b> real_1d_array &x, <b>double</b> &func, real_1d_array &grad, <b>void</b> *ptr),
<b>void</b> (*rep)(<b>const</b> real_1d_array &x, <b>double</b> func, <b>void</b> *ptr) = NULL,
<b>void</b> *ptr = NULL);
</div></pre>
<a name='sub_minasarestartfrom'></a><h3 class=pageheader><code>minasarestartfrom</code> function</h3>
<pre class=source>
<div style='color: navy; margin-top: 0; margin-bottom: 0;'>/*************************************************************************
Obsolete optimization algorithm.
Was replaced by MinBLEIC subpackage.
-- ALGLIB --
Copyright 30.07.2010 by Bochkanov Sergey
*************************************************************************/
</div><div style='margin-top: 0; margin-bottom: 0;'><b>void</b> alglib::minasarestartfrom(
minasastate state,
real_1d_array x,
real_1d_array bndl,
real_1d_array bndu);
</div></pre>
<a name='sub_minasaresults'></a><h3 class=pageheader><code>minasaresults</code> function</h3>
<pre class=source>
<div style='color: navy; margin-top: 0; margin-bottom: 0;'>/*************************************************************************
Obsolete optimization algorithm.
Was replaced by MinBLEIC subpackage.
-- ALGLIB --
Copyright 20.03.2009 by Bochkanov Sergey
*************************************************************************/
</div><div style='margin-top: 0; margin-bottom: 0;'><b>void</b> alglib::minasaresults(
minasastate state,
real_1d_array& x,
minasareport& rep);
</div></pre>
<a name='sub_minasaresultsbuf'></a><h3 class=pageheader><code>minasaresultsbuf</code> function</h3>
<pre class=source>
<div style='color: navy; margin-top: 0; margin-bottom: 0;'>/*************************************************************************
Obsolete optimization algorithm.
Was replaced by MinBLEIC subpackage.
-- ALGLIB --
Copyright 20.03.2009 by Bochkanov Sergey
*************************************************************************/
</div><div style='margin-top: 0; margin-bottom: 0;'><b>void</b> alglib::minasaresultsbuf(
minasastate state,
real_1d_array& x,
minasareport& rep);
</div></pre>
<a name='sub_minasasetalgorithm'></a><h3 class=pageheader><code>minasasetalgorithm</code> function</h3>
<pre class=source>
<div style='color: navy; margin-top: 0; margin-bottom: 0;'>/*************************************************************************
Obsolete optimization algorithm.
Was replaced by MinBLEIC subpackage.
-- ALGLIB --
Copyright 02.04.2010 by Bochkanov Sergey
*************************************************************************/
</div><div style='margin-top: 0; margin-bottom: 0;'><b>void</b> alglib::minasasetalgorithm(minasastate state, ae_int_t algotype);
</div></pre>
<a name='sub_minasasetcond'></a><h3 class=pageheader><code>minasasetcond</code> function</h3>
<pre class=source>
<div style='color: navy; margin-top: 0; margin-bottom: 0;'>/*************************************************************************
Obsolete optimization algorithm.
Was replaced by MinBLEIC subpackage.
-- ALGLIB --
Copyright 02.04.2010 by Bochkanov Sergey
*************************************************************************/
</div><div style='margin-top: 0; margin-bottom: 0;'><b>void</b> alglib::minasasetcond(
minasastate state,
<b>double</b> epsg,
<b>double</b> epsf,
<b>double</b> epsx,
ae_int_t maxits);
</div></pre>
<a name='sub_minasasetstpmax'></a><h3 class=pageheader><code>minasasetstpmax</code> function</h3>
<pre class=source>
<div style='color: navy; margin-top: 0; margin-bottom: 0;'>/*************************************************************************
Obsolete optimization algorithm.
Was replaced by MinBLEIC subpackage.
-- ALGLIB --
Copyright 02.04.2010 by Bochkanov Sergey
*************************************************************************/
</div><div style='margin-top: 0; margin-bottom: 0;'><b>void</b> alglib::minasasetstpmax(minasastate state, <b>double</b> stpmax);
</div></pre>
<a name='sub_minasasetxrep'></a><h3 class=pageheader><code>minasasetxrep</code> function</h3>
<pre class=source>
<div style='color: navy; margin-top: 0; margin-bottom: 0;'>/*************************************************************************
Obsolete optimization algorithm.
Was replaced by MinBLEIC subpackage.
-- ALGLIB --
Copyright 02.04.2010 by Bochkanov Sergey
*************************************************************************/
</div><div style='margin-top: 0; margin-bottom: 0;'><b>void</b> alglib::minasasetxrep(minasastate state, <b>bool</b> needxrep);
</div></pre>
<a name='sub_minbleicsetbarrierdecay'></a><h3 class=pageheader><code>minbleicsetbarrierdecay</code> function</h3>
<pre class=source>
<div style='color: navy; margin-top: 0; margin-bottom: 0;'>/*************************************************************************
This is obsolete function which was used by previous version of the BLEIC
optimizer. It does nothing in the current version of BLEIC.
-- ALGLIB --
Copyright 28.11.2010 by Bochkanov Sergey
*************************************************************************/
</div><div style='margin-top: 0; margin-bottom: 0;'><b>void</b> alglib::minbleicsetbarrierdecay(minbleicstate state, <b>double</b> mudecay);
</div></pre>
<a name='sub_minbleicsetbarrierwidth'></a><h3 class=pageheader><code>minbleicsetbarrierwidth</code> function</h3>
<pre class=source>
<div style='color: navy; margin-top: 0; margin-bottom: 0;'>/*************************************************************************
This is obsolete function which was used by previous version of the BLEIC
optimizer. It does nothing in the current version of BLEIC.
-- ALGLIB --
Copyright 28.11.2010 by Bochkanov Sergey
*************************************************************************/
</div><div style='margin-top: 0; margin-bottom: 0;'><b>void</b> alglib::minbleicsetbarrierwidth(minbleicstate state, <b>double</b> mu);
</div></pre>
<a name='sub_minlbfgssetcholeskypreconditioner'></a><h3 class=pageheader><code>minlbfgssetcholeskypreconditioner</code> function</h3>
<pre class=source>
<div style='color: navy; margin-top: 0; margin-bottom: 0;'>/*************************************************************************
Obsolete function, use MinLBFGSSetCholeskyPreconditioner() instead.
-- ALGLIB --
Copyright 13.10.2010 by Bochkanov Sergey
*************************************************************************/
</div><div style='margin-top: 0; margin-bottom: 0;'><b>void</b> alglib::minlbfgssetcholeskypreconditioner(
minlbfgsstate state,
real_2d_array p,
<b>bool</b> isupper);
</div></pre>
<a name='sub_minlbfgssetdefaultpreconditioner'></a><h3 class=pageheader><code>minlbfgssetdefaultpreconditioner</code> function</h3>
<pre class=source>
<div style='color: navy; margin-top: 0; margin-bottom: 0;'>/*************************************************************************
Obsolete function, use MinLBFGSSetPrecDefault() instead.
-- ALGLIB --
Copyright 13.10.2010 by Bochkanov Sergey
*************************************************************************/
</div><div style='margin-top: 0; margin-bottom: 0;'><b>void</b> alglib::minlbfgssetdefaultpreconditioner(minlbfgsstate state);
</div></pre>
<a name=unit_minlbfgs></a><h2 class=pageheader><code>minlbfgs</code> subpackage</h2>
<div class=pagecontent>
<h3 class=pageheader>Classes</h3>
<a href='#struct_minlbfgsreport' class=toc>minlbfgsreport</a><br>
<a href='#struct_minlbfgsstate' class=toc>minlbfgsstate</a><br>
<h3 class=pageheader>Functions</h3>
<a href='#sub_minlbfgscreate' class=toc>minlbfgscreate</a><br>
<a href='#sub_minlbfgscreatef' class=toc>minlbfgscreatef</a><br>
<a href='#sub_minlbfgsoptimize' class=toc>minlbfgsoptimize</a><br>
<a href='#sub_minlbfgsrequesttermination' class=toc>minlbfgsrequesttermination</a><br>
<a href='#sub_minlbfgsrestartfrom' class=toc>minlbfgsrestartfrom</a><br>
<a href='#sub_minlbfgsresults' class=toc>minlbfgsresults</a><br>
<a href='#sub_minlbfgsresultsbuf' class=toc>minlbfgsresultsbuf</a><br>
<a href='#sub_minlbfgssetcond' class=toc>minlbfgssetcond</a><br>
<a href='#sub_minlbfgssetgradientcheck' class=toc>minlbfgssetgradientcheck</a><br>
<a href='#sub_minlbfgssetpreccholesky' class=toc>minlbfgssetpreccholesky</a><br>
<a href='#sub_minlbfgssetprecdefault' class=toc>minlbfgssetprecdefault</a><br>
<a href='#sub_minlbfgssetprecdiag' class=toc>minlbfgssetprecdiag</a><br>
<a href='#sub_minlbfgssetprecscale' class=toc>minlbfgssetprecscale</a><br>
<a href='#sub_minlbfgssetscale' class=toc>minlbfgssetscale</a><br>
<a href='#sub_minlbfgssetstpmax' class=toc>minlbfgssetstpmax</a><br>
<a href='#sub_minlbfgssetxrep' class=toc>minlbfgssetxrep</a><br>
<h3 class=pageheader>Examples</h3>
<table border=0 cellspacing=0 class='pagecontent'>
<tr align=left valign=top><td><a href='#example_minlbfgs_d_1' class=toc>minlbfgs_d_1</a></td><td width=15> </td><td>Nonlinear optimization by L-BFGS</td></tr>
<tr align=left valign=top><td><a href='#example_minlbfgs_d_2' class=toc>minlbfgs_d_2</a></td><td width=15> </td><td>Nonlinear optimization with additional settings and restarts</td></tr>
<tr align=left valign=top><td><a href='#example_minlbfgs_ftrim' class=toc>minlbfgs_ftrim</a></td><td width=15> </td><td>Nonlinear optimization by LBFGS, function with singularities</td></tr>
<tr align=left valign=top><td><a href='#example_minlbfgs_numdiff' class=toc>minlbfgs_numdiff</a></td><td width=15> </td><td>Nonlinear optimization by L-BFGS with numerical differentiation</td></tr>
</table></div>
<a name='struct_minlbfgsreport'></a><h3 class=pageheader><code>minlbfgsreport</code> class</h3>
<pre class=source>
<div style='color: navy; margin-top: 0; margin-bottom: 0;'>/*************************************************************************
This structure stores optimization report:
* IterationsCount total number of inner iterations
* NFEV number of gradient evaluations
* TerminationType termination type (see below)
TERMINATION CODES
TerminationType field contains completion code, which can be:
-8 internal integrity control detected infinite or NAN values in
function/gradient. Abnormal termination signalled.
-7 gradient verification failed.
See MinLBFGSSetGradientCheck() for more information.
1 relative function improvement is no more than EpsF.
2 relative step is no more than EpsX.
4 gradient norm is no more than EpsG
5 MaxIts steps was taken
7 stopping conditions are too stringent,
further improvement is impossible,
X contains best point found so far.
8 terminated by user who called minlbfgsrequesttermination().
X contains point which was "current accepted" when termination
request was submitted.
Other fields of this structure are not documented and should not be used!
*************************************************************************/
</div><div style='margin-top: 0; margin-bottom: 0;'><b>class</b> minlbfgsreport
{
ae_int_t iterationscount;
ae_int_t nfev;
ae_int_t varidx;
ae_int_t terminationtype;
};
</div></pre>
<a name='struct_minlbfgsstate'></a><h3 class=pageheader><code>minlbfgsstate</code> class</h3>
<pre class=source>
<div style='color: navy; margin-top: 0; margin-bottom: 0;'>/*************************************************************************
*************************************************************************/
</div><div style='margin-top: 0; margin-bottom: 0;'><b>class</b> minlbfgsstate
{
};
</div></pre>
<a name='sub_minlbfgscreate'></a><h3 class=pageheader><code>minlbfgscreate</code> function</h3>
<pre class=source>
<div style='color: navy; margin-top: 0; margin-bottom: 0;'>/*************************************************************************
LIMITED MEMORY BFGS METHOD FOR LARGE SCALE OPTIMIZATION
DESCRIPTION:
The subroutine minimizes function F(x) of N arguments by using a quasi-
Newton method (LBFGS scheme) which is optimized to use a minimum amount
of memory.
The subroutine generates the approximation of an inverse Hessian matrix by
using information about the last M steps of the algorithm (instead of N).
It lessens a required amount of memory from a value of order N^2 to a
value of order 2*N*M.
REQUIREMENTS:
Algorithm will request following information during its operation:
* function value F and its gradient G (simultaneously) at given point X
USAGE:
1. User initializes algorithm state with MinLBFGSCreate() call
2. User tunes solver parameters with MinLBFGSSetCond() MinLBFGSSetStpMax()
and other functions
3. User calls MinLBFGSOptimize() function which takes algorithm state and
pointer (delegate, etc.) to callback function which calculates F/G.
4. User calls MinLBFGSResults() to get solution
5. Optionally user may call MinLBFGSRestartFrom() to solve another problem
with same N/M but another starting point and/or another function.
MinLBFGSRestartFrom() allows to reuse already initialized structure.
INPUT PARAMETERS:
N - problem dimension. N>0
M - number of corrections in the BFGS scheme of Hessian
approximation update. Recommended value: 3<=M<=7. The smaller
value causes worse convergence, the bigger will not cause a
considerably better convergence, but will cause a fall in the
performance. M<=N.
X - initial solution approximation, array[0..N-1].
OUTPUT PARAMETERS:
State - structure which stores algorithm state
NOTES:
1. you may tune stopping conditions with MinLBFGSSetCond() function
2. if target function contains exp() or other fast growing functions, and
optimization algorithm makes too large steps which leads to overflow,
use MinLBFGSSetStpMax() function to bound algorithm's steps. However,
L-BFGS rarely needs such a tuning.
-- ALGLIB --
Copyright 02.04.2010 by Bochkanov Sergey
*************************************************************************/
</div><div style='margin-top: 0; margin-bottom: 0;'><b>void</b> alglib::minlbfgscreate(
ae_int_t m,
real_1d_array x,
minlbfgsstate& state);
<b>void</b> alglib::minlbfgscreate(
ae_int_t n,
ae_int_t m,
real_1d_array x,
minlbfgsstate& state);
</div></pre>
<p align=left class=pagecontent><span class=inlineheader>Examples:</span> <a href='#example_minlbfgs_d_1' class=nav>[1]</a> <a href='#example_minlbfgs_d_2' class=nav>[2]</a> <a href='#example_minlbfgs_ftrim' class=nav>[3]</a> </p>
<a name='sub_minlbfgscreatef'></a><h3 class=pageheader><code>minlbfgscreatef</code> function</h3>
<pre class=source>
<div style='color: navy; margin-top: 0; margin-bottom: 0;'>/*************************************************************************
The subroutine is finite difference variant of MinLBFGSCreate(). It uses
finite differences in order to differentiate target function.
Description below contains information which is specific to this function
only. We recommend to read comments on MinLBFGSCreate() in order to get
more information about creation of LBFGS optimizer.
INPUT PARAMETERS:
N - problem dimension, N>0:
* if given, only leading N elements of X are used
* if not given, automatically determined from size of X
M - number of corrections in the BFGS scheme of Hessian
approximation update. Recommended value: 3<=M<=7. The smaller
value causes worse convergence, the bigger will not cause a
considerably better convergence, but will cause a fall in the
performance. M<=N.
X - starting point, array[0..N-1].
DiffStep- differentiation step, >0
OUTPUT PARAMETERS:
State - structure which stores algorithm state
NOTES:
1. algorithm uses 4-point central formula for differentiation.
2. differentiation step along I-th axis is equal to DiffStep*S[I] where
S[] is scaling vector which can be set by MinLBFGSSetScale() call.
3. we recommend you to use moderate values of differentiation step. Too
large step will result in too large truncation errors, while too small
step will result in too large numerical errors. 1.0E-6 can be good
value to start with.
4. Numerical differentiation is very inefficient - one gradient
calculation needs 4*N function evaluations. This function will work for
any N - either small (1...10), moderate (10...100) or large (100...).
However, performance penalty will be too severe for any N's except for
small ones.
We should also say that code which relies on numerical differentiation
is less robust and precise. LBFGS needs exact gradient values.
Imprecise gradient may slow down convergence, especially on highly
nonlinear problems.
Thus we recommend to use this function for fast prototyping on small-
dimensional problems only, and to implement analytical gradient as soon
as possible.
-- ALGLIB --
Copyright 16.05.2011 by Bochkanov Sergey
*************************************************************************/
</div><div style='margin-top: 0; margin-bottom: 0;'><b>void</b> alglib::minlbfgscreatef(
ae_int_t m,
real_1d_array x,
<b>double</b> diffstep,
minlbfgsstate& state);
<b>void</b> alglib::minlbfgscreatef(
ae_int_t n,
ae_int_t m,
real_1d_array x,
<b>double</b> diffstep,
minlbfgsstate& state);
</div></pre>
<p align=left class=pagecontent><span class=inlineheader>Examples:</span> <a href='#example_minlbfgs_numdiff' class=nav>[1]</a> </p>
<a name='sub_minlbfgsoptimize'></a><h3 class=pageheader><code>minlbfgsoptimize</code> function</h3>
<pre class=source>
<div style='color: navy; margin-top: 0; margin-bottom: 0;'>/*************************************************************************
This family of functions is used to launcn iterations of nonlinear optimizer
These functions accept following parameters:
state - algorithm state
func - callback which calculates function (or merit function)
value func at given point x
grad - callback which calculates function (or merit function)
value func and gradient grad at given point x
rep - optional callback which is called after each iteration
can be NULL
ptr - optional pointer which is passed to func/grad/hess/jac/rep
can be NULL
NOTES:
1. This function has two different implementations: one which uses exact
(analytical) user-supplied gradient, and one which uses function value
only and numerically differentiates function in order to obtain
gradient.
Depending on the specific function used to create optimizer object
(either MinLBFGSCreate() for analytical gradient or MinLBFGSCreateF()
for numerical differentiation) you should choose appropriate variant of
MinLBFGSOptimize() - one which accepts function AND gradient or one
which accepts function ONLY.
Be careful to choose variant of MinLBFGSOptimize() which corresponds to
your optimization scheme! Table below lists different combinations of
callback (function/gradient) passed to MinLBFGSOptimize() and specific
function used to create optimizer.
| USER PASSED TO MinLBFGSOptimize()
CREATED WITH | function only | function and gradient
------------------------------------------------------------
MinLBFGSCreateF() | work FAIL
MinLBFGSCreate() | FAIL work
Here "FAIL" denotes inappropriate combinations of optimizer creation
function and MinLBFGSOptimize() version. Attemps to use such
combination (for example, to create optimizer with MinLBFGSCreateF() and
to pass gradient information to MinCGOptimize()) will lead to exception
being thrown. Either you did not pass gradient when it WAS needed or
you passed gradient when it was NOT needed.
-- ALGLIB --
Copyright 20.03.2009 by Bochkanov Sergey
*************************************************************************/
</div><div style='margin-top: 0; margin-bottom: 0;'><b>void</b> minlbfgsoptimize(minlbfgsstate &state,
<b>void</b> (*func)(<b>const</b> real_1d_array &x, <b>double</b> &func, <b>void</b> *ptr),
<b>void</b> (*rep)(<b>const</b> real_1d_array &x, <b>double</b> func, <b>void</b> *ptr) = NULL,
<b>void</b> *ptr = NULL);
<b>void</b> minlbfgsoptimize(minlbfgsstate &state,
<b>void</b> (*grad)(<b>const</b> real_1d_array &x, <b>double</b> &func, real_1d_array &grad, <b>void</b> *ptr),
<b>void</b> (*rep)(<b>const</b> real_1d_array &x, <b>double</b> func, <b>void</b> *ptr) = NULL,
<b>void</b> *ptr = NULL);
</div></pre>
<p align=left class=pagecontent><span class=inlineheader>Examples:</span> <a href='#example_minlbfgs_d_1' class=nav>[1]</a> <a href='#example_minlbfgs_d_2' class=nav>[2]</a> <a href='#example_minlbfgs_numdiff' class=nav>[3]</a> <a href='#example_minlbfgs_ftrim' class=nav>[4]</a> </p>
<a name='sub_minlbfgsrequesttermination'></a><h3 class=pageheader><code>minlbfgsrequesttermination</code> function</h3>
<pre class=source>
<div style='color: navy; margin-top: 0; margin-bottom: 0;'>/*************************************************************************
This subroutine submits request for termination of running optimizer. It
should be called from user-supplied callback when user decides that it is
time to "smoothly" terminate optimization process. As result, optimizer
stops at point which was "current accepted" when termination request was
submitted and returns error code 8 (successful termination).
INPUT PARAMETERS:
State - optimizer structure
NOTE: after request for termination optimizer may perform several
additional calls to user-supplied callbacks. It does NOT guarantee
to stop immediately - it just guarantees that these additional calls
will be discarded later.
NOTE: calling this function on optimizer which is NOT running will have no
effect.
NOTE: multiple calls to this function are possible. First call is counted,
subsequent calls are silently ignored.
-- ALGLIB --
Copyright 08.10.2014 by Bochkanov Sergey
*************************************************************************/
</div><div style='margin-top: 0; margin-bottom: 0;'><b>void</b> alglib::minlbfgsrequesttermination(minlbfgsstate state);
</div></pre>
<a name='sub_minlbfgsrestartfrom'></a><h3 class=pageheader><code>minlbfgsrestartfrom</code> function</h3>
<pre class=source>
<div style='color: navy; margin-top: 0; margin-bottom: 0;'>/*************************************************************************
This subroutine restarts LBFGS algorithm from new point. All optimization
parameters are left unchanged.
This function allows to solve multiple optimization problems (which
must have same number of dimensions) without object reallocation penalty.
INPUT PARAMETERS:
State - structure used to store algorithm state
X - new starting point.
-- ALGLIB --
Copyright 30.07.2010 by Bochkanov Sergey
*************************************************************************/
</div><div style='margin-top: 0; margin-bottom: 0;'><b>void</b> alglib::minlbfgsrestartfrom(minlbfgsstate state, real_1d_array x);
</div></pre>
<p align=left class=pagecontent><span class=inlineheader>Examples:</span> <a href='#example_minlbfgs_d_2' class=nav>[1]</a> </p>
<a name='sub_minlbfgsresults'></a><h3 class=pageheader><code>minlbfgsresults</code> function</h3>
<pre class=source>
<div style='color: navy; margin-top: 0; margin-bottom: 0;'>/*************************************************************************
L-BFGS algorithm results
INPUT PARAMETERS:
State - algorithm state
OUTPUT PARAMETERS:
X - array[0..N-1], solution
Rep - optimization report:
* Rep.TerminationType completetion code:
* -8 internal integrity control detected infinite
or NAN values in function/gradient. Abnormal
termination signalled.
* -7 gradient verification failed.
See MinLBFGSSetGradientCheck() for more information.
* -2 rounding errors prevent further improvement.
X contains best point found.
* -1 incorrect parameters were specified
* 1 relative function improvement is no more than
EpsF.
* 2 relative step is no more than EpsX.
* 4 gradient norm is no more than EpsG
* 5 MaxIts steps was taken
* 7 stopping conditions are too stringent,
further improvement is impossible
* 8 terminated by user who called minlbfgsrequesttermination().
X contains point which was "current accepted" when
termination request was submitted.
* Rep.IterationsCount contains iterations count
* NFEV countains number of function calculations
-- ALGLIB --
Copyright 02.04.2010 by Bochkanov Sergey
*************************************************************************/
</div><div style='margin-top: 0; margin-bottom: 0;'><b>void</b> alglib::minlbfgsresults(
minlbfgsstate state,
real_1d_array& x,
minlbfgsreport& rep);
</div></pre>
<p align=left class=pagecontent><span class=inlineheader>Examples:</span> <a href='#example_minlbfgs_d_1' class=nav>[1]</a> <a href='#example_minlbfgs_d_2' class=nav>[2]</a> <a href='#example_minlbfgs_numdiff' class=nav>[3]</a> <a href='#example_minlbfgs_ftrim' class=nav>[4]</a> </p>
<a name='sub_minlbfgsresultsbuf'></a><h3 class=pageheader><code>minlbfgsresultsbuf</code> function</h3>
<pre class=source>
<div style='color: navy; margin-top: 0; margin-bottom: 0;'>/*************************************************************************
L-BFGS algorithm results
Buffered implementation of MinLBFGSResults which uses pre-allocated buffer
to store X[]. If buffer size is too small, it resizes buffer. It is
intended to be used in the inner cycles of performance critical algorithms
where array reallocation penalty is too large to be ignored.
-- ALGLIB --
Copyright 20.08.2010 by Bochkanov Sergey
*************************************************************************/
</div><div style='margin-top: 0; margin-bottom: 0;'><b>void</b> alglib::minlbfgsresultsbuf(
minlbfgsstate state,
real_1d_array& x,
minlbfgsreport& rep);
</div></pre>
<a name='sub_minlbfgssetcond'></a><h3 class=pageheader><code>minlbfgssetcond</code> function</h3>
<pre class=source>
<div style='color: navy; margin-top: 0; margin-bottom: 0;'>/*************************************************************************
This function sets stopping conditions for L-BFGS optimization algorithm.
INPUT PARAMETERS:
State - structure which stores algorithm state
EpsG - >=0
The subroutine finishes its work if the condition
|v|<EpsG is satisfied, where:
* |.| means Euclidian norm
* v - scaled gradient vector, v[i]=g[i]*s[i]
* g - gradient
* s - scaling coefficients set by MinLBFGSSetScale()
EpsF - >=0
The subroutine finishes its work if on k+1-th iteration
the condition |F(k+1)-F(k)|<=EpsF*max{|F(k)|,|F(k+1)|,1}
is satisfied.
EpsX - >=0
The subroutine finishes its work if on k+1-th iteration
the condition |v|<=EpsX is fulfilled, where:
* |.| means Euclidian norm
* v - scaled step vector, v[i]=dx[i]/s[i]
* dx - ste pvector, dx=X(k+1)-X(k)
* s - scaling coefficients set by MinLBFGSSetScale()
MaxIts - maximum number of iterations. If MaxIts=0, the number of
iterations is unlimited.
Passing EpsG=0, EpsF=0, EpsX=0 and MaxIts=0 (simultaneously) will lead to
automatic stopping criterion selection (small EpsX).
-- ALGLIB --
Copyright 02.04.2010 by Bochkanov Sergey
*************************************************************************/
</div><div style='margin-top: 0; margin-bottom: 0;'><b>void</b> alglib::minlbfgssetcond(
minlbfgsstate state,
<b>double</b> epsg,
<b>double</b> epsf,
<b>double</b> epsx,
ae_int_t maxits);
</div></pre>
<p align=left class=pagecontent><span class=inlineheader>Examples:</span> <a href='#example_minlbfgs_d_1' class=nav>[1]</a> <a href='#example_minlbfgs_d_2' class=nav>[2]</a> <a href='#example_minlbfgs_numdiff' class=nav>[3]</a> </p>
<a name='sub_minlbfgssetgradientcheck'></a><h3 class=pageheader><code>minlbfgssetgradientcheck</code> function</h3>
<pre class=source>
<div style='color: navy; margin-top: 0; margin-bottom: 0;'>/*************************************************************************
This subroutine turns on verification of the user-supplied analytic
gradient:
* user calls this subroutine before optimization begins
* MinLBFGSOptimize() is called
* prior to actual optimization, for each component of parameters being
optimized X[i] algorithm performs following steps:
* two trial steps are made to X[i]-TestStep*S[i] and X[i]+TestStep*S[i],
where X[i] is i-th component of the initial point and S[i] is a scale
of i-th parameter
* if needed, steps are bounded with respect to constraints on X[]
* F(X) is evaluated at these trial points
* we perform one more evaluation in the middle point of the interval
* we build cubic model using function values and derivatives at trial
points and we compare its prediction with actual value in the middle
point
* in case difference between prediction and actual value is higher than
some predetermined threshold, algorithm stops with completion code -7;
Rep.VarIdx is set to index of the parameter with incorrect derivative.
* after verification is over, algorithm proceeds to the actual optimization.
NOTE 1: verification needs N (parameters count) gradient evaluations. It
is very costly and you should use it only for low dimensional
problems, when you want to be sure that you've correctly
calculated analytic derivatives. You should not use it in the
production code (unless you want to check derivatives provided by
some third party).
NOTE 2: you should carefully choose TestStep. Value which is too large
(so large that function behaviour is significantly non-cubic) will
lead to false alarms. You may use different step for different
parameters by means of setting scale with MinLBFGSSetScale().
NOTE 3: this function may lead to false positives. In case it reports that
I-th derivative was calculated incorrectly, you may decrease test
step and try one more time - maybe your function changes too
sharply and your step is too large for such rapidly chanding
function.
INPUT PARAMETERS:
State - structure used to store algorithm state
TestStep - verification step:
* TestStep=0 turns verification off
* TestStep>0 activates verification
-- ALGLIB --
Copyright 24.05.2012 by Bochkanov Sergey
*************************************************************************/
</div><div style='margin-top: 0; margin-bottom: 0;'><b>void</b> alglib::minlbfgssetgradientcheck(
minlbfgsstate state,
<b>double</b> teststep);
</div></pre>
<a name='sub_minlbfgssetpreccholesky'></a><h3 class=pageheader><code>minlbfgssetpreccholesky</code> function</h3>
<pre class=source>
<div style='color: navy; margin-top: 0; margin-bottom: 0;'>/*************************************************************************
Modification of the preconditioner: Cholesky factorization of approximate
Hessian is used.
INPUT PARAMETERS:
State - structure which stores algorithm state
P - triangular preconditioner, Cholesky factorization of
the approximate Hessian. array[0..N-1,0..N-1],
(if larger, only leading N elements are used).
IsUpper - whether upper or lower triangle of P is given
(other triangle is not referenced)
After call to this function preconditioner is changed to P (P is copied
into the internal buffer).
NOTE: you can change preconditioner "on the fly", during algorithm
iterations.
NOTE 2: P should be nonsingular. Exception will be thrown otherwise.
-- ALGLIB --
Copyright 13.10.2010 by Bochkanov Sergey
*************************************************************************/
</div><div style='margin-top: 0; margin-bottom: 0;'><b>void</b> alglib::minlbfgssetpreccholesky(
minlbfgsstate state,
real_2d_array p,
<b>bool</b> isupper);
</div></pre>
<a name='sub_minlbfgssetprecdefault'></a><h3 class=pageheader><code>minlbfgssetprecdefault</code> function</h3>
<pre class=source>
<div style='color: navy; margin-top: 0; margin-bottom: 0;'>/*************************************************************************
Modification of the preconditioner: default preconditioner (simple
scaling, same for all elements of X) is used.
INPUT PARAMETERS:
State - structure which stores algorithm state
NOTE: you can change preconditioner "on the fly", during algorithm
iterations.
-- ALGLIB --
Copyright 13.10.2010 by Bochkanov Sergey
*************************************************************************/
</div><div style='margin-top: 0; margin-bottom: 0;'><b>void</b> alglib::minlbfgssetprecdefault(minlbfgsstate state);
</div></pre>
<a name='sub_minlbfgssetprecdiag'></a><h3 class=pageheader><code>minlbfgssetprecdiag</code> function</h3>
<pre class=source>
<div style='color: navy; margin-top: 0; margin-bottom: 0;'>/*************************************************************************
Modification of the preconditioner: diagonal of approximate Hessian is
used.
INPUT PARAMETERS:
State - structure which stores algorithm state
D - diagonal of the approximate Hessian, array[0..N-1],
(if larger, only leading N elements are used).
NOTE: you can change preconditioner "on the fly", during algorithm
iterations.
NOTE 2: D[i] should be positive. Exception will be thrown otherwise.
NOTE 3: you should pass diagonal of approximate Hessian - NOT ITS INVERSE.
-- ALGLIB --
Copyright 13.10.2010 by Bochkanov Sergey
*************************************************************************/
</div><div style='margin-top: 0; margin-bottom: 0;'><b>void</b> alglib::minlbfgssetprecdiag(minlbfgsstate state, real_1d_array d);
</div></pre>
<a name='sub_minlbfgssetprecscale'></a><h3 class=pageheader><code>minlbfgssetprecscale</code> function</h3>
<pre class=source>
<div style='color: navy; margin-top: 0; margin-bottom: 0;'>/*************************************************************************
Modification of the preconditioner: scale-based diagonal preconditioning.
This preconditioning mode can be useful when you don't have approximate
diagonal of Hessian, but you know that your variables are badly scaled
(for example, one variable is in [1,10], and another in [1000,100000]),
and most part of the ill-conditioning comes from different scales of vars.
In this case simple scale-based preconditioner, with H[i] = 1/(s[i]^2),
can greatly improve convergence.
IMPRTANT: you should set scale of your variables with MinLBFGSSetScale()
call (before or after MinLBFGSSetPrecScale() call). Without knowledge of
the scale of your variables scale-based preconditioner will be just unit
matrix.
INPUT PARAMETERS:
State - structure which stores algorithm state
-- ALGLIB --
Copyright 13.10.2010 by Bochkanov Sergey
*************************************************************************/
</div><div style='margin-top: 0; margin-bottom: 0;'><b>void</b> alglib::minlbfgssetprecscale(minlbfgsstate state);
</div></pre>
<a name='sub_minlbfgssetscale'></a><h3 class=pageheader><code>minlbfgssetscale</code> function</h3>
<pre class=source>
<div style='color: navy; margin-top: 0; margin-bottom: 0;'>/*************************************************************************
This function sets scaling coefficients for LBFGS optimizer.
ALGLIB optimizers use scaling matrices to test stopping conditions (step
size and gradient are scaled before comparison with tolerances). Scale of
the I-th variable is a translation invariant measure of:
a) "how large" the variable is
b) how large the step should be to make significant changes in the function
Scaling is also used by finite difference variant of the optimizer - step
along I-th axis is equal to DiffStep*S[I].
In most optimizers (and in the LBFGS too) scaling is NOT a form of
preconditioning. It just affects stopping conditions. You should set
preconditioner by separate call to one of the MinLBFGSSetPrec...()
functions.
There is special preconditioning mode, however, which uses scaling
coefficients to form diagonal preconditioning matrix. You can turn this
mode on, if you want. But you should understand that scaling is not the
same thing as preconditioning - these are two different, although related
forms of tuning solver.
INPUT PARAMETERS:
State - structure stores algorithm state
S - array[N], non-zero scaling coefficients
S[i] may be negative, sign doesn't matter.
-- ALGLIB --
Copyright 14.01.2011 by Bochkanov Sergey
*************************************************************************/
</div><div style='margin-top: 0; margin-bottom: 0;'><b>void</b> alglib::minlbfgssetscale(minlbfgsstate state, real_1d_array s);
</div></pre>
<a name='sub_minlbfgssetstpmax'></a><h3 class=pageheader><code>minlbfgssetstpmax</code> function</h3>
<pre class=source>
<div style='color: navy; margin-top: 0; margin-bottom: 0;'>/*************************************************************************
This function sets maximum step length
INPUT PARAMETERS:
State - structure which stores algorithm state
StpMax - maximum step length, >=0. Set StpMax to 0.0 (default), if
you don't want to limit step length.
Use this subroutine when you optimize target function which contains exp()
or other fast growing functions, and optimization algorithm makes too
large steps which leads to overflow. This function allows us to reject
steps that are too large (and therefore expose us to the possible
overflow) without actually calculating function value at the x+stp*d.
-- ALGLIB --
Copyright 02.04.2010 by Bochkanov Sergey
*************************************************************************/
</div><div style='margin-top: 0; margin-bottom: 0;'><b>void</b> alglib::minlbfgssetstpmax(minlbfgsstate state, <b>double</b> stpmax);
</div></pre>
<a name='sub_minlbfgssetxrep'></a><h3 class=pageheader><code>minlbfgssetxrep</code> function</h3>
<pre class=source>
<div style='color: navy; margin-top: 0; margin-bottom: 0;'>/*************************************************************************
This function turns on/off reporting.
INPUT PARAMETERS:
State - structure which stores algorithm state
NeedXRep- whether iteration reports are needed or not
If NeedXRep is True, algorithm will call rep() callback function if it is
provided to MinLBFGSOptimize().
-- ALGLIB --
Copyright 02.04.2010 by Bochkanov Sergey
*************************************************************************/
</div><div style='margin-top: 0; margin-bottom: 0;'><b>void</b> alglib::minlbfgssetxrep(minlbfgsstate state, <b>bool</b> needxrep);
</div></pre>
<a name='example_minlbfgs_d_1'></a><h3 class=pageheader>minlbfgs_d_1 example</h3>
<pre class=source>
#include <font color=blue><b>"stdafx.h"</b></font>
#include <stdlib.h>
#include <stdio.h>
#include <math.h>
#include <font color=blue><b>"optimization.h"</b></font>
using namespace alglib;
<b>void</b> function1_grad(<b>const</b> real_1d_array &x, <b>double</b> &func, real_1d_array &grad, <b>void</b> *ptr)
{
<font color=navy>//</font>
<font color=navy>// this callback calculates f(x0,x1) = 100*(x0+3)^4 + (x1-3)^4</font>
<font color=navy>// and its derivatives df/d0 and df/dx1</font>
<font color=navy>//</font>
func = 100*pow(x[0]+3,4) + pow(x[1]-3,4);
grad[0] = 400*pow(x[0]+3,3);
grad[1] = 4*pow(x[1]-3,3);
}
<b>int</b> main(<b>int</b> argc, char **argv)
{
<font color=navy>//</font>
<font color=navy>// This example demonstrates minimization of f(x,y) = 100*(x+3)^4+(y-3)^4</font>
<font color=navy>// using LBFGS method.</font>
<font color=navy>//</font>
real_1d_array x = <font color=blue><b>"[0,0]"</b></font>;
<b>double</b> epsg = 0.0000000001;
<b>double</b> epsf = 0;
<b>double</b> epsx = 0;
ae_int_t maxits = 0;
minlbfgsstate state;
minlbfgsreport rep;
minlbfgscreate(1, x, state);
minlbfgssetcond(state, epsg, epsf, epsx, maxits);
alglib::minlbfgsoptimize(state, function1_grad);
minlbfgsresults(state, x, rep);
printf(<font color=blue><b>"%d\n"</b></font>, <b>int</b>(rep.terminationtype)); <font color=navy>// EXPECTED: 4</font>
printf(<font color=blue><b>"%s\n"</b></font>, x.tostring(2).c_str()); <font color=navy>// EXPECTED: [-3,3]</font>
<b>return</b> 0;
}
</pre><a name='example_minlbfgs_d_2'></a><h3 class=pageheader>minlbfgs_d_2 example</h3>
<pre class=source>
#include <font color=blue><b>"stdafx.h"</b></font>
#include <stdlib.h>
#include <stdio.h>
#include <math.h>
#include <font color=blue><b>"optimization.h"</b></font>
using namespace alglib;
<b>void</b> function1_grad(<b>const</b> real_1d_array &x, <b>double</b> &func, real_1d_array &grad, <b>void</b> *ptr)
{
<font color=navy>//</font>
<font color=navy>// this callback calculates f(x0,x1) = 100*(x0+3)^4 + (x1-3)^4</font>
<font color=navy>// and its derivatives df/d0 and df/dx1</font>
<font color=navy>//</font>
func = 100*pow(x[0]+3,4) + pow(x[1]-3,4);
grad[0] = 400*pow(x[0]+3,3);
grad[1] = 4*pow(x[1]-3,3);
}
<b>int</b> main(<b>int</b> argc, char **argv)
{
<font color=navy>//</font>
<font color=navy>// This example demonstrates minimization of f(x,y) = 100*(x+3)^4+(y-3)^4</font>
<font color=navy>// using LBFGS method.</font>
<font color=navy>//</font>
<font color=navy>// Several advanced techniques are demonstrated:</font>
<font color=navy>// * upper limit on step size</font>
<font color=navy>// * restart from new point</font>
<font color=navy>//</font>
real_1d_array x = <font color=blue><b>"[0,0]"</b></font>;
<b>double</b> epsg = 0.0000000001;
<b>double</b> epsf = 0;
<b>double</b> epsx = 0;
<b>double</b> stpmax = 0.1;
ae_int_t maxits = 0;
minlbfgsstate state;
minlbfgsreport rep;
<font color=navy>// first run</font>
minlbfgscreate(1, x, state);
minlbfgssetcond(state, epsg, epsf, epsx, maxits);
minlbfgssetstpmax(state, stpmax);
alglib::minlbfgsoptimize(state, function1_grad);
minlbfgsresults(state, x, rep);
printf(<font color=blue><b>"%s\n"</b></font>, x.tostring(2).c_str()); <font color=navy>// EXPECTED: [-3,3]</font>
<font color=navy>// second run - algorithm is restarted</font>
x = <font color=blue><b>"[10,10]"</b></font>;
minlbfgsrestartfrom(state, x);
alglib::minlbfgsoptimize(state, function1_grad);
minlbfgsresults(state, x, rep);
printf(<font color=blue><b>"%d\n"</b></font>, <b>int</b>(rep.terminationtype)); <font color=navy>// EXPECTED: 4</font>
printf(<font color=blue><b>"%s\n"</b></font>, x.tostring(2).c_str()); <font color=navy>// EXPECTED: [-3,3]</font>
<b>return</b> 0;
}
</pre><a name='example_minlbfgs_ftrim'></a><h3 class=pageheader>minlbfgs_ftrim example</h3>
<pre class=source>
#include <font color=blue><b>"stdafx.h"</b></font>
#include <stdlib.h>
#include <stdio.h>
#include <math.h>
#include <font color=blue><b>"optimization.h"</b></font>
using namespace alglib;
<b>void</b> s1_grad(<b>const</b> real_1d_array &x, <b>double</b> &func, real_1d_array &grad, <b>void</b> *ptr)
{
<font color=navy>//</font>
<font color=navy>// this callback calculates f(x) = (1+x)^(-0.2) + (1-x)^(-0.3) + 1000*x and its gradient.</font>
<font color=navy>//</font>
<font color=navy>// function is trimmed when we calculate it near the singular points or outside of the [-1,+1].</font>
<font color=navy>// Note that we <b>do</b> NOT calculate gradient in this case.</font>
<font color=navy>//</font>
<b>if</b>( (x[0]<=-0.999999999999) || (x[0]>=+0.999999999999) )
{
func = 1.0E+300;
<b>return</b>;
}
func = pow(1+x[0],-0.2) + pow(1-x[0],-0.3) + 1000*x[0];
grad[0] = -0.2*pow(1+x[0],-1.2) +0.3*pow(1-x[0],-1.3) + 1000;
}
<b>int</b> main(<b>int</b> argc, char **argv)
{
<font color=navy>//</font>
<font color=navy>// This example demonstrates minimization of f(x) = (1+x)^(-0.2) + (1-x)^(-0.3) + 1000*x.</font>
<font color=navy>// This function has singularities at the boundary of the [-1,+1], but technique called</font>
<font color=navy>// <font color=blue><b>"function trimming"</b></font> allows us to solve this optimization problem.</font>
<font color=navy>//</font>
<font color=navy>// See http://www.alglib.net/optimization/tipsandtricks.php#ftrimming <b>for</b> more information</font>
<font color=navy>// on this subject.</font>
<font color=navy>//</font>
real_1d_array x = <font color=blue><b>"[0]"</b></font>;
<b>double</b> epsg = 1.0e-6;
<b>double</b> epsf = 0;
<b>double</b> epsx = 0;
ae_int_t maxits = 0;
minlbfgsstate state;
minlbfgsreport rep;
minlbfgscreate(1, x, state);
minlbfgssetcond(state, epsg, epsf, epsx, maxits);
alglib::minlbfgsoptimize(state, s1_grad);
minlbfgsresults(state, x, rep);
printf(<font color=blue><b>"%s\n"</b></font>, x.tostring(5).c_str()); <font color=navy>// EXPECTED: [-0.99917305]</font>
<b>return</b> 0;
}
</pre><a name='example_minlbfgs_numdiff'></a><h3 class=pageheader>minlbfgs_numdiff example</h3>
<pre class=source>
#include <font color=blue><b>"stdafx.h"</b></font>
#include <stdlib.h>
#include <stdio.h>
#include <math.h>
#include <font color=blue><b>"optimization.h"</b></font>
using namespace alglib;
<b>void</b> function1_func(<b>const</b> real_1d_array &x, <b>double</b> &func, <b>void</b> *ptr)
{
<font color=navy>//</font>
<font color=navy>// this callback calculates f(x0,x1) = 100*(x0+3)^4 + (x1-3)^4</font>
<font color=navy>//</font>
func = 100*pow(x[0]+3,4) + pow(x[1]-3,4);
}
<b>int</b> main(<b>int</b> argc, char **argv)
{
<font color=navy>//</font>
<font color=navy>// This example demonstrates minimization of f(x,y) = 100*(x+3)^4+(y-3)^4</font>
<font color=navy>// using numerical differentiation to calculate gradient.</font>
<font color=navy>//</font>
real_1d_array x = <font color=blue><b>"[0,0]"</b></font>;
<b>double</b> epsg = 0.0000000001;
<b>double</b> epsf = 0;
<b>double</b> epsx = 0;
<b>double</b> diffstep = 1.0e-6;
ae_int_t maxits = 0;
minlbfgsstate state;
minlbfgsreport rep;
minlbfgscreatef(1, x, diffstep, state);
minlbfgssetcond(state, epsg, epsf, epsx, maxits);
alglib::minlbfgsoptimize(state, function1_func);
minlbfgsresults(state, x, rep);
printf(<font color=blue><b>"%d\n"</b></font>, <b>int</b>(rep.terminationtype)); <font color=navy>// EXPECTED: 4</font>
printf(<font color=blue><b>"%s\n"</b></font>, x.tostring(2).c_str()); <font color=navy>// EXPECTED: [-3,3]</font>
<b>return</b> 0;
}
</pre><a name=unit_minlm></a><h2 class=pageheader><code>minlm</code> subpackage</h2>
<div class=pagecontent>
<h3 class=pageheader>Classes</h3>
<a href='#struct_minlmreport' class=toc>minlmreport</a><br>
<a href='#struct_minlmstate' class=toc>minlmstate</a><br>
<h3 class=pageheader>Functions</h3>
<a href='#sub_minlmcreatefgh' class=toc>minlmcreatefgh</a><br>
<a href='#sub_minlmcreatefgj' class=toc>minlmcreatefgj</a><br>
<a href='#sub_minlmcreatefj' class=toc>minlmcreatefj</a><br>
<a href='#sub_minlmcreatev' class=toc>minlmcreatev</a><br>
<a href='#sub_minlmcreatevgj' class=toc>minlmcreatevgj</a><br>
<a href='#sub_minlmcreatevj' class=toc>minlmcreatevj</a><br>
<a href='#sub_minlmoptimize' class=toc>minlmoptimize</a><br>
<a href='#sub_minlmrequesttermination' class=toc>minlmrequesttermination</a><br>
<a href='#sub_minlmrestartfrom' class=toc>minlmrestartfrom</a><br>
<a href='#sub_minlmresults' class=toc>minlmresults</a><br>
<a href='#sub_minlmresultsbuf' class=toc>minlmresultsbuf</a><br>
<a href='#sub_minlmsetacctype' class=toc>minlmsetacctype</a><br>
<a href='#sub_minlmsetbc' class=toc>minlmsetbc</a><br>
<a href='#sub_minlmsetcond' class=toc>minlmsetcond</a><br>
<a href='#sub_minlmsetgradientcheck' class=toc>minlmsetgradientcheck</a><br>
<a href='#sub_minlmsetscale' class=toc>minlmsetscale</a><br>
<a href='#sub_minlmsetstpmax' class=toc>minlmsetstpmax</a><br>
<a href='#sub_minlmsetxrep' class=toc>minlmsetxrep</a><br>
<h3 class=pageheader>Examples</h3>
<table border=0 cellspacing=0 class='pagecontent'>
<tr align=left valign=top><td><a href='#example_minlm_d_fgh' class=toc>minlm_d_fgh</a></td><td width=15> </td><td>Nonlinear Hessian-based optimization for general functions</td></tr>
<tr align=left valign=top><td><a href='#example_minlm_d_restarts' class=toc>minlm_d_restarts</a></td><td width=15> </td><td>Efficient restarts of LM optimizer</td></tr>
<tr align=left valign=top><td><a href='#example_minlm_d_v' class=toc>minlm_d_v</a></td><td width=15> </td><td>Nonlinear least squares optimization using function vector only</td></tr>
<tr align=left valign=top><td><a href='#example_minlm_d_vb' class=toc>minlm_d_vb</a></td><td width=15> </td><td>Bound constrained nonlinear least squares optimization</td></tr>
<tr align=left valign=top><td><a href='#example_minlm_d_vj' class=toc>minlm_d_vj</a></td><td width=15> </td><td>Nonlinear least squares optimization using function vector and Jacobian</td></tr>
</table></div>
<a name='struct_minlmreport'></a><h3 class=pageheader><code>minlmreport</code> class</h3>
<pre class=source>
<div style='color: navy; margin-top: 0; margin-bottom: 0;'>/*************************************************************************
Optimization report, filled by MinLMResults() function
FIELDS:
* TerminationType, completetion code:
* -7 derivative correctness check failed;
see rep.funcidx, rep.varidx for
more information.
* -3 constraints are inconsistent
* 1 relative function improvement is no more than
EpsF.
* 2 relative step is no more than EpsX.
* 4 gradient is no more than EpsG.
* 5 MaxIts steps was taken
* 7 stopping conditions are too stringent,
further improvement is impossible
* 8 terminated by user who called MinLMRequestTermination().
X contains point which was "current accepted" when termination
request was submitted.
* IterationsCount, contains iterations count
* NFunc, number of function calculations
* NJac, number of Jacobi matrix calculations
* NGrad, number of gradient calculations
* NHess, number of Hessian calculations
* NCholesky, number of Cholesky decomposition calculations
*************************************************************************/
</div><div style='margin-top: 0; margin-bottom: 0;'><b>class</b> minlmreport
{
ae_int_t iterationscount;
ae_int_t terminationtype;
ae_int_t funcidx;
ae_int_t varidx;
ae_int_t nfunc;
ae_int_t njac;
ae_int_t ngrad;
ae_int_t nhess;
ae_int_t ncholesky;
};
</div></pre>
<a name='struct_minlmstate'></a><h3 class=pageheader><code>minlmstate</code> class</h3>
<pre class=source>
<div style='color: navy; margin-top: 0; margin-bottom: 0;'>/*************************************************************************
Levenberg-Marquardt optimizer.
This structure should be created using one of the MinLMCreate???()
functions. You should not access its fields directly; use ALGLIB functions
to work with it.
*************************************************************************/
</div><div style='margin-top: 0; margin-bottom: 0;'><b>class</b> minlmstate
{
};
</div></pre>
<a name='sub_minlmcreatefgh'></a><h3 class=pageheader><code>minlmcreatefgh</code> function</h3>
<pre class=source>
<div style='color: navy; margin-top: 0; margin-bottom: 0;'>/*************************************************************************
LEVENBERG-MARQUARDT-LIKE METHOD FOR NON-LINEAR OPTIMIZATION
DESCRIPTION:
This function is used to find minimum of general form (not "sum-of-
-squares") function
F = F(x[0], ..., x[n-1])
using its gradient and Hessian. Levenberg-Marquardt modification with
L-BFGS pre-optimization and internal pre-conditioned L-BFGS optimization
after each Levenberg-Marquardt step is used.
REQUIREMENTS:
This algorithm will request following information during its operation:
* function value F at given point X
* F and gradient G (simultaneously) at given point X
* F, G and Hessian H (simultaneously) at given point X
There are several overloaded versions of MinLMOptimize() function which
correspond to different LM-like optimization algorithms provided by this
unit. You should choose version which accepts func(), grad() and hess()
function pointers. First pointer is used to calculate F at given point,
second one calculates F(x) and grad F(x), third one calculates F(x),
grad F(x), hess F(x).
You can try to initialize MinLMState structure with FGH-function and then
use incorrect version of MinLMOptimize() (for example, version which does
not provide Hessian matrix), but it will lead to exception being thrown
after first attempt to calculate Hessian.
USAGE:
1. User initializes algorithm state with MinLMCreateFGH() call
2. User tunes solver parameters with MinLMSetCond(), MinLMSetStpMax() and
other functions
3. User calls MinLMOptimize() function which takes algorithm state and
pointers (delegates, etc.) to callback functions.
4. User calls MinLMResults() to get solution
5. Optionally, user may call MinLMRestartFrom() to solve another problem
with same N but another starting point and/or another function.
MinLMRestartFrom() allows to reuse already initialized structure.
INPUT PARAMETERS:
N - dimension, N>1
* if given, only leading N elements of X are used
* if not given, automatically determined from size of X
X - initial solution, array[0..N-1]
OUTPUT PARAMETERS:
State - structure which stores algorithm state
NOTES:
1. you may tune stopping conditions with MinLMSetCond() function
2. if target function contains exp() or other fast growing functions, and
optimization algorithm makes too large steps which leads to overflow,
use MinLMSetStpMax() function to bound algorithm's steps.
-- ALGLIB --
Copyright 30.03.2009 by Bochkanov Sergey
*************************************************************************/
</div><div style='margin-top: 0; margin-bottom: 0;'><b>void</b> alglib::minlmcreatefgh(real_1d_array x, minlmstate& state);
<b>void</b> alglib::minlmcreatefgh(
ae_int_t n,
real_1d_array x,
minlmstate& state);
</div></pre>
<p align=left class=pagecontent><span class=inlineheader>Examples:</span> <a href='#example_minlm_d_fgh' class=nav>[1]</a> </p>
<a name='sub_minlmcreatefgj'></a><h3 class=pageheader><code>minlmcreatefgj</code> function</h3>
<pre class=source>
<div style='color: navy; margin-top: 0; margin-bottom: 0;'>/*************************************************************************
This is obsolete function.
Since ALGLIB 3.3 it is equivalent to MinLMCreateFJ().
-- ALGLIB --
Copyright 30.03.2009 by Bochkanov Sergey
*************************************************************************/
</div><div style='margin-top: 0; margin-bottom: 0;'><b>void</b> alglib::minlmcreatefgj(
ae_int_t m,
real_1d_array x,
minlmstate& state);
<b>void</b> alglib::minlmcreatefgj(
ae_int_t n,
ae_int_t m,
real_1d_array x,
minlmstate& state);
</div></pre>
<a name='sub_minlmcreatefj'></a><h3 class=pageheader><code>minlmcreatefj</code> function</h3>
<pre class=source>
<div style='color: navy; margin-top: 0; margin-bottom: 0;'>/*************************************************************************
This function is considered obsolete since ALGLIB 3.1.0 and is present for
backward compatibility only. We recommend to use MinLMCreateVJ, which
provides similar, but more consistent and feature-rich interface.
-- ALGLIB --
Copyright 30.03.2009 by Bochkanov Sergey
*************************************************************************/
</div><div style='margin-top: 0; margin-bottom: 0;'><b>void</b> alglib::minlmcreatefj(
ae_int_t m,
real_1d_array x,
minlmstate& state);
<b>void</b> alglib::minlmcreatefj(
ae_int_t n,
ae_int_t m,
real_1d_array x,
minlmstate& state);
</div></pre>
<a name='sub_minlmcreatev'></a><h3 class=pageheader><code>minlmcreatev</code> function</h3>
<pre class=source>
<div style='color: navy; margin-top: 0; margin-bottom: 0;'>/*************************************************************************
IMPROVED LEVENBERG-MARQUARDT METHOD FOR
NON-LINEAR LEAST SQUARES OPTIMIZATION
DESCRIPTION:
This function is used to find minimum of function which is represented as
sum of squares:
F(x) = f[0]^2(x[0],...,x[n-1]) + ... + f[m-1]^2(x[0],...,x[n-1])
using value of function vector f[] only. Finite differences are used to
calculate Jacobian.
REQUIREMENTS:
This algorithm will request following information during its operation:
* function vector f[] at given point X
There are several overloaded versions of MinLMOptimize() function which
correspond to different LM-like optimization algorithms provided by this
unit. You should choose version which accepts fvec() callback.
You can try to initialize MinLMState structure with VJ function and then
use incorrect version of MinLMOptimize() (for example, version which
works with general form function and does not accept function vector), but
it will lead to exception being thrown after first attempt to calculate
Jacobian.
USAGE:
1. User initializes algorithm state with MinLMCreateV() call
2. User tunes solver parameters with MinLMSetCond(), MinLMSetStpMax() and
other functions
3. User calls MinLMOptimize() function which takes algorithm state and
callback functions.
4. User calls MinLMResults() to get solution
5. Optionally, user may call MinLMRestartFrom() to solve another problem
with same N/M but another starting point and/or another function.
MinLMRestartFrom() allows to reuse already initialized structure.
INPUT PARAMETERS:
N - dimension, N>1
* if given, only leading N elements of X are used
* if not given, automatically determined from size of X
M - number of functions f[i]
X - initial solution, array[0..N-1]
DiffStep- differentiation step, >0
OUTPUT PARAMETERS:
State - structure which stores algorithm state
See also MinLMIteration, MinLMResults.
NOTES:
1. you may tune stopping conditions with MinLMSetCond() function
2. if target function contains exp() or other fast growing functions, and
optimization algorithm makes too large steps which leads to overflow,
use MinLMSetStpMax() function to bound algorithm's steps.
-- ALGLIB --
Copyright 30.03.2009 by Bochkanov Sergey
*************************************************************************/
</div><div style='margin-top: 0; margin-bottom: 0;'><b>void</b> alglib::minlmcreatev(
ae_int_t m,
real_1d_array x,
<b>double</b> diffstep,
minlmstate& state);
<b>void</b> alglib::minlmcreatev(
ae_int_t n,
ae_int_t m,
real_1d_array x,
<b>double</b> diffstep,
minlmstate& state);
</div></pre>
<p align=left class=pagecontent><span class=inlineheader>Examples:</span> <a href='#example_minlm_d_v' class=nav>[1]</a> <a href='#example_minlm_d_vb' class=nav>[2]</a> <a href='#example_minlm_d_restarts' class=nav>[3]</a> </p>
<a name='sub_minlmcreatevgj'></a><h3 class=pageheader><code>minlmcreatevgj</code> function</h3>
<pre class=source>
<div style='color: navy; margin-top: 0; margin-bottom: 0;'>/*************************************************************************
This is obsolete function.
Since ALGLIB 3.3 it is equivalent to MinLMCreateVJ().
-- ALGLIB --
Copyright 30.03.2009 by Bochkanov Sergey
*************************************************************************/
</div><div style='margin-top: 0; margin-bottom: 0;'><b>void</b> alglib::minlmcreatevgj(
ae_int_t m,
real_1d_array x,
minlmstate& state);
<b>void</b> alglib::minlmcreatevgj(
ae_int_t n,
ae_int_t m,
real_1d_array x,
minlmstate& state);
</div></pre>
<a name='sub_minlmcreatevj'></a><h3 class=pageheader><code>minlmcreatevj</code> function</h3>
<pre class=source>
<div style='color: navy; margin-top: 0; margin-bottom: 0;'>/*************************************************************************
IMPROVED LEVENBERG-MARQUARDT METHOD FOR
NON-LINEAR LEAST SQUARES OPTIMIZATION
DESCRIPTION:
This function is used to find minimum of function which is represented as
sum of squares:
F(x) = f[0]^2(x[0],...,x[n-1]) + ... + f[m-1]^2(x[0],...,x[n-1])
using value of function vector f[] and Jacobian of f[].
REQUIREMENTS:
This algorithm will request following information during its operation:
* function vector f[] at given point X
* function vector f[] and Jacobian of f[] (simultaneously) at given point
There are several overloaded versions of MinLMOptimize() function which
correspond to different LM-like optimization algorithms provided by this
unit. You should choose version which accepts fvec() and jac() callbacks.
First one is used to calculate f[] at given point, second one calculates
f[] and Jacobian df[i]/dx[j].
You can try to initialize MinLMState structure with VJ function and then
use incorrect version of MinLMOptimize() (for example, version which
works with general form function and does not provide Jacobian), but it
will lead to exception being thrown after first attempt to calculate
Jacobian.
USAGE:
1. User initializes algorithm state with MinLMCreateVJ() call
2. User tunes solver parameters with MinLMSetCond(), MinLMSetStpMax() and
other functions
3. User calls MinLMOptimize() function which takes algorithm state and
callback functions.
4. User calls MinLMResults() to get solution
5. Optionally, user may call MinLMRestartFrom() to solve another problem
with same N/M but another starting point and/or another function.
MinLMRestartFrom() allows to reuse already initialized structure.
INPUT PARAMETERS:
N - dimension, N>1
* if given, only leading N elements of X are used
* if not given, automatically determined from size of X
M - number of functions f[i]
X - initial solution, array[0..N-1]
OUTPUT PARAMETERS:
State - structure which stores algorithm state
NOTES:
1. you may tune stopping conditions with MinLMSetCond() function
2. if target function contains exp() or other fast growing functions, and
optimization algorithm makes too large steps which leads to overflow,
use MinLMSetStpMax() function to bound algorithm's steps.
-- ALGLIB --
Copyright 30.03.2009 by Bochkanov Sergey
*************************************************************************/
</div><div style='margin-top: 0; margin-bottom: 0;'><b>void</b> alglib::minlmcreatevj(
ae_int_t m,
real_1d_array x,
minlmstate& state);
<b>void</b> alglib::minlmcreatevj(
ae_int_t n,
ae_int_t m,
real_1d_array x,
minlmstate& state);
</div></pre>
<p align=left class=pagecontent><span class=inlineheader>Examples:</span> <a href='#example_minlm_d_vj' class=nav>[1]</a> </p>
<a name='sub_minlmoptimize'></a><h3 class=pageheader><code>minlmoptimize</code> function</h3>
<pre class=source>
<div style='color: navy; margin-top: 0; margin-bottom: 0;'>/*************************************************************************
This family of functions is used to launcn iterations of nonlinear optimizer
These functions accept following parameters:
state - algorithm state
func - callback which calculates function (or merit function)
value func at given point x
grad - callback which calculates function (or merit function)
value func and gradient grad at given point x
hess - callback which calculates function (or merit function)
value func, gradient grad and Hessian hess at given point x
fvec - callback which calculates function vector fi[]
at given point x
jac - callback which calculates function vector fi[]
and Jacobian jac at given point x
rep - optional callback which is called after each iteration
can be NULL
ptr - optional pointer which is passed to func/grad/hess/jac/rep
can be NULL
NOTES:
1. Depending on function used to create state structure, this algorithm
may accept Jacobian and/or Hessian and/or gradient. According to the
said above, there ase several versions of this function, which accept
different sets of callbacks.
This flexibility opens way to subtle errors - you may create state with
MinLMCreateFGH() (optimization using Hessian), but call function which
does not accept Hessian. So when algorithm will request Hessian, there
will be no callback to call. In this case exception will be thrown.
Be careful to avoid such errors because there is no way to find them at
compile time - you can see them at runtime only.
-- ALGLIB --
Copyright 10.03.2009 by Bochkanov Sergey
*************************************************************************/
</div><div style='margin-top: 0; margin-bottom: 0;'><b>void</b> minlmoptimize(minlmstate &state,
<b>void</b> (*fvec)(<b>const</b> real_1d_array &x, real_1d_array &fi, <b>void</b> *ptr),
<b>void</b> (*rep)(<b>const</b> real_1d_array &x, <b>double</b> func, <b>void</b> *ptr) = NULL,
<b>void</b> *ptr = NULL);
<b>void</b> minlmoptimize(minlmstate &state,
<b>void</b> (*fvec)(<b>const</b> real_1d_array &x, real_1d_array &fi, <b>void</b> *ptr),
<b>void</b> (*jac)(<b>const</b> real_1d_array &x, real_1d_array &fi, real_2d_array &jac, <b>void</b> *ptr),
<b>void</b> (*rep)(<b>const</b> real_1d_array &x, <b>double</b> func, <b>void</b> *ptr) = NULL,
<b>void</b> *ptr = NULL);
<b>void</b> minlmoptimize(minlmstate &state,
<b>void</b> (*func)(<b>const</b> real_1d_array &x, <b>double</b> &func, <b>void</b> *ptr),
<b>void</b> (*grad)(<b>const</b> real_1d_array &x, <b>double</b> &func, real_1d_array &grad, <b>void</b> *ptr),
<b>void</b> (*hess)(<b>const</b> real_1d_array &x, <b>double</b> &func, real_1d_array &grad, real_2d_array &hess, <b>void</b> *ptr),
<b>void</b> (*rep)(<b>const</b> real_1d_array &x, <b>double</b> func, <b>void</b> *ptr) = NULL,
<b>void</b> *ptr = NULL);
<b>void</b> minlmoptimize(minlmstate &state,
<b>void</b> (*func)(<b>const</b> real_1d_array &x, <b>double</b> &func, <b>void</b> *ptr),
<b>void</b> (*jac)(<b>const</b> real_1d_array &x, real_1d_array &fi, real_2d_array &jac, <b>void</b> *ptr),
<b>void</b> (*rep)(<b>const</b> real_1d_array &x, <b>double</b> func, <b>void</b> *ptr) = NULL,
<b>void</b> *ptr = NULL);
<b>void</b> minlmoptimize(minlmstate &state,
<b>void</b> (*func)(<b>const</b> real_1d_array &x, <b>double</b> &func, <b>void</b> *ptr),
<b>void</b> (*grad)(<b>const</b> real_1d_array &x, <b>double</b> &func, real_1d_array &grad, <b>void</b> *ptr),
<b>void</b> (*jac)(<b>const</b> real_1d_array &x, real_1d_array &fi, real_2d_array &jac, <b>void</b> *ptr),
<b>void</b> (*rep)(<b>const</b> real_1d_array &x, <b>double</b> func, <b>void</b> *ptr) = NULL,
<b>void</b> *ptr = NULL);
</div></pre>
<p align=left class=pagecontent><span class=inlineheader>Examples:</span> <a href='#example_minlm_d_v' class=nav>[1]</a> <a href='#example_minlm_d_vj' class=nav>[2]</a> <a href='#example_minlm_d_fgh' class=nav>[3]</a> <a href='#example_minlm_d_vb' class=nav>[4]</a> <a href='#example_minlm_d_restarts' class=nav>[5]</a> </p>
<a name='sub_minlmrequesttermination'></a><h3 class=pageheader><code>minlmrequesttermination</code> function</h3>
<pre class=source>
<div style='color: navy; margin-top: 0; margin-bottom: 0;'>/*************************************************************************
This subroutine submits request for termination of running optimizer. It
should be called from user-supplied callback when user decides that it is
time to "smoothly" terminate optimization process. As result, optimizer
stops at point which was "current accepted" when termination request was
submitted and returns error code 8 (successful termination).
INPUT PARAMETERS:
State - optimizer structure
NOTE: after request for termination optimizer may perform several
additional calls to user-supplied callbacks. It does NOT guarantee
to stop immediately - it just guarantees that these additional calls
will be discarded later.
NOTE: calling this function on optimizer which is NOT running will have no
effect.
NOTE: multiple calls to this function are possible. First call is counted,
subsequent calls are silently ignored.
-- ALGLIB --
Copyright 08.10.2014 by Bochkanov Sergey
*************************************************************************/
</div><div style='margin-top: 0; margin-bottom: 0;'><b>void</b> alglib::minlmrequesttermination(minlmstate state);
</div></pre>
<a name='sub_minlmrestartfrom'></a><h3 class=pageheader><code>minlmrestartfrom</code> function</h3>
<pre class=source>
<div style='color: navy; margin-top: 0; margin-bottom: 0;'>/*************************************************************************
This subroutine restarts LM algorithm from new point. All optimization
parameters are left unchanged.
This function allows to solve multiple optimization problems (which
must have same number of dimensions) without object reallocation penalty.
INPUT PARAMETERS:
State - structure used for reverse communication previously
allocated with MinLMCreateXXX call.
X - new starting point.
-- ALGLIB --
Copyright 30.07.2010 by Bochkanov Sergey
*************************************************************************/
</div><div style='margin-top: 0; margin-bottom: 0;'><b>void</b> alglib::minlmrestartfrom(minlmstate state, real_1d_array x);
</div></pre>
<p align=left class=pagecontent><span class=inlineheader>Examples:</span> <a href='#example_minlm_d_restarts' class=nav>[1]</a> </p>
<a name='sub_minlmresults'></a><h3 class=pageheader><code>minlmresults</code> function</h3>
<pre class=source>
<div style='color: navy; margin-top: 0; margin-bottom: 0;'>/*************************************************************************
Levenberg-Marquardt algorithm results
INPUT PARAMETERS:
State - algorithm state
OUTPUT PARAMETERS:
X - array[0..N-1], solution
Rep - optimization report; includes termination codes and
additional information. Termination codes are listed below,
see comments for this structure for more info.
Termination code is stored in rep.terminationtype field:
* -7 derivative correctness check failed;
see rep.funcidx, rep.varidx for
more information.
* -3 constraints are inconsistent
* 1 relative function improvement is no more than
EpsF.
* 2 relative step is no more than EpsX.
* 4 gradient is no more than EpsG.
* 5 MaxIts steps was taken
* 7 stopping conditions are too stringent,
further improvement is impossible
* 8 terminated by user who called minlmrequesttermination().
X contains point which was "current accepted" when
termination request was submitted.
-- ALGLIB --
Copyright 10.03.2009 by Bochkanov Sergey
*************************************************************************/
</div><div style='margin-top: 0; margin-bottom: 0;'><b>void</b> alglib::minlmresults(
minlmstate state,
real_1d_array& x,
minlmreport& rep);
</div></pre>
<p align=left class=pagecontent><span class=inlineheader>Examples:</span> <a href='#example_minlm_d_v' class=nav>[1]</a> <a href='#example_minlm_d_vj' class=nav>[2]</a> <a href='#example_minlm_d_fgh' class=nav>[3]</a> <a href='#example_minlm_d_vb' class=nav>[4]</a> <a href='#example_minlm_d_restarts' class=nav>[5]</a> </p>
<a name='sub_minlmresultsbuf'></a><h3 class=pageheader><code>minlmresultsbuf</code> function</h3>
<pre class=source>
<div style='color: navy; margin-top: 0; margin-bottom: 0;'>/*************************************************************************
Levenberg-Marquardt algorithm results
Buffered implementation of MinLMResults(), which uses pre-allocated buffer
to store X[]. If buffer size is too small, it resizes buffer. It is
intended to be used in the inner cycles of performance critical algorithms
where array reallocation penalty is too large to be ignored.
-- ALGLIB --
Copyright 10.03.2009 by Bochkanov Sergey
*************************************************************************/
</div><div style='margin-top: 0; margin-bottom: 0;'><b>void</b> alglib::minlmresultsbuf(
minlmstate state,
real_1d_array& x,
minlmreport& rep);
</div></pre>
<a name='sub_minlmsetacctype'></a><h3 class=pageheader><code>minlmsetacctype</code> function</h3>
<pre class=source>
<div style='color: navy; margin-top: 0; margin-bottom: 0;'>/*************************************************************************
This function is used to change acceleration settings
You can choose between three acceleration strategies:
* AccType=0, no acceleration.
* AccType=1, secant updates are used to update quadratic model after each
iteration. After fixed number of iterations (or after model breakdown)
we recalculate quadratic model using analytic Jacobian or finite
differences. Number of secant-based iterations depends on optimization
settings: about 3 iterations - when we have analytic Jacobian, up to 2*N
iterations - when we use finite differences to calculate Jacobian.
AccType=1 is recommended when Jacobian calculation cost is prohibitive
high (several Mx1 function vector calculations followed by several NxN
Cholesky factorizations are faster than calculation of one M*N Jacobian).
It should also be used when we have no Jacobian, because finite difference
approximation takes too much time to compute.
Table below list optimization protocols (XYZ protocol corresponds to
MinLMCreateXYZ) and acceleration types they support (and use by default).
ACCELERATION TYPES SUPPORTED BY OPTIMIZATION PROTOCOLS:
protocol 0 1 comment
V + +
VJ + +
FGH +
DAFAULT VALUES:
protocol 0 1 comment
V x without acceleration it is so slooooooooow
VJ x
FGH x
NOTE: this function should be called before optimization. Attempt to call
it during algorithm iterations may result in unexpected behavior.
NOTE: attempt to call this function with unsupported protocol/acceleration
combination will result in exception being thrown.
-- ALGLIB --
Copyright 14.10.2010 by Bochkanov Sergey
*************************************************************************/
</div><div style='margin-top: 0; margin-bottom: 0;'><b>void</b> alglib::minlmsetacctype(minlmstate state, ae_int_t acctype);
</div></pre>
<a name='sub_minlmsetbc'></a><h3 class=pageheader><code>minlmsetbc</code> function</h3>
<pre class=source>
<div style='color: navy; margin-top: 0; margin-bottom: 0;'>/*************************************************************************
This function sets boundary constraints for LM optimizer
Boundary constraints are inactive by default (after initial creation).
They are preserved until explicitly turned off with another SetBC() call.
INPUT PARAMETERS:
State - structure stores algorithm state
BndL - lower bounds, array[N].
If some (all) variables are unbounded, you may specify
very small number or -INF (latter is recommended because
it will allow solver to use better algorithm).
BndU - upper bounds, array[N].
If some (all) variables are unbounded, you may specify
very large number or +INF (latter is recommended because
it will allow solver to use better algorithm).
NOTE 1: it is possible to specify BndL[i]=BndU[i]. In this case I-th
variable will be "frozen" at X[i]=BndL[i]=BndU[i].
NOTE 2: this solver has following useful properties:
* bound constraints are always satisfied exactly
* function is evaluated only INSIDE area specified by bound constraints
or at its boundary
-- ALGLIB --
Copyright 14.01.2011 by Bochkanov Sergey
*************************************************************************/
</div><div style='margin-top: 0; margin-bottom: 0;'><b>void</b> alglib::minlmsetbc(
minlmstate state,
real_1d_array bndl,
real_1d_array bndu);
</div></pre>
<a name='sub_minlmsetcond'></a><h3 class=pageheader><code>minlmsetcond</code> function</h3>
<pre class=source>
<div style='color: navy; margin-top: 0; margin-bottom: 0;'>/*************************************************************************
This function sets stopping conditions for Levenberg-Marquardt optimization
algorithm.
INPUT PARAMETERS:
State - structure which stores algorithm state
EpsG - >=0
The subroutine finishes its work if the condition
|v|<EpsG is satisfied, where:
* |.| means Euclidian norm
* v - scaled gradient vector, v[i]=g[i]*s[i]
* g - gradient
* s - scaling coefficients set by MinLMSetScale()
EpsF - >=0
The subroutine finishes its work if on k+1-th iteration
the condition |F(k+1)-F(k)|<=EpsF*max{|F(k)|,|F(k+1)|,1}
is satisfied.
EpsX - >=0
The subroutine finishes its work if on k+1-th iteration
the condition |v|<=EpsX is fulfilled, where:
* |.| means Euclidian norm
* v - scaled step vector, v[i]=dx[i]/s[i]
* dx - ste pvector, dx=X(k+1)-X(k)
* s - scaling coefficients set by MinLMSetScale()
MaxIts - maximum number of iterations. If MaxIts=0, the number of
iterations is unlimited. Only Levenberg-Marquardt
iterations are counted (L-BFGS/CG iterations are NOT
counted because their cost is very low compared to that of
LM).
Passing EpsG=0, EpsF=0, EpsX=0 and MaxIts=0 (simultaneously) will lead to
automatic stopping criterion selection (small EpsX).
-- ALGLIB --
Copyright 02.04.2010 by Bochkanov Sergey
*************************************************************************/
</div><div style='margin-top: 0; margin-bottom: 0;'><b>void</b> alglib::minlmsetcond(
minlmstate state,
<b>double</b> epsg,
<b>double</b> epsf,
<b>double</b> epsx,
ae_int_t maxits);
</div></pre>
<p align=left class=pagecontent><span class=inlineheader>Examples:</span> <a href='#example_minlm_d_v' class=nav>[1]</a> <a href='#example_minlm_d_vj' class=nav>[2]</a> <a href='#example_minlm_d_fgh' class=nav>[3]</a> <a href='#example_minlm_d_vb' class=nav>[4]</a> <a href='#example_minlm_d_restarts' class=nav>[5]</a> </p>
<a name='sub_minlmsetgradientcheck'></a><h3 class=pageheader><code>minlmsetgradientcheck</code> function</h3>
<pre class=source>
<div style='color: navy; margin-top: 0; margin-bottom: 0;'>/*************************************************************************
This subroutine turns on verification of the user-supplied analytic
gradient:
* user calls this subroutine before optimization begins
* MinLMOptimize() is called
* prior to actual optimization, for each function Fi and each component
of parameters being optimized X[j] algorithm performs following steps:
* two trial steps are made to X[j]-TestStep*S[j] and X[j]+TestStep*S[j],
where X[j] is j-th parameter and S[j] is a scale of j-th parameter
* if needed, steps are bounded with respect to constraints on X[]
* Fi(X) is evaluated at these trial points
* we perform one more evaluation in the middle point of the interval
* we build cubic model using function values and derivatives at trial
points and we compare its prediction with actual value in the middle
point
* in case difference between prediction and actual value is higher than
some predetermined threshold, algorithm stops with completion code -7;
Rep.VarIdx is set to index of the parameter with incorrect derivative,
Rep.FuncIdx is set to index of the function.
* after verification is over, algorithm proceeds to the actual optimization.
NOTE 1: verification needs N (parameters count) Jacobian evaluations. It
is very costly and you should use it only for low dimensional
problems, when you want to be sure that you've correctly
calculated analytic derivatives. You should not use it in the
production code (unless you want to check derivatives provided
by some third party).
NOTE 2: you should carefully choose TestStep. Value which is too large
(so large that function behaviour is significantly non-cubic) will
lead to false alarms. You may use different step for different
parameters by means of setting scale with MinLMSetScale().
NOTE 3: this function may lead to false positives. In case it reports that
I-th derivative was calculated incorrectly, you may decrease test
step and try one more time - maybe your function changes too
sharply and your step is too large for such rapidly chanding
function.
INPUT PARAMETERS:
State - structure used to store algorithm state
TestStep - verification step:
* TestStep=0 turns verification off
* TestStep>0 activates verification
-- ALGLIB --
Copyright 15.06.2012 by Bochkanov Sergey
*************************************************************************/
</div><div style='margin-top: 0; margin-bottom: 0;'><b>void</b> alglib::minlmsetgradientcheck(minlmstate state, <b>double</b> teststep);
</div></pre>
<a name='sub_minlmsetscale'></a><h3 class=pageheader><code>minlmsetscale</code> function</h3>
<pre class=source>
<div style='color: navy; margin-top: 0; margin-bottom: 0;'>/*************************************************************************
This function sets scaling coefficients for LM optimizer.
ALGLIB optimizers use scaling matrices to test stopping conditions (step
size and gradient are scaled before comparison with tolerances). Scale of
the I-th variable is a translation invariant measure of:
a) "how large" the variable is
b) how large the step should be to make significant changes in the function
Generally, scale is NOT considered to be a form of preconditioner. But LM
optimizer is unique in that it uses scaling matrix both in the stopping
condition tests and as Marquardt damping factor.
Proper scaling is very important for the algorithm performance. It is less
important for the quality of results, but still has some influence (it is
easier to converge when variables are properly scaled, so premature
stopping is possible when very badly scalled variables are combined with
relaxed stopping conditions).
INPUT PARAMETERS:
State - structure stores algorithm state
S - array[N], non-zero scaling coefficients
S[i] may be negative, sign doesn't matter.
-- ALGLIB --
Copyright 14.01.2011 by Bochkanov Sergey
*************************************************************************/
</div><div style='margin-top: 0; margin-bottom: 0;'><b>void</b> alglib::minlmsetscale(minlmstate state, real_1d_array s);
</div></pre>
<a name='sub_minlmsetstpmax'></a><h3 class=pageheader><code>minlmsetstpmax</code> function</h3>
<pre class=source>
<div style='color: navy; margin-top: 0; margin-bottom: 0;'>/*************************************************************************
This function sets maximum step length
INPUT PARAMETERS:
State - structure which stores algorithm state
StpMax - maximum step length, >=0. Set StpMax to 0.0, if you don't
want to limit step length.
Use this subroutine when you optimize target function which contains exp()
or other fast growing functions, and optimization algorithm makes too
large steps which leads to overflow. This function allows us to reject
steps that are too large (and therefore expose us to the possible
overflow) without actually calculating function value at the x+stp*d.
NOTE: non-zero StpMax leads to moderate performance degradation because
intermediate step of preconditioned L-BFGS optimization is incompatible
with limits on step size.
-- ALGLIB --
Copyright 02.04.2010 by Bochkanov Sergey
*************************************************************************/
</div><div style='margin-top: 0; margin-bottom: 0;'><b>void</b> alglib::minlmsetstpmax(minlmstate state, <b>double</b> stpmax);
</div></pre>
<a name='sub_minlmsetxrep'></a><h3 class=pageheader><code>minlmsetxrep</code> function</h3>
<pre class=source>
<div style='color: navy; margin-top: 0; margin-bottom: 0;'>/*************************************************************************
This function turns on/off reporting.
INPUT PARAMETERS:
State - structure which stores algorithm state
NeedXRep- whether iteration reports are needed or not
If NeedXRep is True, algorithm will call rep() callback function if it is
provided to MinLMOptimize(). Both Levenberg-Marquardt and internal L-BFGS
iterations are reported.
-- ALGLIB --
Copyright 02.04.2010 by Bochkanov Sergey
*************************************************************************/
</div><div style='margin-top: 0; margin-bottom: 0;'><b>void</b> alglib::minlmsetxrep(minlmstate state, <b>bool</b> needxrep);
</div></pre>
<a name='example_minlm_d_fgh'></a><h3 class=pageheader>minlm_d_fgh example</h3>
<pre class=source>
#include <font color=blue><b>"stdafx.h"</b></font>
#include <stdlib.h>
#include <stdio.h>
#include <math.h>
#include <font color=blue><b>"optimization.h"</b></font>
using namespace alglib;
<b>void</b> function1_func(<b>const</b> real_1d_array &x, <b>double</b> &func, <b>void</b> *ptr)
{
<font color=navy>//</font>
<font color=navy>// this callback calculates f(x0,x1) = 100*(x0+3)^4 + (x1-3)^4</font>
<font color=navy>//</font>
func = 100*pow(x[0]+3,4) + pow(x[1]-3,4);
}
<b>void</b> function1_grad(<b>const</b> real_1d_array &x, <b>double</b> &func, real_1d_array &grad, <b>void</b> *ptr)
{
<font color=navy>//</font>
<font color=navy>// this callback calculates f(x0,x1) = 100*(x0+3)^4 + (x1-3)^4</font>
<font color=navy>// and its derivatives df/d0 and df/dx1</font>
<font color=navy>//</font>
func = 100*pow(x[0]+3,4) + pow(x[1]-3,4);
grad[0] = 400*pow(x[0]+3,3);
grad[1] = 4*pow(x[1]-3,3);
}
<b>void</b> function1_hess(<b>const</b> real_1d_array &x, <b>double</b> &func, real_1d_array &grad, real_2d_array &hess, <b>void</b> *ptr)
{
<font color=navy>//</font>
<font color=navy>// this callback calculates f(x0,x1) = 100*(x0+3)^4 + (x1-3)^4</font>
<font color=navy>// its derivatives df/d0 and df/dx1</font>
<font color=navy>// and its Hessian.</font>
<font color=navy>//</font>
func = 100*pow(x[0]+3,4) + pow(x[1]-3,4);
grad[0] = 400*pow(x[0]+3,3);
grad[1] = 4*pow(x[1]-3,3);
hess[0][0] = 1200*pow(x[0]+3,2);
hess[0][1] = 0;
hess[1][0] = 0;
hess[1][1] = 12*pow(x[1]-3,2);
}
<b>int</b> main(<b>int</b> argc, char **argv)
{
<font color=navy>//</font>
<font color=navy>// This example demonstrates minimization of F(x0,x1) = 100*(x0+3)^4+(x1-3)^4</font>
<font color=navy>// using <font color=blue><b>"FGH"</b></font> mode of the Levenberg-Marquardt optimizer.</font>
<font color=navy>//</font>
<font color=navy>// F is treated like a monolitic function without internal structure,</font>
<font color=navy>// i.e. we <b>do</b> NOT represent it as a sum of squares.</font>
<font color=navy>//</font>
<font color=navy>// Optimization algorithm uses:</font>
<font color=navy>// * function value F(x0,x1)</font>
<font color=navy>// * gradient G={dF/dxi}</font>
<font color=navy>// * Hessian H={d2F/(dxi*dxj)}</font>
<font color=navy>//</font>
real_1d_array x = <font color=blue><b>"[0,0]"</b></font>;
<b>double</b> epsg = 0.0000000001;
<b>double</b> epsf = 0;
<b>double</b> epsx = 0;
ae_int_t maxits = 0;
minlmstate state;
minlmreport rep;
minlmcreatefgh(x, state);
minlmsetcond(state, epsg, epsf, epsx, maxits);
alglib::minlmoptimize(state, function1_func, function1_grad, function1_hess);
minlmresults(state, x, rep);
printf(<font color=blue><b>"%d\n"</b></font>, <b>int</b>(rep.terminationtype)); <font color=navy>// EXPECTED: 4</font>
printf(<font color=blue><b>"%s\n"</b></font>, x.tostring(2).c_str()); <font color=navy>// EXPECTED: [-3,+3]</font>
<b>return</b> 0;
}
</pre><a name='example_minlm_d_restarts'></a><h3 class=pageheader>minlm_d_restarts example</h3>
<pre class=source>
#include <font color=blue><b>"stdafx.h"</b></font>
#include <stdlib.h>
#include <stdio.h>
#include <math.h>
#include <font color=blue><b>"optimization.h"</b></font>
using namespace alglib;
<b>void</b> function1_fvec(<b>const</b> real_1d_array &x, real_1d_array &fi, <b>void</b> *ptr)
{
<font color=navy>//</font>
<font color=navy>// this callback calculates</font>
<font color=navy>// f0(x0,x1) = 100*(x0+3)^4,</font>
<font color=navy>// f1(x0,x1) = (x1-3)^4</font>
<font color=navy>//</font>
fi[0] = 10*pow(x[0]+3,2);
fi[1] = pow(x[1]-3,2);
}
<b>void</b> function2_fvec(<b>const</b> real_1d_array &x, real_1d_array &fi, <b>void</b> *ptr)
{
<font color=navy>//</font>
<font color=navy>// this callback calculates</font>
<font color=navy>// f0(x0,x1) = x0^2+1</font>
<font color=navy>// f1(x0,x1) = x1-1</font>
<font color=navy>//</font>
fi[0] = x[0]*x[0]+1;
fi[1] = x[1]-1;
}
<b>int</b> main(<b>int</b> argc, char **argv)
{
<font color=navy>//</font>
<font color=navy>// This example demonstrates minimization of F(x0,x1) = f0^2+f1^2, where </font>
<font color=navy>//</font>
<font color=navy>// f0(x0,x1) = 10*(x0+3)^2</font>
<font color=navy>// f1(x0,x1) = (x1-3)^2</font>
<font color=navy>//</font>
<font color=navy>// using several starting points and efficient restarts.</font>
<font color=navy>//</font>
real_1d_array x;
<b>double</b> epsg = 0.0000000001;
<b>double</b> epsf = 0;
<b>double</b> epsx = 0;
ae_int_t maxits = 0;
minlmstate state;
minlmreport rep;
<font color=navy>//</font>
<font color=navy>// create optimizer using minlmcreatev()</font>
<font color=navy>//</font>
x = <font color=blue><b>"[10,10]"</b></font>;
minlmcreatev(2, x, 0.0001, state);
minlmsetcond(state, epsg, epsf, epsx, maxits);
alglib::minlmoptimize(state, function1_fvec);
minlmresults(state, x, rep);
printf(<font color=blue><b>"%s\n"</b></font>, x.tostring(2).c_str()); <font color=navy>// EXPECTED: [-3,+3]</font>
<font color=navy>//</font>
<font color=navy>// restart optimizer using minlmrestartfrom()</font>
<font color=navy>//</font>
<font color=navy>// we can use different starting point, different function,</font>
<font color=navy>// different stopping conditions, but problem size</font>
<font color=navy>// must remain unchanged.</font>
<font color=navy>//</font>
x = <font color=blue><b>"[4,4]"</b></font>;
minlmrestartfrom(state, x);
alglib::minlmoptimize(state, function2_fvec);
minlmresults(state, x, rep);
printf(<font color=blue><b>"%s\n"</b></font>, x.tostring(2).c_str()); <font color=navy>// EXPECTED: [0,1]</font>
<b>return</b> 0;
}
</pre><a name='example_minlm_d_v'></a><h3 class=pageheader>minlm_d_v example</h3>
<pre class=source>
#include <font color=blue><b>"stdafx.h"</b></font>
#include <stdlib.h>
#include <stdio.h>
#include <math.h>
#include <font color=blue><b>"optimization.h"</b></font>
using namespace alglib;
<b>void</b> function1_fvec(<b>const</b> real_1d_array &x, real_1d_array &fi, <b>void</b> *ptr)
{
<font color=navy>//</font>
<font color=navy>// this callback calculates</font>
<font color=navy>// f0(x0,x1) = 100*(x0+3)^4,</font>
<font color=navy>// f1(x0,x1) = (x1-3)^4</font>
<font color=navy>//</font>
fi[0] = 10*pow(x[0]+3,2);
fi[1] = pow(x[1]-3,2);
}
<b>int</b> main(<b>int</b> argc, char **argv)
{
<font color=navy>//</font>
<font color=navy>// This example demonstrates minimization of F(x0,x1) = f0^2+f1^2, where </font>
<font color=navy>//</font>
<font color=navy>// f0(x0,x1) = 10*(x0+3)^2</font>
<font color=navy>// f1(x0,x1) = (x1-3)^2</font>
<font color=navy>//</font>
<font color=navy>// using <font color=blue><b>"V"</b></font> mode of the Levenberg-Marquardt optimizer.</font>
<font color=navy>//</font>
<font color=navy>// Optimization algorithm uses:</font>
<font color=navy>// * function vector f[] = {f1,f2}</font>
<font color=navy>//</font>
<font color=navy>// No other information (Jacobian, gradient, etc.) is needed.</font>
<font color=navy>//</font>
real_1d_array x = <font color=blue><b>"[0,0]"</b></font>;
<b>double</b> epsg = 0.0000000001;
<b>double</b> epsf = 0;
<b>double</b> epsx = 0;
ae_int_t maxits = 0;
minlmstate state;
minlmreport rep;
minlmcreatev(2, x, 0.0001, state);
minlmsetcond(state, epsg, epsf, epsx, maxits);
alglib::minlmoptimize(state, function1_fvec);
minlmresults(state, x, rep);
printf(<font color=blue><b>"%d\n"</b></font>, <b>int</b>(rep.terminationtype)); <font color=navy>// EXPECTED: 4</font>
printf(<font color=blue><b>"%s\n"</b></font>, x.tostring(2).c_str()); <font color=navy>// EXPECTED: [-3,+3]</font>
<b>return</b> 0;
}
</pre><a name='example_minlm_d_vb'></a><h3 class=pageheader>minlm_d_vb example</h3>
<pre class=source>
#include <font color=blue><b>"stdafx.h"</b></font>
#include <stdlib.h>
#include <stdio.h>
#include <math.h>
#include <font color=blue><b>"optimization.h"</b></font>
using namespace alglib;
<b>void</b> function1_fvec(<b>const</b> real_1d_array &x, real_1d_array &fi, <b>void</b> *ptr)
{
<font color=navy>//</font>
<font color=navy>// this callback calculates</font>
<font color=navy>// f0(x0,x1) = 100*(x0+3)^4,</font>
<font color=navy>// f1(x0,x1) = (x1-3)^4</font>
<font color=navy>//</font>
fi[0] = 10*pow(x[0]+3,2);
fi[1] = pow(x[1]-3,2);
}
<b>int</b> main(<b>int</b> argc, char **argv)
{
<font color=navy>//</font>
<font color=navy>// This example demonstrates minimization of F(x0,x1) = f0^2+f1^2, where </font>
<font color=navy>//</font>
<font color=navy>// f0(x0,x1) = 10*(x0+3)^2</font>
<font color=navy>// f1(x0,x1) = (x1-3)^2</font>
<font color=navy>//</font>
<font color=navy>// with boundary constraints</font>
<font color=navy>//</font>
<font color=navy>// -1 <= x0 <= +1</font>
<font color=navy>// -1 <= x1 <= +1</font>
<font color=navy>//</font>
<font color=navy>// using <font color=blue><b>"V"</b></font> mode of the Levenberg-Marquardt optimizer.</font>
<font color=navy>//</font>
<font color=navy>// Optimization algorithm uses:</font>
<font color=navy>// * function vector f[] = {f1,f2}</font>
<font color=navy>//</font>
<font color=navy>// No other information (Jacobian, gradient, etc.) is needed.</font>
<font color=navy>//</font>
real_1d_array x = <font color=blue><b>"[0,0]"</b></font>;
real_1d_array bndl = <font color=blue><b>"[-1,-1]"</b></font>;
real_1d_array bndu = <font color=blue><b>"[+1,+1]"</b></font>;
<b>double</b> epsg = 0.0000000001;
<b>double</b> epsf = 0;
<b>double</b> epsx = 0;
ae_int_t maxits = 0;
minlmstate state;
minlmreport rep;
minlmcreatev(2, x, 0.0001, state);
minlmsetbc(state, bndl, bndu);
minlmsetcond(state, epsg, epsf, epsx, maxits);
alglib::minlmoptimize(state, function1_fvec);
minlmresults(state, x, rep);
printf(<font color=blue><b>"%d\n"</b></font>, <b>int</b>(rep.terminationtype)); <font color=navy>// EXPECTED: 4</font>
printf(<font color=blue><b>"%s\n"</b></font>, x.tostring(2).c_str()); <font color=navy>// EXPECTED: [-1,+1]</font>
<b>return</b> 0;
}
</pre><a name='example_minlm_d_vj'></a><h3 class=pageheader>minlm_d_vj example</h3>
<pre class=source>
#include <font color=blue><b>"stdafx.h"</b></font>
#include <stdlib.h>
#include <stdio.h>
#include <math.h>
#include <font color=blue><b>"optimization.h"</b></font>
using namespace alglib;
<b>void</b> function1_fvec(<b>const</b> real_1d_array &x, real_1d_array &fi, <b>void</b> *ptr)
{
<font color=navy>//</font>
<font color=navy>// this callback calculates</font>
<font color=navy>// f0(x0,x1) = 100*(x0+3)^4,</font>
<font color=navy>// f1(x0,x1) = (x1-3)^4</font>
<font color=navy>//</font>
fi[0] = 10*pow(x[0]+3,2);
fi[1] = pow(x[1]-3,2);
}
<b>void</b> function1_jac(<b>const</b> real_1d_array &x, real_1d_array &fi, real_2d_array &jac, <b>void</b> *ptr)
{
<font color=navy>//</font>
<font color=navy>// this callback calculates</font>
<font color=navy>// f0(x0,x1) = 100*(x0+3)^4,</font>
<font color=navy>// f1(x0,x1) = (x1-3)^4</font>
<font color=navy>// and Jacobian matrix J = [dfi/dxj]</font>
<font color=navy>//</font>
fi[0] = 10*pow(x[0]+3,2);
fi[1] = pow(x[1]-3,2);
jac[0][0] = 20*(x[0]+3);
jac[0][1] = 0;
jac[1][0] = 0;
jac[1][1] = 2*(x[1]-3);
}
<b>int</b> main(<b>int</b> argc, char **argv)
{
<font color=navy>//</font>
<font color=navy>// This example demonstrates minimization of F(x0,x1) = f0^2+f1^2, where </font>
<font color=navy>//</font>
<font color=navy>// f0(x0,x1) = 10*(x0+3)^2</font>
<font color=navy>// f1(x0,x1) = (x1-3)^2</font>
<font color=navy>//</font>
<font color=navy>// using <font color=blue><b>"VJ"</b></font> mode of the Levenberg-Marquardt optimizer.</font>
<font color=navy>//</font>
<font color=navy>// Optimization algorithm uses:</font>
<font color=navy>// * function vector f[] = {f1,f2}</font>
<font color=navy>// * Jacobian matrix J = {dfi/dxj}.</font>
<font color=navy>//</font>
real_1d_array x = <font color=blue><b>"[0,0]"</b></font>;
<b>double</b> epsg = 0.0000000001;
<b>double</b> epsf = 0;
<b>double</b> epsx = 0;
ae_int_t maxits = 0;
minlmstate state;
minlmreport rep;
minlmcreatevj(2, x, state);
minlmsetcond(state, epsg, epsf, epsx, maxits);
alglib::minlmoptimize(state, function1_fvec, function1_jac);
minlmresults(state, x, rep);
printf(<font color=blue><b>"%d\n"</b></font>, <b>int</b>(rep.terminationtype)); <font color=navy>// EXPECTED: 4</font>
printf(<font color=blue><b>"%s\n"</b></font>, x.tostring(2).c_str()); <font color=navy>// EXPECTED: [-3,+3]</font>
<b>return</b> 0;
}
</pre><a name=unit_minnlc></a><h2 class=pageheader><code>minnlc</code> subpackage</h2>
<div class=pagecontent>
<h3 class=pageheader>Classes</h3>
<a href='#struct_minnlcreport' class=toc>minnlcreport</a><br>
<a href='#struct_minnlcstate' class=toc>minnlcstate</a><br>
<h3 class=pageheader>Functions</h3>
<a href='#sub_minnlccreate' class=toc>minnlccreate</a><br>
<a href='#sub_minnlccreatef' class=toc>minnlccreatef</a><br>
<a href='#sub_minnlcoptimize' class=toc>minnlcoptimize</a><br>
<a href='#sub_minnlcrestartfrom' class=toc>minnlcrestartfrom</a><br>
<a href='#sub_minnlcresults' class=toc>minnlcresults</a><br>
<a href='#sub_minnlcresultsbuf' class=toc>minnlcresultsbuf</a><br>
<a href='#sub_minnlcsetalgoaul' class=toc>minnlcsetalgoaul</a><br>
<a href='#sub_minnlcsetbc' class=toc>minnlcsetbc</a><br>
<a href='#sub_minnlcsetcond' class=toc>minnlcsetcond</a><br>
<a href='#sub_minnlcsetgradientcheck' class=toc>minnlcsetgradientcheck</a><br>
<a href='#sub_minnlcsetlc' class=toc>minnlcsetlc</a><br>
<a href='#sub_minnlcsetnlc' class=toc>minnlcsetnlc</a><br>
<a href='#sub_minnlcsetprecexactlowrank' class=toc>minnlcsetprecexactlowrank</a><br>
<a href='#sub_minnlcsetprecinexact' class=toc>minnlcsetprecinexact</a><br>
<a href='#sub_minnlcsetprecnone' class=toc>minnlcsetprecnone</a><br>
<a href='#sub_minnlcsetscale' class=toc>minnlcsetscale</a><br>
<a href='#sub_minnlcsetxrep' class=toc>minnlcsetxrep</a><br>
<h3 class=pageheader>Examples</h3>
<table border=0 cellspacing=0 class='pagecontent'>
<tr align=left valign=top><td><a href='#example_minnlc_d_equality' class=toc>minnlc_d_equality</a></td><td width=15> </td><td>Nonlinearly constrained optimization (equality constraints)</td></tr>
<tr align=left valign=top><td><a href='#example_minnlc_d_inequality' class=toc>minnlc_d_inequality</a></td><td width=15> </td><td>Nonlinearly constrained optimization (inequality constraints)</td></tr>
<tr align=left valign=top><td><a href='#example_minnlc_d_mixed' class=toc>minnlc_d_mixed</a></td><td width=15> </td><td>Nonlinearly constrained optimization with mixed equality/inequality constraints</td></tr>
</table></div>
<a name='struct_minnlcreport'></a><h3 class=pageheader><code>minnlcreport</code> class</h3>
<pre class=source>
<div style='color: navy; margin-top: 0; margin-bottom: 0;'>/*************************************************************************
This structure stores optimization report:
* IterationsCount total number of inner iterations
* NFEV number of gradient evaluations
* TerminationType termination type (see below)
TERMINATION CODES
TerminationType field contains completion code, which can be:
-8 internal integrity control detected infinite or NAN values in
function/gradient. Abnormal termination signalled.
-7 gradient verification failed.
See MinNLCSetGradientCheck() for more information.
1 relative function improvement is no more than EpsF.
2 relative step is no more than EpsX.
4 gradient norm is no more than EpsG
5 MaxIts steps was taken
7 stopping conditions are too stringent,
further improvement is impossible,
X contains best point found so far.
Other fields of this structure are not documented and should not be used!
*************************************************************************/
</div><div style='margin-top: 0; margin-bottom: 0;'><b>class</b> minnlcreport
{
ae_int_t iterationscount;
ae_int_t nfev;
ae_int_t varidx;
ae_int_t funcidx;
ae_int_t terminationtype;
ae_int_t dbgphase0its;
};
</div></pre>
<a name='struct_minnlcstate'></a><h3 class=pageheader><code>minnlcstate</code> class</h3>
<pre class=source>
<div style='color: navy; margin-top: 0; margin-bottom: 0;'>/*************************************************************************
This object stores nonlinear optimizer state.
You should use functions provided by MinNLC subpackage to work with this
object
*************************************************************************/
</div><div style='margin-top: 0; margin-bottom: 0;'><b>class</b> minnlcstate
{
};
</div></pre>
<a name='sub_minnlccreate'></a><h3 class=pageheader><code>minnlccreate</code> function</h3>
<pre class=source>
<div style='color: navy; margin-top: 0; margin-bottom: 0;'>/*************************************************************************
NONLINEARLY CONSTRAINED OPTIMIZATION
WITH PRECONDITIONED AUGMENTED LAGRANGIAN ALGORITHM
DESCRIPTION:
The subroutine minimizes function F(x) of N arguments subject to any
combination of:
* bound constraints
* linear inequality constraints
* linear equality constraints
* nonlinear equality constraints Gi(x)=0
* nonlinear inequality constraints Hi(x)<=0
REQUIREMENTS:
* user must provide function value and gradient for F(), H(), G()
* starting point X0 must be feasible or not too far away from the feasible
set
* F(), G(), H() are twice continuously differentiable on the feasible set
and its neighborhood
* nonlinear constraints G() and H() must have non-zero gradient at G(x)=0
and at H(x)=0. Say, constraint like x^2>=1 is supported, but x^2>=0 is
NOT supported.
USAGE:
Constrained optimization if far more complex than the unconstrained one.
Nonlinearly constrained optimization is one of the most esoteric numerical
procedures.
Here we give very brief outline of the MinNLC optimizer. We strongly
recommend you to study examples in the ALGLIB Reference Manual and to read
ALGLIB User Guide on optimization, which is available at
http://www.alglib.net/optimization/
1. User initializes algorithm state with MinNLCCreate() call and chooses
what NLC solver to use. There is some solver which is used by default,
with default settings, but you should NOT rely on default choice. It
may change in future releases of ALGLIB without notice, and no one can
guarantee that new solver will be able to solve your problem with
default settings.
From the other side, if you choose solver explicitly, you can be pretty
sure that it will work with new ALGLIB releases.
In the current release following solvers can be used:
* AUL solver (activated with MinNLCSetAlgoAUL() function)
2. User adds boundary and/or linear and/or nonlinear constraints by means
of calling one of the following functions:
a) MinNLCSetBC() for boundary constraints
b) MinNLCSetLC() for linear constraints
c) MinNLCSetNLC() for nonlinear constraints
You may combine (a), (b) and (c) in one optimization problem.
3. User sets scale of the variables with MinNLCSetScale() function. It is
VERY important to set scale of the variables, because nonlinearly
constrained problems are hard to solve when variables are badly scaled.
4. User sets stopping conditions with MinNLCSetCond(). If NLC solver
uses inner/outer iteration layout, this function sets stopping
conditions for INNER iterations.
5. User chooses one of the preconditioning methods. Preconditioning is
very important for efficient handling of boundary/linear/nonlinear
constraints. Without preconditioning algorithm would require thousands
of iterations even for simple problems. Two preconditioners can be
used:
* approximate LBFGS-based preconditioner which should be used for
problems with almost orthogonal constraints (activated by calling
MinNLCSetPrecInexact)
* exact low-rank preconditiner (activated by MinNLCSetPrecExactLowRank)
which should be used for problems with moderate number of constraints
which do not have to be orthogonal.
6. Finally, user calls MinNLCOptimize() function which takes algorithm
state and pointer (delegate, etc.) to callback function which calculates
F/G/H.
7. User calls MinNLCResults() to get solution
8. Optionally user may call MinNLCRestartFrom() to solve another problem
with same N but another starting point. MinNLCRestartFrom() allows to
reuse already initialized structure.
INPUT PARAMETERS:
N - problem dimension, N>0:
* if given, only leading N elements of X are used
* if not given, automatically determined from size ofX
X - starting point, array[N]:
* it is better to set X to a feasible point
* but X can be infeasible, in which case algorithm will try
to find feasible point first, using X as initial
approximation.
OUTPUT PARAMETERS:
State - structure stores algorithm state
-- ALGLIB --
Copyright 06.06.2014 by Bochkanov Sergey
*************************************************************************/
</div><div style='margin-top: 0; margin-bottom: 0;'><b>void</b> alglib::minnlccreate(real_1d_array x, minnlcstate& state);
<b>void</b> alglib::minnlccreate(
ae_int_t n,
real_1d_array x,
minnlcstate& state);
</div></pre>
<p align=left class=pagecontent><span class=inlineheader>Examples:</span> <a href='#example_minnlc_d_inequality' class=nav>[1]</a> <a href='#example_minnlc_d_equality' class=nav>[2]</a> <a href='#example_minnlc_d_mixed' class=nav>[3]</a> </p>
<a name='sub_minnlccreatef'></a><h3 class=pageheader><code>minnlccreatef</code> function</h3>
<pre class=source>
<div style='color: navy; margin-top: 0; margin-bottom: 0;'>/*************************************************************************
This subroutine is a finite difference variant of MinNLCCreate(). It uses
finite differences in order to differentiate target function.
Description below contains information which is specific to this function
only. We recommend to read comments on MinNLCCreate() in order to get more
information about creation of NLC optimizer.
INPUT PARAMETERS:
N - problem dimension, N>0:
* if given, only leading N elements of X are used
* if not given, automatically determined from size ofX
X - starting point, array[N]:
* it is better to set X to a feasible point
* but X can be infeasible, in which case algorithm will try
to find feasible point first, using X as initial
approximation.
DiffStep- differentiation step, >0
OUTPUT PARAMETERS:
State - structure stores algorithm state
NOTES:
1. algorithm uses 4-point central formula for differentiation.
2. differentiation step along I-th axis is equal to DiffStep*S[I] where
S[] is scaling vector which can be set by MinNLCSetScale() call.
3. we recommend you to use moderate values of differentiation step. Too
large step will result in too large TRUNCATION errors, while too small
step will result in too large NUMERICAL errors. 1.0E-4 can be good
value to start from.
4. Numerical differentiation is very inefficient - one gradient
calculation needs 4*N function evaluations. This function will work for
any N - either small (1...10), moderate (10...100) or large (100...).
However, performance penalty will be too severe for any N's except for
small ones.
We should also say that code which relies on numerical differentiation
is less robust and precise. Imprecise gradient may slow down
convergence, especially on highly nonlinear problems.
Thus we recommend to use this function for fast prototyping on small-
dimensional problems only, and to implement analytical gradient as soon
as possible.
-- ALGLIB --
Copyright 06.06.2014 by Bochkanov Sergey
*************************************************************************/
</div><div style='margin-top: 0; margin-bottom: 0;'><b>void</b> alglib::minnlccreatef(
real_1d_array x,
<b>double</b> diffstep,
minnlcstate& state);
<b>void</b> alglib::minnlccreatef(
ae_int_t n,
real_1d_array x,
<b>double</b> diffstep,
minnlcstate& state);
</div></pre>
<a name='sub_minnlcoptimize'></a><h3 class=pageheader><code>minnlcoptimize</code> function</h3>
<pre class=source>
<div style='color: navy; margin-top: 0; margin-bottom: 0;'>/*************************************************************************
This family of functions is used to launcn iterations of nonlinear optimizer
These functions accept following parameters:
state - algorithm state
fvec - callback which calculates function vector fi[]
at given point x
jac - callback which calculates function vector fi[]
and Jacobian jac at given point x
rep - optional callback which is called after each iteration
can be NULL
ptr - optional pointer which is passed to func/grad/hess/jac/rep
can be NULL
NOTES:
1. This function has two different implementations: one which uses exact
(analytical) user-supplied Jacobian, and one which uses only function
vector and numerically differentiates function in order to obtain
gradient.
Depending on the specific function used to create optimizer object
you should choose appropriate variant of MinNLCOptimize() - one which
accepts function AND Jacobian or one which accepts ONLY function.
Be careful to choose variant of MinNLCOptimize() which corresponds to
your optimization scheme! Table below lists different combinations of
callback (function/gradient) passed to MinNLCOptimize() and specific
function used to create optimizer.
| USER PASSED TO MinNLCOptimize()
CREATED WITH | function only | function and gradient
------------------------------------------------------------
MinNLCCreateF() | works FAILS
MinNLCCreate() | FAILS works
Here "FAILS" denotes inappropriate combinations of optimizer creation
function and MinNLCOptimize() version. Attemps to use such
combination will lead to exception. Either you did not pass gradient
when it WAS needed or you passed gradient when it was NOT needed.
-- ALGLIB --
Copyright 06.06.2014 by Bochkanov Sergey
*************************************************************************/
</div><div style='margin-top: 0; margin-bottom: 0;'><b>void</b> minnlcoptimize(minnlcstate &state,
<b>void</b> (*fvec)(<b>const</b> real_1d_array &x, real_1d_array &fi, <b>void</b> *ptr),
<b>void</b> (*rep)(<b>const</b> real_1d_array &x, <b>double</b> func, <b>void</b> *ptr) = NULL,
<b>void</b> *ptr = NULL);
<b>void</b> minnlcoptimize(minnlcstate &state,
<b>void</b> (*jac)(<b>const</b> real_1d_array &x, real_1d_array &fi, real_2d_array &jac, <b>void</b> *ptr),
<b>void</b> (*rep)(<b>const</b> real_1d_array &x, <b>double</b> func, <b>void</b> *ptr) = NULL,
<b>void</b> *ptr = NULL);
</div></pre>
<p align=left class=pagecontent><span class=inlineheader>Examples:</span> <a href='#example_minnlc_d_inequality' class=nav>[1]</a> <a href='#example_minnlc_d_equality' class=nav>[2]</a> <a href='#example_minnlc_d_mixed' class=nav>[3]</a> </p>
<a name='sub_minnlcrestartfrom'></a><h3 class=pageheader><code>minnlcrestartfrom</code> function</h3>
<pre class=source>
<div style='color: navy; margin-top: 0; margin-bottom: 0;'>/*************************************************************************
This subroutine restarts algorithm from new point.
All optimization parameters (including constraints) are left unchanged.
This function allows to solve multiple optimization problems (which
must have same number of dimensions) without object reallocation penalty.
INPUT PARAMETERS:
State - structure previously allocated with MinNLCCreate call.
X - new starting point.
-- ALGLIB --
Copyright 28.11.2010 by Bochkanov Sergey
*************************************************************************/
</div><div style='margin-top: 0; margin-bottom: 0;'><b>void</b> alglib::minnlcrestartfrom(minnlcstate state, real_1d_array x);
</div></pre>
<a name='sub_minnlcresults'></a><h3 class=pageheader><code>minnlcresults</code> function</h3>
<pre class=source>
<div style='color: navy; margin-top: 0; margin-bottom: 0;'>/*************************************************************************
MinNLC results
INPUT PARAMETERS:
State - algorithm state
OUTPUT PARAMETERS:
X - array[0..N-1], solution
Rep - optimization report. You should check Rep.TerminationType
in order to distinguish successful termination from
unsuccessful one:
* -8 internal integrity control detected infinite or
NAN values in function/gradient. Abnormal
termination signalled.
* -7 gradient verification failed.
See MinNLCSetGradientCheck() for more information.
* 1 relative function improvement is no more than EpsF.
* 2 scaled step is no more than EpsX.
* 4 scaled gradient norm is no more than EpsG.
* 5 MaxIts steps was taken
More information about fields of this structure can be
found in the comments on MinNLCReport datatype.
-- ALGLIB --
Copyright 06.06.2014 by Bochkanov Sergey
*************************************************************************/
</div><div style='margin-top: 0; margin-bottom: 0;'><b>void</b> alglib::minnlcresults(
minnlcstate state,
real_1d_array& x,
minnlcreport& rep);
</div></pre>
<p align=left class=pagecontent><span class=inlineheader>Examples:</span> <a href='#example_minnlc_d_inequality' class=nav>[1]</a> <a href='#example_minnlc_d_equality' class=nav>[2]</a> <a href='#example_minnlc_d_mixed' class=nav>[3]</a> </p>
<a name='sub_minnlcresultsbuf'></a><h3 class=pageheader><code>minnlcresultsbuf</code> function</h3>
<pre class=source>
<div style='color: navy; margin-top: 0; margin-bottom: 0;'>/*************************************************************************
NLC results
Buffered implementation of MinNLCResults() which uses pre-allocated buffer
to store X[]. If buffer size is too small, it resizes buffer. It is
intended to be used in the inner cycles of performance critical algorithms
where array reallocation penalty is too large to be ignored.
-- ALGLIB --
Copyright 28.11.2010 by Bochkanov Sergey
*************************************************************************/
</div><div style='margin-top: 0; margin-bottom: 0;'><b>void</b> alglib::minnlcresultsbuf(
minnlcstate state,
real_1d_array& x,
minnlcreport& rep);
</div></pre>
<a name='sub_minnlcsetalgoaul'></a><h3 class=pageheader><code>minnlcsetalgoaul</code> function</h3>
<pre class=source>
<div style='color: navy; margin-top: 0; margin-bottom: 0;'>/*************************************************************************
This function tells MinNLC unit to use Augmented Lagrangian algorithm
for nonlinearly constrained optimization. This algorithm is a slight
modification of one described in "A Modified Barrier-Augmented Lagrangian
Method for Constrained Minimization (1999)" by D.GOLDFARB, R.POLYAK,
K. SCHEINBERG, I.YUZEFOVICH.
Augmented Lagrangian algorithm works by converting problem of minimizing
F(x) subject to equality/inequality constraints to unconstrained problem
of the form
min[ f(x) +
+ Rho*PENALTY_EQ(x) + SHIFT_EQ(x,Nu1) +
+ Rho*PENALTY_INEQ(x) + SHIFT_INEQ(x,Nu2) ]
where:
* Rho is a fixed penalization coefficient
* PENALTY_EQ(x) is a penalty term, which is used to APPROXIMATELY enforce
equality constraints
* SHIFT_EQ(x) is a special "shift" term which is used to "fine-tune"
equality constraints, greatly increasing precision
* PENALTY_INEQ(x) is a penalty term which is used to approximately enforce
inequality constraints
* SHIFT_INEQ(x) is a special "shift" term which is used to "fine-tune"
inequality constraints, greatly increasing precision
* Nu1/Nu2 are vectors of Lagrange coefficients which are fine-tuned during
outer iterations of algorithm
This version of AUL algorithm uses preconditioner, which greatly
accelerates convergence. Because this algorithm is similar to penalty
methods, it may perform steps into infeasible area. All kinds of
constraints (boundary, linear and nonlinear ones) may be violated in
intermediate points - and in the solution. However, properly configured
AUL method is significantly better at handling constraints than barrier
and/or penalty methods.
The very basic outline of algorithm is given below:
1) first outer iteration is performed with "default" values of Lagrange
multipliers Nu1/Nu2. Solution quality is low (candidate point can be
too far away from true solution; large violation of constraints is
possible) and is comparable with that of penalty methods.
2) subsequent outer iterations refine Lagrange multipliers and improve
quality of the solution.
INPUT PARAMETERS:
State - structure which stores algorithm state
Rho - penalty coefficient, Rho>0:
* large enough that algorithm converges with desired
precision. Minimum value is 10*max(S'*diag(H)*S), where
S is a scale matrix (set by MinNLCSetScale) and H is a
Hessian of the function being minimized. If you can not
easily estimate Hessian norm, see our recommendations
below.
* not TOO large to prevent ill-conditioning
* for unit-scale problems (variables and Hessian have unit
magnitude), Rho=100 or Rho=1000 can be used.
* it is important to note that Rho is internally multiplied
by scaling matrix, i.e. optimum value of Rho depends on
scale of variables specified by MinNLCSetScale().
ItsCnt - number of outer iterations:
* ItsCnt=0 means that small number of outer iterations is
automatically chosen (10 iterations in current version).
* ItsCnt=1 means that AUL algorithm performs just as usual
barrier method.
* ItsCnt>1 means that AUL algorithm performs specified
number of outer iterations
HOW TO CHOOSE PARAMETERS
Nonlinear optimization is a tricky area and Augmented Lagrangian algorithm
is sometimes hard to tune. Good values of Rho and ItsCnt are problem-
specific. In order to help you we prepared following set of
recommendations:
* for unit-scale problems (variables and Hessian have unit magnitude),
Rho=100 or Rho=1000 can be used.
* start from some small value of Rho and solve problem with just one
outer iteration (ItcCnt=1). In this case algorithm behaves like penalty
method. Increase Rho in 2x or 10x steps until you see that one outer
iteration returns point which is "rough approximation to solution".
It is very important to have Rho so large that penalty term becomes
constraining i.e. modified function becomes highly convex in constrained
directions.
From the other side, too large Rho may prevent you from converging to
the solution. You can diagnose it by studying number of inner iterations
performed by algorithm: too few (5-10 on 1000-dimensional problem) or
too many (orders of magnitude more than dimensionality) usually means
that Rho is too large.
* with just one outer iteration you usually have low-quality solution.
Some constraints can be violated with very large margin, while other
ones (which are NOT violated in the true solution) can push final point
too far in the inner area of the feasible set.
For example, if you have constraint x0>=0 and true solution x0=1, then
merely a presence of "x0>=0" will introduce a bias towards larger values
of x0. Say, algorithm may stop at x0=1.5 instead of 1.0.
* after you found good Rho, you may increase number of outer iterations.
ItsCnt=10 is a good value. Subsequent outer iteration will refine values
of Lagrange multipliers. Constraints which were violated will be
enforced, inactive constraints will be dropped (corresponding multipliers
will be decreased). Ideally, you should see 10-1000x improvement in
constraint handling (constraint violation is reduced).
* if you see that algorithm converges to vicinity of solution, but
additional outer iterations do not refine solution, it may mean that
algorithm is unstable - it wanders around true solution, but can not
approach it. Sometimes algorithm may be stabilized by increasing Rho one
more time, making it 5x or 10x larger.
SCALING OF CONSTRAINTS [IMPORTANT]
AUL optimizer scales variables according to scale specified by
MinNLCSetScale() function, so it can handle problems with badly scaled
variables (as long as we KNOW their scales). However, because function
being optimized is a mix of original function and constraint-dependent
penalty functions, it is important to rescale both variables AND
constraints.
Say, if you minimize f(x)=x^2 subject to 1000000*x>=0, then you have
constraint whose scale is different from that of target function (another
example is 0.000001*x>=0). It is also possible to have constraints whose
scales are misaligned: 1000000*x0>=0, 0.000001*x1<=0. Inappropriate
scaling may ruin convergence because minimizing x^2 subject to x>=0 is NOT
same as minimizing it subject to 1000000*x>=0.
Because we know coefficients of boundary/linear constraints, we can
automatically rescale and normalize them. However, there is no way to
automatically rescale nonlinear constraints Gi(x) and Hi(x) - they are
black boxes.
It means that YOU are the one who is responsible for correct scaling of
nonlinear constraints Gi(x) and Hi(x). We recommend you to rescale
nonlinear constraints in such way that I-th component of dG/dX (or dH/dx)
has magnitude approximately equal to 1/S[i] (where S is a scale set by
MinNLCSetScale() function).
WHAT IF IT DOES NOT CONVERGE?
It is possible that AUL algorithm fails to converge to precise values of
Lagrange multipliers. It stops somewhere around true solution, but candidate
point is still too far from solution, and some constraints are violated.
Such kind of failure is specific for Lagrangian algorithms - technically,
they stop at some point, but this point is not constrained solution.
There are exist several reasons why algorithm may fail to converge:
a) too loose stopping criteria for inner iteration
b) degenerate, redundant constraints
c) target function has unconstrained extremum exactly at the boundary of
some constraint
d) numerical noise in the target function
In all these cases algorithm is unstable - each outer iteration results in
large and almost random step which improves handling of some constraints,
but violates other ones (ideally outer iterations should form a sequence
of progressively decreasing steps towards solution).
First reason possible is that too loose stopping criteria for inner
iteration were specified. Augmented Lagrangian algorithm solves a sequence
of intermediate problems, and requries each of them to be solved with high
precision. Insufficient precision results in incorrect update of Lagrange
multipliers.
Another reason is that you may have specified degenerate constraints: say,
some constraint was repeated twice. In most cases AUL algorithm gracefully
handles such situations, but sometimes it may spend too much time figuring
out subtle degeneracies in constraint matrix.
Third reason is tricky and hard to diagnose. Consider situation when you
minimize f=x^2 subject to constraint x>=0. Unconstrained extremum is
located exactly at the boundary of constrained area. In this case
algorithm will tend to oscillate between negative and positive x. Each
time it stops at x<0 it "reinforces" constraint x>=0, and each time it is
bounced to x>0 it "relaxes" constraint (and is attracted to x<0).
Such situation sometimes happens in problems with hidden symetries.
Algorithm is got caught in a loop with Lagrange multipliers being
continuously increased/decreased. Luckily, such loop forms after at least
three iterations, so this problem can be solved by DECREASING number of
outer iterations down to 1-2 and increasing penalty coefficient Rho as
much as possible.
Final reason is numerical noise. AUL algorithm is robust against moderate
noise (more robust than, say, active set methods), but large noise may
destabilize algorithm.
-- ALGLIB --
Copyright 06.06.2014 by Bochkanov Sergey
*************************************************************************/
</div><div style='margin-top: 0; margin-bottom: 0;'><b>void</b> alglib::minnlcsetalgoaul(
minnlcstate state,
<b>double</b> rho,
ae_int_t itscnt);
</div></pre>
<p align=left class=pagecontent><span class=inlineheader>Examples:</span> <a href='#example_minnlc_d_inequality' class=nav>[1]</a> <a href='#example_minnlc_d_equality' class=nav>[2]</a> <a href='#example_minnlc_d_mixed' class=nav>[3]</a> </p>
<a name='sub_minnlcsetbc'></a><h3 class=pageheader><code>minnlcsetbc</code> function</h3>
<pre class=source>
<div style='color: navy; margin-top: 0; margin-bottom: 0;'>/*************************************************************************
This function sets boundary constraints for NLC optimizer.
Boundary constraints are inactive by default (after initial creation).
They are preserved after algorithm restart with MinNLCRestartFrom().
You may combine boundary constraints with general linear ones - and with
nonlinear ones! Boundary constraints are handled more efficiently than
other types. Thus, if your problem has mixed constraints, you may
explicitly specify some of them as boundary and save some time/space.
INPUT PARAMETERS:
State - structure stores algorithm state
BndL - lower bounds, array[N].
If some (all) variables are unbounded, you may specify
very small number or -INF.
BndU - upper bounds, array[N].
If some (all) variables are unbounded, you may specify
very large number or +INF.
NOTE 1: it is possible to specify BndL[i]=BndU[i]. In this case I-th
variable will be "frozen" at X[i]=BndL[i]=BndU[i].
NOTE 2: when you solve your problem with augmented Lagrangian solver,
boundary constraints are satisfied only approximately! It is
possible that algorithm will evaluate function outside of
feasible area!
-- ALGLIB --
Copyright 06.06.2014 by Bochkanov Sergey
*************************************************************************/
</div><div style='margin-top: 0; margin-bottom: 0;'><b>void</b> alglib::minnlcsetbc(
minnlcstate state,
real_1d_array bndl,
real_1d_array bndu);
</div></pre>
<a name='sub_minnlcsetcond'></a><h3 class=pageheader><code>minnlcsetcond</code> function</h3>
<pre class=source>
<div style='color: navy; margin-top: 0; margin-bottom: 0;'>/*************************************************************************
This function sets stopping conditions for inner iterations of optimizer.
INPUT PARAMETERS:
State - structure which stores algorithm state
EpsG - >=0
The subroutine finishes its work if the condition
|v|<EpsG is satisfied, where:
* |.| means Euclidian norm
* v - scaled gradient vector, v[i]=g[i]*s[i]
* g - gradient
* s - scaling coefficients set by MinNLCSetScale()
EpsF - >=0
The subroutine finishes its work if on k+1-th iteration
the condition |F(k+1)-F(k)|<=EpsF*max{|F(k)|,|F(k+1)|,1}
is satisfied.
EpsX - >=0
The subroutine finishes its work if on k+1-th iteration
the condition |v|<=EpsX is fulfilled, where:
* |.| means Euclidian norm
* v - scaled step vector, v[i]=dx[i]/s[i]
* dx - step vector, dx=X(k+1)-X(k)
* s - scaling coefficients set by MinNLCSetScale()
MaxIts - maximum number of iterations. If MaxIts=0, the number of
iterations is unlimited.
Passing EpsG=0, EpsF=0 and EpsX=0 and MaxIts=0 (simultaneously) will lead
to automatic stopping criterion selection.
-- ALGLIB --
Copyright 06.06.2014 by Bochkanov Sergey
*************************************************************************/
</div><div style='margin-top: 0; margin-bottom: 0;'><b>void</b> alglib::minnlcsetcond(
minnlcstate state,
<b>double</b> epsg,
<b>double</b> epsf,
<b>double</b> epsx,
ae_int_t maxits);
</div></pre>
<p align=left class=pagecontent><span class=inlineheader>Examples:</span> <a href='#example_minnlc_d_inequality' class=nav>[1]</a> <a href='#example_minnlc_d_equality' class=nav>[2]</a> <a href='#example_minnlc_d_mixed' class=nav>[3]</a> </p>
<a name='sub_minnlcsetgradientcheck'></a><h3 class=pageheader><code>minnlcsetgradientcheck</code> function</h3>
<pre class=source>
<div style='color: navy; margin-top: 0; margin-bottom: 0;'>/*************************************************************************
This subroutine turns on verification of the user-supplied analytic
gradient:
* user calls this subroutine before optimization begins
* MinNLCOptimize() is called
* prior to actual optimization, for each component of parameters being
optimized X[i] algorithm performs following steps:
* two trial steps are made to X[i]-TestStep*S[i] and X[i]+TestStep*S[i],
where X[i] is i-th component of the initial point and S[i] is a scale
of i-th parameter
* F(X) is evaluated at these trial points
* we perform one more evaluation in the middle point of the interval
* we build cubic model using function values and derivatives at trial
points and we compare its prediction with actual value in the middle
point
* in case difference between prediction and actual value is higher than
some predetermined threshold, algorithm stops with completion code -7;
Rep.VarIdx is set to index of the parameter with incorrect derivative,
and Rep.FuncIdx is set to index of the function.
* after verification is over, algorithm proceeds to the actual optimization.
NOTE 1: verification needs N (parameters count) gradient evaluations. It
is very costly and you should use it only for low dimensional
problems, when you want to be sure that you've correctly
calculated analytic derivatives. You should not use it in the
production code (unless you want to check derivatives provided by
some third party).
NOTE 2: you should carefully choose TestStep. Value which is too large
(so large that function behaviour is significantly non-cubic) will
lead to false alarms. You may use different step for different
parameters by means of setting scale with MinNLCSetScale().
NOTE 3: this function may lead to false positives. In case it reports that
I-th derivative was calculated incorrectly, you may decrease test
step and try one more time - maybe your function changes too
sharply and your step is too large for such rapidly chanding
function.
INPUT PARAMETERS:
State - structure used to store algorithm state
TestStep - verification step:
* TestStep=0 turns verification off
* TestStep>0 activates verification
-- ALGLIB --
Copyright 15.06.2014 by Bochkanov Sergey
*************************************************************************/
</div><div style='margin-top: 0; margin-bottom: 0;'><b>void</b> alglib::minnlcsetgradientcheck(minnlcstate state, <b>double</b> teststep);
</div></pre>
<a name='sub_minnlcsetlc'></a><h3 class=pageheader><code>minnlcsetlc</code> function</h3>
<pre class=source>
<div style='color: navy; margin-top: 0; margin-bottom: 0;'>/*************************************************************************
This function sets linear constraints for MinNLC optimizer.
Linear constraints are inactive by default (after initial creation). They
are preserved after algorithm restart with MinNLCRestartFrom().
You may combine linear constraints with boundary ones - and with nonlinear
ones! If your problem has mixed constraints, you may explicitly specify
some of them as linear. It may help optimizer to handle them more
efficiently.
INPUT PARAMETERS:
State - structure previously allocated with MinNLCCreate call.
C - linear constraints, array[K,N+1].
Each row of C represents one constraint, either equality
or inequality (see below):
* first N elements correspond to coefficients,
* last element corresponds to the right part.
All elements of C (including right part) must be finite.
CT - type of constraints, array[K]:
* if CT[i]>0, then I-th constraint is C[i,*]*x >= C[i,n+1]
* if CT[i]=0, then I-th constraint is C[i,*]*x = C[i,n+1]
* if CT[i]<0, then I-th constraint is C[i,*]*x <= C[i,n+1]
K - number of equality/inequality constraints, K>=0:
* if given, only leading K elements of C/CT are used
* if not given, automatically determined from sizes of C/CT
NOTE 1: when you solve your problem with augmented Lagrangian solver,
linear constraints are satisfied only approximately! It is
possible that algorithm will evaluate function outside of
feasible area!
-- ALGLIB --
Copyright 06.06.2014 by Bochkanov Sergey
*************************************************************************/
</div><div style='margin-top: 0; margin-bottom: 0;'><b>void</b> alglib::minnlcsetlc(
minnlcstate state,
real_2d_array c,
integer_1d_array ct);
<b>void</b> alglib::minnlcsetlc(
minnlcstate state,
real_2d_array c,
integer_1d_array ct,
ae_int_t k);
</div></pre>
<a name='sub_minnlcsetnlc'></a><h3 class=pageheader><code>minnlcsetnlc</code> function</h3>
<pre class=source>
<div style='color: navy; margin-top: 0; margin-bottom: 0;'>/*************************************************************************
This function sets nonlinear constraints for MinNLC optimizer.
In fact, this function sets NUMBER of nonlinear constraints. Constraints
itself (constraint functions) are passed to MinNLCOptimize() method. This
method requires user-defined vector function F[] and its Jacobian J[],
where:
* first component of F[] and first row of Jacobian J[] corresponds to
function being minimized
* next NLEC components of F[] (and rows of J) correspond to nonlinear
equality constraints G_i(x)=0
* next NLIC components of F[] (and rows of J) correspond to nonlinear
inequality constraints H_i(x)<=0
NOTE: you may combine nonlinear constraints with linear/boundary ones. If
your problem has mixed constraints, you may explicitly specify some
of them as linear ones. It may help optimizer to handle them more
efficiently.
INPUT PARAMETERS:
State - structure previously allocated with MinNLCCreate call.
NLEC - number of Non-Linear Equality Constraints (NLEC), >=0
NLIC - number of Non-Linear Inquality Constraints (NLIC), >=0
NOTE 1: when you solve your problem with augmented Lagrangian solver,
nonlinear constraints are satisfied only approximately! It is
possible that algorithm will evaluate function outside of
feasible area!
NOTE 2: algorithm scales variables according to scale specified by
MinNLCSetScale() function, so it can handle problems with badly
scaled variables (as long as we KNOW their scales).
However, there is no way to automatically scale nonlinear
constraints Gi(x) and Hi(x). Inappropriate scaling of Gi/Hi may
ruin convergence. Solving problem with constraint "1000*G0(x)=0"
is NOT same as solving it with constraint "0.001*G0(x)=0".
It means that YOU are the one who is responsible for correct
scaling of nonlinear constraints Gi(x) and Hi(x). We recommend you
to scale nonlinear constraints in such way that I-th component of
dG/dX (or dH/dx) has approximately unit magnitude (for problems
with unit scale) or has magnitude approximately equal to 1/S[i]
(where S is a scale set by MinNLCSetScale() function).
-- ALGLIB --
Copyright 06.06.2014 by Bochkanov Sergey
*************************************************************************/
</div><div style='margin-top: 0; margin-bottom: 0;'><b>void</b> alglib::minnlcsetnlc(
minnlcstate state,
ae_int_t nlec,
ae_int_t nlic);
</div></pre>
<p align=left class=pagecontent><span class=inlineheader>Examples:</span> <a href='#example_minnlc_d_inequality' class=nav>[1]</a> <a href='#example_minnlc_d_equality' class=nav>[2]</a> <a href='#example_minnlc_d_mixed' class=nav>[3]</a> </p>
<a name='sub_minnlcsetprecexactlowrank'></a><h3 class=pageheader><code>minnlcsetprecexactlowrank</code> function</h3>
<pre class=source>
<div style='color: navy; margin-top: 0; margin-bottom: 0;'>/*************************************************************************
This function sets preconditioner to "exact low rank" mode.
Preconditioning is very important for convergence of Augmented Lagrangian
algorithm because presence of penalty term makes problem ill-conditioned.
Difference between performance of preconditioned and unpreconditioned
methods can be as large as 100x!
MinNLC optimizer may utilize two preconditioners, each with its own
benefits and drawbacks: a) inexact LBFGS-based, and b) exact low rank one.
It also provides special unpreconditioned mode of operation which can be
used for test purposes. Comments below discuss low rank preconditioner.
Exact low-rank preconditioner uses Woodbury matrix identity to build
quadratic model of the penalized function. It has no special assumptions
about orthogonality, so it is quite general. However, for a N-dimensional
problem with K general linear or nonlinear constraints (boundary ones are
not counted) it has O(N*K^2) cost per iteration (for comparison: inexact
LBFGS-based preconditioner has O(N*K) cost).
INPUT PARAMETERS:
State - structure stores algorithm state
UpdateFreq- update frequency. Preconditioner is rebuilt after every
UpdateFreq iterations. Recommended value: 10 or higher.
Zero value means that good default value will be used.
-- ALGLIB --
Copyright 26.09.2014 by Bochkanov Sergey
*************************************************************************/
</div><div style='margin-top: 0; margin-bottom: 0;'><b>void</b> alglib::minnlcsetprecexactlowrank(
minnlcstate state,
ae_int_t updatefreq);
</div></pre>
<p align=left class=pagecontent><span class=inlineheader>Examples:</span> <a href='#example_minnlc_d_inequality' class=nav>[1]</a> <a href='#example_minnlc_d_equality' class=nav>[2]</a> <a href='#example_minnlc_d_mixed' class=nav>[3]</a> </p>
<a name='sub_minnlcsetprecinexact'></a><h3 class=pageheader><code>minnlcsetprecinexact</code> function</h3>
<pre class=source>
<div style='color: navy; margin-top: 0; margin-bottom: 0;'>/*************************************************************************
This function sets preconditioner to "inexact LBFGS-based" mode.
Preconditioning is very important for convergence of Augmented Lagrangian
algorithm because presence of penalty term makes problem ill-conditioned.
Difference between performance of preconditioned and unpreconditioned
methods can be as large as 100x!
MinNLC optimizer may utilize two preconditioners, each with its own
benefits and drawbacks: a) inexact LBFGS-based, and b) exact low rank one.
It also provides special unpreconditioned mode of operation which can be
used for test purposes. Comments below discuss LBFGS-based preconditioner.
Inexact LBFGS-based preconditioner uses L-BFGS formula combined with
orthogonality assumption to perform very fast updates. For a N-dimensional
problem with K general linear or nonlinear constraints (boundary ones are
not counted) it has O(N*K) cost per iteration. This preconditioner has
best quality (less iterations) when general linear and nonlinear
constraints are orthogonal to each other (orthogonality with respect to
boundary constraints is not required). Number of iterations increases when
constraints are non-orthogonal, because algorithm assumes orthogonality,
but still it is better than no preconditioner at all.
INPUT PARAMETERS:
State - structure stores algorithm state
-- ALGLIB --
Copyright 26.09.2014 by Bochkanov Sergey
*************************************************************************/
</div><div style='margin-top: 0; margin-bottom: 0;'><b>void</b> alglib::minnlcsetprecinexact(minnlcstate state);
</div></pre>
<a name='sub_minnlcsetprecnone'></a><h3 class=pageheader><code>minnlcsetprecnone</code> function</h3>
<pre class=source>
<div style='color: navy; margin-top: 0; margin-bottom: 0;'>/*************************************************************************
This function sets preconditioner to "turned off" mode.
Preconditioning is very important for convergence of Augmented Lagrangian
algorithm because presence of penalty term makes problem ill-conditioned.
Difference between performance of preconditioned and unpreconditioned
methods can be as large as 100x!
MinNLC optimizer may utilize two preconditioners, each with its own
benefits and drawbacks: a) inexact LBFGS-based, and b) exact low rank one.
It also provides special unpreconditioned mode of operation which can be
used for test purposes.
This function activates this test mode. Do not use it in production code
to solve real-life problems.
INPUT PARAMETERS:
State - structure stores algorithm state
-- ALGLIB --
Copyright 26.09.2014 by Bochkanov Sergey
*************************************************************************/
</div><div style='margin-top: 0; margin-bottom: 0;'><b>void</b> alglib::minnlcsetprecnone(minnlcstate state);
</div></pre>
<a name='sub_minnlcsetscale'></a><h3 class=pageheader><code>minnlcsetscale</code> function</h3>
<pre class=source>
<div style='color: navy; margin-top: 0; margin-bottom: 0;'>/*************************************************************************
This function sets scaling coefficients for NLC optimizer.
ALGLIB optimizers use scaling matrices to test stopping conditions (step
size and gradient are scaled before comparison with tolerances). Scale of
the I-th variable is a translation invariant measure of:
a) "how large" the variable is
b) how large the step should be to make significant changes in the function
Scaling is also used by finite difference variant of the optimizer - step
along I-th axis is equal to DiffStep*S[I].
INPUT PARAMETERS:
State - structure stores algorithm state
S - array[N], non-zero scaling coefficients
S[i] may be negative, sign doesn't matter.
-- ALGLIB --
Copyright 06.06.2014 by Bochkanov Sergey
*************************************************************************/
</div><div style='margin-top: 0; margin-bottom: 0;'><b>void</b> alglib::minnlcsetscale(minnlcstate state, real_1d_array s);
</div></pre>
<p align=left class=pagecontent><span class=inlineheader>Examples:</span> <a href='#example_minnlc_d_inequality' class=nav>[1]</a> <a href='#example_minnlc_d_equality' class=nav>[2]</a> <a href='#example_minnlc_d_mixed' class=nav>[3]</a> </p>
<a name='sub_minnlcsetxrep'></a><h3 class=pageheader><code>minnlcsetxrep</code> function</h3>
<pre class=source>
<div style='color: navy; margin-top: 0; margin-bottom: 0;'>/*************************************************************************
This function turns on/off reporting.
INPUT PARAMETERS:
State - structure which stores algorithm state
NeedXRep- whether iteration reports are needed or not
If NeedXRep is True, algorithm will call rep() callback function if it is
provided to MinNLCOptimize().
NOTE: algorithm passes two parameters to rep() callback - current point
and penalized function value at current point. Important - function
value which is returned is NOT function being minimized. It is sum
of the value of the function being minimized - and penalty term.
-- ALGLIB --
Copyright 28.11.2010 by Bochkanov Sergey
*************************************************************************/
</div><div style='margin-top: 0; margin-bottom: 0;'><b>void</b> alglib::minnlcsetxrep(minnlcstate state, <b>bool</b> needxrep);
</div></pre>
<a name='example_minnlc_d_equality'></a><h3 class=pageheader>minnlc_d_equality example</h3>
<pre class=source>
#include <font color=blue><b>"stdafx.h"</b></font>
#include <stdlib.h>
#include <stdio.h>
#include <math.h>
#include <font color=blue><b>"optimization.h"</b></font>
using namespace alglib;
<b>void</b> nlcfunc1_jac(<b>const</b> real_1d_array &x, real_1d_array &fi, real_2d_array &jac, <b>void</b> *ptr)
{
<font color=navy>//</font>
<font color=navy>// this callback calculates</font>
<font color=navy>//</font>
<font color=navy>// f0(x0,x1) = -x0+x1</font>
<font color=navy>// f1(x0,x1) = x0^2+x1^2-1</font>
<font color=navy>//</font>
<font color=navy>// and Jacobian matrix J = [dfi/dxj]</font>
<font color=navy>//</font>
fi[0] = -x[0]+x[1];
fi[1] = x[0]*x[0] + x[1]*x[1] - 1.0;
jac[0][0] = -1.0;
jac[0][1] = +1.0;
jac[1][0] = 2*x[0];
jac[1][1] = 2*x[1];
}
<b>int</b> main(<b>int</b> argc, char **argv)
{
<font color=navy>//</font>
<font color=navy>// This example demonstrates minimization of</font>
<font color=navy>//</font>
<font color=navy>// f(x0,x1) = -x0+x1</font>
<font color=navy>//</font>
<font color=navy>// subject to nonlinear equality constraint</font>
<font color=navy>//</font>
<font color=navy>// x0^2 + x1^2 - 1 = 0</font>
<font color=navy>//</font>
real_1d_array x0 = <font color=blue><b>"[0,0]"</b></font>;
real_1d_array s = <font color=blue><b>"[1,1]"</b></font>;
<b>double</b> epsg = 0;
<b>double</b> epsf = 0;
<b>double</b> epsx = 0.000001;
ae_int_t maxits = 0;
ae_int_t outerits = 5;
ae_int_t updatefreq = 10;
<b>double</b> rho = 1000;
minnlcstate state;
minnlcreport rep;
real_1d_array x1;
<font color=navy>//</font>
<font color=navy>// Create optimizer object, choose AUL algorithm and tune its settings:</font>
<font color=navy>// * rho=1000 penalty coefficient</font>
<font color=navy>// * outerits=5 number of outer iterations to tune Lagrange coefficients</font>
<font color=navy>// * epsx=0.000001 stopping condition <b>for</b> inner iterations</font>
<font color=navy>// * s=[1,1] all variables have unit scale</font>
<font color=navy>// * exact low-rank preconditioner is used, updated after each 10 iterations</font>
<font color=navy>//</font>
minnlccreate(2, x0, state);
minnlcsetalgoaul(state, rho, outerits);
minnlcsetcond(state, epsg, epsf, epsx, maxits);
minnlcsetscale(state, s);
minnlcsetprecexactlowrank(state, updatefreq);
<font color=navy>//</font>
<font color=navy>// Set constraints:</font>
<font color=navy>//</font>
<font color=navy>// Nonlinear constraints are tricky - you can not <font color=blue><b>"pack"</b></font> general</font>
<font color=navy>// nonlinear function into <b>double</b> precision array. That's why</font>
<font color=navy>// minnlcsetnlc() does not accept constraints itself - only constraint</font>
<font color=navy>// counts are passed: first parameter is number of equality constraints,</font>
<font color=navy>// second one is number of inequality constraints.</font>
<font color=navy>//</font>
<font color=navy>// As <b>for</b> constraining functions - these functions are passed as part</font>
<font color=navy>// of problem Jacobian (see below).</font>
<font color=navy>//</font>
<font color=navy>// NOTE: MinNLC optimizer supports arbitrary combination of boundary, general</font>
<font color=navy>// linear and general nonlinear constraints. This example does not</font>
<font color=navy>// show how to work with general linear constraints, but you can</font>
<font color=navy>// easily find it in documentation on minnlcsetbc() and</font>
<font color=navy>// minnlcsetlc() functions.</font>
<font color=navy>//</font>
minnlcsetnlc(state, 1, 0);
<font color=navy>//</font>
<font color=navy>// Optimize and test results.</font>
<font color=navy>//</font>
<font color=navy>// Optimizer object accepts vector function and its Jacobian, with first</font>
<font color=navy>// component (Jacobian row) being target function, and next components</font>
<font color=navy>// (Jacobian rows) being nonlinear equality and inequality constraints.</font>
<font color=navy>//</font>
<font color=navy>// So, our vector function has form</font>
<font color=navy>//</font>
<font color=navy>// {f0,f1} = { -x0+x1 , x0^2+x1^2-1 }</font>
<font color=navy>//</font>
<font color=navy>// with Jacobian</font>
<font color=navy>//</font>
<font color=navy>// [ -1 +1 ]</font>
<font color=navy>// J = [ ]</font>
<font color=navy>// [ 2*x0 2*x1 ]</font>
<font color=navy>//</font>
<font color=navy>// with f0 being target function, f1 being constraining function. Number</font>
<font color=navy>// of equality/inequality constraints is specified by minnlcsetnlc(),</font>
<font color=navy>// with equality ones always being first, inequality ones being last.</font>
<font color=navy>//</font>
alglib::minnlcoptimize(state, nlcfunc1_jac);
minnlcresults(state, x1, rep);
printf(<font color=blue><b>"%s\n"</b></font>, x1.tostring(2).c_str()); <font color=navy>// EXPECTED: [0.70710,-0.70710]</font>
<b>return</b> 0;
}
</pre><a name='example_minnlc_d_inequality'></a><h3 class=pageheader>minnlc_d_inequality example</h3>
<pre class=source>
#include <font color=blue><b>"stdafx.h"</b></font>
#include <stdlib.h>
#include <stdio.h>
#include <math.h>
#include <font color=blue><b>"optimization.h"</b></font>
using namespace alglib;
<b>void</b> nlcfunc1_jac(<b>const</b> real_1d_array &x, real_1d_array &fi, real_2d_array &jac, <b>void</b> *ptr)
{
<font color=navy>//</font>
<font color=navy>// this callback calculates</font>
<font color=navy>//</font>
<font color=navy>// f0(x0,x1) = -x0+x1</font>
<font color=navy>// f1(x0,x1) = x0^2+x1^2-1</font>
<font color=navy>//</font>
<font color=navy>// and Jacobian matrix J = [dfi/dxj]</font>
<font color=navy>//</font>
fi[0] = -x[0]+x[1];
fi[1] = x[0]*x[0] + x[1]*x[1] - 1.0;
jac[0][0] = -1.0;
jac[0][1] = +1.0;
jac[1][0] = 2*x[0];
jac[1][1] = 2*x[1];
}
<b>int</b> main(<b>int</b> argc, char **argv)
{
<font color=navy>//</font>
<font color=navy>// This example demonstrates minimization of</font>
<font color=navy>//</font>
<font color=navy>// f(x0,x1) = -x0+x1</font>
<font color=navy>//</font>
<font color=navy>// subject to boundary constraints</font>
<font color=navy>//</font>
<font color=navy>// x0>=0, x1>=0</font>
<font color=navy>//</font>
<font color=navy>// and nonlinear inequality constraint</font>
<font color=navy>//</font>
<font color=navy>// x0^2 + x1^2 - 1 <= 0</font>
<font color=navy>//</font>
real_1d_array x0 = <font color=blue><b>"[0,0]"</b></font>;
real_1d_array s = <font color=blue><b>"[1,1]"</b></font>;
<b>double</b> epsg = 0;
<b>double</b> epsf = 0;
<b>double</b> epsx = 0.000001;
ae_int_t maxits = 0;
ae_int_t outerits = 5;
ae_int_t updatefreq = 10;
<b>double</b> rho = 1000;
real_1d_array bndl = <font color=blue><b>"[0,0]"</b></font>;
real_1d_array bndu = <font color=blue><b>"[+inf,+inf]"</b></font>;
minnlcstate state;
minnlcreport rep;
real_1d_array x1;
<font color=navy>//</font>
<font color=navy>// Create optimizer object, choose AUL algorithm and tune its settings:</font>
<font color=navy>// * rho=1000 penalty coefficient</font>
<font color=navy>// * outerits=5 number of outer iterations to tune Lagrange coefficients</font>
<font color=navy>// * epsx=0.000001 stopping condition <b>for</b> inner iterations</font>
<font color=navy>// * s=[1,1] all variables have unit scale</font>
<font color=navy>// * exact low-rank preconditioner is used, updated after each 10 iterations</font>
<font color=navy>//</font>
minnlccreate(2, x0, state);
minnlcsetalgoaul(state, rho, outerits);
minnlcsetcond(state, epsg, epsf, epsx, maxits);
minnlcsetscale(state, s);
minnlcsetprecexactlowrank(state, updatefreq);
<font color=navy>//</font>
<font color=navy>// Set constraints:</font>
<font color=navy>//</font>
<font color=navy>// 1. boundary constraints are passed with minnlcsetbc() call</font>
<font color=navy>//</font>
<font color=navy>// 2. nonlinear constraints are more tricky - you can not <font color=blue><b>"pack"</b></font> general</font>
<font color=navy>// nonlinear function into <b>double</b> precision array. That's why</font>
<font color=navy>// minnlcsetnlc() does not accept constraints itself - only constraint</font>
<font color=navy>// counts are passed: first parameter is number of equality constraints,</font>
<font color=navy>// second one is number of inequality constraints.</font>
<font color=navy>//</font>
<font color=navy>// As <b>for</b> constraining functions - these functions are passed as part</font>
<font color=navy>// of problem Jacobian (see below).</font>
<font color=navy>//</font>
<font color=navy>// NOTE: MinNLC optimizer supports arbitrary combination of boundary, general</font>
<font color=navy>// linear and general nonlinear constraints. This example does not</font>
<font color=navy>// show how to work with general linear constraints, but you can</font>
<font color=navy>// easily find it in documentation on minnlcsetlc() function.</font>
<font color=navy>//</font>
minnlcsetbc(state, bndl, bndu);
minnlcsetnlc(state, 0, 1);
<font color=navy>//</font>
<font color=navy>// Optimize and test results.</font>
<font color=navy>//</font>
<font color=navy>// Optimizer object accepts vector function and its Jacobian, with first</font>
<font color=navy>// component (Jacobian row) being target function, and next components</font>
<font color=navy>// (Jacobian rows) being nonlinear equality and inequality constraints.</font>
<font color=navy>//</font>
<font color=navy>// So, our vector function has form</font>
<font color=navy>//</font>
<font color=navy>// {f0,f1} = { -x0+x1 , x0^2+x1^2-1 }</font>
<font color=navy>//</font>
<font color=navy>// with Jacobian</font>
<font color=navy>//</font>
<font color=navy>// [ -1 +1 ]</font>
<font color=navy>// J = [ ]</font>
<font color=navy>// [ 2*x0 2*x1 ]</font>
<font color=navy>//</font>
<font color=navy>// with f0 being target function, f1 being constraining function. Number</font>
<font color=navy>// of equality/inequality constraints is specified by minnlcsetnlc(),</font>
<font color=navy>// with equality ones always being first, inequality ones being last.</font>
<font color=navy>//</font>
alglib::minnlcoptimize(state, nlcfunc1_jac);
minnlcresults(state, x1, rep);
printf(<font color=blue><b>"%s\n"</b></font>, x1.tostring(2).c_str()); <font color=navy>// EXPECTED: [1.0000,0.0000]</font>
<b>return</b> 0;
}
</pre><a name='example_minnlc_d_mixed'></a><h3 class=pageheader>minnlc_d_mixed example</h3>
<pre class=source>
#include <font color=blue><b>"stdafx.h"</b></font>
#include <stdlib.h>
#include <stdio.h>
#include <math.h>
#include <font color=blue><b>"optimization.h"</b></font>
using namespace alglib;
<b>void</b> nlcfunc2_jac(<b>const</b> real_1d_array &x, real_1d_array &fi, real_2d_array &jac, <b>void</b> *ptr)
{
<font color=navy>//</font>
<font color=navy>// this callback calculates</font>
<font color=navy>//</font>
<font color=navy>// f0(x0,x1,x2) = x0+x1</font>
<font color=navy>// f1(x0,x1,x2) = x2-exp(x0)</font>
<font color=navy>// f2(x0,x1,x2) = x0^2+x1^2-1</font>
<font color=navy>//</font>
<font color=navy>// and Jacobian matrix J = [dfi/dxj]</font>
<font color=navy>//</font>
fi[0] = x[0]+x[1];
fi[1] = x[2]-exp(x[0]);
fi[2] = x[0]*x[0] + x[1]*x[1] - 1.0;
jac[0][0] = 1.0;
jac[0][1] = 1.0;
jac[0][2] = 0.0;
jac[1][0] = -exp(x[0]);
jac[1][1] = 0.0;
jac[1][2] = 1.0;
jac[2][0] = 2*x[0];
jac[2][1] = 2*x[1];
jac[2][2] = 0.0;
}
<b>int</b> main(<b>int</b> argc, char **argv)
{
<font color=navy>//</font>
<font color=navy>// This example demonstrates minimization of</font>
<font color=navy>//</font>
<font color=navy>// f(x0,x1) = x0+x1</font>
<font color=navy>//</font>
<font color=navy>// subject to nonlinear inequality constraint</font>
<font color=navy>//</font>
<font color=navy>// x0^2 + x1^2 - 1 <= 0</font>
<font color=navy>//</font>
<font color=navy>// and nonlinear equality constraint</font>
<font color=navy>//</font>
<font color=navy>// x2-exp(x0) = 0</font>
<font color=navy>//</font>
real_1d_array x0 = <font color=blue><b>"[0,0,0]"</b></font>;
real_1d_array s = <font color=blue><b>"[1,1,1]"</b></font>;
<b>double</b> epsg = 0;
<b>double</b> epsf = 0;
<b>double</b> epsx = 0.000001;
ae_int_t maxits = 0;
ae_int_t outerits = 5;
ae_int_t updatefreq = 10;
<b>double</b> rho = 1000;
minnlcstate state;
minnlcreport rep;
real_1d_array x1;
<font color=navy>//</font>
<font color=navy>// Create optimizer object, choose AUL algorithm and tune its settings:</font>
<font color=navy>// * rho=1000 penalty coefficient</font>
<font color=navy>// * outerits=5 number of outer iterations to tune Lagrange coefficients</font>
<font color=navy>// * epsx=0.000001 stopping condition <b>for</b> inner iterations</font>
<font color=navy>// * s=[1,1] all variables have unit scale</font>
<font color=navy>// * exact low-rank preconditioner is used, updated after each 10 iterations</font>
<font color=navy>//</font>
minnlccreate(3, x0, state);
minnlcsetalgoaul(state, rho, outerits);
minnlcsetcond(state, epsg, epsf, epsx, maxits);
minnlcsetscale(state, s);
minnlcsetprecexactlowrank(state, updatefreq);
<font color=navy>//</font>
<font color=navy>// Set constraints:</font>
<font color=navy>//</font>
<font color=navy>// Nonlinear constraints are tricky - you can not <font color=blue><b>"pack"</b></font> general</font>
<font color=navy>// nonlinear function into <b>double</b> precision array. That's why</font>
<font color=navy>// minnlcsetnlc() does not accept constraints itself - only constraint</font>
<font color=navy>// counts are passed: first parameter is number of equality constraints,</font>
<font color=navy>// second one is number of inequality constraints.</font>
<font color=navy>//</font>
<font color=navy>// As <b>for</b> constraining functions - these functions are passed as part</font>
<font color=navy>// of problem Jacobian (see below).</font>
<font color=navy>//</font>
<font color=navy>// NOTE: MinNLC optimizer supports arbitrary combination of boundary, general</font>
<font color=navy>// linear and general nonlinear constraints. This example does not</font>
<font color=navy>// show how to work with boundary or general linear constraints, but you</font>
<font color=navy>// can easily find it in documentation on minnlcsetbc() and</font>
<font color=navy>// minnlcsetlc() functions.</font>
<font color=navy>//</font>
minnlcsetnlc(state, 1, 1);
<font color=navy>//</font>
<font color=navy>// Optimize and test results.</font>
<font color=navy>//</font>
<font color=navy>// Optimizer object accepts vector function and its Jacobian, with first</font>
<font color=navy>// component (Jacobian row) being target function, and next components</font>
<font color=navy>// (Jacobian rows) being nonlinear equality and inequality constraints.</font>
<font color=navy>//</font>
<font color=navy>// So, our vector function has form</font>
<font color=navy>//</font>
<font color=navy>// {f0,f1,f2} = { x0+x1 , x2-exp(x0) , x0^2+x1^2-1 }</font>
<font color=navy>//</font>
<font color=navy>// with Jacobian</font>
<font color=navy>//</font>
<font color=navy>// [ +1 +1 0 ]</font>
<font color=navy>// J = [-exp(x0) 0 1 ]</font>
<font color=navy>// [ 2*x0 2*x1 0 ]</font>
<font color=navy>//</font>
<font color=navy>// with f0 being target function, f1 being equality constraint <font color=blue><b>"f1=0"</b></font>,</font>
<font color=navy>// f2 being inequality constraint <font color=blue><b>"f2<=0"</b></font>. Number of equality/inequality</font>
<font color=navy>// constraints is specified by minnlcsetnlc(), with equality ones always</font>
<font color=navy>// being first, inequality ones being last.</font>
<font color=navy>//</font>
alglib::minnlcoptimize(state, nlcfunc2_jac);
minnlcresults(state, x1, rep);
printf(<font color=blue><b>"%s\n"</b></font>, x1.tostring(2).c_str()); <font color=navy>// EXPECTED: [-0.70710,-0.70710,0.49306]</font>
<b>return</b> 0;
}
</pre><a name=unit_minns></a><h2 class=pageheader><code>minns</code> subpackage</h2>
<div class=pagecontent>
<h3 class=pageheader>Classes</h3>
<a href='#struct_minnsreport' class=toc>minnsreport</a><br>
<a href='#struct_minnsstate' class=toc>minnsstate</a><br>
<h3 class=pageheader>Functions</h3>
<a href='#sub_minnscreate' class=toc>minnscreate</a><br>
<a href='#sub_minnscreatef' class=toc>minnscreatef</a><br>
<a href='#sub_minnsoptimize' class=toc>minnsoptimize</a><br>
<a href='#sub_minnsrequesttermination' class=toc>minnsrequesttermination</a><br>
<a href='#sub_minnsrestartfrom' class=toc>minnsrestartfrom</a><br>
<a href='#sub_minnsresults' class=toc>minnsresults</a><br>
<a href='#sub_minnsresultsbuf' class=toc>minnsresultsbuf</a><br>
<a href='#sub_minnssetalgoags' class=toc>minnssetalgoags</a><br>
<a href='#sub_minnssetbc' class=toc>minnssetbc</a><br>
<a href='#sub_minnssetcond' class=toc>minnssetcond</a><br>
<a href='#sub_minnssetlc' class=toc>minnssetlc</a><br>
<a href='#sub_minnssetnlc' class=toc>minnssetnlc</a><br>
<a href='#sub_minnssetscale' class=toc>minnssetscale</a><br>
<a href='#sub_minnssetxrep' class=toc>minnssetxrep</a><br>
<h3 class=pageheader>Examples</h3>
<table border=0 cellspacing=0 class='pagecontent'>
<tr align=left valign=top><td><a href='#example_minns_d_bc' class=toc>minns_d_bc</a></td><td width=15> </td><td>Nonsmooth box constrained optimization</td></tr>
<tr align=left valign=top><td><a href='#example_minns_d_diff' class=toc>minns_d_diff</a></td><td width=15> </td><td>Nonsmooth unconstrained optimization with numerical differentiation</td></tr>
<tr align=left valign=top><td><a href='#example_minns_d_nlc' class=toc>minns_d_nlc</a></td><td width=15> </td><td>Nonsmooth nonlinearly constrained optimization</td></tr>
<tr align=left valign=top><td><a href='#example_minns_d_unconstrained' class=toc>minns_d_unconstrained</a></td><td width=15> </td><td>Nonsmooth unconstrained optimization</td></tr>
</table></div>
<a name='struct_minnsreport'></a><h3 class=pageheader><code>minnsreport</code> class</h3>
<pre class=source>
<div style='color: navy; margin-top: 0; margin-bottom: 0;'>/*************************************************************************
This structure stores optimization report:
* IterationsCount total number of inner iterations
* NFEV number of gradient evaluations
* TerminationType termination type (see below)
* CErr maximum violation of all types of constraints
* LCErr maximum violation of linear constraints
* NLCErr maximum violation of nonlinear constraints
TERMINATION CODES
TerminationType field contains completion code, which can be:
-8 internal integrity control detected infinite or NAN values in
function/gradient. Abnormal termination signalled.
-3 box constraints are inconsistent
-1 inconsistent parameters were passed:
* penalty parameter for minnssetalgoags() is zero,
but we have nonlinear constraints set by minnssetnlc()
2 sampling radius decreased below epsx
5 MaxIts steps was taken
7 stopping conditions are too stringent,
further improvement is impossible,
X contains best point found so far.
8 User requested termination via MinNSRequestTermination()
Other fields of this structure are not documented and should not be used!
*************************************************************************/
</div><div style='margin-top: 0; margin-bottom: 0;'><b>class</b> minnsreport
{
ae_int_t iterationscount;
ae_int_t nfev;
<b>double</b> cerr;
<b>double</b> lcerr;
<b>double</b> nlcerr;
ae_int_t terminationtype;
ae_int_t varidx;
ae_int_t funcidx;
};
</div></pre>
<a name='struct_minnsstate'></a><h3 class=pageheader><code>minnsstate</code> class</h3>
<pre class=source>
<div style='color: navy; margin-top: 0; margin-bottom: 0;'>/*************************************************************************
This object stores nonlinear optimizer state.
You should use functions provided by MinNS subpackage to work with this
object
*************************************************************************/
</div><div style='margin-top: 0; margin-bottom: 0;'><b>class</b> minnsstate
{
};
</div></pre>
<a name='sub_minnscreate'></a><h3 class=pageheader><code>minnscreate</code> function</h3>
<pre class=source>
<div style='color: navy; margin-top: 0; margin-bottom: 0;'>/*************************************************************************
NONSMOOTH NONCONVEX OPTIMIZATION
SUBJECT TO BOX/LINEAR/NONLINEAR-NONSMOOTH CONSTRAINTS
DESCRIPTION:
The subroutine minimizes function F(x) of N arguments subject to any
combination of:
* bound constraints
* linear inequality constraints
* linear equality constraints
* nonlinear equality constraints Gi(x)=0
* nonlinear inequality constraints Hi(x)<=0
IMPORTANT: see MinNSSetAlgoAGS for important information on performance
restrictions of AGS solver.
REQUIREMENTS:
* starting point X0 must be feasible or not too far away from the feasible
set
* F(), G(), H() are continuous, locally Lipschitz and continuously (but
not necessarily twice) differentiable in an open dense subset of R^N.
Functions F(), G() and H() may be nonsmooth and non-convex.
Informally speaking, it means that functions are composed of large
differentiable "patches" with nonsmoothness having place only at the
boundaries between these "patches".
Most real-life nonsmooth functions satisfy these requirements. Say,
anything which involves finite number of abs(), min() and max() is very
likely to pass the test.
Say, it is possible to optimize anything of the following:
* f=abs(x0)+2*abs(x1)
* f=max(x0,x1)
* f=sin(max(x0,x1)+abs(x2))
* for nonlinearly constrained problems: F() must be bounded from below
without nonlinear constraints (this requirement is due to the fact that,
contrary to box and linear constraints, nonlinear ones require special
handling).
* user must provide function value and gradient for F(), H(), G() at all
points where function/gradient can be calculated. If optimizer requires
value exactly at the boundary between "patches" (say, at x=0 for f=abs(x)),
where gradient is not defined, user may resolve tie arbitrarily (in our
case - return +1 or -1 at its discretion).
* NS solver supports numerical differentiation, i.e. it may differentiate
your function for you, but it results in 2N increase of function
evaluations. Not recommended unless you solve really small problems. See
minnscreatef() for more information on this functionality.
USAGE:
1. User initializes algorithm state with MinNSCreate() call and chooses
what NLC solver to use. There is some solver which is used by default,
with default settings, but you should NOT rely on default choice. It
may change in future releases of ALGLIB without notice, and no one can
guarantee that new solver will be able to solve your problem with
default settings.
From the other side, if you choose solver explicitly, you can be pretty
sure that it will work with new ALGLIB releases.
In the current release following solvers can be used:
* AGS solver (activated with MinNSSetAlgoAGS() function)
2. User adds boundary and/or linear and/or nonlinear constraints by means
of calling one of the following functions:
a) MinNSSetBC() for boundary constraints
b) MinNSSetLC() for linear constraints
c) MinNSSetNLC() for nonlinear constraints
You may combine (a), (b) and (c) in one optimization problem.
3. User sets scale of the variables with MinNSSetScale() function. It is
VERY important to set scale of the variables, because nonlinearly
constrained problems are hard to solve when variables are badly scaled.
4. User sets stopping conditions with MinNSSetCond().
5. Finally, user calls MinNSOptimize() function which takes algorithm
state and pointer (delegate, etc) to callback function which calculates
F/G/H.
7. User calls MinNSResults() to get solution
8. Optionally user may call MinNSRestartFrom() to solve another problem
with same N but another starting point. MinNSRestartFrom() allows to
reuse already initialized structure.
INPUT PARAMETERS:
N - problem dimension, N>0:
* if given, only leading N elements of X are used
* if not given, automatically determined from size of X
X - starting point, array[N]:
* it is better to set X to a feasible point
* but X can be infeasible, in which case algorithm will try
to find feasible point first, using X as initial
approximation.
OUTPUT PARAMETERS:
State - structure stores algorithm state
NOTE: minnscreatef() function may be used if you do not have analytic
gradient. This function creates solver which uses numerical
differentiation with user-specified step.
-- ALGLIB --
Copyright 18.05.2015 by Bochkanov Sergey
*************************************************************************/
</div><div style='margin-top: 0; margin-bottom: 0;'><b>void</b> alglib::minnscreate(real_1d_array x, minnsstate& state);
<b>void</b> alglib::minnscreate(ae_int_t n, real_1d_array x, minnsstate& state);
</div></pre>
<p align=left class=pagecontent><span class=inlineheader>Examples:</span> <a href='#example_minns_d_unconstrained' class=nav>[1]</a> <a href='#example_minns_d_bc' class=nav>[2]</a> <a href='#example_minns_d_nlc' class=nav>[3]</a> </p>
<a name='sub_minnscreatef'></a><h3 class=pageheader><code>minnscreatef</code> function</h3>
<pre class=source>
<div style='color: navy; margin-top: 0; margin-bottom: 0;'>/*************************************************************************
Version of minnscreatef() which uses numerical differentiation. I.e., you
do not have to calculate derivatives yourself. However, this version needs
2N times more function evaluations.
2-point differentiation formula is used, because more precise 4-point
formula is unstable when used on non-smooth functions.
INPUT PARAMETERS:
N - problem dimension, N>0:
* if given, only leading N elements of X are used
* if not given, automatically determined from size of X
X - starting point, array[N]:
* it is better to set X to a feasible point
* but X can be infeasible, in which case algorithm will try
to find feasible point first, using X as initial
approximation.
DiffStep- differentiation step, DiffStep>0. Algorithm performs
numerical differentiation with step for I-th variable
being equal to DiffStep*S[I] (here S[] is a scale vector,
set by minnssetscale() function).
Do not use too small steps, because it may lead to
catastrophic cancellation during intermediate calculations.
OUTPUT PARAMETERS:
State - structure stores algorithm state
-- ALGLIB --
Copyright 18.05.2015 by Bochkanov Sergey
*************************************************************************/
</div><div style='margin-top: 0; margin-bottom: 0;'><b>void</b> alglib::minnscreatef(
real_1d_array x,
<b>double</b> diffstep,
minnsstate& state);
<b>void</b> alglib::minnscreatef(
ae_int_t n,
real_1d_array x,
<b>double</b> diffstep,
minnsstate& state);
</div></pre>
<p align=left class=pagecontent><span class=inlineheader>Examples:</span> <a href='#example_minns_d_diff' class=nav>[1]</a> </p>
<a name='sub_minnsoptimize'></a><h3 class=pageheader><code>minnsoptimize</code> function</h3>
<pre class=source>
<div style='color: navy; margin-top: 0; margin-bottom: 0;'>/*************************************************************************
This family of functions is used to launcn iterations of nonlinear optimizer
These functions accept following parameters:
state - algorithm state
fvec - callback which calculates function vector fi[]
at given point x
jac - callback which calculates function vector fi[]
and Jacobian jac at given point x
rep - optional callback which is called after each iteration
can be NULL
ptr - optional pointer which is passed to func/grad/hess/jac/rep
can be NULL
NOTES:
1. This function has two different implementations: one which uses exact
(analytical) user-supplied Jacobian, and one which uses only function
vector and numerically differentiates function in order to obtain
gradient.
Depending on the specific function used to create optimizer object
you should choose appropriate variant of minnsoptimize() - one which
accepts function AND Jacobian or one which accepts ONLY function.
Be careful to choose variant of minnsoptimize() which corresponds to
your optimization scheme! Table below lists different combinations of
callback (function/gradient) passed to minnsoptimize() and specific
function used to create optimizer.
| USER PASSED TO minnsoptimize()
CREATED WITH | function only | function and gradient
------------------------------------------------------------
minnscreatef() | works FAILS
minnscreate() | FAILS works
Here "FAILS" denotes inappropriate combinations of optimizer creation
function and minnsoptimize() version. Attemps to use such
combination will lead to exception. Either you did not pass gradient
when it WAS needed or you passed gradient when it was NOT needed.
-- ALGLIB --
Copyright 18.05.2015 by Bochkanov Sergey
*************************************************************************/
</div><div style='margin-top: 0; margin-bottom: 0;'><b>void</b> minnsoptimize(minnsstate &state,
<b>void</b> (*fvec)(<b>const</b> real_1d_array &x, real_1d_array &fi, <b>void</b> *ptr),
<b>void</b> (*rep)(<b>const</b> real_1d_array &x, <b>double</b> func, <b>void</b> *ptr) = NULL,
<b>void</b> *ptr = NULL);
<b>void</b> minnsoptimize(minnsstate &state,
<b>void</b> (*jac)(<b>const</b> real_1d_array &x, real_1d_array &fi, real_2d_array &jac, <b>void</b> *ptr),
<b>void</b> (*rep)(<b>const</b> real_1d_array &x, <b>double</b> func, <b>void</b> *ptr) = NULL,
<b>void</b> *ptr = NULL);
</div></pre>
<p align=left class=pagecontent><span class=inlineheader>Examples:</span> <a href='#example_minns_d_unconstrained' class=nav>[1]</a> <a href='#example_minns_d_diff' class=nav>[2]</a> <a href='#example_minns_d_bc' class=nav>[3]</a> <a href='#example_minns_d_nlc' class=nav>[4]</a> </p>
<a name='sub_minnsrequesttermination'></a><h3 class=pageheader><code>minnsrequesttermination</code> function</h3>
<pre class=source>
<div style='color: navy; margin-top: 0; margin-bottom: 0;'>/*************************************************************************
This subroutine submits request for termination of running optimizer. It
should be called from user-supplied callback when user decides that it is
time to "smoothly" terminate optimization process. As result, optimizer
stops at point which was "current accepted" when termination request was
submitted and returns error code 8 (successful termination).
INPUT PARAMETERS:
State - optimizer structure
NOTE: after request for termination optimizer may perform several
additional calls to user-supplied callbacks. It does NOT guarantee
to stop immediately - it just guarantees that these additional calls
will be discarded later.
NOTE: calling this function on optimizer which is NOT running will have no
effect.
NOTE: multiple calls to this function are possible. First call is counted,
subsequent calls are silently ignored.
-- ALGLIB --
Copyright 18.05.2015 by Bochkanov Sergey
*************************************************************************/
</div><div style='margin-top: 0; margin-bottom: 0;'><b>void</b> alglib::minnsrequesttermination(minnsstate state);
</div></pre>
<a name='sub_minnsrestartfrom'></a><h3 class=pageheader><code>minnsrestartfrom</code> function</h3>
<pre class=source>
<div style='color: navy; margin-top: 0; margin-bottom: 0;'>/*************************************************************************
This subroutine restarts algorithm from new point.
All optimization parameters (including constraints) are left unchanged.
This function allows to solve multiple optimization problems (which
must have same number of dimensions) without object reallocation penalty.
INPUT PARAMETERS:
State - structure previously allocated with minnscreate() call.
X - new starting point.
-- ALGLIB --
Copyright 18.05.2015 by Bochkanov Sergey
*************************************************************************/
</div><div style='margin-top: 0; margin-bottom: 0;'><b>void</b> alglib::minnsrestartfrom(minnsstate state, real_1d_array x);
</div></pre>
<a name='sub_minnsresults'></a><h3 class=pageheader><code>minnsresults</code> function</h3>
<pre class=source>
<div style='color: navy; margin-top: 0; margin-bottom: 0;'>/*************************************************************************
MinNS results
INPUT PARAMETERS:
State - algorithm state
OUTPUT PARAMETERS:
X - array[0..N-1], solution
Rep - optimization report. You should check Rep.TerminationType
in order to distinguish successful termination from
unsuccessful one:
* -8 internal integrity control detected infinite or
NAN values in function/gradient. Abnormal
termination signalled.
* -3 box constraints are inconsistent
* -1 inconsistent parameters were passed:
* penalty parameter for minnssetalgoags() is zero,
but we have nonlinear constraints set by minnssetnlc()
* 2 sampling radius decreased below epsx
* 7 stopping conditions are too stringent,
further improvement is impossible,
X contains best point found so far.
* 8 User requested termination via minnsrequesttermination()
-- ALGLIB --
Copyright 18.05.2015 by Bochkanov Sergey
*************************************************************************/
</div><div style='margin-top: 0; margin-bottom: 0;'><b>void</b> alglib::minnsresults(
minnsstate state,
real_1d_array& x,
minnsreport& rep);
</div></pre>
<p align=left class=pagecontent><span class=inlineheader>Examples:</span> <a href='#example_minns_d_unconstrained' class=nav>[1]</a> <a href='#example_minns_d_diff' class=nav>[2]</a> <a href='#example_minns_d_bc' class=nav>[3]</a> <a href='#example_minns_d_nlc' class=nav>[4]</a> </p>
<a name='sub_minnsresultsbuf'></a><h3 class=pageheader><code>minnsresultsbuf</code> function</h3>
<pre class=source>
<div style='color: navy; margin-top: 0; margin-bottom: 0;'>/*************************************************************************
Buffered implementation of minnsresults() which uses pre-allocated buffer
to store X[]. If buffer size is too small, it resizes buffer. It is
intended to be used in the inner cycles of performance critical algorithms
where array reallocation penalty is too large to be ignored.
-- ALGLIB --
Copyright 18.05.2015 by Bochkanov Sergey
*************************************************************************/
</div><div style='margin-top: 0; margin-bottom: 0;'><b>void</b> alglib::minnsresultsbuf(
minnsstate state,
real_1d_array& x,
minnsreport& rep);
</div></pre>
<a name='sub_minnssetalgoags'></a><h3 class=pageheader><code>minnssetalgoags</code> function</h3>
<pre class=source>
<div style='color: navy; margin-top: 0; margin-bottom: 0;'>/*************************************************************************
This function tells MinNS unit to use AGS (adaptive gradient sampling)
algorithm for nonsmooth constrained optimization. This algorithm is a
slight modification of one described in "An Adaptive Gradient Sampling
Algorithm for Nonsmooth Optimization" by Frank E. Curtisy and Xiaocun Quez.
This optimizer has following benefits and drawbacks:
+ robustness; it can be used with nonsmooth and nonconvex functions.
+ relatively easy tuning; most of the metaparameters are easy to select.
- it has convergence of steepest descent, slower than CG/LBFGS.
- each iteration involves evaluation of ~2N gradient values and solution
of 2Nx2N quadratic programming problem, which limits applicability of
algorithm by small-scale problems (up to 50-100).
IMPORTANT: this algorithm has convergence guarantees, i.e. it will
steadily move towards some stationary point of the function.
However, "stationary point" does not always mean "solution".
Nonsmooth problems often have "flat spots", i.e. areas where
function do not change at all. Such "flat spots" are stationary
points by definition, and algorithm may be caught here.
Nonsmooth CONVEX tasks are not prone to this problem. Say, if
your function has form f()=MAX(f0,f1,...), and f_i are convex,
then f() is convex too and you have guaranteed convergence to
solution.
INPUT PARAMETERS:
State - structure which stores algorithm state
Radius - initial sampling radius, >=0.
Internally multiplied by vector of per-variable scales
specified by minnssetscale()).
You should select relatively large sampling radius, roughly
proportional to scaled length of the first steps of the
algorithm. Something close to 0.1 in magnitude should be
good for most problems.
AGS solver can automatically decrease radius, so too large
radius is not a problem (assuming that you won't choose
so large radius that algorithm will sample function in
too far away points, where gradient value is irrelevant).
Too small radius won't cause algorithm to fail, but it may
slow down algorithm (it may have to perform too short
steps).
Penalty - penalty coefficient for nonlinear constraints:
* for problem with nonlinear constraints should be some
problem-specific positive value, large enough that
penalty term changes shape of the function.
Starting from some problem-specific value penalty
coefficient becomes large enough to exactly enforce
nonlinear constraints; larger values do not improve
precision.
Increasing it too much may slow down convergence, so you
should choose it carefully.
* can be zero for problems WITHOUT nonlinear constraints
(i.e. for unconstrained ones or ones with just box or
linear constraints)
* if you specify zero value for problem with at least one
nonlinear constraint, algorithm will terminate with
error code -1.
ALGORITHM OUTLINE
The very basic outline of unconstrained AGS algorithm is given below:
0. If sampling radius is below EpsX or we performed more then MaxIts
iterations - STOP.
1. sample O(N) gradient values at random locations around current point;
informally speaking, this sample is an implicit piecewise linear model
of the function, although algorithm formulation does not mention that
explicitly
2. solve quadratic programming problem in order to find descent direction
3. if QP solver tells us that we are near solution, decrease sampling
radius and move to (0)
4. perform backtracking line search
5. after moving to new point, goto (0)
As for the constraints:
* box constraints are handled exactly by modification of the function
being minimized
* linear/nonlinear constraints are handled by adding L1 penalty. Because
our solver can handle nonsmoothness, we can use L1 penalty function,
which is an exact one (i.e. exact solution is returned under such
penalty).
* penalty coefficient for linear constraints is chosen automatically;
however, penalty coefficient for nonlinear constraints must be specified
by user.
-- ALGLIB --
Copyright 18.05.2015 by Bochkanov Sergey
*************************************************************************/
</div><div style='margin-top: 0; margin-bottom: 0;'><b>void</b> alglib::minnssetalgoags(
minnsstate state,
<b>double</b> radius,
<b>double</b> penalty);
</div></pre>
<p align=left class=pagecontent><span class=inlineheader>Examples:</span> <a href='#example_minns_d_unconstrained' class=nav>[1]</a> <a href='#example_minns_d_diff' class=nav>[2]</a> <a href='#example_minns_d_bc' class=nav>[3]</a> <a href='#example_minns_d_nlc' class=nav>[4]</a> </p>
<a name='sub_minnssetbc'></a><h3 class=pageheader><code>minnssetbc</code> function</h3>
<pre class=source>
<div style='color: navy; margin-top: 0; margin-bottom: 0;'>/*************************************************************************
This function sets boundary constraints.
Boundary constraints are inactive by default (after initial creation).
They are preserved after algorithm restart with minnsrestartfrom().
INPUT PARAMETERS:
State - structure stores algorithm state
BndL - lower bounds, array[N].
If some (all) variables are unbounded, you may specify
very small number or -INF.
BndU - upper bounds, array[N].
If some (all) variables are unbounded, you may specify
very large number or +INF.
NOTE 1: it is possible to specify BndL[i]=BndU[i]. In this case I-th
variable will be "frozen" at X[i]=BndL[i]=BndU[i].
NOTE 2: AGS solver has following useful properties:
* bound constraints are always satisfied exactly
* function is evaluated only INSIDE area specified by bound constraints,
even when numerical differentiation is used (algorithm adjusts nodes
according to boundary constraints)
-- ALGLIB --
Copyright 18.05.2015 by Bochkanov Sergey
*************************************************************************/
</div><div style='margin-top: 0; margin-bottom: 0;'><b>void</b> alglib::minnssetbc(
minnsstate state,
real_1d_array bndl,
real_1d_array bndu);
</div></pre>
<p align=left class=pagecontent><span class=inlineheader>Examples:</span> <a href='#example_minns_d_bc' class=nav>[1]</a> </p>
<a name='sub_minnssetcond'></a><h3 class=pageheader><code>minnssetcond</code> function</h3>
<pre class=source>
<div style='color: navy; margin-top: 0; margin-bottom: 0;'>/*************************************************************************
This function sets stopping conditions for iterations of optimizer.
INPUT PARAMETERS:
State - structure which stores algorithm state
EpsX - >=0
The AGS solver finishes its work if on k+1-th iteration
sampling radius decreases below EpsX.
MaxIts - maximum number of iterations. If MaxIts=0, the number of
iterations is unlimited.
Passing EpsX=0 and MaxIts=0 (simultaneously) will lead to automatic
stopping criterion selection. We do not recommend you to rely on default
choice in production code.
-- ALGLIB --
Copyright 18.05.2015 by Bochkanov Sergey
*************************************************************************/
</div><div style='margin-top: 0; margin-bottom: 0;'><b>void</b> alglib::minnssetcond(minnsstate state, <b>double</b> epsx, ae_int_t maxits);
</div></pre>
<p align=left class=pagecontent><span class=inlineheader>Examples:</span> <a href='#example_minns_d_unconstrained' class=nav>[1]</a> <a href='#example_minns_d_diff' class=nav>[2]</a> <a href='#example_minns_d_bc' class=nav>[3]</a> <a href='#example_minns_d_nlc' class=nav>[4]</a> </p>
<a name='sub_minnssetlc'></a><h3 class=pageheader><code>minnssetlc</code> function</h3>
<pre class=source>
<div style='color: navy; margin-top: 0; margin-bottom: 0;'>/*************************************************************************
This function sets linear constraints.
Linear constraints are inactive by default (after initial creation).
They are preserved after algorithm restart with minnsrestartfrom().
INPUT PARAMETERS:
State - structure previously allocated with minnscreate() call.
C - linear constraints, array[K,N+1].
Each row of C represents one constraint, either equality
or inequality (see below):
* first N elements correspond to coefficients,
* last element corresponds to the right part.
All elements of C (including right part) must be finite.
CT - type of constraints, array[K]:
* if CT[i]>0, then I-th constraint is C[i,*]*x >= C[i,n+1]
* if CT[i]=0, then I-th constraint is C[i,*]*x = C[i,n+1]
* if CT[i]<0, then I-th constraint is C[i,*]*x <= C[i,n+1]
K - number of equality/inequality constraints, K>=0:
* if given, only leading K elements of C/CT are used
* if not given, automatically determined from sizes of C/CT
NOTE: linear (non-bound) constraints are satisfied only approximately:
* there always exists some minor violation (about current sampling radius
in magnitude during optimization, about EpsX in the solution) due to use
of penalty method to handle constraints.
* numerical differentiation, if used, may lead to function evaluations
outside of the feasible area, because algorithm does NOT change
numerical differentiation formula according to linear constraints.
If you want constraints to be satisfied exactly, try to reformulate your
problem in such manner that all constraints will become boundary ones
(this kind of constraints is always satisfied exactly, both in the final
solution and in all intermediate points).
-- ALGLIB --
Copyright 18.05.2015 by Bochkanov Sergey
*************************************************************************/
</div><div style='margin-top: 0; margin-bottom: 0;'><b>void</b> alglib::minnssetlc(
minnsstate state,
real_2d_array c,
integer_1d_array ct);
<b>void</b> alglib::minnssetlc(
minnsstate state,
real_2d_array c,
integer_1d_array ct,
ae_int_t k);
</div></pre>
<a name='sub_minnssetnlc'></a><h3 class=pageheader><code>minnssetnlc</code> function</h3>
<pre class=source>
<div style='color: navy; margin-top: 0; margin-bottom: 0;'>/*************************************************************************
This function sets nonlinear constraints.
In fact, this function sets NUMBER of nonlinear constraints. Constraints
itself (constraint functions) are passed to minnsoptimize() method. This
method requires user-defined vector function F[] and its Jacobian J[],
where:
* first component of F[] and first row of Jacobian J[] correspond to
function being minimized
* next NLEC components of F[] (and rows of J) correspond to nonlinear
equality constraints G_i(x)=0
* next NLIC components of F[] (and rows of J) correspond to nonlinear
inequality constraints H_i(x)<=0
NOTE: you may combine nonlinear constraints with linear/boundary ones. If
your problem has mixed constraints, you may explicitly specify some
of them as linear ones. It may help optimizer to handle them more
efficiently.
INPUT PARAMETERS:
State - structure previously allocated with minnscreate() call.
NLEC - number of Non-Linear Equality Constraints (NLEC), >=0
NLIC - number of Non-Linear Inquality Constraints (NLIC), >=0
NOTE 1: nonlinear constraints are satisfied only approximately! It is
possible that algorithm will evaluate function outside of
the feasible area!
NOTE 2: algorithm scales variables according to scale specified by
minnssetscale() function, so it can handle problems with badly
scaled variables (as long as we KNOW their scales).
However, there is no way to automatically scale nonlinear
constraints Gi(x) and Hi(x). Inappropriate scaling of Gi/Hi may
ruin convergence. Solving problem with constraint "1000*G0(x)=0"
is NOT same as solving it with constraint "0.001*G0(x)=0".
It means that YOU are the one who is responsible for correct
scaling of nonlinear constraints Gi(x) and Hi(x). We recommend you
to scale nonlinear constraints in such way that I-th component of
dG/dX (or dH/dx) has approximately unit magnitude (for problems
with unit scale) or has magnitude approximately equal to 1/S[i]
(where S is a scale set by minnssetscale() function).
NOTE 3: nonlinear constraints are always hard to handle, no matter what
algorithm you try to use. Even basic box/linear constraints modify
function curvature by adding valleys and ridges. However,
nonlinear constraints add valleys which are very hard to follow
due to their "curved" nature.
It means that optimization with single nonlinear constraint may be
significantly slower than optimization with multiple linear ones.
It is normal situation, and we recommend you to carefully choose
Rho parameter of minnssetalgoags(), because too large value may
slow down convergence.
-- ALGLIB --
Copyright 18.05.2015 by Bochkanov Sergey
*************************************************************************/
</div><div style='margin-top: 0; margin-bottom: 0;'><b>void</b> alglib::minnssetnlc(minnsstate state, ae_int_t nlec, ae_int_t nlic);
</div></pre>
<p align=left class=pagecontent><span class=inlineheader>Examples:</span> <a href='#example_minns_d_nlc' class=nav>[1]</a> </p>
<a name='sub_minnssetscale'></a><h3 class=pageheader><code>minnssetscale</code> function</h3>
<pre class=source>
<div style='color: navy; margin-top: 0; margin-bottom: 0;'>/*************************************************************************
This function sets scaling coefficients for NLC optimizer.
ALGLIB optimizers use scaling matrices to test stopping conditions (step
size and gradient are scaled before comparison with tolerances). Scale of
the I-th variable is a translation invariant measure of:
a) "how large" the variable is
b) how large the step should be to make significant changes in the function
Scaling is also used by finite difference variant of the optimizer - step
along I-th axis is equal to DiffStep*S[I].
INPUT PARAMETERS:
State - structure stores algorithm state
S - array[N], non-zero scaling coefficients
S[i] may be negative, sign doesn't matter.
-- ALGLIB --
Copyright 18.05.2015 by Bochkanov Sergey
*************************************************************************/
</div><div style='margin-top: 0; margin-bottom: 0;'><b>void</b> alglib::minnssetscale(minnsstate state, real_1d_array s);
</div></pre>
<p align=left class=pagecontent><span class=inlineheader>Examples:</span> <a href='#example_minns_d_unconstrained' class=nav>[1]</a> <a href='#example_minns_d_diff' class=nav>[2]</a> <a href='#example_minns_d_bc' class=nav>[3]</a> <a href='#example_minns_d_nlc' class=nav>[4]</a> </p>
<a name='sub_minnssetxrep'></a><h3 class=pageheader><code>minnssetxrep</code> function</h3>
<pre class=source>
<div style='color: navy; margin-top: 0; margin-bottom: 0;'>/*************************************************************************
This function turns on/off reporting.
INPUT PARAMETERS:
State - structure which stores algorithm state
NeedXRep- whether iteration reports are needed or not
If NeedXRep is True, algorithm will call rep() callback function if it is
provided to minnsoptimize().
-- ALGLIB --
Copyright 28.11.2010 by Bochkanov Sergey
*************************************************************************/
</div><div style='margin-top: 0; margin-bottom: 0;'><b>void</b> alglib::minnssetxrep(minnsstate state, <b>bool</b> needxrep);
</div></pre>
<a name='example_minns_d_bc'></a><h3 class=pageheader>minns_d_bc example</h3>
<pre class=source>
#include <font color=blue><b>"stdafx.h"</b></font>
#include <stdlib.h>
#include <stdio.h>
#include <math.h>
#include <font color=blue><b>"optimization.h"</b></font>
using namespace alglib;
<b>void</b> nsfunc1_jac(<b>const</b> real_1d_array &x, real_1d_array &fi, real_2d_array &jac, <b>void</b> *ptr)
{
<font color=navy>//</font>
<font color=navy>// this callback calculates</font>
<font color=navy>//</font>
<font color=navy>// f0(x0,x1) = 2*|x0|+x1</font>
<font color=navy>//</font>
<font color=navy>// and Jacobian matrix J = [df0/dx0 df0/dx1]</font>
<font color=navy>//</font>
fi[0] = 2*fabs(<b>double</b>(x[0]))+fabs(<b>double</b>(x[1]));
jac[0][0] = 2*alglib::sign(x[0]);
jac[0][1] = alglib::sign(x[1]);
}
<b>int</b> main(<b>int</b> argc, char **argv)
{
<font color=navy>//</font>
<font color=navy>// This example demonstrates minimization of</font>
<font color=navy>//</font>
<font color=navy>// f(x0,x1) = 2*|x0|+|x1|</font>
<font color=navy>//</font>
<font color=navy>// subject to box constraints</font>
<font color=navy>//</font>
<font color=navy>// 1 <= x0 < +INF</font>
<font color=navy>// -INF <= x1 < +INF</font>
<font color=navy>//</font>
<font color=navy>// using nonsmooth nonlinear optimizer.</font>
<font color=navy>//</font>
real_1d_array x0 = <font color=blue><b>"[1,1]"</b></font>;
real_1d_array s = <font color=blue><b>"[1,1]"</b></font>;
real_1d_array bndl = <font color=blue><b>"[1,-inf]"</b></font>;
real_1d_array bndu = <font color=blue><b>"[+inf,+inf]"</b></font>;
<b>double</b> epsx = 0.00001;
<b>double</b> radius = 0.1;
<b>double</b> rho = 0.0;
ae_int_t maxits = 0;
minnsstate state;
minnsreport rep;
real_1d_array x1;
<font color=navy>//</font>
<font color=navy>// Create optimizer object, choose AGS algorithm and tune its settings:</font>
<font color=navy>// * radius=0.1 good initial value; will be automatically decreased later.</font>
<font color=navy>// * rho=0.0 penalty coefficient <b>for</b> nonlinear constraints; can be zero</font>
<font color=navy>// because we <b>do</b> not have such constraints</font>
<font color=navy>// * epsx=0.000001 stopping conditions</font>
<font color=navy>// * s=[1,1] all variables have unit scale</font>
<font color=navy>//</font>
minnscreate(2, x0, state);
minnssetalgoags(state, radius, rho);
minnssetcond(state, epsx, maxits);
minnssetscale(state, s);
<font color=navy>//</font>
<font color=navy>// Set box constraints.</font>
<font color=navy>//</font>
<font color=navy>// General linear constraints are set in similar way (see comments on</font>
<font color=navy>// minnssetlc() function <b>for</b> more information).</font>
<font color=navy>//</font>
<font color=navy>// You may combine box, linear and nonlinear constraints in one optimization</font>
<font color=navy>// problem.</font>
<font color=navy>//</font>
minnssetbc(state, bndl, bndu);
<font color=navy>//</font>
<font color=navy>// Optimize and test results.</font>
<font color=navy>//</font>
<font color=navy>// Optimizer object accepts vector function and its Jacobian, with first</font>
<font color=navy>// component (Jacobian row) being target function, and next components</font>
<font color=navy>// (Jacobian rows) being nonlinear equality and inequality constraints</font>
<font color=navy>// (box/linear ones are passed separately by means of minnssetbc() and</font>
<font color=navy>// minnssetlc() calls).</font>
<font color=navy>//</font>
<font color=navy>// If you <b>do</b> not have nonlinear constraints (exactly our situation), then</font>
<font color=navy>// you will have one-component function vector and 1xN Jacobian matrix.</font>
<font color=navy>//</font>
<font color=navy>// So, our vector function has form</font>
<font color=navy>//</font>
<font color=navy>// {f0} = { 2*|x0|+|x1| }</font>
<font color=navy>//</font>
<font color=navy>// with Jacobian</font>
<font color=navy>//</font>
<font color=navy>// [ ]</font>
<font color=navy>// J = [ 2*sign(x0) sign(x1) ]</font>
<font color=navy>// [ ]</font>
<font color=navy>//</font>
<font color=navy>// NOTE: nonsmooth optimizer requires considerably more function</font>
<font color=navy>// evaluations than smooth solver - about 2N times more. Using</font>
<font color=navy>// numerical differentiation introduces additional (multiplicative)</font>
<font color=navy>// 2N speedup.</font>
<font color=navy>//</font>
<font color=navy>// It means that <b>if</b> smooth optimizer WITH user-supplied gradient</font>
<font color=navy>// needs 100 function evaluations to solve 50-dimensional problem,</font>
<font color=navy>// then AGS solver with user-supplied gradient will need about 10.000</font>
<font color=navy>// function evaluations, and with numerical gradient about 1.000.000</font>
<font color=navy>// function evaluations will be performed.</font>
<font color=navy>//</font>
<font color=navy>// NOTE: AGS solver used by us can handle nonsmooth and nonconvex</font>
<font color=navy>// optimization problems. It has convergence guarantees, i.e. it will</font>
<font color=navy>// converge to stationary point of the function after running <b>for</b> some</font>
<font color=navy>// time.</font>
<font color=navy>//</font>
<font color=navy>// However, it is important to remember that <font color=blue><b>"stationary point"</b></font> is not</font>
<font color=navy>// equal to <font color=blue><b>"solution"</b></font>. If your problem is convex, everything is OK.</font>
<font color=navy>// But nonconvex optimization problems may have <font color=blue><b>"flat spots"</b></font> - large</font>
<font color=navy>// areas where gradient is exactly zero, but function value is far away</font>
<font color=navy>// from optimal. Such areas are stationary points too, and optimizer</font>
<font color=navy>// may be trapped here.</font>
<font color=navy>//</font>
<font color=navy>// <font color=blue><b>"Flat spots"</b></font> are nonsmooth equivalent of the saddle points, but with</font>
<font color=navy>// orders of magnitude worse properties - they may be quite large and</font>
<font color=navy>// hard to avoid. All nonsmooth optimizers are prone to this kind of the</font>
<font color=navy>// problem, because it is impossible to automatically distinguish "flat</font>
<font color=navy>// spot" from true solution.</font>
<font color=navy>//</font>
<font color=navy>// This note is here to warn you that you should be very careful when</font>
<font color=navy>// you solve nonsmooth optimization problems. Visual inspection of</font>
<font color=navy>// results is essential.</font>
<font color=navy>//</font>
<font color=navy>//</font>
alglib::minnsoptimize(state, nsfunc1_jac);
minnsresults(state, x1, rep);
printf(<font color=blue><b>"%s\n"</b></font>, x1.tostring(2).c_str()); <font color=navy>// EXPECTED: [1.0000,0.0000]</font>
<b>return</b> 0;
}
</pre><a name='example_minns_d_diff'></a><h3 class=pageheader>minns_d_diff example</h3>
<pre class=source>
#include <font color=blue><b>"stdafx.h"</b></font>
#include <stdlib.h>
#include <stdio.h>
#include <math.h>
#include <font color=blue><b>"optimization.h"</b></font>
using namespace alglib;
<b>void</b> nsfunc1_fvec(<b>const</b> real_1d_array &x, real_1d_array &fi, <b>void</b> *ptr)
{
<font color=navy>//</font>
<font color=navy>// this callback calculates</font>
<font color=navy>//</font>
<font color=navy>// f0(x0,x1) = 2*|x0|+x1</font>
<font color=navy>//</font>
fi[0] = 2*fabs(<b>double</b>(x[0]))+fabs(<b>double</b>(x[1]));
}
<b>int</b> main(<b>int</b> argc, char **argv)
{
<font color=navy>//</font>
<font color=navy>// This example demonstrates minimization of</font>
<font color=navy>//</font>
<font color=navy>// f(x0,x1) = 2*|x0|+|x1|</font>
<font color=navy>//</font>
<font color=navy>// using nonsmooth nonlinear optimizer with numerical</font>
<font color=navy>// differentiation provided by ALGLIB.</font>
<font color=navy>//</font>
<font color=navy>// NOTE: nonsmooth optimizer requires considerably more function</font>
<font color=navy>// evaluations than smooth solver - about 2N times more. Using</font>
<font color=navy>// numerical differentiation introduces additional (multiplicative)</font>
<font color=navy>// 2N speedup.</font>
<font color=navy>//</font>
<font color=navy>// It means that <b>if</b> smooth optimizer WITH user-supplied gradient</font>
<font color=navy>// needs 100 function evaluations to solve 50-dimensional problem,</font>
<font color=navy>// then AGS solver with user-supplied gradient will need about 10.000</font>
<font color=navy>// function evaluations, and with numerical gradient about 1.000.000</font>
<font color=navy>// function evaluations will be performed.</font>
<font color=navy>//</font>
real_1d_array x0 = <font color=blue><b>"[1,1]"</b></font>;
real_1d_array s = <font color=blue><b>"[1,1]"</b></font>;
<b>double</b> epsx = 0.00001;
<b>double</b> diffstep = 0.000001;
<b>double</b> radius = 0.1;
<b>double</b> rho = 0.0;
ae_int_t maxits = 0;
minnsstate state;
minnsreport rep;
real_1d_array x1;
<font color=navy>//</font>
<font color=navy>// Create optimizer object, choose AGS algorithm and tune its settings:</font>
<font color=navy>// * radius=0.1 good initial value; will be automatically decreased later.</font>
<font color=navy>// * rho=0.0 penalty coefficient <b>for</b> nonlinear constraints; can be zero</font>
<font color=navy>// because we <b>do</b> not have such constraints</font>
<font color=navy>// * epsx=0.000001 stopping conditions</font>
<font color=navy>// * s=[1,1] all variables have unit scale</font>
<font color=navy>//</font>
minnscreatef(2, x0, diffstep, state);
minnssetalgoags(state, radius, rho);
minnssetcond(state, epsx, maxits);
minnssetscale(state, s);
<font color=navy>//</font>
<font color=navy>// Optimize and test results.</font>
<font color=navy>//</font>
<font color=navy>// Optimizer object accepts vector function, with first component</font>
<font color=navy>// being target function, and next components being nonlinear equality</font>
<font color=navy>// and inequality constraints (box/linear ones are passed separately</font>
<font color=navy>// by means of minnssetbc() and minnssetlc() calls).</font>
<font color=navy>//</font>
<font color=navy>// If you <b>do</b> not have nonlinear constraints (exactly our situation), then</font>
<font color=navy>// you will have one-component function vector.</font>
<font color=navy>//</font>
<font color=navy>// So, our vector function has form</font>
<font color=navy>//</font>
<font color=navy>// {f0} = { 2*|x0|+|x1| }</font>
<font color=navy>//</font>
alglib::minnsoptimize(state, nsfunc1_fvec);
minnsresults(state, x1, rep);
printf(<font color=blue><b>"%s\n"</b></font>, x1.tostring(2).c_str()); <font color=navy>// EXPECTED: [0.0000,0.0000]</font>
<b>return</b> 0;
}
</pre><a name='example_minns_d_nlc'></a><h3 class=pageheader>minns_d_nlc example</h3>
<pre class=source>
#include <font color=blue><b>"stdafx.h"</b></font>
#include <stdlib.h>
#include <stdio.h>
#include <math.h>
#include <font color=blue><b>"optimization.h"</b></font>
using namespace alglib;
<b>void</b> nsfunc2_jac(<b>const</b> real_1d_array &x, real_1d_array &fi, real_2d_array &jac, <b>void</b> *ptr)
{
<font color=navy>//</font>
<font color=navy>// this callback calculates function vector</font>
<font color=navy>//</font>
<font color=navy>// f0(x0,x1) = 2*|x0|+x1</font>
<font color=navy>// f1(x0,x1) = x0-1</font>
<font color=navy>// f2(x0,x1) = -x1-1</font>
<font color=navy>//</font>
<font color=navy>// and Jacobian matrix J</font>
<font color=navy>//</font>
<font color=navy>// [ df0/dx0 df0/dx1 ]</font>
<font color=navy>// J = [ df1/dx0 df1/dx1 ]</font>
<font color=navy>// [ df2/dx0 df2/dx1 ]</font>
<font color=navy>//</font>
fi[0] = 2*fabs(<b>double</b>(x[0]))+fabs(<b>double</b>(x[1]));
jac[0][0] = 2*alglib::sign(x[0]);
jac[0][1] = alglib::sign(x[1]);
fi[1] = x[0]-1;
jac[1][0] = 1;
jac[1][1] = 0;
fi[2] = -x[1]-1;
jac[2][0] = 0;
jac[2][1] = -1;
}
<b>int</b> main(<b>int</b> argc, char **argv)
{
<font color=navy>//</font>
<font color=navy>// This example demonstrates minimization of</font>
<font color=navy>//</font>
<font color=navy>// f(x0,x1) = 2*|x0|+|x1|</font>
<font color=navy>//</font>
<font color=navy>// subject to combination of equality and inequality constraints</font>
<font color=navy>//</font>
<font color=navy>// x0 = 1</font>
<font color=navy>// x1 >= -1</font>
<font color=navy>//</font>
<font color=navy>// using nonsmooth nonlinear optimizer. Although these constraints</font>
<font color=navy>// are linear, we treat them as general nonlinear ones in order to</font>
<font color=navy>// demonstrate nonlinearly constrained optimization setup.</font>
<font color=navy>//</font>
real_1d_array x0 = <font color=blue><b>"[1,1]"</b></font>;
real_1d_array s = <font color=blue><b>"[1,1]"</b></font>;
<b>double</b> epsx = 0.00001;
<b>double</b> radius = 0.1;
<b>double</b> rho = 50.0;
ae_int_t maxits = 0;
minnsstate state;
minnsreport rep;
real_1d_array x1;
<font color=navy>//</font>
<font color=navy>// Create optimizer object, choose AGS algorithm and tune its settings:</font>
<font color=navy>// * radius=0.1 good initial value; will be automatically decreased later.</font>
<font color=navy>// * rho=50.0 penalty coefficient <b>for</b> nonlinear constraints. It is your</font>
<font color=navy>// responsibility to choose good one - large enough that it</font>
<font color=navy>// enforces constraints, but small enough in order to avoid</font>
<font color=navy>// extreme slowdown due to ill-conditioning.</font>
<font color=navy>// * epsx=0.000001 stopping conditions</font>
<font color=navy>// * s=[1,1] all variables have unit scale</font>
<font color=navy>//</font>
minnscreate(2, x0, state);
minnssetalgoags(state, radius, rho);
minnssetcond(state, epsx, maxits);
minnssetscale(state, s);
<font color=navy>//</font>
<font color=navy>// Set general nonlinear constraints.</font>
<font color=navy>//</font>
<font color=navy>// This part is more tricky than working with box/linear constraints - you</font>
<font color=navy>// can not <font color=blue><b>"pack"</b></font> general nonlinear function into <b>double</b> precision array.</font>
<font color=navy>// That's why minnssetnlc() does not accept constraints itself - only</font>
<font color=navy>// constraint COUNTS are passed: first parameter is number of equality</font>
<font color=navy>// constraints, second one is number of inequality constraints.</font>
<font color=navy>//</font>
<font color=navy>// As <b>for</b> constraining functions - these functions are passed as part</font>
<font color=navy>// of problem Jacobian (see below).</font>
<font color=navy>//</font>
<font color=navy>// NOTE: MinNS optimizer supports arbitrary combination of boundary, general</font>
<font color=navy>// linear and general nonlinear constraints. This example does not</font>
<font color=navy>// show how to work with general linear constraints, but you can</font>
<font color=navy>// easily find it in documentation on minnlcsetlc() function.</font>
<font color=navy>//</font>
minnssetnlc(state, 1, 1);
<font color=navy>//</font>
<font color=navy>// Optimize and test results.</font>
<font color=navy>//</font>
<font color=navy>// Optimizer object accepts vector function and its Jacobian, with first</font>
<font color=navy>// component (Jacobian row) being target function, and next components</font>
<font color=navy>// (Jacobian rows) being nonlinear equality and inequality constraints</font>
<font color=navy>// (box/linear ones are passed separately by means of minnssetbc() and</font>
<font color=navy>// minnssetlc() calls).</font>
<font color=navy>//</font>
<font color=navy>// Nonlinear equality constraints have form Gi(x)=0, inequality ones</font>
<font color=navy>// have form Hi(x)<=0, so we may have to <font color=blue><b>"normalize"</b></font> constraints prior</font>
<font color=navy>// to passing them to optimizer (right side is zero, constraints are</font>
<font color=navy>// sorted, multiplied by -1 when needed).</font>
<font color=navy>//</font>
<font color=navy>// So, our vector function has form</font>
<font color=navy>//</font>
<font color=navy>// {f0,f1,f2} = { 2*|x0|+|x1|, x0-1, -x1-1 }</font>
<font color=navy>//</font>
<font color=navy>// with Jacobian</font>
<font color=navy>//</font>
<font color=navy>// [ 2*sign(x0) sign(x1) ]</font>
<font color=navy>// J = [ 1 0 ]</font>
<font color=navy>// [ 0 -1 ]</font>
<font color=navy>//</font>
<font color=navy>// which means that we have optimization problem</font>
<font color=navy>//</font>
<font color=navy>// min{f0} subject to f1=0, f2<=0</font>
<font color=navy>//</font>
<font color=navy>// which is essentially same as</font>
<font color=navy>//</font>
<font color=navy>// min { 2*|x0|+|x1| } subject to x0=1, x1>=-1</font>
<font color=navy>//</font>
<font color=navy>// NOTE: AGS solver used by us can handle nonsmooth and nonconvex</font>
<font color=navy>// optimization problems. It has convergence guarantees, i.e. it will</font>
<font color=navy>// converge to stationary point of the function after running <b>for</b> some</font>
<font color=navy>// time.</font>
<font color=navy>//</font>
<font color=navy>// However, it is important to remember that <font color=blue><b>"stationary point"</b></font> is not</font>
<font color=navy>// equal to <font color=blue><b>"solution"</b></font>. If your problem is convex, everything is OK.</font>
<font color=navy>// But nonconvex optimization problems may have <font color=blue><b>"flat spots"</b></font> - large</font>
<font color=navy>// areas where gradient is exactly zero, but function value is far away</font>
<font color=navy>// from optimal. Such areas are stationary points too, and optimizer</font>
<font color=navy>// may be trapped here.</font>
<font color=navy>//</font>
<font color=navy>// <font color=blue><b>"Flat spots"</b></font> are nonsmooth equivalent of the saddle points, but with</font>
<font color=navy>// orders of magnitude worse properties - they may be quite large and</font>
<font color=navy>// hard to avoid. All nonsmooth optimizers are prone to this kind of the</font>
<font color=navy>// problem, because it is impossible to automatically distinguish "flat</font>
<font color=navy>// spot" from true solution.</font>
<font color=navy>//</font>
<font color=navy>// This note is here to warn you that you should be very careful when</font>
<font color=navy>// you solve nonsmooth optimization problems. Visual inspection of</font>
<font color=navy>// results is essential.</font>
<font color=navy>//</font>
alglib::minnsoptimize(state, nsfunc2_jac);
minnsresults(state, x1, rep);
printf(<font color=blue><b>"%s\n"</b></font>, x1.tostring(2).c_str()); <font color=navy>// EXPECTED: [1.0000,0.0000]</font>
<b>return</b> 0;
}
</pre><a name='example_minns_d_unconstrained'></a><h3 class=pageheader>minns_d_unconstrained example</h3>
<pre class=source>
#include <font color=blue><b>"stdafx.h"</b></font>
#include <stdlib.h>
#include <stdio.h>
#include <math.h>
#include <font color=blue><b>"optimization.h"</b></font>
using namespace alglib;
<b>void</b> nsfunc1_jac(<b>const</b> real_1d_array &x, real_1d_array &fi, real_2d_array &jac, <b>void</b> *ptr)
{
<font color=navy>//</font>
<font color=navy>// this callback calculates</font>
<font color=navy>//</font>
<font color=navy>// f0(x0,x1) = 2*|x0|+x1</font>
<font color=navy>//</font>
<font color=navy>// and Jacobian matrix J = [df0/dx0 df0/dx1]</font>
<font color=navy>//</font>
fi[0] = 2*fabs(<b>double</b>(x[0]))+fabs(<b>double</b>(x[1]));
jac[0][0] = 2*alglib::sign(x[0]);
jac[0][1] = alglib::sign(x[1]);
}
<b>int</b> main(<b>int</b> argc, char **argv)
{
<font color=navy>//</font>
<font color=navy>// This example demonstrates minimization of</font>
<font color=navy>//</font>
<font color=navy>// f(x0,x1) = 2*|x0|+|x1|</font>
<font color=navy>//</font>
<font color=navy>// using nonsmooth nonlinear optimizer.</font>
<font color=navy>//</font>
real_1d_array x0 = <font color=blue><b>"[1,1]"</b></font>;
real_1d_array s = <font color=blue><b>"[1,1]"</b></font>;
<b>double</b> epsx = 0.00001;
<b>double</b> radius = 0.1;
<b>double</b> rho = 0.0;
ae_int_t maxits = 0;
minnsstate state;
minnsreport rep;
real_1d_array x1;
<font color=navy>//</font>
<font color=navy>// Create optimizer object, choose AGS algorithm and tune its settings:</font>
<font color=navy>// * radius=0.1 good initial value; will be automatically decreased later.</font>
<font color=navy>// * rho=0.0 penalty coefficient <b>for</b> nonlinear constraints; can be zero</font>
<font color=navy>// because we <b>do</b> not have such constraints</font>
<font color=navy>// * epsx=0.000001 stopping conditions</font>
<font color=navy>// * s=[1,1] all variables have unit scale</font>
<font color=navy>//</font>
minnscreate(2, x0, state);
minnssetalgoags(state, radius, rho);
minnssetcond(state, epsx, maxits);
minnssetscale(state, s);
<font color=navy>//</font>
<font color=navy>// Optimize and test results.</font>
<font color=navy>//</font>
<font color=navy>// Optimizer object accepts vector function and its Jacobian, with first</font>
<font color=navy>// component (Jacobian row) being target function, and next components</font>
<font color=navy>// (Jacobian rows) being nonlinear equality and inequality constraints</font>
<font color=navy>// (box/linear ones are passed separately by means of minnssetbc() and</font>
<font color=navy>// minnssetlc() calls).</font>
<font color=navy>//</font>
<font color=navy>// If you <b>do</b> not have nonlinear constraints (exactly our situation), then</font>
<font color=navy>// you will have one-component function vector and 1xN Jacobian matrix.</font>
<font color=navy>//</font>
<font color=navy>// So, our vector function has form</font>
<font color=navy>//</font>
<font color=navy>// {f0} = { 2*|x0|+|x1| }</font>
<font color=navy>//</font>
<font color=navy>// with Jacobian</font>
<font color=navy>//</font>
<font color=navy>// [ ]</font>
<font color=navy>// J = [ 2*sign(x0) sign(x1) ]</font>
<font color=navy>// [ ]</font>
<font color=navy>//</font>
<font color=navy>// NOTE: nonsmooth optimizer requires considerably more function</font>
<font color=navy>// evaluations than smooth solver - about 2N times more. Using</font>
<font color=navy>// numerical differentiation introduces additional (multiplicative)</font>
<font color=navy>// 2N speedup.</font>
<font color=navy>//</font>
<font color=navy>// It means that <b>if</b> smooth optimizer WITH user-supplied gradient</font>
<font color=navy>// needs 100 function evaluations to solve 50-dimensional problem,</font>
<font color=navy>// then AGS solver with user-supplied gradient will need about 10.000</font>
<font color=navy>// function evaluations, and with numerical gradient about 1.000.000</font>
<font color=navy>// function evaluations will be performed.</font>
<font color=navy>//</font>
<font color=navy>// NOTE: AGS solver used by us can handle nonsmooth and nonconvex</font>
<font color=navy>// optimization problems. It has convergence guarantees, i.e. it will</font>
<font color=navy>// converge to stationary point of the function after running <b>for</b> some</font>
<font color=navy>// time.</font>
<font color=navy>//</font>
<font color=navy>// However, it is important to remember that <font color=blue><b>"stationary point"</b></font> is not</font>
<font color=navy>// equal to <font color=blue><b>"solution"</b></font>. If your problem is convex, everything is OK.</font>
<font color=navy>// But nonconvex optimization problems may have <font color=blue><b>"flat spots"</b></font> - large</font>
<font color=navy>// areas where gradient is exactly zero, but function value is far away</font>
<font color=navy>// from optimal. Such areas are stationary points too, and optimizer</font>
<font color=navy>// may be trapped here.</font>
<font color=navy>//</font>
<font color=navy>// <font color=blue><b>"Flat spots"</b></font> are nonsmooth equivalent of the saddle points, but with</font>
<font color=navy>// orders of magnitude worse properties - they may be quite large and</font>
<font color=navy>// hard to avoid. All nonsmooth optimizers are prone to this kind of the</font>
<font color=navy>// problem, because it is impossible to automatically distinguish "flat</font>
<font color=navy>// spot" from true solution.</font>
<font color=navy>//</font>
<font color=navy>// This note is here to warn you that you should be very careful when</font>
<font color=navy>// you solve nonsmooth optimization problems. Visual inspection of</font>
<font color=navy>// results is essential.</font>
<font color=navy>//</font>
alglib::minnsoptimize(state, nsfunc1_jac);
minnsresults(state, x1, rep);
printf(<font color=blue><b>"%s\n"</b></font>, x1.tostring(2).c_str()); <font color=navy>// EXPECTED: [0.0000,0.0000]</font>
<b>return</b> 0;
}
</pre><a name=unit_minqp></a><h2 class=pageheader><code>minqp</code> subpackage</h2>
<div class=pagecontent>
<h3 class=pageheader>Classes</h3>
<a href='#struct_minqpreport' class=toc>minqpreport</a><br>
<a href='#struct_minqpstate' class=toc>minqpstate</a><br>
<h3 class=pageheader>Functions</h3>
<a href='#sub_minqpcreate' class=toc>minqpcreate</a><br>
<a href='#sub_minqpoptimize' class=toc>minqpoptimize</a><br>
<a href='#sub_minqpresults' class=toc>minqpresults</a><br>
<a href='#sub_minqpresultsbuf' class=toc>minqpresultsbuf</a><br>
<a href='#sub_minqpsetalgobleic' class=toc>minqpsetalgobleic</a><br>
<a href='#sub_minqpsetalgocholesky' class=toc>minqpsetalgocholesky</a><br>
<a href='#sub_minqpsetalgoquickqp' class=toc>minqpsetalgoquickqp</a><br>
<a href='#sub_minqpsetbc' class=toc>minqpsetbc</a><br>
<a href='#sub_minqpsetlc' class=toc>minqpsetlc</a><br>
<a href='#sub_minqpsetlinearterm' class=toc>minqpsetlinearterm</a><br>
<a href='#sub_minqpsetorigin' class=toc>minqpsetorigin</a><br>
<a href='#sub_minqpsetquadraticterm' class=toc>minqpsetquadraticterm</a><br>
<a href='#sub_minqpsetquadratictermsparse' class=toc>minqpsetquadratictermsparse</a><br>
<a href='#sub_minqpsetscale' class=toc>minqpsetscale</a><br>
<a href='#sub_minqpsetstartingpoint' class=toc>minqpsetstartingpoint</a><br>
<h3 class=pageheader>Examples</h3>
<table border=0 cellspacing=0 class='pagecontent'>
<tr align=left valign=top><td><a href='#example_minqp_d_bc1' class=toc>minqp_d_bc1</a></td><td width=15> </td><td>Bound constrained dense quadratic programming</td></tr>
<tr align=left valign=top><td><a href='#example_minqp_d_lc1' class=toc>minqp_d_lc1</a></td><td width=15> </td><td>Linearly constrained dense quadratic programming</td></tr>
<tr align=left valign=top><td><a href='#example_minqp_d_nonconvex' class=toc>minqp_d_nonconvex</a></td><td width=15> </td><td>Nonconvex quadratic programming</td></tr>
<tr align=left valign=top><td><a href='#example_minqp_d_u1' class=toc>minqp_d_u1</a></td><td width=15> </td><td>Unconstrained dense quadratic programming</td></tr>
<tr align=left valign=top><td><a href='#example_minqp_d_u2' class=toc>minqp_d_u2</a></td><td width=15> </td><td>Unconstrained sparse quadratic programming</td></tr>
</table></div>
<a name='struct_minqpreport'></a><h3 class=pageheader><code>minqpreport</code> class</h3>
<pre class=source>
<div style='color: navy; margin-top: 0; margin-bottom: 0;'>/*************************************************************************
This structure stores optimization report:
* InnerIterationsCount number of inner iterations
* OuterIterationsCount number of outer iterations
* NCholesky number of Cholesky decomposition
* NMV number of matrix-vector products
(only products calculated as part of iterative
process are counted)
* TerminationType completion code (see below)
Completion codes:
* -5 inappropriate solver was used:
* QuickQP solver for problem with general linear constraints
* Cholesky solver for semidefinite or indefinite problems
* Cholesky solver for problems with non-boundary constraints
* -4 BLEIC-QP or QuickQP solver found unconstrained direction
of negative curvature (function is unbounded from
below even under constraints), no meaningful
minimum can be found.
* -3 inconsistent constraints (or, maybe, feasible point is
too hard to find). If you are sure that constraints are feasible,
try to restart optimizer with better initial approximation.
* -1 solver error
* 1..4 successful completion
* 5 MaxIts steps was taken
* 7 stopping conditions are too stringent,
further improvement is impossible,
X contains best point found so far.
*************************************************************************/
</div><div style='margin-top: 0; margin-bottom: 0;'><b>class</b> minqpreport
{
ae_int_t inneriterationscount;
ae_int_t outeriterationscount;
ae_int_t nmv;
ae_int_t ncholesky;
ae_int_t terminationtype;
};
</div></pre>
<a name='struct_minqpstate'></a><h3 class=pageheader><code>minqpstate</code> class</h3>
<pre class=source>
<div style='color: navy; margin-top: 0; margin-bottom: 0;'>/*************************************************************************
This object stores nonlinear optimizer state.
You should use functions provided by MinQP subpackage to work with this
object
*************************************************************************/
</div><div style='margin-top: 0; margin-bottom: 0;'><b>class</b> minqpstate
{
};
</div></pre>
<a name='sub_minqpcreate'></a><h3 class=pageheader><code>minqpcreate</code> function</h3>
<pre class=source>
<div style='color: navy; margin-top: 0; margin-bottom: 0;'>/*************************************************************************
CONSTRAINED QUADRATIC PROGRAMMING
The subroutine creates QP optimizer. After initial creation, it contains
default optimization problem with zero quadratic and linear terms and no
constraints. You should set quadratic/linear terms with calls to functions
provided by MinQP subpackage.
You should also choose appropriate QP solver and set it and its stopping
criteria by means of MinQPSetAlgo??????() function. Then, you should start
solution process by means of MinQPOptimize() call. Solution itself can be
obtained with MinQPResults() function.
INPUT PARAMETERS:
N - problem size
OUTPUT PARAMETERS:
State - optimizer with zero quadratic/linear terms
and no constraints
-- ALGLIB --
Copyright 11.01.2011 by Bochkanov Sergey
*************************************************************************/
</div><div style='margin-top: 0; margin-bottom: 0;'><b>void</b> alglib::minqpcreate(ae_int_t n, minqpstate& state);
</div></pre>
<p align=left class=pagecontent><span class=inlineheader>Examples:</span> <a href='#example_minqp_d_u1' class=nav>[1]</a> <a href='#example_minqp_d_bc1' class=nav>[2]</a> <a href='#example_minqp_d_lc1' class=nav>[3]</a> <a href='#example_minqp_d_u2' class=nav>[4]</a> <a href='#example_minqp_d_nonconvex' class=nav>[5]</a> </p>
<a name='sub_minqpoptimize'></a><h3 class=pageheader><code>minqpoptimize</code> function</h3>
<pre class=source>
<div style='color: navy; margin-top: 0; margin-bottom: 0;'>/*************************************************************************
This function solves quadratic programming problem.
Prior to calling this function you should choose solver by means of one of
the following functions:
* MinQPSetAlgoQuickQP() - for QuickQP solver
* MinQPSetAlgoBLEIC() - for BLEIC-QP solver
These functions also allow you to control stopping criteria of the solver.
If you did not set solver, MinQP subpackage will automatically select
solver for your problem and will run it with default stopping criteria.
However, it is better to set explicitly solver and its stopping criteria.
INPUT PARAMETERS:
State - algorithm state
You should use MinQPResults() function to access results after calls
to this function.
-- ALGLIB --
Copyright 11.01.2011 by Bochkanov Sergey.
Special thanks to Elvira Illarionova for important suggestions on
the linearly constrained QP algorithm.
*************************************************************************/
</div><div style='margin-top: 0; margin-bottom: 0;'><b>void</b> alglib::minqpoptimize(minqpstate state);
</div></pre>
<p align=left class=pagecontent><span class=inlineheader>Examples:</span> <a href='#example_minqp_d_u1' class=nav>[1]</a> <a href='#example_minqp_d_bc1' class=nav>[2]</a> <a href='#example_minqp_d_lc1' class=nav>[3]</a> <a href='#example_minqp_d_u2' class=nav>[4]</a> <a href='#example_minqp_d_nonconvex' class=nav>[5]</a> </p>
<a name='sub_minqpresults'></a><h3 class=pageheader><code>minqpresults</code> function</h3>
<pre class=source>
<div style='color: navy; margin-top: 0; margin-bottom: 0;'>/*************************************************************************
QP solver results
INPUT PARAMETERS:
State - algorithm state
OUTPUT PARAMETERS:
X - array[0..N-1], solution.
This array is allocated and initialized only when
Rep.TerminationType parameter is positive (success).
Rep - optimization report. You should check Rep.TerminationType,
which contains completion code, and you may check another
fields which contain another information about algorithm
functioning.
Failure codes returned by algorithm are:
* -5 inappropriate solver was used:
* Cholesky solver for (semi)indefinite problems
* Cholesky solver for problems with sparse matrix
* QuickQP solver for problem with general linear
constraints
* -4 BLEIC-QP/QuickQP solver found unconstrained
direction of negative curvature (function is
unbounded from below even under constraints), no
meaningful minimum can be found.
* -3 inconsistent constraints (or maybe feasible point
is too hard to find). If you are sure that
constraints are feasible, try to restart optimizer
with better initial approximation.
Completion codes specific for Cholesky algorithm:
* 4 successful completion
Completion codes specific for BLEIC/QuickQP algorithms:
* 1 relative function improvement is no more than EpsF.
* 2 scaled step is no more than EpsX.
* 4 scaled gradient norm is no more than EpsG.
* 5 MaxIts steps was taken
-- ALGLIB --
Copyright 11.01.2011 by Bochkanov Sergey
*************************************************************************/
</div><div style='margin-top: 0; margin-bottom: 0;'><b>void</b> alglib::minqpresults(
minqpstate state,
real_1d_array& x,
minqpreport& rep);
</div></pre>
<p align=left class=pagecontent><span class=inlineheader>Examples:</span> <a href='#example_minqp_d_u1' class=nav>[1]</a> <a href='#example_minqp_d_bc1' class=nav>[2]</a> <a href='#example_minqp_d_lc1' class=nav>[3]</a> <a href='#example_minqp_d_u2' class=nav>[4]</a> <a href='#example_minqp_d_nonconvex' class=nav>[5]</a> </p>
<a name='sub_minqpresultsbuf'></a><h3 class=pageheader><code>minqpresultsbuf</code> function</h3>
<pre class=source>
<div style='color: navy; margin-top: 0; margin-bottom: 0;'>/*************************************************************************
QP results
Buffered implementation of MinQPResults() which uses pre-allocated buffer
to store X[]. If buffer size is too small, it resizes buffer. It is
intended to be used in the inner cycles of performance critical algorithms
where array reallocation penalty is too large to be ignored.
-- ALGLIB --
Copyright 11.01.2011 by Bochkanov Sergey
*************************************************************************/
</div><div style='margin-top: 0; margin-bottom: 0;'><b>void</b> alglib::minqpresultsbuf(
minqpstate state,
real_1d_array& x,
minqpreport& rep);
</div></pre>
<a name='sub_minqpsetalgobleic'></a><h3 class=pageheader><code>minqpsetalgobleic</code> function</h3>
<pre class=source>
<div style='color: navy; margin-top: 0; margin-bottom: 0;'>/*************************************************************************
This function tells solver to use BLEIC-based algorithm and sets stopping
criteria for the algorithm.
ALGORITHM FEATURES:
* supports dense and sparse QP problems
* supports boundary and general linear equality/inequality constraints
* can solve all types of problems (convex, semidefinite, nonconvex) as
long as they are bounded from below under constraints.
Say, it is possible to solve "min{-x^2} subject to -1<=x<=+1".
Of course, global minimum is found only for positive definite and
semidefinite problems. As for indefinite ones - only local minimum is
found.
ALGORITHM OUTLINE:
* BLEIC-QP solver is just a driver function for MinBLEIC solver; it solves
quadratic programming problem as general linearly constrained
optimization problem, which is solved by means of BLEIC solver (part of
ALGLIB, active set method).
ALGORITHM LIMITATIONS:
* unlike QuickQP solver, this algorithm does not perform Newton steps and
does not use Level 3 BLAS. Being general-purpose active set method, it
can activate constraints only one-by-one. Thus, its performance is lower
than that of QuickQP.
* its precision is also a bit inferior to that of QuickQP. BLEIC-QP
performs only LBFGS steps (no Newton steps), which are good at detecting
neighborhood of the solution, buy need many iterations to find solution
with more than 6 digits of precision.
INPUT PARAMETERS:
State - structure which stores algorithm state
EpsG - >=0
The subroutine finishes its work if the condition
|v|<EpsG is satisfied, where:
* |.| means Euclidian norm
* v - scaled constrained gradient vector, v[i]=g[i]*s[i]
* g - gradient
* s - scaling coefficients set by MinQPSetScale()
EpsF - >=0
The subroutine finishes its work if exploratory steepest
descent step on k+1-th iteration satisfies following
condition: |F(k+1)-F(k)|<=EpsF*max{|F(k)|,|F(k+1)|,1}
EpsX - >=0
The subroutine finishes its work if exploratory steepest
descent step on k+1-th iteration satisfies following
condition:
* |.| means Euclidian norm
* v - scaled step vector, v[i]=dx[i]/s[i]
* dx - step vector, dx=X(k+1)-X(k)
* s - scaling coefficients set by MinQPSetScale()
MaxIts - maximum number of iterations. If MaxIts=0, the number of
iterations is unlimited. NOTE: this algorithm uses LBFGS
iterations, which are relatively cheap, but improve
function value only a bit. So you will need many iterations
to converge - from 0.1*N to 10*N, depending on problem's
condition number.
IT IS VERY IMPORTANT TO CALL MinQPSetScale() WHEN YOU USE THIS ALGORITHM
BECAUSE ITS STOPPING CRITERIA ARE SCALE-DEPENDENT!
Passing EpsG=0, EpsF=0 and EpsX=0 and MaxIts=0 (simultaneously) will lead
to automatic stopping criterion selection (presently it is small step
length, but it may change in the future versions of ALGLIB).
-- ALGLIB --
Copyright 11.01.2011 by Bochkanov Sergey
*************************************************************************/
</div><div style='margin-top: 0; margin-bottom: 0;'><b>void</b> alglib::minqpsetalgobleic(
minqpstate state,
<b>double</b> epsg,
<b>double</b> epsf,
<b>double</b> epsx,
ae_int_t maxits);
</div></pre>
<a name='sub_minqpsetalgocholesky'></a><h3 class=pageheader><code>minqpsetalgocholesky</code> function</h3>
<pre class=source>
<div style='color: navy; margin-top: 0; margin-bottom: 0;'>/*************************************************************************
This function tells solver to use Cholesky-based algorithm. This algorithm
was deprecated in ALGLIB 3.9.0 because its performance is inferior to that
of BLEIC-QP or QuickQP on high-dimensional problems. Furthermore, it
supports only dense convex QP problems.
This solver is no longer active by default.
We recommend you to switch to BLEIC-QP or QuickQP solver.
INPUT PARAMETERS:
State - structure which stores algorithm state
-- ALGLIB --
Copyright 11.01.2011 by Bochkanov Sergey
*************************************************************************/
</div><div style='margin-top: 0; margin-bottom: 0;'><b>void</b> alglib::minqpsetalgocholesky(minqpstate state);
</div></pre>
<a name='sub_minqpsetalgoquickqp'></a><h3 class=pageheader><code>minqpsetalgoquickqp</code> function</h3>
<pre class=source>
<div style='color: navy; margin-top: 0; margin-bottom: 0;'>/*************************************************************************
This function tells solver to use QuickQP algorithm: special extra-fast
algorithm for problems with boundary-only constrants. It may solve
non-convex problems as long as they are bounded from below under
constraints.
ALGORITHM FEATURES:
* many times (from 5x to 50x!) faster than BLEIC-based QP solver; utilizes
accelerated methods for activation of constraints.
* supports dense and sparse QP problems
* supports ONLY boundary constraints; general linear constraints are NOT
supported by this solver
* can solve all types of problems (convex, semidefinite, nonconvex) as
long as they are bounded from below under constraints.
Say, it is possible to solve "min{-x^2} subject to -1<=x<=+1".
In convex/semidefinite case global minimum is returned, in nonconvex
case - algorithm returns one of the local minimums.
ALGORITHM OUTLINE:
* algorithm performs two kinds of iterations: constrained CG iterations
and constrained Newton iterations
* initially it performs small number of constrained CG iterations, which
can efficiently activate/deactivate multiple constraints
* after CG phase algorithm tries to calculate Cholesky decomposition and
to perform several constrained Newton steps. If Cholesky decomposition
failed (matrix is indefinite even under constraints), we perform more
CG iterations until we converge to such set of constraints that system
matrix becomes positive definite. Constrained Newton steps greatly
increase convergence speed and precision.
* algorithm interleaves CG and Newton iterations which allows to handle
indefinite matrices (CG phase) and quickly converge after final set of
constraints is found (Newton phase). Combination of CG and Newton phases
is called "outer iteration".
* it is possible to turn off Newton phase (beneficial for semidefinite
problems - Cholesky decomposition will fail too often)
ALGORITHM LIMITATIONS:
* algorithm does not support general linear constraints; only boundary
ones are supported
* Cholesky decomposition for sparse problems is performed with Skyline
Cholesky solver, which is intended for low-profile matrices. No profile-
reducing reordering of variables is performed in this version of ALGLIB.
* problems with near-zero negative eigenvalues (or exacty zero ones) may
experience about 2-3x performance penalty. The reason is that Cholesky
decomposition can not be performed until we identify directions of zero
and negative curvature and activate corresponding boundary constraints -
but we need a lot of trial and errors because these directions are hard
to notice in the matrix spectrum.
In this case you may turn off Newton phase of algorithm.
Large negative eigenvalues are not an issue, so highly non-convex
problems can be solved very efficiently.
INPUT PARAMETERS:
State - structure which stores algorithm state
EpsG - >=0
The subroutine finishes its work if the condition
|v|<EpsG is satisfied, where:
* |.| means Euclidian norm
* v - scaled constrained gradient vector, v[i]=g[i]*s[i]
* g - gradient
* s - scaling coefficients set by MinQPSetScale()
EpsF - >=0
The subroutine finishes its work if exploratory steepest
descent step on k+1-th iteration satisfies following
condition: |F(k+1)-F(k)|<=EpsF*max{|F(k)|,|F(k+1)|,1}
EpsX - >=0
The subroutine finishes its work if exploratory steepest
descent step on k+1-th iteration satisfies following
condition:
* |.| means Euclidian norm
* v - scaled step vector, v[i]=dx[i]/s[i]
* dx - step vector, dx=X(k+1)-X(k)
* s - scaling coefficients set by MinQPSetScale()
MaxOuterIts-maximum number of OUTER iterations. One outer iteration
includes some amount of CG iterations (from 5 to ~N) and
one or several (usually small amount) Newton steps. Thus,
one outer iteration has high cost, but can greatly reduce
funcation value.
UseNewton- use Newton phase or not:
* Newton phase improves performance of positive definite
dense problems (about 2 times improvement can be observed)
* can result in some performance penalty on semidefinite
or slightly negative definite problems - each Newton
phase will bring no improvement (Cholesky failure), but
still will require computational time.
* if you doubt, you can turn off this phase - optimizer
will retain its most of its high speed.
IT IS VERY IMPORTANT TO CALL MinQPSetScale() WHEN YOU USE THIS ALGORITHM
BECAUSE ITS STOPPING CRITERIA ARE SCALE-DEPENDENT!
Passing EpsG=0, EpsF=0 and EpsX=0 and MaxIts=0 (simultaneously) will lead
to automatic stopping criterion selection (presently it is small step
length, but it may change in the future versions of ALGLIB).
-- ALGLIB --
Copyright 22.05.2014 by Bochkanov Sergey
*************************************************************************/
</div><div style='margin-top: 0; margin-bottom: 0;'><b>void</b> alglib::minqpsetalgoquickqp(
minqpstate state,
<b>double</b> epsg,
<b>double</b> epsf,
<b>double</b> epsx,
ae_int_t maxouterits,
<b>bool</b> usenewton);
</div></pre>
<a name='sub_minqpsetbc'></a><h3 class=pageheader><code>minqpsetbc</code> function</h3>
<pre class=source>
<div style='color: navy; margin-top: 0; margin-bottom: 0;'>/*************************************************************************
This function sets boundary constraints for QP solver
Boundary constraints are inactive by default (after initial creation).
After being set, they are preserved until explicitly turned off with
another SetBC() call.
INPUT PARAMETERS:
State - structure stores algorithm state
BndL - lower bounds, array[N].
If some (all) variables are unbounded, you may specify
very small number or -INF (latter is recommended because
it will allow solver to use better algorithm).
BndU - upper bounds, array[N].
If some (all) variables are unbounded, you may specify
very large number or +INF (latter is recommended because
it will allow solver to use better algorithm).
NOTE: it is possible to specify BndL[i]=BndU[i]. In this case I-th
variable will be "frozen" at X[i]=BndL[i]=BndU[i].
-- ALGLIB --
Copyright 11.01.2011 by Bochkanov Sergey
*************************************************************************/
</div><div style='margin-top: 0; margin-bottom: 0;'><b>void</b> alglib::minqpsetbc(
minqpstate state,
real_1d_array bndl,
real_1d_array bndu);
</div></pre>
<p align=left class=pagecontent><span class=inlineheader>Examples:</span> <a href='#example_minqp_d_bc1' class=nav>[1]</a> </p>
<a name='sub_minqpsetlc'></a><h3 class=pageheader><code>minqpsetlc</code> function</h3>
<pre class=source>
<div style='color: navy; margin-top: 0; margin-bottom: 0;'>/*************************************************************************
This function sets linear constraints for QP optimizer.
Linear constraints are inactive by default (after initial creation).
INPUT PARAMETERS:
State - structure previously allocated with MinQPCreate call.
C - linear constraints, array[K,N+1].
Each row of C represents one constraint, either equality
or inequality (see below):
* first N elements correspond to coefficients,
* last element corresponds to the right part.
All elements of C (including right part) must be finite.
CT - type of constraints, array[K]:
* if CT[i]>0, then I-th constraint is C[i,*]*x >= C[i,n+1]
* if CT[i]=0, then I-th constraint is C[i,*]*x = C[i,n+1]
* if CT[i]<0, then I-th constraint is C[i,*]*x <= C[i,n+1]
K - number of equality/inequality constraints, K>=0:
* if given, only leading K elements of C/CT are used
* if not given, automatically determined from sizes of C/CT
NOTE 1: linear (non-bound) constraints are satisfied only approximately -
there always exists some minor violation (about 10^-10...10^-13)
due to numerical errors.
-- ALGLIB --
Copyright 19.06.2012 by Bochkanov Sergey
*************************************************************************/
</div><div style='margin-top: 0; margin-bottom: 0;'><b>void</b> alglib::minqpsetlc(
minqpstate state,
real_2d_array c,
integer_1d_array ct);
<b>void</b> alglib::minqpsetlc(
minqpstate state,
real_2d_array c,
integer_1d_array ct,
ae_int_t k);
</div></pre>
<p align=left class=pagecontent><span class=inlineheader>Examples:</span> <a href='#example_minqp_d_lc1' class=nav>[1]</a> </p>
<a name='sub_minqpsetlinearterm'></a><h3 class=pageheader><code>minqpsetlinearterm</code> function</h3>
<pre class=source>
<div style='color: navy; margin-top: 0; margin-bottom: 0;'>/*************************************************************************
This function sets linear term for QP solver.
By default, linear term is zero.
INPUT PARAMETERS:
State - structure which stores algorithm state
B - linear term, array[N].
-- ALGLIB --
Copyright 11.01.2011 by Bochkanov Sergey
*************************************************************************/
</div><div style='margin-top: 0; margin-bottom: 0;'><b>void</b> alglib::minqpsetlinearterm(minqpstate state, real_1d_array b);
</div></pre>
<p align=left class=pagecontent><span class=inlineheader>Examples:</span> <a href='#example_minqp_d_u1' class=nav>[1]</a> <a href='#example_minqp_d_bc1' class=nav>[2]</a> <a href='#example_minqp_d_lc1' class=nav>[3]</a> <a href='#example_minqp_d_u2' class=nav>[4]</a> <a href='#example_minqp_d_nonconvex' class=nav>[5]</a> </p>
<a name='sub_minqpsetorigin'></a><h3 class=pageheader><code>minqpsetorigin</code> function</h3>
<pre class=source>
<div style='color: navy; margin-top: 0; margin-bottom: 0;'>/*************************************************************************
This function sets origin for QP solver. By default, following QP program
is solved:
min(0.5*x'*A*x+b'*x)
This function allows to solve different problem:
min(0.5*(x-x_origin)'*A*(x-x_origin)+b'*(x-x_origin))
INPUT PARAMETERS:
State - structure which stores algorithm state
XOrigin - origin, array[N].
-- ALGLIB --
Copyright 11.01.2011 by Bochkanov Sergey
*************************************************************************/
</div><div style='margin-top: 0; margin-bottom: 0;'><b>void</b> alglib::minqpsetorigin(minqpstate state, real_1d_array xorigin);
</div></pre>
<a name='sub_minqpsetquadraticterm'></a><h3 class=pageheader><code>minqpsetquadraticterm</code> function</h3>
<pre class=source>
<div style='color: navy; margin-top: 0; margin-bottom: 0;'>/*************************************************************************
This function sets dense quadratic term for QP solver. By default,
quadratic term is zero.
SUPPORT BY ALGLIB QP ALGORITHMS:
Dense quadratic term can be handled by any of the QP algorithms supported
by ALGLIB QP Solver.
IMPORTANT:
This solver minimizes following function:
f(x) = 0.5*x'*A*x + b'*x.
Note that quadratic term has 0.5 before it. So if you want to minimize
f(x) = x^2 + x
you should rewrite your problem as follows:
f(x) = 0.5*(2*x^2) + x
and your matrix A will be equal to [[2.0]], not to [[1.0]]
INPUT PARAMETERS:
State - structure which stores algorithm state
A - matrix, array[N,N]
IsUpper - (optional) storage type:
* if True, symmetric matrix A is given by its upper
triangle, and the lower triangle isn�t used
* if False, symmetric matrix A is given by its lower
triangle, and the upper triangle isn�t used
* if not given, both lower and upper triangles must be
filled.
-- ALGLIB --
Copyright 11.01.2011 by Bochkanov Sergey
*************************************************************************/
</div><div style='margin-top: 0; margin-bottom: 0;'><b>void</b> alglib::minqpsetquadraticterm(minqpstate state, real_2d_array a);
<b>void</b> alglib::minqpsetquadraticterm(
minqpstate state,
real_2d_array a,
<b>bool</b> isupper);
</div></pre>
<p align=left class=pagecontent><span class=inlineheader>Examples:</span> <a href='#example_minqp_d_u1' class=nav>[1]</a> <a href='#example_minqp_d_bc1' class=nav>[2]</a> <a href='#example_minqp_d_lc1' class=nav>[3]</a> <a href='#example_minqp_d_nonconvex' class=nav>[4]</a> </p>
<a name='sub_minqpsetquadratictermsparse'></a><h3 class=pageheader><code>minqpsetquadratictermsparse</code> function</h3>
<pre class=source>
<div style='color: navy; margin-top: 0; margin-bottom: 0;'>/*************************************************************************
This function sets sparse quadratic term for QP solver. By default,
quadratic term is zero.
IMPORTANT:
This solver minimizes following function:
f(x) = 0.5*x'*A*x + b'*x.
Note that quadratic term has 0.5 before it. So if you want to minimize
f(x) = x^2 + x
you should rewrite your problem as follows:
f(x) = 0.5*(2*x^2) + x
and your matrix A will be equal to [[2.0]], not to [[1.0]]
INPUT PARAMETERS:
State - structure which stores algorithm state
A - matrix, array[N,N]
IsUpper - (optional) storage type:
* if True, symmetric matrix A is given by its upper
triangle, and the lower triangle isn�t used
* if False, symmetric matrix A is given by its lower
triangle, and the upper triangle isn�t used
* if not given, both lower and upper triangles must be
filled.
-- ALGLIB --
Copyright 11.01.2011 by Bochkanov Sergey
*************************************************************************/
</div><div style='margin-top: 0; margin-bottom: 0;'><b>void</b> alglib::minqpsetquadratictermsparse(
minqpstate state,
sparsematrix a,
<b>bool</b> isupper);
</div></pre>
<p align=left class=pagecontent><span class=inlineheader>Examples:</span> <a href='#example_minqp_d_u2' class=nav>[1]</a> </p>
<a name='sub_minqpsetscale'></a><h3 class=pageheader><code>minqpsetscale</code> function</h3>
<pre class=source>
<div style='color: navy; margin-top: 0; margin-bottom: 0;'>/*************************************************************************
This function sets scaling coefficients.
ALGLIB optimizers use scaling matrices to test stopping conditions (step
size and gradient are scaled before comparison with tolerances). Scale of
the I-th variable is a translation invariant measure of:
a) "how large" the variable is
b) how large the step should be to make significant changes in the function
BLEIC-based QP solver uses scale for two purposes:
* to evaluate stopping conditions
* for preconditioning of the underlying BLEIC solver
INPUT PARAMETERS:
State - structure stores algorithm state
S - array[N], non-zero scaling coefficients
S[i] may be negative, sign doesn't matter.
-- ALGLIB --
Copyright 14.01.2011 by Bochkanov Sergey
*************************************************************************/
</div><div style='margin-top: 0; margin-bottom: 0;'><b>void</b> alglib::minqpsetscale(minqpstate state, real_1d_array s);
</div></pre>
<a name='sub_minqpsetstartingpoint'></a><h3 class=pageheader><code>minqpsetstartingpoint</code> function</h3>
<pre class=source>
<div style='color: navy; margin-top: 0; margin-bottom: 0;'>/*************************************************************************
This function sets starting point for QP solver. It is useful to have
good initial approximation to the solution, because it will increase
speed of convergence and identification of active constraints.
INPUT PARAMETERS:
State - structure which stores algorithm state
X - starting point, array[N].
-- ALGLIB --
Copyright 11.01.2011 by Bochkanov Sergey
*************************************************************************/
</div><div style='margin-top: 0; margin-bottom: 0;'><b>void</b> alglib::minqpsetstartingpoint(minqpstate state, real_1d_array x);
</div></pre>
<p align=left class=pagecontent><span class=inlineheader>Examples:</span> <a href='#example_minqp_d_u1' class=nav>[1]</a> <a href='#example_minqp_d_bc1' class=nav>[2]</a> <a href='#example_minqp_d_lc1' class=nav>[3]</a> <a href='#example_minqp_d_u2' class=nav>[4]</a> <a href='#example_minqp_d_nonconvex' class=nav>[5]</a> </p>
<a name='example_minqp_d_bc1'></a><h3 class=pageheader>minqp_d_bc1 example</h3>
<pre class=source>
#include <font color=blue><b>"stdafx.h"</b></font>
#include <stdlib.h>
#include <stdio.h>
#include <math.h>
#include <font color=blue><b>"optimization.h"</b></font>
using namespace alglib;
<b>int</b> main(<b>int</b> argc, char **argv)
{
<font color=navy>//</font>
<font color=navy>// This example demonstrates minimization of F(x0,x1) = x0^2 + x1^2 -6*x0 - 4*x1</font>
<font color=navy>// subject to bound constraints 0<=x0<=2.5, 0<=x1<=2.5</font>
<font color=navy>//</font>
<font color=navy>// Exact solution is [x0,x1] = [2.5,2]</font>
<font color=navy>//</font>
<font color=navy>// We provide algorithm with starting point. With such small problem good starting</font>
<font color=navy>// point is not really necessary, but with high-dimensional problem it can save us</font>
<font color=navy>// a lot of time.</font>
<font color=navy>//</font>
<font color=navy>// IMPORTANT: this solver minimizes following function:</font>
<font color=navy>// f(x) = 0.5*x'*A*x + b'*x.</font>
<font color=navy>// Note that quadratic term has 0.5 before it. So <b>if</b> you want to minimize</font>
<font color=navy>// quadratic function, you should rewrite it in such way that quadratic term</font>
<font color=navy>// is multiplied by 0.5 too.</font>
<font color=navy>// For example, our function is f(x)=x0^2+x1^2+..., but we rewrite it as </font>
<font color=navy>// f(x) = 0.5*(2*x0^2+2*x1^2) + ....</font>
<font color=navy>// and pass diag(2,2) as quadratic term - NOT diag(1,1)!</font>
<font color=navy>//</font>
real_2d_array a = <font color=blue><b>"[[2,0],[0,2]]"</b></font>;
real_1d_array b = <font color=blue><b>"[-6,-4]"</b></font>;
real_1d_array x0 = <font color=blue><b>"[0,1]"</b></font>;
real_1d_array s = <font color=blue><b>"[1,1]"</b></font>;
real_1d_array bndl = <font color=blue><b>"[0.0,0.0]"</b></font>;
real_1d_array bndu = <font color=blue><b>"[2.5,2.5]"</b></font>;
real_1d_array x;
minqpstate state;
minqpreport rep;
<font color=navy>// create solver, set quadratic/linear terms</font>
minqpcreate(2, state);
minqpsetquadraticterm(state, a);
minqpsetlinearterm(state, b);
minqpsetstartingpoint(state, x0);
minqpsetbc(state, bndl, bndu);
<font color=navy>// Set scale of the parameters.</font>
<font color=navy>// It is strongly recommended that you set scale of your variables.</font>
<font color=navy>// Knowing their scales is essential <b>for</b> evaluation of stopping criteria</font>
<font color=navy>// and <b>for</b> preconditioning of the algorithm steps.</font>
<font color=navy>// You can find more information on scaling at http://www.alglib.net/optimization/scaling.php</font>
minqpsetscale(state, s);
<font color=navy>// solve problem with QuickQP solver, default stopping criteria are used</font>
minqpsetalgoquickqp(state, 0.0, 0.0, 0.0, 0, true);
minqpoptimize(state);
minqpresults(state, x, rep);
printf(<font color=blue><b>"%d\n"</b></font>, <b>int</b>(rep.terminationtype)); <font color=navy>// EXPECTED: 4</font>
printf(<font color=blue><b>"%s\n"</b></font>, x.tostring(2).c_str()); <font color=navy>// EXPECTED: [2.5,2]</font>
<font color=navy>// solve problem with BLEIC-based QP solver</font>
<font color=navy>// default stopping criteria are used.</font>
minqpsetalgobleic(state, 0.0, 0.0, 0.0, 0);
minqpoptimize(state);
minqpresults(state, x, rep);
printf(<font color=blue><b>"%s\n"</b></font>, x.tostring(2).c_str()); <font color=navy>// EXPECTED: [2.5,2]</font>
<b>return</b> 0;
}
</pre><a name='example_minqp_d_lc1'></a><h3 class=pageheader>minqp_d_lc1 example</h3>
<pre class=source>
#include <font color=blue><b>"stdafx.h"</b></font>
#include <stdlib.h>
#include <stdio.h>
#include <math.h>
#include <font color=blue><b>"optimization.h"</b></font>
using namespace alglib;
<b>int</b> main(<b>int</b> argc, char **argv)
{
<font color=navy>//</font>
<font color=navy>// This example demonstrates minimization of F(x0,x1) = x0^2 + x1^2 -6*x0 - 4*x1</font>
<font color=navy>// subject to linear constraint x0+x1<=2</font>
<font color=navy>//</font>
<font color=navy>// Exact solution is [x0,x1] = [1.5,0.5]</font>
<font color=navy>//</font>
<font color=navy>// IMPORTANT: this solver minimizes following function:</font>
<font color=navy>// f(x) = 0.5*x'*A*x + b'*x.</font>
<font color=navy>// Note that quadratic term has 0.5 before it. So <b>if</b> you want to minimize</font>
<font color=navy>// quadratic function, you should rewrite it in such way that quadratic term</font>
<font color=navy>// is multiplied by 0.5 too.</font>
<font color=navy>// For example, our function is f(x)=x0^2+x1^2+..., but we rewrite it as </font>
<font color=navy>// f(x) = 0.5*(2*x0^2+2*x1^2) + ....</font>
<font color=navy>// and pass diag(2,2) as quadratic term - NOT diag(1,1)!</font>
<font color=navy>//</font>
real_2d_array a = <font color=blue><b>"[[2,0],[0,2]]"</b></font>;
real_1d_array b = <font color=blue><b>"[-6,-4]"</b></font>;
real_1d_array s = <font color=blue><b>"[1,1]"</b></font>;
real_2d_array c = <font color=blue><b>"[[1.0,1.0,2.0]]"</b></font>;
integer_1d_array ct = <font color=blue><b>"[-1]"</b></font>;
real_1d_array x;
minqpstate state;
minqpreport rep;
<font color=navy>// create solver, set quadratic/linear terms</font>
minqpcreate(2, state);
minqpsetquadraticterm(state, a);
minqpsetlinearterm(state, b);
minqpsetlc(state, c, ct);
<font color=navy>// Set scale of the parameters.</font>
<font color=navy>// It is strongly recommended that you set scale of your variables.</font>
<font color=navy>// Knowing their scales is essential <b>for</b> evaluation of stopping criteria</font>
<font color=navy>// and <b>for</b> preconditioning of the algorithm steps.</font>
<font color=navy>// You can find more information on scaling at http://www.alglib.net/optimization/scaling.php</font>
minqpsetscale(state, s);
<font color=navy>// solve problem with BLEIC-based QP solver</font>
<font color=navy>// default stopping criteria are used.</font>
minqpsetalgobleic(state, 0.0, 0.0, 0.0, 0);
minqpoptimize(state);
minqpresults(state, x, rep);
printf(<font color=blue><b>"%s\n"</b></font>, x.tostring(1).c_str()); <font color=navy>// EXPECTED: [1.500,0.500]</font>
<font color=navy>// solve problem with QuickQP solver, default stopping criteria are used</font>
<font color=navy>// Oops! It does not support general linear constraints, -5 returned as completion code!</font>
minqpsetalgoquickqp(state, 0.0, 0.0, 0.0, 0, true);
minqpoptimize(state);
minqpresults(state, x, rep);
printf(<font color=blue><b>"%d\n"</b></font>, <b>int</b>(rep.terminationtype)); <font color=navy>// EXPECTED: -5</font>
<b>return</b> 0;
}
</pre><a name='example_minqp_d_nonconvex'></a><h3 class=pageheader>minqp_d_nonconvex example</h3>
<pre class=source>
#include <font color=blue><b>"stdafx.h"</b></font>
#include <stdlib.h>
#include <stdio.h>
#include <math.h>
#include <font color=blue><b>"optimization.h"</b></font>
using namespace alglib;
<b>int</b> main(<b>int</b> argc, char **argv)
{
<font color=navy>//</font>
<font color=navy>// This example demonstrates minimization of nonconvex function</font>
<font color=navy>// F(x0,x1) = -(x0^2+x1^2)</font>
<font color=navy>// subject to constraints x0,x1 in [1.0,2.0]</font>
<font color=navy>// Exact solution is [x0,x1] = [2,2].</font>
<font color=navy>//</font>
<font color=navy>// IMPORTANT: this solver minimizes following function:</font>
<font color=navy>// f(x) = 0.5*x'*A*x + b'*x.</font>
<font color=navy>// Note that quadratic term has 0.5 before it. So <b>if</b> you want to minimize</font>
<font color=navy>// quadratic function, you should rewrite it in such way that quadratic term</font>
<font color=navy>// is multiplied by 0.5 too.</font>
<font color=navy>//</font>
<font color=navy>// For example, our function is f(x)=-(x0^2+x1^2), but we rewrite it as </font>
<font color=navy>// f(x) = 0.5*(-2*x0^2-2*x1^2)</font>
<font color=navy>// and pass diag(-2,-2) as quadratic term - NOT diag(-1,-1)!</font>
<font color=navy>//</font>
real_2d_array a = <font color=blue><b>"[[-2,0],[0,-2]]"</b></font>;
real_1d_array x0 = <font color=blue><b>"[1,1]"</b></font>;
real_1d_array s = <font color=blue><b>"[1,1]"</b></font>;
real_1d_array bndl = <font color=blue><b>"[1.0,1.0]"</b></font>;
real_1d_array bndu = <font color=blue><b>"[2.0,2.0]"</b></font>;
real_1d_array x;
minqpstate state;
minqpreport rep;
<font color=navy>// create solver, set quadratic/linear terms, constraints</font>
minqpcreate(2, state);
minqpsetquadraticterm(state, a);
minqpsetstartingpoint(state, x0);
minqpsetbc(state, bndl, bndu);
<font color=navy>// Set scale of the parameters.</font>
<font color=navy>// It is strongly recommended that you set scale of your variables.</font>
<font color=navy>// Knowing their scales is essential <b>for</b> evaluation of stopping criteria</font>
<font color=navy>// and <b>for</b> preconditioning of the algorithm steps.</font>
<font color=navy>// You can find more information on scaling at http://www.alglib.net/optimization/scaling.php</font>
minqpsetscale(state, s);
<font color=navy>// solve problem with BLEIC-QP solver.</font>
<font color=navy>// default stopping criteria are used.</font>
minqpsetalgobleic(state, 0.0, 0.0, 0.0, 0);
minqpoptimize(state);
minqpresults(state, x, rep);
printf(<font color=blue><b>"%s\n"</b></font>, x.tostring(2).c_str()); <font color=navy>// EXPECTED: [2,2]</font>
<font color=navy>// Hmm... this problem is bounded from below (has solution) only under constraints.</font>
<font color=navy>// What it we remove them?</font>
<font color=navy>//</font>
<font color=navy>// You may see that algorithm detects unboundedness of the problem, </font>
<font color=navy>// -4 is returned as completion code.</font>
real_1d_array nobndl = <font color=blue><b>"[-inf,-inf]"</b></font>;
real_1d_array nobndu = <font color=blue><b>"[+inf,+inf]"</b></font>;
minqpsetbc(state, nobndl, nobndu);
minqpsetalgobleic(state, 0.0, 0.0, 0.0, 0);
minqpoptimize(state);
minqpresults(state, x, rep);
printf(<font color=blue><b>"%d\n"</b></font>, <b>int</b>(rep.terminationtype)); <font color=navy>// EXPECTED: -4</font>
<b>return</b> 0;
}
</pre><a name='example_minqp_d_u1'></a><h3 class=pageheader>minqp_d_u1 example</h3>
<pre class=source>
#include <font color=blue><b>"stdafx.h"</b></font>
#include <stdlib.h>
#include <stdio.h>
#include <math.h>
#include <font color=blue><b>"optimization.h"</b></font>
using namespace alglib;
<b>int</b> main(<b>int</b> argc, char **argv)
{
<font color=navy>//</font>
<font color=navy>// This example demonstrates minimization of F(x0,x1) = x0^2 + x1^2 -6*x0 - 4*x1</font>
<font color=navy>//</font>
<font color=navy>// Exact solution is [x0,x1] = [3,2]</font>
<font color=navy>//</font>
<font color=navy>// We provide algorithm with starting point, although in this case</font>
<font color=navy>// (dense matrix, no constraints) it can work without such information.</font>
<font color=navy>//</font>
<font color=navy>// IMPORTANT: this solver minimizes following function:</font>
<font color=navy>// f(x) = 0.5*x'*A*x + b'*x.</font>
<font color=navy>// Note that quadratic term has 0.5 before it. So <b>if</b> you want to minimize</font>
<font color=navy>// quadratic function, you should rewrite it in such way that quadratic term</font>
<font color=navy>// is multiplied by 0.5 too.</font>
<font color=navy>//</font>
<font color=navy>// For example, our function is f(x)=x0^2+x1^2+..., but we rewrite it as </font>
<font color=navy>// f(x) = 0.5*(2*x0^2+2*x1^2) + ....</font>
<font color=navy>// and pass diag(2,2) as quadratic term - NOT diag(1,1)!</font>
<font color=navy>//</font>
real_2d_array a = <font color=blue><b>"[[2,0],[0,2]]"</b></font>;
real_1d_array b = <font color=blue><b>"[-6,-4]"</b></font>;
real_1d_array x0 = <font color=blue><b>"[0,1]"</b></font>;
real_1d_array s = <font color=blue><b>"[1,1]"</b></font>;
real_1d_array x;
minqpstate state;
minqpreport rep;
<font color=navy>// create solver, set quadratic/linear terms</font>
minqpcreate(2, state);
minqpsetquadraticterm(state, a);
minqpsetlinearterm(state, b);
minqpsetstartingpoint(state, x0);
<font color=navy>// Set scale of the parameters.</font>
<font color=navy>// It is strongly recommended that you set scale of your variables.</font>
<font color=navy>// Knowing their scales is essential <b>for</b> evaluation of stopping criteria</font>
<font color=navy>// and <b>for</b> preconditioning of the algorithm steps.</font>
<font color=navy>// You can find more information on scaling at http://www.alglib.net/optimization/scaling.php</font>
minqpsetscale(state, s);
<font color=navy>// solve problem with QuickQP solver, default stopping criteria are used, Newton phase is active</font>
minqpsetalgoquickqp(state, 0.0, 0.0, 0.0, 0, true);
minqpoptimize(state);
minqpresults(state, x, rep);
printf(<font color=blue><b>"%d\n"</b></font>, <b>int</b>(rep.terminationtype)); <font color=navy>// EXPECTED: 4</font>
printf(<font color=blue><b>"%s\n"</b></font>, x.tostring(2).c_str()); <font color=navy>// EXPECTED: [3,2]</font>
<font color=navy>// solve problem with BLEIC-based QP solver.</font>
<font color=navy>// default stopping criteria are used.</font>
minqpsetalgobleic(state, 0.0, 0.0, 0.0, 0);
minqpoptimize(state);
minqpresults(state, x, rep);
printf(<font color=blue><b>"%s\n"</b></font>, x.tostring(2).c_str()); <font color=navy>// EXPECTED: [3,2]</font>
<b>return</b> 0;
}
</pre><a name='example_minqp_d_u2'></a><h3 class=pageheader>minqp_d_u2 example</h3>
<pre class=source>
#include <font color=blue><b>"stdafx.h"</b></font>
#include <stdlib.h>
#include <stdio.h>
#include <math.h>
#include <font color=blue><b>"optimization.h"</b></font>
using namespace alglib;
<b>int</b> main(<b>int</b> argc, char **argv)
{
<font color=navy>//</font>
<font color=navy>// This example demonstrates minimization of F(x0,x1) = x0^2 + x1^2 -6*x0 - 4*x1,</font>
<font color=navy>// with quadratic term given by sparse matrix structure.</font>
<font color=navy>//</font>
<font color=navy>// Exact solution is [x0,x1] = [3,2]</font>
<font color=navy>//</font>
<font color=navy>// We provide algorithm with starting point, although in this case</font>
<font color=navy>// (dense matrix, no constraints) it can work without such information.</font>
<font color=navy>//</font>
<font color=navy>// IMPORTANT: this solver minimizes following function:</font>
<font color=navy>// f(x) = 0.5*x'*A*x + b'*x.</font>
<font color=navy>// Note that quadratic term has 0.5 before it. So <b>if</b> you want to minimize</font>
<font color=navy>// quadratic function, you should rewrite it in such way that quadratic term</font>
<font color=navy>// is multiplied by 0.5 too.</font>
<font color=navy>//</font>
<font color=navy>// For example, our function is f(x)=x0^2+x1^2+..., but we rewrite it as </font>
<font color=navy>// f(x) = 0.5*(2*x0^2+2*x1^2) + ....</font>
<font color=navy>// and pass diag(2,2) as quadratic term - NOT diag(1,1)!</font>
<font color=navy>//</font>
sparsematrix a;
real_1d_array b = <font color=blue><b>"[-6,-4]"</b></font>;
real_1d_array x0 = <font color=blue><b>"[0,1]"</b></font>;
real_1d_array s = <font color=blue><b>"[1,1]"</b></font>;
real_1d_array x;
minqpstate state;
minqpreport rep;
<font color=navy>// initialize sparsematrix structure</font>
sparsecreate(2, 2, 0, a);
sparseset(a, 0, 0, 2.0);
sparseset(a, 1, 1, 2.0);
<font color=navy>// create solver, set quadratic/linear terms</font>
minqpcreate(2, state);
minqpsetquadratictermsparse(state, a, true);
minqpsetlinearterm(state, b);
minqpsetstartingpoint(state, x0);
<font color=navy>// Set scale of the parameters.</font>
<font color=navy>// It is strongly recommended that you set scale of your variables.</font>
<font color=navy>// Knowing their scales is essential <b>for</b> evaluation of stopping criteria</font>
<font color=navy>// and <b>for</b> preconditioning of the algorithm steps.</font>
<font color=navy>// You can find more information on scaling at http://www.alglib.net/optimization/scaling.php</font>
minqpsetscale(state, s);
<font color=navy>// solve problem with BLEIC-based QP solver.</font>
<font color=navy>// default stopping criteria are used.</font>
minqpsetalgobleic(state, 0.0, 0.0, 0.0, 0);
minqpoptimize(state);
minqpresults(state, x, rep);
printf(<font color=blue><b>"%s\n"</b></font>, x.tostring(2).c_str()); <font color=navy>// EXPECTED: [3,2]</font>
<font color=navy>// try to solve problem with Cholesky-based QP solver...</font>
<font color=navy>// Oops! It does not support sparse matrices, -5 returned as completion code!</font>
minqpsetalgocholesky(state);
minqpoptimize(state);
minqpresults(state, x, rep);
printf(<font color=blue><b>"%d\n"</b></font>, <b>int</b>(rep.terminationtype)); <font color=navy>// EXPECTED: -5</font>
<b>return</b> 0;
}
</pre><a name=unit_mlpbase></a><h2 class=pageheader><code>mlpbase</code> subpackage</h2>
<div class=pagecontent>
<h3 class=pageheader>Classes</h3>
<a href='#struct_modelerrors' class=toc>modelerrors</a><br>
<a href='#struct_multilayerperceptron' class=toc>multilayerperceptron</a><br>
<h3 class=pageheader>Functions</h3>
<a href='#sub_mlpactivationfunction' class=toc>mlpactivationfunction</a><br>
<a href='#sub_mlpallerrorssparsesubset' class=toc>mlpallerrorssparsesubset</a><br>
<a href='#sub_mlpallerrorssubset' class=toc>mlpallerrorssubset</a><br>
<a href='#sub_mlpavgce' class=toc>mlpavgce</a><br>
<a href='#sub_mlpavgcesparse' class=toc>mlpavgcesparse</a><br>
<a href='#sub_mlpavgerror' class=toc>mlpavgerror</a><br>
<a href='#sub_mlpavgerrorsparse' class=toc>mlpavgerrorsparse</a><br>
<a href='#sub_mlpavgrelerror' class=toc>mlpavgrelerror</a><br>
<a href='#sub_mlpavgrelerrorsparse' class=toc>mlpavgrelerrorsparse</a><br>
<a href='#sub_mlpclserror' class=toc>mlpclserror</a><br>
<a href='#sub_mlpcopy' class=toc>mlpcopy</a><br>
<a href='#sub_mlpcopytunableparameters' class=toc>mlpcopytunableparameters</a><br>
<a href='#sub_mlpcreate0' class=toc>mlpcreate0</a><br>
<a href='#sub_mlpcreate1' class=toc>mlpcreate1</a><br>
<a href='#sub_mlpcreate2' class=toc>mlpcreate2</a><br>
<a href='#sub_mlpcreateb0' class=toc>mlpcreateb0</a><br>
<a href='#sub_mlpcreateb1' class=toc>mlpcreateb1</a><br>
<a href='#sub_mlpcreateb2' class=toc>mlpcreateb2</a><br>
<a href='#sub_mlpcreatec0' class=toc>mlpcreatec0</a><br>
<a href='#sub_mlpcreatec1' class=toc>mlpcreatec1</a><br>
<a href='#sub_mlpcreatec2' class=toc>mlpcreatec2</a><br>
<a href='#sub_mlpcreater0' class=toc>mlpcreater0</a><br>
<a href='#sub_mlpcreater1' class=toc>mlpcreater1</a><br>
<a href='#sub_mlpcreater2' class=toc>mlpcreater2</a><br>
<a href='#sub_mlperror' class=toc>mlperror</a><br>
<a href='#sub_mlperrorn' class=toc>mlperrorn</a><br>
<a href='#sub_mlperrorsparse' class=toc>mlperrorsparse</a><br>
<a href='#sub_mlperrorsparsesubset' class=toc>mlperrorsparsesubset</a><br>
<a href='#sub_mlperrorsubset' class=toc>mlperrorsubset</a><br>
<a href='#sub_mlpgetinputscaling' class=toc>mlpgetinputscaling</a><br>
<a href='#sub_mlpgetinputscount' class=toc>mlpgetinputscount</a><br>
<a href='#sub_mlpgetlayerscount' class=toc>mlpgetlayerscount</a><br>
<a href='#sub_mlpgetlayersize' class=toc>mlpgetlayersize</a><br>
<a href='#sub_mlpgetneuroninfo' class=toc>mlpgetneuroninfo</a><br>
<a href='#sub_mlpgetoutputscaling' class=toc>mlpgetoutputscaling</a><br>
<a href='#sub_mlpgetoutputscount' class=toc>mlpgetoutputscount</a><br>
<a href='#sub_mlpgetweight' class=toc>mlpgetweight</a><br>
<a href='#sub_mlpgetweightscount' class=toc>mlpgetweightscount</a><br>
<a href='#sub_mlpgrad' class=toc>mlpgrad</a><br>
<a href='#sub_mlpgradbatch' class=toc>mlpgradbatch</a><br>
<a href='#sub_mlpgradbatchsparse' class=toc>mlpgradbatchsparse</a><br>
<a href='#sub_mlpgradbatchsparsesubset' class=toc>mlpgradbatchsparsesubset</a><br>
<a href='#sub_mlpgradbatchsubset' class=toc>mlpgradbatchsubset</a><br>
<a href='#sub_mlpgradn' class=toc>mlpgradn</a><br>
<a href='#sub_mlpgradnbatch' class=toc>mlpgradnbatch</a><br>
<a href='#sub_mlphessianbatch' class=toc>mlphessianbatch</a><br>
<a href='#sub_mlphessiannbatch' class=toc>mlphessiannbatch</a><br>
<a href='#sub_mlpinitpreprocessor' class=toc>mlpinitpreprocessor</a><br>
<a href='#sub_mlpissoftmax' class=toc>mlpissoftmax</a><br>
<a href='#sub_mlpprocess' class=toc>mlpprocess</a><br>
<a href='#sub_mlpprocessi' class=toc>mlpprocessi</a><br>
<a href='#sub_mlpproperties' class=toc>mlpproperties</a><br>
<a href='#sub_mlprandomize' class=toc>mlprandomize</a><br>
<a href='#sub_mlprandomizefull' class=toc>mlprandomizefull</a><br>
<a href='#sub_mlprelclserror' class=toc>mlprelclserror</a><br>
<a href='#sub_mlprelclserrorsparse' class=toc>mlprelclserrorsparse</a><br>
<a href='#sub_mlprmserror' class=toc>mlprmserror</a><br>
<a href='#sub_mlprmserrorsparse' class=toc>mlprmserrorsparse</a><br>
<a href='#sub_mlpserialize' class=toc>mlpserialize</a><br>
<a href='#sub_mlpsetinputscaling' class=toc>mlpsetinputscaling</a><br>
<a href='#sub_mlpsetneuroninfo' class=toc>mlpsetneuroninfo</a><br>
<a href='#sub_mlpsetoutputscaling' class=toc>mlpsetoutputscaling</a><br>
<a href='#sub_mlpsetweight' class=toc>mlpsetweight</a><br>
<a href='#sub_mlpunserialize' class=toc>mlpunserialize</a><br>
<h3 class=pageheader>Examples</h3>
<table border=0 cellspacing=0 class='pagecontent'>
</table></div>
<a name='struct_modelerrors'></a><h3 class=pageheader><code>modelerrors</code> class</h3>
<pre class=source>
<div style='color: navy; margin-top: 0; margin-bottom: 0;'>/*************************************************************************
Model's errors:
* RelCLSError - fraction of misclassified cases.
* AvgCE - acerage cross-entropy
* RMSError - root-mean-square error
* AvgError - average error
* AvgRelError - average relative error
NOTE 1: RelCLSError/AvgCE are zero on regression problems.
NOTE 2: on classification problems RMSError/AvgError/AvgRelError contain
errors in prediction of posterior probabilities
*************************************************************************/
</div><div style='margin-top: 0; margin-bottom: 0;'><b>class</b> modelerrors
{
<b>double</b> relclserror;
<b>double</b> avgce;
<b>double</b> rmserror;
<b>double</b> avgerror;
<b>double</b> avgrelerror;
};
</div></pre>
<a name='struct_multilayerperceptron'></a><h3 class=pageheader><code>multilayerperceptron</code> class</h3>
<pre class=source>
<div style='color: navy; margin-top: 0; margin-bottom: 0;'>/*************************************************************************
*************************************************************************/
</div><div style='margin-top: 0; margin-bottom: 0;'><b>class</b> multilayerperceptron
{
};
</div></pre>
<a name='sub_mlpactivationfunction'></a><h3 class=pageheader><code>mlpactivationfunction</code> function</h3>
<pre class=source>
<div style='color: navy; margin-top: 0; margin-bottom: 0;'>/*************************************************************************
Neural network activation function
INPUT PARAMETERS:
NET - neuron input
K - function index (zero for linear function)
OUTPUT PARAMETERS:
F - function
DF - its derivative
D2F - its second derivative
-- ALGLIB --
Copyright 04.11.2007 by Bochkanov Sergey
*************************************************************************/
</div><div style='margin-top: 0; margin-bottom: 0;'><b>void</b> alglib::mlpactivationfunction(
<b>double</b> net,
ae_int_t k,
<b>double</b>& f,
<b>double</b>& df,
<b>double</b>& d2f);
</div></pre>
<a name='sub_mlpallerrorssparsesubset'></a><h3 class=pageheader><code>mlpallerrorssparsesubset</code> function</h3>
<pre class=source>
<div style='color: navy; margin-top: 0; margin-bottom: 0;'>/*************************************************************************
Calculation of all types of errors on subset of dataset.
FOR USERS OF COMMERCIAL EDITION:
! Commercial version of ALGLIB includes two important improvements of
! this function:
! * multicore support (C++ and C# computational cores)
! * SSE support
!
! First improvement gives close-to-linear speedup on multicore systems.
! Second improvement gives constant speedup (2-3x depending on your CPU)
!
! In order to use multicore features you have to:
! * use commercial version of ALGLIB
! * call this function with "smp_" prefix, which indicates that
! multicore code will be used (for multicore support)
!
! In order to use SSE features you have to:
! * use commercial version of ALGLIB on Intel processors
! * use C++ computational core
!
! This note is given for users of commercial edition; if you use GPL
! edition, you still will be able to call smp-version of this function,
! but all computations will be done serially.
!
! We recommend you to carefully read ALGLIB Reference Manual, section
! called 'SMP support', before using parallel version of this function.
INPUT PARAMETERS:
Network - network initialized with one of the network creation funcs
XY - original dataset given by sparse matrix;
one sample = one row;
first NIn columns contain inputs,
next NOut columns - desired outputs.
SetSize - real size of XY, SetSize>=0;
Subset - subset of SubsetSize elements, array[SubsetSize];
SubsetSize- number of elements in Subset[] array:
* if SubsetSize>0, rows of XY with indices Subset[0]...
...Subset[SubsetSize-1] are processed
* if SubsetSize=0, zeros are returned
* if SubsetSize<0, entire dataset is processed; Subset[]
array is ignored in this case.
OUTPUT PARAMETERS:
Rep - it contains all type of errors.
-- ALGLIB --
Copyright 04.09.2012 by Bochkanov Sergey
*************************************************************************/
</div><div style='margin-top: 0; margin-bottom: 0;'><b>void</b> alglib::mlpallerrorssparsesubset(
multilayerperceptron network,
sparsematrix xy,
ae_int_t setsize,
integer_1d_array subset,
ae_int_t subsetsize,
modelerrors& rep);
<b>void</b> alglib::smp_mlpallerrorssparsesubset(
multilayerperceptron network,
sparsematrix xy,
ae_int_t setsize,
integer_1d_array subset,
ae_int_t subsetsize,
modelerrors& rep);
</div></pre>
<a name='sub_mlpallerrorssubset'></a><h3 class=pageheader><code>mlpallerrorssubset</code> function</h3>
<pre class=source>
<div style='color: navy; margin-top: 0; margin-bottom: 0;'>/*************************************************************************
Calculation of all types of errors on subset of dataset.
FOR USERS OF COMMERCIAL EDITION:
! Commercial version of ALGLIB includes two important improvements of
! this function:
! * multicore support (C++ and C# computational cores)
! * SSE support
!
! First improvement gives close-to-linear speedup on multicore systems.
! Second improvement gives constant speedup (2-3x depending on your CPU)
!
! In order to use multicore features you have to:
! * use commercial version of ALGLIB
! * call this function with "smp_" prefix, which indicates that
! multicore code will be used (for multicore support)
!
! In order to use SSE features you have to:
! * use commercial version of ALGLIB on Intel processors
! * use C++ computational core
!
! This note is given for users of commercial edition; if you use GPL
! edition, you still will be able to call smp-version of this function,
! but all computations will be done serially.
!
! We recommend you to carefully read ALGLIB Reference Manual, section
! called 'SMP support', before using parallel version of this function.
INPUT PARAMETERS:
Network - network initialized with one of the network creation funcs
XY - original dataset; one sample = one row;
first NIn columns contain inputs,
next NOut columns - desired outputs.
SetSize - real size of XY, SetSize>=0;
Subset - subset of SubsetSize elements, array[SubsetSize];
SubsetSize- number of elements in Subset[] array:
* if SubsetSize>0, rows of XY with indices Subset[0]...
...Subset[SubsetSize-1] are processed
* if SubsetSize=0, zeros are returned
* if SubsetSize<0, entire dataset is processed; Subset[]
array is ignored in this case.
OUTPUT PARAMETERS:
Rep - it contains all type of errors.
-- ALGLIB --
Copyright 04.09.2012 by Bochkanov Sergey
*************************************************************************/
</div><div style='margin-top: 0; margin-bottom: 0;'><b>void</b> alglib::mlpallerrorssubset(
multilayerperceptron network,
real_2d_array xy,
ae_int_t setsize,
integer_1d_array subset,
ae_int_t subsetsize,
modelerrors& rep);
<b>void</b> alglib::smp_mlpallerrorssubset(
multilayerperceptron network,
real_2d_array xy,
ae_int_t setsize,
integer_1d_array subset,
ae_int_t subsetsize,
modelerrors& rep);
</div></pre>
<a name='sub_mlpavgce'></a><h3 class=pageheader><code>mlpavgce</code> function</h3>
<pre class=source>
<div style='color: navy; margin-top: 0; margin-bottom: 0;'>/*************************************************************************
Average cross-entropy (in bits per element) on the test set.
FOR USERS OF COMMERCIAL EDITION:
! Commercial version of ALGLIB includes two important improvements of
! this function:
! * multicore support (C++ and C# computational cores)
! * SSE support
!
! First improvement gives close-to-linear speedup on multicore systems.
! Second improvement gives constant speedup (2-3x depending on your CPU)
!
! In order to use multicore features you have to:
! * use commercial version of ALGLIB
! * call this function with "smp_" prefix, which indicates that
! multicore code will be used (for multicore support)
!
! In order to use SSE features you have to:
! * use commercial version of ALGLIB on Intel processors
! * use C++ computational core
!
! This note is given for users of commercial edition; if you use GPL
! edition, you still will be able to call smp-version of this function,
! but all computations will be done serially.
!
! We recommend you to carefully read ALGLIB Reference Manual, section
! called 'SMP support', before using parallel version of this function.
INPUT PARAMETERS:
Network - neural network;
XY - training set, see below for information on the
training set format;
NPoints - points count.
RESULT:
CrossEntropy/(NPoints*LN(2)).
Zero if network solves regression task.
DATASET FORMAT:
This function uses two different dataset formats - one for regression
networks, another one for classification networks.
For regression networks with NIn inputs and NOut outputs following dataset
format is used:
* dataset is given by NPoints*(NIn+NOut) matrix
* each row corresponds to one example
* first NIn columns are inputs, next NOut columns are outputs
For classification networks with NIn inputs and NClasses clases following
dataset format is used:
* dataset is given by NPoints*(NIn+1) matrix
* each row corresponds to one example
* first NIn columns are inputs, last column stores class number (from 0 to
NClasses-1).
-- ALGLIB --
Copyright 08.01.2009 by Bochkanov Sergey
*************************************************************************/
</div><div style='margin-top: 0; margin-bottom: 0;'><b>double</b> alglib::mlpavgce(
multilayerperceptron network,
real_2d_array xy,
ae_int_t npoints);
<b>double</b> alglib::smp_mlpavgce(
multilayerperceptron network,
real_2d_array xy,
ae_int_t npoints);
</div></pre>
<a name='sub_mlpavgcesparse'></a><h3 class=pageheader><code>mlpavgcesparse</code> function</h3>
<pre class=source>
<div style='color: navy; margin-top: 0; margin-bottom: 0;'>/*************************************************************************
Average cross-entropy (in bits per element) on the test set given by
sparse matrix.
FOR USERS OF COMMERCIAL EDITION:
! Commercial version of ALGLIB includes two important improvements of
! this function:
! * multicore support (C++ and C# computational cores)
! * SSE support
!
! First improvement gives close-to-linear speedup on multicore systems.
! Second improvement gives constant speedup (2-3x depending on your CPU)
!
! In order to use multicore features you have to:
! * use commercial version of ALGLIB
! * call this function with "smp_" prefix, which indicates that
! multicore code will be used (for multicore support)
!
! In order to use SSE features you have to:
! * use commercial version of ALGLIB on Intel processors
! * use C++ computational core
!
! This note is given for users of commercial edition; if you use GPL
! edition, you still will be able to call smp-version of this function,
! but all computations will be done serially.
!
! We recommend you to carefully read ALGLIB Reference Manual, section
! called 'SMP support', before using parallel version of this function.
INPUT PARAMETERS:
Network - neural network;
XY - training set, see below for information on the
training set format. This function checks correctness
of the dataset (no NANs/INFs, class numbers are
correct) and throws exception when incorrect dataset
is passed. Sparse matrix must use CRS format for
storage.
NPoints - points count, >=0.
RESULT:
CrossEntropy/(NPoints*LN(2)).
Zero if network solves regression task.
DATASET FORMAT:
This function uses two different dataset formats - one for regression
networks, another one for classification networks.
For regression networks with NIn inputs and NOut outputs following dataset
format is used:
* dataset is given by NPoints*(NIn+NOut) matrix
* each row corresponds to one example
* first NIn columns are inputs, next NOut columns are outputs
For classification networks with NIn inputs and NClasses clases following
dataset format is used:
* dataset is given by NPoints*(NIn+1) matrix
* each row corresponds to one example
* first NIn columns are inputs, last column stores class number (from 0 to
NClasses-1).
-- ALGLIB --
Copyright 9.08.2012 by Bochkanov Sergey
*************************************************************************/
</div><div style='margin-top: 0; margin-bottom: 0;'><b>double</b> alglib::mlpavgcesparse(
multilayerperceptron network,
sparsematrix xy,
ae_int_t npoints);
<b>double</b> alglib::smp_mlpavgcesparse(
multilayerperceptron network,
sparsematrix xy,
ae_int_t npoints);
</div></pre>
<a name='sub_mlpavgerror'></a><h3 class=pageheader><code>mlpavgerror</code> function</h3>
<pre class=source>
<div style='color: navy; margin-top: 0; margin-bottom: 0;'>/*************************************************************************
Average absolute error on the test set.
FOR USERS OF COMMERCIAL EDITION:
! Commercial version of ALGLIB includes two important improvements of
! this function:
! * multicore support (C++ and C# computational cores)
! * SSE support
!
! First improvement gives close-to-linear speedup on multicore systems.
! Second improvement gives constant speedup (2-3x depending on your CPU)
!
! In order to use multicore features you have to:
! * use commercial version of ALGLIB
! * call this function with "smp_" prefix, which indicates that
! multicore code will be used (for multicore support)
!
! In order to use SSE features you have to:
! * use commercial version of ALGLIB on Intel processors
! * use C++ computational core
!
! This note is given for users of commercial edition; if you use GPL
! edition, you still will be able to call smp-version of this function,
! but all computations will be done serially.
!
! We recommend you to carefully read ALGLIB Reference Manual, section
! called 'SMP support', before using parallel version of this function.
INPUT PARAMETERS:
Network - neural network;
XY - training set, see below for information on the
training set format;
NPoints - points count.
RESULT:
Its meaning for regression task is obvious. As for classification task, it
means average error when estimating posterior probabilities.
DATASET FORMAT:
This function uses two different dataset formats - one for regression
networks, another one for classification networks.
For regression networks with NIn inputs and NOut outputs following dataset
format is used:
* dataset is given by NPoints*(NIn+NOut) matrix
* each row corresponds to one example
* first NIn columns are inputs, next NOut columns are outputs
For classification networks with NIn inputs and NClasses clases following
dataset format is used:
* dataset is given by NPoints*(NIn+1) matrix
* each row corresponds to one example
* first NIn columns are inputs, last column stores class number (from 0 to
NClasses-1).
-- ALGLIB --
Copyright 11.03.2008 by Bochkanov Sergey
*************************************************************************/
</div><div style='margin-top: 0; margin-bottom: 0;'><b>double</b> alglib::mlpavgerror(
multilayerperceptron network,
real_2d_array xy,
ae_int_t npoints);
<b>double</b> alglib::smp_mlpavgerror(
multilayerperceptron network,
real_2d_array xy,
ae_int_t npoints);
</div></pre>
<a name='sub_mlpavgerrorsparse'></a><h3 class=pageheader><code>mlpavgerrorsparse</code> function</h3>
<pre class=source>
<div style='color: navy; margin-top: 0; margin-bottom: 0;'>/*************************************************************************
Average absolute error on the test set given by sparse matrix.
FOR USERS OF COMMERCIAL EDITION:
! Commercial version of ALGLIB includes two important improvements of
! this function:
! * multicore support (C++ and C# computational cores)
! * SSE support
!
! First improvement gives close-to-linear speedup on multicore systems.
! Second improvement gives constant speedup (2-3x depending on your CPU)
!
! In order to use multicore features you have to:
! * use commercial version of ALGLIB
! * call this function with "smp_" prefix, which indicates that
! multicore code will be used (for multicore support)
!
! In order to use SSE features you have to:
! * use commercial version of ALGLIB on Intel processors
! * use C++ computational core
!
! This note is given for users of commercial edition; if you use GPL
! edition, you still will be able to call smp-version of this function,
! but all computations will be done serially.
!
! We recommend you to carefully read ALGLIB Reference Manual, section
! called 'SMP support', before using parallel version of this function.
INPUT PARAMETERS:
Network - neural network;
XY - training set, see below for information on the
training set format. This function checks correctness
of the dataset (no NANs/INFs, class numbers are
correct) and throws exception when incorrect dataset
is passed. Sparse matrix must use CRS format for
storage.
NPoints - points count, >=0.
RESULT:
Its meaning for regression task is obvious. As for classification task, it
means average error when estimating posterior probabilities.
DATASET FORMAT:
This function uses two different dataset formats - one for regression
networks, another one for classification networks.
For regression networks with NIn inputs and NOut outputs following dataset
format is used:
* dataset is given by NPoints*(NIn+NOut) matrix
* each row corresponds to one example
* first NIn columns are inputs, next NOut columns are outputs
For classification networks with NIn inputs and NClasses clases following
dataset format is used:
* dataset is given by NPoints*(NIn+1) matrix
* each row corresponds to one example
* first NIn columns are inputs, last column stores class number (from 0 to
NClasses-1).
-- ALGLIB --
Copyright 09.08.2012 by Bochkanov Sergey
*************************************************************************/
</div><div style='margin-top: 0; margin-bottom: 0;'><b>double</b> alglib::mlpavgerrorsparse(
multilayerperceptron network,
sparsematrix xy,
ae_int_t npoints);
<b>double</b> alglib::smp_mlpavgerrorsparse(
multilayerperceptron network,
sparsematrix xy,
ae_int_t npoints);
</div></pre>
<a name='sub_mlpavgrelerror'></a><h3 class=pageheader><code>mlpavgrelerror</code> function</h3>
<pre class=source>
<div style='color: navy; margin-top: 0; margin-bottom: 0;'>/*************************************************************************
Average relative error on the test set.
FOR USERS OF COMMERCIAL EDITION:
! Commercial version of ALGLIB includes two important improvements of
! this function:
! * multicore support (C++ and C# computational cores)
! * SSE support
!
! First improvement gives close-to-linear speedup on multicore systems.
! Second improvement gives constant speedup (2-3x depending on your CPU)
!
! In order to use multicore features you have to:
! * use commercial version of ALGLIB
! * call this function with "smp_" prefix, which indicates that
! multicore code will be used (for multicore support)
!
! In order to use SSE features you have to:
! * use commercial version of ALGLIB on Intel processors
! * use C++ computational core
!
! This note is given for users of commercial edition; if you use GPL
! edition, you still will be able to call smp-version of this function,
! but all computations will be done serially.
!
! We recommend you to carefully read ALGLIB Reference Manual, section
! called 'SMP support', before using parallel version of this function.
INPUT PARAMETERS:
Network - neural network;
XY - training set, see below for information on the
training set format;
NPoints - points count.
RESULT:
Its meaning for regression task is obvious. As for classification task, it
means average relative error when estimating posterior probability of
belonging to the correct class.
DATASET FORMAT:
This function uses two different dataset formats - one for regression
networks, another one for classification networks.
For regression networks with NIn inputs and NOut outputs following dataset
format is used:
* dataset is given by NPoints*(NIn+NOut) matrix
* each row corresponds to one example
* first NIn columns are inputs, next NOut columns are outputs
For classification networks with NIn inputs and NClasses clases following
dataset format is used:
* dataset is given by NPoints*(NIn+1) matrix
* each row corresponds to one example
* first NIn columns are inputs, last column stores class number (from 0 to
NClasses-1).
-- ALGLIB --
Copyright 11.03.2008 by Bochkanov Sergey
*************************************************************************/
</div><div style='margin-top: 0; margin-bottom: 0;'><b>double</b> alglib::mlpavgrelerror(
multilayerperceptron network,
real_2d_array xy,
ae_int_t npoints);
<b>double</b> alglib::smp_mlpavgrelerror(
multilayerperceptron network,
real_2d_array xy,
ae_int_t npoints);
</div></pre>
<a name='sub_mlpavgrelerrorsparse'></a><h3 class=pageheader><code>mlpavgrelerrorsparse</code> function</h3>
<pre class=source>
<div style='color: navy; margin-top: 0; margin-bottom: 0;'>/*************************************************************************
Average relative error on the test set given by sparse matrix.
FOR USERS OF COMMERCIAL EDITION:
! Commercial version of ALGLIB includes two important improvements of
! this function:
! * multicore support (C++ and C# computational cores)
! * SSE support
!
! First improvement gives close-to-linear speedup on multicore systems.
! Second improvement gives constant speedup (2-3x depending on your CPU)
!
! In order to use multicore features you have to:
! * use commercial version of ALGLIB
! * call this function with "smp_" prefix, which indicates that
! multicore code will be used (for multicore support)
!
! In order to use SSE features you have to:
! * use commercial version of ALGLIB on Intel processors
! * use C++ computational core
!
! This note is given for users of commercial edition; if you use GPL
! edition, you still will be able to call smp-version of this function,
! but all computations will be done serially.
!
! We recommend you to carefully read ALGLIB Reference Manual, section
! called 'SMP support', before using parallel version of this function.
INPUT PARAMETERS:
Network - neural network;
XY - training set, see below for information on the
training set format. This function checks correctness
of the dataset (no NANs/INFs, class numbers are
correct) and throws exception when incorrect dataset
is passed. Sparse matrix must use CRS format for
storage.
NPoints - points count, >=0.
RESULT:
Its meaning for regression task is obvious. As for classification task, it
means average relative error when estimating posterior probability of
belonging to the correct class.
DATASET FORMAT:
This function uses two different dataset formats - one for regression
networks, another one for classification networks.
For regression networks with NIn inputs and NOut outputs following dataset
format is used:
* dataset is given by NPoints*(NIn+NOut) matrix
* each row corresponds to one example
* first NIn columns are inputs, next NOut columns are outputs
For classification networks with NIn inputs and NClasses clases following
dataset format is used:
* dataset is given by NPoints*(NIn+1) matrix
* each row corresponds to one example
* first NIn columns are inputs, last column stores class number (from 0 to
NClasses-1).
-- ALGLIB --
Copyright 09.08.2012 by Bochkanov Sergey
*************************************************************************/
</div><div style='margin-top: 0; margin-bottom: 0;'><b>double</b> alglib::mlpavgrelerrorsparse(
multilayerperceptron network,
sparsematrix xy,
ae_int_t npoints);
<b>double</b> alglib::smp_mlpavgrelerrorsparse(
multilayerperceptron network,
sparsematrix xy,
ae_int_t npoints);
</div></pre>
<a name='sub_mlpclserror'></a><h3 class=pageheader><code>mlpclserror</code> function</h3>
<pre class=source>
<div style='color: navy; margin-top: 0; margin-bottom: 0;'>/*************************************************************************
Classification error of the neural network on dataset.
FOR USERS OF COMMERCIAL EDITION:
! Commercial version of ALGLIB includes two important improvements of
! this function:
! * multicore support (C++ and C# computational cores)
! * SSE support
!
! First improvement gives close-to-linear speedup on multicore systems.
! Second improvement gives constant speedup (2-3x depending on your CPU)
!
! In order to use multicore features you have to:
! * use commercial version of ALGLIB
! * call this function with "smp_" prefix, which indicates that
! multicore code will be used (for multicore support)
!
! In order to use SSE features you have to:
! * use commercial version of ALGLIB on Intel processors
! * use C++ computational core
!
! This note is given for users of commercial edition; if you use GPL
! edition, you still will be able to call smp-version of this function,
! but all computations will be done serially.
!
! We recommend you to carefully read ALGLIB Reference Manual, section
! called 'SMP support', before using parallel version of this function.
INPUT PARAMETERS:
Network - neural network;
XY - training set, see below for information on the
training set format;
NPoints - points count.
RESULT:
classification error (number of misclassified cases)
DATASET FORMAT:
This function uses two different dataset formats - one for regression
networks, another one for classification networks.
For regression networks with NIn inputs and NOut outputs following dataset
format is used:
* dataset is given by NPoints*(NIn+NOut) matrix
* each row corresponds to one example
* first NIn columns are inputs, next NOut columns are outputs
For classification networks with NIn inputs and NClasses clases following
dataset format is used:
* dataset is given by NPoints*(NIn+1) matrix
* each row corresponds to one example
* first NIn columns are inputs, last column stores class number (from 0 to
NClasses-1).
-- ALGLIB --
Copyright 04.11.2007 by Bochkanov Sergey
*************************************************************************/
</div><div style='margin-top: 0; margin-bottom: 0;'>ae_int_t alglib::mlpclserror(
multilayerperceptron network,
real_2d_array xy,
ae_int_t npoints);
ae_int_t alglib::smp_mlpclserror(
multilayerperceptron network,
real_2d_array xy,
ae_int_t npoints);
</div></pre>
<a name='sub_mlpcopy'></a><h3 class=pageheader><code>mlpcopy</code> function</h3>
<pre class=source>
<div style='color: navy; margin-top: 0; margin-bottom: 0;'>/*************************************************************************
Copying of neural network
INPUT PARAMETERS:
Network1 - original
OUTPUT PARAMETERS:
Network2 - copy
-- ALGLIB --
Copyright 04.11.2007 by Bochkanov Sergey
*************************************************************************/
</div><div style='margin-top: 0; margin-bottom: 0;'><b>void</b> alglib::mlpcopy(
multilayerperceptron network1,
multilayerperceptron& network2);
</div></pre>
<a name='sub_mlpcopytunableparameters'></a><h3 class=pageheader><code>mlpcopytunableparameters</code> function</h3>
<pre class=source>
<div style='color: navy; margin-top: 0; margin-bottom: 0;'>/*************************************************************************
This function copies tunable parameters (weights/means/sigmas) from one
network to another with same architecture. It performs some rudimentary
checks that architectures are same, and throws exception if check fails.
It is intended for fast copying of states between two network which are
known to have same geometry.
INPUT PARAMETERS:
Network1 - source, must be correctly initialized
Network2 - target, must have same architecture
OUTPUT PARAMETERS:
Network2 - network state is copied from source to target
-- ALGLIB --
Copyright 20.06.2013 by Bochkanov Sergey
*************************************************************************/
</div><div style='margin-top: 0; margin-bottom: 0;'><b>void</b> alglib::mlpcopytunableparameters(
multilayerperceptron network1,
multilayerperceptron network2);
</div></pre>
<a name='sub_mlpcreate0'></a><h3 class=pageheader><code>mlpcreate0</code> function</h3>
<pre class=source>
<div style='color: navy; margin-top: 0; margin-bottom: 0;'>/*************************************************************************
Creates neural network with NIn inputs, NOut outputs, without hidden
layers, with linear output layer. Network weights are filled with small
random values.
-- ALGLIB --
Copyright 04.11.2007 by Bochkanov Sergey
*************************************************************************/
</div><div style='margin-top: 0; margin-bottom: 0;'><b>void</b> alglib::mlpcreate0(
ae_int_t nin,
ae_int_t nout,
multilayerperceptron& network);
</div></pre>
<a name='sub_mlpcreate1'></a><h3 class=pageheader><code>mlpcreate1</code> function</h3>
<pre class=source>
<div style='color: navy; margin-top: 0; margin-bottom: 0;'>/*************************************************************************
Same as MLPCreate0, but with one hidden layer (NHid neurons) with
non-linear activation function. Output layer is linear.
-- ALGLIB --
Copyright 04.11.2007 by Bochkanov Sergey
*************************************************************************/
</div><div style='margin-top: 0; margin-bottom: 0;'><b>void</b> alglib::mlpcreate1(
ae_int_t nin,
ae_int_t nhid,
ae_int_t nout,
multilayerperceptron& network);
</div></pre>
<a name='sub_mlpcreate2'></a><h3 class=pageheader><code>mlpcreate2</code> function</h3>
<pre class=source>
<div style='color: navy; margin-top: 0; margin-bottom: 0;'>/*************************************************************************
Same as MLPCreate0, but with two hidden layers (NHid1 and NHid2 neurons)
with non-linear activation function. Output layer is linear.
$ALL
-- ALGLIB --
Copyright 04.11.2007 by Bochkanov Sergey
*************************************************************************/
</div><div style='margin-top: 0; margin-bottom: 0;'><b>void</b> alglib::mlpcreate2(
ae_int_t nin,
ae_int_t nhid1,
ae_int_t nhid2,
ae_int_t nout,
multilayerperceptron& network);
</div></pre>
<a name='sub_mlpcreateb0'></a><h3 class=pageheader><code>mlpcreateb0</code> function</h3>
<pre class=source>
<div style='color: navy; margin-top: 0; margin-bottom: 0;'>/*************************************************************************
Creates neural network with NIn inputs, NOut outputs, without hidden
layers with non-linear output layer. Network weights are filled with small
random values.
Activation function of the output layer takes values:
(B, +INF), if D>=0
or
(-INF, B), if D<0.
-- ALGLIB --
Copyright 30.03.2008 by Bochkanov Sergey
*************************************************************************/
</div><div style='margin-top: 0; margin-bottom: 0;'><b>void</b> alglib::mlpcreateb0(
ae_int_t nin,
ae_int_t nout,
<b>double</b> b,
<b>double</b> d,
multilayerperceptron& network);
</div></pre>
<a name='sub_mlpcreateb1'></a><h3 class=pageheader><code>mlpcreateb1</code> function</h3>
<pre class=source>
<div style='color: navy; margin-top: 0; margin-bottom: 0;'>/*************************************************************************
Same as MLPCreateB0 but with non-linear hidden layer.
-- ALGLIB --
Copyright 30.03.2008 by Bochkanov Sergey
*************************************************************************/
</div><div style='margin-top: 0; margin-bottom: 0;'><b>void</b> alglib::mlpcreateb1(
ae_int_t nin,
ae_int_t nhid,
ae_int_t nout,
<b>double</b> b,
<b>double</b> d,
multilayerperceptron& network);
</div></pre>
<a name='sub_mlpcreateb2'></a><h3 class=pageheader><code>mlpcreateb2</code> function</h3>
<pre class=source>
<div style='color: navy; margin-top: 0; margin-bottom: 0;'>/*************************************************************************
Same as MLPCreateB0 but with two non-linear hidden layers.
-- ALGLIB --
Copyright 30.03.2008 by Bochkanov Sergey
*************************************************************************/
</div><div style='margin-top: 0; margin-bottom: 0;'><b>void</b> alglib::mlpcreateb2(
ae_int_t nin,
ae_int_t nhid1,
ae_int_t nhid2,
ae_int_t nout,
<b>double</b> b,
<b>double</b> d,
multilayerperceptron& network);
</div></pre>
<a name='sub_mlpcreatec0'></a><h3 class=pageheader><code>mlpcreatec0</code> function</h3>
<pre class=source>
<div style='color: navy; margin-top: 0; margin-bottom: 0;'>/*************************************************************************
Creates classifier network with NIn inputs and NOut possible classes.
Network contains no hidden layers and linear output layer with SOFTMAX-
normalization (so outputs sums up to 1.0 and converge to posterior
probabilities).
-- ALGLIB --
Copyright 04.11.2007 by Bochkanov Sergey
*************************************************************************/
</div><div style='margin-top: 0; margin-bottom: 0;'><b>void</b> alglib::mlpcreatec0(
ae_int_t nin,
ae_int_t nout,
multilayerperceptron& network);
</div></pre>
<a name='sub_mlpcreatec1'></a><h3 class=pageheader><code>mlpcreatec1</code> function</h3>
<pre class=source>
<div style='color: navy; margin-top: 0; margin-bottom: 0;'>/*************************************************************************
Same as MLPCreateC0, but with one non-linear hidden layer.
-- ALGLIB --
Copyright 04.11.2007 by Bochkanov Sergey
*************************************************************************/
</div><div style='margin-top: 0; margin-bottom: 0;'><b>void</b> alglib::mlpcreatec1(
ae_int_t nin,
ae_int_t nhid,
ae_int_t nout,
multilayerperceptron& network);
</div></pre>
<a name='sub_mlpcreatec2'></a><h3 class=pageheader><code>mlpcreatec2</code> function</h3>
<pre class=source>
<div style='color: navy; margin-top: 0; margin-bottom: 0;'>/*************************************************************************
Same as MLPCreateC0, but with two non-linear hidden layers.
-- ALGLIB --
Copyright 04.11.2007 by Bochkanov Sergey
*************************************************************************/
</div><div style='margin-top: 0; margin-bottom: 0;'><b>void</b> alglib::mlpcreatec2(
ae_int_t nin,
ae_int_t nhid1,
ae_int_t nhid2,
ae_int_t nout,
multilayerperceptron& network);
</div></pre>
<a name='sub_mlpcreater0'></a><h3 class=pageheader><code>mlpcreater0</code> function</h3>
<pre class=source>
<div style='color: navy; margin-top: 0; margin-bottom: 0;'>/*************************************************************************
Creates neural network with NIn inputs, NOut outputs, without hidden
layers with non-linear output layer. Network weights are filled with small
random values. Activation function of the output layer takes values [A,B].
-- ALGLIB --
Copyright 30.03.2008 by Bochkanov Sergey
*************************************************************************/
</div><div style='margin-top: 0; margin-bottom: 0;'><b>void</b> alglib::mlpcreater0(
ae_int_t nin,
ae_int_t nout,
<b>double</b> a,
<b>double</b> b,
multilayerperceptron& network);
</div></pre>
<a name='sub_mlpcreater1'></a><h3 class=pageheader><code>mlpcreater1</code> function</h3>
<pre class=source>
<div style='color: navy; margin-top: 0; margin-bottom: 0;'>/*************************************************************************
Same as MLPCreateR0, but with non-linear hidden layer.
-- ALGLIB --
Copyright 30.03.2008 by Bochkanov Sergey
*************************************************************************/
</div><div style='margin-top: 0; margin-bottom: 0;'><b>void</b> alglib::mlpcreater1(
ae_int_t nin,
ae_int_t nhid,
ae_int_t nout,
<b>double</b> a,
<b>double</b> b,
multilayerperceptron& network);
</div></pre>
<a name='sub_mlpcreater2'></a><h3 class=pageheader><code>mlpcreater2</code> function</h3>
<pre class=source>
<div style='color: navy; margin-top: 0; margin-bottom: 0;'>/*************************************************************************
Same as MLPCreateR0, but with two non-linear hidden layers.
-- ALGLIB --
Copyright 30.03.2008 by Bochkanov Sergey
*************************************************************************/
</div><div style='margin-top: 0; margin-bottom: 0;'><b>void</b> alglib::mlpcreater2(
ae_int_t nin,
ae_int_t nhid1,
ae_int_t nhid2,
ae_int_t nout,
<b>double</b> a,
<b>double</b> b,
multilayerperceptron& network);
</div></pre>
<a name='sub_mlperror'></a><h3 class=pageheader><code>mlperror</code> function</h3>
<pre class=source>
<div style='color: navy; margin-top: 0; margin-bottom: 0;'>/*************************************************************************
Error of the neural network on dataset.
FOR USERS OF COMMERCIAL EDITION:
! Commercial version of ALGLIB includes two important improvements of
! this function:
! * multicore support (C++ and C# computational cores)
! * SSE support
!
! First improvement gives close-to-linear speedup on multicore systems.
! Second improvement gives constant speedup (2-3x, depending on your CPU)
!
! In order to use multicore features you have to:
! * use commercial version of ALGLIB
! * call this function with "smp_" prefix, which indicates that
! multicore code will be used (for multicore support)
!
! In order to use SSE features you have to:
! * use commercial version of ALGLIB on Intel processors
! * use C++ computational core
!
! This note is given for users of commercial edition; if you use GPL
! edition, you still will be able to call smp-version of this function,
! but all computations will be done serially.
!
! We recommend you to carefully read ALGLIB Reference Manual, section
! called 'SMP support', before using parallel version of this function.
INPUT PARAMETERS:
Network - neural network;
XY - training set, see below for information on the
training set format;
NPoints - points count.
RESULT:
sum-of-squares error, SUM(sqr(y[i]-desired_y[i])/2)
DATASET FORMAT:
This function uses two different dataset formats - one for regression
networks, another one for classification networks.
For regression networks with NIn inputs and NOut outputs following dataset
format is used:
* dataset is given by NPoints*(NIn+NOut) matrix
* each row corresponds to one example
* first NIn columns are inputs, next NOut columns are outputs
For classification networks with NIn inputs and NClasses clases following
dataset format is used:
* dataset is given by NPoints*(NIn+1) matrix
* each row corresponds to one example
* first NIn columns are inputs, last column stores class number (from 0 to
NClasses-1).
-- ALGLIB --
Copyright 04.11.2007 by Bochkanov Sergey
*************************************************************************/
</div><div style='margin-top: 0; margin-bottom: 0;'><b>double</b> alglib::mlperror(
multilayerperceptron network,
real_2d_array xy,
ae_int_t npoints);
<b>double</b> alglib::smp_mlperror(
multilayerperceptron network,
real_2d_array xy,
ae_int_t npoints);
</div></pre>
<a name='sub_mlperrorn'></a><h3 class=pageheader><code>mlperrorn</code> function</h3>
<pre class=source>
<div style='color: navy; margin-top: 0; margin-bottom: 0;'>/*************************************************************************
Natural error function for neural network, internal subroutine.
NOTE: this function is single-threaded. Unlike other error function, it
receives no speed-up from being executed in SMP mode.
-- ALGLIB --
Copyright 04.11.2007 by Bochkanov Sergey
*************************************************************************/
</div><div style='margin-top: 0; margin-bottom: 0;'><b>double</b> alglib::mlperrorn(
multilayerperceptron network,
real_2d_array xy,
ae_int_t ssize);
</div></pre>
<a name='sub_mlperrorsparse'></a><h3 class=pageheader><code>mlperrorsparse</code> function</h3>
<pre class=source>
<div style='color: navy; margin-top: 0; margin-bottom: 0;'>/*************************************************************************
Error of the neural network on dataset given by sparse matrix.
FOR USERS OF COMMERCIAL EDITION:
! Commercial version of ALGLIB includes two important improvements of
! this function:
! * multicore support (C++ and C# computational cores)
! * SSE support
!
! First improvement gives close-to-linear speedup on multicore systems.
! Second improvement gives constant speedup (2-3x, depending on your CPU)
!
! In order to use multicore features you have to:
! * use commercial version of ALGLIB
! * call this function with "smp_" prefix, which indicates that
! multicore code will be used (for multicore support)
!
! In order to use SSE features you have to:
! * use commercial version of ALGLIB on Intel processors
! * use C++ computational core
!
! This note is given for users of commercial edition; if you use GPL
! edition, you still will be able to call smp-version of this function,
! but all computations will be done serially.
!
! We recommend you to carefully read ALGLIB Reference Manual, section
! called 'SMP support', before using parallel version of this function.
INPUT PARAMETERS:
Network - neural network
XY - training set, see below for information on the
training set format. This function checks correctness
of the dataset (no NANs/INFs, class numbers are
correct) and throws exception when incorrect dataset
is passed. Sparse matrix must use CRS format for
storage.
NPoints - points count, >=0
RESULT:
sum-of-squares error, SUM(sqr(y[i]-desired_y[i])/2)
DATASET FORMAT:
This function uses two different dataset formats - one for regression
networks, another one for classification networks.
For regression networks with NIn inputs and NOut outputs following dataset
format is used:
* dataset is given by NPoints*(NIn+NOut) matrix
* each row corresponds to one example
* first NIn columns are inputs, next NOut columns are outputs
For classification networks with NIn inputs and NClasses clases following
dataset format is used:
* dataset is given by NPoints*(NIn+1) matrix
* each row corresponds to one example
* first NIn columns are inputs, last column stores class number (from 0 to
NClasses-1).
-- ALGLIB --
Copyright 23.07.2012 by Bochkanov Sergey
*************************************************************************/
</div><div style='margin-top: 0; margin-bottom: 0;'><b>double</b> alglib::mlperrorsparse(
multilayerperceptron network,
sparsematrix xy,
ae_int_t npoints);
<b>double</b> alglib::smp_mlperrorsparse(
multilayerperceptron network,
sparsematrix xy,
ae_int_t npoints);
</div></pre>
<a name='sub_mlperrorsparsesubset'></a><h3 class=pageheader><code>mlperrorsparsesubset</code> function</h3>
<pre class=source>
<div style='color: navy; margin-top: 0; margin-bottom: 0;'>/*************************************************************************
Error of the neural network on subset of sparse dataset.
FOR USERS OF COMMERCIAL EDITION:
! Commercial version of ALGLIB includes two important improvements of
! this function:
! * multicore support (C++ and C# computational cores)
! * SSE support
!
! First improvement gives close-to-linear speedup on multicore systems.
! Second improvement gives constant speedup (2-3x depending on your CPU)
!
! In order to use multicore features you have to:
! * use commercial version of ALGLIB
! * call this function with "smp_" prefix, which indicates that
! multicore code will be used (for multicore support)
!
! In order to use SSE features you have to:
! * use commercial version of ALGLIB on Intel processors
! * use C++ computational core
!
! This note is given for users of commercial edition; if you use GPL
! edition, you still will be able to call smp-version of this function,
! but all computations will be done serially.
!
! We recommend you to carefully read ALGLIB Reference Manual, section
! called 'SMP support', before using parallel version of this function.
INPUT PARAMETERS:
Network - neural network;
XY - training set, see below for information on the
training set format. This function checks correctness
of the dataset (no NANs/INFs, class numbers are
correct) and throws exception when incorrect dataset
is passed. Sparse matrix must use CRS format for
storage.
SetSize - real size of XY, SetSize>=0;
it is used when SubsetSize<0;
Subset - subset of SubsetSize elements, array[SubsetSize];
SubsetSize- number of elements in Subset[] array:
* if SubsetSize>0, rows of XY with indices Subset[0]...
...Subset[SubsetSize-1] are processed
* if SubsetSize=0, zeros are returned
* if SubsetSize<0, entire dataset is processed; Subset[]
array is ignored in this case.
RESULT:
sum-of-squares error, SUM(sqr(y[i]-desired_y[i])/2)
DATASET FORMAT:
This function uses two different dataset formats - one for regression
networks, another one for classification networks.
For regression networks with NIn inputs and NOut outputs following dataset
format is used:
* dataset is given by NPoints*(NIn+NOut) matrix
* each row corresponds to one example
* first NIn columns are inputs, next NOut columns are outputs
For classification networks with NIn inputs and NClasses clases following
dataset format is used:
* dataset is given by NPoints*(NIn+1) matrix
* each row corresponds to one example
* first NIn columns are inputs, last column stores class number (from 0 to
NClasses-1).
-- ALGLIB --
Copyright 04.09.2012 by Bochkanov Sergey
*************************************************************************/
</div><div style='margin-top: 0; margin-bottom: 0;'><b>double</b> alglib::mlperrorsparsesubset(
multilayerperceptron network,
sparsematrix xy,
ae_int_t setsize,
integer_1d_array subset,
ae_int_t subsetsize);
<b>double</b> alglib::smp_mlperrorsparsesubset(
multilayerperceptron network,
sparsematrix xy,
ae_int_t setsize,
integer_1d_array subset,
ae_int_t subsetsize);
</div></pre>
<a name='sub_mlperrorsubset'></a><h3 class=pageheader><code>mlperrorsubset</code> function</h3>
<pre class=source>
<div style='color: navy; margin-top: 0; margin-bottom: 0;'>/*************************************************************************
Error of the neural network on subset of dataset.
FOR USERS OF COMMERCIAL EDITION:
! Commercial version of ALGLIB includes two important improvements of
! this function:
! * multicore support (C++ and C# computational cores)
! * SSE support
!
! First improvement gives close-to-linear speedup on multicore systems.
! Second improvement gives constant speedup (2-3x depending on your CPU)
!
! In order to use multicore features you have to:
! * use commercial version of ALGLIB
! * call this function with "smp_" prefix, which indicates that
! multicore code will be used (for multicore support)
!
! In order to use SSE features you have to:
! * use commercial version of ALGLIB on Intel processors
! * use C++ computational core
!
! This note is given for users of commercial edition; if you use GPL
! edition, you still will be able to call smp-version of this function,
! but all computations will be done serially.
!
! We recommend you to carefully read ALGLIB Reference Manual, section
! called 'SMP support', before using parallel version of this function.
INPUT PARAMETERS:
Network - neural network;
XY - training set, see below for information on the
training set format;
SetSize - real size of XY, SetSize>=0;
Subset - subset of SubsetSize elements, array[SubsetSize];
SubsetSize- number of elements in Subset[] array:
* if SubsetSize>0, rows of XY with indices Subset[0]...
...Subset[SubsetSize-1] are processed
* if SubsetSize=0, zeros are returned
* if SubsetSize<0, entire dataset is processed; Subset[]
array is ignored in this case.
RESULT:
sum-of-squares error, SUM(sqr(y[i]-desired_y[i])/2)
DATASET FORMAT:
This function uses two different dataset formats - one for regression
networks, another one for classification networks.
For regression networks with NIn inputs and NOut outputs following dataset
format is used:
* dataset is given by NPoints*(NIn+NOut) matrix
* each row corresponds to one example
* first NIn columns are inputs, next NOut columns are outputs
For classification networks with NIn inputs and NClasses clases following
dataset format is used:
* dataset is given by NPoints*(NIn+1) matrix
* each row corresponds to one example
* first NIn columns are inputs, last column stores class number (from 0 to
NClasses-1).
-- ALGLIB --
Copyright 04.09.2012 by Bochkanov Sergey
*************************************************************************/
</div><div style='margin-top: 0; margin-bottom: 0;'><b>double</b> alglib::mlperrorsubset(
multilayerperceptron network,
real_2d_array xy,
ae_int_t setsize,
integer_1d_array subset,
ae_int_t subsetsize);
<b>double</b> alglib::smp_mlperrorsubset(
multilayerperceptron network,
real_2d_array xy,
ae_int_t setsize,
integer_1d_array subset,
ae_int_t subsetsize);
</div></pre>
<a name='sub_mlpgetinputscaling'></a><h3 class=pageheader><code>mlpgetinputscaling</code> function</h3>
<pre class=source>
<div style='color: navy; margin-top: 0; margin-bottom: 0;'>/*************************************************************************
This function returns offset/scaling coefficients for I-th input of the
network.
INPUT PARAMETERS:
Network - network
I - input index
OUTPUT PARAMETERS:
Mean - mean term
Sigma - sigma term, guaranteed to be nonzero.
I-th input is passed through linear transformation
IN[i] = (IN[i]-Mean)/Sigma
before feeding to the network
-- ALGLIB --
Copyright 25.03.2011 by Bochkanov Sergey
*************************************************************************/
</div><div style='margin-top: 0; margin-bottom: 0;'><b>void</b> alglib::mlpgetinputscaling(
multilayerperceptron network,
ae_int_t i,
<b>double</b>& mean,
<b>double</b>& sigma);
</div></pre>
<a name='sub_mlpgetinputscount'></a><h3 class=pageheader><code>mlpgetinputscount</code> function</h3>
<pre class=source>
<div style='color: navy; margin-top: 0; margin-bottom: 0;'>/*************************************************************************
Returns number of inputs.
-- ALGLIB --
Copyright 19.10.2011 by Bochkanov Sergey
*************************************************************************/
</div><div style='margin-top: 0; margin-bottom: 0;'>ae_int_t alglib::mlpgetinputscount(multilayerperceptron network);
</div></pre>
<a name='sub_mlpgetlayerscount'></a><h3 class=pageheader><code>mlpgetlayerscount</code> function</h3>
<pre class=source>
<div style='color: navy; margin-top: 0; margin-bottom: 0;'>/*************************************************************************
This function returns total number of layers (including input, hidden and
output layers).
-- ALGLIB --
Copyright 25.03.2011 by Bochkanov Sergey
*************************************************************************/
</div><div style='margin-top: 0; margin-bottom: 0;'>ae_int_t alglib::mlpgetlayerscount(multilayerperceptron network);
</div></pre>
<a name='sub_mlpgetlayersize'></a><h3 class=pageheader><code>mlpgetlayersize</code> function</h3>
<pre class=source>
<div style='color: navy; margin-top: 0; margin-bottom: 0;'>/*************************************************************************
This function returns size of K-th layer.
K=0 corresponds to input layer, K=CNT-1 corresponds to output layer.
Size of the output layer is always equal to the number of outputs, although
when we have softmax-normalized network, last neuron doesn't have any
connections - it is just zero.
-- ALGLIB --
Copyright 25.03.2011 by Bochkanov Sergey
*************************************************************************/
</div><div style='margin-top: 0; margin-bottom: 0;'>ae_int_t alglib::mlpgetlayersize(
multilayerperceptron network,
ae_int_t k);
</div></pre>
<a name='sub_mlpgetneuroninfo'></a><h3 class=pageheader><code>mlpgetneuroninfo</code> function</h3>
<pre class=source>
<div style='color: navy; margin-top: 0; margin-bottom: 0;'>/*************************************************************************
This function returns information about Ith neuron of Kth layer
INPUT PARAMETERS:
Network - network
K - layer index
I - neuron index (within layer)
OUTPUT PARAMETERS:
FKind - activation function type (used by MLPActivationFunction())
this value is zero for input or linear neurons
Threshold - also called offset, bias
zero for input neurons
NOTE: this function throws exception if layer or neuron with given index
do not exists.
-- ALGLIB --
Copyright 25.03.2011 by Bochkanov Sergey
*************************************************************************/
</div><div style='margin-top: 0; margin-bottom: 0;'><b>void</b> alglib::mlpgetneuroninfo(
multilayerperceptron network,
ae_int_t k,
ae_int_t i,
ae_int_t& fkind,
<b>double</b>& threshold);
</div></pre>
<a name='sub_mlpgetoutputscaling'></a><h3 class=pageheader><code>mlpgetoutputscaling</code> function</h3>
<pre class=source>
<div style='color: navy; margin-top: 0; margin-bottom: 0;'>/*************************************************************************
This function returns offset/scaling coefficients for I-th output of the
network.
INPUT PARAMETERS:
Network - network
I - input index
OUTPUT PARAMETERS:
Mean - mean term
Sigma - sigma term, guaranteed to be nonzero.
I-th output is passed through linear transformation
OUT[i] = OUT[i]*Sigma+Mean
before returning it to user. In case we have SOFTMAX-normalized network,
we return (Mean,Sigma)=(0.0,1.0).
-- ALGLIB --
Copyright 25.03.2011 by Bochkanov Sergey
*************************************************************************/
</div><div style='margin-top: 0; margin-bottom: 0;'><b>void</b> alglib::mlpgetoutputscaling(
multilayerperceptron network,
ae_int_t i,
<b>double</b>& mean,
<b>double</b>& sigma);
</div></pre>
<a name='sub_mlpgetoutputscount'></a><h3 class=pageheader><code>mlpgetoutputscount</code> function</h3>
<pre class=source>
<div style='color: navy; margin-top: 0; margin-bottom: 0;'>/*************************************************************************
Returns number of outputs.
-- ALGLIB --
Copyright 19.10.2011 by Bochkanov Sergey
*************************************************************************/
</div><div style='margin-top: 0; margin-bottom: 0;'>ae_int_t alglib::mlpgetoutputscount(multilayerperceptron network);
</div></pre>
<a name='sub_mlpgetweight'></a><h3 class=pageheader><code>mlpgetweight</code> function</h3>
<pre class=source>
<div style='color: navy; margin-top: 0; margin-bottom: 0;'>/*************************************************************************
This function returns information about connection from I0-th neuron of
K0-th layer to I1-th neuron of K1-th layer.
INPUT PARAMETERS:
Network - network
K0 - layer index
I0 - neuron index (within layer)
K1 - layer index
I1 - neuron index (within layer)
RESULT:
connection weight (zero for non-existent connections)
This function:
1. throws exception if layer or neuron with given index do not exists.
2. returns zero if neurons exist, but there is no connection between them
-- ALGLIB --
Copyright 25.03.2011 by Bochkanov Sergey
*************************************************************************/
</div><div style='margin-top: 0; margin-bottom: 0;'><b>double</b> alglib::mlpgetweight(
multilayerperceptron network,
ae_int_t k0,
ae_int_t i0,
ae_int_t k1,
ae_int_t i1);
</div></pre>
<a name='sub_mlpgetweightscount'></a><h3 class=pageheader><code>mlpgetweightscount</code> function</h3>
<pre class=source>
<div style='color: navy; margin-top: 0; margin-bottom: 0;'>/*************************************************************************
Returns number of weights.
-- ALGLIB --
Copyright 19.10.2011 by Bochkanov Sergey
*************************************************************************/
</div><div style='margin-top: 0; margin-bottom: 0;'>ae_int_t alglib::mlpgetweightscount(multilayerperceptron network);
</div></pre>
<a name='sub_mlpgrad'></a><h3 class=pageheader><code>mlpgrad</code> function</h3>
<pre class=source>
<div style='color: navy; margin-top: 0; margin-bottom: 0;'>/*************************************************************************
Gradient calculation
INPUT PARAMETERS:
Network - network initialized with one of the network creation funcs
X - input vector, length of array must be at least NIn
DesiredY- desired outputs, length of array must be at least NOut
Grad - possibly preallocated array. If size of array is smaller
than WCount, it will be reallocated. It is recommended to
reuse previously allocated array to reduce allocation
overhead.
OUTPUT PARAMETERS:
E - error function, SUM(sqr(y[i]-desiredy[i])/2,i)
Grad - gradient of E with respect to weights of network, array[WCount]
-- ALGLIB --
Copyright 04.11.2007 by Bochkanov Sergey
*************************************************************************/
</div><div style='margin-top: 0; margin-bottom: 0;'><b>void</b> alglib::mlpgrad(
multilayerperceptron network,
real_1d_array x,
real_1d_array desiredy,
<b>double</b>& e,
real_1d_array& grad);
</div></pre>
<a name='sub_mlpgradbatch'></a><h3 class=pageheader><code>mlpgradbatch</code> function</h3>
<pre class=source>
<div style='color: navy; margin-top: 0; margin-bottom: 0;'>/*************************************************************************
Batch gradient calculation for a set of inputs/outputs
FOR USERS OF COMMERCIAL EDITION:
! Commercial version of ALGLIB includes two important improvements of
! this function:
! * multicore support (C++ and C# computational cores)
! * SSE support
!
! First improvement gives close-to-linear speedup on multicore systems.
! Second improvement gives constant speedup (2-3x depending on your CPU)
!
! In order to use multicore features you have to:
! * use commercial version of ALGLIB
! * call this function with "smp_" prefix, which indicates that
! multicore code will be used (for multicore support)
!
! In order to use SSE features you have to:
! * use commercial version of ALGLIB on Intel processors
! * use C++ computational core
!
! This note is given for users of commercial edition; if you use GPL
! edition, you still will be able to call smp-version of this function,
! but all computations will be done serially.
!
! We recommend you to carefully read ALGLIB Reference Manual, section
! called 'SMP support', before using parallel version of this function.
INPUT PARAMETERS:
Network - network initialized with one of the network creation funcs
XY - original dataset in dense format; one sample = one row:
* first NIn columns contain inputs,
* for regression problem, next NOut columns store
desired outputs.
* for classification problem, next column (just one!)
stores class number.
SSize - number of elements in XY
Grad - possibly preallocated array. If size of array is smaller
than WCount, it will be reallocated. It is recommended to
reuse previously allocated array to reduce allocation
overhead.
OUTPUT PARAMETERS:
E - error function, SUM(sqr(y[i]-desiredy[i])/2,i)
Grad - gradient of E with respect to weights of network, array[WCount]
-- ALGLIB --
Copyright 04.11.2007 by Bochkanov Sergey
*************************************************************************/
</div><div style='margin-top: 0; margin-bottom: 0;'><b>void</b> alglib::mlpgradbatch(
multilayerperceptron network,
real_2d_array xy,
ae_int_t ssize,
<b>double</b>& e,
real_1d_array& grad);
<b>void</b> alglib::smp_mlpgradbatch(
multilayerperceptron network,
real_2d_array xy,
ae_int_t ssize,
<b>double</b>& e,
real_1d_array& grad);
</div></pre>
<a name='sub_mlpgradbatchsparse'></a><h3 class=pageheader><code>mlpgradbatchsparse</code> function</h3>
<pre class=source>
<div style='color: navy; margin-top: 0; margin-bottom: 0;'>/*************************************************************************
Batch gradient calculation for a set of inputs/outputs given by sparse
matrices
FOR USERS OF COMMERCIAL EDITION:
! Commercial version of ALGLIB includes two important improvements of
! this function:
! * multicore support (C++ and C# computational cores)
! * SSE support
!
! First improvement gives close-to-linear speedup on multicore systems.
! Second improvement gives constant speedup (2-3x depending on your CPU)
!
! In order to use multicore features you have to:
! * use commercial version of ALGLIB
! * call this function with "smp_" prefix, which indicates that
! multicore code will be used (for multicore support)
!
! In order to use SSE features you have to:
! * use commercial version of ALGLIB on Intel processors
! * use C++ computational core
!
! This note is given for users of commercial edition; if you use GPL
! edition, you still will be able to call smp-version of this function,
! but all computations will be done serially.
!
! We recommend you to carefully read ALGLIB Reference Manual, section
! called 'SMP support', before using parallel version of this function.
INPUT PARAMETERS:
Network - network initialized with one of the network creation funcs
XY - original dataset in sparse format; one sample = one row:
* MATRIX MUST BE STORED IN CRS FORMAT
* first NIn columns contain inputs.
* for regression problem, next NOut columns store
desired outputs.
* for classification problem, next column (just one!)
stores class number.
SSize - number of elements in XY
Grad - possibly preallocated array. If size of array is smaller
than WCount, it will be reallocated. It is recommended to
reuse previously allocated array to reduce allocation
overhead.
OUTPUT PARAMETERS:
E - error function, SUM(sqr(y[i]-desiredy[i])/2,i)
Grad - gradient of E with respect to weights of network, array[WCount]
-- ALGLIB --
Copyright 26.07.2012 by Bochkanov Sergey
*************************************************************************/
</div><div style='margin-top: 0; margin-bottom: 0;'><b>void</b> alglib::mlpgradbatchsparse(
multilayerperceptron network,
sparsematrix xy,
ae_int_t ssize,
<b>double</b>& e,
real_1d_array& grad);
<b>void</b> alglib::smp_mlpgradbatchsparse(
multilayerperceptron network,
sparsematrix xy,
ae_int_t ssize,
<b>double</b>& e,
real_1d_array& grad);
</div></pre>
<a name='sub_mlpgradbatchsparsesubset'></a><h3 class=pageheader><code>mlpgradbatchsparsesubset</code> function</h3>
<pre class=source>
<div style='color: navy; margin-top: 0; margin-bottom: 0;'>/*************************************************************************
Batch gradient calculation for a set of inputs/outputs for a subset of
dataset given by set of indexes.
FOR USERS OF COMMERCIAL EDITION:
! Commercial version of ALGLIB includes two important improvements of
! this function:
! * multicore support (C++ and C# computational cores)
! * SSE support
!
! First improvement gives close-to-linear speedup on multicore systems.
! Second improvement gives constant speedup (2-3x depending on your CPU)
!
! In order to use multicore features you have to:
! * use commercial version of ALGLIB
! * call this function with "smp_" prefix, which indicates that
! multicore code will be used (for multicore support)
!
! In order to use SSE features you have to:
! * use commercial version of ALGLIB on Intel processors
! * use C++ computational core
!
! This note is given for users of commercial edition; if you use GPL
! edition, you still will be able to call smp-version of this function,
! but all computations will be done serially.
!
! We recommend you to carefully read ALGLIB Reference Manual, section
! called 'SMP support', before using parallel version of this function.
INPUT PARAMETERS:
Network - network initialized with one of the network creation funcs
XY - original dataset in sparse format; one sample = one row:
* MATRIX MUST BE STORED IN CRS FORMAT
* first NIn columns contain inputs,
* for regression problem, next NOut columns store
desired outputs.
* for classification problem, next column (just one!)
stores class number.
SetSize - real size of XY, SetSize>=0;
Idx - subset of SubsetSize elements, array[SubsetSize]:
* Idx[I] stores row index in the original dataset which is
given by XY. Gradient is calculated with respect to rows
whose indexes are stored in Idx[].
* Idx[] must store correct indexes; this function throws
an exception in case incorrect index (less than 0 or
larger than rows(XY)) is given
* Idx[] may store indexes in any order and even with
repetitions.
SubsetSize- number of elements in Idx[] array:
* positive value means that subset given by Idx[] is processed
* zero value results in zero gradient
* negative value means that full dataset is processed
Grad - possibly preallocated array. If size of array is smaller
than WCount, it will be reallocated. It is recommended to
reuse previously allocated array to reduce allocation
overhead.
OUTPUT PARAMETERS:
E - error function, SUM(sqr(y[i]-desiredy[i])/2,i)
Grad - gradient of E with respect to weights of network,
array[WCount]
NOTE: when SubsetSize<0 is used full dataset by call MLPGradBatchSparse
function.
-- ALGLIB --
Copyright 26.07.2012 by Bochkanov Sergey
*************************************************************************/
</div><div style='margin-top: 0; margin-bottom: 0;'><b>void</b> alglib::mlpgradbatchsparsesubset(
multilayerperceptron network,
sparsematrix xy,
ae_int_t setsize,
integer_1d_array idx,
ae_int_t subsetsize,
<b>double</b>& e,
real_1d_array& grad);
<b>void</b> alglib::smp_mlpgradbatchsparsesubset(
multilayerperceptron network,
sparsematrix xy,
ae_int_t setsize,
integer_1d_array idx,
ae_int_t subsetsize,
<b>double</b>& e,
real_1d_array& grad);
</div></pre>
<a name='sub_mlpgradbatchsubset'></a><h3 class=pageheader><code>mlpgradbatchsubset</code> function</h3>
<pre class=source>
<div style='color: navy; margin-top: 0; margin-bottom: 0;'>/*************************************************************************
Batch gradient calculation for a subset of dataset
FOR USERS OF COMMERCIAL EDITION:
! Commercial version of ALGLIB includes two important improvements of
! this function:
! * multicore support (C++ and C# computational cores)
! * SSE support
!
! First improvement gives close-to-linear speedup on multicore systems.
! Second improvement gives constant speedup (2-3x depending on your CPU)
!
! In order to use multicore features you have to:
! * use commercial version of ALGLIB
! * call this function with "smp_" prefix, which indicates that
! multicore code will be used (for multicore support)
!
! In order to use SSE features you have to:
! * use commercial version of ALGLIB on Intel processors
! * use C++ computational core
!
! This note is given for users of commercial edition; if you use GPL
! edition, you still will be able to call smp-version of this function,
! but all computations will be done serially.
!
! We recommend you to carefully read ALGLIB Reference Manual, section
! called 'SMP support', before using parallel version of this function.
INPUT PARAMETERS:
Network - network initialized with one of the network creation funcs
XY - original dataset in dense format; one sample = one row:
* first NIn columns contain inputs,
* for regression problem, next NOut columns store
desired outputs.
* for classification problem, next column (just one!)
stores class number.
SetSize - real size of XY, SetSize>=0;
Idx - subset of SubsetSize elements, array[SubsetSize]:
* Idx[I] stores row index in the original dataset which is
given by XY. Gradient is calculated with respect to rows
whose indexes are stored in Idx[].
* Idx[] must store correct indexes; this function throws
an exception in case incorrect index (less than 0 or
larger than rows(XY)) is given
* Idx[] may store indexes in any order and even with
repetitions.
SubsetSize- number of elements in Idx[] array:
* positive value means that subset given by Idx[] is processed
* zero value results in zero gradient
* negative value means that full dataset is processed
Grad - possibly preallocated array. If size of array is smaller
than WCount, it will be reallocated. It is recommended to
reuse previously allocated array to reduce allocation
overhead.
OUTPUT PARAMETERS:
E - error function, SUM(sqr(y[i]-desiredy[i])/2,i)
Grad - gradient of E with respect to weights of network,
array[WCount]
-- ALGLIB --
Copyright 26.07.2012 by Bochkanov Sergey
*************************************************************************/
</div><div style='margin-top: 0; margin-bottom: 0;'><b>void</b> alglib::mlpgradbatchsubset(
multilayerperceptron network,
real_2d_array xy,
ae_int_t setsize,
integer_1d_array idx,
ae_int_t subsetsize,
<b>double</b>& e,
real_1d_array& grad);
<b>void</b> alglib::smp_mlpgradbatchsubset(
multilayerperceptron network,
real_2d_array xy,
ae_int_t setsize,
integer_1d_array idx,
ae_int_t subsetsize,
<b>double</b>& e,
real_1d_array& grad);
</div></pre>
<a name='sub_mlpgradn'></a><h3 class=pageheader><code>mlpgradn</code> function</h3>
<pre class=source>
<div style='color: navy; margin-top: 0; margin-bottom: 0;'>/*************************************************************************
Gradient calculation (natural error function is used)
INPUT PARAMETERS:
Network - network initialized with one of the network creation funcs
X - input vector, length of array must be at least NIn
DesiredY- desired outputs, length of array must be at least NOut
Grad - possibly preallocated array. If size of array is smaller
than WCount, it will be reallocated. It is recommended to
reuse previously allocated array to reduce allocation
overhead.
OUTPUT PARAMETERS:
E - error function, sum-of-squares for regression networks,
cross-entropy for classification networks.
Grad - gradient of E with respect to weights of network, array[WCount]
-- ALGLIB --
Copyright 04.11.2007 by Bochkanov Sergey
*************************************************************************/
</div><div style='margin-top: 0; margin-bottom: 0;'><b>void</b> alglib::mlpgradn(
multilayerperceptron network,
real_1d_array x,
real_1d_array desiredy,
<b>double</b>& e,
real_1d_array& grad);
</div></pre>
<a name='sub_mlpgradnbatch'></a><h3 class=pageheader><code>mlpgradnbatch</code> function</h3>
<pre class=source>
<div style='color: navy; margin-top: 0; margin-bottom: 0;'>/*************************************************************************
Batch gradient calculation for a set of inputs/outputs
(natural error function is used)
INPUT PARAMETERS:
Network - network initialized with one of the network creation funcs
XY - set of inputs/outputs; one sample = one row;
first NIn columns contain inputs,
next NOut columns - desired outputs.
SSize - number of elements in XY
Grad - possibly preallocated array. If size of array is smaller
than WCount, it will be reallocated. It is recommended to
reuse previously allocated array to reduce allocation
overhead.
OUTPUT PARAMETERS:
E - error function, sum-of-squares for regression networks,
cross-entropy for classification networks.
Grad - gradient of E with respect to weights of network, array[WCount]
-- ALGLIB --
Copyright 04.11.2007 by Bochkanov Sergey
*************************************************************************/
</div><div style='margin-top: 0; margin-bottom: 0;'><b>void</b> alglib::mlpgradnbatch(
multilayerperceptron network,
real_2d_array xy,
ae_int_t ssize,
<b>double</b>& e,
real_1d_array& grad);
</div></pre>
<a name='sub_mlphessianbatch'></a><h3 class=pageheader><code>mlphessianbatch</code> function</h3>
<pre class=source>
<div style='color: navy; margin-top: 0; margin-bottom: 0;'>/*************************************************************************
Batch Hessian calculation using R-algorithm.
Internal subroutine.
-- ALGLIB --
Copyright 26.01.2008 by Bochkanov Sergey.
Hessian calculation based on R-algorithm described in
"Fast Exact Multiplication by the Hessian",
B. A. Pearlmutter,
Neural Computation, 1994.
*************************************************************************/
</div><div style='margin-top: 0; margin-bottom: 0;'><b>void</b> alglib::mlphessianbatch(
multilayerperceptron network,
real_2d_array xy,
ae_int_t ssize,
<b>double</b>& e,
real_1d_array& grad,
real_2d_array& h);
</div></pre>
<a name='sub_mlphessiannbatch'></a><h3 class=pageheader><code>mlphessiannbatch</code> function</h3>
<pre class=source>
<div style='color: navy; margin-top: 0; margin-bottom: 0;'>/*************************************************************************
Batch Hessian calculation (natural error function) using R-algorithm.
Internal subroutine.
-- ALGLIB --
Copyright 26.01.2008 by Bochkanov Sergey.
Hessian calculation based on R-algorithm described in
"Fast Exact Multiplication by the Hessian",
B. A. Pearlmutter,
Neural Computation, 1994.
*************************************************************************/
</div><div style='margin-top: 0; margin-bottom: 0;'><b>void</b> alglib::mlphessiannbatch(
multilayerperceptron network,
real_2d_array xy,
ae_int_t ssize,
<b>double</b>& e,
real_1d_array& grad,
real_2d_array& h);
</div></pre>
<a name='sub_mlpinitpreprocessor'></a><h3 class=pageheader><code>mlpinitpreprocessor</code> function</h3>
<pre class=source>
<div style='color: navy; margin-top: 0; margin-bottom: 0;'>/*************************************************************************
Internal subroutine.
-- ALGLIB --
Copyright 30.03.2008 by Bochkanov Sergey
*************************************************************************/
</div><div style='margin-top: 0; margin-bottom: 0;'><b>void</b> alglib::mlpinitpreprocessor(
multilayerperceptron network,
real_2d_array xy,
ae_int_t ssize);
</div></pre>
<a name='sub_mlpissoftmax'></a><h3 class=pageheader><code>mlpissoftmax</code> function</h3>
<pre class=source>
<div style='color: navy; margin-top: 0; margin-bottom: 0;'>/*************************************************************************
Tells whether network is SOFTMAX-normalized (i.e. classifier) or not.
-- ALGLIB --
Copyright 04.11.2007 by Bochkanov Sergey
*************************************************************************/
</div><div style='margin-top: 0; margin-bottom: 0;'><b>bool</b> alglib::mlpissoftmax(multilayerperceptron network);
</div></pre>
<a name='sub_mlpprocess'></a><h3 class=pageheader><code>mlpprocess</code> function</h3>
<pre class=source>
<div style='color: navy; margin-top: 0; margin-bottom: 0;'>/*************************************************************************
Procesing
INPUT PARAMETERS:
Network - neural network
X - input vector, array[0..NIn-1].
OUTPUT PARAMETERS:
Y - result. Regression estimate when solving regression task,
vector of posterior probabilities for classification task.
See also MLPProcessI
-- ALGLIB --
Copyright 04.11.2007 by Bochkanov Sergey
*************************************************************************/
</div><div style='margin-top: 0; margin-bottom: 0;'><b>void</b> alglib::mlpprocess(
multilayerperceptron network,
real_1d_array x,
real_1d_array& y);
</div></pre>
<a name='sub_mlpprocessi'></a><h3 class=pageheader><code>mlpprocessi</code> function</h3>
<pre class=source>
<div style='color: navy; margin-top: 0; margin-bottom: 0;'>/*************************************************************************
'interactive' variant of MLPProcess for languages like Python which
support constructs like "Y = MLPProcess(NN,X)" and interactive mode of the
interpreter
This function allocates new array on each call, so it is significantly
slower than its 'non-interactive' counterpart, but it is more convenient
when you call it from command line.
-- ALGLIB --
Copyright 21.09.2010 by Bochkanov Sergey
*************************************************************************/
</div><div style='margin-top: 0; margin-bottom: 0;'><b>void</b> alglib::mlpprocessi(
multilayerperceptron network,
real_1d_array x,
real_1d_array& y);
</div></pre>
<a name='sub_mlpproperties'></a><h3 class=pageheader><code>mlpproperties</code> function</h3>
<pre class=source>
<div style='color: navy; margin-top: 0; margin-bottom: 0;'>/*************************************************************************
Returns information about initialized network: number of inputs, outputs,
weights.
-- ALGLIB --
Copyright 04.11.2007 by Bochkanov Sergey
*************************************************************************/
</div><div style='margin-top: 0; margin-bottom: 0;'><b>void</b> alglib::mlpproperties(
multilayerperceptron network,
ae_int_t& nin,
ae_int_t& nout,
ae_int_t& wcount);
</div></pre>
<a name='sub_mlprandomize'></a><h3 class=pageheader><code>mlprandomize</code> function</h3>
<pre class=source>
<div style='color: navy; margin-top: 0; margin-bottom: 0;'>/*************************************************************************
Randomization of neural network weights
-- ALGLIB --
Copyright 06.11.2007 by Bochkanov Sergey
*************************************************************************/
</div><div style='margin-top: 0; margin-bottom: 0;'><b>void</b> alglib::mlprandomize(multilayerperceptron network);
</div></pre>
<a name='sub_mlprandomizefull'></a><h3 class=pageheader><code>mlprandomizefull</code> function</h3>
<pre class=source>
<div style='color: navy; margin-top: 0; margin-bottom: 0;'>/*************************************************************************
Randomization of neural network weights and standartisator
-- ALGLIB --
Copyright 10.03.2008 by Bochkanov Sergey
*************************************************************************/
</div><div style='margin-top: 0; margin-bottom: 0;'><b>void</b> alglib::mlprandomizefull(multilayerperceptron network);
</div></pre>
<a name='sub_mlprelclserror'></a><h3 class=pageheader><code>mlprelclserror</code> function</h3>
<pre class=source>
<div style='color: navy; margin-top: 0; margin-bottom: 0;'>/*************************************************************************
Relative classification error on the test set.
FOR USERS OF COMMERCIAL EDITION:
! Commercial version of ALGLIB includes two important improvements of
! this function:
! * multicore support (C++ and C# computational cores)
! * SSE support
!
! First improvement gives close-to-linear speedup on multicore systems.
! Second improvement gives constant speedup (2-3x depending on your CPU)
!
! In order to use multicore features you have to:
! * use commercial version of ALGLIB
! * call this function with "smp_" prefix, which indicates that
! multicore code will be used (for multicore support)
!
! In order to use SSE features you have to:
! * use commercial version of ALGLIB on Intel processors
! * use C++ computational core
!
! This note is given for users of commercial edition; if you use GPL
! edition, you still will be able to call smp-version of this function,
! but all computations will be done serially.
!
! We recommend you to carefully read ALGLIB Reference Manual, section
! called 'SMP support', before using parallel version of this function.
INPUT PARAMETERS:
Network - neural network;
XY - training set, see below for information on the
training set format;
NPoints - points count.
RESULT:
Percent of incorrectly classified cases. Works both for classifier
networks and general purpose networks used as classifiers.
DATASET FORMAT:
This function uses two different dataset formats - one for regression
networks, another one for classification networks.
For regression networks with NIn inputs and NOut outputs following dataset
format is used:
* dataset is given by NPoints*(NIn+NOut) matrix
* each row corresponds to one example
* first NIn columns are inputs, next NOut columns are outputs
For classification networks with NIn inputs and NClasses clases following
dataset format is used:
* dataset is given by NPoints*(NIn+1) matrix
* each row corresponds to one example
* first NIn columns are inputs, last column stores class number (from 0 to
NClasses-1).
-- ALGLIB --
Copyright 25.12.2008 by Bochkanov Sergey
*************************************************************************/
</div><div style='margin-top: 0; margin-bottom: 0;'><b>double</b> alglib::mlprelclserror(
multilayerperceptron network,
real_2d_array xy,
ae_int_t npoints);
<b>double</b> alglib::smp_mlprelclserror(
multilayerperceptron network,
real_2d_array xy,
ae_int_t npoints);
</div></pre>
<a name='sub_mlprelclserrorsparse'></a><h3 class=pageheader><code>mlprelclserrorsparse</code> function</h3>
<pre class=source>
<div style='color: navy; margin-top: 0; margin-bottom: 0;'>/*************************************************************************
Relative classification error on the test set given by sparse matrix.
FOR USERS OF COMMERCIAL EDITION:
! Commercial version of ALGLIB includes two important improvements of
! this function:
! * multicore support (C++ and C# computational cores)
! * SSE support
!
! First improvement gives close-to-linear speedup on multicore systems.
! Second improvement gives constant speedup (2-3x depending on your CPU)
!
! In order to use multicore features you have to:
! * use commercial version of ALGLIB
! * call this function with "smp_" prefix, which indicates that
! multicore code will be used (for multicore support)
!
! In order to use SSE features you have to:
! * use commercial version of ALGLIB on Intel processors
! * use C++ computational core
!
! This note is given for users of commercial edition; if you use GPL
! edition, you still will be able to call smp-version of this function,
! but all computations will be done serially.
!
! We recommend you to carefully read ALGLIB Reference Manual, section
! called 'SMP support', before using parallel version of this function.
INPUT PARAMETERS:
Network - neural network;
XY - training set, see below for information on the
training set format. Sparse matrix must use CRS format
for storage.
NPoints - points count, >=0.
RESULT:
Percent of incorrectly classified cases. Works both for classifier
networks and general purpose networks used as classifiers.
DATASET FORMAT:
This function uses two different dataset formats - one for regression
networks, another one for classification networks.
For regression networks with NIn inputs and NOut outputs following dataset
format is used:
* dataset is given by NPoints*(NIn+NOut) matrix
* each row corresponds to one example
* first NIn columns are inputs, next NOut columns are outputs
For classification networks with NIn inputs and NClasses clases following
dataset format is used:
* dataset is given by NPoints*(NIn+1) matrix
* each row corresponds to one example
* first NIn columns are inputs, last column stores class number (from 0 to
NClasses-1).
-- ALGLIB --
Copyright 09.08.2012 by Bochkanov Sergey
*************************************************************************/
</div><div style='margin-top: 0; margin-bottom: 0;'><b>double</b> alglib::mlprelclserrorsparse(
multilayerperceptron network,
sparsematrix xy,
ae_int_t npoints);
<b>double</b> alglib::smp_mlprelclserrorsparse(
multilayerperceptron network,
sparsematrix xy,
ae_int_t npoints);
</div></pre>
<a name='sub_mlprmserror'></a><h3 class=pageheader><code>mlprmserror</code> function</h3>
<pre class=source>
<div style='color: navy; margin-top: 0; margin-bottom: 0;'>/*************************************************************************
RMS error on the test set given.
FOR USERS OF COMMERCIAL EDITION:
! Commercial version of ALGLIB includes two important improvements of
! this function:
! * multicore support (C++ and C# computational cores)
! * SSE support
!
! First improvement gives close-to-linear speedup on multicore systems.
! Second improvement gives constant speedup (2-3x depending on your CPU)
!
! In order to use multicore features you have to:
! * use commercial version of ALGLIB
! * call this function with "smp_" prefix, which indicates that
! multicore code will be used (for multicore support)
!
! In order to use SSE features you have to:
! * use commercial version of ALGLIB on Intel processors
! * use C++ computational core
!
! This note is given for users of commercial edition; if you use GPL
! edition, you still will be able to call smp-version of this function,
! but all computations will be done serially.
!
! We recommend you to carefully read ALGLIB Reference Manual, section
! called 'SMP support', before using parallel version of this function.
INPUT PARAMETERS:
Network - neural network;
XY - training set, see below for information on the
training set format;
NPoints - points count.
RESULT:
Root mean square error. Its meaning for regression task is obvious. As for
classification task, RMS error means error when estimating posterior
probabilities.
DATASET FORMAT:
This function uses two different dataset formats - one for regression
networks, another one for classification networks.
For regression networks with NIn inputs and NOut outputs following dataset
format is used:
* dataset is given by NPoints*(NIn+NOut) matrix
* each row corresponds to one example
* first NIn columns are inputs, next NOut columns are outputs
For classification networks with NIn inputs and NClasses clases following
dataset format is used:
* dataset is given by NPoints*(NIn+1) matrix
* each row corresponds to one example
* first NIn columns are inputs, last column stores class number (from 0 to
NClasses-1).
-- ALGLIB --
Copyright 04.11.2007 by Bochkanov Sergey
*************************************************************************/
</div><div style='margin-top: 0; margin-bottom: 0;'><b>double</b> alglib::mlprmserror(
multilayerperceptron network,
real_2d_array xy,
ae_int_t npoints);
<b>double</b> alglib::smp_mlprmserror(
multilayerperceptron network,
real_2d_array xy,
ae_int_t npoints);
</div></pre>
<a name='sub_mlprmserrorsparse'></a><h3 class=pageheader><code>mlprmserrorsparse</code> function</h3>
<pre class=source>
<div style='color: navy; margin-top: 0; margin-bottom: 0;'>/*************************************************************************
RMS error on the test set given by sparse matrix.
FOR USERS OF COMMERCIAL EDITION:
! Commercial version of ALGLIB includes two important improvements of
! this function:
! * multicore support (C++ and C# computational cores)
! * SSE support
!
! First improvement gives close-to-linear speedup on multicore systems.
! Second improvement gives constant speedup (2-3x depending on your CPU)
!
! In order to use multicore features you have to:
! * use commercial version of ALGLIB
! * call this function with "smp_" prefix, which indicates that
! multicore code will be used (for multicore support)
!
! In order to use SSE features you have to:
! * use commercial version of ALGLIB on Intel processors
! * use C++ computational core
!
! This note is given for users of commercial edition; if you use GPL
! edition, you still will be able to call smp-version of this function,
! but all computations will be done serially.
!
! We recommend you to carefully read ALGLIB Reference Manual, section
! called 'SMP support', before using parallel version of this function.
INPUT PARAMETERS:
Network - neural network;
XY - training set, see below for information on the
training set format. This function checks correctness
of the dataset (no NANs/INFs, class numbers are
correct) and throws exception when incorrect dataset
is passed. Sparse matrix must use CRS format for
storage.
NPoints - points count, >=0.
RESULT:
Root mean square error. Its meaning for regression task is obvious. As for
classification task, RMS error means error when estimating posterior
probabilities.
DATASET FORMAT:
This function uses two different dataset formats - one for regression
networks, another one for classification networks.
For regression networks with NIn inputs and NOut outputs following dataset
format is used:
* dataset is given by NPoints*(NIn+NOut) matrix
* each row corresponds to one example
* first NIn columns are inputs, next NOut columns are outputs
For classification networks with NIn inputs and NClasses clases following
dataset format is used:
* dataset is given by NPoints*(NIn+1) matrix
* each row corresponds to one example
* first NIn columns are inputs, last column stores class number (from 0 to
NClasses-1).
-- ALGLIB --
Copyright 09.08.2012 by Bochkanov Sergey
*************************************************************************/
</div><div style='margin-top: 0; margin-bottom: 0;'><b>double</b> alglib::mlprmserrorsparse(
multilayerperceptron network,
sparsematrix xy,
ae_int_t npoints);
<b>double</b> alglib::smp_mlprmserrorsparse(
multilayerperceptron network,
sparsematrix xy,
ae_int_t npoints);
</div></pre>
<a name='sub_mlpserialize'></a><h3 class=pageheader><code>mlpserialize</code> function</h3>
<pre class=source>
<div style='color: navy; margin-top: 0; margin-bottom: 0;'>/*************************************************************************
This function serializes data structure to string.
Important properties of s_out:
* it contains alphanumeric characters, dots, underscores, minus signs
* these symbols are grouped into words, which are separated by spaces
and Windows-style (CR+LF) newlines
* although serializer uses spaces and CR+LF as separators, you can
replace any separator character by arbitrary combination of spaces,
tabs, Windows or Unix newlines. It allows flexible reformatting of
the string in case you want to include it into text or XML file.
But you should not insert separators into the middle of the "words"
nor you should change case of letters.
* s_out can be freely moved between 32-bit and 64-bit systems, little
and big endian machines, and so on. You can serialize structure on
32-bit machine and unserialize it on 64-bit one (or vice versa), or
serialize it on SPARC and unserialize on x86. You can also
serialize it in C++ version of ALGLIB and unserialize in C# one,
and vice versa.
*************************************************************************/
</div><div style='margin-top: 0; margin-bottom: 0;'><b>void</b> mlpserialize(multilayerperceptron &obj, std::string &s_out);
</div></pre>
<a name='sub_mlpsetinputscaling'></a><h3 class=pageheader><code>mlpsetinputscaling</code> function</h3>
<pre class=source>
<div style='color: navy; margin-top: 0; margin-bottom: 0;'>/*************************************************************************
This function sets offset/scaling coefficients for I-th input of the
network.
INPUT PARAMETERS:
Network - network
I - input index
Mean - mean term
Sigma - sigma term (if zero, will be replaced by 1.0)
NTE: I-th input is passed through linear transformation
IN[i] = (IN[i]-Mean)/Sigma
before feeding to the network. This function sets Mean and Sigma.
-- ALGLIB --
Copyright 25.03.2011 by Bochkanov Sergey
*************************************************************************/
</div><div style='margin-top: 0; margin-bottom: 0;'><b>void</b> alglib::mlpsetinputscaling(
multilayerperceptron network,
ae_int_t i,
<b>double</b> mean,
<b>double</b> sigma);
</div></pre>
<a name='sub_mlpsetneuroninfo'></a><h3 class=pageheader><code>mlpsetneuroninfo</code> function</h3>
<pre class=source>
<div style='color: navy; margin-top: 0; margin-bottom: 0;'>/*************************************************************************
This function modifies information about Ith neuron of Kth layer
INPUT PARAMETERS:
Network - network
K - layer index
I - neuron index (within layer)
FKind - activation function type (used by MLPActivationFunction())
this value must be zero for input neurons
(you can not set activation function for input neurons)
Threshold - also called offset, bias
this value must be zero for input neurons
(you can not set threshold for input neurons)
NOTES:
1. this function throws exception if layer or neuron with given index do
not exists.
2. this function also throws exception when you try to set non-linear
activation function for input neurons (any kind of network) or for output
neurons of classifier network.
3. this function throws exception when you try to set non-zero threshold for
input neurons (any kind of network).
-- ALGLIB --
Copyright 25.03.2011 by Bochkanov Sergey
*************************************************************************/
</div><div style='margin-top: 0; margin-bottom: 0;'><b>void</b> alglib::mlpsetneuroninfo(
multilayerperceptron network,
ae_int_t k,
ae_int_t i,
ae_int_t fkind,
<b>double</b> threshold);
</div></pre>
<a name='sub_mlpsetoutputscaling'></a><h3 class=pageheader><code>mlpsetoutputscaling</code> function</h3>
<pre class=source>
<div style='color: navy; margin-top: 0; margin-bottom: 0;'>/*************************************************************************
This function sets offset/scaling coefficients for I-th output of the
network.
INPUT PARAMETERS:
Network - network
I - input index
Mean - mean term
Sigma - sigma term (if zero, will be replaced by 1.0)
OUTPUT PARAMETERS:
NOTE: I-th output is passed through linear transformation
OUT[i] = OUT[i]*Sigma+Mean
before returning it to user. This function sets Sigma/Mean. In case we
have SOFTMAX-normalized network, you can not set (Sigma,Mean) to anything
other than(0.0,1.0) - this function will throw exception.
-- ALGLIB --
Copyright 25.03.2011 by Bochkanov Sergey
*************************************************************************/
</div><div style='margin-top: 0; margin-bottom: 0;'><b>void</b> alglib::mlpsetoutputscaling(
multilayerperceptron network,
ae_int_t i,
<b>double</b> mean,
<b>double</b> sigma);
</div></pre>
<a name='sub_mlpsetweight'></a><h3 class=pageheader><code>mlpsetweight</code> function</h3>
<pre class=source>
<div style='color: navy; margin-top: 0; margin-bottom: 0;'>/*************************************************************************
This function modifies information about connection from I0-th neuron of
K0-th layer to I1-th neuron of K1-th layer.
INPUT PARAMETERS:
Network - network
K0 - layer index
I0 - neuron index (within layer)
K1 - layer index
I1 - neuron index (within layer)
W - connection weight (must be zero for non-existent
connections)
This function:
1. throws exception if layer or neuron with given index do not exists.
2. throws exception if you try to set non-zero weight for non-existent
connection
-- ALGLIB --
Copyright 25.03.2011 by Bochkanov Sergey
*************************************************************************/
</div><div style='margin-top: 0; margin-bottom: 0;'><b>void</b> alglib::mlpsetweight(
multilayerperceptron network,
ae_int_t k0,
ae_int_t i0,
ae_int_t k1,
ae_int_t i1,
<b>double</b> w);
</div></pre>
<a name='sub_mlpunserialize'></a><h3 class=pageheader><code>mlpunserialize</code> function</h3>
<pre class=source>
<div style='color: navy; margin-top: 0; margin-bottom: 0;'>/*************************************************************************
This function unserializes data structure from string.
*************************************************************************/
</div><div style='margin-top: 0; margin-bottom: 0;'><b>void</b> mlpunserialize(std::string &s_in, multilayerperceptron &obj);
</div></pre>
<a name=unit_mlpe></a><h2 class=pageheader><code>mlpe</code> subpackage</h2>
<div class=pagecontent>
<h3 class=pageheader>Classes</h3>
<a href='#struct_mlpensemble' class=toc>mlpensemble</a><br>
<h3 class=pageheader>Functions</h3>
<a href='#sub_mlpeavgce' class=toc>mlpeavgce</a><br>
<a href='#sub_mlpeavgerror' class=toc>mlpeavgerror</a><br>
<a href='#sub_mlpeavgrelerror' class=toc>mlpeavgrelerror</a><br>
<a href='#sub_mlpecreate0' class=toc>mlpecreate0</a><br>
<a href='#sub_mlpecreate1' class=toc>mlpecreate1</a><br>
<a href='#sub_mlpecreate2' class=toc>mlpecreate2</a><br>
<a href='#sub_mlpecreateb0' class=toc>mlpecreateb0</a><br>
<a href='#sub_mlpecreateb1' class=toc>mlpecreateb1</a><br>
<a href='#sub_mlpecreateb2' class=toc>mlpecreateb2</a><br>
<a href='#sub_mlpecreatec0' class=toc>mlpecreatec0</a><br>
<a href='#sub_mlpecreatec1' class=toc>mlpecreatec1</a><br>
<a href='#sub_mlpecreatec2' class=toc>mlpecreatec2</a><br>
<a href='#sub_mlpecreatefromnetwork' class=toc>mlpecreatefromnetwork</a><br>
<a href='#sub_mlpecreater0' class=toc>mlpecreater0</a><br>
<a href='#sub_mlpecreater1' class=toc>mlpecreater1</a><br>
<a href='#sub_mlpecreater2' class=toc>mlpecreater2</a><br>
<a href='#sub_mlpeissoftmax' class=toc>mlpeissoftmax</a><br>
<a href='#sub_mlpeprocess' class=toc>mlpeprocess</a><br>
<a href='#sub_mlpeprocessi' class=toc>mlpeprocessi</a><br>
<a href='#sub_mlpeproperties' class=toc>mlpeproperties</a><br>
<a href='#sub_mlperandomize' class=toc>mlperandomize</a><br>
<a href='#sub_mlperelclserror' class=toc>mlperelclserror</a><br>
<a href='#sub_mlpermserror' class=toc>mlpermserror</a><br>
<a href='#sub_mlpeserialize' class=toc>mlpeserialize</a><br>
<a href='#sub_mlpeunserialize' class=toc>mlpeunserialize</a><br>
<h3 class=pageheader>Examples</h3>
<table border=0 cellspacing=0 class='pagecontent'>
</table></div>
<a name='struct_mlpensemble'></a><h3 class=pageheader><code>mlpensemble</code> class</h3>
<pre class=source>
<div style='color: navy; margin-top: 0; margin-bottom: 0;'>/*************************************************************************
Neural networks ensemble
*************************************************************************/
</div><div style='margin-top: 0; margin-bottom: 0;'><b>class</b> mlpensemble
{
};
</div></pre>
<a name='sub_mlpeavgce'></a><h3 class=pageheader><code>mlpeavgce</code> function</h3>
<pre class=source>
<div style='color: navy; margin-top: 0; margin-bottom: 0;'>/*************************************************************************
Average cross-entropy (in bits per element) on the test set
INPUT PARAMETERS:
Ensemble- ensemble
XY - test set
NPoints - test set size
RESULT:
CrossEntropy/(NPoints*LN(2)).
Zero if ensemble solves regression task.
-- ALGLIB --
Copyright 17.02.2009 by Bochkanov Sergey
*************************************************************************/
</div><div style='margin-top: 0; margin-bottom: 0;'><b>double</b> alglib::mlpeavgce(
mlpensemble ensemble,
real_2d_array xy,
ae_int_t npoints);
</div></pre>
<a name='sub_mlpeavgerror'></a><h3 class=pageheader><code>mlpeavgerror</code> function</h3>
<pre class=source>
<div style='color: navy; margin-top: 0; margin-bottom: 0;'>/*************************************************************************
Average error on the test set
INPUT PARAMETERS:
Ensemble- ensemble
XY - test set
NPoints - test set size
RESULT:
Its meaning for regression task is obvious. As for classification task
it means average error when estimating posterior probabilities.
-- ALGLIB --
Copyright 17.02.2009 by Bochkanov Sergey
*************************************************************************/
</div><div style='margin-top: 0; margin-bottom: 0;'><b>double</b> alglib::mlpeavgerror(
mlpensemble ensemble,
real_2d_array xy,
ae_int_t npoints);
</div></pre>
<a name='sub_mlpeavgrelerror'></a><h3 class=pageheader><code>mlpeavgrelerror</code> function</h3>
<pre class=source>
<div style='color: navy; margin-top: 0; margin-bottom: 0;'>/*************************************************************************
Average relative error on the test set
INPUT PARAMETERS:
Ensemble- ensemble
XY - test set
NPoints - test set size
RESULT:
Its meaning for regression task is obvious. As for classification task
it means average relative error when estimating posterior probabilities.
-- ALGLIB --
Copyright 17.02.2009 by Bochkanov Sergey
*************************************************************************/
</div><div style='margin-top: 0; margin-bottom: 0;'><b>double</b> alglib::mlpeavgrelerror(
mlpensemble ensemble,
real_2d_array xy,
ae_int_t npoints);
</div></pre>
<a name='sub_mlpecreate0'></a><h3 class=pageheader><code>mlpecreate0</code> function</h3>
<pre class=source>
<div style='color: navy; margin-top: 0; margin-bottom: 0;'>/*************************************************************************
Like MLPCreate0, but for ensembles.
-- ALGLIB --
Copyright 18.02.2009 by Bochkanov Sergey
*************************************************************************/
</div><div style='margin-top: 0; margin-bottom: 0;'><b>void</b> alglib::mlpecreate0(
ae_int_t nin,
ae_int_t nout,
ae_int_t ensemblesize,
mlpensemble& ensemble);
</div></pre>
<a name='sub_mlpecreate1'></a><h3 class=pageheader><code>mlpecreate1</code> function</h3>
<pre class=source>
<div style='color: navy; margin-top: 0; margin-bottom: 0;'>/*************************************************************************
Like MLPCreate1, but for ensembles.
-- ALGLIB --
Copyright 18.02.2009 by Bochkanov Sergey
*************************************************************************/
</div><div style='margin-top: 0; margin-bottom: 0;'><b>void</b> alglib::mlpecreate1(
ae_int_t nin,
ae_int_t nhid,
ae_int_t nout,
ae_int_t ensemblesize,
mlpensemble& ensemble);
</div></pre>
<a name='sub_mlpecreate2'></a><h3 class=pageheader><code>mlpecreate2</code> function</h3>
<pre class=source>
<div style='color: navy; margin-top: 0; margin-bottom: 0;'>/*************************************************************************
Like MLPCreate2, but for ensembles.
-- ALGLIB --
Copyright 18.02.2009 by Bochkanov Sergey
*************************************************************************/
</div><div style='margin-top: 0; margin-bottom: 0;'><b>void</b> alglib::mlpecreate2(
ae_int_t nin,
ae_int_t nhid1,
ae_int_t nhid2,
ae_int_t nout,
ae_int_t ensemblesize,
mlpensemble& ensemble);
</div></pre>
<a name='sub_mlpecreateb0'></a><h3 class=pageheader><code>mlpecreateb0</code> function</h3>
<pre class=source>
<div style='color: navy; margin-top: 0; margin-bottom: 0;'>/*************************************************************************
Like MLPCreateB0, but for ensembles.
-- ALGLIB --
Copyright 18.02.2009 by Bochkanov Sergey
*************************************************************************/
</div><div style='margin-top: 0; margin-bottom: 0;'><b>void</b> alglib::mlpecreateb0(
ae_int_t nin,
ae_int_t nout,
<b>double</b> b,
<b>double</b> d,
ae_int_t ensemblesize,
mlpensemble& ensemble);
</div></pre>
<a name='sub_mlpecreateb1'></a><h3 class=pageheader><code>mlpecreateb1</code> function</h3>
<pre class=source>
<div style='color: navy; margin-top: 0; margin-bottom: 0;'>/*************************************************************************
Like MLPCreateB1, but for ensembles.
-- ALGLIB --
Copyright 18.02.2009 by Bochkanov Sergey
*************************************************************************/
</div><div style='margin-top: 0; margin-bottom: 0;'><b>void</b> alglib::mlpecreateb1(
ae_int_t nin,
ae_int_t nhid,
ae_int_t nout,
<b>double</b> b,
<b>double</b> d,
ae_int_t ensemblesize,
mlpensemble& ensemble);
</div></pre>
<a name='sub_mlpecreateb2'></a><h3 class=pageheader><code>mlpecreateb2</code> function</h3>
<pre class=source>
<div style='color: navy; margin-top: 0; margin-bottom: 0;'>/*************************************************************************
Like MLPCreateB2, but for ensembles.
-- ALGLIB --
Copyright 18.02.2009 by Bochkanov Sergey
*************************************************************************/
</div><div style='margin-top: 0; margin-bottom: 0;'><b>void</b> alglib::mlpecreateb2(
ae_int_t nin,
ae_int_t nhid1,
ae_int_t nhid2,
ae_int_t nout,
<b>double</b> b,
<b>double</b> d,
ae_int_t ensemblesize,
mlpensemble& ensemble);
</div></pre>
<a name='sub_mlpecreatec0'></a><h3 class=pageheader><code>mlpecreatec0</code> function</h3>
<pre class=source>
<div style='color: navy; margin-top: 0; margin-bottom: 0;'>/*************************************************************************
Like MLPCreateC0, but for ensembles.
-- ALGLIB --
Copyright 18.02.2009 by Bochkanov Sergey
*************************************************************************/
</div><div style='margin-top: 0; margin-bottom: 0;'><b>void</b> alglib::mlpecreatec0(
ae_int_t nin,
ae_int_t nout,
ae_int_t ensemblesize,
mlpensemble& ensemble);
</div></pre>
<a name='sub_mlpecreatec1'></a><h3 class=pageheader><code>mlpecreatec1</code> function</h3>
<pre class=source>
<div style='color: navy; margin-top: 0; margin-bottom: 0;'>/*************************************************************************
Like MLPCreateC1, but for ensembles.
-- ALGLIB --
Copyright 18.02.2009 by Bochkanov Sergey
*************************************************************************/
</div><div style='margin-top: 0; margin-bottom: 0;'><b>void</b> alglib::mlpecreatec1(
ae_int_t nin,
ae_int_t nhid,
ae_int_t nout,
ae_int_t ensemblesize,
mlpensemble& ensemble);
</div></pre>
<a name='sub_mlpecreatec2'></a><h3 class=pageheader><code>mlpecreatec2</code> function</h3>
<pre class=source>
<div style='color: navy; margin-top: 0; margin-bottom: 0;'>/*************************************************************************
Like MLPCreateC2, but for ensembles.
-- ALGLIB --
Copyright 18.02.2009 by Bochkanov Sergey
*************************************************************************/
</div><div style='margin-top: 0; margin-bottom: 0;'><b>void</b> alglib::mlpecreatec2(
ae_int_t nin,
ae_int_t nhid1,
ae_int_t nhid2,
ae_int_t nout,
ae_int_t ensemblesize,
mlpensemble& ensemble);
</div></pre>
<a name='sub_mlpecreatefromnetwork'></a><h3 class=pageheader><code>mlpecreatefromnetwork</code> function</h3>
<pre class=source>
<div style='color: navy; margin-top: 0; margin-bottom: 0;'>/*************************************************************************
Creates ensemble from network. Only network geometry is copied.
-- ALGLIB --
Copyright 17.02.2009 by Bochkanov Sergey
*************************************************************************/
</div><div style='margin-top: 0; margin-bottom: 0;'><b>void</b> alglib::mlpecreatefromnetwork(
multilayerperceptron network,
ae_int_t ensemblesize,
mlpensemble& ensemble);
</div></pre>
<a name='sub_mlpecreater0'></a><h3 class=pageheader><code>mlpecreater0</code> function</h3>
<pre class=source>
<div style='color: navy; margin-top: 0; margin-bottom: 0;'>/*************************************************************************
Like MLPCreateR0, but for ensembles.
-- ALGLIB --
Copyright 18.02.2009 by Bochkanov Sergey
*************************************************************************/
</div><div style='margin-top: 0; margin-bottom: 0;'><b>void</b> alglib::mlpecreater0(
ae_int_t nin,
ae_int_t nout,
<b>double</b> a,
<b>double</b> b,
ae_int_t ensemblesize,
mlpensemble& ensemble);
</div></pre>
<a name='sub_mlpecreater1'></a><h3 class=pageheader><code>mlpecreater1</code> function</h3>
<pre class=source>
<div style='color: navy; margin-top: 0; margin-bottom: 0;'>/*************************************************************************
Like MLPCreateR1, but for ensembles.
-- ALGLIB --
Copyright 18.02.2009 by Bochkanov Sergey
*************************************************************************/
</div><div style='margin-top: 0; margin-bottom: 0;'><b>void</b> alglib::mlpecreater1(
ae_int_t nin,
ae_int_t nhid,
ae_int_t nout,
<b>double</b> a,
<b>double</b> b,
ae_int_t ensemblesize,
mlpensemble& ensemble);
</div></pre>
<a name='sub_mlpecreater2'></a><h3 class=pageheader><code>mlpecreater2</code> function</h3>
<pre class=source>
<div style='color: navy; margin-top: 0; margin-bottom: 0;'>/*************************************************************************
Like MLPCreateR2, but for ensembles.
-- ALGLIB --
Copyright 18.02.2009 by Bochkanov Sergey
*************************************************************************/
</div><div style='margin-top: 0; margin-bottom: 0;'><b>void</b> alglib::mlpecreater2(
ae_int_t nin,
ae_int_t nhid1,
ae_int_t nhid2,
ae_int_t nout,
<b>double</b> a,
<b>double</b> b,
ae_int_t ensemblesize,
mlpensemble& ensemble);
</div></pre>
<a name='sub_mlpeissoftmax'></a><h3 class=pageheader><code>mlpeissoftmax</code> function</h3>
<pre class=source>
<div style='color: navy; margin-top: 0; margin-bottom: 0;'>/*************************************************************************
Return normalization type (whether ensemble is SOFTMAX-normalized or not).
-- ALGLIB --
Copyright 17.02.2009 by Bochkanov Sergey
*************************************************************************/
</div><div style='margin-top: 0; margin-bottom: 0;'><b>bool</b> alglib::mlpeissoftmax(mlpensemble ensemble);
</div></pre>
<a name='sub_mlpeprocess'></a><h3 class=pageheader><code>mlpeprocess</code> function</h3>
<pre class=source>
<div style='color: navy; margin-top: 0; margin-bottom: 0;'>/*************************************************************************
Procesing
INPUT PARAMETERS:
Ensemble- neural networks ensemble
X - input vector, array[0..NIn-1].
Y - (possibly) preallocated buffer; if size of Y is less than
NOut, it will be reallocated. If it is large enough, it
is NOT reallocated, so we can save some time on reallocation.
OUTPUT PARAMETERS:
Y - result. Regression estimate when solving regression task,
vector of posterior probabilities for classification task.
-- ALGLIB --
Copyright 17.02.2009 by Bochkanov Sergey
*************************************************************************/
</div><div style='margin-top: 0; margin-bottom: 0;'><b>void</b> alglib::mlpeprocess(
mlpensemble ensemble,
real_1d_array x,
real_1d_array& y);
</div></pre>
<a name='sub_mlpeprocessi'></a><h3 class=pageheader><code>mlpeprocessi</code> function</h3>
<pre class=source>
<div style='color: navy; margin-top: 0; margin-bottom: 0;'>/*************************************************************************
'interactive' variant of MLPEProcess for languages like Python which
support constructs like "Y = MLPEProcess(LM,X)" and interactive mode of the
interpreter
This function allocates new array on each call, so it is significantly
slower than its 'non-interactive' counterpart, but it is more convenient
when you call it from command line.
-- ALGLIB --
Copyright 17.02.2009 by Bochkanov Sergey
*************************************************************************/
</div><div style='margin-top: 0; margin-bottom: 0;'><b>void</b> alglib::mlpeprocessi(
mlpensemble ensemble,
real_1d_array x,
real_1d_array& y);
</div></pre>
<a name='sub_mlpeproperties'></a><h3 class=pageheader><code>mlpeproperties</code> function</h3>
<pre class=source>
<div style='color: navy; margin-top: 0; margin-bottom: 0;'>/*************************************************************************
Return ensemble properties (number of inputs and outputs).
-- ALGLIB --
Copyright 17.02.2009 by Bochkanov Sergey
*************************************************************************/
</div><div style='margin-top: 0; margin-bottom: 0;'><b>void</b> alglib::mlpeproperties(
mlpensemble ensemble,
ae_int_t& nin,
ae_int_t& nout);
</div></pre>
<a name='sub_mlperandomize'></a><h3 class=pageheader><code>mlperandomize</code> function</h3>
<pre class=source>
<div style='color: navy; margin-top: 0; margin-bottom: 0;'>/*************************************************************************
Randomization of MLP ensemble
-- ALGLIB --
Copyright 17.02.2009 by Bochkanov Sergey
*************************************************************************/
</div><div style='margin-top: 0; margin-bottom: 0;'><b>void</b> alglib::mlperandomize(mlpensemble ensemble);
</div></pre>
<a name='sub_mlperelclserror'></a><h3 class=pageheader><code>mlperelclserror</code> function</h3>
<pre class=source>
<div style='color: navy; margin-top: 0; margin-bottom: 0;'>/*************************************************************************
Relative classification error on the test set
INPUT PARAMETERS:
Ensemble- ensemble
XY - test set
NPoints - test set size
RESULT:
percent of incorrectly classified cases.
Works both for classifier betwork and for regression networks which
are used as classifiers.
-- ALGLIB --
Copyright 17.02.2009 by Bochkanov Sergey
*************************************************************************/
</div><div style='margin-top: 0; margin-bottom: 0;'><b>double</b> alglib::mlperelclserror(
mlpensemble ensemble,
real_2d_array xy,
ae_int_t npoints);
</div></pre>
<a name='sub_mlpermserror'></a><h3 class=pageheader><code>mlpermserror</code> function</h3>
<pre class=source>
<div style='color: navy; margin-top: 0; margin-bottom: 0;'>/*************************************************************************
RMS error on the test set
INPUT PARAMETERS:
Ensemble- ensemble
XY - test set
NPoints - test set size
RESULT:
root mean square error.
Its meaning for regression task is obvious. As for classification task
RMS error means error when estimating posterior probabilities.
-- ALGLIB --
Copyright 17.02.2009 by Bochkanov Sergey
*************************************************************************/
</div><div style='margin-top: 0; margin-bottom: 0;'><b>double</b> alglib::mlpermserror(
mlpensemble ensemble,
real_2d_array xy,
ae_int_t npoints);
</div></pre>
<a name='sub_mlpeserialize'></a><h3 class=pageheader><code>mlpeserialize</code> function</h3>
<pre class=source>
<div style='color: navy; margin-top: 0; margin-bottom: 0;'>/*************************************************************************
This function serializes data structure to string.
Important properties of s_out:
* it contains alphanumeric characters, dots, underscores, minus signs
* these symbols are grouped into words, which are separated by spaces
and Windows-style (CR+LF) newlines
* although serializer uses spaces and CR+LF as separators, you can
replace any separator character by arbitrary combination of spaces,
tabs, Windows or Unix newlines. It allows flexible reformatting of
the string in case you want to include it into text or XML file.
But you should not insert separators into the middle of the "words"
nor you should change case of letters.
* s_out can be freely moved between 32-bit and 64-bit systems, little
and big endian machines, and so on. You can serialize structure on
32-bit machine and unserialize it on 64-bit one (or vice versa), or
serialize it on SPARC and unserialize on x86. You can also
serialize it in C++ version of ALGLIB and unserialize in C# one,
and vice versa.
*************************************************************************/
</div><div style='margin-top: 0; margin-bottom: 0;'><b>void</b> mlpeserialize(mlpensemble &obj, std::string &s_out);
</div></pre>
<a name='sub_mlpeunserialize'></a><h3 class=pageheader><code>mlpeunserialize</code> function</h3>
<pre class=source>
<div style='color: navy; margin-top: 0; margin-bottom: 0;'>/*************************************************************************
This function unserializes data structure from string.
*************************************************************************/
</div><div style='margin-top: 0; margin-bottom: 0;'><b>void</b> mlpeunserialize(std::string &s_in, mlpensemble &obj);
</div></pre>
<a name=unit_mlptrain></a><h2 class=pageheader><code>mlptrain</code> subpackage</h2>
<div class=pagecontent>
<h3 class=pageheader>Classes</h3>
<a href='#struct_mlpcvreport' class=toc>mlpcvreport</a><br>
<a href='#struct_mlpreport' class=toc>mlpreport</a><br>
<a href='#struct_mlptrainer' class=toc>mlptrainer</a><br>
<h3 class=pageheader>Functions</h3>
<a href='#sub_mlpcontinuetraining' class=toc>mlpcontinuetraining</a><br>
<a href='#sub_mlpcreatetrainer' class=toc>mlpcreatetrainer</a><br>
<a href='#sub_mlpcreatetrainercls' class=toc>mlpcreatetrainercls</a><br>
<a href='#sub_mlpebagginglbfgs' class=toc>mlpebagginglbfgs</a><br>
<a href='#sub_mlpebagginglm' class=toc>mlpebagginglm</a><br>
<a href='#sub_mlpetraines' class=toc>mlpetraines</a><br>
<a href='#sub_mlpkfoldcv' class=toc>mlpkfoldcv</a><br>
<a href='#sub_mlpkfoldcvlbfgs' class=toc>mlpkfoldcvlbfgs</a><br>
<a href='#sub_mlpkfoldcvlm' class=toc>mlpkfoldcvlm</a><br>
<a href='#sub_mlpsetalgobatch' class=toc>mlpsetalgobatch</a><br>
<a href='#sub_mlpsetcond' class=toc>mlpsetcond</a><br>
<a href='#sub_mlpsetdataset' class=toc>mlpsetdataset</a><br>
<a href='#sub_mlpsetdecay' class=toc>mlpsetdecay</a><br>
<a href='#sub_mlpsetsparsedataset' class=toc>mlpsetsparsedataset</a><br>
<a href='#sub_mlpstarttraining' class=toc>mlpstarttraining</a><br>
<a href='#sub_mlptrainensemblees' class=toc>mlptrainensemblees</a><br>
<a href='#sub_mlptraines' class=toc>mlptraines</a><br>
<a href='#sub_mlptrainlbfgs' class=toc>mlptrainlbfgs</a><br>
<a href='#sub_mlptrainlm' class=toc>mlptrainlm</a><br>
<a href='#sub_mlptrainnetwork' class=toc>mlptrainnetwork</a><br>
<h3 class=pageheader>Examples</h3>
<table border=0 cellspacing=0 class='pagecontent'>
<tr align=left valign=top><td><a href='#example_nn_cls2' class=toc>nn_cls2</a></td><td width=15> </td><td>Binary classification problem</td></tr>
<tr align=left valign=top><td><a href='#example_nn_cls3' class=toc>nn_cls3</a></td><td width=15> </td><td>Multiclass classification problem</td></tr>
<tr align=left valign=top><td><a href='#example_nn_crossvalidation' class=toc>nn_crossvalidation</a></td><td width=15> </td><td>Cross-validation</td></tr>
<tr align=left valign=top><td><a href='#example_nn_ensembles_es' class=toc>nn_ensembles_es</a></td><td width=15> </td><td>Early stopping ensembles</td></tr>
<tr align=left valign=top><td><a href='#example_nn_parallel' class=toc>nn_parallel</a></td><td width=15> </td><td>Parallel training</td></tr>
<tr align=left valign=top><td><a href='#example_nn_regr' class=toc>nn_regr</a></td><td width=15> </td><td>Regression problem with one output (2=>1)</td></tr>
<tr align=left valign=top><td><a href='#example_nn_regr_n' class=toc>nn_regr_n</a></td><td width=15> </td><td>Regression problem with multiple outputs (2=>2)</td></tr>
<tr align=left valign=top><td><a href='#example_nn_trainerobject' class=toc>nn_trainerobject</a></td><td width=15> </td><td>Advanced example on trainer object</td></tr>
</table></div>
<a name='struct_mlpcvreport'></a><h3 class=pageheader><code>mlpcvreport</code> class</h3>
<pre class=source>
<div style='color: navy; margin-top: 0; margin-bottom: 0;'>/*************************************************************************
Cross-validation estimates of generalization error
*************************************************************************/
</div><div style='margin-top: 0; margin-bottom: 0;'><b>class</b> mlpcvreport
{
<b>double</b> relclserror;
<b>double</b> avgce;
<b>double</b> rmserror;
<b>double</b> avgerror;
<b>double</b> avgrelerror;
};
</div></pre>
<a name='struct_mlpreport'></a><h3 class=pageheader><code>mlpreport</code> class</h3>
<pre class=source>
<div style='color: navy; margin-top: 0; margin-bottom: 0;'>/*************************************************************************
Training report:
* RelCLSError - fraction of misclassified cases.
* AvgCE - acerage cross-entropy
* RMSError - root-mean-square error
* AvgError - average error
* AvgRelError - average relative error
* NGrad - number of gradient calculations
* NHess - number of Hessian calculations
* NCholesky - number of Cholesky decompositions
NOTE 1: RelCLSError/AvgCE are zero on regression problems.
NOTE 2: on classification problems RMSError/AvgError/AvgRelError contain
errors in prediction of posterior probabilities
*************************************************************************/
</div><div style='margin-top: 0; margin-bottom: 0;'><b>class</b> mlpreport
{
<b>double</b> relclserror;
<b>double</b> avgce;
<b>double</b> rmserror;
<b>double</b> avgerror;
<b>double</b> avgrelerror;
ae_int_t ngrad;
ae_int_t nhess;
ae_int_t ncholesky;
};
</div></pre>
<a name='struct_mlptrainer'></a><h3 class=pageheader><code>mlptrainer</code> class</h3>
<pre class=source>
<div style='color: navy; margin-top: 0; margin-bottom: 0;'>/*************************************************************************
Trainer object for neural network.
You should not try to access fields of this object directly - use ALGLIB
functions to work with this object.
*************************************************************************/
</div><div style='margin-top: 0; margin-bottom: 0;'><b>class</b> mlptrainer
{
};
</div></pre>
<a name='sub_mlpcontinuetraining'></a><h3 class=pageheader><code>mlpcontinuetraining</code> function</h3>
<pre class=source>
<div style='color: navy; margin-top: 0; margin-bottom: 0;'>/*************************************************************************
IMPORTANT: this is an "expert" version of the MLPTrain() function. We do
not recommend you to use it unless you are pretty sure that you
need ability to monitor training progress.
FOR USERS OF COMMERCIAL EDITION:
! Commercial version of ALGLIB includes two important improvements of
! this function:
! * multicore support (C++ and C# computational cores)
! * SSE support (C++ computational core)
!
! Second improvement gives constant speedup (2-3X). First improvement
! gives close-to-linear speedup on multicore systems. Following
! operations can be executed in parallel:
! * gradient calculation over large dataset (if dataset is large enough)
!
! In order to use multicore features you have to:
! * use commercial version of ALGLIB
! * call this function with "smp_" prefix, which indicates that
! multicore code will be used (for multicore support)
!
! In order to use SSE features you have to:
! * use commercial version of ALGLIB on Intel processors
! * use C++ computational core
!
! This note is given for users of commercial edition; if you use GPL
! edition, you still will be able to call smp-version of this function,
! but all computations will be done serially.
!
! We recommend you to carefully read ALGLIB Reference Manual, section
! called 'SMP support', before using parallel version of this function.
This function performs step-by-step training of the neural network. Here
"step-by-step" means that training starts with MLPStartTraining() call,
and then user subsequently calls MLPContinueTraining() to perform one more
iteration of the training.
This function performs one more iteration of the training and returns
either True (training continues) or False (training stopped). In case True
was returned, Network weights are updated according to the current state
of the optimization progress. In case False was returned, no additional
updates is performed (previous update of the network weights moved us to
the final point, and no additional updates is needed).
EXAMPLE:
>
> [initialize network and trainer object]
>
> MLPStartTraining(Trainer, Network, True)
> while MLPContinueTraining(Trainer, Network) do
> [visualize training progress]
>
INPUT PARAMETERS:
S - trainer object
Network - neural network structure, which is used to store
current state of the training process.
OUTPUT PARAMETERS:
Network - weights of the neural network are rewritten by the
current approximation.
NOTE: this method uses sum-of-squares error function for training.
NOTE: it is expected that trainer object settings are NOT changed during
step-by-step training, i.e. no one changes stopping criteria or
training set during training. It is possible and there is no defense
against such actions, but algorithm behavior in such cases is
undefined and can be unpredictable.
NOTE: It is expected that Network is the same one which was passed to
MLPStartTraining() function. However, THIS function checks only
following:
* that number of network inputs is consistent with trainer object
settings
* that number of network outputs/classes is consistent with trainer
object settings
* that number of network weights is the same as number of weights in
the network passed to MLPStartTraining() function
Exception is thrown when these conditions are violated.
It is also expected that you do not change state of the network on
your own - the only party who has right to change network during its
training is a trainer object. Any attempt to interfere with trainer
may lead to unpredictable results.
-- ALGLIB --
Copyright 23.07.2012 by Bochkanov Sergey
*************************************************************************/
</div><div style='margin-top: 0; margin-bottom: 0;'><b>bool</b> alglib::mlpcontinuetraining(
mlptrainer s,
multilayerperceptron network);
<b>bool</b> alglib::smp_mlpcontinuetraining(
mlptrainer s,
multilayerperceptron network);
</div></pre>
<a name='sub_mlpcreatetrainer'></a><h3 class=pageheader><code>mlpcreatetrainer</code> function</h3>
<pre class=source>
<div style='color: navy; margin-top: 0; margin-bottom: 0;'>/*************************************************************************
Creation of the network trainer object for regression networks
INPUT PARAMETERS:
NIn - number of inputs, NIn>=1
NOut - number of outputs, NOut>=1
OUTPUT PARAMETERS:
S - neural network trainer object.
This structure can be used to train any regression
network with NIn inputs and NOut outputs.
-- ALGLIB --
Copyright 23.07.2012 by Bochkanov Sergey
*************************************************************************/
</div><div style='margin-top: 0; margin-bottom: 0;'><b>void</b> alglib::mlpcreatetrainer(ae_int_t nin, ae_int_t nout, mlptrainer& s);
</div></pre>
<p align=left class=pagecontent><span class=inlineheader>Examples:</span> <a href='#example_nn_regr' class=nav>[1]</a> <a href='#example_nn_regr_n' class=nav>[2]</a> <a href='#example_nn_trainerobject' class=nav>[3]</a> <a href='#example_nn_crossvalidation' class=nav>[4]</a> <a href='#example_nn_ensembles_es' class=nav>[5]</a> <a href='#example_nn_parallel' class=nav>[6]</a> </p>
<a name='sub_mlpcreatetrainercls'></a><h3 class=pageheader><code>mlpcreatetrainercls</code> function</h3>
<pre class=source>
<div style='color: navy; margin-top: 0; margin-bottom: 0;'>/*************************************************************************
Creation of the network trainer object for classification networks
INPUT PARAMETERS:
NIn - number of inputs, NIn>=1
NClasses - number of classes, NClasses>=2
OUTPUT PARAMETERS:
S - neural network trainer object.
This structure can be used to train any classification
network with NIn inputs and NOut outputs.
-- ALGLIB --
Copyright 23.07.2012 by Bochkanov Sergey
*************************************************************************/
</div><div style='margin-top: 0; margin-bottom: 0;'><b>void</b> alglib::mlpcreatetrainercls(
ae_int_t nin,
ae_int_t nclasses,
mlptrainer& s);
</div></pre>
<p align=left class=pagecontent><span class=inlineheader>Examples:</span> <a href='#example_nn_cls2' class=nav>[1]</a> <a href='#example_nn_cls3' class=nav>[2]</a> </p>
<a name='sub_mlpebagginglbfgs'></a><h3 class=pageheader><code>mlpebagginglbfgs</code> function</h3>
<pre class=source>
<div style='color: navy; margin-top: 0; margin-bottom: 0;'>/*************************************************************************
Training neural networks ensemble using bootstrap aggregating (bagging).
L-BFGS algorithm is used as base training method.
INPUT PARAMETERS:
Ensemble - model with initialized geometry
XY - training set
NPoints - training set size
Decay - weight decay coefficient, >=0.001
Restarts - restarts, >0.
WStep - stopping criterion, same as in MLPTrainLBFGS
MaxIts - stopping criterion, same as in MLPTrainLBFGS
OUTPUT PARAMETERS:
Ensemble - trained model
Info - return code:
* -8, if both WStep=0 and MaxIts=0
* -2, if there is a point with class number
outside of [0..NClasses-1].
* -1, if incorrect parameters was passed
(NPoints<0, Restarts<1).
* 2, if task has been solved.
Rep - training report.
OOBErrors - out-of-bag generalization error estimate
-- ALGLIB --
Copyright 17.02.2009 by Bochkanov Sergey
*************************************************************************/
</div><div style='margin-top: 0; margin-bottom: 0;'><b>void</b> alglib::mlpebagginglbfgs(
mlpensemble ensemble,
real_2d_array xy,
ae_int_t npoints,
<b>double</b> decay,
ae_int_t restarts,
<b>double</b> wstep,
ae_int_t maxits,
ae_int_t& info,
mlpreport& rep,
mlpcvreport& ooberrors);
</div></pre>
<a name='sub_mlpebagginglm'></a><h3 class=pageheader><code>mlpebagginglm</code> function</h3>
<pre class=source>
<div style='color: navy; margin-top: 0; margin-bottom: 0;'>/*************************************************************************
Training neural networks ensemble using bootstrap aggregating (bagging).
Modified Levenberg-Marquardt algorithm is used as base training method.
INPUT PARAMETERS:
Ensemble - model with initialized geometry
XY - training set
NPoints - training set size
Decay - weight decay coefficient, >=0.001
Restarts - restarts, >0.
OUTPUT PARAMETERS:
Ensemble - trained model
Info - return code:
* -2, if there is a point with class number
outside of [0..NClasses-1].
* -1, if incorrect parameters was passed
(NPoints<0, Restarts<1).
* 2, if task has been solved.
Rep - training report.
OOBErrors - out-of-bag generalization error estimate
-- ALGLIB --
Copyright 17.02.2009 by Bochkanov Sergey
*************************************************************************/
</div><div style='margin-top: 0; margin-bottom: 0;'><b>void</b> alglib::mlpebagginglm(
mlpensemble ensemble,
real_2d_array xy,
ae_int_t npoints,
<b>double</b> decay,
ae_int_t restarts,
ae_int_t& info,
mlpreport& rep,
mlpcvreport& ooberrors);
</div></pre>
<a name='sub_mlpetraines'></a><h3 class=pageheader><code>mlpetraines</code> function</h3>
<pre class=source>
<div style='color: navy; margin-top: 0; margin-bottom: 0;'>/*************************************************************************
Training neural networks ensemble using early stopping.
INPUT PARAMETERS:
Ensemble - model with initialized geometry
XY - training set
NPoints - training set size
Decay - weight decay coefficient, >=0.001
Restarts - restarts, >0.
OUTPUT PARAMETERS:
Ensemble - trained model
Info - return code:
* -2, if there is a point with class number
outside of [0..NClasses-1].
* -1, if incorrect parameters was passed
(NPoints<0, Restarts<1).
* 6, if task has been solved.
Rep - training report.
OOBErrors - out-of-bag generalization error estimate
-- ALGLIB --
Copyright 10.03.2009 by Bochkanov Sergey
*************************************************************************/
</div><div style='margin-top: 0; margin-bottom: 0;'><b>void</b> alglib::mlpetraines(
mlpensemble ensemble,
real_2d_array xy,
ae_int_t npoints,
<b>double</b> decay,
ae_int_t restarts,
ae_int_t& info,
mlpreport& rep);
</div></pre>
<a name='sub_mlpkfoldcv'></a><h3 class=pageheader><code>mlpkfoldcv</code> function</h3>
<pre class=source>
<div style='color: navy; margin-top: 0; margin-bottom: 0;'>/*************************************************************************
This function estimates generalization error using cross-validation on the
current dataset with current training settings.
FOR USERS OF COMMERCIAL EDITION:
! Commercial version of ALGLIB includes two important improvements of
! this function:
! * multicore support (C++ and C# computational cores)
! * SSE support (C++ computational core)
!
! Second improvement gives constant speedup (2-3X). First improvement
! gives close-to-linear speedup on multicore systems. Following
! operations can be executed in parallel:
! * FoldsCount cross-validation rounds (always)
! * NRestarts training sessions performed within each of
! cross-validation rounds (if NRestarts>1)
! * gradient calculation over large dataset (if dataset is large enough)
!
! In order to use multicore features you have to:
! * use commercial version of ALGLIB
! * call this function with "smp_" prefix, which indicates that
! multicore code will be used (for multicore support)
!
! In order to use SSE features you have to:
! * use commercial version of ALGLIB on Intel processors
! * use C++ computational core
!
! This note is given for users of commercial edition; if you use GPL
! edition, you still will be able to call smp-version of this function,
! but all computations will be done serially.
!
! We recommend you to carefully read ALGLIB Reference Manual, section
! called 'SMP support', before using parallel version of this function.
INPUT PARAMETERS:
S - trainer object
Network - neural network. It must have same number of inputs and
output/classes as was specified during creation of the
trainer object. Network is not changed during cross-
validation and is not trained - it is used only as
representative of its architecture. I.e., we estimate
generalization properties of ARCHITECTURE, not some
specific network.
NRestarts - number of restarts, >=0:
* NRestarts>0 means that for each cross-validation
round specified number of random restarts is
performed, with best network being chosen after
training.
* NRestarts=0 is same as NRestarts=1
FoldsCount - number of folds in k-fold cross-validation:
* 2<=FoldsCount<=size of dataset
* recommended value: 10.
* values larger than dataset size will be silently
truncated down to dataset size
OUTPUT PARAMETERS:
Rep - structure which contains cross-validation estimates:
* Rep.RelCLSError - fraction of misclassified cases.
* Rep.AvgCE - acerage cross-entropy
* Rep.RMSError - root-mean-square error
* Rep.AvgError - average error
* Rep.AvgRelError - average relative error
NOTE: when no dataset was specified with MLPSetDataset/SetSparseDataset(),
or subset with only one point was given, zeros are returned as
estimates.
NOTE: this method performs FoldsCount cross-validation rounds, each one
with NRestarts random starts. Thus, FoldsCount*NRestarts networks
are trained in total.
NOTE: Rep.RelCLSError/Rep.AvgCE are zero on regression problems.
NOTE: on classification problems Rep.RMSError/Rep.AvgError/Rep.AvgRelError
contain errors in prediction of posterior probabilities.
-- ALGLIB --
Copyright 23.07.2012 by Bochkanov Sergey
*************************************************************************/
</div><div style='margin-top: 0; margin-bottom: 0;'><b>void</b> alglib::mlpkfoldcv(
mlptrainer s,
multilayerperceptron network,
ae_int_t nrestarts,
ae_int_t foldscount,
mlpreport& rep);
<b>void</b> alglib::smp_mlpkfoldcv(
mlptrainer s,
multilayerperceptron network,
ae_int_t nrestarts,
ae_int_t foldscount,
mlpreport& rep);
</div></pre>
<p align=left class=pagecontent><span class=inlineheader>Examples:</span> <a href='#example_nn_crossvalidation' class=nav>[1]</a> <a href='#example_nn_parallel' class=nav>[2]</a> </p>
<a name='sub_mlpkfoldcvlbfgs'></a><h3 class=pageheader><code>mlpkfoldcvlbfgs</code> function</h3>
<pre class=source>
<div style='color: navy; margin-top: 0; margin-bottom: 0;'>/*************************************************************************
Cross-validation estimate of generalization error.
Base algorithm - L-BFGS.
INPUT PARAMETERS:
Network - neural network with initialized geometry. Network is
not changed during cross-validation - it is used only
as a representative of its architecture.
XY - training set.
SSize - training set size
Decay - weight decay, same as in MLPTrainLBFGS
Restarts - number of restarts, >0.
restarts are counted for each partition separately, so
total number of restarts will be Restarts*FoldsCount.
WStep - stopping criterion, same as in MLPTrainLBFGS
MaxIts - stopping criterion, same as in MLPTrainLBFGS
FoldsCount - number of folds in k-fold cross-validation,
2<=FoldsCount<=SSize.
recommended value: 10.
OUTPUT PARAMETERS:
Info - return code, same as in MLPTrainLBFGS
Rep - report, same as in MLPTrainLM/MLPTrainLBFGS
CVRep - generalization error estimates
-- ALGLIB --
Copyright 09.12.2007 by Bochkanov Sergey
*************************************************************************/
</div><div style='margin-top: 0; margin-bottom: 0;'><b>void</b> alglib::mlpkfoldcvlbfgs(
multilayerperceptron network,
real_2d_array xy,
ae_int_t npoints,
<b>double</b> decay,
ae_int_t restarts,
<b>double</b> wstep,
ae_int_t maxits,
ae_int_t foldscount,
ae_int_t& info,
mlpreport& rep,
mlpcvreport& cvrep);
</div></pre>
<a name='sub_mlpkfoldcvlm'></a><h3 class=pageheader><code>mlpkfoldcvlm</code> function</h3>
<pre class=source>
<div style='color: navy; margin-top: 0; margin-bottom: 0;'>/*************************************************************************
Cross-validation estimate of generalization error.
Base algorithm - Levenberg-Marquardt.
INPUT PARAMETERS:
Network - neural network with initialized geometry. Network is
not changed during cross-validation - it is used only
as a representative of its architecture.
XY - training set.
SSize - training set size
Decay - weight decay, same as in MLPTrainLBFGS
Restarts - number of restarts, >0.
restarts are counted for each partition separately, so
total number of restarts will be Restarts*FoldsCount.
FoldsCount - number of folds in k-fold cross-validation,
2<=FoldsCount<=SSize.
recommended value: 10.
OUTPUT PARAMETERS:
Info - return code, same as in MLPTrainLBFGS
Rep - report, same as in MLPTrainLM/MLPTrainLBFGS
CVRep - generalization error estimates
-- ALGLIB --
Copyright 09.12.2007 by Bochkanov Sergey
*************************************************************************/
</div><div style='margin-top: 0; margin-bottom: 0;'><b>void</b> alglib::mlpkfoldcvlm(
multilayerperceptron network,
real_2d_array xy,
ae_int_t npoints,
<b>double</b> decay,
ae_int_t restarts,
ae_int_t foldscount,
ae_int_t& info,
mlpreport& rep,
mlpcvreport& cvrep);
</div></pre>
<a name='sub_mlpsetalgobatch'></a><h3 class=pageheader><code>mlpsetalgobatch</code> function</h3>
<pre class=source>
<div style='color: navy; margin-top: 0; margin-bottom: 0;'>/*************************************************************************
This function sets training algorithm: batch training using L-BFGS will be
used.
This algorithm:
* the most robust for small-scale problems, but may be too slow for large
scale ones.
* perfoms full pass through the dataset before performing step
* uses conditions specified by MLPSetCond() for stopping
* is default one used by trainer object
INPUT PARAMETERS:
S - trainer object
-- ALGLIB --
Copyright 23.07.2012 by Bochkanov Sergey
*************************************************************************/
</div><div style='margin-top: 0; margin-bottom: 0;'><b>void</b> alglib::mlpsetalgobatch(mlptrainer s);
</div></pre>
<a name='sub_mlpsetcond'></a><h3 class=pageheader><code>mlpsetcond</code> function</h3>
<pre class=source>
<div style='color: navy; margin-top: 0; margin-bottom: 0;'>/*************************************************************************
This function sets stopping criteria for the optimizer.
INPUT PARAMETERS:
S - trainer object
WStep - stopping criterion. Algorithm stops if step size is
less than WStep. Recommended value - 0.01. Zero step
size means stopping after MaxIts iterations.
WStep>=0.
MaxIts - stopping criterion. Algorithm stops after MaxIts
epochs (full passes over entire dataset). Zero MaxIts
means stopping when step is sufficiently small.
MaxIts>=0.
NOTE: by default, WStep=0.005 and MaxIts=0 are used. These values are also
used when MLPSetCond() is called with WStep=0 and MaxIts=0.
NOTE: these stopping criteria are used for all kinds of neural training -
from "conventional" networks to early stopping ensembles. When used
for "conventional" networks, they are used as the only stopping
criteria. When combined with early stopping, they used as ADDITIONAL
stopping criteria which can terminate early stopping algorithm.
-- ALGLIB --
Copyright 23.07.2012 by Bochkanov Sergey
*************************************************************************/
</div><div style='margin-top: 0; margin-bottom: 0;'><b>void</b> alglib::mlpsetcond(mlptrainer s, <b>double</b> wstep, ae_int_t maxits);
</div></pre>
<a name='sub_mlpsetdataset'></a><h3 class=pageheader><code>mlpsetdataset</code> function</h3>
<pre class=source>
<div style='color: navy; margin-top: 0; margin-bottom: 0;'>/*************************************************************************
This function sets "current dataset" of the trainer object to one passed
by user.
INPUT PARAMETERS:
S - trainer object
XY - training set, see below for information on the
training set format. This function checks correctness
of the dataset (no NANs/INFs, class numbers are
correct) and throws exception when incorrect dataset
is passed.
NPoints - points count, >=0.
DATASET FORMAT:
This function uses two different dataset formats - one for regression
networks, another one for classification networks.
For regression networks with NIn inputs and NOut outputs following dataset
format is used:
* dataset is given by NPoints*(NIn+NOut) matrix
* each row corresponds to one example
* first NIn columns are inputs, next NOut columns are outputs
For classification networks with NIn inputs and NClasses clases following
datasetformat is used:
* dataset is given by NPoints*(NIn+1) matrix
* each row corresponds to one example
* first NIn columns are inputs, last column stores class number (from 0 to
NClasses-1).
-- ALGLIB --
Copyright 23.07.2012 by Bochkanov Sergey
*************************************************************************/
</div><div style='margin-top: 0; margin-bottom: 0;'><b>void</b> alglib::mlpsetdataset(
mlptrainer s,
real_2d_array xy,
ae_int_t npoints);
</div></pre>
<p align=left class=pagecontent><span class=inlineheader>Examples:</span> <a href='#example_nn_regr' class=nav>[1]</a> <a href='#example_nn_regr_n' class=nav>[2]</a> <a href='#example_nn_cls2' class=nav>[3]</a> <a href='#example_nn_cls3' class=nav>[4]</a> <a href='#example_nn_trainerobject' class=nav>[5]</a> <a href='#example_nn_crossvalidation' class=nav>[6]</a> <a href='#example_nn_ensembles_es' class=nav>[7]</a> <a href='#example_nn_parallel' class=nav>[8]</a> </p>
<a name='sub_mlpsetdecay'></a><h3 class=pageheader><code>mlpsetdecay</code> function</h3>
<pre class=source>
<div style='color: navy; margin-top: 0; margin-bottom: 0;'>/*************************************************************************
This function sets weight decay coefficient which is used for training.
INPUT PARAMETERS:
S - trainer object
Decay - weight decay coefficient, >=0. Weight decay term
'Decay*||Weights||^2' is added to error function. If
you don't know what Decay to choose, use 1.0E-3.
Weight decay can be set to zero, in this case network
is trained without weight decay.
NOTE: by default network uses some small nonzero value for weight decay.
-- ALGLIB --
Copyright 23.07.2012 by Bochkanov Sergey
*************************************************************************/
</div><div style='margin-top: 0; margin-bottom: 0;'><b>void</b> alglib::mlpsetdecay(mlptrainer s, <b>double</b> decay);
</div></pre>
<a name='sub_mlpsetsparsedataset'></a><h3 class=pageheader><code>mlpsetsparsedataset</code> function</h3>
<pre class=source>
<div style='color: navy; margin-top: 0; margin-bottom: 0;'>/*************************************************************************
This function sets "current dataset" of the trainer object to one passed
by user (sparse matrix is used to store dataset).
INPUT PARAMETERS:
S - trainer object
XY - training set, see below for information on the
training set format. This function checks correctness
of the dataset (no NANs/INFs, class numbers are
correct) and throws exception when incorrect dataset
is passed. Any sparse storage format can be used:
Hash-table, CRS...
NPoints - points count, >=0
DATASET FORMAT:
This function uses two different dataset formats - one for regression
networks, another one for classification networks.
For regression networks with NIn inputs and NOut outputs following dataset
format is used:
* dataset is given by NPoints*(NIn+NOut) matrix
* each row corresponds to one example
* first NIn columns are inputs, next NOut columns are outputs
For classification networks with NIn inputs and NClasses clases following
datasetformat is used:
* dataset is given by NPoints*(NIn+1) matrix
* each row corresponds to one example
* first NIn columns are inputs, last column stores class number (from 0 to
NClasses-1).
-- ALGLIB --
Copyright 23.07.2012 by Bochkanov Sergey
*************************************************************************/
</div><div style='margin-top: 0; margin-bottom: 0;'><b>void</b> alglib::mlpsetsparsedataset(
mlptrainer s,
sparsematrix xy,
ae_int_t npoints);
</div></pre>
<a name='sub_mlpstarttraining'></a><h3 class=pageheader><code>mlpstarttraining</code> function</h3>
<pre class=source>
<div style='color: navy; margin-top: 0; margin-bottom: 0;'>/*************************************************************************
IMPORTANT: this is an "expert" version of the MLPTrain() function. We do
not recommend you to use it unless you are pretty sure that you
need ability to monitor training progress.
This function performs step-by-step training of the neural network. Here
"step-by-step" means that training starts with MLPStartTraining() call,
and then user subsequently calls MLPContinueTraining() to perform one more
iteration of the training.
After call to this function trainer object remembers network and is ready
to train it. However, no training is performed until first call to
MLPContinueTraining() function. Subsequent calls to MLPContinueTraining()
will advance training progress one iteration further.
EXAMPLE:
>
> ...initialize network and trainer object....
>
> MLPStartTraining(Trainer, Network, True)
> while MLPContinueTraining(Trainer, Network) do
> ...visualize training progress...
>
INPUT PARAMETERS:
S - trainer object
Network - neural network. It must have same number of inputs and
output/classes as was specified during creation of the
trainer object.
RandomStart - randomize network before training or not:
* True means that network is randomized and its
initial state (one which was passed to the trainer
object) is lost.
* False means that training is started from the
current state of the network
OUTPUT PARAMETERS:
Network - neural network which is ready to training (weights are
initialized, preprocessor is initialized using current
training set)
NOTE: this method uses sum-of-squares error function for training.
NOTE: it is expected that trainer object settings are NOT changed during
step-by-step training, i.e. no one changes stopping criteria or
training set during training. It is possible and there is no defense
against such actions, but algorithm behavior in such cases is
undefined and can be unpredictable.
-- ALGLIB --
Copyright 23.07.2012 by Bochkanov Sergey
*************************************************************************/
</div><div style='margin-top: 0; margin-bottom: 0;'><b>void</b> alglib::mlpstarttraining(
mlptrainer s,
multilayerperceptron network,
<b>bool</b> randomstart);
</div></pre>
<a name='sub_mlptrainensemblees'></a><h3 class=pageheader><code>mlptrainensemblees</code> function</h3>
<pre class=source>
<div style='color: navy; margin-top: 0; margin-bottom: 0;'>/*************************************************************************
This function trains neural network ensemble passed to this function using
current dataset and early stopping training algorithm. Each early stopping
round performs NRestarts random restarts (thus, EnsembleSize*NRestarts
training rounds is performed in total).
FOR USERS OF COMMERCIAL EDITION:
! Commercial version of ALGLIB includes two important improvements of
! this function:
! * multicore support (C++ and C# computational cores)
! * SSE support (C++ computational core)
!
! Second improvement gives constant speedup (2-3X). First improvement
! gives close-to-linear speedup on multicore systems. Following
! operations can be executed in parallel:
! * EnsembleSize training sessions performed for each of ensemble
! members (always parallelized)
! * NRestarts training sessions performed within each of training
! sessions (if NRestarts>1)
! * gradient calculation over large dataset (if dataset is large enough)
!
! In order to use multicore features you have to:
! * use commercial version of ALGLIB
! * call this function with "smp_" prefix, which indicates that
! multicore code will be used (for multicore support)
!
! In order to use SSE features you have to:
! * use commercial version of ALGLIB on Intel processors
! * use C++ computational core
!
! This note is given for users of commercial edition; if you use GPL
! edition, you still will be able to call smp-version of this function,
! but all computations will be done serially.
!
! We recommend you to carefully read ALGLIB Reference Manual, section
! called 'SMP support', before using parallel version of this function.
INPUT PARAMETERS:
S - trainer object;
Ensemble - neural network ensemble. It must have same number of
inputs and outputs/classes as was specified during
creation of the trainer object.
NRestarts - number of restarts, >=0:
* NRestarts>0 means that specified number of random
restarts are performed during each ES round;
* NRestarts=0 is silently replaced by 1.
OUTPUT PARAMETERS:
Ensemble - trained ensemble;
Rep - it contains all type of errors.
NOTE: this training method uses BOTH early stopping and weight decay! So,
you should select weight decay before starting training just as you
select it before training "conventional" networks.
NOTE: when no dataset was specified with MLPSetDataset/SetSparseDataset(),
or single-point dataset was passed, ensemble is filled by zero
values.
NOTE: this method uses sum-of-squares error function for training.
-- ALGLIB --
Copyright 22.08.2012 by Bochkanov Sergey
*************************************************************************/
</div><div style='margin-top: 0; margin-bottom: 0;'><b>void</b> alglib::mlptrainensemblees(
mlptrainer s,
mlpensemble ensemble,
ae_int_t nrestarts,
mlpreport& rep);
<b>void</b> alglib::smp_mlptrainensemblees(
mlptrainer s,
mlpensemble ensemble,
ae_int_t nrestarts,
mlpreport& rep);
</div></pre>
<p align=left class=pagecontent><span class=inlineheader>Examples:</span> <a href='#example_nn_ensembles_es' class=nav>[1]</a> <a href='#example_nn_parallel' class=nav>[2]</a> </p>
<a name='sub_mlptraines'></a><h3 class=pageheader><code>mlptraines</code> function</h3>
<pre class=source>
<div style='color: navy; margin-top: 0; margin-bottom: 0;'>/*************************************************************************
Neural network training using early stopping (base algorithm - L-BFGS with
regularization).
INPUT PARAMETERS:
Network - neural network with initialized geometry
TrnXY - training set
TrnSize - training set size, TrnSize>0
ValXY - validation set
ValSize - validation set size, ValSize>0
Decay - weight decay constant, >=0.001
Decay term 'Decay*||Weights||^2' is added to error
function.
If you don't know what Decay to choose, use 0.001.
Restarts - number of restarts, either:
* strictly positive number - algorithm make specified
number of restarts from random position.
* -1, in which case algorithm makes exactly one run
from the initial state of the network (no randomization).
If you don't know what Restarts to choose, choose one
one the following:
* -1 (deterministic start)
* +1 (one random restart)
* +5 (moderate amount of random restarts)
OUTPUT PARAMETERS:
Network - trained neural network.
Info - return code:
* -2, if there is a point with class number
outside of [0..NOut-1].
* -1, if wrong parameters specified
(NPoints<0, Restarts<1, ...).
* 2, task has been solved, stopping criterion met -
sufficiently small step size. Not expected (we
use EARLY stopping) but possible and not an
error.
* 6, task has been solved, stopping criterion met -
increasing of validation set error.
Rep - training report
NOTE:
Algorithm stops if validation set error increases for a long enough or
step size is small enought (there are task where validation set may
decrease for eternity). In any case solution returned corresponds to the
minimum of validation set error.
-- ALGLIB --
Copyright 10.03.2009 by Bochkanov Sergey
*************************************************************************/
</div><div style='margin-top: 0; margin-bottom: 0;'><b>void</b> alglib::mlptraines(
multilayerperceptron network,
real_2d_array trnxy,
ae_int_t trnsize,
real_2d_array valxy,
ae_int_t valsize,
<b>double</b> decay,
ae_int_t restarts,
ae_int_t& info,
mlpreport& rep);
</div></pre>
<a name='sub_mlptrainlbfgs'></a><h3 class=pageheader><code>mlptrainlbfgs</code> function</h3>
<pre class=source>
<div style='color: navy; margin-top: 0; margin-bottom: 0;'>/*************************************************************************
Neural network training using L-BFGS algorithm with regularization.
Subroutine trains neural network with restarts from random positions.
Algorithm is well suited for problems of any dimensionality (memory
requirements and step complexity are linear by weights number).
INPUT PARAMETERS:
Network - neural network with initialized geometry
XY - training set
NPoints - training set size
Decay - weight decay constant, >=0.001
Decay term 'Decay*||Weights||^2' is added to error
function.
If you don't know what Decay to choose, use 0.001.
Restarts - number of restarts from random position, >0.
If you don't know what Restarts to choose, use 2.
WStep - stopping criterion. Algorithm stops if step size is
less than WStep. Recommended value - 0.01. Zero step
size means stopping after MaxIts iterations.
MaxIts - stopping criterion. Algorithm stops after MaxIts
iterations (NOT gradient calculations). Zero MaxIts
means stopping when step is sufficiently small.
OUTPUT PARAMETERS:
Network - trained neural network.
Info - return code:
* -8, if both WStep=0 and MaxIts=0
* -2, if there is a point with class number
outside of [0..NOut-1].
* -1, if wrong parameters specified
(NPoints<0, Restarts<1).
* 2, if task has been solved.
Rep - training report
-- ALGLIB --
Copyright 09.12.2007 by Bochkanov Sergey
*************************************************************************/
</div><div style='margin-top: 0; margin-bottom: 0;'><b>void</b> alglib::mlptrainlbfgs(
multilayerperceptron network,
real_2d_array xy,
ae_int_t npoints,
<b>double</b> decay,
ae_int_t restarts,
<b>double</b> wstep,
ae_int_t maxits,
ae_int_t& info,
mlpreport& rep);
</div></pre>
<a name='sub_mlptrainlm'></a><h3 class=pageheader><code>mlptrainlm</code> function</h3>
<pre class=source>
<div style='color: navy; margin-top: 0; margin-bottom: 0;'>/*************************************************************************
Neural network training using modified Levenberg-Marquardt with exact
Hessian calculation and regularization. Subroutine trains neural network
with restarts from random positions. Algorithm is well suited for small
and medium scale problems (hundreds of weights).
INPUT PARAMETERS:
Network - neural network with initialized geometry
XY - training set
NPoints - training set size
Decay - weight decay constant, >=0.001
Decay term 'Decay*||Weights||^2' is added to error
function.
If you don't know what Decay to choose, use 0.001.
Restarts - number of restarts from random position, >0.
If you don't know what Restarts to choose, use 2.
OUTPUT PARAMETERS:
Network - trained neural network.
Info - return code:
* -9, if internal matrix inverse subroutine failed
* -2, if there is a point with class number
outside of [0..NOut-1].
* -1, if wrong parameters specified
(NPoints<0, Restarts<1).
* 2, if task has been solved.
Rep - training report
-- ALGLIB --
Copyright 10.03.2009 by Bochkanov Sergey
*************************************************************************/
</div><div style='margin-top: 0; margin-bottom: 0;'><b>void</b> alglib::mlptrainlm(
multilayerperceptron network,
real_2d_array xy,
ae_int_t npoints,
<b>double</b> decay,
ae_int_t restarts,
ae_int_t& info,
mlpreport& rep);
</div></pre>
<a name='sub_mlptrainnetwork'></a><h3 class=pageheader><code>mlptrainnetwork</code> function</h3>
<pre class=source>
<div style='color: navy; margin-top: 0; margin-bottom: 0;'>/*************************************************************************
This function trains neural network passed to this function, using current
dataset (one which was passed to MLPSetDataset() or MLPSetSparseDataset())
and current training settings. Training from NRestarts random starting
positions is performed, best network is chosen.
Training is performed using current training algorithm.
FOR USERS OF COMMERCIAL EDITION:
! Commercial version of ALGLIB includes two important improvements of
! this function:
! * multicore support (C++ and C# computational cores)
! * SSE support (C++ computational core)
!
! Second improvement gives constant speedup (2-3X). First improvement
! gives close-to-linear speedup on multicore systems. Following
! operations can be executed in parallel:
! * NRestarts training sessions performed within each of
! cross-validation rounds (if NRestarts>1)
! * gradient calculation over large dataset (if dataset is large enough)
!
! In order to use multicore features you have to:
! * use commercial version of ALGLIB
! * call this function with "smp_" prefix, which indicates that
! multicore code will be used (for multicore support)
!
! In order to use SSE features you have to:
! * use commercial version of ALGLIB on Intel processors
! * use C++ computational core
!
! This note is given for users of commercial edition; if you use GPL
! edition, you still will be able to call smp-version of this function,
! but all computations will be done serially.
!
! We recommend you to carefully read ALGLIB Reference Manual, section
! called 'SMP support', before using parallel version of this function.
INPUT PARAMETERS:
S - trainer object
Network - neural network. It must have same number of inputs and
output/classes as was specified during creation of the
trainer object.
NRestarts - number of restarts, >=0:
* NRestarts>0 means that specified number of random
restarts are performed, best network is chosen after
training
* NRestarts=0 means that current state of the network
is used for training.
OUTPUT PARAMETERS:
Network - trained network
NOTE: when no dataset was specified with MLPSetDataset/SetSparseDataset(),
network is filled by zero values. Same behavior for functions
MLPStartTraining and MLPContinueTraining.
NOTE: this method uses sum-of-squares error function for training.
-- ALGLIB --
Copyright 23.07.2012 by Bochkanov Sergey
*************************************************************************/
</div><div style='margin-top: 0; margin-bottom: 0;'><b>void</b> alglib::mlptrainnetwork(
mlptrainer s,
multilayerperceptron network,
ae_int_t nrestarts,
mlpreport& rep);
<b>void</b> alglib::smp_mlptrainnetwork(
mlptrainer s,
multilayerperceptron network,
ae_int_t nrestarts,
mlpreport& rep);
</div></pre>
<p align=left class=pagecontent><span class=inlineheader>Examples:</span> <a href='#example_nn_regr' class=nav>[1]</a> <a href='#example_nn_regr_n' class=nav>[2]</a> <a href='#example_nn_cls2' class=nav>[3]</a> <a href='#example_nn_cls3' class=nav>[4]</a> <a href='#example_nn_trainerobject' class=nav>[5]</a> <a href='#example_nn_parallel' class=nav>[6]</a> </p>
<a name='example_nn_cls2'></a><h3 class=pageheader>nn_cls2 example</h3>
<pre class=source>
#include <font color=blue><b>"stdafx.h"</b></font>
#include <stdlib.h>
#include <stdio.h>
#include <math.h>
#include <font color=blue><b>"dataanalysis.h"</b></font>
using namespace alglib;
<b>int</b> main(<b>int</b> argc, char **argv)
{
<font color=navy>//</font>
<font color=navy>// Suppose that we want to classify numbers as positive (<b>class</b> 0) and negative</font>
<font color=navy>// (<b>class</b> 1). We have training set which includes several strictly positive</font>
<font color=navy>// or negative numbers - and zero.</font>
<font color=navy>//</font>
<font color=navy>// The problem is that we are not sure how to classify zero, so from time to</font>
<font color=navy>// time we mark it as positive or negative (with equal probability). Other</font>
<font color=navy>// numbers are marked in pure deterministic setting. How will neural network</font>
<font color=navy>// cope with such classification task?</font>
<font color=navy>//</font>
<font color=navy>// NOTE: we use network with excessive amount of neurons, which guarantees</font>
<font color=navy>// almost exact reproduction of the training set. Generalization ability</font>
<font color=navy>// of such network is rather low, but we are not concerned with such</font>
<font color=navy>// questions in this basic demo.</font>
<font color=navy>//</font>
mlptrainer trn;
multilayerperceptron network;
mlpreport rep;
real_1d_array x = <font color=blue><b>"[0]"</b></font>;
real_1d_array y = <font color=blue><b>"[0,0]"</b></font>;
<font color=navy>//</font>
<font color=navy>// Training set. One row corresponds to one record [A => <b>class</b>(A)].</font>
<font color=navy>//</font>
<font color=navy>// Classes are denoted by numbers from 0 to 1, where 0 corresponds to positive</font>
<font color=navy>// numbers and 1 to negative numbers.</font>
<font color=navy>//</font>
<font color=navy>// [ +1 0]</font>
<font color=navy>// [ +2 0]</font>
<font color=navy>// [ -1 1]</font>
<font color=navy>// [ -2 1]</font>
<font color=navy>// [ 0 0] !! sometimes we classify 0 as positive, sometimes as negative</font>
<font color=navy>// [ 0 1] !!</font>
<font color=navy>//</font>
real_2d_array xy = <font color=blue><b>"[[+1,0],[+2,0],[-1,1],[-2,1],[0,0],[0,1]]"</b></font>;
<font color=navy>//</font>
<font color=navy>//</font>
<font color=navy>// When we solve classification problems, everything is slightly different from</font>
<font color=navy>// the regression ones:</font>
<font color=navy>//</font>
<font color=navy>// 1. Network is created. Because we solve classification problem, we use</font>
<font color=navy>// mlpcreatec1() function instead of mlpcreate1(). This function creates</font>
<font color=navy>// classifier network with SOFTMAX-normalized outputs. This network returns</font>
<font color=navy>// vector of <b>class</b> membership probabilities which are normalized to be</font>
<font color=navy>// non-negative and sum to 1.0</font>
<font color=navy>//</font>
<font color=navy>// 2. We use mlpcreatetrainercls() function instead of mlpcreatetrainer() to</font>
<font color=navy>// create trainer object. Trainer object process dataset and neural network</font>
<font color=navy>// slightly differently to account <b>for</b> specifics of the classification</font>
<font color=navy>// problems.</font>
<font color=navy>//</font>
<font color=navy>// 3. Dataset is attached to trainer object. Note that dataset format is slightly</font>
<font color=navy>// different from one used <b>for</b> regression.</font>
<font color=navy>//</font>
mlpcreatetrainercls(1, 2, trn);
mlpcreatec1(1, 5, 2, network);
mlpsetdataset(trn, xy, 6);
<font color=navy>//</font>
<font color=navy>// Network is trained with 5 restarts from random positions</font>
<font color=navy>//</font>
mlptrainnetwork(trn, network, 5, rep);
<font color=navy>//</font>
<font color=navy>// Test our neural network on strictly positive and strictly negative numbers.</font>
<font color=navy>//</font>
<font color=navy>// IMPORTANT! Classifier network returns <b>class</b> membership probabilities instead</font>
<font color=navy>// of <b>class</b> indexes. Network returns two values (probabilities) instead of one</font>
<font color=navy>// (<b>class</b> index).</font>
<font color=navy>//</font>
<font color=navy>// Thus, <b>for</b> +1 we expect to get [P0,P1] = [1,0], where P0 is probability that</font>
<font color=navy>// number is positive (belongs to <b>class</b> 0), and P1 is probability that number</font>
<font color=navy>// is negative (belongs to <b>class</b> 1).</font>
<font color=navy>//</font>
<font color=navy>// For -1 we expect to get [P0,P1] = [0,1]</font>
<font color=navy>//</font>
<font color=navy>// Following properties are guaranteed by network architecture:</font>
<font color=navy>// * P0>=0, P1>=0 non-negativity</font>
<font color=navy>// * P0+P1=1 normalization</font>
<font color=navy>//</font>
x = <font color=blue><b>"[1]"</b></font>;
mlpprocess(network, x, y);
printf(<font color=blue><b>"%s\n"</b></font>, y.tostring(1).c_str()); <font color=navy>// EXPECTED: [1.000,0.000]</font>
x = <font color=blue><b>"[-1]"</b></font>;
mlpprocess(network, x, y);
printf(<font color=blue><b>"%s\n"</b></font>, y.tostring(1).c_str()); <font color=navy>// EXPECTED: [0.000,1.000]</font>
<font color=navy>//</font>
<font color=navy>// But what our network will <b>return</b> <b>for</b> 0, which is between classes 0 and 1?</font>
<font color=navy>//</font>
<font color=navy>// In our dataset it has two different marks assigned (<b>class</b> 0 AND <b>class</b> 1).</font>
<font color=navy>// So network will <b>return</b> something average between <b>class</b> 0 and <b>class</b> 1:</font>
<font color=navy>// 0 => [0.5, 0.5]</font>
<font color=navy>//</font>
x = <font color=blue><b>"[0]"</b></font>;
mlpprocess(network, x, y);
printf(<font color=blue><b>"%s\n"</b></font>, y.tostring(1).c_str()); <font color=navy>// EXPECTED: [0.500,0.500]</font>
<b>return</b> 0;
}
</pre><a name='example_nn_cls3'></a><h3 class=pageheader>nn_cls3 example</h3>
<pre class=source>
#include <font color=blue><b>"stdafx.h"</b></font>
#include <stdlib.h>
#include <stdio.h>
#include <math.h>
#include <font color=blue><b>"dataanalysis.h"</b></font>
using namespace alglib;
<b>int</b> main(<b>int</b> argc, char **argv)
{
<font color=navy>//</font>
<font color=navy>// Suppose that we want to classify numbers as positive (<b>class</b> 0) and negative</font>
<font color=navy>// (<b>class</b> 1). We also have one more <b>class</b> <b>for</b> zero (<b>class</b> 2).</font>
<font color=navy>//</font>
<font color=navy>// NOTE: we use network with excessive amount of neurons, which guarantees</font>
<font color=navy>// almost exact reproduction of the training set. Generalization ability</font>
<font color=navy>// of such network is rather low, but we are not concerned with such</font>
<font color=navy>// questions in this basic demo.</font>
<font color=navy>//</font>
mlptrainer trn;
multilayerperceptron network;
mlpreport rep;
real_1d_array x = <font color=blue><b>"[0]"</b></font>;
real_1d_array y = <font color=blue><b>"[0,0,0]"</b></font>;
<font color=navy>//</font>
<font color=navy>// Training set. One row corresponds to one record [A => <b>class</b>(A)].</font>
<font color=navy>//</font>
<font color=navy>// Classes are denoted by numbers from 0 to 2, where 0 corresponds to positive</font>
<font color=navy>// numbers, 1 to negative numbers, 2 to zero</font>
<font color=navy>//</font>
<font color=navy>// [ +1 0]</font>
<font color=navy>// [ +2 0]</font>
<font color=navy>// [ -1 1]</font>
<font color=navy>// [ -2 1]</font>
<font color=navy>// [ 0 2]</font>
<font color=navy>//</font>
real_2d_array xy = <font color=blue><b>"[[+1,0],[+2,0],[-1,1],[-2,1],[0,2]]"</b></font>;
<font color=navy>//</font>
<font color=navy>//</font>
<font color=navy>// When we solve classification problems, everything is slightly different from</font>
<font color=navy>// the regression ones:</font>
<font color=navy>//</font>
<font color=navy>// 1. Network is created. Because we solve classification problem, we use</font>
<font color=navy>// mlpcreatec1() function instead of mlpcreate1(). This function creates</font>
<font color=navy>// classifier network with SOFTMAX-normalized outputs. This network returns</font>
<font color=navy>// vector of <b>class</b> membership probabilities which are normalized to be</font>
<font color=navy>// non-negative and sum to 1.0</font>
<font color=navy>//</font>
<font color=navy>// 2. We use mlpcreatetrainercls() function instead of mlpcreatetrainer() to</font>
<font color=navy>// create trainer object. Trainer object process dataset and neural network</font>
<font color=navy>// slightly differently to account <b>for</b> specifics of the classification</font>
<font color=navy>// problems.</font>
<font color=navy>//</font>
<font color=navy>// 3. Dataset is attached to trainer object. Note that dataset format is slightly</font>
<font color=navy>// different from one used <b>for</b> regression.</font>
<font color=navy>//</font>
mlpcreatetrainercls(1, 3, trn);
mlpcreatec1(1, 5, 3, network);
mlpsetdataset(trn, xy, 5);
<font color=navy>//</font>
<font color=navy>// Network is trained with 5 restarts from random positions</font>
<font color=navy>//</font>
mlptrainnetwork(trn, network, 5, rep);
<font color=navy>//</font>
<font color=navy>// Test our neural network on strictly positive and strictly negative numbers.</font>
<font color=navy>//</font>
<font color=navy>// IMPORTANT! Classifier network returns <b>class</b> membership probabilities instead</font>
<font color=navy>// of <b>class</b> indexes. Network returns three values (probabilities) instead of one</font>
<font color=navy>// (<b>class</b> index).</font>
<font color=navy>//</font>
<font color=navy>// Thus, <b>for</b> +1 we expect to get [P0,P1,P2] = [1,0,0],</font>
<font color=navy>// <b>for</b> -1 we expect to get [P0,P1,P2] = [0,1,0],</font>
<font color=navy>// and <b>for</b> 0 we will get [P0,P1,P2] = [0,0,1].</font>
<font color=navy>//</font>
<font color=navy>// Following properties are guaranteed by network architecture:</font>
<font color=navy>// * P0>=0, P1>=0, P2>=0 non-negativity</font>
<font color=navy>// * P0+P1+P2=1 normalization</font>
<font color=navy>//</font>
x = <font color=blue><b>"[1]"</b></font>;
mlpprocess(network, x, y);
printf(<font color=blue><b>"%s\n"</b></font>, y.tostring(1).c_str()); <font color=navy>// EXPECTED: [1.000,0.000,0.000]</font>
x = <font color=blue><b>"[-1]"</b></font>;
mlpprocess(network, x, y);
printf(<font color=blue><b>"%s\n"</b></font>, y.tostring(1).c_str()); <font color=navy>// EXPECTED: [0.000,1.000,0.000]</font>
x = <font color=blue><b>"[0]"</b></font>;
mlpprocess(network, x, y);
printf(<font color=blue><b>"%s\n"</b></font>, y.tostring(1).c_str()); <font color=navy>// EXPECTED: [0.000,0.000,1.000]</font>
<b>return</b> 0;
}
</pre><a name='example_nn_crossvalidation'></a><h3 class=pageheader>nn_crossvalidation example</h3>
<pre class=source>
#include <font color=blue><b>"stdafx.h"</b></font>
#include <stdlib.h>
#include <stdio.h>
#include <math.h>
#include <font color=blue><b>"dataanalysis.h"</b></font>
using namespace alglib;
<b>int</b> main(<b>int</b> argc, char **argv)
{
<font color=navy>//</font>
<font color=navy>// This example shows how to perform cross-validation with ALGLIB</font>
<font color=navy>//</font>
mlptrainer trn;
multilayerperceptron network;
mlpreport rep;
<font color=navy>//</font>
<font color=navy>// Training set: f(x)=1/(x^2+1)</font>
<font color=navy>// One row corresponds to one record [x,f(x)]</font>
<font color=navy>//</font>
real_2d_array xy = <font color=blue><b>"[[-2.0,0.2],[-1.6,0.3],[-1.3,0.4],[-1,0.5],[-0.6,0.7],[-0.3,0.9],[0,1],[2.0,0.2],[1.6,0.3],[1.3,0.4],[1,0.5],[0.6,0.7],[0.3,0.9]]"</b></font>;
<font color=navy>//</font>
<font color=navy>// Trainer object is created.</font>
<font color=navy>// Dataset is attached to trainer object.</font>
<font color=navy>//</font>
<font color=navy>// NOTE: it is not good idea to perform cross-validation on sample</font>
<font color=navy>// as small as ours (13 examples). It is done <b>for</b> demonstration</font>
<font color=navy>// purposes only. Generalization error estimates won't be</font>
<font color=navy>// precise enough <b>for</b> practical purposes.</font>
<font color=navy>//</font>
mlpcreatetrainer(1, 1, trn);
mlpsetdataset(trn, xy, 13);
<font color=navy>//</font>
<font color=navy>// The key property of the cross-validation is that it estimates</font>
<font color=navy>// generalization properties of neural ARCHITECTURE. It does NOT</font>
<font color=navy>// estimates generalization error of some specific network which</font>
<font color=navy>// is passed to the k-fold CV routine.</font>
<font color=navy>//</font>
<font color=navy>// In our example we create 1x4x1 neural network and pass it to</font>
<font color=navy>// CV routine without training it. Original state of the network</font>
<font color=navy>// is not used <b>for</b> cross-validation - each round is restarted from</font>
<font color=navy>// random initial state. Only geometry of network matters.</font>
<font color=navy>//</font>
<font color=navy>// We perform 5 restarts from different random positions <b>for</b> each</font>
<font color=navy>// of the 10 cross-validation rounds.</font>
<font color=navy>//</font>
mlpcreate1(1, 4, 1, network);
mlpkfoldcv(trn, network, 5, 10, rep);
<font color=navy>//</font>
<font color=navy>// Cross-validation routine stores estimates of the generalization</font>
<font color=navy>// error to MLP report structure. You may examine its fields and</font>
<font color=navy>// see estimates of different errors (RMS, CE, Avg).</font>
<font color=navy>//</font>
<font color=navy>// Because cross-validation is non-deterministic, in our manual we</font>
<font color=navy>// can not say what values will be stored to rep after call to</font>
<font color=navy>// mlpkfoldcv(). Every CV round will <b>return</b> slightly different</font>
<font color=navy>// estimates.</font>
<font color=navy>//</font>
<b>return</b> 0;
}
</pre><a name='example_nn_ensembles_es'></a><h3 class=pageheader>nn_ensembles_es example</h3>
<pre class=source>
#include <font color=blue><b>"stdafx.h"</b></font>
#include <stdlib.h>
#include <stdio.h>
#include <math.h>
#include <font color=blue><b>"dataanalysis.h"</b></font>
using namespace alglib;
<b>int</b> main(<b>int</b> argc, char **argv)
{
<font color=navy>//</font>
<font color=navy>// This example shows how to train early stopping ensebles.</font>
<font color=navy>//</font>
mlptrainer trn;
mlpensemble ensemble;
mlpreport rep;
<font color=navy>//</font>
<font color=navy>// Training set: f(x)=1/(x^2+1)</font>
<font color=navy>// One row corresponds to one record [x,f(x)]</font>
<font color=navy>//</font>
real_2d_array xy = <font color=blue><b>"[[-2.0,0.2],[-1.6,0.3],[-1.3,0.4],[-1,0.5],[-0.6,0.7],[-0.3,0.9],[0,1],[2.0,0.2],[1.6,0.3],[1.3,0.4],[1,0.5],[0.6,0.7],[0.3,0.9]]"</b></font>;
<font color=navy>//</font>
<font color=navy>// Trainer object is created.</font>
<font color=navy>// Dataset is attached to trainer object.</font>
<font color=navy>//</font>
<font color=navy>// NOTE: it is not good idea to use early stopping ensemble on sample</font>
<font color=navy>// as small as ours (13 examples). It is done <b>for</b> demonstration</font>
<font color=navy>// purposes only. Ensemble training algorithm won't find good</font>
<font color=navy>// solution on such small sample.</font>
<font color=navy>//</font>
mlpcreatetrainer(1, 1, trn);
mlpsetdataset(trn, xy, 13);
<font color=navy>//</font>
<font color=navy>// Ensemble is created and trained. Each of 50 network is trained</font>
<font color=navy>// with 5 restarts.</font>
<font color=navy>//</font>
mlpecreate1(1, 4, 1, 50, ensemble);
mlptrainensemblees(trn, ensemble, 5, rep);
<b>return</b> 0;
}
</pre><a name='example_nn_parallel'></a><h3 class=pageheader>nn_parallel example</h3>
<pre class=source>
#include <font color=blue><b>"stdafx.h"</b></font>
#include <stdlib.h>
#include <stdio.h>
#include <math.h>
#include <font color=blue><b>"dataanalysis.h"</b></font>
using namespace alglib;
<b>int</b> main(<b>int</b> argc, char **argv)
{
<font color=navy>//</font>
<font color=navy>// This example shows how to use parallel functionality of ALGLIB.</font>
<font color=navy>// We generate simple 1-dimensional regression problem and show how</font>
<font color=navy>// to use parallel training, parallel cross-validation, parallel</font>
<font color=navy>// training of neural ensembles.</font>
<font color=navy>//</font>
<font color=navy>// We assume that you already know how to use ALGLIB in serial mode</font>
<font color=navy>// and concentrate on its parallel capabilities.</font>
<font color=navy>//</font>
<font color=navy>// NOTE: it is not good idea to use parallel features on sample as small</font>
<font color=navy>// as ours (13 examples). It is done only <b>for</b> demonstration purposes.</font>
<font color=navy>//</font>
mlptrainer trn;
multilayerperceptron network;
mlpensemble ensemble;
mlpreport rep;
real_2d_array xy = <font color=blue><b>"[[-2.0,0.2],[-1.6,0.3],[-1.3,0.4],[-1,0.5],[-0.6,0.7],[-0.3,0.9],[0,1],[2.0,0.2],[1.6,0.3],[1.3,0.4],[1,0.5],[0.6,0.7],[0.3,0.9]]"</b></font>;
mlpcreatetrainer(1, 1, trn);
mlpsetdataset(trn, xy, 13);
mlpcreate1(1, 4, 1, network);
mlpecreate1(1, 4, 1, 50, ensemble);
<font color=navy>//</font>
<font color=navy>// Below we demonstrate how to perform:</font>
<font color=navy>// * parallel training of individual networks</font>
<font color=navy>// * parallel cross-validation</font>
<font color=navy>// * parallel training of neural ensembles</font>
<font color=navy>//</font>
<font color=navy>// In order to use multithreading, you have to:</font>
<font color=navy>// 1) Install SMP edition of ALGLIB.</font>
<font color=navy>// 2) This step is specific <b>for</b> C++ users: you should activate OS-specific</font>
<font color=navy>// capabilities of ALGLIB by defining AE_OS=AE_POSIX (<b>for</b> *nix systems)</font>
<font color=navy>// or AE_OS=AE_WINDOWS (<b>for</b> Windows systems).</font>
<font color=navy>// C# users <b>do</b> not have to perform this step because C# programs are</font>
<font color=navy>// portable across different systems without OS-specific tuning.</font>
<font color=navy>// 3) Allow ALGLIB to know about number of worker threads to use:</font>
<font color=navy>// a) autodetection (C++, C#):</font>
<font color=navy>// ALGLIB will automatically determine number of CPU cores and</font>
<font color=navy>// (by default) will use all cores except <b>for</b> one. Say, on 4-core</font>
<font color=navy>// system it will use three cores - unless you manually told it</font>
<font color=navy>// to use more or less. It will keep your system responsive during</font>
<font color=navy>// lengthy computations.</font>
<font color=navy>// Such behavior may be changed with setnworkers() call:</font>
<font color=navy>// * alglib::setnworkers(0) = use all cores</font>
<font color=navy>// * alglib::setnworkers(-1) = leave one core unused</font>
<font color=navy>// * alglib::setnworkers(-2) = leave two cores unused</font>
<font color=navy>// * alglib::setnworkers(+2) = use 2 cores (even <b>if</b> you have more)</font>
<font color=navy>// b) manual specification (C++, C#):</font>
<font color=navy>// You may want to specify maximum number of worker threads during</font>
<font color=navy>// compile time by means of preprocessor definition AE_NWORKERS.</font>
<font color=navy>// For C++ it will be <font color=blue><b>"AE_NWORKERS=X"</b></font> where X can be any positive number.</font>
<font color=navy>// For C# it is <font color=blue><b>"AE_NWORKERSX"</b></font>, where X should be replaced by number of</font>
<font color=navy>// workers (AE_NWORKERS2, AE_NWORKERS3, AE_NWORKERS4, ...).</font>
<font color=navy>// You can add this definition to compiler command line or change</font>
<font color=navy>// corresponding project settings in your IDE.</font>
<font color=navy>//</font>
<font color=navy>// After you installed and configured SMP edition of ALGLIB, you may choose</font>
<font color=navy>// between serial and multithreaded versions of SMP-capable functions:</font>
<font color=navy>// * serial version works as usual, in the context of the calling thread</font>
<font color=navy>// * multithreaded version (with <font color=blue><b>"smp_"</b></font> prefix) creates (or wakes up) worker</font>
<font color=navy>// threads, inserts task in the worker queue, and waits <b>for</b> completion of</font>
<font color=navy>// the task. All processing is done in context of worker thread(s).</font>
<font color=navy>//</font>
<font color=navy>// NOTE: because starting/stopping worker threads costs thousands of CPU cycles,</font>
<font color=navy>// you should not use multithreading <b>for</b> lightweight computational problems.</font>
<font color=navy>//</font>
<font color=navy>// NOTE: some old POSIX-compatible operating systems <b>do</b> not support</font>
<font color=navy>// sysconf(_SC_NPROCESSORS_ONLN) system call which is required in order</font>
<font color=navy>// to automatically determine number of active cores. On these systems</font>
<font color=navy>// you should specify number of cores manually at compile time.</font>
<font color=navy>// Without it ALGLIB will run in single-threaded mode.</font>
<font color=navy>//</font>
<font color=navy>//</font>
<font color=navy>// First, we perform parallel training of individual network with 5</font>
<font color=navy>// restarts from random positions. These 5 rounds of training are</font>
<font color=navy>// executed in parallel manner, with best network chosen after</font>
<font color=navy>// training.</font>
<font color=navy>//</font>
<font color=navy>// ALGLIB can use additional way to speed up computations - divide</font>
<font color=navy>// dataset into smaller subsets and process these subsets</font>
<font color=navy>// simultaneously. It allows us to efficiently parallelize even</font>
<font color=navy>// single training round. This operation is performed automatically</font>
<font color=navy>// <b>for</b> large datasets, but our toy dataset is too small.</font>
<font color=navy>//</font>
smp_mlptrainnetwork(trn, network, 5, rep);
<font color=navy>//</font>
<font color=navy>// Then, we perform parallel 10-fold cross-validation, with 5 random</font>
<font color=navy>// restarts per each CV round. I.e., 5*10=50 networks are trained</font>
<font color=navy>// in total. All these operations can be parallelized.</font>
<font color=navy>//</font>
<font color=navy>// NOTE: again, ALGLIB can parallelize calculation of gradient</font>
<font color=navy>// over entire dataset - but our dataset is too small.</font>
<font color=navy>//</font>
smp_mlpkfoldcv(trn, network, 5, 10, rep);
<font color=navy>//</font>
<font color=navy>// Finally, we train early stopping ensemble of 50 neural networks,</font>
<font color=navy>// each of them is trained with 5 random restarts. I.e., 5*50=250</font>
<font color=navy>// networks aretrained in total.</font>
<font color=navy>//</font>
smp_mlptrainensemblees(trn, ensemble, 5, rep);
<b>return</b> 0;
}
</pre><a name='example_nn_regr'></a><h3 class=pageheader>nn_regr example</h3>
<pre class=source>
#include <font color=blue><b>"stdafx.h"</b></font>
#include <stdlib.h>
#include <stdio.h>
#include <math.h>
#include <font color=blue><b>"dataanalysis.h"</b></font>
using namespace alglib;
<b>int</b> main(<b>int</b> argc, char **argv)
{
<font color=navy>//</font>
<font color=navy>// The very simple example on neural network: network is trained to reproduce</font>
<font color=navy>// small 2x2 multiplication table.</font>
<font color=navy>//</font>
<font color=navy>// NOTE: we use network with excessive amount of neurons, which guarantees</font>
<font color=navy>// almost exact reproduction of the training set. Generalization ability</font>
<font color=navy>// of such network is rather low, but we are not concerned with such</font>
<font color=navy>// questions in this basic demo.</font>
<font color=navy>//</font>
mlptrainer trn;
multilayerperceptron network;
mlpreport rep;
<font color=navy>//</font>
<font color=navy>// Training set:</font>
<font color=navy>// * one row corresponds to one record A*B=C in the multiplication table</font>
<font color=navy>// * first two columns store A and B, last column stores C</font>
<font color=navy>//</font>
<font color=navy>// [1 * 1 = 1]</font>
<font color=navy>// [1 * 2 = 2]</font>
<font color=navy>// [2 * 1 = 2]</font>
<font color=navy>// [2 * 2 = 4]</font>
<font color=navy>//</font>
real_2d_array xy = <font color=blue><b>"[[1,1,1],[1,2,2],[2,1,2],[2,2,4]]"</b></font>;
<font color=navy>//</font>
<font color=navy>// Network is created.</font>
<font color=navy>// Trainer object is created.</font>
<font color=navy>// Dataset is attached to trainer object.</font>
<font color=navy>//</font>
mlpcreatetrainer(2, 1, trn);
mlpcreate1(2, 5, 1, network);
mlpsetdataset(trn, xy, 4);
<font color=navy>//</font>
<font color=navy>// Network is trained with 5 restarts from random positions</font>
<font color=navy>//</font>
mlptrainnetwork(trn, network, 5, rep);
<font color=navy>//</font>
<font color=navy>// 2*2=?</font>
<font color=navy>//</font>
real_1d_array x = <font color=blue><b>"[2,2]"</b></font>;
real_1d_array y = <font color=blue><b>"[0]"</b></font>;
mlpprocess(network, x, y);
printf(<font color=blue><b>"%s\n"</b></font>, y.tostring(1).c_str()); <font color=navy>// EXPECTED: [4.000]</font>
<b>return</b> 0;
}
</pre><a name='example_nn_regr_n'></a><h3 class=pageheader>nn_regr_n example</h3>
<pre class=source>
#include <font color=blue><b>"stdafx.h"</b></font>
#include <stdlib.h>
#include <stdio.h>
#include <math.h>
#include <font color=blue><b>"dataanalysis.h"</b></font>
using namespace alglib;
<b>int</b> main(<b>int</b> argc, char **argv)
{
<font color=navy>//</font>
<font color=navy>// Network with 2 inputs and 2 outputs is trained to reproduce vector function:</font>
<font color=navy>// (x0,x1) => (x0+x1, x0*x1)</font>
<font color=navy>//</font>
<font color=navy>// Informally speaking, we want neural network to simultaneously calculate</font>
<font color=navy>// both sum of two numbers and their product.</font>
<font color=navy>//</font>
<font color=navy>// NOTE: we use network with excessive amount of neurons, which guarantees</font>
<font color=navy>// almost exact reproduction of the training set. Generalization ability</font>
<font color=navy>// of such network is rather low, but we are not concerned with such</font>
<font color=navy>// questions in this basic demo.</font>
<font color=navy>//</font>
mlptrainer trn;
multilayerperceptron network;
mlpreport rep;
<font color=navy>//</font>
<font color=navy>// Training set. One row corresponds to one record [A,B,A+B,A*B].</font>
<font color=navy>//</font>
<font color=navy>// [ 1 1 1+1 1*1 ]</font>
<font color=navy>// [ 1 2 1+2 1*2 ]</font>
<font color=navy>// [ 2 1 2+1 2*1 ]</font>
<font color=navy>// [ 2 2 2+2 2*2 ]</font>
<font color=navy>//</font>
real_2d_array xy = <font color=blue><b>"[[1,1,2,1],[1,2,3,2],[2,1,3,2],[2,2,4,4]]"</b></font>;
<font color=navy>//</font>
<font color=navy>// Network is created.</font>
<font color=navy>// Trainer object is created.</font>
<font color=navy>// Dataset is attached to trainer object.</font>
<font color=navy>//</font>
mlpcreatetrainer(2, 2, trn);
mlpcreate1(2, 5, 2, network);
mlpsetdataset(trn, xy, 4);
<font color=navy>//</font>
<font color=navy>// Network is trained with 5 restarts from random positions</font>
<font color=navy>//</font>
mlptrainnetwork(trn, network, 5, rep);
<font color=navy>//</font>
<font color=navy>// 2+1=?</font>
<font color=navy>// 2*1=?</font>
<font color=navy>//</font>
real_1d_array x = <font color=blue><b>"[2,1]"</b></font>;
real_1d_array y = <font color=blue><b>"[0,0]"</b></font>;
mlpprocess(network, x, y);
printf(<font color=blue><b>"%s\n"</b></font>, y.tostring(1).c_str()); <font color=navy>// EXPECTED: [3.000,2.000]</font>
<b>return</b> 0;
}
</pre><a name='example_nn_trainerobject'></a><h3 class=pageheader>nn_trainerobject example</h3>
<pre class=source>
#include <font color=blue><b>"stdafx.h"</b></font>
#include <stdlib.h>
#include <stdio.h>
#include <math.h>
#include <font color=blue><b>"dataanalysis.h"</b></font>
using namespace alglib;
<b>int</b> main(<b>int</b> argc, char **argv)
{
<font color=navy>//</font>
<font color=navy>// Trainer object is used to train network. It stores dataset, training settings,</font>
<font color=navy>// and other information which is NOT part of neural network. You should use</font>
<font color=navy>// trainer object as follows:</font>
<font color=navy>// (1) you create trainer object and specify task type (classification/regression)</font>
<font color=navy>// and number of inputs/outputs</font>
<font color=navy>// (2) you add dataset to the trainer object</font>
<font color=navy>// (3) you may change training settings (stopping criteria or weight decay)</font>
<font color=navy>// (4) finally, you may train one or more networks</font>
<font color=navy>//</font>
<font color=navy>// You may interleave stages 2...4 and repeat them many times. Trainer object</font>
<font color=navy>// remembers its internal state and can be used several times after its creation</font>
<font color=navy>// and initialization.</font>
<font color=navy>//</font>
mlptrainer trn;
<font color=navy>//</font>
<font color=navy>// Stage 1: object creation.</font>
<font color=navy>//</font>
<font color=navy>// We have to specify number of inputs and outputs. Trainer object can be used</font>
<font color=navy>// only <b>for</b> problems with same number of inputs/outputs as was specified during</font>
<font color=navy>// its creation.</font>
<font color=navy>//</font>
<font color=navy>// In case you want to train SOFTMAX-normalized network which solves classification</font>
<font color=navy>// problems, you must use another function to create trainer object:</font>
<font color=navy>// mlpcreatetrainercls().</font>
<font color=navy>//</font>
<font color=navy>// Below we create trainer object which can be used to train regression networks</font>
<font color=navy>// with 2 inputs and 1 output.</font>
<font color=navy>//</font>
mlpcreatetrainer(2, 1, trn);
<font color=navy>//</font>
<font color=navy>// Stage 2: specification of the training set</font>
<font color=navy>//</font>
<font color=navy>// By default trainer object stores empty dataset. So to solve your non-empty problem</font>
<font color=navy>// you have to set dataset by passing to trainer dense or sparse matrix.</font>
<font color=navy>//</font>
<font color=navy>// One row of the matrix corresponds to one record A*B=C in the multiplication table.</font>
<font color=navy>// First two columns store A and B, last column stores C</font>
<font color=navy>//</font>
<font color=navy>// [1 * 1 = 1] [ 1 1 1 ]</font>
<font color=navy>// [1 * 2 = 2] [ 1 2 2 ]</font>
<font color=navy>// [2 * 1 = 2] = [ 2 1 2 ]</font>
<font color=navy>// [2 * 2 = 4] [ 2 2 4 ]</font>
<font color=navy>//</font>
real_2d_array xy = <font color=blue><b>"[[1,1,1],[1,2,2],[2,1,2],[2,2,4]]"</b></font>;
mlpsetdataset(trn, xy, 4);
<font color=navy>//</font>
<font color=navy>// Stage 3: modification of the training parameters.</font>
<font color=navy>//</font>
<font color=navy>// You may modify parameters like weights decay or stopping criteria:</font>
<font color=navy>// * we set moderate weight decay</font>
<font color=navy>// * we choose iterations limit as stopping condition (another condition - step size -</font>
<font color=navy>// is zero, which means than this condition is not active)</font>
<font color=navy>//</font>
<b>double</b> wstep = 0.000;
ae_int_t maxits = 100;
mlpsetdecay(trn, 0.01);
mlpsetcond(trn, wstep, maxits);
<font color=navy>//</font>
<font color=navy>// Stage 4: training.</font>
<font color=navy>//</font>
<font color=navy>// We will train several networks with different architecture using same trainer object.</font>
<font color=navy>// We may change training parameters or even dataset, so different networks are trained</font>
<font color=navy>// differently. But in this simple example we will train all networks with same settings.</font>
<font color=navy>//</font>
<font color=navy>// We create and train three networks:</font>
<font color=navy>// * network 1 has 2x1 architecture (2 inputs, no hidden neurons, 1 output)</font>
<font color=navy>// * network 2 has 2x5x1 architecture (2 inputs, 5 hidden neurons, 1 output)</font>
<font color=navy>// * network 3 has 2x5x5x1 architecture (2 inputs, two hidden layers, 1 output)</font>
<font color=navy>//</font>
<font color=navy>// NOTE: these networks solve regression problems. For classification problems you</font>
<font color=navy>// should use mlpcreatec0/c1/c2 to create neural networks which have SOFTMAX-</font>
<font color=navy>// normalized outputs.</font>
<font color=navy>//</font>
multilayerperceptron net1;
multilayerperceptron net2;
multilayerperceptron net3;
mlpreport rep;
mlpcreate0(2, 1, net1);
mlpcreate1(2, 5, 1, net2);
mlpcreate2(2, 5, 5, 1, net3);
mlptrainnetwork(trn, net1, 5, rep);
mlptrainnetwork(trn, net2, 5, rep);
mlptrainnetwork(trn, net3, 5, rep);
<b>return</b> 0;
}
</pre><a name=unit_nearestneighbor></a><h2 class=pageheader><code>nearestneighbor</code> subpackage</h2>
<div class=pagecontent>
<h3 class=pageheader>Classes</h3>
<a href='#struct_kdtree' class=toc>kdtree</a><br>
<h3 class=pageheader>Functions</h3>
<a href='#sub_kdtreebuild' class=toc>kdtreebuild</a><br>
<a href='#sub_kdtreebuildtagged' class=toc>kdtreebuildtagged</a><br>
<a href='#sub_kdtreequeryaknn' class=toc>kdtreequeryaknn</a><br>
<a href='#sub_kdtreequeryknn' class=toc>kdtreequeryknn</a><br>
<a href='#sub_kdtreequeryresultsdistances' class=toc>kdtreequeryresultsdistances</a><br>
<a href='#sub_kdtreequeryresultsdistancesi' class=toc>kdtreequeryresultsdistancesi</a><br>
<a href='#sub_kdtreequeryresultstags' class=toc>kdtreequeryresultstags</a><br>
<a href='#sub_kdtreequeryresultstagsi' class=toc>kdtreequeryresultstagsi</a><br>
<a href='#sub_kdtreequeryresultsx' class=toc>kdtreequeryresultsx</a><br>
<a href='#sub_kdtreequeryresultsxi' class=toc>kdtreequeryresultsxi</a><br>
<a href='#sub_kdtreequeryresultsxy' class=toc>kdtreequeryresultsxy</a><br>
<a href='#sub_kdtreequeryresultsxyi' class=toc>kdtreequeryresultsxyi</a><br>
<a href='#sub_kdtreequeryrnn' class=toc>kdtreequeryrnn</a><br>
<a href='#sub_kdtreeserialize' class=toc>kdtreeserialize</a><br>
<a href='#sub_kdtreeunserialize' class=toc>kdtreeunserialize</a><br>
<h3 class=pageheader>Examples</h3>
<table border=0 cellspacing=0 class='pagecontent'>
<tr align=left valign=top><td><a href='#example_nneighbor_d_1' class=toc>nneighbor_d_1</a></td><td width=15> </td><td>Nearest neighbor search, KNN queries</td></tr>
<tr align=left valign=top><td><a href='#example_nneighbor_d_2' class=toc>nneighbor_d_2</a></td><td width=15> </td><td>Serialization of KD-trees</td></tr>
</table></div>
<a name='struct_kdtree'></a><h3 class=pageheader><code>kdtree</code> class</h3>
<pre class=source>
<div style='color: navy; margin-top: 0; margin-bottom: 0;'>/*************************************************************************
*************************************************************************/
</div><div style='margin-top: 0; margin-bottom: 0;'><b>class</b> kdtree
{
};
</div></pre>
<a name='sub_kdtreebuild'></a><h3 class=pageheader><code>kdtreebuild</code> function</h3>
<pre class=source>
<div style='color: navy; margin-top: 0; margin-bottom: 0;'>/*************************************************************************
KD-tree creation
This subroutine creates KD-tree from set of X-values and optional Y-values
INPUT PARAMETERS
XY - dataset, array[0..N-1,0..NX+NY-1].
one row corresponds to one point.
first NX columns contain X-values, next NY (NY may be zero)
columns may contain associated Y-values
N - number of points, N>=0.
NX - space dimension, NX>=1.
NY - number of optional Y-values, NY>=0.
NormType- norm type:
* 0 denotes infinity-norm
* 1 denotes 1-norm
* 2 denotes 2-norm (Euclidean norm)
OUTPUT PARAMETERS
KDT - KD-tree
NOTES
1. KD-tree creation have O(N*logN) complexity and O(N*(2*NX+NY)) memory
requirements.
2. Although KD-trees may be used with any combination of N and NX, they
are more efficient than brute-force search only when N >> 4^NX. So they
are most useful in low-dimensional tasks (NX=2, NX=3). NX=1 is another
inefficient case, because simple binary search (without additional
structures) is much more efficient in such tasks than KD-trees.
-- ALGLIB --
Copyright 28.02.2010 by Bochkanov Sergey
*************************************************************************/
</div><div style='margin-top: 0; margin-bottom: 0;'><b>void</b> alglib::kdtreebuild(
real_2d_array xy,
ae_int_t nx,
ae_int_t ny,
ae_int_t normtype,
kdtree& kdt);
<b>void</b> alglib::kdtreebuild(
real_2d_array xy,
ae_int_t n,
ae_int_t nx,
ae_int_t ny,
ae_int_t normtype,
kdtree& kdt);
</div></pre>
<p align=left class=pagecontent><span class=inlineheader>Examples:</span> <a href='#example_nneighbor_d_1' class=nav>[1]</a> <a href='#example_nneighbor_d_2' class=nav>[2]</a> </p>
<a name='sub_kdtreebuildtagged'></a><h3 class=pageheader><code>kdtreebuildtagged</code> function</h3>
<pre class=source>
<div style='color: navy; margin-top: 0; margin-bottom: 0;'>/*************************************************************************
KD-tree creation
This subroutine creates KD-tree from set of X-values, integer tags and
optional Y-values
INPUT PARAMETERS
XY - dataset, array[0..N-1,0..NX+NY-1].
one row corresponds to one point.
first NX columns contain X-values, next NY (NY may be zero)
columns may contain associated Y-values
Tags - tags, array[0..N-1], contains integer tags associated
with points.
N - number of points, N>=0
NX - space dimension, NX>=1.
NY - number of optional Y-values, NY>=0.
NormType- norm type:
* 0 denotes infinity-norm
* 1 denotes 1-norm
* 2 denotes 2-norm (Euclidean norm)
OUTPUT PARAMETERS
KDT - KD-tree
NOTES
1. KD-tree creation have O(N*logN) complexity and O(N*(2*NX+NY)) memory
requirements.
2. Although KD-trees may be used with any combination of N and NX, they
are more efficient than brute-force search only when N >> 4^NX. So they
are most useful in low-dimensional tasks (NX=2, NX=3). NX=1 is another
inefficient case, because simple binary search (without additional
structures) is much more efficient in such tasks than KD-trees.
-- ALGLIB --
Copyright 28.02.2010 by Bochkanov Sergey
*************************************************************************/
</div><div style='margin-top: 0; margin-bottom: 0;'><b>void</b> alglib::kdtreebuildtagged(
real_2d_array xy,
integer_1d_array tags,
ae_int_t nx,
ae_int_t ny,
ae_int_t normtype,
kdtree& kdt);
<b>void</b> alglib::kdtreebuildtagged(
real_2d_array xy,
integer_1d_array tags,
ae_int_t n,
ae_int_t nx,
ae_int_t ny,
ae_int_t normtype,
kdtree& kdt);
</div></pre>
<p align=left class=pagecontent><span class=inlineheader>Examples:</span> <a href='#example_nneighbor_d_1' class=nav>[1]</a> </p>
<a name='sub_kdtreequeryaknn'></a><h3 class=pageheader><code>kdtreequeryaknn</code> function</h3>
<pre class=source>
<div style='color: navy; margin-top: 0; margin-bottom: 0;'>/*************************************************************************
K-NN query: approximate K nearest neighbors
INPUT PARAMETERS
KDT - KD-tree
X - point, array[0..NX-1].
K - number of neighbors to return, K>=1
SelfMatch - whether self-matches are allowed:
* if True, nearest neighbor may be the point itself
(if it exists in original dataset)
* if False, then only points with non-zero distance
are returned
* if not given, considered True
Eps - approximation factor, Eps>=0. eps-approximate nearest
neighbor is a neighbor whose distance from X is at
most (1+eps) times distance of true nearest neighbor.
RESULT
number of actual neighbors found (either K or N, if K>N).
NOTES
significant performance gain may be achieved only when Eps is is on
the order of magnitude of 1 or larger.
This subroutine performs query and stores its result in the internal
structures of the KD-tree. You can use following subroutines to obtain
these results:
* KDTreeQueryResultsX() to get X-values
* KDTreeQueryResultsXY() to get X- and Y-values
* KDTreeQueryResultsTags() to get tag values
* KDTreeQueryResultsDistances() to get distances
-- ALGLIB --
Copyright 28.02.2010 by Bochkanov Sergey
*************************************************************************/
</div><div style='margin-top: 0; margin-bottom: 0;'>ae_int_t alglib::kdtreequeryaknn(
kdtree kdt,
real_1d_array x,
ae_int_t k,
<b>double</b> eps);
ae_int_t alglib::kdtreequeryaknn(
kdtree kdt,
real_1d_array x,
ae_int_t k,
<b>bool</b> selfmatch,
<b>double</b> eps);
</div></pre>
<p align=left class=pagecontent><span class=inlineheader>Examples:</span> <a href='#example_nneighbor_d_1' class=nav>[1]</a> </p>
<a name='sub_kdtreequeryknn'></a><h3 class=pageheader><code>kdtreequeryknn</code> function</h3>
<pre class=source>
<div style='color: navy; margin-top: 0; margin-bottom: 0;'>/*************************************************************************
K-NN query: K nearest neighbors
INPUT PARAMETERS
KDT - KD-tree
X - point, array[0..NX-1].
K - number of neighbors to return, K>=1
SelfMatch - whether self-matches are allowed:
* if True, nearest neighbor may be the point itself
(if it exists in original dataset)
* if False, then only points with non-zero distance
are returned
* if not given, considered True
RESULT
number of actual neighbors found (either K or N, if K>N).
This subroutine performs query and stores its result in the internal
structures of the KD-tree. You can use following subroutines to obtain
these results:
* KDTreeQueryResultsX() to get X-values
* KDTreeQueryResultsXY() to get X- and Y-values
* KDTreeQueryResultsTags() to get tag values
* KDTreeQueryResultsDistances() to get distances
-- ALGLIB --
Copyright 28.02.2010 by Bochkanov Sergey
*************************************************************************/
</div><div style='margin-top: 0; margin-bottom: 0;'>ae_int_t alglib::kdtreequeryknn(kdtree kdt, real_1d_array x, ae_int_t k);
ae_int_t alglib::kdtreequeryknn(
kdtree kdt,
real_1d_array x,
ae_int_t k,
<b>bool</b> selfmatch);
</div></pre>
<p align=left class=pagecontent><span class=inlineheader>Examples:</span> <a href='#example_nneighbor_d_1' class=nav>[1]</a> </p>
<a name='sub_kdtreequeryresultsdistances'></a><h3 class=pageheader><code>kdtreequeryresultsdistances</code> function</h3>
<pre class=source>
<div style='color: navy; margin-top: 0; margin-bottom: 0;'>/*************************************************************************
Distances from last query
INPUT PARAMETERS
KDT - KD-tree
R - possibly pre-allocated buffer. If X is too small to store
result, it is resized. If size(X) is enough to store
result, it is left unchanged.
OUTPUT PARAMETERS
R - filled with distances (in corresponding norm)
NOTES
1. points are ordered by distance from the query point (first = closest)
2. if XY is larger than required to store result, only leading part will
be overwritten; trailing part will be left unchanged. So if on input
XY = [[A,B],[C,D]], and result is [1,2], then on exit we will get
XY = [[1,2],[C,D]]. This is done purposely to increase performance; if
you want function to resize array according to result size, use
function with same name and suffix 'I'.
SEE ALSO
* KDTreeQueryResultsX() X-values
* KDTreeQueryResultsXY() X- and Y-values
* KDTreeQueryResultsTags() tag values
-- ALGLIB --
Copyright 28.02.2010 by Bochkanov Sergey
*************************************************************************/
</div><div style='margin-top: 0; margin-bottom: 0;'><b>void</b> alglib::kdtreequeryresultsdistances(kdtree kdt, real_1d_array& r);
</div></pre>
<p align=left class=pagecontent><span class=inlineheader>Examples:</span> <a href='#example_nneighbor_d_1' class=nav>[1]</a> </p>
<a name='sub_kdtreequeryresultsdistancesi'></a><h3 class=pageheader><code>kdtreequeryresultsdistancesi</code> function</h3>
<pre class=source>
<div style='color: navy; margin-top: 0; margin-bottom: 0;'>/*************************************************************************
Distances from last query; 'interactive' variant for languages like Python
which support constructs like "R = KDTreeQueryResultsDistancesI(KDT)"
and interactive mode of interpreter.
This function allocates new array on each call, so it is significantly
slower than its 'non-interactive' counterpart, but it is more convenient
when you call it from command line.
-- ALGLIB --
Copyright 28.02.2010 by Bochkanov Sergey
*************************************************************************/
</div><div style='margin-top: 0; margin-bottom: 0;'><b>void</b> alglib::kdtreequeryresultsdistancesi(kdtree kdt, real_1d_array& r);
</div></pre>
<a name='sub_kdtreequeryresultstags'></a><h3 class=pageheader><code>kdtreequeryresultstags</code> function</h3>
<pre class=source>
<div style='color: navy; margin-top: 0; margin-bottom: 0;'>/*************************************************************************
Tags from last query
INPUT PARAMETERS
KDT - KD-tree
Tags - possibly pre-allocated buffer. If X is too small to store
result, it is resized. If size(X) is enough to store
result, it is left unchanged.
OUTPUT PARAMETERS
Tags - filled with tags associated with points,
or, when no tags were supplied, with zeros
NOTES
1. points are ordered by distance from the query point (first = closest)
2. if XY is larger than required to store result, only leading part will
be overwritten; trailing part will be left unchanged. So if on input
XY = [[A,B],[C,D]], and result is [1,2], then on exit we will get
XY = [[1,2],[C,D]]. This is done purposely to increase performance; if
you want function to resize array according to result size, use
function with same name and suffix 'I'.
SEE ALSO
* KDTreeQueryResultsX() X-values
* KDTreeQueryResultsXY() X- and Y-values
* KDTreeQueryResultsDistances() distances
-- ALGLIB --
Copyright 28.02.2010 by Bochkanov Sergey
*************************************************************************/
</div><div style='margin-top: 0; margin-bottom: 0;'><b>void</b> alglib::kdtreequeryresultstags(kdtree kdt, integer_1d_array& tags);
</div></pre>
<p align=left class=pagecontent><span class=inlineheader>Examples:</span> <a href='#example_nneighbor_d_1' class=nav>[1]</a> </p>
<a name='sub_kdtreequeryresultstagsi'></a><h3 class=pageheader><code>kdtreequeryresultstagsi</code> function</h3>
<pre class=source>
<div style='color: navy; margin-top: 0; margin-bottom: 0;'>/*************************************************************************
Tags from last query; 'interactive' variant for languages like Python
which support constructs like "Tags = KDTreeQueryResultsTagsI(KDT)" and
interactive mode of interpreter.
This function allocates new array on each call, so it is significantly
slower than its 'non-interactive' counterpart, but it is more convenient
when you call it from command line.
-- ALGLIB --
Copyright 28.02.2010 by Bochkanov Sergey
*************************************************************************/
</div><div style='margin-top: 0; margin-bottom: 0;'><b>void</b> alglib::kdtreequeryresultstagsi(kdtree kdt, integer_1d_array& tags);
</div></pre>
<a name='sub_kdtreequeryresultsx'></a><h3 class=pageheader><code>kdtreequeryresultsx</code> function</h3>
<pre class=source>
<div style='color: navy; margin-top: 0; margin-bottom: 0;'>/*************************************************************************
X-values from last query
INPUT PARAMETERS
KDT - KD-tree
X - possibly pre-allocated buffer. If X is too small to store
result, it is resized. If size(X) is enough to store
result, it is left unchanged.
OUTPUT PARAMETERS
X - rows are filled with X-values
NOTES
1. points are ordered by distance from the query point (first = closest)
2. if XY is larger than required to store result, only leading part will
be overwritten; trailing part will be left unchanged. So if on input
XY = [[A,B],[C,D]], and result is [1,2], then on exit we will get
XY = [[1,2],[C,D]]. This is done purposely to increase performance; if
you want function to resize array according to result size, use
function with same name and suffix 'I'.
SEE ALSO
* KDTreeQueryResultsXY() X- and Y-values
* KDTreeQueryResultsTags() tag values
* KDTreeQueryResultsDistances() distances
-- ALGLIB --
Copyright 28.02.2010 by Bochkanov Sergey
*************************************************************************/
</div><div style='margin-top: 0; margin-bottom: 0;'><b>void</b> alglib::kdtreequeryresultsx(kdtree kdt, real_2d_array& x);
</div></pre>
<p align=left class=pagecontent><span class=inlineheader>Examples:</span> <a href='#example_nneighbor_d_1' class=nav>[1]</a> </p>
<a name='sub_kdtreequeryresultsxi'></a><h3 class=pageheader><code>kdtreequeryresultsxi</code> function</h3>
<pre class=source>
<div style='color: navy; margin-top: 0; margin-bottom: 0;'>/*************************************************************************
X-values from last query; 'interactive' variant for languages like Python
which support constructs like "X = KDTreeQueryResultsXI(KDT)" and
interactive mode of interpreter.
This function allocates new array on each call, so it is significantly
slower than its 'non-interactive' counterpart, but it is more convenient
when you call it from command line.
-- ALGLIB --
Copyright 28.02.2010 by Bochkanov Sergey
*************************************************************************/
</div><div style='margin-top: 0; margin-bottom: 0;'><b>void</b> alglib::kdtreequeryresultsxi(kdtree kdt, real_2d_array& x);
</div></pre>
<a name='sub_kdtreequeryresultsxy'></a><h3 class=pageheader><code>kdtreequeryresultsxy</code> function</h3>
<pre class=source>
<div style='color: navy; margin-top: 0; margin-bottom: 0;'>/*************************************************************************
X- and Y-values from last query
INPUT PARAMETERS
KDT - KD-tree
XY - possibly pre-allocated buffer. If XY is too small to store
result, it is resized. If size(XY) is enough to store
result, it is left unchanged.
OUTPUT PARAMETERS
XY - rows are filled with points: first NX columns with
X-values, next NY columns - with Y-values.
NOTES
1. points are ordered by distance from the query point (first = closest)
2. if XY is larger than required to store result, only leading part will
be overwritten; trailing part will be left unchanged. So if on input
XY = [[A,B],[C,D]], and result is [1,2], then on exit we will get
XY = [[1,2],[C,D]]. This is done purposely to increase performance; if
you want function to resize array according to result size, use
function with same name and suffix 'I'.
SEE ALSO
* KDTreeQueryResultsX() X-values
* KDTreeQueryResultsTags() tag values
* KDTreeQueryResultsDistances() distances
-- ALGLIB --
Copyright 28.02.2010 by Bochkanov Sergey
*************************************************************************/
</div><div style='margin-top: 0; margin-bottom: 0;'><b>void</b> alglib::kdtreequeryresultsxy(kdtree kdt, real_2d_array& xy);
</div></pre>
<p align=left class=pagecontent><span class=inlineheader>Examples:</span> <a href='#example_nneighbor_d_1' class=nav>[1]</a> </p>
<a name='sub_kdtreequeryresultsxyi'></a><h3 class=pageheader><code>kdtreequeryresultsxyi</code> function</h3>
<pre class=source>
<div style='color: navy; margin-top: 0; margin-bottom: 0;'>/*************************************************************************
XY-values from last query; 'interactive' variant for languages like Python
which support constructs like "XY = KDTreeQueryResultsXYI(KDT)" and
interactive mode of interpreter.
This function allocates new array on each call, so it is significantly
slower than its 'non-interactive' counterpart, but it is more convenient
when you call it from command line.
-- ALGLIB --
Copyright 28.02.2010 by Bochkanov Sergey
*************************************************************************/
</div><div style='margin-top: 0; margin-bottom: 0;'><b>void</b> alglib::kdtreequeryresultsxyi(kdtree kdt, real_2d_array& xy);
</div></pre>
<a name='sub_kdtreequeryrnn'></a><h3 class=pageheader><code>kdtreequeryrnn</code> function</h3>
<pre class=source>
<div style='color: navy; margin-top: 0; margin-bottom: 0;'>/*************************************************************************
R-NN query: all points within R-sphere centered at X
INPUT PARAMETERS
KDT - KD-tree
X - point, array[0..NX-1].
R - radius of sphere (in corresponding norm), R>0
SelfMatch - whether self-matches are allowed:
* if True, nearest neighbor may be the point itself
(if it exists in original dataset)
* if False, then only points with non-zero distance
are returned
* if not given, considered True
RESULT
number of neighbors found, >=0
This subroutine performs query and stores its result in the internal
structures of the KD-tree. You can use following subroutines to obtain
actual results:
* KDTreeQueryResultsX() to get X-values
* KDTreeQueryResultsXY() to get X- and Y-values
* KDTreeQueryResultsTags() to get tag values
* KDTreeQueryResultsDistances() to get distances
-- ALGLIB --
Copyright 28.02.2010 by Bochkanov Sergey
*************************************************************************/
</div><div style='margin-top: 0; margin-bottom: 0;'>ae_int_t alglib::kdtreequeryrnn(kdtree kdt, real_1d_array x, <b>double</b> r);
ae_int_t alglib::kdtreequeryrnn(
kdtree kdt,
real_1d_array x,
<b>double</b> r,
<b>bool</b> selfmatch);
</div></pre>
<p align=left class=pagecontent><span class=inlineheader>Examples:</span> <a href='#example_nneighbor_d_1' class=nav>[1]</a> </p>
<a name='sub_kdtreeserialize'></a><h3 class=pageheader><code>kdtreeserialize</code> function</h3>
<pre class=source>
<div style='color: navy; margin-top: 0; margin-bottom: 0;'>/*************************************************************************
This function serializes data structure to string.
Important properties of s_out:
* it contains alphanumeric characters, dots, underscores, minus signs
* these symbols are grouped into words, which are separated by spaces
and Windows-style (CR+LF) newlines
* although serializer uses spaces and CR+LF as separators, you can
replace any separator character by arbitrary combination of spaces,
tabs, Windows or Unix newlines. It allows flexible reformatting of
the string in case you want to include it into text or XML file.
But you should not insert separators into the middle of the "words"
nor you should change case of letters.
* s_out can be freely moved between 32-bit and 64-bit systems, little
and big endian machines, and so on. You can serialize structure on
32-bit machine and unserialize it on 64-bit one (or vice versa), or
serialize it on SPARC and unserialize on x86. You can also
serialize it in C++ version of ALGLIB and unserialize in C# one,
and vice versa.
*************************************************************************/
</div><div style='margin-top: 0; margin-bottom: 0;'><b>void</b> kdtreeserialize(kdtree &obj, std::string &s_out);
</div></pre>
<a name='sub_kdtreeunserialize'></a><h3 class=pageheader><code>kdtreeunserialize</code> function</h3>
<pre class=source>
<div style='color: navy; margin-top: 0; margin-bottom: 0;'>/*************************************************************************
This function unserializes data structure from string.
*************************************************************************/
</div><div style='margin-top: 0; margin-bottom: 0;'><b>void</b> kdtreeunserialize(std::string &s_in, kdtree &obj);
</div></pre>
<a name='example_nneighbor_d_1'></a><h3 class=pageheader>nneighbor_d_1 example</h3>
<pre class=source>
#include <font color=blue><b>"stdafx.h"</b></font>
#include <stdlib.h>
#include <stdio.h>
#include <math.h>
#include <font color=blue><b>"alglibmisc.h"</b></font>
using namespace alglib;
<b>int</b> main(<b>int</b> argc, char **argv)
{
real_2d_array a = <font color=blue><b>"[[0,0],[0,1],[1,0],[1,1]]"</b></font>;
ae_int_t nx = 2;
ae_int_t ny = 0;
ae_int_t normtype = 2;
kdtree kdt;
real_1d_array x;
real_2d_array r = <font color=blue><b>"[[]]"</b></font>;
ae_int_t k;
kdtreebuild(a, nx, ny, normtype, kdt);
x = <font color=blue><b>"[-1,0]"</b></font>;
k = kdtreequeryknn(kdt, x, 1);
printf(<font color=blue><b>"%d\n"</b></font>, <b>int</b>(k)); <font color=navy>// EXPECTED: 1</font>
kdtreequeryresultsx(kdt, r);
printf(<font color=blue><b>"%s\n"</b></font>, r.tostring(1).c_str()); <font color=navy>// EXPECTED: [[0,0]]</font>
<b>return</b> 0;
}
</pre><a name='example_nneighbor_d_2'></a><h3 class=pageheader>nneighbor_d_2 example</h3>
<pre class=source>
#include <font color=blue><b>"stdafx.h"</b></font>
#include <stdlib.h>
#include <stdio.h>
#include <math.h>
#include <font color=blue><b>"alglibmisc.h"</b></font>
using namespace alglib;
<b>int</b> main(<b>int</b> argc, char **argv)
{
real_2d_array a = <font color=blue><b>"[[0,0],[0,1],[1,0],[1,1]]"</b></font>;
ae_int_t nx = 2;
ae_int_t ny = 0;
ae_int_t normtype = 2;
kdtree kdt0;
kdtree kdt1;
std::string s;
real_1d_array x;
real_2d_array r0 = <font color=blue><b>"[[]]"</b></font>;
real_2d_array r1 = <font color=blue><b>"[[]]"</b></font>;
<font color=navy>//</font>
<font color=navy>// Build tree and serialize it</font>
<font color=navy>//</font>
kdtreebuild(a, nx, ny, normtype, kdt0);
alglib::kdtreeserialize(kdt0, s);
alglib::kdtreeunserialize(s, kdt1);
<font color=navy>//</font>
<font color=navy>// Compare results from KNN queries</font>
<font color=navy>//</font>
x = <font color=blue><b>"[-1,0]"</b></font>;
kdtreequeryknn(kdt0, x, 1);
kdtreequeryresultsx(kdt0, r0);
kdtreequeryknn(kdt1, x, 1);
kdtreequeryresultsx(kdt1, r1);
printf(<font color=blue><b>"%s\n"</b></font>, r0.tostring(1).c_str()); <font color=navy>// EXPECTED: [[0,0]]</font>
printf(<font color=blue><b>"%s\n"</b></font>, r1.tostring(1).c_str()); <font color=navy>// EXPECTED: [[0,0]]</font>
<b>return</b> 0;
}
</pre><a name=unit_nleq></a><h2 class=pageheader><code>nleq</code> subpackage</h2>
<div class=pagecontent>
<h3 class=pageheader>Classes</h3>
<a href='#struct_nleqreport' class=toc>nleqreport</a><br>
<a href='#struct_nleqstate' class=toc>nleqstate</a><br>
<h3 class=pageheader>Functions</h3>
<a href='#sub_nleqcreatelm' class=toc>nleqcreatelm</a><br>
<a href='#sub_nleqrestartfrom' class=toc>nleqrestartfrom</a><br>
<a href='#sub_nleqresults' class=toc>nleqresults</a><br>
<a href='#sub_nleqresultsbuf' class=toc>nleqresultsbuf</a><br>
<a href='#sub_nleqsetcond' class=toc>nleqsetcond</a><br>
<a href='#sub_nleqsetstpmax' class=toc>nleqsetstpmax</a><br>
<a href='#sub_nleqsetxrep' class=toc>nleqsetxrep</a><br>
<a href='#sub_nleqsolve' class=toc>nleqsolve</a><br>
<h3 class=pageheader>Examples</h3>
<table border=0 cellspacing=0 class='pagecontent'>
</table></div>
<a name='struct_nleqreport'></a><h3 class=pageheader><code>nleqreport</code> class</h3>
<pre class=source>
<div style='color: navy; margin-top: 0; margin-bottom: 0;'>/*************************************************************************
*************************************************************************/
</div><div style='margin-top: 0; margin-bottom: 0;'><b>class</b> nleqreport
{
ae_int_t iterationscount;
ae_int_t nfunc;
ae_int_t njac;
ae_int_t terminationtype;
};
</div></pre>
<a name='struct_nleqstate'></a><h3 class=pageheader><code>nleqstate</code> class</h3>
<pre class=source>
<div style='color: navy; margin-top: 0; margin-bottom: 0;'>/*************************************************************************
*************************************************************************/
</div><div style='margin-top: 0; margin-bottom: 0;'><b>class</b> nleqstate
{
};
</div></pre>
<a name='sub_nleqcreatelm'></a><h3 class=pageheader><code>nleqcreatelm</code> function</h3>
<pre class=source>
<div style='color: navy; margin-top: 0; margin-bottom: 0;'>/*************************************************************************
LEVENBERG-MARQUARDT-LIKE NONLINEAR SOLVER
DESCRIPTION:
This algorithm solves system of nonlinear equations
F[0](x[0], ..., x[n-1]) = 0
F[1](x[0], ..., x[n-1]) = 0
...
F[M-1](x[0], ..., x[n-1]) = 0
with M/N do not necessarily coincide. Algorithm converges quadratically
under following conditions:
* the solution set XS is nonempty
* for some xs in XS there exist such neighbourhood N(xs) that:
* vector function F(x) and its Jacobian J(x) are continuously
differentiable on N
* ||F(x)|| provides local error bound on N, i.e. there exists such
c1, that ||F(x)||>c1*distance(x,XS)
Note that these conditions are much more weaker than usual non-singularity
conditions. For example, algorithm will converge for any affine function
F (whether its Jacobian singular or not).
REQUIREMENTS:
Algorithm will request following information during its operation:
* function vector F[] and Jacobian matrix at given point X
* value of merit function f(x)=F[0]^2(x)+...+F[M-1]^2(x) at given point X
USAGE:
1. User initializes algorithm state with NLEQCreateLM() call
2. User tunes solver parameters with NLEQSetCond(), NLEQSetStpMax() and
other functions
3. User calls NLEQSolve() function which takes algorithm state and
pointers (delegates, etc.) to callback functions which calculate merit
function value and Jacobian.
4. User calls NLEQResults() to get solution
5. Optionally, user may call NLEQRestartFrom() to solve another problem
with same parameters (N/M) but another starting point and/or another
function vector. NLEQRestartFrom() allows to reuse already initialized
structure.
INPUT PARAMETERS:
N - space dimension, N>1:
* if provided, only leading N elements of X are used
* if not provided, determined automatically from size of X
M - system size
X - starting point
OUTPUT PARAMETERS:
State - structure which stores algorithm state
NOTES:
1. you may tune stopping conditions with NLEQSetCond() function
2. if target function contains exp() or other fast growing functions, and
optimization algorithm makes too large steps which leads to overflow,
use NLEQSetStpMax() function to bound algorithm's steps.
3. this algorithm is a slightly modified implementation of the method
described in 'Levenberg-Marquardt method for constrained nonlinear
equations with strong local convergence properties' by Christian Kanzow
Nobuo Yamashita and Masao Fukushima and further developed in 'On the
convergence of a New Levenberg-Marquardt Method' by Jin-yan Fan and
Ya-Xiang Yuan.
-- ALGLIB --
Copyright 20.08.2009 by Bochkanov Sergey
*************************************************************************/
</div><div style='margin-top: 0; margin-bottom: 0;'><b>void</b> alglib::nleqcreatelm(ae_int_t m, real_1d_array x, nleqstate& state);
<b>void</b> alglib::nleqcreatelm(
ae_int_t n,
ae_int_t m,
real_1d_array x,
nleqstate& state);
</div></pre>
<a name='sub_nleqrestartfrom'></a><h3 class=pageheader><code>nleqrestartfrom</code> function</h3>
<pre class=source>
<div style='color: navy; margin-top: 0; margin-bottom: 0;'>/*************************************************************************
This subroutine restarts CG algorithm from new point. All optimization
parameters are left unchanged.
This function allows to solve multiple optimization problems (which
must have same number of dimensions) without object reallocation penalty.
INPUT PARAMETERS:
State - structure used for reverse communication previously
allocated with MinCGCreate call.
X - new starting point.
BndL - new lower bounds
BndU - new upper bounds
-- ALGLIB --
Copyright 30.07.2010 by Bochkanov Sergey
*************************************************************************/
</div><div style='margin-top: 0; margin-bottom: 0;'><b>void</b> alglib::nleqrestartfrom(nleqstate state, real_1d_array x);
</div></pre>
<a name='sub_nleqresults'></a><h3 class=pageheader><code>nleqresults</code> function</h3>
<pre class=source>
<div style='color: navy; margin-top: 0; margin-bottom: 0;'>/*************************************************************************
NLEQ solver results
INPUT PARAMETERS:
State - algorithm state.
OUTPUT PARAMETERS:
X - array[0..N-1], solution
Rep - optimization report:
* Rep.TerminationType completetion code:
* -4 ERROR: algorithm has converged to the
stationary point Xf which is local minimum of
f=F[0]^2+...+F[m-1]^2, but is not solution of
nonlinear system.
* 1 sqrt(f)<=EpsF.
* 5 MaxIts steps was taken
* 7 stopping conditions are too stringent,
further improvement is impossible
* Rep.IterationsCount contains iterations count
* NFEV countains number of function calculations
* ActiveConstraints contains number of active constraints
-- ALGLIB --
Copyright 20.08.2009 by Bochkanov Sergey
*************************************************************************/
</div><div style='margin-top: 0; margin-bottom: 0;'><b>void</b> alglib::nleqresults(
nleqstate state,
real_1d_array& x,
nleqreport& rep);
</div></pre>
<a name='sub_nleqresultsbuf'></a><h3 class=pageheader><code>nleqresultsbuf</code> function</h3>
<pre class=source>
<div style='color: navy; margin-top: 0; margin-bottom: 0;'>/*************************************************************************
NLEQ solver results
Buffered implementation of NLEQResults(), which uses pre-allocated buffer
to store X[]. If buffer size is too small, it resizes buffer. It is
intended to be used in the inner cycles of performance critical algorithms
where array reallocation penalty is too large to be ignored.
-- ALGLIB --
Copyright 20.08.2009 by Bochkanov Sergey
*************************************************************************/
</div><div style='margin-top: 0; margin-bottom: 0;'><b>void</b> alglib::nleqresultsbuf(
nleqstate state,
real_1d_array& x,
nleqreport& rep);
</div></pre>
<a name='sub_nleqsetcond'></a><h3 class=pageheader><code>nleqsetcond</code> function</h3>
<pre class=source>
<div style='color: navy; margin-top: 0; margin-bottom: 0;'>/*************************************************************************
This function sets stopping conditions for the nonlinear solver
INPUT PARAMETERS:
State - structure which stores algorithm state
EpsF - >=0
The subroutine finishes its work if on k+1-th iteration
the condition ||F||<=EpsF is satisfied
MaxIts - maximum number of iterations. If MaxIts=0, the number of
iterations is unlimited.
Passing EpsF=0 and MaxIts=0 simultaneously will lead to automatic
stopping criterion selection (small EpsF).
NOTES:
-- ALGLIB --
Copyright 20.08.2010 by Bochkanov Sergey
*************************************************************************/
</div><div style='margin-top: 0; margin-bottom: 0;'><b>void</b> alglib::nleqsetcond(nleqstate state, <b>double</b> epsf, ae_int_t maxits);
</div></pre>
<a name='sub_nleqsetstpmax'></a><h3 class=pageheader><code>nleqsetstpmax</code> function</h3>
<pre class=source>
<div style='color: navy; margin-top: 0; margin-bottom: 0;'>/*************************************************************************
This function sets maximum step length
INPUT PARAMETERS:
State - structure which stores algorithm state
StpMax - maximum step length, >=0. Set StpMax to 0.0, if you don't
want to limit step length.
Use this subroutine when target function contains exp() or other fast
growing functions, and algorithm makes too large steps which lead to
overflow. This function allows us to reject steps that are too large (and
therefore expose us to the possible overflow) without actually calculating
function value at the x+stp*d.
-- ALGLIB --
Copyright 20.08.2010 by Bochkanov Sergey
*************************************************************************/
</div><div style='margin-top: 0; margin-bottom: 0;'><b>void</b> alglib::nleqsetstpmax(nleqstate state, <b>double</b> stpmax);
</div></pre>
<a name='sub_nleqsetxrep'></a><h3 class=pageheader><code>nleqsetxrep</code> function</h3>
<pre class=source>
<div style='color: navy; margin-top: 0; margin-bottom: 0;'>/*************************************************************************
This function turns on/off reporting.
INPUT PARAMETERS:
State - structure which stores algorithm state
NeedXRep- whether iteration reports are needed or not
If NeedXRep is True, algorithm will call rep() callback function if it is
provided to NLEQSolve().
-- ALGLIB --
Copyright 20.08.2010 by Bochkanov Sergey
*************************************************************************/
</div><div style='margin-top: 0; margin-bottom: 0;'><b>void</b> alglib::nleqsetxrep(nleqstate state, <b>bool</b> needxrep);
</div></pre>
<a name='sub_nleqsolve'></a><h3 class=pageheader><code>nleqsolve</code> function</h3>
<pre class=source>
<div style='color: navy; margin-top: 0; margin-bottom: 0;'>/*************************************************************************
This family of functions is used to launcn iterations of nonlinear solver
These functions accept following parameters:
state - algorithm state
func - callback which calculates function (or merit function)
value func at given point x
jac - callback which calculates function vector fi[]
and Jacobian jac at given point x
rep - optional callback which is called after each iteration
can be NULL
ptr - optional pointer which is passed to func/grad/hess/jac/rep
can be NULL
-- ALGLIB --
Copyright 20.03.2009 by Bochkanov Sergey
*************************************************************************/
</div><div style='margin-top: 0; margin-bottom: 0;'><b>void</b> nleqsolve(nleqstate &state,
<b>void</b> (*func)(<b>const</b> real_1d_array &x, <b>double</b> &func, <b>void</b> *ptr),
<b>void</b> (*jac)(<b>const</b> real_1d_array &x, real_1d_array &fi, real_2d_array &jac, <b>void</b> *ptr),
<b>void</b> (*rep)(<b>const</b> real_1d_array &x, <b>double</b> func, <b>void</b> *ptr) = NULL,
<b>void</b> *ptr = NULL);
</div></pre>
<a name=unit_normaldistr></a><h2 class=pageheader><code>normaldistr</code> subpackage</h2>
<div class=pagecontent>
<h3 class=pageheader>Functions</h3>
<a href='#sub_errorfunction' class=toc>errorfunction</a><br>
<a href='#sub_errorfunctionc' class=toc>errorfunctionc</a><br>
<a href='#sub_inverf' class=toc>inverf</a><br>
<a href='#sub_invnormaldistribution' class=toc>invnormaldistribution</a><br>
<a href='#sub_normaldistribution' class=toc>normaldistribution</a><br>
<h3 class=pageheader>Examples</h3>
<table border=0 cellspacing=0 class='pagecontent'>
</table></div>
<a name='sub_errorfunction'></a><h3 class=pageheader><code>errorfunction</code> function</h3>
<pre class=source>
<div style='color: navy; margin-top: 0; margin-bottom: 0;'>/*************************************************************************
Error function
The integral is
x
-
2 | | 2
erf(x) = -------- | exp( - t ) dt.
sqrt(pi) | |
-
0
For 0 <= |x| < 1, erf(x) = x * P4(x**2)/Q5(x**2); otherwise
erf(x) = 1 - erfc(x).
ACCURACY:
Relative error:
arithmetic domain # trials peak rms
IEEE 0,1 30000 3.7e-16 1.0e-16
Cephes Math Library Release 2.8: June, 2000
Copyright 1984, 1987, 1988, 1992, 2000 by Stephen L. Moshier
*************************************************************************/
</div><div style='margin-top: 0; margin-bottom: 0;'><b>double</b> alglib::errorfunction(<b>double</b> x);
</div></pre>
<a name='sub_errorfunctionc'></a><h3 class=pageheader><code>errorfunctionc</code> function</h3>
<pre class=source>
<div style='color: navy; margin-top: 0; margin-bottom: 0;'>/*************************************************************************
Complementary error function
1 - erf(x) =
inf.
-
2 | | 2
erfc(x) = -------- | exp( - t ) dt
sqrt(pi) | |
-
x
For small x, erfc(x) = 1 - erf(x); otherwise rational
approximations are computed.
ACCURACY:
Relative error:
arithmetic domain # trials peak rms
IEEE 0,26.6417 30000 5.7e-14 1.5e-14
Cephes Math Library Release 2.8: June, 2000
Copyright 1984, 1987, 1988, 1992, 2000 by Stephen L. Moshier
*************************************************************************/
</div><div style='margin-top: 0; margin-bottom: 0;'><b>double</b> alglib::errorfunctionc(<b>double</b> x);
</div></pre>
<a name='sub_inverf'></a><h3 class=pageheader><code>inverf</code> function</h3>
<pre class=source>
<div style='color: navy; margin-top: 0; margin-bottom: 0;'>/*************************************************************************
Inverse of the error function
Cephes Math Library Release 2.8: June, 2000
Copyright 1984, 1987, 1988, 1992, 2000 by Stephen L. Moshier
*************************************************************************/
</div><div style='margin-top: 0; margin-bottom: 0;'><b>double</b> alglib::inverf(<b>double</b> e);
</div></pre>
<a name='sub_invnormaldistribution'></a><h3 class=pageheader><code>invnormaldistribution</code> function</h3>
<pre class=source>
<div style='color: navy; margin-top: 0; margin-bottom: 0;'>/*************************************************************************
Inverse of Normal distribution function
Returns the argument, x, for which the area under the
Gaussian probability density function (integrated from
minus infinity to x) is equal to y.
For small arguments 0 < y < exp(-2), the program computes
z = sqrt( -2.0 * log(y) ); then the approximation is
x = z - log(z)/z - (1/z) P(1/z) / Q(1/z).
There are two rational functions P/Q, one for 0 < y < exp(-32)
and the other for y up to exp(-2). For larger arguments,
w = y - 0.5, and x/sqrt(2pi) = w + w**3 R(w**2)/S(w**2)).
ACCURACY:
Relative error:
arithmetic domain # trials peak rms
IEEE 0.125, 1 20000 7.2e-16 1.3e-16
IEEE 3e-308, 0.135 50000 4.6e-16 9.8e-17
Cephes Math Library Release 2.8: June, 2000
Copyright 1984, 1987, 1988, 1992, 2000 by Stephen L. Moshier
*************************************************************************/
</div><div style='margin-top: 0; margin-bottom: 0;'><b>double</b> alglib::invnormaldistribution(<b>double</b> y0);
</div></pre>
<a name='sub_normaldistribution'></a><h3 class=pageheader><code>normaldistribution</code> function</h3>
<pre class=source>
<div style='color: navy; margin-top: 0; margin-bottom: 0;'>/*************************************************************************
Normal distribution function
Returns the area under the Gaussian probability density
function, integrated from minus infinity to x:
x
-
1 | | 2
ndtr(x) = --------- | exp( - t /2 ) dt
sqrt(2pi) | |
-
-inf.
= ( 1 + erf(z) ) / 2
= erfc(z) / 2
where z = x/sqrt(2). Computation is via the functions
erf and erfc.
ACCURACY:
Relative error:
arithmetic domain # trials peak rms
IEEE -13,0 30000 3.4e-14 6.7e-15
Cephes Math Library Release 2.8: June, 2000
Copyright 1984, 1987, 1988, 1992, 2000 by Stephen L. Moshier
*************************************************************************/
</div><div style='margin-top: 0; margin-bottom: 0;'><b>double</b> alglib::normaldistribution(<b>double</b> x);
</div></pre>
<a name=unit_normestimator></a><h2 class=pageheader><code>normestimator</code> subpackage</h2>
<div class=pagecontent>
<h3 class=pageheader>Classes</h3>
<a href='#struct_normestimatorstate' class=toc>normestimatorstate</a><br>
<h3 class=pageheader>Functions</h3>
<a href='#sub_normestimatorcreate' class=toc>normestimatorcreate</a><br>
<a href='#sub_normestimatorestimatesparse' class=toc>normestimatorestimatesparse</a><br>
<a href='#sub_normestimatorresults' class=toc>normestimatorresults</a><br>
<a href='#sub_normestimatorsetseed' class=toc>normestimatorsetseed</a><br>
<h3 class=pageheader>Examples</h3>
<table border=0 cellspacing=0 class='pagecontent'>
</table></div>
<a name='struct_normestimatorstate'></a><h3 class=pageheader><code>normestimatorstate</code> class</h3>
<pre class=source>
<div style='color: navy; margin-top: 0; margin-bottom: 0;'>/*************************************************************************
This object stores state of the iterative norm estimation algorithm.
You should use ALGLIB functions to work with this object.
*************************************************************************/
</div><div style='margin-top: 0; margin-bottom: 0;'><b>class</b> normestimatorstate
{
};
</div></pre>
<a name='sub_normestimatorcreate'></a><h3 class=pageheader><code>normestimatorcreate</code> function</h3>
<pre class=source>
<div style='color: navy; margin-top: 0; margin-bottom: 0;'>/*************************************************************************
This procedure initializes matrix norm estimator.
USAGE:
1. User initializes algorithm state with NormEstimatorCreate() call
2. User calls NormEstimatorEstimateSparse() (or NormEstimatorIteration())
3. User calls NormEstimatorResults() to get solution.
INPUT PARAMETERS:
M - number of rows in the matrix being estimated, M>0
N - number of columns in the matrix being estimated, N>0
NStart - number of random starting vectors
recommended value - at least 5.
NIts - number of iterations to do with best starting vector
recommended value - at least 5.
OUTPUT PARAMETERS:
State - structure which stores algorithm state
NOTE: this algorithm is effectively deterministic, i.e. it always returns
same result when repeatedly called for the same matrix. In fact, algorithm
uses randomized starting vectors, but internal random numbers generator
always generates same sequence of the random values (it is a feature, not
bug).
Algorithm can be made non-deterministic with NormEstimatorSetSeed(0) call.
-- ALGLIB --
Copyright 06.12.2011 by Bochkanov Sergey
*************************************************************************/
</div><div style='margin-top: 0; margin-bottom: 0;'><b>void</b> alglib::normestimatorcreate(
ae_int_t m,
ae_int_t n,
ae_int_t nstart,
ae_int_t nits,
normestimatorstate& state);
</div></pre>
<a name='sub_normestimatorestimatesparse'></a><h3 class=pageheader><code>normestimatorestimatesparse</code> function</h3>
<pre class=source>
<div style='color: navy; margin-top: 0; margin-bottom: 0;'>/*************************************************************************
This function estimates norm of the sparse M*N matrix A.
INPUT PARAMETERS:
State - norm estimator state, must be initialized with a call
to NormEstimatorCreate()
A - sparse M*N matrix, must be converted to CRS format
prior to calling this function.
After this function is over you can call NormEstimatorResults() to get
estimate of the norm(A).
-- ALGLIB --
Copyright 06.12.2011 by Bochkanov Sergey
*************************************************************************/
</div><div style='margin-top: 0; margin-bottom: 0;'><b>void</b> alglib::normestimatorestimatesparse(
normestimatorstate state,
sparsematrix a);
</div></pre>
<a name='sub_normestimatorresults'></a><h3 class=pageheader><code>normestimatorresults</code> function</h3>
<pre class=source>
<div style='color: navy; margin-top: 0; margin-bottom: 0;'>/*************************************************************************
Matrix norm estimation results
INPUT PARAMETERS:
State - algorithm state
OUTPUT PARAMETERS:
Nrm - estimate of the matrix norm, Nrm>=0
-- ALGLIB --
Copyright 06.12.2011 by Bochkanov Sergey
*************************************************************************/
</div><div style='margin-top: 0; margin-bottom: 0;'><b>void</b> alglib::normestimatorresults(normestimatorstate state, <b>double</b>& nrm);
</div></pre>
<a name='sub_normestimatorsetseed'></a><h3 class=pageheader><code>normestimatorsetseed</code> function</h3>
<pre class=source>
<div style='color: navy; margin-top: 0; margin-bottom: 0;'>/*************************************************************************
This function changes seed value used by algorithm. In some cases we need
deterministic processing, i.e. subsequent calls must return equal results,
in other cases we need non-deterministic algorithm which returns different
results for the same matrix on every pass.
Setting zero seed will lead to non-deterministic algorithm, while non-zero
value will make our algorithm deterministic.
INPUT PARAMETERS:
State - norm estimator state, must be initialized with a call
to NormEstimatorCreate()
SeedVal - seed value, >=0. Zero value = non-deterministic algo.
-- ALGLIB --
Copyright 06.12.2011 by Bochkanov Sergey
*************************************************************************/
</div><div style='margin-top: 0; margin-bottom: 0;'><b>void</b> alglib::normestimatorsetseed(
normestimatorstate state,
ae_int_t seedval);
</div></pre>
<a name=unit_odesolver></a><h2 class=pageheader><code>odesolver</code> subpackage</h2>
<div class=pagecontent>
<h3 class=pageheader>Classes</h3>
<a href='#struct_odesolverreport' class=toc>odesolverreport</a><br>
<a href='#struct_odesolverstate' class=toc>odesolverstate</a><br>
<h3 class=pageheader>Functions</h3>
<a href='#sub_odesolverresults' class=toc>odesolverresults</a><br>
<a href='#sub_odesolverrkck' class=toc>odesolverrkck</a><br>
<a href='#sub_odesolversolve' class=toc>odesolversolve</a><br>
<h3 class=pageheader>Examples</h3>
<table border=0 cellspacing=0 class='pagecontent'>
<tr align=left valign=top><td><a href='#example_odesolver_d1' class=toc>odesolver_d1</a></td><td width=15> </td><td>Solving y'=-y with ODE solver</td></tr>
</table></div>
<a name='struct_odesolverreport'></a><h3 class=pageheader><code>odesolverreport</code> class</h3>
<pre class=source>
<div style='color: navy; margin-top: 0; margin-bottom: 0;'>/*************************************************************************
*************************************************************************/
</div><div style='margin-top: 0; margin-bottom: 0;'><b>class</b> odesolverreport
{
ae_int_t nfev;
ae_int_t terminationtype;
};
</div></pre>
<a name='struct_odesolverstate'></a><h3 class=pageheader><code>odesolverstate</code> class</h3>
<pre class=source>
<div style='color: navy; margin-top: 0; margin-bottom: 0;'>/*************************************************************************
*************************************************************************/
</div><div style='margin-top: 0; margin-bottom: 0;'><b>class</b> odesolverstate
{
};
</div></pre>
<a name='sub_odesolverresults'></a><h3 class=pageheader><code>odesolverresults</code> function</h3>
<pre class=source>
<div style='color: navy; margin-top: 0; margin-bottom: 0;'>/*************************************************************************
ODE solver results
Called after OdeSolverIteration returned False.
INPUT PARAMETERS:
State - algorithm state (used by OdeSolverIteration).
OUTPUT PARAMETERS:
M - number of tabulated values, M>=1
XTbl - array[0..M-1], values of X
YTbl - array[0..M-1,0..N-1], values of Y in X[i]
Rep - solver report:
* Rep.TerminationType completetion code:
* -2 X is not ordered by ascending/descending or
there are non-distinct X[], i.e. X[i]=X[i+1]
* -1 incorrect parameters were specified
* 1 task has been solved
* Rep.NFEV contains number of function calculations
-- ALGLIB --
Copyright 01.09.2009 by Bochkanov Sergey
*************************************************************************/
</div><div style='margin-top: 0; margin-bottom: 0;'><b>void</b> alglib::odesolverresults(
odesolverstate state,
ae_int_t& m,
real_1d_array& xtbl,
real_2d_array& ytbl,
odesolverreport& rep);
</div></pre>
<p align=left class=pagecontent><span class=inlineheader>Examples:</span> <a href='#example_odesolver_d1' class=nav>[1]</a> </p>
<a name='sub_odesolverrkck'></a><h3 class=pageheader><code>odesolverrkck</code> function</h3>
<pre class=source>
<div style='color: navy; margin-top: 0; margin-bottom: 0;'>/*************************************************************************
Cash-Karp adaptive ODE solver.
This subroutine solves ODE Y'=f(Y,x) with initial conditions Y(xs)=Ys
(here Y may be single variable or vector of N variables).
INPUT PARAMETERS:
Y - initial conditions, array[0..N-1].
contains values of Y[] at X[0]
N - system size
X - points at which Y should be tabulated, array[0..M-1]
integrations starts at X[0], ends at X[M-1], intermediate
values at X[i] are returned too.
SHOULD BE ORDERED BY ASCENDING OR BY DESCENDING!
M - number of intermediate points + first point + last point:
* M>2 means that you need both Y(X[M-1]) and M-2 values at
intermediate points
* M=2 means that you want just to integrate from X[0] to
X[1] and don't interested in intermediate values.
* M=1 means that you don't want to integrate :)
it is degenerate case, but it will be handled correctly.
* M<1 means error
Eps - tolerance (absolute/relative error on each step will be
less than Eps). When passing:
* Eps>0, it means desired ABSOLUTE error
* Eps<0, it means desired RELATIVE error. Relative errors
are calculated with respect to maximum values of Y seen
so far. Be careful to use this criterion when starting
from Y[] that are close to zero.
H - initial step lenth, it will be adjusted automatically
after the first step. If H=0, step will be selected
automatically (usualy it will be equal to 0.001 of
min(x[i]-x[j])).
OUTPUT PARAMETERS
State - structure which stores algorithm state between subsequent
calls of OdeSolverIteration. Used for reverse communication.
This structure should be passed to the OdeSolverIteration
subroutine.
SEE ALSO
AutoGKSmoothW, AutoGKSingular, AutoGKIteration, AutoGKResults.
-- ALGLIB --
Copyright 01.09.2009 by Bochkanov Sergey
*************************************************************************/
</div><div style='margin-top: 0; margin-bottom: 0;'><b>void</b> alglib::odesolverrkck(
real_1d_array y,
real_1d_array x,
<b>double</b> eps,
<b>double</b> h,
odesolverstate& state);
<b>void</b> alglib::odesolverrkck(
real_1d_array y,
ae_int_t n,
real_1d_array x,
ae_int_t m,
<b>double</b> eps,
<b>double</b> h,
odesolverstate& state);
</div></pre>
<p align=left class=pagecontent><span class=inlineheader>Examples:</span> <a href='#example_odesolver_d1' class=nav>[1]</a> </p>
<a name='sub_odesolversolve'></a><h3 class=pageheader><code>odesolversolve</code> function</h3>
<pre class=source>
<div style='color: navy; margin-top: 0; margin-bottom: 0;'>/*************************************************************************
This function is used to launcn iterations of ODE solver
It accepts following parameters:
diff - callback which calculates dy/dx for given y and x
ptr - optional pointer which is passed to diff; can be NULL
-- ALGLIB --
Copyright 01.09.2009 by Bochkanov Sergey
*************************************************************************/
</div><div style='margin-top: 0; margin-bottom: 0;'><b>void</b> odesolversolve(odesolverstate &state,
<b>void</b> (*diff)(<b>const</b> real_1d_array &y, <b>double</b> x, real_1d_array &dy, <b>void</b> *ptr),
<b>void</b> *ptr = NULL);
</div></pre>
<p align=left class=pagecontent><span class=inlineheader>Examples:</span> <a href='#example_odesolver_d1' class=nav>[1]</a> </p>
<a name='example_odesolver_d1'></a><h3 class=pageheader>odesolver_d1 example</h3>
<pre class=source>
#include <font color=blue><b>"stdafx.h"</b></font>
#include <stdlib.h>
#include <stdio.h>
#include <math.h>
#include <font color=blue><b>"diffequations.h"</b></font>
using namespace alglib;
<b>void</b> ode_function_1_diff(<b>const</b> real_1d_array &y, <b>double</b> x, real_1d_array &dy, <b>void</b> *ptr)
{
<font color=navy>// this callback calculates f(y[],x)=-y[0]</font>
dy[0] = -y[0];
}
<b>int</b> main(<b>int</b> argc, char **argv)
{
real_1d_array y = <font color=blue><b>"[1]"</b></font>;
real_1d_array x = <font color=blue><b>"[0, 1, 2, 3]"</b></font>;
<b>double</b> eps = 0.00001;
<b>double</b> h = 0;
odesolverstate s;
ae_int_t m;
real_1d_array xtbl;
real_2d_array ytbl;
odesolverreport rep;
odesolverrkck(y, x, eps, h, s);
alglib::odesolversolve(s, ode_function_1_diff);
odesolverresults(s, m, xtbl, ytbl, rep);
printf(<font color=blue><b>"%d\n"</b></font>, <b>int</b>(m)); <font color=navy>// EXPECTED: 4</font>
printf(<font color=blue><b>"%s\n"</b></font>, xtbl.tostring(2).c_str()); <font color=navy>// EXPECTED: [0, 1, 2, 3]</font>
printf(<font color=blue><b>"%s\n"</b></font>, ytbl.tostring(2).c_str()); <font color=navy>// EXPECTED: [[1], [0.367], [0.135], [0.050]]</font>
<b>return</b> 0;
}
</pre><a name=unit_ortfac></a><h2 class=pageheader><code>ortfac</code> subpackage</h2>
<div class=pagecontent>
<h3 class=pageheader>Functions</h3>
<a href='#sub_cmatrixlq' class=toc>cmatrixlq</a><br>
<a href='#sub_cmatrixlqunpackl' class=toc>cmatrixlqunpackl</a><br>
<a href='#sub_cmatrixlqunpackq' class=toc>cmatrixlqunpackq</a><br>
<a href='#sub_cmatrixqr' class=toc>cmatrixqr</a><br>
<a href='#sub_cmatrixqrunpackq' class=toc>cmatrixqrunpackq</a><br>
<a href='#sub_cmatrixqrunpackr' class=toc>cmatrixqrunpackr</a><br>
<a href='#sub_hmatrixtd' class=toc>hmatrixtd</a><br>
<a href='#sub_hmatrixtdunpackq' class=toc>hmatrixtdunpackq</a><br>
<a href='#sub_rmatrixbd' class=toc>rmatrixbd</a><br>
<a href='#sub_rmatrixbdmultiplybyp' class=toc>rmatrixbdmultiplybyp</a><br>
<a href='#sub_rmatrixbdmultiplybyq' class=toc>rmatrixbdmultiplybyq</a><br>
<a href='#sub_rmatrixbdunpackdiagonals' class=toc>rmatrixbdunpackdiagonals</a><br>
<a href='#sub_rmatrixbdunpackpt' class=toc>rmatrixbdunpackpt</a><br>
<a href='#sub_rmatrixbdunpackq' class=toc>rmatrixbdunpackq</a><br>
<a href='#sub_rmatrixhessenberg' class=toc>rmatrixhessenberg</a><br>
<a href='#sub_rmatrixhessenbergunpackh' class=toc>rmatrixhessenbergunpackh</a><br>
<a href='#sub_rmatrixhessenbergunpackq' class=toc>rmatrixhessenbergunpackq</a><br>
<a href='#sub_rmatrixlq' class=toc>rmatrixlq</a><br>
<a href='#sub_rmatrixlqunpackl' class=toc>rmatrixlqunpackl</a><br>
<a href='#sub_rmatrixlqunpackq' class=toc>rmatrixlqunpackq</a><br>
<a href='#sub_rmatrixqr' class=toc>rmatrixqr</a><br>
<a href='#sub_rmatrixqrunpackq' class=toc>rmatrixqrunpackq</a><br>
<a href='#sub_rmatrixqrunpackr' class=toc>rmatrixqrunpackr</a><br>
<a href='#sub_smatrixtd' class=toc>smatrixtd</a><br>
<a href='#sub_smatrixtdunpackq' class=toc>smatrixtdunpackq</a><br>
<h3 class=pageheader>Examples</h3>
<table border=0 cellspacing=0 class='pagecontent'>
</table></div>
<a name='sub_cmatrixlq'></a><h3 class=pageheader><code>cmatrixlq</code> function</h3>
<pre class=source>
<div style='color: navy; margin-top: 0; margin-bottom: 0;'>/*************************************************************************
LQ decomposition of a rectangular complex matrix of size MxN
COMMERCIAL EDITION OF ALGLIB:
! Commercial version of ALGLIB includes two important improvements of
! this function, which can be used from C++ and C#:
! * Intel MKL support (lightweight Intel MKL is shipped with ALGLIB)
! * multicore support
!
! Intel MKL gives approximately constant (with respect to number of
! worker threads) acceleration factor which depends on CPU being used,
! problem size and "baseline" ALGLIB edition which is used for
! comparison.
!
! Say, on SSE2-capable CPU with N=1024, HPC ALGLIB will be:
! * about 2-3x faster than ALGLIB for C++ without MKL
! * about 7-10x faster than "pure C#" edition of ALGLIB
! Difference in performance will be more striking on newer CPU's with
! support for newer SIMD instructions. Generally, MKL accelerates any
! problem whose size is at least 128, with best efficiency achieved for
! N's larger than 512.
!
! Commercial edition of ALGLIB also supports multithreaded acceleration
! of this function. We should note that QP decomposition is harder to
! parallelize than, say, matrix-matrix product - this algorithm has
! many internal synchronization points which can not be avoided. However
! parallelism starts to be profitable starting from N=512, achieving
! near-linear speedup for N=4096 or higher.
!
! In order to use multicore features you have to:
! * use commercial version of ALGLIB
! * call this function with "smp_" prefix, which indicates that
! multicore code will be used (for multicore support)
!
! We recommend you to read 'Working with commercial version' section of
! ALGLIB Reference Manual in order to find out how to use performance-
! related features provided by commercial edition of ALGLIB.
Input parameters:
A - matrix A whose indexes range within [0..M-1, 0..N-1]
M - number of rows in matrix A.
N - number of columns in matrix A.
Output parameters:
A - matrices Q and L in compact form
Tau - array of scalar factors which are used to form matrix Q. Array
whose indexes range within [0.. Min(M,N)-1]
Matrix A is represented as A = LQ, where Q is an orthogonal matrix of size
MxM, L - lower triangular (or lower trapezoid) matrix of size MxN.
-- LAPACK routine (version 3.0) --
Univ. of Tennessee, Univ. of California Berkeley, NAG Ltd.,
Courant Institute, Argonne National Lab, and Rice University
September 30, 1994
*************************************************************************/
</div><div style='margin-top: 0; margin-bottom: 0;'><b>void</b> alglib::cmatrixlq(
complex_2d_array& a,
ae_int_t m,
ae_int_t n,
complex_1d_array& tau);
<b>void</b> alglib::smp_cmatrixlq(
complex_2d_array& a,
ae_int_t m,
ae_int_t n,
complex_1d_array& tau);
</div></pre>
<a name='sub_cmatrixlqunpackl'></a><h3 class=pageheader><code>cmatrixlqunpackl</code> function</h3>
<pre class=source>
<div style='color: navy; margin-top: 0; margin-bottom: 0;'>/*************************************************************************
Unpacking of matrix L from the LQ decomposition of a matrix A
Input parameters:
A - matrices Q and L in compact form.
Output of CMatrixLQ subroutine.
M - number of rows in given matrix A. M>=0.
N - number of columns in given matrix A. N>=0.
Output parameters:
L - matrix L, array[0..M-1, 0..N-1].
-- ALGLIB routine --
17.02.2010
Bochkanov Sergey
*************************************************************************/
</div><div style='margin-top: 0; margin-bottom: 0;'><b>void</b> alglib::cmatrixlqunpackl(
complex_2d_array a,
ae_int_t m,
ae_int_t n,
complex_2d_array& l);
</div></pre>
<a name='sub_cmatrixlqunpackq'></a><h3 class=pageheader><code>cmatrixlqunpackq</code> function</h3>
<pre class=source>
<div style='color: navy; margin-top: 0; margin-bottom: 0;'>/*************************************************************************
Partial unpacking of matrix Q from LQ decomposition of a complex matrix A.
COMMERCIAL EDITION OF ALGLIB:
! Commercial version of ALGLIB includes two important improvements of
! this function, which can be used from C++ and C#:
! * Intel MKL support (lightweight Intel MKL is shipped with ALGLIB)
! * multicore support
!
! Intel MKL gives approximately constant (with respect to number of
! worker threads) acceleration factor which depends on CPU being used,
! problem size and "baseline" ALGLIB edition which is used for
! comparison.
!
! Say, on SSE2-capable CPU with N=1024, HPC ALGLIB will be:
! * about 2-3x faster than ALGLIB for C++ without MKL
! * about 7-10x faster than "pure C#" edition of ALGLIB
! Difference in performance will be more striking on newer CPU's with
! support for newer SIMD instructions. Generally, MKL accelerates any
! problem whose size is at least 128, with best efficiency achieved for
! N's larger than 512.
!
! Commercial edition of ALGLIB also supports multithreaded acceleration
! of this function. We should note that QP decomposition is harder to
! parallelize than, say, matrix-matrix product - this algorithm has
! many internal synchronization points which can not be avoided. However
! parallelism starts to be profitable starting from N=512, achieving
! near-linear speedup for N=4096 or higher.
!
! In order to use multicore features you have to:
! * use commercial version of ALGLIB
! * call this function with "smp_" prefix, which indicates that
! multicore code will be used (for multicore support)
!
! We recommend you to read 'Working with commercial version' section of
! ALGLIB Reference Manual in order to find out how to use performance-
! related features provided by commercial edition of ALGLIB.
Input parameters:
A - matrices Q and R in compact form.
Output of CMatrixLQ subroutine .
M - number of rows in matrix A. M>=0.
N - number of columns in matrix A. N>=0.
Tau - scalar factors which are used to form Q.
Output of CMatrixLQ subroutine .
QRows - required number of rows in matrix Q. N>=QColumns>=0.
Output parameters:
Q - first QRows rows of matrix Q.
Array whose index ranges within [0..QRows-1, 0..N-1].
If QRows=0, array isn't changed.
-- ALGLIB routine --
17.02.2010
Bochkanov Sergey
*************************************************************************/
</div><div style='margin-top: 0; margin-bottom: 0;'><b>void</b> alglib::cmatrixlqunpackq(
complex_2d_array a,
ae_int_t m,
ae_int_t n,
complex_1d_array tau,
ae_int_t qrows,
complex_2d_array& q);
<b>void</b> alglib::smp_cmatrixlqunpackq(
complex_2d_array a,
ae_int_t m,
ae_int_t n,
complex_1d_array tau,
ae_int_t qrows,
complex_2d_array& q);
</div></pre>
<a name='sub_cmatrixqr'></a><h3 class=pageheader><code>cmatrixqr</code> function</h3>
<pre class=source>
<div style='color: navy; margin-top: 0; margin-bottom: 0;'>/*************************************************************************
QR decomposition of a rectangular complex matrix of size MxN
COMMERCIAL EDITION OF ALGLIB:
! Commercial version of ALGLIB includes two important improvements of
! this function, which can be used from C++ and C#:
! * Intel MKL support (lightweight Intel MKL is shipped with ALGLIB)
! * multicore support
!
! Intel MKL gives approximately constant (with respect to number of
! worker threads) acceleration factor which depends on CPU being used,
! problem size and "baseline" ALGLIB edition which is used for
! comparison.
!
! Say, on SSE2-capable CPU with N=1024, HPC ALGLIB will be:
! * about 2-3x faster than ALGLIB for C++ without MKL
! * about 7-10x faster than "pure C#" edition of ALGLIB
! Difference in performance will be more striking on newer CPU's with
! support for newer SIMD instructions. Generally, MKL accelerates any
! problem whose size is at least 128, with best efficiency achieved for
! N's larger than 512.
!
! Commercial edition of ALGLIB also supports multithreaded acceleration
! of this function. We should note that QP decomposition is harder to
! parallelize than, say, matrix-matrix product - this algorithm has
! many internal synchronization points which can not be avoided. However
! parallelism starts to be profitable starting from N=512, achieving
! near-linear speedup for N=4096 or higher.
!
! In order to use multicore features you have to:
! * use commercial version of ALGLIB
! * call this function with "smp_" prefix, which indicates that
! multicore code will be used (for multicore support)
!
! We recommend you to read 'Working with commercial version' section of
! ALGLIB Reference Manual in order to find out how to use performance-
! related features provided by commercial edition of ALGLIB.
Input parameters:
A - matrix A whose indexes range within [0..M-1, 0..N-1]
M - number of rows in matrix A.
N - number of columns in matrix A.
Output parameters:
A - matrices Q and R in compact form
Tau - array of scalar factors which are used to form matrix Q. Array
whose indexes range within [0.. Min(M,N)-1]
Matrix A is represented as A = QR, where Q is an orthogonal matrix of size
MxM, R - upper triangular (or upper trapezoid) matrix of size MxN.
-- LAPACK routine (version 3.0) --
Univ. of Tennessee, Univ. of California Berkeley, NAG Ltd.,
Courant Institute, Argonne National Lab, and Rice University
September 30, 1994
*************************************************************************/
</div><div style='margin-top: 0; margin-bottom: 0;'><b>void</b> alglib::cmatrixqr(
complex_2d_array& a,
ae_int_t m,
ae_int_t n,
complex_1d_array& tau);
<b>void</b> alglib::smp_cmatrixqr(
complex_2d_array& a,
ae_int_t m,
ae_int_t n,
complex_1d_array& tau);
</div></pre>
<a name='sub_cmatrixqrunpackq'></a><h3 class=pageheader><code>cmatrixqrunpackq</code> function</h3>
<pre class=source>
<div style='color: navy; margin-top: 0; margin-bottom: 0;'>/*************************************************************************
Partial unpacking of matrix Q from QR decomposition of a complex matrix A.
COMMERCIAL EDITION OF ALGLIB:
! Commercial version of ALGLIB includes two important improvements of
! this function, which can be used from C++ and C#:
! * Intel MKL support (lightweight Intel MKL is shipped with ALGLIB)
! * multicore support
!
! Intel MKL gives approximately constant (with respect to number of
! worker threads) acceleration factor which depends on CPU being used,
! problem size and "baseline" ALGLIB edition which is used for
! comparison.
!
! Say, on SSE2-capable CPU with N=1024, HPC ALGLIB will be:
! * about 2-3x faster than ALGLIB for C++ without MKL
! * about 7-10x faster than "pure C#" edition of ALGLIB
! Difference in performance will be more striking on newer CPU's with
! support for newer SIMD instructions. Generally, MKL accelerates any
! problem whose size is at least 128, with best efficiency achieved for
! N's larger than 512.
!
! Commercial edition of ALGLIB also supports multithreaded acceleration
! of this function. We should note that QP decomposition is harder to
! parallelize than, say, matrix-matrix product - this algorithm has
! many internal synchronization points which can not be avoided. However
! parallelism starts to be profitable starting from N=512, achieving
! near-linear speedup for N=4096 or higher.
!
! In order to use multicore features you have to:
! * use commercial version of ALGLIB
! * call this function with "smp_" prefix, which indicates that
! multicore code will be used (for multicore support)
!
! We recommend you to read 'Working with commercial version' section of
! ALGLIB Reference Manual in order to find out how to use performance-
! related features provided by commercial edition of ALGLIB.
Input parameters:
A - matrices Q and R in compact form.
Output of CMatrixQR subroutine .
M - number of rows in matrix A. M>=0.
N - number of columns in matrix A. N>=0.
Tau - scalar factors which are used to form Q.
Output of CMatrixQR subroutine .
QColumns - required number of columns in matrix Q. M>=QColumns>=0.
Output parameters:
Q - first QColumns columns of matrix Q.
Array whose index ranges within [0..M-1, 0..QColumns-1].
If QColumns=0, array isn't changed.
-- ALGLIB routine --
17.02.2010
Bochkanov Sergey
*************************************************************************/
</div><div style='margin-top: 0; margin-bottom: 0;'><b>void</b> alglib::cmatrixqrunpackq(
complex_2d_array a,
ae_int_t m,
ae_int_t n,
complex_1d_array tau,
ae_int_t qcolumns,
complex_2d_array& q);
<b>void</b> alglib::smp_cmatrixqrunpackq(
complex_2d_array a,
ae_int_t m,
ae_int_t n,
complex_1d_array tau,
ae_int_t qcolumns,
complex_2d_array& q);
</div></pre>
<a name='sub_cmatrixqrunpackr'></a><h3 class=pageheader><code>cmatrixqrunpackr</code> function</h3>
<pre class=source>
<div style='color: navy; margin-top: 0; margin-bottom: 0;'>/*************************************************************************
Unpacking of matrix R from the QR decomposition of a matrix A
Input parameters:
A - matrices Q and R in compact form.
Output of CMatrixQR subroutine.
M - number of rows in given matrix A. M>=0.
N - number of columns in given matrix A. N>=0.
Output parameters:
R - matrix R, array[0..M-1, 0..N-1].
-- ALGLIB routine --
17.02.2010
Bochkanov Sergey
*************************************************************************/
</div><div style='margin-top: 0; margin-bottom: 0;'><b>void</b> alglib::cmatrixqrunpackr(
complex_2d_array a,
ae_int_t m,
ae_int_t n,
complex_2d_array& r);
</div></pre>
<a name='sub_hmatrixtd'></a><h3 class=pageheader><code>hmatrixtd</code> function</h3>
<pre class=source>
<div style='color: navy; margin-top: 0; margin-bottom: 0;'>/*************************************************************************
Reduction of a Hermitian matrix which is given by its higher or lower
triangular part to a real tridiagonal matrix using unitary similarity
transformation: Q'*A*Q = T.
COMMERCIAL EDITION OF ALGLIB:
! Commercial version of ALGLIB includes one important improvement of
! this function, which can be used from C++ and C#:
! * Intel MKL support (lightweight Intel MKL is shipped with ALGLIB)
!
! Intel MKL gives approximately constant (with respect to number of
! worker threads) acceleration factor which depends on CPU being used,
! problem size and "baseline" ALGLIB edition which is used for
! comparison.
!
! Generally, commercial ALGLIB is several times faster than open-source
! generic C edition, and many times faster than open-source C# edition.
!
! Multithreaded acceleration is NOT supported for this function.
!
! We recommend you to read 'Working with commercial version' section of
! ALGLIB Reference Manual in order to find out how to use performance-
! related features provided by commercial edition of ALGLIB.
Input parameters:
A - matrix to be transformed
array with elements [0..N-1, 0..N-1].
N - size of matrix A.
IsUpper - storage format. If IsUpper = True, then matrix A is given
by its upper triangle, and the lower triangle is not used
and not modified by the algorithm, and vice versa
if IsUpper = False.
Output parameters:
A - matrices T and Q in compact form (see lower)
Tau - array of factors which are forming matrices H(i)
array with elements [0..N-2].
D - main diagonal of real symmetric matrix T.
array with elements [0..N-1].
E - secondary diagonal of real symmetric matrix T.
array with elements [0..N-2].
If IsUpper=True, the matrix Q is represented as a product of elementary
reflectors
Q = H(n-2) . . . H(2) H(0).
Each H(i) has the form
H(i) = I - tau * v * v'
where tau is a complex scalar, and v is a complex vector with
v(i+1:n-1) = 0, v(i) = 1, v(0:i-1) is stored on exit in
A(0:i-1,i+1), and tau in TAU(i).
If IsUpper=False, the matrix Q is represented as a product of elementary
reflectors
Q = H(0) H(2) . . . H(n-2).
Each H(i) has the form
H(i) = I - tau * v * v'
where tau is a complex scalar, and v is a complex vector with
v(0:i) = 0, v(i+1) = 1, v(i+2:n-1) is stored on exit in A(i+2:n-1,i),
and tau in TAU(i).
The contents of A on exit are illustrated by the following examples
with n = 5:
if UPLO = 'U': if UPLO = 'L':
( d e v1 v2 v3 ) ( d )
( d e v2 v3 ) ( e d )
( d e v3 ) ( v0 e d )
( d e ) ( v0 v1 e d )
( d ) ( v0 v1 v2 e d )
where d and e denote diagonal and off-diagonal elements of T, and vi
denotes an element of the vector defining H(i).
-- LAPACK routine (version 3.0) --
Univ. of Tennessee, Univ. of California Berkeley, NAG Ltd.,
Courant Institute, Argonne National Lab, and Rice University
October 31, 1992
*************************************************************************/
</div><div style='margin-top: 0; margin-bottom: 0;'><b>void</b> alglib::hmatrixtd(
complex_2d_array& a,
ae_int_t n,
<b>bool</b> isupper,
complex_1d_array& tau,
real_1d_array& d,
real_1d_array& e);
</div></pre>
<a name='sub_hmatrixtdunpackq'></a><h3 class=pageheader><code>hmatrixtdunpackq</code> function</h3>
<pre class=source>
<div style='color: navy; margin-top: 0; margin-bottom: 0;'>/*************************************************************************
Unpacking matrix Q which reduces a Hermitian matrix to a real tridiagonal
form.
COMMERCIAL EDITION OF ALGLIB:
! Commercial version of ALGLIB includes one important improvement of
! this function, which can be used from C++ and C#:
! * Intel MKL support (lightweight Intel MKL is shipped with ALGLIB)
!
! Intel MKL gives approximately constant (with respect to number of
! worker threads) acceleration factor which depends on CPU being used,
! problem size and "baseline" ALGLIB edition which is used for
! comparison.
!
! Generally, commercial ALGLIB is several times faster than open-source
! generic C edition, and many times faster than open-source C# edition.
!
! Multithreaded acceleration is NOT supported for this function.
!
! We recommend you to read 'Working with commercial version' section of
! ALGLIB Reference Manual in order to find out how to use performance-
! related features provided by commercial edition of ALGLIB.
Input parameters:
A - the result of a HMatrixTD subroutine
N - size of matrix A.
IsUpper - storage format (a parameter of HMatrixTD subroutine)
Tau - the result of a HMatrixTD subroutine
Output parameters:
Q - transformation matrix.
array with elements [0..N-1, 0..N-1].
-- ALGLIB --
Copyright 2005-2010 by Bochkanov Sergey
*************************************************************************/
</div><div style='margin-top: 0; margin-bottom: 0;'><b>void</b> alglib::hmatrixtdunpackq(
complex_2d_array a,
ae_int_t n,
<b>bool</b> isupper,
complex_1d_array tau,
complex_2d_array& q);
</div></pre>
<a name='sub_rmatrixbd'></a><h3 class=pageheader><code>rmatrixbd</code> function</h3>
<pre class=source>
<div style='color: navy; margin-top: 0; margin-bottom: 0;'>/*************************************************************************
Reduction of a rectangular matrix to bidiagonal form
The algorithm reduces the rectangular matrix A to bidiagonal form by
orthogonal transformations P and Q: A = Q*B*(P^T).
COMMERCIAL EDITION OF ALGLIB:
! Commercial version of ALGLIB includes one important improvement of
! this function, which can be used from C++ and C#:
! * Intel MKL support (lightweight Intel MKL is shipped with ALGLIB)
!
! Intel MKL gives approximately constant (with respect to number of
! worker threads) acceleration factor which depends on CPU being used,
! problem size and "baseline" ALGLIB edition which is used for
! comparison.
!
! Multithreaded acceleration is NOT supported for this function because
! bidiagonal decompostion is inherently sequential in nature.
!
! We recommend you to read 'Working with commercial version' section of
! ALGLIB Reference Manual in order to find out how to use performance-
! related features provided by commercial edition of ALGLIB.
Input parameters:
A - source matrix. array[0..M-1, 0..N-1]
M - number of rows in matrix A.
N - number of columns in matrix A.
Output parameters:
A - matrices Q, B, P in compact form (see below).
TauQ - scalar factors which are used to form matrix Q.
TauP - scalar factors which are used to form matrix P.
The main diagonal and one of the secondary diagonals of matrix A are
replaced with bidiagonal matrix B. Other elements contain elementary
reflections which form MxM matrix Q and NxN matrix P, respectively.
If M>=N, B is the upper bidiagonal MxN matrix and is stored in the
corresponding elements of matrix A. Matrix Q is represented as a
product of elementary reflections Q = H(0)*H(1)*...*H(n-1), where
H(i) = 1-tau*v*v'. Here tau is a scalar which is stored in TauQ[i], and
vector v has the following structure: v(0:i-1)=0, v(i)=1, v(i+1:m-1) is
stored in elements A(i+1:m-1,i). Matrix P is as follows: P =
G(0)*G(1)*...*G(n-2), where G(i) = 1 - tau*u*u'. Tau is stored in TauP[i],
u(0:i)=0, u(i+1)=1, u(i+2:n-1) is stored in elements A(i,i+2:n-1).
If M<N, B is the lower bidiagonal MxN matrix and is stored in the
corresponding elements of matrix A. Q = H(0)*H(1)*...*H(m-2), where
H(i) = 1 - tau*v*v', tau is stored in TauQ, v(0:i)=0, v(i+1)=1, v(i+2:m-1)
is stored in elements A(i+2:m-1,i). P = G(0)*G(1)*...*G(m-1),
G(i) = 1-tau*u*u', tau is stored in TauP, u(0:i-1)=0, u(i)=1, u(i+1:n-1)
is stored in A(i,i+1:n-1).
EXAMPLE:
m=6, n=5 (m > n): m=5, n=6 (m < n):
( d e u1 u1 u1 ) ( d u1 u1 u1 u1 u1 )
( v1 d e u2 u2 ) ( e d u2 u2 u2 u2 )
( v1 v2 d e u3 ) ( v1 e d u3 u3 u3 )
( v1 v2 v3 d e ) ( v1 v2 e d u4 u4 )
( v1 v2 v3 v4 d ) ( v1 v2 v3 e d u5 )
( v1 v2 v3 v4 v5 )
Here vi and ui are vectors which form H(i) and G(i), and d and e -
are the diagonal and off-diagonal elements of matrix B.
-- LAPACK routine (version 3.0) --
Univ. of Tennessee, Univ. of California Berkeley, NAG Ltd.,
Courant Institute, Argonne National Lab, and Rice University
September 30, 1994.
Sergey Bochkanov, ALGLIB project, translation from FORTRAN to
pseudocode, 2007-2010.
*************************************************************************/
</div><div style='margin-top: 0; margin-bottom: 0;'><b>void</b> alglib::rmatrixbd(
real_2d_array& a,
ae_int_t m,
ae_int_t n,
real_1d_array& tauq,
real_1d_array& taup);
</div></pre>
<a name='sub_rmatrixbdmultiplybyp'></a><h3 class=pageheader><code>rmatrixbdmultiplybyp</code> function</h3>
<pre class=source>
<div style='color: navy; margin-top: 0; margin-bottom: 0;'>/*************************************************************************
Multiplication by matrix P which reduces matrix A to bidiagonal form.
The algorithm allows pre- or post-multiply by P or P'.
Input parameters:
QP - matrices Q and P in compact form.
Output of RMatrixBD subroutine.
M - number of rows in matrix A.
N - number of columns in matrix A.
TAUP - scalar factors which are used to form P.
Output of RMatrixBD subroutine.
Z - multiplied matrix.
Array whose indexes range within [0..ZRows-1,0..ZColumns-1].
ZRows - number of rows in matrix Z. If FromTheRight=False,
ZRows=N, otherwise ZRows can be arbitrary.
ZColumns - number of columns in matrix Z. If FromTheRight=True,
ZColumns=N, otherwise ZColumns can be arbitrary.
FromTheRight - pre- or post-multiply.
DoTranspose - multiply by P or P'.
Output parameters:
Z - product of Z and P.
Array whose indexes range within [0..ZRows-1,0..ZColumns-1].
If ZRows=0 or ZColumns=0, the array is not modified.
-- ALGLIB --
2005-2010
Bochkanov Sergey
*************************************************************************/
</div><div style='margin-top: 0; margin-bottom: 0;'><b>void</b> alglib::rmatrixbdmultiplybyp(
real_2d_array qp,
ae_int_t m,
ae_int_t n,
real_1d_array taup,
real_2d_array& z,
ae_int_t zrows,
ae_int_t zcolumns,
<b>bool</b> fromtheright,
<b>bool</b> dotranspose);
</div></pre>
<a name='sub_rmatrixbdmultiplybyq'></a><h3 class=pageheader><code>rmatrixbdmultiplybyq</code> function</h3>
<pre class=source>
<div style='color: navy; margin-top: 0; margin-bottom: 0;'>/*************************************************************************
Multiplication by matrix Q which reduces matrix A to bidiagonal form.
The algorithm allows pre- or post-multiply by Q or Q'.
COMMERCIAL EDITION OF ALGLIB:
! Commercial version of ALGLIB includes one important improvement of
! this function, which can be used from C++ and C#:
! * Intel MKL support (lightweight Intel MKL is shipped with ALGLIB)
!
! Intel MKL gives approximately constant (with respect to number of
! worker threads) acceleration factor which depends on CPU being used,
! problem size and "baseline" ALGLIB edition which is used for
! comparison.
!
! Multithreaded acceleration is NOT supported for this function.
!
! We recommend you to read 'Working with commercial version' section of
! ALGLIB Reference Manual in order to find out how to use performance-
! related features provided by commercial edition of ALGLIB.
Input parameters:
QP - matrices Q and P in compact form.
Output of ToBidiagonal subroutine.
M - number of rows in matrix A.
N - number of columns in matrix A.
TAUQ - scalar factors which are used to form Q.
Output of ToBidiagonal subroutine.
Z - multiplied matrix.
array[0..ZRows-1,0..ZColumns-1]
ZRows - number of rows in matrix Z. If FromTheRight=False,
ZRows=M, otherwise ZRows can be arbitrary.
ZColumns - number of columns in matrix Z. If FromTheRight=True,
ZColumns=M, otherwise ZColumns can be arbitrary.
FromTheRight - pre- or post-multiply.
DoTranspose - multiply by Q or Q'.
Output parameters:
Z - product of Z and Q.
Array[0..ZRows-1,0..ZColumns-1]
If ZRows=0 or ZColumns=0, the array is not modified.
-- ALGLIB --
2005-2010
Bochkanov Sergey
*************************************************************************/
</div><div style='margin-top: 0; margin-bottom: 0;'><b>void</b> alglib::rmatrixbdmultiplybyq(
real_2d_array qp,
ae_int_t m,
ae_int_t n,
real_1d_array tauq,
real_2d_array& z,
ae_int_t zrows,
ae_int_t zcolumns,
<b>bool</b> fromtheright,
<b>bool</b> dotranspose);
</div></pre>
<a name='sub_rmatrixbdunpackdiagonals'></a><h3 class=pageheader><code>rmatrixbdunpackdiagonals</code> function</h3>
<pre class=source>
<div style='color: navy; margin-top: 0; margin-bottom: 0;'>/*************************************************************************
Unpacking of the main and secondary diagonals of bidiagonal decomposition
of matrix A.
Input parameters:
B - output of RMatrixBD subroutine.
M - number of rows in matrix B.
N - number of columns in matrix B.
Output parameters:
IsUpper - True, if the matrix is upper bidiagonal.
otherwise IsUpper is False.
D - the main diagonal.
Array whose index ranges within [0..Min(M,N)-1].
E - the secondary diagonal (upper or lower, depending on
the value of IsUpper).
Array index ranges within [0..Min(M,N)-1], the last
element is not used.
-- ALGLIB --
2005-2010
Bochkanov Sergey
*************************************************************************/
</div><div style='margin-top: 0; margin-bottom: 0;'><b>void</b> alglib::rmatrixbdunpackdiagonals(
real_2d_array b,
ae_int_t m,
ae_int_t n,
<b>bool</b>& isupper,
real_1d_array& d,
real_1d_array& e);
</div></pre>
<a name='sub_rmatrixbdunpackpt'></a><h3 class=pageheader><code>rmatrixbdunpackpt</code> function</h3>
<pre class=source>
<div style='color: navy; margin-top: 0; margin-bottom: 0;'>/*************************************************************************
Unpacking matrix P which reduces matrix A to bidiagonal form.
The subroutine returns transposed matrix P.
Input parameters:
QP - matrices Q and P in compact form.
Output of ToBidiagonal subroutine.
M - number of rows in matrix A.
N - number of columns in matrix A.
TAUP - scalar factors which are used to form P.
Output of ToBidiagonal subroutine.
PTRows - required number of rows of matrix P^T. N >= PTRows >= 0.
Output parameters:
PT - first PTRows columns of matrix P^T
Array[0..PTRows-1, 0..N-1]
If PTRows=0, the array is not modified.
-- ALGLIB --
2005-2010
Bochkanov Sergey
*************************************************************************/
</div><div style='margin-top: 0; margin-bottom: 0;'><b>void</b> alglib::rmatrixbdunpackpt(
real_2d_array qp,
ae_int_t m,
ae_int_t n,
real_1d_array taup,
ae_int_t ptrows,
real_2d_array& pt);
</div></pre>
<a name='sub_rmatrixbdunpackq'></a><h3 class=pageheader><code>rmatrixbdunpackq</code> function</h3>
<pre class=source>
<div style='color: navy; margin-top: 0; margin-bottom: 0;'>/*************************************************************************
Unpacking matrix Q which reduces a matrix to bidiagonal form.
COMMERCIAL EDITION OF ALGLIB:
! Commercial version of ALGLIB includes one important improvement of
! this function, which can be used from C++ and C#:
! * Intel MKL support (lightweight Intel MKL is shipped with ALGLIB)
!
! Intel MKL gives approximately constant (with respect to number of
! worker threads) acceleration factor which depends on CPU being used,
! problem size and "baseline" ALGLIB edition which is used for
! comparison.
!
! Multithreaded acceleration is NOT supported for this function.
!
! We recommend you to read 'Working with commercial version' section of
! ALGLIB Reference Manual in order to find out how to use performance-
! related features provided by commercial edition of ALGLIB.
Input parameters:
QP - matrices Q and P in compact form.
Output of ToBidiagonal subroutine.
M - number of rows in matrix A.
N - number of columns in matrix A.
TAUQ - scalar factors which are used to form Q.
Output of ToBidiagonal subroutine.
QColumns - required number of columns in matrix Q.
M>=QColumns>=0.
Output parameters:
Q - first QColumns columns of matrix Q.
Array[0..M-1, 0..QColumns-1]
If QColumns=0, the array is not modified.
-- ALGLIB --
2005-2010
Bochkanov Sergey
*************************************************************************/
</div><div style='margin-top: 0; margin-bottom: 0;'><b>void</b> alglib::rmatrixbdunpackq(
real_2d_array qp,
ae_int_t m,
ae_int_t n,
real_1d_array tauq,
ae_int_t qcolumns,
real_2d_array& q);
</div></pre>
<a name='sub_rmatrixhessenberg'></a><h3 class=pageheader><code>rmatrixhessenberg</code> function</h3>
<pre class=source>
<div style='color: navy; margin-top: 0; margin-bottom: 0;'>/*************************************************************************
Reduction of a square matrix to upper Hessenberg form: Q'*A*Q = H,
where Q is an orthogonal matrix, H - Hessenberg matrix.
COMMERCIAL EDITION OF ALGLIB:
! Commercial version of ALGLIB includes one important improvement of
! this function, which can be used from C++ and C#:
! * Intel MKL support (lightweight Intel MKL is shipped with ALGLIB)
!
! Intel MKL gives approximately constant (with respect to number of
! worker threads) acceleration factor which depends on CPU being used,
! problem size and "baseline" ALGLIB edition which is used for
! comparison.
!
! Generally, commercial ALGLIB is several times faster than open-source
! generic C edition, and many times faster than open-source C# edition.
!
! Multithreaded acceleration is NOT supported for this function.
!
! We recommend you to read 'Working with commercial version' section of
! ALGLIB Reference Manual in order to find out how to use performance-
! related features provided by commercial edition of ALGLIB.
Input parameters:
A - matrix A with elements [0..N-1, 0..N-1]
N - size of matrix A.
Output parameters:
A - matrices Q and P in compact form (see below).
Tau - array of scalar factors which are used to form matrix Q.
Array whose index ranges within [0..N-2]
Matrix H is located on the main diagonal, on the lower secondary diagonal
and above the main diagonal of matrix A. The elements which are used to
form matrix Q are situated in array Tau and below the lower secondary
diagonal of matrix A as follows:
Matrix Q is represented as a product of elementary reflections
Q = H(0)*H(2)*...*H(n-2),
where each H(i) is given by
H(i) = 1 - tau * v * (v^T)
where tau is a scalar stored in Tau[I]; v - is a real vector,
so that v(0:i) = 0, v(i+1) = 1, v(i+2:n-1) stored in A(i+2:n-1,i).
-- LAPACK routine (version 3.0) --
Univ. of Tennessee, Univ. of California Berkeley, NAG Ltd.,
Courant Institute, Argonne National Lab, and Rice University
October 31, 1992
*************************************************************************/
</div><div style='margin-top: 0; margin-bottom: 0;'><b>void</b> alglib::rmatrixhessenberg(
real_2d_array& a,
ae_int_t n,
real_1d_array& tau);
</div></pre>
<a name='sub_rmatrixhessenbergunpackh'></a><h3 class=pageheader><code>rmatrixhessenbergunpackh</code> function</h3>
<pre class=source>
<div style='color: navy; margin-top: 0; margin-bottom: 0;'>/*************************************************************************
Unpacking matrix H (the result of matrix A reduction to upper Hessenberg form)
Input parameters:
A - output of RMatrixHessenberg subroutine.
N - size of matrix A.
Output parameters:
H - matrix H. Array whose indexes range within [0..N-1, 0..N-1].
-- ALGLIB --
2005-2010
Bochkanov Sergey
*************************************************************************/
</div><div style='margin-top: 0; margin-bottom: 0;'><b>void</b> alglib::rmatrixhessenbergunpackh(
real_2d_array a,
ae_int_t n,
real_2d_array& h);
</div></pre>
<a name='sub_rmatrixhessenbergunpackq'></a><h3 class=pageheader><code>rmatrixhessenbergunpackq</code> function</h3>
<pre class=source>
<div style='color: navy; margin-top: 0; margin-bottom: 0;'>/*************************************************************************
Unpacking matrix Q which reduces matrix A to upper Hessenberg form
COMMERCIAL EDITION OF ALGLIB:
! Commercial version of ALGLIB includes one important improvement of
! this function, which can be used from C++ and C#:
! * Intel MKL support (lightweight Intel MKL is shipped with ALGLIB)
!
! Intel MKL gives approximately constant (with respect to number of
! worker threads) acceleration factor which depends on CPU being used,
! problem size and "baseline" ALGLIB edition which is used for
! comparison.
!
! Generally, commercial ALGLIB is several times faster than open-source
! generic C edition, and many times faster than open-source C# edition.
!
! Multithreaded acceleration is NOT supported for this function.
!
! We recommend you to read 'Working with commercial version' section of
! ALGLIB Reference Manual in order to find out how to use performance-
! related features provided by commercial edition of ALGLIB.
Input parameters:
A - output of RMatrixHessenberg subroutine.
N - size of matrix A.
Tau - scalar factors which are used to form Q.
Output of RMatrixHessenberg subroutine.
Output parameters:
Q - matrix Q.
Array whose indexes range within [0..N-1, 0..N-1].
-- ALGLIB --
2005-2010
Bochkanov Sergey
*************************************************************************/
</div><div style='margin-top: 0; margin-bottom: 0;'><b>void</b> alglib::rmatrixhessenbergunpackq(
real_2d_array a,
ae_int_t n,
real_1d_array tau,
real_2d_array& q);
</div></pre>
<a name='sub_rmatrixlq'></a><h3 class=pageheader><code>rmatrixlq</code> function</h3>
<pre class=source>
<div style='color: navy; margin-top: 0; margin-bottom: 0;'>/*************************************************************************
LQ decomposition of a rectangular matrix of size MxN
COMMERCIAL EDITION OF ALGLIB:
! Commercial version of ALGLIB includes two important improvements of
! this function, which can be used from C++ and C#:
! * Intel MKL support (lightweight Intel MKL is shipped with ALGLIB)
! * multicore support
!
! Intel MKL gives approximately constant (with respect to number of
! worker threads) acceleration factor which depends on CPU being used,
! problem size and "baseline" ALGLIB edition which is used for
! comparison.
!
! Say, on SSE2-capable CPU with N=1024, HPC ALGLIB will be:
! * about 2-3x faster than ALGLIB for C++ without MKL
! * about 7-10x faster than "pure C#" edition of ALGLIB
! Difference in performance will be more striking on newer CPU's with
! support for newer SIMD instructions. Generally, MKL accelerates any
! problem whose size is at least 128, with best efficiency achieved for
! N's larger than 512.
!
! Commercial edition of ALGLIB also supports multithreaded acceleration
! of this function. We should note that QP decomposition is harder to
! parallelize than, say, matrix-matrix product - this algorithm has
! many internal synchronization points which can not be avoided. However
! parallelism starts to be profitable starting from N=512, achieving
! near-linear speedup for N=4096 or higher.
!
! In order to use multicore features you have to:
! * use commercial version of ALGLIB
! * call this function with "smp_" prefix, which indicates that
! multicore code will be used (for multicore support)
!
! We recommend you to read 'Working with commercial version' section of
! ALGLIB Reference Manual in order to find out how to use performance-
! related features provided by commercial edition of ALGLIB.
Input parameters:
A - matrix A whose indexes range within [0..M-1, 0..N-1].
M - number of rows in matrix A.
N - number of columns in matrix A.
Output parameters:
A - matrices L and Q in compact form (see below)
Tau - array of scalar factors which are used to form
matrix Q. Array whose index ranges within [0..Min(M,N)-1].
Matrix A is represented as A = LQ, where Q is an orthogonal matrix of size
MxM, L - lower triangular (or lower trapezoid) matrix of size M x N.
The elements of matrix L are located on and below the main diagonal of
matrix A. The elements which are located in Tau array and above the main
diagonal of matrix A are used to form matrix Q as follows:
Matrix Q is represented as a product of elementary reflections
Q = H(k-1)*H(k-2)*...*H(1)*H(0),
where k = min(m,n), and each H(i) is of the form
H(i) = 1 - tau * v * (v^T)
where tau is a scalar stored in Tau[I]; v - real vector, so that v(0:i-1)=0,
v(i) = 1, v(i+1:n-1) stored in A(i,i+1:n-1).
-- ALGLIB routine --
17.02.2010
Bochkanov Sergey
*************************************************************************/
</div><div style='margin-top: 0; margin-bottom: 0;'><b>void</b> alglib::rmatrixlq(
real_2d_array& a,
ae_int_t m,
ae_int_t n,
real_1d_array& tau);
<b>void</b> alglib::smp_rmatrixlq(
real_2d_array& a,
ae_int_t m,
ae_int_t n,
real_1d_array& tau);
</div></pre>
<a name='sub_rmatrixlqunpackl'></a><h3 class=pageheader><code>rmatrixlqunpackl</code> function</h3>
<pre class=source>
<div style='color: navy; margin-top: 0; margin-bottom: 0;'>/*************************************************************************
Unpacking of matrix L from the LQ decomposition of a matrix A
Input parameters:
A - matrices Q and L in compact form.
Output of RMatrixLQ subroutine.
M - number of rows in given matrix A. M>=0.
N - number of columns in given matrix A. N>=0.
Output parameters:
L - matrix L, array[0..M-1, 0..N-1].
-- ALGLIB routine --
17.02.2010
Bochkanov Sergey
*************************************************************************/
</div><div style='margin-top: 0; margin-bottom: 0;'><b>void</b> alglib::rmatrixlqunpackl(
real_2d_array a,
ae_int_t m,
ae_int_t n,
real_2d_array& l);
</div></pre>
<a name='sub_rmatrixlqunpackq'></a><h3 class=pageheader><code>rmatrixlqunpackq</code> function</h3>
<pre class=source>
<div style='color: navy; margin-top: 0; margin-bottom: 0;'>/*************************************************************************
Partial unpacking of matrix Q from the LQ decomposition of a matrix A
COMMERCIAL EDITION OF ALGLIB:
! Commercial version of ALGLIB includes two important improvements of
! this function, which can be used from C++ and C#:
! * Intel MKL support (lightweight Intel MKL is shipped with ALGLIB)
! * multicore support
!
! Intel MKL gives approximately constant (with respect to number of
! worker threads) acceleration factor which depends on CPU being used,
! problem size and "baseline" ALGLIB edition which is used for
! comparison.
!
! Say, on SSE2-capable CPU with N=1024, HPC ALGLIB will be:
! * about 2-3x faster than ALGLIB for C++ without MKL
! * about 7-10x faster than "pure C#" edition of ALGLIB
! Difference in performance will be more striking on newer CPU's with
! support for newer SIMD instructions. Generally, MKL accelerates any
! problem whose size is at least 128, with best efficiency achieved for
! N's larger than 512.
!
! Commercial edition of ALGLIB also supports multithreaded acceleration
! of this function. We should note that QP decomposition is harder to
! parallelize than, say, matrix-matrix product - this algorithm has
! many internal synchronization points which can not be avoided. However
! parallelism starts to be profitable starting from N=512, achieving
! near-linear speedup for N=4096 or higher.
!
! In order to use multicore features you have to:
! * use commercial version of ALGLIB
! * call this function with "smp_" prefix, which indicates that
! multicore code will be used (for multicore support)
!
! We recommend you to read 'Working with commercial version' section of
! ALGLIB Reference Manual in order to find out how to use performance-
! related features provided by commercial edition of ALGLIB.
Input parameters:
A - matrices L and Q in compact form.
Output of RMatrixLQ subroutine.
M - number of rows in given matrix A. M>=0.
N - number of columns in given matrix A. N>=0.
Tau - scalar factors which are used to form Q.
Output of the RMatrixLQ subroutine.
QRows - required number of rows in matrix Q. N>=QRows>=0.
Output parameters:
Q - first QRows rows of matrix Q. Array whose indexes range
within [0..QRows-1, 0..N-1]. If QRows=0, the array remains
unchanged.
-- ALGLIB routine --
17.02.2010
Bochkanov Sergey
*************************************************************************/
</div><div style='margin-top: 0; margin-bottom: 0;'><b>void</b> alglib::rmatrixlqunpackq(
real_2d_array a,
ae_int_t m,
ae_int_t n,
real_1d_array tau,
ae_int_t qrows,
real_2d_array& q);
<b>void</b> alglib::smp_rmatrixlqunpackq(
real_2d_array a,
ae_int_t m,
ae_int_t n,
real_1d_array tau,
ae_int_t qrows,
real_2d_array& q);
</div></pre>
<a name='sub_rmatrixqr'></a><h3 class=pageheader><code>rmatrixqr</code> function</h3>
<pre class=source>
<div style='color: navy; margin-top: 0; margin-bottom: 0;'>/*************************************************************************
QR decomposition of a rectangular matrix of size MxN
COMMERCIAL EDITION OF ALGLIB:
! Commercial version of ALGLIB includes two important improvements of
! this function, which can be used from C++ and C#:
! * Intel MKL support (lightweight Intel MKL is shipped with ALGLIB)
! * multicore support
!
! Intel MKL gives approximately constant (with respect to number of
! worker threads) acceleration factor which depends on CPU being used,
! problem size and "baseline" ALGLIB edition which is used for
! comparison.
!
! Say, on SSE2-capable CPU with N=1024, HPC ALGLIB will be:
! * about 2-3x faster than ALGLIB for C++ without MKL
! * about 7-10x faster than "pure C#" edition of ALGLIB
! Difference in performance will be more striking on newer CPU's with
! support for newer SIMD instructions. Generally, MKL accelerates any
! problem whose size is at least 128, with best efficiency achieved for
! N's larger than 512.
!
! Commercial edition of ALGLIB also supports multithreaded acceleration
! of this function. We should note that QP decomposition is harder to
! parallelize than, say, matrix-matrix product - this algorithm has
! many internal synchronization points which can not be avoided. However
! parallelism starts to be profitable starting from N=512, achieving
! near-linear speedup for N=4096 or higher.
!
! In order to use multicore features you have to:
! * use commercial version of ALGLIB
! * call this function with "smp_" prefix, which indicates that
! multicore code will be used (for multicore support)
!
! We recommend you to read 'Working with commercial version' section of
! ALGLIB Reference Manual in order to find out how to use performance-
! related features provided by commercial edition of ALGLIB.
Input parameters:
A - matrix A whose indexes range within [0..M-1, 0..N-1].
M - number of rows in matrix A.
N - number of columns in matrix A.
Output parameters:
A - matrices Q and R in compact form (see below).
Tau - array of scalar factors which are used to form
matrix Q. Array whose index ranges within [0.. Min(M-1,N-1)].
Matrix A is represented as A = QR, where Q is an orthogonal matrix of size
MxM, R - upper triangular (or upper trapezoid) matrix of size M x N.
The elements of matrix R are located on and above the main diagonal of
matrix A. The elements which are located in Tau array and below the main
diagonal of matrix A are used to form matrix Q as follows:
Matrix Q is represented as a product of elementary reflections
Q = H(0)*H(2)*...*H(k-1),
where k = min(m,n), and each H(i) is in the form
H(i) = 1 - tau * v * (v^T)
where tau is a scalar stored in Tau[I]; v - real vector,
so that v(0:i-1) = 0, v(i) = 1, v(i+1:m-1) stored in A(i+1:m-1,i).
-- ALGLIB routine --
17.02.2010
Bochkanov Sergey
*************************************************************************/
</div><div style='margin-top: 0; margin-bottom: 0;'><b>void</b> alglib::rmatrixqr(
real_2d_array& a,
ae_int_t m,
ae_int_t n,
real_1d_array& tau);
<b>void</b> alglib::smp_rmatrixqr(
real_2d_array& a,
ae_int_t m,
ae_int_t n,
real_1d_array& tau);
</div></pre>
<a name='sub_rmatrixqrunpackq'></a><h3 class=pageheader><code>rmatrixqrunpackq</code> function</h3>
<pre class=source>
<div style='color: navy; margin-top: 0; margin-bottom: 0;'>/*************************************************************************
Partial unpacking of matrix Q from the QR decomposition of a matrix A
COMMERCIAL EDITION OF ALGLIB:
! Commercial version of ALGLIB includes two important improvements of
! this function, which can be used from C++ and C#:
! * Intel MKL support (lightweight Intel MKL is shipped with ALGLIB)
! * multicore support
!
! Intel MKL gives approximately constant (with respect to number of
! worker threads) acceleration factor which depends on CPU being used,
! problem size and "baseline" ALGLIB edition which is used for
! comparison.
!
! Say, on SSE2-capable CPU with N=1024, HPC ALGLIB will be:
! * about 2-3x faster than ALGLIB for C++ without MKL
! * about 7-10x faster than "pure C#" edition of ALGLIB
! Difference in performance will be more striking on newer CPU's with
! support for newer SIMD instructions. Generally, MKL accelerates any
! problem whose size is at least 128, with best efficiency achieved for
! N's larger than 512.
!
! Commercial edition of ALGLIB also supports multithreaded acceleration
! of this function. We should note that QP decomposition is harder to
! parallelize than, say, matrix-matrix product - this algorithm has
! many internal synchronization points which can not be avoided. However
! parallelism starts to be profitable starting from N=512, achieving
! near-linear speedup for N=4096 or higher.
!
! In order to use multicore features you have to:
! * use commercial version of ALGLIB
! * call this function with "smp_" prefix, which indicates that
! multicore code will be used (for multicore support)
!
! We recommend you to read 'Working with commercial version' section of
! ALGLIB Reference Manual in order to find out how to use performance-
! related features provided by commercial edition of ALGLIB.
Input parameters:
A - matrices Q and R in compact form.
Output of RMatrixQR subroutine.
M - number of rows in given matrix A. M>=0.
N - number of columns in given matrix A. N>=0.
Tau - scalar factors which are used to form Q.
Output of the RMatrixQR subroutine.
QColumns - required number of columns of matrix Q. M>=QColumns>=0.
Output parameters:
Q - first QColumns columns of matrix Q.
Array whose indexes range within [0..M-1, 0..QColumns-1].
If QColumns=0, the array remains unchanged.
-- ALGLIB routine --
17.02.2010
Bochkanov Sergey
*************************************************************************/
</div><div style='margin-top: 0; margin-bottom: 0;'><b>void</b> alglib::rmatrixqrunpackq(
real_2d_array a,
ae_int_t m,
ae_int_t n,
real_1d_array tau,
ae_int_t qcolumns,
real_2d_array& q);
<b>void</b> alglib::smp_rmatrixqrunpackq(
real_2d_array a,
ae_int_t m,
ae_int_t n,
real_1d_array tau,
ae_int_t qcolumns,
real_2d_array& q);
</div></pre>
<a name='sub_rmatrixqrunpackr'></a><h3 class=pageheader><code>rmatrixqrunpackr</code> function</h3>
<pre class=source>
<div style='color: navy; margin-top: 0; margin-bottom: 0;'>/*************************************************************************
Unpacking of matrix R from the QR decomposition of a matrix A
Input parameters:
A - matrices Q and R in compact form.
Output of RMatrixQR subroutine.
M - number of rows in given matrix A. M>=0.
N - number of columns in given matrix A. N>=0.
Output parameters:
R - matrix R, array[0..M-1, 0..N-1].
-- ALGLIB routine --
17.02.2010
Bochkanov Sergey
*************************************************************************/
</div><div style='margin-top: 0; margin-bottom: 0;'><b>void</b> alglib::rmatrixqrunpackr(
real_2d_array a,
ae_int_t m,
ae_int_t n,
real_2d_array& r);
</div></pre>
<a name='sub_smatrixtd'></a><h3 class=pageheader><code>smatrixtd</code> function</h3>
<pre class=source>
<div style='color: navy; margin-top: 0; margin-bottom: 0;'>/*************************************************************************
Reduction of a symmetric matrix which is given by its higher or lower
triangular part to a tridiagonal matrix using orthogonal similarity
transformation: Q'*A*Q=T.
COMMERCIAL EDITION OF ALGLIB:
! Commercial version of ALGLIB includes one important improvement of
! this function, which can be used from C++ and C#:
! * Intel MKL support (lightweight Intel MKL is shipped with ALGLIB)
!
! Intel MKL gives approximately constant (with respect to number of
! worker threads) acceleration factor which depends on CPU being used,
! problem size and "baseline" ALGLIB edition which is used for
! comparison.
!
! Generally, commercial ALGLIB is several times faster than open-source
! generic C edition, and many times faster than open-source C# edition.
!
! Multithreaded acceleration is NOT supported for this function.
!
! We recommend you to read 'Working with commercial version' section of
! ALGLIB Reference Manual in order to find out how to use performance-
! related features provided by commercial edition of ALGLIB.
Input parameters:
A - matrix to be transformed
array with elements [0..N-1, 0..N-1].
N - size of matrix A.
IsUpper - storage format. If IsUpper = True, then matrix A is given
by its upper triangle, and the lower triangle is not used
and not modified by the algorithm, and vice versa
if IsUpper = False.
Output parameters:
A - matrices T and Q in compact form (see lower)
Tau - array of factors which are forming matrices H(i)
array with elements [0..N-2].
D - main diagonal of symmetric matrix T.
array with elements [0..N-1].
E - secondary diagonal of symmetric matrix T.
array with elements [0..N-2].
If IsUpper=True, the matrix Q is represented as a product of elementary
reflectors
Q = H(n-2) . . . H(2) H(0).
Each H(i) has the form
H(i) = I - tau * v * v'
where tau is a real scalar, and v is a real vector with
v(i+1:n-1) = 0, v(i) = 1, v(0:i-1) is stored on exit in
A(0:i-1,i+1), and tau in TAU(i).
If IsUpper=False, the matrix Q is represented as a product of elementary
reflectors
Q = H(0) H(2) . . . H(n-2).
Each H(i) has the form
H(i) = I - tau * v * v'
where tau is a real scalar, and v is a real vector with
v(0:i) = 0, v(i+1) = 1, v(i+2:n-1) is stored on exit in A(i+2:n-1,i),
and tau in TAU(i).
The contents of A on exit are illustrated by the following examples
with n = 5:
if UPLO = 'U': if UPLO = 'L':
( d e v1 v2 v3 ) ( d )
( d e v2 v3 ) ( e d )
( d e v3 ) ( v0 e d )
( d e ) ( v0 v1 e d )
( d ) ( v0 v1 v2 e d )
where d and e denote diagonal and off-diagonal elements of T, and vi
denotes an element of the vector defining H(i).
-- LAPACK routine (version 3.0) --
Univ. of Tennessee, Univ. of California Berkeley, NAG Ltd.,
Courant Institute, Argonne National Lab, and Rice University
October 31, 1992
*************************************************************************/
</div><div style='margin-top: 0; margin-bottom: 0;'><b>void</b> alglib::smatrixtd(
real_2d_array& a,
ae_int_t n,
<b>bool</b> isupper,
real_1d_array& tau,
real_1d_array& d,
real_1d_array& e);
</div></pre>
<a name='sub_smatrixtdunpackq'></a><h3 class=pageheader><code>smatrixtdunpackq</code> function</h3>
<pre class=source>
<div style='color: navy; margin-top: 0; margin-bottom: 0;'>/*************************************************************************
Unpacking matrix Q which reduces symmetric matrix to a tridiagonal
form.
COMMERCIAL EDITION OF ALGLIB:
! Commercial version of ALGLIB includes one important improvement of
! this function, which can be used from C++ and C#:
! * Intel MKL support (lightweight Intel MKL is shipped with ALGLIB)
!
! Intel MKL gives approximately constant (with respect to number of
! worker threads) acceleration factor which depends on CPU being used,
! problem size and "baseline" ALGLIB edition which is used for
! comparison.
!
! Generally, commercial ALGLIB is several times faster than open-source
! generic C edition, and many times faster than open-source C# edition.
!
! Multithreaded acceleration is NOT supported for this function.
!
! We recommend you to read 'Working with commercial version' section of
! ALGLIB Reference Manual in order to find out how to use performance-
! related features provided by commercial edition of ALGLIB.
Input parameters:
A - the result of a SMatrixTD subroutine
N - size of matrix A.
IsUpper - storage format (a parameter of SMatrixTD subroutine)
Tau - the result of a SMatrixTD subroutine
Output parameters:
Q - transformation matrix.
array with elements [0..N-1, 0..N-1].
-- ALGLIB --
Copyright 2005-2010 by Bochkanov Sergey
*************************************************************************/
</div><div style='margin-top: 0; margin-bottom: 0;'><b>void</b> alglib::smatrixtdunpackq(
real_2d_array a,
ae_int_t n,
<b>bool</b> isupper,
real_1d_array tau,
real_2d_array& q);
</div></pre>
<a name=unit_parametric></a><h2 class=pageheader><code>parametric</code> subpackage</h2>
<div class=pagecontent>
<h3 class=pageheader>Classes</h3>
<a href='#struct_pspline2interpolant' class=toc>pspline2interpolant</a><br>
<a href='#struct_pspline3interpolant' class=toc>pspline3interpolant</a><br>
<h3 class=pageheader>Functions</h3>
<a href='#sub_parametricrdpfixed' class=toc>parametricrdpfixed</a><br>
<a href='#sub_pspline2arclength' class=toc>pspline2arclength</a><br>
<a href='#sub_pspline2build' class=toc>pspline2build</a><br>
<a href='#sub_pspline2buildperiodic' class=toc>pspline2buildperiodic</a><br>
<a href='#sub_pspline2calc' class=toc>pspline2calc</a><br>
<a href='#sub_pspline2diff' class=toc>pspline2diff</a><br>
<a href='#sub_pspline2diff2' class=toc>pspline2diff2</a><br>
<a href='#sub_pspline2parametervalues' class=toc>pspline2parametervalues</a><br>
<a href='#sub_pspline2tangent' class=toc>pspline2tangent</a><br>
<a href='#sub_pspline3arclength' class=toc>pspline3arclength</a><br>
<a href='#sub_pspline3build' class=toc>pspline3build</a><br>
<a href='#sub_pspline3buildperiodic' class=toc>pspline3buildperiodic</a><br>
<a href='#sub_pspline3calc' class=toc>pspline3calc</a><br>
<a href='#sub_pspline3diff' class=toc>pspline3diff</a><br>
<a href='#sub_pspline3diff2' class=toc>pspline3diff2</a><br>
<a href='#sub_pspline3parametervalues' class=toc>pspline3parametervalues</a><br>
<a href='#sub_pspline3tangent' class=toc>pspline3tangent</a><br>
<h3 class=pageheader>Examples</h3>
<table border=0 cellspacing=0 class='pagecontent'>
<tr align=left valign=top><td><a href='#example_parametric_rdp' class=toc>parametric_rdp</a></td><td width=15> </td><td>Parametric Ramer-Douglas-Peucker approximation</td></tr>
</table></div>
<a name='struct_pspline2interpolant'></a><h3 class=pageheader><code>pspline2interpolant</code> class</h3>
<pre class=source>
<div style='color: navy; margin-top: 0; margin-bottom: 0;'>/*************************************************************************
Parametric spline inteprolant: 2-dimensional curve.
You should not try to access its members directly - use PSpline2XXXXXXXX()
functions instead.
*************************************************************************/
</div><div style='margin-top: 0; margin-bottom: 0;'><b>class</b> pspline2interpolant
{
};
</div></pre>
<a name='struct_pspline3interpolant'></a><h3 class=pageheader><code>pspline3interpolant</code> class</h3>
<pre class=source>
<div style='color: navy; margin-top: 0; margin-bottom: 0;'>/*************************************************************************
Parametric spline inteprolant: 3-dimensional curve.
You should not try to access its members directly - use PSpline3XXXXXXXX()
functions instead.
*************************************************************************/
</div><div style='margin-top: 0; margin-bottom: 0;'><b>class</b> pspline3interpolant
{
};
</div></pre>
<a name='sub_parametricrdpfixed'></a><h3 class=pageheader><code>parametricrdpfixed</code> function</h3>
<pre class=source>
<div style='color: navy; margin-top: 0; margin-bottom: 0;'>/*************************************************************************
This subroutine fits piecewise linear curve to points with Ramer-Douglas-
Peucker algorithm. This function performs PARAMETRIC fit, i.e. it can be
used to fit curves like circles.
On input it accepts dataset which describes parametric multidimensional
curve X(t), with X being vector, and t taking values in [0,N), where N is
a number of points in dataset. As result, it returns reduced dataset X2,
which can be used to build parametric curve X2(t), which approximates
X(t) with desired precision (or has specified number of sections).
INPUT PARAMETERS:
X - array of multidimensional points:
* at least N elements, leading N elements are used if more
than N elements were specified
* order of points is IMPORTANT because it is parametric
fit
* each row of array is one point which has D coordinates
N - number of elements in X
D - number of dimensions (elements per row of X)
StopM - stopping condition - desired number of sections:
* at most M sections are generated by this function
* less than M sections can be generated if we have N<M
(or some X are non-distinct).
* zero StopM means that algorithm does not stop after
achieving some pre-specified section count
StopEps - stopping condition - desired precision:
* algorithm stops after error in each section is at most Eps
* zero Eps means that algorithm does not stop after
achieving some pre-specified precision
OUTPUT PARAMETERS:
X2 - array of corner points for piecewise approximation,
has length NSections+1 or zero (for NSections=0).
Idx2 - array of indexes (parameter values):
* has length NSections+1 or zero (for NSections=0).
* each element of Idx2 corresponds to same-numbered
element of X2
* each element of Idx2 is index of corresponding element
of X2 at original array X, i.e. I-th row of X2 is
Idx2[I]-th row of X.
* elements of Idx2 can be treated as parameter values
which should be used when building new parametric curve
* Idx2[0]=0, Idx2[NSections]=N-1
NSections- number of sections found by algorithm, NSections<=M,
NSections can be zero for degenerate datasets
(N<=1 or all X[] are non-distinct).
NOTE: algorithm stops after:
a) dividing curve into StopM sections
b) achieving required precision StopEps
c) dividing curve into N-1 sections
If both StopM and StopEps are non-zero, algorithm is stopped by the
FIRST criterion which is satisfied. In case both StopM and StopEps
are zero, algorithm stops because of (c).
-- ALGLIB --
Copyright 02.10.2014 by Bochkanov Sergey
*************************************************************************/
</div><div style='margin-top: 0; margin-bottom: 0;'><b>void</b> alglib::parametricrdpfixed(
real_2d_array x,
ae_int_t n,
ae_int_t d,
ae_int_t stopm,
<b>double</b> stopeps,
real_2d_array& x2,
integer_1d_array& idx2,
ae_int_t& nsections);
</div></pre>
<p align=left class=pagecontent><span class=inlineheader>Examples:</span> <a href='#example_parametric_rdp' class=nav>[1]</a> </p>
<a name='sub_pspline2arclength'></a><h3 class=pageheader><code>pspline2arclength</code> function</h3>
<pre class=source>
<div style='color: navy; margin-top: 0; margin-bottom: 0;'>/*************************************************************************
This function calculates arc length, i.e. length of curve between t=a
and t=b.
INPUT PARAMETERS:
P - parametric spline interpolant
A,B - parameter values corresponding to arc ends:
* B>A will result in positive length returned
* B<A will result in negative length returned
RESULT:
length of arc starting at T=A and ending at T=B.
-- ALGLIB PROJECT --
Copyright 30.05.2010 by Bochkanov Sergey
*************************************************************************/
</div><div style='margin-top: 0; margin-bottom: 0;'><b>double</b> alglib::pspline2arclength(
pspline2interpolant p,
<b>double</b> a,
<b>double</b> b);
</div></pre>
<a name='sub_pspline2build'></a><h3 class=pageheader><code>pspline2build</code> function</h3>
<pre class=source>
<div style='color: navy; margin-top: 0; margin-bottom: 0;'>/*************************************************************************
This function builds non-periodic 2-dimensional parametric spline which
starts at (X[0],Y[0]) and ends at (X[N-1],Y[N-1]).
INPUT PARAMETERS:
XY - points, array[0..N-1,0..1].
XY[I,0:1] corresponds to the Ith point.
Order of points is important!
N - points count, N>=5 for Akima splines, N>=2 for other types of
splines.
ST - spline type:
* 0 Akima spline
* 1 parabolically terminated Catmull-Rom spline (Tension=0)
* 2 parabolically terminated cubic spline
PT - parameterization type:
* 0 uniform
* 1 chord length
* 2 centripetal
OUTPUT PARAMETERS:
P - parametric spline interpolant
NOTES:
* this function assumes that there all consequent points are distinct.
I.e. (x0,y0)<>(x1,y1), (x1,y1)<>(x2,y2), (x2,y2)<>(x3,y3) and so on.
However, non-consequent points may coincide, i.e. we can have (x0,y0)=
=(x2,y2).
-- ALGLIB PROJECT --
Copyright 28.05.2010 by Bochkanov Sergey
*************************************************************************/
</div><div style='margin-top: 0; margin-bottom: 0;'><b>void</b> alglib::pspline2build(
real_2d_array xy,
ae_int_t n,
ae_int_t st,
ae_int_t pt,
pspline2interpolant& p);
</div></pre>
<a name='sub_pspline2buildperiodic'></a><h3 class=pageheader><code>pspline2buildperiodic</code> function</h3>
<pre class=source>
<div style='color: navy; margin-top: 0; margin-bottom: 0;'>/*************************************************************************
This function builds periodic 2-dimensional parametric spline which
starts at (X[0],Y[0]), goes through all points to (X[N-1],Y[N-1]) and then
back to (X[0],Y[0]).
INPUT PARAMETERS:
XY - points, array[0..N-1,0..1].
XY[I,0:1] corresponds to the Ith point.
XY[N-1,0:1] must be different from XY[0,0:1].
Order of points is important!
N - points count, N>=3 for other types of splines.
ST - spline type:
* 1 Catmull-Rom spline (Tension=0) with cyclic boundary conditions
* 2 cubic spline with cyclic boundary conditions
PT - parameterization type:
* 0 uniform
* 1 chord length
* 2 centripetal
OUTPUT PARAMETERS:
P - parametric spline interpolant
NOTES:
* this function assumes that there all consequent points are distinct.
I.e. (x0,y0)<>(x1,y1), (x1,y1)<>(x2,y2), (x2,y2)<>(x3,y3) and so on.
However, non-consequent points may coincide, i.e. we can have (x0,y0)=
=(x2,y2).
* last point of sequence is NOT equal to the first point. You shouldn't
make curve "explicitly periodic" by making them equal.
-- ALGLIB PROJECT --
Copyright 28.05.2010 by Bochkanov Sergey
*************************************************************************/
</div><div style='margin-top: 0; margin-bottom: 0;'><b>void</b> alglib::pspline2buildperiodic(
real_2d_array xy,
ae_int_t n,
ae_int_t st,
ae_int_t pt,
pspline2interpolant& p);
</div></pre>
<a name='sub_pspline2calc'></a><h3 class=pageheader><code>pspline2calc</code> function</h3>
<pre class=source>
<div style='color: navy; margin-top: 0; margin-bottom: 0;'>/*************************************************************************
This function calculates the value of the parametric spline for a given
value of parameter T
INPUT PARAMETERS:
P - parametric spline interpolant
T - point:
* T in [0,1] corresponds to interval spanned by points
* for non-periodic splines T<0 (or T>1) correspond to parts of
the curve before the first (after the last) point
* for periodic splines T<0 (or T>1) are projected into [0,1]
by making T=T-floor(T).
OUTPUT PARAMETERS:
X - X-position
Y - Y-position
-- ALGLIB PROJECT --
Copyright 28.05.2010 by Bochkanov Sergey
*************************************************************************/
</div><div style='margin-top: 0; margin-bottom: 0;'><b>void</b> alglib::pspline2calc(
pspline2interpolant p,
<b>double</b> t,
<b>double</b>& x,
<b>double</b>& y);
</div></pre>
<a name='sub_pspline2diff'></a><h3 class=pageheader><code>pspline2diff</code> function</h3>
<pre class=source>
<div style='color: navy; margin-top: 0; margin-bottom: 0;'>/*************************************************************************
This function calculates derivative, i.e. it returns (dX/dT,dY/dT).
INPUT PARAMETERS:
P - parametric spline interpolant
T - point:
* T in [0,1] corresponds to interval spanned by points
* for non-periodic splines T<0 (or T>1) correspond to parts of
the curve before the first (after the last) point
* for periodic splines T<0 (or T>1) are projected into [0,1]
by making T=T-floor(T).
OUTPUT PARAMETERS:
X - X-value
DX - X-derivative
Y - Y-value
DY - Y-derivative
-- ALGLIB PROJECT --
Copyright 28.05.2010 by Bochkanov Sergey
*************************************************************************/
</div><div style='margin-top: 0; margin-bottom: 0;'><b>void</b> alglib::pspline2diff(
pspline2interpolant p,
<b>double</b> t,
<b>double</b>& x,
<b>double</b>& dx,
<b>double</b>& y,
<b>double</b>& dy);
</div></pre>
<a name='sub_pspline2diff2'></a><h3 class=pageheader><code>pspline2diff2</code> function</h3>
<pre class=source>
<div style='color: navy; margin-top: 0; margin-bottom: 0;'>/*************************************************************************
This function calculates first and second derivative with respect to T.
INPUT PARAMETERS:
P - parametric spline interpolant
T - point:
* T in [0,1] corresponds to interval spanned by points
* for non-periodic splines T<0 (or T>1) correspond to parts of
the curve before the first (after the last) point
* for periodic splines T<0 (or T>1) are projected into [0,1]
by making T=T-floor(T).
OUTPUT PARAMETERS:
X - X-value
DX - derivative
D2X - second derivative
Y - Y-value
DY - derivative
D2Y - second derivative
-- ALGLIB PROJECT --
Copyright 28.05.2010 by Bochkanov Sergey
*************************************************************************/
</div><div style='margin-top: 0; margin-bottom: 0;'><b>void</b> alglib::pspline2diff2(
pspline2interpolant p,
<b>double</b> t,
<b>double</b>& x,
<b>double</b>& dx,
<b>double</b>& d2x,
<b>double</b>& y,
<b>double</b>& dy,
<b>double</b>& d2y);
</div></pre>
<a name='sub_pspline2parametervalues'></a><h3 class=pageheader><code>pspline2parametervalues</code> function</h3>
<pre class=source>
<div style='color: navy; margin-top: 0; margin-bottom: 0;'>/*************************************************************************
This function returns vector of parameter values correspoding to points.
I.e. for P created from (X[0],Y[0])...(X[N-1],Y[N-1]) and U=TValues(P) we
have
(X[0],Y[0]) = PSpline2Calc(P,U[0]),
(X[1],Y[1]) = PSpline2Calc(P,U[1]),
(X[2],Y[2]) = PSpline2Calc(P,U[2]),
...
INPUT PARAMETERS:
P - parametric spline interpolant
OUTPUT PARAMETERS:
N - array size
T - array[0..N-1]
NOTES:
* for non-periodic splines U[0]=0, U[0]<U[1]<...<U[N-1], U[N-1]=1
* for periodic splines U[0]=0, U[0]<U[1]<...<U[N-1], U[N-1]<1
-- ALGLIB PROJECT --
Copyright 28.05.2010 by Bochkanov Sergey
*************************************************************************/
</div><div style='margin-top: 0; margin-bottom: 0;'><b>void</b> alglib::pspline2parametervalues(
pspline2interpolant p,
ae_int_t& n,
real_1d_array& t);
</div></pre>
<a name='sub_pspline2tangent'></a><h3 class=pageheader><code>pspline2tangent</code> function</h3>
<pre class=source>
<div style='color: navy; margin-top: 0; margin-bottom: 0;'>/*************************************************************************
This function calculates tangent vector for a given value of parameter T
INPUT PARAMETERS:
P - parametric spline interpolant
T - point:
* T in [0,1] corresponds to interval spanned by points
* for non-periodic splines T<0 (or T>1) correspond to parts of
the curve before the first (after the last) point
* for periodic splines T<0 (or T>1) are projected into [0,1]
by making T=T-floor(T).
OUTPUT PARAMETERS:
X - X-component of tangent vector (normalized)
Y - Y-component of tangent vector (normalized)
NOTE:
X^2+Y^2 is either 1 (for non-zero tangent vector) or 0.
-- ALGLIB PROJECT --
Copyright 28.05.2010 by Bochkanov Sergey
*************************************************************************/
</div><div style='margin-top: 0; margin-bottom: 0;'><b>void</b> alglib::pspline2tangent(
pspline2interpolant p,
<b>double</b> t,
<b>double</b>& x,
<b>double</b>& y);
</div></pre>
<a name='sub_pspline3arclength'></a><h3 class=pageheader><code>pspline3arclength</code> function</h3>
<pre class=source>
<div style='color: navy; margin-top: 0; margin-bottom: 0;'>/*************************************************************************
This function calculates arc length, i.e. length of curve between t=a
and t=b.
INPUT PARAMETERS:
P - parametric spline interpolant
A,B - parameter values corresponding to arc ends:
* B>A will result in positive length returned
* B<A will result in negative length returned
RESULT:
length of arc starting at T=A and ending at T=B.
-- ALGLIB PROJECT --
Copyright 30.05.2010 by Bochkanov Sergey
*************************************************************************/
</div><div style='margin-top: 0; margin-bottom: 0;'><b>double</b> alglib::pspline3arclength(
pspline3interpolant p,
<b>double</b> a,
<b>double</b> b);
</div></pre>
<a name='sub_pspline3build'></a><h3 class=pageheader><code>pspline3build</code> function</h3>
<pre class=source>
<div style='color: navy; margin-top: 0; margin-bottom: 0;'>/*************************************************************************
This function builds non-periodic 3-dimensional parametric spline which
starts at (X[0],Y[0],Z[0]) and ends at (X[N-1],Y[N-1],Z[N-1]).
Same as PSpline2Build() function, but for 3D, so we won't duplicate its
description here.
-- ALGLIB PROJECT --
Copyright 28.05.2010 by Bochkanov Sergey
*************************************************************************/
</div><div style='margin-top: 0; margin-bottom: 0;'><b>void</b> alglib::pspline3build(
real_2d_array xy,
ae_int_t n,
ae_int_t st,
ae_int_t pt,
pspline3interpolant& p);
</div></pre>
<a name='sub_pspline3buildperiodic'></a><h3 class=pageheader><code>pspline3buildperiodic</code> function</h3>
<pre class=source>
<div style='color: navy; margin-top: 0; margin-bottom: 0;'>/*************************************************************************
This function builds periodic 3-dimensional parametric spline which
starts at (X[0],Y[0],Z[0]), goes through all points to (X[N-1],Y[N-1],Z[N-1])
and then back to (X[0],Y[0],Z[0]).
Same as PSpline2Build() function, but for 3D, so we won't duplicate its
description here.
-- ALGLIB PROJECT --
Copyright 28.05.2010 by Bochkanov Sergey
*************************************************************************/
</div><div style='margin-top: 0; margin-bottom: 0;'><b>void</b> alglib::pspline3buildperiodic(
real_2d_array xy,
ae_int_t n,
ae_int_t st,
ae_int_t pt,
pspline3interpolant& p);
</div></pre>
<a name='sub_pspline3calc'></a><h3 class=pageheader><code>pspline3calc</code> function</h3>
<pre class=source>
<div style='color: navy; margin-top: 0; margin-bottom: 0;'>/*************************************************************************
This function calculates the value of the parametric spline for a given
value of parameter T.
INPUT PARAMETERS:
P - parametric spline interpolant
T - point:
* T in [0,1] corresponds to interval spanned by points
* for non-periodic splines T<0 (or T>1) correspond to parts of
the curve before the first (after the last) point
* for periodic splines T<0 (or T>1) are projected into [0,1]
by making T=T-floor(T).
OUTPUT PARAMETERS:
X - X-position
Y - Y-position
Z - Z-position
-- ALGLIB PROJECT --
Copyright 28.05.2010 by Bochkanov Sergey
*************************************************************************/
</div><div style='margin-top: 0; margin-bottom: 0;'><b>void</b> alglib::pspline3calc(
pspline3interpolant p,
<b>double</b> t,
<b>double</b>& x,
<b>double</b>& y,
<b>double</b>& z);
</div></pre>
<a name='sub_pspline3diff'></a><h3 class=pageheader><code>pspline3diff</code> function</h3>
<pre class=source>
<div style='color: navy; margin-top: 0; margin-bottom: 0;'>/*************************************************************************
This function calculates derivative, i.e. it returns (dX/dT,dY/dT,dZ/dT).
INPUT PARAMETERS:
P - parametric spline interpolant
T - point:
* T in [0,1] corresponds to interval spanned by points
* for non-periodic splines T<0 (or T>1) correspond to parts of
the curve before the first (after the last) point
* for periodic splines T<0 (or T>1) are projected into [0,1]
by making T=T-floor(T).
OUTPUT PARAMETERS:
X - X-value
DX - X-derivative
Y - Y-value
DY - Y-derivative
Z - Z-value
DZ - Z-derivative
-- ALGLIB PROJECT --
Copyright 28.05.2010 by Bochkanov Sergey
*************************************************************************/
</div><div style='margin-top: 0; margin-bottom: 0;'><b>void</b> alglib::pspline3diff(
pspline3interpolant p,
<b>double</b> t,
<b>double</b>& x,
<b>double</b>& dx,
<b>double</b>& y,
<b>double</b>& dy,
<b>double</b>& z,
<b>double</b>& dz);
</div></pre>
<a name='sub_pspline3diff2'></a><h3 class=pageheader><code>pspline3diff2</code> function</h3>
<pre class=source>
<div style='color: navy; margin-top: 0; margin-bottom: 0;'>/*************************************************************************
This function calculates first and second derivative with respect to T.
INPUT PARAMETERS:
P - parametric spline interpolant
T - point:
* T in [0,1] corresponds to interval spanned by points
* for non-periodic splines T<0 (or T>1) correspond to parts of
the curve before the first (after the last) point
* for periodic splines T<0 (or T>1) are projected into [0,1]
by making T=T-floor(T).
OUTPUT PARAMETERS:
X - X-value
DX - derivative
D2X - second derivative
Y - Y-value
DY - derivative
D2Y - second derivative
Z - Z-value
DZ - derivative
D2Z - second derivative
-- ALGLIB PROJECT --
Copyright 28.05.2010 by Bochkanov Sergey
*************************************************************************/
</div><div style='margin-top: 0; margin-bottom: 0;'><b>void</b> alglib::pspline3diff2(
pspline3interpolant p,
<b>double</b> t,
<b>double</b>& x,
<b>double</b>& dx,
<b>double</b>& d2x,
<b>double</b>& y,
<b>double</b>& dy,
<b>double</b>& d2y,
<b>double</b>& z,
<b>double</b>& dz,
<b>double</b>& d2z);
</div></pre>
<a name='sub_pspline3parametervalues'></a><h3 class=pageheader><code>pspline3parametervalues</code> function</h3>
<pre class=source>
<div style='color: navy; margin-top: 0; margin-bottom: 0;'>/*************************************************************************
This function returns vector of parameter values correspoding to points.
Same as PSpline2ParameterValues(), but for 3D.
-- ALGLIB PROJECT --
Copyright 28.05.2010 by Bochkanov Sergey
*************************************************************************/
</div><div style='margin-top: 0; margin-bottom: 0;'><b>void</b> alglib::pspline3parametervalues(
pspline3interpolant p,
ae_int_t& n,
real_1d_array& t);
</div></pre>
<a name='sub_pspline3tangent'></a><h3 class=pageheader><code>pspline3tangent</code> function</h3>
<pre class=source>
<div style='color: navy; margin-top: 0; margin-bottom: 0;'>/*************************************************************************
This function calculates tangent vector for a given value of parameter T
INPUT PARAMETERS:
P - parametric spline interpolant
T - point:
* T in [0,1] corresponds to interval spanned by points
* for non-periodic splines T<0 (or T>1) correspond to parts of
the curve before the first (after the last) point
* for periodic splines T<0 (or T>1) are projected into [0,1]
by making T=T-floor(T).
OUTPUT PARAMETERS:
X - X-component of tangent vector (normalized)
Y - Y-component of tangent vector (normalized)
Z - Z-component of tangent vector (normalized)
NOTE:
X^2+Y^2+Z^2 is either 1 (for non-zero tangent vector) or 0.
-- ALGLIB PROJECT --
Copyright 28.05.2010 by Bochkanov Sergey
*************************************************************************/
</div><div style='margin-top: 0; margin-bottom: 0;'><b>void</b> alglib::pspline3tangent(
pspline3interpolant p,
<b>double</b> t,
<b>double</b>& x,
<b>double</b>& y,
<b>double</b>& z);
</div></pre>
<a name='example_parametric_rdp'></a><h3 class=pageheader>parametric_rdp example</h3>
<pre class=source>
#include <font color=blue><b>"stdafx.h"</b></font>
#include <stdlib.h>
#include <stdio.h>
#include <math.h>
#include <font color=blue><b>"interpolation.h"</b></font>
using namespace alglib;
<b>int</b> main(<b>int</b> argc, char **argv)
{
<font color=navy>//</font>
<font color=navy>// We use RDP algorithm to approximate parametric 2D curve given by</font>
<font color=navy>// locations in t=0,1,2,3 (see below), which form piecewise linear</font>
<font color=navy>// trajectory through D-dimensional space (2-dimensional in our example).</font>
<font color=navy>// </font>
<font color=navy>// |</font>
<font color=navy>// |</font>
<font color=navy>// - * * X2................X3</font>
<font color=navy>// | .</font>
<font color=navy>// | .</font>
<font color=navy>// - * * . * * * *</font>
<font color=navy>// | .</font>
<font color=navy>// | .</font>
<font color=navy>// - * X1 * * * *</font>
<font color=navy>// | .....</font>
<font color=navy>// | ....</font>
<font color=navy>// X0----|-----|-----|-----|-----|-----|---</font>
<font color=navy>//</font>
ae_int_t npoints = 4;
ae_int_t ndimensions = 2;
real_2d_array x = <font color=blue><b>"[[0,0],[2,1],[3,3],[6,3]]"</b></font>;
<font color=navy>//</font>
<font color=navy>// Approximation of parametric curve is performed by another parametric curve</font>
<font color=navy>// with lesser amount of points. It allows to work with <font color=blue><b>"compressed"</b></font></font>
<font color=navy>// representation, which needs smaller amount of memory. Say, in our example</font>
<font color=navy>// (we allow points with error smaller than 0.8) approximation will have</font>
<font color=navy>// just two sequential sections connecting X0 with X2, and X2 with X3.</font>
<font color=navy>// </font>
<font color=navy>// |</font>
<font color=navy>// |</font>
<font color=navy>// - * * X2................X3</font>
<font color=navy>// | . </font>
<font color=navy>// | . </font>
<font color=navy>// - * . * * * *</font>
<font color=navy>// | . </font>
<font color=navy>// | . </font>
<font color=navy>// - . X1 * * * *</font>
<font color=navy>// | . </font>
<font color=navy>// | . </font>
<font color=navy>// X0----|-----|-----|-----|-----|-----|---</font>
<font color=navy>//</font>
<font color=navy>//</font>
real_2d_array y;
integer_1d_array idxy;
ae_int_t nsections;
ae_int_t limitcnt = 0;
<b>double</b> limiteps = 0.8;
parametricrdpfixed(x, npoints, ndimensions, limitcnt, limiteps, y, idxy, nsections);
printf(<font color=blue><b>"%d\n"</b></font>, <b>int</b>(nsections)); <font color=navy>// EXPECTED: 2</font>
printf(<font color=blue><b>"%s\n"</b></font>, idxy.tostring().c_str()); <font color=navy>// EXPECTED: [0,2,3]</font>
<b>return</b> 0;
}
</pre><a name=unit_pca></a><h2 class=pageheader><code>pca</code> subpackage</h2>
<div class=pagecontent>
<h3 class=pageheader>Functions</h3>
<a href='#sub_pcabuildbasis' class=toc>pcabuildbasis</a><br>
<h3 class=pageheader>Examples</h3>
<table border=0 cellspacing=0 class='pagecontent'>
</table></div>
<a name='sub_pcabuildbasis'></a><h3 class=pageheader><code>pcabuildbasis</code> function</h3>
<pre class=source>
<div style='color: navy; margin-top: 0; margin-bottom: 0;'>/*************************************************************************
Principal components analysis
Subroutine builds orthogonal basis where first axis corresponds to
direction with maximum variance, second axis maximizes variance in subspace
orthogonal to first axis and so on.
It should be noted that, unlike LDA, PCA does not use class labels.
COMMERCIAL EDITION OF ALGLIB:
! Commercial version of ALGLIB includes one important improvement of
! this function, which can be used from C++ and C#:
! * Intel MKL support (lightweight Intel MKL is shipped with ALGLIB)
!
! Intel MKL gives approximately constant (with respect to number of
! worker threads) acceleration factor which depends on CPU being used,
! problem size and "baseline" ALGLIB edition which is used for
! comparison. Best results are achieved for high-dimensional problems
! (NVars is at least 256).
!
! We recommend you to read 'Working with commercial version' section of
! ALGLIB Reference Manual in order to find out how to use performance-
! related features provided by commercial edition of ALGLIB.
INPUT PARAMETERS:
X - dataset, array[0..NPoints-1,0..NVars-1].
matrix contains ONLY INDEPENDENT VARIABLES.
NPoints - dataset size, NPoints>=0
NVars - number of independent variables, NVars>=1
OUTPUT PARAMETERS:
Info - return code:
* -4, if SVD subroutine haven't converged
* -1, if wrong parameters has been passed (NPoints<0,
NVars<1)
* 1, if task is solved
S2 - array[0..NVars-1]. variance values corresponding
to basis vectors.
V - array[0..NVars-1,0..NVars-1]
matrix, whose columns store basis vectors.
-- ALGLIB --
Copyright 25.08.2008 by Bochkanov Sergey
*************************************************************************/
</div><div style='margin-top: 0; margin-bottom: 0;'><b>void</b> alglib::pcabuildbasis(
real_2d_array x,
ae_int_t npoints,
ae_int_t nvars,
ae_int_t& info,
real_1d_array& s2,
real_2d_array& v);
</div></pre>
<a name=unit_poissondistr></a><h2 class=pageheader><code>poissondistr</code> subpackage</h2>
<div class=pagecontent>
<h3 class=pageheader>Functions</h3>
<a href='#sub_invpoissondistribution' class=toc>invpoissondistribution</a><br>
<a href='#sub_poissoncdistribution' class=toc>poissoncdistribution</a><br>
<a href='#sub_poissondistribution' class=toc>poissondistribution</a><br>
<h3 class=pageheader>Examples</h3>
<table border=0 cellspacing=0 class='pagecontent'>
</table></div>
<a name='sub_invpoissondistribution'></a><h3 class=pageheader><code>invpoissondistribution</code> function</h3>
<pre class=source>
<div style='color: navy; margin-top: 0; margin-bottom: 0;'>/*************************************************************************
Inverse Poisson distribution
Finds the Poisson variable x such that the integral
from 0 to x of the Poisson density is equal to the
given probability y.
This is accomplished using the inverse gamma integral
function and the relation
m = igami( k+1, y ).
ACCURACY:
See inverse incomplete gamma function
Cephes Math Library Release 2.8: June, 2000
Copyright 1984, 1987, 1995, 2000 by Stephen L. Moshier
*************************************************************************/
</div><div style='margin-top: 0; margin-bottom: 0;'><b>double</b> alglib::invpoissondistribution(ae_int_t k, <b>double</b> y);
</div></pre>
<a name='sub_poissoncdistribution'></a><h3 class=pageheader><code>poissoncdistribution</code> function</h3>
<pre class=source>
<div style='color: navy; margin-top: 0; margin-bottom: 0;'>/*************************************************************************
Complemented Poisson distribution
Returns the sum of the terms k+1 to infinity of the Poisson
distribution:
inf. j
-- -m m
> e --
-- j!
j=k+1
The terms are not summed directly; instead the incomplete
gamma integral is employed, according to the formula
y = pdtrc( k, m ) = igam( k+1, m ).
The arguments must both be positive.
ACCURACY:
See incomplete gamma function
Cephes Math Library Release 2.8: June, 2000
Copyright 1984, 1987, 1995, 2000 by Stephen L. Moshier
*************************************************************************/
</div><div style='margin-top: 0; margin-bottom: 0;'><b>double</b> alglib::poissoncdistribution(ae_int_t k, <b>double</b> m);
</div></pre>
<a name='sub_poissondistribution'></a><h3 class=pageheader><code>poissondistribution</code> function</h3>
<pre class=source>
<div style='color: navy; margin-top: 0; margin-bottom: 0;'>/*************************************************************************
Poisson distribution
Returns the sum of the first k+1 terms of the Poisson
distribution:
k j
-- -m m
> e --
-- j!
j=0
The terms are not summed directly; instead the incomplete
gamma integral is employed, according to the relation
y = pdtr( k, m ) = igamc( k+1, m ).
The arguments must both be positive.
ACCURACY:
See incomplete gamma function
Cephes Math Library Release 2.8: June, 2000
Copyright 1984, 1987, 1995, 2000 by Stephen L. Moshier
*************************************************************************/
</div><div style='margin-top: 0; margin-bottom: 0;'><b>double</b> alglib::poissondistribution(ae_int_t k, <b>double</b> m);
</div></pre>
<a name=unit_polint></a><h2 class=pageheader><code>polint</code> subpackage</h2>
<div class=pagecontent>
<h3 class=pageheader>Functions</h3>
<a href='#sub_polynomialbar2cheb' class=toc>polynomialbar2cheb</a><br>
<a href='#sub_polynomialbar2pow' class=toc>polynomialbar2pow</a><br>
<a href='#sub_polynomialbuild' class=toc>polynomialbuild</a><br>
<a href='#sub_polynomialbuildcheb1' class=toc>polynomialbuildcheb1</a><br>
<a href='#sub_polynomialbuildcheb2' class=toc>polynomialbuildcheb2</a><br>
<a href='#sub_polynomialbuildeqdist' class=toc>polynomialbuildeqdist</a><br>
<a href='#sub_polynomialcalccheb1' class=toc>polynomialcalccheb1</a><br>
<a href='#sub_polynomialcalccheb2' class=toc>polynomialcalccheb2</a><br>
<a href='#sub_polynomialcalceqdist' class=toc>polynomialcalceqdist</a><br>
<a href='#sub_polynomialcheb2bar' class=toc>polynomialcheb2bar</a><br>
<a href='#sub_polynomialpow2bar' class=toc>polynomialpow2bar</a><br>
<h3 class=pageheader>Examples</h3>
<table border=0 cellspacing=0 class='pagecontent'>
<tr align=left valign=top><td><a href='#example_polint_d_calcdiff' class=toc>polint_d_calcdiff</a></td><td width=15> </td><td>Interpolation and differentiation using barycentric representation</td></tr>
<tr align=left valign=top><td><a href='#example_polint_d_conv' class=toc>polint_d_conv</a></td><td width=15> </td><td>Conversion between power basis and barycentric representation</td></tr>
<tr align=left valign=top><td><a href='#example_polint_d_spec' class=toc>polint_d_spec</a></td><td width=15> </td><td>Polynomial interpolation on special grids (equidistant, Chebyshev I/II)</td></tr>
</table></div>
<a name='sub_polynomialbar2cheb'></a><h3 class=pageheader><code>polynomialbar2cheb</code> function</h3>
<pre class=source>
<div style='color: navy; margin-top: 0; margin-bottom: 0;'>/*************************************************************************
Conversion from barycentric representation to Chebyshev basis.
This function has O(N^2) complexity.
INPUT PARAMETERS:
P - polynomial in barycentric form
A,B - base interval for Chebyshev polynomials (see below)
A<>B
OUTPUT PARAMETERS
T - coefficients of Chebyshev representation;
P(x) = sum { T[i]*Ti(2*(x-A)/(B-A)-1), i=0..N-1 },
where Ti - I-th Chebyshev polynomial.
NOTES:
barycentric interpolant passed as P may be either polynomial obtained
from polynomial interpolation/ fitting or rational function which is
NOT polynomial. We can't distinguish between these two cases, and this
algorithm just tries to work assuming that P IS a polynomial. If not,
algorithm will return results, but they won't have any meaning.
-- ALGLIB --
Copyright 30.09.2010 by Bochkanov Sergey
*************************************************************************/
</div><div style='margin-top: 0; margin-bottom: 0;'><b>void</b> alglib::polynomialbar2cheb(
barycentricinterpolant p,
<b>double</b> a,
<b>double</b> b,
real_1d_array& t);
</div></pre>
<a name='sub_polynomialbar2pow'></a><h3 class=pageheader><code>polynomialbar2pow</code> function</h3>
<pre class=source>
<div style='color: navy; margin-top: 0; margin-bottom: 0;'>/*************************************************************************
Conversion from barycentric representation to power basis.
This function has O(N^2) complexity.
INPUT PARAMETERS:
P - polynomial in barycentric form
C - offset (see below); 0.0 is used as default value.
S - scale (see below); 1.0 is used as default value. S<>0.
OUTPUT PARAMETERS
A - coefficients, P(x) = sum { A[i]*((X-C)/S)^i, i=0..N-1 }
N - number of coefficients (polynomial degree plus 1)
NOTES:
1. this function accepts offset and scale, which can be set to improve
numerical properties of polynomial. For example, if P was obtained as
result of interpolation on [-1,+1], you can set C=0 and S=1 and
represent P as sum of 1, x, x^2, x^3 and so on. In most cases you it
is exactly what you need.
However, if your interpolation model was built on [999,1001], you will
see significant growth of numerical errors when using {1, x, x^2, x^3}
as basis. Representing P as sum of 1, (x-1000), (x-1000)^2, (x-1000)^3
will be better option. Such representation can be obtained by using
1000.0 as offset C and 1.0 as scale S.
2. power basis is ill-conditioned and tricks described above can't solve
this problem completely. This function will return coefficients in
any case, but for N>8 they will become unreliable. However, N's
less than 5 are pretty safe.
3. barycentric interpolant passed as P may be either polynomial obtained
from polynomial interpolation/ fitting or rational function which is
NOT polynomial. We can't distinguish between these two cases, and this
algorithm just tries to work assuming that P IS a polynomial. If not,
algorithm will return results, but they won't have any meaning.
-- ALGLIB --
Copyright 30.09.2010 by Bochkanov Sergey
*************************************************************************/
</div><div style='margin-top: 0; margin-bottom: 0;'><b>void</b> alglib::polynomialbar2pow(
barycentricinterpolant p,
real_1d_array& a);
<b>void</b> alglib::polynomialbar2pow(
barycentricinterpolant p,
<b>double</b> c,
<b>double</b> s,
real_1d_array& a);
</div></pre>
<p align=left class=pagecontent><span class=inlineheader>Examples:</span> <a href='#example_polint_d_conv' class=nav>[1]</a> </p>
<a name='sub_polynomialbuild'></a><h3 class=pageheader><code>polynomialbuild</code> function</h3>
<pre class=source>
<div style='color: navy; margin-top: 0; margin-bottom: 0;'>/*************************************************************************
Lagrange intepolant: generation of the model on the general grid.
This function has O(N^2) complexity.
INPUT PARAMETERS:
X - abscissas, array[0..N-1]
Y - function values, array[0..N-1]
N - number of points, N>=1
OUTPUT PARAMETERS
P - barycentric model which represents Lagrange interpolant
(see ratint unit info and BarycentricCalc() description for
more information).
-- ALGLIB --
Copyright 02.12.2009 by Bochkanov Sergey
*************************************************************************/
</div><div style='margin-top: 0; margin-bottom: 0;'><b>void</b> alglib::polynomialbuild(
real_1d_array x,
real_1d_array y,
barycentricinterpolant& p);
<b>void</b> alglib::polynomialbuild(
real_1d_array x,
real_1d_array y,
ae_int_t n,
barycentricinterpolant& p);
</div></pre>
<p align=left class=pagecontent><span class=inlineheader>Examples:</span> <a href='#example_polint_d_calcdiff' class=nav>[1]</a> </p>
<a name='sub_polynomialbuildcheb1'></a><h3 class=pageheader><code>polynomialbuildcheb1</code> function</h3>
<pre class=source>
<div style='color: navy; margin-top: 0; margin-bottom: 0;'>/*************************************************************************
Lagrange intepolant on Chebyshev grid (first kind).
This function has O(N) complexity.
INPUT PARAMETERS:
A - left boundary of [A,B]
B - right boundary of [A,B]
Y - function values at the nodes, array[0..N-1],
Y[I] = Y(0.5*(B+A) + 0.5*(B-A)*Cos(PI*(2*i+1)/(2*n)))
N - number of points, N>=1
for N=1 a constant model is constructed.
OUTPUT PARAMETERS
P - barycentric model which represents Lagrange interpolant
(see ratint unit info and BarycentricCalc() description for
more information).
-- ALGLIB --
Copyright 03.12.2009 by Bochkanov Sergey
*************************************************************************/
</div><div style='margin-top: 0; margin-bottom: 0;'><b>void</b> alglib::polynomialbuildcheb1(
<b>double</b> a,
<b>double</b> b,
real_1d_array y,
barycentricinterpolant& p);
<b>void</b> alglib::polynomialbuildcheb1(
<b>double</b> a,
<b>double</b> b,
real_1d_array y,
ae_int_t n,
barycentricinterpolant& p);
</div></pre>
<p align=left class=pagecontent><span class=inlineheader>Examples:</span> <a href='#example_polint_d_spec' class=nav>[1]</a> </p>
<a name='sub_polynomialbuildcheb2'></a><h3 class=pageheader><code>polynomialbuildcheb2</code> function</h3>
<pre class=source>
<div style='color: navy; margin-top: 0; margin-bottom: 0;'>/*************************************************************************
Lagrange intepolant on Chebyshev grid (second kind).
This function has O(N) complexity.
INPUT PARAMETERS:
A - left boundary of [A,B]
B - right boundary of [A,B]
Y - function values at the nodes, array[0..N-1],
Y[I] = Y(0.5*(B+A) + 0.5*(B-A)*Cos(PI*i/(n-1)))
N - number of points, N>=1
for N=1 a constant model is constructed.
OUTPUT PARAMETERS
P - barycentric model which represents Lagrange interpolant
(see ratint unit info and BarycentricCalc() description for
more information).
-- ALGLIB --
Copyright 03.12.2009 by Bochkanov Sergey
*************************************************************************/
</div><div style='margin-top: 0; margin-bottom: 0;'><b>void</b> alglib::polynomialbuildcheb2(
<b>double</b> a,
<b>double</b> b,
real_1d_array y,
barycentricinterpolant& p);
<b>void</b> alglib::polynomialbuildcheb2(
<b>double</b> a,
<b>double</b> b,
real_1d_array y,
ae_int_t n,
barycentricinterpolant& p);
</div></pre>
<p align=left class=pagecontent><span class=inlineheader>Examples:</span> <a href='#example_polint_d_spec' class=nav>[1]</a> </p>
<a name='sub_polynomialbuildeqdist'></a><h3 class=pageheader><code>polynomialbuildeqdist</code> function</h3>
<pre class=source>
<div style='color: navy; margin-top: 0; margin-bottom: 0;'>/*************************************************************************
Lagrange intepolant: generation of the model on equidistant grid.
This function has O(N) complexity.
INPUT PARAMETERS:
A - left boundary of [A,B]
B - right boundary of [A,B]
Y - function values at the nodes, array[0..N-1]
N - number of points, N>=1
for N=1 a constant model is constructed.
OUTPUT PARAMETERS
P - barycentric model which represents Lagrange interpolant
(see ratint unit info and BarycentricCalc() description for
more information).
-- ALGLIB --
Copyright 03.12.2009 by Bochkanov Sergey
*************************************************************************/
</div><div style='margin-top: 0; margin-bottom: 0;'><b>void</b> alglib::polynomialbuildeqdist(
<b>double</b> a,
<b>double</b> b,
real_1d_array y,
barycentricinterpolant& p);
<b>void</b> alglib::polynomialbuildeqdist(
<b>double</b> a,
<b>double</b> b,
real_1d_array y,
ae_int_t n,
barycentricinterpolant& p);
</div></pre>
<p align=left class=pagecontent><span class=inlineheader>Examples:</span> <a href='#example_polint_d_spec' class=nav>[1]</a> </p>
<a name='sub_polynomialcalccheb1'></a><h3 class=pageheader><code>polynomialcalccheb1</code> function</h3>
<pre class=source>
<div style='color: navy; margin-top: 0; margin-bottom: 0;'>/*************************************************************************
Fast polynomial interpolation function on Chebyshev points (first kind)
with O(N) complexity.
INPUT PARAMETERS:
A - left boundary of [A,B]
B - right boundary of [A,B]
F - function values, array[0..N-1]
N - number of points on Chebyshev grid (first kind),
X[i] = 0.5*(B+A) + 0.5*(B-A)*Cos(PI*(2*i+1)/(2*n))
for N=1 a constant model is constructed.
T - position where P(x) is calculated
RESULT
value of the Lagrange interpolant at T
IMPORTANT
this function provides fast interface which is not overflow-safe
nor it is very precise.
the best option is to use PolIntBuildCheb1()/BarycentricCalc()
subroutines unless you are pretty sure that your data will not result
in overflow.
-- ALGLIB --
Copyright 02.12.2009 by Bochkanov Sergey
*************************************************************************/
</div><div style='margin-top: 0; margin-bottom: 0;'><b>double</b> alglib::polynomialcalccheb1(
<b>double</b> a,
<b>double</b> b,
real_1d_array f,
<b>double</b> t);
<b>double</b> alglib::polynomialcalccheb1(
<b>double</b> a,
<b>double</b> b,
real_1d_array f,
ae_int_t n,
<b>double</b> t);
</div></pre>
<p align=left class=pagecontent><span class=inlineheader>Examples:</span> <a href='#example_polint_d_spec' class=nav>[1]</a> </p>
<a name='sub_polynomialcalccheb2'></a><h3 class=pageheader><code>polynomialcalccheb2</code> function</h3>
<pre class=source>
<div style='color: navy; margin-top: 0; margin-bottom: 0;'>/*************************************************************************
Fast polynomial interpolation function on Chebyshev points (second kind)
with O(N) complexity.
INPUT PARAMETERS:
A - left boundary of [A,B]
B - right boundary of [A,B]
F - function values, array[0..N-1]
N - number of points on Chebyshev grid (second kind),
X[i] = 0.5*(B+A) + 0.5*(B-A)*Cos(PI*i/(n-1))
for N=1 a constant model is constructed.
T - position where P(x) is calculated
RESULT
value of the Lagrange interpolant at T
IMPORTANT
this function provides fast interface which is not overflow-safe
nor it is very precise.
the best option is to use PolIntBuildCheb2()/BarycentricCalc()
subroutines unless you are pretty sure that your data will not result
in overflow.
-- ALGLIB --
Copyright 02.12.2009 by Bochkanov Sergey
*************************************************************************/
</div><div style='margin-top: 0; margin-bottom: 0;'><b>double</b> alglib::polynomialcalccheb2(
<b>double</b> a,
<b>double</b> b,
real_1d_array f,
<b>double</b> t);
<b>double</b> alglib::polynomialcalccheb2(
<b>double</b> a,
<b>double</b> b,
real_1d_array f,
ae_int_t n,
<b>double</b> t);
</div></pre>
<p align=left class=pagecontent><span class=inlineheader>Examples:</span> <a href='#example_polint_d_spec' class=nav>[1]</a> </p>
<a name='sub_polynomialcalceqdist'></a><h3 class=pageheader><code>polynomialcalceqdist</code> function</h3>
<pre class=source>
<div style='color: navy; margin-top: 0; margin-bottom: 0;'>/*************************************************************************
Fast equidistant polynomial interpolation function with O(N) complexity
INPUT PARAMETERS:
A - left boundary of [A,B]
B - right boundary of [A,B]
F - function values, array[0..N-1]
N - number of points on equidistant grid, N>=1
for N=1 a constant model is constructed.
T - position where P(x) is calculated
RESULT
value of the Lagrange interpolant at T
IMPORTANT
this function provides fast interface which is not overflow-safe
nor it is very precise.
the best option is to use PolynomialBuildEqDist()/BarycentricCalc()
subroutines unless you are pretty sure that your data will not result
in overflow.
-- ALGLIB --
Copyright 02.12.2009 by Bochkanov Sergey
*************************************************************************/
</div><div style='margin-top: 0; margin-bottom: 0;'><b>double</b> alglib::polynomialcalceqdist(
<b>double</b> a,
<b>double</b> b,
real_1d_array f,
<b>double</b> t);
<b>double</b> alglib::polynomialcalceqdist(
<b>double</b> a,
<b>double</b> b,
real_1d_array f,
ae_int_t n,
<b>double</b> t);
</div></pre>
<p align=left class=pagecontent><span class=inlineheader>Examples:</span> <a href='#example_polint_d_spec' class=nav>[1]</a> </p>
<a name='sub_polynomialcheb2bar'></a><h3 class=pageheader><code>polynomialcheb2bar</code> function</h3>
<pre class=source>
<div style='color: navy; margin-top: 0; margin-bottom: 0;'>/*************************************************************************
Conversion from Chebyshev basis to barycentric representation.
This function has O(N^2) complexity.
INPUT PARAMETERS:
T - coefficients of Chebyshev representation;
P(x) = sum { T[i]*Ti(2*(x-A)/(B-A)-1), i=0..N },
where Ti - I-th Chebyshev polynomial.
N - number of coefficients:
* if given, only leading N elements of T are used
* if not given, automatically determined from size of T
A,B - base interval for Chebyshev polynomials (see above)
A<B
OUTPUT PARAMETERS
P - polynomial in barycentric form
-- ALGLIB --
Copyright 30.09.2010 by Bochkanov Sergey
*************************************************************************/
</div><div style='margin-top: 0; margin-bottom: 0;'><b>void</b> alglib::polynomialcheb2bar(
real_1d_array t,
<b>double</b> a,
<b>double</b> b,
barycentricinterpolant& p);
<b>void</b> alglib::polynomialcheb2bar(
real_1d_array t,
ae_int_t n,
<b>double</b> a,
<b>double</b> b,
barycentricinterpolant& p);
</div></pre>
<a name='sub_polynomialpow2bar'></a><h3 class=pageheader><code>polynomialpow2bar</code> function</h3>
<pre class=source>
<div style='color: navy; margin-top: 0; margin-bottom: 0;'>/*************************************************************************
Conversion from power basis to barycentric representation.
This function has O(N^2) complexity.
INPUT PARAMETERS:
A - coefficients, P(x) = sum { A[i]*((X-C)/S)^i, i=0..N-1 }
N - number of coefficients (polynomial degree plus 1)
* if given, only leading N elements of A are used
* if not given, automatically determined from size of A
C - offset (see below); 0.0 is used as default value.
S - scale (see below); 1.0 is used as default value. S<>0.
OUTPUT PARAMETERS
P - polynomial in barycentric form
NOTES:
1. this function accepts offset and scale, which can be set to improve
numerical properties of polynomial. For example, if you interpolate on
[-1,+1], you can set C=0 and S=1 and convert from sum of 1, x, x^2,
x^3 and so on. In most cases you it is exactly what you need.
However, if your interpolation model was built on [999,1001], you will
see significant growth of numerical errors when using {1, x, x^2, x^3}
as input basis. Converting from sum of 1, (x-1000), (x-1000)^2,
(x-1000)^3 will be better option (you have to specify 1000.0 as offset
C and 1.0 as scale S).
2. power basis is ill-conditioned and tricks described above can't solve
this problem completely. This function will return barycentric model
in any case, but for N>8 accuracy well degrade. However, N's less than
5 are pretty safe.
-- ALGLIB --
Copyright 30.09.2010 by Bochkanov Sergey
*************************************************************************/
</div><div style='margin-top: 0; margin-bottom: 0;'><b>void</b> alglib::polynomialpow2bar(
real_1d_array a,
barycentricinterpolant& p);
<b>void</b> alglib::polynomialpow2bar(
real_1d_array a,
ae_int_t n,
<b>double</b> c,
<b>double</b> s,
barycentricinterpolant& p);
</div></pre>
<p align=left class=pagecontent><span class=inlineheader>Examples:</span> <a href='#example_polint_d_conv' class=nav>[1]</a> </p>
<a name='example_polint_d_calcdiff'></a><h3 class=pageheader>polint_d_calcdiff example</h3>
<pre class=source>
#include <font color=blue><b>"stdafx.h"</b></font>
#include <stdlib.h>
#include <stdio.h>
#include <math.h>
#include <font color=blue><b>"interpolation.h"</b></font>
using namespace alglib;
<b>int</b> main(<b>int</b> argc, char **argv)
{
<font color=navy>//</font>
<font color=navy>// Here we demonstrate polynomial interpolation and differentiation</font>
<font color=navy>// of y=x^2-x sampled at [0,1,2]. Barycentric representation of polynomial is used.</font>
<font color=navy>//</font>
real_1d_array x = <font color=blue><b>"[0,1,2]"</b></font>;
real_1d_array y = <font color=blue><b>"[0,0,2]"</b></font>;
<b>double</b> t = -1;
<b>double</b> v;
<b>double</b> dv;
<b>double</b> d2v;
barycentricinterpolant p;
<font color=navy>// barycentric model is created</font>
polynomialbuild(x, y, p);
<font color=navy>// barycentric interpolation is demonstrated</font>
v = barycentriccalc(p, t);
printf(<font color=blue><b>"%.4f\n"</b></font>, <b>double</b>(v)); <font color=navy>// EXPECTED: 2.0</font>
<font color=navy>// barycentric differentation is demonstrated</font>
barycentricdiff1(p, t, v, dv);
printf(<font color=blue><b>"%.4f\n"</b></font>, <b>double</b>(v)); <font color=navy>// EXPECTED: 2.0</font>
printf(<font color=blue><b>"%.4f\n"</b></font>, <b>double</b>(dv)); <font color=navy>// EXPECTED: -3.0</font>
<font color=navy>// second derivatives with barycentric representation</font>
barycentricdiff1(p, t, v, dv);
printf(<font color=blue><b>"%.4f\n"</b></font>, <b>double</b>(v)); <font color=navy>// EXPECTED: 2.0</font>
printf(<font color=blue><b>"%.4f\n"</b></font>, <b>double</b>(dv)); <font color=navy>// EXPECTED: -3.0</font>
barycentricdiff2(p, t, v, dv, d2v);
printf(<font color=blue><b>"%.4f\n"</b></font>, <b>double</b>(v)); <font color=navy>// EXPECTED: 2.0</font>
printf(<font color=blue><b>"%.4f\n"</b></font>, <b>double</b>(dv)); <font color=navy>// EXPECTED: -3.0</font>
printf(<font color=blue><b>"%.4f\n"</b></font>, <b>double</b>(d2v)); <font color=navy>// EXPECTED: 2.0</font>
<b>return</b> 0;
}
</pre><a name='example_polint_d_conv'></a><h3 class=pageheader>polint_d_conv example</h3>
<pre class=source>
#include <font color=blue><b>"stdafx.h"</b></font>
#include <stdlib.h>
#include <stdio.h>
#include <math.h>
#include <font color=blue><b>"interpolation.h"</b></font>
using namespace alglib;
<b>int</b> main(<b>int</b> argc, char **argv)
{
<font color=navy>//</font>
<font color=navy>// Here we demonstrate conversion of y=x^2-x</font>
<font color=navy>// between power basis and barycentric representation.</font>
<font color=navy>//</font>
real_1d_array a = <font color=blue><b>"[0,-1,+1]"</b></font>;
<b>double</b> t = 2;
real_1d_array a2;
<b>double</b> v;
barycentricinterpolant p;
<font color=navy>//</font>
<font color=navy>// a=[0,-1,+1] is decomposition of y=x^2-x in the power basis:</font>
<font color=navy>//</font>
<font color=navy>// y = 0 - 1*x + 1*x^2</font>
<font color=navy>//</font>
<font color=navy>// We convert it to the barycentric form.</font>
<font color=navy>//</font>
polynomialpow2bar(a, p);
<font color=navy>// now we have barycentric interpolation; we can use it <b>for</b> interpolation</font>
v = barycentriccalc(p, t);
printf(<font color=blue><b>"%.2f\n"</b></font>, <b>double</b>(v)); <font color=navy>// EXPECTED: 2.0</font>
<font color=navy>// we can also convert back from barycentric representation to power basis</font>
polynomialbar2pow(p, a2);
printf(<font color=blue><b>"%s\n"</b></font>, a2.tostring(2).c_str()); <font color=navy>// EXPECTED: [0,-1,+1]</font>
<b>return</b> 0;
}
</pre><a name='example_polint_d_spec'></a><h3 class=pageheader>polint_d_spec example</h3>
<pre class=source>
#include <font color=blue><b>"stdafx.h"</b></font>
#include <stdlib.h>
#include <stdio.h>
#include <math.h>
#include <font color=blue><b>"interpolation.h"</b></font>
using namespace alglib;
<b>int</b> main(<b>int</b> argc, char **argv)
{
<font color=navy>//</font>
<font color=navy>// Temporaries:</font>
<font color=navy>// * values of y=x^2-x sampled at three special grids:</font>
<font color=navy>// * equdistant grid spanning [0,2], x[i] = 2*i/(N-1), i=0..N-1</font>
<font color=navy>// * Chebyshev-I grid spanning [-1,+1], x[i] = 1 + Cos(PI*(2*i+1)/(2*n)), i=0..N-1</font>
<font color=navy>// * Chebyshev-II grid spanning [-1,+1], x[i] = 1 + Cos(PI*i/(n-1)), i=0..N-1</font>
<font color=navy>// * barycentric interpolants <b>for</b> these three grids</font>
<font color=navy>// * vectors to store coefficients of quadratic representation</font>
<font color=navy>//</font>
real_1d_array y_eqdist = <font color=blue><b>"[0,0,2]"</b></font>;
real_1d_array y_cheb1 = <font color=blue><b>"[-0.116025,0.000000,1.616025]"</b></font>;
real_1d_array y_cheb2 = <font color=blue><b>"[0,0,2]"</b></font>;
barycentricinterpolant p_eqdist;
barycentricinterpolant p_cheb1;
barycentricinterpolant p_cheb2;
real_1d_array a_eqdist;
real_1d_array a_cheb1;
real_1d_array a_cheb2;
<font color=navy>//</font>
<font color=navy>// First, we demonstrate construction of barycentric interpolants on</font>
<font color=navy>// special grids. We unpack power representation to ensure that</font>
<font color=navy>// interpolant was built correctly.</font>
<font color=navy>//</font>
<font color=navy>// In all three cases we should get same quadratic function.</font>
<font color=navy>//</font>
polynomialbuildeqdist(0.0, 2.0, y_eqdist, p_eqdist);
polynomialbar2pow(p_eqdist, a_eqdist);
printf(<font color=blue><b>"%s\n"</b></font>, a_eqdist.tostring(4).c_str()); <font color=navy>// EXPECTED: [0,-1,+1]</font>
polynomialbuildcheb1(-1, +1, y_cheb1, p_cheb1);
polynomialbar2pow(p_cheb1, a_cheb1);
printf(<font color=blue><b>"%s\n"</b></font>, a_cheb1.tostring(4).c_str()); <font color=navy>// EXPECTED: [0,-1,+1]</font>
polynomialbuildcheb2(-1, +1, y_cheb2, p_cheb2);
polynomialbar2pow(p_cheb2, a_cheb2);
printf(<font color=blue><b>"%s\n"</b></font>, a_cheb2.tostring(4).c_str()); <font color=navy>// EXPECTED: [0,-1,+1]</font>
<font color=navy>//</font>
<font color=navy>// Now we demonstrate polynomial interpolation without construction </font>
<font color=navy>// of the barycentricinterpolant structure.</font>
<font color=navy>//</font>
<font color=navy>// We calculate interpolant value at x=-2.</font>
<font color=navy>// In all three cases we should get same f=6</font>
<font color=navy>//</font>
<b>double</b> t = -2;
<b>double</b> v;
v = polynomialcalceqdist(0.0, 2.0, y_eqdist, t);
printf(<font color=blue><b>"%.4f\n"</b></font>, <b>double</b>(v)); <font color=navy>// EXPECTED: 6.0</font>
v = polynomialcalccheb1(-1, +1, y_cheb1, t);
printf(<font color=blue><b>"%.4f\n"</b></font>, <b>double</b>(v)); <font color=navy>// EXPECTED: 6.0</font>
v = polynomialcalccheb2(-1, +1, y_cheb2, t);
printf(<font color=blue><b>"%.4f\n"</b></font>, <b>double</b>(v)); <font color=navy>// EXPECTED: 6.0</font>
<b>return</b> 0;
}
</pre><a name=unit_polynomialsolver></a><h2 class=pageheader><code>polynomialsolver</code> subpackage</h2>
<div class=pagecontent>
<h3 class=pageheader>Classes</h3>
<a href='#struct_polynomialsolverreport' class=toc>polynomialsolverreport</a><br>
<h3 class=pageheader>Functions</h3>
<a href='#sub_polynomialsolve' class=toc>polynomialsolve</a><br>
<h3 class=pageheader>Examples</h3>
<table border=0 cellspacing=0 class='pagecontent'>
</table></div>
<a name='struct_polynomialsolverreport'></a><h3 class=pageheader><code>polynomialsolverreport</code> class</h3>
<pre class=source>
<div style='color: navy; margin-top: 0; margin-bottom: 0;'>/*************************************************************************
*************************************************************************/
</div><div style='margin-top: 0; margin-bottom: 0;'><b>class</b> polynomialsolverreport
{
<b>double</b> maxerr;
};
</div></pre>
<a name='sub_polynomialsolve'></a><h3 class=pageheader><code>polynomialsolve</code> function</h3>
<pre class=source>
<div style='color: navy; margin-top: 0; margin-bottom: 0;'>/*************************************************************************
Polynomial root finding.
This function returns all roots of the polynomial
P(x) = a0 + a1*x + a2*x^2 + ... + an*x^n
Both real and complex roots are returned (see below).
INPUT PARAMETERS:
A - array[N+1], polynomial coefficients:
* A[0] is constant term
* A[N] is a coefficient of X^N
N - polynomial degree
OUTPUT PARAMETERS:
X - array of complex roots:
* for isolated real root, X[I] is strictly real: IMAGE(X[I])=0
* complex roots are always returned in pairs - roots occupy
positions I and I+1, with:
* X[I+1]=Conj(X[I])
* IMAGE(X[I]) > 0
* IMAGE(X[I+1]) = -IMAGE(X[I]) < 0
* multiple real roots may have non-zero imaginary part due
to roundoff errors. There is no reliable way to distinguish
real root of multiplicity 2 from two complex roots in
the presence of roundoff errors.
Rep - report, additional information, following fields are set:
* Rep.MaxErr - max( |P(xi)| ) for i=0..N-1. This field
allows to quickly estimate "quality" of the roots being
returned.
NOTE: this function uses companion matrix method to find roots. In case
internal EVD solver fails do find eigenvalues, exception is
generated.
NOTE: roots are not "polished" and no matrix balancing is performed
for them.
-- ALGLIB --
Copyright 24.02.2014 by Bochkanov Sergey
*************************************************************************/
</div><div style='margin-top: 0; margin-bottom: 0;'><b>void</b> alglib::polynomialsolve(
real_1d_array a,
ae_int_t n,
complex_1d_array& x,
polynomialsolverreport& rep);
</div></pre>
<a name=unit_psif></a><h2 class=pageheader><code>psif</code> subpackage</h2>
<div class=pagecontent>
<h3 class=pageheader>Functions</h3>
<a href='#sub_psi' class=toc>psi</a><br>
<h3 class=pageheader>Examples</h3>
<table border=0 cellspacing=0 class='pagecontent'>
</table></div>
<a name='sub_psi'></a><h3 class=pageheader><code>psi</code> function</h3>
<pre class=source>
<div style='color: navy; margin-top: 0; margin-bottom: 0;'>/*************************************************************************
Psi (digamma) function
d -
psi(x) = -- ln | (x)
dx
is the logarithmic derivative of the gamma function.
For integer x,
n-1
-
psi(n) = -EUL + > 1/k.
-
k=1
This formula is used for 0 < n <= 10. If x is negative, it
is transformed to a positive argument by the reflection
formula psi(1-x) = psi(x) + pi cot(pi x).
For general positive x, the argument is made greater than 10
using the recurrence psi(x+1) = psi(x) + 1/x.
Then the following asymptotic expansion is applied:
inf. B
- 2k
psi(x) = log(x) - 1/2x - > -------
- 2k
k=1 2k x
where the B2k are Bernoulli numbers.
ACCURACY:
Relative error (except absolute when |psi| < 1):
arithmetic domain # trials peak rms
IEEE 0,30 30000 1.3e-15 1.4e-16
IEEE -30,0 40000 1.5e-15 2.2e-16
Cephes Math Library Release 2.8: June, 2000
Copyright 1984, 1987, 1992, 2000 by Stephen L. Moshier
*************************************************************************/
</div><div style='margin-top: 0; margin-bottom: 0;'><b>double</b> alglib::psi(<b>double</b> x);
</div></pre>
<a name=unit_ratint></a><h2 class=pageheader><code>ratint</code> subpackage</h2>
<div class=pagecontent>
<h3 class=pageheader>Classes</h3>
<a href='#struct_barycentricinterpolant' class=toc>barycentricinterpolant</a><br>
<h3 class=pageheader>Functions</h3>
<a href='#sub_barycentricbuildfloaterhormann' class=toc>barycentricbuildfloaterhormann</a><br>
<a href='#sub_barycentricbuildxyw' class=toc>barycentricbuildxyw</a><br>
<a href='#sub_barycentriccalc' class=toc>barycentriccalc</a><br>
<a href='#sub_barycentricdiff1' class=toc>barycentricdiff1</a><br>
<a href='#sub_barycentricdiff2' class=toc>barycentricdiff2</a><br>
<a href='#sub_barycentriclintransx' class=toc>barycentriclintransx</a><br>
<a href='#sub_barycentriclintransy' class=toc>barycentriclintransy</a><br>
<a href='#sub_barycentricunpack' class=toc>barycentricunpack</a><br>
<h3 class=pageheader>Examples</h3>
<table border=0 cellspacing=0 class='pagecontent'>
</table></div>
<a name='struct_barycentricinterpolant'></a><h3 class=pageheader><code>barycentricinterpolant</code> class</h3>
<pre class=source>
<div style='color: navy; margin-top: 0; margin-bottom: 0;'>/*************************************************************************
Barycentric interpolant.
*************************************************************************/
</div><div style='margin-top: 0; margin-bottom: 0;'><b>class</b> barycentricinterpolant
{
};
</div></pre>
<a name='sub_barycentricbuildfloaterhormann'></a><h3 class=pageheader><code>barycentricbuildfloaterhormann</code> function</h3>
<pre class=source>
<div style='color: navy; margin-top: 0; margin-bottom: 0;'>/*************************************************************************
Rational interpolant without poles
The subroutine constructs the rational interpolating function without real
poles (see 'Barycentric rational interpolation with no poles and high
rates of approximation', Michael S. Floater. and Kai Hormann, for more
information on this subject).
Input parameters:
X - interpolation nodes, array[0..N-1].
Y - function values, array[0..N-1].
N - number of nodes, N>0.
D - order of the interpolation scheme, 0 <= D <= N-1.
D<0 will cause an error.
D>=N it will be replaced with D=N-1.
if you don't know what D to choose, use small value about 3-5.
Output parameters:
B - barycentric interpolant.
Note:
this algorithm always succeeds and calculates the weights with close
to machine precision.
-- ALGLIB PROJECT --
Copyright 17.06.2007 by Bochkanov Sergey
*************************************************************************/
</div><div style='margin-top: 0; margin-bottom: 0;'><b>void</b> alglib::barycentricbuildfloaterhormann(
real_1d_array x,
real_1d_array y,
ae_int_t n,
ae_int_t d,
barycentricinterpolant& b);
</div></pre>
<a name='sub_barycentricbuildxyw'></a><h3 class=pageheader><code>barycentricbuildxyw</code> function</h3>
<pre class=source>
<div style='color: navy; margin-top: 0; margin-bottom: 0;'>/*************************************************************************
Rational interpolant from X/Y/W arrays
F(t) = SUM(i=0,n-1,w[i]*f[i]/(t-x[i])) / SUM(i=0,n-1,w[i]/(t-x[i]))
INPUT PARAMETERS:
X - interpolation nodes, array[0..N-1]
F - function values, array[0..N-1]
W - barycentric weights, array[0..N-1]
N - nodes count, N>0
OUTPUT PARAMETERS:
B - barycentric interpolant built from (X, Y, W)
-- ALGLIB --
Copyright 17.08.2009 by Bochkanov Sergey
*************************************************************************/
</div><div style='margin-top: 0; margin-bottom: 0;'><b>void</b> alglib::barycentricbuildxyw(
real_1d_array x,
real_1d_array y,
real_1d_array w,
ae_int_t n,
barycentricinterpolant& b);
</div></pre>
<a name='sub_barycentriccalc'></a><h3 class=pageheader><code>barycentriccalc</code> function</h3>
<pre class=source>
<div style='color: navy; margin-top: 0; margin-bottom: 0;'>/*************************************************************************
Rational interpolation using barycentric formula
F(t) = SUM(i=0,n-1,w[i]*f[i]/(t-x[i])) / SUM(i=0,n-1,w[i]/(t-x[i]))
Input parameters:
B - barycentric interpolant built with one of model building
subroutines.
T - interpolation point
Result:
barycentric interpolant F(t)
-- ALGLIB --
Copyright 17.08.2009 by Bochkanov Sergey
*************************************************************************/
</div><div style='margin-top: 0; margin-bottom: 0;'><b>double</b> alglib::barycentriccalc(barycentricinterpolant b, <b>double</b> t);
</div></pre>
<a name='sub_barycentricdiff1'></a><h3 class=pageheader><code>barycentricdiff1</code> function</h3>
<pre class=source>
<div style='color: navy; margin-top: 0; margin-bottom: 0;'>/*************************************************************************
Differentiation of barycentric interpolant: first derivative.
Algorithm used in this subroutine is very robust and should not fail until
provided with values too close to MaxRealNumber (usually MaxRealNumber/N
or greater will overflow).
INPUT PARAMETERS:
B - barycentric interpolant built with one of model building
subroutines.
T - interpolation point
OUTPUT PARAMETERS:
F - barycentric interpolant at T
DF - first derivative
NOTE
-- ALGLIB --
Copyright 17.08.2009 by Bochkanov Sergey
*************************************************************************/
</div><div style='margin-top: 0; margin-bottom: 0;'><b>void</b> alglib::barycentricdiff1(
barycentricinterpolant b,
<b>double</b> t,
<b>double</b>& f,
<b>double</b>& df);
</div></pre>
<a name='sub_barycentricdiff2'></a><h3 class=pageheader><code>barycentricdiff2</code> function</h3>
<pre class=source>
<div style='color: navy; margin-top: 0; margin-bottom: 0;'>/*************************************************************************
Differentiation of barycentric interpolant: first/second derivatives.
INPUT PARAMETERS:
B - barycentric interpolant built with one of model building
subroutines.
T - interpolation point
OUTPUT PARAMETERS:
F - barycentric interpolant at T
DF - first derivative
D2F - second derivative
NOTE: this algorithm may fail due to overflow/underflor if used on data
whose values are close to MaxRealNumber or MinRealNumber. Use more robust
BarycentricDiff1() subroutine in such cases.
-- ALGLIB --
Copyright 17.08.2009 by Bochkanov Sergey
*************************************************************************/
</div><div style='margin-top: 0; margin-bottom: 0;'><b>void</b> alglib::barycentricdiff2(
barycentricinterpolant b,
<b>double</b> t,
<b>double</b>& f,
<b>double</b>& df,
<b>double</b>& d2f);
</div></pre>
<a name='sub_barycentriclintransx'></a><h3 class=pageheader><code>barycentriclintransx</code> function</h3>
<pre class=source>
<div style='color: navy; margin-top: 0; margin-bottom: 0;'>/*************************************************************************
This subroutine performs linear transformation of the argument.
INPUT PARAMETERS:
B - rational interpolant in barycentric form
CA, CB - transformation coefficients: x = CA*t + CB
OUTPUT PARAMETERS:
B - transformed interpolant with X replaced by T
-- ALGLIB PROJECT --
Copyright 19.08.2009 by Bochkanov Sergey
*************************************************************************/
</div><div style='margin-top: 0; margin-bottom: 0;'><b>void</b> alglib::barycentriclintransx(
barycentricinterpolant b,
<b>double</b> ca,
<b>double</b> cb);
</div></pre>
<a name='sub_barycentriclintransy'></a><h3 class=pageheader><code>barycentriclintransy</code> function</h3>
<pre class=source>
<div style='color: navy; margin-top: 0; margin-bottom: 0;'>/*************************************************************************
This subroutine performs linear transformation of the barycentric
interpolant.
INPUT PARAMETERS:
B - rational interpolant in barycentric form
CA, CB - transformation coefficients: B2(x) = CA*B(x) + CB
OUTPUT PARAMETERS:
B - transformed interpolant
-- ALGLIB PROJECT --
Copyright 19.08.2009 by Bochkanov Sergey
*************************************************************************/
</div><div style='margin-top: 0; margin-bottom: 0;'><b>void</b> alglib::barycentriclintransy(
barycentricinterpolant b,
<b>double</b> ca,
<b>double</b> cb);
</div></pre>
<a name='sub_barycentricunpack'></a><h3 class=pageheader><code>barycentricunpack</code> function</h3>
<pre class=source>
<div style='color: navy; margin-top: 0; margin-bottom: 0;'>/*************************************************************************
Extracts X/Y/W arrays from rational interpolant
INPUT PARAMETERS:
B - barycentric interpolant
OUTPUT PARAMETERS:
N - nodes count, N>0
X - interpolation nodes, array[0..N-1]
F - function values, array[0..N-1]
W - barycentric weights, array[0..N-1]
-- ALGLIB --
Copyright 17.08.2009 by Bochkanov Sergey
*************************************************************************/
</div><div style='margin-top: 0; margin-bottom: 0;'><b>void</b> alglib::barycentricunpack(
barycentricinterpolant b,
ae_int_t& n,
real_1d_array& x,
real_1d_array& y,
real_1d_array& w);
</div></pre>
<a name=unit_rbf></a><h2 class=pageheader><code>rbf</code> subpackage</h2>
<div class=pagecontent>
<h3 class=pageheader>Classes</h3>
<a href='#struct_rbfmodel' class=toc>rbfmodel</a><br>
<a href='#struct_rbfreport' class=toc>rbfreport</a><br>
<h3 class=pageheader>Functions</h3>
<a href='#sub_rbfbuildmodel' class=toc>rbfbuildmodel</a><br>
<a href='#sub_rbfcalc' class=toc>rbfcalc</a><br>
<a href='#sub_rbfcalc2' class=toc>rbfcalc2</a><br>
<a href='#sub_rbfcalc3' class=toc>rbfcalc3</a><br>
<a href='#sub_rbfcalcbuf' class=toc>rbfcalcbuf</a><br>
<a href='#sub_rbfcreate' class=toc>rbfcreate</a><br>
<a href='#sub_rbfgridcalc2' class=toc>rbfgridcalc2</a><br>
<a href='#sub_rbfserialize' class=toc>rbfserialize</a><br>
<a href='#sub_rbfsetalgomultilayer' class=toc>rbfsetalgomultilayer</a><br>
<a href='#sub_rbfsetalgoqnn' class=toc>rbfsetalgoqnn</a><br>
<a href='#sub_rbfsetconstterm' class=toc>rbfsetconstterm</a><br>
<a href='#sub_rbfsetlinterm' class=toc>rbfsetlinterm</a><br>
<a href='#sub_rbfsetpoints' class=toc>rbfsetpoints</a><br>
<a href='#sub_rbfsetzeroterm' class=toc>rbfsetzeroterm</a><br>
<a href='#sub_rbfunpack' class=toc>rbfunpack</a><br>
<a href='#sub_rbfunserialize' class=toc>rbfunserialize</a><br>
<h3 class=pageheader>Examples</h3>
<table border=0 cellspacing=0 class='pagecontent'>
<tr align=left valign=top><td><a href='#example_rbf_d_ml_ls' class=toc>rbf_d_ml_ls</a></td><td width=15> </td><td>Least squares problem solved with RBF-ML algorithm</td></tr>
<tr align=left valign=top><td><a href='#example_rbf_d_ml_simple' class=toc>rbf_d_ml_simple</a></td><td width=15> </td><td>Simple model built with RBF-ML algorithm</td></tr>
<tr align=left valign=top><td><a href='#example_rbf_d_polterm' class=toc>rbf_d_polterm</a></td><td width=15> </td><td>RBF models - working with polynomial term</td></tr>
<tr align=left valign=top><td><a href='#example_rbf_d_qnn' class=toc>rbf_d_qnn</a></td><td width=15> </td><td>Simple model built with RBF-QNN algorithm</td></tr>
<tr align=left valign=top><td><a href='#example_rbf_d_serialize' class=toc>rbf_d_serialize</a></td><td width=15> </td><td>Serialization/unserialization</td></tr>
<tr align=left valign=top><td><a href='#example_rbf_d_vector' class=toc>rbf_d_vector</a></td><td width=15> </td><td>Working with vector functions</td></tr>
</table></div>
<a name='struct_rbfmodel'></a><h3 class=pageheader><code>rbfmodel</code> class</h3>
<pre class=source>
<div style='color: navy; margin-top: 0; margin-bottom: 0;'>/*************************************************************************
RBF model.
Never try to directly work with fields of this object - always use ALGLIB
functions to use this object.
*************************************************************************/
</div><div style='margin-top: 0; margin-bottom: 0;'><b>class</b> rbfmodel
{
};
</div></pre>
<a name='struct_rbfreport'></a><h3 class=pageheader><code>rbfreport</code> class</h3>
<pre class=source>
<div style='color: navy; margin-top: 0; margin-bottom: 0;'>/*************************************************************************
RBF solution report:
* TerminationType - termination type, positive values - success,
non-positive - failure.
*************************************************************************/
</div><div style='margin-top: 0; margin-bottom: 0;'><b>class</b> rbfreport
{
ae_int_t arows;
ae_int_t acols;
ae_int_t annz;
ae_int_t iterationscount;
ae_int_t nmv;
ae_int_t terminationtype;
};
</div></pre>
<a name='sub_rbfbuildmodel'></a><h3 class=pageheader><code>rbfbuildmodel</code> function</h3>
<pre class=source>
<div style='color: navy; margin-top: 0; margin-bottom: 0;'>/*************************************************************************
This function builds RBF model and returns report (contains some
information which can be used for evaluation of the algorithm properties).
Call to this function modifies RBF model by calculating its centers/radii/
weights and saving them into RBFModel structure. Initially RBFModel
contain zero coefficients, but after call to this function we will have
coefficients which were calculated in order to fit our dataset.
After you called this function you can call RBFCalc(), RBFGridCalc() and
other model calculation functions.
INPUT PARAMETERS:
S - RBF model, initialized by RBFCreate() call
Rep - report:
* Rep.TerminationType:
* -5 - non-distinct basis function centers were detected,
interpolation aborted
* -4 - nonconvergence of the internal SVD solver
* 1 - successful termination
Fields are used for debugging purposes:
* Rep.IterationsCount - iterations count of the LSQR solver
* Rep.NMV - number of matrix-vector products
* Rep.ARows - rows count for the system matrix
* Rep.ACols - columns count for the system matrix
* Rep.ANNZ - number of significantly non-zero elements
(elements above some algorithm-determined threshold)
NOTE: failure to build model will leave current state of the structure
unchanged.
-- ALGLIB --
Copyright 13.12.2011 by Bochkanov Sergey
*************************************************************************/
</div><div style='margin-top: 0; margin-bottom: 0;'><b>void</b> alglib::rbfbuildmodel(rbfmodel s, rbfreport& rep);
</div></pre>
<p align=left class=pagecontent><span class=inlineheader>Examples:</span> <a href='#example_rbf_d_qnn' class=nav>[1]</a> <a href='#example_rbf_d_vector' class=nav>[2]</a> <a href='#example_rbf_d_polterm' class=nav>[3]</a> <a href='#example_rbf_d_ml_simple' class=nav>[4]</a> <a href='#example_rbf_d_ml_ls' class=nav>[5]</a> </p>
<a name='sub_rbfcalc'></a><h3 class=pageheader><code>rbfcalc</code> function</h3>
<pre class=source>
<div style='color: navy; margin-top: 0; margin-bottom: 0;'>/*************************************************************************
This function calculates values of the RBF model at the given point.
This is general function which can be used for arbitrary NX (dimension of
the space of arguments) and NY (dimension of the function itself). However
when you have NY=1 you may find more convenient to use RBFCalc2() or
RBFCalc3().
This function returns 0.0 when model is not initialized.
INPUT PARAMETERS:
S - RBF model
X - coordinates, array[NX].
X may have more than NX elements, in this case only
leading NX will be used.
OUTPUT PARAMETERS:
Y - function value, array[NY]. Y is out-parameter and
reallocated after call to this function. In case you want
to reuse previously allocated Y, you may use RBFCalcBuf(),
which reallocates Y only when it is too small.
-- ALGLIB --
Copyright 13.12.2011 by Bochkanov Sergey
*************************************************************************/
</div><div style='margin-top: 0; margin-bottom: 0;'><b>void</b> alglib::rbfcalc(rbfmodel s, real_1d_array x, real_1d_array& y);
</div></pre>
<p align=left class=pagecontent><span class=inlineheader>Examples:</span> <a href='#example_rbf_d_vector' class=nav>[1]</a> </p>
<a name='sub_rbfcalc2'></a><h3 class=pageheader><code>rbfcalc2</code> function</h3>
<pre class=source>
<div style='color: navy; margin-top: 0; margin-bottom: 0;'>/*************************************************************************
This function calculates values of the RBF model in the given point.
This function should be used when we have NY=1 (scalar function) and NX=2
(2-dimensional space). If you have 3-dimensional space, use RBFCalc3(). If
you have general situation (NX-dimensional space, NY-dimensional function)
you should use general, less efficient implementation RBFCalc().
If you want to calculate function values many times, consider using
RBFGridCalc2(), which is far more efficient than many subsequent calls to
RBFCalc2().
This function returns 0.0 when:
* model is not initialized
* NX<>2
*NY<>1
INPUT PARAMETERS:
S - RBF model
X0 - first coordinate, finite number
X1 - second coordinate, finite number
RESULT:
value of the model or 0.0 (as defined above)
-- ALGLIB --
Copyright 13.12.2011 by Bochkanov Sergey
*************************************************************************/
</div><div style='margin-top: 0; margin-bottom: 0;'><b>double</b> alglib::rbfcalc2(rbfmodel s, <b>double</b> x0, <b>double</b> x1);
</div></pre>
<p align=left class=pagecontent><span class=inlineheader>Examples:</span> <a href='#example_rbf_d_qnn' class=nav>[1]</a> <a href='#example_rbf_d_polterm' class=nav>[2]</a> <a href='#example_rbf_d_ml_simple' class=nav>[3]</a> <a href='#example_rbf_d_ml_ls' class=nav>[4]</a> </p>
<a name='sub_rbfcalc3'></a><h3 class=pageheader><code>rbfcalc3</code> function</h3>
<pre class=source>
<div style='color: navy; margin-top: 0; margin-bottom: 0;'>/*************************************************************************
This function calculates values of the RBF model in the given point.
This function should be used when we have NY=1 (scalar function) and NX=3
(3-dimensional space). If you have 2-dimensional space, use RBFCalc2(). If
you have general situation (NX-dimensional space, NY-dimensional function)
you should use general, less efficient implementation RBFCalc().
This function returns 0.0 when:
* model is not initialized
* NX<>3
*NY<>1
INPUT PARAMETERS:
S - RBF model
X0 - first coordinate, finite number
X1 - second coordinate, finite number
X2 - third coordinate, finite number
RESULT:
value of the model or 0.0 (as defined above)
-- ALGLIB --
Copyright 13.12.2011 by Bochkanov Sergey
*************************************************************************/
</div><div style='margin-top: 0; margin-bottom: 0;'><b>double</b> alglib::rbfcalc3(rbfmodel s, <b>double</b> x0, <b>double</b> x1, <b>double</b> x2);
</div></pre>
<a name='sub_rbfcalcbuf'></a><h3 class=pageheader><code>rbfcalcbuf</code> function</h3>
<pre class=source>
<div style='color: navy; margin-top: 0; margin-bottom: 0;'>/*************************************************************************
This function calculates values of the RBF model at the given point.
Same as RBFCalc(), but does not reallocate Y when in is large enough to
store function values.
INPUT PARAMETERS:
S - RBF model
X - coordinates, array[NX].
X may have more than NX elements, in this case only
leading NX will be used.
Y - possibly preallocated array
OUTPUT PARAMETERS:
Y - function value, array[NY]. Y is not reallocated when it
is larger than NY.
-- ALGLIB --
Copyright 13.12.2011 by Bochkanov Sergey
*************************************************************************/
</div><div style='margin-top: 0; margin-bottom: 0;'><b>void</b> alglib::rbfcalcbuf(rbfmodel s, real_1d_array x, real_1d_array& y);
</div></pre>
<a name='sub_rbfcreate'></a><h3 class=pageheader><code>rbfcreate</code> function</h3>
<pre class=source>
<div style='color: navy; margin-top: 0; margin-bottom: 0;'>/*************************************************************************
This function creates RBF model for a scalar (NY=1) or vector (NY>1)
function in a NX-dimensional space (NX=2 or NX=3).
Newly created model is empty. It can be used for interpolation right after
creation, but it just returns zeros. You have to add points to the model,
tune interpolation settings, and then call model construction function
RBFBuildModel() which will update model according to your specification.
USAGE:
1. User creates model with RBFCreate()
2. User adds dataset with RBFSetPoints() (points do NOT have to be on a
regular grid)
3. (OPTIONAL) User chooses polynomial term by calling:
* RBFLinTerm() to set linear term
* RBFConstTerm() to set constant term
* RBFZeroTerm() to set zero term
By default, linear term is used.
4. User chooses specific RBF algorithm to use: either QNN (RBFSetAlgoQNN)
or ML (RBFSetAlgoMultiLayer).
5. User calls RBFBuildModel() function which rebuilds model according to
the specification
6. User may call RBFCalc() to calculate model value at the specified point,
RBFGridCalc() to calculate model values at the points of the regular
grid. User may extract model coefficients with RBFUnpack() call.
INPUT PARAMETERS:
NX - dimension of the space, NX=2 or NX=3
NY - function dimension, NY>=1
OUTPUT PARAMETERS:
S - RBF model (initially equals to zero)
NOTE 1: memory requirements. RBF models require amount of memory which is
proportional to the number of data points. Memory is allocated
during model construction, but most of this memory is freed after
model coefficients are calculated.
Some approximate estimates for N centers with default settings are
given below:
* about 250*N*(sizeof(double)+2*sizeof(int)) bytes of memory is
needed during model construction stage.
* about 15*N*sizeof(double) bytes is needed after model is built.
For example, for N=100000 we may need 0.6 GB of memory to build
model, but just about 0.012 GB to store it.
-- ALGLIB --
Copyright 13.12.2011 by Bochkanov Sergey
*************************************************************************/
</div><div style='margin-top: 0; margin-bottom: 0;'><b>void</b> alglib::rbfcreate(ae_int_t nx, ae_int_t ny, rbfmodel& s);
</div></pre>
<p align=left class=pagecontent><span class=inlineheader>Examples:</span> <a href='#example_rbf_d_qnn' class=nav>[1]</a> <a href='#example_rbf_d_vector' class=nav>[2]</a> <a href='#example_rbf_d_polterm' class=nav>[3]</a> <a href='#example_rbf_d_serialize' class=nav>[4]</a> <a href='#example_rbf_d_ml_simple' class=nav>[5]</a> <a href='#example_rbf_d_ml_ls' class=nav>[6]</a> </p>
<a name='sub_rbfgridcalc2'></a><h3 class=pageheader><code>rbfgridcalc2</code> function</h3>
<pre class=source>
<div style='color: navy; margin-top: 0; margin-bottom: 0;'>/*************************************************************************
This function calculates values of the RBF model at the regular grid.
Grid have N0*N1 points, with Point[I,J] = (X0[I], X1[J])
This function returns 0.0 when:
* model is not initialized
* NX<>2
*NY<>1
INPUT PARAMETERS:
S - RBF model
X0 - array of grid nodes, first coordinates, array[N0]
N0 - grid size (number of nodes) in the first dimension
X1 - array of grid nodes, second coordinates, array[N1]
N1 - grid size (number of nodes) in the second dimension
OUTPUT PARAMETERS:
Y - function values, array[N0,N1]. Y is out-variable and
is reallocated by this function.
-- ALGLIB --
Copyright 13.12.2011 by Bochkanov Sergey
*************************************************************************/
</div><div style='margin-top: 0; margin-bottom: 0;'><b>void</b> alglib::rbfgridcalc2(
rbfmodel s,
real_1d_array x0,
ae_int_t n0,
real_1d_array x1,
ae_int_t n1,
real_2d_array& y);
</div></pre>
<a name='sub_rbfserialize'></a><h3 class=pageheader><code>rbfserialize</code> function</h3>
<pre class=source>
<div style='color: navy; margin-top: 0; margin-bottom: 0;'>/*************************************************************************
This function serializes data structure to string.
Important properties of s_out:
* it contains alphanumeric characters, dots, underscores, minus signs
* these symbols are grouped into words, which are separated by spaces
and Windows-style (CR+LF) newlines
* although serializer uses spaces and CR+LF as separators, you can
replace any separator character by arbitrary combination of spaces,
tabs, Windows or Unix newlines. It allows flexible reformatting of
the string in case you want to include it into text or XML file.
But you should not insert separators into the middle of the "words"
nor you should change case of letters.
* s_out can be freely moved between 32-bit and 64-bit systems, little
and big endian machines, and so on. You can serialize structure on
32-bit machine and unserialize it on 64-bit one (or vice versa), or
serialize it on SPARC and unserialize on x86. You can also
serialize it in C++ version of ALGLIB and unserialize in C# one,
and vice versa.
*************************************************************************/
</div><div style='margin-top: 0; margin-bottom: 0;'><b>void</b> rbfserialize(rbfmodel &obj, std::string &s_out);
</div></pre>
<a name='sub_rbfsetalgomultilayer'></a><h3 class=pageheader><code>rbfsetalgomultilayer</code> function</h3>
<pre class=source>
<div style='color: navy; margin-top: 0; margin-bottom: 0;'>/*************************************************************************
This function sets RBF interpolation algorithm. ALGLIB supports several
RBF algorithms with different properties.
This algorithm is called RBF-ML. It builds multilayer RBF model, i.e.
model with subsequently decreasing radii, which allows us to combine
smoothness (due to large radii of the first layers) with exactness (due
to small radii of the last layers) and fast convergence.
Internally RBF-ML uses many different means of acceleration, from sparse
matrices to KD-trees, which results in algorithm whose working time is
roughly proportional to N*log(N)*Density*RBase^2*NLayers, where N is a
number of points, Density is an average density if points per unit of the
interpolation space, RBase is an initial radius, NLayers is a number of
layers.
RBF-ML is good for following kinds of interpolation problems:
1. "exact" problems (perfect fit) with well separated points
2. least squares problems with arbitrary distribution of points (algorithm
gives perfect fit where it is possible, and resorts to least squares
fit in the hard areas).
3. noisy problems where we want to apply some controlled amount of
smoothing.
INPUT PARAMETERS:
S - RBF model, initialized by RBFCreate() call
RBase - RBase parameter, RBase>0
NLayers - NLayers parameter, NLayers>0, recommended value to start
with - about 5.
LambdaV - regularization value, can be useful when solving problem
in the least squares sense. Optimal lambda is problem-
dependent and require trial and error. In our experience,
good lambda can be as large as 0.1, and you can use 0.001
as initial guess.
Default value - 0.01, which is used when LambdaV is not
given. You can specify zero value, but it is not
recommended to do so.
TUNING ALGORITHM
In order to use this algorithm you have to choose three parameters:
* initial radius RBase
* number of layers in the model NLayers
* regularization coefficient LambdaV
Initial radius is easy to choose - you can pick any number several times
larger than the average distance between points. Algorithm won't break
down if you choose radius which is too large (model construction time will
increase, but model will be built correctly).
Choose such number of layers that RLast=RBase/2^(NLayers-1) (radius used
by the last layer) will be smaller than the typical distance between
points. In case model error is too large, you can increase number of
layers. Having more layers will make model construction and evaluation
proportionally slower, but it will allow you to have model which precisely
fits your data. From the other side, if you want to suppress noise, you
can DECREASE number of layers to make your model less flexible.
Regularization coefficient LambdaV controls smoothness of the individual
models built for each layer. We recommend you to use default value in case
you don't want to tune this parameter, because having non-zero LambdaV
accelerates and stabilizes internal iterative algorithm. In case you want
to suppress noise you can use LambdaV as additional parameter (larger
value = more smoothness) to tune.
TYPICAL ERRORS
1. Using initial radius which is too large. Memory requirements of the
RBF-ML are roughly proportional to N*Density*RBase^2 (where Density is
an average density of points per unit of the interpolation space). In
the extreme case of the very large RBase we will need O(N^2) units of
memory - and many layers in order to decrease radius to some reasonably
small value.
2. Using too small number of layers - RBF models with large radius are not
flexible enough to reproduce small variations in the target function.
You need many layers with different radii, from large to small, in
order to have good model.
3. Using initial radius which is too small. You will get model with
"holes" in the areas which are too far away from interpolation centers.
However, algorithm will work correctly (and quickly) in this case.
4. Using too many layers - you will get too large and too slow model. This
model will perfectly reproduce your function, but maybe you will be
able to achieve similar results with less layers (and less memory).
-- ALGLIB --
Copyright 02.03.2012 by Bochkanov Sergey
*************************************************************************/
</div><div style='margin-top: 0; margin-bottom: 0;'><b>void</b> alglib::rbfsetalgomultilayer(
rbfmodel s,
<b>double</b> rbase,
ae_int_t nlayers);
<b>void</b> alglib::rbfsetalgomultilayer(
rbfmodel s,
<b>double</b> rbase,
ae_int_t nlayers,
<b>double</b> lambdav);
</div></pre>
<p align=left class=pagecontent><span class=inlineheader>Examples:</span> <a href='#example_rbf_d_ml_simple' class=nav>[1]</a> <a href='#example_rbf_d_ml_ls' class=nav>[2]</a> </p>
<a name='sub_rbfsetalgoqnn'></a><h3 class=pageheader><code>rbfsetalgoqnn</code> function</h3>
<pre class=source>
<div style='color: navy; margin-top: 0; margin-bottom: 0;'>/*************************************************************************
This function sets RBF interpolation algorithm. ALGLIB supports several
RBF algorithms with different properties.
This algorithm is called RBF-QNN and it is good for point sets with
following properties:
a) all points are distinct
b) all points are well separated.
c) points distribution is approximately uniform. There is no "contour
lines", clusters of points, or other small-scale structures.
Algorithm description:
1) interpolation centers are allocated to data points
2) interpolation radii are calculated as distances to the nearest centers
times Q coefficient (where Q is a value from [0.75,1.50]).
3) after performing (2) radii are transformed in order to avoid situation
when single outlier has very large radius and influences many points
across all dataset. Transformation has following form:
new_r[i] = min(r[i],Z*median(r[]))
where r[i] is I-th radius, median() is a median radius across entire
dataset, Z is user-specified value which controls amount of deviation
from median radius.
When (a) is violated, we will be unable to build RBF model. When (b) or
(c) are violated, model will be built, but interpolation quality will be
low. See http://www.alglib.net/interpolation/ for more information on this
subject.
This algorithm is used by default.
Additional Q parameter controls smoothness properties of the RBF basis:
* Q<0.75 will give perfectly conditioned basis, but terrible smoothness
properties (RBF interpolant will have sharp peaks around function values)
* Q around 1.0 gives good balance between smoothness and condition number
* Q>1.5 will lead to badly conditioned systems and slow convergence of the
underlying linear solver (although smoothness will be very good)
* Q>2.0 will effectively make optimizer useless because it won't converge
within reasonable amount of iterations. It is possible to set such large
Q, but it is advised not to do so.
INPUT PARAMETERS:
S - RBF model, initialized by RBFCreate() call
Q - Q parameter, Q>0, recommended value - 1.0
Z - Z parameter, Z>0, recommended value - 5.0
NOTE: this function has some serialization-related subtleties. We
recommend you to study serialization examples from ALGLIB Reference
Manual if you want to perform serialization of your models.
-- ALGLIB --
Copyright 13.12.2011 by Bochkanov Sergey
*************************************************************************/
</div><div style='margin-top: 0; margin-bottom: 0;'><b>void</b> alglib::rbfsetalgoqnn(rbfmodel s);
<b>void</b> alglib::rbfsetalgoqnn(rbfmodel s, <b>double</b> q, <b>double</b> z);
</div></pre>
<p align=left class=pagecontent><span class=inlineheader>Examples:</span> <a href='#example_rbf_d_qnn' class=nav>[1]</a> <a href='#example_rbf_d_vector' class=nav>[2]</a> <a href='#example_rbf_d_polterm' class=nav>[3]</a> </p>
<a name='sub_rbfsetconstterm'></a><h3 class=pageheader><code>rbfsetconstterm</code> function</h3>
<pre class=source>
<div style='color: navy; margin-top: 0; margin-bottom: 0;'>/*************************************************************************
This function sets constant term (model is a sum of radial basis functions
plus constant). This function won't have effect until next call to
RBFBuildModel().
INPUT PARAMETERS:
S - RBF model, initialized by RBFCreate() call
NOTE: this function has some serialization-related subtleties. We
recommend you to study serialization examples from ALGLIB Reference
Manual if you want to perform serialization of your models.
-- ALGLIB --
Copyright 13.12.2011 by Bochkanov Sergey
*************************************************************************/
</div><div style='margin-top: 0; margin-bottom: 0;'><b>void</b> alglib::rbfsetconstterm(rbfmodel s);
</div></pre>
<p align=left class=pagecontent><span class=inlineheader>Examples:</span> <a href='#example_rbf_d_polterm' class=nav>[1]</a> </p>
<a name='sub_rbfsetlinterm'></a><h3 class=pageheader><code>rbfsetlinterm</code> function</h3>
<pre class=source>
<div style='color: navy; margin-top: 0; margin-bottom: 0;'>/*************************************************************************
This function sets linear term (model is a sum of radial basis functions
plus linear polynomial). This function won't have effect until next call
to RBFBuildModel().
INPUT PARAMETERS:
S - RBF model, initialized by RBFCreate() call
NOTE: this function has some serialization-related subtleties. We
recommend you to study serialization examples from ALGLIB Reference
Manual if you want to perform serialization of your models.
-- ALGLIB --
Copyright 13.12.2011 by Bochkanov Sergey
*************************************************************************/
</div><div style='margin-top: 0; margin-bottom: 0;'><b>void</b> alglib::rbfsetlinterm(rbfmodel s);
</div></pre>
<p align=left class=pagecontent><span class=inlineheader>Examples:</span> <a href='#example_rbf_d_polterm' class=nav>[1]</a> </p>
<a name='sub_rbfsetpoints'></a><h3 class=pageheader><code>rbfsetpoints</code> function</h3>
<pre class=source>
<div style='color: navy; margin-top: 0; margin-bottom: 0;'>/*************************************************************************
This function adds dataset.
This function overrides results of the previous calls, i.e. multiple calls
of this function will result in only the last set being added.
INPUT PARAMETERS:
S - RBF model, initialized by RBFCreate() call.
XY - points, array[N,NX+NY]. One row corresponds to one point
in the dataset. First NX elements are coordinates, next
NY elements are function values. Array may be larger than
specific, in this case only leading [N,NX+NY] elements
will be used.
N - number of points in the dataset
After you've added dataset and (optionally) tuned algorithm settings you
should call RBFBuildModel() in order to build a model for you.
NOTE: this function has some serialization-related subtleties. We
recommend you to study serialization examples from ALGLIB Reference
Manual if you want to perform serialization of your models.
-- ALGLIB --
Copyright 13.12.2011 by Bochkanov Sergey
*************************************************************************/
</div><div style='margin-top: 0; margin-bottom: 0;'><b>void</b> alglib::rbfsetpoints(rbfmodel s, real_2d_array xy);
<b>void</b> alglib::rbfsetpoints(rbfmodel s, real_2d_array xy, ae_int_t n);
</div></pre>
<p align=left class=pagecontent><span class=inlineheader>Examples:</span> <a href='#example_rbf_d_qnn' class=nav>[1]</a> <a href='#example_rbf_d_vector' class=nav>[2]</a> <a href='#example_rbf_d_polterm' class=nav>[3]</a> <a href='#example_rbf_d_ml_simple' class=nav>[4]</a> <a href='#example_rbf_d_ml_ls' class=nav>[5]</a> </p>
<a name='sub_rbfsetzeroterm'></a><h3 class=pageheader><code>rbfsetzeroterm</code> function</h3>
<pre class=source>
<div style='color: navy; margin-top: 0; margin-bottom: 0;'>/*************************************************************************
This function sets zero term (model is a sum of radial basis functions
without polynomial term). This function won't have effect until next call
to RBFBuildModel().
INPUT PARAMETERS:
S - RBF model, initialized by RBFCreate() call
NOTE: this function has some serialization-related subtleties. We
recommend you to study serialization examples from ALGLIB Reference
Manual if you want to perform serialization of your models.
-- ALGLIB --
Copyright 13.12.2011 by Bochkanov Sergey
*************************************************************************/
</div><div style='margin-top: 0; margin-bottom: 0;'><b>void</b> alglib::rbfsetzeroterm(rbfmodel s);
</div></pre>
<p align=left class=pagecontent><span class=inlineheader>Examples:</span> <a href='#example_rbf_d_polterm' class=nav>[1]</a> </p>
<a name='sub_rbfunpack'></a><h3 class=pageheader><code>rbfunpack</code> function</h3>
<pre class=source>
<div style='color: navy; margin-top: 0; margin-bottom: 0;'>/*************************************************************************
This function "unpacks" RBF model by extracting its coefficients.
INPUT PARAMETERS:
S - RBF model
OUTPUT PARAMETERS:
NX - dimensionality of argument
NY - dimensionality of the target function
XWR - model information, array[NC,NX+NY+1].
One row of the array corresponds to one basis function:
* first NX columns - coordinates of the center
* next NY columns - weights, one per dimension of the
function being modelled
* last column - radius, same for all dimensions of
the function being modelled
NC - number of the centers
V - polynomial term , array[NY,NX+1]. One row per one
dimension of the function being modelled. First NX
elements are linear coefficients, V[NX] is equal to the
constant part.
-- ALGLIB --
Copyright 13.12.2011 by Bochkanov Sergey
*************************************************************************/
</div><div style='margin-top: 0; margin-bottom: 0;'><b>void</b> alglib::rbfunpack(
rbfmodel s,
ae_int_t& nx,
ae_int_t& ny,
real_2d_array& xwr,
ae_int_t& nc,
real_2d_array& v);
</div></pre>
<p align=left class=pagecontent><span class=inlineheader>Examples:</span> <a href='#example_rbf_d_polterm' class=nav>[1]</a> </p>
<a name='sub_rbfunserialize'></a><h3 class=pageheader><code>rbfunserialize</code> function</h3>
<pre class=source>
<div style='color: navy; margin-top: 0; margin-bottom: 0;'>/*************************************************************************
This function unserializes data structure from string.
*************************************************************************/
</div><div style='margin-top: 0; margin-bottom: 0;'><b>void</b> rbfunserialize(std::string &s_in, rbfmodel &obj);
</div></pre>
<a name='example_rbf_d_ml_ls'></a><h3 class=pageheader>rbf_d_ml_ls example</h3>
<pre class=source>
#include <font color=blue><b>"stdafx.h"</b></font>
#include <stdlib.h>
#include <stdio.h>
#include <math.h>
#include <font color=blue><b>"interpolation.h"</b></font>
using namespace alglib;
<b>int</b> main(<b>int</b> argc, char **argv)
{
<font color=navy>//</font>
<font color=navy>// This example shows how to solve least squares problems with RBF-ML algorithm.</font>
<font color=navy>// Below we assume that you already know basic concepts shown in the RBF_D_QNN and</font>
<font color=navy>// RBF_D_ML_SIMPLE examples.</font>
<font color=navy>//</font>
rbfmodel model;
rbfreport rep;
<b>double</b> v;
<font color=navy>//</font>
<font color=navy>// We have 2-dimensional space and very simple fitting problem - all points</font>
<font color=navy>// except <b>for</b> two are well separated and located at straight line. Two</font>
<font color=navy>// <font color=blue><b>"exceptional"</b></font> points are very close, with distance between them as small</font>
<font color=navy>// as 0.01. RBF-QNN algorithm will have many difficulties with such distribution</font>
<font color=navy>// of points:</font>
<font color=navy>// X Y</font>
<font color=navy>// -2 1</font>
<font color=navy>// -1 0</font>
<font color=navy>// -0.005 1</font>
<font color=navy>// +0.005 2</font>
<font color=navy>// +1 -1</font>
<font color=navy>// +2 1</font>
<font color=navy>// How will RBF-ML handle such problem?</font>
<font color=navy>//</font>
rbfcreate(2, 1, model);
real_2d_array xy0 = <font color=blue><b>"[[-2,0,1],[-1,0,0],[-0.005,0,1],[+0.005,0,2],[+1,0,-1],[+2,0,1]]"</b></font>;
rbfsetpoints(model, xy0);
<font color=navy>// First, we try to use R=5.0 with single layer (NLayers=1) and moderate amount</font>
<font color=navy>// of regularization. Well, we already expected that results will be bad:</font>
<font color=navy>// Model(x=-2,y=0)=0.8407 (instead of 1.0)</font>
<font color=navy>// Model(x=0.005,y=0)=0.6584 (instead of 2.0)</font>
<font color=navy>// We need more layers to show better results.</font>
rbfsetalgomultilayer(model, 5.0, 1, 1.0e-3);
rbfbuildmodel(model, rep);
v = rbfcalc2(model, -2.0, 0.0);
printf(<font color=blue><b>"%.2f\n"</b></font>, <b>double</b>(v)); <font color=navy>// EXPECTED: 0.8407981659</font>
v = rbfcalc2(model, 0.005, 0.0);
printf(<font color=blue><b>"%.2f\n"</b></font>, <b>double</b>(v)); <font color=navy>// EXPECTED: 0.6584267649</font>
<font color=navy>// With 4 layers we got better result at x=-2 (point which is well separated</font>
<font color=navy>// from its neighbors). Model is now many times closer to the original data</font>
<font color=navy>// Model(x=-2,y=0)=0.9992 (instead of 1.0)</font>
<font color=navy>// Model(x=0.005,y=0)=1.5534 (instead of 2.0)</font>
<font color=navy>// We may see that at x=0.005 result is a bit closer to 2.0, but does not</font>
<font color=navy>// reproduce function value precisely because of close neighbor located at</font>
<font color=navy>// at x=-0.005. Let's add two layers...</font>
rbfsetalgomultilayer(model, 5.0, 4, 1.0e-3);
rbfbuildmodel(model, rep);
v = rbfcalc2(model, -2.0, 0.0);
printf(<font color=blue><b>"%.2f\n"</b></font>, <b>double</b>(v)); <font color=navy>// EXPECTED: 0.9992673278</font>
v = rbfcalc2(model, 0.005, 0.0);
printf(<font color=blue><b>"%.2f\n"</b></font>, <b>double</b>(v)); <font color=navy>// EXPECTED: 1.5534666012</font>
<font color=navy>// With 6 layers we got almost perfect fit:</font>
<font color=navy>// Model(x=-2,y=0)=1.000 (perfect fit)</font>
<font color=navy>// Model(x=0.005,y=0)=1.996 (instead of 2.0)</font>
<font color=navy>// Of course, we can reduce error at x=0.005 down to zero by adding more</font>
<font color=navy>// layers. But <b>do</b> we really need it?</font>
rbfsetalgomultilayer(model, 5.0, 6, 1.0e-3);
rbfbuildmodel(model, rep);
v = rbfcalc2(model, -2.0, 0.0);
printf(<font color=blue><b>"%.2f\n"</b></font>, <b>double</b>(v)); <font color=navy>// EXPECTED: 1.0000000000</font>
v = rbfcalc2(model, 0.005, 0.0);
printf(<font color=blue><b>"%.2f\n"</b></font>, <b>double</b>(v)); <font color=navy>// EXPECTED: 1.9965775952</font>
<font color=navy>// Do we really need zero error? We have f(+0.005)=2 and f(-0.005)=1.</font>
<font color=navy>// Two points are very close, and in real life situations it often means</font>
<font color=navy>// that difference in function values can be explained by noise in the</font>
<font color=navy>// data. Thus, true value of the underlying function should be close to</font>
<font color=navy>// 1.5 (halfway between 1.0 and 2.0).</font>
<font color=navy>//</font>
<font color=navy>// How can we get such result with RBF-ML? Well, we can:</font>
<font color=navy>// a) reduce number of layers (make model less flexible)</font>
<font color=navy>// b) increase regularization coefficient (another way of reducing flexibility)</font>
<font color=navy>//</font>
<font color=navy>// Having NLayers=5 and LambdaV=0.1 gives us good least squares fit to the data:</font>
<font color=navy>// Model(x=-2,y=0)=1.000</font>
<font color=navy>// Model(x=-0.005,y=0)=1.504</font>
<font color=navy>// Model(x=+0.005,y=0)=1.496</font>
rbfsetalgomultilayer(model, 5.0, 5, 1.0e-1);
rbfbuildmodel(model, rep);
v = rbfcalc2(model, -2.0, 0.0);
printf(<font color=blue><b>"%.2f\n"</b></font>, <b>double</b>(v)); <font color=navy>// EXPECTED: 1.0000001620</font>
v = rbfcalc2(model, -0.005, 0.0);
printf(<font color=blue><b>"%.2f\n"</b></font>, <b>double</b>(v)); <font color=navy>// EXPECTED: 1.5042954378</font>
v = rbfcalc2(model, 0.005, 0.0);
printf(<font color=blue><b>"%.2f\n"</b></font>, <b>double</b>(v)); <font color=navy>// EXPECTED: 1.4957042013</font>
<b>return</b> 0;
}
</pre><a name='example_rbf_d_ml_simple'></a><h3 class=pageheader>rbf_d_ml_simple example</h3>
<pre class=source>
#include <font color=blue><b>"stdafx.h"</b></font>
#include <stdlib.h>
#include <stdio.h>
#include <math.h>
#include <font color=blue><b>"interpolation.h"</b></font>
using namespace alglib;
<b>int</b> main(<b>int</b> argc, char **argv)
{
<font color=navy>//</font>
<font color=navy>// This example shows how to build models with RBF-ML algorithm. Below</font>
<font color=navy>// we assume that you already know basic concepts shown in the example</font>
<font color=navy>// on RBF-QNN algorithm.</font>
<font color=navy>//</font>
<font color=navy>// RBF-ML is a multilayer RBF algorithm, which fits a sequence of models</font>
<font color=navy>// with decreasing radii. Each model is fitted with fixed number of</font>
<font color=navy>// iterations of linear solver. First layers give only inexact approximation</font>
<font color=navy>// of the target function, because RBF problems with large radii are</font>
<font color=navy>// ill-conditioned. However, as we add more and more layers with smaller</font>
<font color=navy>// and smaller radii, we get better conditioned systems - and more precise models.</font>
<font color=navy>//</font>
rbfmodel model;
rbfreport rep;
<b>double</b> v;
<font color=navy>//</font>
<font color=navy>// We have 2-dimensional space and very simple interpolation problem - all</font>
<font color=navy>// points are distinct and located at straight line. We want to solve it</font>
<font color=navy>// with RBF-ML algorithm. This problem is very simple, and RBF-QNN will</font>
<font color=navy>// solve it too, but we want to evaluate RBF-ML and to start from the simple</font>
<font color=navy>// problem.</font>
<font color=navy>// X Y</font>
<font color=navy>// -2 1</font>
<font color=navy>// -1 0</font>
<font color=navy>// 0 1</font>
<font color=navy>// +1 -1</font>
<font color=navy>// +2 1</font>
<font color=navy>//</font>
rbfcreate(2, 1, model);
real_2d_array xy0 = <font color=blue><b>"[[-2,0,1],[-1,0,0],[0,0,1],[+1,0,-1],[+2,0,1]]"</b></font>;
rbfsetpoints(model, xy0);
<font color=navy>// First, we try to use R=5.0 with single layer (NLayers=1) and moderate amount</font>
<font color=navy>// of regularization.... but results are disappointing: Model(x=0,y=0)=-0.02,</font>
<font color=navy>// and we need 1.0 at (x,y)=(0,0). Why?</font>
<font color=navy>//</font>
<font color=navy>// Because first layer gives very smooth and imprecise approximation of the</font>
<font color=navy>// function. Average distance between points is 1.0, and R=5.0 is too large</font>
<font color=navy>// to give us flexible model. It can give smoothness, but can't give precision.</font>
<font color=navy>// So we need more layers with smaller radii.</font>
rbfsetalgomultilayer(model, 5.0, 1, 1.0e-3);
rbfbuildmodel(model, rep);
printf(<font color=blue><b>"%d\n"</b></font>, <b>int</b>(rep.terminationtype)); <font color=navy>// EXPECTED: 1</font>
v = rbfcalc2(model, 0.0, 0.0);
printf(<font color=blue><b>"%.2f\n"</b></font>, <b>double</b>(v)); <font color=navy>// EXPECTED: -0.021690</font>
<font color=navy>// Now we know that single layer is not enough. We still want to start with</font>
<font color=navy>// R=5.0 because it has good smoothness properties, but we will add more layers,</font>
<font color=navy>// each with R[i+1]=R[i]/2. We think that 4 layers is enough, because last layer</font>
<font color=navy>// will have R = 5.0/2^3 = 5/8 ~ 0.63, which is smaller than the average distance</font>
<font color=navy>// between points. And it works!</font>
rbfsetalgomultilayer(model, 5.0, 4, 1.0e-3);
rbfbuildmodel(model, rep);
printf(<font color=blue><b>"%d\n"</b></font>, <b>int</b>(rep.terminationtype)); <font color=navy>// EXPECTED: 1</font>
v = rbfcalc2(model, 0.0, 0.0);
printf(<font color=blue><b>"%.2f\n"</b></font>, <b>double</b>(v)); <font color=navy>// EXPECTED: 1.000000</font>
<font color=navy>// BTW, <b>if</b> you look at v, you will see that it is equal to 0.9999999997, not to 1.</font>
<font color=navy>// This small error can be fixed by adding one more layer.</font>
<b>return</b> 0;
}
</pre><a name='example_rbf_d_polterm'></a><h3 class=pageheader>rbf_d_polterm example</h3>
<pre class=source>
#include <font color=blue><b>"stdafx.h"</b></font>
#include <stdlib.h>
#include <stdio.h>
#include <math.h>
#include <font color=blue><b>"interpolation.h"</b></font>
using namespace alglib;
<b>int</b> main(<b>int</b> argc, char **argv)
{
<font color=navy>//</font>
<font color=navy>// This example show how to work with polynomial term</font>
<font color=navy>// </font>
<font color=navy>// Suppose that we have set of 2-dimensional points with associated</font>
<font color=navy>// scalar function values, and we want to build a RBF model using</font>
<font color=navy>// our data.</font>
<font color=navy>//</font>
<b>double</b> v;
rbfmodel model;
real_2d_array xy = <font color=blue><b>"[[-1,0,2],[+1,0,3]]"</b></font>;
rbfreport rep;
rbfcreate(2, 1, model);
rbfsetpoints(model, xy);
rbfsetalgoqnn(model);
<font color=navy>//</font>
<font color=navy>// By default, RBF model uses linear term. It means that model</font>
<font color=navy>// looks like</font>
<font color=navy>// f(x,y) = SUM(RBF[i]) + a*x + b*y + c</font>
<font color=navy>// where RBF[i] is I-th radial basis function and a*x+by+c is a</font>
<font color=navy>// linear term. Having linear terms in a model gives us:</font>
<font color=navy>// (1) improved extrapolation properties</font>
<font color=navy>// (2) linearity of the model when data can be perfectly fitted</font>
<font color=navy>// by the linear function</font>
<font color=navy>// (3) linear asymptotic behavior</font>
<font color=navy>//</font>
<font color=navy>// Our simple dataset can be modelled by the linear function</font>
<font color=navy>// f(x,y) = 0.5*x + 2.5</font>
<font color=navy>// and rbfbuildmodel() with default settings should preserve this</font>
<font color=navy>// linearity.</font>
<font color=navy>//</font>
ae_int_t nx;
ae_int_t ny;
ae_int_t nc;
real_2d_array xwr;
real_2d_array c;
rbfbuildmodel(model, rep);
printf(<font color=blue><b>"%d\n"</b></font>, <b>int</b>(rep.terminationtype)); <font color=navy>// EXPECTED: 1</font>
rbfunpack(model, nx, ny, xwr, nc, c);
printf(<font color=blue><b>"%s\n"</b></font>, c.tostring(2).c_str()); <font color=navy>// EXPECTED: [[0.500,0.000,2.500]]</font>
<font color=navy>// asymptotic behavior of our function is linear</font>
v = rbfcalc2(model, 1000.0, 0.0);
printf(<font color=blue><b>"%.1f\n"</b></font>, <b>double</b>(v)); <font color=navy>// EXPECTED: 502.50</font>
<font color=navy>//</font>
<font color=navy>// Instead of linear term we can use constant term. In this case</font>
<font color=navy>// we will get model which has form</font>
<font color=navy>// f(x,y) = SUM(RBF[i]) + c</font>
<font color=navy>// where RBF[i] is I-th radial basis function and c is a constant,</font>
<font color=navy>// which is equal to the average function value on the dataset.</font>
<font color=navy>//</font>
<font color=navy>// Because we've already attached dataset to the model the only</font>
<font color=navy>// thing we have to <b>do</b> is to call rbfsetconstterm() and then</font>
<font color=navy>// rebuild model with rbfbuildmodel().</font>
<font color=navy>//</font>
rbfsetconstterm(model);
rbfbuildmodel(model, rep);
printf(<font color=blue><b>"%d\n"</b></font>, <b>int</b>(rep.terminationtype)); <font color=navy>// EXPECTED: 1</font>
rbfunpack(model, nx, ny, xwr, nc, c);
printf(<font color=blue><b>"%s\n"</b></font>, c.tostring(2).c_str()); <font color=navy>// EXPECTED: [[0.000,0.000,2.500]]</font>
<font color=navy>// asymptotic behavior of our function is constant</font>
v = rbfcalc2(model, 1000.0, 0.0);
printf(<font color=blue><b>"%.2f\n"</b></font>, <b>double</b>(v)); <font color=navy>// EXPECTED: 2.500</font>
<font color=navy>//</font>
<font color=navy>// Finally, we can use zero term. Just plain RBF without polynomial</font>
<font color=navy>// part:</font>
<font color=navy>// f(x,y) = SUM(RBF[i])</font>
<font color=navy>// where RBF[i] is I-th radial basis function.</font>
<font color=navy>//</font>
rbfsetzeroterm(model);
rbfbuildmodel(model, rep);
printf(<font color=blue><b>"%d\n"</b></font>, <b>int</b>(rep.terminationtype)); <font color=navy>// EXPECTED: 1</font>
rbfunpack(model, nx, ny, xwr, nc, c);
printf(<font color=blue><b>"%s\n"</b></font>, c.tostring(2).c_str()); <font color=navy>// EXPECTED: [[0.000,0.000,0.000]]</font>
<font color=navy>// asymptotic behavior of our function is just zero constant</font>
v = rbfcalc2(model, 1000.0, 0.0);
printf(<font color=blue><b>"%.2f\n"</b></font>, <b>double</b>(v)); <font color=navy>// EXPECTED: 0.000</font>
<b>return</b> 0;
}
</pre><a name='example_rbf_d_qnn'></a><h3 class=pageheader>rbf_d_qnn example</h3>
<pre class=source>
#include <font color=blue><b>"stdafx.h"</b></font>
#include <stdlib.h>
#include <stdio.h>
#include <math.h>
#include <font color=blue><b>"interpolation.h"</b></font>
using namespace alglib;
<b>int</b> main(<b>int</b> argc, char **argv)
{
<font color=navy>//</font>
<font color=navy>// This example illustrates basic concepts of the RBF models: creation, modification,</font>
<font color=navy>// evaluation.</font>
<font color=navy>// </font>
<font color=navy>// Suppose that we have set of 2-dimensional points with associated</font>
<font color=navy>// scalar function values, and we want to build a RBF model using</font>
<font color=navy>// our data.</font>
<font color=navy>// </font>
<font color=navy>// NOTE: we can work with 3D models too :)</font>
<font color=navy>// </font>
<font color=navy>// Typical sequence of steps is given below:</font>
<font color=navy>// 1. we create RBF model object</font>
<font color=navy>// 2. we attach our dataset to the RBF model and tune algorithm settings</font>
<font color=navy>// 3. we rebuild RBF model using QNN algorithm on new data</font>
<font color=navy>// 4. we use RBF model (evaluate, serialize, etc.)</font>
<font color=navy>//</font>
<b>double</b> v;
<font color=navy>//</font>
<font color=navy>// Step 1: RBF model creation.</font>
<font color=navy>//</font>
<font color=navy>// We have to specify dimensionality of the space (2 or 3) and</font>
<font color=navy>// dimensionality of the function (scalar or vector).</font>
<font color=navy>//</font>
rbfmodel model;
rbfcreate(2, 1, model);
<font color=navy>// New model is empty - it can be evaluated,</font>
<font color=navy>// but we just get zero value at any point.</font>
v = rbfcalc2(model, 0.0, 0.0);
printf(<font color=blue><b>"%.2f\n"</b></font>, <b>double</b>(v)); <font color=navy>// EXPECTED: 0.000</font>
<font color=navy>//</font>
<font color=navy>// Step 2: we add dataset.</font>
<font color=navy>//</font>
<font color=navy>// XY arrays containt two points - x0=(-1,0) and x1=(+1,0) -</font>
<font color=navy>// and two function values f(x0)=2, f(x1)=3.</font>
<font color=navy>//</font>
real_2d_array xy = <font color=blue><b>"[[-1,0,2],[+1,0,3]]"</b></font>;
rbfsetpoints(model, xy);
<font color=navy>// We added points, but model was not rebuild yet.</font>
<font color=navy>// If we call rbfcalc2(), we still will get 0.0 as result.</font>
v = rbfcalc2(model, 0.0, 0.0);
printf(<font color=blue><b>"%.2f\n"</b></font>, <b>double</b>(v)); <font color=navy>// EXPECTED: 0.000</font>
<font color=navy>//</font>
<font color=navy>// Step 3: rebuild model</font>
<font color=navy>//</font>
<font color=navy>// After we've configured model, we should rebuild it -</font>
<font color=navy>// it will change coefficients stored internally in the</font>
<font color=navy>// rbfmodel structure.</font>
<font color=navy>//</font>
<font color=navy>// By default, RBF uses QNN algorithm, which works well with</font>
<font color=navy>// relatively uniform datasets (all points are well separated,</font>
<font color=navy>// average distance is approximately same <b>for</b> all points).</font>
<font color=navy>// This default algorithm is perfectly suited <b>for</b> our simple</font>
<font color=navy>// made up data.</font>
<font color=navy>//</font>
<font color=navy>// NOTE: we recommend you to take a look at example of RBF-ML,</font>
<font color=navy>// multilayer RBF algorithm, which sometimes is a better</font>
<font color=navy>// option than QNN.</font>
<font color=navy>//</font>
rbfreport rep;
rbfsetalgoqnn(model);
rbfbuildmodel(model, rep);
printf(<font color=blue><b>"%d\n"</b></font>, <b>int</b>(rep.terminationtype)); <font color=navy>// EXPECTED: 1</font>
<font color=navy>//</font>
<font color=navy>// Step 4: model was built</font>
<font color=navy>//</font>
<font color=navy>// After call of rbfbuildmodel(), rbfcalc2() will <b>return</b></font>
<font color=navy>// value of the new model.</font>
<font color=navy>//</font>
v = rbfcalc2(model, 0.0, 0.0);
printf(<font color=blue><b>"%.2f\n"</b></font>, <b>double</b>(v)); <font color=navy>// EXPECTED: 2.500</font>
<b>return</b> 0;
}
</pre><a name='example_rbf_d_serialize'></a><h3 class=pageheader>rbf_d_serialize example</h3>
<pre class=source>
#include <font color=blue><b>"stdafx.h"</b></font>
#include <stdlib.h>
#include <stdio.h>
#include <math.h>
#include <font color=blue><b>"interpolation.h"</b></font>
using namespace alglib;
<b>int</b> main(<b>int</b> argc, char **argv)
{
<font color=navy>//</font>
<font color=navy>// This example show how to serialize and unserialize RBF model</font>
<font color=navy>// </font>
<font color=navy>// Suppose that we have set of 2-dimensional points with associated</font>
<font color=navy>// scalar function values, and we want to build a RBF model using</font>
<font color=navy>// our data. Then we want to serialize it to string and to unserialize</font>
<font color=navy>// from string, loading to another instance of RBF model.</font>
<font color=navy>//</font>
<font color=navy>// Here we assume that you already know how to create RBF models.</font>
<font color=navy>//</font>
std::string s;
<b>double</b> v;
rbfmodel model0;
rbfmodel model1;
real_2d_array xy = <font color=blue><b>"[[-1,0,2],[+1,0,3]]"</b></font>;
rbfreport rep;
<font color=navy>// model initialization</font>
rbfcreate(2, 1, model0);
rbfsetpoints(model0, xy);
rbfsetalgoqnn(model0);
rbfbuildmodel(model0, rep);
printf(<font color=blue><b>"%d\n"</b></font>, <b>int</b>(rep.terminationtype)); <font color=navy>// EXPECTED: 1</font>
<font color=navy>//</font>
<font color=navy>// Serialization - it looks easy,</font>
<font color=navy>// but you should carefully read next section.</font>
<font color=navy>//</font>
alglib::rbfserialize(model0, s);
alglib::rbfunserialize(s, model1);
<font color=navy>// both models <b>return</b> same value</font>
v = rbfcalc2(model0, 0.0, 0.0);
printf(<font color=blue><b>"%.2f\n"</b></font>, <b>double</b>(v)); <font color=navy>// EXPECTED: 2.500</font>
v = rbfcalc2(model1, 0.0, 0.0);
printf(<font color=blue><b>"%.2f\n"</b></font>, <b>double</b>(v)); <font color=navy>// EXPECTED: 2.500</font>
<font color=navy>//</font>
<font color=navy>// Previous section shows that model state is saved/restored during</font>
<font color=navy>// serialization. However, some properties are NOT serialized.</font>
<font color=navy>//</font>
<font color=navy>// Serialization saves/restores RBF model, but it does NOT saves/restores</font>
<font color=navy>// settings which were used to build current model. In particular, dataset</font>
<font color=navy>// which were used to build model, is not preserved.</font>
<font color=navy>//</font>
<font color=navy>// What does it mean in <b>for</b> us?</font>
<font color=navy>//</font>
<font color=navy>// Do you remember this sequence: rbfcreate-rbfsetpoints-rbfbuildmodel?</font>
<font color=navy>// First step creates model, second step adds dataset and tunes model</font>
<font color=navy>// settings, third step builds model using current dataset and model</font>
<font color=navy>// construction settings.</font>
<font color=navy>//</font>
<font color=navy>// If you call rbfbuildmodel() without calling rbfsetpoints() first, you</font>
<font color=navy>// will get empty (zero) RBF model. In our example, model0 contains</font>
<font color=navy>// dataset which was added by rbfsetpoints() call. However, model1 does</font>
<font color=navy>// NOT contain dataset - because dataset is NOT serialized.</font>
<font color=navy>//</font>
<font color=navy>// This, <b>if</b> we call rbfbuildmodel(model0,rep), we will get same model,</font>
<font color=navy>// which returns 2.5 at (x,y)=(0,0). However, after same call model1 will</font>
<font color=navy>// <b>return</b> zero - because it contains RBF model (coefficients), but does NOT</font>
<font color=navy>// contain dataset which was used to build this model.</font>
<font color=navy>//</font>
<font color=navy>// Basically, it means that:</font>
<font color=navy>// * serialization of the RBF model preserves anything related to the model</font>
<font color=navy>// EVALUATION</font>
<font color=navy>// * but it does NOT creates perfect copy of the original object.</font>
<font color=navy>//</font>
rbfbuildmodel(model0, rep);
v = rbfcalc2(model0, 0.0, 0.0);
printf(<font color=blue><b>"%.2f\n"</b></font>, <b>double</b>(v)); <font color=navy>// EXPECTED: 2.500</font>
rbfbuildmodel(model1, rep);
v = rbfcalc2(model1, 0.0, 0.0);
printf(<font color=blue><b>"%.2f\n"</b></font>, <b>double</b>(v)); <font color=navy>// EXPECTED: 0.000</font>
<b>return</b> 0;
}
</pre><a name='example_rbf_d_vector'></a><h3 class=pageheader>rbf_d_vector example</h3>
<pre class=source>
#include <font color=blue><b>"stdafx.h"</b></font>
#include <stdlib.h>
#include <stdio.h>
#include <math.h>
#include <font color=blue><b>"interpolation.h"</b></font>
using namespace alglib;
<b>int</b> main(<b>int</b> argc, char **argv)
{
<font color=navy>//</font>
<font color=navy>// Suppose that we have set of 2-dimensional points with associated VECTOR</font>
<font color=navy>// function values, and we want to build a RBF model using our data.</font>
<font color=navy>// </font>
<font color=navy>// Typical sequence of steps is given below:</font>
<font color=navy>// 1. we create RBF model object</font>
<font color=navy>// 2. we attach our dataset to the RBF model and tune algorithm settings</font>
<font color=navy>// 3. we rebuild RBF model using new data</font>
<font color=navy>// 4. we use RBF model (evaluate, serialize, etc.)</font>
<font color=navy>//</font>
real_1d_array x;
real_1d_array y;
<font color=navy>//</font>
<font color=navy>// Step 1: RBF model creation.</font>
<font color=navy>//</font>
<font color=navy>// We have to specify dimensionality of the space (equal to 2) and</font>
<font color=navy>// dimensionality of the function (2-dimensional vector function).</font>
<font color=navy>//</font>
rbfmodel model;
rbfcreate(2, 2, model);
<font color=navy>// New model is empty - it can be evaluated,</font>
<font color=navy>// but we just get zero value at any point.</font>
x = <font color=blue><b>"[+1,+1]"</b></font>;
rbfcalc(model, x, y);
printf(<font color=blue><b>"%s\n"</b></font>, y.tostring(2).c_str()); <font color=navy>// EXPECTED: [0.000,0.000]</font>
<font color=navy>//</font>
<font color=navy>// Step 2: we add dataset.</font>
<font color=navy>//</font>
<font color=navy>// XY arrays containt four points:</font>
<font color=navy>// * (x0,y0) = (+1,+1), f(x0,y0)=(0,-1)</font>
<font color=navy>// * (x1,y1) = (+1,-1), f(x1,y1)=(-1,0)</font>
<font color=navy>// * (x2,y2) = (-1,-1), f(x2,y2)=(0,+1)</font>
<font color=navy>// * (x3,y3) = (-1,+1), f(x3,y3)=(+1,0)</font>
<font color=navy>//</font>
<font color=navy>// By default, RBF uses QNN algorithm, which works well with</font>
<font color=navy>// relatively uniform datasets (all points are well separated,</font>
<font color=navy>// average distance is approximately same <b>for</b> all points).</font>
<font color=navy>//</font>
<font color=navy>// This default algorithm is perfectly suited <b>for</b> our simple</font>
<font color=navy>// made up data.</font>
<font color=navy>//</font>
real_2d_array xy = <font color=blue><b>"[[+1,+1,0,-1],[+1,-1,-1,0],[-1,-1,0,+1],[-1,+1,+1,0]]"</b></font>;
rbfsetpoints(model, xy);
<font color=navy>// We added points, but model was not rebuild yet.</font>
<font color=navy>// If we call rbfcalc(), we still will get 0.0 as result.</font>
rbfcalc(model, x, y);
printf(<font color=blue><b>"%s\n"</b></font>, y.tostring(2).c_str()); <font color=navy>// EXPECTED: [0.000,0.000]</font>
<font color=navy>//</font>
<font color=navy>// Step 3: rebuild model</font>
<font color=navy>//</font>
<font color=navy>// After we've configured model, we should rebuild it -</font>
<font color=navy>// it will change coefficients stored internally in the</font>
<font color=navy>// rbfmodel structure.</font>
<font color=navy>//</font>
rbfreport rep;
rbfbuildmodel(model, rep);
printf(<font color=blue><b>"%d\n"</b></font>, <b>int</b>(rep.terminationtype)); <font color=navy>// EXPECTED: 1</font>
<font color=navy>//</font>
<font color=navy>// Step 4: model was built</font>
<font color=navy>//</font>
<font color=navy>// After call of rbfbuildmodel(), rbfcalc() will <b>return</b></font>
<font color=navy>// value of the new model.</font>
<font color=navy>//</font>
rbfcalc(model, x, y);
printf(<font color=blue><b>"%s\n"</b></font>, y.tostring(2).c_str()); <font color=navy>// EXPECTED: [0.000,-1.000]</font>
<b>return</b> 0;
}
</pre><a name=unit_rcond></a><h2 class=pageheader><code>rcond</code> subpackage</h2>
<div class=pagecontent>
<h3 class=pageheader>Functions</h3>
<a href='#sub_cmatrixlurcond1' class=toc>cmatrixlurcond1</a><br>
<a href='#sub_cmatrixlurcondinf' class=toc>cmatrixlurcondinf</a><br>
<a href='#sub_cmatrixrcond1' class=toc>cmatrixrcond1</a><br>
<a href='#sub_cmatrixrcondinf' class=toc>cmatrixrcondinf</a><br>
<a href='#sub_cmatrixtrrcond1' class=toc>cmatrixtrrcond1</a><br>
<a href='#sub_cmatrixtrrcondinf' class=toc>cmatrixtrrcondinf</a><br>
<a href='#sub_hpdmatrixcholeskyrcond' class=toc>hpdmatrixcholeskyrcond</a><br>
<a href='#sub_hpdmatrixrcond' class=toc>hpdmatrixrcond</a><br>
<a href='#sub_rmatrixlurcond1' class=toc>rmatrixlurcond1</a><br>
<a href='#sub_rmatrixlurcondinf' class=toc>rmatrixlurcondinf</a><br>
<a href='#sub_rmatrixrcond1' class=toc>rmatrixrcond1</a><br>
<a href='#sub_rmatrixrcondinf' class=toc>rmatrixrcondinf</a><br>
<a href='#sub_rmatrixtrrcond1' class=toc>rmatrixtrrcond1</a><br>
<a href='#sub_rmatrixtrrcondinf' class=toc>rmatrixtrrcondinf</a><br>
<a href='#sub_spdmatrixcholeskyrcond' class=toc>spdmatrixcholeskyrcond</a><br>
<a href='#sub_spdmatrixrcond' class=toc>spdmatrixrcond</a><br>
<h3 class=pageheader>Examples</h3>
<table border=0 cellspacing=0 class='pagecontent'>
</table></div>
<a name='sub_cmatrixlurcond1'></a><h3 class=pageheader><code>cmatrixlurcond1</code> function</h3>
<pre class=source>
<div style='color: navy; margin-top: 0; margin-bottom: 0;'>/*************************************************************************
Estimate of the condition number of a matrix given by its LU decomposition (1-norm)
The algorithm calculates a lower bound of the condition number. In this case,
the algorithm does not return a lower bound of the condition number, but an
inverse number (to avoid an overflow in case of a singular matrix).
Input parameters:
LUA - LU decomposition of a matrix in compact form. Output of
the CMatrixLU subroutine.
N - size of matrix A.
Result: 1/LowerBound(cond(A))
NOTE:
if k(A) is very large, then matrix is assumed degenerate, k(A)=INF,
0.0 is returned in such cases.
*************************************************************************/
</div><div style='margin-top: 0; margin-bottom: 0;'><b>double</b> alglib::cmatrixlurcond1(complex_2d_array lua, ae_int_t n);
</div></pre>
<a name='sub_cmatrixlurcondinf'></a><h3 class=pageheader><code>cmatrixlurcondinf</code> function</h3>
<pre class=source>
<div style='color: navy; margin-top: 0; margin-bottom: 0;'>/*************************************************************************
Estimate of the condition number of a matrix given by its LU decomposition
(infinity norm).
The algorithm calculates a lower bound of the condition number. In this case,
the algorithm does not return a lower bound of the condition number, but an
inverse number (to avoid an overflow in case of a singular matrix).
Input parameters:
LUA - LU decomposition of a matrix in compact form. Output of
the CMatrixLU subroutine.
N - size of matrix A.
Result: 1/LowerBound(cond(A))
NOTE:
if k(A) is very large, then matrix is assumed degenerate, k(A)=INF,
0.0 is returned in such cases.
*************************************************************************/
</div><div style='margin-top: 0; margin-bottom: 0;'><b>double</b> alglib::cmatrixlurcondinf(complex_2d_array lua, ae_int_t n);
</div></pre>
<a name='sub_cmatrixrcond1'></a><h3 class=pageheader><code>cmatrixrcond1</code> function</h3>
<pre class=source>
<div style='color: navy; margin-top: 0; margin-bottom: 0;'>/*************************************************************************
Estimate of a matrix condition number (1-norm)
The algorithm calculates a lower bound of the condition number. In this case,
the algorithm does not return a lower bound of the condition number, but an
inverse number (to avoid an overflow in case of a singular matrix).
Input parameters:
A - matrix. Array whose indexes range within [0..N-1, 0..N-1].
N - size of matrix A.
Result: 1/LowerBound(cond(A))
NOTE:
if k(A) is very large, then matrix is assumed degenerate, k(A)=INF,
0.0 is returned in such cases.
*************************************************************************/
</div><div style='margin-top: 0; margin-bottom: 0;'><b>double</b> alglib::cmatrixrcond1(complex_2d_array a, ae_int_t n);
</div></pre>
<a name='sub_cmatrixrcondinf'></a><h3 class=pageheader><code>cmatrixrcondinf</code> function</h3>
<pre class=source>
<div style='color: navy; margin-top: 0; margin-bottom: 0;'>/*************************************************************************
Estimate of a matrix condition number (infinity-norm).
The algorithm calculates a lower bound of the condition number. In this case,
the algorithm does not return a lower bound of the condition number, but an
inverse number (to avoid an overflow in case of a singular matrix).
Input parameters:
A - matrix. Array whose indexes range within [0..N-1, 0..N-1].
N - size of matrix A.
Result: 1/LowerBound(cond(A))
NOTE:
if k(A) is very large, then matrix is assumed degenerate, k(A)=INF,
0.0 is returned in such cases.
*************************************************************************/
</div><div style='margin-top: 0; margin-bottom: 0;'><b>double</b> alglib::cmatrixrcondinf(complex_2d_array a, ae_int_t n);
</div></pre>
<a name='sub_cmatrixtrrcond1'></a><h3 class=pageheader><code>cmatrixtrrcond1</code> function</h3>
<pre class=source>
<div style='color: navy; margin-top: 0; margin-bottom: 0;'>/*************************************************************************
Triangular matrix: estimate of a condition number (1-norm)
The algorithm calculates a lower bound of the condition number. In this case,
the algorithm does not return a lower bound of the condition number, but an
inverse number (to avoid an overflow in case of a singular matrix).
Input parameters:
A - matrix. Array[0..N-1, 0..N-1].
N - size of A.
IsUpper - True, if the matrix is upper triangular.
IsUnit - True, if the matrix has a unit diagonal.
Result: 1/LowerBound(cond(A))
NOTE:
if k(A) is very large, then matrix is assumed degenerate, k(A)=INF,
0.0 is returned in such cases.
*************************************************************************/
</div><div style='margin-top: 0; margin-bottom: 0;'><b>double</b> alglib::cmatrixtrrcond1(
complex_2d_array a,
ae_int_t n,
<b>bool</b> isupper,
<b>bool</b> isunit);
</div></pre>
<a name='sub_cmatrixtrrcondinf'></a><h3 class=pageheader><code>cmatrixtrrcondinf</code> function</h3>
<pre class=source>
<div style='color: navy; margin-top: 0; margin-bottom: 0;'>/*************************************************************************
Triangular matrix: estimate of a matrix condition number (infinity-norm).
The algorithm calculates a lower bound of the condition number. In this case,
the algorithm does not return a lower bound of the condition number, but an
inverse number (to avoid an overflow in case of a singular matrix).
Input parameters:
A - matrix. Array whose indexes range within [0..N-1, 0..N-1].
N - size of matrix A.
IsUpper - True, if the matrix is upper triangular.
IsUnit - True, if the matrix has a unit diagonal.
Result: 1/LowerBound(cond(A))
NOTE:
if k(A) is very large, then matrix is assumed degenerate, k(A)=INF,
0.0 is returned in such cases.
*************************************************************************/
</div><div style='margin-top: 0; margin-bottom: 0;'><b>double</b> alglib::cmatrixtrrcondinf(
complex_2d_array a,
ae_int_t n,
<b>bool</b> isupper,
<b>bool</b> isunit);
</div></pre>
<a name='sub_hpdmatrixcholeskyrcond'></a><h3 class=pageheader><code>hpdmatrixcholeskyrcond</code> function</h3>
<pre class=source>
<div style='color: navy; margin-top: 0; margin-bottom: 0;'>/*************************************************************************
Condition number estimate of a Hermitian positive definite matrix given by
Cholesky decomposition.
The algorithm calculates a lower bound of the condition number. In this
case, the algorithm does not return a lower bound of the condition number,
but an inverse number (to avoid an overflow in case of a singular matrix).
It should be noted that 1-norm and inf-norm condition numbers of symmetric
matrices are equal, so the algorithm doesn't take into account the
differences between these types of norms.
Input parameters:
CD - Cholesky decomposition of matrix A,
output of SMatrixCholesky subroutine.
N - size of matrix A.
Result: 1/LowerBound(cond(A))
NOTE:
if k(A) is very large, then matrix is assumed degenerate, k(A)=INF,
0.0 is returned in such cases.
*************************************************************************/
</div><div style='margin-top: 0; margin-bottom: 0;'><b>double</b> alglib::hpdmatrixcholeskyrcond(
complex_2d_array a,
ae_int_t n,
<b>bool</b> isupper);
</div></pre>
<a name='sub_hpdmatrixrcond'></a><h3 class=pageheader><code>hpdmatrixrcond</code> function</h3>
<pre class=source>
<div style='color: navy; margin-top: 0; margin-bottom: 0;'>/*************************************************************************
Condition number estimate of a Hermitian positive definite matrix.
The algorithm calculates a lower bound of the condition number. In this case,
the algorithm does not return a lower bound of the condition number, but an
inverse number (to avoid an overflow in case of a singular matrix).
It should be noted that 1-norm and inf-norm of condition numbers of symmetric
matrices are equal, so the algorithm doesn't take into account the
differences between these types of norms.
Input parameters:
A - Hermitian positive definite matrix which is given by its
upper or lower triangle depending on the value of
IsUpper. Array with elements [0..N-1, 0..N-1].
N - size of matrix A.
IsUpper - storage format.
Result:
1/LowerBound(cond(A)), if matrix A is positive definite,
-1, if matrix A is not positive definite, and its condition number
could not be found by this algorithm.
NOTE:
if k(A) is very large, then matrix is assumed degenerate, k(A)=INF,
0.0 is returned in such cases.
*************************************************************************/
</div><div style='margin-top: 0; margin-bottom: 0;'><b>double</b> alglib::hpdmatrixrcond(
complex_2d_array a,
ae_int_t n,
<b>bool</b> isupper);
</div></pre>
<a name='sub_rmatrixlurcond1'></a><h3 class=pageheader><code>rmatrixlurcond1</code> function</h3>
<pre class=source>
<div style='color: navy; margin-top: 0; margin-bottom: 0;'>/*************************************************************************
Estimate of the condition number of a matrix given by its LU decomposition (1-norm)
The algorithm calculates a lower bound of the condition number. In this case,
the algorithm does not return a lower bound of the condition number, but an
inverse number (to avoid an overflow in case of a singular matrix).
Input parameters:
LUA - LU decomposition of a matrix in compact form. Output of
the RMatrixLU subroutine.
N - size of matrix A.
Result: 1/LowerBound(cond(A))
NOTE:
if k(A) is very large, then matrix is assumed degenerate, k(A)=INF,
0.0 is returned in such cases.
*************************************************************************/
</div><div style='margin-top: 0; margin-bottom: 0;'><b>double</b> alglib::rmatrixlurcond1(real_2d_array lua, ae_int_t n);
</div></pre>
<a name='sub_rmatrixlurcondinf'></a><h3 class=pageheader><code>rmatrixlurcondinf</code> function</h3>
<pre class=source>
<div style='color: navy; margin-top: 0; margin-bottom: 0;'>/*************************************************************************
Estimate of the condition number of a matrix given by its LU decomposition
(infinity norm).
The algorithm calculates a lower bound of the condition number. In this case,
the algorithm does not return a lower bound of the condition number, but an
inverse number (to avoid an overflow in case of a singular matrix).
Input parameters:
LUA - LU decomposition of a matrix in compact form. Output of
the RMatrixLU subroutine.
N - size of matrix A.
Result: 1/LowerBound(cond(A))
NOTE:
if k(A) is very large, then matrix is assumed degenerate, k(A)=INF,
0.0 is returned in such cases.
*************************************************************************/
</div><div style='margin-top: 0; margin-bottom: 0;'><b>double</b> alglib::rmatrixlurcondinf(real_2d_array lua, ae_int_t n);
</div></pre>
<a name='sub_rmatrixrcond1'></a><h3 class=pageheader><code>rmatrixrcond1</code> function</h3>
<pre class=source>
<div style='color: navy; margin-top: 0; margin-bottom: 0;'>/*************************************************************************
Estimate of a matrix condition number (1-norm)
The algorithm calculates a lower bound of the condition number. In this case,
the algorithm does not return a lower bound of the condition number, but an
inverse number (to avoid an overflow in case of a singular matrix).
Input parameters:
A - matrix. Array whose indexes range within [0..N-1, 0..N-1].
N - size of matrix A.
Result: 1/LowerBound(cond(A))
NOTE:
if k(A) is very large, then matrix is assumed degenerate, k(A)=INF,
0.0 is returned in such cases.
*************************************************************************/
</div><div style='margin-top: 0; margin-bottom: 0;'><b>double</b> alglib::rmatrixrcond1(real_2d_array a, ae_int_t n);
</div></pre>
<a name='sub_rmatrixrcondinf'></a><h3 class=pageheader><code>rmatrixrcondinf</code> function</h3>
<pre class=source>
<div style='color: navy; margin-top: 0; margin-bottom: 0;'>/*************************************************************************
Estimate of a matrix condition number (infinity-norm).
The algorithm calculates a lower bound of the condition number. In this case,
the algorithm does not return a lower bound of the condition number, but an
inverse number (to avoid an overflow in case of a singular matrix).
Input parameters:
A - matrix. Array whose indexes range within [0..N-1, 0..N-1].
N - size of matrix A.
Result: 1/LowerBound(cond(A))
NOTE:
if k(A) is very large, then matrix is assumed degenerate, k(A)=INF,
0.0 is returned in such cases.
*************************************************************************/
</div><div style='margin-top: 0; margin-bottom: 0;'><b>double</b> alglib::rmatrixrcondinf(real_2d_array a, ae_int_t n);
</div></pre>
<a name='sub_rmatrixtrrcond1'></a><h3 class=pageheader><code>rmatrixtrrcond1</code> function</h3>
<pre class=source>
<div style='color: navy; margin-top: 0; margin-bottom: 0;'>/*************************************************************************
Triangular matrix: estimate of a condition number (1-norm)
The algorithm calculates a lower bound of the condition number. In this case,
the algorithm does not return a lower bound of the condition number, but an
inverse number (to avoid an overflow in case of a singular matrix).
Input parameters:
A - matrix. Array[0..N-1, 0..N-1].
N - size of A.
IsUpper - True, if the matrix is upper triangular.
IsUnit - True, if the matrix has a unit diagonal.
Result: 1/LowerBound(cond(A))
NOTE:
if k(A) is very large, then matrix is assumed degenerate, k(A)=INF,
0.0 is returned in such cases.
*************************************************************************/
</div><div style='margin-top: 0; margin-bottom: 0;'><b>double</b> alglib::rmatrixtrrcond1(
real_2d_array a,
ae_int_t n,
<b>bool</b> isupper,
<b>bool</b> isunit);
</div></pre>
<a name='sub_rmatrixtrrcondinf'></a><h3 class=pageheader><code>rmatrixtrrcondinf</code> function</h3>
<pre class=source>
<div style='color: navy; margin-top: 0; margin-bottom: 0;'>/*************************************************************************
Triangular matrix: estimate of a matrix condition number (infinity-norm).
The algorithm calculates a lower bound of the condition number. In this case,
the algorithm does not return a lower bound of the condition number, but an
inverse number (to avoid an overflow in case of a singular matrix).
Input parameters:
A - matrix. Array whose indexes range within [0..N-1, 0..N-1].
N - size of matrix A.
IsUpper - True, if the matrix is upper triangular.
IsUnit - True, if the matrix has a unit diagonal.
Result: 1/LowerBound(cond(A))
NOTE:
if k(A) is very large, then matrix is assumed degenerate, k(A)=INF,
0.0 is returned in such cases.
*************************************************************************/
</div><div style='margin-top: 0; margin-bottom: 0;'><b>double</b> alglib::rmatrixtrrcondinf(
real_2d_array a,
ae_int_t n,
<b>bool</b> isupper,
<b>bool</b> isunit);
</div></pre>
<a name='sub_spdmatrixcholeskyrcond'></a><h3 class=pageheader><code>spdmatrixcholeskyrcond</code> function</h3>
<pre class=source>
<div style='color: navy; margin-top: 0; margin-bottom: 0;'>/*************************************************************************
Condition number estimate of a symmetric positive definite matrix given by
Cholesky decomposition.
The algorithm calculates a lower bound of the condition number. In this
case, the algorithm does not return a lower bound of the condition number,
but an inverse number (to avoid an overflow in case of a singular matrix).
It should be noted that 1-norm and inf-norm condition numbers of symmetric
matrices are equal, so the algorithm doesn't take into account the
differences between these types of norms.
Input parameters:
CD - Cholesky decomposition of matrix A,
output of SMatrixCholesky subroutine.
N - size of matrix A.
Result: 1/LowerBound(cond(A))
NOTE:
if k(A) is very large, then matrix is assumed degenerate, k(A)=INF,
0.0 is returned in such cases.
*************************************************************************/
</div><div style='margin-top: 0; margin-bottom: 0;'><b>double</b> alglib::spdmatrixcholeskyrcond(
real_2d_array a,
ae_int_t n,
<b>bool</b> isupper);
</div></pre>
<a name='sub_spdmatrixrcond'></a><h3 class=pageheader><code>spdmatrixrcond</code> function</h3>
<pre class=source>
<div style='color: navy; margin-top: 0; margin-bottom: 0;'>/*************************************************************************
Condition number estimate of a symmetric positive definite matrix.
The algorithm calculates a lower bound of the condition number. In this case,
the algorithm does not return a lower bound of the condition number, but an
inverse number (to avoid an overflow in case of a singular matrix).
It should be noted that 1-norm and inf-norm of condition numbers of symmetric
matrices are equal, so the algorithm doesn't take into account the
differences between these types of norms.
Input parameters:
A - symmetric positive definite matrix which is given by its
upper or lower triangle depending on the value of
IsUpper. Array with elements [0..N-1, 0..N-1].
N - size of matrix A.
IsUpper - storage format.
Result:
1/LowerBound(cond(A)), if matrix A is positive definite,
-1, if matrix A is not positive definite, and its condition number
could not be found by this algorithm.
NOTE:
if k(A) is very large, then matrix is assumed degenerate, k(A)=INF,
0.0 is returned in such cases.
*************************************************************************/
</div><div style='margin-top: 0; margin-bottom: 0;'><b>double</b> alglib::spdmatrixrcond(real_2d_array a, ae_int_t n, <b>bool</b> isupper);
</div></pre>
<a name=unit_schur></a><h2 class=pageheader><code>schur</code> subpackage</h2>
<div class=pagecontent>
<h3 class=pageheader>Functions</h3>
<a href='#sub_rmatrixschur' class=toc>rmatrixschur</a><br>
<h3 class=pageheader>Examples</h3>
<table border=0 cellspacing=0 class='pagecontent'>
</table></div>
<a name='sub_rmatrixschur'></a><h3 class=pageheader><code>rmatrixschur</code> function</h3>
<pre class=source>
<div style='color: navy; margin-top: 0; margin-bottom: 0;'>/*************************************************************************
Subroutine performing the Schur decomposition of a general matrix by using
the QR algorithm with multiple shifts.
COMMERCIAL EDITION OF ALGLIB:
! Commercial version of ALGLIB includes one important improvement of
! this function, which can be used from C++ and C#:
! * Intel MKL support (lightweight Intel MKL is shipped with ALGLIB)
!
! Intel MKL gives approximately constant (with respect to number of
! worker threads) acceleration factor which depends on CPU being used,
! problem size and "baseline" ALGLIB edition which is used for
! comparison.
!
! Multithreaded acceleration is NOT supported for this function.
!
! We recommend you to read 'Working with commercial version' section of
! ALGLIB Reference Manual in order to find out how to use performance-
! related features provided by commercial edition of ALGLIB.
The source matrix A is represented as S'*A*S = T, where S is an orthogonal
matrix (Schur vectors), T - upper quasi-triangular matrix (with blocks of
sizes 1x1 and 2x2 on the main diagonal).
Input parameters:
A - matrix to be decomposed.
Array whose indexes range within [0..N-1, 0..N-1].
N - size of A, N>=0.
Output parameters:
A - contains matrix T.
Array whose indexes range within [0..N-1, 0..N-1].
S - contains Schur vectors.
Array whose indexes range within [0..N-1, 0..N-1].
Note 1:
The block structure of matrix T can be easily recognized: since all
the elements below the blocks are zeros, the elements a[i+1,i] which
are equal to 0 show the block border.
Note 2:
The algorithm performance depends on the value of the internal parameter
NS of the InternalSchurDecomposition subroutine which defines the number
of shifts in the QR algorithm (similarly to the block width in block-matrix
algorithms in linear algebra). If you require maximum performance on
your machine, it is recommended to adjust this parameter manually.
Result:
True,
if the algorithm has converged and parameters A and S contain the result.
False,
if the algorithm has not converged.
Algorithm implemented on the basis of the DHSEQR subroutine (LAPACK 3.0 library).
*************************************************************************/
</div><div style='margin-top: 0; margin-bottom: 0;'><b>bool</b> alglib::rmatrixschur(real_2d_array& a, ae_int_t n, real_2d_array& s);
</div></pre>
<a name=unit_sparse></a><h2 class=pageheader><code>sparse</code> subpackage</h2>
<div class=pagecontent>
<h3 class=pageheader>Classes</h3>
<a href='#struct_sparsebuffers' class=toc>sparsebuffers</a><br>
<a href='#struct_sparsematrix' class=toc>sparsematrix</a><br>
<h3 class=pageheader>Functions</h3>
<a href='#sub_sparseadd' class=toc>sparseadd</a><br>
<a href='#sub_sparseconvertto' class=toc>sparseconvertto</a><br>
<a href='#sub_sparseconverttocrs' class=toc>sparseconverttocrs</a><br>
<a href='#sub_sparseconverttohash' class=toc>sparseconverttohash</a><br>
<a href='#sub_sparseconverttosks' class=toc>sparseconverttosks</a><br>
<a href='#sub_sparsecopy' class=toc>sparsecopy</a><br>
<a href='#sub_sparsecopybuf' class=toc>sparsecopybuf</a><br>
<a href='#sub_sparsecopytobuf' class=toc>sparsecopytobuf</a><br>
<a href='#sub_sparsecopytocrs' class=toc>sparsecopytocrs</a><br>
<a href='#sub_sparsecopytocrsbuf' class=toc>sparsecopytocrsbuf</a><br>
<a href='#sub_sparsecopytohash' class=toc>sparsecopytohash</a><br>
<a href='#sub_sparsecopytohashbuf' class=toc>sparsecopytohashbuf</a><br>
<a href='#sub_sparsecopytosks' class=toc>sparsecopytosks</a><br>
<a href='#sub_sparsecopytosksbuf' class=toc>sparsecopytosksbuf</a><br>
<a href='#sub_sparsecreate' class=toc>sparsecreate</a><br>
<a href='#sub_sparsecreatebuf' class=toc>sparsecreatebuf</a><br>
<a href='#sub_sparsecreatecrs' class=toc>sparsecreatecrs</a><br>
<a href='#sub_sparsecreatecrsbuf' class=toc>sparsecreatecrsbuf</a><br>
<a href='#sub_sparsecreatesks' class=toc>sparsecreatesks</a><br>
<a href='#sub_sparsecreatesksbuf' class=toc>sparsecreatesksbuf</a><br>
<a href='#sub_sparseenumerate' class=toc>sparseenumerate</a><br>
<a href='#sub_sparsefree' class=toc>sparsefree</a><br>
<a href='#sub_sparseget' class=toc>sparseget</a><br>
<a href='#sub_sparsegetcompressedrow' class=toc>sparsegetcompressedrow</a><br>
<a href='#sub_sparsegetdiagonal' class=toc>sparsegetdiagonal</a><br>
<a href='#sub_sparsegetlowercount' class=toc>sparsegetlowercount</a><br>
<a href='#sub_sparsegetmatrixtype' class=toc>sparsegetmatrixtype</a><br>
<a href='#sub_sparsegetncols' class=toc>sparsegetncols</a><br>
<a href='#sub_sparsegetnrows' class=toc>sparsegetnrows</a><br>
<a href='#sub_sparsegetrow' class=toc>sparsegetrow</a><br>
<a href='#sub_sparsegetuppercount' class=toc>sparsegetuppercount</a><br>
<a href='#sub_sparseiscrs' class=toc>sparseiscrs</a><br>
<a href='#sub_sparseishash' class=toc>sparseishash</a><br>
<a href='#sub_sparseissks' class=toc>sparseissks</a><br>
<a href='#sub_sparsemm' class=toc>sparsemm</a><br>
<a href='#sub_sparsemm2' class=toc>sparsemm2</a><br>
<a href='#sub_sparsemtm' class=toc>sparsemtm</a><br>
<a href='#sub_sparsemtv' class=toc>sparsemtv</a><br>
<a href='#sub_sparsemv' class=toc>sparsemv</a><br>
<a href='#sub_sparsemv2' class=toc>sparsemv2</a><br>
<a href='#sub_sparseresizematrix' class=toc>sparseresizematrix</a><br>
<a href='#sub_sparserewriteexisting' class=toc>sparserewriteexisting</a><br>
<a href='#sub_sparseset' class=toc>sparseset</a><br>
<a href='#sub_sparsesmm' class=toc>sparsesmm</a><br>
<a href='#sub_sparsesmv' class=toc>sparsesmv</a><br>
<a href='#sub_sparseswap' class=toc>sparseswap</a><br>
<a href='#sub_sparsetransposesks' class=toc>sparsetransposesks</a><br>
<a href='#sub_sparsetrmv' class=toc>sparsetrmv</a><br>
<a href='#sub_sparsetrsv' class=toc>sparsetrsv</a><br>
<a href='#sub_sparsevsmv' class=toc>sparsevsmv</a><br>
<h3 class=pageheader>Examples</h3>
<table border=0 cellspacing=0 class='pagecontent'>
<tr align=left valign=top><td><a href='#example_sparse_d_1' class=toc>sparse_d_1</a></td><td width=15> </td><td>Basic operations with sparse matrices</td></tr>
<tr align=left valign=top><td><a href='#example_sparse_d_crs' class=toc>sparse_d_crs</a></td><td width=15> </td><td>Advanced topic: creation in the CRS format.</td></tr>
</table></div>
<a name='struct_sparsebuffers'></a><h3 class=pageheader><code>sparsebuffers</code> class</h3>
<pre class=source>
<div style='color: navy; margin-top: 0; margin-bottom: 0;'>/*************************************************************************
Temporary buffers for sparse matrix operations.
You should pass an instance of this structure to factorization functions.
It allows to reuse memory during repeated sparse factorizations. You do
not have to call some initialization function - simply passing an instance
to factorization function is enough.
*************************************************************************/
</div><div style='margin-top: 0; margin-bottom: 0;'><b>class</b> sparsebuffers
{
};
</div></pre>
<a name='struct_sparsematrix'></a><h3 class=pageheader><code>sparsematrix</code> class</h3>
<pre class=source>
<div style='color: navy; margin-top: 0; margin-bottom: 0;'>/*************************************************************************
Sparse matrix structure.
You should use ALGLIB functions to work with sparse matrix. Never try to
access its fields directly!
NOTES ON THE SPARSE STORAGE FORMATS
Sparse matrices can be stored using several formats:
* Hash-Table representation
* Compressed Row Storage (CRS)
* Skyline matrix storage (SKS)
Each of the formats has benefits and drawbacks:
* Hash-table is good for dynamic operations (insertion of new elements),
but does not support linear algebra operations
* CRS is good for operations like matrix-vector or matrix-matrix products,
but its initialization is less convenient - you have to tell row sizes
at the initialization, and you have to fill matrix only row by row,
from left to right.
* SKS is a special format which is used to store triangular factors from
Cholesky factorization. It does not support dynamic modification, and
support for linear algebra operations is very limited.
Tables below outline information about these two formats:
OPERATIONS WITH MATRIX HASH CRS SKS
creation + + +
SparseGet + + +
SparseRewriteExisting + + +
SparseSet +
SparseAdd +
SparseGetRow + +
SparseGetCompressedRow + +
sparse-dense linear algebra + +
*************************************************************************/
</div><div style='margin-top: 0; margin-bottom: 0;'><b>class</b> sparsematrix
{
};
</div></pre>
<a name='sub_sparseadd'></a><h3 class=pageheader><code>sparseadd</code> function</h3>
<pre class=source>
<div style='color: navy; margin-top: 0; margin-bottom: 0;'>/*************************************************************************
This function adds value to S[i,j] - element of the sparse matrix. Matrix
must be in a Hash-Table mode.
In case S[i,j] already exists in the table, V i added to its value. In
case S[i,j] is non-existent, it is inserted in the table. Table
automatically grows when necessary.
INPUT PARAMETERS
S - sparse M*N matrix in Hash-Table representation.
Exception will be thrown for CRS matrix.
I - row index of the element to modify, 0<=I<M
J - column index of the element to modify, 0<=J<N
V - value to add, must be finite number
OUTPUT PARAMETERS
S - modified matrix
NOTE 1: when S[i,j] is exactly zero after modification, it is deleted
from the table.
-- ALGLIB PROJECT --
Copyright 14.10.2011 by Bochkanov Sergey
*************************************************************************/
</div><div style='margin-top: 0; margin-bottom: 0;'><b>void</b> alglib::sparseadd(sparsematrix s, ae_int_t i, ae_int_t j, <b>double</b> v);
</div></pre>
<p align=left class=pagecontent><span class=inlineheader>Examples:</span> <a href='#example_sparse_d_1' class=nav>[1]</a> </p>
<a name='sub_sparseconvertto'></a><h3 class=pageheader><code>sparseconvertto</code> function</h3>
<pre class=source>
<div style='color: navy; margin-top: 0; margin-bottom: 0;'>/*************************************************************************
This function performs in-place conversion to desired sparse storage
format.
INPUT PARAMETERS
S0 - sparse matrix in any format.
Fmt - desired storage format of the output, as returned by
SparseGetMatrixType() function:
* 0 for hash-based storage
* 1 for CRS
* 2 for SKS
OUTPUT PARAMETERS
S0 - sparse matrix in requested format.
NOTE: in-place conversion wastes a lot of memory which is used to store
temporaries. If you perform a lot of repeated conversions, we
recommend to use out-of-place buffered conversion functions, like
SparseCopyToBuf(), which can reuse already allocated memory.
-- ALGLIB PROJECT --
Copyright 16.01.2014 by Bochkanov Sergey
*************************************************************************/
</div><div style='margin-top: 0; margin-bottom: 0;'><b>void</b> alglib::sparseconvertto(sparsematrix s0, ae_int_t fmt);
</div></pre>
<a name='sub_sparseconverttocrs'></a><h3 class=pageheader><code>sparseconverttocrs</code> function</h3>
<pre class=source>
<div style='color: navy; margin-top: 0; margin-bottom: 0;'>/*************************************************************************
This function converts matrix to CRS format.
Some algorithms (linear algebra ones, for example) require matrices in
CRS format. This function allows to perform in-place conversion.
INPUT PARAMETERS
S - sparse M*N matrix in any format
OUTPUT PARAMETERS
S - matrix in CRS format
NOTE: this function has no effect when called with matrix which is
already in CRS mode.
NOTE: this function allocates temporary memory to store a copy of the
matrix. If you perform a lot of repeated conversions, we recommend
you to use SparseCopyToCRSBuf() function, which can reuse
previously allocated memory.
-- ALGLIB PROJECT --
Copyright 14.10.2011 by Bochkanov Sergey
*************************************************************************/
</div><div style='margin-top: 0; margin-bottom: 0;'><b>void</b> alglib::sparseconverttocrs(sparsematrix s);
</div></pre>
<p align=left class=pagecontent><span class=inlineheader>Examples:</span> <a href='#example_sparse_d_1' class=nav>[1]</a> </p>
<a name='sub_sparseconverttohash'></a><h3 class=pageheader><code>sparseconverttohash</code> function</h3>
<pre class=source>
<div style='color: navy; margin-top: 0; margin-bottom: 0;'>/*************************************************************************
This function performs in-place conversion to Hash table storage.
INPUT PARAMETERS
S - sparse matrix in CRS format.
OUTPUT PARAMETERS
S - sparse matrix in Hash table format.
NOTE: this function has no effect when called with matrix which is
already in Hash table mode.
NOTE: in-place conversion involves allocation of temporary arrays. If you
perform a lot of repeated in- place conversions, it may lead to
memory fragmentation. Consider using out-of-place SparseCopyToHashBuf()
function in this case.
-- ALGLIB PROJECT --
Copyright 20.07.2012 by Bochkanov Sergey
*************************************************************************/
</div><div style='margin-top: 0; margin-bottom: 0;'><b>void</b> alglib::sparseconverttohash(sparsematrix s);
</div></pre>
<a name='sub_sparseconverttosks'></a><h3 class=pageheader><code>sparseconverttosks</code> function</h3>
<pre class=source>
<div style='color: navy; margin-top: 0; margin-bottom: 0;'>/*************************************************************************
This function performs in-place conversion to SKS format.
INPUT PARAMETERS
S - sparse matrix in any format.
OUTPUT PARAMETERS
S - sparse matrix in SKS format.
NOTE: this function has no effect when called with matrix which is
already in SKS mode.
NOTE: in-place conversion involves allocation of temporary arrays. If you
perform a lot of repeated in- place conversions, it may lead to
memory fragmentation. Consider using out-of-place SparseCopyToSKSBuf()
function in this case.
-- ALGLIB PROJECT --
Copyright 15.01.2014 by Bochkanov Sergey
*************************************************************************/
</div><div style='margin-top: 0; margin-bottom: 0;'><b>void</b> alglib::sparseconverttosks(sparsematrix s);
</div></pre>
<a name='sub_sparsecopy'></a><h3 class=pageheader><code>sparsecopy</code> function</h3>
<pre class=source>
<div style='color: navy; margin-top: 0; margin-bottom: 0;'>/*************************************************************************
This function copies S0 to S1.
This function completely deallocates memory owned by S1 before creating a
copy of S0. If you want to reuse memory, use SparseCopyBuf.
NOTE: this function does not verify its arguments, it just copies all
fields of the structure.
-- ALGLIB PROJECT --
Copyright 14.10.2011 by Bochkanov Sergey
*************************************************************************/
</div><div style='margin-top: 0; margin-bottom: 0;'><b>void</b> alglib::sparsecopy(sparsematrix s0, sparsematrix& s1);
</div></pre>
<a name='sub_sparsecopybuf'></a><h3 class=pageheader><code>sparsecopybuf</code> function</h3>
<pre class=source>
<div style='color: navy; margin-top: 0; margin-bottom: 0;'>/*************************************************************************
This function copies S0 to S1.
Memory already allocated in S1 is reused as much as possible.
NOTE: this function does not verify its arguments, it just copies all
fields of the structure.
-- ALGLIB PROJECT --
Copyright 14.10.2011 by Bochkanov Sergey
*************************************************************************/
</div><div style='margin-top: 0; margin-bottom: 0;'><b>void</b> alglib::sparsecopybuf(sparsematrix s0, sparsematrix s1);
</div></pre>
<a name='sub_sparsecopytobuf'></a><h3 class=pageheader><code>sparsecopytobuf</code> function</h3>
<pre class=source>
<div style='color: navy; margin-top: 0; margin-bottom: 0;'>/*************************************************************************
This function performs out-of-place conversion to desired sparse storage
format. S0 is copied to S1 and converted on-the-fly. Memory allocated in
S1 is reused to maximum extent possible.
INPUT PARAMETERS
S0 - sparse matrix in any format.
Fmt - desired storage format of the output, as returned by
SparseGetMatrixType() function:
* 0 for hash-based storage
* 1 for CRS
* 2 for SKS
OUTPUT PARAMETERS
S1 - sparse matrix in requested format.
-- ALGLIB PROJECT --
Copyright 16.01.2014 by Bochkanov Sergey
*************************************************************************/
</div><div style='margin-top: 0; margin-bottom: 0;'><b>void</b> alglib::sparsecopytobuf(
sparsematrix s0,
ae_int_t fmt,
sparsematrix s1);
</div></pre>
<a name='sub_sparsecopytocrs'></a><h3 class=pageheader><code>sparsecopytocrs</code> function</h3>
<pre class=source>
<div style='color: navy; margin-top: 0; margin-bottom: 0;'>/*************************************************************************
This function performs out-of-place conversion to CRS format. S0 is
copied to S1 and converted on-the-fly.
INPUT PARAMETERS
S0 - sparse matrix in any format.
OUTPUT PARAMETERS
S1 - sparse matrix in CRS format.
NOTE: if S0 is stored as CRS, it is just copied without conversion.
NOTE: this function de-allocates memory occupied by S1 before starting CRS
conversion. If you perform a lot of repeated CRS conversions, it may
lead to memory fragmentation. In this case we recommend you to use
SparseCopyToCRSBuf() function which re-uses memory in S1 as much as
possible.
-- ALGLIB PROJECT --
Copyright 20.07.2012 by Bochkanov Sergey
*************************************************************************/
</div><div style='margin-top: 0; margin-bottom: 0;'><b>void</b> alglib::sparsecopytocrs(sparsematrix s0, sparsematrix& s1);
</div></pre>
<a name='sub_sparsecopytocrsbuf'></a><h3 class=pageheader><code>sparsecopytocrsbuf</code> function</h3>
<pre class=source>
<div style='color: navy; margin-top: 0; margin-bottom: 0;'>/*************************************************************************
This function performs out-of-place conversion to CRS format. S0 is
copied to S1 and converted on-the-fly. Memory allocated in S1 is reused to
maximum extent possible.
INPUT PARAMETERS
S0 - sparse matrix in any format.
S1 - matrix which may contain some pre-allocated memory, or
can be just uninitialized structure.
OUTPUT PARAMETERS
S1 - sparse matrix in CRS format.
NOTE: if S0 is stored as CRS, it is just copied without conversion.
-- ALGLIB PROJECT --
Copyright 20.07.2012 by Bochkanov Sergey
*************************************************************************/
</div><div style='margin-top: 0; margin-bottom: 0;'><b>void</b> alglib::sparsecopytocrsbuf(sparsematrix s0, sparsematrix s1);
</div></pre>
<a name='sub_sparsecopytohash'></a><h3 class=pageheader><code>sparsecopytohash</code> function</h3>
<pre class=source>
<div style='color: navy; margin-top: 0; margin-bottom: 0;'>/*************************************************************************
This function performs out-of-place conversion to Hash table storage
format. S0 is copied to S1 and converted on-the-fly.
INPUT PARAMETERS
S0 - sparse matrix in any format.
OUTPUT PARAMETERS
S1 - sparse matrix in Hash table format.
NOTE: if S0 is stored as Hash-table, it is just copied without conversion.
NOTE: this function de-allocates memory occupied by S1 before starting
conversion. If you perform a lot of repeated conversions, it may
lead to memory fragmentation. In this case we recommend you to use
SparseCopyToHashBuf() function which re-uses memory in S1 as much as
possible.
-- ALGLIB PROJECT --
Copyright 20.07.2012 by Bochkanov Sergey
*************************************************************************/
</div><div style='margin-top: 0; margin-bottom: 0;'><b>void</b> alglib::sparsecopytohash(sparsematrix s0, sparsematrix& s1);
</div></pre>
<a name='sub_sparsecopytohashbuf'></a><h3 class=pageheader><code>sparsecopytohashbuf</code> function</h3>
<pre class=source>
<div style='color: navy; margin-top: 0; margin-bottom: 0;'>/*************************************************************************
This function performs out-of-place conversion to Hash table storage
format. S0 is copied to S1 and converted on-the-fly. Memory allocated in
S1 is reused to maximum extent possible.
INPUT PARAMETERS
S0 - sparse matrix in any format.
OUTPUT PARAMETERS
S1 - sparse matrix in Hash table format.
NOTE: if S0 is stored as Hash-table, it is just copied without conversion.
-- ALGLIB PROJECT --
Copyright 20.07.2012 by Bochkanov Sergey
*************************************************************************/
</div><div style='margin-top: 0; margin-bottom: 0;'><b>void</b> alglib::sparsecopytohashbuf(sparsematrix s0, sparsematrix s1);
</div></pre>
<a name='sub_sparsecopytosks'></a><h3 class=pageheader><code>sparsecopytosks</code> function</h3>
<pre class=source>
<div style='color: navy; margin-top: 0; margin-bottom: 0;'>/*************************************************************************
This function performs out-of-place conversion to SKS storage format.
S0 is copied to S1 and converted on-the-fly.
INPUT PARAMETERS
S0 - sparse matrix in any format.
OUTPUT PARAMETERS
S1 - sparse matrix in SKS format.
NOTE: if S0 is stored as SKS, it is just copied without conversion.
NOTE: this function de-allocates memory occupied by S1 before starting
conversion. If you perform a lot of repeated conversions, it may
lead to memory fragmentation. In this case we recommend you to use
SparseCopyToSKSBuf() function which re-uses memory in S1 as much as
possible.
-- ALGLIB PROJECT --
Copyright 20.07.2012 by Bochkanov Sergey
*************************************************************************/
</div><div style='margin-top: 0; margin-bottom: 0;'><b>void</b> alglib::sparsecopytosks(sparsematrix s0, sparsematrix& s1);
</div></pre>
<a name='sub_sparsecopytosksbuf'></a><h3 class=pageheader><code>sparsecopytosksbuf</code> function</h3>
<pre class=source>
<div style='color: navy; margin-top: 0; margin-bottom: 0;'>/*************************************************************************
This function performs out-of-place conversion to SKS format. S0 is
copied to S1 and converted on-the-fly. Memory allocated in S1 is reused
to maximum extent possible.
INPUT PARAMETERS
S0 - sparse matrix in any format.
OUTPUT PARAMETERS
S1 - sparse matrix in SKS format.
NOTE: if S0 is stored as SKS, it is just copied without conversion.
-- ALGLIB PROJECT --
Copyright 20.07.2012 by Bochkanov Sergey
*************************************************************************/
</div><div style='margin-top: 0; margin-bottom: 0;'><b>void</b> alglib::sparsecopytosksbuf(sparsematrix s0, sparsematrix s1);
</div></pre>
<a name='sub_sparsecreate'></a><h3 class=pageheader><code>sparsecreate</code> function</h3>
<pre class=source>
<div style='color: navy; margin-top: 0; margin-bottom: 0;'>/*************************************************************************
This function creates sparse matrix in a Hash-Table format.
This function creates Hast-Table matrix, which can be converted to CRS
format after its initialization is over. Typical usage scenario for a
sparse matrix is:
1. creation in a Hash-Table format
2. insertion of the matrix elements
3. conversion to the CRS representation
4. matrix is passed to some linear algebra algorithm
Some information about different matrix formats can be found below, in
the "NOTES" section.
INPUT PARAMETERS
M - number of rows in a matrix, M>=1
N - number of columns in a matrix, N>=1
K - K>=0, expected number of non-zero elements in a matrix.
K can be inexact approximation, can be less than actual
number of elements (table will grow when needed) or
even zero).
It is important to understand that although hash-table
may grow automatically, it is better to provide good
estimate of data size.
OUTPUT PARAMETERS
S - sparse M*N matrix in Hash-Table representation.
All elements of the matrix are zero.
NOTE 1
Hash-tables use memory inefficiently, and they have to keep some amount
of the "spare memory" in order to have good performance. Hash table for
matrix with K non-zero elements will need C*K*(8+2*sizeof(int)) bytes,
where C is a small constant, about 1.5-2 in magnitude.
CRS storage, from the other side, is more memory-efficient, and needs
just K*(8+sizeof(int))+M*sizeof(int) bytes, where M is a number of rows
in a matrix.
When you convert from the Hash-Table to CRS representation, all unneeded
memory will be freed.
NOTE 2
Comments of SparseMatrix structure outline information about different
sparse storage formats. We recommend you to read them before starting to
use ALGLIB sparse matrices.
NOTE 3
This function completely overwrites S with new sparse matrix. Previously
allocated storage is NOT reused. If you want to reuse already allocated
memory, call SparseCreateBuf function.
-- ALGLIB PROJECT --
Copyright 14.10.2011 by Bochkanov Sergey
*************************************************************************/
</div><div style='margin-top: 0; margin-bottom: 0;'><b>void</b> alglib::sparsecreate(ae_int_t m, ae_int_t n, sparsematrix& s);
<b>void</b> alglib::sparsecreate(
ae_int_t m,
ae_int_t n,
ae_int_t k,
sparsematrix& s);
</div></pre>
<p align=left class=pagecontent><span class=inlineheader>Examples:</span> <a href='#example_sparse_d_1' class=nav>[1]</a> </p>
<a name='sub_sparsecreatebuf'></a><h3 class=pageheader><code>sparsecreatebuf</code> function</h3>
<pre class=source>
<div style='color: navy; margin-top: 0; margin-bottom: 0;'>/*************************************************************************
This version of SparseCreate function creates sparse matrix in Hash-Table
format, reusing previously allocated storage as much as possible. Read
comments for SparseCreate() for more information.
INPUT PARAMETERS
M - number of rows in a matrix, M>=1
N - number of columns in a matrix, N>=1
K - K>=0, expected number of non-zero elements in a matrix.
K can be inexact approximation, can be less than actual
number of elements (table will grow when needed) or
even zero).
It is important to understand that although hash-table
may grow automatically, it is better to provide good
estimate of data size.
S - SparseMatrix structure which MAY contain some already
allocated storage.
OUTPUT PARAMETERS
S - sparse M*N matrix in Hash-Table representation.
All elements of the matrix are zero.
Previously allocated storage is reused, if its size
is compatible with expected number of non-zeros K.
-- ALGLIB PROJECT --
Copyright 14.01.2014 by Bochkanov Sergey
*************************************************************************/
</div><div style='margin-top: 0; margin-bottom: 0;'><b>void</b> alglib::sparsecreatebuf(ae_int_t m, ae_int_t n, sparsematrix s);
<b>void</b> alglib::sparsecreatebuf(
ae_int_t m,
ae_int_t n,
ae_int_t k,
sparsematrix s);
</div></pre>
<a name='sub_sparsecreatecrs'></a><h3 class=pageheader><code>sparsecreatecrs</code> function</h3>
<pre class=source>
<div style='color: navy; margin-top: 0; margin-bottom: 0;'>/*************************************************************************
This function creates sparse matrix in a CRS format (expert function for
situations when you are running out of memory).
This function creates CRS matrix. Typical usage scenario for a CRS matrix
is:
1. creation (you have to tell number of non-zero elements at each row at
this moment)
2. insertion of the matrix elements (row by row, from left to right)
3. matrix is passed to some linear algebra algorithm
This function is a memory-efficient alternative to SparseCreate(), but it
is more complex because it requires you to know in advance how large your
matrix is. Some information about different matrix formats can be found
in comments on SparseMatrix structure. We recommend you to read them
before starting to use ALGLIB sparse matrices..
INPUT PARAMETERS
M - number of rows in a matrix, M>=1
N - number of columns in a matrix, N>=1
NER - number of elements at each row, array[M], NER[I]>=0
OUTPUT PARAMETERS
S - sparse M*N matrix in CRS representation.
You have to fill ALL non-zero elements by calling
SparseSet() BEFORE you try to use this matrix.
NOTE: this function completely overwrites S with new sparse matrix.
Previously allocated storage is NOT reused. If you want to reuse
already allocated memory, call SparseCreateCRSBuf function.
-- ALGLIB PROJECT --
Copyright 14.10.2011 by Bochkanov Sergey
*************************************************************************/
</div><div style='margin-top: 0; margin-bottom: 0;'><b>void</b> alglib::sparsecreatecrs(
ae_int_t m,
ae_int_t n,
integer_1d_array ner,
sparsematrix& s);
</div></pre>
<p align=left class=pagecontent><span class=inlineheader>Examples:</span> <a href='#example_sparse_d_crs' class=nav>[1]</a> </p>
<a name='sub_sparsecreatecrsbuf'></a><h3 class=pageheader><code>sparsecreatecrsbuf</code> function</h3>
<pre class=source>
<div style='color: navy; margin-top: 0; margin-bottom: 0;'>/*************************************************************************
This function creates sparse matrix in a CRS format (expert function for
situations when you are running out of memory). This version of CRS
matrix creation function may reuse memory already allocated in S.
This function creates CRS matrix. Typical usage scenario for a CRS matrix
is:
1. creation (you have to tell number of non-zero elements at each row at
this moment)
2. insertion of the matrix elements (row by row, from left to right)
3. matrix is passed to some linear algebra algorithm
This function is a memory-efficient alternative to SparseCreate(), but it
is more complex because it requires you to know in advance how large your
matrix is. Some information about different matrix formats can be found
in comments on SparseMatrix structure. We recommend you to read them
before starting to use ALGLIB sparse matrices..
INPUT PARAMETERS
M - number of rows in a matrix, M>=1
N - number of columns in a matrix, N>=1
NER - number of elements at each row, array[M], NER[I]>=0
S - sparse matrix structure with possibly preallocated
memory.
OUTPUT PARAMETERS
S - sparse M*N matrix in CRS representation.
You have to fill ALL non-zero elements by calling
SparseSet() BEFORE you try to use this matrix.
-- ALGLIB PROJECT --
Copyright 14.10.2011 by Bochkanov Sergey
*************************************************************************/
</div><div style='margin-top: 0; margin-bottom: 0;'><b>void</b> alglib::sparsecreatecrsbuf(
ae_int_t m,
ae_int_t n,
integer_1d_array ner,
sparsematrix s);
</div></pre>
<a name='sub_sparsecreatesks'></a><h3 class=pageheader><code>sparsecreatesks</code> function</h3>
<pre class=source>
<div style='color: navy; margin-top: 0; margin-bottom: 0;'>/*************************************************************************
This function creates sparse matrix in a SKS format (skyline storage
format). In most cases you do not need this function - CRS format better
suits most use cases.
INPUT PARAMETERS
M, N - number of rows(M) and columns (N) in a matrix:
* M=N (as for now, ALGLIB supports only square SKS)
* N>=1
* M>=1
D - "bottom" bandwidths, array[M], D[I]>=0.
I-th element stores number of non-zeros at I-th row,
below the diagonal (diagonal itself is not included)
U - "top" bandwidths, array[N], U[I]>=0.
I-th element stores number of non-zeros at I-th row,
above the diagonal (diagonal itself is not included)
OUTPUT PARAMETERS
S - sparse M*N matrix in SKS representation.
All elements are filled by zeros.
You may use SparseRewriteExisting() to change their
values.
NOTE: this function completely overwrites S with new sparse matrix.
Previously allocated storage is NOT reused. If you want to reuse
already allocated memory, call SparseCreateSKSBuf function.
-- ALGLIB PROJECT --
Copyright 13.01.2014 by Bochkanov Sergey
*************************************************************************/
</div><div style='margin-top: 0; margin-bottom: 0;'><b>void</b> alglib::sparsecreatesks(
ae_int_t m,
ae_int_t n,
integer_1d_array d,
integer_1d_array u,
sparsematrix& s);
</div></pre>
<a name='sub_sparsecreatesksbuf'></a><h3 class=pageheader><code>sparsecreatesksbuf</code> function</h3>
<pre class=source>
<div style='color: navy; margin-top: 0; margin-bottom: 0;'>/*************************************************************************
This is "buffered" version of SparseCreateSKS() which reuses memory
previously allocated in S (of course, memory is reallocated if needed).
This function creates sparse matrix in a SKS format (skyline storage
format). In most cases you do not need this function - CRS format better
suits most use cases.
INPUT PARAMETERS
M, N - number of rows(M) and columns (N) in a matrix:
* M=N (as for now, ALGLIB supports only square SKS)
* N>=1
* M>=1
D - "bottom" bandwidths, array[M], 0<=D[I]<=I.
I-th element stores number of non-zeros at I-th row,
below the diagonal (diagonal itself is not included)
U - "top" bandwidths, array[N], 0<=U[I]<=I.
I-th element stores number of non-zeros at I-th row,
above the diagonal (diagonal itself is not included)
OUTPUT PARAMETERS
S - sparse M*N matrix in SKS representation.
All elements are filled by zeros.
You may use SparseSet()/SparseAdd() to change their
values.
-- ALGLIB PROJECT --
Copyright 13.01.2014 by Bochkanov Sergey
*************************************************************************/
</div><div style='margin-top: 0; margin-bottom: 0;'><b>void</b> alglib::sparsecreatesksbuf(
ae_int_t m,
ae_int_t n,
integer_1d_array d,
integer_1d_array u,
sparsematrix s);
</div></pre>
<a name='sub_sparseenumerate'></a><h3 class=pageheader><code>sparseenumerate</code> function</h3>
<pre class=source>
<div style='color: navy; margin-top: 0; margin-bottom: 0;'>/*************************************************************************
This function is used to enumerate all elements of the sparse matrix.
Before first call user initializes T0 and T1 counters by zero. These
counters are used to remember current position in a matrix; after each
call they are updated by the function.
Subsequent calls to this function return non-zero elements of the sparse
matrix, one by one. If you enumerate CRS matrix, matrix is traversed from
left to right, from top to bottom. In case you enumerate matrix stored as
Hash table, elements are returned in random order.
EXAMPLE
> T0=0
> T1=0
> while SparseEnumerate(S,T0,T1,I,J,V) do
> ....do something with I,J,V
INPUT PARAMETERS
S - sparse M*N matrix in Hash-Table or CRS representation.
T0 - internal counter
T1 - internal counter
OUTPUT PARAMETERS
T0 - new value of the internal counter
T1 - new value of the internal counter
I - row index of non-zero element, 0<=I<M.
J - column index of non-zero element, 0<=J<N
V - value of the T-th element
RESULT
True in case of success (next non-zero element was retrieved)
False in case all non-zero elements were enumerated
NOTE: you may call SparseRewriteExisting() during enumeration, but it is
THE ONLY matrix modification function you can call!!! Other
matrix modification functions should not be called during enumeration!
-- ALGLIB PROJECT --
Copyright 14.03.2012 by Bochkanov Sergey
*************************************************************************/
</div><div style='margin-top: 0; margin-bottom: 0;'><b>bool</b> alglib::sparseenumerate(
sparsematrix s,
ae_int_t& t0,
ae_int_t& t1,
ae_int_t& i,
ae_int_t& j,
<b>double</b>& v);
</div></pre>
<a name='sub_sparsefree'></a><h3 class=pageheader><code>sparsefree</code> function</h3>
<pre class=source>
<div style='color: navy; margin-top: 0; margin-bottom: 0;'>/*************************************************************************
The function frees all memory occupied by sparse matrix. Sparse matrix
structure becomes unusable after this call.
OUTPUT PARAMETERS
S - sparse matrix to delete
-- ALGLIB PROJECT --
Copyright 24.07.2012 by Bochkanov Sergey
*************************************************************************/
</div><div style='margin-top: 0; margin-bottom: 0;'><b>void</b> alglib::sparsefree(sparsematrix& s);
</div></pre>
<a name='sub_sparseget'></a><h3 class=pageheader><code>sparseget</code> function</h3>
<pre class=source>
<div style='color: navy; margin-top: 0; margin-bottom: 0;'>/*************************************************************************
This function returns S[i,j] - element of the sparse matrix. Matrix can
be in any mode (Hash-Table, CRS, SKS), but this function is less efficient
for CRS matrices. Hash-Table and SKS matrices can find element in O(1)
time, while CRS matrices need O(log(RS)) time, where RS is an number of
non-zero elements in a row.
INPUT PARAMETERS
S - sparse M*N matrix in Hash-Table representation.
Exception will be thrown for CRS matrix.
I - row index of the element to modify, 0<=I<M
J - column index of the element to modify, 0<=J<N
RESULT
value of S[I,J] or zero (in case no element with such index is found)
-- ALGLIB PROJECT --
Copyright 14.10.2011 by Bochkanov Sergey
*************************************************************************/
</div><div style='margin-top: 0; margin-bottom: 0;'><b>double</b> alglib::sparseget(sparsematrix s, ae_int_t i, ae_int_t j);
</div></pre>
<p align=left class=pagecontent><span class=inlineheader>Examples:</span> <a href='#example_sparse_d_1' class=nav>[1]</a> <a href='#example_sparse_d_crs' class=nav>[2]</a> </p>
<a name='sub_sparsegetcompressedrow'></a><h3 class=pageheader><code>sparsegetcompressedrow</code> function</h3>
<pre class=source>
<div style='color: navy; margin-top: 0; margin-bottom: 0;'>/*************************************************************************
This function returns I-th row of the sparse matrix IN COMPRESSED FORMAT -
only non-zero elements are returned (with their indexes). Matrix must be
stored in CRS or SKS format.
INPUT PARAMETERS:
S - sparse M*N matrix in CRS format
I - row index, 0<=I<M
ColIdx - output buffer for column indexes, can be preallocated.
In case buffer size is too small to store I-th row, it
is automatically reallocated.
Vals - output buffer for values, can be preallocated. In case
buffer size is too small to store I-th row, it is
automatically reallocated.
OUTPUT PARAMETERS:
ColIdx - column indexes of non-zero elements, sorted by
ascending. Symbolically non-zero elements are counted
(i.e. if you allocated place for element, but it has
zero numerical value - it is counted).
Vals - values. Vals[K] stores value of matrix element with
indexes (I,ColIdx[K]). Symbolically non-zero elements
are counted (i.e. if you allocated place for element,
but it has zero numerical value - it is counted).
NZCnt - number of symbolically non-zero elements per row.
NOTE: when incorrect I (outside of [0,M-1]) or matrix (non CRS/SKS)
is passed, this function throws exception.
NOTE: this function may allocate additional, unnecessary place for ColIdx
and Vals arrays. It is dictated by performance reasons - on SKS
matrices it is faster to allocate space at the beginning with
some "extra"-space, than performing two passes over matrix - first
time to calculate exact space required for data, second time - to
store data itself.
-- ALGLIB PROJECT --
Copyright 10.12.2014 by Bochkanov Sergey
*************************************************************************/
</div><div style='margin-top: 0; margin-bottom: 0;'><b>void</b> alglib::sparsegetcompressedrow(
sparsematrix s,
ae_int_t i,
integer_1d_array& colidx,
real_1d_array& vals,
ae_int_t& nzcnt);
</div></pre>
<a name='sub_sparsegetdiagonal'></a><h3 class=pageheader><code>sparsegetdiagonal</code> function</h3>
<pre class=source>
<div style='color: navy; margin-top: 0; margin-bottom: 0;'>/*************************************************************************
This function returns I-th diagonal element of the sparse matrix.
Matrix can be in any mode (Hash-Table or CRS storage), but this function
is most efficient for CRS matrices - it requires less than 50 CPU cycles
to extract diagonal element. For Hash-Table matrices we still have O(1)
query time, but function is many times slower.
INPUT PARAMETERS
S - sparse M*N matrix in Hash-Table representation.
Exception will be thrown for CRS matrix.
I - index of the element to modify, 0<=I<min(M,N)
RESULT
value of S[I,I] or zero (in case no element with such index is found)
-- ALGLIB PROJECT --
Copyright 14.10.2011 by Bochkanov Sergey
*************************************************************************/
</div><div style='margin-top: 0; margin-bottom: 0;'><b>double</b> alglib::sparsegetdiagonal(sparsematrix s, ae_int_t i);
</div></pre>
<a name='sub_sparsegetlowercount'></a><h3 class=pageheader><code>sparsegetlowercount</code> function</h3>
<pre class=source>
<div style='color: navy; margin-top: 0; margin-bottom: 0;'>/*************************************************************************
The function returns number of strictly lower triangular non-zero elements
in the matrix. It counts SYMBOLICALLY non-zero elements, i.e. entries
in the sparse matrix data structure. If some element has zero numerical
value, it is still counted.
This function has different cost for different types of matrices:
* for hash-based matrices it involves complete pass over entire hash-table
with O(NNZ) cost, where NNZ is number of non-zero elements
* for CRS and SKS matrix types cost of counting is O(N) (N - matrix size).
RESULT: number of non-zero elements strictly below main diagonal
-- ALGLIB PROJECT --
Copyright 12.02.2014 by Bochkanov Sergey
*************************************************************************/
</div><div style='margin-top: 0; margin-bottom: 0;'>ae_int_t alglib::sparsegetlowercount(sparsematrix s);
</div></pre>
<a name='sub_sparsegetmatrixtype'></a><h3 class=pageheader><code>sparsegetmatrixtype</code> function</h3>
<pre class=source>
<div style='color: navy; margin-top: 0; margin-bottom: 0;'>/*************************************************************************
This function returns type of the matrix storage format.
INPUT PARAMETERS:
S - sparse matrix.
RESULT:
sparse storage format used by matrix:
0 - Hash-table
1 - CRS (compressed row storage)
2 - SKS (skyline)
NOTE: future versions of ALGLIB may include additional sparse storage
formats.
-- ALGLIB PROJECT --
Copyright 20.07.2012 by Bochkanov Sergey
*************************************************************************/
</div><div style='margin-top: 0; margin-bottom: 0;'>ae_int_t alglib::sparsegetmatrixtype(sparsematrix s);
</div></pre>
<a name='sub_sparsegetncols'></a><h3 class=pageheader><code>sparsegetncols</code> function</h3>
<pre class=source>
<div style='color: navy; margin-top: 0; margin-bottom: 0;'>/*************************************************************************
The function returns number of columns of a sparse matrix.
RESULT: number of columns of a sparse matrix.
-- ALGLIB PROJECT --
Copyright 23.08.2012 by Bochkanov Sergey
*************************************************************************/
</div><div style='margin-top: 0; margin-bottom: 0;'>ae_int_t alglib::sparsegetncols(sparsematrix s);
</div></pre>
<a name='sub_sparsegetnrows'></a><h3 class=pageheader><code>sparsegetnrows</code> function</h3>
<pre class=source>
<div style='color: navy; margin-top: 0; margin-bottom: 0;'>/*************************************************************************
The function returns number of rows of a sparse matrix.
RESULT: number of rows of a sparse matrix.
-- ALGLIB PROJECT --
Copyright 23.08.2012 by Bochkanov Sergey
*************************************************************************/
</div><div style='margin-top: 0; margin-bottom: 0;'>ae_int_t alglib::sparsegetnrows(sparsematrix s);
</div></pre>
<a name='sub_sparsegetrow'></a><h3 class=pageheader><code>sparsegetrow</code> function</h3>
<pre class=source>
<div style='color: navy; margin-top: 0; margin-bottom: 0;'>/*************************************************************************
This function returns I-th row of the sparse matrix. Matrix must be stored
in CRS or SKS format.
INPUT PARAMETERS:
S - sparse M*N matrix in CRS format
I - row index, 0<=I<M
IRow - output buffer, can be preallocated. In case buffer
size is too small to store I-th row, it is
automatically reallocated.
OUTPUT PARAMETERS:
IRow - array[M], I-th row.
NOTE: this function has O(N) running time, where N is a column count. It
allocates and fills N-element array, even although most of its
elemets are zero.
NOTE: If you have O(non-zeros-per-row) time and memory requirements, use
SparseGetCompressedRow() function. It returns data in compressed
format.
NOTE: when incorrect I (outside of [0,M-1]) or matrix (non CRS/SKS)
is passed, this function throws exception.
-- ALGLIB PROJECT --
Copyright 10.12.2014 by Bochkanov Sergey
*************************************************************************/
</div><div style='margin-top: 0; margin-bottom: 0;'><b>void</b> alglib::sparsegetrow(
sparsematrix s,
ae_int_t i,
real_1d_array& irow);
</div></pre>
<a name='sub_sparsegetuppercount'></a><h3 class=pageheader><code>sparsegetuppercount</code> function</h3>
<pre class=source>
<div style='color: navy; margin-top: 0; margin-bottom: 0;'>/*************************************************************************
The function returns number of strictly upper triangular non-zero elements
in the matrix. It counts SYMBOLICALLY non-zero elements, i.e. entries
in the sparse matrix data structure. If some element has zero numerical
value, it is still counted.
This function has different cost for different types of matrices:
* for hash-based matrices it involves complete pass over entire hash-table
with O(NNZ) cost, where NNZ is number of non-zero elements
* for CRS and SKS matrix types cost of counting is O(N) (N - matrix size).
RESULT: number of non-zero elements strictly above main diagonal
-- ALGLIB PROJECT --
Copyright 12.02.2014 by Bochkanov Sergey
*************************************************************************/
</div><div style='margin-top: 0; margin-bottom: 0;'>ae_int_t alglib::sparsegetuppercount(sparsematrix s);
</div></pre>
<a name='sub_sparseiscrs'></a><h3 class=pageheader><code>sparseiscrs</code> function</h3>
<pre class=source>
<div style='color: navy; margin-top: 0; margin-bottom: 0;'>/*************************************************************************
This function checks matrix storage format and returns True when matrix is
stored using CRS representation.
INPUT PARAMETERS:
S - sparse matrix.
RESULT:
True if matrix type is CRS
False if matrix type is not CRS
-- ALGLIB PROJECT --
Copyright 20.07.2012 by Bochkanov Sergey
*************************************************************************/
</div><div style='margin-top: 0; margin-bottom: 0;'><b>bool</b> alglib::sparseiscrs(sparsematrix s);
</div></pre>
<a name='sub_sparseishash'></a><h3 class=pageheader><code>sparseishash</code> function</h3>
<pre class=source>
<div style='color: navy; margin-top: 0; margin-bottom: 0;'>/*************************************************************************
This function checks matrix storage format and returns True when matrix is
stored using Hash table representation.
INPUT PARAMETERS:
S - sparse matrix.
RESULT:
True if matrix type is Hash table
False if matrix type is not Hash table
-- ALGLIB PROJECT --
Copyright 20.07.2012 by Bochkanov Sergey
*************************************************************************/
</div><div style='margin-top: 0; margin-bottom: 0;'><b>bool</b> alglib::sparseishash(sparsematrix s);
</div></pre>
<a name='sub_sparseissks'></a><h3 class=pageheader><code>sparseissks</code> function</h3>
<pre class=source>
<div style='color: navy; margin-top: 0; margin-bottom: 0;'>/*************************************************************************
This function checks matrix storage format and returns True when matrix is
stored using SKS representation.
INPUT PARAMETERS:
S - sparse matrix.
RESULT:
True if matrix type is SKS
False if matrix type is not SKS
-- ALGLIB PROJECT --
Copyright 20.07.2012 by Bochkanov Sergey
*************************************************************************/
</div><div style='margin-top: 0; margin-bottom: 0;'><b>bool</b> alglib::sparseissks(sparsematrix s);
</div></pre>
<a name='sub_sparsemm'></a><h3 class=pageheader><code>sparsemm</code> function</h3>
<pre class=source>
<div style='color: navy; margin-top: 0; margin-bottom: 0;'>/*************************************************************************
This function calculates matrix-matrix product S*A. Matrix S must be
stored in CRS or SKS format (exception will be thrown otherwise).
INPUT PARAMETERS
S - sparse M*N matrix in CRS or SKS format.
A - array[N][K], input dense matrix. For performance reasons
we make only quick checks - we check that array size
is at least N, but we do not check for NAN's or INF's.
K - number of columns of matrix (A).
B - output buffer, possibly preallocated. In case buffer
size is too small to store result, this buffer is
automatically resized.
OUTPUT PARAMETERS
B - array[M][K], S*A
NOTE: this function throws exception when called for non-CRS/SKS matrix.
You must convert your matrix with SparseConvertToCRS/SKS() before using
this function.
-- ALGLIB PROJECT --
Copyright 14.10.2011 by Bochkanov Sergey
*************************************************************************/
</div><div style='margin-top: 0; margin-bottom: 0;'><b>void</b> alglib::sparsemm(
sparsematrix s,
real_2d_array a,
ae_int_t k,
real_2d_array& b);
</div></pre>
<a name='sub_sparsemm2'></a><h3 class=pageheader><code>sparsemm2</code> function</h3>
<pre class=source>
<div style='color: navy; margin-top: 0; margin-bottom: 0;'>/*************************************************************************
This function simultaneously calculates two matrix-matrix products:
S*A and S^T*A.
S must be square (non-rectangular) matrix stored in CRS or SKS format
(exception will be thrown otherwise).
INPUT PARAMETERS
S - sparse N*N matrix in CRS or SKS format.
A - array[N][K], input dense matrix. For performance reasons
we make only quick checks - we check that array size is
at least N, but we do not check for NAN's or INF's.
K - number of columns of matrix (A).
B0 - output buffer, possibly preallocated. In case buffer
size is too small to store result, this buffer is
automatically resized.
B1 - output buffer, possibly preallocated. In case buffer
size is too small to store result, this buffer is
automatically resized.
OUTPUT PARAMETERS
B0 - array[N][K], S*A
B1 - array[N][K], S^T*A
NOTE: this function throws exception when called for non-CRS/SKS matrix.
You must convert your matrix with SparseConvertToCRS/SKS() before using
this function.
-- ALGLIB PROJECT --
Copyright 14.10.2011 by Bochkanov Sergey
*************************************************************************/
</div><div style='margin-top: 0; margin-bottom: 0;'><b>void</b> alglib::sparsemm2(
sparsematrix s,
real_2d_array a,
ae_int_t k,
real_2d_array& b0,
real_2d_array& b1);
</div></pre>
<a name='sub_sparsemtm'></a><h3 class=pageheader><code>sparsemtm</code> function</h3>
<pre class=source>
<div style='color: navy; margin-top: 0; margin-bottom: 0;'>/*************************************************************************
This function calculates matrix-matrix product S^T*A. Matrix S must be
stored in CRS or SKS format (exception will be thrown otherwise).
INPUT PARAMETERS
S - sparse M*N matrix in CRS or SKS format.
A - array[M][K], input dense matrix. For performance reasons
we make only quick checks - we check that array size is
at least M, but we do not check for NAN's or INF's.
K - number of columns of matrix (A).
B - output buffer, possibly preallocated. In case buffer
size is too small to store result, this buffer is
automatically resized.
OUTPUT PARAMETERS
B - array[N][K], S^T*A
NOTE: this function throws exception when called for non-CRS/SKS matrix.
You must convert your matrix with SparseConvertToCRS/SKS() before using
this function.
-- ALGLIB PROJECT --
Copyright 14.10.2011 by Bochkanov Sergey
*************************************************************************/
</div><div style='margin-top: 0; margin-bottom: 0;'><b>void</b> alglib::sparsemtm(
sparsematrix s,
real_2d_array a,
ae_int_t k,
real_2d_array& b);
</div></pre>
<a name='sub_sparsemtv'></a><h3 class=pageheader><code>sparsemtv</code> function</h3>
<pre class=source>
<div style='color: navy; margin-top: 0; margin-bottom: 0;'>/*************************************************************************
This function calculates matrix-vector product S^T*x. Matrix S must be
stored in CRS or SKS format (exception will be thrown otherwise).
INPUT PARAMETERS
S - sparse M*N matrix in CRS or SKS format.
X - array[M], input vector. For performance reasons we
make only quick checks - we check that array size is
at least M, but we do not check for NAN's or INF's.
Y - output buffer, possibly preallocated. In case buffer
size is too small to store result, this buffer is
automatically resized.
OUTPUT PARAMETERS
Y - array[N], S^T*x
NOTE: this function throws exception when called for non-CRS/SKS matrix.
You must convert your matrix with SparseConvertToCRS/SKS() before using
this function.
-- ALGLIB PROJECT --
Copyright 14.10.2011 by Bochkanov Sergey
*************************************************************************/
</div><div style='margin-top: 0; margin-bottom: 0;'><b>void</b> alglib::sparsemtv(sparsematrix s, real_1d_array x, real_1d_array& y);
</div></pre>
<a name='sub_sparsemv'></a><h3 class=pageheader><code>sparsemv</code> function</h3>
<pre class=source>
<div style='color: navy; margin-top: 0; margin-bottom: 0;'>/*************************************************************************
This function calculates matrix-vector product S*x. Matrix S must be
stored in CRS or SKS format (exception will be thrown otherwise).
INPUT PARAMETERS
S - sparse M*N matrix in CRS or SKS format.
X - array[N], input vector. For performance reasons we
make only quick checks - we check that array size is
at least N, but we do not check for NAN's or INF's.
Y - output buffer, possibly preallocated. In case buffer
size is too small to store result, this buffer is
automatically resized.
OUTPUT PARAMETERS
Y - array[M], S*x
NOTE: this function throws exception when called for non-CRS/SKS matrix.
You must convert your matrix with SparseConvertToCRS/SKS() before using
this function.
-- ALGLIB PROJECT --
Copyright 14.10.2011 by Bochkanov Sergey
*************************************************************************/
</div><div style='margin-top: 0; margin-bottom: 0;'><b>void</b> alglib::sparsemv(sparsematrix s, real_1d_array x, real_1d_array& y);
</div></pre>
<p align=left class=pagecontent><span class=inlineheader>Examples:</span> <a href='#example_sparse_d_1' class=nav>[1]</a> <a href='#example_sparse_d_crs' class=nav>[2]</a> </p>
<a name='sub_sparsemv2'></a><h3 class=pageheader><code>sparsemv2</code> function</h3>
<pre class=source>
<div style='color: navy; margin-top: 0; margin-bottom: 0;'>/*************************************************************************
This function simultaneously calculates two matrix-vector products:
S*x and S^T*x.
S must be square (non-rectangular) matrix stored in CRS or SKS format
(exception will be thrown otherwise).
INPUT PARAMETERS
S - sparse N*N matrix in CRS or SKS format.
X - array[N], input vector. For performance reasons we
make only quick checks - we check that array size is
at least N, but we do not check for NAN's or INF's.
Y0 - output buffer, possibly preallocated. In case buffer
size is too small to store result, this buffer is
automatically resized.
Y1 - output buffer, possibly preallocated. In case buffer
size is too small to store result, this buffer is
automatically resized.
OUTPUT PARAMETERS
Y0 - array[N], S*x
Y1 - array[N], S^T*x
NOTE: this function throws exception when called for non-CRS/SKS matrix.
You must convert your matrix with SparseConvertToCRS/SKS() before using
this function.
-- ALGLIB PROJECT --
Copyright 14.10.2011 by Bochkanov Sergey
*************************************************************************/
</div><div style='margin-top: 0; margin-bottom: 0;'><b>void</b> alglib::sparsemv2(
sparsematrix s,
real_1d_array x,
real_1d_array& y0,
real_1d_array& y1);
</div></pre>
<a name='sub_sparseresizematrix'></a><h3 class=pageheader><code>sparseresizematrix</code> function</h3>
<pre class=source>
<div style='color: navy; margin-top: 0; margin-bottom: 0;'>/*************************************************************************
This procedure resizes Hash-Table matrix. It can be called when you have
deleted too many elements from the matrix, and you want to free unneeded
memory.
-- ALGLIB PROJECT --
Copyright 14.10.2011 by Bochkanov Sergey
*************************************************************************/
</div><div style='margin-top: 0; margin-bottom: 0;'><b>void</b> alglib::sparseresizematrix(sparsematrix s);
</div></pre>
<a name='sub_sparserewriteexisting'></a><h3 class=pageheader><code>sparserewriteexisting</code> function</h3>
<pre class=source>
<div style='color: navy; margin-top: 0; margin-bottom: 0;'>/*************************************************************************
This function rewrites existing (non-zero) element. It returns True if
element exists or False, when it is called for non-existing (zero)
element.
This function works with any kind of the matrix.
The purpose of this function is to provide convenient thread-safe way to
modify sparse matrix. Such modification (already existing element is
rewritten) is guaranteed to be thread-safe without any synchronization, as
long as different threads modify different elements.
INPUT PARAMETERS
S - sparse M*N matrix in any kind of representation
(Hash, SKS, CRS).
I - row index of non-zero element to modify, 0<=I<M
J - column index of non-zero element to modify, 0<=J<N
V - value to rewrite, must be finite number
OUTPUT PARAMETERS
S - modified matrix
RESULT
True in case when element exists
False in case when element doesn't exist or it is zero
-- ALGLIB PROJECT --
Copyright 14.03.2012 by Bochkanov Sergey
*************************************************************************/
</div><div style='margin-top: 0; margin-bottom: 0;'><b>bool</b> alglib::sparserewriteexisting(
sparsematrix s,
ae_int_t i,
ae_int_t j,
<b>double</b> v);
</div></pre>
<a name='sub_sparseset'></a><h3 class=pageheader><code>sparseset</code> function</h3>
<pre class=source>
<div style='color: navy; margin-top: 0; margin-bottom: 0;'>/*************************************************************************
This function modifies S[i,j] - element of the sparse matrix.
For Hash-based storage format:
* this function can be called at any moment - during matrix initialization
or later
* new value can be zero or non-zero. In case new value of S[i,j] is zero,
this element is deleted from the table.
* this function has no effect when called with zero V for non-existent
element.
For CRS-bases storage format:
* this function can be called ONLY DURING MATRIX INITIALIZATION
* new value MUST be non-zero. Exception will be thrown for zero V.
* elements must be initialized in correct order - from top row to bottom,
within row - from left to right.
For SKS storage: NOT SUPPORTED! Use SparseRewriteExisting() to work with
SKS matrices.
INPUT PARAMETERS
S - sparse M*N matrix in Hash-Table or CRS representation.
I - row index of the element to modify, 0<=I<M
J - column index of the element to modify, 0<=J<N
V - value to set, must be finite number, can be zero
OUTPUT PARAMETERS
S - modified matrix
-- ALGLIB PROJECT --
Copyright 14.10.2011 by Bochkanov Sergey
*************************************************************************/
</div><div style='margin-top: 0; margin-bottom: 0;'><b>void</b> alglib::sparseset(sparsematrix s, ae_int_t i, ae_int_t j, <b>double</b> v);
</div></pre>
<p align=left class=pagecontent><span class=inlineheader>Examples:</span> <a href='#example_sparse_d_1' class=nav>[1]</a> <a href='#example_sparse_d_crs' class=nav>[2]</a> </p>
<a name='sub_sparsesmm'></a><h3 class=pageheader><code>sparsesmm</code> function</h3>
<pre class=source>
<div style='color: navy; margin-top: 0; margin-bottom: 0;'>/*************************************************************************
This function calculates matrix-matrix product S*A, when S is symmetric
matrix. Matrix S must be stored in CRS or SKS format (exception will be
thrown otherwise).
INPUT PARAMETERS
S - sparse M*M matrix in CRS or SKS format.
IsUpper - whether upper or lower triangle of S is given:
* if upper triangle is given, only S[i,j] for j>=i
are used, and lower triangle is ignored (it can be
empty - these elements are not referenced at all).
* if lower triangle is given, only S[i,j] for j<=i
are used, and upper triangle is ignored.
A - array[N][K], input dense matrix. For performance reasons
we make only quick checks - we check that array size is
at least N, but we do not check for NAN's or INF's.
K - number of columns of matrix (A).
B - output buffer, possibly preallocated. In case buffer
size is too small to store result, this buffer is
automatically resized.
OUTPUT PARAMETERS
B - array[M][K], S*A
NOTE: this function throws exception when called for non-CRS/SKS matrix.
You must convert your matrix with SparseConvertToCRS/SKS() before using
this function.
-- ALGLIB PROJECT --
Copyright 14.10.2011 by Bochkanov Sergey
*************************************************************************/
</div><div style='margin-top: 0; margin-bottom: 0;'><b>void</b> alglib::sparsesmm(
sparsematrix s,
<b>bool</b> isupper,
real_2d_array a,
ae_int_t k,
real_2d_array& b);
</div></pre>
<a name='sub_sparsesmv'></a><h3 class=pageheader><code>sparsesmv</code> function</h3>
<pre class=source>
<div style='color: navy; margin-top: 0; margin-bottom: 0;'>/*************************************************************************
This function calculates matrix-vector product S*x, when S is symmetric
matrix. Matrix S must be stored in CRS or SKS format (exception will be
thrown otherwise).
INPUT PARAMETERS
S - sparse M*M matrix in CRS or SKS format.
IsUpper - whether upper or lower triangle of S is given:
* if upper triangle is given, only S[i,j] for j>=i
are used, and lower triangle is ignored (it can be
empty - these elements are not referenced at all).
* if lower triangle is given, only S[i,j] for j<=i
are used, and upper triangle is ignored.
X - array[N], input vector. For performance reasons we
make only quick checks - we check that array size is
at least N, but we do not check for NAN's or INF's.
Y - output buffer, possibly preallocated. In case buffer
size is too small to store result, this buffer is
automatically resized.
OUTPUT PARAMETERS
Y - array[M], S*x
NOTE: this function throws exception when called for non-CRS/SKS matrix.
You must convert your matrix with SparseConvertToCRS/SKS() before using
this function.
-- ALGLIB PROJECT --
Copyright 14.10.2011 by Bochkanov Sergey
*************************************************************************/
</div><div style='margin-top: 0; margin-bottom: 0;'><b>void</b> alglib::sparsesmv(
sparsematrix s,
<b>bool</b> isupper,
real_1d_array x,
real_1d_array& y);
</div></pre>
<a name='sub_sparseswap'></a><h3 class=pageheader><code>sparseswap</code> function</h3>
<pre class=source>
<div style='color: navy; margin-top: 0; margin-bottom: 0;'>/*************************************************************************
This function efficiently swaps contents of S0 and S1.
-- ALGLIB PROJECT --
Copyright 16.01.2014 by Bochkanov Sergey
*************************************************************************/
</div><div style='margin-top: 0; margin-bottom: 0;'><b>void</b> alglib::sparseswap(sparsematrix s0, sparsematrix s1);
</div></pre>
<a name='sub_sparsetransposesks'></a><h3 class=pageheader><code>sparsetransposesks</code> function</h3>
<pre class=source>
<div style='color: navy; margin-top: 0; margin-bottom: 0;'>/*************************************************************************
This function performs efficient in-place transpose of SKS matrix. No
additional memory is allocated during transposition.
This function supports only skyline storage format (SKS).
INPUT PARAMETERS
S - sparse matrix in SKS format.
OUTPUT PARAMETERS
S - sparse matrix, transposed.
-- ALGLIB PROJECT --
Copyright 16.01.2014 by Bochkanov Sergey
*************************************************************************/
</div><div style='margin-top: 0; margin-bottom: 0;'><b>void</b> alglib::sparsetransposesks(sparsematrix s);
</div></pre>
<a name='sub_sparsetrmv'></a><h3 class=pageheader><code>sparsetrmv</code> function</h3>
<pre class=source>
<div style='color: navy; margin-top: 0; margin-bottom: 0;'>/*************************************************************************
This function calculates matrix-vector product op(S)*x, when x is vector,
S is symmetric triangular matrix, op(S) is transposition or no operation.
Matrix S must be stored in CRS or SKS format (exception will be thrown
otherwise).
INPUT PARAMETERS
S - sparse square matrix in CRS or SKS format.
IsUpper - whether upper or lower triangle of S is used:
* if upper triangle is given, only S[i,j] for j>=i
are used, and lower triangle is ignored (it can be
empty - these elements are not referenced at all).
* if lower triangle is given, only S[i,j] for j<=i
are used, and upper triangle is ignored.
IsUnit - unit or non-unit diagonal:
* if True, diagonal elements of triangular matrix are
considered equal to 1.0. Actual elements stored in
S are not referenced at all.
* if False, diagonal stored in S is used
OpType - operation type:
* if 0, S*x is calculated
* if 1, (S^T)*x is calculated (transposition)
X - array[N] which stores input vector. For performance
reasons we make only quick checks - we check that
array size is at least N, but we do not check for
NAN's or INF's.
Y - possibly preallocated input buffer. Automatically
resized if its size is too small.
OUTPUT PARAMETERS
Y - array[N], op(S)*x
NOTE: this function throws exception when called for non-CRS/SKS matrix.
You must convert your matrix with SparseConvertToCRS/SKS() before using
this function.
-- ALGLIB PROJECT --
Copyright 20.01.2014 by Bochkanov Sergey
*************************************************************************/
</div><div style='margin-top: 0; margin-bottom: 0;'><b>void</b> alglib::sparsetrmv(
sparsematrix s,
<b>bool</b> isupper,
<b>bool</b> isunit,
ae_int_t optype,
real_1d_array& x,
real_1d_array& y);
</div></pre>
<a name='sub_sparsetrsv'></a><h3 class=pageheader><code>sparsetrsv</code> function</h3>
<pre class=source>
<div style='color: navy; margin-top: 0; margin-bottom: 0;'>/*************************************************************************
This function solves linear system op(S)*y=x where x is vector, S is
symmetric triangular matrix, op(S) is transposition or no operation.
Matrix S must be stored in CRS or SKS format (exception will be thrown
otherwise).
INPUT PARAMETERS
S - sparse square matrix in CRS or SKS format.
IsUpper - whether upper or lower triangle of S is used:
* if upper triangle is given, only S[i,j] for j>=i
are used, and lower triangle is ignored (it can be
empty - these elements are not referenced at all).
* if lower triangle is given, only S[i,j] for j<=i
are used, and upper triangle is ignored.
IsUnit - unit or non-unit diagonal:
* if True, diagonal elements of triangular matrix are
considered equal to 1.0. Actual elements stored in
S are not referenced at all.
* if False, diagonal stored in S is used. It is your
responsibility to make sure that diagonal is
non-zero.
OpType - operation type:
* if 0, S*x is calculated
* if 1, (S^T)*x is calculated (transposition)
X - array[N] which stores input vector. For performance
reasons we make only quick checks - we check that
array size is at least N, but we do not check for
NAN's or INF's.
OUTPUT PARAMETERS
X - array[N], inv(op(S))*x
NOTE: this function throws exception when called for non-CRS/SKS matrix.
You must convert your matrix with SparseConvertToCRS/SKS() before
using this function.
NOTE: no assertion or tests are done during algorithm operation. It is
your responsibility to provide invertible matrix to algorithm.
-- ALGLIB PROJECT --
Copyright 20.01.2014 by Bochkanov Sergey
*************************************************************************/
</div><div style='margin-top: 0; margin-bottom: 0;'><b>void</b> alglib::sparsetrsv(
sparsematrix s,
<b>bool</b> isupper,
<b>bool</b> isunit,
ae_int_t optype,
real_1d_array& x);
</div></pre>
<a name='sub_sparsevsmv'></a><h3 class=pageheader><code>sparsevsmv</code> function</h3>
<pre class=source>
<div style='color: navy; margin-top: 0; margin-bottom: 0;'>/*************************************************************************
This function calculates vector-matrix-vector product x'*S*x, where S is
symmetric matrix. Matrix S must be stored in CRS or SKS format (exception
will be thrown otherwise).
INPUT PARAMETERS
S - sparse M*M matrix in CRS or SKS format.
IsUpper - whether upper or lower triangle of S is given:
* if upper triangle is given, only S[i,j] for j>=i
are used, and lower triangle is ignored (it can be
empty - these elements are not referenced at all).
* if lower triangle is given, only S[i,j] for j<=i
are used, and upper triangle is ignored.
X - array[N], input vector. For performance reasons we
make only quick checks - we check that array size is
at least N, but we do not check for NAN's or INF's.
RESULT
x'*S*x
NOTE: this function throws exception when called for non-CRS/SKS matrix.
You must convert your matrix with SparseConvertToCRS/SKS() before using
this function.
-- ALGLIB PROJECT --
Copyright 27.01.2014 by Bochkanov Sergey
*************************************************************************/
</div><div style='margin-top: 0; margin-bottom: 0;'><b>double</b> alglib::sparsevsmv(sparsematrix s, <b>bool</b> isupper, real_1d_array x);
</div></pre>
<a name='example_sparse_d_1'></a><h3 class=pageheader>sparse_d_1 example</h3>
<pre class=source>
#include <font color=blue><b>"stdafx.h"</b></font>
#include <stdlib.h>
#include <stdio.h>
#include <math.h>
#include <font color=blue><b>"linalg.h"</b></font>
using namespace alglib;
<b>int</b> main(<b>int</b> argc, char **argv)
{
<font color=navy>//</font>
<font color=navy>// This example demonstrates creation/initialization of the sparse matrix</font>
<font color=navy>// and matrix-vector multiplication.</font>
<font color=navy>//</font>
<font color=navy>// First, we have to create matrix and initialize it. Matrix is initially created</font>
<font color=navy>// in the Hash-Table format, which allows convenient initialization. We can modify</font>
<font color=navy>// Hash-Table matrix with sparseset() and sparseadd() functions.</font>
<font color=navy>//</font>
<font color=navy>// NOTE: Unlike CRS format, Hash-Table representation allows you to initialize</font>
<font color=navy>// elements in the arbitrary order. You may see that we initialize a[0][0] first,</font>
<font color=navy>// then move to the second row, and then move back to the first row.</font>
<font color=navy>//</font>
sparsematrix s;
sparsecreate(2, 2, s);
sparseset(s, 0, 0, 2.0);
sparseset(s, 1, 1, 1.0);
sparseset(s, 0, 1, 1.0);
sparseadd(s, 1, 1, 4.0);
<font color=navy>//</font>
<font color=navy>// Now S is equal to</font>
<font color=navy>// [ 2 1 ]</font>
<font color=navy>// [ 5 ]</font>
<font color=navy>// Lets check it by reading matrix contents with sparseget().</font>
<font color=navy>// You may see that with sparseget() you may read both non-zero</font>
<font color=navy>// and zero elements.</font>
<font color=navy>//</font>
<b>double</b> v;
v = sparseget(s, 0, 0);
printf(<font color=blue><b>"%.2f\n"</b></font>, <b>double</b>(v)); <font color=navy>// EXPECTED: 2.0000</font>
v = sparseget(s, 0, 1);
printf(<font color=blue><b>"%.2f\n"</b></font>, <b>double</b>(v)); <font color=navy>// EXPECTED: 1.0000</font>
v = sparseget(s, 1, 0);
printf(<font color=blue><b>"%.2f\n"</b></font>, <b>double</b>(v)); <font color=navy>// EXPECTED: 0.0000</font>
v = sparseget(s, 1, 1);
printf(<font color=blue><b>"%.2f\n"</b></font>, <b>double</b>(v)); <font color=navy>// EXPECTED: 5.0000</font>
<font color=navy>//</font>
<font color=navy>// After successful creation we can use our matrix <b>for</b> linear operations.</font>
<font color=navy>//</font>
<font color=navy>// However, there is one more thing we MUST <b>do</b> before using S in linear</font>
<font color=navy>// operations: we have to convert it from HashTable representation (used <b>for</b></font>
<font color=navy>// initialization and dynamic operations) to CRS format with sparseconverttocrs()</font>
<font color=navy>// call. If you omit this call, ALGLIB will generate exception on the first</font>
<font color=navy>// attempt to use S in linear operations. </font>
<font color=navy>//</font>
sparseconverttocrs(s);
<font color=navy>//</font>
<font color=navy>// Now S is in the CRS format and we are ready to <b>do</b> linear operations.</font>
<font color=navy>// Lets calculate A*x <b>for</b> some x.</font>
<font color=navy>//</font>
real_1d_array x = <font color=blue><b>"[1,-1]"</b></font>;
real_1d_array y = <font color=blue><b>"[]"</b></font>;
sparsemv(s, x, y);
printf(<font color=blue><b>"%s\n"</b></font>, y.tostring(2).c_str()); <font color=navy>// EXPECTED: [1.000,-5.000]</font>
<b>return</b> 0;
}
</pre><a name='example_sparse_d_crs'></a><h3 class=pageheader>sparse_d_crs example</h3>
<pre class=source>
#include <font color=blue><b>"stdafx.h"</b></font>
#include <stdlib.h>
#include <stdio.h>
#include <math.h>
#include <font color=blue><b>"linalg.h"</b></font>
using namespace alglib;
<b>int</b> main(<b>int</b> argc, char **argv)
{
<font color=navy>//</font>
<font color=navy>// This example demonstrates creation/initialization of the sparse matrix in the</font>
<font color=navy>// CRS format.</font>
<font color=navy>//</font>
<font color=navy>// Hash-Table format used by default is very convenient (it allows easy</font>
<font color=navy>// insertion of elements, automatic memory reallocation), but has</font>
<font color=navy>// significant memory and performance overhead. Insertion of one element </font>
<font color=navy>// costs hundreds of CPU cycles, and memory consumption is several times</font>
<font color=navy>// higher than that of CRS.</font>
<font color=navy>//</font>
<font color=navy>// When you work with really large matrices and when you can tell in </font>
<font color=navy>// advance how many elements EXACTLY you need, it can be beneficial to </font>
<font color=navy>// create matrix in the CRS format from the very beginning.</font>
<font color=navy>//</font>
<font color=navy>// If you want to create matrix in the CRS format, you should:</font>
<font color=navy>// * use sparsecreatecrs() function</font>
<font color=navy>// * know row sizes in advance (number of non-zero entries in the each row)</font>
<font color=navy>// * initialize matrix with sparseset() - another function, sparseadd(), is not allowed</font>
<font color=navy>// * initialize elements from left to right, from top to bottom, each</font>
<font color=navy>// element is initialized only once.</font>
<font color=navy>//</font>
sparsematrix s;
integer_1d_array row_sizes = <font color=blue><b>"[2,2,2,1]"</b></font>;
sparsecreatecrs(4, 4, row_sizes, s);
sparseset(s, 0, 0, 2.0);
sparseset(s, 0, 1, 1.0);
sparseset(s, 1, 1, 4.0);
sparseset(s, 1, 2, 2.0);
sparseset(s, 2, 2, 3.0);
sparseset(s, 2, 3, 1.0);
sparseset(s, 3, 3, 9.0);
<font color=navy>//</font>
<font color=navy>// Now S is equal to</font>
<font color=navy>// [ 2 1 ]</font>
<font color=navy>// [ 4 2 ]</font>
<font color=navy>// [ 3 1 ]</font>
<font color=navy>// [ 9 ]</font>
<font color=navy>//</font>
<font color=navy>// We should point that we have initialized S elements from left to right,</font>
<font color=navy>// from top to bottom. CRS representation does NOT allow you to <b>do</b> so in</font>
<font color=navy>// the different order. Try to change order of the sparseset() calls above,</font>
<font color=navy>// and you will see that your program generates exception.</font>
<font color=navy>//</font>
<font color=navy>// We can check it by reading matrix contents with sparseget().</font>
<font color=navy>// However, you should remember that sparseget() is inefficient on</font>
<font color=navy>// CRS matrices (it may have to pass through all elements of the row </font>
<font color=navy>// until it finds element you need).</font>
<font color=navy>//</font>
<b>double</b> v;
v = sparseget(s, 0, 0);
printf(<font color=blue><b>"%.2f\n"</b></font>, <b>double</b>(v)); <font color=navy>// EXPECTED: 2.0000</font>
v = sparseget(s, 2, 3);
printf(<font color=blue><b>"%.2f\n"</b></font>, <b>double</b>(v)); <font color=navy>// EXPECTED: 1.0000</font>
<font color=navy>// you may see that you can read zero elements (which are not stored) with sparseget()</font>
v = sparseget(s, 3, 2);
printf(<font color=blue><b>"%.2f\n"</b></font>, <b>double</b>(v)); <font color=navy>// EXPECTED: 0.0000</font>
<font color=navy>//</font>
<font color=navy>// After successful creation we can use our matrix <b>for</b> linear operations.</font>
<font color=navy>// Lets calculate A*x <b>for</b> some x.</font>
<font color=navy>//</font>
real_1d_array x = <font color=blue><b>"[1,-1,1,-1]"</b></font>;
real_1d_array y = <font color=blue><b>"[]"</b></font>;
sparsemv(s, x, y);
printf(<font color=blue><b>"%s\n"</b></font>, y.tostring(2).c_str()); <font color=navy>// EXPECTED: [1.000,-2.000,2.000,-9]</font>
<b>return</b> 0;
}
</pre><a name=unit_spdgevd></a><h2 class=pageheader><code>spdgevd</code> subpackage</h2>
<div class=pagecontent>
<h3 class=pageheader>Functions</h3>
<a href='#sub_smatrixgevd' class=toc>smatrixgevd</a><br>
<a href='#sub_smatrixgevdreduce' class=toc>smatrixgevdreduce</a><br>
<h3 class=pageheader>Examples</h3>
<table border=0 cellspacing=0 class='pagecontent'>
</table></div>
<a name='sub_smatrixgevd'></a><h3 class=pageheader><code>smatrixgevd</code> function</h3>
<pre class=source>
<div style='color: navy; margin-top: 0; margin-bottom: 0;'>/*************************************************************************
Algorithm for solving the following generalized symmetric positive-definite
eigenproblem:
A*x = lambda*B*x (1) or
A*B*x = lambda*x (2) or
B*A*x = lambda*x (3).
where A is a symmetric matrix, B - symmetric positive-definite matrix.
The problem is solved by reducing it to an ordinary symmetric eigenvalue
problem.
Input parameters:
A - symmetric matrix which is given by its upper or lower
triangular part.
Array whose indexes range within [0..N-1, 0..N-1].
N - size of matrices A and B.
IsUpperA - storage format of matrix A.
B - symmetric positive-definite matrix which is given by
its upper or lower triangular part.
Array whose indexes range within [0..N-1, 0..N-1].
IsUpperB - storage format of matrix B.
ZNeeded - if ZNeeded is equal to:
* 0, the eigenvectors are not returned;
* 1, the eigenvectors are returned.
ProblemType - if ProblemType is equal to:
* 1, the following problem is solved: A*x = lambda*B*x;
* 2, the following problem is solved: A*B*x = lambda*x;
* 3, the following problem is solved: B*A*x = lambda*x.
Output parameters:
D - eigenvalues in ascending order.
Array whose index ranges within [0..N-1].
Z - if ZNeeded is equal to:
* 0, Z hasn�t changed;
* 1, Z contains eigenvectors.
Array whose indexes range within [0..N-1, 0..N-1].
The eigenvectors are stored in matrix columns. It should
be noted that the eigenvectors in such problems do not
form an orthogonal system.
Result:
True, if the problem was solved successfully.
False, if the error occurred during the Cholesky decomposition of matrix
B (the matrix isn�t positive-definite) or during the work of the iterative
algorithm for solving the symmetric eigenproblem.
See also the GeneralizedSymmetricDefiniteEVDReduce subroutine.
-- ALGLIB --
Copyright 1.28.2006 by Bochkanov Sergey
*************************************************************************/
</div><div style='margin-top: 0; margin-bottom: 0;'><b>bool</b> alglib::smatrixgevd(
real_2d_array a,
ae_int_t n,
<b>bool</b> isuppera,
real_2d_array b,
<b>bool</b> isupperb,
ae_int_t zneeded,
ae_int_t problemtype,
real_1d_array& d,
real_2d_array& z);
</div></pre>
<a name='sub_smatrixgevdreduce'></a><h3 class=pageheader><code>smatrixgevdreduce</code> function</h3>
<pre class=source>
<div style='color: navy; margin-top: 0; margin-bottom: 0;'>/*************************************************************************
Algorithm for reduction of the following generalized symmetric positive-
definite eigenvalue problem:
A*x = lambda*B*x (1) or
A*B*x = lambda*x (2) or
B*A*x = lambda*x (3)
to the symmetric eigenvalues problem C*y = lambda*y (eigenvalues of this and
the given problems are the same, and the eigenvectors of the given problem
could be obtained by multiplying the obtained eigenvectors by the
transformation matrix x = R*y).
Here A is a symmetric matrix, B - symmetric positive-definite matrix.
Input parameters:
A - symmetric matrix which is given by its upper or lower
triangular part.
Array whose indexes range within [0..N-1, 0..N-1].
N - size of matrices A and B.
IsUpperA - storage format of matrix A.
B - symmetric positive-definite matrix which is given by
its upper or lower triangular part.
Array whose indexes range within [0..N-1, 0..N-1].
IsUpperB - storage format of matrix B.
ProblemType - if ProblemType is equal to:
* 1, the following problem is solved: A*x = lambda*B*x;
* 2, the following problem is solved: A*B*x = lambda*x;
* 3, the following problem is solved: B*A*x = lambda*x.
Output parameters:
A - symmetric matrix which is given by its upper or lower
triangle depending on IsUpperA. Contains matrix C.
Array whose indexes range within [0..N-1, 0..N-1].
R - upper triangular or low triangular transformation matrix
which is used to obtain the eigenvectors of a given problem
as the product of eigenvectors of C (from the right) and
matrix R (from the left). If the matrix is upper
triangular, the elements below the main diagonal
are equal to 0 (and vice versa). Thus, we can perform
the multiplication without taking into account the
internal structure (which is an easier though less
effective way).
Array whose indexes range within [0..N-1, 0..N-1].
IsUpperR - type of matrix R (upper or lower triangular).
Result:
True, if the problem was reduced successfully.
False, if the error occurred during the Cholesky decomposition of
matrix B (the matrix is not positive-definite).
-- ALGLIB --
Copyright 1.28.2006 by Bochkanov Sergey
*************************************************************************/
</div><div style='margin-top: 0; margin-bottom: 0;'><b>bool</b> alglib::smatrixgevdreduce(
real_2d_array& a,
ae_int_t n,
<b>bool</b> isuppera,
real_2d_array b,
<b>bool</b> isupperb,
ae_int_t problemtype,
real_2d_array& r,
<b>bool</b>& isupperr);
</div></pre>
<a name=unit_spline1d></a><h2 class=pageheader><code>spline1d</code> subpackage</h2>
<div class=pagecontent>
<h3 class=pageheader>Classes</h3>
<a href='#struct_spline1dinterpolant' class=toc>spline1dinterpolant</a><br>
<h3 class=pageheader>Functions</h3>
<a href='#sub_spline1dbuildakima' class=toc>spline1dbuildakima</a><br>
<a href='#sub_spline1dbuildcatmullrom' class=toc>spline1dbuildcatmullrom</a><br>
<a href='#sub_spline1dbuildcubic' class=toc>spline1dbuildcubic</a><br>
<a href='#sub_spline1dbuildhermite' class=toc>spline1dbuildhermite</a><br>
<a href='#sub_spline1dbuildlinear' class=toc>spline1dbuildlinear</a><br>
<a href='#sub_spline1dbuildmonotone' class=toc>spline1dbuildmonotone</a><br>
<a href='#sub_spline1dcalc' class=toc>spline1dcalc</a><br>
<a href='#sub_spline1dconvcubic' class=toc>spline1dconvcubic</a><br>
<a href='#sub_spline1dconvdiff2cubic' class=toc>spline1dconvdiff2cubic</a><br>
<a href='#sub_spline1dconvdiffcubic' class=toc>spline1dconvdiffcubic</a><br>
<a href='#sub_spline1ddiff' class=toc>spline1ddiff</a><br>
<a href='#sub_spline1dgriddiff2cubic' class=toc>spline1dgriddiff2cubic</a><br>
<a href='#sub_spline1dgriddiffcubic' class=toc>spline1dgriddiffcubic</a><br>
<a href='#sub_spline1dintegrate' class=toc>spline1dintegrate</a><br>
<a href='#sub_spline1dlintransx' class=toc>spline1dlintransx</a><br>
<a href='#sub_spline1dlintransy' class=toc>spline1dlintransy</a><br>
<a href='#sub_spline1dunpack' class=toc>spline1dunpack</a><br>
<h3 class=pageheader>Examples</h3>
<table border=0 cellspacing=0 class='pagecontent'>
<tr align=left valign=top><td><a href='#example_spline1d_d_convdiff' class=toc>spline1d_d_convdiff</a></td><td width=15> </td><td>Resampling using cubic splines</td></tr>
<tr align=left valign=top><td><a href='#example_spline1d_d_cubic' class=toc>spline1d_d_cubic</a></td><td width=15> </td><td>Cubic spline interpolation</td></tr>
<tr align=left valign=top><td><a href='#example_spline1d_d_griddiff' class=toc>spline1d_d_griddiff</a></td><td width=15> </td><td>Differentiation on the grid using cubic splines</td></tr>
<tr align=left valign=top><td><a href='#example_spline1d_d_linear' class=toc>spline1d_d_linear</a></td><td width=15> </td><td>Piecewise linear spline interpolation</td></tr>
<tr align=left valign=top><td><a href='#example_spline1d_d_monotone' class=toc>spline1d_d_monotone</a></td><td width=15> </td><td>Monotone interpolation</td></tr>
</table></div>
<a name='struct_spline1dinterpolant'></a><h3 class=pageheader><code>spline1dinterpolant</code> class</h3>
<pre class=source>
<div style='color: navy; margin-top: 0; margin-bottom: 0;'>/*************************************************************************
1-dimensional spline interpolant
*************************************************************************/
</div><div style='margin-top: 0; margin-bottom: 0;'><b>class</b> spline1dinterpolant
{
};
</div></pre>
<a name='sub_spline1dbuildakima'></a><h3 class=pageheader><code>spline1dbuildakima</code> function</h3>
<pre class=source>
<div style='color: navy; margin-top: 0; margin-bottom: 0;'>/*************************************************************************
This subroutine builds Akima spline interpolant
INPUT PARAMETERS:
X - spline nodes, array[0..N-1]
Y - function values, array[0..N-1]
N - points count (optional):
* N>=2
* if given, only first N points are used to build spline
* if not given, automatically detected from X/Y sizes
(len(X) must be equal to len(Y))
OUTPUT PARAMETERS:
C - spline interpolant
ORDER OF POINTS
Subroutine automatically sorts points, so caller may pass unsorted array.
-- ALGLIB PROJECT --
Copyright 24.06.2007 by Bochkanov Sergey
*************************************************************************/
</div><div style='margin-top: 0; margin-bottom: 0;'><b>void</b> alglib::spline1dbuildakima(
real_1d_array x,
real_1d_array y,
spline1dinterpolant& c);
<b>void</b> alglib::spline1dbuildakima(
real_1d_array x,
real_1d_array y,
ae_int_t n,
spline1dinterpolant& c);
</div></pre>
<a name='sub_spline1dbuildcatmullrom'></a><h3 class=pageheader><code>spline1dbuildcatmullrom</code> function</h3>
<pre class=source>
<div style='color: navy; margin-top: 0; margin-bottom: 0;'>/*************************************************************************
This subroutine builds Catmull-Rom spline interpolant.
INPUT PARAMETERS:
X - spline nodes, array[0..N-1].
Y - function values, array[0..N-1].
OPTIONAL PARAMETERS:
N - points count:
* N>=2
* if given, only first N points are used to build spline
* if not given, automatically detected from X/Y sizes
(len(X) must be equal to len(Y))
BoundType - boundary condition type:
* -1 for periodic boundary condition
* 0 for parabolically terminated spline (default)
Tension - tension parameter:
* tension=0 corresponds to classic Catmull-Rom spline (default)
* 0<tension<1 corresponds to more general form - cardinal spline
OUTPUT PARAMETERS:
C - spline interpolant
ORDER OF POINTS
Subroutine automatically sorts points, so caller may pass unsorted array.
PROBLEMS WITH PERIODIC BOUNDARY CONDITIONS:
Problems with periodic boundary conditions have Y[first_point]=Y[last_point].
However, this subroutine doesn't require you to specify equal values for
the first and last points - it automatically forces them to be equal by
copying Y[first_point] (corresponds to the leftmost, minimal X[]) to
Y[last_point]. However it is recommended to pass consistent values of Y[],
i.e. to make Y[first_point]=Y[last_point].
-- ALGLIB PROJECT --
Copyright 23.06.2007 by Bochkanov Sergey
*************************************************************************/
</div><div style='margin-top: 0; margin-bottom: 0;'><b>void</b> alglib::spline1dbuildcatmullrom(
real_1d_array x,
real_1d_array y,
spline1dinterpolant& c);
<b>void</b> alglib::spline1dbuildcatmullrom(
real_1d_array x,
real_1d_array y,
ae_int_t n,
ae_int_t boundtype,
<b>double</b> tension,
spline1dinterpolant& c);
</div></pre>
<a name='sub_spline1dbuildcubic'></a><h3 class=pageheader><code>spline1dbuildcubic</code> function</h3>
<pre class=source>
<div style='color: navy; margin-top: 0; margin-bottom: 0;'>/*************************************************************************
This subroutine builds cubic spline interpolant.
INPUT PARAMETERS:
X - spline nodes, array[0..N-1].
Y - function values, array[0..N-1].
OPTIONAL PARAMETERS:
N - points count:
* N>=2
* if given, only first N points are used to build spline
* if not given, automatically detected from X/Y sizes
(len(X) must be equal to len(Y))
BoundLType - boundary condition type for the left boundary
BoundL - left boundary condition (first or second derivative,
depending on the BoundLType)
BoundRType - boundary condition type for the right boundary
BoundR - right boundary condition (first or second derivative,
depending on the BoundRType)
OUTPUT PARAMETERS:
C - spline interpolant
ORDER OF POINTS
Subroutine automatically sorts points, so caller may pass unsorted array.
SETTING BOUNDARY VALUES:
The BoundLType/BoundRType parameters can have the following values:
* -1, which corresonds to the periodic (cyclic) boundary conditions.
In this case:
* both BoundLType and BoundRType must be equal to -1.
* BoundL/BoundR are ignored
* Y[last] is ignored (it is assumed to be equal to Y[first]).
* 0, which corresponds to the parabolically terminated spline
(BoundL and/or BoundR are ignored).
* 1, which corresponds to the first derivative boundary condition
* 2, which corresponds to the second derivative boundary condition
* by default, BoundType=0 is used
PROBLEMS WITH PERIODIC BOUNDARY CONDITIONS:
Problems with periodic boundary conditions have Y[first_point]=Y[last_point].
However, this subroutine doesn't require you to specify equal values for
the first and last points - it automatically forces them to be equal by
copying Y[first_point] (corresponds to the leftmost, minimal X[]) to
Y[last_point]. However it is recommended to pass consistent values of Y[],
i.e. to make Y[first_point]=Y[last_point].
-- ALGLIB PROJECT --
Copyright 23.06.2007 by Bochkanov Sergey
*************************************************************************/
</div><div style='margin-top: 0; margin-bottom: 0;'><b>void</b> alglib::spline1dbuildcubic(
real_1d_array x,
real_1d_array y,
spline1dinterpolant& c);
<b>void</b> alglib::spline1dbuildcubic(
real_1d_array x,
real_1d_array y,
ae_int_t n,
ae_int_t boundltype,
<b>double</b> boundl,
ae_int_t boundrtype,
<b>double</b> boundr,
spline1dinterpolant& c);
</div></pre>
<a name='sub_spline1dbuildhermite'></a><h3 class=pageheader><code>spline1dbuildhermite</code> function</h3>
<pre class=source>
<div style='color: navy; margin-top: 0; margin-bottom: 0;'>/*************************************************************************
This subroutine builds Hermite spline interpolant.
INPUT PARAMETERS:
X - spline nodes, array[0..N-1]
Y - function values, array[0..N-1]
D - derivatives, array[0..N-1]
N - points count (optional):
* N>=2
* if given, only first N points are used to build spline
* if not given, automatically detected from X/Y sizes
(len(X) must be equal to len(Y))
OUTPUT PARAMETERS:
C - spline interpolant.
ORDER OF POINTS
Subroutine automatically sorts points, so caller may pass unsorted array.
-- ALGLIB PROJECT --
Copyright 23.06.2007 by Bochkanov Sergey
*************************************************************************/
</div><div style='margin-top: 0; margin-bottom: 0;'><b>void</b> alglib::spline1dbuildhermite(
real_1d_array x,
real_1d_array y,
real_1d_array d,
spline1dinterpolant& c);
<b>void</b> alglib::spline1dbuildhermite(
real_1d_array x,
real_1d_array y,
real_1d_array d,
ae_int_t n,
spline1dinterpolant& c);
</div></pre>
<a name='sub_spline1dbuildlinear'></a><h3 class=pageheader><code>spline1dbuildlinear</code> function</h3>
<pre class=source>
<div style='color: navy; margin-top: 0; margin-bottom: 0;'>/*************************************************************************
This subroutine builds linear spline interpolant
INPUT PARAMETERS:
X - spline nodes, array[0..N-1]
Y - function values, array[0..N-1]
N - points count (optional):
* N>=2
* if given, only first N points are used to build spline
* if not given, automatically detected from X/Y sizes
(len(X) must be equal to len(Y))
OUTPUT PARAMETERS:
C - spline interpolant
ORDER OF POINTS
Subroutine automatically sorts points, so caller may pass unsorted array.
-- ALGLIB PROJECT --
Copyright 24.06.2007 by Bochkanov Sergey
*************************************************************************/
</div><div style='margin-top: 0; margin-bottom: 0;'><b>void</b> alglib::spline1dbuildlinear(
real_1d_array x,
real_1d_array y,
spline1dinterpolant& c);
<b>void</b> alglib::spline1dbuildlinear(
real_1d_array x,
real_1d_array y,
ae_int_t n,
spline1dinterpolant& c);
</div></pre>
<p align=left class=pagecontent><span class=inlineheader>Examples:</span> <a href='#example_spline1d_d_linear' class=nav>[1]</a> <a href='#example_spline1d_d_cubic' class=nav>[2]</a> </p>
<a name='sub_spline1dbuildmonotone'></a><h3 class=pageheader><code>spline1dbuildmonotone</code> function</h3>
<pre class=source>
<div style='color: navy; margin-top: 0; margin-bottom: 0;'>/*************************************************************************
This function builds monotone cubic Hermite interpolant. This interpolant
is monotonic in [x(0),x(n-1)] and is constant outside of this interval.
In case y[] form non-monotonic sequence, interpolant is piecewise
monotonic. Say, for x=(0,1,2,3,4) and y=(0,1,2,1,0) interpolant will
monotonically grow at [0..2] and monotonically decrease at [2..4].
INPUT PARAMETERS:
X - spline nodes, array[0..N-1]. Subroutine automatically
sorts points, so caller may pass unsorted array.
Y - function values, array[0..N-1]
N - the number of points(N>=2).
OUTPUT PARAMETERS:
C - spline interpolant.
-- ALGLIB PROJECT --
Copyright 21.06.2012 by Bochkanov Sergey
*************************************************************************/
</div><div style='margin-top: 0; margin-bottom: 0;'><b>void</b> alglib::spline1dbuildmonotone(
real_1d_array x,
real_1d_array y,
spline1dinterpolant& c);
<b>void</b> alglib::spline1dbuildmonotone(
real_1d_array x,
real_1d_array y,
ae_int_t n,
spline1dinterpolant& c);
</div></pre>
<p align=left class=pagecontent><span class=inlineheader>Examples:</span> <a href='#example_spline1d_d_monotone' class=nav>[1]</a> </p>
<a name='sub_spline1dcalc'></a><h3 class=pageheader><code>spline1dcalc</code> function</h3>
<pre class=source>
<div style='color: navy; margin-top: 0; margin-bottom: 0;'>/*************************************************************************
This subroutine calculates the value of the spline at the given point X.
INPUT PARAMETERS:
C - spline interpolant
X - point
Result:
S(x)
-- ALGLIB PROJECT --
Copyright 23.06.2007 by Bochkanov Sergey
*************************************************************************/
</div><div style='margin-top: 0; margin-bottom: 0;'><b>double</b> alglib::spline1dcalc(spline1dinterpolant c, <b>double</b> x);
</div></pre>
<p align=left class=pagecontent><span class=inlineheader>Examples:</span> <a href='#example_spline1d_d_linear' class=nav>[1]</a> <a href='#example_spline1d_d_cubic' class=nav>[2]</a> <a href='#example_spline1d_d_monotone' class=nav>[3]</a> </p>
<a name='sub_spline1dconvcubic'></a><h3 class=pageheader><code>spline1dconvcubic</code> function</h3>
<pre class=source>
<div style='color: navy; margin-top: 0; margin-bottom: 0;'>/*************************************************************************
This function solves following problem: given table y[] of function values
at old nodes x[] and new nodes x2[], it calculates and returns table of
function values y2[] (calculated at x2[]).
This function yields same result as Spline1DBuildCubic() call followed by
sequence of Spline1DDiff() calls, but it can be several times faster when
called for ordered X[] and X2[].
INPUT PARAMETERS:
X - old spline nodes
Y - function values
X2 - new spline nodes
OPTIONAL PARAMETERS:
N - points count:
* N>=2
* if given, only first N points from X/Y are used
* if not given, automatically detected from X/Y sizes
(len(X) must be equal to len(Y))
BoundLType - boundary condition type for the left boundary
BoundL - left boundary condition (first or second derivative,
depending on the BoundLType)
BoundRType - boundary condition type for the right boundary
BoundR - right boundary condition (first or second derivative,
depending on the BoundRType)
N2 - new points count:
* N2>=2
* if given, only first N2 points from X2 are used
* if not given, automatically detected from X2 size
OUTPUT PARAMETERS:
F2 - function values at X2[]
ORDER OF POINTS
Subroutine automatically sorts points, so caller may pass unsorted array.
Function values are correctly reordered on return, so F2[I] is always
equal to S(X2[I]) independently of points order.
SETTING BOUNDARY VALUES:
The BoundLType/BoundRType parameters can have the following values:
* -1, which corresonds to the periodic (cyclic) boundary conditions.
In this case:
* both BoundLType and BoundRType must be equal to -1.
* BoundL/BoundR are ignored
* Y[last] is ignored (it is assumed to be equal to Y[first]).
* 0, which corresponds to the parabolically terminated spline
(BoundL and/or BoundR are ignored).
* 1, which corresponds to the first derivative boundary condition
* 2, which corresponds to the second derivative boundary condition
* by default, BoundType=0 is used
PROBLEMS WITH PERIODIC BOUNDARY CONDITIONS:
Problems with periodic boundary conditions have Y[first_point]=Y[last_point].
However, this subroutine doesn't require you to specify equal values for
the first and last points - it automatically forces them to be equal by
copying Y[first_point] (corresponds to the leftmost, minimal X[]) to
Y[last_point]. However it is recommended to pass consistent values of Y[],
i.e. to make Y[first_point]=Y[last_point].
-- ALGLIB PROJECT --
Copyright 03.09.2010 by Bochkanov Sergey
*************************************************************************/
</div><div style='margin-top: 0; margin-bottom: 0;'><b>void</b> alglib::spline1dconvcubic(
real_1d_array x,
real_1d_array y,
real_1d_array x2,
real_1d_array& y2);
<b>void</b> alglib::spline1dconvcubic(
real_1d_array x,
real_1d_array y,
ae_int_t n,
ae_int_t boundltype,
<b>double</b> boundl,
ae_int_t boundrtype,
<b>double</b> boundr,
real_1d_array x2,
ae_int_t n2,
real_1d_array& y2);
</div></pre>
<p align=left class=pagecontent><span class=inlineheader>Examples:</span> <a href='#example_spline1d_d_convdiff' class=nav>[1]</a> </p>
<a name='sub_spline1dconvdiff2cubic'></a><h3 class=pageheader><code>spline1dconvdiff2cubic</code> function</h3>
<pre class=source>
<div style='color: navy; margin-top: 0; margin-bottom: 0;'>/*************************************************************************
This function solves following problem: given table y[] of function values
at old nodes x[] and new nodes x2[], it calculates and returns table of
function values y2[], first and second derivatives d2[] and dd2[]
(calculated at x2[]).
This function yields same result as Spline1DBuildCubic() call followed by
sequence of Spline1DDiff() calls, but it can be several times faster when
called for ordered X[] and X2[].
INPUT PARAMETERS:
X - old spline nodes
Y - function values
X2 - new spline nodes
OPTIONAL PARAMETERS:
N - points count:
* N>=2
* if given, only first N points from X/Y are used
* if not given, automatically detected from X/Y sizes
(len(X) must be equal to len(Y))
BoundLType - boundary condition type for the left boundary
BoundL - left boundary condition (first or second derivative,
depending on the BoundLType)
BoundRType - boundary condition type for the right boundary
BoundR - right boundary condition (first or second derivative,
depending on the BoundRType)
N2 - new points count:
* N2>=2
* if given, only first N2 points from X2 are used
* if not given, automatically detected from X2 size
OUTPUT PARAMETERS:
F2 - function values at X2[]
D2 - first derivatives at X2[]
DD2 - second derivatives at X2[]
ORDER OF POINTS
Subroutine automatically sorts points, so caller may pass unsorted array.
Function values are correctly reordered on return, so F2[I] is always
equal to S(X2[I]) independently of points order.
SETTING BOUNDARY VALUES:
The BoundLType/BoundRType parameters can have the following values:
* -1, which corresonds to the periodic (cyclic) boundary conditions.
In this case:
* both BoundLType and BoundRType must be equal to -1.
* BoundL/BoundR are ignored
* Y[last] is ignored (it is assumed to be equal to Y[first]).
* 0, which corresponds to the parabolically terminated spline
(BoundL and/or BoundR are ignored).
* 1, which corresponds to the first derivative boundary condition
* 2, which corresponds to the second derivative boundary condition
* by default, BoundType=0 is used
PROBLEMS WITH PERIODIC BOUNDARY CONDITIONS:
Problems with periodic boundary conditions have Y[first_point]=Y[last_point].
However, this subroutine doesn't require you to specify equal values for
the first and last points - it automatically forces them to be equal by
copying Y[first_point] (corresponds to the leftmost, minimal X[]) to
Y[last_point]. However it is recommended to pass consistent values of Y[],
i.e. to make Y[first_point]=Y[last_point].
-- ALGLIB PROJECT --
Copyright 03.09.2010 by Bochkanov Sergey
*************************************************************************/
</div><div style='margin-top: 0; margin-bottom: 0;'><b>void</b> alglib::spline1dconvdiff2cubic(
real_1d_array x,
real_1d_array y,
real_1d_array x2,
real_1d_array& y2,
real_1d_array& d2,
real_1d_array& dd2);
<b>void</b> alglib::spline1dconvdiff2cubic(
real_1d_array x,
real_1d_array y,
ae_int_t n,
ae_int_t boundltype,
<b>double</b> boundl,
ae_int_t boundrtype,
<b>double</b> boundr,
real_1d_array x2,
ae_int_t n2,
real_1d_array& y2,
real_1d_array& d2,
real_1d_array& dd2);
</div></pre>
<p align=left class=pagecontent><span class=inlineheader>Examples:</span> <a href='#example_spline1d_d_convdiff' class=nav>[1]</a> </p>
<a name='sub_spline1dconvdiffcubic'></a><h3 class=pageheader><code>spline1dconvdiffcubic</code> function</h3>
<pre class=source>
<div style='color: navy; margin-top: 0; margin-bottom: 0;'>/*************************************************************************
This function solves following problem: given table y[] of function values
at old nodes x[] and new nodes x2[], it calculates and returns table of
function values y2[] and derivatives d2[] (calculated at x2[]).
This function yields same result as Spline1DBuildCubic() call followed by
sequence of Spline1DDiff() calls, but it can be several times faster when
called for ordered X[] and X2[].
INPUT PARAMETERS:
X - old spline nodes
Y - function values
X2 - new spline nodes
OPTIONAL PARAMETERS:
N - points count:
* N>=2
* if given, only first N points from X/Y are used
* if not given, automatically detected from X/Y sizes
(len(X) must be equal to len(Y))
BoundLType - boundary condition type for the left boundary
BoundL - left boundary condition (first or second derivative,
depending on the BoundLType)
BoundRType - boundary condition type for the right boundary
BoundR - right boundary condition (first or second derivative,
depending on the BoundRType)
N2 - new points count:
* N2>=2
* if given, only first N2 points from X2 are used
* if not given, automatically detected from X2 size
OUTPUT PARAMETERS:
F2 - function values at X2[]
D2 - first derivatives at X2[]
ORDER OF POINTS
Subroutine automatically sorts points, so caller may pass unsorted array.
Function values are correctly reordered on return, so F2[I] is always
equal to S(X2[I]) independently of points order.
SETTING BOUNDARY VALUES:
The BoundLType/BoundRType parameters can have the following values:
* -1, which corresonds to the periodic (cyclic) boundary conditions.
In this case:
* both BoundLType and BoundRType must be equal to -1.
* BoundL/BoundR are ignored
* Y[last] is ignored (it is assumed to be equal to Y[first]).
* 0, which corresponds to the parabolically terminated spline
(BoundL and/or BoundR are ignored).
* 1, which corresponds to the first derivative boundary condition
* 2, which corresponds to the second derivative boundary condition
* by default, BoundType=0 is used
PROBLEMS WITH PERIODIC BOUNDARY CONDITIONS:
Problems with periodic boundary conditions have Y[first_point]=Y[last_point].
However, this subroutine doesn't require you to specify equal values for
the first and last points - it automatically forces them to be equal by
copying Y[first_point] (corresponds to the leftmost, minimal X[]) to
Y[last_point]. However it is recommended to pass consistent values of Y[],
i.e. to make Y[first_point]=Y[last_point].
-- ALGLIB PROJECT --
Copyright 03.09.2010 by Bochkanov Sergey
*************************************************************************/
</div><div style='margin-top: 0; margin-bottom: 0;'><b>void</b> alglib::spline1dconvdiffcubic(
real_1d_array x,
real_1d_array y,
real_1d_array x2,
real_1d_array& y2,
real_1d_array& d2);
<b>void</b> alglib::spline1dconvdiffcubic(
real_1d_array x,
real_1d_array y,
ae_int_t n,
ae_int_t boundltype,
<b>double</b> boundl,
ae_int_t boundrtype,
<b>double</b> boundr,
real_1d_array x2,
ae_int_t n2,
real_1d_array& y2,
real_1d_array& d2);
</div></pre>
<p align=left class=pagecontent><span class=inlineheader>Examples:</span> <a href='#example_spline1d_d_convdiff' class=nav>[1]</a> </p>
<a name='sub_spline1ddiff'></a><h3 class=pageheader><code>spline1ddiff</code> function</h3>
<pre class=source>
<div style='color: navy; margin-top: 0; margin-bottom: 0;'>/*************************************************************************
This subroutine differentiates the spline.
INPUT PARAMETERS:
C - spline interpolant.
X - point
Result:
S - S(x)
DS - S'(x)
D2S - S''(x)
-- ALGLIB PROJECT --
Copyright 24.06.2007 by Bochkanov Sergey
*************************************************************************/
</div><div style='margin-top: 0; margin-bottom: 0;'><b>void</b> alglib::spline1ddiff(
spline1dinterpolant c,
<b>double</b> x,
<b>double</b>& s,
<b>double</b>& ds,
<b>double</b>& d2s);
</div></pre>
<a name='sub_spline1dgriddiff2cubic'></a><h3 class=pageheader><code>spline1dgriddiff2cubic</code> function</h3>
<pre class=source>
<div style='color: navy; margin-top: 0; margin-bottom: 0;'>/*************************************************************************
This function solves following problem: given table y[] of function values
at nodes x[], it calculates and returns tables of first and second
function derivatives d1[] and d2[] (calculated at the same nodes x[]).
This function yields same result as Spline1DBuildCubic() call followed by
sequence of Spline1DDiff() calls, but it can be several times faster when
called for ordered X[] and X2[].
INPUT PARAMETERS:
X - spline nodes
Y - function values
OPTIONAL PARAMETERS:
N - points count:
* N>=2
* if given, only first N points are used
* if not given, automatically detected from X/Y sizes
(len(X) must be equal to len(Y))
BoundLType - boundary condition type for the left boundary
BoundL - left boundary condition (first or second derivative,
depending on the BoundLType)
BoundRType - boundary condition type for the right boundary
BoundR - right boundary condition (first or second derivative,
depending on the BoundRType)
OUTPUT PARAMETERS:
D1 - S' values at X[]
D2 - S'' values at X[]
ORDER OF POINTS
Subroutine automatically sorts points, so caller may pass unsorted array.
Derivative values are correctly reordered on return, so D[I] is always
equal to S'(X[I]) independently of points order.
SETTING BOUNDARY VALUES:
The BoundLType/BoundRType parameters can have the following values:
* -1, which corresonds to the periodic (cyclic) boundary conditions.
In this case:
* both BoundLType and BoundRType must be equal to -1.
* BoundL/BoundR are ignored
* Y[last] is ignored (it is assumed to be equal to Y[first]).
* 0, which corresponds to the parabolically terminated spline
(BoundL and/or BoundR are ignored).
* 1, which corresponds to the first derivative boundary condition
* 2, which corresponds to the second derivative boundary condition
* by default, BoundType=0 is used
PROBLEMS WITH PERIODIC BOUNDARY CONDITIONS:
Problems with periodic boundary conditions have Y[first_point]=Y[last_point].
However, this subroutine doesn't require you to specify equal values for
the first and last points - it automatically forces them to be equal by
copying Y[first_point] (corresponds to the leftmost, minimal X[]) to
Y[last_point]. However it is recommended to pass consistent values of Y[],
i.e. to make Y[first_point]=Y[last_point].
-- ALGLIB PROJECT --
Copyright 03.09.2010 by Bochkanov Sergey
*************************************************************************/
</div><div style='margin-top: 0; margin-bottom: 0;'><b>void</b> alglib::spline1dgriddiff2cubic(
real_1d_array x,
real_1d_array y,
real_1d_array& d1,
real_1d_array& d2);
<b>void</b> alglib::spline1dgriddiff2cubic(
real_1d_array x,
real_1d_array y,
ae_int_t n,
ae_int_t boundltype,
<b>double</b> boundl,
ae_int_t boundrtype,
<b>double</b> boundr,
real_1d_array& d1,
real_1d_array& d2);
</div></pre>
<p align=left class=pagecontent><span class=inlineheader>Examples:</span> <a href='#example_spline1d_d_griddiff' class=nav>[1]</a> </p>
<a name='sub_spline1dgriddiffcubic'></a><h3 class=pageheader><code>spline1dgriddiffcubic</code> function</h3>
<pre class=source>
<div style='color: navy; margin-top: 0; margin-bottom: 0;'>/*************************************************************************
This function solves following problem: given table y[] of function values
at nodes x[], it calculates and returns table of function derivatives d[]
(calculated at the same nodes x[]).
This function yields same result as Spline1DBuildCubic() call followed by
sequence of Spline1DDiff() calls, but it can be several times faster when
called for ordered X[] and X2[].
INPUT PARAMETERS:
X - spline nodes
Y - function values
OPTIONAL PARAMETERS:
N - points count:
* N>=2
* if given, only first N points are used
* if not given, automatically detected from X/Y sizes
(len(X) must be equal to len(Y))
BoundLType - boundary condition type for the left boundary
BoundL - left boundary condition (first or second derivative,
depending on the BoundLType)
BoundRType - boundary condition type for the right boundary
BoundR - right boundary condition (first or second derivative,
depending on the BoundRType)
OUTPUT PARAMETERS:
D - derivative values at X[]
ORDER OF POINTS
Subroutine automatically sorts points, so caller may pass unsorted array.
Derivative values are correctly reordered on return, so D[I] is always
equal to S'(X[I]) independently of points order.
SETTING BOUNDARY VALUES:
The BoundLType/BoundRType parameters can have the following values:
* -1, which corresonds to the periodic (cyclic) boundary conditions.
In this case:
* both BoundLType and BoundRType must be equal to -1.
* BoundL/BoundR are ignored
* Y[last] is ignored (it is assumed to be equal to Y[first]).
* 0, which corresponds to the parabolically terminated spline
(BoundL and/or BoundR are ignored).
* 1, which corresponds to the first derivative boundary condition
* 2, which corresponds to the second derivative boundary condition
* by default, BoundType=0 is used
PROBLEMS WITH PERIODIC BOUNDARY CONDITIONS:
Problems with periodic boundary conditions have Y[first_point]=Y[last_point].
However, this subroutine doesn't require you to specify equal values for
the first and last points - it automatically forces them to be equal by
copying Y[first_point] (corresponds to the leftmost, minimal X[]) to
Y[last_point]. However it is recommended to pass consistent values of Y[],
i.e. to make Y[first_point]=Y[last_point].
-- ALGLIB PROJECT --
Copyright 03.09.2010 by Bochkanov Sergey
*************************************************************************/
</div><div style='margin-top: 0; margin-bottom: 0;'><b>void</b> alglib::spline1dgriddiffcubic(
real_1d_array x,
real_1d_array y,
real_1d_array& d);
<b>void</b> alglib::spline1dgriddiffcubic(
real_1d_array x,
real_1d_array y,
ae_int_t n,
ae_int_t boundltype,
<b>double</b> boundl,
ae_int_t boundrtype,
<b>double</b> boundr,
real_1d_array& d);
</div></pre>
<p align=left class=pagecontent><span class=inlineheader>Examples:</span> <a href='#example_spline1d_d_griddiff' class=nav>[1]</a> </p>
<a name='sub_spline1dintegrate'></a><h3 class=pageheader><code>spline1dintegrate</code> function</h3>
<pre class=source>
<div style='color: navy; margin-top: 0; margin-bottom: 0;'>/*************************************************************************
This subroutine integrates the spline.
INPUT PARAMETERS:
C - spline interpolant.
X - right bound of the integration interval [a, x],
here 'a' denotes min(x[])
Result:
integral(S(t)dt,a,x)
-- ALGLIB PROJECT --
Copyright 23.06.2007 by Bochkanov Sergey
*************************************************************************/
</div><div style='margin-top: 0; margin-bottom: 0;'><b>double</b> alglib::spline1dintegrate(spline1dinterpolant c, <b>double</b> x);
</div></pre>
<a name='sub_spline1dlintransx'></a><h3 class=pageheader><code>spline1dlintransx</code> function</h3>
<pre class=source>
<div style='color: navy; margin-top: 0; margin-bottom: 0;'>/*************************************************************************
This subroutine performs linear transformation of the spline argument.
INPUT PARAMETERS:
C - spline interpolant.
A, B- transformation coefficients: x = A*t + B
Result:
C - transformed spline
-- ALGLIB PROJECT --
Copyright 30.06.2007 by Bochkanov Sergey
*************************************************************************/
</div><div style='margin-top: 0; margin-bottom: 0;'><b>void</b> alglib::spline1dlintransx(spline1dinterpolant c, <b>double</b> a, <b>double</b> b);
</div></pre>
<a name='sub_spline1dlintransy'></a><h3 class=pageheader><code>spline1dlintransy</code> function</h3>
<pre class=source>
<div style='color: navy; margin-top: 0; margin-bottom: 0;'>/*************************************************************************
This subroutine performs linear transformation of the spline.
INPUT PARAMETERS:
C - spline interpolant.
A, B- transformation coefficients: S2(x) = A*S(x) + B
Result:
C - transformed spline
-- ALGLIB PROJECT --
Copyright 30.06.2007 by Bochkanov Sergey
*************************************************************************/
</div><div style='margin-top: 0; margin-bottom: 0;'><b>void</b> alglib::spline1dlintransy(spline1dinterpolant c, <b>double</b> a, <b>double</b> b);
</div></pre>
<a name='sub_spline1dunpack'></a><h3 class=pageheader><code>spline1dunpack</code> function</h3>
<pre class=source>
<div style='color: navy; margin-top: 0; margin-bottom: 0;'>/*************************************************************************
This subroutine unpacks the spline into the coefficients table.
INPUT PARAMETERS:
C - spline interpolant.
X - point
OUTPUT PARAMETERS:
Tbl - coefficients table, unpacked format, array[0..N-2, 0..5].
For I = 0...N-2:
Tbl[I,0] = X[i]
Tbl[I,1] = X[i+1]
Tbl[I,2] = C0
Tbl[I,3] = C1
Tbl[I,4] = C2
Tbl[I,5] = C3
On [x[i], x[i+1]] spline is equals to:
S(x) = C0 + C1*t + C2*t^2 + C3*t^3
t = x-x[i]
NOTE:
You can rebuild spline with Spline1DBuildHermite() function, which
accepts as inputs function values and derivatives at nodes, which are
easy to calculate when you have coefficients.
-- ALGLIB PROJECT --
Copyright 29.06.2007 by Bochkanov Sergey
*************************************************************************/
</div><div style='margin-top: 0; margin-bottom: 0;'><b>void</b> alglib::spline1dunpack(
spline1dinterpolant c,
ae_int_t& n,
real_2d_array& tbl);
</div></pre>
<a name='example_spline1d_d_convdiff'></a><h3 class=pageheader>spline1d_d_convdiff example</h3>
<pre class=source>
#include <font color=blue><b>"stdafx.h"</b></font>
#include <stdlib.h>
#include <stdio.h>
#include <math.h>
#include <font color=blue><b>"interpolation.h"</b></font>
using namespace alglib;
<b>int</b> main(<b>int</b> argc, char **argv)
{
<font color=navy>//</font>
<font color=navy>// We use cubic spline to <b>do</b> resampling, i.e. having</font>
<font color=navy>// values of f(x)=x^2 sampled at 5 equidistant nodes on [-1,+1]</font>
<font color=navy>// we calculate values/derivatives of cubic spline on </font>
<font color=navy>// another grid (equidistant with 9 nodes on [-1,+1])</font>
<font color=navy>// WITHOUT CONSTRUCTION OF SPLINE OBJECT.</font>
<font color=navy>//</font>
<font color=navy>// There are efficient functions spline1dconvcubic(),</font>
<font color=navy>// spline1dconvdiffcubic() and spline1dconvdiff2cubic() </font>
<font color=navy>// <b>for</b> such calculations.</font>
<font color=navy>//</font>
<font color=navy>// We use default boundary conditions ("parabolically terminated</font>
<font color=navy>// spline") because cubic spline built with such boundary conditions </font>
<font color=navy>// will exactly reproduce any quadratic f(x).</font>
<font color=navy>//</font>
<font color=navy>// Actually, we could use natural conditions, but we feel that </font>
<font color=navy>// spline which exactly reproduces f() will show us more </font>
<font color=navy>// understandable results.</font>
<font color=navy>//</font>
real_1d_array x_old = <font color=blue><b>"[-1.0,-0.5,0.0,+0.5,+1.0]"</b></font>;
real_1d_array y_old = <font color=blue><b>"[+1.0,0.25,0.0,0.25,+1.0]"</b></font>;
real_1d_array x_new = <font color=blue><b>"[-1.00,-0.75,-0.50,-0.25,0.00,+0.25,+0.50,+0.75,+1.00]"</b></font>;
real_1d_array y_new;
real_1d_array d1_new;
real_1d_array d2_new;
<font color=navy>//</font>
<font color=navy>// First, conversion without differentiation.</font>
<font color=navy>//</font>
<font color=navy>//</font>
spline1dconvcubic(x_old, y_old, x_new, y_new);
printf(<font color=blue><b>"%s\n"</b></font>, y_new.tostring(3).c_str()); <font color=navy>// EXPECTED: [1.0000, 0.5625, 0.2500, 0.0625, 0.0000, 0.0625, 0.2500, 0.5625, 1.0000]</font>
<font color=navy>//</font>
<font color=navy>// Then, conversion with differentiation (first derivatives only)</font>
<font color=navy>//</font>
<font color=navy>//</font>
spline1dconvdiffcubic(x_old, y_old, x_new, y_new, d1_new);
printf(<font color=blue><b>"%s\n"</b></font>, y_new.tostring(3).c_str()); <font color=navy>// EXPECTED: [1.0000, 0.5625, 0.2500, 0.0625, 0.0000, 0.0625, 0.2500, 0.5625, 1.0000]</font>
printf(<font color=blue><b>"%s\n"</b></font>, d1_new.tostring(3).c_str()); <font color=navy>// EXPECTED: [-2.0, -1.5, -1.0, -0.5, 0.0, 0.5, 1.0, 1.5, 2.0]</font>
<font color=navy>//</font>
<font color=navy>// Finally, conversion with first and second derivatives</font>
<font color=navy>//</font>
<font color=navy>//</font>
spline1dconvdiff2cubic(x_old, y_old, x_new, y_new, d1_new, d2_new);
printf(<font color=blue><b>"%s\n"</b></font>, y_new.tostring(3).c_str()); <font color=navy>// EXPECTED: [1.0000, 0.5625, 0.2500, 0.0625, 0.0000, 0.0625, 0.2500, 0.5625, 1.0000]</font>
printf(<font color=blue><b>"%s\n"</b></font>, d1_new.tostring(3).c_str()); <font color=navy>// EXPECTED: [-2.0, -1.5, -1.0, -0.5, 0.0, 0.5, 1.0, 1.5, 2.0]</font>
printf(<font color=blue><b>"%s\n"</b></font>, d2_new.tostring(3).c_str()); <font color=navy>// EXPECTED: [2.0, 2.0, 2.0, 2.0, 2.0, 2.0, 2.0, 2.0, 2.0]</font>
<b>return</b> 0;
}
</pre><a name='example_spline1d_d_cubic'></a><h3 class=pageheader>spline1d_d_cubic example</h3>
<pre class=source>
#include <font color=blue><b>"stdafx.h"</b></font>
#include <stdlib.h>
#include <stdio.h>
#include <math.h>
#include <font color=blue><b>"interpolation.h"</b></font>
using namespace alglib;
<b>int</b> main(<b>int</b> argc, char **argv)
{
<font color=navy>//</font>
<font color=navy>// We use cubic spline to interpolate f(x)=x^2 sampled </font>
<font color=navy>// at 5 equidistant nodes on [-1,+1].</font>
<font color=navy>//</font>
<font color=navy>// First, we use default boundary conditions ("parabolically terminated</font>
<font color=navy>// spline") because cubic spline built with such boundary conditions </font>
<font color=navy>// will exactly reproduce any quadratic f(x).</font>
<font color=navy>//</font>
<font color=navy>// Then we try to use natural boundary conditions</font>
<font color=navy>// d2S(-1)/dx^2 = 0.0</font>
<font color=navy>// d2S(+1)/dx^2 = 0.0</font>
<font color=navy>// and see that such spline interpolated f(x) with small error.</font>
<font color=navy>//</font>
real_1d_array x = <font color=blue><b>"[-1.0,-0.5,0.0,+0.5,+1.0]"</b></font>;
real_1d_array y = <font color=blue><b>"[+1.0,0.25,0.0,0.25,+1.0]"</b></font>;
<b>double</b> t = 0.25;
<b>double</b> v;
spline1dinterpolant s;
ae_int_t natural_bound_type = 2;
<font color=navy>//</font>
<font color=navy>// Test exact boundary conditions: build S(x), calculare S(0.25)</font>
<font color=navy>// (almost same as original function)</font>
<font color=navy>//</font>
spline1dbuildcubic(x, y, s);
v = spline1dcalc(s, t);
printf(<font color=blue><b>"%.4f\n"</b></font>, <b>double</b>(v)); <font color=navy>// EXPECTED: 0.0625</font>
<font color=navy>//</font>
<font color=navy>// Test natural boundary conditions: build S(x), calculare S(0.25)</font>
<font color=navy>// (small interpolation error)</font>
<font color=navy>//</font>
spline1dbuildcubic(x, y, 5, natural_bound_type, 0.0, natural_bound_type, 0.0, s);
v = spline1dcalc(s, t);
printf(<font color=blue><b>"%.3f\n"</b></font>, <b>double</b>(v)); <font color=navy>// EXPECTED: 0.0580</font>
<b>return</b> 0;
}
</pre><a name='example_spline1d_d_griddiff'></a><h3 class=pageheader>spline1d_d_griddiff example</h3>
<pre class=source>
#include <font color=blue><b>"stdafx.h"</b></font>
#include <stdlib.h>
#include <stdio.h>
#include <math.h>
#include <font color=blue><b>"interpolation.h"</b></font>
using namespace alglib;
<b>int</b> main(<b>int</b> argc, char **argv)
{
<font color=navy>//</font>
<font color=navy>// We use cubic spline to <b>do</b> grid differentiation, i.e. having</font>
<font color=navy>// values of f(x)=x^2 sampled at 5 equidistant nodes on [-1,+1]</font>
<font color=navy>// we calculate derivatives of cubic spline at nodes WITHOUT</font>
<font color=navy>// CONSTRUCTION OF SPLINE OBJECT.</font>
<font color=navy>//</font>
<font color=navy>// There are efficient functions spline1dgriddiffcubic() and</font>
<font color=navy>// spline1dgriddiff2cubic() <b>for</b> such calculations.</font>
<font color=navy>//</font>
<font color=navy>// We use default boundary conditions ("parabolically terminated</font>
<font color=navy>// spline") because cubic spline built with such boundary conditions </font>
<font color=navy>// will exactly reproduce any quadratic f(x).</font>
<font color=navy>//</font>
<font color=navy>// Actually, we could use natural conditions, but we feel that </font>
<font color=navy>// spline which exactly reproduces f() will show us more </font>
<font color=navy>// understandable results.</font>
<font color=navy>//</font>
real_1d_array x = <font color=blue><b>"[-1.0,-0.5,0.0,+0.5,+1.0]"</b></font>;
real_1d_array y = <font color=blue><b>"[+1.0,0.25,0.0,0.25,+1.0]"</b></font>;
real_1d_array d1;
real_1d_array d2;
<font color=navy>//</font>
<font color=navy>// We calculate first derivatives: they must be equal to 2*x</font>
<font color=navy>//</font>
spline1dgriddiffcubic(x, y, d1);
printf(<font color=blue><b>"%s\n"</b></font>, d1.tostring(3).c_str()); <font color=navy>// EXPECTED: [-2.0, -1.0, 0.0, +1.0, +2.0]</font>
<font color=navy>//</font>
<font color=navy>// Now test griddiff2, which returns first AND second derivatives.</font>
<font color=navy>// First derivative is 2*x, second is equal to 2.0</font>
<font color=navy>//</font>
spline1dgriddiff2cubic(x, y, d1, d2);
printf(<font color=blue><b>"%s\n"</b></font>, d1.tostring(3).c_str()); <font color=navy>// EXPECTED: [-2.0, -1.0, 0.0, +1.0, +2.0]</font>
printf(<font color=blue><b>"%s\n"</b></font>, d2.tostring(3).c_str()); <font color=navy>// EXPECTED: [ 2.0, 2.0, 2.0, 2.0, 2.0]</font>
<b>return</b> 0;
}
</pre><a name='example_spline1d_d_linear'></a><h3 class=pageheader>spline1d_d_linear example</h3>
<pre class=source>
#include <font color=blue><b>"stdafx.h"</b></font>
#include <stdlib.h>
#include <stdio.h>
#include <math.h>
#include <font color=blue><b>"interpolation.h"</b></font>
using namespace alglib;
<b>int</b> main(<b>int</b> argc, char **argv)
{
<font color=navy>//</font>
<font color=navy>// We use piecewise linear spline to interpolate f(x)=x^2 sampled </font>
<font color=navy>// at 5 equidistant nodes on [-1,+1].</font>
<font color=navy>//</font>
real_1d_array x = <font color=blue><b>"[-1.0,-0.5,0.0,+0.5,+1.0]"</b></font>;
real_1d_array y = <font color=blue><b>"[+1.0,0.25,0.0,0.25,+1.0]"</b></font>;
<b>double</b> t = 0.25;
<b>double</b> v;
spline1dinterpolant s;
<font color=navy>// build spline</font>
spline1dbuildlinear(x, y, s);
<font color=navy>// calculate S(0.25) - it is quite different from 0.25^2=0.0625</font>
v = spline1dcalc(s, t);
printf(<font color=blue><b>"%.4f\n"</b></font>, <b>double</b>(v)); <font color=navy>// EXPECTED: 0.125</font>
<b>return</b> 0;
}
</pre><a name='example_spline1d_d_monotone'></a><h3 class=pageheader>spline1d_d_monotone example</h3>
<pre class=source>
#include <font color=blue><b>"stdafx.h"</b></font>
#include <stdlib.h>
#include <stdio.h>
#include <math.h>
#include <font color=blue><b>"interpolation.h"</b></font>
using namespace alglib;
<b>int</b> main(<b>int</b> argc, char **argv)
{
<font color=navy>//</font>
<font color=navy>// Spline built witn spline1dbuildcubic() can be non-monotone even when</font>
<font color=navy>// Y-values form monotone sequence. Say, <b>for</b> x=[0,1,2] and y=[0,1,1]</font>
<font color=navy>// cubic spline will monotonically grow until x=1.5 and then start</font>
<font color=navy>// decreasing.</font>
<font color=navy>//</font>
<font color=navy>// That's why ALGLIB provides special spline construction function</font>
<font color=navy>// which builds spline which preserves monotonicity of the original</font>
<font color=navy>// dataset.</font>
<font color=navy>//</font>
<font color=navy>// NOTE: in case original dataset is non-monotonic, ALGLIB splits it</font>
<font color=navy>// into monotone subsequences and builds piecewise monotonic spline.</font>
<font color=navy>//</font>
real_1d_array x = <font color=blue><b>"[0,1,2]"</b></font>;
real_1d_array y = <font color=blue><b>"[0,1,1]"</b></font>;
spline1dinterpolant s;
<font color=navy>// build spline</font>
spline1dbuildmonotone(x, y, s);
<font color=navy>// calculate S at x = [-0.5, 0.0, 0.5, 1.0, 1.5, 2.0]</font>
<font color=navy>// you may see that spline is really monotonic</font>
<b>double</b> v;
v = spline1dcalc(s, -0.5);
printf(<font color=blue><b>"%.4f\n"</b></font>, <b>double</b>(v)); <font color=navy>// EXPECTED: 0.0000</font>
v = spline1dcalc(s, 0.0);
printf(<font color=blue><b>"%.4f\n"</b></font>, <b>double</b>(v)); <font color=navy>// EXPECTED: 0.0000</font>
v = spline1dcalc(s, +0.5);
printf(<font color=blue><b>"%.4f\n"</b></font>, <b>double</b>(v)); <font color=navy>// EXPECTED: 0.5000</font>
v = spline1dcalc(s, 1.0);
printf(<font color=blue><b>"%.4f\n"</b></font>, <b>double</b>(v)); <font color=navy>// EXPECTED: 1.0000</font>
v = spline1dcalc(s, 1.5);
printf(<font color=blue><b>"%.4f\n"</b></font>, <b>double</b>(v)); <font color=navy>// EXPECTED: 1.0000</font>
v = spline1dcalc(s, 2.0);
printf(<font color=blue><b>"%.4f\n"</b></font>, <b>double</b>(v)); <font color=navy>// EXPECTED: 1.0000</font>
<b>return</b> 0;
}
</pre><a name=unit_spline2d></a><h2 class=pageheader><code>spline2d</code> subpackage</h2>
<div class=pagecontent>
<h3 class=pageheader>Classes</h3>
<a href='#struct_spline2dinterpolant' class=toc>spline2dinterpolant</a><br>
<h3 class=pageheader>Functions</h3>
<a href='#sub_spline2dbuildbicubic' class=toc>spline2dbuildbicubic</a><br>
<a href='#sub_spline2dbuildbicubicv' class=toc>spline2dbuildbicubicv</a><br>
<a href='#sub_spline2dbuildbilinear' class=toc>spline2dbuildbilinear</a><br>
<a href='#sub_spline2dbuildbilinearv' class=toc>spline2dbuildbilinearv</a><br>
<a href='#sub_spline2dcalc' class=toc>spline2dcalc</a><br>
<a href='#sub_spline2dcalcv' class=toc>spline2dcalcv</a><br>
<a href='#sub_spline2dcalcvbuf' class=toc>spline2dcalcvbuf</a><br>
<a href='#sub_spline2dcopy' class=toc>spline2dcopy</a><br>
<a href='#sub_spline2ddiff' class=toc>spline2ddiff</a><br>
<a href='#sub_spline2dlintransf' class=toc>spline2dlintransf</a><br>
<a href='#sub_spline2dlintransxy' class=toc>spline2dlintransxy</a><br>
<a href='#sub_spline2dresamplebicubic' class=toc>spline2dresamplebicubic</a><br>
<a href='#sub_spline2dresamplebilinear' class=toc>spline2dresamplebilinear</a><br>
<a href='#sub_spline2dunpack' class=toc>spline2dunpack</a><br>
<a href='#sub_spline2dunpackv' class=toc>spline2dunpackv</a><br>
<h3 class=pageheader>Examples</h3>
<table border=0 cellspacing=0 class='pagecontent'>
<tr align=left valign=top><td><a href='#example_spline2d_bicubic' class=toc>spline2d_bicubic</a></td><td width=15> </td><td>Bilinear spline interpolation</td></tr>
<tr align=left valign=top><td><a href='#example_spline2d_bilinear' class=toc>spline2d_bilinear</a></td><td width=15> </td><td>Bilinear spline interpolation</td></tr>
<tr align=left valign=top><td><a href='#example_spline2d_copytrans' class=toc>spline2d_copytrans</a></td><td width=15> </td><td>Copy and transform</td></tr>
<tr align=left valign=top><td><a href='#example_spline2d_unpack' class=toc>spline2d_unpack</a></td><td width=15> </td><td>Unpacking bilinear spline</td></tr>
<tr align=left valign=top><td><a href='#example_spline2d_vector' class=toc>spline2d_vector</a></td><td width=15> </td><td>Copy and transform</td></tr>
</table></div>
<a name='struct_spline2dinterpolant'></a><h3 class=pageheader><code>spline2dinterpolant</code> class</h3>
<pre class=source>
<div style='color: navy; margin-top: 0; margin-bottom: 0;'>/*************************************************************************
2-dimensional spline inteprolant
*************************************************************************/
</div><div style='margin-top: 0; margin-bottom: 0;'><b>class</b> spline2dinterpolant
{
};
</div></pre>
<a name='sub_spline2dbuildbicubic'></a><h3 class=pageheader><code>spline2dbuildbicubic</code> function</h3>
<pre class=source>
<div style='color: navy; margin-top: 0; margin-bottom: 0;'>/*************************************************************************
This subroutine was deprecated in ALGLIB 3.6.0
We recommend you to switch to Spline2DBuildBicubicV(), which is more
flexible and accepts its arguments in more convenient order.
-- ALGLIB PROJECT --
Copyright 05.07.2007 by Bochkanov Sergey
*************************************************************************/
</div><div style='margin-top: 0; margin-bottom: 0;'><b>void</b> alglib::spline2dbuildbicubic(
real_1d_array x,
real_1d_array y,
real_2d_array f,
ae_int_t m,
ae_int_t n,
spline2dinterpolant& c);
</div></pre>
<a name='sub_spline2dbuildbicubicv'></a><h3 class=pageheader><code>spline2dbuildbicubicv</code> function</h3>
<pre class=source>
<div style='color: navy; margin-top: 0; margin-bottom: 0;'>/*************************************************************************
This subroutine builds bicubic vector-valued spline.
Input parameters:
X - spline abscissas, array[0..N-1]
Y - spline ordinates, array[0..M-1]
F - function values, array[0..M*N*D-1]:
* first D elements store D values at (X[0],Y[0])
* next D elements store D values at (X[1],Y[0])
* general form - D function values at (X[i],Y[j]) are stored
at F[D*(J*N+I)...D*(J*N+I)+D-1].
M,N - grid size, M>=2, N>=2
D - vector dimension, D>=1
Output parameters:
C - spline interpolant
-- ALGLIB PROJECT --
Copyright 16.04.2012 by Bochkanov Sergey
*************************************************************************/
</div><div style='margin-top: 0; margin-bottom: 0;'><b>void</b> alglib::spline2dbuildbicubicv(
real_1d_array x,
ae_int_t n,
real_1d_array y,
ae_int_t m,
real_1d_array f,
ae_int_t d,
spline2dinterpolant& c);
</div></pre>
<p align=left class=pagecontent><span class=inlineheader>Examples:</span> <a href='#example_spline2d_bicubic' class=nav>[1]</a> </p>
<a name='sub_spline2dbuildbilinear'></a><h3 class=pageheader><code>spline2dbuildbilinear</code> function</h3>
<pre class=source>
<div style='color: navy; margin-top: 0; margin-bottom: 0;'>/*************************************************************************
This subroutine was deprecated in ALGLIB 3.6.0
We recommend you to switch to Spline2DBuildBilinearV(), which is more
flexible and accepts its arguments in more convenient order.
-- ALGLIB PROJECT --
Copyright 05.07.2007 by Bochkanov Sergey
*************************************************************************/
</div><div style='margin-top: 0; margin-bottom: 0;'><b>void</b> alglib::spline2dbuildbilinear(
real_1d_array x,
real_1d_array y,
real_2d_array f,
ae_int_t m,
ae_int_t n,
spline2dinterpolant& c);
</div></pre>
<a name='sub_spline2dbuildbilinearv'></a><h3 class=pageheader><code>spline2dbuildbilinearv</code> function</h3>
<pre class=source>
<div style='color: navy; margin-top: 0; margin-bottom: 0;'>/*************************************************************************
This subroutine builds bilinear vector-valued spline.
Input parameters:
X - spline abscissas, array[0..N-1]
Y - spline ordinates, array[0..M-1]
F - function values, array[0..M*N*D-1]:
* first D elements store D values at (X[0],Y[0])
* next D elements store D values at (X[1],Y[0])
* general form - D function values at (X[i],Y[j]) are stored
at F[D*(J*N+I)...D*(J*N+I)+D-1].
M,N - grid size, M>=2, N>=2
D - vector dimension, D>=1
Output parameters:
C - spline interpolant
-- ALGLIB PROJECT --
Copyright 16.04.2012 by Bochkanov Sergey
*************************************************************************/
</div><div style='margin-top: 0; margin-bottom: 0;'><b>void</b> alglib::spline2dbuildbilinearv(
real_1d_array x,
ae_int_t n,
real_1d_array y,
ae_int_t m,
real_1d_array f,
ae_int_t d,
spline2dinterpolant& c);
</div></pre>
<p align=left class=pagecontent><span class=inlineheader>Examples:</span> <a href='#example_spline2d_bilinear' class=nav>[1]</a> <a href='#example_spline2d_vector' class=nav>[2]</a> </p>
<a name='sub_spline2dcalc'></a><h3 class=pageheader><code>spline2dcalc</code> function</h3>
<pre class=source>
<div style='color: navy; margin-top: 0; margin-bottom: 0;'>/*************************************************************************
This subroutine calculates the value of the bilinear or bicubic spline at
the given point X.
Input parameters:
C - coefficients table.
Built by BuildBilinearSpline or BuildBicubicSpline.
X, Y- point
Result:
S(x,y)
-- ALGLIB PROJECT --
Copyright 05.07.2007 by Bochkanov Sergey
*************************************************************************/
</div><div style='margin-top: 0; margin-bottom: 0;'><b>double</b> alglib::spline2dcalc(spline2dinterpolant c, <b>double</b> x, <b>double</b> y);
</div></pre>
<p align=left class=pagecontent><span class=inlineheader>Examples:</span> <a href='#example_spline2d_bilinear' class=nav>[1]</a> <a href='#example_spline2d_bicubic' class=nav>[2]</a> </p>
<a name='sub_spline2dcalcv'></a><h3 class=pageheader><code>spline2dcalcv</code> function</h3>
<pre class=source>
<div style='color: navy; margin-top: 0; margin-bottom: 0;'>/*************************************************************************
This subroutine calculates bilinear or bicubic vector-valued spline at the
given point (X,Y).
INPUT PARAMETERS:
C - spline interpolant.
X, Y- point
OUTPUT PARAMETERS:
F - array[D] which stores function values. F is out-parameter and
it is reallocated after call to this function. In case you
want to reuse previously allocated F, you may use
Spline2DCalcVBuf(), which reallocates F only when it is too
small.
-- ALGLIB PROJECT --
Copyright 16.04.2012 by Bochkanov Sergey
*************************************************************************/
</div><div style='margin-top: 0; margin-bottom: 0;'><b>void</b> alglib::spline2dcalcv(
spline2dinterpolant c,
<b>double</b> x,
<b>double</b> y,
real_1d_array& f);
</div></pre>
<p align=left class=pagecontent><span class=inlineheader>Examples:</span> <a href='#example_spline2d_vector' class=nav>[1]</a> </p>
<a name='sub_spline2dcalcvbuf'></a><h3 class=pageheader><code>spline2dcalcvbuf</code> function</h3>
<pre class=source>
<div style='color: navy; margin-top: 0; margin-bottom: 0;'>/*************************************************************************
This subroutine calculates bilinear or bicubic vector-valued spline at the
given point (X,Y).
INPUT PARAMETERS:
C - spline interpolant.
X, Y- point
F - output buffer, possibly preallocated array. In case array size
is large enough to store result, it is not reallocated. Array
which is too short will be reallocated
OUTPUT PARAMETERS:
F - array[D] (or larger) which stores function values
-- ALGLIB PROJECT --
Copyright 16.04.2012 by Bochkanov Sergey
*************************************************************************/
</div><div style='margin-top: 0; margin-bottom: 0;'><b>void</b> alglib::spline2dcalcvbuf(
spline2dinterpolant c,
<b>double</b> x,
<b>double</b> y,
real_1d_array& f);
</div></pre>
<a name='sub_spline2dcopy'></a><h3 class=pageheader><code>spline2dcopy</code> function</h3>
<pre class=source>
<div style='color: navy; margin-top: 0; margin-bottom: 0;'>/*************************************************************************
This subroutine makes the copy of the spline model.
Input parameters:
C - spline interpolant
Output parameters:
CC - spline copy
-- ALGLIB PROJECT --
Copyright 29.06.2007 by Bochkanov Sergey
*************************************************************************/
</div><div style='margin-top: 0; margin-bottom: 0;'><b>void</b> alglib::spline2dcopy(spline2dinterpolant c, spline2dinterpolant& cc);
</div></pre>
<p align=left class=pagecontent><span class=inlineheader>Examples:</span> <a href='#example_spline2d_copytrans' class=nav>[1]</a> </p>
<a name='sub_spline2ddiff'></a><h3 class=pageheader><code>spline2ddiff</code> function</h3>
<pre class=source>
<div style='color: navy; margin-top: 0; margin-bottom: 0;'>/*************************************************************************
This subroutine calculates the value of the bilinear or bicubic spline at
the given point X and its derivatives.
Input parameters:
C - spline interpolant.
X, Y- point
Output parameters:
F - S(x,y)
FX - dS(x,y)/dX
FY - dS(x,y)/dY
FXY - d2S(x,y)/dXdY
-- ALGLIB PROJECT --
Copyright 05.07.2007 by Bochkanov Sergey
*************************************************************************/
</div><div style='margin-top: 0; margin-bottom: 0;'><b>void</b> alglib::spline2ddiff(
spline2dinterpolant c,
<b>double</b> x,
<b>double</b> y,
<b>double</b>& f,
<b>double</b>& fx,
<b>double</b>& fy,
<b>double</b>& fxy);
</div></pre>
<a name='sub_spline2dlintransf'></a><h3 class=pageheader><code>spline2dlintransf</code> function</h3>
<pre class=source>
<div style='color: navy; margin-top: 0; margin-bottom: 0;'>/*************************************************************************
This subroutine performs linear transformation of the spline.
Input parameters:
C - spline interpolant.
A, B- transformation coefficients: S2(x,y) = A*S(x,y) + B
Output parameters:
C - transformed spline
-- ALGLIB PROJECT --
Copyright 30.06.2007 by Bochkanov Sergey
*************************************************************************/
</div><div style='margin-top: 0; margin-bottom: 0;'><b>void</b> alglib::spline2dlintransf(spline2dinterpolant c, <b>double</b> a, <b>double</b> b);
</div></pre>
<p align=left class=pagecontent><span class=inlineheader>Examples:</span> <a href='#example_spline2d_copytrans' class=nav>[1]</a> </p>
<a name='sub_spline2dlintransxy'></a><h3 class=pageheader><code>spline2dlintransxy</code> function</h3>
<pre class=source>
<div style='color: navy; margin-top: 0; margin-bottom: 0;'>/*************************************************************************
This subroutine performs linear transformation of the spline argument.
Input parameters:
C - spline interpolant
AX, BX - transformation coefficients: x = A*t + B
AY, BY - transformation coefficients: y = A*u + B
Result:
C - transformed spline
-- ALGLIB PROJECT --
Copyright 30.06.2007 by Bochkanov Sergey
*************************************************************************/
</div><div style='margin-top: 0; margin-bottom: 0;'><b>void</b> alglib::spline2dlintransxy(
spline2dinterpolant c,
<b>double</b> ax,
<b>double</b> bx,
<b>double</b> ay,
<b>double</b> by);
</div></pre>
<p align=left class=pagecontent><span class=inlineheader>Examples:</span> <a href='#example_spline2d_copytrans' class=nav>[1]</a> </p>
<a name='sub_spline2dresamplebicubic'></a><h3 class=pageheader><code>spline2dresamplebicubic</code> function</h3>
<pre class=source>
<div style='color: navy; margin-top: 0; margin-bottom: 0;'>/*************************************************************************
Bicubic spline resampling
Input parameters:
A - function values at the old grid,
array[0..OldHeight-1, 0..OldWidth-1]
OldHeight - old grid height, OldHeight>1
OldWidth - old grid width, OldWidth>1
NewHeight - new grid height, NewHeight>1
NewWidth - new grid width, NewWidth>1
Output parameters:
B - function values at the new grid,
array[0..NewHeight-1, 0..NewWidth-1]
-- ALGLIB routine --
15 May, 2007
Copyright by Bochkanov Sergey
*************************************************************************/
</div><div style='margin-top: 0; margin-bottom: 0;'><b>void</b> alglib::spline2dresamplebicubic(
real_2d_array a,
ae_int_t oldheight,
ae_int_t oldwidth,
real_2d_array& b,
ae_int_t newheight,
ae_int_t newwidth);
</div></pre>
<a name='sub_spline2dresamplebilinear'></a><h3 class=pageheader><code>spline2dresamplebilinear</code> function</h3>
<pre class=source>
<div style='color: navy; margin-top: 0; margin-bottom: 0;'>/*************************************************************************
Bilinear spline resampling
Input parameters:
A - function values at the old grid,
array[0..OldHeight-1, 0..OldWidth-1]
OldHeight - old grid height, OldHeight>1
OldWidth - old grid width, OldWidth>1
NewHeight - new grid height, NewHeight>1
NewWidth - new grid width, NewWidth>1
Output parameters:
B - function values at the new grid,
array[0..NewHeight-1, 0..NewWidth-1]
-- ALGLIB routine --
09.07.2007
Copyright by Bochkanov Sergey
*************************************************************************/
</div><div style='margin-top: 0; margin-bottom: 0;'><b>void</b> alglib::spline2dresamplebilinear(
real_2d_array a,
ae_int_t oldheight,
ae_int_t oldwidth,
real_2d_array& b,
ae_int_t newheight,
ae_int_t newwidth);
</div></pre>
<a name='sub_spline2dunpack'></a><h3 class=pageheader><code>spline2dunpack</code> function</h3>
<pre class=source>
<div style='color: navy; margin-top: 0; margin-bottom: 0;'>/*************************************************************************
This subroutine was deprecated in ALGLIB 3.6.0
We recommend you to switch to Spline2DUnpackV(), which is more flexible
and accepts its arguments in more convenient order.
-- ALGLIB PROJECT --
Copyright 29.06.2007 by Bochkanov Sergey
*************************************************************************/
</div><div style='margin-top: 0; margin-bottom: 0;'><b>void</b> alglib::spline2dunpack(
spline2dinterpolant c,
ae_int_t& m,
ae_int_t& n,
real_2d_array& tbl);
</div></pre>
<a name='sub_spline2dunpackv'></a><h3 class=pageheader><code>spline2dunpackv</code> function</h3>
<pre class=source>
<div style='color: navy; margin-top: 0; margin-bottom: 0;'>/*************************************************************************
This subroutine unpacks two-dimensional spline into the coefficients table
Input parameters:
C - spline interpolant.
Result:
M, N- grid size (x-axis and y-axis)
D - number of components
Tbl - coefficients table, unpacked format,
D - components: [0..(N-1)*(M-1)*D-1, 0..19].
For T=0..D-1 (component index), I = 0...N-2 (x index),
J=0..M-2 (y index):
K := T + I*D + J*D*(N-1)
K-th row stores decomposition for T-th component of the
vector-valued function
Tbl[K,0] = X[i]
Tbl[K,1] = X[i+1]
Tbl[K,2] = Y[j]
Tbl[K,3] = Y[j+1]
Tbl[K,4] = C00
Tbl[K,5] = C01
Tbl[K,6] = C02
Tbl[K,7] = C03
Tbl[K,8] = C10
Tbl[K,9] = C11
...
Tbl[K,19] = C33
On each grid square spline is equals to:
S(x) = SUM(c[i,j]*(t^i)*(u^j), i=0..3, j=0..3)
t = x-x[j]
u = y-y[i]
-- ALGLIB PROJECT --
Copyright 16.04.2012 by Bochkanov Sergey
*************************************************************************/
</div><div style='margin-top: 0; margin-bottom: 0;'><b>void</b> alglib::spline2dunpackv(
spline2dinterpolant c,
ae_int_t& m,
ae_int_t& n,
ae_int_t& d,
real_2d_array& tbl);
</div></pre>
<p align=left class=pagecontent><span class=inlineheader>Examples:</span> <a href='#example_spline2d_unpack' class=nav>[1]</a> </p>
<a name='example_spline2d_bicubic'></a><h3 class=pageheader>spline2d_bicubic example</h3>
<pre class=source>
#include <font color=blue><b>"stdafx.h"</b></font>
#include <stdlib.h>
#include <stdio.h>
#include <math.h>
#include <font color=blue><b>"interpolation.h"</b></font>
using namespace alglib;
<b>int</b> main(<b>int</b> argc, char **argv)
{
<font color=navy>//</font>
<font color=navy>// We use bilinear spline to interpolate f(x,y)=x^2+2*y^2 sampled </font>
<font color=navy>// at (x,y) from [0.0, 0.5, 1.0] X [0.0, 1.0].</font>
<font color=navy>//</font>
real_1d_array x = <font color=blue><b>"[0.0, 0.5, 1.0]"</b></font>;
real_1d_array y = <font color=blue><b>"[0.0, 1.0]"</b></font>;
real_1d_array f = <font color=blue><b>"[0.00,0.25,1.00,2.00,2.25,3.00]"</b></font>;
<b>double</b> vx = 0.25;
<b>double</b> vy = 0.50;
<b>double</b> v;
<b>double</b> dx;
<b>double</b> dy;
<b>double</b> dxy;
spline2dinterpolant s;
<font color=navy>// build spline</font>
spline2dbuildbicubicv(x, 3, y, 2, f, 1, s);
<font color=navy>// calculate S(0.25,0.50)</font>
v = spline2dcalc(s, vx, vy);
printf(<font color=blue><b>"%.4f\n"</b></font>, <b>double</b>(v)); <font color=navy>// EXPECTED: 1.0625</font>
<font color=navy>// calculate derivatives</font>
spline2ddiff(s, vx, vy, v, dx, dy, dxy);
printf(<font color=blue><b>"%.4f\n"</b></font>, <b>double</b>(v)); <font color=navy>// EXPECTED: 1.0625</font>
printf(<font color=blue><b>"%.4f\n"</b></font>, <b>double</b>(dx)); <font color=navy>// EXPECTED: 0.5000</font>
printf(<font color=blue><b>"%.4f\n"</b></font>, <b>double</b>(dy)); <font color=navy>// EXPECTED: 2.0000</font>
<b>return</b> 0;
}
</pre><a name='example_spline2d_bilinear'></a><h3 class=pageheader>spline2d_bilinear example</h3>
<pre class=source>
#include <font color=blue><b>"stdafx.h"</b></font>
#include <stdlib.h>
#include <stdio.h>
#include <math.h>
#include <font color=blue><b>"interpolation.h"</b></font>
using namespace alglib;
<b>int</b> main(<b>int</b> argc, char **argv)
{
<font color=navy>//</font>
<font color=navy>// We use bilinear spline to interpolate f(x,y)=x^2+2*y^2 sampled </font>
<font color=navy>// at (x,y) from [0.0, 0.5, 1.0] X [0.0, 1.0].</font>
<font color=navy>//</font>
real_1d_array x = <font color=blue><b>"[0.0, 0.5, 1.0]"</b></font>;
real_1d_array y = <font color=blue><b>"[0.0, 1.0]"</b></font>;
real_1d_array f = <font color=blue><b>"[0.00,0.25,1.00,2.00,2.25,3.00]"</b></font>;
<b>double</b> vx = 0.25;
<b>double</b> vy = 0.50;
<b>double</b> v;
spline2dinterpolant s;
<font color=navy>// build spline</font>
spline2dbuildbilinearv(x, 3, y, 2, f, 1, s);
<font color=navy>// calculate S(0.25,0.50)</font>
v = spline2dcalc(s, vx, vy);
printf(<font color=blue><b>"%.4f\n"</b></font>, <b>double</b>(v)); <font color=navy>// EXPECTED: 1.1250</font>
<b>return</b> 0;
}
</pre><a name='example_spline2d_copytrans'></a><h3 class=pageheader>spline2d_copytrans example</h3>
<pre class=source>
#include <font color=blue><b>"stdafx.h"</b></font>
#include <stdlib.h>
#include <stdio.h>
#include <math.h>
#include <font color=blue><b>"interpolation.h"</b></font>
using namespace alglib;
<b>int</b> main(<b>int</b> argc, char **argv)
{
<font color=navy>//</font>
<font color=navy>// We build bilinear spline <b>for</b> f(x,y)=x+2*y <b>for</b> (x,y) in [0,1].</font>
<font color=navy>// Then we apply several transformations to this spline.</font>
<font color=navy>//</font>
real_1d_array x = <font color=blue><b>"[0.0, 1.0]"</b></font>;
real_1d_array y = <font color=blue><b>"[0.0, 1.0]"</b></font>;
real_1d_array f = <font color=blue><b>"[0.00,1.00,2.00,3.00]"</b></font>;
spline2dinterpolant s;
spline2dinterpolant snew;
<b>double</b> v;
spline2dbuildbilinearv(x, 2, y, 2, f, 1, s);
<font color=navy>// copy spline, apply transformation x:=2*xnew, y:=4*ynew</font>
<font color=navy>// evaluate at (xnew,ynew) = (0.25,0.25) - should be same as (x,y)=(0.5,1.0)</font>
spline2dcopy(s, snew);
spline2dlintransxy(snew, 2.0, 0.0, 4.0, 0.0);
v = spline2dcalc(snew, 0.25, 0.25);
printf(<font color=blue><b>"%.4f\n"</b></font>, <b>double</b>(v)); <font color=navy>// EXPECTED: 2.500</font>
<font color=navy>// copy spline, apply transformation SNew:=2*S+3</font>
spline2dcopy(s, snew);
spline2dlintransf(snew, 2.0, 3.0);
v = spline2dcalc(snew, 0.5, 1.0);
printf(<font color=blue><b>"%.4f\n"</b></font>, <b>double</b>(v)); <font color=navy>// EXPECTED: 8.000</font>
<font color=navy>//</font>
<font color=navy>// Same example, but <b>for</b> vector spline (f0,f1) = {x+2*y, 2*x+y}</font>
<font color=navy>//</font>
real_1d_array f2 = <font color=blue><b>"[0.00,0.00, 1.00,2.00, 2.00,1.00, 3.00,3.00]"</b></font>;
real_1d_array vr;
spline2dbuildbilinearv(x, 2, y, 2, f2, 2, s);
<font color=navy>// copy spline, apply transformation x:=2*xnew, y:=4*ynew</font>
spline2dcopy(s, snew);
spline2dlintransxy(snew, 2.0, 0.0, 4.0, 0.0);
spline2dcalcv(snew, 0.25, 0.25, vr);
printf(<font color=blue><b>"%s\n"</b></font>, vr.tostring(4).c_str()); <font color=navy>// EXPECTED: [2.500,2.000]</font>
<font color=navy>// copy spline, apply transformation SNew:=2*S+3</font>
spline2dcopy(s, snew);
spline2dlintransf(snew, 2.0, 3.0);
spline2dcalcv(snew, 0.5, 1.0, vr);
printf(<font color=blue><b>"%s\n"</b></font>, vr.tostring(4).c_str()); <font color=navy>// EXPECTED: [8.000,7.000]</font>
<b>return</b> 0;
}
</pre><a name='example_spline2d_unpack'></a><h3 class=pageheader>spline2d_unpack example</h3>
<pre class=source>
#include <font color=blue><b>"stdafx.h"</b></font>
#include <stdlib.h>
#include <stdio.h>
#include <math.h>
#include <font color=blue><b>"interpolation.h"</b></font>
using namespace alglib;
<b>int</b> main(<b>int</b> argc, char **argv)
{
<font color=navy>//</font>
<font color=navy>// We build bilinear spline <b>for</b> f(x,y)=x+2*y+3*xy <b>for</b> (x,y) in [0,1].</font>
<font color=navy>// Then we demonstrate how to unpack it.</font>
<font color=navy>//</font>
real_1d_array x = <font color=blue><b>"[0.0, 1.0]"</b></font>;
real_1d_array y = <font color=blue><b>"[0.0, 1.0]"</b></font>;
real_1d_array f = <font color=blue><b>"[0.00,1.00,2.00,6.00]"</b></font>;
real_2d_array c;
ae_int_t m;
ae_int_t n;
ae_int_t d;
spline2dinterpolant s;
<font color=navy>// build spline</font>
spline2dbuildbilinearv(x, 2, y, 2, f, 1, s);
<font color=navy>// unpack and test</font>
spline2dunpackv(s, m, n, d, c);
printf(<font color=blue><b>"%s\n"</b></font>, c.tostring(4).c_str()); <font color=navy>// EXPECTED: [[0, 1, 0, 1, 0,2,0,0, 1,3,0,0, 0,0,0,0, 0,0,0,0 ]]</font>
<b>return</b> 0;
}
</pre><a name='example_spline2d_vector'></a><h3 class=pageheader>spline2d_vector example</h3>
<pre class=source>
#include <font color=blue><b>"stdafx.h"</b></font>
#include <stdlib.h>
#include <stdio.h>
#include <math.h>
#include <font color=blue><b>"interpolation.h"</b></font>
using namespace alglib;
<b>int</b> main(<b>int</b> argc, char **argv)
{
<font color=navy>//</font>
<font color=navy>// We build bilinear vector-valued spline (f0,f1) = {x+2*y, 2*x+y}</font>
<font color=navy>// Spline is built using function values at 2x2 grid: (x,y)=[0,1]*[0,1]</font>
<font color=navy>// Then we perform evaluation at (x,y)=(0.1,0.3)</font>
<font color=navy>//</font>
real_1d_array x = <font color=blue><b>"[0.0, 1.0]"</b></font>;
real_1d_array y = <font color=blue><b>"[0.0, 1.0]"</b></font>;
real_1d_array f = <font color=blue><b>"[0.00,0.00, 1.00,2.00, 2.00,1.00, 3.00,3.00]"</b></font>;
spline2dinterpolant s;
real_1d_array vr;
spline2dbuildbilinearv(x, 2, y, 2, f, 2, s);
spline2dcalcv(s, 0.1, 0.3, vr);
printf(<font color=blue><b>"%s\n"</b></font>, vr.tostring(4).c_str()); <font color=navy>// EXPECTED: [0.700,0.500]</font>
<b>return</b> 0;
}
</pre><a name=unit_spline3d></a><h2 class=pageheader><code>spline3d</code> subpackage</h2>
<div class=pagecontent>
<h3 class=pageheader>Classes</h3>
<a href='#struct_spline3dinterpolant' class=toc>spline3dinterpolant</a><br>
<h3 class=pageheader>Functions</h3>
<a href='#sub_spline3dbuildtrilinearv' class=toc>spline3dbuildtrilinearv</a><br>
<a href='#sub_spline3dcalc' class=toc>spline3dcalc</a><br>
<a href='#sub_spline3dcalcv' class=toc>spline3dcalcv</a><br>
<a href='#sub_spline3dcalcvbuf' class=toc>spline3dcalcvbuf</a><br>
<a href='#sub_spline3dlintransf' class=toc>spline3dlintransf</a><br>
<a href='#sub_spline3dlintransxyz' class=toc>spline3dlintransxyz</a><br>
<a href='#sub_spline3dresampletrilinear' class=toc>spline3dresampletrilinear</a><br>
<a href='#sub_spline3dunpackv' class=toc>spline3dunpackv</a><br>
<h3 class=pageheader>Examples</h3>
<table border=0 cellspacing=0 class='pagecontent'>
<tr align=left valign=top><td><a href='#example_spline3d_trilinear' class=toc>spline3d_trilinear</a></td><td width=15> </td><td>Trilinear spline interpolation</td></tr>
<tr align=left valign=top><td><a href='#example_spline3d_vector' class=toc>spline3d_vector</a></td><td width=15> </td><td>Vector-valued trilinear spline interpolation</td></tr>
</table></div>
<a name='struct_spline3dinterpolant'></a><h3 class=pageheader><code>spline3dinterpolant</code> class</h3>
<pre class=source>
<div style='color: navy; margin-top: 0; margin-bottom: 0;'>/*************************************************************************
3-dimensional spline inteprolant
*************************************************************************/
</div><div style='margin-top: 0; margin-bottom: 0;'><b>class</b> spline3dinterpolant
{
};
</div></pre>
<a name='sub_spline3dbuildtrilinearv'></a><h3 class=pageheader><code>spline3dbuildtrilinearv</code> function</h3>
<pre class=source>
<div style='color: navy; margin-top: 0; margin-bottom: 0;'>/*************************************************************************
This subroutine builds trilinear vector-valued spline.
INPUT PARAMETERS:
X - spline abscissas, array[0..N-1]
Y - spline ordinates, array[0..M-1]
Z - spline applicates, array[0..L-1]
F - function values, array[0..M*N*L*D-1]:
* first D elements store D values at (X[0],Y[0],Z[0])
* next D elements store D values at (X[1],Y[0],Z[0])
* next D elements store D values at (X[2],Y[0],Z[0])
* ...
* next D elements store D values at (X[0],Y[1],Z[0])
* next D elements store D values at (X[1],Y[1],Z[0])
* next D elements store D values at (X[2],Y[1],Z[0])
* ...
* next D elements store D values at (X[0],Y[0],Z[1])
* next D elements store D values at (X[1],Y[0],Z[1])
* next D elements store D values at (X[2],Y[0],Z[1])
* ...
* general form - D function values at (X[i],Y[j]) are stored
at F[D*(N*(M*K+J)+I)...D*(N*(M*K+J)+I)+D-1].
M,N,
L - grid size, M>=2, N>=2, L>=2
D - vector dimension, D>=1
OUTPUT PARAMETERS:
C - spline interpolant
-- ALGLIB PROJECT --
Copyright 26.04.2012 by Bochkanov Sergey
*************************************************************************/
</div><div style='margin-top: 0; margin-bottom: 0;'><b>void</b> alglib::spline3dbuildtrilinearv(
real_1d_array x,
ae_int_t n,
real_1d_array y,
ae_int_t m,
real_1d_array z,
ae_int_t l,
real_1d_array f,
ae_int_t d,
spline3dinterpolant& c);
</div></pre>
<p align=left class=pagecontent><span class=inlineheader>Examples:</span> <a href='#example_spline3d_trilinear' class=nav>[1]</a> <a href='#example_spline3d_vector' class=nav>[2]</a> </p>
<a name='sub_spline3dcalc'></a><h3 class=pageheader><code>spline3dcalc</code> function</h3>
<pre class=source>
<div style='color: navy; margin-top: 0; margin-bottom: 0;'>/*************************************************************************
This subroutine calculates the value of the trilinear or tricubic spline at
the given point (X,Y,Z).
INPUT PARAMETERS:
C - coefficients table.
Built by BuildBilinearSpline or BuildBicubicSpline.
X, Y,
Z - point
Result:
S(x,y,z)
-- ALGLIB PROJECT --
Copyright 26.04.2012 by Bochkanov Sergey
*************************************************************************/
</div><div style='margin-top: 0; margin-bottom: 0;'><b>double</b> alglib::spline3dcalc(
spline3dinterpolant c,
<b>double</b> x,
<b>double</b> y,
<b>double</b> z);
</div></pre>
<p align=left class=pagecontent><span class=inlineheader>Examples:</span> <a href='#example_spline3d_trilinear' class=nav>[1]</a> </p>
<a name='sub_spline3dcalcv'></a><h3 class=pageheader><code>spline3dcalcv</code> function</h3>
<pre class=source>
<div style='color: navy; margin-top: 0; margin-bottom: 0;'>/*************************************************************************
This subroutine calculates trilinear or tricubic vector-valued spline at the
given point (X,Y,Z).
INPUT PARAMETERS:
C - spline interpolant.
X, Y,
Z - point
OUTPUT PARAMETERS:
F - array[D] which stores function values. F is out-parameter and
it is reallocated after call to this function. In case you
want to reuse previously allocated F, you may use
Spline2DCalcVBuf(), which reallocates F only when it is too
small.
-- ALGLIB PROJECT --
Copyright 26.04.2012 by Bochkanov Sergey
*************************************************************************/
</div><div style='margin-top: 0; margin-bottom: 0;'><b>void</b> alglib::spline3dcalcv(
spline3dinterpolant c,
<b>double</b> x,
<b>double</b> y,
<b>double</b> z,
real_1d_array& f);
</div></pre>
<p align=left class=pagecontent><span class=inlineheader>Examples:</span> <a href='#example_spline3d_vector' class=nav>[1]</a> </p>
<a name='sub_spline3dcalcvbuf'></a><h3 class=pageheader><code>spline3dcalcvbuf</code> function</h3>
<pre class=source>
<div style='color: navy; margin-top: 0; margin-bottom: 0;'>/*************************************************************************
This subroutine calculates bilinear or bicubic vector-valued spline at the
given point (X,Y,Z).
INPUT PARAMETERS:
C - spline interpolant.
X, Y,
Z - point
F - output buffer, possibly preallocated array. In case array size
is large enough to store result, it is not reallocated. Array
which is too short will be reallocated
OUTPUT PARAMETERS:
F - array[D] (or larger) which stores function values
-- ALGLIB PROJECT --
Copyright 26.04.2012 by Bochkanov Sergey
*************************************************************************/
</div><div style='margin-top: 0; margin-bottom: 0;'><b>void</b> alglib::spline3dcalcvbuf(
spline3dinterpolant c,
<b>double</b> x,
<b>double</b> y,
<b>double</b> z,
real_1d_array& f);
</div></pre>
<a name='sub_spline3dlintransf'></a><h3 class=pageheader><code>spline3dlintransf</code> function</h3>
<pre class=source>
<div style='color: navy; margin-top: 0; margin-bottom: 0;'>/*************************************************************************
This subroutine performs linear transformation of the spline.
INPUT PARAMETERS:
C - spline interpolant.
A, B- transformation coefficients: S2(x,y) = A*S(x,y,z) + B
OUTPUT PARAMETERS:
C - transformed spline
-- ALGLIB PROJECT --
Copyright 26.04.2012 by Bochkanov Sergey
*************************************************************************/
</div><div style='margin-top: 0; margin-bottom: 0;'><b>void</b> alglib::spline3dlintransf(spline3dinterpolant c, <b>double</b> a, <b>double</b> b);
</div></pre>
<a name='sub_spline3dlintransxyz'></a><h3 class=pageheader><code>spline3dlintransxyz</code> function</h3>
<pre class=source>
<div style='color: navy; margin-top: 0; margin-bottom: 0;'>/*************************************************************************
This subroutine performs linear transformation of the spline argument.
INPUT PARAMETERS:
C - spline interpolant
AX, BX - transformation coefficients: x = A*u + B
AY, BY - transformation coefficients: y = A*v + B
AZ, BZ - transformation coefficients: z = A*w + B
OUTPUT PARAMETERS:
C - transformed spline
-- ALGLIB PROJECT --
Copyright 26.04.2012 by Bochkanov Sergey
*************************************************************************/
</div><div style='margin-top: 0; margin-bottom: 0;'><b>void</b> alglib::spline3dlintransxyz(
spline3dinterpolant c,
<b>double</b> ax,
<b>double</b> bx,
<b>double</b> ay,
<b>double</b> by,
<b>double</b> az,
<b>double</b> bz);
</div></pre>
<a name='sub_spline3dresampletrilinear'></a><h3 class=pageheader><code>spline3dresampletrilinear</code> function</h3>
<pre class=source>
<div style='color: navy; margin-top: 0; margin-bottom: 0;'>/*************************************************************************
Trilinear spline resampling
INPUT PARAMETERS:
A - array[0..OldXCount*OldYCount*OldZCount-1], function
values at the old grid, :
A[0] x=0,y=0,z=0
A[1] x=1,y=0,z=0
A[..] ...
A[..] x=oldxcount-1,y=0,z=0
A[..] x=0,y=1,z=0
A[..] ...
...
OldZCount - old Z-count, OldZCount>1
OldYCount - old Y-count, OldYCount>1
OldXCount - old X-count, OldXCount>1
NewZCount - new Z-count, NewZCount>1
NewYCount - new Y-count, NewYCount>1
NewXCount - new X-count, NewXCount>1
OUTPUT PARAMETERS:
B - array[0..NewXCount*NewYCount*NewZCount-1], function
values at the new grid:
B[0] x=0,y=0,z=0
B[1] x=1,y=0,z=0
B[..] ...
B[..] x=newxcount-1,y=0,z=0
B[..] x=0,y=1,z=0
B[..] ...
...
-- ALGLIB routine --
26.04.2012
Copyright by Bochkanov Sergey
*************************************************************************/
</div><div style='margin-top: 0; margin-bottom: 0;'><b>void</b> alglib::spline3dresampletrilinear(
real_1d_array a,
ae_int_t oldzcount,
ae_int_t oldycount,
ae_int_t oldxcount,
ae_int_t newzcount,
ae_int_t newycount,
ae_int_t newxcount,
real_1d_array& b);
</div></pre>
<a name='sub_spline3dunpackv'></a><h3 class=pageheader><code>spline3dunpackv</code> function</h3>
<pre class=source>
<div style='color: navy; margin-top: 0; margin-bottom: 0;'>/*************************************************************************
This subroutine unpacks tri-dimensional spline into the coefficients table
INPUT PARAMETERS:
C - spline interpolant.
Result:
N - grid size (X)
M - grid size (Y)
L - grid size (Z)
D - number of components
SType- spline type. Currently, only one spline type is supported:
trilinear spline, as indicated by SType=1.
Tbl - spline coefficients: [0..(N-1)*(M-1)*(L-1)*D-1, 0..13].
For T=0..D-1 (component index), I = 0...N-2 (x index),
J=0..M-2 (y index), K=0..L-2 (z index):
Q := T + I*D + J*D*(N-1) + K*D*(N-1)*(M-1),
Q-th row stores decomposition for T-th component of the
vector-valued function
Tbl[Q,0] = X[i]
Tbl[Q,1] = X[i+1]
Tbl[Q,2] = Y[j]
Tbl[Q,3] = Y[j+1]
Tbl[Q,4] = Z[k]
Tbl[Q,5] = Z[k+1]
Tbl[Q,6] = C000
Tbl[Q,7] = C100
Tbl[Q,8] = C010
Tbl[Q,9] = C110
Tbl[Q,10]= C001
Tbl[Q,11]= C101
Tbl[Q,12]= C011
Tbl[Q,13]= C111
On each grid square spline is equals to:
S(x) = SUM(c[i,j,k]*(x^i)*(y^j)*(z^k), i=0..1, j=0..1, k=0..1)
t = x-x[j]
u = y-y[i]
v = z-z[k]
NOTE: format of Tbl is given for SType=1. Future versions of
ALGLIB can use different formats for different values of
SType.
-- ALGLIB PROJECT --
Copyright 26.04.2012 by Bochkanov Sergey
*************************************************************************/
</div><div style='margin-top: 0; margin-bottom: 0;'><b>void</b> alglib::spline3dunpackv(
spline3dinterpolant c,
ae_int_t& n,
ae_int_t& m,
ae_int_t& l,
ae_int_t& d,
ae_int_t& stype,
real_2d_array& tbl);
</div></pre>
<a name='example_spline3d_trilinear'></a><h3 class=pageheader>spline3d_trilinear example</h3>
<pre class=source>
#include <font color=blue><b>"stdafx.h"</b></font>
#include <stdlib.h>
#include <stdio.h>
#include <math.h>
#include <font color=blue><b>"interpolation.h"</b></font>
using namespace alglib;
<b>int</b> main(<b>int</b> argc, char **argv)
{
<font color=navy>//</font>
<font color=navy>// We use trilinear spline to interpolate f(x,y,z)=x+xy+z sampled </font>
<font color=navy>// at (x,y,z) from [0.0, 1.0] X [0.0, 1.0] X [0.0, 1.0].</font>
<font color=navy>//</font>
<font color=navy>// We store x, y and z-values at local arrays with same names.</font>
<font color=navy>// Function values are stored in the array F as follows:</font>
<font color=navy>// f[0] (x,y,z) = (0,0,0)</font>
<font color=navy>// f[1] (x,y,z) = (1,0,0)</font>
<font color=navy>// f[2] (x,y,z) = (0,1,0)</font>
<font color=navy>// f[3] (x,y,z) = (1,1,0)</font>
<font color=navy>// f[4] (x,y,z) = (0,0,1)</font>
<font color=navy>// f[5] (x,y,z) = (1,0,1)</font>
<font color=navy>// f[6] (x,y,z) = (0,1,1)</font>
<font color=navy>// f[7] (x,y,z) = (1,1,1)</font>
<font color=navy>//</font>
real_1d_array x = <font color=blue><b>"[0.0, 1.0]"</b></font>;
real_1d_array y = <font color=blue><b>"[0.0, 1.0]"</b></font>;
real_1d_array z = <font color=blue><b>"[0.0, 1.0]"</b></font>;
real_1d_array f = <font color=blue><b>"[0,1,0,2,1,2,1,3]"</b></font>;
<b>double</b> vx = 0.50;
<b>double</b> vy = 0.50;
<b>double</b> vz = 0.50;
<b>double</b> v;
spline3dinterpolant s;
<font color=navy>// build spline</font>
spline3dbuildtrilinearv(x, 2, y, 2, z, 2, f, 1, s);
<font color=navy>// calculate S(0.5,0.5,0.5)</font>
v = spline3dcalc(s, vx, vy, vz);
printf(<font color=blue><b>"%.4f\n"</b></font>, <b>double</b>(v)); <font color=navy>// EXPECTED: 1.2500</font>
<b>return</b> 0;
}
</pre><a name='example_spline3d_vector'></a><h3 class=pageheader>spline3d_vector example</h3>
<pre class=source>
#include <font color=blue><b>"stdafx.h"</b></font>
#include <stdlib.h>
#include <stdio.h>
#include <math.h>
#include <font color=blue><b>"interpolation.h"</b></font>
using namespace alglib;
<b>int</b> main(<b>int</b> argc, char **argv)
{
<font color=navy>//</font>
<font color=navy>// We use trilinear vector-valued spline to interpolate {f0,f1}={x+xy+z,x+xy+yz+z}</font>
<font color=navy>// sampled at (x,y,z) from [0.0, 1.0] X [0.0, 1.0] X [0.0, 1.0].</font>
<font color=navy>//</font>
<font color=navy>// We store x, y and z-values at local arrays with same names.</font>
<font color=navy>// Function values are stored in the array F as follows:</font>
<font color=navy>// f[0] f0, (x,y,z) = (0,0,0)</font>
<font color=navy>// f[1] f1, (x,y,z) = (0,0,0)</font>
<font color=navy>// f[2] f0, (x,y,z) = (1,0,0)</font>
<font color=navy>// f[3] f1, (x,y,z) = (1,0,0)</font>
<font color=navy>// f[4] f0, (x,y,z) = (0,1,0)</font>
<font color=navy>// f[5] f1, (x,y,z) = (0,1,0)</font>
<font color=navy>// f[6] f0, (x,y,z) = (1,1,0)</font>
<font color=navy>// f[7] f1, (x,y,z) = (1,1,0)</font>
<font color=navy>// f[8] f0, (x,y,z) = (0,0,1)</font>
<font color=navy>// f[9] f1, (x,y,z) = (0,0,1)</font>
<font color=navy>// f[10] f0, (x,y,z) = (1,0,1)</font>
<font color=navy>// f[11] f1, (x,y,z) = (1,0,1)</font>
<font color=navy>// f[12] f0, (x,y,z) = (0,1,1)</font>
<font color=navy>// f[13] f1, (x,y,z) = (0,1,1)</font>
<font color=navy>// f[14] f0, (x,y,z) = (1,1,1)</font>
<font color=navy>// f[15] f1, (x,y,z) = (1,1,1)</font>
<font color=navy>//</font>
real_1d_array x = <font color=blue><b>"[0.0, 1.0]"</b></font>;
real_1d_array y = <font color=blue><b>"[0.0, 1.0]"</b></font>;
real_1d_array z = <font color=blue><b>"[0.0, 1.0]"</b></font>;
real_1d_array f = <font color=blue><b>"[0,0, 1,1, 0,0, 2,2, 1,1, 2,2, 1,2, 3,4]"</b></font>;
<b>double</b> vx = 0.50;
<b>double</b> vy = 0.50;
<b>double</b> vz = 0.50;
spline3dinterpolant s;
<font color=navy>// build spline</font>
spline3dbuildtrilinearv(x, 2, y, 2, z, 2, f, 2, s);
<font color=navy>// calculate S(0.5,0.5,0.5) - we have vector of values instead of single value</font>
real_1d_array v;
spline3dcalcv(s, vx, vy, vz, v);
printf(<font color=blue><b>"%s\n"</b></font>, v.tostring(4).c_str()); <font color=navy>// EXPECTED: [1.2500,1.5000]</font>
<b>return</b> 0;
}
</pre><a name=unit_stest></a><h2 class=pageheader><code>stest</code> subpackage</h2>
<div class=pagecontent>
<h3 class=pageheader>Functions</h3>
<a href='#sub_onesamplesigntest' class=toc>onesamplesigntest</a><br>
<h3 class=pageheader>Examples</h3>
<table border=0 cellspacing=0 class='pagecontent'>
</table></div>
<a name='sub_onesamplesigntest'></a><h3 class=pageheader><code>onesamplesigntest</code> function</h3>
<pre class=source>
<div style='color: navy; margin-top: 0; margin-bottom: 0;'>/*************************************************************************
Sign test
This test checks three hypotheses about the median of the given sample.
The following tests are performed:
* two-tailed test (null hypothesis - the median is equal to the given
value)
* left-tailed test (null hypothesis - the median is greater than or
equal to the given value)
* right-tailed test (null hypothesis - the median is less than or
equal to the given value)
Requirements:
* the scale of measurement should be ordinal, interval or ratio (i.e.
the test could not be applied to nominal variables).
The test is non-parametric and doesn't require distribution X to be normal
Input parameters:
X - sample. Array whose index goes from 0 to N-1.
N - size of the sample.
Median - assumed median value.
Output parameters:
BothTails - p-value for two-tailed test.
If BothTails is less than the given significance level
the null hypothesis is rejected.
LeftTail - p-value for left-tailed test.
If LeftTail is less than the given significance level,
the null hypothesis is rejected.
RightTail - p-value for right-tailed test.
If RightTail is less than the given significance level
the null hypothesis is rejected.
While calculating p-values high-precision binomial distribution
approximation is used, so significance levels have about 15 exact digits.
-- ALGLIB --
Copyright 08.09.2006 by Bochkanov Sergey
*************************************************************************/
</div><div style='margin-top: 0; margin-bottom: 0;'><b>void</b> alglib::onesamplesigntest(
real_1d_array x,
ae_int_t n,
<b>double</b> median,
<b>double</b>& bothtails,
<b>double</b>& lefttail,
<b>double</b>& righttail);
</div></pre>
<a name=unit_studenttdistr></a><h2 class=pageheader><code>studenttdistr</code> subpackage</h2>
<div class=pagecontent>
<h3 class=pageheader>Functions</h3>
<a href='#sub_invstudenttdistribution' class=toc>invstudenttdistribution</a><br>
<a href='#sub_studenttdistribution' class=toc>studenttdistribution</a><br>
<h3 class=pageheader>Examples</h3>
<table border=0 cellspacing=0 class='pagecontent'>
</table></div>
<a name='sub_invstudenttdistribution'></a><h3 class=pageheader><code>invstudenttdistribution</code> function</h3>
<pre class=source>
<div style='color: navy; margin-top: 0; margin-bottom: 0;'>/*************************************************************************
Functional inverse of Student's t distribution
Given probability p, finds the argument t such that stdtr(k,t)
is equal to p.
ACCURACY:
Tested at random 1 <= k <= 100. The "domain" refers to p:
Relative error:
arithmetic domain # trials peak rms
IEEE .001,.999 25000 5.7e-15 8.0e-16
IEEE 10^-6,.001 25000 2.0e-12 2.9e-14
Cephes Math Library Release 2.8: June, 2000
Copyright 1984, 1987, 1995, 2000 by Stephen L. Moshier
*************************************************************************/
</div><div style='margin-top: 0; margin-bottom: 0;'><b>double</b> alglib::invstudenttdistribution(ae_int_t k, <b>double</b> p);
</div></pre>
<a name='sub_studenttdistribution'></a><h3 class=pageheader><code>studenttdistribution</code> function</h3>
<pre class=source>
<div style='color: navy; margin-top: 0; margin-bottom: 0;'>/*************************************************************************
Student's t distribution
Computes the integral from minus infinity to t of the Student
t distribution with integer k > 0 degrees of freedom:
t
-
| |
- | 2 -(k+1)/2
| ( (k+1)/2 ) | ( x )
---------------------- | ( 1 + --- ) dx
- | ( k )
sqrt( k pi ) | ( k/2 ) |
| |
-
-inf.
Relation to incomplete beta integral:
1 - stdtr(k,t) = 0.5 * incbet( k/2, 1/2, z )
where
z = k/(k + t**2).
For t < -2, this is the method of computation. For higher t,
a direct method is derived from integration by parts.
Since the function is symmetric about t=0, the area under the
right tail of the density is found by calling the function
with -t instead of t.
ACCURACY:
Tested at random 1 <= k <= 25. The "domain" refers to t.
Relative error:
arithmetic domain # trials peak rms
IEEE -100,-2 50000 5.9e-15 1.4e-15
IEEE -2,100 500000 2.7e-15 4.9e-17
Cephes Math Library Release 2.8: June, 2000
Copyright 1984, 1987, 1995, 2000 by Stephen L. Moshier
*************************************************************************/
</div><div style='margin-top: 0; margin-bottom: 0;'><b>double</b> alglib::studenttdistribution(ae_int_t k, <b>double</b> t);
</div></pre>
<a name=unit_studentttests></a><h2 class=pageheader><code>studentttests</code> subpackage</h2>
<div class=pagecontent>
<h3 class=pageheader>Functions</h3>
<a href='#sub_studentttest1' class=toc>studentttest1</a><br>
<a href='#sub_studentttest2' class=toc>studentttest2</a><br>
<a href='#sub_unequalvariancettest' class=toc>unequalvariancettest</a><br>
<h3 class=pageheader>Examples</h3>
<table border=0 cellspacing=0 class='pagecontent'>
</table></div>
<a name='sub_studentttest1'></a><h3 class=pageheader><code>studentttest1</code> function</h3>
<pre class=source>
<div style='color: navy; margin-top: 0; margin-bottom: 0;'>/*************************************************************************
One-sample t-test
This test checks three hypotheses about the mean of the given sample. The
following tests are performed:
* two-tailed test (null hypothesis - the mean is equal to the given
value)
* left-tailed test (null hypothesis - the mean is greater than or
equal to the given value)
* right-tailed test (null hypothesis - the mean is less than or equal
to the given value).
The test is based on the assumption that a given sample has a normal
distribution and an unknown dispersion. If the distribution sharply
differs from normal, the test will work incorrectly.
INPUT PARAMETERS:
X - sample. Array whose index goes from 0 to N-1.
N - size of sample, N>=0
Mean - assumed value of the mean.
OUTPUT PARAMETERS:
BothTails - p-value for two-tailed test.
If BothTails is less than the given significance level
the null hypothesis is rejected.
LeftTail - p-value for left-tailed test.
If LeftTail is less than the given significance level,
the null hypothesis is rejected.
RightTail - p-value for right-tailed test.
If RightTail is less than the given significance level
the null hypothesis is rejected.
NOTE: this function correctly handles degenerate cases:
* when N=0, all p-values are set to 1.0
* when variance of X[] is exactly zero, p-values are set
to 1.0 or 0.0, depending on difference between sample mean and
value of mean being tested.
-- ALGLIB --
Copyright 08.09.2006 by Bochkanov Sergey
*************************************************************************/
</div><div style='margin-top: 0; margin-bottom: 0;'><b>void</b> alglib::studentttest1(
real_1d_array x,
ae_int_t n,
<b>double</b> mean,
<b>double</b>& bothtails,
<b>double</b>& lefttail,
<b>double</b>& righttail);
</div></pre>
<a name='sub_studentttest2'></a><h3 class=pageheader><code>studentttest2</code> function</h3>
<pre class=source>
<div style='color: navy; margin-top: 0; margin-bottom: 0;'>/*************************************************************************
Two-sample pooled test
This test checks three hypotheses about the mean of the given samples. The
following tests are performed:
* two-tailed test (null hypothesis - the means are equal)
* left-tailed test (null hypothesis - the mean of the first sample is
greater than or equal to the mean of the second sample)
* right-tailed test (null hypothesis - the mean of the first sample is
less than or equal to the mean of the second sample).
Test is based on the following assumptions:
* given samples have normal distributions
* dispersions are equal
* samples are independent.
Input parameters:
X - sample 1. Array whose index goes from 0 to N-1.
N - size of sample.
Y - sample 2. Array whose index goes from 0 to M-1.
M - size of sample.
Output parameters:
BothTails - p-value for two-tailed test.
If BothTails is less than the given significance level
the null hypothesis is rejected.
LeftTail - p-value for left-tailed test.
If LeftTail is less than the given significance level,
the null hypothesis is rejected.
RightTail - p-value for right-tailed test.
If RightTail is less than the given significance level
the null hypothesis is rejected.
NOTE: this function correctly handles degenerate cases:
* when N=0 or M=0, all p-values are set to 1.0
* when both samples has exactly zero variance, p-values are set
to 1.0 or 0.0, depending on difference between means.
-- ALGLIB --
Copyright 18.09.2006 by Bochkanov Sergey
*************************************************************************/
</div><div style='margin-top: 0; margin-bottom: 0;'><b>void</b> alglib::studentttest2(
real_1d_array x,
ae_int_t n,
real_1d_array y,
ae_int_t m,
<b>double</b>& bothtails,
<b>double</b>& lefttail,
<b>double</b>& righttail);
</div></pre>
<a name='sub_unequalvariancettest'></a><h3 class=pageheader><code>unequalvariancettest</code> function</h3>
<pre class=source>
<div style='color: navy; margin-top: 0; margin-bottom: 0;'>/*************************************************************************
Two-sample unpooled test
This test checks three hypotheses about the mean of the given samples. The
following tests are performed:
* two-tailed test (null hypothesis - the means are equal)
* left-tailed test (null hypothesis - the mean of the first sample is
greater than or equal to the mean of the second sample)
* right-tailed test (null hypothesis - the mean of the first sample is
less than or equal to the mean of the second sample).
Test is based on the following assumptions:
* given samples have normal distributions
* samples are independent.
Equality of variances is NOT required.
Input parameters:
X - sample 1. Array whose index goes from 0 to N-1.
N - size of the sample.
Y - sample 2. Array whose index goes from 0 to M-1.
M - size of the sample.
Output parameters:
BothTails - p-value for two-tailed test.
If BothTails is less than the given significance level
the null hypothesis is rejected.
LeftTail - p-value for left-tailed test.
If LeftTail is less than the given significance level,
the null hypothesis is rejected.
RightTail - p-value for right-tailed test.
If RightTail is less than the given significance level
the null hypothesis is rejected.
NOTE: this function correctly handles degenerate cases:
* when N=0 or M=0, all p-values are set to 1.0
* when both samples has zero variance, p-values are set
to 1.0 or 0.0, depending on difference between means.
* when only one sample has zero variance, test reduces to 1-sample
version.
-- ALGLIB --
Copyright 18.09.2006 by Bochkanov Sergey
*************************************************************************/
</div><div style='margin-top: 0; margin-bottom: 0;'><b>void</b> alglib::unequalvariancettest(
real_1d_array x,
ae_int_t n,
real_1d_array y,
ae_int_t m,
<b>double</b>& bothtails,
<b>double</b>& lefttail,
<b>double</b>& righttail);
</div></pre>
<a name=unit_svd></a><h2 class=pageheader><code>svd</code> subpackage</h2>
<div class=pagecontent>
<h3 class=pageheader>Functions</h3>
<a href='#sub_rmatrixsvd' class=toc>rmatrixsvd</a><br>
<h3 class=pageheader>Examples</h3>
<table border=0 cellspacing=0 class='pagecontent'>
</table></div>
<a name='sub_rmatrixsvd'></a><h3 class=pageheader><code>rmatrixsvd</code> function</h3>
<pre class=source>
<div style='color: navy; margin-top: 0; margin-bottom: 0;'>/*************************************************************************
Singular value decomposition of a rectangular matrix.
COMMERCIAL EDITION OF ALGLIB:
! Commercial version of ALGLIB includes one important improvement of
! this function, which can be used from C++ and C#:
! * Intel MKL support (lightweight Intel MKL is shipped with ALGLIB)
!
! Intel MKL gives approximately constant (with respect to number of
! worker threads) acceleration factor which depends on CPU being used,
! problem size and "baseline" ALGLIB edition which is used for
! comparison.
!
! Generally, commercial ALGLIB is several times faster than open-source
! generic C edition, and many times faster than open-source C# edition.
!
! Multithreaded acceleration is only partially supported (some parts are
! optimized, but most - are not).
!
! We recommend you to read 'Working with commercial version' section of
! ALGLIB Reference Manual in order to find out how to use performance-
! related features provided by commercial edition of ALGLIB.
The algorithm calculates the singular value decomposition of a matrix of
size MxN: A = U * S * V^T
The algorithm finds the singular values and, optionally, matrices U and V^T.
The algorithm can find both first min(M,N) columns of matrix U and rows of
matrix V^T (singular vectors), and matrices U and V^T wholly (of sizes MxM
and NxN respectively).
Take into account that the subroutine does not return matrix V but V^T.
Input parameters:
A - matrix to be decomposed.
Array whose indexes range within [0..M-1, 0..N-1].
M - number of rows in matrix A.
N - number of columns in matrix A.
UNeeded - 0, 1 or 2. See the description of the parameter U.
VTNeeded - 0, 1 or 2. See the description of the parameter VT.
AdditionalMemory -
If the parameter:
* equals 0, the algorithm doesn�t use additional
memory (lower requirements, lower performance).
* equals 1, the algorithm uses additional
memory of size min(M,N)*min(M,N) of real numbers.
It often speeds up the algorithm.
* equals 2, the algorithm uses additional
memory of size M*min(M,N) of real numbers.
It allows to get a maximum performance.
The recommended value of the parameter is 2.
Output parameters:
W - contains singular values in descending order.
U - if UNeeded=0, U isn't changed, the left singular vectors
are not calculated.
if Uneeded=1, U contains left singular vectors (first
min(M,N) columns of matrix U). Array whose indexes range
within [0..M-1, 0..Min(M,N)-1].
if UNeeded=2, U contains matrix U wholly. Array whose
indexes range within [0..M-1, 0..M-1].
VT - if VTNeeded=0, VT isn�t changed, the right singular vectors
are not calculated.
if VTNeeded=1, VT contains right singular vectors (first
min(M,N) rows of matrix V^T). Array whose indexes range
within [0..min(M,N)-1, 0..N-1].
if VTNeeded=2, VT contains matrix V^T wholly. Array whose
indexes range within [0..N-1, 0..N-1].
-- ALGLIB --
Copyright 2005 by Bochkanov Sergey
*************************************************************************/
</div><div style='margin-top: 0; margin-bottom: 0;'><b>bool</b> alglib::rmatrixsvd(
real_2d_array a,
ae_int_t m,
ae_int_t n,
ae_int_t uneeded,
ae_int_t vtneeded,
ae_int_t additionalmemory,
real_1d_array& w,
real_2d_array& u,
real_2d_array& vt);
<b>bool</b> alglib::smp_rmatrixsvd(
real_2d_array a,
ae_int_t m,
ae_int_t n,
ae_int_t uneeded,
ae_int_t vtneeded,
ae_int_t additionalmemory,
real_1d_array& w,
real_2d_array& u,
real_2d_array& vt);
</div></pre>
<a name=unit_trfac></a><h2 class=pageheader><code>trfac</code> subpackage</h2>
<div class=pagecontent>
<h3 class=pageheader>Functions</h3>
<a href='#sub_cmatrixlu' class=toc>cmatrixlu</a><br>
<a href='#sub_hpdmatrixcholesky' class=toc>hpdmatrixcholesky</a><br>
<a href='#sub_rmatrixlu' class=toc>rmatrixlu</a><br>
<a href='#sub_sparsecholeskyskyline' class=toc>sparsecholeskyskyline</a><br>
<a href='#sub_spdmatrixcholesky' class=toc>spdmatrixcholesky</a><br>
<a href='#sub_spdmatrixcholeskyupdateadd1' class=toc>spdmatrixcholeskyupdateadd1</a><br>
<a href='#sub_spdmatrixcholeskyupdateadd1buf' class=toc>spdmatrixcholeskyupdateadd1buf</a><br>
<a href='#sub_spdmatrixcholeskyupdatefix' class=toc>spdmatrixcholeskyupdatefix</a><br>
<a href='#sub_spdmatrixcholeskyupdatefixbuf' class=toc>spdmatrixcholeskyupdatefixbuf</a><br>
<h3 class=pageheader>Examples</h3>
<table border=0 cellspacing=0 class='pagecontent'>
</table></div>
<a name='sub_cmatrixlu'></a><h3 class=pageheader><code>cmatrixlu</code> function</h3>
<pre class=source>
<div style='color: navy; margin-top: 0; margin-bottom: 0;'>/*************************************************************************
LU decomposition of a general complex matrix with row pivoting
A is represented as A = P*L*U, where:
* L is lower unitriangular matrix
* U is upper triangular matrix
* P = P0*P1*...*PK, K=min(M,N)-1,
Pi - permutation matrix for I and Pivots[I]
This is cache-oblivous implementation of LU decomposition. It is optimized
for square matrices. As for rectangular matrices:
* best case - M>>N
* worst case - N>>M, small M, large N, matrix does not fit in CPU cache
COMMERCIAL EDITION OF ALGLIB:
! Commercial version of ALGLIB includes two important improvements of
! this function, which can be used from C++ and C#:
! * Intel MKL support (lightweight Intel MKL is shipped with ALGLIB)
! * multicore support
!
! Intel MKL gives approximately constant (with respect to number of
! worker threads) acceleration factor which depends on CPU being used,
! problem size and "baseline" ALGLIB edition which is used for
! comparison.
!
! Say, on SSE2-capable CPU with N=1024, HPC ALGLIB will be:
! * about 2-3x faster than ALGLIB for C++ without MKL
! * about 7-10x faster than "pure C#" edition of ALGLIB
! Difference in performance will be more striking on newer CPU's with
! support for newer SIMD instructions. Generally, MKL accelerates any
! problem whose size is at least 128, with best efficiency achieved for
! N's larger than 512.
!
! Commercial edition of ALGLIB also supports multithreaded acceleration
! of this function. We should note that LU decomposition is harder to
! parallelize than, say, matrix-matrix product - this algorithm has
! many internal synchronization points which can not be avoided. However
! parallelism starts to be profitable starting from N=1024, achieving
! near-linear speedup for N=4096 or higher.
!
! In order to use multicore features you have to:
! * use commercial version of ALGLIB
! * call this function with "smp_" prefix, which indicates that
! multicore code will be used (for multicore support)
!
! We recommend you to read 'Working with commercial version' section of
! ALGLIB Reference Manual in order to find out how to use performance-
! related features provided by commercial edition of ALGLIB.
INPUT PARAMETERS:
A - array[0..M-1, 0..N-1].
M - number of rows in matrix A.
N - number of columns in matrix A.
OUTPUT PARAMETERS:
A - matrices L and U in compact form:
* L is stored under main diagonal
* U is stored on and above main diagonal
Pivots - permutation matrix in compact form.
array[0..Min(M-1,N-1)].
-- ALGLIB routine --
10.01.2010
Bochkanov Sergey
*************************************************************************/
</div><div style='margin-top: 0; margin-bottom: 0;'><b>void</b> alglib::cmatrixlu(
complex_2d_array& a,
ae_int_t m,
ae_int_t n,
integer_1d_array& pivots);
<b>void</b> alglib::smp_cmatrixlu(
complex_2d_array& a,
ae_int_t m,
ae_int_t n,
integer_1d_array& pivots);
</div></pre>
<a name='sub_hpdmatrixcholesky'></a><h3 class=pageheader><code>hpdmatrixcholesky</code> function</h3>
<pre class=source>
<div style='color: navy; margin-top: 0; margin-bottom: 0;'>/*************************************************************************
Cache-oblivious Cholesky decomposition
The algorithm computes Cholesky decomposition of a Hermitian positive-
definite matrix. The result of an algorithm is a representation of A as
A=U'*U or A=L*L' (here X' detones conj(X^T)).
COMMERCIAL EDITION OF ALGLIB:
! Commercial version of ALGLIB includes two important improvements of
! this function, which can be used from C++ and C#:
! * Intel MKL support (lightweight Intel MKL is shipped with ALGLIB)
! * multicore support
!
! Intel MKL gives approximately constant (with respect to number of
! worker threads) acceleration factor which depends on CPU being used,
! problem size and "baseline" ALGLIB edition which is used for
! comparison.
!
! Say, on SSE2-capable CPU with N=1024, HPC ALGLIB will be:
! * about 2-3x faster than ALGLIB for C++ without MKL
! * about 7-10x faster than "pure C#" edition of ALGLIB
! Difference in performance will be more striking on newer CPU's with
! support for newer SIMD instructions. Generally, MKL accelerates any
! problem whose size is at least 128, with best efficiency achieved for
! N's larger than 512.
!
! Commercial edition of ALGLIB also supports multithreaded acceleration
! of this function. We should note that Cholesky decomposition is harder
! to parallelize than, say, matrix-matrix product - this algorithm has
! several synchronization points which can not be avoided. However,
! parallelism starts to be profitable starting from N=500.
!
! In order to use multicore features you have to:
! * use commercial version of ALGLIB
! * call this function with "smp_" prefix, which indicates that
! multicore code will be used (for multicore support)
!
! We recommend you to read 'Working with commercial version' section of
! ALGLIB Reference Manual in order to find out how to use performance-
! related features provided by commercial edition of ALGLIB.
INPUT PARAMETERS:
A - upper or lower triangle of a factorized matrix.
array with elements [0..N-1, 0..N-1].
N - size of matrix A.
IsUpper - if IsUpper=True, then A contains an upper triangle of
a symmetric matrix, otherwise A contains a lower one.
OUTPUT PARAMETERS:
A - the result of factorization. If IsUpper=True, then
the upper triangle contains matrix U, so that A = U'*U,
and the elements below the main diagonal are not modified.
Similarly, if IsUpper = False.
RESULT:
If the matrix is positive-definite, the function returns True.
Otherwise, the function returns False. Contents of A is not determined
in such case.
-- ALGLIB routine --
15.12.2009
Bochkanov Sergey
*************************************************************************/
</div><div style='margin-top: 0; margin-bottom: 0;'><b>bool</b> alglib::hpdmatrixcholesky(
complex_2d_array& a,
ae_int_t n,
<b>bool</b> isupper);
<b>bool</b> alglib::smp_hpdmatrixcholesky(
complex_2d_array& a,
ae_int_t n,
<b>bool</b> isupper);
</div></pre>
<a name='sub_rmatrixlu'></a><h3 class=pageheader><code>rmatrixlu</code> function</h3>
<pre class=source>
<div style='color: navy; margin-top: 0; margin-bottom: 0;'>/*************************************************************************
LU decomposition of a general real matrix with row pivoting
A is represented as A = P*L*U, where:
* L is lower unitriangular matrix
* U is upper triangular matrix
* P = P0*P1*...*PK, K=min(M,N)-1,
Pi - permutation matrix for I and Pivots[I]
This is cache-oblivous implementation of LU decomposition.
It is optimized for square matrices. As for rectangular matrices:
* best case - M>>N
* worst case - N>>M, small M, large N, matrix does not fit in CPU cache
COMMERCIAL EDITION OF ALGLIB:
! Commercial version of ALGLIB includes two important improvements of
! this function, which can be used from C++ and C#:
! * Intel MKL support (lightweight Intel MKL is shipped with ALGLIB)
! * multicore support
!
! Intel MKL gives approximately constant (with respect to number of
! worker threads) acceleration factor which depends on CPU being used,
! problem size and "baseline" ALGLIB edition which is used for
! comparison.
!
! Say, on SSE2-capable CPU with N=1024, HPC ALGLIB will be:
! * about 2-3x faster than ALGLIB for C++ without MKL
! * about 7-10x faster than "pure C#" edition of ALGLIB
! Difference in performance will be more striking on newer CPU's with
! support for newer SIMD instructions. Generally, MKL accelerates any
! problem whose size is at least 128, with best efficiency achieved for
! N's larger than 512.
!
! Commercial edition of ALGLIB also supports multithreaded acceleration
! of this function. We should note that LU decomposition is harder to
! parallelize than, say, matrix-matrix product - this algorithm has
! many internal synchronization points which can not be avoided. However
! parallelism starts to be profitable starting from N=1024, achieving
! near-linear speedup for N=4096 or higher.
!
! In order to use multicore features you have to:
! * use commercial version of ALGLIB
! * call this function with "smp_" prefix, which indicates that
! multicore code will be used (for multicore support)
!
! We recommend you to read 'Working with commercial version' section of
! ALGLIB Reference Manual in order to find out how to use performance-
! related features provided by commercial edition of ALGLIB.
INPUT PARAMETERS:
A - array[0..M-1, 0..N-1].
M - number of rows in matrix A.
N - number of columns in matrix A.
OUTPUT PARAMETERS:
A - matrices L and U in compact form:
* L is stored under main diagonal
* U is stored on and above main diagonal
Pivots - permutation matrix in compact form.
array[0..Min(M-1,N-1)].
-- ALGLIB routine --
10.01.2010
Bochkanov Sergey
*************************************************************************/
</div><div style='margin-top: 0; margin-bottom: 0;'><b>void</b> alglib::rmatrixlu(
real_2d_array& a,
ae_int_t m,
ae_int_t n,
integer_1d_array& pivots);
<b>void</b> alglib::smp_rmatrixlu(
real_2d_array& a,
ae_int_t m,
ae_int_t n,
integer_1d_array& pivots);
</div></pre>
<a name='sub_sparsecholeskyskyline'></a><h3 class=pageheader><code>sparsecholeskyskyline</code> function</h3>
<pre class=source>
<div style='color: navy; margin-top: 0; margin-bottom: 0;'>/*************************************************************************
Sparse Cholesky decomposition for skyline matrixm using in-place algorithm
without allocating additional storage.
The algorithm computes Cholesky decomposition of a symmetric positive-
definite sparse matrix. The result of an algorithm is a representation of
A as A=U^T*U or A=L*L^T
This function is a more efficient alternative to general, but slower
SparseCholeskyX(), because it does not create temporary copies of the
target. It performs factorization in-place, which gives best performance
on low-profile matrices. Its drawback, however, is that it can not perform
profile-reducing permutation of input matrix.
INPUT PARAMETERS:
A - sparse matrix in skyline storage (SKS) format.
N - size of matrix A (can be smaller than actual size of A)
IsUpper - if IsUpper=True, then factorization is performed on upper
triangle. Another triangle is ignored (it may contant some
data, but it is not changed).
OUTPUT PARAMETERS:
A - the result of factorization, stored in SKS. If IsUpper=True,
then the upper triangle contains matrix U, such that
A = U^T*U. Lower triangle is not changed.
Similarly, if IsUpper = False. In this case L is returned,
and we have A = L*(L^T).
Note that THIS function does not perform permutation of
rows to reduce bandwidth.
RESULT:
If the matrix is positive-definite, the function returns True.
Otherwise, the function returns False. Contents of A is not determined
in such case.
NOTE: for performance reasons this function does NOT check that input
matrix includes only finite values. It is your responsibility to
make sure that there are no infinite or NAN values in the matrix.
-- ALGLIB routine --
16.01.2014
Bochkanov Sergey
*************************************************************************/
</div><div style='margin-top: 0; margin-bottom: 0;'><b>bool</b> alglib::sparsecholeskyskyline(
sparsematrix a,
ae_int_t n,
<b>bool</b> isupper);
</div></pre>
<a name='sub_spdmatrixcholesky'></a><h3 class=pageheader><code>spdmatrixcholesky</code> function</h3>
<pre class=source>
<div style='color: navy; margin-top: 0; margin-bottom: 0;'>/*************************************************************************
Cache-oblivious Cholesky decomposition
The algorithm computes Cholesky decomposition of a symmetric positive-
definite matrix. The result of an algorithm is a representation of A as
A=U^T*U or A=L*L^T
COMMERCIAL EDITION OF ALGLIB:
! Commercial version of ALGLIB includes two important improvements of
! this function, which can be used from C++ and C#:
! * Intel MKL support (lightweight Intel MKL is shipped with ALGLIB)
! * multicore support
!
! Intel MKL gives approximately constant (with respect to number of
! worker threads) acceleration factor which depends on CPU being used,
! problem size and "baseline" ALGLIB edition which is used for
! comparison.
!
! Say, on SSE2-capable CPU with N=1024, HPC ALGLIB will be:
! * about 2-3x faster than ALGLIB for C++ without MKL
! * about 7-10x faster than "pure C#" edition of ALGLIB
! Difference in performance will be more striking on newer CPU's with
! support for newer SIMD instructions. Generally, MKL accelerates any
! problem whose size is at least 128, with best efficiency achieved for
! N's larger than 512.
!
! Commercial edition of ALGLIB also supports multithreaded acceleration
! of this function. We should note that Cholesky decomposition is harder
! to parallelize than, say, matrix-matrix product - this algorithm has
! several synchronization points which can not be avoided. However,
! parallelism starts to be profitable starting from N=500.
!
! In order to use multicore features you have to:
! * use commercial version of ALGLIB
! * call this function with "smp_" prefix, which indicates that
! multicore code will be used (for multicore support)
!
! We recommend you to read 'Working with commercial version' section of
! ALGLIB Reference Manual in order to find out how to use performance-
! related features provided by commercial edition of ALGLIB.
INPUT PARAMETERS:
A - upper or lower triangle of a factorized matrix.
array with elements [0..N-1, 0..N-1].
N - size of matrix A.
IsUpper - if IsUpper=True, then A contains an upper triangle of
a symmetric matrix, otherwise A contains a lower one.
OUTPUT PARAMETERS:
A - the result of factorization. If IsUpper=True, then
the upper triangle contains matrix U, so that A = U^T*U,
and the elements below the main diagonal are not modified.
Similarly, if IsUpper = False.
RESULT:
If the matrix is positive-definite, the function returns True.
Otherwise, the function returns False. Contents of A is not determined
in such case.
-- ALGLIB routine --
15.12.2009
Bochkanov Sergey
*************************************************************************/
</div><div style='margin-top: 0; margin-bottom: 0;'><b>bool</b> alglib::spdmatrixcholesky(
real_2d_array& a,
ae_int_t n,
<b>bool</b> isupper);
<b>bool</b> alglib::smp_spdmatrixcholesky(
real_2d_array& a,
ae_int_t n,
<b>bool</b> isupper);
</div></pre>
<a name='sub_spdmatrixcholeskyupdateadd1'></a><h3 class=pageheader><code>spdmatrixcholeskyupdateadd1</code> function</h3>
<pre class=source>
<div style='color: navy; margin-top: 0; margin-bottom: 0;'>/*************************************************************************
Update of Cholesky decomposition: rank-1 update to original A. "Buffered"
version which uses preallocated buffer which is saved between subsequent
function calls.
This function uses internally allocated buffer which is not saved between
subsequent calls. So, if you perform a lot of subsequent updates,
we recommend you to use "buffered" version of this function:
SPDMatrixCholeskyUpdateAdd1Buf().
INPUT PARAMETERS:
A - upper or lower Cholesky factor.
array with elements [0..N-1, 0..N-1].
Exception is thrown if array size is too small.
N - size of matrix A, N>0
IsUpper - if IsUpper=True, then A contains upper Cholesky factor;
otherwise A contains a lower one.
U - array[N], rank-1 update to A: A_mod = A + u*u'
Exception is thrown if array size is too small.
BufR - possibly preallocated buffer; automatically resized if
needed. It is recommended to reuse this buffer if you
perform a lot of subsequent decompositions.
OUTPUT PARAMETERS:
A - updated factorization. If IsUpper=True, then the upper
triangle contains matrix U, and the elements below the main
diagonal are not modified. Similarly, if IsUpper = False.
NOTE: this function always succeeds, so it does not return completion code
NOTE: this function checks sizes of input arrays, but it does NOT checks
for presence of infinities or NAN's.
-- ALGLIB --
03.02.2014
Sergey Bochkanov
*************************************************************************/
</div><div style='margin-top: 0; margin-bottom: 0;'><b>void</b> alglib::spdmatrixcholeskyupdateadd1(
real_2d_array& a,
ae_int_t n,
<b>bool</b> isupper,
real_1d_array u);
</div></pre>
<a name='sub_spdmatrixcholeskyupdateadd1buf'></a><h3 class=pageheader><code>spdmatrixcholeskyupdateadd1buf</code> function</h3>
<pre class=source>
<div style='color: navy; margin-top: 0; margin-bottom: 0;'>/*************************************************************************
Update of Cholesky decomposition: rank-1 update to original A. "Buffered"
version which uses preallocated buffer which is saved between subsequent
function calls.
See comments for SPDMatrixCholeskyUpdateAdd1() for more information.
INPUT PARAMETERS:
A - upper or lower Cholesky factor.
array with elements [0..N-1, 0..N-1].
Exception is thrown if array size is too small.
N - size of matrix A, N>0
IsUpper - if IsUpper=True, then A contains upper Cholesky factor;
otherwise A contains a lower one.
U - array[N], rank-1 update to A: A_mod = A + u*u'
Exception is thrown if array size is too small.
BufR - possibly preallocated buffer; automatically resized if
needed. It is recommended to reuse this buffer if you
perform a lot of subsequent decompositions.
OUTPUT PARAMETERS:
A - updated factorization. If IsUpper=True, then the upper
triangle contains matrix U, and the elements below the main
diagonal are not modified. Similarly, if IsUpper = False.
-- ALGLIB --
03.02.2014
Sergey Bochkanov
*************************************************************************/
</div><div style='margin-top: 0; margin-bottom: 0;'><b>void</b> alglib::spdmatrixcholeskyupdateadd1buf(
real_2d_array& a,
ae_int_t n,
<b>bool</b> isupper,
real_1d_array u,
real_1d_array& bufr);
</div></pre>
<a name='sub_spdmatrixcholeskyupdatefix'></a><h3 class=pageheader><code>spdmatrixcholeskyupdatefix</code> function</h3>
<pre class=source>
<div style='color: navy; margin-top: 0; margin-bottom: 0;'>/*************************************************************************
Update of Cholesky decomposition: "fixing" some variables.
This function uses internally allocated buffer which is not saved between
subsequent calls. So, if you perform a lot of subsequent updates,
we recommend you to use "buffered" version of this function:
SPDMatrixCholeskyUpdateFixBuf().
"FIXING" EXPLAINED:
Suppose we have N*N positive definite matrix A. "Fixing" some variable
means filling corresponding row/column of A by zeros, and setting
diagonal element to 1.
For example, if we fix 2nd variable in 4*4 matrix A, it becomes Af:
( A00 A01 A02 A03 ) ( Af00 0 Af02 Af03 )
( A10 A11 A12 A13 ) ( 0 1 0 0 )
( A20 A21 A22 A23 ) => ( Af20 0 Af22 Af23 )
( A30 A31 A32 A33 ) ( Af30 0 Af32 Af33 )
If we have Cholesky decomposition of A, it must be recalculated after
variables were fixed. However, it is possible to use efficient
algorithm, which needs O(K*N^2) time to "fix" K variables, given
Cholesky decomposition of original, "unfixed" A.
INPUT PARAMETERS:
A - upper or lower Cholesky factor.
array with elements [0..N-1, 0..N-1].
Exception is thrown if array size is too small.
N - size of matrix A, N>0
IsUpper - if IsUpper=True, then A contains upper Cholesky factor;
otherwise A contains a lower one.
Fix - array[N], I-th element is True if I-th variable must be
fixed. Exception is thrown if array size is too small.
BufR - possibly preallocated buffer; automatically resized if
needed. It is recommended to reuse this buffer if you
perform a lot of subsequent decompositions.
OUTPUT PARAMETERS:
A - updated factorization. If IsUpper=True, then the upper
triangle contains matrix U, and the elements below the main
diagonal are not modified. Similarly, if IsUpper = False.
NOTE: this function always succeeds, so it does not return completion code
NOTE: this function checks sizes of input arrays, but it does NOT checks
for presence of infinities or NAN's.
NOTE: this function is efficient only for moderate amount of updated
variables - say, 0.1*N or 0.3*N. For larger amount of variables it
will still work, but you may get better performance with
straightforward Cholesky.
-- ALGLIB --
03.02.2014
Sergey Bochkanov
*************************************************************************/
</div><div style='margin-top: 0; margin-bottom: 0;'><b>void</b> alglib::spdmatrixcholeskyupdatefix(
real_2d_array& a,
ae_int_t n,
<b>bool</b> isupper,
boolean_1d_array fix);
</div></pre>
<a name='sub_spdmatrixcholeskyupdatefixbuf'></a><h3 class=pageheader><code>spdmatrixcholeskyupdatefixbuf</code> function</h3>
<pre class=source>
<div style='color: navy; margin-top: 0; margin-bottom: 0;'>/*************************************************************************
Update of Cholesky decomposition: "fixing" some variables. "Buffered"
version which uses preallocated buffer which is saved between subsequent
function calls.
See comments for SPDMatrixCholeskyUpdateFix() for more information.
INPUT PARAMETERS:
A - upper or lower Cholesky factor.
array with elements [0..N-1, 0..N-1].
Exception is thrown if array size is too small.
N - size of matrix A, N>0
IsUpper - if IsUpper=True, then A contains upper Cholesky factor;
otherwise A contains a lower one.
Fix - array[N], I-th element is True if I-th variable must be
fixed. Exception is thrown if array size is too small.
BufR - possibly preallocated buffer; automatically resized if
needed. It is recommended to reuse this buffer if you
perform a lot of subsequent decompositions.
OUTPUT PARAMETERS:
A - updated factorization. If IsUpper=True, then the upper
triangle contains matrix U, and the elements below the main
diagonal are not modified. Similarly, if IsUpper = False.
-- ALGLIB --
03.02.2014
Sergey Bochkanov
*************************************************************************/
</div><div style='margin-top: 0; margin-bottom: 0;'><b>void</b> alglib::spdmatrixcholeskyupdatefixbuf(
real_2d_array& a,
ae_int_t n,
<b>bool</b> isupper,
boolean_1d_array fix,
real_1d_array& bufr);
</div></pre>
<a name=unit_trigintegrals></a><h2 class=pageheader><code>trigintegrals</code> subpackage</h2>
<div class=pagecontent>
<h3 class=pageheader>Functions</h3>
<a href='#sub_hyperbolicsinecosineintegrals' class=toc>hyperbolicsinecosineintegrals</a><br>
<a href='#sub_sinecosineintegrals' class=toc>sinecosineintegrals</a><br>
<h3 class=pageheader>Examples</h3>
<table border=0 cellspacing=0 class='pagecontent'>
</table></div>
<a name='sub_hyperbolicsinecosineintegrals'></a><h3 class=pageheader><code>hyperbolicsinecosineintegrals</code> function</h3>
<pre class=source>
<div style='color: navy; margin-top: 0; margin-bottom: 0;'>/*************************************************************************
Hyperbolic sine and cosine integrals
Approximates the integrals
x
-
| | cosh t - 1
Chi(x) = eul + ln x + | ----------- dt,
| | t
-
0
x
-
| | sinh t
Shi(x) = | ------ dt
| | t
-
0
where eul = 0.57721566490153286061 is Euler's constant.
The integrals are evaluated by power series for x < 8
and by Chebyshev expansions for x between 8 and 88.
For large x, both functions approach exp(x)/2x.
Arguments greater than 88 in magnitude return MAXNUM.
ACCURACY:
Test interval 0 to 88.
Relative error:
arithmetic function # trials peak rms
IEEE Shi 30000 6.9e-16 1.6e-16
Absolute error, except relative when |Chi| > 1:
IEEE Chi 30000 8.4e-16 1.4e-16
Cephes Math Library Release 2.8: June, 2000
Copyright 1984, 1987, 2000 by Stephen L. Moshier
*************************************************************************/
</div><div style='margin-top: 0; margin-bottom: 0;'><b>void</b> alglib::hyperbolicsinecosineintegrals(
<b>double</b> x,
<b>double</b>& shi,
<b>double</b>& chi);
</div></pre>
<a name='sub_sinecosineintegrals'></a><h3 class=pageheader><code>sinecosineintegrals</code> function</h3>
<pre class=source>
<div style='color: navy; margin-top: 0; margin-bottom: 0;'>/*************************************************************************
Sine and cosine integrals
Evaluates the integrals
x
-
| cos t - 1
Ci(x) = eul + ln x + | --------- dt,
| t
-
0
x
-
| sin t
Si(x) = | ----- dt
| t
-
0
where eul = 0.57721566490153286061 is Euler's constant.
The integrals are approximated by rational functions.
For x > 8 auxiliary functions f(x) and g(x) are employed
such that
Ci(x) = f(x) sin(x) - g(x) cos(x)
Si(x) = pi/2 - f(x) cos(x) - g(x) sin(x)
ACCURACY:
Test interval = [0,50].
Absolute error, except relative when > 1:
arithmetic function # trials peak rms
IEEE Si 30000 4.4e-16 7.3e-17
IEEE Ci 30000 6.9e-16 5.1e-17
Cephes Math Library Release 2.1: January, 1989
Copyright 1984, 1987, 1989 by Stephen L. Moshier
*************************************************************************/
</div><div style='margin-top: 0; margin-bottom: 0;'><b>void</b> alglib::sinecosineintegrals(<b>double</b> x, <b>double</b>& si, <b>double</b>& ci);
</div></pre>
<a name=unit_variancetests></a><h2 class=pageheader><code>variancetests</code> subpackage</h2>
<div class=pagecontent>
<h3 class=pageheader>Functions</h3>
<a href='#sub_ftest' class=toc>ftest</a><br>
<a href='#sub_onesamplevariancetest' class=toc>onesamplevariancetest</a><br>
<h3 class=pageheader>Examples</h3>
<table border=0 cellspacing=0 class='pagecontent'>
</table></div>
<a name='sub_ftest'></a><h3 class=pageheader><code>ftest</code> function</h3>
<pre class=source>
<div style='color: navy; margin-top: 0; margin-bottom: 0;'>/*************************************************************************
Two-sample F-test
This test checks three hypotheses about dispersions of the given samples.
The following tests are performed:
* two-tailed test (null hypothesis - the dispersions are equal)
* left-tailed test (null hypothesis - the dispersion of the first
sample is greater than or equal to the dispersion of the second
sample).
* right-tailed test (null hypothesis - the dispersion of the first
sample is less than or equal to the dispersion of the second sample)
The test is based on the following assumptions:
* the given samples have normal distributions
* the samples are independent.
Input parameters:
X - sample 1. Array whose index goes from 0 to N-1.
N - sample size.
Y - sample 2. Array whose index goes from 0 to M-1.
M - sample size.
Output parameters:
BothTails - p-value for two-tailed test.
If BothTails is less than the given significance level
the null hypothesis is rejected.
LeftTail - p-value for left-tailed test.
If LeftTail is less than the given significance level,
the null hypothesis is rejected.
RightTail - p-value for right-tailed test.
If RightTail is less than the given significance level
the null hypothesis is rejected.
-- ALGLIB --
Copyright 19.09.2006 by Bochkanov Sergey
*************************************************************************/
</div><div style='margin-top: 0; margin-bottom: 0;'><b>void</b> alglib::ftest(
real_1d_array x,
ae_int_t n,
real_1d_array y,
ae_int_t m,
<b>double</b>& bothtails,
<b>double</b>& lefttail,
<b>double</b>& righttail);
</div></pre>
<a name='sub_onesamplevariancetest'></a><h3 class=pageheader><code>onesamplevariancetest</code> function</h3>
<pre class=source>
<div style='color: navy; margin-top: 0; margin-bottom: 0;'>/*************************************************************************
One-sample chi-square test
This test checks three hypotheses about the dispersion of the given sample
The following tests are performed:
* two-tailed test (null hypothesis - the dispersion equals the given
number)
* left-tailed test (null hypothesis - the dispersion is greater than
or equal to the given number)
* right-tailed test (null hypothesis - dispersion is less than or
equal to the given number).
Test is based on the following assumptions:
* the given sample has a normal distribution.
Input parameters:
X - sample 1. Array whose index goes from 0 to N-1.
N - size of the sample.
Variance - dispersion value to compare with.
Output parameters:
BothTails - p-value for two-tailed test.
If BothTails is less than the given significance level
the null hypothesis is rejected.
LeftTail - p-value for left-tailed test.
If LeftTail is less than the given significance level,
the null hypothesis is rejected.
RightTail - p-value for right-tailed test.
If RightTail is less than the given significance level
the null hypothesis is rejected.
-- ALGLIB --
Copyright 19.09.2006 by Bochkanov Sergey
*************************************************************************/
</div><div style='margin-top: 0; margin-bottom: 0;'><b>void</b> alglib::onesamplevariancetest(
real_1d_array x,
ae_int_t n,
<b>double</b> variance,
<b>double</b>& bothtails,
<b>double</b>& lefttail,
<b>double</b>& righttail);
</div></pre>
<a name=unit_wsr></a><h2 class=pageheader><code>wsr</code> subpackage</h2>
<div class=pagecontent>
<h3 class=pageheader>Functions</h3>
<a href='#sub_wilcoxonsignedranktest' class=toc>wilcoxonsignedranktest</a><br>
<h3 class=pageheader>Examples</h3>
<table border=0 cellspacing=0 class='pagecontent'>
</table></div>
<a name='sub_wilcoxonsignedranktest'></a><h3 class=pageheader><code>wilcoxonsignedranktest</code> function</h3>
<pre class=source>
<div style='color: navy; margin-top: 0; margin-bottom: 0;'>/*************************************************************************
Wilcoxon signed-rank test
This test checks three hypotheses about the median of the given sample.
The following tests are performed:
* two-tailed test (null hypothesis - the median is equal to the given
value)
* left-tailed test (null hypothesis - the median is greater than or
equal to the given value)
* right-tailed test (null hypothesis - the median is less than or
equal to the given value)
Requirements:
* the scale of measurement should be ordinal, interval or ratio (i.e.
the test could not be applied to nominal variables).
* the distribution should be continuous and symmetric relative to its
median.
* number of distinct values in the X array should be greater than 4
The test is non-parametric and doesn't require distribution X to be normal
Input parameters:
X - sample. Array whose index goes from 0 to N-1.
N - size of the sample.
Median - assumed median value.
Output parameters:
BothTails - p-value for two-tailed test.
If BothTails is less than the given significance level
the null hypothesis is rejected.
LeftTail - p-value for left-tailed test.
If LeftTail is less than the given significance level,
the null hypothesis is rejected.
RightTail - p-value for right-tailed test.
If RightTail is less than the given significance level
the null hypothesis is rejected.
To calculate p-values, special approximation is used. This method lets us
calculate p-values with two decimal places in interval [0.0001, 1].
"Two decimal places" does not sound very impressive, but in practice the
relative error of less than 1% is enough to make a decision.
There is no approximation outside the [0.0001, 1] interval. Therefore, if
the significance level outlies this interval, the test returns 0.0001.
-- ALGLIB --
Copyright 08.09.2006 by Bochkanov Sergey
*************************************************************************/
</div><div style='margin-top: 0; margin-bottom: 0;'><b>void</b> alglib::wilcoxonsignedranktest(
real_1d_array x,
ae_int_t n,
<b>double</b> e,
<b>double</b>& bothtails,
<b>double</b>& lefttail,
<b>double</b>& righttail);
</div></pre>
<a name=unit_xdebug></a><h2 class=pageheader><code>xdebug</code> subpackage</h2>
<div class=pagecontent>
<h3 class=pageheader>Classes</h3>
<a href='#struct_xdebugrecord1' class=toc>xdebugrecord1</a><br>
<h3 class=pageheader>Functions</h3>
<a href='#sub_xdebugb1appendcopy' class=toc>xdebugb1appendcopy</a><br>
<a href='#sub_xdebugb1count' class=toc>xdebugb1count</a><br>
<a href='#sub_xdebugb1not' class=toc>xdebugb1not</a><br>
<a href='#sub_xdebugb1outeven' class=toc>xdebugb1outeven</a><br>
<a href='#sub_xdebugb2count' class=toc>xdebugb2count</a><br>
<a href='#sub_xdebugb2not' class=toc>xdebugb2not</a><br>
<a href='#sub_xdebugb2outsin' class=toc>xdebugb2outsin</a><br>
<a href='#sub_xdebugb2transpose' class=toc>xdebugb2transpose</a><br>
<a href='#sub_xdebugc1appendcopy' class=toc>xdebugc1appendcopy</a><br>
<a href='#sub_xdebugc1neg' class=toc>xdebugc1neg</a><br>
<a href='#sub_xdebugc1outeven' class=toc>xdebugc1outeven</a><br>
<a href='#sub_xdebugc1sum' class=toc>xdebugc1sum</a><br>
<a href='#sub_xdebugc2neg' class=toc>xdebugc2neg</a><br>
<a href='#sub_xdebugc2outsincos' class=toc>xdebugc2outsincos</a><br>
<a href='#sub_xdebugc2sum' class=toc>xdebugc2sum</a><br>
<a href='#sub_xdebugc2transpose' class=toc>xdebugc2transpose</a><br>
<a href='#sub_xdebugi1appendcopy' class=toc>xdebugi1appendcopy</a><br>
<a href='#sub_xdebugi1neg' class=toc>xdebugi1neg</a><br>
<a href='#sub_xdebugi1outeven' class=toc>xdebugi1outeven</a><br>
<a href='#sub_xdebugi1sum' class=toc>xdebugi1sum</a><br>
<a href='#sub_xdebugi2neg' class=toc>xdebugi2neg</a><br>
<a href='#sub_xdebugi2outsin' class=toc>xdebugi2outsin</a><br>
<a href='#sub_xdebugi2sum' class=toc>xdebugi2sum</a><br>
<a href='#sub_xdebugi2transpose' class=toc>xdebugi2transpose</a><br>
<a href='#sub_xdebuginitrecord1' class=toc>xdebuginitrecord1</a><br>
<a href='#sub_xdebugmaskedbiasedproductsum' class=toc>xdebugmaskedbiasedproductsum</a><br>
<a href='#sub_xdebugr1appendcopy' class=toc>xdebugr1appendcopy</a><br>
<a href='#sub_xdebugr1neg' class=toc>xdebugr1neg</a><br>
<a href='#sub_xdebugr1outeven' class=toc>xdebugr1outeven</a><br>
<a href='#sub_xdebugr1sum' class=toc>xdebugr1sum</a><br>
<a href='#sub_xdebugr2neg' class=toc>xdebugr2neg</a><br>
<a href='#sub_xdebugr2outsin' class=toc>xdebugr2outsin</a><br>
<a href='#sub_xdebugr2sum' class=toc>xdebugr2sum</a><br>
<a href='#sub_xdebugr2transpose' class=toc>xdebugr2transpose</a><br>
<h3 class=pageheader>Examples</h3>
<table border=0 cellspacing=0 class='pagecontent'>
</table></div>
<a name='struct_xdebugrecord1'></a><h3 class=pageheader><code>xdebugrecord1</code> class</h3>
<pre class=source>
<div style='color: navy; margin-top: 0; margin-bottom: 0;'>/*************************************************************************
*************************************************************************/
</div><div style='margin-top: 0; margin-bottom: 0;'><b>class</b> xdebugrecord1
{
ae_int_t i;
alglib::complex c;
real_1d_array a;
};
</div></pre>
<a name='sub_xdebugb1appendcopy'></a><h3 class=pageheader><code>xdebugb1appendcopy</code> function</h3>
<pre class=source>
<div style='color: navy; margin-top: 0; margin-bottom: 0;'>/*************************************************************************
This is debug function intended for testing ALGLIB interface generator.
Never use it in any real life project.
Appends copy of array to itself.
Array is passed using "var" convention.
-- ALGLIB --
Copyright 11.10.2013 by Bochkanov Sergey
*************************************************************************/
</div><div style='margin-top: 0; margin-bottom: 0;'><b>void</b> alglib::xdebugb1appendcopy(boolean_1d_array& a);
</div></pre>
<a name='sub_xdebugb1count'></a><h3 class=pageheader><code>xdebugb1count</code> function</h3>
<pre class=source>
<div style='color: navy; margin-top: 0; margin-bottom: 0;'>/*************************************************************************
This is debug function intended for testing ALGLIB interface generator.
Never use it in any real life project.
Counts number of True values in the boolean 1D array.
-- ALGLIB --
Copyright 11.10.2013 by Bochkanov Sergey
*************************************************************************/
</div><div style='margin-top: 0; margin-bottom: 0;'>ae_int_t alglib::xdebugb1count(boolean_1d_array a);
</div></pre>
<a name='sub_xdebugb1not'></a><h3 class=pageheader><code>xdebugb1not</code> function</h3>
<pre class=source>
<div style='color: navy; margin-top: 0; margin-bottom: 0;'>/*************************************************************************
This is debug function intended for testing ALGLIB interface generator.
Never use it in any real life project.
Replace all values in array by NOT(a[i]).
Array is passed using "shared" convention.
-- ALGLIB --
Copyright 11.10.2013 by Bochkanov Sergey
*************************************************************************/
</div><div style='margin-top: 0; margin-bottom: 0;'><b>void</b> alglib::xdebugb1not(boolean_1d_array& a);
</div></pre>
<a name='sub_xdebugb1outeven'></a><h3 class=pageheader><code>xdebugb1outeven</code> function</h3>
<pre class=source>
<div style='color: navy; margin-top: 0; margin-bottom: 0;'>/*************************************************************************
This is debug function intended for testing ALGLIB interface generator.
Never use it in any real life project.
Generate N-element array with even-numbered elements set to True.
Array is passed using "out" convention.
-- ALGLIB --
Copyright 11.10.2013 by Bochkanov Sergey
*************************************************************************/
</div><div style='margin-top: 0; margin-bottom: 0;'><b>void</b> alglib::xdebugb1outeven(ae_int_t n, boolean_1d_array& a);
</div></pre>
<a name='sub_xdebugb2count'></a><h3 class=pageheader><code>xdebugb2count</code> function</h3>
<pre class=source>
<div style='color: navy; margin-top: 0; margin-bottom: 0;'>/*************************************************************************
This is debug function intended for testing ALGLIB interface generator.
Never use it in any real life project.
Counts number of True values in the boolean 2D array.
-- ALGLIB --
Copyright 11.10.2013 by Bochkanov Sergey
*************************************************************************/
</div><div style='margin-top: 0; margin-bottom: 0;'>ae_int_t alglib::xdebugb2count(boolean_2d_array a);
</div></pre>
<a name='sub_xdebugb2not'></a><h3 class=pageheader><code>xdebugb2not</code> function</h3>
<pre class=source>
<div style='color: navy; margin-top: 0; margin-bottom: 0;'>/*************************************************************************
This is debug function intended for testing ALGLIB interface generator.
Never use it in any real life project.
Replace all values in array by NOT(a[i]).
Array is passed using "shared" convention.
-- ALGLIB --
Copyright 11.10.2013 by Bochkanov Sergey
*************************************************************************/
</div><div style='margin-top: 0; margin-bottom: 0;'><b>void</b> alglib::xdebugb2not(boolean_2d_array& a);
</div></pre>
<a name='sub_xdebugb2outsin'></a><h3 class=pageheader><code>xdebugb2outsin</code> function</h3>
<pre class=source>
<div style='color: navy; margin-top: 0; margin-bottom: 0;'>/*************************************************************************
This is debug function intended for testing ALGLIB interface generator.
Never use it in any real life project.
Generate MxN matrix with elements set to "Sin(3*I+5*J)>0"
Array is passed using "out" convention.
-- ALGLIB --
Copyright 11.10.2013 by Bochkanov Sergey
*************************************************************************/
</div><div style='margin-top: 0; margin-bottom: 0;'><b>void</b> alglib::xdebugb2outsin(ae_int_t m, ae_int_t n, boolean_2d_array& a);
</div></pre>
<a name='sub_xdebugb2transpose'></a><h3 class=pageheader><code>xdebugb2transpose</code> function</h3>
<pre class=source>
<div style='color: navy; margin-top: 0; margin-bottom: 0;'>/*************************************************************************
This is debug function intended for testing ALGLIB interface generator.
Never use it in any real life project.
Transposes array.
Array is passed using "var" convention.
-- ALGLIB --
Copyright 11.10.2013 by Bochkanov Sergey
*************************************************************************/
</div><div style='margin-top: 0; margin-bottom: 0;'><b>void</b> alglib::xdebugb2transpose(boolean_2d_array& a);
</div></pre>
<a name='sub_xdebugc1appendcopy'></a><h3 class=pageheader><code>xdebugc1appendcopy</code> function</h3>
<pre class=source>
<div style='color: navy; margin-top: 0; margin-bottom: 0;'>/*************************************************************************
This is debug function intended for testing ALGLIB interface generator.
Never use it in any real life project.
Appends copy of array to itself.
Array is passed using "var" convention.
-- ALGLIB --
Copyright 11.10.2013 by Bochkanov Sergey
*************************************************************************/
</div><div style='margin-top: 0; margin-bottom: 0;'><b>void</b> alglib::xdebugc1appendcopy(complex_1d_array& a);
</div></pre>
<a name='sub_xdebugc1neg'></a><h3 class=pageheader><code>xdebugc1neg</code> function</h3>
<pre class=source>
<div style='color: navy; margin-top: 0; margin-bottom: 0;'>/*************************************************************************
This is debug function intended for testing ALGLIB interface generator.
Never use it in any real life project.
Replace all values in array by -A[I]
Array is passed using "shared" convention.
-- ALGLIB --
Copyright 11.10.2013 by Bochkanov Sergey
*************************************************************************/
</div><div style='margin-top: 0; margin-bottom: 0;'><b>void</b> alglib::xdebugc1neg(complex_1d_array& a);
</div></pre>
<a name='sub_xdebugc1outeven'></a><h3 class=pageheader><code>xdebugc1outeven</code> function</h3>
<pre class=source>
<div style='color: navy; margin-top: 0; margin-bottom: 0;'>/*************************************************************************
This is debug function intended for testing ALGLIB interface generator.
Never use it in any real life project.
Generate N-element array with even-numbered A[K] set to (x,y) = (K*0.25, K*0.125)
and odd-numbered ones are set to 0.
Array is passed using "out" convention.
-- ALGLIB --
Copyright 11.10.2013 by Bochkanov Sergey
*************************************************************************/
</div><div style='margin-top: 0; margin-bottom: 0;'><b>void</b> alglib::xdebugc1outeven(ae_int_t n, complex_1d_array& a);
</div></pre>
<a name='sub_xdebugc1sum'></a><h3 class=pageheader><code>xdebugc1sum</code> function</h3>
<pre class=source>
<div style='color: navy; margin-top: 0; margin-bottom: 0;'>/*************************************************************************
This is debug function intended for testing ALGLIB interface generator.
Never use it in any real life project.
Returns sum of elements in the array.
-- ALGLIB --
Copyright 11.10.2013 by Bochkanov Sergey
*************************************************************************/
</div><div style='margin-top: 0; margin-bottom: 0;'>alglib::complex alglib::xdebugc1sum(complex_1d_array a);
</div></pre>
<a name='sub_xdebugc2neg'></a><h3 class=pageheader><code>xdebugc2neg</code> function</h3>
<pre class=source>
<div style='color: navy; margin-top: 0; margin-bottom: 0;'>/*************************************************************************
This is debug function intended for testing ALGLIB interface generator.
Never use it in any real life project.
Replace all values in array by -a[i,j]
Array is passed using "shared" convention.
-- ALGLIB --
Copyright 11.10.2013 by Bochkanov Sergey
*************************************************************************/
</div><div style='margin-top: 0; margin-bottom: 0;'><b>void</b> alglib::xdebugc2neg(complex_2d_array& a);
</div></pre>
<a name='sub_xdebugc2outsincos'></a><h3 class=pageheader><code>xdebugc2outsincos</code> function</h3>
<pre class=source>
<div style='color: navy; margin-top: 0; margin-bottom: 0;'>/*************************************************************************
This is debug function intended for testing ALGLIB interface generator.
Never use it in any real life project.
Generate MxN matrix with elements set to "Sin(3*I+5*J),Cos(3*I+5*J)"
Array is passed using "out" convention.
-- ALGLIB --
Copyright 11.10.2013 by Bochkanov Sergey
*************************************************************************/
</div><div style='margin-top: 0; margin-bottom: 0;'><b>void</b> alglib::xdebugc2outsincos(
ae_int_t m,
ae_int_t n,
complex_2d_array& a);
</div></pre>
<a name='sub_xdebugc2sum'></a><h3 class=pageheader><code>xdebugc2sum</code> function</h3>
<pre class=source>
<div style='color: navy; margin-top: 0; margin-bottom: 0;'>/*************************************************************************
This is debug function intended for testing ALGLIB interface generator.
Never use it in any real life project.
Returns sum of elements in the array.
-- ALGLIB --
Copyright 11.10.2013 by Bochkanov Sergey
*************************************************************************/
</div><div style='margin-top: 0; margin-bottom: 0;'>alglib::complex alglib::xdebugc2sum(complex_2d_array a);
</div></pre>
<a name='sub_xdebugc2transpose'></a><h3 class=pageheader><code>xdebugc2transpose</code> function</h3>
<pre class=source>
<div style='color: navy; margin-top: 0; margin-bottom: 0;'>/*************************************************************************
This is debug function intended for testing ALGLIB interface generator.
Never use it in any real life project.
Transposes array.
Array is passed using "var" convention.
-- ALGLIB --
Copyright 11.10.2013 by Bochkanov Sergey
*************************************************************************/
</div><div style='margin-top: 0; margin-bottom: 0;'><b>void</b> alglib::xdebugc2transpose(complex_2d_array& a);
</div></pre>
<a name='sub_xdebugi1appendcopy'></a><h3 class=pageheader><code>xdebugi1appendcopy</code> function</h3>
<pre class=source>
<div style='color: navy; margin-top: 0; margin-bottom: 0;'>/*************************************************************************
This is debug function intended for testing ALGLIB interface generator.
Never use it in any real life project.
Appends copy of array to itself.
Array is passed using "var" convention.
-- ALGLIB --
Copyright 11.10.2013 by Bochkanov Sergey
*************************************************************************/
</div><div style='margin-top: 0; margin-bottom: 0;'><b>void</b> alglib::xdebugi1appendcopy(integer_1d_array& a);
</div></pre>
<a name='sub_xdebugi1neg'></a><h3 class=pageheader><code>xdebugi1neg</code> function</h3>
<pre class=source>
<div style='color: navy; margin-top: 0; margin-bottom: 0;'>/*************************************************************************
This is debug function intended for testing ALGLIB interface generator.
Never use it in any real life project.
Replace all values in array by -A[I]
Array is passed using "shared" convention.
-- ALGLIB --
Copyright 11.10.2013 by Bochkanov Sergey
*************************************************************************/
</div><div style='margin-top: 0; margin-bottom: 0;'><b>void</b> alglib::xdebugi1neg(integer_1d_array& a);
</div></pre>
<a name='sub_xdebugi1outeven'></a><h3 class=pageheader><code>xdebugi1outeven</code> function</h3>
<pre class=source>
<div style='color: navy; margin-top: 0; margin-bottom: 0;'>/*************************************************************************
This is debug function intended for testing ALGLIB interface generator.
Never use it in any real life project.
Generate N-element array with even-numbered A[I] set to I, and odd-numbered
ones set to 0.
Array is passed using "out" convention.
-- ALGLIB --
Copyright 11.10.2013 by Bochkanov Sergey
*************************************************************************/
</div><div style='margin-top: 0; margin-bottom: 0;'><b>void</b> alglib::xdebugi1outeven(ae_int_t n, integer_1d_array& a);
</div></pre>
<a name='sub_xdebugi1sum'></a><h3 class=pageheader><code>xdebugi1sum</code> function</h3>
<pre class=source>
<div style='color: navy; margin-top: 0; margin-bottom: 0;'>/*************************************************************************
This is debug function intended for testing ALGLIB interface generator.
Never use it in any real life project.
Returns sum of elements in the array.
-- ALGLIB --
Copyright 11.10.2013 by Bochkanov Sergey
*************************************************************************/
</div><div style='margin-top: 0; margin-bottom: 0;'>ae_int_t alglib::xdebugi1sum(integer_1d_array a);
</div></pre>
<a name='sub_xdebugi2neg'></a><h3 class=pageheader><code>xdebugi2neg</code> function</h3>
<pre class=source>
<div style='color: navy; margin-top: 0; margin-bottom: 0;'>/*************************************************************************
This is debug function intended for testing ALGLIB interface generator.
Never use it in any real life project.
Replace all values in array by -a[i,j]
Array is passed using "shared" convention.
-- ALGLIB --
Copyright 11.10.2013 by Bochkanov Sergey
*************************************************************************/
</div><div style='margin-top: 0; margin-bottom: 0;'><b>void</b> alglib::xdebugi2neg(integer_2d_array& a);
</div></pre>
<a name='sub_xdebugi2outsin'></a><h3 class=pageheader><code>xdebugi2outsin</code> function</h3>
<pre class=source>
<div style='color: navy; margin-top: 0; margin-bottom: 0;'>/*************************************************************************
This is debug function intended for testing ALGLIB interface generator.
Never use it in any real life project.
Generate MxN matrix with elements set to "Sign(Sin(3*I+5*J))"
Array is passed using "out" convention.
-- ALGLIB --
Copyright 11.10.2013 by Bochkanov Sergey
*************************************************************************/
</div><div style='margin-top: 0; margin-bottom: 0;'><b>void</b> alglib::xdebugi2outsin(ae_int_t m, ae_int_t n, integer_2d_array& a);
</div></pre>
<a name='sub_xdebugi2sum'></a><h3 class=pageheader><code>xdebugi2sum</code> function</h3>
<pre class=source>
<div style='color: navy; margin-top: 0; margin-bottom: 0;'>/*************************************************************************
This is debug function intended for testing ALGLIB interface generator.
Never use it in any real life project.
Returns sum of elements in the array.
-- ALGLIB --
Copyright 11.10.2013 by Bochkanov Sergey
*************************************************************************/
</div><div style='margin-top: 0; margin-bottom: 0;'>ae_int_t alglib::xdebugi2sum(integer_2d_array a);
</div></pre>
<a name='sub_xdebugi2transpose'></a><h3 class=pageheader><code>xdebugi2transpose</code> function</h3>
<pre class=source>
<div style='color: navy; margin-top: 0; margin-bottom: 0;'>/*************************************************************************
This is debug function intended for testing ALGLIB interface generator.
Never use it in any real life project.
Transposes array.
Array is passed using "var" convention.
-- ALGLIB --
Copyright 11.10.2013 by Bochkanov Sergey
*************************************************************************/
</div><div style='margin-top: 0; margin-bottom: 0;'><b>void</b> alglib::xdebugi2transpose(integer_2d_array& a);
</div></pre>
<a name='sub_xdebuginitrecord1'></a><h3 class=pageheader><code>xdebuginitrecord1</code> function</h3>
<pre class=source>
<div style='color: navy; margin-top: 0; margin-bottom: 0;'>/*************************************************************************
This is debug function intended for testing ALGLIB interface generator.
Never use it in any real life project.
Creates and returns XDebugRecord1 structure:
* integer and complex fields of Rec1 are set to 1 and 1+i correspondingly
* array field of Rec1 is set to [2,3]
-- ALGLIB --
Copyright 27.05.2014 by Bochkanov Sergey
*************************************************************************/
</div><div style='margin-top: 0; margin-bottom: 0;'><b>void</b> alglib::xdebuginitrecord1(xdebugrecord1& rec1);
</div></pre>
<a name='sub_xdebugmaskedbiasedproductsum'></a><h3 class=pageheader><code>xdebugmaskedbiasedproductsum</code> function</h3>
<pre class=source>
<div style='color: navy; margin-top: 0; margin-bottom: 0;'>/*************************************************************************
This is debug function intended for testing ALGLIB interface generator.
Never use it in any real life project.
Returns sum of a[i,j]*(1+b[i,j]) such that c[i,j] is True
-- ALGLIB --
Copyright 11.10.2013 by Bochkanov Sergey
*************************************************************************/
</div><div style='margin-top: 0; margin-bottom: 0;'><b>double</b> alglib::xdebugmaskedbiasedproductsum(
ae_int_t m,
ae_int_t n,
real_2d_array a,
real_2d_array b,
boolean_2d_array c);
</div></pre>
<a name='sub_xdebugr1appendcopy'></a><h3 class=pageheader><code>xdebugr1appendcopy</code> function</h3>
<pre class=source>
<div style='color: navy; margin-top: 0; margin-bottom: 0;'>/*************************************************************************
This is debug function intended for testing ALGLIB interface generator.
Never use it in any real life project.
Appends copy of array to itself.
Array is passed using "var" convention.
-- ALGLIB --
Copyright 11.10.2013 by Bochkanov Sergey
*************************************************************************/
</div><div style='margin-top: 0; margin-bottom: 0;'><b>void</b> alglib::xdebugr1appendcopy(real_1d_array& a);
</div></pre>
<a name='sub_xdebugr1neg'></a><h3 class=pageheader><code>xdebugr1neg</code> function</h3>
<pre class=source>
<div style='color: navy; margin-top: 0; margin-bottom: 0;'>/*************************************************************************
This is debug function intended for testing ALGLIB interface generator.
Never use it in any real life project.
Replace all values in array by -A[I]
Array is passed using "shared" convention.
-- ALGLIB --
Copyright 11.10.2013 by Bochkanov Sergey
*************************************************************************/
</div><div style='margin-top: 0; margin-bottom: 0;'><b>void</b> alglib::xdebugr1neg(real_1d_array& a);
</div></pre>
<a name='sub_xdebugr1outeven'></a><h3 class=pageheader><code>xdebugr1outeven</code> function</h3>
<pre class=source>
<div style='color: navy; margin-top: 0; margin-bottom: 0;'>/*************************************************************************
This is debug function intended for testing ALGLIB interface generator.
Never use it in any real life project.
Generate N-element array with even-numbered A[I] set to I*0.25,
and odd-numbered ones are set to 0.
Array is passed using "out" convention.
-- ALGLIB --
Copyright 11.10.2013 by Bochkanov Sergey
*************************************************************************/
</div><div style='margin-top: 0; margin-bottom: 0;'><b>void</b> alglib::xdebugr1outeven(ae_int_t n, real_1d_array& a);
</div></pre>
<a name='sub_xdebugr1sum'></a><h3 class=pageheader><code>xdebugr1sum</code> function</h3>
<pre class=source>
<div style='color: navy; margin-top: 0; margin-bottom: 0;'>/*************************************************************************
This is debug function intended for testing ALGLIB interface generator.
Never use it in any real life project.
Returns sum of elements in the array.
-- ALGLIB --
Copyright 11.10.2013 by Bochkanov Sergey
*************************************************************************/
</div><div style='margin-top: 0; margin-bottom: 0;'><b>double</b> alglib::xdebugr1sum(real_1d_array a);
</div></pre>
<a name='sub_xdebugr2neg'></a><h3 class=pageheader><code>xdebugr2neg</code> function</h3>
<pre class=source>
<div style='color: navy; margin-top: 0; margin-bottom: 0;'>/*************************************************************************
This is debug function intended for testing ALGLIB interface generator.
Never use it in any real life project.
Replace all values in array by -a[i,j]
Array is passed using "shared" convention.
-- ALGLIB --
Copyright 11.10.2013 by Bochkanov Sergey
*************************************************************************/
</div><div style='margin-top: 0; margin-bottom: 0;'><b>void</b> alglib::xdebugr2neg(real_2d_array& a);
</div></pre>
<a name='sub_xdebugr2outsin'></a><h3 class=pageheader><code>xdebugr2outsin</code> function</h3>
<pre class=source>
<div style='color: navy; margin-top: 0; margin-bottom: 0;'>/*************************************************************************
This is debug function intended for testing ALGLIB interface generator.
Never use it in any real life project.
Generate MxN matrix with elements set to "Sin(3*I+5*J)"
Array is passed using "out" convention.
-- ALGLIB --
Copyright 11.10.2013 by Bochkanov Sergey
*************************************************************************/
</div><div style='margin-top: 0; margin-bottom: 0;'><b>void</b> alglib::xdebugr2outsin(ae_int_t m, ae_int_t n, real_2d_array& a);
</div></pre>
<a name='sub_xdebugr2sum'></a><h3 class=pageheader><code>xdebugr2sum</code> function</h3>
<pre class=source>
<div style='color: navy; margin-top: 0; margin-bottom: 0;'>/*************************************************************************
This is debug function intended for testing ALGLIB interface generator.
Never use it in any real life project.
Returns sum of elements in the array.
-- ALGLIB --
Copyright 11.10.2013 by Bochkanov Sergey
*************************************************************************/
</div><div style='margin-top: 0; margin-bottom: 0;'><b>double</b> alglib::xdebugr2sum(real_2d_array a);
</div></pre>
<a name='sub_xdebugr2transpose'></a><h3 class=pageheader><code>xdebugr2transpose</code> function</h3>
<pre class=source>
<div style='color: navy; margin-top: 0; margin-bottom: 0;'>/*************************************************************************
This is debug function intended for testing ALGLIB interface generator.
Never use it in any real life project.
Transposes array.
Array is passed using "var" convention.
-- ALGLIB --
Copyright 11.10.2013 by Bochkanov Sergey
*************************************************************************/
</div><div style='margin-top: 0; margin-bottom: 0;'><b>void</b> alglib::xdebugr2transpose(real_2d_array& a);
</div></pre>
</body>
</html>
|