MCPcopy Create free account
hub / github.com/FareedKhan-dev/ai-long-task / _sample_from_island_random

Method _sample_from_island_random

data/database.py:1488–1517  ·  view source on GitHub ↗

Sample a completely random parent from a specific island (uniform distribution) Args: island_id: The island to sample from Returns: Parent program selected uniformly at random

(self, island_id: int)

Source from the content-addressed store, hash-verified

1486 return parent
1487
1488 def _sample_from_island_random(self, island_id: int) -> Program:
1489 """
1490 Sample a completely random parent from a specific island (uniform distribution)
1491
1492 Args:
1493 island_id: The island to sample from
1494
1495 Returns:
1496 Parent program selected uniformly at random
1497 """
1498 island_id = island_id % len(self.islands)
1499 island_programs = list(self.islands[island_id])
1500
1501 if not island_programs:
1502 # Island is empty, fall back to any available program
1503 logger.debug(f"Island {island_id} is empty, sampling from all programs")
1504 return self._sample_random_parent()
1505
1506 # Clean up stale references
1507 valid_programs = [pid for pid in island_programs if pid in self.programs]
1508
1509 if not valid_programs:
1510 logger.warning(
1511 f"Island {island_id} has no valid programs, falling back to random sampling"
1512 )
1513 return self._sample_random_parent()
1514
1515 # Uniform random selection
1516 parent_id = random.choice(valid_programs)
1517 return self.programs[parent_id]
1518
1519 def _sample_from_archive_for_island(self, island_id: int) -> Program:
1520 """

Callers 1

sample_from_islandMethod · 0.95

Calls 1

_sample_random_parentMethod · 0.95

Tested by

no test coverage detected