Apply exponential time decay to scalar weights. Args: weights: Weight mapping days_inactive: Inactive days decay_rate: Daily decay rate minimum_weight: Floor Returns: Decayed mapping
(
weights: Dict[str, float],
days_inactive: int,
decay_rate: float = 0.01,
minimum_weight: float = 0.1,
)
| 778 | |
| 779 | |
| 780 | def apply_time_decay( |
| 781 | weights: Dict[str, float], |
| 782 | days_inactive: int, |
| 783 | decay_rate: float = 0.01, |
| 784 | minimum_weight: float = 0.1, |
| 785 | ) -> Dict[str, float]: |
| 786 | """ |
| 787 | Apply exponential time decay to scalar weights. |
| 788 | |
| 789 | Args: |
| 790 | weights: Weight mapping |
| 791 | days_inactive: Inactive days |
| 792 | decay_rate: Daily decay rate |
| 793 | minimum_weight: Floor |
| 794 | |
| 795 | Returns: |
| 796 | Decayed mapping |
| 797 | """ |
| 798 | if days_inactive <= 0: |
| 799 | return { |
| 800 | topic: float(weight) |
| 801 | for topic, weight in weights.items() |
| 802 | } |
| 803 | |
| 804 | decayed: Dict[str, float] = {} |
| 805 | for topic, weight in weights.items(): |
| 806 | value = float(weight) * ((1 - decay_rate) ** days_inactive) |
| 807 | decayed[topic] = max(minimum_weight, value) |
| 808 | return decayed |
| 809 | |
| 810 | |
| 811 | def _apply_selective_decay( |
nothing calls this directly
no outgoing calls
no test coverage detected