Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fine-tune the sample size for CMRR.py #136

Merged
merged 16 commits into from
Sep 9, 2024

Conversation

Expertium
Copy link
Contributor

@Expertium Expertium commented Sep 8, 2024

So here's the idea: the amount of time it takes to run CMRR for small values of days_to_simulate is very small. Which means that we can increase the sample size without having to worry about CMRR taking too long to annoy the user.

Instead of writing a whole bunch of else-if statements, I made a function that calculates the "best" sample size. Specifically, it calculates what sample size would make CMRR run roughly as long as it would with sample_size=4 and days_to_simulate=365.

sample_size=4 and days_to_simulate=365 is used as the default, and then if days_to_simulate is lower, sample size is increased to make the total run time approximately constant for days_to_simulate <=365.

You can run something like:

for i in range(1, 366):
    print(i, best_sample_size(i))

to see what sample size values it outputs for each value of days_to_simulate.

Don't forget to add this to FSRS-rs and merge it into Anki.

So here's the idea: the amount of time it takes to run CMRR for small values of days_to_simulate is very small. Which means that we can increase the sample size without having to worry about CMRR taking too long to annoy the user.
Instead of writing a whole bunch of else-if statements, I made a function that calculates the "best" sample size. Specifically, it calculates what sample size would make CMRR run roughly as long as it owuld with sample_size=4 and days_to_simulate=365.
sample_size=4 and days_to_simulate=365 is used as the default, and then if days_to_simulate is lower, sample size is increased to make the total run time approximately constant.
@L-M-Sherlock
Copy link
Member

sample size is increased to make the total run time approximately constant.

Do you verify it?

@Expertium
Copy link
Contributor Author

Only "on paper". I can't verify it without having a version of Anki that actually implements it.

@L-M-Sherlock
Copy link
Member

OK. I will test it later.

@Expertium
Copy link
Contributor Author

I tested it in Python and it seems that my approximation provides a decent fit, but it could be better. I improved the coefficients.

@Expertium
Copy link
Contributor Author

Expertium commented Sep 8, 2024

Here are the times with the new method for calculating the sample size:
times.txt
Of course, they will vary depending on your hardware, the point is that they are the same on the same hardware and don't depend on days_to_simulate, at least as long as it's not greater than 365.

@Expertium
Copy link
Contributor Author

Expertium commented Sep 8, 2024

Ok, I changed the coefficients and the output value for days_to_simulate<=30, so here are the new times.
times.txt
And here are the sample sizes given by the new function.
sample sizes.txt

I'm sure that this is ready to be merged now.

@L-M-Sherlock
Copy link
Member

Sorry to bother you. Maybe you need to update the workload graph again. I found that I forgot to set loss_aversion to 1 when plotting the workload. Here is the new workload graph:

workload

@Expertium
Copy link
Contributor Author

Expertium commented Sep 9, 2024

Well, give me the raw data again. And make it start from 0.50.
Btw, you will likely have to revert this PR.

@L-M-Sherlock
Copy link
Member

Btw, you will likely have to revert this PR.

If I revert this PR, the width of the green area will be larger than current one, right? If so, I won't revert it.

@Expertium
Copy link
Contributor Author

Alright. Release a new version of the Google Colab optimizer so I can test and see if graphs look ok.
And give the raw data with desired retention starting from 0.5

@L-M-Sherlock
Copy link
Member

L-M-Sherlock commented Sep 9, 2024

You can modify this code to install fsrs-optimizer from your GitHub repo and branch.

image
%pip install -q git+https://github.com/Expertium/fsrs-optimizer.git@patch-2

Reference: https://stackoverflow.com/questions/20101834/pip-install-from-git-repo-branch

@L-M-Sherlock
Copy link
Member

The raw data:

[0.5, 0.501, 0.502, 0.503, 0.504, 0.505, 0.506, 0.507, 0.508, 0.509, 0.51, 0.511, 0.512, 0.513, 0.514, 0.515, 0.516, 0.517, 0.518, 0.519, 0.52, 0.521, 0.522, 0.523, 0.524, 0.525, 0.526, 0.527, 0.528, 0.529, 0.53, 0.531, 0.532, 0.533, 0.534, 0.535, 0.536, 0.537, 0.538, 0.539, 0.54, 0.541, 0.542, 0.543, 0.544, 0.545, 0.546, 0.547, 0.548, 0.549, 0.55, 0.551, 0.552, 0.553, 0.554, 0.555, 0.556, 0.557, 0.558, 0.559, 0.56, 0.5609999999999999, 0.562, 0.563, 0.5640000000000001, 0.565, 0.5660000000000001, 0.567, 0.5680000000000001, 0.569, 0.5700000000000001, 0.571, 0.5720000000000001, 0.573, 0.574, 0.575, 0.576, 0.577, 0.578, 0.579, 0.58, 0.581, 0.582, 0.583, 0.584, 0.585, 0.586, 0.587, 0.588, 0.589, 0.59, 0.591, 0.592, 0.593, 0.594, 0.595, 0.596, 0.597, 0.598, 0.599, 0.6, 0.601, 0.602, 0.603, 0.604, 0.605, 0.606, 0.607, 0.608, 0.609, 0.61, 0.611, 0.612, 0.613, 0.614, 0.615, 0.616, 0.617, 0.618, 0.619, 0.62, 0.621, 0.622, 0.623, 0.624, 0.625, 0.626, 0.627, 0.628, 0.629, 0.63, 0.631, 0.632, 0.633, 0.634, 0.635, 0.636, 0.637, 0.638, 0.639, 0.64, 0.641, 0.642, 0.643, 0.644, 0.645, 0.646, 0.647, 0.648, 0.649, 0.65, 0.651, 0.652, 0.653, 0.654, 0.655, 0.656, 0.657, 0.658, 0.659, 0.66, 0.661, 0.662, 0.663, 0.664, 0.665, 0.666, 0.667, 0.668, 0.669, 0.67, 0.671, 0.672, 0.673, 0.674, 0.675, 0.6759999999999999, 0.677, 0.6779999999999999, 0.679, 0.6799999999999999, 0.681, 0.6819999999999999, 0.683, 0.6839999999999999, 0.685, 0.6859999999999999, 0.687, 0.688, 0.6890000000000001, 0.69, 0.6910000000000001, 0.692, 0.6930000000000001, 0.694, 0.6950000000000001, 0.696, 0.6970000000000001, 0.698, 0.6990000000000001, 0.7, 0.7010000000000001, 0.702, 0.7030000000000001, 0.704, 0.7050000000000001, 0.706, 0.7070000000000001, 0.708, 0.709, 0.71, 0.711, 0.712, 0.713, 0.714, 0.715, 0.716, 0.717, 0.718, 0.719, 0.72, 0.721, 0.722, 0.723, 0.724, 0.725, 0.726, 0.727, 0.728, 0.729, 0.73, 0.731, 0.732, 0.733, 0.734, 0.735, 0.736, 0.737, 0.738, 0.739, 0.74, 0.741, 0.742, 0.743, 0.744, 0.745, 0.746, 0.747, 0.748, 0.749, 0.75, 0.751, 0.752, 0.753, 0.754, 0.755, 0.756, 0.757, 0.758, 0.759, 0.76, 0.761, 0.762, 0.763, 0.764, 0.765, 0.766, 0.767, 0.768, 0.769, 0.77, 0.771, 0.772, 0.773, 0.774, 0.775, 0.776, 0.777, 0.778, 0.779, 0.78, 0.781, 0.782, 0.783, 0.784, 0.785, 0.786, 0.787, 0.788, 0.7889999999999999, 0.79, 0.7909999999999999, 0.792, 0.7929999999999999, 0.794, 0.7949999999999999, 0.796, 0.7969999999999999, 0.798, 0.7989999999999999, 0.8, 0.8009999999999999, 0.802, 0.8029999999999999, 0.804, 0.8049999999999999, 0.806, 0.8069999999999999, 0.808, 0.8089999999999999, 0.81, 0.8109999999999999, 0.812, 0.813, 0.8140000000000001, 0.815, 0.8160000000000001, 0.817, 0.8180000000000001, 0.819, 0.8200000000000001, 0.821, 0.8220000000000001, 0.823, 0.8240000000000001, 0.825, 0.8260000000000001, 0.827, 0.8280000000000001, 0.829, 0.8300000000000001, 0.831, 0.8320000000000001, 0.833, 0.8340000000000001, 0.835, 0.8360000000000001, 0.837, 0.8380000000000001, 0.839, 0.8400000000000001, 0.841, 0.8420000000000001, 0.843, 0.8440000000000001, 0.845, 0.8460000000000001, 0.847, 0.8480000000000001, 0.849, 0.8500000000000001, 0.851, 0.852, 0.853, 0.854, 0.855, 0.856, 0.857, 0.858, 0.859, 0.86, 0.861, 0.862, 0.863, 0.864, 0.865, 0.866, 0.867, 0.868, 0.869, 0.87, 0.871, 0.872, 0.873, 0.874, 0.875, 0.876, 0.877, 0.878, 0.879, 0.88, 0.881, 0.882, 0.883, 0.884, 0.885, 0.886, 0.887, 0.888, 0.889, 0.89, 0.891, 0.892, 0.893, 0.894, 0.895, 0.896, 0.897, 0.898, 0.899, 0.9, 0.901, 0.902, 0.903, 0.904, 0.905, 0.906, 0.907, 0.908, 0.909, 0.91, 0.911, 0.912, 0.913, 0.914, 0.915, 0.916, 0.917, 0.9179999999999999, 0.919, 0.9199999999999999, 0.921, 0.9219999999999999, 0.923, 0.9239999999999999, 0.925, 0.9259999999999999, 0.927, 0.9279999999999999, 0.929, 0.9299999999999999, 0.931, 0.9319999999999999, 0.933, 0.9339999999999999, 0.935, 0.9359999999999999, 0.937, 0.938, 0.9390000000000001, 0.94, 0.9410000000000001, 0.942, 0.9430000000000001, 0.944, 0.9450000000000001, 0.946, 0.9470000000000001, 0.948, 0.9490000000000001, 0.95, 0.9510000000000001, 0.952, 0.9530000000000001, 0.954, 0.9550000000000001, 0.956, 0.9570000000000001, 0.958, 0.9590000000000001, 0.96, 0.9610000000000001, 0.962, 0.9630000000000001, 0.964, 0.9650000000000001, 0.966, 0.9670000000000001, 0.968, 0.9690000000000001, 0.97, 0.9710000000000001, 0.972, 0.9730000000000001, 0.974, 0.9750000000000001, 0.976, 0.9770000000000001, 0.978, 0.9790000000000001, 0.98, 0.981, 0.982, 0.983, 0.984, 0.985, 0.986, 0.987, 0.988, 0.989, 0.99, 0.991, 0.992, 0.993, 0.994, 0.995, 0.996, 0.997, 0.998, 0.999]
[904191.77, 903597.4450000001, 905478.8925, 905149.33, 905730.6325, 907019.6600000001, 908393.4025000001, 911860.415, 909220.01, 909406.4275, 912193.4975000002, 912481.6050000001, 912752.3300000001, 913504.1375, 914202.8800000001, 917575.2975000001, 915950.5775, 918840.3475, 917233.4625000001, 914840.7350000001, 915048.6125, 917069.9974999999, 919857.0975, 917181.2000000001, 916701.8675, 919143.0975, 917444.6525000001, 922248.1150000001, 920602.9075000001, 921494.2825000001, 924744.26, 923258.1950000001, 921295.7900000002, 924660.6125, 926078.9175, 926632.7775, 928220.8700000001, 927266.1499999999, 928882.8875, 930333.6975, 929979.0650000001, 930336.6799999999, 934637.9825, 933838.2525000001, 931469.4874999999, 932127.43, 936908.9925, 936831.1325000001, 938553.6950000001, 938329.8150000001, 932692.8925000001, 933301.9500000001, 936112.1700000002, 936494.2075, 936393.77, 937902.25, 938077.1975, 941505.905, 940706.5000000001, 939581.1124999999, 941195.3300000002, 938819.755, 944730.2175, 944169.605, 943044.7875, 944317.29, 948299.115, 942539.635, 947549.4025000002, 948687.6425, 950621.7075, 949172.765, 950135.2475000002, 949687.285, 950940.7925, 950484.725, 953823.5650000001, 951384.3975000002, 951327.0825, 953602.1499999999, 955867.62, 954307.3225, 955731.7525000002, 954787.405, 955438.5125000001, 957547.0774999999, 956488.2675000001, 955270.9425, 957988.4475000001, 953162.4650000001, 953503.2525000001, 954481.3474999999, 954731.4700000001, 956524.2925, 956013.7625, 956400.3325000001, 956892.1000000001, 959589.4025000001, 959004.0025000001, 960075.1925000001, 962715.97, 962020.3775, 959875.4924999999, 959935.2474999999, 965066.0500000002, 964499.5475, 966072.02, 963258.4975, 965411.9850000001, 962346.965, 962988.665, 963137.6800000002, 965326.06, 966869.685, 966088.6900000001, 968026.5475000001, 968841.1775000001, 966389.2825000002, 969930.5250000001, 967848.3325, 967671.8200000001, 971127.2875, 972278.7750000001, 970370.3025, 968884.4400000001, 972447.7050000001, 972924.1675000001, 972363.8375, 972659.6075000002, 970682.6350000001, 970958.815, 974452.8325, 976232.5475000001, 975227.5100000001, 974511.9675, 976266.8400000001, 975678.8350000001, 971991.3650000001, 971695.8375000001, 973555.3300000001, 979048.7124999999, 974221.925, 978606.9275000001, 976954.5175000001, 977509.6100000001, 979337.81, 979628.5700000001, 980165.3325, 980658.4275000001, 978570.4400000002, 980191.5900000001, 983664.025, 982456.8675000002, 980471.3049999999, 984152.455, 984418.0725000001, 987703.03, 986526.5725000001, 991204.93, 988748.4100000001, 988813.9550000001, 989679.7375, 992272.1075, 987596.4125, 993163.9975, 992897.4275, 991492.29, 993518.0925, 993209.4375000001, 995035.0575000001, 997019.0625000001, 996116.1375000001, 998155.7175, 997362.3175, 1002235.78, 999180.2925, 996035.3925000001, 1000889.365, 1003388.7675000001, 1006320.0625000001, 1002172.3875000001, 1005940.935, 1005776.0475, 1004480.595, 1006402.755, 1004074.9825, 1006393.745, 1008668.5374999999, 1008554.4900000001, 1009053.4275, 1011155.4525, 1010305.4225000001, 1012368.0025000002, 1011877.6300000001, 1014837.775, 1011432.93, 1015502.3225, 1012676.01, 1012127.5725, 1009186.5575000001, 1012887.3, 1011565.855, 1014955.6625000001, 1012257.3575, 1015936.5825, 1016809.8525, 1015208.2375, 1017495.7925000002, 1020667.7025, 1020056.5700000001, 1018823.5775000001, 1020374.2825000001, 1024142.9475, 1020713.925, 1021434.2050000001, 1024389.61, 1020998.6200000001, 1027559.1100000001, 1027054.8475000001, 1029074.4325, 1027817.1075, 1027506.5000000001, 1029814.355, 1030164.3125, 1028458.5150000001, 1029031.0700000001, 1032929.1600000001, 1028732.3200000001, 1030989.6575000001, 1031843.7775000001, 1031087.6100000001, 1033508.97, 1034970.3925000001, 1033912.205, 1033596.9175, 1031355.9450000001, 1035060.3700000001, 1035098.5625, 1036393.3, 1039434.505, 1036657.4775, 1039521.3125, 1036338.775, 1041146.2875000002, 1040320.5125000001, 1041715.2300000001, 1039900.1475000002, 1045107.7925, 1041429.6525000001, 1045226.43, 1041738.6925, 1041942.71, 1041716.4000000001, 1045686.1025, 1045063.6700000002, 1045128.2, 1046819.31, 1045637.8900000001, 1049681.5, 1049661.685, 1052129.2075, 1048667.83, 1049403.7025000001, 1052264.3725, 1052642.085, 1052799.05, 1054612.5825, 1052095.6, 1051107.8575000002, 1053351.6300000001, 1056008.5275, 1056263.3575000002, 1057257.7200000002, 1057260.1475000002, 1058208.6724999999, 1060203.1150000002, 1060047.04, 1066344.415, 1060304.1275, 1059509.8200000003, 1063863.26, 1066787.46, 1064593.58, 1065952.3350000002, 1065449.8900000001, 1064454.8275000001, 1066132.3900000001, 1067101.3800000001, 1065116.37, 1068613.55, 1070304.79, 1072478.4100000001, 1069991.5825, 1071119.6175, 1071770.6600000001, 1073332.5, 1079731.5450000002, 1076641.1150000002, 1075050.6, 1077359.9575, 1077861.1425, 1076435.8125, 1077976.62, 1080551.3225000002, 1080153.975, 1079213.54, 1082153.375, 1085248.5925, 1084809.105, 1087232.7925, 1090574.935, 1087585.655, 1089413.845, 1090725.98, 1090478.2075, 1086909.7025, 1089818.215, 1095890.6725, 1096429.4125, 1095801.5675000001, 1094426.8275000001, 1098529.9525000001, 1098296.2575, 1098493.265, 1102270.4700000002, 1101911.6275, 1104654.1549999998, 1108268.9575, 1105922.73, 1108266.3425, 1107656.0225, 1111962.4675000003, 1112801.8325, 1115032.1775, 1119549.7575, 1119845.5225, 1122063.015, 1118447.31, 1122752.1124999998, 1124019.23, 1130706.79, 1126245.51, 1129937.6374999997, 1129957.69, 1132564.1925000001, 1135301.3900000001, 1140214.6500000004, 1134926.2175, 1135364.88, 1137412.84, 1143088.1025, 1142274.3775, 1141984.955, 1146684.21, 1145210.3375000001, 1150660.5575, 1154582.7825, 1155222.5625, 1155265.605, 1154516.0725, 1160719.745, 1161607.56, 1160047.12, 1164924.72, 1167152.63, 1168419.0925, 1169731.5475, 1171480.8125, 1172942.1275, 1179352.9049999998, 1180111.8225, 1183202.9775, 1185142.98, 1185556.8250000002, 1188978.165, 1188079.175, 1191780.2825, 1195833.4625, 1200157.5275, 1199014.9475, 1203506.7349999999, 1201821.1925, 1208239.3, 1206346.9849999999, 1209929.4449999998, 1213485.2249999999, 1215754.68, 1216467.5675, 1226280.0474999999, 1223618.6425, 1233658.18, 1233429.8225, 1243559.8699999999, 1239922.6099999999, 1239566.5675000001, 1246996.3875, 1252431.5625, 1250002.6724999999, 1254793.92, 1254823.495, 1258621.1975, 1259686.2149999999, 1264397.4525000001, 1273363.955, 1274893.4025, 1280532.6524999999, 1282451.505, 1284729.96, 1290566.43, 1298365.9049999998, 1309799.4475, 1312908.915, 1319964.5350000001, 1323500.2325000002, 1323768.4525, 1326431.805, 1336314.5975, 1340718.7000000002, 1347987.45, 1350196.405, 1350448.71, 1356246.9825, 1361572.8675, 1369302.04, 1378718.6800000002, 1380432.3675000002, 1385144.18, 1392548.6625, 1400089.0025, 1407467.8475000001, 1413036.21, 1416623.045, 1421608.5574999999, 1441395.275, 1450601.5424999997, 1458614.0849999997, 1466695.0975, 1472125.105, 1487779.875, 1494167.945, 1502220.8875000002, 1515626.0549999997, 1530986.08, 1535527.8074999999, 1542925.6275, 1557812.73, 1564549.605, 1582129.7349999999, 1589983.2725, 1593675.1749999998, 1607846.5875, 1622842.2374999998, 1633320.7125, 1649600.0374999999, 1672911.8975, 1679390.3125, 1699577.72, 1709354.8525, 1755129.7399999998, 1768678.2374999998, 1783725.4075, 1807743.6975, 1825861.3524999998, 1859463.97, 1886111.8074999996, 1913786.9024999999, 1944565.05, 1965007.6275, 1993036.8175, 2026170.6175, 2057302.255, 2077622.18, 2111962.38, 2156870.0349999997, 2195085.9524999997, 2239366.93, 2280923.4399999995, 2355264.0149999997, 2405457.9524999997, 2464225.1424999996, 2527824.9675, 2597216.8600000003, 2679318.8549999995, 2754985.3999999994, 2866898.5, 2971760.5949999997, 3079694.985, 3212257.0124999997, 3381759.9475, 3560968.2824999997, 3781515.05, 4021466.2074999996, 4342146.819999999, 4725554.645, 5205784.425, 5854488.712499999, 6760801.887499999, 8166434.0525, 10606878.452499999, 16215521.9925]

@Expertium
Copy link
Contributor Author

Workload_retention_smooth_3 0

@Expertium
Copy link
Contributor Author

Alright, should be good, you can merge it. Don't forget to add the new method of calculating the sample size to the Rust version.

Ensure that nothing is plotted above the box with the graph
Copy link
Member

@L-M-Sherlock L-M-Sherlock left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM

@L-M-Sherlock L-M-Sherlock added this pull request to the merge queue Sep 9, 2024
Merged via the queue into open-spaced-repetition:main with commit aef1af1 Sep 9, 2024
1 check passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants