mahout分析(1) org.apache.mahout.matrix
1、前言在进行机器学习研究时,最重要的就是数据,而数据离不开矩阵和向量,所以,我觉得分析mahout项目最先从矩阵和向量开始。在分析之前,我比较关注以下几个问题。
1、它是怎么通过矩阵来保存数据;
2、提供那些计算方法来计算矩阵;
3、提供什么方法来生成矩阵;
4、......
2、API
首先,看一下org.apache.mahout.matrix 类的API,
2.1、接口汇总
InterfaceSummaryBinaryFunction This interface allows the formulation of binary functions to be applied tomatrices inside the inner loops of their implementations.
矩阵内部用于二进制运算的一些功能和函数
Matrix The basic interface including numerous convenience functions
提供许多便捷函数的接口
UnaryFunction This interface allows the formulation of unary functions to be applied tomatrices inside the inner loops of their implementations.
矩阵内部的一元函数
Vector The basic interface including numerous convenience functions
矢量
Vector.Element 这里再将Matrix和Vector接口的方法再详细讲解一下
2.1.1 Matrix接口提供的方法:
提供以下五种方法来配置矩阵
Matrixassign(double value)
Assign the value to all elements of the receiver Matrix assign(double[][] values)
Assign the values to the receiver
通过数组配置
Matrix assign(Matrix other)
Assign the other vector values to the receiver
通过另外Matrix属性进行配置,应该用于复制矩阵的方法。
Matrix assign(Matrix other,BinaryFunction function)
Apply the function to each element of the receiver and the correspondingelement of the other argument
这个没有看懂,后面二进制函数主要功能不太清楚
Matrix assign(UnaryFunction function)
Apply the function to each element of the receiver
这个没有看懂,一元函数的功能不太清楚
还提供通过行、列的序号的矢量来分配矩阵
MatrixassignColumn(int column,Vector other)
Assign the other vector values to the column of the receiver MatrixassignRow(int row,Vector other)
Assign the other vector values to the row of the receive 当然,还提供通过行、列序号来获取矩阵中某一行、某一列的值;提供矩阵相乘、数乘的方法等。
另外,拉普拉斯定理还不太清楚。
oubledeterminant()
Returns matrix determinator using Laplace theorem 2.1.2 Vector接口提供的方法
和Matrix一样,提供六种分配矢量的方法
Vector assign(BinaryFunction f,double y)
Apply the function to each element of the receiver, using the y value asthe second argument of the BinaryFunction
通过一个二元函数和y进行分配
Vectorassign(double value)
Assign the value to all elements of the receiver Vectorassign(double[] values)
Assign the values to the receiver Vector assign(UnaryFunction function)
Apply the function to each element of the receiver
通过一元函数进行分配
Vectorassign(Vector other)
Assign the other matrix values to the receiver Vectorassign(Vector other,BinaryFunction function)
Apply the function to each element of the receiver and the correspondingelement of the other argument int cardinality () 函数返回矢量中元素的最大个数,及基数
Matrix cross (Vector other) 提供外积的方法,返回一个矩阵。
double dot (Vector x) 提供内积的方法,返回一个数值
Vector normalize () 均一化
当然还提供矢量相乘和相除的方法
3、小结
单从接口来看,提供了很多非常灵活的方法可以扩展,基本包含了矩阵和矢量的基本运算方法,下一步将分析这些方法的具体实现。
页:
[1]