Wen1201 commited on
Commit
b162a06
·
verified ·
1 Parent(s): f8a87cd

Update bayesian_llm_assistant.py

Browse files
Files changed (1) hide show
  1. bayesian_llm_assistant.py +44 -36
bayesian_llm_assistant.py CHANGED
@@ -316,7 +316,7 @@ Format responses with proper markdown for better readability.
316
  interp = results['interpretation']
317
  diag = results['diagnostics']
318
 
319
- # 找出顯著的屬性
320
  sig_types = [
321
  results['trial_labels'][i]
322
  for i, sig in enumerate(results['by_trial']['delta_significant'])
@@ -332,7 +332,7 @@ Format responses with proper markdown for better readability.
332
  - SD | 標準差: {overall['d_sd']:.4f}
333
  - 95% HDI: [{overall['d_hdi_low']:.4f}, {overall['d_hdi_high']:.4f}]
334
 
335
- - **sigma (Between-type Variation) | sigma(屬性間變異)**:
336
  - Mean | 平均: {overall['sigma_mean']:.4f}
337
  - SD | 標準差: {overall['sigma_sd']:.4f}
338
  - 95% HDI: [{overall['sigma_hdi_low']:.4f}, {overall['sigma_hdi_high']:.4f}]
@@ -355,24 +355,24 @@ Format responses with proper markdown for better readability.
355
  - **Effect Size | 效果大小**: {interp['effect_size']}
356
  - **Heterogeneity | 異質性**: {interp['heterogeneity']}
357
 
358
- ### Significant Types | 顯著的屬性
359
- {len(sig_types)} out of {results['n_trials']} types show significant speed effects:
360
- {len(sig_types)} 個屬性(共 {results['n_trials']} )顯示顯著的速度效應
361
  {', '.join(sig_types) if sig_types else 'None 無'}
362
 
363
- ### Number of Types Analyzed | 分析的屬性數量
364
- {results['n_trials']} types in total 共 {results['n_trials']} 個屬性
365
 
366
  ### Key Finding | 關鍵發現
367
  {
368
  f"On average, Fire-type Pokémon are {overall['or_mean']:.2f} times more likely to win compared to Water-type (95% HDI: [{overall['or_hdi_low']:.2f}, {overall['or_hdi_high']:.2f}]). 平均而言,火系寶可夢獲勝的可能性是水系的 {overall['or_mean']:.2f} 倍 (95% HDI: [{overall['or_hdi_low']:.2f}, {overall['or_hdi_high']:.2f}])。"
369
 
370
  if overall['or_mean'] > 1
371
- else f"Interestingly, the data suggests no clear speed advantage or even a slight disadvantage. 有趣的是,資料顯示速度並無明顯優勢,甚至可能略有劣勢。"
372
  }
373
 
374
- The variation between types (sigma = {overall['sigma_mean']:.3f}) indicates {interp['heterogeneity'].lower()}.
375
- 屬性間的變異(sigma = {overall['sigma_mean']:.3f})表示{interp['heterogeneity'].lower()}。
376
  """
377
  return context
378
 
@@ -420,20 +420,20 @@ Please:
420
 
421
  summary_prompt = """請根據提供的貝氏階層模型分析結果生成一份完整的總結報告,包含:
422
 
423
- 1. **模型目的**:簡述這個階層模型在分析什麼
424
  2. **整體發現**:
425
- - 速度勝率有什麼整體影響
426
  - d 和勝算比告訴我們什麼?
427
  - HDI 的意義是什麼?
428
- 3. **屬性間差異**:
429
  - sigma 告訴我們什麼?
430
- - 哪些屬性特別受速度影響
431
  4. **模型品質**:
432
  - 模型收斂得好嗎?(R-hat、ESS)
433
  - 結果可信嗎?
434
  5. **實戰啟示**:
435
  - 訓練師如何運用這些資訊?
436
- - 哪些屬性應該優先考慮速度
437
 
438
  請用清楚的繁體中文 Markdown 格式撰寫,包含適當的章節標題。"""
439
 
@@ -444,11 +444,11 @@ Please:
444
  """解釋特定指標"""
445
 
446
  metric_explanations = {
447
- 'd': 'd (整體對數勝算比)',
448
- 'sigma': 'sigma (屬性間變異)',
449
- 'or_speed': 'Odds Ratio (勝算比)',
450
  'hdi': '95% HDI (最高密度區間)',
451
- 'delta': 'delta (屬性特定效應)',
452
  'rhat': 'R-hat (收斂診斷)',
453
  'ess': 'ESS (有效樣本數)'
454
  }
@@ -479,7 +479,7 @@ Please:
479
  請涵蓋:
480
  1. 兩者的根本哲學差異是什麼?
481
  2. p 值 vs HDI(可信區間)有什麼不同?
482
- 3. 為什麼我們用階層模型來分析多個屬性
483
  4. 貝氏方法的優勢和限制是什麼?
484
  5. 什麼時候該用貝氏、什麼時候該用頻率論?
485
 
@@ -491,16 +491,18 @@ Please:
491
  def explain_hierarchical_model(self):
492
  """解釋階層模型的概念"""
493
 
494
- explain_prompt = """請用簡單的方式解釋貝氏階層模型,特別是在寶可夢屬性分析的情境下。
495
 
496
  請涵蓋:
497
  1. 什麼是階層模型?為什麼要用階層結構?
498
  2. 「借用資訊」(borrowing strength) 是什麼意思?
 
499
  3. 收縮效應 (shrinkage) 如何運作?
500
- 4. 為什麼階層模型適合分析多個屬性
501
- 5. d、sigma、delta 之間的關係是什麼?
 
502
 
503
- 請用寶可夢的實際例子讓說明更具體易懂,全程使用繁體中文。"""
504
 
505
  text, _ = self.get_response(explain_prompt, None)
506
  return text
@@ -508,14 +510,15 @@ Please:
508
  def battle_strategy_advice(self, analysis_results):
509
  """提供對戰策略建議"""
510
 
511
- strategy_prompt = """根據貝氏階層模型的分析結果,請為寶可夢訓練師提供實際的對戰策略建議。
512
 
513
  請考慮:
514
- 1. 整體而言,速度對勝率的影響有多大
515
- 2. 哪些屬性特別受益於速度哪些不受影響?
516
- 3. 訓練師在組建隊伍時應該如何權衡速度
517
- 4. 有沒有屬性可以忽略速度、專其他數值
518
- 5. 對競技對戰有什麼啟示?
 
519
 
520
  請具體且可操作,使用繁體中文回答。"""
521
 
@@ -523,16 +526,21 @@ Please:
523
  return text
524
 
525
  def compare_types(self, analysis_results):
526
- """比較不同屬性"""
527
 
528
- compare_prompt = """請比較分析結果中不同屬性速度反應差異。
529
 
530
  請說明:
531
- 1. 哪些屬性速度最敏感什麼?
532
- 2. 哪些屬性對速度不敏感?可的原因是什麼?
533
- 3. 屬性間的異質性(sigma)告訴我們什麼?
 
 
534
  4. 有沒有令人意外的發現?
 
 
535
  5. 這些差異對組隊策略有什麼啟示?
 
536
 
537
  請用繁體中文回答。"""
538
 
@@ -541,4 +549,4 @@ Please:
541
 
542
  def reset_conversation(self):
543
  """重置對話歷史"""
544
- self.conversation_history = []
 
316
  interp = results['interpretation']
317
  diag = results['diagnostics']
318
 
319
+ # 找出顯著的配對
320
  sig_types = [
321
  results['trial_labels'][i]
322
  for i, sig in enumerate(results['by_trial']['delta_significant'])
 
332
  - SD | 標準差: {overall['d_sd']:.4f}
333
  - 95% HDI: [{overall['d_hdi_low']:.4f}, {overall['d_hdi_high']:.4f}]
334
 
335
+ - **sigma (Between-pair Variation) | sigma(配對間變異)**:
336
  - Mean | 平均: {overall['sigma_mean']:.4f}
337
  - SD | 標準差: {overall['sigma_sd']:.4f}
338
  - 95% HDI: [{overall['sigma_hdi_low']:.4f}, {overall['sigma_hdi_high']:.4f}]
 
355
  - **Effect Size | 效果大小**: {interp['effect_size']}
356
  - **Heterogeneity | 異質性**: {interp['heterogeneity']}
357
 
358
+ ### Significant Pairs | 顯著的配對
359
+ {len(sig_types)} out of {results['n_trials']} pairs show significant Fire advantage:
360
+ {len(sig_types)} 組配對(共 {results['n_trials']} )顯示顯著的火系優勢
361
  {', '.join(sig_types) if sig_types else 'None 無'}
362
 
363
+ ### Number of Pairs Analyzed | 分析的配對數量
364
+ {results['n_trials']} pairs in total 共 {results['n_trials']} 組配對
365
 
366
  ### Key Finding | 關鍵發現
367
  {
368
  f"On average, Fire-type Pokémon are {overall['or_mean']:.2f} times more likely to win compared to Water-type (95% HDI: [{overall['or_hdi_low']:.2f}, {overall['or_hdi_high']:.2f}]). 平均而言,火系寶可夢獲勝的可能性是水系的 {overall['or_mean']:.2f} 倍 (95% HDI: [{overall['or_hdi_low']:.2f}, {overall['or_hdi_high']:.2f}])。"
369
 
370
  if overall['or_mean'] > 1
371
+ else f"Interestingly, Water-type Pokémon show advantage over Fire-type despite type matchup, with OR = {overall['or_mean']:.2f}. 有趣的是,儘管屬性相剋,水系寶可夢相對火系仍顯示優勢,OR = {overall['or_mean']:.2f}。"
372
  }
373
 
374
+ The variation between matchup pairs (sigma = {overall['sigma_mean']:.3f}) indicates {interp['heterogeneity'].lower()}.
375
+ 配對間的變異(sigma = {overall['sigma_mean']:.3f})表示{interp['heterogeneity'].lower()}。
376
  """
377
  return context
378
 
 
420
 
421
  summary_prompt = """請根據提供的貝氏階層模型分析結果生成一份完整的總結報告,包含:
422
 
423
+ 1. **模型目的**:簡述這個階層模型在分析什麼(火系 vs 水系配對比較)
424
  2. **整體發現**:
425
+ - 火系相於水系的整體勝率優勢如何
426
  - d 和勝算比告訴我們什麼?
427
  - HDI 的意義是什麼?
428
+ 3. **配對間差異**:
429
  - sigma 告訴我們什麼?
430
+ - 哪些配對組合中火系特別強勢哪些則較弱?
431
  4. **模型品質**:
432
  - 模型收斂得好嗎?(R-hat、ESS)
433
  - 結果可信嗎?
434
  5. **實戰啟示**:
435
  - 訓練師如何運用這些資訊?
436
+ - 在火水對抗中,應該選擇哪些特定的寶可夢
437
 
438
  請用清楚的繁體中文 Markdown 格式撰寫,包含適當的章節標題。"""
439
 
 
444
  """解釋特定指標"""
445
 
446
  metric_explanations = {
447
+ 'd': 'd (火系 vs 水系整體對數勝算比)',
448
+ 'sigma': 'sigma (配對間變異)',
449
+ 'or_speed': 'Odds Ratio (火系對水系勝算比)',
450
  'hdi': '95% HDI (最高密度區間)',
451
+ 'delta': 'delta (配對特定效應)',
452
  'rhat': 'R-hat (收斂診斷)',
453
  'ess': 'ESS (有效樣本數)'
454
  }
 
479
  請涵蓋:
480
  1. 兩者的根本哲學差異是什麼?
481
  2. p 值 vs HDI(可信區間)有什麼不同?
482
+ 3. 為什麼我們用階層模型來分析多組配對
483
  4. 貝氏方法的優勢和限制是什麼?
484
  5. 什麼時候該用貝氏、什麼時候該用頻率論?
485
 
 
491
  def explain_hierarchical_model(self):
492
  """解釋階層模型的概念"""
493
 
494
+ explain_prompt = """請用簡單的方式解釋貝氏階層模型,特別是在火系對水系配對分析的情境下。
495
 
496
  請涵蓋:
497
  1. 什麼是階層模型?為什麼要用階層結構?
498
  2. 「借用資訊」(borrowing strength) 是什麼意思?
499
+ - 在本分析中,如何跨 46 組配對借用資訊?
500
  3. 收縮效應 (shrinkage) 如何運作?
501
+ - 為什麼某些極端的配對結果會被「拉回」
502
+ 4. 什麼階層模型適合分析多組配對
503
+ 5. d(整體火系優勢)、sigma(配對間變異)、delta(各配對特定效應)之間的關係是什麼?
504
 
505
+ 請用火系對水系的實際配對例子讓說明更具體易懂,全程使用繁體中文。"""
506
 
507
  text, _ = self.get_response(explain_prompt, None)
508
  return text
 
510
  def battle_strategy_advice(self, analysis_results):
511
  """提供對戰策略建議"""
512
 
513
+ strategy_prompt = """根據貝氏階層模型的分析結果,請為寶可夢訓練師提供實際的組隊策略建議。
514
 
515
  請考慮:
516
+ 1. 整體而言,火系水系的勝率如何
517
+ 2. 哪些火系寶可夢在對抗水系時特別(對應 delta 顯著為正的配對)
518
+ 3. 是否有火系寶可夢即使對抗水系仍表現不佳(delta 顯著為負)
519
+ 4. 訓練師在選擇火系對抗水系時應該意什麼
520
+ 5. 對競技對戰的組隊和屬性覆蓋有什麼啟示?
521
+ 6. 有沒有出乎意料的發現?(例如某些火系特別強/弱)
522
 
523
  請具體且可操作,使用繁體中文回答。"""
524
 
 
526
  return text
527
 
528
  def compare_types(self, analysis_results):
529
+ """比較不同配對"""
530
 
531
+ compare_prompt = """請比較分析結果中不同組合火系優勢差異。
532
 
533
  請說明:
534
+ 1. 哪些中火系特別強勢可能的原因是什麼?
535
+ - 考慮:特殊力、數值優勢、招式組合
536
+ 2. 哪些配對中火系反而處於劣勢?為什麼?
537
+ 3. 配對間的異質性(sigma)告訴我們什麼?
538
+ - 是否某些火/水系寶可夢特別能打破屬性相剋?
539
  4. 有沒有令人意外的發現?
540
+ - 例如:某個火系儘管屬性不利仍大幅獲勝
541
+ - 或某個火系表現比預期差很多
542
  5. 這些差異對組隊策略有什麼啟示?
543
+ - 如何針對性地選擇火系來對抗水系?
544
 
545
  請用繁體中文回答。"""
546
 
 
549
 
550
  def reset_conversation(self):
551
  """重置對話歷史"""
552
+ self.conversation_history = []