![]() |
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
\[\argmin_{y_1 >= y_2 >= ... >= y_n} \sum_i (x_i - y_i)^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. |