本文整理汇总了Python中titus.util.callfcn函数的典型用法代码示例。如果您正苦于以下问题:Python callfcn函数的具体用法?Python callfcn怎么用?Python callfcn使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了callfcn函数的13个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: __call__
def __call__(self, state, scope, paramTypes, data, clusters, metric, update):
if len(data) == 0:
raise PFARuntimeException("no data")
centers = [x["center"] for x in clusters]
length = len(clusters)
if length == 0:
raise PFARuntimeException("no clusters")
matched = [[] for i in xrange(length)]
for datum in data:
besti = 0
bestCenter = None
bestDistance = 0.0
i = 0
while i < length:
thisCenter = centers[i]
thisDistance = callfcn(state, scope, metric, [datum, thisCenter])
if bestCenter is None or thisDistance < bestDistance:
besti = i
bestCenter = thisCenter
bestDistance = thisDistance
i += 1
matched[besti].append(datum)
out = []
for i, matchedData in enumerate(matched):
if len(matchedData) == 0:
out.append(clusters[i])
else:
out.append(callfcn(state, scope, update, [matchedData, clusters[i]]))
return out
示例2: __call__
def __call__(self, state, scope, pos, paramTypes, x, y, fcn):
if isinstance(x, (list, tuple)) and all(isinstance(xi, (list, tuple)) for xi in x) and \
isinstance(y, (list, tuple)) and all(isinstance(yi, (list, tuple)) for yi in y):
if len(x) != len(y) or any(len(xi) != len(yi) for xi, yi in zip(x, y)):
raise PFARuntimeException("misaligned matrices", self.errcodeBase + 0, self.name, pos)
return [[callfcn(state, scope, fcn, [xj, yj]) for xj, yj in zip(xi, yi)] for xi, yi in zip(x, y)]
elif isinstance(x, dict) and all(isinstance(x[i], dict) for i in x.keys()) and \
isinstance(y, dict) and all(isinstance(y[i], dict) for i in y.keys()):
rows = rowKeys(x).union(rowKeys(y))
cols = colKeys(x).union(colKeys(y))
return dict((i, dict((j, callfcn(state, scope, fcn, [x.get(i, {}).get(j, 0.0), y.get(i, {}).get(j, 0.0)])) for j in cols)) for i in rows)
示例3: __call__
def __call__(self, state, scope, paramTypes, a, fcn):
out = []
for x in a:
y = callfcn(state, scope, fcn, [x])
if y is not None:
out.append(y)
return out
示例4: __call__
def __call__(self, state, scope, pos, paramTypes, a, b, fcn):
aset = set(a.keys())
bset = set(b.keys())
if aset != bset:
return False
else:
return all(callfcn(state, scope, fcn, [k, a[k], b[k]]) for k in aset)
示例5: __call__
def __call__(self, state, scope, pos, paramTypes, points, *args):
if len(args) == 1:
weight, = args
else:
weight = None
if len(points) == 0:
raise PFARuntimeException("not enough points", self.errcodeBase + 0, self.name, pos)
dimensions = len(points[0])
numer = [0.0] * dimensions
denom = [0.0] * dimensions
for point in points:
if len(point) != dimensions:
raise PFARuntimeException("inconsistent dimensionality", self.errcodeBase + 1, self.name, pos)
if weight is None:
w = 1.0
else:
w = callfcn(state, scope, weight, [point])
for i in xrange(dimensions):
numer[i] += w * point[i]
denom[i] += w
for i in xrange(dimensions):
numer[i] /= denom[i]
return numer
示例6: __call__
def __call__(self, state, scope, paramTypes, datum, table, *metric):
if len(metric) == 1:
metric, = metric
# do signature 3
one = None
oned = None
for item in table:
d = callfcn(state, scope, metric, [datum, item["x"]])
if one is None or d < oned:
one = item
oned = d
return one["to"]
elif isinstance(paramTypes[0], dict) and paramTypes[0].get("type") == "array":
# do signature 2
one = None
oned = None
for item in table:
x = item["x"]
if len(x) != len(datum):
raise PFARuntimeException("inconsistent dimensionality")
d = sum((x0i - xi)**2 for x0i, xi in zip(datum, x))
if one is None or d < oned:
one = item
oned = d
return one["to"]
else:
# do signature 1
one = None
oned = None
for item in table:
d = abs(datum - item["x"])
if one is None or d < oned:
one = item
oned = d
return one["to"]
示例7: __call__
def __call__(self, state, scope, paramTypes, m, fcn):
out = {}
for k, v in m.items():
vv = callfcn(state, scope, fcn, [k, v])
if vv is not None:
out[k] = vv
return out
示例8: __call__
def __call__(self, state, scope, pos, paramTypes, a, fcn):
out = {}
for x in a:
key = callfcn(state, scope, fcn, [x])
if key not in out:
out[key] = []
out[key].append(x)
return out
示例9: __call__
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)
示例10: __call__
def __call__(self, state, scope, pos, paramTypes, datum, comparisons, missingTest):
for comparison in comparisons:
result = callfcn(state, scope, missingTest, [datum, comparison])
if result is not None:
if isinstance(result, dict) and result.keys() == ["boolean"]:
return result.values()[0]
else:
return result
raise PFARuntimeException("no successful surrogate", self.errcodeBase + 0, self.name, pos)
示例11: __call__
def __call__(self, state, scope, pos, paramTypes, datum, model, kernel):
const = model["const"]
negClass = model["negClass"]
posClass = model["posClass"]
if len(negClass) == 0 and len(posClass) == 0:
raise PFARuntimeException("no support vectors", self.errcodeBase + 0, self.name, pos)
negClassScore = 0.0
for sv in negClass:
supVec = sv["supVec"]
if len(supVec) != len(datum):
raise PFARuntimeException("support vectors must have same length as datum", self.errcodeBase + 1, self.name, pos)
coeff = sv["coeff"]
negClassScore += callfcn(state, scope, kernel, [supVec, datum])*coeff
posClassScore = 0.0
for sv in posClass:
supVec = sv["supVec"]
if len(supVec) != len(datum):
raise PFARuntimeException("support vectors must have same length as datum", self.errcodeBase + 1, self.name, pos)
coeff = sv["coeff"]
posClassScore += callfcn(state, scope, kernel, [supVec, datum])*coeff
return negClassScore + posClassScore + const
示例12: __call__
def __call__(self, state, scope, paramTypes, x, top, n, lessThan):
index = 0
for best in top:
if callfcn(state, scope, lessThan, [best, x]):
break
index += 1
if index == len(top):
out = top + [x]
else:
above, below = top[:index], top[index:]
out = above + [x] + below
return out[:n]
示例13: __call__
def __call__(self, state, scope, paramTypes, datum, treeNode, test):
treeNodeTypeName = paramTypes[1]["name"]
node = treeNode
while True:
if callfcn(state, scope, test, [datum, node]):
union = node["pass"]
else:
union = node["fail"]
if union is None:
node = None
break
else:
(utype, node), = union.items()
if utype != treeNodeTypeName:
break
return node