A model for a learning thermostat