def build_objective(model, deterministic=False, epsilon=1e-12):
predictions = nn.layers.get_output(model.l_out, deterministic=deterministic)
targets = T.cast(nn.layers.get_output(model.l_target), 'int32')
enable_targets = nn.layers.get_output(model.l_enable_target)
predictions = T.clip(predictions, epsilon, 1.-epsilon)
sum_of_objectives = 0
unit_ptr = 0
for obj_idx, obj_name in enumerate(order_objectives):
n_classes = len(property_bin_borders[obj_name])
v_obj = objective(obj_idx, (unit_ptr, unit_ptr+n_classes), predictions, targets)
# take the mean of the objectives where it matters (enabled targets)
obj_scalar = T.sum(enable_targets[:,obj_idx] * v_obj) / (0.00001 + T.sum(enable_targets[:,obj_idx]))
if deterministic:
d_objectives_deterministic[obj_name] = obj_scalar
else:
d_objectives[obj_name] = obj_scalar
sum_of_objectives += obj_scalar
unit_ptr = unit_ptr+n_classes
return sum_of_objectives
评论列表
文章目录