#%% m = 2 d = 2 device = -1 mesh_bound = zeros((2,m)) # mesh_bound[0] = arange(m)-1 # mesh_bound[1] = arange(m)+1 mesh_bound[0] = 0 mesh_bound[1] = 1 mesh_size = array([40,]*m) I = LagrangeInterp(m,d,mesh_bound,mesh_size) I.double() if device>=0: I.cuda(device) mesh_bound[1] += 1/1000 dataset = meshgen(mesh_bound, [1001,1001]) dataset = torch.from_numpy(dataset) dataset = I.interp_coe.data.new(dataset.size()).copy_(dataset) dataset = Variable(dataset) mesh_bound[1] -= 1/1000 IFixInputs = LagrangeInterpFixInputs(dataset,m,d,mesh_bound,mesh_size) IFixInputs.double() if device>=0: IFixInputs.cuda(device) ax = plt.figure().add_subplot(1,1,1) ax.imshow(I(dataset).data.cpu().numpy()) #%% nfi = NumpyFunctionInterface([I.interp_coe,],forward=lambda :forward(I,dataset)) nfi.flat_param = random.randn(nfi.numel()) x,f,d = lbfgsb(nfi.f,nfi.flat_param,nfi.fprime,m=1000,factr=1,pgtol=1e-14,iprint=10) infe,infe_true = compare(I, dataset)
#%% m = 3 d = 2 device = -1 mesh_bound = zeros((2, m)) # mesh_bound[0] = arange(m)-1 # mesh_bound[1] = arange(m)+1 mesh_bound[0] = 0 mesh_bound[1] = 1 mesh_size = array([ 40, ] * m) I = Interp(m, d, mesh_bound, mesh_size, device=device) mesh_bound[1] += 1 / 200 dataset = meshgen(mesh_bound, [201, 201, 201]) dataset = torch.from_numpy(dataset).clone() dataset = I.interp_coe.data.new(dataset.size()).copy_(dataset) nfi = NumpyFunctionInterface([ I.interp_coe, ], forward=lambda: I.forward(dataset)) nfi.flat_param = random.randn(nfi.numel()) x0 = nfi.flat_param #%% inputs_shape = [50, 50, 50] IN, JN, KN = int(200 / inputs_shape[0]), int(200 / inputs_shape[1]), int( 200 / inputs_shape[2]) indx = zeros((IN * JN * KN, 3), dtype=int32) idx = 0 for i in range(IN):