Google Distance Matrix using Microsoft Bing Maps - bing-maps

Is there a way to use Bing Maps Driving REST Service the same way we use Google Distance Matrix?
I want to be able to calculate the distance:
p1 -> p2
p1 -> p3
p1 -> p4
...
p1 -> p15
With Google Distance Matrix I am able to get the distance for the 15 routes with one request, but using Bing I don't find a way to do it (only with 15 requests for each distance calculation).

Bing Maps does not expose a distance Matrix API, however it is possible to generate the required data using the Bing Maps Routing Service. You could make a request for each distance but this would be slow and generate a lot of transactions. The Bing Maps Routing Service allows you to pass in up to 25 waypoints into a single request. As such you can use this to do a batch calculation. For example, lets say we have 3 locations. A matrix would be 3x3 = 9 cells, 3 of these would have a value of 0 (i.e. A -> A). This leaves 6 cells that need calculations. To further optimize would could assume the distance between two locations is the same regardless of the direction of travel (i.e. A -> B = B -> A). If we make this assumption we only need to calculate the values for 3 cells; A-> B, A-> C, B-> C. To further optimize the route calculation we could align the waypoints such that we minimize the number of extra calculations done; A -> B, B -> C, C -> A. By doing this we can then calculate a route from A -> B -> C -> A. This would be a route with only 4 waypoints. The route response will then contain an array of route legs, each having a defined distance and time value which you can use to generate your matrix.
In your case you are only calculating from one location to 15 others. This is a 2 x 15 matrix and a bit similar than the above method to accomplish. In this case you can calculate a multi-waypoint route back and forth from the start point and each waypoint. Lets say the start is S and the other points are A, B, C, we could calculate a route from S -> A -> S -> B -> S -> C. This response for the route would have an array of route legs. The odd indexed route legs in the array would have your distance/times from S -> (A,B,C). Using this method you could calculate the data you need from S to 11 other locations. If you have 15 locations you would need to make two route requests. Note that if you are doing this while displaying an interactive map you can generate a session key from the map and use that in the request o make the route calls non-billable.
I'm assuming you want to do this so that you can calculate an optimized route using a traveling salesmen algorithm. If this is the case you might find this code sample interesting: https://code.msdn.microsoft.com/windowsapps/Bing-Maps-trip-optimizer-c4e037f7

Related

How to define Traingular membership function for fuzzy controller design?

I am designing a fuzzy controller and for that, I have to define 3 triangular function sets. They are:
1 large
2 medium
3 small
But my problem is I have following data only:
Maximum input = 3 Minimum input= 0.1
Maximum output = 5.5 Minimum output= 0.8
How to define 3 triangular set range based on only this given information?
Here is the formula for a triangular membership function
f=0 if x<=a
f=(x-a)/(b-a) if a<=x<=b
f=(c-x)/(c-b) if b<=x<=c
f=0 if x>c
where a is the min, c is the max and b is the midpoint.
In your case, take the top situation where the max is 3 and the min is 0.1. The midpoint is (3+0.1)/2=1.55, so you have
f=0 if x<=0.1
f=(x-0)/(1.55-1) if 0.1<=x<=1.55
f=(3-x)/(3-1.55) if 1.55<=x<=3
f=0 if x>3
You should be able to take the 2nd example from here, but if not let me know. Something worth pointing out is that the midpoint may not be the ideal b in your situation. Any point between a and c could serve as your b, just know that it is the point where the membership function equals 1.
It is difficult to tell, but it looks like maybe you just have given parameters for two of the functions, perhaps for small and large or medium and large. You may need to use some judgement for the 3rd membership function.

Pseudo randomization in MATLAB with minimum intervals between stimulus categories

For an experiment I need to pseudo randomize a vector of 100 trials of stimulus categories, 80% of which are category A, 10% B, and 10% C. The B trials have at least two non-B trials between each other, and the C trials must come after two A trials and have two A trials following them.
At first I tried building a script that randomized a vector and sort of "popped" out the trials that were not where they should be, and put them in a space in the vector where there was a long series of A trials. I'm worried though that this is overcomplicated and will create an endless series of unforeseen errors that will need to be debugged, as well as it not being random enough.
After that I tried building a script which simply shuffles the vector until it reaches the criteria, which seems to require less code. However now that I have spent several hours on it, I am wondering if these criteria aren't too strict for this to make sense, meaning that it would take forever for the vector to shuffle before it actually met the criteria.
What do you think is the simplest way to handle this problem? Additionally, which would be the best shuffle function to use, since Shuffle in psychtoolbox seems to not be working correctly?
The scope of this question moves much beyond language-specific constructs, and involves a good understanding of probability and permutation/combinations.
An approach to solving this question is:
Create blocks of vectors, such that each block is independent to be placed anywhere.
Randomly allocate these blocks to get a final random vector satisfying all constraints.
Part 0: Category A
Since category A has no constraints imposed on it, we will go to the next category.
Part 1: Make category C independent
The only constraint on category C is that it must have two A's before and after. Hence, we first create random groups of 5 vectors, of the pattern A A C A A.
At this point, we have an array of A vectors (excluding blocks), blocks of A A C A A vectors, and B vectors.
Part 2: Resolving placement of B
The constraint on B is that two consecutive Bs must have at-least 2 non-B vectors between them.
Visualize as follows: Let's pool A and A A C A A in one array, X. Let's place all Bs in a row (suppose there are 3 Bs):
s0 B s1 B s2 B s3
Where s is the number of vectors between each B. Hence, we require that s1, s2 be at least 2, and overall s0 + s1 + s2 + s3 equal to number of vectors in X.
The task is then to choose random vectors from X and assign them to each s. At the end, we finally have a random vector with all categories shuffled, satisfying the constraints.
P.S. This can be mapped to the classic problem of finding a set of random numbers that add up to a certain sum, with constraints.
It is easier to reduce the constrained sum problem to one with no constraints. This can be done as:
s0 B s1 t1 B s2 t2 B s3
Where t1 and t2 are chosen from X just enough to satisfy constraints on B, and s0 + s1 + s2 + s3 equal to number of vectors in X not in t.
Implementation
Implementing the same in MATLAB could benefit from using cell arrays, and this algorithm for the random numbers of constant sum.
You would also need to maintain separate pools for each category, and keep building blocks and piece them together.
Really, this is not trivial but also not impossible. This is the approach you could try, if you want to step aside from brute-force search like you have tried before.

MinHashing vs SimHashing

Suppose I have five sets I'd like to cluster. I understand that the SimHashing technique described here:
https://moultano.wordpress.com/2010/01/21/simple-simhashing-3kbzhsxyg4467-6/
could yield three clusters ({A}, {B,C,D} and {E}), for instance, if its results were:
A -> h01
B -> h02
C -> h02
D -> h02
E -> h03
Similarly, the MinHashing technique described in the Chapter 3 of the MMDS book:
http://infolab.stanford.edu/~ullman/mmds/ch3.pdf
could also yield the same three clusters if its results were:
A -> h01 - h02 - h03
B -> h04 - h05 - h06
|
C -> h04 - h07 - h08
|
D -> h09 - h10 - h08
E -> h11 - h12 - h13
(Each set corresponds to a MH signature composed of three "bands", and two sets are grouped if at least one of their signature bands is matching. More bands would mean more matching chances.)
However I have several questions related to these:
(1) Can SH be understood as a single band version of MH?
(2) Does MH necessarily imply the use of a data structure like Union-Find to build the clusters?
(3) Am I right in thinking that the clusters, in both techniques, are actually "pre-clusters", in the sense that they are just sets of "candidate pairs"?
(4) If (3) is true, does it imply that I still have to do an O(n^2) search inside each "pre-cluster", to partition them further into "real" clusters? (which might be reasonable if I have a lot of small and fairly balanced pre-clusters, not so much otherwise)
SimHash and MinHash are both hashing algorithms that are able to map a set to a list of values which corresponds to the signature of the set.
In case of SimHash the list of values is just a list of bits (the values are either 0 or 1). In case of MinHash a value in the list represents the minimum hash value of all set elements relative to a given hash function which is typically a 32bit or 64bit value.
A major difference of both algorithms is the probability of hash collisions. In case of SimHash it is equal to the cosine similarity and in case of MinHash it is equal to the Jaccard similarity. Depending how you define the similarity between sets the one or the other algorithm could be more appropriate.
Regardless of the chosen hashing algorithm, the values of the calculated signature are equally partitioned over a certain number of bands. If the signatures of any two sets are identical within at least one band, the corresponding pair of sets is selected as candidate for similarity. (This means if n sets have the same signature within a band, there are O(n^2) candidate pairs just from this band.) Estimating the similarity of each candidate pair using the complete signature (including the values from other bands) and keeping only those pairs with an estimated similarity above a given threshold gives you all similar pairs of sets which finally define the final clustering.

How to compare two routes using google direction apis or some other apis for iPhone app

I want to compare two routes to check if they are same or not in my iPhone app.
There is a person X who wants to go to point A to point B and another person wants to go to point A1 to point B1.
I can get a route between A to B using this direction APIs of google.
http://maps.googleapis.com/maps/api/directions/xml?origin=Point a A address&destination=Point B address&sensor=false
same way I can get route of A1 to B1.
but the latitude and longitude I am getting in xmls are not matching (even a single point is not matching). So here is my question how can I match two routes I want to know is this same route or not.
If the optimal route A1B1 is actually a subset of the route AB I'd expect the start_location and end_locations for the matching steps to share similar longitudes and latitudes, but this isn't a requirement of the directions API. The best path from A to B might pass through A1 and B1, but that doesn't mean the best path from A1 to B1 will share the exact same steps.
What I think you want to do is look at the polyline points returned for the route segments and see if they would pass through A1 and B1 in the correct order. You can expand the encoded polyline strings into a list of latitude and longitudes using this algorithm.

clustering cell tower ids

If you have a list of cell tower ids and their respective start and end time (i.e. the time the phone was registered at that tower), is there an easy to cluster the ids and visualise the cells and their clusters in a diagram?
Thanks
Not without some knowledge of location. Minimally at start time and at end time. If you were travelling in a line for example you could estimate the distance of the tower from the midpoint of those. If you just have time data but no location data there is nothing you can map.
Edit: To simplify, if you have no location data, you can't map much of anything, you could simply index transitions - which towers are certainly adjacent. If you jumped from tower A to B to D to B to C to F to C to D to E to A, then you can map them in graph form:
A -- B -- C -- F
| | //
E -- D
This is only the connections that are definitely there, in the example F could be connected to D, or B could be connected to E, but you can only map the transitions you are sure of.
With location data for the mobile device, you could map the points of influence of the towers. From these points you could derive probable areas of influence (circular).
Conversely with location data for the towers, you could map probable transition spots. These could be connected into polygons of influence.
With no location data you can only make speculative graphs.