2

Let $A$ be an $m \times n$ matrix, $\mathbf x \in \mathbb R^n$, and define the truncation operator $T \colon \mathbb R^m \to \mathbb R^m$ by $(T \mathbf y)_i = \max\{\min\{\mathbf y_i, c\}, 0\}$, so $T$ truncates each entry of its argument to $[0, c]$.

What is the computational complexity of $TA\mathbf y$?

I know from Wikipedia that $A \mathbf y$ should be $O(mn)$. What about $T$? I might be totally wrong, but if $T$ has to make 2 comparisons over each of $m$ elements, would it be $O(m)$? So the total complexity of $TA\mathbf y$ would be $O(m^2n)$?

Is this right? Thanks.

caitlin
  • 125

2 Answers2

2

Updated answer:

No. Given that the truncation operator :$ℝ^→ℝ^$ by $()=max\{min\{,\},0\}$, it's reasonable to deduce that it takes $O(m)$.

Matrix multiplication takes $O(m n)$, and then we get a new vector Ay, applying T on it takes another O(m).

Hence, it takes O(mn+m) = O(mn) in total.

(Exception is that it's done in designated hardware, where it could be parallelized, as low as O(1) for truncation operator.)

Peter HU
  • 139
  • thanks for your answer. I have a question though. if you look at this complexity analysis for least squares regression (https://math.stackexchange.com/questions/84495/computational-complexity-of-least-square-regression-operation), you see that we throw away the big O terms that are dominated by the biggest. Why don't you do that here in this case? – caitlin Nov 26 '23 at 04:34
  • phrased another way, O(mn) will dominate O(m), so why isn't the answer O(mn)? – caitlin Nov 26 '23 at 04:35
  • This answer happens to be wrong. It only takes $O(1)$ time per entry of $Ay$, or $O(m)$ time in total. The running times $O(mn)$ and $O(m)$ should be added, not multiplied. (If it was written with ChatGPT or GenAI, that is not allowed.) – D.W. Nov 26 '23 at 06:11
  • Good point! Just fell in a pitfall. Answer ameneded now. – Peter HU Nov 26 '23 at 10:57
1

No, that's not correct. It takes $O(mn)$ time to compute $Ay$. Then, it takes $O(m)$ time to apply $T$ to that result. So, the total running time is $O(mn+m)$. Equivalently, the total running time is $O(mn)$.

In my experience, the $T$ operation is normally known as clipping, not truncation.

D.W.
  • 5,958
  • thanks for your answer, but this is quite confusing, because i just asked this question (https://math.stackexchange.com/questions/4814457/algorithm-analysis-when-to-throw-away-terms#4814467) and was told that we need to multiply $mn$ and $m$. – caitlin Nov 26 '23 at 05:58
  • @caitlin, I don't blame you for being confused. The two other answers are incorrect. That is why you are hearing contradictory information. I would be confused in your place too. – D.W. Nov 26 '23 at 06:12