本文整理汇总了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
开发者ID:bwengals,项目名称:hadrian,代码行数:34,代码来源:cluster.py
示例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)
开发者ID:ajutzeler,项目名称:hadrian,代码行数:12,代码来源:la.py
示例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
开发者ID:bwengals,项目名称:hadrian,代码行数:7,代码来源:array.py
示例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)
开发者ID:verdimrc,项目名称:hadrian,代码行数:7,代码来源:map.py
示例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
开发者ID:ajutzeler,项目名称:hadrian,代码行数:28,代码来源:neighbor.py
示例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"]
开发者ID:bwengals,项目名称:hadrian,代码行数:35,代码来源:interp.py
示例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
开发者ID:bwengals,项目名称:hadrian,代码行数:7,代码来源:map.py
示例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
开发者ID:nkhuyu,项目名称:hadrian,代码行数:8,代码来源:array.py
示例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)
开发者ID:ajutzeler,项目名称:hadrian,代码行数:45,代码来源:metric.py
示例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)
开发者ID:ajutzeler,项目名称:hadrian,代码行数:9,代码来源:tree.py
示例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
开发者ID:nkhuyu,项目名称:hadrian,代码行数:21,代码来源:svm.py
示例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]
开发者ID:bwengals,项目名称:hadrian,代码行数:12,代码来源:sample.py
示例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
开发者ID:codeaudit,项目名称:hadrian,代码行数:16,代码来源:tree.py
注:本文中的titus.util.callfcn函数示例由纯净天空整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。 |
请发表评论