Mathematics Stack Exchange is a question and answer site for people studying math at any level and professionals in related fields. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

I have the following algorithm which needs to be expressed more concisely using mathematical symbols and I need help for that.

The algorithm accepts a square matrix and a related set of integers (ids) and returns a real number.

(1) I have a square matrix S of size N x N.

(2) Each row of the matrix has two integers associated with it. $Id_{true}$ and $Id_{obs}$.

(3) V consecutive rows have the same $Id_{true}$. Rows with the same $Id_{true}$ may or may not have same $Id_{obs}$. Thus each $Id_{true}$ is related to V number of $Id_{obs}$.

(4) Let the most frequently occurring id in $\{Id_{obs}\}$ be $Id_f$. Tie is not acceptable. The frequency with which $Id_f$ occurs must be greater than all other Ids frequency.

(5) If $Id_{true}$ == $Id_{f}$, success else failure.

(6) At the end of processing all rows of S, the no of successes is counted and returned as a percentage.

share|cite|improve this question
The matrix S does not seem relevant to your algorithm. – Tsuyoshi Ito Nov 19 '11 at 22:42
I process each row of the matrix.... – suresh Nov 19 '11 at 22:44
You are not processing matrix S in any way. What is relevant is the integers associated with each row, but from your description, they have nothing to do with matrix S. – Tsuyoshi Ito Nov 19 '11 at 22:45
@TsuyoshiIto yes - you are right. That is because I did not explain how the ids are related to the rows...which I thought is irrelevant to mention here. – suresh Nov 19 '11 at 23:03

I take it your algorithm is something like


for i from 1 to N do if Id_true = Id_obs then count:=count + 1 fi;

return 100 count / N.

As for a mathematical formula, how about $${100\over N}\sum_{i=1}^N1_{Id_{true}(i)=Id_{obs}(i)}$$ where $1_P$ is the notation for the quantity that is 1 if $P$ is true and 0 if $P$ is false.

share|cite|improve this answer
I am sorry that I missed one step in the algorithm when I posted the question earlier, which I realized only when I read your solution. Extremely sorry for that. – suresh Nov 19 '11 at 23:38
OK, so first you need some steps to identify the most frequent element in a finite list. It is not clear to me whether you are asking for an algorithm or a formula. If the former, there are algorithms around for finding the most frequent element in a list, and there are programming websites for asking for them. If the latter, you could cook something up, I'm not sure there's a standard accepted formula. – Gerry Myerson Nov 20 '11 at 0:12
I was asking for a concise mathematical representation. I have already implemented the above algorithm. – suresh Nov 20 '11 at 0:21

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.