tree_structured.binary_function

Binary Function.

Module Contents

Classes

BinaryFunction

BinaryFunction class helps to define a binary function and work with.

class tree_structured.binary_function.BinaryFunction(n_binary_input: int)

BinaryFunction class helps to define a binary function and work with.

Parameters:

n_binary_input (int) – It should be greater than zero. n_binary_input value is number of input features to a binary function.

n_diff_states

Number of possible unique arrangements of the binary function. For instance, if n_binary_input=2, then there are 2**2=4 possible unique arrangements for this function. [0,0], [1,0], [0,1], [1,1].

Type:

int

function

For each unique arrangement of the binary input, function store one binary value as a response of the function to that input arrangement. Also, the binary values are stored in an order.

For instance, if n_binary_input=2,

function[0] stores the boolean response of the function to [0, 0] as (2**0)* 0 + (2**1)* 0 = 0.

function[1] stores the boolean response of the function to [1, 0] as (2**0)* 1 + (2**1)* 0 = 1.

function[2] stores the boolean response of the function to [0, 1] as (2**0)* 0 + (2**1)* 1 = 2.

function[3] store the boolean response of the function to [1, 1] as (2**0)* 1 + (2**1)* 1 = 3.

Type:

ndarray of bool of size (n_diff_states,)

w

In NoiseCut model each box has a binary function. This array is used for storing calculated weights of the function in NoiseCut model.

Type:

ndarray of size (), default = None

set_random_binary_function() None

Set binary function values randomly.

set_binary_function_manually(input_function: list[bool] | numpy.typing.NDArray[numpy.bool_]) None

Set binary function values by the input_function.

Parameters:

input_function ({array_like, ndarray} of size (n_diff_states,)) – Input binary function value to set function with it.

calc_output_func(binary_input: list[bool] | numpy.typing.NDArray[numpy.bool_]) numpy.bool_

Return calculated output of the function based on the binary input.

Parameters:

binary_input (ndarray of size n_binary_input) – Input array to the binary function.

Returns:

Output of function for binary_input as input.

Return type:

bool

__repr__() str

Return repr(self).

__convert_decimal_to_reverse_binary(decimal: int) numpy.typing.NDArray[numpy.bool_]

Convert decimal to reverse_binary.

Parameters:

decimal (int) – See Notes section below.

Returns:

Return reverse binary of the decimal value.

Return type:

ndarray of bool of shape(n_binary_input, )

Notes

to understand the definition of the terms better let’s consider, n_binary_input=4:

reverse_binaryndarray of shape (dimension,)

binary representation of a value in which first element in the array has the least value. For instance, reverse_binary representation of decimal=7 is [1, 1, 1, 0].

decimalint

decimal value of a reverse_binary. For instance, the decimal value of reverse_binary=[1, 1, 1, 0] is 7 (decimal = ( 2**0)*1 + (2**1)*1 + (2**2)*1 + (2**3)*0 = 7).

get_str_info_function(prev_feature: int = 1, name_input: str = 'feature_') str

Return information of function in string format.

Parameters:
  • prev_feature (int) – Index of the first input to the function (just for naming purpose).

  • name_input (str) – String name to show what is exactly the input to the function.

Returns:

Information of function.

Return type:

str

static validate_n_binary_input_binary_function(n_binary_input: Any) None

Validate n_binary_input if it is integer and greater than 0.

Parameters:

n_binary_input ({float, int}) – Input value for n_binary_input to be validated.

static validate_binary_input(binary_input: list[bool] | numpy.typing.NDArray[numpy.bool_], expected_size: int) tuple[bool, numpy.typing.NDArray[numpy.bool_]]

Validate binary_input as expected to match the expected_size.

Parameters:
  • binary_input ({array-like, ndarray} of bool) – Input array to the binary function.

  • expected_size (int) – Expected size of the binary_input array.

Returns:

  • status (bool) – True if binary_input is a valid input.

  • binary_input (ndarray of bool) – Validated binary_input.