Exemple #1
0
    def partialsumV(self, actv, acth, row):
        """
         sums out hidden variables for given v
          exp( log(exp(bh + actv*W)+1).sum(axis=0) + (v*bv).sum(axis=0) )
        """
        # acth = bv + actv*W
        cp.prod(acth, self.weight, actv, "t", "n")
        cp.matrix_plus_col(acth, self.bh)

        # acth = log(exp(acth)+1)
        cp.apply_scalar_functor(acth, cp.scalar_functor.RECT, 1.0)

        # row = actv.sum(axis=0)
        cp.reduce_to_row(row, acth, cp.reduce_functor.ADD)

        # row += h*bh
        cp.matrix_times_col(actv, self.bv)
        cp.reduce_to_row(row, actv, cp.reduce_functor.ADD, 1.0, 1.0)

        # exp(row)
        m = row.np.astype("float64")

        return math.fsum(m.flatten()) / actv.shape[1]
Exemple #2
0
    def partialsumV(self, actv, acth, row):
        """
         sums out hidden variables for given v
          exp( log(exp(bh + actv*W)+1).sum(axis=0) + (v*bv).sum(axis=0) )
        """
        # acth = bv + actv*W
        cp.prod(acth, self.weight, actv, 't', 'n')
        cp.matrix_plus_col(acth, self.bh)

        # acth = log(exp(acth)+1)
        cp.apply_scalar_functor(acth, cp.scalar_functor.RECT, 1.0)

        # row = actv.sum(axis=0)
        cp.reduce_to_row(row, acth, cp.reduce_functor.ADD)

        # row += h*bh
        cp.matrix_times_col(actv, self.bv)
        cp.reduce_to_row(row, actv, cp.reduce_functor.ADD, 1.0, 1.0)

        # exp(row)
        m = row.np.astype("float64")

        return math.fsum(m.flatten()) / actv.shape[1]
Exemple #3
0
    def partialsum(self, acth, actv, row):
        """
        sums out visible variables for given hidden variables
          exp( log(exp(bv + acth*W)+1).sum(axis=0) + (h*bh).sum(axis=0) )
        """
        # actv = bv + acth*W
        cp.prod(actv, self.weight, acth, "n", "n")
        cp.matrix_plus_col(actv, self.bv)

        # actv = log(exp(actv)+1)
        cp.apply_scalar_functor(actv, cp.scalar_functor.RECT, 1.0)

        # row = actv.sum(axis=0)
        cp.reduce_to_row(row, actv, cp.reduce_functor.ADD)

        # row += h*bh
        cp.matrix_times_col(acth, self.bh)
        cp.reduce_to_row(row, acth, cp.reduce_functor.ADD, 1.0, 1.0)
        # cp.prod(row,self.bv,actv,'t','n',1.0,1.0)

        # exp(row)
        m = row.np.astype("float64")

        return math.fsum(np.exp(m).flatten())
Exemple #4
0
    def partialsum(self, acth, actv, row):
        """
        sums out visible variables for given hidden variables
          exp( log(exp(bv + acth*W)+1).sum(axis=0) + (h*bh).sum(axis=0) )
        """
        # actv = bv + acth*W
        cp.prod(actv, self.weight, acth, 'n', 'n')
        cp.matrix_plus_col(actv, self.bv)

        # actv = log(exp(actv)+1)
        cp.apply_scalar_functor(actv, cp.scalar_functor.RECT, 1.0)

        # row = actv.sum(axis=0)
        cp.reduce_to_row(row, actv, cp.reduce_functor.ADD)

        # row += h*bh
        cp.matrix_times_col(acth, self.bh)
        cp.reduce_to_row(row, acth, cp.reduce_functor.ADD, 1.0, 1.0)
        #cp.prod(row,self.bv,actv,'t','n',1.0,1.0)

        # exp(row)
        m = row.np.astype("float64")

        return math.fsum(np.exp(m).flatten())