def prediction_array(self, time, space_array): # combine time with space dimension space_array = self.space_class(space_array, copy=False) t = DataArray(time * np.ones(space_array.ndata)) if space_array.original_shape is not None: t.original_shape = space_array.original_shape return t.adddim(space_array, type=self.data_class)
def predict(self, time, space_array, force_update=False): """ Generate a prediction from the trained model. Supply single time and spatial sample points in separate arrays If force_update=False then the spatial component is assumed unchanged, so only the time is altered. This is important: updating the spatial sample points loses all cached net paths. """ if self.kde.targets_set and not force_update: self.kde.update_target_times(time) return self.kde.pdf() else: space_array = self.space_class(space_array, copy=False) time_array = DataArray(np.ones(space_array.ndata) * time) targets_array = time_array.adddim(space_array, type=self.data_class) return self.kde.pdf(targets=targets_array)
targets, max_distance=radius, max_split=1e4) k = NetworkKernelEqualSplitLinear(sources.getone(0), 200.) k.set_walker(nw) z = k.pdf() zn = z / max(z) # plt.figure() # itn_net.plot_network() # plt.scatter(nodes[:, 0], nodes[:, 1], marker='x', s=15, c='k') # plt.scatter(*targets.to_cartesian().separate, s=(zn * 20) ** 2) # plt.scatter(*sources.getone(0).cartesian_coords, c='r', s=50) # add time to sources and targets times = DataArray(np.random.rand(num_pts)) sources_st = times.adddim(sources, type=NetworkSpaceTimeData) targets_st = DataArray(np.ones(targets.ndata)).adddim( targets, type=NetworkSpaceTimeData) kst = NetworkTemporalKernelEqualSplit( [sources_st.time.getone(0), sources_st.space.getone(0)], [0.5, 200.]) kst.set_walker(nw) zst = kst.pdf(target_times=targets_st.time) zstn = zst / z.max() # plt.figure() # itn_net.plot_network() # plt.scatter(nodes[:, 0], nodes[:, 1], marker='x', s=15, c='k') # plt.scatter(*targets.to_cartesian().separate, s=(zstn * 20) ** 2) # plt.scatter(*sources.getone(0).cartesian_coords, c=sources_st.time.getone(0), s=50, vmax=1., vmin=0.)