/usr/include/shogun/structure/Plif.h is in libshogun-dev 3.2.0-7.3build4.
This file is owned by root:root, with mode 0o644.
The actual contents of the file can be viewed below.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 | /*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 3 of the License, or
* (at your option) any later version.
*
* Written (W) 1999-2008 Gunnar Raetsch
* Copyright (C) 1999-2009 Fraunhofer Institute FIRST and Max-Planck-Society
*/
#ifndef __PLIF_H__
#define __PLIF_H__
#include <shogun/lib/common.h>
#include <shogun/lib/SGVector.h>
#include <shogun/mathematics/Math.h>
#include <shogun/structure/PlifBase.h>
namespace shogun
{
/** Ways to transform inputs */
enum ETransformType
{
/// Linear
T_LINEAR,
/// Logarithmic
T_LOG,
/// Logarithmic (log(1+x))
T_LOG_PLUS1,
/// Logarithmic (log(3+x))
T_LOG_PLUS3,
/// Linear (3+x)
T_LINEAR_PLUS3
};
/** @brief class Plif */
class CPlif: public CPlifBase
{
public:
/** constructor
*
* @param len len
*/
CPlif(int32_t len=0);
virtual ~CPlif();
/** init penalty struct cache */
void init_penalty_struct_cache();
/** lookup penalty SVM
*
* @param p_value value
* @param d_values d values
* @return the penalty
*/
float64_t lookup_penalty_svm(
float64_t p_value, float64_t *d_values) const;
/** lookup penalty float64_t
*
* @param p_value value
* @param svm_values SVM values
* @return the penalty
*/
float64_t lookup_penalty(
float64_t p_value, float64_t* svm_values) const;
/** lookup penalty int32_t
*
* @param p_value value
* @param svm_values SVM values
* @return the penalty
*/
float64_t lookup_penalty(int32_t p_value, float64_t* svm_values) const;
/** lookup
*
* @param p_value value
* @return a penalty
*/
inline float64_t lookup(float64_t p_value)
{
ASSERT(use_svm == 0)
return lookup_penalty(p_value, NULL);
}
/** penalty clear derivative */
void penalty_clear_derivative();
/** penalty add derivative SVM
*
* @param p_value value
* @param svm_values SVM values
* @param factor factor weighting the added value
*/
void penalty_add_derivative_svm(
float64_t p_value, float64_t* svm_values, float64_t factor) ;
/** penalty add derivative
*
* @param p_value value
* @param svm_values SVM values
* @param factor factor weighting the added value
*/
void penalty_add_derivative(float64_t p_value, float64_t* svm_values, float64_t factor);
/** get cum derivative
*
* @param p_len len
* @return cum derivative
*/
const float64_t * get_cum_derivative(int32_t & p_len) const
{
p_len = len;
return cum_derivatives.vector;
}
/** set transform type
*
* @param type_str type (string)
* @return if setting was successful
*/
bool set_transform_type(const char *type_str);
/** get transform type
*
* @return type_str type (string)
*/
const char* get_transform_type()
{
if (transform== T_LINEAR)
return "linear";
else if (transform== T_LOG)
return "log";
else if (transform== T_LOG_PLUS1)
return "log(+1)";
else if (transform== T_LOG_PLUS3)
return "log(+3)";
else if (transform== T_LINEAR_PLUS3)
return "(+3)";
else
SG_ERROR("wrong type")
return "";
}
/** set ID
*
* @param p_id the id to set
*/
void set_id(int32_t p_id)
{
id=p_id;
}
/** get ID
*
* @return the ID
*/
int32_t get_id() const
{
return id;
}
/** get maximum ID
*
* @return maximum ID
*/
int32_t get_max_id() const
{
return get_id();
}
/** set use SVM
*
* @param p_use_svm if SVM shall be used
*/
void set_use_svm(int32_t p_use_svm)
{
invalidate_cache();
use_svm=p_use_svm;
}
/** get use SVM
*
* @return if SVM is used
*/
int32_t get_use_svm() const
{
return use_svm;
}
/** check if plif uses SVM values
*
* @return if plif uses SVM values
*/
virtual bool uses_svm_values() const
{
return (get_use_svm()!=0);
}
/** set use cache
*
* @param p_use_cache if cache shall be used
*/
void set_use_cache(int32_t p_use_cache)
{
invalidate_cache();
use_cache=p_use_cache;
}
/** invalidate the cache
*/
void invalidate_cache()
{
SG_FREE(cache);
cache=NULL;
}
/** get use cache
*
* @return if cache is used
*/
int32_t get_use_cache()
{
return use_cache;
}
/** set plif
*
* @param p_len len
* @param p_limits limit
* @param p_penalties penalties
*/
void set_plif(
int32_t p_len, float64_t *p_limits, float64_t* p_penalties)
{
ASSERT(len==p_len)
for (int32_t i=0; i<len; i++)
{
limits[i]=p_limits[i];
penalties[i]=p_penalties[i];
}
invalidate_cache();
penalty_clear_derivative();
}
/** set plif_limits
*
* @param p_limits limit
*/
void set_plif_limits(SGVector<float64_t> p_limits)
{
ASSERT(len==p_limits.vlen)
limits = p_limits;
invalidate_cache();
penalty_clear_derivative();
}
/** set plif penalty
*
* @param p_penalties penalties
*/
void set_plif_penalty(SGVector<float64_t> p_penalties)
{
ASSERT(len==p_penalties.vlen)
penalties = p_penalties;
invalidate_cache();
penalty_clear_derivative();
}
/** set plif length
*
* @param p_len len
*/
void set_plif_length(int32_t p_len)
{
if (len!=p_len)
{
len=p_len;
SG_DEBUG("set_plif len=%i\n", p_len)
limits = SGVector<float64_t>(len);
penalties = SGVector<float64_t>(len);
cum_derivatives = SGVector<float64_t>(len);
}
for (int32_t i=0; i<len; i++)
{
limits[i]=0.0;
penalties[i]=0.0;
cum_derivatives[i]=0.0;
}
invalidate_cache();
penalty_clear_derivative();
}
/** get Plif limits
*
* @return limits
*/
SGVector<float64_t> get_plif_limits()
{
return limits;
}
/** get plif penalty
*
* @return plif penalty
*/
SGVector<float64_t> get_plif_penalties()
{
return penalties;
}
/** set maximum value
*
* @param p_max_value maximum value
*/
inline void set_max_value(float64_t p_max_value)
{
max_value=p_max_value;
invalidate_cache();
}
/** get maximum value
*
* @return maximum value
*/
virtual float64_t get_max_value() const
{
return max_value;
}
/** set minimum value
*
* @param p_min_value minimum value
*/
inline void set_min_value(float64_t p_min_value)
{
min_value=p_min_value;
invalidate_cache();
}
/** get minimum value
*
* @return minimum value
*/
virtual float64_t get_min_value() const
{
return min_value;
}
/** set name
*
* @param p_name name
*/
void set_plif_name(char *p_name);
/** get name
*
* @return name
*/
char* get_plif_name() const;
/** get do calc
*
* @return if calc shall be done
*/
bool get_do_calc();
/** set do calc
*
* @param b if calc shall be done
*/
void set_do_calc(bool b);
/** get SVM_ids and number of SVMs used
*
*/
void get_used_svms(int32_t* num_svms, int32_t* svm_ids);
/** get plif len
*
* @return plif len
*/
inline int32_t get_plif_len()
{
return len;
}
/** print PLIF
*
* lists some properties of the PLIF
*/
virtual void list_plif() const
{
SG_PRINT("CPlif(min_value=%1.2f, max_value=%1.2f, use_svm=%i)\n", min_value, max_value, use_svm)
}
/** delete plif struct
*
* @param PEN array of plifs
* @param P id of plif
*/
static void delete_penalty_struct(CPlif** PEN, int32_t P);
/** @return object name */
virtual const char* get_name() const { return "Plif"; }
protected:
/** len */
int32_t len;
/** limits */
SGVector<float64_t> limits;
/** penalties */
SGVector<float64_t> penalties;
/** cum derivatives */
SGVector<float64_t> cum_derivatives;
/** maximum value */
float64_t max_value;
/** minimum value */
float64_t min_value;
/** cache */
float64_t *cache;
/** transform type */
enum ETransformType transform;
/** id */
int32_t id;
/** name */
char * name;
/** if SVM shall be used */
int32_t use_svm;
/** if cache shall be used */
bool use_cache;
/** do calc
* if this is true: lookup_penalty behaves normal
* else: lookup_penalty returns the p_value untransformed*/
bool do_calc;
};
}
#endif
|