| 1 |
import scipy |
| 2 |
import numpy |
| 3 |
|
| 4 |
try: |
| 5 |
import cupy |
| 6 |
except: |
| 7 |
import numpy as cupy |
| 8 |
|
| 9 |
from apricot import SumRedundancySelection |
| 10 |
from apricot.optimizers import * |
| 11 |
|
| 12 |
from sklearn.datasets import load_digits |
| 13 |
from sklearn.metrics import pairwise_distances |
| 14 |
|
| 15 |
from numpy.testing import assert_almost_equal |
| 16 |
from numpy.testing import assert_array_equal |
| 17 |
from numpy.testing import assert_array_almost_equal |
| 18 |
|
| 19 |
digits_data = load_digits() |
| 20 |
X_digits = digits_data.data |
| 21 |
|
| 22 |
X_digits_cosine_sparse = scipy.sparse.csr_matrix((1 - pairwise_distances( |
| 23 |
X_digits, metric='cosine')) ** 2) |
| 24 |
X_digits_corr_cupy = cupy.array((1 - pairwise_distances( |
| 25 |
X_digits, metric='correlation')) ** 2) |
| 26 |
X_digits_cosine_cupy = cupy.array((1 - pairwise_distances( |
| 27 |
X_digits, metric='cosine')) ** 2) |
| 28 |
|
| 29 |
digits_corr_ranking = [0, 1631, 1308, 1259, 1024, 673, 734, 1595, 75, 1078, |
| 30 |
958, 447, 1195, 1221, 576, 1660, 998, 1274, 632, 1671, 1572, 1180, 1742, |
| 31 |
1779, 713, 1514, 813, 988, 1576, 757, 1000, 1025, 1419, 1499, 133, 1551, |
| 32 |
1580, 1316, 689, 1589, 756, 1462, 889, 413, 599, 1311, 1275, 1163, 54, |
| 33 |
1657, 1400, 1001, 1264, 1495, 1302, 1154, 1473, 317, 1488, 194, 527, 1283, |
| 34 |
675, 1604, 1077, 215, 766, 946, 1165, 403, 1115, 972, 1079, 1754, 914, 617, |
| 35 |
57, 1182, 751, 1717, 876, 31, 103, 941, 1467, 218, 1440, 637, 982, 1708, |
| 36 |
1272, 7, 966, 981, 163, 1562, 440, 341, 1301, 1216] |
| 37 |
|
| 38 |
digits_corr_gains = [-1.0, -1.0053, -1.2226, -1.2786, -1.5351, -1.5826, |
| 39 |
-1.7436, -2.2005, -2.2884, -2.5087, -2.7581, -2.8347, -3.0216, -3.3001, |
| 40 |
-3.3921, -4.1251, -4.2028, -4.4885, -4.8339, -4.8857, -5.1816, -5.3797, |
| 41 |
-5.7385, -6.03, -6.0674, -6.4577, -6.8554, -6.9494, -7.0362, -7.4869, |
| 42 |
-7.6198, -8.117, -8.5624, -8.7402, -8.9086, -9.2393, -9.372, -9.7991, |
| 43 |
-10.003, -10.3158, -10.7446, -10.8657, -11.3165, -11.518, -11.8186, |
| 44 |
-11.8664, -12.24, -12.5102, -12.865, -13.1717, -13.5104, -13.611, -14.0063, |
| 45 |
-14.3125, -14.4315, -14.9093, -15.4115, -15.5949, -15.8784, -15.9565, |
| 46 |
-16.2537, -16.4321, -16.8201, -17.01, -17.5617, -17.6755, -18.0406, |
| 47 |
-18.2885, -19.0408, -19.1925, -19.3148, -19.7779, -19.8668, -20.3401, |
| 48 |
-20.4092, -21.0325, -21.2272, -21.472, -21.9653, -22.1756, -22.5028, |
| 49 |
-22.8417, -23.1781, -23.34, -23.5919, -24.1087, -24.2592, -24.4434, |
| 50 |
-24.7991, -25.0295, -25.2185, -25.8405, -26.3942, -26.5413, -26.8281, |
| 51 |
-27.0728, -27.2003, -27.7439, -27.9688, -28.2785] |
| 52 |
|
| 53 |
digits_euclidean_ranking = [0, 623, 163, 1572, 215, 241, 988, 1635, 1505, 766, |
| 54 |
673, 67, 1296, 283, 947, 1589, 172, 832, 1001, 1259, 1495, 1111, 919, 1576, |
| 55 |
141, 1710, 1437, 1106, 1308, 1595, 982, 317, 1274, 131, 1375, 204, 998, 788, |
| 56 |
732, 756, 1462, 916, 155, 1086, 77, 851, 1574, 680, 263, 1436, 1205, 609, |
| 57 |
1660, 1221, 1275, 1035, 1514, 953, 1754, 1604, 853, 1562, 1094, 1457, 1264, |
| 58 |
1685, 218, 447, 1492, 689, 951, 235, 1272, 734, 1657, 494, 517, 1317, 210, |
| 59 |
629, 1467, 1587, 1290, 926, 1735, 565, 1419, 1522, 801, 660, 1499, 1220, |
| 60 |
757, 1000, 312, 1470, 135, 1070, 889, 1426] |
| 61 |
|
| 62 |
digits_euclidean_gains = [-5935.0, -9777.0, -13543.0, -17943.0, -22857.0, |
| 63 |
-27221.0, -33987.0, -37289.0, -42655.0, -44649.0, -50719.0, -54275.0, |
| 64 |
-61769.0, -67425.0, -69983.0, -75243.0, -78809.0, -86093.0, -91183.0, |
| 65 |
-95109.0, -100791.0, -106791.0, -111741.0, -116985.0, -121935.0, |
| 66 |
-128081.0, -132819.0, -138007.0, -142801.0, -148589.0, -153975.0, |
| 67 |
-157323.0, -164121.0, -168921.0, -174335.0, -179963.0, -184405.0, |
| 68 |
-190255.0, -196089.0, -201213.0, -206047.0, -210323.0, -215441.0, |
| 69 |
-221839.0, -227461.0, -233779.0, -238253.0, -243317.0, -248155.0, |
| 70 |
-254819.0, -259613.0, -263847.0, -270369.0, -274331.0, -281473.0, |
| 71 |
-286875.0, -292657.0, -296343.0, -303373.0, -308247.0, -314769.0, |
| 72 |
-317825.0, -324991.0, -330459.0, -336565.0, -342469.0, -347659.0, |
| 73 |
-353903.0, -358113.0, -365203.0, -370033.0, -376423.0, -379817.0, |
| 74 |
-386027.0, -391541.0, -397755.0, -402413.0, -406833.0, -413851.0, |
| 75 |
-420295.0, -425313.0, -430743.0, -437069.0, -442009.0, -445999.0, |
| 76 |
-453759.0, -460717.0, -467225.0, -470579.0, -478611.0, -481381.0, |
| 77 |
-486279.0, -492717.0, -501067.0, -507697.0, -511129.0, -517415.0, |
| 78 |
-523749.0, -527895.0, -533187.0] |
| 79 |
|
| 80 |
digits_cosine_ranking = [0, 1626, 1308, 1259, 1078, 673, 1595, 958, 75, |
| 81 |
447, 1660, 1221, 1180, 734, 1589, 1462, 632, 1671, 1779, 1717, 133, |
| 82 |
966, 914, 1274, 1514, 1000, 1035, 1580, 1373, 1311, 403, 1272, 946, |
| 83 |
766, 215, 1611, 813, 876, 1572, 1316, 1631, 713, 1467, 1499, 1508, |
| 84 |
941, 1264, 1275, 194, 1024, 527, 1079, 998, 1473, 1182, 990, 131, |
| 85 |
1585, 204, 617, 675, 67, 1001, 1200, 31, 413, 341, 1025, 1213, 1301, |
| 86 |
1576, 1400, 218, 317, 442, 1734, 192, 1551, 801, 1495, 1708, 889, 561, |
| 87 |
1604, 4, 751, 704, 1314, 994, 155, 151, 981, 1125, 498, 57, 1480, 1742, |
| 88 |
1562, 1195, 988] |
| 89 |
|
| 90 |
digits_cosine_gains = [-1.0, -1.2608, -1.8589, -2.2945, -2.9785, -3.273, |
| 91 |
-4.0554, -4.5342, -5.1995, -5.9721, -6.2496, -6.8113, -7.5169, -8.1488, |
| 92 |
-9.0023, -9.2591, -10.006, -10.618, -11.3895, -11.7181, -12.7751, -13.2362, |
| 93 |
-14.0317, -14.7067, -15.1397, -15.7079, -16.3536, -17.0946, -17.5568, |
| 94 |
-18.2507, -19.4527, -20.1545, -20.7871, -21.4178, -21.7413, -22.5283, |
| 95 |
-23.3034, -23.7622, -24.2979, -25.3123, -25.7659, -26.4916, -27.6042, |
| 96 |
-28.0639, -28.5733, -29.3231, -30.0786, -30.4752, -31.2483, -31.8044, |
| 97 |
-32.8744, -33.6345, -34.0621, -34.7931, -35.4228, -36.1701, -36.9265, |
| 98 |
-37.5654, -38.2502, -38.9728, -39.8254, -40.4355, -41.1174, -41.7559, |
| 99 |
-42.4764, -43.3304, -43.9796, -44.5423, -45.3739, -46.0711, -46.7337, |
| 100 |
-47.2139, -47.7222, -48.8554, -49.4269, -50.3968, -51.0522, -51.5147, |
| 101 |
-52.5101, -52.9929, -53.7409, -54.115, -55.3053, -55.9741, -56.6847, |
| 102 |
-57.6243, -58.176, -58.5817, -59.7514, -60.3535, -60.7568, -61.6063, |
| 103 |
-62.5969, -63.1069, -64.0203, -64.638, -65.5255, -66.1212, -66.8677, |
| 104 |
-67.4475] |
| 105 |
|
| 106 |
digits_cosine_greedi_ranking = [16, 617, 1660, 673, 1000, 1589, 1308, 1221, |
| 107 |
1595, 1078, 447, 1626, 1514, 1259, 632, 133, 1671, 1717, 914, 75, 946, |
| 108 |
734, 1779, 766, 1462, 1580, 1272, 1473, 1311, 1611, 1180, 1572, 876, 1024, |
| 109 |
1631, 1274, 215, 1035, 403, 958, 1316, 966, 1182, 1373, 1508, 1025, 1467, |
| 110 |
1499, 194, 1275, 1264, 813, 998, 67, 527, 1079, 131, 204, 990, 1585, 675, |
| 111 |
713, 1200, 1301, 413, 192, 1001, 1400, 1576, 218, 1213, 981, 1734, 31, 341, |
| 112 |
317, 1495, 889, 1708, 801, 1125, 442, 751, 1059, 1314, 4, 12, 1604, 1562, |
| 113 |
704, 107, 561, 163, 988, 498, 1551, 1195, 1480, 994, 151] |
| 114 |
|
| 115 |
digits_cosine_greedi_gains = [-1.0, -1.3478, -1.9394, -2.3069, -3.1291, -3.4523, |
| 116 |
-3.811, -4.7084, -5.3596, -5.7415, -6.1306, -6.9337, -7.5382, -7.9192, |
| 117 |
-8.7388, -9.5881, -10.0552, -10.5168, -11.4115, -12.0015, -12.4559, -13.359, |
| 118 |
-13.957, -14.6866, -14.849, -15.9155, -16.5696, -17.298, -18.0227, -18.5558, |
| 119 |
-19.1504, -19.9612, -20.7278, -21.2489, -22.0421, -22.5731, -23.1782, -23.8589, |
| 120 |
-24.283, -25.1361, -25.8376, -26.5521, -27.0485, -28.0133, -28.5404, -29.4877, |
| 121 |
-30.0386, -30.6349, -31.0334, -32.2181, -32.7685, -33.3918, -34.193, -34.753, |
| 122 |
-35.6558, -36.0367, -36.7902, -37.8717, -38.4027, -38.9991, -39.478, -40.4198, |
| 123 |
-41.1552, -41.7612, -42.363, -43.2004, -44.1362, -44.6401, -45.3337, -45.9022, |
| 124 |
-46.5817, -47.0738, -48.3477, -48.9314, -49.5341, -50.1541, -51.1846, -51.5936, |
| 125 |
-52.3633, -52.9651, -53.8957, -54.671, -55.369, -55.8204, -56.6435, -57.4165, |
| 126 |
-58.2005, -59.0945, -59.66, -60.1562, -61.0494, -62.0454, -62.5839, -63.0563, |
| 127 |
-64.1159, -64.557, -65.2267, -66.0529, -66.849, -67.6248] |
| 128 |
|
| 129 |
digits_cosine_stochastic_ranking = [1081, 1014, 1386, 770, 567, 137, 723, 1491, |
| 130 |
1274, 1492, 1728, 1456, 186, 1448, 386, 148, 891, 1759, 1424, 587, 191, 629, |
| 131 |
1507, 1084, 1473, 946, 518, 638, 1739, 502, 1537, 1227, 689, 88, 238, 1667, |
| 132 |
1785, 1067, 1461, 1222, 1099, 607, 364, 1572, 1195, 217, 1034, 208, 84, |
| 133 |
1128, 425, 345, 626, 843, 1070, 83, 1449, 1071, 1644, 1392, 1415, 449, 802, |
| 134 |
1348, 1553, 175, 1455, 1770, 1395, 1032, 879, 1220, 1137, 129, 754, 1695, |
| 135 |
1459, 782, 549, 1069, 260, 834, 517, 919, 1622, 700, 424, 1685, 245, 1339, |
| 136 |
1152, 1212, 1425, 937, 1665, 291, 1535, 701, 1508, 1219] |
| 137 |
|
| 138 |
digits_cosine_stochastic_gains = [-1.0, -2.5269, -2.7995, -3.2931, -5.5216, |
| 139 |
-6.0637, -7.7541, -8.1408, -7.2975, -10.4072, -11.2111, -10.3373, -10.6228, |
| 140 |
-12.2424, -13.1709, -18.8132, -14.5518, -19.0894, -18.2777, -18.8472, |
| 141 |
-17.3115, -23.1732, -23.7351, -26.0553, -18.8892, -17.7293, -29.2051, |
| 142 |
-23.7703, -27.484, -27.9689, -34.4357, -33.4325, -23.4861, -31.3646, |
| 143 |
-30.627, -35.9673, -36.9382, -38.8354, -37.5974, -33.8208, -38.1725, |
| 144 |
-43.8267, -39.2434, -31.1408, -34.4416, -44.662, -43.0794, -51.7522, |
| 145 |
-45.9076, -45.5261, -53.8562, -54.4264, -51.2669, -53.0412, -44.3672, |
| 146 |
-52.5772, -53.4106, -66.2475, -61.2402, -58.9847, -59.9399, -65.6418, |
| 147 |
-67.2847, -61.22, -63.0781, -66.7774, -76.5662, -67.3135, -69.2438, |
| 148 |
-66.9263, -77.0899, -69.448, -57.6908, -71.3056, -69.0238, -82.4863, |
| 149 |
-82.4559, -78.3968, -79.779, -96.6816, -69.961, -84.4731, -70.0465, |
| 150 |
-69.5608, -81.6036, -94.3322, -109.4369, -80.056, -72.2626, -79.6127, |
| 151 |
-80.3194, -86.0693, -95.2923, -89.2698, -82.4462, -84.8242, -99.9732, |
| 152 |
-102.3375, -72.4036, -91.7773] |
| 153 |
|
| 154 |
digits_cosine_sample_ranking = [0, 1626, 1308, 1589, 673, 734, 914, 75, 1660, |
| 155 |
447, 1717, 1671, 1078, 133, 1221, 958, 1514, 1373, 1580, 766, 966, 1272, |
| 156 |
1462, 1035, 1275, 1311, 632, 1180, 1631, 1576, 946, 1024, 215, 1274, 403, |
| 157 |
527, 876, 1611, 617, 813, 998, 1499, 1508, 1079, 1473, 194, 317, 1264, |
| 158 |
1316, 67, 1562, 1585, 204, 990, 675, 1314, 1301, 889, 218, 941, 413, 994, |
| 159 |
1604, 4, 1025, 801, 341, 31, 131, 704, 442, 689, 155, 192, 751, 1163, 1400, |
| 160 |
1552, 57, 1731, 561, 151, 163, 1734, 1648, 1495, 1587, 498, 972, 728, 1195, |
| 161 |
988, 1125, 1304, 800, 1721, 7, 19, 1754, 981] |
| 162 |
|
| 163 |
digits_cosine_sample_gains = [-1.0, -1.2608, -1.8589, -2.3718, -2.9235, |
| 164 |
-3.3502, -4.1682, -4.7961, -5.3775, -5.8901, -6.4477, -6.8991, -7.7067, |
| 165 |
-8.1207, -8.9752, -9.6247, -10.2187, -10.4458, -11.617, -12.2125, -12.9059, |
| 166 |
-13.5264, -14.323, -14.9052, -15.3206, -16.1262, -16.5538, -17.6517, |
| 167 |
-18.1862, -18.9705, -19.4022, -20.3438, -20.9218, -21.26, -22.1514, |
| 168 |
-22.8178, -23.5192, -24.0593, -24.7916, -25.6778, -26.448, -27.0072, |
| 169 |
-27.5813, -28.1622, -28.9791, -29.6623, -30.212, -30.8247, -31.4657, |
| 170 |
-32.7805, -33.1168, -33.913, -34.5045, -35.0171, -35.7662, -36.9909, |
| 171 |
-37.4624, -38.2663, -38.7272, -39.5656, -40.1986, -40.7718, -41.6487, |
| 172 |
-42.6081, -43.0435, -43.8426, -44.2991, -45.0666, -45.9207, -46.4336, |
| 173 |
-47.4731, -47.8693, -48.9462, -49.5734, -50.278, -51.0253, -51.7427, |
| 174 |
-52.3166, -53.3424, -54.1884, -54.6391, -55.5147, -55.9356, -56.7033, |
| 175 |
-57.3959, -58.1553, -58.8327, -59.6321, -60.1963, -60.9938, -61.5477, |
| 176 |
-62.3124, -62.7948, -63.7351, -64.9801, -65.5436, -66.2565, -66.9823, |
| 177 |
-67.8899, -68.5351] |
| 178 |
|
| •179 |
digits_cosine_modular_ranking = [0, 1, 2, 3, 4, 5, 6, 7, 8, 9, |
| 180 |
10, 11, 12, 13, 14, 15, 16, 17, 18, 19, |
| 181 |
20, 21, 22, 23, 24, 25, 26, 27, 28, 29, |
| 182 |
30, 31, 32, 33, 34, 35, 36, 37, 38, 39, |
| 183 |
40, 41, 42, 43, 44, 45, 46, 47, 48, 49, |
| 184 |
50, 51, 52, 53, 54, 55, 56, 57, 58, 59, |
| 185 |
60, 61, 62, 63, 64, 65, 66, 67, 68, 69, |
| 186 |
70, 71, 72, 73, 74, 75, 76, 77, 78, 79, |
| 187 |
80, 81, 82, 83, 84, 85, 86, 87, 88, 89, |
| 188 |
90, 91, 92, 93, 94, 95, 96, 97, 98, 99] |
| 189 |
|
| •190 |
digits_cosine_modular_gains = [-1.0, -1.5389, -3.0365, -3.5809, -4.1258, -6.3708, -7.4814, -5.2822, -9.816, -10.1087, |
| 191 |
-11.2945, -12.0195, -10.2326, -14.4426, -15.4059, -13.5579, -15.712, -18.8125, -18.1894, -16.5568, |
| 192 |
-21.4572, -22.6813, -20.5902, -21.7776, -22.6762, -22.7138, -28.8823, -26.2444, -31.125, -29.2979, |
| 193 |
-27.6456, -27.191, -32.4208, -35.4842, -33.8871, -37.3775, -40.0967, -36.2334, -36.487, -41.201, |
| 194 |
-46.9144, -44.8115, -41.252, -40.5032, -41.1934, -44.3236, -47.6659, -46.5503, -47.7433, -48.3655, |
| 195 |
-42.9863, -45.7986, -52.5101, -57.7592, -46.5784, -63.3521, -56.248, -52.9443, -56.6673, -59.9108, |
| 196 |
-57.0929, -66.185, -66.4162, -69.7889, -63.3601, -60.7774, -64.9483, -53.2438, -64.4567, -63.1722, |
| 197 |
-69.1823, -66.228, -78.5513, -71.3569, -84.6291, -60.0869, -84.3693, -69.2598, -71.6762, -79.8334, |
| 198 |
-79.2383, -85.0744, -84.2064, -79.5252, -75.8808, -84.791, -80.2349, -86.4289, -89.9171, -89.6284, |
| 199 |
-91.0734, -95.421, -94.9176, -97.0423, -93.7396, -101.5086, -100.2028, -99.8039, -100.3847, -102.4461] |
| 200 |
|
| 201 |
# Test some similarity functions |
| 202 |
|
| 203 |
def test_digits_euclidean_naive(): |
| 204 |
model = SumRedundancySelection(100, 'euclidean', optimizer='naive') |
| 205 |
model.fit(X_digits) |
| 206 |
assert_array_equal(model.ranking, digits_euclidean_ranking) |
| 207 |
assert_array_almost_equal(model.gains, digits_euclidean_gains, 4) |
| 208 |
assert_array_almost_equal(model.subset, X_digits[model.ranking]) |
| 209 |
|
| 210 |
def test_digits_euclidean_lazy(): |
| 211 |
model = SumRedundancySelection(100, 'euclidean', optimizer='lazy') |
| 212 |
model.fit(X_digits) |
| 213 |
assert_array_equal(model.ranking, digits_euclidean_ranking) |
| 214 |
assert_array_almost_equal(model.gains, digits_euclidean_gains, 4) |
| 215 |
assert_array_almost_equal(model.subset, X_digits[model.ranking]) |
| 216 |
|
| 217 |
def test_digits_euclidean_two_stage(): |
| 218 |
model = SumRedundancySelection(100, 'euclidean', optimizer='two-stage') |
| 219 |
model.fit(X_digits) |
| 220 |
assert_array_equal(model.ranking, digits_euclidean_ranking) |
| 221 |
assert_array_almost_equal(model.gains, digits_euclidean_gains, 4) |
| 222 |
assert_array_almost_equal(model.subset, X_digits[model.ranking]) |
| 223 |
|
| 224 |
def test_digits_corr_naive(): |
| 225 |
model = SumRedundancySelection(100, 'corr', optimizer='naive') |
| 226 |
model.fit(X_digits) |
| 227 |
assert_array_equal(model.ranking, digits_corr_ranking) |
| 228 |
assert_array_almost_equal(model.gains, digits_corr_gains, 4) |
| 229 |
assert_array_almost_equal(model.subset, X_digits[model.ranking]) |
| 230 |
|
| 231 |
def test_digits_corr_lazy(): |
| 232 |
model = SumRedundancySelection(100, 'corr', optimizer='lazy') |
| 233 |
model.fit(X_digits) |
| 234 |
assert_array_equal(model.ranking, digits_corr_ranking) |
| 235 |
assert_array_almost_equal(model.gains, digits_corr_gains, 4) |
| 236 |
assert_array_almost_equal(model.subset, X_digits[model.ranking]) |
| 237 |
|
| 238 |
def test_digits_corr_two_stage(): |
| 239 |
model = SumRedundancySelection(100, 'corr', optimizer='two-stage') |
| 240 |
model.fit(X_digits) |
| 241 |
assert_array_equal(model.ranking, digits_corr_ranking) |
| 242 |
assert_array_almost_equal(model.gains, digits_corr_gains, 4) |
| 243 |
assert_array_almost_equal(model.subset, X_digits[model.ranking]) |
| 244 |
|
| 245 |
def test_digits_cosine_naive(): |
| 246 |
model = SumRedundancySelection(100, 'cosine', optimizer='naive') |
| 247 |
model.fit(X_digits) |
| 248 |
assert_array_equal(model.ranking, digits_cosine_ranking) |
| 249 |
assert_array_almost_equal(model.gains, digits_cosine_gains, 4) |
| 250 |
assert_array_almost_equal(model.subset, X_digits[model.ranking]) |
| 251 |
|
| 252 |
def test_digits_cosine_lazy(): |
| 253 |
model = SumRedundancySelection(100, 'cosine', optimizer='lazy') |
| 254 |
model.fit(X_digits) |
| 255 |
assert_array_equal(model.ranking, digits_cosine_ranking) |
| 256 |
assert_array_almost_equal(model.gains, digits_cosine_gains, 4) |
| 257 |
assert_array_almost_equal(model.subset, X_digits[model.ranking]) |
| 258 |
|
| 259 |
def test_digits_cosine_two_stage(): |
| 260 |
model = SumRedundancySelection(100, 'cosine', optimizer='two-stage') |
| 261 |
model.fit(X_digits) |
| 262 |
assert_array_equal(model.ranking, digits_cosine_ranking) |
| 263 |
assert_array_almost_equal(model.gains, digits_cosine_gains, 4) |
| 264 |
assert_array_almost_equal(model.subset, X_digits[model.ranking]) |
| 265 |
|
| 266 |
def test_digits_precomputed_naive(): |
| 267 |
model = SumRedundancySelection(100, 'precomputed', optimizer='naive') |
| 268 |
model.fit(X_digits_corr_cupy) |
| 269 |
assert_array_equal(model.ranking, digits_corr_ranking) |
| 270 |
assert_array_almost_equal(model.gains, digits_corr_gains, 4) |
| 271 |
|
| 272 |
def test_digits_precomputed_lazy(): |
| 273 |
model = SumRedundancySelection(100, 'precomputed', optimizer='lazy') |
| 274 |
model.fit(X_digits_corr_cupy) |
| 275 |
assert_array_equal(model.ranking, digits_corr_ranking) |
| 276 |
assert_array_almost_equal(model.gains, digits_corr_gains, 4) |
| 277 |
|
| 278 |
def test_digits_precomputed_two_stage(): |
| 279 |
model = SumRedundancySelection(100, 'precomputed', optimizer='two-stage') |
| 280 |
model.fit(X_digits_corr_cupy) |
| 281 |
assert_array_equal(model.ranking, digits_corr_ranking) |
| 282 |
assert_array_almost_equal(model.gains, digits_corr_gains, 4) |
| 283 |
|
| 284 |
# Test with initialization |
| 285 |
|
| 286 |
def test_digits_euclidean_naive_init(): |
| 287 |
model = SumRedundancySelection(100, 'euclidean', optimizer='naive', |
| 288 |
initial_subset=digits_euclidean_ranking[:5]) |
| 289 |
model.fit(X_digits) |
| 290 |
assert_array_equal(model.ranking[:20], digits_euclidean_ranking[5:25]) |
| 291 |
assert_array_almost_equal(model.gains[:20], digits_euclidean_gains[5:25], 4) |
| 292 |
assert_array_almost_equal(model.subset, X_digits[model.ranking]) |
| 293 |
|
| 294 |
def test_digits_euclidean_lazy_init(): |
| 295 |
model = SumRedundancySelection(100, 'euclidean', optimizer='lazy', |
| 296 |
initial_subset=digits_euclidean_ranking[:5]) |
| 297 |
model.fit(X_digits) |
| 298 |
assert_array_equal(model.ranking[:-5], digits_euclidean_ranking[5:]) |
| 299 |
assert_array_almost_equal(model.gains[:-5], digits_euclidean_gains[5:], 4) |
| 300 |
assert_array_almost_equal(model.subset, X_digits[model.ranking]) |
| 301 |
|
| 302 |
def test_digits_euclidean_two_stage_init(): |
| 303 |
model = SumRedundancySelection(100, 'euclidean', optimizer='two-stage', |
| 304 |
initial_subset=digits_euclidean_ranking[:5]) |
| 305 |
model.fit(X_digits) |
| 306 |
assert_array_equal(model.ranking[:-5], digits_euclidean_ranking[5:]) |
| 307 |
assert_array_almost_equal(model.gains[:-5], digits_euclidean_gains[5:], 4) |
| 308 |
assert_array_almost_equal(model.subset, X_digits[model.ranking]) |
| 309 |
|
| 310 |
def test_digits_corr_naive_init(): |
| 311 |
model = SumRedundancySelection(100, 'corr', optimizer='naive', |
| 312 |
initial_subset=digits_corr_ranking[:5]) |
| 313 |
model.fit(X_digits) |
| 314 |
assert_array_equal(model.ranking[:-5], digits_corr_ranking[5:]) |
| 315 |
assert_array_almost_equal(model.gains[:-5], digits_corr_gains[5:], 4) |
| 316 |
assert_array_almost_equal(model.subset, X_digits[model.ranking]) |
| 317 |
|
| 318 |
def test_digits_corr_lazy_init(): |
| 319 |
model = SumRedundancySelection(100, 'corr', optimizer='lazy', |
| 320 |
initial_subset=digits_corr_ranking[:5]) |
| 321 |
model.fit(X_digits) |
| 322 |
assert_array_equal(model.ranking[:-5], digits_corr_ranking[5:]) |
| 323 |
assert_array_almost_equal(model.gains[:-5], digits_corr_gains[5:], 4) |
| 324 |
assert_array_almost_equal(model.subset, X_digits[model.ranking]) |
| 325 |
|
| 326 |
def test_digits_corr_two_stage_init(): |
| 327 |
model = SumRedundancySelection(100, 'corr', optimizer='two-stage', |
| 328 |
initial_subset=digits_corr_ranking[:5]) |
| 329 |
model.fit(X_digits) |
| 330 |
assert_array_equal(model.ranking[:-5], digits_corr_ranking[5:]) |
| 331 |
assert_array_almost_equal(model.gains[:-5], digits_corr_gains[5:], 4) |
| 332 |
assert_array_almost_equal(model.subset, X_digits[model.ranking]) |
| 333 |
|
| 334 |
def test_digits_cosine_naive_init(): |
| 335 |
model = SumRedundancySelection(100, 'cosine', optimizer='naive', |
| 336 |
initial_subset=digits_cosine_ranking[:5]) |
| 337 |
model.fit(X_digits) |
| 338 |
assert_array_equal(model.ranking[:-5], digits_cosine_ranking[5:]) |
| 339 |
assert_array_almost_equal(model.gains[:-5], digits_cosine_gains[5:], 4) |
| 340 |
assert_array_almost_equal(model.subset, X_digits[model.ranking]) |
| 341 |
|
| 342 |
def test_digits_cosine_lazy_init(): |
| 343 |
model = SumRedundancySelection(100, 'cosine', optimizer='lazy', |
| 344 |
initial_subset=digits_cosine_ranking[:5]) |
| 345 |
model.fit(X_digits) |
| 346 |
assert_array_equal(model.ranking[:-5], digits_cosine_ranking[5:]) |
| 347 |
assert_array_almost_equal(model.gains[:-5], digits_cosine_gains[5:], 4) |
| 348 |
assert_array_almost_equal(model.subset, X_digits[model.ranking]) |
| 349 |
|
| 350 |
def test_digits_cosine_two_stage_init(): |
| 351 |
model = SumRedundancySelection(100, 'cosine', optimizer='two-stage', |
| 352 |
initial_subset=digits_cosine_ranking[:5]) |
| 353 |
model.fit(X_digits) |
| 354 |
assert_array_equal(model.ranking[:-5], digits_cosine_ranking[5:]) |
| 355 |
assert_array_almost_equal(model.gains[:-5], digits_cosine_gains[5:], 4) |
| 356 |
assert_array_almost_equal(model.subset, X_digits[model.ranking]) |
| 357 |
|
| 358 |
def test_digits_precomputed_naive_init(): |
| 359 |
model = SumRedundancySelection(100, 'precomputed', optimizer='naive', |
| 360 |
initial_subset=digits_cosine_ranking[:5]) |
| 361 |
model.fit(X_digits_cosine_cupy) |
| 362 |
assert_array_equal(model.ranking[:-5], digits_cosine_ranking[5:]) |
| 363 |
assert_array_almost_equal(model.gains[:-5], digits_cosine_gains[5:], 4) |
| 364 |
|
| 365 |
def test_digits_precomputed_lazy_init(): |
| 366 |
model = SumRedundancySelection(100, 'precomputed', optimizer='lazy', |
| 367 |
initial_subset=digits_cosine_ranking[:5]) |
| 368 |
model.fit(X_digits_cosine_cupy) |
| 369 |
assert_array_equal(model.ranking[:-5], digits_cosine_ranking[5:]) |
| 370 |
assert_array_almost_equal(model.gains[:-5], digits_cosine_gains[5:], 4) |
| 371 |
|
| 372 |
def test_digits_precomputed_two_stage_init(): |
| 373 |
model = SumRedundancySelection(100, 'precomputed', optimizer='two-stage', |
| 374 |
initial_subset=digits_cosine_ranking[:5]) |
| 375 |
model.fit(X_digits_cosine_cupy) |
| 376 |
assert_array_equal(model.ranking[:-5], digits_cosine_ranking[5:]) |
| 377 |
assert_array_almost_equal(model.gains[:-5], digits_cosine_gains[5:], 4) |
| 378 |
|
| 379 |
# Test all optimizers |
| 380 |
|
| 381 |
def test_digits_cosine_greedi_nn(): |
| 382 |
model = SumRedundancySelection(100, 'cosine', optimizer='greedi', |
| 383 |
optimizer_kwds={'optimizer1': 'naive', 'optimizer2': 'naive'}, |
| 384 |
random_state=0) |
| 385 |
model.fit(X_digits) |
| 386 |
assert_array_equal(model.ranking, digits_cosine_greedi_ranking) |
| 387 |
assert_array_almost_equal(model.gains, digits_cosine_greedi_gains, 4) |
| 388 |
assert_array_almost_equal(model.subset, X_digits[model.ranking]) |
| 389 |
|
| 390 |
def test_digits_cosine_greedi_ll(): |
| 391 |
model = SumRedundancySelection(100, 'cosine', optimizer='greedi', |
| 392 |
optimizer_kwds={'optimizer1': 'lazy', 'optimizer2': 'lazy'}, |
| 393 |
random_state=0) |
| 394 |
model.fit(X_digits) |
| 395 |
assert_array_equal(model.ranking, digits_cosine_greedi_ranking) |
| 396 |
assert_array_almost_equal(model.gains, digits_cosine_greedi_gains, 4) |
| 397 |
assert_array_almost_equal(model.subset, X_digits[model.ranking]) |
| 398 |
|
| 399 |
def test_digits_cosine_greedi_ln(): |
| 400 |
model = SumRedundancySelection(100, 'cosine', optimizer='greedi', |
| 401 |
optimizer_kwds={'optimizer1': 'lazy', 'optimizer2': 'naive'}, |
| 402 |
random_state=0) |
| 403 |
model.fit(X_digits) |
| 404 |
assert_array_equal(model.ranking, digits_cosine_greedi_ranking) |
| 405 |
assert_array_almost_equal(model.gains, digits_cosine_greedi_gains, 4) |
| 406 |
assert_array_almost_equal(model.subset, X_digits[model.ranking]) |
| 407 |
|
| 408 |
def test_digits_cosine_greedi_nl(): |
| 409 |
model = SumRedundancySelection(100, 'cosine', optimizer='greedi', |
| 410 |
optimizer_kwds={'optimizer1': 'naive', 'optimizer2': 'lazy'}, |
| 411 |
random_state=0) |
| 412 |
model.fit(X_digits) |
| 413 |
assert_array_equal(model.ranking, digits_cosine_greedi_ranking) |
| 414 |
assert_array_almost_equal(model.gains, digits_cosine_greedi_gains, 4) |
| 415 |
assert_array_almost_equal(model.subset, X_digits[model.ranking]) |
| 416 |
|
| 417 |
def test_digits_cosine_approximate(): |
| 418 |
pass |
| 419 |
#model = SumRedundancySelection(100, 'cosine', optimizer='approximate-lazy') |
| 420 |
#model.fit(X_digits) |
| 421 |
#assert_array_equal(model.ranking, digits_cosine_approx_ranking) |
| 422 |
#assert_array_almost_equal(model.gains, digits_cosine_approx_gains, 4) |
| 423 |
|
| 424 |
def test_digits_cosine_stochastic(): |
| 425 |
model = SumRedundancySelection(100, 'cosine', optimizer='stochastic', |
| 426 |
random_state=0) |
| 427 |
model.fit(X_digits) |
| 428 |
assert_array_equal(model.ranking, digits_cosine_stochastic_ranking) |
| 429 |
assert_array_almost_equal(model.gains, digits_cosine_stochastic_gains, 4) |
| 430 |
assert_array_almost_equal(model.subset, X_digits[model.ranking]) |
| 431 |
|
| 432 |
def test_digits_cosine_sample(): |
| 433 |
model = SumRedundancySelection(100, 'cosine', optimizer='sample', |
| 434 |
random_state=0) |
| 435 |
model.fit(X_digits) |
| 436 |
assert_array_equal(model.ranking, digits_cosine_sample_ranking) |
| 437 |
assert_array_almost_equal(model.gains, digits_cosine_sample_gains, 4) |
| 438 |
assert_array_almost_equal(model.subset, X_digits[model.ranking]) |
| 439 |
|
| 440 |
def test_digits_sqrt_modular(): |
| 441 |
model = SumRedundancySelection(100, 'cosine', optimizer='modular', |
| 442 |
random_state=0) |
| 443 |
model.fit(X_digits) |
| 444 |
assert_array_equal(model.ranking, digits_cosine_modular_ranking) |
| 445 |
assert_array_almost_equal(model.gains, digits_cosine_modular_gains, 4) |
| 446 |
assert_array_almost_equal(model.subset, X_digits[model.ranking]) |
| 447 |
|
| 448 |
# Using the partial_fit method |
| 449 |
|
| 450 |
def test_digits_cosine_sieve_batch(): |
| 451 |
return |
| 452 |
model = SumRedundancySelection(100, 'cosine', random_state=0, |
| 453 |
reservoir=X_digits) |
| 454 |
model.partial_fit(X_digits) |
| 455 |
print("[" + ", ".join(map(str, model.ranking)) + "]") |
| 456 |
print("[" + ", ".join([str(round(gain, 4)) for gain in model.gains]) + "]") |
| 457 |
assert_array_equal(model.ranking, digits_cosine_sieve_ranking) |
| 458 |
assert_array_almost_equal(model.gains, digits_cosine_sieve_gains, 4) |
| 459 |
assert_array_almost_equal(model.subset, X_digits[model.ranking]) |
| 460 |
|
| 461 |
def test_digits_cosine_sieve_minibatch(): |
| 462 |
return |
| 463 |
model = SumRedundancySelection(100, 'cosine', random_state=0, |
| 464 |
reservoir=X_digits) |
| 465 |
model.partial_fit(X_digits[:300]) |
| 466 |
model.partial_fit(X_digits[300:500]) |
| 467 |
model.partial_fit(X_digits[500:]) |
| 468 |
assert_array_equal(model.ranking, digits_cosine_sieve_ranking) |
| 469 |
assert_array_almost_equal(model.gains, digits_cosine_sieve_gains, 4) |
| 470 |
assert_array_almost_equal(model.subset, X_digits[model.ranking]) |
| 471 |
|
| 472 |
# Using Optimizer Objects |
| 473 |
|
| 474 |
def test_digits_cosine_naive_object(): |
| 475 |
model = SumRedundancySelection(100, 'cosine', optimizer=NaiveGreedy()) |
| 476 |
model.fit(X_digits) |
| 477 |
assert_array_equal(model.ranking, digits_cosine_ranking) |
| 478 |
assert_array_almost_equal(model.gains, digits_cosine_gains, 4) |
| 479 |
assert_array_almost_equal(model.subset, X_digits[model.ranking]) |
| 480 |
|
| 481 |
def test_digits_cosine_lazy_object(): |
| 482 |
model = SumRedundancySelection(100, 'cosine', optimizer=LazyGreedy()) |
| 483 |
model.fit(X_digits) |
| 484 |
assert_array_equal(model.ranking, digits_cosine_ranking) |
| 485 |
assert_array_almost_equal(model.gains, digits_cosine_gains, 4) |
| 486 |
assert_array_almost_equal(model.subset, X_digits[model.ranking]) |
| 487 |
|
| 488 |
def test_digits_cosine_two_stage_object(): |
| 489 |
model = SumRedundancySelection(100, 'cosine', optimizer=TwoStageGreedy()) |
| 490 |
model.fit(X_digits) |
| 491 |
assert_array_equal(model.ranking, digits_cosine_ranking) |
| 492 |
assert_array_almost_equal(model.gains, digits_cosine_gains, 4) |
| 493 |
assert_array_almost_equal(model.subset, X_digits[model.ranking]) |
| 494 |
|
| 495 |
def test_digits_cosine_greedi_nn_object(): |
| 496 |
model = SumRedundancySelection(100, 'cosine', optimizer=GreeDi( |
| 497 |
optimizer1='naive', optimizer2='naive', random_state=0)) |
| 498 |
model.fit(X_digits) |
| 499 |
assert_array_equal(model.ranking, digits_cosine_greedi_ranking) |
| 500 |
assert_array_almost_equal(model.gains, digits_cosine_greedi_gains, 4) |
| 501 |
assert_array_almost_equal(model.subset, X_digits[model.ranking]) |
| 502 |
|
| 503 |
def test_digits_cosine_greedi_ll_object(): |
| 504 |
model = SumRedundancySelection(100, 'cosine', optimizer=GreeDi( |
| 505 |
optimizer1='lazy', optimizer2='lazy', random_state=0)) |
| 506 |
model.fit(X_digits) |
| 507 |
assert_array_equal(model.ranking, digits_cosine_greedi_ranking) |
| 508 |
assert_array_almost_equal(model.gains, digits_cosine_greedi_gains, 4) |
| 509 |
assert_array_almost_equal(model.subset, X_digits[model.ranking]) |
| 510 |
|
| 511 |
def test_digits_cosine_greedi_ln_object(): |
| 512 |
model = SumRedundancySelection(100, 'cosine', optimizer=GreeDi( |
| 513 |
optimizer1='lazy', optimizer2='naive', random_state=0)) |
| 514 |
model.fit(X_digits) |
| 515 |
assert_array_equal(model.ranking, digits_cosine_greedi_ranking) |
| 516 |
assert_array_almost_equal(model.gains, digits_cosine_greedi_gains, 4) |
| 517 |
assert_array_almost_equal(model.subset, X_digits[model.ranking]) |
| 518 |
|
| 519 |
def test_digits_cosine_greedi_nl_object(): |
| 520 |
model = SumRedundancySelection(100, 'cosine', optimizer=GreeDi( |
| 521 |
optimizer1='naive', optimizer2='lazy', random_state=0)) |
| 522 |
model.fit(X_digits) |
| 523 |
assert_array_equal(model.ranking, digits_cosine_greedi_ranking) |
| 524 |
assert_array_almost_equal(model.gains, digits_cosine_greedi_gains, 4) |
| 525 |
assert_array_almost_equal(model.subset, X_digits[model.ranking]) |
| 526 |
|
| 527 |
def test_digits_cosine_approximate_object(): |
| 528 |
#model = SumRedundancySelection(100, 'cosine', |
| 529 |
# optimizer=ApproximateLazyGreedy()) |
| 530 |
#model.fit(X_digits) |
| 531 |
#assert_array_equal(model.ranking, digits_cosine_approx_ranking) |
| 532 |
#assert_array_almost_equal(model.gains, digits_cosine_approx_gains, 4) |
| 533 |
pass |
| 534 |
|
| 535 |
def test_digits_cosine_stochastic_object(): |
| 536 |
model = SumRedundancySelection(100, 'cosine', |
| 537 |
optimizer=StochasticGreedy(random_state=0)) |
| 538 |
model.fit(X_digits) |
| 539 |
assert_array_equal(model.ranking, digits_cosine_stochastic_ranking) |
| 540 |
assert_array_almost_equal(model.gains, digits_cosine_stochastic_gains, 4) |
| 541 |
assert_array_almost_equal(model.subset, X_digits[model.ranking]) |
| 542 |
|
| 543 |
def test_digits_cosine_sample_object(): |
| 544 |
model = SumRedundancySelection(100, 'cosine', |
| 545 |
optimizer=SampleGreedy(random_state=0)) |
| 546 |
model.fit(X_digits) |
| 547 |
assert_array_equal(model.ranking, digits_cosine_sample_ranking) |
| 548 |
assert_array_almost_equal(model.gains, digits_cosine_sample_gains, 4) |
| 549 |
assert_array_almost_equal(model.subset, X_digits[model.ranking]) |
| 550 |
|
| 551 |
def test_digits_sqrt_modular_object(): |
| 552 |
model = SumRedundancySelection(100, 'cosine', |
| 553 |
optimizer=ModularGreedy(random_state=0)) |
| 554 |
model.fit(X_digits) |
| 555 |
assert_array_equal(model.ranking, digits_cosine_modular_ranking) |
| 556 |
assert_array_almost_equal(model.gains, digits_cosine_modular_gains, 4) |
| 557 |
assert_array_almost_equal(model.subset, X_digits[model.ranking]) |
| 558 |
|
| 559 |
# Test all optimizers on sparse data |
| 560 |
|
| 561 |
def test_digits_cosine_naive_sparse(): |
| 562 |
model = SumRedundancySelection(100, 'precomputed', optimizer='naive') |
| 563 |
model.fit(X_digits_cosine_sparse) |
| 564 |
assert_array_equal(model.ranking, digits_cosine_ranking) |
| 565 |
assert_array_almost_equal(model.gains, digits_cosine_gains, 4) |
| 566 |
|
| 567 |
def test_digits_cosine_lazy_sparse(): |
| 568 |
model = SumRedundancySelection(100, 'precomputed', optimizer='lazy') |
| 569 |
model.fit(X_digits_cosine_sparse) |
| 570 |
assert_array_equal(model.ranking, digits_cosine_ranking) |
| 571 |
assert_array_almost_equal(model.gains, digits_cosine_gains, 4) |
| 572 |
|
| 573 |
def test_digits_cosine_two_stage_sparse(): |
| 574 |
model = SumRedundancySelection(100, 'precomputed', optimizer='two-stage') |
| 575 |
model.fit(X_digits_cosine_sparse) |
| 576 |
assert_array_equal(model.ranking, digits_cosine_ranking) |
| 577 |
assert_array_almost_equal(model.gains, digits_cosine_gains, 4) |
| 578 |
|
| 579 |
def test_digits_cosine_greedi_nn_sparse(): |
| 580 |
model = SumRedundancySelection(100, 'precomputed', optimizer='greedi', |
| 581 |
optimizer_kwds={'optimizer1': 'naive', 'optimizer2': 'naive'}, |
| 582 |
random_state=0) |
| 583 |
model.fit(X_digits_cosine_sparse) |
| 584 |
assert_array_equal(model.ranking, digits_cosine_greedi_ranking) |
| 585 |
assert_array_almost_equal(model.gains, digits_cosine_greedi_gains, 4) |
| 586 |
|
| 587 |
def test_digits_cosine_greedi_ll_sparse(): |
| 588 |
model = SumRedundancySelection(100, 'precomputed', optimizer='greedi', |
| 589 |
optimizer_kwds={'optimizer1': 'lazy', 'optimizer2': 'lazy'}, |
| 590 |
random_state=0) |
| 591 |
model.fit(X_digits_cosine_sparse) |
| 592 |
assert_array_equal(model.ranking, digits_cosine_greedi_ranking) |
| 593 |
assert_array_almost_equal(model.gains, digits_cosine_greedi_gains, 4) |
| 594 |
|
| 595 |
def test_digits_cosine_greedi_ln_sparse(): |
| 596 |
model = SumRedundancySelection(100, 'precomputed', optimizer='greedi', |
| 597 |
optimizer_kwds={'optimizer1': 'lazy', 'optimizer2': 'naive'}, |
| 598 |
random_state=0) |
| 599 |
model.fit(X_digits_cosine_sparse) |
| 600 |
assert_array_equal(model.ranking, digits_cosine_greedi_ranking) |
| 601 |
assert_array_almost_equal(model.gains, digits_cosine_greedi_gains, 4) |
| 602 |
|
| 603 |
def test_digits_cosine_greedi_nl_sparse(): |
| 604 |
model = SumRedundancySelection(100, 'precomputed', optimizer='greedi', |
| 605 |
optimizer_kwds={'optimizer1': 'naive', 'optimizer2': 'lazy'}, |
| 606 |
random_state=0) |
| 607 |
model.fit(X_digits_cosine_sparse) |
| 608 |
assert_array_equal(model.ranking, digits_cosine_greedi_ranking) |
| 609 |
assert_array_almost_equal(model.gains, digits_cosine_greedi_gains, 4) |
| 610 |
|
| 611 |
def test_digits_cosine_approximate_sparse(): |
| 612 |
pass |
| 613 |
# Approximate doesn't work with supermodular functions. |
| 614 |
|
| 615 |
#model = SumRedundancySelection(100, 'precomputed', optimizer='approximate-lazy') |
| 616 |
#model.fit(X_digits_cosine_sparse) |
| 617 |
#assert_array_equal(model.ranking, digits_cosine_approx_ranking) |
| 618 |
#assert_array_almost_equal(model.gains, digits_cosine_approx_gains, 4) |
| 619 |
|
| 620 |
def test_digits_cosine_stochastic_sparse(): |
| 621 |
model = SumRedundancySelection(100, 'precomputed', optimizer='stochastic', |
| 622 |
random_state=0) |
| 623 |
model.fit(X_digits_cosine_sparse) |
| 624 |
assert_array_equal(model.ranking, digits_cosine_stochastic_ranking) |
| 625 |
assert_array_almost_equal(model.gains, digits_cosine_stochastic_gains, 4) |
| 626 |
|
| 627 |
def test_digits_cosine_sample_sparse(): |
| 628 |
model = SumRedundancySelection(100, 'precomputed', optimizer='sample', |
| 629 |
random_state=0) |
| 630 |
model.fit(X_digits_cosine_sparse) |
| 631 |
assert_array_equal(model.ranking, digits_cosine_sample_ranking) |
| 632 |
assert_array_almost_equal(model.gains, digits_cosine_sample_gains, 4) |
| 633 |
|
| 634 |
def test_digits_sqrt_modular_sparse(): |
| 635 |
model = SumRedundancySelection(100, 'precomputed', optimizer='modular', |
| 636 |
random_state=0) |
| 637 |
model.fit(X_digits_cosine_sparse) |
| 638 |
assert_array_equal(model.ranking, digits_cosine_modular_ranking) |
| 639 |
assert_array_almost_equal(model.gains, digits_cosine_modular_gains, 4) |