tree_structured.structured_data

Generate a structure for the dataset.

Module Contents

Classes

StructuredData

Generate a structure for the dataset.

class tree_structured.structured_data.StructuredData(n_input_each_box: list[int] | numpy.typing.NDArray[numpy.int_])

Bases: noisecut.tree_structured.base_structured_data.BaseStructuredData

Generate a structure for the dataset.

StructuredData class consist of some attributes and methods to keep track of the structure of the data with binary functions related to black boxes.

Parameters:

n_input_each_box ({list, ndarray} of int of shape (n_box,)) –

An array of size n_box (number of first-layer black boxes) which keeps number of input features to each box. For instance, when n_input_each_box=[2, 4, 1], it means there are three first-layer black boxes and number of input features to box1, box2 and box3 is 2, 4, and 1, respectively.

Note: There is only one black box in the second-layer.

all_f

List of BinaryFunction objects to store data related to function of each first-layer black box. For instance, all_f[0] is a variable of type BinaryFunction which keeps info of box1 which exists in the first-layer black boxes.

Type:

list of BinaryFunction of len n_box

black_box_f

A BinaryFunction object to store info of the second-layer black box.

Note: There is only one black box in the second-layer.

Type:

BinaryFunction

__set_start_index_function() None

Set i_func array.

Set i_func array which keeps widely-used values in some of the methods of this class. For instance, if n_input_each_box = [2, 4, 1], i_func is set to [0, 0+2, 0+2+4, 0+2+4+1] = [0, 2, 6, 7].

set_binary_function_of_box(id_box: int, func: list[bool] | numpy.typing.NDArray[numpy.bool_]) None

Return the binary function of the requested box.

Parameters:
  • id_box (int) – Index of the box, it starts from zero.

  • func (ndarray of shape(2**n_input_each_box[id_box],)) – Binary function.

get_binary_function_of_box(id_box: int) numpy.typing.NDArray[numpy.bool_]

Return the binary function of the requested box.

Parameters:

id_box (int) – Index of the box, it starts from zero.

Returns:

Binary function of the id_box.

Return type:

ndarray of bool of shape (2**`self.n_input_each_box[id_box]`,)

set_binary_function_black_box(func: list[bool] | numpy.typing.NDArray[numpy.bool_]) None

Return binary function of the 2nd-layer black box.

Parameters:

func (ndarray of bool of shape (2**n_box,)) – Binary function of the 2nd-layer black box.

get_binary_function_black_box() numpy.typing.NDArray[numpy.bool_]

Return binary function of the 2nd-layer black box.

Returns:

Binary function of the output box.

Return type:

ndarray of bool of shape (2**n_box,)

convert_decimal_index_to_decimal(decimal_index: numpy.typing.NDArray[numpy.int_]) int

Convert decimal_index to decimal (see Notes).

Parameters:

decimal_index (ndarray of shape (n_box,)) – See Notes.

Returns:

Decimal number.

Return type:

int

Notes

To understand the definition of the terms better let’s consider, n_box=3 and n_input_each_box = [2, 4, 1]. One valid binary input feature can be as reverse_binary = [0, 1, 1, 1, 0, 1, 1].

reverse_binaryndarray of shape (dimension,)

Binary representation of a value in which first element in the array has the least value.

decimal_indexndarray of shape (n_box,)

Each element of the array stores the decimal representation of the binary input feature to each box. For instance, based on the above example, decimal index of the reverse_binary is as [decimal(0, 1), decimal(1, 1, 0, 1), decimal(1)] = [2, 11, 1].

decimalint

Decimal value of a reverse_binary. For instance, based on the above example, the decimal value of reverse_binary is 110 (decimal = (2**0)*0 + (2**1)*1 + (2**2)*1 + (2**3)*1+ (2**4)*0 + (2**5)*1 + (2**6)*1 = 110).

static convert_decimal_to_reverse_binary(decimal_number: int, dim: int) numpy.typing.NDArray[numpy.bool_]

Convert decimal to reverse_binary (see Notes).

Parameters:
  • decimal_number (int) – See Notes.

  • dim (int) – Length of the binary number.

Returns:

Reverse binary.

Return type:

ndarray of bool of shape(dim, )

Notes

To understand the definition of the terms better let’s consider, n_box=3 and n_input_each_box = [2, 4, 1]. One valid binary input feature can be as reverse_binary = [0, 1, 1, 1, 0, 1, 1].

reverse_binaryndarray of shape (dimension,)

Binary representation of a value in which first element in the array has the least value.

decimal_indexndarray of shape (n_box,)

Each element of the array stores the decimal representation of the binary input feature to each box. For instance, based on the above example, decimal index of the reverse_binary is as [decimal(0, 1), decimal(1, 1, 0, 1), decimal(1)] = [2, 11, 1].

decimalint

Decimal value of a reverse_binary. For instance, based on the above example, the decimal value of reverse_binary is 110 (decimal = (2**0)*0 + (2**1)*1 + (2**2)*1 + (2**3)*1+ (2**4)*0 + (2**5)*1 + (2**6)*1 = 110).

static convert_reverse_binary_to_decimal(reverse_binary: numpy.typing.NDArray[numpy.bool_]) int

Convert reverse_binary to decimal(see Notes).

Parameters:

reverse_binary (ndarray of shape (dim,)) – See Notes.

Returns:

Decimal value.

Return type:

int

Notes

To understand the definition of the terms better let’s consider, n_box=3 and n_input_each_box = [2, 4, 1]. One valid binary input feature can be as reverse_binary = [0, 1, 1, 1, 0, 1, 1].

reverse_binaryndarray of shape (dimension,)

Binary representation of a value in which first element in the array has the least value.

decimal_indexndarray of shape (n_box,)

Each element of the array stores the decimal representation of the binary input feature to each box. For instance, based on the above example, decimal index of the reverse_binary is as [decimal(0, 1), decimal(1, 1, 0, 1), decimal(1)] = [2, 11, 1].

decimalint

Decimal value of a reverse_binary. For instance, based on the above example, the decimal value of reverse_binary is 110 (decimal = (2**0)*0 + (2**1)*1 + (2**2)*1 + (2**3)*1+ (2**4)*0 + (2**5)*1 + (2**6)*1 = 110).

calc_output_structured_system(x_binary_number: numpy.typing.NDArray[numpy.bool_]) numpy.bool_

Calculate output of the structured system for x_binary_number.

Parameters:

x_binary_number (ndarray of bool of shape (dimension,)) – Input binary array to the system.

Returns:

Binary output for x_binary_number.

Return type:

bool

calc_decimal_input_structured_system_to_black_box(x_binary_number: numpy.typing.NDArray[numpy.bool_]) int

Return decimal value of the binary input to the second-layer black box.

Parameters:

x_binary_number (ndarray of shape (dimension,)) – Array of binary values as the input of the structured system.

Returns:

Decimal value.

Return type:

int

Examples

Let’s consider, n_box=3 and n_input_each_box = [2, 4, 1]. One valid binary input feature can be as reverse_binary = [0, 1, 1, 1, 0, 1, 1]. decimal value to the 2nd-layer black box is calculated as follows: decimal( [func_box1(0, 1), func_box1(1, 1, 0, 1), func_box3(1)] )=decimal( [0, 1, 1] ) = 6.

calc_output_structured_system_multiple_input(multiple_x_binary: numpy.typing.NDArray[numpy.bool_]) numpy.typing.NDArray[numpy.bool_]

Return output of the structured system to more than one input.

Parameters:

multiple_x_binary (ndarray of shape (dimension,n_samples)) – Each row of the multiple_x_binary array is a binary input value to the structured system.

Returns:

Output of the system in one_to_one mapping of binary input multiple_x_binary.

Return type:

ndarray of shape (n_samples,)

build_complete_data_set_y_array() numpy.typing.NDArray[numpy.bool_]

Return complete dataset output.

Return output of the structured system to any combination of input features in an order. Index of the output array is equivalent to decimal value of the reverse binary input.

Returns:

Output of the system.

Return type:

ndarray of bool of shape (2**dimension,)

Examples

For instance, consider a structured system with dimension=5. y[ 1] is the output of the structured system to binary input [1, 0, 0, 0, 0]. y[22] is the output of the structured system to binary input [1, 0, 1, 1, 0].

get_complete_data_set(file_name: str | None = None) tuple[numpy.typing.NDArray[numpy.bool_], numpy.typing.NDArray[numpy.bool_]]

Return and write output of the system to all possible input binaries.

Parameters:

file_name (str, default=None) – Name of the file (with or without the path) in which you aim to store results. If file_name=None, dataset will not be written in a file.

Returns:

  • x (ndarray of bool of shape (2**dimension, dimension)) – Binary input dataset.

  • y (ndarray of bool of shape (2**dimension,)) – Binary output dataset in one_to_one mapping of x.

print_binary_function_model() None

Print all functions of the structured model.