예제 #1
0
    def __init__(self, workloads):
        # q or r = - (-q and -r)
        # W = 1 x 1 - (Q1 x R1)

        self.A = Kronecker([Ones(*W.shape) for W in workloads])  # totals
        self.B = -1 * Kronecker([Ones(*W.shape) - W
                                 for W in workloads])  # negations
        Sum.__init__(self, [self.A, self.B])
예제 #2
0
def sum_kron_canonical(WtW):
    if isinstance(WtW, Kronecker):
        return Sum([1.0 * WtW])
    elif isinstance(WtW, Weighted) and isinstance(WtW.base, Kronecker):
        return Sum([WtW])
    elif isinstance(WtW, Sum):
        return Sum([1.0 * X for X in WtW.matrices])
    elif isinstance(WtW, Weighted) and isinstance(WtW.base, Sum):
        c = WtW.weight
        return Sum([c * X for X in WtW.base.matrices])
    else:
        raise ValueError('Input format not recognized')
예제 #3
0
    def __init__(self, domain, weights):
        self.domain = tuple(domain)
        self.weights = weights
        subs = []
        n, d = np.prod(domain), len(domain)
        mult = np.ones(2**d)
        for key, wgt in enumerate(weights):
            Q = Marginal(domain, key)
            mult[key] = n / Q.shape[0]
            if wgt != 0: subs.append(wgt * Q.gram())
        self._mult = mult

        Sum.__init__(self, subs)
예제 #4
0
 def gram(self):
     return Sum([
         self.A.gram(), self.A.T @ self.B, self.B.T @ self.A,
         self.B.gram()
     ])