<jupyter_start><jupyter_text>In this notebook, we replicate the setup from Brown+19 and apply PCA to the dataset as a simple feature extractor. We use a linear binary classifier to get a benchmark for the complexity classification task.<jupyter_code>import numpy
import matplotlib.pyplot as plt
import sys
sys.path.insert(1, '/home/alg010/ruby/coda/codes/')
import CodaPCA
freqs_hz = numpy.concatenate([
    numpy.arange(700e6, 1300e6, 1e6),
    numpy.arange(1500e6, 1800e6, 1e6)])
assert freqs_hz.shape == (900,)
c_mps = 299792458
wls_m2 = (c_mps / freqs_hz) ** 2<jupyter_output><empty_output><jupyter_text>$$    P(\lambda^2) = P_1 e^{2i(\chi_1 + \phi_1 \lambda^2)} + P_2 e^{2i(\chi_2 + \phi_2 \lambda^2)}$$<jupyter_code># Generate parameters for the Faraday spectra

numpy.random.seed(1)

N = 130000
size = (N, 1)
P1 = numpy.ones(size)
P2 = numpy.random.uniform(0, 1, size=size)
simple = numpy.random.randint(2, size=size, dtype=bool)
P2[simple] = 0
phi_1 = numpy.random.uniform(-50, 50, size=size)
phi_2 = numpy.random.uniform(-50, 50, size=size)
chi_1 = numpy.random.uniform(0, numpy.pi, size=size)
chi_2 = numpy.random.uniform(0, numpy.pi, size=size)
sigma = numpy.random.uniform(0, 0.333, size=size)
noise = (
    numpy.random.normal(
        scale=sigma, size=(N, len(wls_m2))) +
    numpy.random.normal(
        scale=sigma, size=(N, len(wls_m2))) * 1j)
# Then generate the spectra.
P = (
    P1 * numpy.exp(2j * (chi_1 + phi_1 * wls_m2)) +
    P2 * numpy.exp(2j * (chi_2 + phi_2 * wls_m2)))
# Finally, add noise to obtain the noisy spectra.
P_noisy = P + noise
plt.plot(wls_m2, P_noisy[2].real)
plt.plot(wls_m2, P_noisy[2].imag)
plt.plot(wls_m2, abs(P_noisy[2]), c='k')<jupyter_output><empty_output>
StarcoderdataJupyterStructuredCleanDedup