コード例 #1
0
int main() {
    // limits of integration
    const double a = -1;
    const double b = 7;

    // actual integral value
    double trueVal = 1.0 / c * (std::exp(c*b) - std::exp(c*a)) - 1.0 / d * (std::cos(d*b) - std::cos(d*a));
    printf("True integral value = %22.16e\n\n", trueVal);

    // test composite numerical integration function
    int n[] = {6, 12, 24, 36, 48, 60, 72, 84, 96, 108};
    int ntests = 10;
    Mat errs(ntests);
    Mat hvals(ntests);
    Mat approxs(ntests);
    // calculate approxs, errs, convergence rates
    for(unsigned int i = 0; i < ntests; i++) {
        approxs(i) = composite_int(f, a, b, n[i]);
        errs(i) = std::abs((trueVal - approxs(i)) / trueVal);
        hvals(i) = (b - a) / n[i];
    }

    // output results
    std::cout << "Composite Numerical Integration Approximation:" << std::endl;
    for(unsigned int i = 0; i < ntests; i++) {
        printf("   %6i", n[i]);
        if(i == 0)
            printf("  %22.16e  %7.1e     ----\n", approxs(i), errs(i));
        else
            printf("  %22.16e  %7.1e   %f\n", approxs(i), errs(i), (std::log(errs(i-1)) - std::log(errs(i)))/(std::log(hvals(i-1)) - std::log(hvals(i))));
    }

    return 0;
}
コード例 #2
0
uint64_t CRedisClient::hvals(const string &key, CRedisClient::VecString &values)
{
    CResult result;
    hvals( key, result );

    ReplyType type = result.getType();
    if ( REDIS_REPLY_ERROR == type )
    {
        throw ReplyErr( result.getErrorString() );
    }else if ( REDIS_REPLY_ARRAY != type )
    {
        throw ProtocolErr( "HVALS: data recved is not arry");
    }
    CResult::ListCResult::const_iterator it = result.getArry().begin();
    CResult::ListCResult::const_iterator end = result.getArry().end();
    for ( ; it != end; ++it )
    {
        values.push_back( static_cast<string>(*it) );
    }
    return values.size();
}
コード例 #3
0
ファイル: hasher.cpp プロジェクト: UW-Kutz-Lab/LILAC-backup
vector<float> hasher::get_cur_scores(){
    const rmf& hvals = rand_scores;
    vector<float> scores(tor_hashes.size()-2, 0);
    for(size_t g = 2; g < tor_hashes.size(); g++){
        vector<vector<size_t> >& hvec = tor_hashes[g];
        //preceding has table gives probability that distance is more than
        //current measure
        vector<vector<size_t> >& hvecm2 = tor_hashes[g-2];
        //gval hvec = dval[i]*2
        //gval hvecm1 = dval[i]
        //gval hvecm2 = dval[i]/2
        //if(!in hvecm1), pr bad is for 2*gval = dval*2
        //if(!in hvecm2), pr bad is for 2*gval = dval
        //if(in hvec) pr good is for gval/2 = dval
        //therefore need to be minus two hash funcs
        for(size_t i = 0; i < (size_t)hvals.rows(); i++){
            float pr_far;
            size_t num_near = 0;
            size_t num_far=0;
            pr_far = 0;
            size_t num_ave = 0;
            for(size_t j = 0; j < (size_t)hvals.cols(); j++){
                //    increment corresponding hash table bin
                //    gamma/2, 2*gamma, 1/2, 1/3 sensitive
                //    for now we treat not being near as zero probability of begin near
                //    for now, hold two counts: number of vectors for which
                //    the hash function claims the rvec is near
                //    and number of times the rvec claims it is not near a vector
                //
                //    if (n_near*((1/2)/(1/3) < n_far)) then
                //    say it is near a vector. Else, it is not
                size_t num_near_tmp = hvec[j][get_bin(hvals(i, j), hvec[j].size())];
                long num_far_tmp = (long)hvecm2[j][get_bin(hvals(i, j), hvec[j].size())];
                num_near += num_near_tmp;
                //if not zero, make zero. otherwise make 1
                num_far_tmp = (num_far_tmp == 0);
                num_far += num_far_tmp;
                pr_far += (pow(0.5, num_near_tmp) + num_far_tmp);
                num_ave += (1+num_far_tmp);
            }
            //cout << num_near*1.0/hvals.cols() << endl;
            pr_far/= num_ave;
        //    if(pr_far < 0.2){
       if(num_far < 1){ 
                scores[g-2]++;
            }
        }
        scores[g-2]/=rand_scores.rows();
    }
    size_t num_bel_min = 0;

    list<rmf>::iterator beg;
    for(size_t r = 0; r < (size_t)rand_vecs.rows(); r++){
        float mindis=mnorm;
        list<rmf>::iterator lcur;
        for(lcur=in_vecs.begin(); lcur != in_vecs.end(); lcur++){
            for(size_t i = 0; i < (size_t)lcur->rows(); i++){
                float cdist = (rand_vecs.row(r) - lcur->row(i)).norm();
                if(cdist < mindis){
                    mindis = cdist;
                }
            }
        }
        if(mindis < 0.25){
            num_bel_min++;
        }
    }
   // float act_bel_min = (1.0*num_bel_min)/(1.0*rand_vecs.rows());
    cout << scores[0]*rand_vecs.rows() << ", " << num_bel_min << endl;
    return scores;
}