Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
def get_x(self, size):
if self.disc.meshtype == 'static':
if size != self.disc.resolution[0] - 2 + self.disc.nanchor:
raise ValueError('Mesh resolution does not match batch size.')
discreteop = Fractional(self.alpha, self.geom, self.disc, None)
x = discreteop.get_x()
x = np.roll(x, len(x)-1)
elif self.disc.meshtype == 'dynamic':
# x = self.geom.random_points(size-self.disc.nanchor, 'sobol')
x = self.geom.uniform_points(size-self.disc.nanchor, False)
discreteop = Fractional(self.alpha, self.geom, self.disc, x)
x = discreteop.get_x()
if self.disc.nanchor > 0:
x = np.vstack((self.geom.random_boundary_points(self.disc.nanchor, 'sobol'), x))
y = self.func(x)
return x, y, discreteop
def get_x(self, size):
if self.disc.meshtype == 'static':
if size != self.disc.resolution[0] - 2 + self.disc.nanchor:
raise ValueError('Mesh resolution does not match batch size.')
discreteop = Fractional(self.alpha_train, self.geom, self.disc, None)
x = discreteop.get_x()
x = np.roll(x, len(x)-1)
elif self.disc.meshtype == 'dynamic':
x = self.geom.random_points(size-self.disc.nanchor, 'sobol')
discreteop = Fractional(self.alpha_train, self.geom, self.disc, x)
x = discreteop.get_x()
if self.disc.nanchor > 0:
x = np.vstack((self.geom.random_points(self.disc.nanchor, 'sobol'), x))
y = self.func(x)
return x, y, discreteop
def get_x(self, size):
if self.disc.meshtype == 'static':
if size != self.disc.resolution[0] - 2 + self.disc.nanchor:
raise ValueError('Mesh resolution does not match batch size.')
discreteop = Fractional(self.alpha, self.geom, self.disc, None)
x = discreteop.get_x()
x = np.roll(x, len(x)-1)
elif self.disc.meshtype == 'dynamic':
# x = self.geom.random_points(size-self.disc.nanchor, 'sobol')
x = self.geom.uniform_points(size-self.disc.nanchor, False)
discreteop = Fractional(self.alpha, self.geom, self.disc, x)
x = discreteop.get_x()
if self.disc.nanchor > 0:
x = np.vstack((self.geom.random_boundary_points(self.disc.nanchor, 'sobol'), x))
y = self.func(x)
return x, y, discreteop
def get_x_dynamic(self):
self.fracx = Fractional(self.alpha, self.geom, self.disc, self.x0[:, :-1])
xx = self.fracx.get_x()
x = np.empty((len(xx), self.geom.dim+1))
x[:len(self.x0)] = self.x0
beg = len(self.x0)
for i in range(len(self.x0)):
tmp = xx[self.fracx.xindex_start[i]:self.fracx.xindex_start[i+1]]
x[beg: beg+len(tmp), :1] = tmp
x[beg: beg+len(tmp), -1] = self.x0[i, -1]
beg += len(tmp)
return x
def get_matrix_static(self):
print('Warning: assume zero boundary condition.')
n = (self.disc.resolution[0] - 2) * (self.nt - 1)
int_mat = np.zeros((n, n), dtype=config.real(np))
self.fracx = Fractional(self.alpha, self.geom, self.disc, None)
int_mat_one = self.fracx.get_matrix()
beg = 0
for i in range(self.nt - 1):
int_mat[beg:beg+self.disc.resolution[0]-2, beg:beg+self.disc.resolution[0]-2] = \
int_mat_one[1:-1, 1:-1]
beg += self.disc.resolution[0] - 2
return int_mat