美文网首页
8.4 阴 鸽巢 群 regularize

8.4 阴 鸽巢 群 regularize

作者: 反复练习的阿离很笨吧 | 来源:发表于2018-10-25 17:06 被阅读0次

每次上组合数学都会想:
是谁这么机智想出这么巧的方法的!

晚上和一个妹子做大数据实验,三个实验,HDFS、HBase、NoSQL都做了,开心耶,数据库初体验。
我终于知道当时为什么一直找不到命令,就是因为教程上的命令打错了,中文-和英文-是有区别的,啊啊啊啊啊啊啊啊!
大量不cd到文件夹,打多/,复制的时候$也复制上了,复制的时候#也复制上了,打错文件名,复制的时候忘改版本号,眼花缭乱,我是不是真的不适合学计算机?
我觉得吧,向量化一个很大的用途就是不用写for loop了。
我感觉这里的x是列向量,写成X矩阵的时候,就转置成传统数据库的行形式。
完了,我已经忘记regularized和unregularized是在哪里出现的了。

function [J, grad] = lrCostFunction(theta, X, y, lambda)
%LRCOSTFUNCTION Compute cost and gradient for logistic regression with 
%regularization
%   J = LRCOSTFUNCTION(theta, X, y, lambda) computes the cost of using
%   theta as the parameter for regularized logistic regression and the
%   gradient of the cost w.r.t. to the parameters. 

% Initialize some useful values
m = length(y); % number of training examples

% You need to return the following variables correctly 
J = 0;
grad = zeros(size(theta));

% ====================== YOUR CODE HERE ======================
% Instructions: Compute the cost of a particular choice of theta.
%               You should set J to the cost.
%               Compute the partial derivatives and set grad to the partial
%               derivatives of the cost w.r.t. each parameter in theta
%
% Hint: The computation of the cost function and gradients can be
%       efficiently vectorized. For example, consider the computation
%
%           sigmoid(X * theta)
%
%       Each row of the resulting matrix will contain the value of the
%       prediction for that example. You can make use of this to vectorize
%       the cost function and gradient computations. 
%
% Hint: When computing the gradient of the regularized cost function, 
%       there're many possible vectorized solutions, but one solution
%       looks like:
%           grad = (unregularized gradient for logistic regression)
%           temp = theta; 
%           temp(1) = 0;   % because we don't add anything for j = 0  
%           grad = grad + YOUR_CODE_HERE (using the temp variable)
%

J=(-y'*log(sigmoid(X*theta))-(1-y)'*log(1-sigmoid(X*theta)))/m+lambda * sum(theta(2:end).^2)/(2*m);

%grad=(X'*sigmoid(X*theta)-y)/m; 括号写着写着就忘了,辣鸡matlab
grad=(X'*(sigmoid(X*theta)-y))/m;
%theta_s = [0; theta(2:end)]; 下面用的temp把bias值置为0
temp=theta;
temp(1)=0;
%grad=grad+lambda/m*sum(temp); 这里公式抄错了,是没有sigma的
grad=grad+lambda/m*temp;


% =============================================================

grad = grad(:);

end


相关文章

  • 8.4 阴 鸽巢 群 regularize

    每次上组合数学都会想:是谁这么机智想出这么巧的方法的! 晚上和一个妹子做大数据实验,三个实验,HDFS、HBase...

  • 鸽巢原理

    人教版小学数学六年级下册数学广角的内容是鸽巢原理。什么是鸽巢原理呢?鸽巢原理又称抽屉原理,它是组合数学的一个...

  • 鸽巢原理

    别名 鸽笼原理,狄利克雷抽屉原理 表述 表述1:若有n个笼子和n+1只鸽子,所有的鸽子都被关在鸽笼里,那么至少有一...

  • 鸽巢问题

  • [Combinatorial] 6 容斥与鸽巢

    6 容斥和鸽巢我想容斥就是把不好算的补集的并集转化为求交集。交集是很好球的了。鸽巢比较难的一个地方就是,如何构造鸽...

  • 4.17源桐教学反馈(想到了收玩具)

    4.17源桐教学反馈[爱心][爱心] 了解到今天的鸽巢原理源桐上课没有听太懂,就用一节课来复习鸽巢问题,再一次过课...

  • 【机器学习】-Week3 11. Regularized log

    Regularized Logistic Regression We can regularize logisti...

  • 鳌头漫笔(42)鸽巢路

    鸽巢路,顾名思义邻近鸽巢河 是鳌江镇区第四条出城道路 排在曙光路,新河路,车站大道后 北接一零四国道,南连滨江大道...

  • 推荐模型的自适应细粒度正则化

    KDD'19 论文 LambdaOpt: Learn to Regularize Recommender Mode...

  • 【恋恋风尘】鸽回巢

    当商务车堵在外滩的时候,宋如南莫名地想到了下午看见的那群鸽子。那时她正对着镜子化妆,四五点钟的天光澄澈又哀怨,极淡...

网友评论

      本文标题:8.4 阴 鸽巢 群 regularize

      本文链接:https://www.haomeiwen.com/subject/dboqtqtx.html