def gradient_it(m, eps): cnt = 0 (A, B) = ut.split_at(m) x0 = [0] * len(B) r0 = ut.minus(B, ut.subst(A, x0)) p0 = r0 z0 = r0 s0 = r0 for i in range(0, 2 * len(B)): sub = ut.subst(A, z0) prev_p = p0 prev_r = r0 At = ut.transpose_matrix(A) # print(At) a = ut.scalar_product(p0, r0) / ut.scalar_product(s0, sub) x0 = ut.plus(x0, ut.mul(a, z0)) r0 = ut.minus(r0, ut.mul(a, sub)) p0 = ut.minus(p0, ut.mul(a, ut.subst(At, s0))) b = ut.scalar_product(p0, r0) / ut.scalar_product(prev_p, prev_r) z0 = ut.plus(r0, ut.mul(b, z0)) s0 = ut.plus(p0, ut.mul(b, s0)) if abs(ut.norm(r0) / ut.norm(B)) < eps: break cnt += 1 return (x0, cnt)
def get_bit(self, port): if port.ibuffer: self.pipes[port] += port.ibuffer port.ibuffer = '' else: self.pipes[port] += self.noise_bit() bit, self.pipes[port] = utils.split_at(self.pipes[port], 1) return bit
def load_fc_weights_from_vgg16bn(model): "Load weights for model from the dense layers of the Vgg16BN model." # See imagenet_batchnorm.ipynb for info on how the weights for # Vgg16BN can be generated from the standard Vgg16 weights. from vgg16bn import Vgg16BN vgg16_bn = Vgg16BN() _, fc_layers = utils.split_at(vgg16_bn.model, Convolution2D) utils.copy_weights(fc_layers, model.layers)
def jacobi(m, eps): (A, f) = split_at(m) (B, c) = to_iter(A, f) prev = c x = plus(subst(B, prev), c) cnt = 1 n = norma(B) if (n >= 1): print("norma > 1, Jacobi error") return ([[]], 0) e1 = (1 - n) / n * eps while (myNorm(minus(x, prev)) > e1): cnt += 1 prev = x x = plus(subst(B, prev), c) return (x, cnt)
def handoff(self): if not self.peer: return sent, self.obuffer = utils.split_at(self.obuffer, min(self.rate, self.peer.rate)) self.peer.ibuffer += sent
def get(self, nbits=None): if not nbits: nbits = len(self.ibuffer) ret, self.ibuffer = utils.split_at(self.ibuffer, nbits) return ret
f = open(path, 'r') m = [] for line in f: m.append([float(x) for x in line.split()]) return m eps = 0.00001 # m = read_matrix("./tests/test4.in") m = utils.gilbert_test(10) m_g = copy.deepcopy(m) m_j = copy.deepcopy(m) m_gr = copy.deepcopy(m) m_test = copy.deepcopy(m) (clean_m, ldsfj) = utils.split_at(m) print("".join([ "Rank matrix ", str(task6.matrix_rate(clean_m)), ", condition_number ", str(task6.condition_number(clean_m)) ])) gauss_res = task1.gauss(m_g) print("".join(["Gauss Result==", str(gauss_res)])) # print(m_g) # print(m_j)split_at (jacob_res, j_it) = task2.jacobi(m_j, eps) print("".join([ "Jacobi Result==", str(jacob_res), " with eps==",