def __call__(self, state, scope, pos, paramTypes, similarity, x, y, p, missingWeight=None): length = len(x) if missingWeight is None: missingWeight = [1.0] * length if len(y) != length or len(missingWeight) != length: raise PFARuntimeException("dimensions of vectors do not match", self.errcodeBase + 0, self.name, pos) if math.isnan(p) or p <= 0: raise PFARuntimeException("Minkowski parameter p must be positive", self.errcodeBase + 1, self.name, pos) tally = 0.0 numer = 0.0 denom = 0.0 if math.isinf(p): for i in xrange(length): xi = x[i] yi = y[i] if xi is not None and yi is not None: if isinstance(paramTypes[1]["items"], (tuple, list)): xi, = xi.values() if isinstance(paramTypes[2]["items"], (tuple, list)): yi, = yi.values() z = callfcn(state, scope, similarity, [xi, yi]) if z > tally: tally = z denom += missingWeight[i] numer += missingWeight[i] if denom == 0.0: return float("nan") else: return tally * numer / denom else: for i in xrange(length): xi = x[i] yi = y[i] if xi is not None and yi is not None: if isinstance(paramTypes[1]["items"], (tuple, list)): xi, = xi.values() if isinstance(paramTypes[2]["items"], (tuple, list)): yi, = yi.values() tally += powLikeJava( callfcn(state, scope, similarity, [xi, yi]), p) denom += missingWeight[i] numer += missingWeight[i] if denom == 0.0: return float("nan") else: return powLikeJava(tally * numer / denom, 1.0 / p)
def __call__(self, state, scope, pos, paramTypes, similarity, x, y, p, missingWeight=None): length = len(x) if missingWeight is None: missingWeight = [1.0] * length if len(y) != length or len(missingWeight) != length: raise PFARuntimeException("dimensions of vectors do not match", self.errcodeBase + 0, self.name, pos) if math.isnan(p) or p <= 0: raise PFARuntimeException("Minkowski parameter p must be positive", self.errcodeBase + 1, self.name, pos) tally = 0.0 numer = 0.0 denom = 0.0 if math.isinf(p): for i in xrange(length): xi = x[i] yi = y[i] if xi is not None and yi is not None: if isinstance(paramTypes[1]["items"], (tuple, list)): xi, = xi.values() if isinstance(paramTypes[2]["items"], (tuple, list)): yi, = yi.values() z = callfcn(state, scope, similarity, [xi, yi]) if z > tally: tally = z denom += missingWeight[i] numer += missingWeight[i] if denom == 0.0: return float("nan") else: return tally * numer / denom else: for i in xrange(length): xi = x[i] yi = y[i] if xi is not None and yi is not None: if isinstance(paramTypes[1]["items"], (tuple, list)): xi, = xi.values() if isinstance(paramTypes[2]["items"], (tuple, list)): yi, = yi.values() tally += powLikeJava(callfcn(state, scope, similarity, [xi, yi]), p) denom += missingWeight[i] numer += missingWeight[i] if denom == 0.0: return float("nan") else: return powLikeJava(tally * numer / denom, 1.0/p)
def __call__(self, state, scope, pos, paramTypes, x, y, gamma, intercept, degree): return powLikeJava(gamma*dot(x, y, self.errcodeBase + 0, self.name, pos) + intercept, degree)
def __call__(self, state, scope, pos, paramTypes, x, y, gamma, intercept, degree): return powLikeJava(gamma * dot(x, y, self.errcodeBase + 0, self.name, pos) + intercept, degree)