def __init__(self, vals: np.matrix): self.shift_factor = np.array(vals.min(1)).astype(float) self.scale_factor = np.array(vals.max(1) - self.shift_factor).astype(float) self.scale_factor = self.scale_factor + (self.scale_factor == 0).astype(float) self.shift_factor = self.shift_factor.reshape( self.shift_factor.shape[0], 1) self.scale_factor = self.scale_factor.reshape( self.scale_factor.shape[0], 1) self.scale_factor = 1.0
def ahp(item_no: np.matrix, m: np.matrix, w: np.matrix): """ ABC analysis according to Analytical Hierarchy Process (AHP) Arguments: item_no {[type]} -- list of item numbers m {[type]} -- ranking criteria Returns: [type] -- a matrix of item ranked and classified according to AHP """ fmin, fmax = m.min(0), m.max(0) norm = lambda i, v : (v-fmin[0,i])/(fmax[0,i]-fmin[0,i]) ahp = [[item_no[k,0],sum(w[i]*norm(i, m[k,i]) for i in range(0,4))] for k in range(0,len(m))] ahp = sorted(ahp,key=lambda x: x[1], reverse=True) # annotate ABC ABC.annotate_ABC(ahp) return ahp
def bounding_box(points: np.matrix): """Return a, b so that all points lay in bounding box spanned by a and b.""" return points.min(axis=0), points.max(axis=0)