Beispiel #1
0
FuzzyIndices::CampelloIndices::CampelloIndices(FuzzyIndices& outer) :
		outer(outer) {
	std::shared_ptr<std::vector<int>> elements = outer.elements();
	a = compute_a(*elements.get());
	b = compute_b(*elements.get());
	c = compute_c(*elements.get());
	d = compute_d(*elements.get());
}
CNDCGRankLoss::CNDCGRankLoss(CModel* &model, CVecData* &data)
  : CRankLoss(model, data) 
{
  truncation = 10;
  // do nothing serious here at the moment...                       
  std::cout << "In CNDCGRankLoss!" << std::endl;
  int num_query = _data->NumOfSubset();
  Scalar *Y_array = _data->labels().Data();
  max_subset_size = 0;
  for (int q=0;q<num_query;q++){
    int offset = _data->subset[q].startIndex;
    int subsetsize = _data->subset[q].size;
    if (max_subset_size < subsetsize){
      max_subset_size = subsetsize;
    }
    int length = subsetsize;
    vector<int> indices(length);
    iota(indices.begin(), indices.end(), 0);
    indirect_greater_than<Scalar> igt(&(Y_array[offset]));
    //indirect_less_than<Scalar> igt(&(Y_array[offset]));
    sort(indices.begin(), indices.end(),igt);
    sort_vectors.push_back(indices);

    // use this to compute bs
    vector<double> b;
    compute_b(offset, subsetsize, Y_array, indices, b);
    bs.push_back( b );
  }
  // use largest query information to compute c_i
  for (int i=0;i<max_subset_size;i++){
    //c.push_back( 1.0/pow((i+1.0),1.4) );
    c.push_back( max(truncation+1-i,0) );
  }
  pi = (int *) malloc(sizeof(int)*max_subset_size);
  compute_a(max_subset_size, a); 
  //cout << "finished init\n";
  //cout << "max_subset_size " << max_subset_size <<" \n";
  //cout << "a.size " << a.size() <<" \n";
  //cout << "c.size " << c.size() <<" \n";

}
Beispiel #3
0
void SMO::optimize()
{
  
  int iter = 0;
  int counter = min(data->size(), 1000);

  while (1) {

    if (--counter == 0) {
      counter = min(data->size(), 1000);
      if (shrinking) shrink();
      cout << ".";
    }
    int i,j;
    bool kktViolation = selectWorkingSet(i, j);
    //cout << "kktViolation " << kktViolation << endl;
    //cout << "indices " << i << " " << j << endl;
    if (!kktViolation) { // && !shrinking) {
      break;
    }
    else if (!kktViolation) {
      reconstructGradient();
      for (int k=0; k < size(); k++)
	//activeSet.insert(k);
      cout << "*";
      kktViolation = selectWorkingSet(i, j);
      if (!kktViolation) {
	break;
      }
    }
    ++iter;
    
    update(i, j);
  }

  b = compute_b();
}
Beispiel #4
0
/* y = ax^b + c 
 * 	return 0 if success, -1 otherwise
 * 	if success, a, b and c are modified
 * */
int _starpu_regression_non_linear_power(struct starpu_history_list_t *ptr, double *a, double *b, double *c)
{
	unsigned n = find_list_size(ptr);

	unsigned *x = malloc(n*sizeof(unsigned));
	STARPU_ASSERT(x);

	double *y = malloc(n*sizeof(double));
	STARPU_ASSERT(y);

	dump_list(x, y, ptr);

	double cmin = 0.0;
	double cmax = find_list_min(y, n);
	
	unsigned iter;

	double err = 100000.0;

	for (iter = 0; iter < MAXREGITER; iter++)
	{
		double c1, c2;
		double r1, r2;
		
		double radius = 0.01;

		c1 = cmin + (0.5-radius)*(cmax - cmin);
		c2 = cmin + (0.5+radius)*(cmax - cmin);

		r1 = test_r(c1, n, x, y);
		r2 = test_r(c2, n, x, y);

		double err1, err2;
		err1 = fabs(1.0 - r1);
		err2 = fabs(1.0 - r2);

		if (err1 < err2)
		{
			cmax = (cmin + cmax)/2;
		}
		else {
			/* 2 is better */
			cmin = (cmin + cmax)/2;
		}

		if (fabs(err - STARPU_MIN(err1, err2)) < EPS)
		{
			err = STARPU_MIN(err1, err2);
			break;
		}

		err = STARPU_MIN(err1, err2);
	}

	*c = (cmin + cmax)/2;

	*b = compute_b(*c, n, x, y); 
	*a = exp(compute_a(*c, *b, n, x, y));

	free(x);
	free(y);

	return 0;
}