Computes polynomial coefficients for the given data.

@param length Number of elements in data with relevant data.
@param data Set of observation data.
@return true if successful or false if it fails.
320812
public boolean process( int offset , int length , double ...data ) {
		if( data.length < 3 )
			throw new IllegalArgumentException("At least three points");

		A.reshape(data.length,3);
		y.reshape(data.length,1);

		int indexDst = 0;
		int indexSrc = offset;
		for( int i = 0; i < length; i++ ) {
			double d = data[indexSrc++];

			A.data[indexDst++] = i*i;
			A.data[indexDst++] = i;
			A.data[indexDst++] = 1;

			y.data[i] = d;
		}

		if( !solver.setA(A) )
			return false;

		solver.solve(y,x);

		return true;
	}
514033
private int calculateFrequency(long seasonLength) {
        long startTime = timestamps[0];
        //Prevents frequency from being 0
        if (timestamps[1] - timestamps[0] > seasonLength) {
            throw new RuntimeException("Provided length of season is too small. No data points exist " +
                    "within the first season of the metric.");
        }

        int numDatapointsInSeason = 0;
        for (long timestamp : timestamps) {
            if ((timestamp - startTime) < seasonLength) {
                numDatapointsInSeason++;
            } else {
                break;
            }
        }

        return numDatapointsInSeason;
    }
1109299
public static int count(final Object array) {

    if (isArray(array)) {
      return Array.getLength(array);
    } else if (array != null) {
      throw new IllegalArgumentException("Given data is not an array.");
    } else {
      return 0;
    }
  }
596957
public static double of(double... data) {
    double sum = 0.;
    for(double v : data) {
      sum += v;
    }
    return sum / data.length;
  }
386077
private static double shapiroWilkW(double[] x) {
        Arrays.sort(x);
        
        int n = x.length;
        if(n<3) {
            throw new IllegalArgumentException("The provided collection must have more than 2 elements.");
        }
        if (n > 5000) {
            throw new IllegalArgumentException("The provided collection must have less or equal to 5000 elements.");
        }
        
        int nn2 = n/2;
        double[] a = new double[nn2+1]; /* 1-based */

        /*    
            ALGORITHM AS R94 APPL. STATIST. (1995) vol.44, no.4, 547-551.
            Calculates the Shapiro-Wilk W test and its significance level
        */
        double small = 1e-19;

        /* polynomial coefficients */
        double g[] = { -2.273, 0.459 };
        double c1[] = { 0.0, 0.221157, -0.147981, -2.07119, 4.434685, -2.706056 };
        double c2[] = { 0.0, 0.042981, -0.293762, -1.752461, 5.682633, -3.582633 };
        double c3[] = { 0.544, -0.39978, 0.025054, -6.714e-4 };
        double c4[] = { 1.3822, -0.77857, 0.062767, -0.0020322 };
        double c5[] = { -1.5861, -0.31082, -0.083751, 0.0038915 };
        double c6[] = { -0.4803, -0.082676, 0.0030302 };

        /* Local variables */
        int i, j, i1;

        double ssassx, summ2, ssumm2, gamma, range;
        double a1, a2, an, m, s, sa, xi, sx, xx, y, w1;
        double fac, asa, an25, ssa, sax, rsn, ssx, xsx;

        double pw;
        an = (double)n;

        if (n == 3) {
            a[1] = 0.70710678;/* = sqrt(1/2) */
        }
        else {
            an25 = an + 0.25;
            summ2 = 0.0;
            for (i = 1; i <= nn2; i++) {
                a[i] = ContinuousDistributions.normalQuantile((i - 0.375) / an25, 0, 1); // p(X <= x), 
                summ2 += a[i] * a[i];
            }
            summ2 *= 2.0;
            ssumm2 = Math.sqrt(summ2);
            rsn = 1.0 / Math.sqrt(an);
            a1 = poly(c1, 6, rsn) - a[1] / ssumm2;

            /* Normalize a[] */
            if (n > 5) {
                i1 = 3;
                a2 = -a[2] / ssumm2 + poly(c2, 6, rsn);
                fac = Math.sqrt((summ2 - 2.0 * (a[1] * a[1]) - 2.0 * (a[2] * a[2])) / (1.0 - 2.0 * (a1 * a1) - 2.0 * (a2 * a2)));
                a[2] = a2;
            } 
            else {
                i1 = 2;
                fac = Math.sqrt((summ2 - 2.0 * (a[1] * a[1])) / ( 1.0  - 2.0 * (a1 * a1)));
            }
            a[1] = a1;
            for (i = i1; i <= nn2; i++) {
                a[i] /= - fac;
            }
        }

        /* Check for zero range */

        range = x[n-1] - x[0];
        if (range < small) {
            throw new IllegalArgumentException("The range is too small.");
        }


        /* Check for correct sort order on range - scaled X */

        xx = x[0] / range;
        sx = xx;
        sa = -a[1];
        for (i = 1, j = n - 1; i < n; j--) {
            xi = x[i] / range;
            if (xx - xi > small) {
                throw new IllegalArgumentException("The xx - xi is too big.");
            }
            sx += xi;
            i++;
            if (i != j) {
                sa += sign(i - j) * a[Math.min(i, j)];
            }
            xx = xi;
        }


        /* Calculate W statistic as squared correlation
        between data and coefficients */

        sa /= n;
        sx /= n;
        ssa = ssx = sax = 0.;
        for (i = 0, j = n - 1; i < n; i++, j--) {
            if (i != j) {
                asa = sign(i - j) * a[1 + Math.min(i, j)] - sa;
            }
            else {
                asa = -sa;
            }
            xsx = x[i] / range - sx;
            ssa += asa * asa;
            ssx += xsx * xsx;
            sax += asa * xsx;
        }

        /* W1 equals (1-W) calculated to avoid excessive rounding error
        for W very near 1 (a potential problem in very large samples) */

        ssassx = Math.sqrt(ssa * ssx);
        w1 = (ssassx - sax) * (ssassx + sax) / (ssa * ssx);
        double w = 1.0 - w1;

        /* Calculate significance level for W */

        if (n == 3) {/* exact P value : */
            double pi6 = 6.0/Math.PI; /* 1.90985931710274 = 6/pi */ 
            double stqr = Math.PI/3.0; /* 1.04719755119660 = asin(sqrt(3/4)) */
            pw = pi6 * (Math.asin(Math.sqrt(w)) - stqr);
            if (pw < 0.) {
                pw = 0;
            }
            //return w;
            return pw;
        }
        y = Math.log(w1);
        xx = Math.log(an);
        if (n <= 11) {
            gamma = poly(g, 2, an);
            if (y >= gamma) {
                pw = 1e-99; /* an "obvious" value, was 'small' which was 1e-19f */
                //return w;
                return pw;
            }
            y = -Math.log(gamma - y);
            m = poly(c3, 4, an);
            s = Math.exp(poly(c4, 4, an));
        } 
        else { /* n >= 12 */
            m = poly(c5, 4, xx);
            s = Math.exp(poly(c6, 3, xx));
        }

        // Oops, we don't have pnorm
        // pw = pnorm(y, m, s, 0/* upper tail */, 0);
        pw=ContinuousDistributions.gaussCdf((y-m)/s);

        //return w;
        return pw;
    }
161325
public boolean read(DataInputStream daIn, boolean bFixedLength) // Fixed length = false
    {
        try   {
            float fData = daIn.readFloat();
            Float flData = null;
            if (!Float.isNaN(fData))
                flData = new Float(fData);
            int errorCode = this.setData(flData, DBConstants.DONT_DISPLAY, DBConstants.READ_MOVE);
            return (errorCode == DBConstants.NORMAL_RETURN);    // Success
        } catch (IOException ex)    {
            ex.printStackTrace();
            return false;
        }
    }
981637
def length(cls, dataset):
        
        if not dataset.data:
            return 0
        length = 0
        ds = cls._inner_dataset_template(dataset)
        for d in dataset.data:
            ds.data = d
            length += ds.interface.length(ds)
        return length+len(dataset.data)-1
200404
private static double[] calcLinReg(double[] xData, double[] yData) {
        double sumX = 0;
        double sumY = 0;
        double prod = 0;
        int nstat = xData.length;
        double[] regCoef = new double[3]; //(intercept, gradient, r2)

        double meanYValue = mean(yData);
        double meanXValue = mean(xData);

        //calculating regression coefficients
        for (int i = 0; i < nstat; i++) {
            sumX += (xData[i] - meanXValue) * (xData[i] - meanXValue);
            sumY += (yData[i] - meanYValue) * (yData[i] - meanYValue);
            prod += (xData[i] - meanXValue) * (yData[i] - meanYValue);
        }
        if (sumX > 0 && sumY > 0) {
            regCoef[1] = prod / sumX;  //gradient
            regCoef[0] = meanYValue - regCoef[1] * meanXValue; //intercept
            regCoef[2] = Math.pow((prod / Math.sqrt(sumX * sumY)), 2); //r2
        }
        return regCoef;
    }
1144758
public int writeSampleData(final byte [] newSampleData, final int offset, int length)
	{
		synchronized(lock)
		{
			System.arraycopy(newSampleData, offset, resultSampleBuffer, 0, length);
			int anzSamples = writeIntoFloatArrayBuffer(length);
			if (dspEnabled)
			{
				// call the callbacks for digital signal processing
				// ...
				anzSamples = callEffects(sampleBuffer, currentWritePosition, anzSamples);
				// and recalc from the float array...
				length = readFromFloatArrayBuffer(anzSamples);
			}
			currentWritePosition = (currentWritePosition + anzSamples) % sampleBufferSize;
			return length;
		}
	}
1306615
@Override
    public double d(double[] x, double[] y) {
        if (x.length != y.length)
            throw new IllegalArgumentException(String.format("Arrays have different length: x[%d], y[%d]", x.length, y.length));

        return 1 - Math.cor(x, y);
    }
1102479
function (data, length) {
        !_.isArray(data) && (data = [{}]);
        ((length < 1) || !_.isFinite(length)) && (length = data.length);

        // if the iteration count is greater than the length of data, we repeat the last item in data. here, we are
        // using a for-loop so that we do not have excessive spatial complexity
        if (length > data.length) {
            for (var i = data.length, filler = data[i - 1]; i < length; i++) {
                data[i] = filler;
            }
        }

        // just to be sure that there are no extra items in array, we match the lengths and return the data
        data.length = length;

        return data;
    }
482455
public static void calculate(LPC lpc, long[] R) {
    int coeffCount = lpc.order;

    //calculate first iteration directly
    double[] A = lpc.rawCoefficients;
    for(int i = 0; i < coeffCount+1; i++) A[i] = 0.0;
    A[0] = 1;
    double E = R[0];

    //calculate remaining iterations

    if(R[0] == 0) {
      for(int i = 0; i < coeffCount+1; i++)
        A[i] = 0.0;
    }
    else {
      double[] ATemp = lpc.tempCoefficients;
      for(int i = 0; i < coeffCount+1; i++) ATemp[i] = 0.0;

      for(int k = 0; k < coeffCount; k++) {
        double lambda = 0.0;
        double temp = 0;
        for(int j = 0; j <= k; j++) {
          temp += A[j]*R[k+1-j];
        }
        lambda = -temp/E;

        for(int i = 0; i <= k+1; i++) {
          ATemp[i] = A[i]+lambda*A[k+1-i];
        }
        System.arraycopy(ATemp, 0, A, 0, coeffCount+1);
        E = (1-lambda*lambda)*E;
      }
    }
    lpc.rawError = E;
  }
788483
def _process_counter_example(self, mma, w_string):
        "
        diff = len(w_string)
        same = 0
        membership_answer = self._membership_query(w_string)
        while True:
            i = (same + diff) / 2
            access_string = self._run_in_hypothesis(mma, w_string, i)
            if membership_answer != self._membership_query(access_string + w_string[i:]):
                diff = i
            else:
                same = i
            if diff - same == 1:
                break
        exp = w_string[diff:]
        self.observation_table.em_vector.append(exp)
        for row in self.observation_table.sm_vector + self.observation_table.smi_vector:
            self._fill_table_entry(row, exp)
        return 0
938736
protected final void slicingBy4 (final int[] data) {

        final int n = data.length;
        for (int i = 0; i < n; i++) {
            slicingBy4(data[i]);
        }

        crc ^= INT_FLAG_MASK_LONG;
    }
368053
public boolean read(DataInputStream daIn, boolean bFixedLength) // Fixed length = false
    {
        try   {
            long lData = daIn.readLong();
            java.util.Date daData = null;
            if (lData != Long.MIN_VALUE + 1)
                daData = new java.util.Date(lData);
            int errorCode = this.setData(daData, DBConstants.DONT_DISPLAY, DBConstants.READ_MOVE);
            return (errorCode == DBConstants.NORMAL_RETURN);    // Success
        } catch (IOException ex)    {
            ex.printStackTrace();
            return false;
        }
    }
611010
public synchronized int read(int plane, byte data[], int offset, int length) throws IOException {
		if (offset < 0 || length < 0 || length > data.length - offset)
			throw new IndexOutOfBoundsException();

		if (bytesToRead[plane] == 0)
			return 0;

		if (bytesToRead[plane] < length)
			length = bytesToRead[plane];

		buffer[plane].position(readPointer[plane]);
		int partLength = buffer[plane].capacity() - readPointer[plane];

		if (partLength > length) {
			buffer[plane].get(data, offset, length);
			readPointer[plane] += length;
		}
		else {
			buffer[plane].get(data, offset, partLength);
			buffer[plane].position(0);
			buffer[plane].get(data, partLength, length - partLength);
			readPointer[plane] = length - partLength;
		}

		bytesToRead[plane] -= length;
		bytesToWrite[plane] += length;

		return length;
	}
811541
def evaluate_polynomial(coefficients, value)
            result = 0
            coefficients.reverse_each do |coefficient|
                result = result*value + coefficient
                result = result % @prime
            end

            return result
        end