示例#1
0
文件: cell.py 项目: benureau/goals
 def cp_all(self):
     if len(self.c_history) < 2:
         return 0.0
     estimator = SpanSeigelEstimator(len(self.c_history))
     for c in self.c_history:
         if c is not None:
             estimator.add(c)
     return estimator.value()
示例#2
0
文件: cell.py 项目: humm/goals
 def cp_all(self):
     if len(self.c_history) < 2:
         return 0.0
     estimator = SpanSeigelEstimator(len(self.c_history))
     for c in self.c_history:
         if c is not None:
             estimator.add(c)
     return estimator.value()
示例#3
0
文件: cell.py 项目: benureau/goals
 def pei_all(self):
     if len(self.pe_history) < 2:
         return 0.0
     estimator = SpanSeigelEstimator(len(self.pe_history))
     for pe in self.pe_history:
         if pe is not None:
             estimator.add(pe)
     return estimator.value()
示例#4
0
文件: cell.py 项目: humm/goals
 def pei_all(self):
     if len(self.pe_history) < 2:
         return 0.0
     estimator = SpanSeigelEstimator(len(self.pe_history))
     for pe in self.pe_history:
         if pe is not None:
             estimator.add(pe)
     return estimator.value()
示例#5
0
文件: cell.py 项目: benureau/goals
    def __init__(self, bounds, graph, uid, cfg, depth=0, w=None):
        """"""
        Cell.__init__(self, bounds, graph, uid, depth=depth, w=w, cfg=cfg)

        self.goals = []

        self.c_history = []  # C  : Competence
        self.cp_history = [0.0]  # CP : Competence Progress
        self.estimator_cp = SpanSeigelEstimator(cfg.cell.max_cp)
示例#6
0
文件: cell.py 项目: benureau/goals
    def __init__(self, bounds, graph, uid, cfg, depth=0, w=None):
        """"""
        Cell.__init__(self, bounds, graph, uid, depth=depth, w=w, cfg=cfg)

        self.predictions = []

        self.pe_history = []  # PE : Prediction Error
        self.pei_history = [0.0]  # PEI: PE Improvement
        self.estimator_pei = SpanSeigelEstimator(cfg.cell.max_pei)
示例#7
0
文件: cell.py 项目: humm/goals
    def __init__(self, bounds, graph, uid, cfg, depth = 0, w = None):
        """"""
        Cell.__init__(self, bounds, graph, uid, depth = depth, w = w, cfg = cfg)

        self.goals       = []

        self.c_history     = []    # C  : Competence
        self.cp_history    = [0.0] # CP : Competence Progress
        self.estimator_cp  = SpanSeigelEstimator(cfg.cell.max_cp)
示例#8
0
文件: cell.py 项目: humm/goals
    def __init__(self, bounds, graph, uid, cfg, depth = 0,  w = None):
        """"""
        Cell.__init__(self, bounds, graph, uid,  depth = depth, w = w, cfg = cfg)

        self.predictions = []

        self.pe_history    = []    # PE : Prediction Error
        self.pei_history   = [0.0] # PEI: PE Improvement
        self.estimator_pei = SpanSeigelEstimator(cfg.cell.max_pei)
示例#9
0
文件: cell.py 项目: benureau/goals
class GoalCell(Cell):
    def __init__(self, bounds, graph, uid, cfg, depth=0, w=None):
        """"""
        Cell.__init__(self, bounds, graph, uid, depth=depth, w=w, cfg=cfg)

        self.goals = []

        self.c_history = []  # C  : Competence
        self.cp_history = [0.0]  # CP : Competence Progress
        self.estimator_cp = SpanSeigelEstimator(cfg.cell.max_cp)

    def add(self, goal, effect, competence=None):

        if goal is None or not self.belongs(goal):
            return

        self.goals.append(goal)
        self.effects.append(effect)

        if competence is None:
            competence = cmpce.competence(goal, effect, cfg=self.cfg)

        self.c_history.append(competence)
        self.estimator_cp.add(competence)

        if len(self.c_history) >= self.cfg.cell.min_cp:
            self.cp_history.append(self.estimator_cp.value())
        else:
            self.cp_history.append(0.0)

    def split(self, low_bounds, high_bounds):
        return self.graph.goal_split(self, low_bounds, high_bounds)

    @property
    def competence(self):
        return self.c_history[-1]

    @property
    def cp_all(self):
        if len(self.c_history) < 2:
            return 0.0
        estimator = SpanSeigelEstimator(len(self.c_history))
        for c in self.c_history:
            if c is not None:
                estimator.add(c)
        return estimator.value()

    @property
    def cp(self):
        return self.cp_history[-1]

    def avg_competence(self, span=None):
        if len(self.c_history) == 0:
            return None
        if span is not None and span > 0:
            return sum(self.c_history[:-span]) / span
        else:
            return sum(self.c_history) / len(self.c_history)

    def __len__(self):
        return len(self.goals)
示例#10
0
文件: cell.py 项目: benureau/goals
class EffectCell(Cell):
    def __init__(self, bounds, graph, uid, cfg, depth=0, w=None):
        """"""
        Cell.__init__(self, bounds, graph, uid, depth=depth, w=w, cfg=cfg)

        self.predictions = []

        self.pe_history = []  # PE : Prediction Error
        self.pei_history = [0.0]  # PEI: PE Improvement
        self.estimator_pei = SpanSeigelEstimator(cfg.cell.max_pei)

    def add(self, effect, prediction=None, pred_error=None):

        if not self.belongs(effect):
            return False

        self.effects.append(effect)

        if prediction is not None or pred_error is not None:
            self.predictions.append(prediction)
            if pred_error is None:
                pred_error = cmpce.competence(prediction, effect, cfg=self.cfg)

            self.pe_history.append(pred_error)
            self.estimator_pei.add(pred_error)

            if len(self.pe_history) >= self.cfg.cell.min_pei:
                self.pei_history.append(self.estimator_pei.value())
            else:
                self.pei_history.append(0.0)

        return True

    def split(self, low_bounds, high_bounds):
        return self.graph.effect_split(self, low_bounds, high_bounds)

    @property
    def pe(self):
        return self.pe_history[-1]

    @property
    def pei(self):
        return self.pei_history[-1]

    @property
    def pei_all(self):
        if len(self.pe_history) < 2:
            return 0.0
        estimator = SpanSeigelEstimator(len(self.pe_history))
        for pe in self.pe_history:
            if pe is not None:
                estimator.add(pe)
        return estimator.value()

    def avg_pred_error(self, span=None):
        if len(self.pe_history) == 0:
            return None
        if span is not None and span > 0:
            return sum(self.pe_history[:-span]) / span
        else:
            return sum(self.pe_history) / len(self.pe_history)

    def __len__(self):
        return len(self.effects)
示例#11
0
文件: cell.py 项目: humm/goals
class GoalCell(Cell):

    def __init__(self, bounds, graph, uid, cfg, depth = 0, w = None):
        """"""
        Cell.__init__(self, bounds, graph, uid, depth = depth, w = w, cfg = cfg)

        self.goals       = []

        self.c_history     = []    # C  : Competence
        self.cp_history    = [0.0] # CP : Competence Progress
        self.estimator_cp  = SpanSeigelEstimator(cfg.cell.max_cp)

    def add(self, goal, effect, competence = None):

        if goal is None or not self.belongs(goal):
            return

        self.goals.append(goal)
        self.effects.append(effect)

        if competence is None:
            competence = cmpce.competence(goal, effect, cfg = self.cfg)

        self.c_history.append(competence)
        self.estimator_cp.add(competence)

        if len(self.c_history) >= self.cfg.cell.min_cp:
            self.cp_history.append(self.estimator_cp.value())
        else:
            self.cp_history.append(0.0)

    def split(self, low_bounds, high_bounds):
        return self.graph.goal_split(self, low_bounds, high_bounds)

    @property
    def competence(self):
        return self.c_history[-1]

    @property
    def cp_all(self):
        if len(self.c_history) < 2:
            return 0.0
        estimator = SpanSeigelEstimator(len(self.c_history))
        for c in self.c_history:
            if c is not None:
                estimator.add(c)
        return estimator.value()

    @property
    def cp(self):
        return self.cp_history[-1]

    def avg_competence(self, span = None):
        if len(self.c_history) == 0:
            return None
        if span is not None and span > 0:
            return sum(self.c_history[:-span])/span
        else:
            return sum(self.c_history)/len(self.c_history)

    def __len__(self):
        return len(self.goals)
示例#12
0
文件: cell.py 项目: humm/goals
class EffectCell(Cell):

    def __init__(self, bounds, graph, uid, cfg, depth = 0,  w = None):
        """"""
        Cell.__init__(self, bounds, graph, uid,  depth = depth, w = w, cfg = cfg)

        self.predictions = []

        self.pe_history    = []    # PE : Prediction Error
        self.pei_history   = [0.0] # PEI: PE Improvement
        self.estimator_pei = SpanSeigelEstimator(cfg.cell.max_pei)

    def add(self, effect, prediction = None, pred_error = None):

        if not self.belongs(effect):
            return False

        self.effects.append(effect)

        if prediction is not None or pred_error is not None:
            self.predictions.append(prediction)
            if pred_error is None:
                pred_error = cmpce.competence(prediction, effect, cfg = self.cfg)

            self.pe_history.append(pred_error)
            self.estimator_pei.add(pred_error)

            if len(self.pe_history) >= self.cfg.cell.min_pei:
                self.pei_history.append(self.estimator_pei.value())
            else:
                self.pei_history.append(0.0)

        return True

    def split(self, low_bounds, high_bounds):
        return self.graph.effect_split(self, low_bounds, high_bounds)

    @property
    def pe(self):
        return self.pe_history[-1]

    @property
    def pei(self):
        return self.pei_history[-1]

    @property
    def pei_all(self):
        if len(self.pe_history) < 2:
            return 0.0
        estimator = SpanSeigelEstimator(len(self.pe_history))
        for pe in self.pe_history:
            if pe is not None:
                estimator.add(pe)
        return estimator.value()

    def avg_pred_error(self, span = None):
        if len(self.pe_history) == 0:
            return None
        if span is not None and span > 0:
            return sum(self.pe_history[:-span])/span
        else:
            return sum(self.pe_history)/len(self.pe_history)

    def __len__(self):
        return len(self.effects)