jamie@141: /* jamie@141: * Copyright (C) 2012 Jamie Bullock jamie@140: * jamie@141: * Permission is hereby granted, free of charge, to any person obtaining a copy jamie@141: * of this software and associated documentation files (the "Software"), to jamie@141: * deal in the Software without restriction, including without limitation the jamie@141: * rights to use, copy, modify, merge, publish, distribute, sublicense, and/or jamie@141: * sell copies of the Software, and to permit persons to whom the Software is jamie@141: * furnished to do so, subject to the following conditions: jamie@1: * jamie@141: * The above copyright notice and this permission notice shall be included in jamie@141: * all copies or substantial portions of the Software. jamie@1: * jamie@141: * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR jamie@141: * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, jamie@141: * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE jamie@141: * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER jamie@141: * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING jamie@141: * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS jamie@141: * IN THE SOFTWARE. jamie@1: * jamie@1: */ jamie@1: jamie@1: /* xtract_delta.c: defines functions that extract a feature as a single value from more than one input vector */ jamie@1: jamie@106: #include jamie@259: #include "xtract/libxtract.h" jamie@1: jamie@146: int xtract_flux(const double *data, const int N, const void *argv , double *result) jamie@140: { jamie@1: jamie@117: /* FIX: don't be lazy -- take the lnorm of the difference vector! */ jamie@106: return xtract_lnorm(data, N, argv, result); jamie@105: jamie@106: } jamie@106: jamie@146: int xtract_lnorm(const double *data, const int N, const void *argv , double *result) jamie@140: { jamie@106: jamie@107: int n, jamie@239: type, jamie@239: normalise, jamie@239: k = 0; jamie@106: jamie@146: double order; jamie@106: jamie@146: order = *(double *)argv; jamie@146: type = *((double *)argv+1); jamie@239: normalise = (int)*((double *)argv+2); jamie@106: jamie@146: order = order > 0 ? order : 2.0; jamie@106: jamie@146: *result = 0.0; jamie@239: jamie@140: switch(type) jamie@140: { jamie@106: jamie@140: case XTRACT_POSITIVE_SLOPE: jamie@140: for(n = 0; n < N; n++) jamie@140: { jamie@140: if(data[n] > 0) jamie@239: { jamie@146: *result += pow(data[n], order); jamie@239: ++k; jamie@239: } jamie@140: } jamie@140: break; jamie@140: default: jamie@140: for(n = 0; n < N; n++) jamie@239: { jamie@239: *result += pow(fabs(data[n]), order); jamie@239: ++k; jamie@239: } jamie@140: break; jamie@106: jamie@106: } jamie@106: jamie@146: *result = pow(*result, 1.0 / order); jamie@239: jamie@239: if (k == 0) jamie@239: { jamie@239: return XTRACT_NO_RESULT; jamie@239: } jamie@239: jamie@239: if (normalise == 1) jamie@239: { jamie@239: *result = log(1 + *result); jamie@239: } jamie@106: jamie@106: return XTRACT_SUCCESS; jamie@1: jamie@1: } jamie@1: jamie@146: int xtract_attack_time(const double *data, const int N, const void *argv , double *result) jamie@140: { jamie@1: jamie@56: return XTRACT_FEATURE_NOT_IMPLEMENTED; jamie@1: jamie@1: } jamie@1: jamie@146: int xtract_decay_time(const double *data, const int N, const void *argv, double *result) jamie@140: { jamie@1: jamie@56: return XTRACT_FEATURE_NOT_IMPLEMENTED; jamie@1: jamie@1: } jamie@1: jamie@146: int xtract_difference_vector(const double *data, const int N, const void *argv, double *result) jamie@140: { jamie@1: jamie@146: const double *frame1, jamie@106: *frame2; jamie@106: jamie@106: int n; jamie@106: jamie@106: n = N >> 1; jamie@106: jamie@106: frame1 = data; jamie@106: frame2 = data + n; jamie@106: jamie@106: while(n--) jamie@106: result[n] = frame1[n] - frame2[n]; jamie@106: jamie@106: return XTRACT_SUCCESS; jamie@1: jamie@1: }