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;
}
int main()
{
  vector< int > v;
  v.push_back(3);
  v.push_back(5);
  v.push_back(2);
  cout << "min_odd = "
       << *min_element_if(v.begin(),
			  v.end(),
			  compose1_1(bind2nd(greater< int >(), 0),
				     bind2nd(modulus< int >(), 2)))
       << endl;
  return 0;
}
Exemple #3
0
PPMonoidElem SQFR(ConstRefPPMonoidElem T)
{
  vector<long> expv;
  exponents(expv,T);
  replace_if(expv.begin(),expv.end(),bind2nd(not_equal_to<long>(),0),1);
  return PPMonoidElem(owner(T),expv);
}//SQFR
Exemple #4
0
BVHAccelTreeNode *BVHAccel::BuildHierarchy(vector<BVHAccelTreeNode *> &list, unsigned int begin, unsigned int end, unsigned int axis) {


	const int treeType = 4; // Tree type to generate (2 = binary, 4 = quad, 8 = octree)


	unsigned int splitAxis = axis;
	float splitValue;

	nNodes += 1;
	if (end - begin == 1) // Only a single item in list so return it
		return list[begin];

	BVHAccelTreeNode *parent = new BVHAccelTreeNode();
	parent->primitive = 0xffffffffu;
	parent->leftChild = NULL;
	parent->rightSibling = NULL;

	vector<unsigned int> splits;
	splits.reserve(treeType + 1);
	splits.push_back(begin);
	splits.push_back(end);
	for (unsigned int i = 2; i <= treeType; i *= 2) { // Calculate splits, according to tree type and do partition
		for (unsigned int j = 0, offset = 0; j + offset < i && splits.size() > j + 1; j += 2) {
			if (splits[j + 1] - splits[j] < 2) {
				j--;
				offset++;
				continue; // Less than two elements: no need to split
			}

			FindBestSplit(list, splits[j], splits[j + 1], &splitValue, &splitAxis);

			vector<BVHAccelTreeNode *>::iterator it =
					partition(list.begin() + splits[j], list.begin() + splits[j + 1], bind2nd(ptr_fun(bvh_ltf[splitAxis]), splitValue));
			unsigned int middle = distance(list.begin(), it);
			middle = max(splits[j] + 1, min(splits[j + 1] - 1, middle)); // Make sure coincidental BBs are still split
			splits.insert(splits.begin() + j + 1, middle);
		}
	}

	BVHAccelTreeNode *child, *lastChild;
	// Left Child
	child = BuildHierarchy(list, splits[0], splits[1], splitAxis);
	parent->leftChild = child;
	parent->bbox = child->bbox;
	lastChild = child;

	// Add remaining children
	for (unsigned int i = 1; i < splits.size() - 1; i++) {
		child = BuildHierarchy(list, splits[i], splits[i + 1], splitAxis);
		lastChild->rightSibling = child;
		parent->bbox = Union(parent->bbox, child->bbox);
		lastChild = child;
	}

	return parent;
}
Exemple #5
0
bool
Matrix::is_count_mat() const {
  // TODO: this needs to be much more robust, or maybe we need to have
  // a 3 way split: matrices can be freq or count, or just plain wrong
  for (Matrix::const_iterator i = begin(); i != end(); ++i)
    if (find_if(*i, *i + alphabet_size, bind2nd(greater<float>(), 1)) 
	!= *i + alphabet_size)
      return true;
  return false;
}
Value * FunctionCallNode::GenerateCode (CodeGeneratorState & state) const {
	Function * callee = state.module->getFunction (this->name.c_str ());
	if (NULL == callee)
		throw "Unknown function called";

	if (callee->arg_size () != this->params->size ())
		throw "Prototype mismatch";

	vector <Value *> arguments;
	arguments.reserve (this->params->size ());
	transform (this->params->begin (), this->params->end (), back_inserter (arguments), bind2nd (mem_fun (& IASTNode::GenerateCode), state));

	return state.builder->CreateCall (callee, arguments.begin (), arguments.end (), "tmp");
}
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;
}
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;
}
bool Coff_object::is_undef(const char a_sym[]) const
{
    using std::find_if;
    using std::not1;
    using std::bind2nd;
    using std::ptr_fun;
    using std::strcmp;

    typedef std::vector<const char*> T;

    T::const_iterator beg_p = m_undef_symbols.begin();
    T::const_iterator end_p = m_undef_symbols.end();

    T::const_iterator pos = find_if( beg_p, end_p, not1(bind2nd( ptr_fun(strcmp), a_sym)) );

    return (pos != end_p);
}
Exemple #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;
}
Exemple #11
0
Matrix
Matrix::combine(const Matrix &matrix1, const Matrix &matrix2, int offset) {
  Matrix newmat;
  newmat.width = std::max(matrix1.width,
			  matrix2.width + offset);
  newmat.matrix = new float*[newmat.width];
  for (size_t i = 0; i < newmat.width; ++i) {
    newmat.matrix[i] = new float[alphabet_size];
    fill(newmat.matrix[i], newmat.matrix[i] + alphabet_size, 0);
  }
  for (size_t i = 0; i < matrix1.width; ++i)
    for (size_t j = 0; j < alphabet_size; ++j)
      newmat.matrix[i][j] += matrix1.matrix[i][j];
  for (size_t i = 0; i < matrix2.width; ++i)
    for (size_t j = 0; j < alphabet_size; ++j)
      newmat.matrix[i + offset][j] += matrix2.matrix[i][j];
  for (size_t i = 0; i < newmat.width; ++i) {
    const float total = accumulate(newmat.matrix[i],
				   newmat.matrix[i] + alphabet_size, 0.0);
    transform(newmat.matrix[i], newmat.matrix[i] + alphabet_size,
	      newmat.matrix[i], bind2nd(divides<float>(), total));
  }
  return newmat;
}
Exemple #12
0
void	BBCutter::SetFillDutyCycle(float v) { for_each(procs.begin(),procs.end(),bind2nd(mem_fun(&CutProc::SetFillDutyCycle),v));}
Exemple #13
0
void	BBCutter::SetMaxPhraseLength(long v) { for_each(procs.begin(),procs.end(),bind2nd(mem_fun(&CutProc::SetMaxPhraseLength),v));}
Exemple #14
0
DtxAck::DtxAck(const qpid::framing::SequenceSet& acked, DeliveryRecords& unacked)
{
    remove_copy_if(unacked.begin(), unacked.end(), inserter(pending, pending.end()), 
                   not1(bind2nd(mem_fun_ref(&DeliveryRecord::coveredBy), &acked)));
}
Exemple #15
0
void	BBCutter::SetMinPan(float v)      { for_each(procs.begin(),procs.end(),bind2nd(mem_fun(&CutProc::SetMinPan),v));}
Value * ASTNodesListNode::GenerateCode (CodeGeneratorState & state) const {
	for_each (this->exprs.begin (), this->exprs.end (), bind2nd (mem_fun (& IASTNode::GenerateCode), state));
}
Exemple #17
0
void	BBCutter::SetMaxDetune(float v)   { for_each(procs.begin(),procs.end(),bind2nd(mem_fun(&CutProc::SetMaxDetune),v));}