Exemple #1
0
def gen_vdata_poly(entry, npoly):

    data = entry.Data
    Rd = entry.Rdisk
    Rp = entry.Vb_peak_location

    z_sample = data.R
    z_fit = np.array([0.5, 1, 2, 0.5 * Rd, Rd, 2 * Rd, 0.5 * Rp, Rp, 2 * Rp])
    sample = data.V
    error = np.sqrt(data.e_V**2 + 2**2)

    V_spline = InterpolatedUnivariateSpline(z_sample, sample)
    V_spline_fit = V_spline(z_fit)

    n_poly = min(npoly, len(sample) - 2)
    clf = PolynomialRegression(n_poly)
    clf.fit(z_sample[:, None], sample, error)
    y_fit = clf.predict(z_fit[:, None])
    sample_fit = clf.predict(z_sample[:, None])

    z_fine = np.logspace(np.log10(data.R[0]), np.log10(data.R[-1]), 100)
    y_fine = clf.predict(z_fine[:, None])
    pos = np.argmax(y_fine)
    vmax = y_fine[pos]
    rmax = z_fine[pos]

    chi2_dof = (np.sum(
        ((sample_fit - sample) / error)**2) / (len(sample) - n_poly - 1))

    dy_pred = (clf.predict(z_fit[:, None] * 1.05) -
               clf.predict(z_fit[:, None] * 0.95)) / (z_fit * 0.1)

    ddy_pred = (clf.predict(z_fit[:, None] * 1.05) +
                clf.predict(z_fit[:, None] * 0.95) - 2 * y_fit) / (
                    (z_fit * 0.05)**2)

    s2 = sample_fit**2 - data.Gas**2 - entry.ML_maxbulge * data.Bulge**2 - min(
        entry.ML_maxdisk, 0.2) * data.Disk**2
    s2 = np.array([max(item, 0.0) for item in s2])
    Vdm_max = InterpolatedUnivariateSpline(z_sample, np.sqrt(s2))
    s2 = sample_fit**2 - data.Gas**2 - entry.ML_maxbulge * data.Bulge**2 - min(
        entry.ML_maxdisk, 0.4) * data.Disk**2
    s2 = np.array([max(item, 0.0) for item in s2])
    Vdm_med = InterpolatedUnivariateSpline(z_sample, np.sqrt(s2))
    s2 = sample_fit**2 - data.Gas**2 - entry.ML_maxbulge * data.Bulge**2 - min(
        entry.ML_maxdisk, 0.6) * data.Disk**2
    s2 = np.array([max(item, 0.0) for item in s2])
    Vdm_min = InterpolatedUnivariateSpline(z_sample, np.sqrt(s2))

    return vmax,rmax,chi2_dof,y_fit,dy_pred,ddy_pred,sample_fit,\
            Vdm_med,Vdm_max,Vdm_min,V_spline,V_spline_fit
Exemple #2
0
def test_PolynomialRegression_simple():
    x = np.arange(10.).reshape((10, 1))
    y = np.arange(10.)
    dy = 1

    clf = PolynomialRegression(2).fit(x, y, dy)
    y_true = clf.predict(x)

    assert_allclose(y, y_true, atol=1E-10)
def test_PolynomialRegression_simple():
    x = np.arange(10.).reshape((10, 1))
    y = np.arange(10.)
    dy = 1

    clf = PolynomialRegression(2).fit(x, y, dy)
    y_true = clf.predict(x)

    assert_allclose(y, y_true, atol=1E-10)
def fit_Polynomial(features_train, labels_train, features_pred, order=3):
	model = PolynomialRegression(order)
	model.fit(features_train, labels_train)
	labels_pred = model.predict(features_pred)
	return labels_pred