Skip to content

Commit

Permalink
fix(optimization), #561: Use float32 for fmin error function.
Browse files Browse the repository at this point in the history
  • Loading branch information
vinci1it2000 committed Nov 6, 2019
1 parent 36de470 commit ea8fde2
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 4 deletions.
3 changes: 2 additions & 1 deletion co2mpas/core/model/physical/clutch_tc/torque_converter.py
Original file line number Diff line number Diff line change
Expand Up @@ -198,7 +198,8 @@ def calibrate_m1000_curve_factor(
)

def _err(factor):
return mae(ds, np.nan_to_num(predict((gbs, gbt / factor)) - es))
e = mae(ds, np.nan_to_num(predict((gbs, gbt / factor)) - es))
return np.float32(e)

return fmin(_err, default_m1000_curve_factor(full_load_curve))

Expand Down
9 changes: 6 additions & 3 deletions co2mpas/core/model/physical/control/hybrid.py
Original file line number Diff line number Diff line change
Expand Up @@ -220,6 +220,7 @@ def _invert(y, xp, fp):
with np.errstate(divide='ignore', invalid='ignore'):
x = xp[:-1] + (np.diff(xp) / np.diff(fp)) * (y[:, None] - fp[:-1])
b = (xp[:-1] - dfl.EPS <= x) & (x <= (xp[1:] + dfl.EPS))
# noinspection PyUnresolvedReferences
return x[np.arange(b.shape[0]), np.nanargmax(b, 1)], y


Expand Down Expand Up @@ -286,7 +287,7 @@ def _interp(x, xp, fp):
return (x - x0) * np.where(np.isclose(dx, 0), 0, dy / dx) + y0, x


# noinspection PyMissingOrEmptyDocstring
# noinspection PyMissingOrEmptyDocstring,PyArgumentEqualDefault
class HEV:
def __init__(self, drive_line_efficiencies, motors_efficiencies):

Expand Down Expand Up @@ -544,6 +545,7 @@ def define_serial_motor_maximum_power_function(
def calculate_serial_motor_maximum_power(engine_speed, final_drive_speed):
es = np.atleast_1d(engine_speed)
ps = func(engine_speed, final_drive_speed, planetary_ratio)
# noinspection PyArgumentEqualDefault
return np.pad(
np.column_stack((
planet_f(ps * motor_p2_planetary_speed_ratio),
Expand Down Expand Up @@ -698,6 +700,7 @@ def serial(self, times, motive_powers, final_drive_speeds_in,
motors_maximums_powers, engine_speeds_out=None,
ice_power_losses=None, battery_power_losses=0, opt=True):
hev, fc, n = self.hev_power_model, self.fuel_map_model, 200
# noinspection PyArgumentEqualDefault
pi, pb, bps_ev = hev.ice_power(motive_powers, np.pad(
motors_maximums_powers[:, :-3], ((0, 0), (0, 3)), 'constant'
))
Expand Down Expand Up @@ -1104,9 +1107,9 @@ def fit(self, ems_data, on_engine, drive_battery_state_of_charges,
def _(x):
x = x.valuesdict()
time = x['starter_time']
return np.maximum(0, s * (self._k(x, soc) - np.where(
return np.float32(np.maximum(0, s * (self._k(x, soc) - np.where(
~on_engine, *self.reference(ems_data, time)['k_reference'].T
)[b].T)).sum()
)[b].T)).sum())

p = lmfit.Parameters()
starter_time = self.starter_model.time
Expand Down

0 comments on commit ea8fde2

Please sign in to comment.