Ejemplo n.º 1
0
int main() {

    cout << plus<int>()(3,4) << endl; // prints 7

    plus<int> intAdd;        // function object that can add two int values
    negate<int>  intNegate;  // function object that can negate an int value

    // uses intAdd::operator(int, int) to add 10 and 20
    int sum = intAdd(10, 20);        // sum = 30

    cout << sum << endl;

    // uses intNegate::operator(int) to generate -10 as second parameter
    // to intAdd::operator(int, int)
    sum = intAdd(10, intNegate(10));  // sum = 0

    cout << sum << endl;

    int arry[] = {0,1,2,3,4,5,16,17,18,19};

    vector<int> vec(arry, arry + 10);

    cout <<
    count_if(vec.begin(), vec.end(),
             bind2nd(less_equal<int>(), 10));
    cout << endl;

    cout <<
    count_if(vec.begin(), vec.end(),
             not1(bind2nd(less_equal<int>(), 10)));
    cout << endl;

    return 0;
}
Ejemplo n.º 2
0
int main() {

	cout << plus<int>()(3,4) << endl; // prints 7
	
	plus<int> intAdd;      // object that can add two int values
	negate<int> intNegate; // object that can negate an int value
	
	// uses intAdd::operator(int, int) to add 10 and 20
	int sum = intAdd(10, 20);         // equivalent to sum = 30
	cout << sum << endl;
	
	sum = intNegate(intAdd(10, 20));  // equivalent to sum = -30
	cout << sum << endl;
	
	// uses intNegate::operator(int) to generate -10 
	// as the second argument to intAdd::operator(int, int)
	sum = intAdd(10, intNegate(10));  // sum = 0
	
	cout << sum << endl;
	
#ifdef LIST_INIT
	vector<int> vec = {0,1,2,3,4,5,16,17,18,19};
#else
	int temp[] = {0,1,2,3,4,5,16,17,18,19};
	vector<int> vec(begin(temp), end(temp));
#endif
	
	// bind second argument to less_equal
	cout << count_if(vec.begin(), vec.end(),
		             bind(less_equal<int>(), _1, 10));  
	cout << endl;
	
	vector<string> svec;
	string in;
	while (cin >> in) 
		svec.push_back(in);

	function<decltype(size_compare)> fp1 = size_compare;

	//decltype(fp1)::result_type ret;
	function<bool(const string&)> fp2 = bind(size_compare, _1, 6);
	cout << count_if(svec.begin(), svec.end(), fp2)
	     << endl;
	cout << count_if(svec.begin(), svec.end(), 
	                 bind(size_compare, _1, 6))
	     << endl;


	return 0;
}
Ejemplo n.º 3
0
int main(void)
{
    string text = "the quick red fox jumps over the slow red turtle";
    istringstream is(text);
    vector<string> words;
    string s;

    while (is >> s)
        words.push_back(s);

    elimDups(words);    // put words into alphabetical order and remove duplicates

    for (const auto &s : words)
        cout << s << " ";
    cout << endl;

    // resort by length, maintaining alphabetical order among words of the same
    // length
    stable_sort(words.begin(), words.end(), isShorter);

    for (const auto &s : words)
        cout << s << " ";
    cout << endl;

    // how may words greater than length 6
    cout << count_if(words.begin(), words.end(),
            [](const string &s) { return s.size() > 6; })
         << " word(s) greater than length 6" << endl;

    return 0;
}
Ejemplo n.º 4
0
int main() {
  auto function = bind(longer_than_6, _1);
  vector<string> vec{"the",  "quick", "red",  "fox", "jumps",
                     "over", "the",   "slow", "red", "turtle"};
  cout << count_if(vec.begin(), vec.end(), function) << endl;
  return 0;
}
Ejemplo n.º 5
0
size_t test_suite::failure_count() const
{
  using std::count_if;
  using boost::bind;
  
  const size_t this_suite =
    static_cast<size_t>(
      count_if(
        _results.begin(),
        _results.end(),
        !bind(&test_result::success, _1)
      )
    );
  
  size_t children = 0;
  for (
    suite_map::const_iterator i = _suites.begin(), e = _suites.end();
    i != e;
    ++i
  )
  {
    children += i->second.failure_count();
  }
  
  return this_suite + children;
}
Ejemplo n.º 6
0
float StageClassifier::Evaluate(vector<vector<vector<float>>>& X, vector<bool>& y)
{
    vector<float> probs;
    vector<float> TPRs, FPRs;
    float area = 0;

    for (int i = 0; i < X.size(); i++)
        probs.push_back(Predict(X[i]));

    /* test on training set (0.5 threshhold??) */
    //#if SETLEVEL == DEBUG_LEVEL
    //int TP = 0, TN = 0;
    //for (int i = 0; i < X.size(); i++)
    //{
    //    if ((probs[i] >= 0.5) && y[i] == true)
    //        TP++;
    //    else if ((probs[i] < 0.5) && y[i] == false)
    //        TN++;
    //}
    //LOG_DEBUG_NN("\t\tStrong classifier: ");
    //LOG_DEBUG_NN("TP = " << TP << '/' << y.size() / 2 << ", TN = " << TN << '/' << y.size() / 2);
    //LOG_DEBUG_NN(", Result: " << (float)(TP + TN) / y.size());
    //#endif

    for (float threshhold = 1; threshhold >= 0; threshhold -= auc_step)
    {
        TPRs.push_back(count_if(probs.begin(), probs.begin() + n_pos, bind2nd(greater_equal<float>(), threshhold)) / (float)n_pos);
        FPRs.push_back(count_if(probs.begin() + n_pos, probs.end(), bind2nd(greater_equal<float>(), threshhold)) / (float)n_neg);

        if (FPRs.size() > 1)
            area += (TPRs.back() + TPRs[TPRs.size() - 2]) * (FPRs.back() - FPRs[FPRs.size() - 2]) / 2; // trapezoid
            //area += TPRs[TPRs.size() - 2] * (FPRs.back() - FPRs[FPRs.size() - 2]); // left riemann sum
            //area += TPRs.back() * (FPRs.back() - FPRs[FPRs.size() - 2]); // right Riemann sum
    }

    return area;
}
Ejemplo n.º 7
0
void StageClassifier::SearchTheta(vector<vector<vector<float>>>& X, vector<bool>& y)
{
    int whole_n_total = (int)y.size();
    int whole_n_pos = (int)count(y.begin(), y.end(), true);
    int whole_n_neg = (int)(whole_n_total - whole_n_pos);

    vector<float> probs;

    for (int i = 0; i < X.size(); i++)
        probs.push_back(Predict(X[i]));

    /* search min TPR */
    float threshhold;
    for (threshhold = 1; threshhold >= 0; threshhold -= search_step)
    {
        TPR = count_if(probs.begin(), probs.begin() + whole_n_pos, bind2nd(greater_equal<float>(), threshhold)) / (float)whole_n_pos;
        if (TPR >= TPR_min)
            break;
    }

    /* get corresponding theta and FPR */
    theta = threshhold;
    FPR = count_if(probs.begin() + whole_n_pos, probs.end(), bind2nd(greater_equal<float>(), threshhold)) / (float)whole_n_neg;
}
Ejemplo n.º 8
0
int main()
{
	vector<int> ivec{1, 16, 256, 4096, 65536};
	vector<string> svec{"pooh", "pooh", "pooh", "hoop", "pooh"};

	auto cnt = count_if(ivec.cbegin(), ivec.cend(), bind(greater<int>(), _1, 1024));
	cout << cnt << endl;
	auto it = find_if(svec.cbegin(), svec.cend(), bind(not_equal_to<string>(), _1, "pooh"));
	cout << *it << endl;
	transform(ivec.begin(), ivec.end(), ivec.begin(), bind(multiplies<int>(), _1, 2));
	for (const auto &val : ivec)
		cout << val << ' ';

	return 0;
}
Ejemplo n.º 9
0
int main(int argc, char* argv[])
{
    ifstream file(argv[1]);
    string word;
    vector<string> text;
    while (file >> word)
    {
        text.push_back(word);
    }
    for (auto i = 0; i < 50;++i)
    {
        if(auto n = count_if(text.cbegin(), text.cend(), Boundry(i)))
        std::cout << i << " length words has" << n << "." << std::endl;
    }

    return 0;
}
Ejemplo n.º 10
0
int main(int argc, char *argv[])
{
    double duty = 0.5;
    if (argc > 1)
    {
        duty = std::atof(argv[1]);
    }

    // sample frequency is fixed at 1 kHz, signal frequency at 10 Hz
    Aquila::SquareGenerator gen(1000);
    gen.setDuty(duty).setAmplitude(1).setFrequency(10).generate(1000);

    // prints number of positive samples in generated signal
    std::cout << count_if(gen.begin(), gen.end(),
                          bind2nd(greater<Aquila::SampleType>(), 0));

    return 0;
}
Ejemplo n.º 11
0
int main()
{
    list<string> words;
    string next_word;

    while (cin >> next_word)
        words.push_back(next_word);

    words.sort();
    print_words(words);

    words.unique();
    print_words(words);

    list<string>::size_type wc = count_if(words.begin(), words.end(), GT6);
    cout << wc << " words 6 characters or longer" << endl;
    return 0;
}
Ejemplo n.º 12
0
int main() 
{
	vector<int> iVector{ 1, 22, 3434, 83448, 83781 }, iRet;
	// cout the int which is bigger than 1024 using function class
	int count = count_if(iVector.begin(), iVector.end(), bind(std::greater<int>(), _1, 1024));

	vector<string> sVector{"pooh", "hello", "pooh", "world"};
	// find the first string not equal to "pooh"
	vector<string>::iterator position = find_if(sVector.begin(), sVector.end(), bind(std::not_equal_to<string>(), _1, "pooh"));

	// multiplies each element in iVector, and put the result to iRet;
	std::transform(iVector.begin(), iVector.end(), back_inserter(iRet), bind(std::multiplies<int>(), _1, 2));

	cout << "cout : " << count << endl;
	cout << "The first string : " << *position << endl;
	for (const auto& item: iRet) 
	{
		cout << item << " ";
	}
	cout << endl;
	return 0;
}
Ejemplo n.º 13
0
//! Exercise 10.20
std::size_t bigerThan6(vector<string> const& v)
{
    return count_if(v.cbegin(), v.cend(), [](string const& s){
        return s.size() > 6;
    });
}
Ejemplo n.º 14
0
  insertElements(con, 1, 10);
  printContainer(con, "con: ");  // con: 1 2 3 4 5 6 7 8 9 10

  int numOf1 = count(con.begin(), con.end(), 1);
  psln(numOf1);
  EXPECT_EQ(1, numOf1);      // one 1.
  con.push_back(1);
  con.push_back(1);
  printContainer(con, "con: ");  // con: 1 2 3 4 5 6 7 8 9 10 1 1
  numOf1 = count(con.begin(), con.end(), 1);
  psln(numOf1);
  EXPECT_EQ(3, numOf1);      // three 1.

  using std::count_if;
  int numOfEven = count_if(con.begin(), con.end(),
    [](int elem) -> bool {
    return ( elem % 2 == 0 );     // 2 4 6 8 10 -> five even.
  });
  psln(numOfEven);
  EXPECT_EQ(5, numOfEven);

END_TEST;




bool absLess(int a, int b) {
  return abs(a) < abs(b);
}