pspp-cvs
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[Pspp-cvs] pspp/src/math/linreg ChangeLog coefficient.c pr...


From: Jason H Stover
Subject: [Pspp-cvs] pspp/src/math/linreg ChangeLog coefficient.c pr...
Date: Fri, 07 Apr 2006 19:37:13 +0000

CVSROOT:        /sources/pspp
Module name:    pspp
Branch:         
Changes by:     Jason H Stover <address@hidden> 06/04/07 19:37:13

Modified files:
        src/math/linreg: ChangeLog coefficient.c predict.c linreg.h 

Log message:
        added residual computation; improved handling of bad input

CVSWeb URLs:
http://cvs.savannah.gnu.org/viewcvs/pspp/pspp/src/math/linreg/ChangeLog.diff?tr1=1.3&tr2=1.4&r1=text&r2=text
http://cvs.savannah.gnu.org/viewcvs/pspp/pspp/src/math/linreg/coefficient.c.diff?tr1=1.4&tr2=1.5&r1=text&r2=text
http://cvs.savannah.gnu.org/viewcvs/pspp/pspp/src/math/linreg/predict.c.diff?tr1=1.1&tr2=1.2&r1=text&r2=text
http://cvs.savannah.gnu.org/viewcvs/pspp/pspp/src/math/linreg/linreg.h.diff?tr1=1.2&tr2=1.3&r1=text&r2=text

Patches:
Index: pspp/src/math/linreg/ChangeLog
diff -u pspp/src/math/linreg/ChangeLog:1.3 pspp/src/math/linreg/ChangeLog:1.4
--- pspp/src/math/linreg/ChangeLog:1.3  Wed Apr  5 19:18:51 2006
+++ pspp/src/math/linreg/ChangeLog      Fri Apr  7 19:37:13 2006
@@ -1,3 +1,12 @@
+2006-04-07  Jason Stover  <address@hidden>
+
+       * predict.c (pspp_linreg_predict): Improved handling of null
+       pointer args.
+
+       * predict.c (pspp_linreg_residuals): New function.
+
+       * coefficient.c: Improved handling of null pointer args.
+
 2006-04-05  Jason Stover  <address@hidden>
 
        * predict.c: New file. pspp_linreg_predict() uses a linear model
Index: pspp/src/math/linreg/coefficient.c
diff -u pspp/src/math/linreg/coefficient.c:1.4 
pspp/src/math/linreg/coefficient.c:1.5
--- pspp/src/math/linreg/coefficient.c:1.4      Wed Apr  5 19:18:51 2006
+++ pspp/src/math/linreg/coefficient.c  Fri Apr  7 19:37:13 2006
@@ -105,7 +105,10 @@
 double
 pspp_linreg_coeff_get_est (const struct pspp_linreg_coeff *c)
 {
-  assert (c != NULL);
+  if (c == NULL)
+    {
+      return 0.0;
+    }
   return c->estimate;
 }
 /*
@@ -114,7 +117,10 @@
 double 
 pspp_linreg_coeff_get_std_err (const struct pspp_linreg_coeff *c)
 {
-  assert (c != NULL);
+  if (c == NULL)
+    {
+      return 0.0;
+    }
   return c->std_err;
 }
 /*
@@ -123,6 +129,10 @@
 int
 pspp_linreg_coeff_get_n_vars (struct pspp_linreg_coeff *c)
 {
+  if (c == NULL)
+    {
+      return 0;
+    }
   return c->n_vars;
 }
 
@@ -132,6 +142,10 @@
 const struct variable *
 pspp_linreg_coeff_get_var (struct pspp_linreg_coeff *c, int i)
 {
+  if (c == NULL)
+    {
+      return NULL;
+    }
   assert (i < c->n_vars);
   return (c->v_info + i)->v;
 }
@@ -146,6 +160,10 @@
   int i = 0;
   const struct variable *candidate;
 
+  if (c == NULL || v == NULL)
+    {
+      return NULL;
+    }
   while (i < c->n_vars)
     {
       candidate = pspp_linreg_coeff_get_var (c, i);
@@ -170,11 +188,10 @@
   struct pspp_linreg_coeff *result;
   const struct variable *tmp;
 
-  assert (c != NULL);
-  assert (c->coeff != NULL);
-  assert (c->n_indeps > 0);
-  assert (v != NULL);
-  assert (val != NULL);
+  if (c == NULL || c->coeff == NULL || c->n_indeps == NULL || v == NULL)
+    {
+      return NULL;
+    }
   
   result = c->coeff + i;
   tmp = pspp_linreg_coeff_get_var (result, 0);
@@ -192,7 +209,7 @@
     {
       return result;
     }
-  else
+  else if (val != NULL)
     {
       /*
        If v is categorical, we need to ensure the coefficient
@@ -211,5 +228,6 @@
        }
       return result;
     }
+  return NULL;
 }
 
Index: pspp/src/math/linreg/linreg.h
diff -u pspp/src/math/linreg/linreg.h:1.2 pspp/src/math/linreg/linreg.h:1.3
--- pspp/src/math/linreg/linreg.h:1.2   Wed Apr  5 19:18:51 2006
+++ pspp/src/math/linreg/linreg.h       Fri Apr  7 19:37:13 2006
@@ -22,7 +22,7 @@
 #ifndef LINREG_H
 #define LINREG_H
 
-
+#include <gsl/gsl_math.h>
 #include <gsl/gsl_vector.h>
 #include <gsl/gsl_matrix.h>
 
@@ -181,4 +181,7 @@
 double
 pspp_linreg_predict (const struct variable *, const union value *, 
                     const pspp_linreg_cache *, int);
+double
+pspp_linreg_residual (const struct variable *, const union value *,
+                     const union value *, const pspp_linreg_cache *, int);
 #endif
Index: pspp/src/math/linreg/predict.c
diff -u pspp/src/math/linreg/predict.c:1.1 pspp/src/math/linreg/predict.c:1.2
--- pspp/src/math/linreg/predict.c:1.1  Wed Apr  5 19:18:51 2006
+++ pspp/src/math/linreg/predict.c      Fri Apr  7 19:37:13 2006
@@ -38,10 +38,15 @@
   double result;
   double tmp;
   
-  assert (predictors != NULL);
-  assert (vals != NULL);
-  assert (c != NULL);
-
+  if (predictors == NULL || vals == NULL || c == NULL)
+    {
+      return GSL_NAN;
+    }
+  if (c->coeff == NULL)
+    {
+      /* The stupid model: just guess the mean. */
+      return c->depvar_mean;
+    }
   result = c->coeff->estimate; /* Intercept. */
 
   /*
@@ -60,3 +65,24 @@
     }
   return result;
 }
+
+double
+pspp_linreg_residual (const struct variable *predictors,
+                     const union value *vals,
+                     const union value *obs,
+                     const pspp_linreg_cache *c,
+                     int n_vals)
+{
+  double pred;
+  double result;
+
+  if (predictors == NULL || vals == NULL || c == NULL || obs == NULL)
+    {
+      return GSL_NAN;
+    }
+  
+  pred = pspp_linreg_predict (predictors, vals, c, n_vals);
+  
+  result = gsl_isnan (pred) ? GSL_NAN : (obs->f - pred);
+  return result;
+}




reply via email to

[Prev in Thread] Current Thread [Next in Thread]