Skip to content

Commit

Permalink
mean absolute error regression
Browse files Browse the repository at this point in the history
  • Loading branch information
piiswrong committed Dec 9, 2015
1 parent db530e1 commit f8123cd
Show file tree
Hide file tree
Showing 4 changed files with 18 additions and 1 deletion.
7 changes: 7 additions & 0 deletions src/operator/mshadow_op.h
Original file line number Diff line number Diff line change
Expand Up @@ -239,6 +239,13 @@ struct floor {
}
};

/*! \brief used for generate gradient of MAE loss*/
struct minus_sign {
MSHADOW_XINLINE static real_t Map(real_t a, real_t b) {
return a-b > 0.0f ? 1.0f : -1.0f;
}
};

} // namespace mshadow_op
} // namespace op
} // namespace mxnet
Expand Down
3 changes: 2 additions & 1 deletion src/operator/regression_output-inl.h
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ namespace op {
namespace reg_enum {
enum RegressionOutputOpInputs {kData, kLabel};
enum RegressionOutputOutputs {kOut};
enum RegressionOutputType {kLinear, kLogistic};
enum RegressionOutputType {kLinear, kLogistic, kMAE};
} // reg_enum

struct RegressionOutputParam : public dmlc::Parameter<RegressionOutputParam> {
Expand Down Expand Up @@ -139,6 +139,7 @@ class RegressionOutputProp : public OperatorProperty {
switch (type) {
case reg_enum::kLinear: return "LinearRegressionOutput";
case reg_enum::kLogistic: return "LogisticRegressionOutput";
case reg_enum::kMAE: return "MAERegressionOutput";
default: LOG(FATAL) << "unknown type"; return "";
}
}
Expand Down
7 changes: 7 additions & 0 deletions src/operator/regression_output.cc
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,8 @@ Operator *CreateRegressionOutputOp<cpu>(reg_enum::RegressionOutputType type,
return new RegressionOutputOp<cpu, mshadow::op::identity, mshadow::op::minus>(param);
case reg_enum::kLogistic:
return new RegressionOutputOp<cpu, mshadow_op::sigmoid, mshadow::op::minus>(param);
case reg_enum::kMAE:
return new RegressionOutputOp<cpu, mshadow::op::identity, mshadow_op::minus_sign>();
default:
LOG(FATAL) << "unknown activation type " << type;
}
Expand All @@ -37,6 +39,11 @@ MXNET_REGISTER_OP_PROPERTY(LinearRegressionOutput, RegressionOutputProp<reg_enum
.add_argument("label", "Symbol", "Input label to function.")
.add_arguments(RegressionOutputParam::__FIELDS__());

MXNET_REGISTER_OP_PROPERTY(MAERegressionOutput, RegressionOutputProp<reg_enum::kMAE>)
.describe("Use mean absolute error regression for final output, this is used on final output of a net.")
.add_argument("data", "Symbol", "Input data to function.")
.add_argument("label", "Symbol", "Input label to function.");

MXNET_REGISTER_OP_PROPERTY(LogisticRegressionOutput, RegressionOutputProp<reg_enum::kLogistic>)
.describe("Use Logistic regression for final output, this is used on final output of a net.\n"
"Logistic regression is suitable for binary classification "
Expand Down
2 changes: 2 additions & 0 deletions src/operator/regression_output.cu
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,8 @@ Operator *CreateRegressionOutputOp<gpu>(reg_enum::RegressionOutputType type, Reg
return new RegressionOutputOp<gpu, mshadow::op::identity, mshadow::op::minus>(param);
case reg_enum::kLogistic:
return new RegressionOutputOp<gpu, mshadow_op::sigmoid, mshadow::op::minus>(param);
case reg_enum::kMAE:
return new RegressionOutputOp<gpu, mshadow::op::identity, mshadow_op::minus_sign>();
default:
LOG(FATAL) << "unknown activation type " << type;
}
Expand Down

0 comments on commit f8123cd

Please sign in to comment.