2023 "Huawei Cup" Chinese Graduate Mathematical Modeling Competition (Question F) In-depth Analysis | Complete Code of Mathematical Modeling + Full Analysis of the Modeling Process

F question code + ideas

Have you ever felt at a loss when faced with complex mathematical modeling problems? As the O Award winner of the 2021 American College Student Mathematical Modeling Competition, I provide you with a set of excellent problem-solving ideas to allow you to easily deal with various problems.
Let’s take a look at question F in the research competition! The full text has been released~

Problem restatement

1. How to use dual-polarization radar data to effectively improve the short-term forecast of severe convective precipitation? It is required to establish a model that can extract microphysical feature information from dual-polarization radar data to conduct 0-1 hour precipitation forecast.
2. Some current data-driven models have the problem of "returning to the mean", and the generated heavy precipitation forecasts are often too vague. It is required to design a model based on question 1 to generate more realistic and detailed precipitation forecast results.
3. It is required to use radar reflectivity Z_H and differential reflectivity Z_DR to establish a model for quantitative precipitation estimation, that is, use these two variables to predict precipitation.
4. It is required to design a model to evaluate the contribution of dual-polarization radar data to heavy precipitation forecasting, and integrate it with other data sources by optimizing the data fusion strategy to improve the accuracy of heavy precipitation detection and forecasting.
Insert image description here

Question one

1. Input and output design
Input: X = X t − 9 , . . . , X t X=Xt−9 ,...,XtX=Xt9,...,Xt
whereX t ∈ RH × W × CXtRH×W×C represents the radar image at time t, H and W are the height and width, and C is the number of channels.
Output:Y = Y t + 1 , . . . , Y t + 10 Y^=Y^t+1,...,Y^t+10Y=Yt+1,...,Yt+10
of whichY t ∈ RH × WY^t ∈RH×WYtRH×W represents the predictionZH Z_HZH.
2. Convolution feature extraction
Use the convolution layer to extract local features of the input: F = f ( [ X ; Θ f ] F=f([X; Θf ]F=f([X;Θ f ] )
where f represents the convolution operation,Θ f \Theta_fThfare the convolutional layer parameters.
3. Convolutional LSTM modeling spatiotemporal correlation

4. Transpose convolution upsampling
Y = f T ( [ H ; Θ T ] ) Y^=fT ([H; ΘT ])Y=fT([H;Θ T ])
wheref T f^TfT represents transposed convolution, H is the output feature of convolution LSTM,Θ T \Theta_{T}ThTis the transposed convolution parameter.
5.Loss function design

Code:

import tensorflow as tf
from tensorflow.keras.layers import ConvLSTM2D, Conv2D, Conv2DTranspose

# 输入层
inputs = tf.keras.Input(shape=(10, 128, 128, 3)) 

# 卷积层提取特征
x = Conv2D(filters=64, kernel_size=3, activation='relu')(inputs)
x = MaxPooling2D((2, 2))(x)
from tensorflow.keras.layers import ConvLSTM2D, Conv2D, Conv2DTranspose, Attention
from tensorflow.keras import Model

inputs = Input(shape=(10, 128, 128, 3))

# 第一层卷积
x = Conv2D(64, 3, padding='same', activation='relu')(inputs)  

# 第二层卷积
x = Conv2D(64, 3, padding='same', activation='relu')(x)

# 第一层卷积LSTM 
x = ConvLSTM2D(64, 3, padding='same', return_sequences=True)(x)

# 第二层卷积LSTM
x = ConvLSTM2D(64, 3, padding='same', return_sequences=True)(x)

# 注意力机制

# 利用一个Dense层学习注意力权重
attn_layer = Dense(units=64, activation='tanh')(x)  

# 计算注意力权重
attn_weights = Dense(units=10, activation='softmax')(attn_layer)

# 尺度注意力权重
attn_weights = Reshape((10, 1, 1, 1))(attn_weights) 

# 计算注意力输出
attn_output = Multiply()([x, attn_weights])

# 转置卷积上采样 

# 第1层转置卷积
x = Conv2DTranspose(filters=64, kernel_size=3, strides=2, padding='same')(attn_output)

# 第2层转置卷积 
x = Conv2DTranspose(filters=32, kernel_size=3, strides=2, padding='same')(x)  

# 第3层转置卷积
x = Conv2DTranspose(filters=1, kernel_size=3, strides=2, padding='same')(x)

# 构建Model
model = Model(inputs, x)

# 编译与训练
model.compile(loss='mae', optimizer='adam')
model.fit(X_train, y_train, epochs=10) 

# 预测
y_pred = model.predict(X_test)

# 编译与训练
model.compile(loss='mae', optimizer='adam') 
model.fit(X_train, y_train, epochs=10)

# 预测
y_pred = model.predict(X_test)

Insert image description here

Question 2

1. Build a multi-scale forecast model.
In the convolutional LSTM model, predict Z_H at different scales at the same time: · Low resolution Z_H: reflects the large-scale precipitation pattern
· High-resolution Z_H: reflects the small-scale precipitation details 2. Add Priori constraints:
Based on meteorological knowledge, add prior constraints on heavy precipitation, for example: Heavy precipitation has aggregation characteristics
Cell movement follows the flow field
Life cycle is divided into different development stages
These prior knowledge can be added to the model as constraints.
3. Model integration:
Use multiple different models to fuse their respective forecast results.
4. Data enhancement:
Enhance the training data by rotating, flipping, adding noise, etc. to improve the robustness of the model.
5. Model and training strategy optimization:
Improve the model structure, adjust the loss function, optimize training hyper-parameters, etc.

from tensorflow.keras.layers import Input, ConvLSTM2D, UpSampling2D
from tensorflow.keras.models import Model

inputs = Input(shape=(10, 128, 128, 1))

# 低分辨率预测分支

x1 = ConvLSTM2D(filters=32, kernel_size=3, padding='same', return_sequences=True)(inputs)
x1 = BatchNormalization()(x1) # 加入BN层
x1 = ConvLSTM2D(filters=32, kernel_size=3, padding='same')(x1)  
x1 = Conv2D(filters=1, kernel_size=1, padding='same')(x1)

# 高分辨率预测分支 

x2 = ConvLSTM2D(filters=64, kernel_size=3, padding='same', return_sequences=True)(inputs)
x2 = BatchNormalization()(x2) 
x2 = ConvLSTM2D(filters=64, kernel_size=3, padding='same')(x2)
x2 = UpSampling2D(size=(2,2))(x2) # 双线性插值上采样 
x2 = Conv2D(filters=1, kernel_size=1, padding='same')(x2)

# 合并不同尺度

merged = Add()([x1, x2])  
merged = BatchNormalization()(merged) # BN层融合不同分支

# 编译与训练
model.compile(loss='mse', optimizer='adam') 


Insert image description here

Question three

Idea:
1. Input and output design
Input: radar reflectivity ZH Z_HZHand differential reflectivity ZDR Z_DRZDR output: Predicted precipitation R
2. Establish the ZR relationship
R = a ∗ ZH b ∗ ZDR c R = a * Z_H^b * Z_DR^cR=aZHbZDRcwhere a, b, c are empirical parameters.
Transform the problem into determining these three parameters.
3. Parameter determination
Collect observation data: Collect a large number of triplet data (Z_H, Z_DR, R) from multiple regions and multiple precipitation types.
Data preprocessing: remove samples with large errors and check data quality. Normalize Z_H and Z_DR.
Fitting parameters: Construct loss functionL = ∑ i = 1 N ( R ^ i − R i ) 2 L = ∑ i = 1 N ( R i − R i ) 2 \mathcal L=\sum_{i=1}^ N(\hat R_i-R_i)^2L=∑i=1N (R^i −Ri )2L=i=1N(R^iRi)2 L=i=1N(RiRi)2,其中 R ^ i = a Z H i b Z D R i c R i = a Z H i b Z D R i c \hat R_i=aZ_{H_i}^bZ_{DR_i}^cR^i =aZHi b ZDRi c R^i=the ZHibZDRicRi=a Z H ib Z D R i c . Use gradient descent algorithm to learn parameters a, b, c to minimize the loss function.
4. Model selection: Compare different power index combinations and select a set of parameters with the best fitting effect. Model testing
Collect independent test data: Ensure that the training and test data are in different regions and precipitation types.
Test set prediction: Substitute the test data Z_H and Z_DR into the obtained ZR relationship to generate precipitation predictionR ^ \hat RR^ .
Evaluation indicators: Calculate RMSE, MAE, etc. to test the prediction effect. Plot a scatter plot to compareR ^ \hat RR^ and R.
Model improvement: Compare the prediction effects of different regions and precipitation types, analyze the reasons, and further optimize the model.
Extreme case validation: Use data under extreme rainfall cases to verify the applicability and robustness of the model.
Insert image description here

Code:

import numpy as np
from sklearn.metrics import mean_squared_error

# 收集并预处理观测数据
zh = [12, 15, 13, ...] # 反射率因子Z_H
zdr = [0.8, 1.2, 0.7, ...] # 差分反射率Z_DR
r = [10, 25, 12, ...] # 实测降水量R

# 定义Z-R关系,初始化参数  
def zr_relation(zh, zdr, a, b, c):
    return a * zh**b * zdr**c


# 使用最小二乘法拟合参数
def train(zh, zdr, r, a, b, c):
    preds = [zr_relation(z, zd, a, b, c) for z,zd in zip(zh, zdr)]  
    loss = mean_squared_error(r, preds)
    # 参数初始化
a, b, c = 0.01, 1.4, 0.9  

# 梯度下降函数
def grad_descent(zh, zdr, r, a, b, c, lr=0.01, epochs=100):

    for i in range(epochs):
        
        # 计算损失函数  
        preds = [zr_relation(z, zd, a, b, c) for z, zd in zip(zh, zdr)]
        loss = np.mean((preds - r)**2)
        
        # 计算梯度
        a_grad = 2 * np.mean((preds - r) * preds * (a ** (b-1)) * (c ** (c-1)))
        b_grad = 2 * np.mean((preds - r) * preds * (np.log(z) * a ** b * (c ** c)))
        c_grad = 2 * np.mean((preds - r) * preds * (np.log(zd) * a ** b * (c ** (c-1))))
        
        # 参数更新  
        a = a - lr * a_grad
        b = b - lr * b_grad 
        c = c - lr * c_grad
        
    return a, b, c
    
# 拟合参数
a, b, c = grad_descent(zh, zdr, r, a, b, c)

# 模型评估
zh_test, zdr_test, r_test = ... # 测试数据
preds_test = [zr_relation(z, zd, a, b, c) for z, zd in 

Insert image description here

gradient descent function

Question 4

  1. Baseline model

Y^0 = f(X0; θ0) \hat{Y}_0 = f(X_0; \theta_0)Y^0=f(X0;i0)

where X 0 X_0X0is single polarization Z_H, θ 0 \theta_0i0is the model parameter, Y ^ 0 \hat{Y}_0Y^0for prediction.

  1. Evaluation model

Y^1 = f(X1;θ1) \hat{Y}_1 = f(X_1;\theta_1)Y^1=f(X1;i1)

where X 1 X_1X1Inclusion Z_H, Z_DR, K_DP, θ 1 \theta_1i1is the parameter, Y ^ 1 \hat{Y}_1Y^1for prediction.

  1. Model evaluation

R M S E 0 = 1 n ∑ i = 1 n ( Y i − Y ^ 0 i ) 2 RMSE_0 = \frac{1}{n}\sum_{i=1}^{n}(Y_i - \hat{Y}_{0i})^2 RMSE0=n1i=1n(YiY^0 i)2

R M S E 1 = 1 n ∑ i = 1 n ( Y i − Y ^ 1 i ) 2 RMSE_1 = \frac{1}{n}\sum_{i=1}^{n}(Y_i - \hat{Y}_{1i})^2 RMSE1=n1i=1n(YiY^1 i)2

Compare RMSE 0 RMSE_0RMSE0and RMSE 1 RMSE_1RMSE1

  1. Attention mechanism fusion

Y ^ = ∑ i = 1 m α i f i ( X i ; θ i ) \hat{Y} = \sum_{i=1}^{m}\alpha_i f_i(X_i; \theta_i) Y^=i=1maifi(Xi;ii)

Learning weight α i \alpha_iai, adaptively fuse different data sources X i X_iXiPrediction.

import tensorflow as tf
from tensorflow.keras import layers, models

# 1. 构建基准模型 
inputs_zh = layers.Input(shape=(10, 64, 64, 1))
conv_zh = layers.Conv2D(32, 3)(inputs_zh)
lstm_zh = layers.LSTM(32)(conv_zh)
outputs_zh = layers.Dense(64*64)(lstm_zh)
base_model = models.Model(inputs_zh, outputs_zh)

# 2. 构建增强模型
inputs_dual_pol = layers.Input(shape=(10, 64, 64, 3))  
conv_dual_pol = layers.Conv2D(32, 3)(inputs_dual_pol)
lstm_dual_pol = layers.LSTM(32)(conv_dual_pol)
outputs_dual_pol = layers.Dense(64*64)(lstm_dual_pol)
enhanced_model = models.Model(inputs_dual_pol, outputs_dual_pol)

# 3. 模型训练
# 载入数据
X_train, X_test = load_data()  

# 数据预处理
X_train = normalize(X_train)
X_test = normalize(X_test)

For more full versions, see here:
(5 private messages/2 messages) How to evaluate question F of the 2023 Mathematical Modeling Competition? -csdn

Guess you like

Origin blog.csdn.net/qq_25834913/article/details/133236337