Example #1
0
def metric_calibration_status(y_true, y_pred):
    """
    Metric for the `calibration_status`.

    :param y_true:
        Reference calibration_status.
    :type y_true: list

    :param y_pred:
        Predicted calibration_status.
    :type y_pred: list

    :return:
        Error.
    :rtype: list
    """
    return [v[0] for v in y_pred]


#: Metrics to compare outputs with targets.
metrics = sh.map_list(targets, mae, metric_calibration_status)

#: Upper score limits to raise the warnings.
up_limit = {'identified_co2_emissions': 0.5}

#: Prediction model.
# noinspection PyProtectedMember
dsp = sh.Blueprint(
    copy.deepcopy(_fc).add_data('kco2_wltp_correction_factor'), inputs,
    outputs, models)._set_cls(define_sub_model)
Example #2
0
        eng = calculate_gear_box_speeds_in(gears, vel, vsr, sv)
        return calculate_error_coefficients(t_gears, gears, t_eng, eng, vel,
                                            sv)

    def _sort(v):
        e = sh.selector(t_e, v[0], output_type='list')
        return (e[0], -e[1], -e[2]), v[1]

    # Sort by error.
    rank = sorted(
        ((_err(k, m), k, m)
         for k, m in sorted(sh.selector(at_m, data, allow_miss=True).items())),
        key=_sort)

    if rank:
        data['at_scores'] = collections.OrderedDict((k, e) for e, k, m in rank)
        e, k, m = rank[0]
        mdl[sgs], mdl[k] = k, m
        log.debug(
            'at_gear_shifting_model: %s with mean_absolute_error %.3f '
            '[RPM], accuracy_score %.3f, and correlation_coefficient '
            '%.3f.', k, *sh.selector(t_e, e, output_type='list'))

    return mdl


#: Prediction model.
# noinspection PyProtectedMember
dsp = sh.Blueprint(_at_gear, inputs, outputs,
                   models)._set_cls(define_sub_model)
Example #3
0
#: Upper score limits to raise the warnings.
up_limit = sh.map_list(targets, 40)


def select_models(keys, data):
    """
    Select models from data.

    :param keys:
        Model keys.
    :type keys: list

    :param data:
        Cycle data.
    :type data: dict

    :return:
        Models.
    :rtype: dict
    """
    mdl = sh.selector(keys, data, allow_miss=True)
    if 'tyre_dynamic_rolling_coefficient' in mdl:
        mdl.pop('r_dynamic', None)
    return mdl


#: Prediction model.
# noinspection PyProtectedMember
dsp = sh.Blueprint(_physical, inputs, outputs,
                   models)._set_cls(define_sub_model)
Example #4
0
#: Inputs required to run the model.
inputs = [
    'drive_battery_electric_powers', 'times', 'motive_powers', 'accelerations',
    'on_engine', 'starter_currents', 'initial_service_battery_state_of_charge'
]

#: Relevant outputs of the model.
outputs = [
    'alternator_currents', 'service_battery_currents',
    'drive_battery_currents', 'dcdc_converter_currents',
    'service_battery_state_of_charges', 'drive_battery_state_of_charges'
]
#: Targets to compare the outputs of the model.
targets = outputs

#: Weights coefficients to compute the model score.
weights = sh.map_list(targets, 1, 1, 1, 1, 0, 0)

#: Metrics to compare outputs with targets.
metrics = sh.map_list(targets, *([co2_utl.mae] * 6))

#: Upper score limits to raise the warnings.
up_limit = dict.fromkeys(('alternator_currents', 'service_battery_currents',
                          'drive_battery_currents', 'dcdc_converter_currents'),
                         60)

#: Prediction model.
# noinspection PyProtectedMember
dsp = sh.Blueprint(_electrics, inputs, outputs,
                   models)._set_cls(define_sub_model)
Example #5
0
                                                ext=('.dill', )))

dsp.add_function(function=parse_excel_file,
                 inputs=['input_file_name', 'input_file'],
                 outputs=['raw_data'],
                 input_domain=check_file_format)

if _dice is not None:
    _out, _inp = ['base', 'meta', 'dice'], [
        'input_file_name', 'input_file', 'encryption_keys',
        'encryption_keys_passwords'
    ]
    # noinspection PyProtectedMember
    dsp.add_function(function=sh.Blueprint(
        sh.SubDispatchFunction(_dice,
                               function_id='load_ta_file',
                               inputs=_inp[1:],
                               outputs=_out))._set_cls(sh.add_args),
                     description='Load inputs from .co2mpas.ta file.',
                     inputs=_inp,
                     outputs=['raw_data'],
                     filters=[functools.partial(sh.map_list, [_out])],
                     input_domain=functools.partial(check_file_format,
                                                    ext=('.co2mpas.ta', )))

    _out, _inp = ['data', 'dice'], ['input_file_name', 'input_file']
    # noinspection PyProtectedMember
    dsp.add_function(function=sh.Blueprint(
        sh.SubDispatchFunction(_dice, inputs=_inp[1:],
                               outputs=_out))._set_cls(sh.add_args),
                     function_id='load_co2mpas_file',
    :param y_pred:
        Predicted engine speed vector [RPM].
    :type y_pred: numpy.array

    :param after_treatment_warm_up_phases:
        Phases when engine speed is affected by the after treatment warm up [-].
    :type after_treatment_warm_up_phases: numpy.array

    :return:
        Error.
    :rtype: float
    """
    b = after_treatment_warm_up_phases
    if b.any():
        from co2mpas.utils import mae
        return float(mae(y_true[b], y_pred[b]))
    else:
        return 0


#: Metrics to compare outputs with targets.
metrics = sh.map_list(targets, metric_after_treatment_speed_model)

#: Upper score limits to raise the warnings.
up_limit = sh.map_list(targets, 160)

#: Prediction model.
# noinspection PyProtectedMember
dsp = sh.Blueprint(_after_treat, inputs, outputs,
                   models)._set_cls(define_sub_model)
Example #7
0
                     'timestamp'
                 ],
                 outputs=['output_file_name'],
                 input_domain=check_first_arg_false)

if _dice is not None:
    dsp.add_data('co2mpas_version', __version__)
    _out, _inp = ['output_file_name', 'output_file'], [
        'excel_input', 'base', 'start_time', 'excel_output', 'output_folder',
        'report', 'encryption_keys', 'meta', 'sign_key', 'dice', 'timestamp',
        'co2mpas_version'
    ]

    # noinspection PyProtectedMember,PyTypeChecker
    dsp.add_function(function=sh.Blueprint(
        sh.SubDispatchFunction(_dice, inputs=_inp,
                               outputs=_out))._set_cls(sh.add_args),
                     function_id='write_ta_output',
                     description='Write ta output file.',
                     inputs=['type_approval_mode', 'input_file'] + _inp[1:],
                     outputs=_out,
                     input_domain=check_first_arg)
else:
    dsp.add_data('base', description='Base data.')
    dsp.add_data('excel_input', description='Excel input file.')
    dsp.add_data('encryption_keys', description='Encryption keys for TA mode.')
    dsp.add_data('meta', description='Meta data.')
    dsp.add_data('sign_key', description='User signature key for TA mode.')


@sh.add_function(dsp)