Abstract
Tree-matching algorithms are essential for comparing hierarchical data structures, yet traditional methods often impose a rigid constraint: they strictly preserve ancestry. This paper introduces "flexible tree matching," a framework that relaxes these constraints through a tunable cost model. By allowing structural "rule-breaking," the method better aligns with human intuition in domains like web design, where hierarchies are often suggestive rather than definitive. We demonstrate that while the problem is NP-complete, a stochastic approximation algorithm combined with structured prediction can learn to match trees with near-human consistency.
The Problem: Rigid vs. Suggestive Hierarchies
Comparing trees is a fundamental task across diverse fields, from computational biology to natural language processing. The standard approach, tree edit distance, calculates the minimum cost to transform one tree into another. However, classical tree matching is inherently "rigid." It assumes that if node A is an ancestor of node B in the source tree, their corresponding nodes in the target tree must maintain that same relationship.
This rigidity often fails in practical applications. Consider web design: a designer might move a search bar from a header (top of the tree) to a footer (bottom of the tree) during a mobile redesign. A rigid algorithm would fail to match these elements because their ancestry has changed, despite their functional identity remaining the same. Flexible tree matching addresses this by treating hierarchy as a guideline rather than a strict law.
Methods: The Flexible Cost Model
The authors propose a flexible cost model that treats tree matching as a bipartite matching problem. The model incorporates three primary penalty terms to balance structural fidelity with flexibility:
- Relabeling ($c_r$): Penalizes matching nodes with different labels (e.g., matching a "button" to a "text field").
- Ancestry ($c_a$): Penalizes matches that violate parent-child relationships.
- Sibling ($c_s$): Penalizes "breaking up the family" by matching siblings to different parents in the target tree.
By adjusting these weights, the algorithm can be tuned for different levels of structural strictness. For example, setting a high ancestry weight ($w_a$) forces the algorithm to behave more like a traditional rigid matcher, while lowering it allows for the "rule-breaking" necessary for web retargeting.
Computational Complexity and Learning
The paper proves that flexible tree matching is NP-complete (specifically via a reduction from the 3-PARTITION problem). To handle this complexity, the authors employ a Metropolis algorithm—a stochastic Monte Carlo method—to efficiently find high-quality approximate solutions. To avoid manual parameter tuning, the researchers used a generalized perceptron (a structured prediction technique) to "learn" the optimal balance of weights by observing examples of human-provided matchings.
Evaluation and Results
The model was evaluated using a corpus of 50 popular websites. A human ground truth dataset was established through an online study where participants provided 117 manual matchings across 52 unique page pairs.
Key findings include:
- Human Inconsistency: Humans agreed with each other only 78.3% of the time, establishing a realistic performance ceiling for any algorithm.
- Accuracy: The flexible model achieved 68.7% similarity to human matchings. When using a more relaxed "nearest-neighbor" metric, accuracy jumped to 77.7%, nearly matching the 78.3% human-to-human consistency rate.
- Practical Utility: The method successfully enabled "automatic retargeting," transferring content and styling from desktop layouts to mobile formats while preserving the underlying design logic.
Conclusion
Flexible tree matching acknowledges that in many human-centric domains, hierarchy is suggestive, not definitive. While the problem is computationally hard, the combination of stochastic search and structured learning provides a practical path forward for complex data matching tasks in web design, 3D modeling, and beyond.
Summary updated