// spei() // Calculates the Standardized Precipitation-Evapotransporation Index // from a series of climatic balance (precipitation minus etp). The // SPEI is the standardized value of the climatic balance (P-ETP), // computed following a Log Logistic probability distribution. void spei(float dataSeries[], int n, int seasons, float speiSeries[]) { int i, j, k, nSeason; float seasonSeries[NUMDATOSMAX], beta[3], logLogisticParams[NUMSEASONSMAX][3]; // Loop through all seasons defined by seasons for (j=1; j<=seasons; j++) { // Extract and sort the seasonal series k = 0; for (i=j-1; i<n; i+=seasons) { seasonSeries[k] = dataSeries[i]; k++; } nSeason = k; upward(seasonSeries, nSeason); // Compute probability weighted moments //pwm(seasonSeries, nSeason, beta, -0.35, 0, 0); pwm(seasonSeries, nSeason, beta, 0, 0, 0); // Fit a Log Logistic probability function logLogisticFit(beta, logLogisticParams[j]); //printf("\nSeason %u", jndice); //printf("\nLogLogistic beta param.: %.4f", logLogisticParams[jndice][0]); //printf("\nLogLogistic alpha param.: %.4f", logLogisticParams[jndice][1]); //printf("\nLogLogistic gamma param.: %.4f\n", logLogisticParams[jndice][2]); // Calculate the standardized values for (i=j-1; i<n; i+=seasons) { speiSeries[i] = logLogisticCDF(dataSeries[i], logLogisticParams[j]); speiSeries[i] = -standardGaussianInvCDF(speiSeries[i]); } } }
void upward(int cur){ int parent = PARENT(cur); if (cur && arr[parent] > arr[cur]){ swap(parent, cur); upward(parent); } }
void add_value(heap_t *h, float v) { assert(h->curr_max < HEAP_SIZE); h->head[h->curr_max++] = v; upward(h); }
void push(long long weight){ arr[size++] = weight; upward(size-1); }
void eliminate(ContainerSets& C, SubsumptionsTags::hyperedges_may_not_be_sorted_by_size) const { typedef typename ContainerSets::iterator iterator; const iterator& end(C.end()); upward(C, C.begin(), end); upward(C, boost::make_reverse_iterator(end), boost::make_reverse_iterator(C.begin())); }
void eliminate(ContainerSets& C, SubsumptionsTags::hyperedges_sorted_by_size) const { upward(C, C.begin(), C.end()); }
void upward(ContainerSets& C, Iterator begin, const Iterator end) const { upward(C, begin, end, size_tag()); }