Пример #1
0
    def new_target(self, uav, noisy_states):
        ogrid = [np.linspace(*dim, num=res) for dim, res in zip(
            self.get_effective_area(), self.grid_resolution)]
        x, y, z = meshgrid_nd(*ogrid)
        acq = self.acquisition_fn(
            np.column_stack((x.flat, y.flat, z.flat)), uav, noisy_states)
        max_idx = np.unravel_index(np.argmax(acq), x.shape)
        x0 = np.array([x[max_idx], y[max_idx], z[max_idx]])

        x, val, unused = fmin_l_bfgs_b(
            NegateFn(self.acquisition_fn).eval_with_derivative, x0,
            args=(uav, noisy_states,), bounds=self.get_effective_area(),
            pgtol=1e-10, factr=1e2)

        idx = np.argmax(self.acquisition_fn.predictor.y_train.data)
        x0 = np.asarray(noisy_states[uav].position)
        for dx in 5 * rnd.randn(5):
            x2, val2, unused = fmin_l_bfgs_b(
                NegateFn(self.acquisition_fn).eval_with_derivative, x0 + dx,
                args=(uav, noisy_states,), bounds=self.get_effective_area(),
                pgtol=1e-10, factr=1e2)
            if val2 < val:
                x = x2

        idx = np.argmax(self.acquisition_fn.predictor.y_train.data)
        x0 = self.acquisition_fn.predictor.x_train.data[idx]
        for dx in 5 * rnd.randn(5):
            x2, val2, unused = fmin_l_bfgs_b(
                NegateFn(self.acquisition_fn).eval_with_derivative, x0 + dx,
                args=(uav, noisy_states,), bounds=self.get_effective_area(),
                pgtol=1e-10, factr=1e2)
            if val2 < val:
                x = x2

        return [x]
Пример #2
0
    def init(self, conf):
        area = conf['area']
        self.area = np.asarray(area)

        self._positions = self.fileh.createEArray(
            self.fileh.root, 'positions', tables.FloatAtom(),
            (self.client.numUAVs, 0, 3), expectedrows=self.expected_steps,
            title='Noiseless positions (numUAVs x timesteps x 3) of the UAVs '
            'over time.')
        self.fileh.createArray(
            self.fileh.root, 'sample_locations', self.client.get_locations(),
            title='Locations where prediction was requested '
            '(num locations x 3)')
        self.fileh.createArray(
            self.fileh.root, 'reference_samples',
            np.asarray(self.client.get_reference_samples()),
            title='Reference samples (num locations)')

        ogrid = [np.linspace(*dim, num=res) for dim, res in zip(
            area, [29, 29, 9])]
        x, y, z = meshgrid_nd(*ogrid)
        locations = np.column_stack((x.flat, y.flat, z.flat))
        self.fileh.createArray(
            self.fileh.root, 'gt_locations', locations,
            title='Locations where ground truth was evaluated '
            '(num locations x 3)')
        self.fileh.createArray(
            self.fileh.root, 'gt_samples',
            np.asarray(self.client.get_samples(locations)),
            title='Ground truth samples (num locations)')
Пример #3
0
def predict_on_volume(predictor, area, grid_resolution):
    ogrid = [np.linspace(*dim, num=res) for dim, res in zip(
        area, grid_resolution)]
    x, y, z = meshgrid_nd(*ogrid)

    pred, mse = predictor.predict(
        np.column_stack((x.flat, y.flat, z.flat)), eval_MSE=True)
    np.maximum(0, pred, out=pred)

    assert x.shape == y.shape and y.shape == z.shape
    pred = pred.reshape(x.shape)
    mse = mse.reshape(x.shape)
    return pred, mse, (x, y, z)
Пример #4
0
 def _plot_plume(self):
     area = self.conf['area']
     ogrid = [np.linspace(*dim, num=res) for dim, res in zip(
         area, (29, 29, 9))]
     x, y, z = meshgrid_nd(*ogrid)
     values = griddata(
         self.data.root.gt_locations.read(),
         self.data.root.gt_samples.read(),
         np.column_stack((x.flat, y.flat, z.flat))).reshape(x.shape)
     self._truth_volume = self.plot_volume2(
         (x, y, z), values, 0.1, figure=self.truth.mayavi_scene)
     if not self.plain:
         mlab.points3d(
             *self.data.root.sample_locations.read().T, scale_factor=5,
             color=(0.7, 0.0, 0.0), figure=self.truth.mayavi_scene)