Make a vector positive

1k Views Asked by At

I have some vectors, which I want to make positive, like taking the absolute value of each element. The vector should be differentiable, so I cannot use some kind of abs-value. I'm looking for the mathematical expression to do this.

I thought about taking the square-root of the hadamard product of the vector. $$ c = (\sqrt{(A \odot A})^T ) \cdot (B \odot B) $$

How would the differential $$\frac{dc}{dA}$$ looks like?

Edit: The Matlab execution is:

c = sqrt(A.^2)'*B.^2
1

There are 1 best solutions below

8
On

Let's consider a one-dimensiona vector, then $$c = \sqrt{A^2}B^2=B^2|A|$$

Hence it is not differentiable.

However, if you consider

$$ c = ((A \odot A)^T ) \cdot (B \odot B) = \sum_{i=1}^n (B_iA_i)^2 $$ $$\frac{dc}{dA}=2A \odot (B \odot B)$$

Edit:

To preserve the magnitude of $A$, let's consider the following approximation, consider approximating $\sqrt{x^2}$ with $\sqrt{x^2+\epsilon}$.

enter image description here If we were to use

$$c=\sum_{i=1}^n\sqrt{A_i^2+\epsilon}B_i^2$$

$$\frac{dc}{dA_i}=\frac{A_i}{\sqrt{A_i^2+\epsilon}}B_i^2$$

The Matlab execution for $\frac{dc}{dA}$ would be

(A./(A.^2+ epsilon)).* B.^2