Takes the given functions and makes a function which returns the product of the output of original functions. It works well with functions returning numpy arrays of the same shape. Args: *functions: Base functions for the product. The functions shall have the same argument and
(*functions: Callable, exponents: Optional[Sequence] = None)
| 35 | |
| 36 | |
| 37 | def make_product(*functions: Callable, exponents: Optional[Sequence] = None) -> Callable: |
| 38 | """ |
| 39 | Takes the given functions and makes a function which returns the product of the output of original functions. It |
| 40 | works well with functions returning numpy arrays of the same shape. |
| 41 | |
| 42 | Args: |
| 43 | *functions: Base functions for the product. The functions shall have the same argument and if they return numpy |
| 44 | arrays, the returned arrays shall have the same shape. |
| 45 | exponents: Exponents of the functions in the product. The i-th given function in the product will be raised to |
| 46 | the power of exponents[i]. |
| 47 | |
| 48 | Returns: |
| 49 | A function which returns the product function of the given functions output. |
| 50 | """ |
| 51 | if exponents is None: |
| 52 | exponents = np.ones(shape=(len(functions))) |
| 53 | else: |
| 54 | assert len(functions) == len(exponents), 'the length of exponents must be the ' \ |
| 55 | 'same as the number of given functions' |
| 56 | |
| 57 | def product_function(*args, **kwargs): |
| 58 | return np.prod([functions[i](*args, **kwargs)**exponents[i] |
| 59 | for i in range(len(exponents))], axis=0) |
| 60 | |
| 61 | return product_function |
| 62 | |
| 63 | |
| 64 | def make_query_strategy(utility_measure: Callable, selector: Callable) -> Callable: |
no outgoing calls
no test coverage detected
searching dependent graphs…