涓婚鏉冮噸婕傜Щ锛氭棫鏍稿績鏂瑰悜鏉冮噸琛板噺锛屾柊鍏存柟鍚戞潈閲嶆彁鍗? Args: profile: 鐢ㄦ埛鐢诲儚 params: checkfile 涓殑鍙傛暟 selected_papers: 鐢ㄦ埛閫変腑鐨勮鏂囷紙鐢ㄤ簬妫€娴嬫柊鍏翠富棰橈級 Returns: (鏇存柊鍚庣殑 profile, drift_event 鍏冩暟鎹?
(
profile: Dict[str, Any],
params: Dict[str, Any],
selected_papers: Optional[List[Dict]] = None,
date: Optional[str] = None,
)
| 921 | |
| 922 | def topic_weight_decay( |
| 923 | profile: Dict[str, Any], |
| 924 | params: Dict[str, Any], |
| 925 | selected_papers: Optional[List[Dict]] = None, |
| 926 | date: Optional[str] = None, |
| 927 | ) -> Tuple[Dict[str, Any], Dict[str, Any]]: |
| 928 | """ |
| 929 | 涓婚鏉冮噸婕傜Щ锛氭棫鏍稿績鏂瑰悜鏉冮噸琛板噺锛屾柊鍏存柟鍚戞潈閲嶆彁鍗? |
| 930 | Args: |
| 931 | profile: 鐢ㄦ埛鐢诲儚 |
| 932 | params: checkfile 涓殑鍙傛暟 |
| 933 | selected_papers: 鐢ㄦ埛閫変腑鐨勮鏂囷紙鐢ㄤ簬妫€娴嬫柊鍏翠富棰橈級 |
| 934 | |
| 935 | Returns: |
| 936 | (鏇存柊鍚庣殑 profile, drift_event 鍏冩暟鎹? |
| 937 | """ |
| 938 | updated = copy.deepcopy(profile) |
| 939 | core_directions = updated.get("core_directions", {}) |
| 940 | |
| 941 | # 1. 鏃ф柟鍚戣“鍑? |
| 942 | for direction in list(core_directions.keys()): |
| 943 | core_directions[direction] *= params.get("decay_factor", 0.7) |
| 944 | |
| 945 | # 2. 浠庤鏂囦腑鎻愬彇鏂板叴涓婚 |
| 946 | emerging_topics = _extract_emerging_topics(selected_papers, params) |
| 947 | |
| 948 | # 3. 鏂版柟鍚戞彁鍗?娣诲姞 |
| 949 | for topic in emerging_topics: |
| 950 | if topic in core_directions: |
| 951 | core_directions[topic] *= params.get("boost_factor", 1.5) |
| 952 | else: |
| 953 | core_directions[topic] = params.get("min_emerging_score", 0.4) |
| 954 | |
| 955 | # 4. 褰掍竴鍖栧埌 [0, 1] |
| 956 | max_score = max(core_directions.values()) if core_directions else 1.0 |
| 957 | if max_score > 0: |
| 958 | for k in core_directions: |
| 959 | core_directions[k] = min(1.0, core_directions[k] / max_score) |
| 960 | |
| 961 | # 5. 闄愬埗鏂瑰悜鏁伴噺 |
| 962 | if len(core_directions) > params.get("max_topics", 5): |
| 963 | sorted_dirs = sorted(core_directions.items(), key=lambda x: x[1], reverse=True) |
| 964 | core_directions = dict(sorted_dirs[: params["max_topics"]]) |
| 965 | |
| 966 | updated["core_directions"] = core_directions |
| 967 | |
| 968 | # 6. 鍚屾鏇存柊 topic_weights |
| 969 | updated["topic_weights"] = copy.deepcopy(core_directions) |
| 970 | |
| 971 | # 7. 鏇存柊 drift_state |
| 972 | updated["drift_state"] = _update_drift_state(profile, date, score_delta=0.2) |
| 973 | |
| 974 | drift_event = { |
| 975 | "method": "topic_weight_decay", |
| 976 | "emerging_topics": emerging_topics, |
| 977 | "old_directions_count": len(profile.get("core_directions", {})), |
| 978 | "new_directions_count": len(core_directions), |
| 979 | "directions_added": [t for t in emerging_topics if t not in profile.get("core_directions", {})], |
| 980 | } |
nothing calls this directly
no test coverage detected