def discretize_oversample_2D(model, x_range, y_range, factor=10):
 x = np.arange((x_range[0] - (0.5 * (1 - (1 / factor)))), (x_range[1] + (0.5 * (1 + (1 / factor)))), (1.0 / factor))
 y = np.arange((y_range[0] - (0.5 * (1 - (1 / factor)))), (y_range[1] + (0.5 * (1 + (1 / factor)))), (1.0 / factor))
 (x_grid, y_grid) = np.meshgrid(x, y)
 values = model(x_grid, y_grid)
 shape = ((y.size // factor), factor, (x.size // factor), factor)
 values = np.reshape(values, shape)
 return values.mean(axis=3).mean(axis=1)[:(-1), :(-1)]

def discretize_oversample_2D ( model , x_range , y_range , factor = 10 ) : x = np . arange ( ( x_range [ 0 ] - ( 0.5 * ( 1 - ( 1 / factor ) ) ) ) , ( x_range [ 1 ] + ( 0.5 * ( 1 + ( 1 / factor ) ) ) ) , ( 1.0 / factor ) ) y = np . arange ( ( y_range [ 0 ] - ( 0.5 * ( 1 - ( 1 / factor ) ) ) ) , ( y_range [ 1 ] + ( 0.5 * ( 1 + ( 1 / factor ) ) ) ) , ( 1.0 / factor ) ) ( x_grid , y_grid ) = np . meshgrid ( x , y ) values = model ( x_grid , y_grid ) shape = ( ( y . size // factor ) , factor , ( x . size // factor ) , factor ) values = np . reshape ( values , shape ) return values . mean ( axis = 3 ) . mean ( axis = 1 ) [ : ( - 1 ) , : ( - 1 ) ]
discretize model by taking the average on an oversampled grid .