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.umd.js CHANGED
@@ -496,7 +496,7 @@
496
496
  return prng;
497
497
  }
498
498
 
499
- const version="5.2.1";
499
+ const version="5.2.2";
500
500
 
501
501
  const default_request_retention = 0.9;
502
502
  const default_maximum_interval = 36500;
@@ -539,7 +539,7 @@
539
539
  FSRS6_DEFAULT_DECAY
540
540
  ]);
541
541
  const W17_W18_Ceiling = 2;
542
- const CLAMP_PARAMETERS = (w17_w18_ceiling) => [
542
+ const CLAMP_PARAMETERS = (w17_w18_ceiling, enable_short_term = default_enable_short_term) => [
543
543
  [S_MIN, INIT_S_MAX],
544
544
  [S_MIN, INIT_S_MAX],
545
545
  [S_MIN, INIT_S_MAX],
@@ -559,18 +559,26 @@
559
559
  [1, 6],
560
560
  [0, w17_w18_ceiling],
561
561
  [0, w17_w18_ceiling],
562
- [0, 0.8],
562
+ [
563
+ enable_short_term ? 0.01 : 0,
564
+ 0.8
565
+ ],
563
566
  [0.1, 0.8]
564
567
  ];
565
568
 
566
- const clipParameters = (parameters, numRelearningSteps) => {
569
+ const clipParameters = (parameters, numRelearningSteps, enableShortTerm = default_enable_short_term) => {
567
570
  let w17_w18_ceiling = W17_W18_Ceiling;
568
571
  if (Math.max(0, numRelearningSteps) > 1) {
569
572
  const value = -(Math.log(parameters[11]) + Math.log(Math.pow(2, parameters[13]) - 1) + parameters[14] * 0.3) / numRelearningSteps;
570
573
  w17_w18_ceiling = clamp(+value.toFixed(8), 0.01, 2);
571
574
  }
572
- const clip = CLAMP_PARAMETERS(w17_w18_ceiling);
573
- return clip.map(([min, max], index) => clamp(parameters[index], min, max));
575
+ const clip = CLAMP_PARAMETERS(w17_w18_ceiling, enableShortTerm).slice(
576
+ 0,
577
+ parameters.length
578
+ );
579
+ return clip.map(
580
+ ([min, max], index) => clamp(parameters[index] || 0, min, max)
581
+ );
574
582
  };
575
583
  const checkParameters = (parameters) => {
576
584
  const invalid = parameters.find(
@@ -585,18 +593,30 @@
585
593
  }
586
594
  return parameters;
587
595
  };
588
- const migrateParameters = (parameters) => {
596
+ const migrateParameters = (parameters, numRelearningSteps = 0, enableShortTerm = default_enable_short_term) => {
589
597
  if (parameters === void 0) {
590
598
  return [...default_w];
591
599
  }
592
600
  switch (parameters.length) {
593
601
  case 21:
594
- return [...parameters];
602
+ return clipParameters(
603
+ Array.from(parameters),
604
+ numRelearningSteps,
605
+ enableShortTerm
606
+ );
595
607
  case 19:
596
608
  console.debug("[FSRS-6]auto fill w from 19 to 21 length");
597
- return [...parameters, 0, FSRS5_DEFAULT_DECAY];
609
+ return clipParameters(
610
+ Array.from(parameters),
611
+ numRelearningSteps,
612
+ enableShortTerm
613
+ ).concat([0, FSRS5_DEFAULT_DECAY]);
598
614
  case 17: {
599
- const w = [...parameters];
615
+ const w = clipParameters(
616
+ Array.from(parameters),
617
+ numRelearningSteps,
618
+ enableShortTerm
619
+ );
600
620
  w[4] = +(w[5] * 2 + w[4]).toFixed(8);
601
621
  w[5] = +(Math.log(w[5] * 3 + 1) / 3).toFixed(8);
602
622
  w[6] = +(w[6] + 0.5).toFixed(8);
@@ -612,13 +632,18 @@
612
632
  var _a, _b;
613
633
  const learning_steps = Array.isArray(props == null ? void 0 : props.learning_steps) ? props.learning_steps : default_learning_steps;
614
634
  const relearning_steps = Array.isArray(props == null ? void 0 : props.relearning_steps) ? props.relearning_steps : default_relearning_steps;
615
- const w = clipParameters(migrateParameters(props == null ? void 0 : props.w), relearning_steps.length);
635
+ const enable_short_term = (_a = props == null ? void 0 : props.enable_short_term) != null ? _a : default_enable_short_term;
636
+ const w = migrateParameters(
637
+ props == null ? void 0 : props.w,
638
+ relearning_steps.length,
639
+ enable_short_term
640
+ );
616
641
  return {
617
642
  request_retention: (props == null ? void 0 : props.request_retention) || default_request_retention,
618
643
  maximum_interval: (props == null ? void 0 : props.maximum_interval) || default_maximum_interval,
619
644
  w,
620
- enable_fuzz: (_a = props == null ? void 0 : props.enable_fuzz) != null ? _a : default_enable_fuzz,
621
- enable_short_term: (_b = props == null ? void 0 : props.enable_short_term) != null ? _b : default_enable_short_term,
645
+ enable_fuzz: (_b = props == null ? void 0 : props.enable_fuzz) != null ? _b : default_enable_fuzz,
646
+ enable_short_term,
622
647
  learning_steps,
623
648
  relearning_steps
624
649
  };
@@ -719,9 +744,10 @@
719
744
  Number(value)
720
745
  );
721
746
  } else if (prop === "w") {
722
- value = clipParameters(
723
- migrateParameters(value),
724
- target.relearning_steps.length
747
+ value = migrateParameters(
748
+ value,
749
+ target.relearning_steps.length,
750
+ target.enable_short_term
725
751
  );
726
752
  _this.forgetting_curve = forgetting_curve.bind(this, value);
727
753
  _this.intervalModifier = _this.calculate_interval_modifier(
@@ -1569,9 +1595,10 @@
1569
1595
  } else if (prop === "enable_short_term") {
1570
1596
  _this.Scheduler = value === true ? BasicScheduler : LongTermScheduler;
1571
1597
  } else if (prop === "w") {
1572
- value = clipParameters(
1573
- migrateParameters(value),
1574
- target.relearning_steps.length
1598
+ value = migrateParameters(
1599
+ value,
1600
+ target.relearning_steps.length,
1601
+ target.enable_short_term
1575
1602
  );
1576
1603
  _this.forgetting_curve = forgetting_curve.bind(this, value);
1577
1604
  _this.intervalModifier = _this.calculate_interval_modifier(