How to use the deepxde.config.real function in DeepXDE

To help you get started, we’ve selected a few DeepXDE examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github lululxvi / deepxde / deepxde / geometry / geometry_1d.py View on Github external
def uniform_boundary_points(self, n):
        if n == 1:
            return np.array([[self.l]]).astype(config.real(np))
        xl = np.full((n // 2, 1), self.l).astype(config.real(np))
        xr = np.full((n - n // 2, 1), self.r).astype(config.real(np))
        return np.vstack((xl, xr))
github lululxvi / deepxde / deepxde / data / ide.py View on Github external
def losses_test():
            int_mat = self.get_int_matrix(False)
            f = self.pde(model.net.x, outputs, int_mat)
            if not isinstance(f, (list, tuple)):
                f = [f]
            return [loss(tf.zeros(tf.shape(fi)), fi) for fi in f] + [
                tf.constant(0, dtype=config.real(tf)) for _ in self.bcs
            ]
github lululxvi / deepxde / deepxde / fractional.py View on Github external
raise AssertionError("No dynamic points")

        if sparse:
            print("Generating sparse fractional matrix...")
            dense_shape = (self.x0.shape[0], self.x.shape[0])
            indices, values = [], []
            beg = self.x0.shape[0]
            for i in range(self.x0.shape[0]):
                for _ in range(array_ops.shape(self.w[i])[0]):
                    indices.append([i, beg])
                    beg += 1
                values = array_ops.hstack((values, self.w[i]))
            return indices, values, dense_shape

        print("Generating dense fractional matrix...")
        int_mat = np.zeros((self.x0.shape[0], self.x.shape[0]), dtype=config.real(np))
        beg = self.x0.shape[0]
        for i in range(self.x0.shape[0]):
            int_mat[i, beg : beg + self.w[i].size] = self.w[i]
            beg += self.w[i].size
        return int_mat
github lululxvi / deepxde / deepxde / geometry / geometry_1d.py View on Github external
def log_uniform_points(self, n, boundary=True):
        eps = 0 if self.l > 0 else np.finfo(config.real(np)).eps
        l = np.log(self.l + eps)
        r = np.log(self.r + eps)
        if boundary:
            x = np.linspace(l, r, num=n, dtype=config.real(np))[:, None]
        else:
            x = np.linspace(l, r, num=n + 1, endpoint=False, dtype=config.real(np))[
                1:, None
            ]
        return np.exp(x) - eps
github lululxvi / deepxde / deepxde / array_ops.py View on Github external
def convert_to_array(value):
    """Convert a list to numpy array or tensorflow tensor."""
    if istensorlist(value):
        return tf.convert_to_tensor(value, dtype=config.real(tf))
    value = np.array(value)
    if value.dtype != config.real(np):
        return value.astype(config.real(np))
    return value
github lululxvi / deepxde / deepxde / maps / opnn.py View on Github external
def build(self):
        print("Building operator neural network...")
        self.X_func = tf.placeholder(config.real(tf), [None, self.layer_size_func[0]])
        self.X_loc = tf.placeholder(config.real(tf), [None, self.layer_size_loc[0]])

        # Function NN
        y_func = self.X_func
        if self.stacked:
            # Stacked
            stack_size = self.layer_size_func[-1]
            for i in range(1, len(self.layer_size_func) - 1):
                y_func = self.stacked_dense(
                    y_func, self.layer_size_func[i], stack_size, self.activation
                )
            y_func = self.stacked_dense(y_func, 1, stack_size, use_bias=self.use_bias)
        else:
            # Unstacked
            for i in range(1, len(self.layer_size_func) - 1):
                y_func = self.dense(
                    y_func,
github lululxvi / deepxde / deepxde / fractional.py View on Github external
def modify_third_order(self, x=None, w=None):
        w0 = np.hstack(([config.real(np)(0)], w))
        w1 = np.hstack((w, [config.real(np)(0)]))
        w2 = np.hstack(([config.real(np)(0)] * 2, w[:-1]))
        beta = 1 - self.alpha / 2
        w = (
            (-6 * beta ** 2 + 11 * beta + 1) / 6 * w0
            + (11 - 6 * beta) * (1 - beta) / 12 * w1
            + (6 * beta + 1) * (beta - 1) / 12 * w2
        )
        if x is None:
            return w
        x = np.vstack(([2 * x[0] - x[1]], x))
        if not self.geom.inside(x[0]):
            return x[1:], w[1:]
        return x, w
github lululxvi / deepxde / deepxde / maps / resnet.py View on Github external
def build(self):
        print("Building residual neural network...")
        self.x = tf.placeholder(config.real(tf), [None, self.input_size])

        y = self.dense(self.x, self.num_neurons, activation=self.activation)
        for _ in range(self.num_blocks):
            y = self.residual_block(y)
        self.y = self.dense(y, self.output_size)

        self.y_ = tf.placeholder(config.real(tf), [None, self.output_size])