MLib-Optimization模块代码阅读[to be Continued]
2015-05-01 15:35
429 查看
常用机器学习算法最终都会需要求解一个无约束凸优化问题
minw∈ℝdf(x)\; min_{w\in \mathbb R^d}\;f(x)这个模块实现了常用的优化问题求解算法,例如梯度下降法,LBFGS算法等。各种不同的线性求解算法区别在于2点:
下降方向(梯度方向、牛顿方向等)
步长(wolf条件等)
这个模块一共有以下几个文件:
Gradient.scala:针对特定机器学习问题,定义了一些梯度计算函数
Updater.scala:根据计算好的梯度及步长信息来更新迭代
Optimizer.scala:定义凸优化问题 基类 Optimizer,优化函数optimize
GradientDescent.scala:梯度下降算法
LBFGS.scala:LBFGS算法
NNLS.scala:??
下面较为详细的阅读各个文件的源代码。
定义Gradient 继承类:
LogisticGradient for LR
LeastSquaresGradient for linear regression
HingeGradient for SVM
minw∈ℝdf(x)\; min_{w\in \mathbb R^d}\;f(x)这个模块实现了常用的优化问题求解算法,例如梯度下降法,LBFGS算法等。各种不同的线性求解算法区别在于2点:
下降方向(梯度方向、牛顿方向等)
步长(wolf条件等)
这个模块一共有以下几个文件:
Gradient.scala:针对特定机器学习问题,定义了一些梯度计算函数
Updater.scala:根据计算好的梯度及步长信息来更新迭代
Optimizer.scala:定义凸优化问题 基类 Optimizer,优化函数optimize
GradientDescent.scala:梯度下降算法
LBFGS.scala:LBFGS算法
NNLS.scala:??
下面较为详细的阅读各个文件的源代码。
Gradient.scala文件
定义Gradient 基类/** * 计算loss function在某个data point的gradient和loss value */ abstract class Gradient extends Serializable { /** * @param data:一个data point * @param label:data point的标签 * @param weights:权重向量 * * @return (gradient: 梯度, loss: 损失函数值) */ def compute(data: Vector, label: Double, weights: Vector): (Vector, Double) /** * @param cumGradient the computed gradient will be added to this vector * * @return loss:损失函数值 */ def compute(data: Vector, label: Double, weights: Vector, cumGradient: Vector): Double }
定义Gradient 继承类:
LogisticGradient for LR
LeastSquaresGradient for linear regression
HingeGradient for SVM
class LogisticGradient(numClasses: Int) extends Gradient { numClasses match { case 2 => /** * For Binary Logistic Regression. * 考虑到效率,2分类单独做 */ val margin = -1.0 * dot(data, weights) val multiplier = (1.0 / (1.0 + math.exp(margin))) - label axpy(multiplier, data, cumGradient) if (label > 0) { // The following is equivalent to log(1 + exp(margin)) but more numerically stable. MLUtils.log1pExp(margin) } else { MLUtils.log1pExp(margin) - margin }
相关文章推荐
- 建立自己的代码大全 ......to be continued
- CC150第14章JAVA总结 to be continued
- (数字IC)低功耗设计入门(八)——物理级低功耗设计&to be continued?
- jquery[0] ---to be continued
- 【期刊&&会议】机器学习&&深度学习 + 计算机视觉(To be continued..)
- 推荐几个好用的asp.net控件(to be continued)
- GIT Tips (To be continued)
- 各种怪问题 ...... to be continued
- java 中的 String (to be continued)
- 几本不错的开源书(to be continued)
- 算法基元(to be continued)
- 关于联通块DP的一些问题(to be continued)
- C语言常用代码(To be continue...)
- 1012.The Best Rank (25)...to be continued...
- 1014.Waiting in Line (30)...to be continued...
- Survey over pattern string match algorithm[6 items updated && to be continued]
- 1071.Speech Patterns (25)...to be continued...
- toBeContinued h5,bootstrap springboot pythonflask nodejs
- 看美剧学英语,lie te me s01e01 重点单词 to be continued
- 1053.Path of Equal Weight (30)...to be continued...