tf.nn.isotonic_regression
bookmark_borderbookmark
Stay organized with collections
Save and categorize content based on your preferences.
Solves isotonic regression problems along the given axis.
tf.nn.isotonic_regression(
inputs, decreasing=True, axis=-1
)
For each vector x, the problem solved is
\argminy1>=y2>=...>=yn∑i(xi−yi)2.
As the solution is component-wise constant, a second tensor is returned that
encodes the segments. The problems are solved over the given axis.
Consider the following example, where we solve a batch of two problems. The
first input is [3, 1, 2], while the second 1, 3, 4.
>>> x = tf.constant([[3, 1, 2], [1, 3, 4]], dtype=tf.float32)
>>> y, segments = tf.nn.isotonic_regression(x, axis=1)
>>> y # The solution.
<tf.Tensor: shape=(2, 3), dtype=float32, numpy=
array([[3. , 1.5 , 1.5 ],
[2.6666667, 2.6666667, 2.6666667]], dtype=float32)>
Note that the first solution has two blocks [2] and [1.5, 1.5]. The second
solution is constant, and thus has a single segment. These segments are
exactly what the second returned tensor encodes:
segments
<tf.Tensor: shape=(2, 3), dtype=int32, numpy=
array([[0, 1, 1],
[0, 0, 0]], dtype=int32)>
Args |
inputs
|
A tensor holding the inputs.
|
decreasing
|
If set to False, the inequalities in the optimizing constrained
are flipped.
|
axis
|
The axis along which the problems should be solved.
|
Returns |
output
|
The solutions, same shape as type as the input.
|
segments
|
An int32 tensor, same shape as the input indicating the segments
that have the same value. Specifically, those positions that have the same
value correspond to the same segment. These values start at zero, and are
monotonously increasing for each solution.
|
Except as otherwise noted, the content of this page is licensed under the Creative Commons Attribution 4.0 License, and code samples are licensed under the Apache 2.0 License. For details, see the Google Developers Site Policies. Java is a registered trademark of Oracle and/or its affiliates. Some content is licensed under the numpy license.
Last updated 2021-05-14 UTC.
[[["Easy to understand","easyToUnderstand","thumb-up"],["Solved my problem","solvedMyProblem","thumb-up"],["Other","otherUp","thumb-up"]],[["Missing the information I need","missingTheInformationINeed","thumb-down"],["Too complicated / too many steps","tooComplicatedTooManySteps","thumb-down"],["Out of date","outOfDate","thumb-down"],["Samples / code issue","samplesCodeIssue","thumb-down"],["Other","otherDown","thumb-down"]],["Last updated 2021-05-14 UTC."],[],[],null,["# tf.nn.isotonic_regression\n\n|---------------------------------------------------------------------------------------------------------------------------|\n| [View source on GitHub](https://github.com/tensorflow/tensorflow/blob/v2.5.0/tensorflow/python/ops/nn_ops.py#L5844-L5916) |\n\nSolves isotonic regression problems along the given axis. \n\n tf.nn.isotonic_regression(\n inputs, decreasing=True, axis=-1\n )\n\nFor each vector x, the problem solved is \n$$\\\\argmin_{y_1 \\\u003e= y_2 \\\u003e= ... \\\u003e= y_n} \\\\sum_i (x_i - y_i)\\^2.$$\n\nAs the solution is component-wise constant, a second tensor is returned that\nencodes the segments. The problems are solved over the given axis.\n\nConsider the following example, where we solve a batch of two problems. The\nfirst input is \\[3, 1, 2\\], while the second [1, 3, 4](/versions/r2.5/api_docs/python/tf/nn/as%20the%20axis%20is%201). \n\n \u003e\u003e\u003e x = tf.constant([[3, 1, 2], [1, 3, 4]], dtype=tf.float32)\n \u003e\u003e\u003e y, segments = tf.nn.isotonic_regression(x, axis=1)\n \u003e\u003e\u003e y # The solution.\n \u003ctf.Tensor: shape=(2, 3), dtype=float32, numpy=\n array([[3. , 1.5 , 1.5 ],\n [2.6666667, 2.6666667, 2.6666667]], dtype=float32)\u003e\n\nNote that the first solution has two blocks \\[2\\] and \\[1.5, 1.5\\]. The second\nsolution is constant, and thus has a single segment. These segments are\nexactly what the second returned tensor encodes: \n\n segments\n \u003ctf.Tensor: shape=(2, 3), dtype=int32, numpy=\n array([[0, 1, 1],\n [0, 0, 0]], dtype=int32)\u003e\n\n\u003cbr /\u003e\n\n\u003cbr /\u003e\n\n\u003cbr /\u003e\n\n| Args ---- ||\n|--------------|------------------------------------------------------------------------------|\n| `inputs` | A tensor holding the inputs. |\n| `decreasing` | If set to False, the inequalities in the optimizing constrained are flipped. |\n| `axis` | The axis along which the problems should be solved. |\n\n\u003cbr /\u003e\n\n\u003cbr /\u003e\n\n\u003cbr /\u003e\n\n\u003cbr /\u003e\n\n| Returns ------- ||\n|------------|------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------|\n| `output` | The solutions, same shape as type as the input. |\n| `segments` | An int32 tensor, same shape as the input indicating the segments that have the same value. Specifically, those positions that have the same value correspond to the same segment. These values start at zero, and are monotonously increasing for each solution. |\n\n\u003cbr /\u003e"]]