Skill: evgyur/decision-trees (version 1.0.1)

--- name: decision-trees description: Decision tree analysis for complex decision-making across all domains. Use when user needs to evaluate multiple options with uncertain outcomes, assess risk/reward scenarios, or structure choices systematically. Applicable to business, investment, personal decisions, operations, career choices, product strategy, and any situation requiring structured evaluation. Triggers include decision tree, should I, what if, evaluate options, compare alternatives, risk analysis. --- # Decision Trees — Structured Decision-Making Decision tree analysis: a visual tool for making decisions with probabilities and expected value. ## When to Use ✅ **Good for:** - Business decisions (investments, hiring, product launches) - Personal choices (career, relocation, purchases) - Trading & investing (position sizing, entry/exit) - Operational decisions (expansion, outsourcing) - Any situation with measurable consequences ❌ **Not suitable for:** - Decisions with true uncertainty (black swans) - Fast tactical choices - Purely emotional/ethical questions ## Method **Decision tree** = tree-like structure where: - **Decision nodes** (squares) — your actions - **Chance nodes** (circles) — random events - **End nodes** (triangles) — final outcomes **Process:** 1. **Define options** — all possible actions 2. **Define outcomes** — what can happen after each action 3. **Estimate probabilities** — how likely is each outcome (0-100%) 4. **Estimate values** — utility/reward for each outcome (money, points, utility units) 5. **Calculate EV** — expected value = Σ (probability × value) 6. **Choose** — option with highest EV ## Formula ``` EV = Σ (probability_i × value_i) ``` **Example:** - Outcome A: 70% probability, +$100 → 0.7 × 100 = $70 - Outcome B: 30% probability, -$50 → 0.3 × (-50) = -$15 - **EV = $70 + (-$15) = $55** ## Classic Example (from Wikipedia) **Decision:** Go to party or stay home? ### Estimates: - Party: +9 utility (fun) - Home: +3 utility (comfort) - Carrying jacket unnecessarily: -2 utility - Being cold: -10 utility - Probability cold: 70% - Probability warm: 30% ### Tree: ``` Decision ├─ Go to party │ ├─ Take jacket │ │ ├─ Cold (70%) → 9 utility (party) │ │ └─ Warm (30%) → 9 - 2 = 7 utility (carried unnecessarily) │ │ EV = 0.7 × 9 + 0.3 × 7 = 8.4 │ └─ Don't take jacket │ ├─ Cold (70%) → 9 - 10 = -1 utility (froze) │ └─ Warm (30%) → 9 utility (perfect) │ EV = 0.7 × (-1) + 0.3 × 9 = 2.0 └─ Stay home └─ EV = 3.0 (always) ``` **Conclusion:** Go and take jacket (EV = 8.4) > stay home (EV = 3.0) > go without jacket (EV = 2.0) ## Business Example **Decision:** Launch new product? ### Estimates: - Success probability: 40% - Failure probability: 60% - Profit if success: $500K - Loss if failure: $200K - Don't launch: $0 ### Tree: ``` Launch product ├─ Success (40%) → +$500K └─ Failure (60%) → -$200K EV = (0.4 × 500K) + (0.6 × -200K) = 200K - 120K = +$80K Don't launch └─ EV = $0 ``` **Conclusion:** Launch (EV = +$80K) is better than not launching ($0). ## Trading Example **Decision:** Enter position or wait? ### Estimates: - Probability of rise: 60% - Probability of fall: 40% - Position size: $1000 - Target: +10% ($100 profit) - Stop-loss: -5% ($50 loss) ### Tree: ``` Enter position ├─ Rise (60%) → +$100 └─ Fall (40%) → -$50 EV = (0.6 × 100) + (0.4 × -50) = 60 - 20 = +$40 Wait └─ No position → $0 EV = $0 ``` **Conclusion:** Entering position has positive EV (+$40), better than waiting ($0). ## Method Limitations ⚠️ **Critical points:** 1. **Subjective estimates** — probabilities often "finger in the air" 2. **Doesn't account for risk appetite** — ignores psychology (loss aversion) 3. **Simplified model** — reality is more complex 4. **Unstable** — small data changes can drastically alter the tree 5. **May be inaccurate** — other methods exist that are more precise (random forests) **But:** The method is valuable for **structuring thinking**, even if numbers are approximate. ## User Workflow ### 1. Structuring Ask: - What are the action options? - What are possible outcomes? - What are values/utility for each outcome? - How do we measure value? (money, utility units, happiness points) ### 2. Probability Estimation Help estimate through: - Historical data (if available) - Comparable situations - Expert judgment (user experience) - Subjective assessment (if no data) ### 3. Visualization Draw tree in markdown: ``` Decision ├─ Option A │ ├─ Outcome A1 (X%) → Value Y │ └─ Outcome A2 (Z%) → Value W └─ Option B └─ Outcome B1 (100%) → Value V ``` ### 4. EV Calculation For each option: ``` EV_A = (X% × Y) + (Z% × W) EV_B = V ``` ### 5. Recommendation Option with highest EV = best choice (rationally). **But add context:** - Risk tolerance (can user handle worst case) - Time horizon (when is result needed) - Other factors (reputational risk, emotions, ethics) ## Application Examples by Domain ### Trading & Investing **Position Sizing:** - Options: 5%, 10%, 20% of capital - Outcomes: Profit/loss with different probabilities - Value: Absolute profit in $ **Entry Timing:** - Options: Enter now, wait for -5%, wait for -10% - Outcomes: Price goes up/down - Value: Opportunity cost vs better entry price ### Business Strategy **Product Launch:** - Options: Launch / don't launch - Outcomes: Success / failure - Value: Revenue, market share, costs **Hiring Decision:** - Options: Hire candidate A / candidate B / don't hire - Outcomes: Successful onboarding / quit after X months - Value: Productivity, costs, opportunity cost ### Personal Decisions **Career Change:** - Options: Stay / change job / start business - Outcomes: Success / failure in new role - Value: Salary, satisfaction, growth, risk **Real Estate:** - Options: Buy house A / house B / continue renting - Outcomes: Price increase / decrease / personal situation changes - Value: Net worth, monthly costs, quality of life ### Operations **Capacity Planning:** - Options: Expand production / outsource / status quo - Outcomes: Demand increases / decreases - Value: Profit, utilization, fixed costs **Vendor Selection:** - Options: Vendor A / Vendor B / in-house - Outcomes: Quality, reliability, failures - Value: Total cost of ownership ## Calculator Script Use `scripts/decision_tree.py` for automated EV calculations: ```bash python3 scripts/decision_tree.py --interactive ``` Or via JSON: ```bash python3 scripts/decision_tree.py --json tree.json ``` JSON format: ```json { "decision": "Launch product?", "options": [ { "name": "Launch", "outcomes": [ {"name": "Success", "probability": 0.4, "value": 500000}, {"name": "Failure", "probability": 0.6, "value": -200000} ] }, { "name": "Don't launch", "outcomes": [ {"name": "Status quo", "probability": 1.0, "value": 0} ] } ] } ``` Output: ``` 📊 Decision Tree Analysis Decision: Launch product? Option 1: Launch └─ EV = $80,000.00 ├─ Success (40.0%) → +$500,000.00 └─ Failure (60.0%) → -$200,000.00 Option 2: Don't launch └─ EV = $0.00 └─ Status quo (100.0%) → $0.00 ✅ Recommendation: Launch (EV: $80,000.00) ``` ## Final Checklist Before giving recommendation, ensure: - ✅ All options covered - ✅ Probabilities sum to 100% for each branch - ✅ Values are realistic (not fantasies) - ✅ Worst case scenario is clear to user - ✅ Risk/reward ratio is explicit - ✅ Method limitations mentioned - ✅ Qualitative context added (not just EV) ## Method Advantages ✅ **Simple** — people understand trees intuitively ✅ **Visual** — clear structure ✅ **Works with little data** — can use expert estimates ✅ **White box** — transparent logic ✅ **Worst/best case** — extreme scenarios visible ✅ **Multiple decision-makers** — can account for different interests ## Method Disadvantages ❌ **Unstable** — small data changes → large tree changes ❌ **Inaccurate** — often more precise methods exist ❌ **Subjective** — probability estimates "from the head" ❌ **Complex** — becomes unwieldy with many outcomes ❌ **Doesn't account for risk preference** — assumes risk neutrality ## Important The method is valuable for **structuring thinking**, but numbers are often taken from thin air. What matters more is the process — **forcing yourself to think through all branches** and explicitly evaluate consequences. Don't sell the decision as "scientifically proven" — it's just a framework for conscious choice. ## Further Reading - Decision trees in operations research - Influence diagrams (more compact for complex decisions) - Utility functions (accounting for risk aversion) - Monte Carlo simulation (for greater accuracy) - Real options analysis (for strategic decisions)

path: README.md
content: # Decision Trees Skill

Decision tree analysis for complex decision-making across all domains.

## 📊 What It Does

Helps you make structured decisions using decision tree analysis with expected value (EV) calculations. Works for any situation where you need to evaluate multiple options with uncertain outcomes.

## ✨ Features

- **Universal application**: business, investing, personal decisions, operations, career choices
- **Expected value calculation**: quantify risk/reward scenarios
- **Visual tree structure**: see all options and outcomes clearly
- **Python calculator**: automate EV calculations (interactive + JSON)
- **Examples across domains**: trading, business strategy, personal life, operations

## 🎯 Use Cases

### Trading & Investing
- Position sizing (how much capital to allocate)
- Entry timing (buy now or wait)
- Exit strategy (take profit or hold)

### Business Strategy
- Product launch decisions
- Hiring choices
- Capacity planning
- Vendor selection

### Personal Decisions
- Career changes
- Real estate purchases
- Major life decisions

### Operations
- Outsourcing vs in-house
- Expansion timing
- Resource allocation

## 🚀 How It Works

1. **Define options** — all possible actions
2. **Define outcomes** — what can happen after each action
3. **Estimate probabilities** — how likely is each outcome (0-100%)
4. **Estimate values** — utility/reward for each outcome (money, points, utility units)
5. **Calculate EV** — expected value = Σ (probability × value)
6. **Choose** — option with highest EV (with qualitative context)

## 📝 Example

**Decision:** Launch new product?

**Options:**
- Launch (40% success → +$500K, 60% failure → -$200K)
- Don't launch (100% → $0)

**Calculation:**
```
Launch EV = (0.4 × $500K) + (0.6 × -$200K) = $80K
Don't launch EV = $0

✅ Recommendation: Launch (EV: $80K)
```

## 🛠️ Python Calculator

The skill includes a Python script for automated EV calculations:

### Interactive mode:
```bash
python3 scripts/decision_tree.py --interactive
```

### JSON mode:
```bash
python3 scripts/decision_tree.py --json tree.json
```

**JSON format:**
```json
{
  "decision": "Launch product?",
  "options": [
    {
      "name": "Launch",
      "outcomes": [
        {"name": "Success", "probability": 0.4, "value": 500000},
        {"name": "Failure", "probability": 0.6, "value": -200000}
      ]
    },
    {
      "name": "Don't launch",
      "outcomes": [
        {"name": "Status quo", "probability": 1.0, "value": 0}
      ]
    }
  ]
}
```

**Output:**
```
📊 Decision Tree Analysis

Decision: Launch product?

Option 1: Launch
  └─ EV = $80,000.00
     ├─ Success (40.0%) → +$500,000.00
     └─ Failure (60.0%) → -$200,000.00

Option 2: Don't launch
  └─ EV = $0.00
     └─ Status quo (100.0%) → $0.00

✅ Recommendation: Launch (EV: $80,000.00)
```

## ⚠️ Limitations

- **Subjective probabilities** — often "finger in the air" estimates
- **Doesn't account for risk appetite** — ignores loss aversion
- **Simplified model** — reality is more complex
- **Unstable** — small data changes can drastically alter the tree
- **May be inaccurate** — other methods may be more precise

**But:** The method is valuable for **structuring thinking**, even if numbers are approximate. The process forces you to think through all branches explicitly.

## 📚 What's Included

- **SKILL.md** — Complete guide with examples across domains
- **scripts/decision_tree.py** — EV calculator (interactive + JSON mode)
- Decision tree methodology
- Classic examples (party decision, product launch, trading)
- Advantages & disadvantages
- Domain-specific applications

## 🎓 Background

Decision trees are a standard tool in:
- Operations research
- Decision analysis
- Business strategy
- Economics & finance
- Machine learning (different use case)

They've been used since the 1960s for structured decision-making under uncertainty.

## 🤝 Contributing

This is an AgentSkill for Clawdbot. Improvements welcome:
- Additional examples
- Better visualization
- Enhanced calculator features
- Domain-specific templates

## 📄 License

MIT License — free to use and modify.

## 🔗 Resources

- [Decision tree on Wikipedia](https://en.wikipedia.org/wiki/Decision_tree)
- [Decision analysis](https://en.wikipedia.org/wiki/Decision_analysis)
- [Expected value](https://en.wikipedia.org/wiki/Expected_value)
- [ClawdHub](https://clawdhub.com) — discover more skills

---

**Created for Clawdbot** — the AI-powered CLI assistant.

Install via ClawdHub:
```bash
clawdhub install decision-trees
```

Or download manually from GitHub releases.


path: scripts/decision_tree.py
content: #!/usr/bin/env python3
"""
Decision Tree Calculator
Calculates expected value (EV) for decision tree analysis.
"""

import argparse
import json
import sys
from typing import List, Dict, Any


def calculate_ev(outcomes: List[Dict[str, Any]]) -> float:
    """Calculate expected value from list of outcomes."""
    return sum(outcome["probability"] * outcome["value"] for outcome in outcomes)


def validate_probabilities(outcomes: List[Dict[str, Any]]) -> bool:
    """Check if probabilities sum to 1.0 (with tolerance)."""
    total = sum(outcome["probability"] for outcome in outcomes)
    return abs(total - 1.0) < 0.001


def format_value(value: float) -> str:
    """Format monetary value with sign."""
    sign = "+" if value > 0 else ""
    return f"{sign}${value:,.2f}"


def print_tree(data: Dict[str, Any]) -> None:
    """Print formatted decision tree analysis."""
    print(f"\n📊 Decision Tree Analysis\n")
    print(f"Decision: {data['decision']}\n")
    
    best_option = None
    best_ev = float('-inf')
    
    for i, option in enumerate(data['options'], 1):
        ev = calculate_ev(option['outcomes'])
        
        print(f"Option {i}: {option['name']}")
        print(f"  └─ EV = {format_value(ev)}")
        
        for outcome in option['outcomes']:
            prob_pct = outcome['probability'] * 100
            value_str = format_value(outcome['value'])
            print(f"     ├─ {outcome['name']} ({prob_pct:.1f}%) → {value_str}")
        
        print()
        
        if ev > best_ev:
            best_ev = ev
            best_option = option['name']
    
    print(f"✅ Recommendation: {best_option} (EV: {format_value(best_ev)})")
    print()


def interactive_mode() -> None:
    """Interactive mode for building decision tree."""
    print("📊 Decision Tree Calculator - Interactive Mode\n")
    
    decision = input("What decision are you analyzing? ")
    options = []
    
    while True:
        print(f"\nOption {len(options) + 1}")
        name = input("  Option name (or 'done' to finish): ")
        
        if name.lower() == 'done':
            break
        
        outcomes = []
        remaining_prob = 1.0
        
        print(f"  Outcomes for '{name}':")
        
        while remaining_prob > 0.001:
            outcome_name = input(f"    Outcome name (remaining probability: {remaining_prob:.2%}): ")
            
            if remaining_prob < 1.0:
                use_remaining = input(f"    Use remaining {remaining_prob:.2%}? (y/n): ").lower()
                if use_remaining == 'y':
                    prob = remaining_prob
                else:
                    prob = float(input("    Probability (0-1): "))
            else:
                prob = float(input("    Probability (0-1): "))
            
            value = float(input("    Value ($): "))
            
            outcomes.append({
                "name": outcome_name,
                "probability": prob,
                "value": value
            })
            
            remaining_prob -= prob
        
        if not validate_probabilities(outcomes):
            print("  ⚠️  Warning: Probabilities don't sum to 1.0")
        
        options.append({
            "name": name,
            "outcomes": outcomes
        })
    
    data = {
        "decision": decision,
        "options": options
    }
    
    print_tree(data)
    
    # Offer to save
    save = input("Save to JSON file? (y/n): ").lower()
    if save == 'y':
        filename = input("Filename: ")
        with open(filename, 'w') as f:
            json.dump(data, f, indent=2)
        print(f"✅ Saved to {filename}")


def main():
    parser = argparse.ArgumentParser(description='Decision Tree Calculator')
    parser.add_argument('--json', help='Path to JSON file with decision tree')
    parser.add_argument('--interactive', '-i', action='store_true', 
                        help='Interactive mode')
    
    args = parser.parse_args()
    
    if args.interactive:
        interactive_mode()
    elif args.json:
        try:
            with open(args.json, 'r') as f:
                data = json.load(f)
            
            # Validate structure
            if 'decision' not in data or 'options' not in data:
                print("Error: JSON must have 'decision' and 'options' fields")
                sys.exit(1)
            
            # Validate probabilities
            for option in data['options']:
                if not validate_probabilities(option['outcomes']):
                    print(f"Warning: Probabilities for '{option['name']}' don't sum to 1.0")
            
            print_tree(data)
            
        except FileNotFoundError:
            print(f"Error: File '{args.json}' not found")
            sys.exit(1)
        except json.JSONDecodeError:
            print(f"Error: Invalid JSON in '{args.json}'")
            sys.exit(1)
    else:
        parser.print_help()
        sys.exit(1)


if __name__ == '__main__':
    main()


Security scan verdicts — ClawScan: clean | static analysis: clean | VirusTotal: clean | SkillSpector: suspicious (HIGH)