Starting from:
$30

$24

Artificial Intelligence Lab #3 Solution




1. The connection of the road network is specified as a matrix M (filename is “road.txt”). There are 10 sites indexed as (0, 1, . . . , 9). Entry M (i, j) denotes the length of the road between site i and j in kms (the roads are uni-directional). The roads are uni-directional (i.e., there could be a road from A to B, but not from B to A). If the entry is 0, it means no connection. Vehicles depart from a source and then take a path (filename “vehicle.txt”). The time of departure (in minutes) is given in filename “time.txt”, nth vehicle departs at time instance n. The speed (in kmph) of the vehicle in a road is given by the formula e0.5x/(1 + e0.5x) + 15/(1 + e0.5x), where x is the number of vehicles ahead in a given road. If there are n vehicles in the road, then for the first vehicle x = 0, second vehicle x = 1, and for the last vehicle x = n − 1. The time taken to travel the road is dist/speed. Implement a function that takes time as input and reports

the position of various vehicles at that given time. [20]




2. There is an under-powered car stuck in the bottom of a 1-dim valley. It needs to find its way to the top. The car has three actions namely A = {−1, 0, +1} which means accelerate backward, no acceleration and accelerate forward, respectively. A chosen action is applied for a fixed duration of time, after which a new action is chosen. The ranges for position and velocity are [−1.2, 0.5] and [−0.07, 0.07], respectively. The car is needs to reach the top on the right, i.e., position of 0.5. The dynamics is according to the equations:




vn+1 = vn + 0.001an − 0.0025 cos(3pn )




pn+1 = pn + vn




(a) Implement a function which takes in the current position and action and outputs the

position and velocity at the next step. [25] (b) Implement a random agent which at each time instant chooses one of the three actions

uniformly at random. Plot {(pn , vn ), n ≥ 1} produced by the random agent. Take the

initial position to be −0.5, and initial velocity to be 0. [15] (c) Implement another agent which accelerates in the direction of the current velocity. Plot

{(pn , vn ), n ≥ 1} produced by this agent. Take the initial position to be −0.5, and initial

velocity to be 0. [10]




3. Read the text file “speeches.txt”




(a) Compute the next word probabilities. [10] (b) Based on the next word probabilities, write down a code that will produce random text

of length 5000. [10]

(c) Compute the next word probability from the previous task and show that it converges to

the next word probabilities calculated from the original text. [10]



















End of paper

More products