Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Argmax statement evaluation Java

Tags:

java

algorithm

I have the following pseudocode:

for j = 0 to argmax {l where t mod 2^l = 0} do

t is a counter being incremented outside of this for loop. My question is how to evaluate the argmax statement?

enter image description here

I believe the 'i' in the code to be a typo. 't' is probably correct.

like image 948
masb Avatar asked Jul 30 '26 13:07

masb


2 Answers

There is no closed-form argmax function.

Argmax says find the parameter (argument) that maximizes the function.

Which can be arbitrarily complex, if you have a complex expression inside of the statement.

Here, it can maybe be implemented as a one-liner mathematical expression, the authors were just too lazy to spell out because of line length. Otherwise, if you have a finite integer domain, you can implement it using a loop:

def argmaximod2l(maxl, i):
  for l in range(maxl, 0, -1):
    if i % (2**l) == 0: return l
  raise Exception("No l was divisible by i.")

if you have two integers, you can use nested loops; and if your parameters a doubles and you have a smooth convex function, you can use gradient descent methods.

In this particular case, the maximum l should be the number of trailing zeroes of i. There are much more efficient methods (there might also be a library function, e.g. Long.numberOfLeadingZeros in Java) available.

In this particular case, you might want to implement the loop as:

for (int j=0, i=t; (i&1)==0; j++, i>>>=1) {
  ...
}
like image 178
Has QUIT--Anony-Mousse Avatar answered Aug 01 '26 03:08

Has QUIT--Anony-Mousse


Not quite sure if I am getting the gist of your question?

for (int j = 0; j < argmax; j++) {...}

So as argmax is a function, then

for (int j = 0; j < argmax(); j++) {...}

private int argmax () {return some int}
like image 44
Scary Wombat Avatar answered Aug 01 '26 01:08

Scary Wombat



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!