The give relationship is -
beta(i)
= a-b*log(u(i)) [if r(i) <= 0.5]
= a+b*log(u(i)) [if r(i) > 0.5]
Where i varies from 1 to n (n is the length of the chromosome). r(i) and u(i) are uniform random numbers belonging to the interval [0,1]. a and b are constants.
I want to make a list of beta values for each i and hence wrote the following lines of code:
Expand|Select|Wrap|Line Numbers
- bet = []
- for i in range(chromlen):
- if (random.uniform(0,1) <= 0.5):
- bet.append((a-b*(math.log(random.uniform(0,1)+0.000000000001)))
- else:
- bet.append((a+b*(math.log(random.uniform(0,1)+0.000000000001)))
- beta = bet
I'm receiving a message when I run the program that says "There's an error in your program: invalid syntax" and it highlights 'else' in red.
I can't figure out where I made a mistake. Please help. Thanks.
I've imported 'random' and 'math' earlier in the code. As I mentioned before, this is just part of the code.