Ejemplo n.º 1
0
void ProgressTask::doTestProgress(double mbps, double duration,
                                  unsigned int no_conn) {
    if (duration <= current_duration || terminated())
        return;

    current_duration = duration;

    // Don't let the speed decrease the last half second:
    if (duration < tot_duration-0.5 || mbps > current_mbps)
        current_mbps = mbps;

    if (duration >= tot_duration) {
        setResult(fValue(current_mbps));
        return;
    }

    setMessage("progress");
    log() << "task progress " << current_mbps << ' ' << duration/tot_duration;

    if (duration > tot_duration-0.35) {
        // Less than 0.35 seconds left, don't make any new requests
        // (but let existing requests keep going).
        noMoreConnections();
        current_load_size = 0;
        soon_finished = true;
        return;
    }

    // Calculate appropriate load size for subsequent requests

    //unsigned int n = getNoConnections();
    if (!no_conn)
        return;

    double time_left = tot_duration - duration;

    // We'll probably load this number of bytes during the time_left:
    double exp_bytes;
    if (speedlimit_mbps > 0.0)
        exp_bytes = std::min(speedlimit_mbps, mbps) * std::min(time_left, 0.3) / 0.000008;
    else
        exp_bytes = mbps * time_left / 0.000008;

    current_load_size = static_cast<size_t>(exp_bytes / 4.0 / no_conn);
    if (current_load_size > 40000000)
        current_load_size = 40000000;
    else if (current_load_size < 6000)
        current_load_size = 6000;

    if (speedlimit_mbps > mbps) {
        dbg_log() << "We're going too slow, wake up the passive connections";
        wakeUp();
    }
}
Ejemplo n.º 2
0
void DFO_CalcConfidenceGrid:: CalcOutput(FOcalcType  calcType)
{
    DoStatusChk();
    if (StatusNotOK())
        return;

    //number of cases selected - a confidence will be calculated for each selected case
    int nx = inputGridResultsDC->xData.Size();
    int ny = inputGridResultsDC->yData.Size();

    if (autoBestCase)
    {
        double minS = 1.0E100;
        for (int i = 0; i < nx; i++)
        {
            for (int j = 0; j < ny; j++)
            {
                double sse = inputGridResultsDC->gData[i][j];
                if (sse < minS)
                {
                    minS = sse;
                    bestCaseXIndex = i;
                    bestCaseYIndex = j;
                }
            }
        }

    }

    double bestS = inputGridResultsDC->gData[bestCaseXIndex][bestCaseYIndex];
    if (bestS <= 0.0)
    {
        SetObjErrMsg("Expecting best SSE to be greater than 0");
        return;
    }
    int n = nDataPts;  //number of data points - should be same for all cases

    if (!outputGridDC.CreateFrom(*inputGridResultsDC))
    {
        SetObjErrMsg("grid allocation??");
        return;
    }

    if (!outputAlphaGridDC.CreateFrom(*inputGridResultsDC))
    {
        SetObjErrMsg("alpha grid allocation??");
        return;
    }

    char errMsg[80];
    for (int i = 0; i < nx; i++)
    {
        SC_DoubleArray& alpha = outputGridDC.gData[i];
        int p = nParam;  //number of parameters

        if (distribution == dF)
        {
            SC_DoubleArray fValue(ny);
            double factor = double(n - p) / double(p);

            for (int j = 0; j < ny; j++)
            {
                double currS = inputGridResultsDC->gData[i][j];
                if (currS <= 0.0)
                {
                    SetObjErrMsg("Expecting all SSE to be greater than 0");
                    return;
                }
                fValue[j] = factor * fabs(currS - bestS) / currS;
            }

            if (!CalcQF(fValue, p, n - p, alpha, errMsg, 80))
            {
                SetObjErrMsg(errMsg);
                return;
            }
        }
        else if (distribution == dChiSqr)
        {
            SC_DoubleArray chiSqValue(ny);
            double logBestS = log(bestS);

            for (int j = 0; j < ny; j++)
            {
                double currS = inputGridResultsDC->gData[i][j];
                if (currS <= 0.0)
                {
                    SetObjErrMsg("Expecting all SSE to be greater than 0");
                    return;
                }
                chiSqValue[j] = n * fabs(log(currS) - logBestS);
            }

            if (!CalcQChiSquared(chiSqValue, p, alpha, errMsg, 80))
            {
                SetObjErrMsg(errMsg);
                return;
            }
        }
        SC_DoubleArray& conf = outputAlphaGridDC.gData[i];
        for (int k = 0; k < ny; k++)
            conf[k] = 1.0 - alpha[k];
    }

    if (distribution == dF)
    {
        outputGridDC.SetID("F-test alpha");
        outputAlphaGridDC.SetID("F-test confidence (1-alpha)");
    }
    else if (distribution == dChiSqr)
    {
        outputGridDC.SetID("Log-likelihood alpha");
        outputAlphaGridDC.SetID("Log-likelihood confidence (1-alpha)");
    }
}