def createTruth(npoints, nrepeats=4000): """ Generates a range of initial states for both vehicles, then simulates from each one a certain number of times. """ ## generating a grid of features res = int(npoints**.25) npoints = res**4 x_0 = np.linspace(-1., 1., res) X_0 = np.empty((npoints, 4)) for feature in range(4): X_0[:, feature] = np.repeat(np.tile(x_0, res**feature), res**(3 - feature)) ## randomly generating features #X_0 = np.random.uniform(-1,1,size=(npoints,4)) y_0 = [] for point in range(npoints): x = X_0[point, :] mean1 = x[:2] * mean_bounds + mean_means mean1 = motionModels.initialState_normal(mean1, noise * .1) mean2 = x[2:4] * mean_bounds + mean_means mean2 = motionModels.initialState_normal(mean2, noise * .1) out = alarms.alarm_MCS(mean1, mean2, truthMM1, truthMM2, times, nrepeats) y_0 += [out[0]] y_0 = np.array(y_0) np.save(model_name + '_X.npy', X_0) np.save(model_name + '_Y.npy', y_0)
v = np.random.normal(10., 5., nsims) - timeback * a th = np.random.uniform(-np.pi, np.pi, nsims) x = np.random.normal(0., 5., nsims) - timeback * v * np.cos(th) y = np.random.normal(0., 5., nsims) - timeback * v * np.sin(th) vehicle2 = np.array((x, y, th, v, a, w)).T truth = [] results = defaultdict(list) for sim in range(nsims): veh1 = vehicle1[sim, :] veh2 = vehicle2[sim, :] veh1 = motionModels.initialState_normal(veh1, initialnoise) veh2 = motionModels.initialState_normal(veh2, initialnoise) # find 'real' collision occurrences by using very high-res particle alarm pred, rt = alarms.alarm_MCS(veh1, veh2, MM1, MM2, times, 10000) truth += [pred] results['optimal'].append((pred, rt)) # estimators starttime = timer() result = alarms_nb.alarm_MCSbike(vehicle1[sim], initialnoise, vehicle2[sim], initialnoise, times.shape[0], timeres, noise, 10) time = timer() - starttime results['MC 10'].append((result, time)) starttime = timer() result = alarms_nb.alarm_MCSbike(vehicle1[sim], initialnoise, vehicle2[sim], initialnoise, times.shape[0], timeres, noise, 100)
truth = [] results = defaultdict(list) for sim in range(nsims): veh1 = vehicle1[sim, :] veh2 = vehicle2[sim, :] veh1 = motionModels.initialState_normal(veh1, initialcovariance) veh2 = motionModels.initialState_normal(veh2, initialcovariance) # find 'true' collision occurrences by using very high-res MCS alarm pred, rt = alarms.alarm_truth(veh1, veh2, MM1, MM2, np.array(times)) truth += [pred] results['optimal'] += [(pred, rt)] for nSamples in mc_samplecounts: result = alarms.alarm_MCS(veh1, veh2, MM1, MM2, times, nSamples) label = str(nSamples) + " MCS" results[label] += [result] result = model.alarm(veh1, veh2, MM1, MM2, times) results['MLP'] += [result] result = alarms.alarm_expected(veh1, veh2, MM1, MM2, times) results['expected'] += [result] result = alarms.alarm_UT_1(veh1, veh2, MM1, MM2, times) results['UT 1'] += [result] result = alarms.alarm_UT_2(veh1, veh2, MM1, MM2, times) results['UT 2'] += [result]
v2 = np.random.normal(10., 5., nsims) x2 = np.random.normal(-5, 2., nsims) - timeback * v2 vehicle2 = np.array((x2, v2)).T print "running" truth = [] results = defaultdict(list) for sim in range(nsims): veh1 = vehicle1[sim, :] veh2 = vehicle2[sim, :] veh1 = motionModels.initialState_normal(veh1, initialcovariance) veh2 = motionModels.initialState_normal(veh2, initialcovariance) # find 'true' collision occurrences by using very high-res MCS alarm pred, rt = alarms.alarm_MCS(veh1, veh2, MM1, MM2, np.array(times), 10000) truth += [pred] results['optimal'].append((pred, rt)) # estimators starttime = timer() result = alarms_nb.alarm_MCSroad(vehicle1[sim], initialcovariance, vehicle2[sim], initialcovariance, times.shape[0], timeres, noise, 10) time = timer() - starttime results['MC 10'].append((result, time)) starttime = timer() result = alarms_nb.alarm_MCSroad(vehicle1[sim], initialcovariance, vehicle2[sim], initialcovariance, times.shape[0], timeres, noise, 100)