理论总结
随着版本的升级,模型在参数数量、语言理解能力、生成文本质量、多模态能力、推理能力等方面均有显著提升。GPT-4.0作为最新改进版,提供了最先进的功能和性能。
实际对比
1.1.GPT3.5
1.2.GPT4
1.3.GPT4o
在语义理解上,无差别。
下面测试下代码能力。
测试问题
我想做一个基于Python的主客观结合赋权的权重测度,假设现在其他方法测度了主观权重和客观权重,现在写一段代码,实现主客观结合的赋权,方法越高级越好。
2.1.GPT3.5
def weighted_average(subjective_weights, objective_weights, subjective_measurements, objective_measurements):
"""
使用加权平均计算主客观结合的权重测度
Args:
subjective_weights (list): 主观权重列表
objective_weights (list): 客观权重列表
subjective_measurements (list): 主观权重下的测量值列表
objective_measurements (list): 客观权重下的测量值列表
Returns:
combined_measurements (list): 结合主客观权重后的测量值列表
"""
combined_measurements = []
for sub_weight, obj_weight, sub_meas, obj_meas in zip(subjective_weights, objective_weights, subjective_measurements, objective_measurements):
combined_measurement = sub_weight * sub_meas + obj_weight * obj_meas
combined_measurements.append(combined_measurement)
return combined_measurements
def linear_combination(subjective_weights, objective_weights, subjective_measurements, objective_measurements):
"""
使用线性组合计算主客观结合的权重测度
Args:
subjective_weights (list): 主观权重列表
objective_weights (list): 客观权重列表
subjective_measurements (list): 主观权重下的测量值列表
objective_measurements (list): 客观权重下的测量值列表
Returns:
combined_measurements (list): 结合主客观权重后的测量值列表
"""
combined_measurements = []
for sub_weight, obj_weight, sub_meas, obj_meas in zip(subjective_weights, objective_weights, subjective_measurements, objective_measurements):
combined_measurement = sub_weight * sub_meas + obj_weight * obj_meas
combined_measurements.append(combined_measurement)
return combined_measurements
# 示例数据
subjective_weights = [0.6, 0.4] # 主观权重
objective_weights = [0.4, 0.6] # 客观权重
subjective_measurements = [8, 7] # 主观权重下的测量值
objective_measurements = [6, 9] # 客观权重下的测量值
# 计算加权平均
combined_measurements_avg = weighted_average(subjective_weights, objective_weights, subjective_measurements, objective_measurements)
print("加权平均后的测量值:", combined_measurements_avg)
# 计算线性组合
combined_measurements_linear = linear_combination(subjective_weights, objective_weights, subjective_measurements, objective_measurements)
print("线性组合后的测量值:", combined_measurements_linear)
2.2.GPT4
import numpy as np
import skfuzzy as fuzz
from skfuzzy import control as ctrl
# 创建模糊控制变量
subjective_weight = ctrl.Antecedent(np.arange(0, 11, 1), 'subjective_weight')
objective_weight = ctrl.Antecedent(np.arange(0, 11, 1), 'objective_weight')
combined_weight = ctrl.Consequent(np.arange(0, 11, 1), 'combined_weight')
# 设定模糊集合
subjective_weight['low'] = fuzz.trimf(subjective_weight.universe, [0, 0, 5])
subjective_weight['medium'] = fuzz.trimf(subjective_weight.universe, [0, 5, 10])
subjective_weight['high'] = fuzz.trimf(subjective_weight.universe, [5, 10, 10])
objective_weight['low'] = fuzz.trimf(objective_weight.universe, [0, 0, 5])
objective_weight['medium'] = fuzz.trimf(objective_weight.universe, [0, 5, 10])
objective_weight['high'] = fuzz.trimf(objective_weight.universe, [5, 10, 10])
combined_weight['low'] = fuzz.trimf(combined_weight.universe, [0, 0, 5])
combined_weight['medium'] = fuzz.trimf(combined_weight.universe, [0, 5, 10])
combined_weight['high'] = fuzz.trimf(combined_weight.universe, [5, 10, 10])
# 设定规则
rule1 = ctrl.Rule(subjective_weight['low'] & objective_weight['low'], combined_weight['low'])
rule2 = ctrl.Rule(subjective_weight['low'] & objective_weight['medium'], combined_weight['medium'])
rule3 = ctrl.Rule(subjective_weight['low'] & objective_weight['high'], combined_weight['high'])
rule4 = ctrl.Rule(subjective_weight['medium'] & objective_weight['low'], combined_weight['medium'])
rule5 = ctrl.Rule(subjective_weight['medium'] & objective_weight['medium'], combined_weight['medium'])
rule6 = ctrl.Rule(subjective_weight['medium'] & objective_weight['high'], combined_weight['high'])
rule7 = ctrl.Rule(subjective_weight['high'] & objective_weight['low'], combined_weight['high'])
rule8 = ctrl.Rule(subjective_weight['high'] & objective_weight['medium'], combined_weight['high'])
rule9 = ctrl.Rule(subjective_weight['high'] & objective_weight['high'], combined_weight['high'])
# 设定控制系统
combined_weight_ctrl = ctrl.ControlSystem([rule1, rule2, rule3, rule4, rule5, rule6, rule7, rule8, rule9])
combined_weighting = ctrl.ControlSystemSimulation(combined_weight_ctrl)
# 输入主客观权重
combined_weighting.input['subjective_weight'] = 7
combined_weighting.input['objective_weight'] = 3
# 运行模糊推理
combined_weighting.compute()
# 输出结果
print("Combined Weight:", combined_weighting.output['combined_weight'])
combined_weight.view(sim=combined_weighting)
2.3.GPT4o
import numpy as np
from scipy.optimize import minimize
# 假设这是主观权重和客观权重
subjective_weights = np.array([0.4, 0.3, 0.3])
objective_weights = np.array([0.2, 0.5, 0.3])
# 参考权重(例如实际的权重或期望的权重)
reference_weights = np.array([0.3, 0.4, 0.3])
# 规范化权重
def normalize(weights):
return weights / weights.sum()
subjective_weights = normalize(subjective_weights)
objective_weights = normalize(objective_weights)
reference_weights = normalize(reference_weights)
# 结合主客观权重
def combine_weights(alpha, subjective, objective):
combined_weights = alpha * subjective + (1 - alpha) * objective
return normalize(combined_weights)
# 目标函数,最小化结合权重和参考权重之间的MSE
def objective_function(alpha, subjective, objective, reference):
combined_weights = combine_weights(alpha, subjective, objective)
mse = np.mean((combined_weights - reference) ** 2)
return mse
# 初始alpha值
initial_alpha = 0.5
# 使用scipy.optimize.minimize进行优化
result = minimize(objective_function, initial_alpha, args=(subjective_weights, objective_weights, reference_weights),
bounds=[(0, 1)], method='L-BFGS-B')
# 最优的alpha值
optimal_alpha = result.x[0]
# 结合后的权重
combined_weights = combine_weights(optimal_alpha, subjective_weights, objective_weights)
print("主观权重: ", subjective_weights)
print("客观权重: ", objective_weights)
print("参考权重: ", reference_weights)
print("最优alpha: ", optimal_alpha)
print("结合权重: ", combined_weights)