class MultiMean extends SingleParentVariable<Matrix> {

    @Override
    public Tensor<?> gradient(Variable<?> parent, ComputationContext ctx) {
        double[] multiMeanGradient = ctx.gradient(this).data();

        Tensor<?> result = ctx.data(parent).zeros();

        for (int col = 0; col < cols; col++) {
            for (int row = 0; row < rows; row++) {
                int degree = adjacency[row].length + 1;
                int gradientElementIndex = row * cols + col;
                for (int neighbor : adjacency[row]) {
                    int neighborElementIndex = neighbor * cols + col;
                    result.addDataAt(
                        neighborElementIndex,
                        1d / degree * multiMeanGradient[gradientElementIndex]
                    );
                }
                result.addDataAt(
                    selfAdjacency[row] * cols + col,
                    1d / degree * multiMeanGradient[gradientElementIndex]
                );
            }
        }

        return result;
    }

    public  MultiMean(
        Variable<?> parent,
        int[][] adjacency,
        int[] selfAdjacency
    );

}