Memory-based (lazy) value approximation stores training examples and only computes a value when a query state arrives, from the stored examples closest to it.
Write memory_based_value(memory_states, memory_targets, query, method="nearest", k=5, tau=1.0):
memory_states has shape (m, d) (or (m,) for scalar states), memory_targets has shape (m,) and query is one state of dimension .method="nearest": return the target of the single nearest example.method="weighted": return the weighted average of the nearest targets with weights .method="lwr": locally weighted regression. Fit an affine function to the nearest examples by weighted least squares with the same Gaussian weights (solve with np.linalg.lstsq on the rows scaled by ), and return its value at the query.Return a Python float.