示例#1
0
class GradientRBM(Workflow):
    """This unit produces update weights using minibatch according to the
    algorithm described in
    http://deeplearning.net/tutorial/rbm.html (25.11.14).
    Does Gibbs sampling
    cd_k: number of iterations of Gibbs sampling
    """
    def __init__(self, workflow, **kwargs):
        super(GradientRBM, self).__init__(workflow, **kwargs)
        self.stddev = kwargs["stddev"]
        self.batch_size = -1
        self.mem_cpy = MemCpy(self)
        self.mem_cpy.link_from(self.start_point)
        self.repeater = Repeater(self)
        self.repeater.link_from(self.mem_cpy)
        self.decision = IterationCounter(self, max_iterations=kwargs["cd_k"])
        self.decision.link_from(self.repeater)
        self.bino_h = BinarizationGradH(self,
                                        rand=kwargs.get("rand_h", prng.get()))
        self.bino_h.link_attrs(self.mem_cpy, ("input", "output"))
        self.bino_h.link_from(self.decision)
        self.bino_h.gate_block = self.decision.complete
        self.make_v = All2AllSigmoidV(self,
                                      weights_stddev=self.stddev,
                                      weights_transposed=True,
                                      output_sample_shape=kwargs["v_size"])
        self.make_v.link_from(self.bino_h)
        self.make_v.link_attrs(self.bino_h, ("input", "output"))
        self.bino_v = BinarizationGradV(self,
                                        rand=kwargs.get("rand_v", prng.get()))

        self.bino_v.link_attrs(self.make_v, ("input", "output"))
        self.bino_v.link_from(self.make_v)
        self.make_h = All2AllSigmoidH(self,
                                      weights_stddev=self.stddev,
                                      output_sample_shape=kwargs["h_size"])
        self.make_h.link_attrs(self.bino_v, ("input", "output"))
        self.make_h.output = self.mem_cpy.output
        self.make_h.link_from(self.bino_v)

        self.repeater.link_from(self.make_h)
        self.end_point.link_from(self.decision)
        self.end_point.gate_block = ~self.decision.complete
        self.bino_h.gate_block = self.decision.complete

        self.mem_cpy.link_attrs(self, "input")
        self.bino_h.link_attrs(self, "batch_size")
        self.bino_v.link_attrs(self, "batch_size")
        self.make_v.link_attrs(self, "weights")
        self.make_v.link_attrs(self, ("bias", "vbias"))
        self.make_h.link_attrs(self, "weights")
        self.make_h.link_attrs(self, ("bias", "hbias"))
        self.link_attrs(self.make_h, "output")
        self.link_attrs(self.bino_v, ("v1", "output"))
        self.link_attrs(self.make_h, ("h1", "output"))
        self.demand("input", "weights", "hbias", "vbias", "batch_size")

    def run(self):
        self.decision.reset()
        super(GradientRBM, self).run()
示例#2
0
class GradientRBM(Workflow):
    """This unit produces update weights using minibatch according to the
    algorithm described in
    http://deeplearning.net/tutorial/rbm.html (25.11.14).
    Does Gibbs sampling
    cd_k: number of iterations of Gibbs sampling
    """
    def __init__(self, workflow, **kwargs):
        super(GradientRBM, self).__init__(workflow, **kwargs)
        self.stddev = kwargs["stddev"]
        self.batch_size = -1
        self.mem_cpy = MemCpy(self)
        self.mem_cpy.link_from(self.start_point)
        self.repeater = Repeater(self)
        self.repeater.link_from(self.mem_cpy)
        self.decision = IterationCounter(
            self, max_iterations=kwargs["cd_k"])
        self.decision.link_from(self.repeater)
        self.bino_h = BinarizationGradH(
            self, rand=kwargs.get("rand_h", prng.get()))
        self.bino_h.link_attrs(self.mem_cpy, ("input", "output"))
        self.bino_h.link_from(self.decision)
        self.bino_h.gate_block = self.decision.complete
        self.make_v = All2AllSigmoidV(
            self, weights_stddev=self.stddev, weights_transposed=True,
            output_sample_shape=kwargs["v_size"])
        self.make_v.link_from(self.bino_h)
        self.make_v.link_attrs(self.bino_h, ("input", "output"))
        self.bino_v = BinarizationGradV(
            self, rand=kwargs.get("rand_v", prng.get()))

        self.bino_v.link_attrs(self.make_v, ("input", "output"))
        self.bino_v.link_from(self.make_v)
        self.make_h = All2AllSigmoidH(
            self, weights_stddev=self.stddev,
            output_sample_shape=kwargs["h_size"])
        self.make_h.link_attrs(self.bino_v, ("input", "output"))
        self.make_h.output = self.mem_cpy.output
        self.make_h.link_from(self.bino_v)

        self.repeater.link_from(self.make_h)
        self.end_point.link_from(self.decision)
        self.end_point.gate_block = ~self.decision.complete
        self.bino_h.gate_block = self.decision.complete

        self.mem_cpy.link_attrs(self, "input")
        self.bino_h.link_attrs(self, "batch_size")
        self.bino_v.link_attrs(self, "batch_size")
        self.make_v.link_attrs(self, "weights")
        self.make_v.link_attrs(self, ("bias", "vbias"))
        self.make_h.link_attrs(self, "weights")
        self.make_h.link_attrs(self, ("bias", "hbias"))
        self.link_attrs(self.make_h, "output")
        self.link_attrs(self.bino_v, ("v1", "output"))
        self.link_attrs(self.make_h, ("h1", "output"))
        self.demand("input", "weights", "hbias", "vbias", "batch_size")

    def run(self):
        self.decision.reset()
        super(GradientRBM, self).run()
示例#3
0
    def __init__(self, workflow, **kwargs):
        super(GradientRBM, self).__init__(workflow, **kwargs)
        self.stddev = kwargs["stddev"]
        self.batch_size = -1
        self.mem_cpy = MemCpy(self)
        self.mem_cpy.link_from(self.start_point)
        self.repeater = Repeater(self)
        self.repeater.link_from(self.mem_cpy)
        self.decision = IterationCounter(self, max_iterations=kwargs["cd_k"])
        self.decision.link_from(self.repeater)
        self.bino_h = BinarizationGradH(self,
                                        rand=kwargs.get("rand_h", prng.get()))
        self.bino_h.link_attrs(self.mem_cpy, ("input", "output"))
        self.bino_h.link_from(self.decision)
        self.bino_h.gate_block = self.decision.complete
        self.make_v = All2AllSigmoidV(self,
                                      weights_stddev=self.stddev,
                                      weights_transposed=True,
                                      output_sample_shape=kwargs["v_size"])
        self.make_v.link_from(self.bino_h)
        self.make_v.link_attrs(self.bino_h, ("input", "output"))
        self.bino_v = BinarizationGradV(self,
                                        rand=kwargs.get("rand_v", prng.get()))

        self.bino_v.link_attrs(self.make_v, ("input", "output"))
        self.bino_v.link_from(self.make_v)
        self.make_h = All2AllSigmoidH(self,
                                      weights_stddev=self.stddev,
                                      output_sample_shape=kwargs["h_size"])
        self.make_h.link_attrs(self.bino_v, ("input", "output"))
        self.make_h.output = self.mem_cpy.output
        self.make_h.link_from(self.bino_v)

        self.repeater.link_from(self.make_h)
        self.end_point.link_from(self.decision)
        self.end_point.gate_block = ~self.decision.complete
        self.bino_h.gate_block = self.decision.complete

        self.mem_cpy.link_attrs(self, "input")
        self.bino_h.link_attrs(self, "batch_size")
        self.bino_v.link_attrs(self, "batch_size")
        self.make_v.link_attrs(self, "weights")
        self.make_v.link_attrs(self, ("bias", "vbias"))
        self.make_h.link_attrs(self, "weights")
        self.make_h.link_attrs(self, ("bias", "hbias"))
        self.link_attrs(self.make_h, "output")
        self.link_attrs(self.bino_v, ("v1", "output"))
        self.link_attrs(self.make_h, ("h1", "output"))
        self.demand("input", "weights", "hbias", "vbias", "batch_size")
示例#4
0
 def __init__(self, workflow, **kwargs):
     super(NNWorkflow, self).__init__(workflow, **kwargs)
     self._repeater = Repeater(self)
     self._loader = None
     self._forwards = []
     self._evaluator = None
     self._decision = None
     self._gds = []
示例#5
0
    def __init__(self, workflow, **kwargs):
        super(GradientRBM, self).__init__(workflow, **kwargs)
        self.stddev = kwargs["stddev"]
        self.batch_size = -1
        self.mem_cpy = MemCpy(self)
        self.mem_cpy.link_from(self.start_point)
        self.repeater = Repeater(self)
        self.repeater.link_from(self.mem_cpy)
        self.decision = IterationCounter(
            self, max_iterations=kwargs["cd_k"])
        self.decision.link_from(self.repeater)
        self.bino_h = BinarizationGradH(
            self, rand=kwargs.get("rand_h", prng.get()))
        self.bino_h.link_attrs(self.mem_cpy, ("input", "output"))
        self.bino_h.link_from(self.decision)
        self.bino_h.gate_block = self.decision.complete
        self.make_v = All2AllSigmoidV(
            self, weights_stddev=self.stddev, weights_transposed=True,
            output_sample_shape=kwargs["v_size"])
        self.make_v.link_from(self.bino_h)
        self.make_v.link_attrs(self.bino_h, ("input", "output"))
        self.bino_v = BinarizationGradV(
            self, rand=kwargs.get("rand_v", prng.get()))

        self.bino_v.link_attrs(self.make_v, ("input", "output"))
        self.bino_v.link_from(self.make_v)
        self.make_h = All2AllSigmoidH(
            self, weights_stddev=self.stddev,
            output_sample_shape=kwargs["h_size"])
        self.make_h.link_attrs(self.bino_v, ("input", "output"))
        self.make_h.output = self.mem_cpy.output
        self.make_h.link_from(self.bino_v)

        self.repeater.link_from(self.make_h)
        self.end_point.link_from(self.decision)
        self.end_point.gate_block = ~self.decision.complete
        self.bino_h.gate_block = self.decision.complete

        self.mem_cpy.link_attrs(self, "input")
        self.bino_h.link_attrs(self, "batch_size")
        self.bino_v.link_attrs(self, "batch_size")
        self.make_v.link_attrs(self, "weights")
        self.make_v.link_attrs(self, ("bias", "vbias"))
        self.make_h.link_attrs(self, "weights")
        self.make_h.link_attrs(self, ("bias", "hbias"))
        self.link_attrs(self.make_h, "output")
        self.link_attrs(self.bino_v, ("v1", "output"))
        self.link_attrs(self.make_h, ("h1", "output"))
        self.demand("input", "weights", "hbias", "vbias", "batch_size")