0
点赞
收藏
分享

微信扫一扫

不改变初始温度的情况下, 宽度越大、厚度越大、重量越大、车间温度越高, 温度随时间衰减的速度越慢, 退火类型(O态比H2态更慢)、冷却类型(自然冷却比单面风机更慢, 单面风机比双面风机更慢)

云岭逸人 2023-10-07 阅读 31

# 导入所需的库
import pandas as pd
import numpy as np
import matplotlib.pyplot as plt
import seaborn as sns
from sklearn.linear_model import LinearRegression
from sklearn.metrics import mean_squared_error, r2_score
from sklearn.model_selection import train_test_split

# 指定支持中文的字体,例如SimHei或者Microsoft YaHei
plt.rcParams['font.sans-serif'] = ['SimHei']
plt.rcParams['axes.unicode_minus'] = False  # 解决负号显示问题

# 生成数据
def fun_data():
    # 定义物料数量
    num_materials = 40

    # 定义每个物料的温度测量次数和时间间隔
    num_measurements = 10
    time_interval_hours = 6

    # 创建一个时间数组,模拟测量时间点
    measurement_times = np.arange(0, num_measurements * time_interval_hours, time_interval_hours)

    # 创建一个空的DataFrame来存储数据
    data = pd.DataFrame(columns=['Material_ID', 'Measurement_Time', 'Width', 'Thickness', 'Weight', 'Workshop_Temperature',
                                 'Annealing_Type', 'Cooling_Type', 'Temperature'])

    # 模拟每个物料的数据
    for material_id in range(1, num_materials + 1):
        # 生成物料特征数据(宽度、厚度、重量、车间温度、退火类型、冷却类型)
        width = np.random.uniform(5, 20)  # 宽度范围在5到20之间
        thickness = np.random.uniform(1, 5)  # 厚度范围在1到5之间
        weight = np.random.uniform(10, 100)  # 重量范围在10到100之间
        workshop_temperature = np.random.uniform(20, 30)  # 车间温度范围在20到30之间
        annealing_type = np.random.choice(['O态', 'H2态'])  # 随机选择退火类型
        cooling_type = np.random.choice(['自然冷却', '单面风机', '双面风机'])  # 随机选择冷却类型

        # 模拟温度数据(指数衰减)
        initial_temperature = np.random.uniform(100, 200)  # 初始温度范围在100到200之间,不改变
        
        decay_rate_min = 0.01 - width / 1000 - thickness / 1000 - weight / 10000 - workshop_temperature / 1000 # 衰减速率的最小值与宽度、厚度、重量、车间温度负相关
        
        if annealing_type == 'O态': # O态退火比H2态退火更慢,因此衰减速率更低
            decay_rate_min -= 0.01
            
        if cooling_type == '自然冷却': # 自然冷却比单面风机更慢,比双面风机更慢,因此衰减速率更低
            decay_rate_min -= 0.01
            
        elif cooling_type == '单面风机': # 单面风机比双面风机更慢,因此衰减速率稍低
            decay_rate_min -= 0.005
            
        decay_rate_max = decay_rate_min + 0.05 # 衰减速率的最大值比最小值高0.05
        
        decay_rate = np.random.uniform(decay_rate_min, decay_rate_max)  # 衰减速率范围根据物料特征和处理方式调整
        
        temperature_data = initial_temperature * np.exp(-decay_rate * measurement_times)

        # 创建一个临时DataFrame来存储物料的数据
        material_data = pd.DataFrame({
            'Material_ID': [material_id] * num_measurements,
            'Measurement_Time': measurement_times,
            'Width': [width] * num_measurements,
            'Thickness': [thickness] * num_measurements,
            'Weight': [weight] * num_measurements,
            'Workshop_Temperature': [workshop_temperature] * num_measurements,
            'Annealing_Type': [annealing_type] * num_measurements,
            'Cooling_Type': [cooling_type] * num_measurements,
            'Temperature': temperature_data
        })

        # 将物料数据添加到总体数据中
        data = pd.concat([data, material_data], ignore_index=True)
        
        # 修改数据类型
        data['Measurement_Time'] = data['Measurement_Time'].astype("float64")
        
    return data

# 导入数据
data = fun_data()

# 温度与其他变量的关系呈指数回归, 且温度随时间的增长呈指数衰减趋势, 设计模型如下
Temperature = np.exe(
    k1 + k2 * Measurement_Time + \
    k3 * Width + k4 * Thickness + k5 * Weight + k6 * Workshop_Temperature + \
    k7 * Annealing_Type_O态 + k8 * Annealing_Type_H2态 + \
    k9 * Cooling_Type_自然冷却 + k10 * Cooling_Type_单面风机 + k11 * Cooling_Type_双面风机
)

# 定义自变量和因变量
# 对类别型的自变量进行编码,使用独热编码(one-hot encoding),其他默认为数值型自变量
X = data[['Measurement_Time', 'Width', 'Thickness', 'Weight', 'Workshop_Temperature', 'Annealing_Type', 'Cooling_Type']]
X = pd.get_dummies(X, columns=['Annealing_Type', 'Cooling_Type']) # 将退火类型和冷却类型转换为哑变量
y = data['Temperature'] # 选择温度作为因变量

优化fun_data, 使数据更加逼真,
不改变初始温度的情况下,
宽度越大、厚度越大、重量越大、车间温度越高, 温度随时间衰减的速度越慢,
退火类型(O态比H2态更慢)、冷却类型(自然冷却比单面风机更慢, 单面风机比双面风机更慢)

优化fun_data, 使数据更加逼真,

不改变初始温度的情况下,

宽度越大、厚度越大、重量越大、车间温度越高, 温度随时间衰减的速度越慢,

退火类型(O态比H2态更慢)、冷却类型(自然冷却比单面风机更慢, 单面风机比双面风机更慢)

举报

相关推荐

0 条评论