ts-fsrs 5.2.1 → 5.2.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/index.cjs +45 -18
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.ts +4 -4
- package/dist/index.mjs +45 -18
- package/dist/index.mjs.map +1 -1
- package/dist/index.umd.js +46 -19
- package/dist/index.umd.js.map +1 -1
- package/package.json +5 -4
package/dist/index.cjs
CHANGED
|
@@ -468,7 +468,7 @@ function alea(seed) {
|
|
|
468
468
|
return prng;
|
|
469
469
|
}
|
|
470
470
|
|
|
471
|
-
const version="5.2.
|
|
471
|
+
const version="5.2.2";
|
|
472
472
|
|
|
473
473
|
const default_request_retention = 0.9;
|
|
474
474
|
const default_maximum_interval = 36500;
|
|
@@ -511,7 +511,7 @@ const default_w = Object.freeze([
|
|
|
511
511
|
FSRS6_DEFAULT_DECAY
|
|
512
512
|
]);
|
|
513
513
|
const W17_W18_Ceiling = 2;
|
|
514
|
-
const CLAMP_PARAMETERS = (w17_w18_ceiling) => [
|
|
514
|
+
const CLAMP_PARAMETERS = (w17_w18_ceiling, enable_short_term = default_enable_short_term) => [
|
|
515
515
|
[S_MIN, INIT_S_MAX],
|
|
516
516
|
[S_MIN, INIT_S_MAX],
|
|
517
517
|
[S_MIN, INIT_S_MAX],
|
|
@@ -531,18 +531,26 @@ const CLAMP_PARAMETERS = (w17_w18_ceiling) => [
|
|
|
531
531
|
[1, 6],
|
|
532
532
|
[0, w17_w18_ceiling],
|
|
533
533
|
[0, w17_w18_ceiling],
|
|
534
|
-
[
|
|
534
|
+
[
|
|
535
|
+
enable_short_term ? 0.01 : 0,
|
|
536
|
+
0.8
|
|
537
|
+
],
|
|
535
538
|
[0.1, 0.8]
|
|
536
539
|
];
|
|
537
540
|
|
|
538
|
-
const clipParameters = (parameters, numRelearningSteps) => {
|
|
541
|
+
const clipParameters = (parameters, numRelearningSteps, enableShortTerm = default_enable_short_term) => {
|
|
539
542
|
let w17_w18_ceiling = W17_W18_Ceiling;
|
|
540
543
|
if (Math.max(0, numRelearningSteps) > 1) {
|
|
541
544
|
const value = -(Math.log(parameters[11]) + Math.log(Math.pow(2, parameters[13]) - 1) + parameters[14] * 0.3) / numRelearningSteps;
|
|
542
545
|
w17_w18_ceiling = clamp(+value.toFixed(8), 0.01, 2);
|
|
543
546
|
}
|
|
544
|
-
const clip = CLAMP_PARAMETERS(w17_w18_ceiling)
|
|
545
|
-
|
|
547
|
+
const clip = CLAMP_PARAMETERS(w17_w18_ceiling, enableShortTerm).slice(
|
|
548
|
+
0,
|
|
549
|
+
parameters.length
|
|
550
|
+
);
|
|
551
|
+
return clip.map(
|
|
552
|
+
([min, max], index) => clamp(parameters[index] || 0, min, max)
|
|
553
|
+
);
|
|
546
554
|
};
|
|
547
555
|
const checkParameters = (parameters) => {
|
|
548
556
|
const invalid = parameters.find(
|
|
@@ -557,18 +565,30 @@ const checkParameters = (parameters) => {
|
|
|
557
565
|
}
|
|
558
566
|
return parameters;
|
|
559
567
|
};
|
|
560
|
-
const migrateParameters = (parameters) => {
|
|
568
|
+
const migrateParameters = (parameters, numRelearningSteps = 0, enableShortTerm = default_enable_short_term) => {
|
|
561
569
|
if (parameters === void 0) {
|
|
562
570
|
return [...default_w];
|
|
563
571
|
}
|
|
564
572
|
switch (parameters.length) {
|
|
565
573
|
case 21:
|
|
566
|
-
return
|
|
574
|
+
return clipParameters(
|
|
575
|
+
Array.from(parameters),
|
|
576
|
+
numRelearningSteps,
|
|
577
|
+
enableShortTerm
|
|
578
|
+
);
|
|
567
579
|
case 19:
|
|
568
580
|
console.debug("[FSRS-6]auto fill w from 19 to 21 length");
|
|
569
|
-
return
|
|
581
|
+
return clipParameters(
|
|
582
|
+
Array.from(parameters),
|
|
583
|
+
numRelearningSteps,
|
|
584
|
+
enableShortTerm
|
|
585
|
+
).concat([0, FSRS5_DEFAULT_DECAY]);
|
|
570
586
|
case 17: {
|
|
571
|
-
const w =
|
|
587
|
+
const w = clipParameters(
|
|
588
|
+
Array.from(parameters),
|
|
589
|
+
numRelearningSteps,
|
|
590
|
+
enableShortTerm
|
|
591
|
+
);
|
|
572
592
|
w[4] = +(w[5] * 2 + w[4]).toFixed(8);
|
|
573
593
|
w[5] = +(Math.log(w[5] * 3 + 1) / 3).toFixed(8);
|
|
574
594
|
w[6] = +(w[6] + 0.5).toFixed(8);
|
|
@@ -583,13 +603,18 @@ const migrateParameters = (parameters) => {
|
|
|
583
603
|
const generatorParameters = (props) => {
|
|
584
604
|
const learning_steps = Array.isArray(props?.learning_steps) ? props.learning_steps : default_learning_steps;
|
|
585
605
|
const relearning_steps = Array.isArray(props?.relearning_steps) ? props.relearning_steps : default_relearning_steps;
|
|
586
|
-
const
|
|
606
|
+
const enable_short_term = props?.enable_short_term ?? default_enable_short_term;
|
|
607
|
+
const w = migrateParameters(
|
|
608
|
+
props?.w,
|
|
609
|
+
relearning_steps.length,
|
|
610
|
+
enable_short_term
|
|
611
|
+
);
|
|
587
612
|
return {
|
|
588
613
|
request_retention: props?.request_retention || default_request_retention,
|
|
589
614
|
maximum_interval: props?.maximum_interval || default_maximum_interval,
|
|
590
615
|
w,
|
|
591
616
|
enable_fuzz: props?.enable_fuzz ?? default_enable_fuzz,
|
|
592
|
-
enable_short_term
|
|
617
|
+
enable_short_term,
|
|
593
618
|
learning_steps,
|
|
594
619
|
relearning_steps
|
|
595
620
|
};
|
|
@@ -679,9 +704,10 @@ class FSRSAlgorithm {
|
|
|
679
704
|
Number(value)
|
|
680
705
|
);
|
|
681
706
|
} else if (prop === "w") {
|
|
682
|
-
value =
|
|
683
|
-
|
|
684
|
-
target.relearning_steps.length
|
|
707
|
+
value = migrateParameters(
|
|
708
|
+
value,
|
|
709
|
+
target.relearning_steps.length,
|
|
710
|
+
target.enable_short_term
|
|
685
711
|
);
|
|
686
712
|
_this.forgetting_curve = forgetting_curve.bind(this, value);
|
|
687
713
|
_this.intervalModifier = _this.calculate_interval_modifier(
|
|
@@ -1494,9 +1520,10 @@ class FSRS extends FSRSAlgorithm {
|
|
|
1494
1520
|
} else if (prop === "enable_short_term") {
|
|
1495
1521
|
_this.Scheduler = value === true ? BasicScheduler : LongTermScheduler;
|
|
1496
1522
|
} else if (prop === "w") {
|
|
1497
|
-
value =
|
|
1498
|
-
|
|
1499
|
-
target.relearning_steps.length
|
|
1523
|
+
value = migrateParameters(
|
|
1524
|
+
value,
|
|
1525
|
+
target.relearning_steps.length,
|
|
1526
|
+
target.enable_short_term
|
|
1500
1527
|
);
|
|
1501
1528
|
_this.forgetting_curve = forgetting_curve.bind(this, value);
|
|
1502
1529
|
_this.intervalModifier = _this.calculate_interval_modifier(
|