Exemplo n.º 1
0
bool svg_attribute_points::read (const char *data, bool /* from_css */)
{
  m_point_list.clear ();
  double x, y;
  while (*data)
    {
      // Actually error or warning should be printed in case of odd number of coordinates
      CHECK_RET (str_to_double (data, x), true);
      CHECK_RET (str_to_double (data, y), true);
      m_point_list.push_back (QPointF (x, y));
    }
  return true;
}
Exemplo n.º 2
0
/* PUBLIC */
BOOL term_to_double(Term t, double *result)
{
  if (CONSTANT(t))
    return str_to_double(sn_to_str(SYMNUM(t)), result); 
  else
    return FALSE;
}  /* term_to_double */
Exemplo n.º 3
0
static int get_single_data(struct pe_elem *elm, FILE *elemdb)
{
	int err = 0;
	char tmp[64] = {0};

	err = walk_to_elem(elm->sname, elemdb);
	if (err)
		return err;

	err = confirm_seperator(elemdb);
	if (err)
		return err;

	/* Read the weigth of the element */
	fscanf(elemdb, "%[^;]", tmp);
	elm->weight = str_to_double(tmp);

	err = confirm_seperator(elemdb);
	if (err){
		return err;
	}
	/* Read the full name of the element */
	fscanf(elemdb, "%[^;]", elm->lname);

	return 0;
}
Exemplo n.º 4
0
Daemon::Explose*	Daemon::Explose::unserialize(std::stringstream &s, GameObject *owner)
{
  std::stringstream ss;

  ss << this->unPack(s);
  return (new Explose(owner, str_to_double(this->getData(ss)), str_to_int(this->getData(ss)), str_to_int(this->getData(ss))));
}
Exemplo n.º 5
0
bool svg_attribute_offset::read (const char *data, bool /*from_css*/)
{
  CHECK (str_to_double (data, m_offset));
  trim_whitespace_left (data);
  if (*data == '%')
    m_offset *= 0.01;

  if (m_offset < 0.0)
    m_offset = 0.0;
  else if (m_offset > 1.0)
    m_offset = 1.0;

  return true;
}
Exemplo n.º 6
0
int main(int argc, char *argv[]) {
  char *program_name = argv[0];
  double l2_sigma_sq = 0.0;
  int grafting = 0;
  int grafting_light = 0;

  lbfgs_parameter_t params;
  lbfgs_parameter_init(&params);
  params.past = 1;
  params.delta = 1e-7;

  int ch;
  while ((ch = getopt_long(argc, argv, "", longopts, NULL)) != -1) {
    switch (ch) {
    case OPTION_FTOL:
      params.ftol = str_to_double(optarg);
      break;
    case OPTION_GTOL:
      params.gtol = str_to_double(optarg);
      break;
    case OPTION_GRAFTING:
      grafting = str_to_int(optarg);
      break;
    case OPTION_GRAFTING_LIGHT:
      grafting_light = str_to_int(optarg);
      break;
    case OPTION_L1:
      params.orthantwise_c = str_to_double(optarg);
      break;
    case OPTION_L2:
      l2_sigma_sq = str_to_double(optarg);
      break;
    case OPTION_LINESEARCH:
      if (strcmp(optarg, "armijo") == 0)
        params.linesearch = LBFGS_LINESEARCH_BACKTRACKING_ARMIJO;
      else if (strcmp(optarg, "backtracking") == 0)
        params.linesearch = LBFGS_LINESEARCH_BACKTRACKING;
      else if (strcmp(optarg, "wolfe") == 0)
        params.linesearch = LBFGS_LINESEARCH_BACKTRACKING_WOLFE;
      else if (strcmp(optarg, "strong_wolfe") == 0)
        params.linesearch = LBFGS_LINESEARCH_BACKTRACKING_STRONG_WOLFE;
      else {
        usage(program_name);
        return 1;
      }
      break;
    case OPTION_MINSTEP:
      fprintf(stderr,"backtracking\n");
      params.min_step = str_to_double(optarg);
      break;
    case OPTION_MAXSTEP:
      params.max_step = str_to_double(optarg);
      break;
    case '?':
    default:
      usage(program_name);
      return 1;
    }
  }

  argc -= optind;
  argv += optind;

  if (argc != 0 && argc != 1) {
    usage(program_name);
    return 1;
  }

  if (grafting && grafting_light) {
    fprintf(stderr, "Grafting and grafting-light cannot be used simultaneously...");
    return 1;
  }

  if ((grafting || grafting_light) && params.orthantwise_c == 0.) {
    fprintf(stderr, "Grafting requires a l1 norm coefficient...");
    return 1;
  }

  fprintf(stderr, "l1 norm coefficient: %.4e\n", params.orthantwise_c); 
  fprintf(stderr, "l2 prior sigma^2: %.4e\n\n", l2_sigma_sq);

  dataset_t ds;
  
  int fd = 0;
  if (argc == 1 && (fd = open(argv[0], O_RDONLY)) == -1) {
    fprintf(stderr, "Could not open %s\n", argv[0]);
    return 1;
  }

  int r = read_tadm_dataset(fd, &ds);

  if (r != TADM_OK) {
    fprintf(stderr, "Error reading data...\n");
    return 1;
  }
  
  fprintf(stderr, "Features: %zu\n", ds.n_features);
  fprintf(stderr, "Contexts: %zu\n\n", ds.n_contexts);

  if (params.orthantwise_c != 0.0) {
    params.orthantwise_end = ds.n_features;
    // l1 prior only works with backtracking linesearch.
    params.linesearch = LBFGS_LINESEARCH_BACKTRACKING;
  }

  model_t model;
  if (grafting || grafting_light)
    model_new(&model, ds.n_features, true);
  else
    model_new(&model, ds.n_features, false);

  fprintf(stderr, "Iter\t-LL\t\txnorm\t\tgnorm\n\n");

  if (grafting)
    r = maxent_lbfgs_grafting(&ds, &model, &params, l2_sigma_sq, grafting);
  else if (grafting_light)
    r = maxent_lbfgs_grafting_light(&ds, &model, &params, l2_sigma_sq,
        grafting_light);
  else
    r = maxent_lbfgs_optimize(&ds, &model, &params, l2_sigma_sq);

  dataset_free(&ds);

  if (r != LBFGS_STOP && r != LBFGS_SUCCESS && r != LBFGS_ALREADY_MINIMIZED) {
    fprintf(stderr, "%s\n\n", err_to_string(lbfgs_errs, r));
    model_free(&model);
    return 1;
  }

  for (int i = 0; i < ds.n_features; ++i)
    printf("%.8f\n", model.params[i]);

  model_free(&model);

  return 0;
}
Exemplo n.º 7
0
Arquivo: str.c Projeto: Distrotech/nut
int	str_is_double(const char *string, const int base)
{
	double	number;

	return str_to_double(string, &number, base);
}