On Tuesday 15 April 2008 04:02, Daniel Cheng wrote:
> Hi list,
> 
> On LocationManager#shouldSwap(), I wonder if we should use a geometric
> mean instead of just multiplying them together.
> Let's see the current implement:
> 
>  748         double A = 1.0;
>  749         for(int i=0;i<friendLocs.length;i++) {
>  750             if(Math.abs(friendLocs[i] - myLoc) <=
> Double.MIN_VALUE*2) continue;
> 
> #1. some friends are skipped.
>      this number should be small -- my friends shouldn't be sooo close to 
me.
>      rare, but not impossible (?)

It's possible with a race condition. If it does happen it will sabotage 
things, so we check for it. If it persists we randomise our location 
elsewhere.
> 
>  751             A *= Location.distance(friendLocs[i], myLoc);
>  752         }
>  753         for(int i=0;i<hisFriendLocs.length;i++) {
>  754             if(Math.abs(hisFriendLocs[i] - hisLoc) <=
> Double.MIN_VALUE*2) continue;
> 
> #2. again some friends are skipped. (same as #1)
> 
>  755             A *= Location.distance(hisFriendLocs[i], hisLoc);
>  756         }
>  757
>  758         // B = the same, with our two values swapped
>  759         double B = 1.0;
>  760         for(int i=0;i<friendLocs.length;i++) {
> 
> (      never mention his number of friends may not be the same as mine
>        should we use for(int i=0;i<friendLocs.length &&
> ;i<hisFriendLocs.length ; i++)  ? )

No. We are simply implementing the algorithm oskar came up with.
> 
>  761             if(Math.abs(friendLocs[i] - hisLoc) <=
> Double.MIN_VALUE*2) continue;
> 
> #3. skip yet other friends...
>       but this time, we compare my friend's location with his location ..
>       I have him as my friend, so this is skipped _at least_ once.

Normally we don't swap with our direct peers. There is a 10 hop HTL. So no, we 
don't skip him.

I don't understand how it is different - as far as I can see it's symmetrical, 
first we calculate the product for the current situation, then we calculate 
it for it being swapped. Either way we ignore nodes which are too close 
together in order to avoid zeros.
> 
>       The number of friends skipped here is not the same as those in #1 and 
#3..
>        i.e.  A and B are calculated using different number of samples.
> 
>        as Location.distance() < 1.0 ,  the more round you multiply,
> the less the value.
> 
> 
>  762             B *= Location.distance(friendLocs[i], hisLoc);
>  763         }
>  764         for(int i=0;i<hisFriendLocs.length;i++) {
>  765             if(Math.abs(hisFriendLocs[i] - myLoc) <=
> Double.MIN_VALUE*2) continue;
>  766             B *= Location.distance(hisFriendLocs[i], myLoc);
>  767         }
> 
> [...]
> 
>  771         if(A>B) return true;
> 
> #4   And now, we compare A and B. This is unfair!

No it isn't, it's the algorithm specified, which is an application of the 
Metropolis-Hastings algorithm.
> 
> 
> Regards,
> Daniel Cheng
-------------- next part --------------
A non-text attachment was scrubbed...
Name: not available
Type: application/pgp-signature
Size: 189 bytes
Desc: not available
URL: 
<https://emu.freenetproject.org/pipermail/tech/attachments/20080415/d6ccdb58/attachment.pgp>

Reply via email to