LossFunction.h

Go to the documentation of this file.
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   Modifications (w) 2012 Fernando José Iglesias García
00015 */
00016 
00017 #ifndef _LOSSFUNCTION_H__
00018 #define _LOSSFUNCTION_H__
00019 
00020 #include <shogun/base/SGObject.h>
00021 #include <shogun/lib/common.h>
00022 #include <math.h>
00023 
00024 namespace shogun
00025 {
00027     enum ELossType
00028     {
00029         L_HINGELOSS = 0,
00030         L_SMOOTHHINGELOSS = 10,
00031         L_SQUAREDHINGELOSS = 20,
00032         L_SQUAREDLOSS = 30,
00033         L_LOGLOSS = 100,
00034         L_LOGLOSSMARGIN = 110
00035     };
00036 }
00037 
00038 namespace shogun
00039 {
00053 class CLossFunction: public CSGObject
00054 {
00055 public:
00056 
00060     CLossFunction(): CSGObject() {}
00061 
00065     virtual ~CLossFunction() {};
00066 
00075     virtual float64_t loss(float64_t prediction, float64_t label)
00076     {
00077         return loss(prediction * label);
00078     }
00079 
00087     virtual float64_t loss(float64_t z) = 0;
00088 
00097     virtual float64_t first_derivative(float64_t prediction, float64_t label)
00098     {
00099         return loss(prediction * label);
00100     }
00101 
00109     virtual float64_t first_derivative(float64_t z) = 0;
00110 
00119     virtual float64_t second_derivative(float64_t prediction, float64_t label)
00120     {
00121         return loss(prediction * label);
00122     }
00123 
00131     virtual float64_t second_derivative(float64_t z) = 0;
00132 
00143     virtual float64_t get_update(float64_t prediction, float64_t label, float64_t eta_t, float64_t norm) = 0;
00144 
00153     virtual float64_t get_square_grad(float64_t prediction, float64_t label) = 0;
00154 
00162     virtual ELossType get_loss_type()=0;
00163 
00169     virtual const char* get_name() const { return "LossFunction"; }
00170 };
00171 }
00172 #endif // _LOSSFUNCTION_H__
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Defines

SHOGUN Machine Learning Toolbox - Documentation