Example #1
0
 def _train(self, max_itr, callback=None):
     """
     """
     # Check for zero mean and unit variance
     means = np.mean(self.X, axis=0)
     for m in means:
         if np.abs(m) > self.mean_tol:
             raise Exception( \
                 "The samples in X should have a zero mean. That is every column in X" +
                 " should have a zero mean. You can disable this check in the class" +
                 " constructor using mean_tol=inf. Means where found to be: " +
                 str(np.mean(self.X, axis=0)) )
     #np.seterr(invalid='raise')
     self.remember_lh = True
     self._itr = 0
     X0 = np.atleast_2d((self.GP.cf.get_params()))
     X0 = X0.flatten()
     minimize(X0, self.f, self.df, max_itr, callback=callback)
     #print "X0=", X0
     #scipy.optimize.fmin_cg(self.f, X0, disp=True, maxiter=max_itr, fprime=self.df, callback=callback)
     #scipy.optimize.fmin_bfgs(self.f, X0, fprime=self.df)
     #scipy.optimize.fmin_ncg(self.f, X0, fprime=self.df)
     self.GP.cf.clear_temp()
     self.remember_lh = False
     self.old_lh_res = None
Example #2
0
 def _train(self, max_itr, callback=None):
     """
     """
     # Check for zero mean and unit variance
     means = np.mean(self.X, axis=0)
     for m in means:
         if np.abs(m) > self.mean_tol:
             raise Exception( \
                 "The samples in X should have a zero mean. That is every column in X" +
                 " should have a zero mean. You can disable this check in the class" +
                 " constructor using mean_tol=inf. Means where found to be: " +
                 str(np.mean(self.X, axis=0)) )
     #np.seterr(invalid='raise')
     self.remember_lh = True
     self._itr = 0
     X0 = np.atleast_2d((self.GP.cf.get_params()))
     X0 = X0.flatten()
     minimize(X0, self.f, self.df, max_itr, callback=callback)
     #print "X0=", X0
     #scipy.optimize.fmin_cg(self.f, X0, disp=True, maxiter=max_itr, fprime=self.df, callback=callback)
     #scipy.optimize.fmin_bfgs(self.f, X0, fprime=self.df)
     #scipy.optimize.fmin_ncg(self.f, X0, fprime=self.df)
     self.GP.cf.clear_temp()
     self.remember_lh = False
     self.old_lh_res = None
Example #3
0
    'starboardrudder': 7,
    'heeling': 8,
    'draft': 9
}

targetCol = [1]
inputCol = [0, 2, 3, 4, 5, 6, 7, 8, 9]
T = D[:, targetCol]
X = D[:, inputCol]

# Normalize:
normX = preproc.Normalizer(X)
normT = preproc.Normalizer(T)
Xn = normX.transform(X)
Tn = normT.transform(T)

# Setup model:
nn = ann.WeightDecayANN([len(inputCol), 2, 1])
nn.v = 0.1  # Weight decay, just a guess, should actually be found
dm = ModelWithData(nn, Xn, Tn)

# Train model:
err = opt.minimize(dm.get_parameters(), dm.err_func, dm.err_func_d, 10)

# Wrap model for easy use:
ev = wrap_model(X, (normX.transform, nn.forward, normT.invtransform), **names)

print "ev(X) =", ev(X)
print "ev(waterspeed=20) =", ev(waterspeed=20)
print "ev(X, waterspeed=20) =", ev(X, waterspeed=20)
Example #4
0
D = np.loadtxt('data/shipfuel.csv.gz', skiprows=1, delimiter=',')
names = {'waterspeed':0, 'fuel':1, 'trim':2, 'windspeed':3, 'windangle':4,
        'pitch':5, 'portrudder':6, 'starboardrudder':7, 'heeling':8,
        'draft':9 }

targetCol = [1]; inputCol = [0, 2, 3, 4, 5, 6, 7, 8, 9]
T = D[:, targetCol]
X = D[:, inputCol]

# Normalize:
normX = preproc.Normalizer(X)
normT = preproc.Normalizer(T)
Xn = normX.transform(X)
Tn = normT.transform(T)

# Setup model:
nn = ann.WeightDecayANN([len(inputCol), 2, 1])
nn.v = 0.1 # Weight decay, just a guess, should actually be found
dm = ModelWithData(nn, Xn, Tn)

# Train model:
err = opt.minimize(dm.get_parameters(), dm.err_func, dm.err_func_d, 10)

# Wrap model for easy use:
ev = wrap_model(X, (normX.transform, nn.forward, normT.invtransform), **names)

print "ev(X) =", ev(X)
print "ev(waterspeed=20) =", ev(waterspeed=20)
print "ev(X, waterspeed=20) =", ev(X, waterspeed=20)