annotate src/delta.c @ 285:89fe52066db1 tip master

MSCV missing ssize_t fix
author Jamie Bullock <jamie@jamiebullock.com>
date Tue, 16 Jul 2019 18:29:20 +0100
parents d383a8c66b5d
children
rev   line source
jamie@141 1 /*
jamie@141 2 * Copyright (C) 2012 Jamie Bullock
jamie@140 3 *
jamie@141 4 * Permission is hereby granted, free of charge, to any person obtaining a copy
jamie@141 5 * of this software and associated documentation files (the "Software"), to
jamie@141 6 * deal in the Software without restriction, including without limitation the
jamie@141 7 * rights to use, copy, modify, merge, publish, distribute, sublicense, and/or
jamie@141 8 * sell copies of the Software, and to permit persons to whom the Software is
jamie@141 9 * furnished to do so, subject to the following conditions:
jamie@1 10 *
jamie@141 11 * The above copyright notice and this permission notice shall be included in
jamie@141 12 * all copies or substantial portions of the Software.
jamie@1 13 *
jamie@141 14 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
jamie@141 15 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
jamie@141 16 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
jamie@141 17 * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
jamie@141 18 * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
jamie@141 19 * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS
jamie@141 20 * IN THE SOFTWARE.
jamie@1 21 *
jamie@1 22 */
jamie@1 23
jamie@1 24 /* xtract_delta.c: defines functions that extract a feature as a single value from more than one input vector */
jamie@1 25
jamie@106 26 #include <math.h>
jamie@259 27 #include "xtract/libxtract.h"
jamie@1 28
jamie@146 29 int xtract_flux(const double *data, const int N, const void *argv , double *result)
jamie@140 30 {
jamie@1 31
jamie@117 32 /* FIX: don't be lazy -- take the lnorm of the difference vector! */
jamie@106 33 return xtract_lnorm(data, N, argv, result);
jamie@105 34
jamie@106 35 }
jamie@106 36
jamie@146 37 int xtract_lnorm(const double *data, const int N, const void *argv , double *result)
jamie@140 38 {
jamie@106 39
jamie@107 40 int n,
jamie@239 41 type,
jamie@239 42 normalise,
jamie@239 43 k = 0;
jamie@106 44
jamie@146 45 double order;
jamie@106 46
jamie@146 47 order = *(double *)argv;
jamie@146 48 type = *((double *)argv+1);
jamie@239 49 normalise = (int)*((double *)argv+2);
jamie@106 50
jamie@146 51 order = order > 0 ? order : 2.0;
jamie@106 52
jamie@146 53 *result = 0.0;
jamie@239 54
jamie@140 55 switch(type)
jamie@140 56 {
jamie@106 57
jamie@140 58 case XTRACT_POSITIVE_SLOPE:
jamie@140 59 for(n = 0; n < N; n++)
jamie@140 60 {
jamie@140 61 if(data[n] > 0)
jamie@239 62 {
jamie@146 63 *result += pow(data[n], order);
jamie@239 64 ++k;
jamie@239 65 }
jamie@140 66 }
jamie@140 67 break;
jamie@140 68 default:
jamie@140 69 for(n = 0; n < N; n++)
jamie@239 70 {
jamie@239 71 *result += pow(fabs(data[n]), order);
jamie@239 72 ++k;
jamie@239 73 }
jamie@140 74 break;
jamie@106 75
jamie@106 76 }
jamie@106 77
jamie@146 78 *result = pow(*result, 1.0 / order);
jamie@239 79
jamie@239 80 if (k == 0)
jamie@239 81 {
jamie@239 82 return XTRACT_NO_RESULT;
jamie@239 83 }
jamie@239 84
jamie@239 85 if (normalise == 1)
jamie@239 86 {
jamie@239 87 *result = log(1 + *result);
jamie@239 88 }
jamie@106 89
jamie@106 90 return XTRACT_SUCCESS;
jamie@1 91
jamie@1 92 }
jamie@1 93
jamie@146 94 int xtract_attack_time(const double *data, const int N, const void *argv , double *result)
jamie@140 95 {
jamie@1 96
jamie@56 97 return XTRACT_FEATURE_NOT_IMPLEMENTED;
jamie@1 98
jamie@1 99 }
jamie@1 100
jamie@146 101 int xtract_decay_time(const double *data, const int N, const void *argv, double *result)
jamie@140 102 {
jamie@1 103
jamie@56 104 return XTRACT_FEATURE_NOT_IMPLEMENTED;
jamie@1 105
jamie@1 106 }
jamie@1 107
jamie@146 108 int xtract_difference_vector(const double *data, const int N, const void *argv, double *result)
jamie@140 109 {
jamie@1 110
jamie@146 111 const double *frame1,
jamie@106 112 *frame2;
jamie@106 113
jamie@106 114 int n;
jamie@106 115
jamie@106 116 n = N >> 1;
jamie@106 117
jamie@106 118 frame1 = data;
jamie@106 119 frame2 = data + n;
jamie@106 120
jamie@106 121 while(n--)
jamie@106 122 result[n] = frame1[n] - frame2[n];
jamie@106 123
jamie@106 124 return XTRACT_SUCCESS;
jamie@1 125
jamie@1 126 }