|
| 1 | +--- |
| 2 | +layout: post |
| 3 | +title: Hill Climbing Search for Predicate Discovery |
| 4 | +date: 2025-10-23 10:00:00 |
| 5 | +description: An interactive visualization of the hill climbing algorithm used in grammar search invention for task planning |
| 6 | +tags: algorithms optimization machine-learning |
| 7 | +categories: tutorial |
| 8 | +related_posts: false |
| 9 | +--- |
| 10 | + |
| 11 | +Hill climbing is a fundamental optimization algorithm that iteratively improves a solution by making locally optimal choices. In this post, we'll explore how it's used to discover predicates for task planning systems. |
| 12 | + |
| 13 | +## What is Hill Climbing? |
| 14 | + |
| 15 | +Hill climbing is a **local search algorithm** that starts from an initial solution and repeatedly moves to a better neighboring solution until no improvement can be found. Think of it as climbing a hill in dense fog - you can only see your immediate surroundings, so you keep taking steps upward until you reach a peak. |
| 16 | + |
| 17 | +### Key Characteristics: |
| 18 | + |
| 19 | +- **Greedy approach**: Always chooses the best immediate option |
| 20 | +- **Local search**: Only explores nearby solutions |
| 21 | +- **No backtracking**: Cannot undo previous decisions |
| 22 | +- **Fast convergence**: Typically finds solutions quickly |
| 23 | + |
| 24 | +## Application: Predicate Discovery for Planning |
| 25 | + |
| 26 | +In the **Predicators** system for neuro-symbolic learning, hill climbing is used to discover the optimal set of logical predicates that describe a planning domain. |
| 27 | + |
| 28 | +### The Problem: |
| 29 | + |
| 30 | +Given a large grammar of 121 possible predicates, find the subset that: |
| 31 | +- Best describes the planning domain |
| 32 | +- Minimizes the heuristic score (planning difficulty) |
| 33 | +- Enables efficient task completion |
| 34 | + |
| 35 | +### The Solution: |
| 36 | + |
| 37 | +Start with an empty set and iteratively add predicates that provide the most improvement, until no better predicates can be found. |
| 38 | + |
| 39 | +## Interactive Demonstration |
| 40 | + |
| 41 | +Below is a real example from the Predicators paper, showing how hill climbing discovered 5 optimal predicates in just 5 steps, reducing the heuristic from 535,231 to 293! |
| 42 | + |
| 43 | +<div class="row mt-3"> |
| 44 | + <div class="col-sm mt-3 mt-md-0"> |
| 45 | + <iframe src="/assets/html/hill-climbing-visualization.html" width="100%" height="1200" frameborder="0" style="border: 1px solid #ddd; border-radius: 8px;"></iframe> |
| 46 | + </div> |
| 47 | +</div> |
| 48 | + |
| 49 | +## Key Observations |
| 50 | + |
| 51 | +### Massive Early Improvement |
| 52 | +The first predicate reduced the heuristic by **99.7%** (from 535,231 to 13,659)! This shows that even basic logical conditions can dramatically improve planning efficiency. |
| 53 | + |
| 54 | +### Diminishing Returns |
| 55 | +Later steps show smaller improvements: |
| 56 | +- Step 1: -99.7% |
| 57 | +- Step 2: -1.5% |
| 58 | +- Step 3: -97.0% |
| 59 | +- Step 4: -15.4% |
| 60 | +- Step 5: -13.0% |
| 61 | + |
| 62 | +This is typical of hill climbing - early steps make big improvements, later steps fine-tune. |
| 63 | + |
| 64 | +### Fast Convergence |
| 65 | +Only **5 iterations** were needed to find the optimal set from 121 candidates. The algorithm evaluated 726 predicates total but efficiently pruned the search space. |
| 66 | + |
| 67 | +## The Mathematics |
| 68 | + |
| 69 | +The hill climbing algorithm can be formalized as: |
| 70 | + |
| 71 | +$$ |
| 72 | +s_{t+1} = \arg\max_{s' \in N(s_t)} f(s') |
| 73 | +$$ |
| 74 | + |
| 75 | +where: |
| 76 | +- $$s_t$$ is the current state at time $$t$$ |
| 77 | +- $$N(s_t)$$ is the set of neighbor states |
| 78 | +- $$f(s')$$ is the evaluation function (heuristic) |
| 79 | +- We terminate when $$f(s_{t+1}) \leq f(s_t)$$ for all neighbors |
| 80 | + |
| 81 | +In this application: |
| 82 | +- **State**: A set of predicates |
| 83 | +- **Neighbors**: States with one additional predicate |
| 84 | +- **Evaluation**: Heuristic score from learned operators |
| 85 | + |
| 86 | +## Advantages and Limitations |
| 87 | + |
| 88 | +### ✅ Advantages: |
| 89 | +1. **Simple to implement** - straightforward algorithm |
| 90 | +2. **Fast execution** - finds solutions quickly |
| 91 | +3. **Low memory** - only stores current state |
| 92 | +4. **Works well** - effective for many problems |
| 93 | + |
| 94 | +### ⚠️ Limitations: |
| 95 | +1. **Local optima** - may get stuck at peaks that aren't global maxima |
| 96 | +2. **No backtracking** - cannot undo bad early decisions |
| 97 | +3. **Order dependent** - different starting points yield different results |
| 98 | +4. **Plateau problem** - can get stuck on flat regions |
| 99 | + |
| 100 | +## Extensions and Variations |
| 101 | + |
| 102 | +To address limitations, several variants exist: |
| 103 | + |
| 104 | +### Random-Restart Hill Climbing |
| 105 | +Run hill climbing multiple times with different starting points and choose the best result. |
| 106 | + |
| 107 | +### Simulated Annealing |
| 108 | +Occasionally accept worse solutions to escape local optima, with probability decreasing over time. |
| 109 | + |
| 110 | +### Tabu Search |
| 111 | +Maintain a list of recently visited states to avoid cycling. |
| 112 | + |
| 113 | +### Beam Search |
| 114 | +Keep track of multiple candidate solutions simultaneously. |
| 115 | + |
| 116 | +## Real-World Performance |
| 117 | + |
| 118 | +The predicates discovered by this hill climbing search enabled the system to: |
| 119 | +- ✅ Solve **50/50 test tasks** (100% success rate) |
| 120 | +- ⏱️ Average planning time: **0.0023 seconds** |
| 121 | +- 🎯 Found optimal solution in **5 steps** |
| 122 | + |
| 123 | +This demonstrates that simple algorithms can be highly effective when applied to the right problem structure! |
| 124 | + |
| 125 | +## Try It Yourself! |
| 126 | + |
| 127 | +Use the interactive visualization above to: |
| 128 | +1. **Step through** the algorithm iteration by iteration |
| 129 | +2. **Auto-play** to watch the full search process |
| 130 | +3. **See the predicates** being added at each step |
| 131 | +4. **Track the heuristic** improvement on the chart |
| 132 | + |
| 133 | +Use keyboard shortcuts: |
| 134 | +- `→` Next step |
| 135 | +- `←` Previous step |
| 136 | +- `Space` Play/Pause |
| 137 | +- `R` Reset |
| 138 | + |
| 139 | +## Conclusion |
| 140 | + |
| 141 | +Hill climbing is a powerful yet simple optimization technique that works remarkably well for many real-world problems. While it has limitations, understanding when and how to apply it is a crucial skill in AI and machine learning. |
| 142 | + |
| 143 | +The predicate discovery example shows how hill climbing can efficiently search through large spaces to find compact, effective solutions - a key principle in neuro-symbolic AI systems. |
| 144 | + |
| 145 | +## References |
| 146 | + |
| 147 | +- [Predicators: Neuro-Symbolic Learning for Task Planning](https://arxiv.org/abs/2210.00649) |
| 148 | +- Silver, T., Hariprasad, V., Shuttleworth, R. S., Kumar, N., Lozano-Pérez, T., & Kaelbling, L. P. (2022) |
| 149 | + |
0 commit comments