Last active
August 29, 2015 14:21
-
-
Save kgadek/e018008be8cfcce313fd to your computer and use it in GitHub Desktop.
prototyp DriverGen
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class DriverGen: | |
def __init__(self): | |
pass | |
def population_generator(): | |
# raise NotImplementedError | |
current_cost = 0 | |
finalized_pop = [] | |
while True: | |
# Kojarzycie WALL-E? No to ten statek wielki nazywał się Axiom. | |
# Pakujemy **KOPIĘ** populacji, bo łatwiej człowieka sklonować niż | |
# coś o nim mądrego powiedzieć i coś mądrego z takim stadem zrobić | |
# (aka. obliczyć fitness, sfinalizować populację). | |
axiom_returned = yield AxiomSpaceship(cost, current_population) | |
# O, Axiom wrócił. I ma imigrantów. No siema, imigranci! | |
# What? Population is evolving! | |
# ... | |
# Population evolved into population! | |
# (and you just lost 100 credits) | |
current_cost += 100 | |
class AxiomSpaceship: | |
def __init__(self, cost_so_far, current_population): | |
self.cost_so_far = cost_so_far | |
def finalized_population(self): | |
# to wykańcza populację. | |
# (pun intended) | |
raise NotImplementedError | |
# nie ma „current population” bo po co? | |
def get_immigrants(self): | |
raise NotImplementedError | |
def send_emigrants(self, emigrants): | |
raise NotImplementedError | |
# ------------------------------------------------------------------------------ | |
# IMGA+SPEA2 | |
# ---------- | |
# kod wewn. IMGA | |
# Dawno dawno temu… | |
statek_Axiom = None | |
# …w odległej wyspie archipelagu IMGA | |
zycia_krag = wysepka.population_generator() | |
# https://youtu.be/wIrIaSNfHaU | |
while True: | |
# Nants'ngonyama bakithi baba [nadchodzi statek Axiom] | |
# Sithi hu ngonyama [o tak, to jest statek Axiom] | |
statek_Axiom = zycia_krag.send(statek_Axiom) | |
# wieczny życia krąg | |
# co prowadzi nas | |
# o ile nas na to stać | |
if statek_Axiom.cost_so_far > budzet_ZUSu: | |
raise StopIteration | |
# jacyś imigranci? Hakuna matata! | |
simba_grylls_i_reszta = statek_Axiom.get_immigrants() | |
# …albo w sumie nie, oni jedzą robaki. Fuj. | |
# Nakaz deportacji! | |
statek_Axiom.send_emigrants( simba_grylls_i_reszta ) | |
# jak tylko Axiom przyleci w linii 60 to zabierze emigrantów | |
# ------------------------------------------------------------------------------ | |
# SPEA2 | |
# ----- | |
# kod testerki | |
statek_Axiom = None | |
zycia_krag = SPEA2(...).population_generator() | |
while True: | |
statek_Axiom = zycia_krag.send(statek_Axiom) | |
if statek_Axiom.cost_so_far > budzet: | |
break | |
# trochę księgowości: zapisz koszt i obecny progress | |
koszt = statek_Axiom.cost_so_far | |
progress = statek_Axiom.finalized_population() | |
# jakieś metryki | |
metryka_extent = extent(progres) | |
metryka_dst = distance_from_pareto(progres, target_pareto_front) | |
# ------------------------------------------------------------------------------ | |
# HGS+SPEA2 | |
# ----- | |
# kod wewn. HGS-owych node'ów | |
statek_Axiom = None | |
zycia_krag = wysepka.population_generator() | |
while _ in range(metaepoch_length): | |
statek_Axiom = zycia_krag.send(statek_Axiom) | |
nowa_populacja = statek_Axiom.finalized_population() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment