Beispiel #1
0
    def arccosh(x):
        """
        Returns a constant, Scalar, or Vector object that is the arccosh of the user specified value.

        INPUTS
        =======
        val: real valued numeric type

        RETURNS
        =======
        Scalar or Vector class instance

        NOTES
        ======
        If the input value is a constant, each operator method returns a constant with the operation
        applied. If the input value is a Scalar object, the operator method applies the operator to the value
        and propagates the derivative through the chain rule, wrapping the results in a new Scalar object. If the
        input value is a vector, the operator method updates the value of the element, and the jacobian of the vector,
        returning a new vector object with these properties.
        """
        try:
            j = x._jacobian
        except AttributeError:
            return np.arccosh(x)  # If x is a constant
        else:
            try:
                k = j.keys()  # To tell whether x is a scalar or vector
            except AttributeError:
                new = Vector(np.arccosh(x._val),
                             x._jacobian)  # If x is a vector variable
                try:
                    dict_self = x._dict.copy(
                    )  # If x is a complex vector variable, it will update the original dictionary
                    for key in dict_self.keys():
                        dict_self[key] = dict_self[key] * -np.arccosh(
                            x._val) * np.tanh(x._val)
                    new._dict = dict_self
                    return new
                except AttributeError:
                    derivative = Counter()
                    derivative[x] = x._jacobian * -np.arccosh(
                        x._val) * np.tanh(x._val)
                    new._dict = derivative  # If x is not a complex vector variable, it will add an attribute to the new variable
                    return new
            else:
                jacobian = {
                    k: x.partial(k) * -np.arccosh(x._val) * np.tanh(x._val)
                    for k in x._jacobian.keys()
                }
                return Scalar(np.arccosh(x._val), jacobian)
Beispiel #2
0
    def create_vector(vals):
        '''
        Return a list of vector variables with values as defined in vals

        INPUTS
        ======
        vals: list of lists of floats, compulsory
            Value of the list of Vector variables

        RETURNS
        ========
        A list of Vector variables

        '''
        vectors = [None] * len(vals)
        for i in range(len(vals)):
            vectors[i] = Vector(vals[i])
        return vectors
Beispiel #3
0
import numpy as np
from Dotua.nodes.vector import Vector
'''
Test for vector variable basic functions and the jacobian of vector function to vector
'''

# Define vector objects
x = Vector([1, 2])
y = Vector([0, 1])
z = Vector([2, 1])
a = Vector([0, 0])
b = Vector([1, 1])
c = Vector([1, 0])

f_1 = x[0] + x[1]
f_2 = x[0] - 3 - x[1] - x[1]
f_3 = 1 + x[1] - x[0] * x[1] - x[0] - 3
f_4 = 3 / x[0] + (x[0] * x[1]) / 2 - 4 * x[1]
f_5 = x[0]**3 + x[1] / x[0]
f_6 = 2**x[1]
f_7 = 3 + x + y - 2
f_8 = -1 - x - y - 3
f_9 = 3 * x + y * 2 + x * y
f_10 = y / 3 + 2 / x + y / x
f_11 = z + x
f_12 = z + a
f_13 = f_11 + f_12
f_14 = b - 1
f_15 = f_11 - f_12
f_16 = c - f_11
f_17 = f_11 - x