31 lines
885 B
Python
31 lines
885 B
Python
import numpy
|
|
import numpy.typing
|
|
import pdme.util.fast_v_calc
|
|
|
|
|
|
def proportional_cost(a: numpy.ndarray, b: numpy.ndarray) -> numpy.ndarray:
|
|
tops = numpy.max(b / a, axis=-1)
|
|
bottoms = numpy.max(a / b, axis=-1)
|
|
return numpy.maximum(tops, bottoms)
|
|
|
|
|
|
def proportional_costs_vs_actual_measurement(
|
|
dot_inputs_array: numpy.ndarray,
|
|
actual_measurement_array: numpy.ndarray,
|
|
dipoles_to_test: numpy.ndarray,
|
|
) -> numpy.ndarray:
|
|
vals = pdme.util.fast_v_calc.fast_vs_for_dipoleses(
|
|
dot_inputs_array, dipoles_to_test
|
|
)
|
|
return proportional_cost(actual_measurement_array, vals)
|
|
|
|
|
|
def relative_square_diffs(
|
|
approx: numpy.ndarray, target: numpy.ndarray
|
|
) -> numpy.ndarray:
|
|
# Assume that both approx and target are arrays of length m
|
|
# Approx can broadcast if additional indexes to the left
|
|
# diffs.shape = [ m ]
|
|
diffs = (approx - target) ** 2 / (target**2)
|
|
return diffs.sum(axis=-1)
|