00001 /* 00002 Copyright (c) 2009 Yahoo! Inc. All rights reserved. The copyrights 00003 embodied in the content of this file are licensed under the BSD 00004 (revised) open source license. 00005 00006 Copyright (c) 2011 Berlin Institute of Technology and Max-Planck-Society. 00007 00008 This program is free software; you can redistribute it and/or modify 00009 it under the terms of the GNU General Public License as published by 00010 the Free Software Foundation; either version 3 of the License, or 00011 (at your option) any later version. 00012 00013 Modifications (w) 2011 Shashwat Lal Das 00014 */ 00015 00016 #include <shogun/loss/HingeLoss.h> 00017 00018 using namespace shogun; 00019 00020 float64_t CHingeLoss::loss(float64_t prediction, float64_t label) 00021 { 00022 float64_t e = 1 - label * prediction; 00023 00024 return (e > 0) ? e : 0; 00025 } 00026 00027 float64_t CHingeLoss::first_derivative(float64_t prediction, float64_t label) 00028 { 00029 return (label * prediction >= label * label) ? 0 : -label; 00030 } 00031 00032 float64_t CHingeLoss::second_derivative(float64_t prediction, float64_t label) 00033 { 00034 return 0.; 00035 } 00036 00037 float64_t CHingeLoss::get_update(float64_t prediction, float64_t label, float64_t eta_t, float64_t norm) 00038 { 00039 if (label * prediction >= label * label) 00040 return 0; 00041 float64_t err = (label*label - label*prediction)/(label * label); 00042 float64_t normal = eta_t; 00043 return label * (normal < err ? normal : err)/norm; 00044 } 00045 00046 float64_t CHingeLoss::get_square_grad(float64_t prediction, float64_t label) 00047 { 00048 return first_derivative(prediction, label); 00049 }