Calculate product of weighted distance of path netlogo - social-networking

I have a network of people in netlogo. In short a social network. Each social link has a trust value. when a person meets another person whom it does not know and want to make business with it , it needs to have certain recommendation.
In our case this recommendation comes from shortest path which means if "a" wants to make business with "c" and does not know it initially; it can get recommendation from a friend who knows "c". so e.g. trust value of a on c can be calculated as (trust of a on b) * (trust of b on c ).
how can i calculate it.

You can do this the new network extension, nw (bundled with NetLogo), using nw:weighted-distance-to.

Related

Contextual-Bandit Approach: Algorithm 1 LinUCB with disjoint linear models

I am trying to implement the algorithm called LinUCB with disjoint linear models from this paper "A Contextual-Bandit Approach to Personalized News Article Recommendation" http://rob.schapire.net/papers/www10.pdf
This is the algorithm:
Algorithm 1 LinUCB with disjoint linear models
I am confused about the features vector Xt,a (I highlighted on the algorithm).
Is the feature vector related to information (context) of the article(arm) or the user?
I would appreciate your help.
Thank you
The feature vector x_t,a applies to both the user and the arm.
The vector xt,a summarizes information of both the user ut and arm a,
and will be referred to as the context.
In the most general case, the feature vector X_(t,a) is allowed to be a function of both the user context c_t and the arm a, or X_(t, a) = phi(c_t, a). Note that this could simply be a subset: each arm might have different features it uses to predict an outcome, or in other words X_(t, a) is a subset of c_t.
For example, if a movie recommendation website is deciding which movie to recommend, they might need different information from the user when attempting to predict if he'll like sci-fi movies versus drama movies. This different information is reflected in the fact that features are allowed to vary by arm.
Alternatively, it might be the case that X_(t, a) is the same for all a, i.e. X_(t, a) = X_t. For example, when trying to learn the best medical dosage, the algorithm might want to know height, weight, and age for all the patients. In this case the features would not vary by arm.

Machine learning in cab pooling scenario?

So I have this dataset for a transportation problem. Which shows a cab pooling scenario. Consider the following image:
The users with same ride number went in the same cab (each user has the same starting point so please ignore that). Now that means, Y, Z and A are in same proximity, and so as B & C and D & E.
Now I would like to fit this dataset into a machine learning model such that when I enter the destination of any user, the model should give me the prediction on with whom my destination can be coupled so I can go in the cab with those people.
Like if I have to go to a location 'C' I can join people who are going to 'B'.
Which machine learning algorithm can I use in this scenario?
You can probably do without machine learning algorithm. Given the ride number, you can identify locations which are close to each other and group them. When a new location comes, you can see which group it belongs to and pair the people traveling to locations within that group.
To do this you can create a matrix which has locations A, B,C,... as the rows and as columns. What you'll get is a num_of_locations x num_of_locations matrix. For the cell with row label B and column label C you can mark it as 1 since they are in proximity and the locations which aren't in proximity(like A and B) should be marked as zero.
The matrix will be a symmetric one, so if you have too many locations you can save on memory and computation by some optimizations. You can research around saving triangular matrices as sparse matrices.
Also, if you have access to the right resources(paid libraries), you can replace the 0,1 with distances(displacements actually).

Limit stores - most efficient or easy approach?

Say you have multiple vendors (lets say 5) all selling the same items for different prices. You must buy item A,B,C, D, E. Each vendor has item A,B C,D,E so you can easily go through each vendor and find the cheapest version of each item. However, say you are limited to only shopping from X vendors. So you must now find the cheapest combinations that make sure you do not use more vendors than allowed. How does one solve this problem without trying every combination of vendors?
Another way of phrasing an example.
for 5 shops, we are only allowed to use 2 shops to buy 5 items (with each item at a different price in different shops). How do we save the most money? Is there a method of solving without trying every combination
your search is about linear programming ... realy long to explain ^^ : https://en.wikipedia.org/wiki/Linear_programming

Database design for bus reservation

I'm developing a reservation module for buses and I have trouble designing the right database structure for it.
Let's take following case:
Buses go from A to D with stopovers at B and C. A Passenger can reserve ticket for any route, ie. from A to B, C to D, A to D, etc.
So each route can have many "subroutes", and bigger contain smaller ones.
I want to design a table structure for routes and stops in a way that would help easily search for free seats. So if someone reserves seat from A to B, then seats from B to C or D would be still be available.
All ideas would be appreciated.
I'd probably go with a "brute force" structure similar to this basic idea:
(There are many more fields that should exist in the real model. This is only a simplified version containing the bare essentials necessary to establish relationships between tables.)
The ticket "covers" stops through TICKET_STOP table, For example, if a ticket covers 3 stops, then TICKET_STOP will contain 3 rows related to that ticket. If there are 2 other stops not covered by that ticket, then there will be no related rows there, but there is nothing preventing a different ticket from covering these stops.
Liberal usage or natural keys / identifying relationships ensures two tickets cannot cover the same seat/stop combination. Look at how LINE.LINE_ID "migrates" alongside both edges of the diamond-shaped dependency, only to be merged at its bottom, in the TICKET_STOP table.
This model, by itself, won't protect you from anomalies such as a single ticket "skipping" some stops - you'll have to enforce some rules through the application logic. But, it should allow for a fairly simple and fast determination of which seats are free for which parts of the trip, something like this:
SELECT *
FROM
STOP CROSS JOIN SEAT
WHERE
STOP.LINE_ID = :line_id
AND SEAT.BUS_NO = :bus_no
AND NOT EXIST (
SELECT *
FROM TICKET_STOP
WHERE
TICKET_STOP.LINE_ID = :line_id
AND TICKET_STOP.BUS_ID = :bus_no
AND TICKET_STOP.TRIP_NO = :trip_no
AND TICKET_STOP.SEAT_NO = SEAT.SEAT_NO
AND TICKET_STOP.STOP_NO = STOP.STOP_NO
)
(Replace the parameter prefix : with what is appropriate for your DBMS.)
This query essentially generates all combinations of stops and seats for given line and bus, then discards those that are already "covered" by some ticket on the given trip. Those combinations that remain "uncovered" are free for that trip.
You can easily add: STOP.STOP_NO IN ( ... ) or SEAT.SEAT_NO IN ( ... ) to the WHERE clause to restrict the search on specific stops or seats.
From the perspective of bus company:
Usually one route is considered as series of sections, like A to B, B to C, C to D, etc. The fill is calculated on each of those sections separately. So if the bus leaves from A full, and people leave at C, then user can buy ticket at C.
We calculate it this way, that each route has ID, and each section belongs to this route ID. Then if user buys ticket for more than one section, then each section is marked. Then for the next passenger system checks if all sections along the way are available.

Time Aware Social Graph DS/Queries

Classic social networks can be represented as a graph/matrix.
With a graph/matrix one can easily compute
shortest path between 2 participants
reachability from A -> B
general statistics (reciprocity, avg connectivity, etc)
etc
Is there an ideal data structure (or a modification to graph/matrix) that enables easy computation of the above while being time aware?
For example,
Input
t = 0...100
A <-> B (while t = 0...10)
B <-> C (while t = 5...100)
C <-> A (while t = 50...100)
Sample Queries
Is A associated with B at any time? (yes)
Is A associated with B while B is associated with C? (yes. #t = 5...10)
Is C ever reachable from A (yes. # t=5 )
What you're looking for is an explicitly persistent data structure. There's a fair body of literature on this, but it's not that well known. Chris Okasaki wrote a pretty substantial book on the topic. Have a look at my answer to this question.
Given a full implementation of something like Driscoll et al.'s node-splitting structure, there are a few different ways to set up your queries. If you want to know about stuff true in a particular time range, you would only examine nodes containing data about that time range. If you wanted to know what time range something was true, you would start searching, and progressively tighten your bounds as you explore each new node. Just remember that your results might not always be contiguous - consider two people start dating, breaking up, and getting back together.
I would guess that there's probably at least one publication worth of unexplored territory in how to do interesting queries over persistent graphs, if not much more.

Resources