6:28 PM
3

We asked a similar question somewhere else and someone advised trying here instead. How should we calculate $\langle A\rangle \langle A\rangle$ from data on dipole moments? It is a term in an equation for calculating something else. Some example data: x y z Total 26.78 -6.31 ...

Welcome to the site! Just to make sure I'm understanding correctly, you are using $A$ to mean the magnitude of the dipole moment and your goal is to determine the variance of this quantity over some time range? — Tyberius ♦ 49 mins ago
If your Total column is only positive and you are taking the variance of Total column, then what is the issue? Also, the documentation on numpy.var says the absolute value of each component is only taken when the values are complex. — Shoubhik R Maiti 49 mins ago
@Tyberius, thank you for answering and to whoever formatted the notation. I don't even know if the word "magnitude" is right because that is apparently a source of confusion when talking about vectors. This is not something we know much about. The definition of "A" where we got the equation is "A is the total dipole moment of the simulation box." We do need to determine the variance of A over a simulation someone ran where we got the dipole data. — Ant 41 mins ago
@ShoubhikRMaiti, well that is what I guessed too but according to someone else, the second term in the variance expression should be tiny and the way np.var calculates it makes everything positive and the term too large. I don't know how to think about this. — Ant 41 mins ago
This looks very similar to the question physics.stackexchange.com/questions/634716/… And your question is still impossible to answer correctly unless you are able to define $A$. Find out what your definition is then the question is trivial to answer. — Hans Wurst 39 mins ago
@HansWurst, yes you got us started on the right track thanks. The only definition of A that we can find is what we have provided here, which is that it is the total dipole moment of the simulation box as I said in my reply to Tiberius. To us that indicates that the x, y, z components don't matter and that only Total matters in the definition but we are not experienced enough to be sure and maybe someone out there is more familiar with this kind of thing. — Ant 34 mins ago
Going by your comment, it is most likely that your are supposed to calculate the variance for each component of the dipole moment vector. I.e. you are supposed to calculate $$\text{Var}(x), \text{Var}(y) \text{ and } \text{Var}(z),$$ Where each of these component variances is obtained by applying the equation for variance to one column. For example, $$\text{Var}(x) = \langle x^2 \rangle - \langle x\rangle ^2$$ — Hans Wurst 17 mins ago
You cannot describe the variance of a vector by a single number. You could only describe the variance of the magnitude of a vector by a single number, since the magnitude is also a single number. But a vector (in 3 dimensions) as a whole requires 3 numbers and as such also leads to three variances, one for each component. — Hans Wurst 17 mins ago
@HansWurst, the equation we need to use the result in requires a single number so maybe that is a reason to think it is OK to use the variance of the magnitude of Total. I will think over what you said. — Ant 13 mins ago
Sorry @NikeDattani for an extended discussion via coments.

1 hour later…
7:48 PM
@Ant No problem. So (x,y,z) are the x, y, and z-components of the dipole moment vector, and "total" is sqrt(x^2 + y^2 + z^2), and A is supposed to be what? Is A = total? Or is A = x or y or z?
8:14 PM
@NikeDattani, thank you, very kind of you to reply. Yes, x, y, z are components of the dipole moment vector. "Total" is sqrt(x^2 + y^2 + z^2).

We think "total" is A (as described here in Eqn. 10.5, section 10.5.1, page 90 where it appears as "M", it's "A" in another paper).
http://openmd.org/wp-content/docs/OpenMD-2.5.pdf
We're doing a biological problem and don't know much about this. We thought we could just do "np.var(Total)" and that would be fine. But someone we talked to is very sure that that would not be correct. We have no idea why but he seems sure that the <A><A> is not right via np.var().
I hope I am making sense.
@Ant Why not try np.var and also the other formula that has been suggested to you? If your data set is too large, then take a subset of the data and do the calculation. If the results match from both, then you can be sure.
@Ant I looked at the document you mentioned. I have never seen the equation before, but my guess is that they are taking the variance of the magnitude of the dipole moment. This is because all the other terms in the equation are scalar, and they are considering the total dipole moment of the system, so my guess would be that <M> is a scalar as well.
8:30 PM
@ShoubhikRMaiti, thank you for your advice. We did try them both. The results don't match they're very different. So that is why we want to understand what is happening.

I have spent the last few days looking up the equation. It does appear in several papers but there is no detail about how the M term (the one I called "A" in my question because it is "A" in another paper) is calculated.
@ShoubhikRMaiti, I just saw your additional comment. So when you are guessing that they are taking the magnitude of the dipole moment, then that means "np.var(Total)" is OK? The thing that confuses me is that M does seem to be a vector. Maybe I am wrong.
So kind of you both to help figure this out.
@Ant Yes if they are only taking the magnitude, then np.var should be fine I guess. I am not a programmer though.
Why not calculate <A> explicitly? As in <A> = sum(A) / N . How did you get to the formula you gave in the original question?
@ShoubhikRMaiti, thank you that is helpful advice. It's fine if you're not sure because at least it is a place to start.

You asked about the formula in the original question. I guess you mean ⟨𝐴⋅𝐴⟩−⟨𝐴⟩⟨𝐴⟩ which also appears as <A^2> - <A>^2. That is a way to express var(A) (the variance of A, where A is a vector), I think. I have seen it in a few different places, including in some Python documentation.
You asked why not calculate <A> explicitly. We did that but that is where the person who gave us the data for A thinks we're doing something wrong.
He said the term ⟨𝐴⟩⟨𝐴⟩ should be

np.mean(x)**2 + np.mean(y)**2 + np.mean(z)**2

and we thought maybe it should actually be

np.mean(Total)**2.

They look similar but his version ends up much smaller because there are negative values in x, y, z. In our version that uses "Total," the negatives go away from calculating "Total" (because that calculation uses squares).
So he is say that if we use "Total" to calculate ⟨𝐴⟩⟨𝐴⟩, we are ignoring the vector nature of the dipoles. We have no idea if that is true.
9:18 PM
@Ant I think you're calculating "total" wrong, can you send us the paper where it's labeled <A> instead of <M>?
9:59 PM
Here's a more descriptive explanation of what "total dipole moment" means: en.wikipedia.org/wiki/…
@Ant Can you also tell us what each row of your able means? Are these the dipole moment components at different times? Or are they dipole moment vectors of the various bonds in the system?