Examples of CubicSpline


Examples of flanagan.interpolation.CubicSpline

                double[] dataX = new double[this.numberOfDataPoints];
                for(int i=0; i<this.numberOfDataPoints; i++)dataX[i]=i;
                double incrI = ((double)(this.numberOfDataPoints-1))/(nInterp-1);

                interpData = new double[nInterp];
                CubicSpline cs = new CubicSpline(dataX, this.sortedData);
                double interp = 0.0;
                for(int i=0; i<nInterp-1; i++){
                    interpData[i]=cs.interpolate(interp);
                    interp += incrI;

                }
                interpData[nInterp-1] = (double)(this.numberOfDataPoints-1);
            }

            // Bin the data
            int nBins = 100;
            double[] binnedData = new double[nBins];
            double[] bins = new double[nBins];
            double binWidth = this.range/nBins;
            double binLower = this.minimum;
            double binUpper = binLower + binWidth;
            int counter = 0;
            for(int i=0; i<nBins; i++){
                bins[i] = (binUpper + binLower)/2.0;
                binnedData[i] = 0.0;
                boolean test = true;
                if(counter>=nInterp)test = false;
                while(test){
                    if(interpData[counter]<binUpper){
                        binnedData[i] += 1.0;
                    }
                    else{
                        test = false;
                    }
                    counter++;
                    if(counter>=nInterp)test = false;
                }
                binLower = binUpper;
                binUpper = binLower + binWidth;
            }
            if(counter<nInterp)binnedData[nBins-1] += (double)(nInterp-counter);

            // Identify peak
            ArrayMaths am = new ArrayMaths(binnedData);
            double maxI = am.maximum();
            int maxIindex = am.maximumIndex();
            this.peakPoint = bins[maxIindex];
            double halfHeight = maxI/2.0;
            double widthLower = 0.0;
            boolean lowerCheck = false;
            double widthUpper = 0.0;
            boolean upperCheck = false;

            // lower limit
            if(binnedData[0]==halfHeight){
                widthLower = bins[0];
                lowerCheck = true;
            }
            else{
                if(binnedData[0]<halfHeight){
                    if(maxIindex>=2){
                        double[] interpLy = new double[maxIindex+1];
                        double[] interpLx = new double[maxIindex+1];
                        for(int i=0; i<=maxIindex; i++){
                            interpLy[i] = binnedData[i];
                            interpLx[i] = bins[i];
                        }
                        CubicSpline csl = new CubicSpline(interpLx, interpLy);
                        double[] tempx = new double[100];
                        double[] tempy = new double[100];
                        double incr = (interpLx[maxIindex]-interpLx[0])/99;
                        double intr = interpLx[0];
                        for(int i=0; i<99; i++){
                            tempx[i] = intr;
                            tempy[i] = csl.interpolate(intr);
                            intr += incr;
                        }
                        tempy[99] = interpLy[maxIindex];
                        tempx[99] = interpLx[maxIindex];
                        boolean testt = true;
                        int ii = 0;
                        while(testt){
                            if(halfHeight<=tempy[ii]){
                                if(ii==0){
                                    widthLower = tempx[0];
                                    testt = false;
                                    lowerCheck = true;
                                }else{
                                    if(ii==99){
                                        widthLower = tempx[99];
                                        testt = false;
                                        lowerCheck = true;
                                    }
                                    else{
                                        widthLower = (tempx[ii] + tempx[ii-1])/2.0;
                                        testt = false;
                                        lowerCheck = true;
                                    }
                                }
                            }
                            ii++;
                            if(ii>=100)testt = false;
                        }
                    }
                    else{
                        if(maxIindex==2){
                            if(binnedData[1]>=halfHeight){
                                widthLower = bins[0] + (bins[1] - bins[0])*(halfHeight - binnedData[0])/(binnedData[1] - binnedData[0]);
                                lowerCheck = true;
                            }
                            else{
                                widthLower = bins[1] + (bins[2] - bins[1])*(halfHeight - binnedData[1])/(binnedData[2] - binnedData[1]);
                                lowerCheck = true;
                            }
                        }
                        else{
                            widthLower = bins[0] + (bins[1] - bins[0])*(halfHeight - binnedData[0])/(binnedData[1] - binnedData[0]);
                            lowerCheck = true;
                         }
                    }
                }
                else{
                    if(maxIindex>2){
                        if((binnedData[maxIindex]-binnedData[0])>halfHeight*0.5){
                            widthLower = bins[0] + (bins[1] - bins[0])*(halfHeight - binnedData[0])/(binnedData[1] - binnedData[0]);
                            lowerCheck = true;
                        }
                    }
                }
            }

            // upper limit
            int nTop = nBins - 1;
            int nDif = nBins - maxIindex;
            if(binnedData[nTop]==halfHeight){
                widthUpper = bins[nTop];
                upperCheck = true;
            }
            else{
                if(binnedData[nTop]<halfHeight){
                    if(nDif>=3){
                        double[] interpLy = new double[nDif];
                        double[] interpLx = new double[nDif];
                        int ii = 0;
                        for(int i=maxIindex; i<nBins; i++){
                            interpLy[ii] = binnedData[i];
                            interpLx[ii] = bins[i];
                            ii++;
                        }
                        CubicSpline csl = new CubicSpline(interpLx, interpLy);
                        double[] tempx = new double[100];
                        double[] tempy = new double[100];
                        double incr = (interpLx[nDif-1]-interpLx[0])/99;
                        double intr = interpLx[0];
                        for(int i=0; i<99; i++){
                            tempx[i] = intr;
                            tempy[i] = csl.interpolate(intr);
                            intr += incr;
                        }
                        tempy[99] = interpLy[nDif-1];
                        tempx[99] = interpLx[nDif-1];
                        boolean testt = true;
View Full Code Here

Examples of flanagan.interpolation.CubicSpline

                nxpoints=this.nPoints[i];
                double xcs[]= new double[nxpoints];
                double ycs[]= new double[nxpoints];

                  if(lineOpt[i]==1 || lineOpt[i]==2){
                    CubicSpline cs = new CubicSpline(this.nPoints[i]);
                    for(int ii=0; ii<nxpoints; ii++){
                          xcs[ii]=this.data[kk][ii];
                    }
                    csstep=(xcs[nxpoints-1]-xcs[0])/(niPoints-1);
                    ics[0]=xcs[0];
                    for(int ii=1; ii<niPoints; ii++){
                          ics[ii]=ics[ii-1]+csstep;
                    }
                    ics[niPoints-1] = xcs[nxpoints-1];
                     for(int ii=0; ii<nxpoints; ii++){
                          ycs[ii]=this.data[kk+1][ii];
                    }

                    cs.resetData(xcs, ycs);
                    cs.calcDeriv();
                    xoldpoint=xBot+(int)(((xcs[0]-xLow)/xdenom)*xLen);
                    yoldpoint=yBot-(int)(((ycs[0]-yLow)/ydenom)*yLen);
                    for(int ii=1; ii<niPoints; ii++){
                           xnewpoint=xBot+(int)(((ics[ii]-xLow)/xdenom)*xLen);
                          ynewpoint=yBot-(int)(((cs.interpolate(ics[ii])-yLow)/ydenom)*yLen);
                          btest2=printCheck(trimOpt[i], xoldpoint, xnewpoint, yoldpoint, ynewpoint);
                          if(btest2){
                              if(this.lineOpt[i]==2){
                                    dsum++;
                                    if(dsum>dashLength[i]){
                                        dsum=0;
                                        if(dcheck){
                                              dcheck=false;
                                        }
                                else{
                                              dcheck=true;
                                        }
                                    }
                              }
                              if(dcheck)g.drawLine(xoldpoint,yoldpoint,xnewpoint,ynewpoint);
                          }
                          xoldpoint=xnewpoint;
                          yoldpoint=ynewpoint;
                    }
                }

                if(lineOpt[i]==-1 || lineOpt[i]==-2){
                    CubicSpline cs = new CubicSpline(this.nPoints[i]);
                    for(int ii=0; ii<nxpoints; ii++){
                          xcs[ii]=this.data[kk][ii];
                    }
                    for(int ii=0; ii<nxpoints; ii++){
                          ycs[ii]=this.data[kk+1][ii];
                    }
                    csstep=(ycs[nxpoints-1]-ycs[0])/(niPoints-1);
                    ics[0]=ycs[0];
                    for(int ii=1; ii<niPoints; ii++){
                          ics[ii]=ics[ii-1]+csstep;
                    }
                    ics[niPoints-1] = ycs[nxpoints-1];

                    cs.resetData(ycs, xcs);
                    cs.calcDeriv();
                    xoldpoint=xBot+(int)(((xcs[0]-xLow)/xdenom)*xLen);
                    yoldpoint=yBot-(int)(((ycs[0]-yLow)/ydenom)*yLen);
                    for(int ii=1; ii<niPoints; ii++){
                          ynewpoint=yBot+(int)(((ics[ii]-yLow)/ydenom)*yLen);
                          xnewpoint=xBot-(int)(((cs.interpolate(ics[ii])-xLow)/xdenom)*xLen);
                          btest2=printCheck(trimOpt[i], xoldpoint, xnewpoint, yoldpoint, ynewpoint);
                          if(btest2){
                              if(this.lineOpt[i]==2){
                                    dsum++;
                                    if(dsum>dashLength[i]){
View Full Code Here

Examples of flanagan.interpolation.CubicSpline

        if(this.nAnalyteConcns<3)throw new IllegalArgumentException("Method cubicSpline requres at least 3 data points; only " + this.nAnalyteConcns + " were supplied");
        this.methodUsed = 0;
        this.sampleErrorFlag = false;
        this.titleOne = "Cubic spline ";
        if(!this.setDataOneDone)this.setDataOne();
        this.cs = new CubicSpline(this.analyteConcns, this.responses);
        for(int i=0; i<this.nInterp; i++)this.calculatedResponses[i] = cs.interpolate(interpolationConcns[i]);
        if(!this.supressPlot)this.plott();
        this.curveCheck(this.methodIndices[this.methodUsed]);
    }
View Full Code Here

Examples of flanagan.interpolation.CubicSpline

            if(this.nAnalyteConcns>=120){
                this.anscombeC = this.critValuesFive[19];
            }
            else{
                if(this.confidenceLevel==0.95){
                    this.critValues = new CubicSpline(critSize, critValuesFive);
                }
                else{
                    this.critValues = new CubicSpline(critSize, critValuesOne);
                }
                this.anscombeC = this.critValues.interpolate((double)this.nAnalyteConcns);
            }
        }
View Full Code Here

Examples of flanagan.interpolation.CubicSpline

        }
        if(this.methodUsed==14){
            this.linterp = new LinearInterpolation(yy, xx);
        }
        else{
            this.interp = new CubicSpline(yy, xx);
        }

        // record working curve direction
        this.curveDirection = true;
        if(this.interpResponseStart>this.interpResponseEnd)this.curveDirection = false;

        // revisit working range
        this.workingResponseMin = Fmath.minimum(this.calculatedResponses);
        if(this.curveDirection){
            if(this.workingResponseMin<this.interpResponseStart)this.workingResponseMin = this.interpResponseStart;
        }
        else{
            if(this.workingResponseMin<this.interpResponseEnd)this.workingResponseMin = this.interpResponseEnd;
        }
        this.workingResponseMax = Fmath.maximum(this.calculatedResponses);
        if(this.curveDirection){
            if(this.workingResponseMax>this.interpResponseEnd)this.workingResponseMax = this.interpResponseEnd;
        }
        else{
            if(this.workingResponseMax>this.interpResponseStart)this.workingResponseMax = this.interpResponseStart;
        }

        // Prepare response error concn interpolation data within the working range
        double[] ee = new double[this.nWorking];
        double yError = Math.sqrt(super.sumOfSquaresError/(this.nAnalyteConcns - super.nParam));

        if(this.sampleErrorFlag){
            if(!this.weightsEntered){
                for(int i=0; i<this.nWorking; i++){
                    ee[i] = yError;
                }
            }
            else{
                // check if weights are monotonic within the working range
                boolean monoCheck = true;
                int iS = 0;
                int iF = this.nAnalyteConcns-1;
                boolean breakFlag = false;
                if(this.ambigCheck){
                    for(int i=0; i<this.nAnalyteConcns; i++){
                        if(this.interpAnalyteStart>=this.analyteConcns[i]){
                            iS = i;
                            breakFlag = true;
                        }
                        if(breakFlag)break;
                    }
                    breakFlag = false;
                    for(int i=this.nAnalyteConcns-1; i>=0; i--){
                        if(this.interpAnalyteEnd<=this.analyteConcns[i]){
                            iF = i;
                            breakFlag = true;
                        }
                        if(breakFlag)break;
                    }
                }
                int nwe = iF - iS + 1;
                double[] ew = new double[nwe];
                for(int i=0; i<nwe; i++)ew[i] = this.weights[i+iS];
                monoCheck = ImmunoAssay.isMonotonic(ew);

                // check for big jumps in the weights
                if(monoCheck){
                    double gap1 = Math.abs(ew[1] - ew[0]);
                    double gap0 = gap1;
                    for(int i=2; i<nwe; i++){
                        gap1 = Math.abs(ew[i] - ew[i-1]);
                        if(gap1>gap0)gap0 = gap1;
                    }
                    if(gap0>0.6*Math.abs(Fmath.maximum(ew) - Fmath.minimum(ew)))monoCheck = false;
                }

                // scale weights to overall fitting variance
                double[] sWeights = new double[this.nAnalyteConcns];
                double scale = yError/this.weightsMean;
                for(int i=0; i<this.nAnalyteConcns; i++)sWeights[i] = weights[i]*scale;
                if(this.weightsEntered && !monoCheck){
                    // linear interpolation if weights are non-monotonic or have big jumps
                    LinearInterpolation liee = new LinearInterpolation(this.analyteConcns, sWeights);
                    for(int i=0; i<this.nWorking; i++)ee[i] = Math.abs(liee.interpolate(xx[i]));
                }
                else{
                    // cubic spline interpolation if weights are monotonic without big jumps
                    CubicSpline csee = new CubicSpline(this.analyteConcns, sWeights);
                    for(int i=0; i<this.nWorking; i++)ee[i] = Math.abs(csee.interpolate(xx[i]));
                }
            }
            this.errorp = new CubicSpline(yy, ee);

            // Calculate the estimated errors in the estimated concentrations for each of the data points
            this.propagatedErrors = new String[this.nAnalyteConcns];
            double temp = 0.0;
            ArrayList<Double> alpe = new ArrayList<Double>();
            for(int i=0; i<this.nAnalyteConcns; i++){
                boolean checkFlag2 = false;
                if(this.curveDirection){
                    if(this.responses[i]<this.interpResponseStart || this.responses[i]>this.interpResponseEnd)checkFlag2 = true;
                }
                else{
                    if(this.responses[i]>this.interpResponseStart || this.responses[i]<this.interpResponseEnd)checkFlag2 = true;
                }
                if(checkFlag2){
                    this.propagatedErrors[i] = "**";
                }
                else{
                    alpe.add(new Double(this.responses[i]));
                    temp = this.getSampleConcn(this.responses[i]);
                    temp = this.getSampleConcnError();
                    alpe.add(new Double(temp));
                    temp = Fmath.truncate(temp, super.prec);
                    this.propagatedErrors[i] = (new Double(temp)).toString();
                }
            }

            // Calculate minimum, maximum and mean propagated errors
            int npe = alpe.size()/2;
            double[] resp = new double[npe];
            double[] xerr = new double[npe];
            for(int i=0; i<npe; i++){
                resp[i] = (alpe.get(2*i)).doubleValue();
                xerr[i] = (alpe.get(2*i+1)).doubleValue();
            }
            CubicSpline cspe = new CubicSpline(resp, xerr);
            double[] respe = new double[1001];
            double[] xerre = new double[1001];
            respe[0] = resp[0];
            respe[1000] = resp[npe-1];
            double incr = (resp[npe-1] - resp[0])/1000;
            for(int i=1; i<1000; i++){
                respe[i] = respe[i-1] + incr;
            }
            for(int i=0; i<1001; i++){
                xerre[i] = cspe.interpolate(respe[i]);
            }
            Stat stat = new Stat(xerre);
            this.minimumAerror = stat.minimum();
            this.maximumAerror = stat.maximum();
            this.meanAerror = stat.mean();
View Full Code Here

Examples of flanagan.interpolation.CubicSpline

                for(int i=0; i<ni; i++){
                    tr[i] = low+i;
                    trd[i] = (double)tr[i];
                    pp[i] = Stat.erlangBprobability(totalTraffic, tr[i]);
                }
                CubicSpline cs = new CubicSpline(trd, pp);
                prob = cs.interpolate(totalResources);
            }
            else{
                double logdenom = Math.log(crigf) + Stat.logGammaFunction(oneplustr);
                prob = Math.exp(lognumer - logdenom);
            }
View Full Code Here

Examples of flanagan.interpolation.CubicSpline

    yt[0]=CubicSpline.interpolate(temperature, temp, rfInRe1, derivRe1);
    yt[1]=CubicSpline.interpolate(temperature, temp, rfInRe2, derivRe2);
    yt[2]=CubicSpline.interpolate(temperature, temp, rfInRe3, derivRe3);

    // cubic spline interpolation with respect to wavelength
    CubicSpline cs = new CubicSpline(wavl, yt);
    cs.calcDeriv();
    yRe = cs.interpolate(wavelength);

      return yRe;
    }
View Full Code Here

Examples of flanagan.interpolation.CubicSpline

        for(int i=1; i<this.nInterpPoints-1; i++){
            this.xInterp[i] = this.xInterp[i-1] + incr;
        }
        this.xInterp[this.nInterpPoints-1] = this.xPositions[this.nData-1];

        CubicSpline cs = new CubicSpline(this.xPositions, this.yPositions);

        // Interpolate y values
        for(int i=0; i<this.nInterpPoints; i++)this.yInterp[i] = cs.interpolate(this.xInterp[i]);

        // Plot interpolated curve
        if(this.plotOpt){
            int nMax = Math.max(this.nInterpPoints, this.nData);
            double[][] plotData = PlotGraph.data(2, nMax);
View Full Code Here

Examples of flanagan.interpolation.CubicSpline

                lengthC85++;
                double[][] array = new double[lengthT85][lengthC85];
                for(int i=0; i<lengthT85; i++){
                    double[] lvisc = {Math.log(zero[i]), Math.log(twenty[i]), Math.log(forty[i]), Math.log(sixty[i])};
                    CubicSpline cs = new CubicSpline(concn85, lvisc);
                    for(int j=0; j<lengthC85; j++){
                        array[i][j] = cs.interpolate(conc85[j]);
                    }
                }
                BiCubicSpline bcs = new BiCubicSpline(temp85, conc85, array);
                ret = Math.exp(bcs.interpolate(temperature, gPerL));
            }
            else{
                if(temperature>100.0){
                    throw new IllegalArgumentException("Temperature, " + temperature + ", out of range");
                }
                else{
                    int lengthT100 = length60;
                    int lengthC100 =  amC.indexOf(771.9);
                    double[] temp100 = amT.subarray_as_double(0, lengthT100-1);
                    double[] conc100 = amC.subarray_as_double(0, lengthC100);
                    lengthC100++;

                    double[][] array = new double[lengthT100][lengthC100];
                    for(int i=0; i<lengthT100; i++){
                        double[] lvisc = {Math.log(zero[i]), Math.log(forty[i]), Math.log(sixty[i])};
                        CubicSpline cs = new CubicSpline(concn100, lvisc);
                        for(int j=0; j<lengthC100; j++){
                            array[i][j] = cs.interpolate(conc100[j]);

                        }
                    }
                    BiCubicSpline bcs = new BiCubicSpline(temp100, conc100, array);
                    ret = Math.exp(bcs.interpolate(temperature, gPerL));
                }
            }
        }
        else{
            if(temperature==20 && gPerL<=1208.2){
                double[] concM = amC.subarray_as_double(0, viscLength-1);
                CubicSpline cs = new CubicSpline(concM, visc20);
                ret = cs.interpolate(gPerL);
            }
            else{
                throw new IllegalArgumentException("Concentration, " + gPerL + " g/l,  for this temperature, " + temperature + " C,is out of range");
            }
        }
View Full Code Here

Examples of flanagan.interpolation.CubicSpline

                nxpoints=this.nPoints[i];
                double xcs[]= new double[nxpoints];
                double ycs[]= new double[nxpoints];

                  if(lineOpt[i]==1 || lineOpt[i]==2){
                    CubicSpline cs = new CubicSpline(this.nPoints[i]);
                    for(int ii=0; ii<nxpoints; ii++){
                          xcs[ii]=this.data[kk][ii];
                    }
                    csstep=(xcs[nxpoints-1]-xcs[0])/(niPoints-1);
                    ics[0]=xcs[0];
                    for(int ii=1; ii<niPoints; ii++){
                          ics[ii]=ics[ii-1]+csstep;
                    }
                    ics[niPoints-1] = xcs[nxpoints-1];
                     for(int ii=0; ii<nxpoints; ii++){
                          ycs[ii]=this.data[kk+1][ii];
                    }

                    cs.resetData(xcs, ycs);
                    cs.calcDeriv();
                    xoldpoint=xBot+(int)(((xcs[0]-xLow)/xdenom)*xLen);
                    yoldpoint=yBot-(int)(((ycs[0]-yLow)/ydenom)*yLen);
                    for(int ii=1; ii<niPoints; ii++){
                           xnewpoint=xBot+(int)(((ics[ii]-xLow)/xdenom)*xLen);
                          ynewpoint=yBot-(int)(((cs.interpolate(ics[ii])-yLow)/ydenom)*yLen);
                          btest2=printCheck(trimOpt[i], xoldpoint, xnewpoint, yoldpoint, ynewpoint);
                          if(btest2){
                              if(this.lineOpt[i]==2){
                                    dsum++;
                                    if(dsum>dashLength[i]){
                                        dsum=0;
                                        if(dcheck){
                                              dcheck=false;
                                        }
                                else{
                                              dcheck=true;
                                        }
                                    }
                              }
                              if(dcheck)g.drawLine(xoldpoint,yoldpoint,xnewpoint,ynewpoint);
                          }
                          xoldpoint=xnewpoint;
                          yoldpoint=ynewpoint;
                    }
                }

                if(lineOpt[i]==-1 || lineOpt[i]==-2){
                    CubicSpline cs = new CubicSpline(this.nPoints[i]);
                    for(int ii=0; ii<nxpoints; ii++){
                          xcs[ii]=this.data[kk][ii];
                    }
                    for(int ii=0; ii<nxpoints; ii++){
                          ycs[ii]=this.data[kk+1][ii];
                    }
                    csstep=(ycs[nxpoints-1]-ycs[0])/(niPoints-1);
                    ics[0]=ycs[0];
                    for(int ii=1; ii<niPoints; ii++){
                          ics[ii]=ics[ii-1]+csstep;
                    }
                    ics[niPoints-1] = ycs[nxpoints-1];

                    cs.resetData(ycs, xcs);
                    cs.calcDeriv();
                    xoldpoint=xBot+(int)(((xcs[0]-xLow)/xdenom)*xLen);
                    yoldpoint=yBot-(int)(((ycs[0]-yLow)/ydenom)*yLen);
                    for(int ii=1; ii<niPoints; ii++){
                          ynewpoint=yBot+(int)(((ics[ii]-yLow)/ydenom)*yLen);
                          xnewpoint=xBot-(int)(((cs.interpolate(ics[ii])-xLow)/xdenom)*xLen);
                          btest2=printCheck(trimOpt[i], xoldpoint, xnewpoint, yoldpoint, ynewpoint);
                          if(btest2){
                              if(this.lineOpt[i]==2){
                                    dsum++;
                                    if(dsum>dashLength[i]){
View Full Code Here
TOP
Copyright © 2018 www.massapi.com. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.