def calcNodeDriftVector(self): """ calculates the drift vector of a node. """ self.weightEstimate = 1.0 self.ratioW = self.weightEstimate/self.weight # compute statistics delta vector. # delta = (weight*localStatistics - weightEstimate*localEstimate - # (weight - weightEstimate)*globalEstimate) / weight self.cm.delta = VectorOps.multAndAdd(self.cm.localStatistics, \ self.weight, self.localEstimate) VectorOps.multAndAddTo(self.cm.delta, self.ratioW-self.weight,\ self.cm.globalV) # update drift vector VectorOps.cpy(self.cm.drift, self.cm.globalV) VectorOps.addTo(self.cm.drift, self.cm.delta) VectorOps.multAndAddTo(self.cm.drift, 1.0/self.weight, self.cm.slack)
def testAddTo(self): """ tests the addTo(self, a, b) method and prints the result. Final results should be [2,2,2,2,2]. """ self.true_result = [2, 2, 2, 2, 2] self.test_result = VectorOps.addTo(self.target, self.operand) self.assertEqual(self.true_result, self.test_result)
def calcNodeDriftVector(self): """ calculates the drift vector of a node. """ self.weightEstimate = 1.0 self.ratioW = self.weightEstimate / self.weight # compute statistics delta vector. # delta = (weight*localStatistics - weightEstimate*localEstimate - # (weight - weightEstimate)*globalEstimate) / weight self.cm.delta = VectorOps.multAndAdd(self.cm.localStatistics, \ self.weight, self.localEstimate) VectorOps.multAndAddTo(self.cm.delta, self.ratioW-self.weight,\ self.cm.globalV) # update drift vector VectorOps.cpy(self.cm.drift, self.cm.globalV) VectorOps.addTo(self.cm.drift, self.cm.delta) VectorOps.multAndAddTo(self.cm.drift, 1.0 / self.weight, self.cm.slack)
def calcDriftVector(self): """ calculates drift vector. Drift vector is the following vector: u(t) = e(t) + Δv(t), where Δv(t) = v(t) - v'(t) """ # calculate Δv(t) self.dv = VectorOps.subFrom(self.cm.localStatistics, \ self.cm.lastStatistics) # calculate drift vector self.cm.drift = VectorOps.addTo(self.cm.estimate,\ self.dv)
def calc_drift(self): """ calculates drift vector. Drift vector is computed as follows: u(t) = e(t) + delta-v(t), where delta-v(t) = v(t) = v'(t) """ # calculate delta-v self.dv = VectorOps.subFrom(self.cm.localStatistics,\ self.cm.lastStatistics) # calculate drift vector self.cm.drift = VectorOps.addTo(self.cm.estimate, self.dv) # now check if ball is monochromatic if not self.check_ball(self.cm.localStatistics): # if it is not, then send a REP-message to coordinator # (the algorithm here is exactly the same as in REQ_receipt()) self.REQ_receipt()
def calc_drift(self): """ calculates drift vector. Drift vector is computed as follows: u(t) = e(t) + delta-v(t), where delta-v(t) = v(t) = v'(t) """ # calculate delta-v self.dv = VectorOps.subFrom(self.cm.localStatistics,\ self.cm.lastStatistics) # calculate drift vector self.cm.drift = VectorOps.addTo(self.cm.estimate, self.dv) # now check if ball is monochromatic if not self.check_ball(self.cm.localStatistics): # if it is not, then initiate a balancing process, self.coord_elem = self.createBalancingElement(self.node_name,\ self.cm.localStatistics, self.cm.drift, self.weight) # initiating the balancing group with this very element self.bp.addToBalancing(self.coord_elem)
def recalcEstimateVector(self): """ calculates the estimate vector. """ # init sum of weights in the minimum permitted value # (so as to avoid division with zero) self.sumw = 0.000000000001 # for every single node for node in self.all_vectors: # get the weight and the last statistic vector self.w = float(self.all_vectors[node][0]) self.v = self.all_vectors[node][1] # compute the denominator self.sumw += self.w # and compute the numerator self.cm.estimate = VectorOps.addTo(self.cm.estimate, VectorOps.mult(self.v, self.w)) # calculate the final estimate vector self.cm.estimate = VectorOps.multBy\ (self.cm.estimate, 1.0/self.sumw)
def ADJ_SLK_receipt(self, message): """ Upon receipt of an ADJ_SLK message, add the value specified in the message to the value of the slack vector (δ <- δ + Δδ). """ self.cm.slack = VectorOps.addTo(self.cm.slack, message.content)
def ADJ_SLK_receipt(self, message): """ Upon receipt of an ADJ_SLK message, add the value specified in the message to the value of the slack vector (δ <- δ + Δδ). """ self.cm.slack = VectorOps.addTo(self.cm.slack, message.content) self.set_state('SAFE')