Skip to content

Commit dcba83a

Browse files
committed
codex
1 parent 150c7f9 commit dcba83a

22 files changed

+20596
-1343
lines changed

.DS_Store

0 Bytes
Binary file not shown.
1.44 KB
Binary file not shown.
21.1 KB
Binary file not shown.

arc_solver/behavioral_engine.py

Lines changed: 27 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -58,6 +58,7 @@ class RewardBreakdown:
5858
shape_accuracy: float
5959
behaviour_bonus: float
6060
program_length_penalty: float
61+
generalization_penalty: float
6162
reward: float
6263

6364

@@ -115,15 +116,38 @@ def grade(
115116
+ shape_accuracy * self.shape_weight
116117
+ behaviour_bonus * self.behaviour_weight
117118
)
118-
reward = max(0.0, min(1.0, reward - penalty))
119+
generalization_penalty = self._generalization_penalty(predictions, targets)
120+
reward = max(0.0, min(1.0, reward - penalty - generalization_penalty))
119121
return RewardBreakdown(
120122
pixel_accuracy=pixel_accuracy,
121123
shape_accuracy=shape_accuracy,
122124
behaviour_bonus=behaviour_bonus,
123125
program_length_penalty=penalty,
126+
generalization_penalty=generalization_penalty,
124127
reward=reward,
125128
)
126129

130+
def _generalization_penalty(
131+
self,
132+
predictions: Sequence[Array],
133+
targets: Sequence[Array],
134+
) -> float:
135+
penalty = 0.0
136+
if len(predictions) > 1 and len(targets) > 1:
137+
first_pred = predictions[0]
138+
preds_identical = all(np.array_equal(first_pred, pred) for pred in predictions[1:])
139+
first_target = targets[0]
140+
targets_identical = all(np.array_equal(first_target, tgt) for tgt in targets[1:])
141+
if preds_identical and not targets_identical:
142+
penalty += 0.1
143+
144+
constant_predictions = all(np.all(pred == pred.flat[0]) for pred in predictions) if predictions else False
145+
constant_targets = all(np.all(tgt == tgt.flat[0]) for tgt in targets) if targets else False
146+
if constant_predictions and not constant_targets:
147+
penalty += 0.1
148+
149+
return penalty
150+
127151

128152
@dataclass
129153
class BehaviouralMetrics:
@@ -231,6 +255,7 @@ def train(
231255
continue
232256
solved = best_breakdown.reward > 0.999
233257
guidance.reinforce(train_pairs, best_program, best_breakdown.reward, inference)
258+
search.intraverbal.reinforce(best_program, best_breakdown.reward)
234259
episodic.add_successful_solution(
235260
train_pairs,
236261
[best_program],
@@ -311,6 +336,7 @@ def _emit_metrics(
311336
"pixel_accuracy": breakdown.pixel_accuracy,
312337
"shape_accuracy": breakdown.shape_accuracy,
313338
"behaviour_bonus": breakdown.behaviour_bonus,
339+
"generalization_penalty": breakdown.generalization_penalty,
314340
"program_length": len(program),
315341
"global": self.metrics.as_dict(),
316342
}

arc_solver/dsl.py

Lines changed: 0 additions & 71 deletions
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,6 @@
2121
pad_to,
2222
bg_color,
2323
)
24-
from .patterns import PlaceholderTemplate, PlaceholderTemplateEngine
2524

2625

2726
class Op:
@@ -628,69 +627,6 @@ def op_human_spatial_reasoning(a: Array, hypothesis_name: str = "",
628627
return a # Will be replaced by the actual hypothesis result
629628

630629

631-
# Custom operations for placeholder reconstruction
632-
def op_create_pattern_fill(a: Array, pattern: List[int], target_bounds: Tuple[int, int, int, int], direction: str) -> Array:
633-
"""Create a grid with pattern filled in the target bounds."""
634-
from .placeholder_reconstruction import create_pattern_fill
635-
return create_pattern_fill(a, pattern, target_bounds, direction)
636-
637-
638-
def op_tile_pattern(a: Array, pattern: List[int], target_bounds: Tuple[int, int, int, int], direction: str) -> Array:
639-
"""Tile a pattern within the target bounds."""
640-
from .placeholder_reconstruction import tile_pattern
641-
return tile_pattern(a, pattern, target_bounds, direction)
642-
643-
644-
def op_paste_at(source: Array, target_top: int, target_left: int, *, target_grid: Optional[Array] = None) -> Array:
645-
"""Paste source grid into target at specified position."""
646-
from .placeholder_reconstruction import paste_at
647-
if target_grid is None:
648-
# Create a target grid of appropriate size
649-
target_grid = np.zeros((source.shape[0] + target_top, source.shape[1] + target_left), dtype=source.dtype)
650-
return paste_at(source, target_grid, target_top, target_left)
651-
652-
653-
def op_apply_advanced_mirroring(a: Array, template: Any, strategy: str) -> Array:
654-
"""Apply advanced mirroring strategies."""
655-
from .placeholder_reconstruction import apply_advanced_mirroring
656-
return apply_advanced_mirroring(a, template, strategy)
657-
658-
659-
def op_derive_recolor_mapping(a: Array, template: Any, candidate_region: Array) -> Dict[int, int]:
660-
"""Derive recolor mapping from border analysis."""
661-
from .placeholder_reconstruction import derive_recolor_mapping
662-
return derive_recolor_mapping(a, template, candidate_region)
663-
664-
665-
def op_extract_stripe_patterns(a: Array, template: Any) -> Dict[str, Array]:
666-
"""Extract stripe patterns from borders."""
667-
from .placeholder_reconstruction import extract_stripe_patterns
668-
return extract_stripe_patterns(a, template)
669-
670-
671-
def op_apply_placeholder_template(a: Array, template_signature: str, template_shape: Tuple[int, int]) -> Array:
672-
"""Applies a placeholder template to reconstruct a grid."""
673-
engine = PlaceholderTemplateEngine()
674-
# This is a simplified version. We need to reconstruct the template object.
675-
# For now, we'll rely on the engine's internal cache if it exists,
676-
# but this will likely fail if the template isn't already in memory.
677-
# A proper implementation would need to deserialize the template fully.
678-
template = PlaceholderTemplate(signature=template_signature, placeholder_shape=template_shape, fill_fn=lambda x: x) # Dummy fill_fn
679-
result = engine.apply_template(a, template)
680-
if result is None:
681-
raise ValueError("Failed to apply placeholder template from macro.")
682-
return result
683-
684-
685-
def op_extract_using_transformation(a: Array, **kwargs) -> Array:
686-
"""Placeholder for applying a transformation from a macro."""
687-
# This is a complex operation that depends on the HumanGradeReasoner state.
688-
# Implementing this as a pure function would require significant refactoring.
689-
# For now, this will act as a placeholder and return the input grid.
690-
print("WARNING: op_extract_using_transformation is not fully implemented and will not produce the correct output.")
691-
return a
692-
693-
694630
# Registry of primitive operations ---------------------------------------------------------
695631
OPS: Dict[str, Op] = {
696632
"identity": Op("identity", op_identity, 1, []),
@@ -715,13 +651,6 @@ def op_extract_using_transformation(a: Array, **kwargs) -> Array:
715651
"extract_distinct_regions": Op("extract_distinct_regions", op_extract_distinct_regions, 1, []),
716652
"human_spatial_reasoning": Op("human_spatial_reasoning", op_human_spatial_reasoning, 1,
717653
["hypothesis_name", "hypothesis_id", "confidence", "verification_score"]),
718-
719-
# Placeholder reconstruction operations
720-
"create_pattern_fill": Op("create_pattern_fill", op_create_pattern_fill, 1, ["pattern", "target_bounds", "direction"]),
721-
"tile_pattern": Op("tile_pattern", op_tile_pattern, 1, ["pattern", "target_bounds", "direction"]),
722-
"paste_at": Op("paste_at", op_paste_at, 1, ["target_top", "target_left", "target_grid"]),
723-
"apply_placeholder_template": Op("apply_placeholder_template", op_apply_placeholder_template, 1, ["template_signature", "template_shape"]),
724-
"extract_using_transformation": Op("extract_using_transformation", op_extract_using_transformation, 1, ["target_shape", "translation", "subject_signature", "object_signature"]),
725654
}
726655

727656

0 commit comments

Comments
 (0)