1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164
| import numpy as np import torch import torch.nn as nn from typing import Dict, Tuple
class CabinThermalVirtualSensor(nn.Module): """ 座舱热舒适虚拟传感器 基于 MDPI 2025 论文: "Development of Virtual Sensors for Vehicle In-Cabin Temperature Prediction Using Deep Learning" 用少量物理传感器 + AI 推断全舱温度分布 物理传感器(6个): | 位置 | 传感器类型 | 参数 | |------|-----------|------| | 仪表盘 | 温度+湿度 | ±0.5°C, ±3%RH | | 车顶 | 温度 | ±0.5°C | | 副驾座椅 | 温度 | ±0.5°C | | 后排左 | 温度 | ±0.5°C | | 后排右 | 温度 | ±0.5°C | | 挡风玻璃内侧 | 温度 | ±0.5°C | 虚拟推断点(20+): - 驾驶员面部温度 - 驾驶员手部温度 - 方向盘温度 - 座椅表面温度 - 脚部空间温度 - 后视镜附近温度 """ def __init__(self, num_physical: int = 6, num_virtual: int = 20): super().__init__() self.encoder = nn.Sequential( nn.Linear(num_physical + 4, 64), nn.ReLU(), nn.Linear(64, 128), nn.ReLU(), nn.Linear(128, 64) ) self.decoder = nn.Sequential( nn.Linear(64, 128), nn.ReLU(), nn.Linear(128, 64), nn.ReLU(), nn.Linear(64, num_virtual) ) self.pmv_head = nn.Sequential( nn.Linear(num_virtual + 2, 32), nn.ReLU(), nn.Linear(32, 1) ) def forward(self, physical_sensors: torch.Tensor, env_data: torch.Tensor) -> Dict[str, torch.Tensor]: """ Args: physical_sensors: (B, 6) 物理传感器读数 env_data: (B, 4) [外温, 日照W/m², 车速, 风扇转速] Returns: output: { virtual_temps: (B, 20) 虚拟温度点, pmv: (B, 1) 预测平均投票 } """ x = torch.cat([physical_sensors, env_data], dim=-1) latent = self.encoder(x) virtual_temps = self.decoder(latent) humidity = env_data[:, 0:1] * 0 air_speed = env_data[:, 2:3] * 0.01 pmv_input = torch.cat([virtual_temps, humidity, air_speed], dim=-1) pmv = self.pmv_head(pmv_input) return { "virtual_temps": virtual_temps, "pmv": pmv } def comfort_level(self, pmv: float) -> str: """PMV → 舒适等级""" if -0.5 <= pmv <= 0.5: return "comfortable" elif -1.0 <= pmv < -0.5 or 0.5 < pmv <= 1.0: return "slightly_uncomfortable" elif -1.5 <= pmv < -1.0 or 1.0 < pmv <= 1.5: return "uncomfortable" else: return "very_uncomfortable"
class ThermalDMSIntegration: """ 热舒适 + DMS 融合:温度影响疲劳的联合分析 研究发现: - 高温(>28°C)加速 PERCLOS 增长 - 低温(<18°C)增加眨眼频率 - 温度波动导致注意力分散 - 湿度>70%加速主观疲劳感 融合架构: DMS PERCLOS + 热舒适 PMV → 综合疲劳风险评估 """ TEMP_PERCLOS_FACTOR = { (18, 22): 1.0, (22, 26): 1.0, (26, 28): 1.2, (28, 30): 1.5, (30, 32): 1.8, (32, 35): 2.5, } def adjust_fatigue_score(self, perclos: float, cabin_temp: float, humidity: float) -> dict: """ 根据热环境调整疲劳分数 Args: perclos: DMS 检测的 PERCLOS 值 (%) cabin_temp: 座舱温度 (°C) humidity: 相对湿度 (%) Returns: adjusted: 调整后的疲劳评估 """ temp_factor = 1.0 for (lo, hi), factor in self.TEMP_PERCLOS_FACTOR.items(): if lo <= cabin_temp < hi: temp_factor = factor break if humidity > 70: humidity_factor = 1.3 elif humidity > 60: humidity_factor = 1.1 else: humidity_factor = 1.0 adjusted_perclos = perclos * temp_factor * humidity_factor return { "raw_perclos": perclos, "adjusted_perclos": round(adjusted_perclos, 1), "temp_factor": temp_factor, "humidity_factor": humidity_factor, "thermal_alert": cabin_temp > 28 or cabin_temp < 18, }
|