栏目分类:
子分类:
返回
名师互学网用户登录
快速导航关闭
当前搜索
当前分类
子分类
实用工具
热门搜索
名师互学网 > IT > 软件开发 > 后端开发 > C/C++/C#

C#解析Matrix Marke数据格式

C/C++/C# 更新时间: 发布时间: IT归档 最新发布 模块sitemap 名妆网 法律咨询 聚返吧 英语巴士网 伯小乐 网商动力

C#解析Matrix Marke数据格式

阅读目录

  • 前言

  • 1.Matrix Market格式介绍

  • 2.C#读取Matrix Market文件

  • 3.C#保存数据为Matrix Market文件

  • 4.资源

               本博客所有文章分类的总目录:【总目录】本博客博文总目录-实时更新 

开源Math.NET基础数学类库使用总目录:【目录】开源Math.NET基础数学类库使用总目录

回到目录

前言

  上一篇文章,我们介绍了使用C#读写Matlab的Mat数据格式的情况。mat格式的广泛应用使得很多人都了解,但同样还有一些数据格式也是在科学计算,数据分析,测试等方面的通用数据格式,那就是接下来我们要介绍的Matrix Market格式。我们同样是使用C#来操作该格式。

如果本文资源或者显示有问题,请参考 本文原文地址:http://www.cnblogs.com/asxinyu/p/4266758.html

回到目录

1.Matrix Market格式介绍

  Matrix Market是一个基于AscII的可读性很强的文件格式,目的是促进矩阵数据的交流。NIST的数据存储就有大量的数值线性代数相关的研究比较测试数据采用该格式。其他信息可以参考官网:http://math.nist.gov/MatrixMarket/

http://en.wikipedia.org/wiki/Matrix_Market_exchange_formats

The Matrix Market exchange formats are a set of human readable, ASCII-based file formats designed to facilitate the exchange of matrix data. The file formats were designed and adopted for the Matrix Market, a NIST repository for test data for use in comparative studies of algorithms for numerical linear algebra。

下面是一个Matrix Market矩阵的部分截图,可以直接的理解该格式,的确是非常人性化,也方便不同软件,系统间的数据交换。

回到目录

2.C#读取Matrix Market文件

  本文还是使用Math.NET提供的程序,只不过对其结构和使用进行分析。C#读取的返回值的矩阵或者向量格式也都是Math.NET中的类型。C#读取Martix Market文件的主要类型是MatrixMarketReader,在MathNet.Numerics.Data.Text项目中,而其中的方法都是静态方法,分别为读取矩阵和读取向量,并支持从文件和流中分别读取数据。看看如下几个静态函数的原型,就可以知道怎么样了:  

 1 public static Matrix ReadMatrix(string filePath,Compression compression=Compression.Uncompressed) where T : struct, IEquatable, IFormattable 2  3 public static Vector ReadVector(string filePath,Compression compression=Compression.Uncompressed) where T : struct, IEquatable, IFormattable 4  5 public static Matrix ReadMatrix(Stream stream) where T :struct,IEquatable,IFormattable 6  7 public static Vector ReadVector(Stream stream) where T :struct,IEquatable,IFormattable 8  9 public static Matrix ReadMatrix(TextReader reader) where T :struct,IEquatable,IFormattable10 11 public static Vector ReadVector(TextReader reader) where T :struct,IEquatable,IFormattable

  上面要注意的是,该文件支持压缩,所以有一个Compression参数,默认是未压缩的。

回到目录

3.C#保存数据为Matrix Market文件

  C#写入Matrix Market文件的方法和上面的读取类似,使用的是MatrixMarketWriter类的静态方法,支持写入矩阵和向量,方法原型如下:

 1 public static void WriteMatrix(string filePath, Matrix matrix, Compression compression = Compression.Uncompressed) where T : struct, IEquatable, IFormattable 2  3 public static void WriteVector(string filePath, Vector vector, Compression compression = Compression.Uncompressed) where T : struct, IEquatable, IFormattable 4  5 public static void WriteMatrix(Stream stream, Matrix matrix) where T : struct, IEquatable, IFormattable 6  7 public static void WriteVector(Stream stream, Vector vector) where T:struct,IEquatable,IFormattable 8  9 public static void WriteMatrix(TextWriter writer,Matrix matrix) where T :struct,IEquatable, IFormattable10 11 public static void WriteVector(TextWriter writer, Vector vector) where T :struct,IEquatable, IFormattable

  一般来说,写入文件比较常用一点,可以用于系统之间和样本数据的传递。总共就2个类,常用的也就4个方法,使用C#操作该数据格式就可以无忧了。

回到目录

4.资源

  源码下载:参考官网网站。

  如果本文资源或者显示有问题,请参考 本文原文地址:http://www.cnblogs.com/asxinyu/p/4266758.html

本博客还有大量的.NET开源技术文章,您可能感兴趣: 

1.开源Math.NET基础数学类库使用系列文章:链接

2.开源C#彩票数据资料库系列文章:链接

3.开源的.NET平台ORM组件文章:链接

4.其他开源的.NET组件文章:链接

5..NET平台机器学习组件-Infer.NET系列文章:链接

6.Matlab混合编程文章:链接  


转载请注明:文章转载自 www.mshxw.com
本文地址:https://www.mshxw.com/it/231204.html
我们一直用心在做
关于我们 文章归档 网站地图 联系我们

版权所有 (c)2021-2022 MSHXW.COM

ICP备案号:晋ICP备2021003244-6号