Ejemplo n.º 1
0
std::pair<Matrix, std::vector<Label>> filterDataset(const Matrix &A, const std::vector<Label> &labels, const std::bitset<K> &filter) {
    Timer timer("Filter Dataset Timer");

    if (K < labels.size() || filter.count() <= 1) {
        std::stringstream fmt;
        fmt << "Filtro para el dataset tiene tamaño " << K << " cuando el dataset tiene tamaño " << labels.size();
        throw new std::invalid_argument(fmt.str());
    }

    std::vector<Label> output(filter.count(), 0.0);
    int last = 0;

    for (int i = 0; i < A.rows(); ++i) {
        if (filter.test((std::size_t) i)) {
            output[last] = labels[i];
            last++;
        }
    }

    return std::pair<Matrix, std::vector<Label>>(Matrix(A, filter), output);
}
Ejemplo n.º 2
0
void Apriori::confidence_get_unitbitset(
        const std::bitset<NUM> &r_bsdata,
        std::vector<IndexBitSet_t> &r_unitbitset)
{
    std::bitset<NUM> b(0x01);
    int count = r_bsdata.count();
    r_unitbitset.clear();
    for(int i=0; i<NUM; i++){
        if((r_bsdata & b) == b ){
            r_unitbitset.push_back(this->get_index( b ));
            if(--count <= 0) break;
        }
        b <<= 1;
    }
}
Ejemplo n.º 3
0
void bitsetMultiply(std::bitset<N>& x, const std::bitset<N>& y)
{
  std::bitset<N> tmp = x;
  x.reset( );

  // we want to minimize the number of times we shift and add
  if (tmp.count( ) < y.count( )) {
    for (int i=0; i < N; i++)
      if (tmp[i]) bitsetAdd(x, y << i);
  }
  else {
    for (int i=0; i < N; i++)
      if (y[i]) bitsetAdd(x, tmp << i);
  }
}
Ejemplo n.º 4
0
Archivo: 1200.cpp Proyecto: jflyup/POJ
int main()
{
	int substr_len;
	//use the number of unique characters as number base
	int base;
	scanf("%d %d", &substr_len, &base);
	scanf("%s", str);
	int length = strlen(str);

	if(length < substr_len)
	{
		printf("0\n");
		return 0;
	}

	int unique_character = 0;
	int index = 0;
	while(unique_character < base)
	{
		if(value[str[index]] == 0)
			value[str[index]] = unique_character++;
		index++;
	}

	long rolling_hash = 0;
	for(int i = 0; i < substr_len; ++i)
		rolling_hash =  rolling_hash * base + value[str[i]];
	mark[rolling_hash] = 1;

	// Calculate hash value for next window of text: Remove leading digit, add trailing digit
	// hash(s[i+1 ... i+m] ) = base *(hash(s[i .. s+i-1]) – s[i] * (b^(m-1) ) )+ s[i + m] 

	//h = pow(base, substr_len - 1)
	int h = 1;
	for (int i = 0; i < substr_len - 1; i++)
		h *=  base; //int overflow?

	for(int i = 0; i < length - substr_len; i++)
	{
		rolling_hash = base *(rolling_hash - value[str[i]] * h) + value[str[i + substr_len]];
		mark[rolling_hash] = 1;
	}

	printf("%ld\n", mark.count());
	return 0;
};
Ejemplo n.º 5
0
int main()
{
	while(scanf("%d%d%d", &n, &m, &q) == 3 && n + m + q)
	{
		for(int i = 0; i < n; ++i)
			scanf("%d%d%d%d", &cir[i].x, &cir[i].y, &cir[i].z, r + i);
		for(int i = 0; i < m; ++i)
			scanf("%d%d%d%d", &lht[i].x, &lht[i].y, &lht[i].z, val + i);
		scanf("%d%d%d", &obj.x, &obj.y, &obj.z);
		for(int i = 0; i < n; ++i)
			cir[i] = cir[i] - obj;
		for(int i = 0; i < m; ++i)
		{
			lht[i] = lht[i] - obj;
			dis[i] = lht[i].mode();
			cnt[i].reset();
			for(int j = 0; j < n; ++j)
			{
				int sgn1 = sgn((lht[i] - cir[j]).mode() - r[j] * r[j]);
				int sgn2 = sgn(cir[j].mode() - r[j] * r[j]);
				if(sgn1 * sgn2 < 0
				|| sgn1 > 0 && sgn2 > 0 && lht[i].det(cir[j]).mode() < r[j] * r[j] * (LL)dis[i]
				&& lht[i].dot(lht[i] - cir[j]) > 0 && lht[i].dot(cir[j]) > 0)
					cnt[i].set(j);
			}
		}
		double ans = 0;
		for(int i = 0; i < 1 << m; ++i)
		{
			double value = 0;
			cost.reset();
			for(int j = 0; j < m; ++j)
				if((i >> j) & 1)
				{
					cost |= cnt[j];
					value += (double)val[j] / dis[j];
				}
			if((int)cost.count() <= q && ans < value)
				ans = value;
		}
		printf("%.10f\n", ans);
	}
	return 0;
}
Ejemplo n.º 6
0
 void printFlags(std::ostream &out, std::bitset<N> const &flags) {
     std::size_t count = flags.count();
     if (count == 0) {
         out << "none";
     } else {
         std::size_t j = 0;
         for (std::size_t i = 0; i < N; ++i) {
             if (flags.test(i)) {
                 if (count == 2 && j == count - 1) {
                     out << " and ";
                 } else if (count >= 3 && j >= 1 && j < count - 1) {
                     out << ", ";
                 } else if (count >= 3 && j == count - 1) {
                     // Serial comma.
                     out << ", and ";
                 }
                 out << T(i);
                 ++j;
             }
         }
     }
 }