Changeset 10953:a3b2254b1843 in orange


Ignore:
Timestamp:
07/18/12 16:39:01 (21 months ago)
Author:
Ales Erjavec <ales.erjavec@…>
Branch:
default
Message:

Check for non-finite values in the data.

The earth C code calls 'exit()' if they are present in the data (fixes #1213).

File:
1 edited

Legend:

Unmodified
Added
Removed
  • Orange/regression/earth.py

    r10907 r10953  
    223223            raise ValueError("Class variable expected.") 
    224224 
     225        # check for non-finite values in y. 
     226        if not numpy.isfinite(y).all(): 
     227            raise ValueError("Non-finite values present in Y") 
     228 
     229        # mask non-finite values in x. 
     230        x = numpy.ma.masked_invalid(x, copy=False) 
     231 
    225232        if self.scale_resp and y.shape[1] == 1: 
    226             sy = y - numpy.mean(y, axis=0) 
    227             sy = sy / numpy.std(sy, axis=0) 
     233            sy = y - numpy.ma.mean(y, axis=0) 
     234            sy = sy / numpy.ma.std(sy, axis=0) 
    228235        else: 
    229236            sy = y 
     237 
     238        # replace masked values with means. 
     239        if numpy.ma.is_masked(sy): 
     240            mean_sy = numpy.ma.mean(sy, axis=0) 
     241            sy = numpy.where(sy.mask, mean_sy, sy) 
     242 
     243        if numpy.ma.is_masked(x): 
     244            mean_x = numpy.ma.mean(x, axis=0) 
     245            x = numpy.where(x.mask, mean_x, x) 
    230246 
    231247        terms = self.terms 
     
    708724    rval = _c_eval_subsets_xtx(subsets, rss_vec, cases, resp_count, var_count, 
    709725                        X, Y, weights) 
    710     if rval != 0: 
     726    if rval == 1: 
    711727        raise numpy.linalg.LinAlgError("Lin. dep. terms in X") 
     728    elif rval == 2: 
     729        raise Exception("Trying to prune the intercept.") 
     730    elif rval != 0: 
     731        raise Exception("Error %i" % rval) 
    712732 
    713733    subsets_ind = numpy.zeros((var_count, var_count), dtype=int) 
Note: See TracChangeset for help on using the changeset viewer.