显示标签为“Coursera”的博文。显示所有博文
显示标签为“Coursera”的博文。显示所有博文

2013-06-25

Machine Learning 第八波编程作业(完)——Anomaly Detection and Recommender Systems

仅列出核心代码:

1.estimateGuassian.m

mu = mean(X)';
X2 = (X - ones(m, 1)*mu').^2;
sigma2 = mean(X2);

2.selectThreshold.m

cvPredictions = (pval < epsilon);
tp = sum((cvPredictions == 1) & (yval == 1));
fp = sum((cvPredictions == 1) & (yval == 0));
fn = sum((cvPredictions == 0) & (yval == 1));
prec = tp/(tp + fp);
rec = tp/(tp + fn);
F1 = 2*prec*rec/(prec + rec);

3.cofiCostFunc.m

X1 = (X*Theta'- Y).*R;
reg1 = (sum(sum(X.^2)) + sum(sum(Theta.^2)))*lambda/2;
J = sum(sum((X1).^2))/2 + reg1;

X_grad = X1*Theta + lambda*X;
Theta_grad = X1'*X + lambda*Theta;

课程地址:https://www.coursera.org/course/ml

 

2013-06-18

Machine Learning 第七波编程作业——K-means Clustering and Principal Component Analysis

仅列出核心代码:

1.findClosestCentroids.m

m = size(X, 1);
len = zeros(K, 1);
for i = 1:m
    for j = 1:K
        len(j) = norm(X(i, :) - centroids(j, :))^2;
    end
    [~, idx(i)] = min(len);
end

2.computeCentroids.m

for k = 1:K
    ind = find(idx == k);
    centroids(k, :) = mean(X(ind, :));
end

3.pca.m

Sigma = X'*X/m;
[U,S,~] = svd(Sigma);

4.projectData.m

Z = X * U(:, 1:K);

5.recoverData.m

X_rec = Z * U(:, 1:K)';

课程地址:https://www.coursera.org/course/ml

2013-06-11

Machine Learning 第六波编程作业——Support Vector Machines

仅列出核心代码:

1.gaussianKernel.m

sim = exp(-sum((x1 - x2).^2) /(2*sigma^2));

2.dataset3Params.m

TD =  [0.01, 0.03, 0.1, 0.3, 1, 3, 10, 30];
pre_err = zeros(length(TD));
for i = 1:length(TD)
    for j = 1:length(TD)
        C = TD(i);
        sigma = TD(j);
        model= svmTrain(X, y, C, @(x1, x2) gaussianKernel(x1, x2, sigma));
        predictions = svmPredict(model, Xval);
        pre_err(i, j) = mean(double(predictions ~= yval));
    end
end
mm = min(min(pre_err));
[ind_C, ind_sigma] = find(pre_err == mm);
C = TD(ind_C);
sigma = TD(ind_sigma);

3.processEmail.m

for i = 1:length(vocabList)
v = strcmp(str, vocabList(i));
    if v==1
        word_indices = [word_indices ; i];
    end
end

4.emailFeatures.m

x(word_indices) = 1;

课程地址:https://www.coursera.org/course/ml

2013-06-03

Machine Learning 第五波编程作业 – Regularized Linear Regression and Bias/Variance

仅列出核心代码:

1.linearRegCostFunction.m

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

grad(2:end) = (X(:, 2:end).' * (h - y)) /m ...
+ (lambda/m) * theta(2:end);

2.learningCurve.m

for i = 1:m
    Xi = X(1:i, :);
    yi = y(1:i);
    lambda = 1;
    [theta] = trainLinearReg(Xi, yi, lambda);
    lambda = 0;
    % For train error, make sure you compute it on the training subset
    [error_train(i), ~] = linearRegCostFunction(Xi, yi, theta, lambda);
    % For validation error, compute it over the entire cross validation set
    [error_val(i), ~] = linearRegCostFunction(Xval, yval, theta, lambda);
end

3.polyFeatures.m

for i =1:p
    X_poly(:, i) = X(:, 1).^i;
end

4.validationCurve.m

for i = 1:length(lambda_vec)
    [theta] = trainLinearReg(X, y, lambda_vec(i));
    % For train error, make sure you compute it on the training subset
    [error_train(i), ~] = linearRegCostFunction(X, y, theta, 0);
    % For validation error, compute it over the entire cross validation set
    [error_val(i), ~] = linearRegCostFunction(Xval, yval, theta, 0);
end

课程地址:https://www.coursera.org/course/ml

2013-05-28

Machine Learning 第四波编程作业 - Neural Networks: Learning

仅列出核心代码:

1.sigmoidGradient.m

h = 1.0 ./ (1.0 + exp(-z));
g = h.*(1 - h);

2.randInitializeWeights.m

epsilon_init = 0.12;
W = rand(L_out, 1 + L_in)*2*epsilon_init - epsilon_init;

3.nnCostFunction.m

% cost function

A1 = X;
A1 = [ones(m, 1), A1];
Z2 = A1 * Theta1.';
A2 = sigmoid(Z2);
A2 = [ones(m, 1), A2];
Z3 = A2 * Theta2.';
A3 = sigmoid(Z3);
H = A3;
Y = zeros(m, num_labels);
for ind = 1:m
Y(ind, y(ind)) = 1;
end
K = num_labels;
Jk = zeros(K, 1);

for k =1:K

Jk(k) = ( -Y(:, k).' *log(H(:, k)) )-( (1 - Y(:, k)).' * log(1-H(:, k)) );

end
J = sum(Jk)/m;

J = J + ( lambda/(2*m) )*( sum(sum(Theta1(:, 2:end).^2))+sum(sum(Theta2(:, 2:end).^2)) );

% Unroll gradients

delta3 = A3 - Y;
delta2 = delta3*Theta2.* (A2.*(1-A2));
delta2 = delta2(:, 2: end);
Delta2 = zeros(size(delta3, 2), size(A2, 2));
Delta1 = zeros(size(delta2, 2), size(A1, 2));
for i=1:m
Delta2 = Delta2 + delta3(i, :).' * A2(i, :);
Delta1 = Delta1 + delta2(i, :).' * A1(i, :);
end
Theta1_grad = Delta1/m;
Theta1_grad(:, 2:end) = Theta1_grad(:, 2:end) + Theta1(:, 2:end)*(lambda/m);
Theta2_grad = Delta2/m;
Theta2_grad(:, 2:end) = Theta2_grad(:, 2:end) + Theta2(:, 2:end)*(lambda/m);
grad = [Theta1_grad(:) ; Theta2_grad(:)];
end

课程地址:https://www.coursera.org/course/ml

2013-05-20

Machine Learning 第三波编程作业 – Multi-class Classification and Neural Networks

仅列出核心代码:

1.lrCostFunction.m

h = sigmoid(X * theta);   %   h_theta(X) : m*1
%   Cost func
J = (-log(h.')*y - log(ones(1, m) - h.')*(ones(m, 1) - y)) / m ...
    +(lambda/(2*m)) * sum(theta(2:end).^2);

%   Gradient
grad(1) = (X(:, 1).' * (h - y)) /m;

grad(2:end) = (X(:, 2:end).' * (h - y)) /m ...
    + (lambda/m) * theta(2:end);

2.oneVsAll.m

options = optimset('GradObj', 'on', 'MaxIter', 50);
initial_theta = zeros(size(X, 2), 1);
for c = 1:num_labels
    [all_theta(c, :)] = fmincg (@(t)(lrCostFunction(t, X, (y == c), lambda)),...
        initial_theta, options);   
end

3.predictOneVsAll.m

[~, p] = max(X * all_theta.', [], 2);

4.predict.m

X = [ones(size(X), 1), X]; % Add ones to the X data matrix

X1 = sigmoid(X * Theta1.');
X1 = [ones(size(X1), 1), X1]; % Add ones to the X1 data matrix

[~, p] = max(X1 * Theta2.', [], 2);

课程地址:https://www.coursera.org/course/ml

Machine Learning 第二波编程作业 – Logistic Regression

仅列出核心代码:

1.plotData.m

ind1 = find(y==1); ind0 = find(y==0);
plot(X(ind1, 1), X(ind1, 2), 'k+','LineWidth', 2, 'MarkerSize', 7);
plot(X(ind0, 1), X(ind0, 2), 'ko', 'MarkerFaceColor', 'y', 'MarkerSize', 7);

2.sigmoid.m

g = 1 ./ (ones(size(z)) + exp(-z));

3.costFunction.m

h = sigmoid(X * theta); % h_theta(X) : m*1
J = (-log(h.')*y - log(ones(1, m) - h.')*(ones(m, 1) - y)) / m;
grad = (X.' * (h - y)) /m;

4.predict.m

h = sigmoid(X * theta);
p = (h >= 0.5);

5.costFunctionReg.m

h = sigmoid(X * theta); % h_theta(X) : m*1
% Cost func
J = (-log(h.')*y - log(ones(1, m) - h.')*(ones(m, 1) - y)) / m ...
+(lambda/(2*m)) * sum(theta(2:end).^2);

% Gradient
grad(1) = (X(:, 1).' * (h - y)) /m;

grad(2:end) = (X(:, 2:end).' * (h - y)) /m ...
+ (lambda/m) * theta(2:end);


课程地址:https://www.coursera.org/course/ml

2013-05-10

Machine Learning 第一波编程作业 - Linear Regression

仅列出核心代码:

1.computeCost

J = sum((X*theta-y).^2)/(2*m);

2.gradientDescent

theta = theta - (1/m)*alpha*(X.'*(X*theta-y));

3.featureNormalize

mu = mean(X);
sigma = std(X);
X_norm = (X - ones(size(X, 1), 1) * mu) ./ (ones(size(X, 1), 1) * sigma);

4.computeCostMulti

J = (X * theta - y).' * (X * theta - y) / (2*m);

5.gradientDescentMulti

theta = theta - (1/m)*alpha*(X.'*(X*theta-y));

6.normalEqn

theta = inv(X.' * X) * X.' * y;

课程地址:https://www.coursera.org/course/ml

2013-05-07

《A Beginner's Guide to Irrational Behavior》课程论文

China is a labor-populous country, known as the "factory of the world". Some enterprises e.g. the Apple Intel etc., all set OEM factories located in China. I live in Chengdu, Sichuan in China. There is a huge factory with 110,000 workers, Foxconn. Two years ago, employee suicided in Foxconn Shenzhen factory frequently. During a short period(four months), twelve workers jumped from the top of building. As in such a tragic way to end their lives, it shocked the society. Soon, the news attracted attention of the media of China and abroad.

What's the reason of Foxconn's tragedy? Many experts (most of them were psychologists) had made a deep analysis. Some said that Foxconn put too much pressure onto its workers and the cost of living in such a big city in China is high. So that made a very obviously contrast between the two incentives. As a result of such effect, the workers' emotion inevitably lead to go extremely. On the other hand, there were some reports to disclose Foxconn industrial park's management, which was very mechanical, totally inhumanness. Among workers, there were also competitive relationships. It is difficult to establish friendship, unable to find a sense of belonging. Therefore, over time, those workers will be more and more unhappy....

In my opinion, one thing is certain: the workers were hard to feel a sense of accomplishment or happiness. Dan Ariely etc. (D Ariely, 2008) and Michael Norton etc. (M Norton, 2012), made a statement of a unanimous conclusion in their papers, which is: "a sense of identity" is important to everyone. This sense of identity comes from both the completion of the work and the affirmation of the results of the work from others. As "IKEA Effect" indicated, a doubly cherish would be put on the fruit of the task which need someone tried hard to achieve. And such endeavor would better be "systematically", for example, a furniture assembled by someone's own power. But if it is over-specialized, such as the division of labor(A Smith, 1776), there wouldn't be the similar effect. Foxconn's employees just like the products of socialization which makes the extreme division of labor. They are like a big car bed's bearing, working repeatedly  for times. They do not know what is the specific role of such assembly work, day after day, year after year. Where is the "meaning"? Whether it is to assemble the the Legos or assemble iPhone, people must be able to genuineness of seeing the fruits of their own labor. And that will take the initiative to stimulate a strong desire to finish their jobs. Otherwise, do not say to love the work, maybe they will feel tired of living for a long term.

Of course, as complicated "toys" as the iPhone, it is impossible to expect one person to assemble it correctly, and also the efficiency will be too low. But we can bring a sense of accomplishment to workers through other ways. For instance, in each specific part of the assembly, set a visualization object identifies which part of the mobile phone the workers' job belong to. Or in every step-assembly, set a graphical phone showing more completely, for every workers, a virtual mobile phone was assembled after several hours. And then, they would touched the goal of completion and feel some kind meaning. The principle of such mechanism is similar with the electric toothbrush's handle with smiley -- although it seems a little bit silly, sometimes it's very effective.

References:

Ariely, D., Kamenica, E. & Prelec, D. (2008). Man’s Search for Meaning: The Case of Legos. Journal of Economic Behavior and Organization, 67, 671-677.

Norton, M. I., Mochon, D., & Ariely, D. The IKEA Effect: When Labor Leads to Love. Harvard Business School Marketing Unit Working Paper, (11-091).

Smith A. The Wealth of Nations (1776)[J]. New York: Modern Library, 1937, 740.



最后得了7.5分。
一个比较长的评语的是:

I commend you on your use of English, which is generally clear in terms of meaning. You describe a problem of worker despair, leading to suicide. In paragraph 2, you refer to "a very obviously contrast between the two incentives." A clear statement of the two incentives and related behavior would be helpful. In addition, your assertion that inhumane treatment and lack of meaning in work were causative factors in the suicides. Your argument would be much stronger if you gave examples to work conditions to support these assertions.

想想我自己给别人打得分也都很高,瞬间淡定了。