def rescale_max_check_test(mat): """ Checks if a matrix has only ones as maxes after being rescaled twice. """ maxes1, rescaled1 = f.rescale(mat) maxes2, rescaled2 = f.rescale(rescaled1) return np.all(maxes2 == np.ones(maxes2.shape))
def rescale_data_check_test(mat): """ Checks if a matrix matches its original version after being rescaled and re-multiplied with its maximum values. Be aware that numerical errors can cause the test to not pass, which is why the difference is rounded. """ maxes, rescaled = f.rescale(mat) orig = f.reverse_rescale(maxes, rescaled) diff = np.round(mat - orig, 10) return np.all(diff == 0.)
def get_value(self, onset): elapsed = (float(onset) + self.shift) % self.length if self.interp == 'linear': val = float(linear(elapsed / self.length, self.arr)) elif self.interp == 'nearest': val = float(nearest(elapsed / self.length, self.arr)) if self.bounds: ymin, ymax = self.bounds s, y, n = rescale(self.arr, ymin, ymax) val = (val - y) * s + n inv_qnt = 1.0 / self.quantize val = floor(val * inv_qnt) / inv_qnt return val
import functions as f import matplotlib.pyplot as plt import numpy as np import time as t t0 = t.clock() kplr_id = '008191672' kplr_file = 'kplr008191672-2013011073258_llc.fits' jdadj, obsobject, lightdata = f.openfile(kplr_id, kplr_file) time, flux, flux_err = f.fix_data(lightdata) flux, variance = f.rescale(flux, flux_err) time -= np.median(time) depth = 0.00650010001 width = 0.177046694669 period_interval = np.arange(2.00, 8.0, 0.01) offset_intervals = np.arange(0.00, 7.2, 0.01) #Change to numpy arrays to optimize. # z = [[f.sum_chi_squared(flux, f.box(p,o,depth,width,time),variance) for o in offset_intervals] # for p in period_interval] z = [] for p in period_interval: line = [] for o in offset_intervals: if o < p: line.append(f.sum_chi_squared(flux, f.box(p,o,depth,width,time), variance))
import functions as f import matplotlib.pyplot as plt import numpy as np import time as t t0 = t.clock() kplr_id = '008191672' kplr_file = 'kplr008191672-2013011073258_llc.fits' jdadj, obsobject, lightdata = f.openfile(kplr_id, kplr_file) time, flux, flux_err = f.fix_data(lightdata) flux, variance = f.rescale(flux, flux_err) time -= np.median(time) depth = 0.00650010001 width = 0.177046694669 period_interval = np.arange(2.00, 8.0, 0.01) offset_intervals = np.arange(0.00, 7.2, 0.01) #Change to numpy arrays to optimize. # z = [[f.sum_chi_squared(flux, f.box(p,o,depth,width,time),variance) for o in offset_intervals] # for p in period_interval] z = [] for p in period_interval: line = [] for o in offset_intervals: if o < p: line.append(
(8.2, 87000, 0), (4.8, 73000, 0), (2.2, 42000, 1), (9.1, 98000, 0), (6.5, 84000, 0), (6.9, 73000, 0), (5.1, 72000, 0), (9.1, 69000, 1), (9.8, 79000, 1), ] data = map(list, data) # change tuples to lists x = [[1] + row[:2] for row in data] # each element is [1, experience, salary] y = [row[2] for row in data] # each element is paid_account rescaled_x = fnc.rescale(x) beta = estimate_beta(rescaled_x, y) predictions = [predict(x_i, beta) for x_i in rescaled_x] """plt.scatter(predictions, y) plt.xlabel("predicted") plt.ylabel("actual") plt.show()""" def split_data(data, prob): """split data into fractions [prob, 1 - prob]""" results = [], [] for row in data: results[0 if random.random() < prob else 1].append(row) return results
def rescale_max_check_test_2(mat): """ Similar to before, checks that maximum value of a matrix after rescaling is exactly 1. """ maxes, rescaled = f.rescale(mat) return np.max(np.abs(rescaled)) == 1.