mahout分析(1) org.apache.mahout.matrix

 

1、前言

在进行机器学习研究时,最重要的就是数据,而数据离不开矩阵和向量,所以,我觉得分析mahout项目最先从矩阵和向量开始。在分析之前,我比较关注以下几个问题。

1、它是怎么通过矩阵来保存数据;

2、提供那些计算方法来计算矩阵;

3、提供什么方法来生成矩阵;

4、......

 

2、API

  首先,看一下org.apache.mahout.matrix 类的API,

2.1、接口汇总

Interface Summary
BinaryFunction

This interface allows the formulation of binary functions to be applied to matrices 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 to matrices inside the inner loops of their implementations.

矩阵内部的一元函数

Vector

The basic interface including numerous convenience functions

矢量

Vector.Element

 

    这里再将Matrix和Vector接口的方法再详细讲解一下

2.1.1 Matrix接口提供的方法

提供以下五种方法来配置矩阵

 

 Matrix assign (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 corresponding element of the other argument

这个没有看懂,后面二进制函数主要功能不太清楚

 Matrix

assign (UnaryFunction  function)
          Apply the function to each element of the receiver

这个没有看懂,一元函数的功能不太清楚

 

还提供通过行、列的序号的矢量来分配矩阵

 Matrix assignColumn (int column, Vector  other)
          Assign the other vector values to the column of the receiver
 Matrix assignRow (int row, Vector  other)
          Assign the other vector values to the row of the receive

 

当然,还提供通过行、列序号来获取矩阵中某一行、某一列的值;提供矩阵相乘、数乘的方法等。

另外,拉普拉斯定理还不太清楚。

ouble determinant ()
          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 as the second argument of the BinaryFunction

通过一个二元函数和y进行分配

 Vector assign (double value)
          Assign the value to all elements of the receiver
 Vector assign (double[] values)
          Assign the values to the receiver
 Vector

assign (UnaryFunction  function)
          Apply the function to each element of the receiver

通过一元函数进行分配

 Vector assign (Vector  other)
          Assign the other matrix values to the receiver
 Vector assign (Vector  other, BinaryFunction  function)
          Apply the function to each element of the receiver and the corresponding element of the other argument

 

 

int cardinality ()         函数返回矢量中元素的最大个数,及基数
Matrix cross (Vector  other)     提供外积的方法,返回一个矩阵。
double dot (Vector  x)        提供内积的方法,返回一个数值
Vector normalize ()         均一化
当然还提供矢量相乘和相除的方法

 

3、小结

单从接口来看,提供了很多非常灵活的方法可以扩展,基本包含了矩阵和矢量的基本运算方法,下一步将分析这些方法的具体实现。

 

 

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值