当前位置: 首页 > news >正文

第100+27步 ChatGPT学习:概率校准 Temperature Scaling

基于Python 3.9版本演示

一、写在前面

最近看了一篇在Lancet子刊《eClinicalMedicine》上发表的机器学习分类的文章:《Development of a novel dementia risk prediction model in the general population: A large, longitudinal, population-based machine-learning study》。

学到一种叫做“概率校准”的骚操作,顺手利用GPT系统学习学习。

文章中用的技术是:保序回归(Isotonic regression)。

为了体现举一反三,顺便问了GPT还有哪些方法也可以实现概率校准。它给我列举了很多,那么就一个一个学习吧。

这一期,介绍一个叫做 Temperature Scaling 的方法。

二、Temperature Scaling

Temperature Scaling的核心思想是通过引入一个温度参数(temperature parameter, T)来调整模型的logits(未归一化的输出值),从而校准输出的概率分布。具体来说,它是一种后处理方法,即在训练完模型后进行校准,而不改变模型的结构或训练过程。

(1)主要步骤

1)训练模型:首先,训练你的分类模型,获得logits和初步的概率预测。

2)验证集校准:使用验证集来找到最优的温度参数T。通过最小化负对数似然(negative log-likelihood, NLL)或者期望校准误差(expected calibration error, ECE)等校准指标来找到最佳的T。

3)校准:使用找到的最优温度参数T对测试集或实际应用中的预测概率进行校准。

三、Temperature Scaling代码实现

下面,我编一个1比3的不太平衡的数据进行测试,对照组使用不进行校准的SVM模型,实验组就是加入校准的SVM模型,看看性能能够提高多少?

(1)不进行校准的SVM模型(默认参数)

import numpy as np
import matplotlib.pyplot as plt
import pandas as pd
from sklearn.model_selection import train_test_split
from sklearn.preprocessing import StandardScaler
from sklearn.svm import SVC
from sklearn.metrics import confusion_matrix, roc_auc_score, roc_curve# 加载数据
dataset = pd.read_csv('8PSMjianmo.csv')
X = dataset.iloc[:, 1:20].values
Y = dataset.iloc[:, 0].values# 分割数据集
X_train, X_test, y_train, y_test = train_test_split(X, Y, test_size=0.30, random_state=666)# 标准化数据
sc = StandardScaler()
X_train = sc.fit_transform(X_train)
X_test = sc.transform(X_test)# 使用SVM分类器
classifier = SVC(kernel='linear', probability=True)
classifier.fit(X_train, y_train)# 预测结果
y_pred = classifier.predict(X_test)
y_testprba = classifier.decision_function(X_test)y_trainpred = classifier.predict(X_train)
y_trainprba = classifier.decision_function(X_train)# 混淆矩阵
cm_test = confusion_matrix(y_test, y_pred)
cm_train = confusion_matrix(y_train, y_trainpred)
print(cm_train)
print(cm_test)# 绘制测试集混淆矩阵
classes = list(set(y_test))
classes.sort()
plt.imshow(cm_test, cmap=plt.cm.Blues)
indices = range(len(cm_test))
plt.xticks(indices, classes)
plt.yticks(indices, classes)
plt.colorbar()
plt.xlabel('Predicted')
plt.ylabel('Actual')
for first_index in range(len(cm_test)):for second_index in range(len(cm_test[first_index])):plt.text(first_index, second_index, cm_test[first_index][second_index])plt.show()# 绘制训练集混淆矩阵
classes = list(set(y_train))
classes.sort()
plt.imshow(cm_train, cmap=plt.cm.Blues)
indices = range(len(cm_train))
plt.xticks(indices, classes)
plt.yticks(indices, classes)
plt.colorbar()
plt.xlabel('Predicted')
plt.ylabel('Actual')
for first_index in range(len(cm_train)):for second_index in range(len(cm_train[first_index])):plt.text(first_index, second_index, cm_train[first_index][second_index])plt.show()# 计算并打印性能参数
def calculate_metrics(cm, y_true, y_pred_prob):a = cm[0, 0]b = cm[0, 1]c = cm[1, 0]d = cm[1, 1]acc = (a + d) / (a + b + c + d)error_rate = 1 - accsen = d / (d + c)sep = a / (a + b)precision = d / (b + d)F1 = (2 * precision * sen) / (precision + sen)MCC = (d * a - b * c) / (np.sqrt((d + b) * (d + c) * (a + b) * (a + c)))auc_score = roc_auc_score(y_true, y_pred_prob)metrics = {"Accuracy": acc,"Error Rate": error_rate,"Sensitivity": sen,"Specificity": sep,"Precision": precision,"F1 Score": F1,"MCC": MCC,"AUC": auc_score}return metricsmetrics_test = calculate_metrics(cm_test, y_test, y_testprba)
metrics_train = calculate_metrics(cm_train, y_train, y_trainprba)print("Performance Metrics (Test):")
for key, value in metrics_test.items():print(f"{key}: {value:.4f}")print("\nPerformance Metrics (Train):")
for key, value in metrics_train.items():
print(f"{key}: {value:.4f}")

结果输出:

记住这些个数字。

这个参数的SVM还没有LR好。

(2)进行校准的SVM模型(默认参数)

import numpy as np
import matplotlib.pyplot as plt
import pandas as pd
from sklearn.model_selection import train_test_split
from sklearn.preprocessing import StandardScaler
from sklearn.svm import SVC
from sklearn.metrics import confusion_matrix, roc_auc_score, brier_score_loss
from sklearn.calibration import calibration_curve# 加载数据
dataset = pd.read_csv('8PSMjianmo.csv')
X = dataset.iloc[:, 1:20].values
Y = dataset.iloc[:, 0].values# 分割数据集
X_train, X_test, y_train, y_test = train_test_split(X, Y, test_size=0.30, random_state=666)# 标准化数据
sc = StandardScaler()
X_train = sc.fit_transform(X_train)
X_test = sc.transform(X_test)# 使用SVM分类器
classifier = SVC(kernel='rbf', C=0.1, probability=True)
classifier.fit(X_train, y_train)# 获取未校准的概率预测
y_train_probs = classifier.predict_proba(X_train)[:, 1]
y_test_probs = classifier.predict_proba(X_test)[:, 1]# Temperature Scaling
class TemperatureScaling:def __init__(self):self.temperature = 1.0def fit(self, logits, true_labels):from scipy.optimize import minimizedef nll_loss(T):scaled_logits = logits / Tprobs = np.exp(scaled_logits) / np.sum(np.exp(scaled_logits), axis=1, keepdims=True)log_probs = np.log(probs[np.arange(len(true_labels)), true_labels])return -np.mean(log_probs)logits = np.log(np.column_stack([1 - logits, logits]))  # 转换成logitsresult = minimize(nll_loss, [1.0], bounds=[(0.1, 10.0)])self.temperature = result.x[0]def predict_proba(self, probs):logits = np.log(np.column_stack([1 - probs, probs]))  # 转换成logitsscaled_logits = logits / self.temperatureexp_scaled_logits = np.exp(scaled_logits)probs = exp_scaled_logits[:, 1] / np.sum(exp_scaled_logits, axis=1, keepdims=True)[:, 0]return probs# 训练Temperature Scaling模型
temp_scaling = TemperatureScaling()
temp_scaling.fit(y_train_probs, y_train)# 进行校准
calibrated_train_probs = temp_scaling.predict_proba(y_train_probs)
calibrated_test_probs = temp_scaling.predict_proba(y_test_probs)# 预测结果
y_train_pred = (calibrated_train_probs >= 0.5).astype(int)
y_test_pred = (calibrated_test_probs >= 0.5).astype(int)# 混淆矩阵
cm_test = confusion_matrix(y_test, y_test_pred)
cm_train = confusion_matrix(y_train, y_train_pred)
print(cm_train)
print(cm_test)# 绘制混淆矩阵函数
def plot_confusion_matrix(cm, classes, title='Confusion Matrix'):plt.imshow(cm, cmap=plt.cm.Blues)indices = range(len(cm))plt.xticks(indices, classes)plt.yticks(indices, classes)plt.colorbar()plt.xlabel('Predicted')plt.ylabel('Actual')for first_index in range(len(cm)):for second_index in range(len(cm[first_index])):plt.text(second_index, first_index, cm[first_index][second_index])plt.title(title)plt.show()# 绘制测试集混淆矩阵
plot_confusion_matrix(cm_test, list(set(y_test)), 'Confusion Matrix (Test)')# 绘制训练集混淆矩阵
plot_confusion_matrix(cm_train, list(set(y_train)), 'Confusion Matrix (Train)')# 计算并打印性能参数
def calculate_metrics(cm, y_true, y_pred_prob):a = cm[0, 0]b = cm[0, 1]c = cm[1, 0]d = cm[1, 1]acc = (a + d) / (a + b + c + d)error_rate = 1 - accsen = d / (d + c)sep = a / (a + b)precision = d / (b + d)F1 = (2 * precision * sen) / (precision + sen)MCC = (d * a - b * c) / (np.sqrt((d + b) * (d + c) * (a + b) * (a + c)))auc_score = roc_auc_score(y_true, y_pred_prob)brier_score = brier_score_loss(y_true, y_pred_prob)metrics = {"Accuracy": acc,"Error Rate": error_rate,"Sensitivity": sen,"Specificity": sep,"Precision": precision,"F1 Score": F1,"MCC": MCC,"AUC": auc_score,"Brier Score": brier_score}return metricsmetrics_test = calculate_metrics(cm_test, y_test, calibrated_test_probs)
metrics_train = calculate_metrics(cm_train, y_train, calibrated_train_probs)print("Performance Metrics (Test):")
for key, value in metrics_test.items():print(f"{key}: {value:.4f}")print("\nPerformance Metrics (Train):")
for key, value in metrics_train.items():print(f"{key}: {value:.4f}")

看看结果:

大同小异吧。

四、换个策略

参考那篇文章的策略:采用五折交叉验证来建立和评估模型,其中四折用于训练,一折用于评估,在训练集中,其中三折用于建立SVM模型,另一折采用Temperature Scaling概率校正,在训练集内部采用交叉验证对超参数进行调参。

代码:

import numpy as np
import matplotlib.pyplot as plt
import pandas as pd
from sklearn.model_selection import train_test_split, GridSearchCV, KFold
from sklearn.preprocessing import StandardScaler
from sklearn.svm import SVC
from sklearn.metrics import confusion_matrix, roc_auc_score, brier_score_loss
from sklearn.calibration import calibration_curve# 加载数据
dataset = pd.read_csv('8PSMjianmo.csv')
X = dataset.iloc[:, 1:20].values
Y = dataset.iloc[:, 0].values# 分割数据集
X_train, X_test, y_train, y_test = train_test_split(X, Y, test_size=0.30, random_state=666)# 标准化数据
sc = StandardScaler()
X_train = sc.fit_transform(X_train)
X_test = sc.transform(X_test)# 定义五折交叉验证
kf = KFold(n_splits=5, shuffle=True, random_state=666)
calibrated_probs = []
true_labels = []# Temperature Scaling
class TemperatureScaling:def __init__(self):self.temperature = 1.0def fit(self, logits, true_labels):from scipy.optimize import minimizedef nll_loss(T):scaled_logits = logits / Tprobs = np.exp(scaled_logits) / np.sum(np.exp(scaled_logits), axis=1, keepdims=True)log_probs = np.log(probs[np.arange(len(true_labels)), true_labels])return -np.mean(log_probs)logits = np.log(np.column_stack([1 - logits, logits]))  # 转换成logitsresult = minimize(nll_loss, [1.0], bounds=[(0.1, 10.0)])self.temperature = result.x[0]def predict_proba(self, probs):logits = np.log(np.column_stack([1 - probs, probs]))  # 转换成logitsscaled_logits = logits / self.temperatureexp_scaled_logits = np.exp(scaled_logits)probs = exp_scaled_logits[:, 1] / np.sum(exp_scaled_logits, axis=1, keepdims=True)[:, 0]return probsbest_params = None  # 用于存储最优参数for train_index, val_index in kf.split(X_train):X_train_fold, X_val_fold = X_train[train_index], X_train[val_index]y_train_fold, y_val_fold = y_train[train_index], y_train[val_index]# 内部三折交叉验证用于超参数调优inner_kf = KFold(n_splits=3, shuffle=True, random_state=666)param_grid = {'C': [0.01, 0.1, 1, 10, 100], 'kernel': ['rbf']}svm = SVC(probability=True)clf = GridSearchCV(svm, param_grid, cv=inner_kf, scoring='roc_auc')clf.fit(X_train_fold, y_train_fold)best_params = clf.best_params_# 使用最佳参数训练SVMclassifier = SVC(kernel=best_params['kernel'], C=best_params['C'], probability=True)classifier.fit(X_train_fold, y_train_fold)# 获取未校准的概率预测y_val_fold_probs = classifier.predict_proba(X_val_fold)[:, 1]# Temperature Scaling 校准temp_scaling = TemperatureScaling()temp_scaling.fit(y_val_fold_probs, y_val_fold)calibrated_val_fold_probs = temp_scaling.predict_proba(y_val_fold_probs)calibrated_probs.extend(calibrated_val_fold_probs)true_labels.extend(y_val_fold)# 用于测试集的SVM模型训练和校准
classifier_final = SVC(kernel=best_params['kernel'], C=best_params['C'], probability=True)
classifier_final.fit(X_train, y_train)
y_test_probs = classifier_final.predict_proba(X_test)[:, 1]# Temperature Scaling 校准
temp_scaling_final = TemperatureScaling()
temp_scaling_final.fit(y_test_probs, y_test)
calibrated_test_probs = temp_scaling_final.predict_proba(y_test_probs)# 预测结果
y_train_pred = (np.array(calibrated_probs) >= 0.5).astype(int)
y_test_pred = (calibrated_test_probs >= 0.5).astype(int)# 混淆矩阵
cm_test = confusion_matrix(y_test, y_test_pred)
cm_train = confusion_matrix(true_labels, y_train_pred)
print("Training Confusion Matrix:\n", cm_train)
print("Testing Confusion Matrix:\n", cm_test)# 绘制混淆矩阵函数
def plot_confusion_matrix(cm, classes, title='Confusion Matrix'):plt.imshow(cm, cmap=plt.cm.Blues)indices = range(len(cm))plt.xticks(indices, classes)plt.yticks(indices, classes)plt.colorbar()plt.xlabel('Predicted')plt.ylabel('Actual')for first_index in range(len(cm)):for second_index in range(len(cm[first_index])):plt.text(second_index, first_index, cm[first_index][second_index])plt.title(title)plt.show()# 绘制测试集混淆矩阵
plot_confusion_matrix(cm_test, list(set(y_test)), 'Confusion Matrix (Test)')# 绘制训练集混淆矩阵
plot_confusion_matrix(cm_train, list(set(true_labels)), 'Confusion Matrix (Train)')# 计算并打印性能参数
def calculate_metrics(cm, y_true, y_pred_prob):a = cm[0, 0]b = cm[0, 1]c = cm[1, 0]d = cm[1, 1]acc = (a + d) / (a + b + c + d)error_rate = 1 - accsen = d / (d + c)sep = a / (a + b)precision = d / (b + d)F1 = (2 * precision * sen) / (precision + sen)MCC = (d * a - b * c) / (np.sqrt((d + b) * (d + c) * (a + b) * (a + c)))auc_score = roc_auc_score(y_true, y_pred_prob)brier_score = brier_score_loss(y_true, y_pred_prob)metrics = {"Accuracy": acc,"Error Rate": error_rate,"Sensitivity": sen,"Specificity": sep,"Precision": precision,"F1 Score": F1,"MCC": MCC,"AUC": auc_score,"Brier Score": brier_score}return metricsmetrics_test = calculate_metrics(cm_test, y_test, calibrated_test_probs)
metrics_train = calculate_metrics(cm_train, true_labels, np.array(calibrated_probs))print("Performance Metrics (Test):")
for key, value in metrics_test.items():print(f"{key}: {value:.4f}")print("\nPerformance Metrics (Train):")
for key, value in metrics_train.items():print(f"{key}: {value:.4f}")# 绘制校准曲线
def plot_calibration_curve(y_true, probs, title='Calibration Curve'):fraction_of_positives, mean_predicted_value = calibration_curve(y_true, probs, n_bins=10)plt.plot(mean_predicted_value, fraction_of_positives, "s-", label="Temperature Scaling Calibration")plt.plot([0, 1], [0, 1], "k--")plt.xlabel('Mean predicted value')plt.ylabel('Fraction of positives')plt.title(title)plt.legend()plt.show()# 绘制校准曲线
plot_calibration_curve(y_test, calibrated_test_probs, title='Calibration Curve (Test)')
plot_calibration_curve(true_labels, np.array(calibrated_probs), title='Calibration Curve (Train)')

输出:

效果一般般吧。

五、最后

各位可以去试一试在其他数据或者在其他机器学习分类模型中使用的效果。

数据不分享啦。

相关文章:

第100+27步 ChatGPT学习:概率校准 Temperature Scaling

基于Python 3.9版本演示 一、写在前面 最近看了一篇在Lancet子刊《eClinicalMedicine》上发表的机器学习分类的文章:《Development of a novel dementia risk prediction model in the general population: A large, longitudinal, population-based machine-learn…...

Python知识点:如何应用Python工具,使用NLTK进行语言模型构建

开篇,先说一个好消息,截止到2025年1月1日前,翻到文末找到我,赠送定制版的开题报告和任务书,先到先得!过期不候! 如何使用NLTK进行语言模型构建 在自然语言处理(NLP)中&a…...

深入浅出MySQL

深入浅出MySQL 以下内容参考自 《MySQL是怎样运行的:从根儿上理解MySQL》一书,强烈推荐 存储引擎 对于不同的表可以设置不同的存储引擎 CREATE TABLE tableName (xxxx ) ENGINE 引擎名称; # 修改 ALTER TABLE tableName ENGINE xxx; 编码格式 my…...

【WRF工具】cmip6-to-wrfinterm工具概述:生成WRF中间文件

cmip6-to-wrfinterm工具概述 cmip6-to-wrfinterm工具安装cmip6-to-wrfinterm工具使用快速启动(Quick start)情景1:MPI-ESM-1-2-HR(默认):情景2:BCMM情景3:EC-Earth3 更改使用&#x…...

大厂面试真题:阿里经典双重检测DCL对象半初始化问题

阿里面试题中提到的双重检测DCL(Double-Checked Locking)对象半初始化问题,是Java多线程编程中一个经典的问题。以下是对这一问题的详细解析: 一、双重检测锁(DCL)概述 双重检测锁是一种用于实现单例模式…...

20款奔驰CLS300升级原厂抬头显示HUD 23P智能辅助驾驶 触摸屏人机交互系统

以下是为您生成的一份关于 18 款奔驰 CLS 老款改新款的改装文案: 18 款奔驰 CLS 老款改新款:科技升级,畅享极致驾驶体验 在汽车改装的世界里,每一次的升级都是对卓越的追求。今天,让我们一同探索 18 款奔驰 CLS 老款改…...

GoogleNet原理与实战

在2014年的ImageNet图像识别挑战赛中,一个名叫GoogLeNet 的网络架构大放异彩。以前流行的网络使用小到11,大到77的卷积核。本文的一个观点是,有时使用不同大小的卷积核组合是有利的。 回到他那个图里面你会发现,这里的一个通过我们最大的池化…...

MongoDB 数据库服务搭建(单机)

下载地址 下载测试数据 作者:程序那点事儿 日期:2023/02/15 02:16 进入下载页,选择版本后,右键Download复制连接地址 下载安装包 ​ wget https://fastdl.mongodb.org/linux/mongodb-linux-x86_64-rhel70-5.0.14.tgz​ …...

基于springboot+小程序的智慧物业平台管理系统(物业1)

👉文末查看项目功能视频演示获取源码sql脚本视频导入教程视频 1、项目介绍 智慧物业平台管理系统按照操作主体分为管理员和用户。 1、管理员的功能包括报修管理、投诉管理管理、车位管理、车位订单管理、字典管理、房屋管理、公告管理、缴费管理、维修指派管理、…...

[SpringBoot] 苍穹外卖--面试题总结--上

前言 1--苍穹外卖-SpringBoot项目介绍及环境搭建 详解-CSDN博客 2--苍穹外卖-SpringBoot项目中员工管理 详解(一)-CSDN博客 3--苍穹外卖-SpringBoot项目中员工管理 详解(二)-CSDN博客 4--苍穹外码-SpringBoot项目中分类管理 详…...

[C#]使用onnxruntime部署yolov11-onnx实例分割模型

【官方框架地址】 https://github.com/ultralytics/ultralytics.git 【算法介绍】 在C#中使用ONNX Runtime部署YOLOv11-ONNX实例分割模型,涉及到模型的加载、数据预处理、模型推理和后处理几个关键步骤。 首先,需要确保已经安装了ONNX Runtime的NuGe…...

Polars的Config

Config Config 内容使用示例设置并行执行设置日志详细程度指定null值设置推断schema的行数启用低内存模式获取当前配置选项的值 在Polars的Python API中,Config部分提供了配置选项,允许用户自定义Polars的行为。以下是一些可配置的选项及其使用示例&…...

【面试官】 多态连环问

以下是一些关于封装的常见面试题及答案: 封装 1. 什么是封装? 答案:封装是面向对象编程的三大特性之一,它是将数据和操作数据的方法绑定在一起,并且通过访问修饰符限制对数据的直接访问,只提供特定的方法来…...

Vue 路由设置

为了防止遗忘,记录一下用Vue写前端配置路由时的过程,方便后续再需要用到时回忆。 一、举个例子 假如需要实现这样的界面逻辑: 在HomePage中有一组选项卡按钮用于导航到子页面,而子页面Page1中有一个按钮,其响应事件是…...

力扣110:判断二叉树是否为平衡二叉树

利用二叉树遍历的思想编写一个判断二叉树,是否为平衡二叉树 示例 : 输入:root [3,9,20,null,null,15,7] 输出:true思想: 代码: int getDepth(struct TreeNode* node) {//如果结点不存在,返回…...

Chromium 中JavaScript Fetch API接口c++代码实现(一)

Fetch API主要暴露了三个接口一个方法。 三个接口 Request(资源请求)Response(请求的响应)Headers(Request/Response头部信息)一个方法 fetch()(获取资源调用的方法更多介绍参考 Fetch API - Web API | MDN (mozilla.org) 一、 来看一段前端代码 <!DOCTYPE html> <h…...

ARM(5)内存管理单元MMU

一、虚拟地址和物理地址 首先&#xff0c;计算机系统的内存被组成一个由M个连续的字节大小组成的数组。每字节都会有一个唯一的物理地址。CPU访问内存最简单的方式就是使用物理地址。如下图&#xff1a; 图 1 物理地址,物理寻址 而现在都是采用的都是虚拟寻址的方法。CPU生成一…...

文件上传漏洞原理

原理&#xff1a;\n应用中存在上传功能&#xff0c;但是上传的文件没有经过严格的合法性检验或者检验函数存在缺陷&#xff0c;导致可以上传木马文件到服务器&#xff0c;并且能够执行其中的恶意代码。\n\n危害&#xff1a;\n服务器的网页篡改&#xff0c;网站被挂马&#xff0…...

Web安全 - 安全防御工具和体系构建

文章目录 安全标准和框架1. 国内安全标准&#xff1a;等级保护制度&#xff08;等保&#xff09;2. 国际安全标准&#xff1a;ISO27000系列3. NIST安全框架&#xff1a;IDPRR方法4. COBIT与ITIL框架 防火墙防火墙的基本作用防火墙的三种主要类型防火墙的防护能力防火墙的盲区 W…...

服务器数据恢复—raid磁盘故障导致数据库文件损坏的数据恢复案例

服务器存储数据恢复环境&故障&#xff1a; 存储中有一组由3块SAS硬盘组建的raid。上层win server操作系统层面划分了3个分区&#xff0c;数据库存放在D分区&#xff0c;备份存放在E分区。 RAID中一块硬盘的指示灯亮红色&#xff0c;D分区无法识别&#xff1b;E分区可识别&a…...

深入剖析AI大模型:大模型时代的 Prompt 工程全解析

今天聊的内容&#xff0c;我认为是AI开发里面非常重要的内容。它在AI开发里无处不在&#xff0c;当你对 AI 助手说 "用李白的风格写一首关于人工智能的诗"&#xff0c;或者让翻译模型 "将这段合同翻译成商务日语" 时&#xff0c;输入的这句话就是 Prompt。…...

(二)原型模式

原型的功能是将一个已经存在的对象作为源目标,其余对象都是通过这个源目标创建。发挥复制的作用就是原型模式的核心思想。 一、源型模式的定义 原型模式是指第二次创建对象可以通过复制已经存在的原型对象来实现,忽略对象创建过程中的其它细节。 📌 核心特点: 避免重复初…...

DIY|Mac 搭建 ESP-IDF 开发环境及编译小智 AI

前一阵子在百度 AI 开发者大会上&#xff0c;看到基于小智 AI DIY 玩具的演示&#xff0c;感觉有点意思&#xff0c;想着自己也来试试。 如果只是想烧录现成的固件&#xff0c;乐鑫官方除了提供了 Windows 版本的 Flash 下载工具 之外&#xff0c;还提供了基于网页版的 ESP LA…...

鸿蒙中用HarmonyOS SDK应用服务 HarmonyOS5开发一个生活电费的缴纳和查询小程序

一、项目初始化与配置 1. 创建项目 ohpm init harmony/utility-payment-app 2. 配置权限 // module.json5 {"requestPermissions": [{"name": "ohos.permission.INTERNET"},{"name": "ohos.permission.GET_NETWORK_INFO"…...

ArcGIS Pro制作水平横向图例+多级标注

今天介绍下载ArcGIS Pro中如何设置水平横向图例。 之前我们介绍了ArcGIS的横向图例制作&#xff1a;ArcGIS横向、多列图例、顺序重排、符号居中、批量更改图例符号等等&#xff08;ArcGIS出图图例8大技巧&#xff09;&#xff0c;那这次我们看看ArcGIS Pro如何更加快捷的操作。…...

C++使用 new 来创建动态数组

问题&#xff1a; 不能使用变量定义数组大小 原因&#xff1a; 这是因为数组在内存中是连续存储的&#xff0c;编译器需要在编译阶段就确定数组的大小&#xff0c;以便正确地分配内存空间。如果允许使用变量来定义数组的大小&#xff0c;那么编译器就无法在编译时确定数组的大…...

JVM 内存结构 详解

内存结构 运行时数据区&#xff1a; Java虚拟机在运行Java程序过程中管理的内存区域。 程序计数器&#xff1a; ​ 线程私有&#xff0c;程序控制流的指示器&#xff0c;分支、循环、跳转、异常处理、线程恢复等基础功能都依赖这个计数器完成。 ​ 每个线程都有一个程序计数…...

安宝特案例丨Vuzix AR智能眼镜集成专业软件,助力卢森堡医院药房转型,赢得辉瑞创新奖

在Vuzix M400 AR智能眼镜的助力下&#xff0c;卢森堡罗伯特舒曼医院&#xff08;the Robert Schuman Hospitals, HRS&#xff09;凭借在无菌制剂生产流程中引入增强现实技术&#xff08;AR&#xff09;创新项目&#xff0c;荣获了2024年6月7日由卢森堡医院药剂师协会&#xff0…...

【Redis】笔记|第8节|大厂高并发缓存架构实战与优化

缓存架构 代码结构 代码详情 功能点&#xff1a; 多级缓存&#xff0c;先查本地缓存&#xff0c;再查Redis&#xff0c;最后才查数据库热点数据重建逻辑使用分布式锁&#xff0c;二次查询更新缓存采用读写锁提升性能采用Redis的发布订阅机制通知所有实例更新本地缓存适用读多…...

【MATLAB代码】基于最大相关熵准则(MCC)的三维鲁棒卡尔曼滤波算法(MCC-KF),附源代码|订阅专栏后可直接查看

文章所述的代码实现了基于最大相关熵准则(MCC)的三维鲁棒卡尔曼滤波算法(MCC-KF),针对传感器观测数据中存在的脉冲型异常噪声问题,通过非线性加权机制提升滤波器的抗干扰能力。代码通过对比传统KF与MCC-KF在含异常值场景下的表现,验证了后者在状态估计鲁棒性方面的显著优…...