Changeset 1049 for trunk/yat


Ignore:
Timestamp:
Feb 7, 2008, 3:50:38 PM (14 years ago)
Author:
Peter
Message:

replaced some cerr outputs with exception throws - refs #189

Location:
trunk/yat
Files:
4 edited

Legend:

Unmodified
Added
Removed
  • trunk/yat/classifier/SVM.cc

    r1042 r1049  
    3737#include <cmath>
    3838#include <limits>
     39#include <sstream>
    3940#include <stdexcept>
    4041#include <utility>
     
    288289    }
    289290    calculate_margin();
    290     trained_ = calculate_bias();
     291    calculate_bias();
     292    trained_ = true;
    291293  }
    292294
     
    391393  }
    392394 
    393   bool SVM::calculate_bias(void)
     395  void SVM::calculate_bias(void)
    394396  {
    395397
     
    402404
    403405    if (!sample_.nof_sv()){
    404       std::cerr << "SVM::train() error: "
    405                 << "Cannot calculate bias because there is no support vector"
    406                 << std::endl;
    407       return false;
     406      std::stringstream ss;
     407      ss << "yat::classifier::SVM::train() error: "
     408         << "Cannot calculate bias because there is no support vector";
     409      throw std::runtime_error(ss.str());
    408410    }
    409411
     
    416418    for (size_t i=0; i<output_.size(); i++)
    417419      output_(i) += bias_;
    418      
    419     return true;
    420420  }
    421421
  • trunk/yat/classifier/SVM.h

    r1042 r1049  
    208208    /// @return true if successful
    209209    ///
    210     bool calculate_bias(void);
     210    void calculate_bias(void);
    211211
    212212    ///
  • trunk/yat/regression/Local.cc

    r1015 r1049  
    3232#include <cassert>
    3333#include <iostream>
     34#include <sstream>
     35#include <stdexcept>
    3436
    3537namespace theplu {
     
    5355  void Local::fit(const size_t step_size, const size_t nof_points)
    5456  {
    55     if (step_size==0 || nof_points<3){
    56       std::cerr << "yat::regression::Local "
    57                 << "Parameters invalid. Fitting ignored." << std::endl;
    58       return;
     57    if (step_size==0){
     58      std::stringstream ss;
     59      ss << "yat::regression::local: step_size must be larger than zero.";
     60      throw std::runtime_error(ss.str());
     61    }
     62    if (nof_points<3){
     63      std::stringstream ss;
     64      ss << "yat::regression::local: too few data points. "
     65         << "At least 3 data points are needed to perform fitting.";
     66      throw std::runtime_error(ss.str());
    5967    }
    6068
  • trunk/yat/statistics/PearsonCorrelation.cc

    r1024 r1049  
    5050  double PearsonCorrelation::p_value_one_sided() const
    5151  {
    52     if(nof_samples_<2){
    53       std::cerr << "Warning: Only " << nof_samples_ << "samples. "
    54                 << "Need at lest 3.\n";
     52    if(nof_samples_<=2)
    5553      return 1;
    56     }
    5754
    5855    double t = sqrt(nof_samples_ - 2)*fabs(r_) /sqrt(1-r_*r_);
Note: See TracChangeset for help on using the changeset viewer.