def get_actual_value()

in causalml/optimize/utils.py [0:0]


def get_actual_value(treatment, observed_outcome, conversion_value,
                     conditions, conversion_cost, impression_cost):
    '''
    Set the conversion and impression costs based on a dict of parameters.

    Calculate the actual value of targeting a user with the actual treatment group
    using the above parameters.

    Params
    ------
    treatment : array, shape = (num_samples, )
        Treatment array.

    observed_outcome : array, shape = (num_samples, )
        Observed outcome array, aka y.

    conversion_value : array, shape = (num_samples, )
        The value of converting a given user.

    conditions : list, len = len(set(treatment))
        List of treatment conditions.

    conversion_cost : array, shape = (num_samples, num_treatment)
        Array of conversion costs for each unit in each treatment.

    impression_cost : array, shape = (num_samples, num_treatment)
        Array of impression costs for each unit in each treatment.

    Returns
    -------
    actual_value : array, shape = (num_samples, )
        Array of actual values of havng a user in their actual treatment group.

    conversion_value : array, shape = (num_samples, )
        Array of payoffs from converting a user.
    '''

    cost_filter = [actual_group == possible_group
                   for actual_group in treatment
                   for possible_group in conditions]

    conversion_cost_flat = conversion_cost.flatten()
    actual_cc = conversion_cost_flat[cost_filter]
    impression_cost_flat = impression_cost.flatten()
    actual_ic = impression_cost_flat[cost_filter]

    # Calculate the actual value of having a user in their actual treatment
    actual_value = (conversion_value - actual_cc) * \
        observed_outcome - actual_ic

    return actual_value