Last week, I was at a #pdxgeekout session at the Ace Hotel in downtown Portland. @caseorganic, @aaronpk, @brennannovak, and @maxogden were there and Aaron was working on geoloqi and asked everyone how to best randomize the location data used to center the map.
Why try and mask someone’s location? I could set up geoloqi to let people I don’t know leave message that I get only when I pass withing a certain distance from that message. How do they leave a message in an area that I’m likely to get the message? They have to be able to see where I’m likely to find a message. This means the map they see needs to be centered near my location. Since geoloqi is open source, everyone has access to the source. If the interface for people to leave messages is public — which it is, then anyone can query it. If it just returned my location offset by a random amount, given a certain number of queries the centroid of the returned locations would be, quite accurately, my location.
What geoloqi needs is a method of offsetting the current location which statistically cannot be tricked or munged into reproducing one’s current location. This is the major constraint: How does one ensure that a dedicated (stalker/zombie/attacker/real life spamer/salesman) cannot reproduce one’s location, given the algorithm and a set of data requested from the public API for the map center?
Instead of returning a location that is only a random offset from my current location, I want it to take my history into account. I would like it to take all of my history in a certain region — let us call it — and assign a certain probability of me being there based on a sampling of the points. How do I go about doing this?
Let’s take a basis function and look at it:
This basis function is highest at the origin and does an exponential decay as the radius from the origin is increased and defines how slowly the function decreases as a function of the radius (it is similar to the standard deviation in the normal distribution, but I’m not using that here). Using this function we can simulate the uncertainty of finding someone at a specific location. Here’s what it looks like graphed out:
By taking a sampling of points from the history of places they’ve been, we can create a crude probability map of where someone could likely be given their current location . All we need to do is center this function around all of the sampled points. Let us call the sampling of the history points . The probability function over that region is:
Where and are the latitude and longitude of each point in the location history .
Let’s say someone’s been undulating through town and their path looks something like this:
As we can see, because of the rate of change in the function the sampled points get closer as the function’s derivative approaches zero. Our next question is, “How do we create a well distributed sampling of points?” We need to look at our basis function and look at how it decays with distance. If we choose a radius where the height is 0.5, the height of the probability function should stay around unity (unlike the graph above). Here’s the equation for that:
As long as the points are spaced apart, the probability function should remain nearly normalized. If we wanted to make this better behaved, we would weight each basis according to how long it has been since they’ve been there and how many adjacent sample points there are.
Now that we have our main function , we need to calculate the directional derivative so we can compute tangent lines and and their intersections with the plane at :
Now we can choose a random point in the neighborhood of — our current location, a semi-random unit vector , and then calculate a tangent line and it’s intersection with the ground plane.
Let . Let be within a range that is nearly perpendicular to a line through two historical points (say, and ) adjacent to the current point, so that
Keep in mind that is defined with a frame of reference of our coordinate system, while the above dot product is independent of the frame of reference. If we wanted to calculate the possible angles that could take, we need to first calculate the angle between and the axis:
Where is the basis vector for the axis, or .
Then we know that our random angle can be anywhere from (because ). Then to find the angle of we find .
Now, we evaluate , , and find :
Then we find the point . If is below a certain threshold then we can safely return . If not we set and start the iteration again. Lather. Rinse. Repeat as necessary.
Once this point is computed for one person, it should be cached until their location is updated again. If you want to return random points around this , ensure the region of return points doesn’t intersect the current region within which the person is located.
Since is dependant on , care should be taken to ensure it does not fall outside of the desired zoom range for the map. The possible range of values for can be calculated, but it is a very messy problem in the general case. It is left as an exercise to the reader. 😉