def main(): specs = [u.make_specs(1) for i in range(N_SIGNALS)] makers = [s.Periodic(spec, noise=0.0) for spec in specs] # take data to be a list of tuples [... (nsr, error) ...] fft_data = [] lpsvd_data = [] noises = linspace(0.0, 1.0, N_NOISES) for nsr in noises: for spec,maker in zip(specs,makers): maker.noise = 0.0 amp = 2.0 * ( average([m**2 for m in maker.time_series(D_LENGTH)]) ) maker.noise = nsr seed = maker.time_series(D_LENGTH) fft_d = fft.fft(seed) fft_r = [c.real for c in fft.ifft(fft_d)] lpsvd_d = l.LPSVD(seed, count=2.0).decomposition() lpsvd_r = lpsvd_d.time_series(D_LENGTH) maker.noise = 0.0 clean = maker.time_series(D_LENGTH) fft_err = 1.0 * (u.mean_sq_error(clean,fft_r)) / amp lpsvd_err = 1.0 * (u.mean_sq_error(clean,lpsvd_r)) / amp fft_data.append((nsr, fft_err)) lpsvd_data.append((nsr, lpsvd_err)) for fd in fft_data: print str(fd[0])+"\t"+str(fd[1]) for ld in lpsvd_data: print str(ld[0])+"\t"+str(ld[1]) do_plot(fft_data, lpsvd_data) return None
def test_unequal_lengths(self): a = range(10) b = range(100) err = u.mean_sq_error(a,b) self.assertEqual(0, err)
def test_errors(self): a = [1,1,1] b = [1,2,3] err = u.mean_sq_error(a,b) expected = 5.0/3.0 self.assertEqual(err, expected)
def test_zero_error(self): a = range(10) b = a[:] err = u.mean_sq_error(a,b) self.assertEqual(0, err)