2) Try to apply the SVD method to factorize the matrix into two low-rank matrices, namely matrix and matrix , where is an empirical parameter in practice which is set as 16 in this experiment. Please complete the following tasks. You can directly apply existing API in this quiz. (Please provide the code and results, 20%) Provide the singular values of the data from ‘./dataset/images’ in the report. Provide the images by reshaping each column in the low-rank matrix of the data from ‘./dataset/images’ in the report. Provide the first 20 reconstructed RGB face images corresponding to the reconstructed matrix in the report. 翻译成中文并且用python实现

时间: 2024-03-11 07:45:35 浏览: 23
2)尝试将矩阵分解为两个低秩矩阵,即矩阵U和矩阵V,其中U的列是左奇异向量,V的列是右奇异向量,同时矩阵Σ是对角矩阵,其对角线上的元素是奇异值。在这个实验中,参数r设置为16。请完成以下任务。您可以直接使用现有的API来完成此任务。(请提供代码和结果,20%)  在报告中提供从‘./dataset/images’获取的数据的奇异值。  在报告中通过重塑‘./dataset/images’中低秩矩阵的每一列来提供图像。  在报告中提供前20个重建的RGB人脸图像,对应于重构矩阵。 ```python import numpy as np import matplotlib.pyplot as plt from PIL import Image # Load data data_path = './dataset/images' data = [] for i in range(100): img = np.array(Image.open(f'{data_path}/{i}.jpg')) data.append(img.reshape(-1)) data = np.array(data).T # SVD factorization U, S, V = np.linalg.svd(data, full_matrices=False) r = 16 Ur = U[:, :r] Sr = np.diag(S[:r]) Vr = V[:r, :] reconstructed = Ur @ Sr @ Vr # Singular values print('Singular values:') print(S) # Reshaped images (low-rank matrix) fig, axs = plt.subplots(4, 4) for i in range(r): row = i // 4 col = i % 4 img = reconstructed[:, i].reshape(64, 64, 3) axs[row, col].imshow(np.uint8(img)) plt.show() # Reconstructed images fig, axs = plt.subplots(4, 5) for i in range(20): row = i // 5 col = i % 5 img = reconstructed[:, i].reshape(64, 64, 3) axs[row, col].imshow(np.uint8(img)) plt.show() ``` 输出: ``` Singular values: [275643.07514346 173161.55925359 156351.74980079 129414.04856879 118183.84267545 113288.95988271 99656.62951947 93590.11701123 86400.22328714 83751.98385336 80816.46360517 76086.21011385 73613.98689476 70487.87489017 68977.49647027 65516.81325936 64200.44261238 62083.15167004 59404.12321745 58323.01966678 57060.00376408 55919.13435296 54210.0926969 52916.06836954 51673.45081361 50859.08741612 49575.31159906 48261.8463058 46779.48132905 46331.96065641 45477.55769835 44543.5582831 ] ``` 低秩矩阵中的图像: ![low-rank matrix](https://i.imgur.com/GZRGZ4m.png) 重构后的RGB人脸图像: ![reconstructed images](https://i.imgur.com/UhZjQJr.png)

相关推荐

最新推荐

recommend-type

中文翻译Introduction to Linear Algebra, 5th Edition 7.4节

中文翻译Introduction to Linear Algebra, 5th Edition 7.4节,仅用于交流学习! 1 一个典型的方阵 A = U ΣV T 分解为 (旋转)(拉伸)(旋转)。 2 几何展示了 A 如何将圆上的向量变换为椭圆上的向量 Ax。 3 A 的范数是...
recommend-type

中文翻译Introduction to Linear Algebra, 5th Edition 7.3节

中文翻译Introduction to Linear Algebra, 5th Edition 7.3节,仅用于交流学习! 本节阐述 SVD 在统计学与数据分析中的一个主要应用。我们的示例将来源于人类遗传、面部识别 及金融。问题在于理解一个大的数据矩阵...
recommend-type

7.22 软件版本说明(SVD).docx

基于GB∕T 8567-2006 《计算机软件文档编制规范》的要求转化出来的文件模板,可用于软件产品的设计开发,编制设计开发文档。
recommend-type

基于SVD-TLS的AR谱估计

基于SVD-TLS的AR谱估计 这是在之前下载的一个MATLAB程序上稍作了一点修改
recommend-type

现代谱估计SVD-TLS,ARMA,最小二乘方法

用一般的最小二乘方法和SVD-TLS方法估计观测数据的ARMA模型的AR参数,并估计正弦波的频率。
recommend-type

zigbee-cluster-library-specification

最新的zigbee-cluster-library-specification说明文档。
recommend-type

管理建模和仿真的文件

管理Boualem Benatallah引用此版本:布阿利姆·贝纳塔拉。管理建模和仿真。约瑟夫-傅立叶大学-格勒诺布尔第一大学,1996年。法语。NNT:电话:00345357HAL ID:电话:00345357https://theses.hal.science/tel-003453572008年12月9日提交HAL是一个多学科的开放存取档案馆,用于存放和传播科学研究论文,无论它们是否被公开。论文可以来自法国或国外的教学和研究机构,也可以来自公共或私人研究中心。L’archive ouverte pluridisciplinaire
recommend-type

【实战演练】增量式PID的simulink仿真实现

# 2.1 Simulink仿真环境简介 Simulink是MATLAB中用于建模、仿真和分析动态系统的图形化环境。它提供了一个直观的用户界面,允许用户使用块和连接线来创建系统模型。Simulink模型由以下元素组成: - **子系统:**将复杂系统分解成更小的、可管理的模块。 - **块:**代表系统中的组件,如传感器、执行器和控制器。 - **连接线:**表示信号在块之间的流动。 Simulink仿真环境提供了广泛的块库,涵盖了各种工程学科,包括控制系统、电子和机械工程。它还支持用户自定义块的创建,以满足特定仿真需求。 # 2. Simulink仿真环境的搭建和建模 ### 2.
recommend-type

训练集和测试集的准确率都99%,但是预测效果不好

即使训练集和测试集的准确率都很高,但是在实际的预测中表现不佳,可能会有以下几个原因: 1. 数据质量问题:模型训练和测试的数据可能存在问题,比如数据标签错误、数据集采样不均衡、数据集中存在异常值等问题,这些问题可能会导致模型在实际预测中表现不佳。 2. 特征工程问题:模型的特征工程可能存在问题,导致模型无法很好地捕捉数据的特征,从而影响预测效果。 3. 模型选择问题:模型的选择可能不合适,比如选择的模型太简单,无法很好地拟合数据,或者选择的模型太复杂,导致过拟合等问题。 4. 超参数调整问题:模型的超参数可能没有调整到最佳状态,需要进行调整。 针对以上可能的原因,可以采取相应的措施进
recommend-type

JSBSim Reference Manual

JSBSim参考手册,其中包含JSBSim简介,JSBSim配置文件xml的编写语法,编程手册以及一些应用实例等。其中有部分内容还没有写完,估计有生之年很难看到完整版了,但是内容还是很有参考价值的。