zoukankan      html  css  js  c++  java
  • UFLDL 教程学习笔记(一)

         ufdl的新教程,从基础学起。第一节讲的是线性回归。主要目的是熟悉目标函数,计算梯度和优化。

         按着教程写完代码后,总是编译出错,一查是mex的原因,实在不想整了。

         这位博主用的是向量,比较简洁:http://blog.csdn.net/lingerlanlan/article/details/38377023

          这位博主用的是循环,更好理解:http://www.cnblogs.com/william7neral/p/4448566.html

          接下来是logistic regression和向量化,没什么好说的:http://blog.csdn.net/lingerlanlan/article/details/38390085

          

          这节主要是完成liner_regression.m,包括计算目标函数f和梯度g,需要注意的是要分清变量是列向量还是行向量或是矩阵。

           对matlab不太熟,所以我稍微注释了下

          

    function [f,g] = linear_regression(theta, X,y)
      %
      % Arguments:
      %   theta - A vector containing the parameter values to optimize.列向量
      %   X - The examples stored in a matrix.
      %       X(i,j) is the i'th coordinate of the j'th example.
      %   y - The target value for each example.  y(j) is the target for
      %   example j.行向量
      %
      %size(a,1)求矩阵的行数 size(a,2)求矩阵的列数,相当于length(a)
      %size(a)同时求矩阵的行和列数
      % m=size(X,2);
      m = size(X,2);
      n=size(X,1);
    
      f=0;
      g=zeros(size(theta));
    
      %
      % TODO:  Compute the linear regression objective by looping over the examples in X.
      %        Store the objective function value in 'f'.
      %
      % TODO:  Compute the gradient of the objective with respect to theta by looping over
      %        the examples in X and adding up the gradient for each example.  Store the
      %        computed gradient in 'g'.
      
    %%% YOUR CODE HERE %%%
    h = theta' * X
    f = (1/2)* (h-y)' * (h-y)
    g = X * (h - y)'
    View Code

          

          

  • 相关阅读:
    centos7安装zabbix3.4
    Linux修改网卡名称enss33到eth0--Ubuntu16和centos7
    记一次zabbix server挂掉的事件
    angularJs 技巧总结及最佳实践
    Yii2中的format
    本博客停止更新,新内容在个人网站上
    说下browserslist
    Yii2 软删除
    vue-webpack-boilerplate分析
    Node总结 模块机制
  • 原文地址:https://www.cnblogs.com/573177885qq/p/4783465.html
Copyright © 2011-2022 走看看