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 * Written (W) 2012 Fernando José Iglesias García 00009 * Copyright (c) 2011 Berlin Institute of Technology and Max-Planck-Society. 00010 */ 00011 00012 #include <shogun/loss/LogLossMargin.h> 00013 00014 using namespace shogun; 00015 00016 float64_t CLogLossMargin::loss(float64_t z) 00017 { 00018 if (z >= 1) 00019 return log(1+exp(1-z)); 00020 00021 return 1-z + log(1+exp(z-1)); 00022 } 00023 00024 float64_t CLogLossMargin::first_derivative(float64_t z) 00025 { 00026 if (z < 1) 00027 return -1 / (exp(z-1) + 1); 00028 00029 float64_t ez = exp(1-z); 00030 return -ez / (ez + 1); 00031 } 00032 00033 float64_t CLogLossMargin::second_derivative(float64_t z) 00034 { 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 }