Google I / Oの基調講演、製品セッション、ワークショップなどを見るプレイリストを見る


Solves isotonic regression problems along the given axis.

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:

<tf.Tensor: shape=(2, 3), dtype=int32, numpy=
array([[0, 1, 1],
       [0, 0, 0]], dtype=int32)>

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.

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.