docs/apis/PSModel.md
PSModel是Angel中最核心的抽象类,它封装了远程参数服务器的Context和Client细节,提供了常用的远程矩阵(Matrix)和向量(Vector)的获取和更新接口,使得算法工程师可以如同操作本地对象一样的操作参数服务器上的分布式矩阵和向量,它是一个可以进行反复迭代更新的可变模型对象。
PSModel中包含了MatrixContext,MatrixClient,TaskContext这3个核心类,可以对远程的参数服务器进行任意的操作。
编写机器学习算法,建议都通过MLModel获得PSModel后,对它进行编程开发。PSModel包括了如下5大类接口:
可以看出,通过合理初始化PSModel,设置PSModel的行为属性,调用PSModel的各个方法,算法工程师可以完成所有对远程分布式模型(Martrix或者Vector)的任意操作,编写各种具有强分布能力的机器学习算法,而无需关心底层细节,是Angel的核心抽象类。
构造方法
定义: def apply[K <: TVector](modelName: String, row: Int, col: Int, blockRow: Int = -1, blockCol: Int = -1)(implicit ctx:TaskContext)
参数:
getRow
def getRow(rowId: Int): KgetRows
def getRows(rowIndexes:Array[Int]): List[K]getRowsFlow
def getRowsFlow(rowIndex: RowIndex, batchNum: Int): GetRowsResultget
def get(func: GetFunc): GetResultgetRowWithIndex
def getRowWithIndex(rowIndex: Int, index: Array[Int]): TVectorgetRowWithLongIndex
def getRowWithLongIndex(rowIndex: Int, index: Array[Long]): TVectorgetRowWithIndex
def getRowWithIndex(rowIndex: Int, index: Array[Int]): TVectorgetRowWithLongIndex
def getRowWithLongIndex(rowIndex: Int, index: Array[Long]): TVectorincrement
def increment(delta: TVector)increment
def increment(deltas: List[TVector])update
def update(func: UpdaterFunc): Future[VoidResult]syncClock
def syncClock():clock
def clock(): Future[VoidResult]flush
def flush(): Future[VoidResult]setLoadPath
def setLoadPath(path: String)setSavePath
def setSavePath(path: String)setAverage
def setAverage(aver: Boolean)setHogwild
def setHogwild(hogwild: Boolean)setRowType
def setRowType(rowType: MLProtos.RowType)rowType: MLProtos.RowType 目前支持矩阵行向量的元素类型和存储方式有:
用户可以根据实际算法情况,选择最节省内存的存储方式
setOplogType
定义:def setOplogType(oplogType: String)
功能:矩阵更新存储方式,当使用increment方法更新矩阵时,Angel会先将更新行向量缓存在本地。缓存的方式是在本地定义一个和待更新矩阵维度一致的矩阵
参数:
目前支持的存储方式有:
返回值:无
setAttribute
def setAttribute(key: String, value: String)