From: Francois Fleuret Date: Mon, 13 Oct 2008 09:56:47 +0000 (+0200) Subject: automatic commit X-Git-Url: https://fleuret.org/cgi-bin/gitweb/gitweb.cgi?a=commitdiff_plain;h=71a84ea2658cd96726bcf4e582010c24bf2583cf;p=folded-ctf.git automatic commit --- diff --git a/global.cc b/global.cc index bbefd21..76543f8 100644 --- a/global.cc +++ b/global.cc @@ -135,8 +135,6 @@ void Global::read_parser(ParamParser *parser) { char *l = parser->get_association("loss-type"); if(strcmp(l, "exponential") == 0) loss_type = LOSS_EXPONENTIAL; - else if(strcmp(l, "ev-regularized") == 0) - loss_type = LOSS_EV_REGULARIZED; else if(strcmp(l, "hinge") == 0) loss_type = LOSS_HINGE; else if(strcmp(l, "logistic") == 0) diff --git a/loss_machine.cc b/loss_machine.cc index 63a65cc..fd1d07b 100644 --- a/loss_machine.cc +++ b/loss_machine.cc @@ -84,40 +84,6 @@ scalar_t LossMachine::loss(SampleSet *samples, scalar_t *responses) { } break; - case LOSS_EV_REGULARIZED: - { - scalar_t sum_pos = 0, sum_sq_pos = 0, nb_pos = 0, m_pos, v_pos; - scalar_t sum_neg = 0, sum_sq_neg = 0, nb_neg = 0, m_neg, v_neg; - - for(int n = 0; n < samples->nb_samples(); n++) { - if(samples->label(n) > 0) { - sum_pos += responses[n]; - sum_sq_pos += sq(responses[n]); - nb_pos += 1.0; - } else if(samples->label(n) < 0) { - sum_neg += responses[n]; - sum_sq_neg += sq(responses[n]); - nb_neg += 1.0; - } - } - - l = 0; - - if(nb_pos > 0) { - m_pos = sum_pos / nb_pos; - v_pos = sum_sq_pos/(nb_pos - 1) - sq(sum_pos)/(nb_pos * (nb_pos - 1)); - l += nb_pos * exp(v_pos/2 - m_pos); - } - - if(nb_neg > 0) { - m_neg = sum_neg / nb_neg; - v_neg = sum_sq_neg/(nb_neg - 1) - sq(sum_neg)/(nb_neg * (nb_neg - 1)); - l += nb_neg * exp(v_neg/2 + m_neg); - } - - } - break; - case LOSS_HINGE: { for(int n = 0; n < samples->nb_samples(); n++) { @@ -161,6 +127,7 @@ scalar_t LossMachine::optimal_weight(SampleSet *sample_set, case LOSS_EXPONENTIAL: { scalar_t num = 0, den = 0, z; + for(int n = 0; n < sample_set->nb_samples(); n++) { z = sample_set->label(n) * weak_learner_responses[n]; if(z > 0) { @@ -174,103 +141,6 @@ scalar_t LossMachine::optimal_weight(SampleSet *sample_set, } break; - case LOSS_EV_REGULARIZED: - { - - scalar_t u = 0, du = -0.1; - scalar_t *responses = new scalar_t[sample_set->nb_samples()]; - - scalar_t l, prev_l = -1; - - const scalar_t minimum_delta_for_optimization = 1e-5; - - scalar_t shift = 0; - - { - scalar_t sum_pos = 0, sum_sq_pos = 0, nb_pos = 0, m_pos, v_pos; - scalar_t sum_neg = 0, sum_sq_neg = 0, nb_neg = 0, m_neg, v_neg; - - for(int n = 0; n < sample_set->nb_samples(); n++) { - if(sample_set->label(n) > 0) { - sum_pos += responses[n]; - sum_sq_pos += sq(responses[n]); - nb_pos += 1.0; - } else if(sample_set->label(n) < 0) { - sum_neg += responses[n]; - sum_sq_neg += sq(responses[n]); - nb_neg += 1.0; - } - } - - if(nb_pos > 0) { - m_pos = sum_pos / nb_pos; - v_pos = sum_sq_pos/(nb_pos - 1) - sq(sum_pos)/(nb_pos * (nb_pos - 1)); - shift = max(shift, v_pos/2 - m_pos); - } - - if(nb_neg > 0) { - m_neg = sum_neg / nb_neg; - v_neg = sum_sq_neg/(nb_neg - 1) - sq(sum_neg)/(nb_neg * (nb_neg - 1)); - shift = max(shift, v_neg/2 + m_neg); - } - -// (*global.log_stream) << "nb_pos = " << nb_pos << " nb_neg = " << nb_neg << endl; - - } - - int nb = 0; - - while(nb < 100 && abs(du) > minimum_delta_for_optimization) { - nb++; - -// (*global.log_stream) << "l = " << l << " u = " << u << " du = " << du << endl; - - u += du; - for(int s = 0; s < sample_set->nb_samples(); s++) { - responses[s] = current_responses[s] + u * weak_learner_responses[s] ; - } - - { - scalar_t sum_pos = 0, sum_sq_pos = 0, nb_pos = 0, m_pos, v_pos; - scalar_t sum_neg = 0, sum_sq_neg = 0, nb_neg = 0, m_neg, v_neg; - - for(int n = 0; n < sample_set->nb_samples(); n++) { - if(sample_set->label(n) > 0) { - sum_pos += responses[n]; - sum_sq_pos += sq(responses[n]); - nb_pos += 1.0; - } else if(sample_set->label(n) < 0) { - sum_neg += responses[n]; - sum_sq_neg += sq(responses[n]); - nb_neg += 1.0; - } - } - - l = 0; - - if(nb_pos > 0) { - m_pos = sum_pos / nb_pos; - v_pos = sum_sq_pos/(nb_pos - 1) - sq(sum_pos)/(nb_pos * (nb_pos - 1)); - l += nb_pos * exp(v_pos/2 - m_pos - shift); - } - - if(nb_neg > 0) { - m_neg = sum_neg / nb_neg; - v_neg = sum_sq_neg/(nb_neg - 1) - sq(sum_neg)/(nb_neg * (nb_neg - 1)); - l += nb_neg * exp(v_neg/2 + m_neg - shift); - } - - } - - if(l > prev_l) du = du * -0.25; - prev_l = l; - } - - delete[] responses; - - return u; - } - case LOSS_HINGE: case LOSS_LOGISTIC: { @@ -349,8 +219,6 @@ void LossMachine::subsample(int nb, scalar_t *labels, scalar_t *responses, } } while(nb_sampled < nb_to_sample); - (*global.log_stream) << "nb_sampled = " << nb_sampled << " nb_to_sample = " << nb_to_sample << endl; - (*global.log_stream) << "Done." << endl; delete[] sampled_indexes; diff --git a/rgb_image.cc b/rgb_image.cc index c343f47..cc40615 100644 --- a/rgb_image.cc +++ b/rgb_image.cc @@ -91,99 +91,6 @@ RGBImage::~RGBImage() { deallocate(); } -void RGBImage::write_ppm(const char *filename) { - FILE *outfile; - - if ((outfile = fopen (filename, "wb")) == 0) { - fprintf (stderr, "Can't open %s for reading\n", filename); - exit(1); - } - - fprintf(outfile, "P6\n%d %d\n255\n", _width, _height); - - char *raw = new char[_width * _height * 3]; - - int k = 0; - for(int y = 0; y < _height; y++) for(int x = 0; x < _width; x++) { - raw[k++] = _bit_map[x + _width * (y + _height * RED)]; - raw[k++] = _bit_map[x + _width * (y + _height * GREEN)]; - raw[k++] = _bit_map[x + _width * (y + _height * BLUE)]; - } - - fwrite((void *) raw, sizeof(unsigned char), _width * _height * 3, outfile); - fclose(outfile); - - delete[] raw; -} - -void RGBImage::read_ppm(const char *filename) { - const int buffer_size = 1024; - FILE *infile; - char buffer[buffer_size]; - int max; - - deallocate(); - - if((infile = fopen (filename, "r")) == 0) { - fprintf (stderr, "Can't open %s for reading\n", filename); - exit(1); - } - - fgets(buffer, buffer_size, infile); - - if(strncmp(buffer, "P6", 2) == 0) { - - do { - fgets(buffer, buffer_size, infile); - } while((buffer[0] < '0') || (buffer[0] > '9')); - sscanf(buffer, "%d %d", &_width, &_height); - fgets(buffer, buffer_size, infile); - sscanf(buffer, "%d", &max); - - allocate(); - - unsigned char *raw = new unsigned char[_width * _height * RGB_DEPTH]; - fread(raw, sizeof(unsigned char), _width * _height * RGB_DEPTH, infile); - - int k = 0; - for(int y = 0; y < _height; y++) for(int x = 0; x < _width; x++) { - _bit_plans[RED][y][x] = raw[k++]; - _bit_plans[GREEN][y][x] = raw[k++]; - _bit_plans[BLUE][y][x] = raw[k++]; - } - - delete[] raw; - - } else if(strncmp(buffer, "P5", 2) == 0) { - - do { - fgets(buffer, buffer_size, infile); - } while((buffer[0] < '0') || (buffer[0] > '9')); - sscanf(buffer, "%d %d", &_width, &_height); - fgets(buffer, buffer_size, infile); - sscanf(buffer, "%d", &max); - - allocate(); - - unsigned char *pixbuf = new unsigned char[_width * _height]; - fread(buffer, sizeof(unsigned char), _width * _height, infile); - - int k = 0, l = 0; - for(int y = 0; y < _height; y++) for(int x = 0; x < _width; x++) { - unsigned char c = pixbuf[k++]; - _bit_map[l++] = c; - _bit_map[l++] = c; - _bit_map[l++] = c; - } - - delete[] pixbuf; - - } else { - cerr << "Can not read ppm of type [" << buffer << "] from " << filename << ".\n"; - exit(1); - } -} - void RGBImage::read_png(const char *name) { // This is the number of bytes the read_png routine will read to // decide if the file is a PNG or not. According to the png diff --git a/rgb_image.h b/rgb_image.h index 5c886a9..235931e 100644 --- a/rgb_image.h +++ b/rgb_image.h @@ -64,9 +64,6 @@ public: return _bit_plans[d][y][x]; } - virtual void read_ppm(const char *filename); - virtual void write_ppm(const char *filename); - virtual void read_png(const char *filename); virtual void write_png(const char *filename); diff --git a/rgb_image_subpixel.cc b/rgb_image_subpixel.cc index 958d748..7b65504 100644 --- a/rgb_image_subpixel.cc +++ b/rgb_image_subpixel.cc @@ -35,15 +35,6 @@ RGBImageSubpixel::RGBImageSubpixel(RGBImage *image) : RGBImage(image->width() * RGBImageSubpixel::~RGBImageSubpixel() { } -void RGBImageSubpixel::read_ppm(const char *filename) { - abort(); -} - -void RGBImageSubpixel::write_ppm(const char *filename) { - abort(); -} - - void RGBImageSubpixel::read_png(const char *filename) { abort(); } diff --git a/rgb_image_subpixel.h b/rgb_image_subpixel.h index 931fa7c..55618c6 100644 --- a/rgb_image_subpixel.h +++ b/rgb_image_subpixel.h @@ -42,9 +42,6 @@ public: inline int width() const { return _width / _scale; } inline int height() const { return _height / _scale; } - virtual void read_ppm(const char *filename); - virtual void write_ppm(const char *filename); - virtual void read_png(const char *filename); virtual void write_png(const char *filename);