0
$\begingroup$

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.

  • 0
    The matrix S does not seem relevant to your algorithm.2011-11-19
  • 0
    I process each row of the matrix....2011-11-19
  • 0
    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.2011-11-19
  • 0
    @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.2011-11-19

1 Answers 1

1

I take it your algorithm is something like

count:=0;

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.

  • 0
    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.2011-11-19
  • 0
    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.2011-11-20
  • 0
    I was asking for a concise mathematical representation. I have already implemented the above algorithm.2011-11-20