<!-- Copyright 2018 The TensorFlow Constrained Optimization Authors. All Rights
Reserved.
Licensed under the Apache License, Version 2.0 (the "License"); you may not use
this file except in compliance with the License. You may obtain a copy of the
License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software distributed
under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR
CONDITIONS OF ANY KIND, either express or implied. See the License for the
specific language governing permissions and limitations under the License.
=============================================================================-->
# TensorFlow Constrained Optimization (TFCO)
TFCO is a library for optimizing inequality-constrained problems in TensorFlow.
In the most general case, both the objective function and the constraints are
represented as `Tensor`s, giving users the maximum amount of flexibility in
specifying their optimization problems. Constructing these `Tensor`s can be
cumbersome, so we also provide helper functions to make it easy to construct
constrained optimization problems based on *rates*, i.e. proportions of the
training data on which some event occurs (e.g. the error rate, true positive
rate, recall, etc).
For full details, motivation, and theoretical results on the approach taken by
this library, please refer to:
> Cotter, Jiang and Sridharan. "Two-Player Games for Efficient Non-Convex
> Constrained Optimization".
> [ALT'19](http://alt2019.algorithmiclearningtheory.org/).
> [https://arxiv.org/abs/1804.06500](https://arxiv.org/abs/1804.06500)
which will be referred to as [CoJiSr19] throughout the remainder of this
document, and:
> Cotter, Gupta, Jiang, Srebro, Sridharan, Wang, Woodworth and You. "Training
> Well-Generalizing Classifiers for Fairness Metrics and Other Data-Dependent
> Constraints".
> [https://arxiv.org/abs/1807.00028](https://arxiv.org/abs/1807.00028)
which will be referred to as [CotterEtAl18].
### Proxy constraints
Imagine that we want to constrain the recall of a binary classifier to be at
least 90%. Since the recall is proportional to the number of true positive
classifications, which itself is a sum of indicator functions, this constraint
is non-differentiable, and therefore cannot be used in a problem that will be
optimized using a (stochastic) gradient-based algorithm.
For this and similar problems, TFCO supports so-called *proxy constraints*,
which are differentiable (or sub/super-differentiable) approximations of the
original constraints. For example, one could create a proxy recall function by
replacing the indicator functions with sigmoids. During optimization, each proxy
constraint function will be penalized, with the magnitude of the penalty being
chosen to satisfy the corresponding *original* (non-proxy) constraint.
On a problem including proxy constraints—even a convex problem—the
Lagrangian approach discussed above isn't guaranteed to work. However, a
different algorithm, based on minimizing *swap regret* on a slightly *different*
formulation—which we call the "proxy-Lagrangian" formulation—does
work.
### Shrinking
This library is designed to deal with a very flexible class of constrained
problems, but this flexibility makes optimization considerably more difficult:
on a non-convex problem, if one uses the "standard" approach of introducing a
Lagrange multiplier for each constraint, and then jointly maximizing over the
Lagrange multipliers and minimizing over the model parameters, then a stable
stationary point might not even *exist*. Hence, in some cases, oscillation,
instead of convergence, is inevitable.
Thankfully, it turns out that even if, over the course of optimization, no
*particular* iterate does a good job of minimizing the objective while
satisfying the constraints, the *sequence* of iterates, on average, usually
will. This observation suggests the following approach: at training time, we'll
periodically snapshot the model state during optimization; then, at evaluation
time, each time we're given a new example to evaluate, we'll sample one of the
saved snapshots uniformly at random, and apply it to the example. This
*stochastic model* will generally perform well, both with respect to the
objective function, and the constraints.
In fact, we can do better: it's possible to post-process the set of snapshots to
find a distribution over at most **m+1** snapshots, where **m** is the number of
constraints, that will be at least as good (and will usually be much better)
than the (much larger) uniform distribution described above. If you're unable or
unwilling to use a stochastic model at all, then you can instead use a heuristic
to choose the single best snapshot.
In many cases, these issues can be ignored. However, if you experience issues
with oscillation during training, or if you want to squeeze every last drop of
performance out of your model, consider using the "shrinking" procedure of
[CoJiSr19], which is implemented in the "candidates.py" file.
## Public contents
* [constrained_minimization_problem.py](https://github.com/google-research/tensorflow_constrained_optimization/tree/master/tensorflow_constrained_optimization/python/constrained_minimization_problem.py):
contains the `ConstrainedMinimizationProblem` interface, representing an
inequality-constrained problem. Your own constrained optimization problems
should be represented using implementations of this interface. If using the
rate-based helpers, such objects can be constructed as
`RateMinimizationProblem`s.
* [candidates.py](https://github.com/google-research/tensorflow_constrained_optimization/tree/master/tensorflow_constrained_optimization/python/candidates.py):
contains two functions, `find_best_candidate_distribution` and
`find_best_candidate_index`. Both of these functions are given a set of
candidate solutions to a constrained optimization problem, from which the
former finds the best distribution over at most **m+1** candidates, and the
latter heuristically finds the single best candidate. As discussed above,
the set of candidates will typically be model snapshots saved periodically
during optimization. Both of these functions require that scipy be
installed.
The `find_best_candidate_distribution` function implements the approach
described in Lemma 3 of [CoJiSr19], while `find_best_candidate_index`
implements the heuristic used for hyperparameter search in the experiments
of Section 5.2.
* [Optimizing general inequality-constrained problems](https://github.com/google-research/tensorflow_constrained_optimization/tree/master/tensorflow_constrained_optimization/python/train/)
* [constrained_optimizer.py](https://github.com/google-research/tensorflow_constrained_optimization/tree/master/tensorflow_constrained_optimization/python/train/constrained_optimizer.py):
contains the `ConstrainedOptimizer` interface, which is similar to (but
different from) `tf.train.Optimizer`, with the main difference being
that `ConstrainedOptimizer`s are given `ConstrainedMinimizationProblem`s
to optimize, and perform constrained optimization.
* [lagrangian_optimizer.py](https://github.com/google-research/tensorflow_constrained_optimization/tree/master/tensorflow_constrained_optimization/python/train/lagrangian_optimizer.py):
contains the `LagrangianOptimizer` implementation, which is a
`ConstrainedOptimizer` implementing the Lagrangian approach discussed
above (with additive updates to the Lagrange multipliers). You should
use this optimizer for problems *without* proxy constraints. It may also
work for problems with proxy constraints, but we recommend using a
proxy-Lagrangian optimizer, instead.
This optimizer is most similar to Algorithm 3 in Appendix C.3 of
[CoJiSr1
没有合适的资源?快使用搜索试试~ 我知道了~
tensorflow_constrained_optimization-0.1.tar.gz
0 下载量 122 浏览量
2024-03-23
19:49:14
上传
评论
收藏 75KB GZ 举报
温馨提示
共40个文件
py:32个
txt:4个
pkg-info:2个
TensorFlow是一个开放源代码的软件库,用于进行高性能数值计算。通过其灵活的架构,它允许用户轻松地部署计算工作在各种平台(CPUs、GPUs、TPUs)上,无论是在桌面、服务器还是移动设备上。TensorFlow最初由Google Brain团队(属于Google的人工智能部门)开发,并在2015年被发布到Apache 2.0开源许可证下。 TensorFlow的主要特点包括它的高度灵活性、可扩展性和可移植性。它支持从小到大的各种计算,从手机应用到复杂的机器学习系统。TensorFlow提供了一个全面的、灵活的生态系统的库、工具和社区资源,使研究人员能够推动人工智能领域的最前沿,并使开发人员能够轻松构建和部署由机器学习驱动的应用。 TensorFlow的核心是使用数据流图来表示计算。在数据流图中,节点表示在数据上执行的操作,而图中的边表示在操作之间流动的数据。这种表示法允许TensorFlow有效地执行并行计算,并且可以在不同的硬件平台上高效运行。此外,TensorFlow支持自动微分,这对于实现复杂的机器学习算法(如深度学习网络)至关重要。
资源推荐
资源详情
资源评论
收起资源包目录
tensorflow_constrained_optimization-0.1.tar.gz (40个子文件)
tensorflow_constrained_optimization-0.1
tensorflow_constrained_optimization.egg-info
SOURCES.txt 2KB
top_level.txt 36B
PKG-INFO 2KB
requires.txt 78B
dependency_links.txt 1B
setup.py 4KB
PKG-INFO 2KB
tensorflow_constrained_optimization
__init__.py 3KB
python
__init__.py 878B
train
__init__.py 891B
lagrangian_optimizer.py 14KB
proxy_lagrangian_optimizer.py 28KB
proxy_lagrangian_optimizer_test.py 11KB
test_util.py 2KB
constrained_optimizer.py 10KB
lagrangian_optimizer_test.py 5KB
constrained_minimization_problem.py 5KB
candidates.py 13KB
rates
term_test.py 17KB
__init__.py 888B
basic_expression.py 13KB
loss.py 11KB
expression.py 13KB
binary_rates_test.py 23KB
helpers.py 8KB
rate_minimization_problem_test.py 8KB
expression_test.py 5KB
loss_test.py 5KB
helpers_test.py 4KB
operations_test.py 10KB
operations.py 7KB
basic_expression_test.py 9KB
rate_minimization_problem.py 11KB
term.py 42KB
subsettable_context.py 21KB
binary_rates.py 37KB
subsettable_context_test.py 7KB
candidates_test.py 5KB
setup.cfg 38B
README.md 28KB
共 40 条
- 1
资源评论
程序员Chino的日记
- 粉丝: 2701
- 资源: 3万+
上传资源 快速赚钱
- 我的内容管理 展开
- 我的资源 快来上传第一个资源
- 我的收益 登录查看自己的收益
- 我的积分 登录查看自己的积分
- 我的C币 登录后查看C币余额
- 我的收藏
- 我的下载
- 下载帮助
安全验证
文档复制为VIP权益,开通VIP直接复制
信息提交成功