Spaces:
Sleeping
Sleeping
Update scoring_calculation_system.py
Browse files- scoring_calculation_system.py +13 -37
scoring_calculation_system.py
CHANGED
@@ -2188,10 +2188,10 @@ def calculate_breed_compatibility_score(scores: dict, user_prefs: UserPreference
|
|
2188 |
"""
|
2189 |
# 進一步降低關鍵指標閾值,使系統更包容極端組合
|
2190 |
critical_thresholds = {
|
2191 |
-
|
2192 |
-
|
2193 |
-
|
2194 |
-
|
2195 |
}
|
2196 |
|
2197 |
critical_failures = []
|
@@ -2199,30 +2199,23 @@ def calculate_breed_compatibility_score(scores: dict, user_prefs: UserPreference
|
|
2199 |
if scores[metric] < threshold:
|
2200 |
critical_failures.append((metric, scores[metric]))
|
2201 |
|
2202 |
-
# 計算基礎加權分數
|
2203 |
base_score = sum(scores[k] * weights[k] for k in scores.keys())
|
2204 |
|
2205 |
-
# 降低懲罰程度,特別是對空間和運動的組合
|
2206 |
if critical_failures:
|
2207 |
-
# 分開處理不同類型的失敗
|
2208 |
space_exercise_penalty = 0
|
2209 |
other_penalty = 0
|
2210 |
|
2211 |
for metric, score in critical_failures:
|
2212 |
if metric in ['space', 'exercise']:
|
2213 |
-
#
|
2214 |
-
space_exercise_penalty += (critical_thresholds[metric] - score) * 0.2
|
2215 |
else:
|
2216 |
-
|
2217 |
-
other_penalty += (critical_thresholds[metric] - score) * 0.4
|
2218 |
|
2219 |
-
# 應用懲罰時更有彈性
|
2220 |
total_penalty = (space_exercise_penalty + other_penalty) / 2
|
2221 |
base_score *= (1 - total_penalty)
|
2222 |
|
2223 |
-
# 進一步降低多重失敗的懲罰
|
2224 |
if len(critical_failures) > 1:
|
2225 |
-
base_score *= (0.
|
2226 |
|
2227 |
return base_score
|
2228 |
|
@@ -2339,45 +2332,28 @@ def amplify_score_extreme(score: float) -> float:
|
|
2339 |
使用sigmoid曲線來平滑較低分數的轉換,避免突兀的分數跳變
|
2340 |
"""
|
2341 |
def smooth_curve(x: float, steepness: float = 12) -> float:
|
2342 |
-
"""
|
2343 |
-
使用sigmoid曲線來平滑分數轉換
|
2344 |
-
|
2345 |
-
參數:
|
2346 |
-
x: 0-1之間的位置值
|
2347 |
-
steepness: 曲線的陡峭程度,較大的值會使轉換更加陡峭
|
2348 |
-
|
2349 |
-
返回:
|
2350 |
-
0-1之間的平滑轉換值
|
2351 |
-
"""
|
2352 |
import math
|
2353 |
return 1 / (1 + math.exp(-steepness * (x - 0.5)))
|
2354 |
|
2355 |
-
# 處理最高分數範圍:90-100 -> 92-99
|
2356 |
if score >= 0.9:
|
2357 |
-
position = (score - 0.9) / 0.1
|
2358 |
-
return 0.92 + (position * 0.
|
2359 |
|
2360 |
-
# 處理優秀分數範圍:80-90 -> 85-92
|
2361 |
elif score >= 0.8:
|
2362 |
position = (score - 0.8) / 0.1
|
2363 |
-
return 0.
|
2364 |
|
2365 |
-
# 處理良好分數範圍:70-80 -> 78-85
|
2366 |
elif score >= 0.7:
|
2367 |
position = (score - 0.7) / 0.1
|
2368 |
-
return 0.
|
2369 |
|
2370 |
-
# 處理一般分數範圍:50-70 -> 70-78
|
2371 |
elif score >= 0.5:
|
2372 |
position = (score - 0.5) / 0.2
|
2373 |
-
|
2374 |
-
return base + (smooth_curve(position) * 0.08)
|
2375 |
|
2376 |
-
# 處理較低分數範圍:0-50 -> 60-70
|
2377 |
else:
|
2378 |
position = score / 0.5
|
2379 |
-
|
2380 |
-
return base + (smooth_curve(position) * 0.10)
|
2381 |
|
2382 |
|
2383 |
# def amplify_score_extreme(score: float) -> float:
|
|
|
2188 |
"""
|
2189 |
# 進一步降低關鍵指標閾值,使系統更包容極端組合
|
2190 |
critical_thresholds = {
|
2191 |
+
'space': 0.45, # 進一步降低閾值
|
2192 |
+
'exercise': 0.45,
|
2193 |
+
'experience': 0.55,
|
2194 |
+
'noise': 0.55
|
2195 |
}
|
2196 |
|
2197 |
critical_failures = []
|
|
|
2199 |
if scores[metric] < threshold:
|
2200 |
critical_failures.append((metric, scores[metric]))
|
2201 |
|
|
|
2202 |
base_score = sum(scores[k] * weights[k] for k in scores.keys())
|
2203 |
|
|
|
2204 |
if critical_failures:
|
|
|
2205 |
space_exercise_penalty = 0
|
2206 |
other_penalty = 0
|
2207 |
|
2208 |
for metric, score in critical_failures:
|
2209 |
if metric in ['space', 'exercise']:
|
2210 |
+
space_exercise_penalty += (critical_thresholds[metric] - score) * 0.15 # 降低懲罰
|
|
|
2211 |
else:
|
2212 |
+
other_penalty += (critical_thresholds[metric] - score) * 0.3
|
|
|
2213 |
|
|
|
2214 |
total_penalty = (space_exercise_penalty + other_penalty) / 2
|
2215 |
base_score *= (1 - total_penalty)
|
2216 |
|
|
|
2217 |
if len(critical_failures) > 1:
|
2218 |
+
base_score *= (0.98 ** (len(critical_failures) - 1)) # 進一步降低多重失敗懲罰
|
2219 |
|
2220 |
return base_score
|
2221 |
|
|
|
2332 |
使用sigmoid曲線來平滑較低分數的轉換,避免突兀的分數跳變
|
2333 |
"""
|
2334 |
def smooth_curve(x: float, steepness: float = 12) -> float:
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
2335 |
import math
|
2336 |
return 1 / (1 + math.exp(-steepness * (x - 0.5)))
|
2337 |
|
|
|
2338 |
if score >= 0.9:
|
2339 |
+
position = (score - 0.9) / 0.1
|
2340 |
+
return 0.92 + (position * 0.08) # 擴大高分區間
|
2341 |
|
|
|
2342 |
elif score >= 0.8:
|
2343 |
position = (score - 0.8) / 0.1
|
2344 |
+
return 0.82 + (position * 0.10) # 增加分數差異
|
2345 |
|
|
|
2346 |
elif score >= 0.7:
|
2347 |
position = (score - 0.7) / 0.1
|
2348 |
+
return 0.72 + (position * 0.10) # 增加分數差異
|
2349 |
|
|
|
2350 |
elif score >= 0.5:
|
2351 |
position = (score - 0.5) / 0.2
|
2352 |
+
return 0.65 + (smooth_curve(position) * 0.07)
|
|
|
2353 |
|
|
|
2354 |
else:
|
2355 |
position = score / 0.5
|
2356 |
+
return 0.60 + (smooth_curve(position) * 0.05)
|
|
|
2357 |
|
2358 |
|
2359 |
# def amplify_score_extreme(score: float) -> float:
|