I would like to write code which gives cumulative probabilities (0-1) to each number which are descending in order. For example;
I have a set of number:
150
152
155
160
175
I will give those numbers a probability in this way:
for first one (150) probability is = 175/total Sum
Second one is = 160/totalsum + previous probability….and so on.
The main point is 150 will have the higher probability than others.
What would you suggest to me. Set will contain more than 30 numbers…
Here is the code:
int ll;
float prefitness=0;//Previous fittnesses
int minus =0;
for (int sdf=0;sdf<PopulationSize;sdf++)//population size is the total number counts
{
ll=sortindex[sdf];//sortindex is an array with numbers in ascending order
Sol_list[ll].fittness=(double)Sol_list[PopulationSize-1-minus].PortfolioDuration/sum+prefitness;
prefitness=Sol_list[ll].fittness;
minus++;
}
float move=0;
int xc;
for (int yj=0;yj<PopulationSize;yj++)
{
xc=sortindex[yj];
Sol_list[xc].fittnesspre =move;
move=Sol_list[xc].fittness;
}
Your problem is that you aren’t using the sorted index in all access of Sol_list. This one is wrong:
It should say: