00001 /* 00002 * This program is free software; you can redistribute it and/or modify 00003 * it under the terms of the GNU General Public License as published by 00004 * the Free Software Foundation; either version 3 of the License, or 00005 * (at your option) any later version. 00006 * 00007 * Written (W) 2011 Shashwat Lal Das 00008 * Copyright (c) 2011 Berlin Institute of Technology and Max-Planck-Society. 00009 */ 00010 00011 #include <shogun/loss/LogLossMargin.h> 00012 00013 using namespace shogun; 00014 00015 float64_t CLogLossMargin::loss(float64_t prediction, float64_t label) 00016 { 00017 float64_t z = prediction * label; 00018 if (z >= 1) 00019 return log(1+exp(1-z)); 00020 return 1-z + log(1+exp(z-1)); 00021 } 00022 00023 float64_t CLogLossMargin::first_derivative(float64_t prediction, float64_t label) 00024 { 00025 float64_t z = prediction * label; 00026 if (z < 1) 00027 return -1 / (exp(z-1) + 1); 00028 float64_t ez = exp(1-z); 00029 return -ez / (ez + 1); 00030 } 00031 00032 float64_t CLogLossMargin::second_derivative(float64_t prediction, float64_t label) 00033 { 00034 float64_t z = prediction * label; 00035 float64_t ez = exp(z-1); 00036 00037 return ez / (ez + 1)*(ez + 1); 00038 } 00039 00040 float64_t CLogLossMargin::get_update(float64_t prediction, float64_t label, float64_t eta_t, float64_t norm) 00041 { 00042 SG_NOTIMPLEMENTED; 00043 return -1; 00044 } 00045 00046 float64_t CLogLossMargin::get_square_grad(float64_t prediction, float64_t label) 00047 { 00048 SG_NOTIMPLEMENTED; 00049 return -1; 00050 }