Skip to content

Latest commit

 

History

History
220 lines (129 loc) · 5.6 KB

math_func.md

File metadata and controls

220 lines (129 loc) · 5.6 KB

module math_func

General math function nodes for the simulation.

Classes:

  • Identity: A node that returns the input. Mainly for testing.

  • Sum: A node that sums some inputs element-wise.

  • Product: A node that multiplies some inputs element-wise.


class Identity

A node that returns the input.

Examples:

    >>> Identity("identity", "arr")(np.array([1, 2, 3]))
    array([1, 2, 3])
    >>> Identity("identity", "hap")(
        (np.array([1, 2, 3]), np.array([4, 5, 6]))
    )
    (array([1, 2, 3]), array([4, 5, 6]))

method __init__

__init__(alias: str, input_alias: str)

Initialize Identity node.

Args:

  • alias: The alias of the node.
  • input_alias: The alias of the input node.

method run

run(input_vals)

Return the input.


class Sum

A node that sums some inputs element-wise.

If all inputs are vectors (num_samples length arrays), then the output is a vector that is the element-wise sum of the inputs.

If all inputs are all matrices (num_feats x num_samples arrays), then the output is a matrix (with the same dimensions) that is the element-wise sum.

If the input is a mix of vectors and matrices: - All matrices must have the same dimensions. - Matrices are summed element-wise. - Vectors are summed element-wise over each of the num_feats of the matrices.

Examples:

    >>> Sum("sum", ["arrs"])([np.array([1, 2, 3]), np.array([4, 5, 6])])
    array([5, 7, 9])

    >>> Sum("sum", ["arrs"])([
        np.array([[1, 2, 3], [4, 5, 6]]),
        np.array([[7, 8, 9], [10, 11, 12]])
    ])
    array([[ 8, 10, 12],
           [14, 16, 18]])
    
    >>> Sum("sum", ["arrs"])([
        np.array([1, 2, 3]),
        np.array([[1, 1, 1], [2, 2, 2]]),
        np.array([[1, 1, 1], [2, 2, 2]])
    ])
    array([[3, 4, 5],
           [5, 6, 7]])

method __init__

__init__(alias: str, input_aliases: list)

Initialize Sum node.

Args:

  • alias: The alias of the node.
  • input_aliases (list): The aliases of the inputs to be summed.

method run

run(*input_vals)

Return the sum of the inputs.


class Product

A node that multiplies some inputs element-wise.

If all inputs are vectors (num_samples length arrays), then the output is a vector that is the element-wise product of the inputs.

If all inputs are all matrices (num_feats x num_samples arrays), then the output is a matrix (with the same dimensions) that is the element-wise product.

If the input is a mix of vectors and matrices: - All matrices must have the same dimensions. - Matrices are multiplied element-wise. - Vectors are multiplied element-wise over each of the num_feats of the matrices.

Examples:

    >>> Product("product", ["arrs"])(
        [np.array([1, 2, 3]), np.array([4, 5, 6])]
    )
    array([ 4, 10, 18])

    >>> Product("product", ["arrs"])([
        np.array([[1, 2, 3], [4, 5, 6]]),
        np.array([[7, 8, 9], [10, 11, 12]])
    ])
    array([[ 7, 16, 27],
           [40, 55, 72]])
    
    >>> Product("product", ["arrs"])([
        np.array([1, 2, 3]),
        np.array([[1, 1, 1], [2, 2, 2]]),
        np.array([[1, 1, 1], [2, 2, 2]])
    ])
    array([[1, 2, 3],
           [4, 8, 12]])

method __init__

__init__(alias: str, input_aliases: list)

Initialize Product node.

Args:

  • alias: The alias of the node.
  • input_aliases (list): The aliases of the inputs to be multiplied.

method run

run(*input_vals)

Return the product of the inputs.


This file was automatically generated via lazydocs.