示例#1
0
def makePropForward(freq_basis_array, x_hat, Delta_T_Sampling, phase_correction_noisetraces, num, n_train, numf):
    ''' Extracts learned parameters from Kalman Filtering msmt_record and makes
        predictions for timesteps > n_train.

    Parameters:
    ----------
        freq_basis_array (`float64`): Array containing `numf` number of basis frequencies.
        x_hat (`float64`): Aposteriori KF estimates based on msmt_record.
        Delta_T_Sampling (`float64`): Time interval between measurements.
        phase_correction_noisetraces (`float64`): Applies depending on choice of basis
        num (`int`): Number of points in msmt_record.
        n_train (`int`): Predicted timestep at which algorithm is expected to finish learning.
        numf (`int`): Number of spectral basis frequencies in freq_basis_array.

    Returns:
    -------
        Propagate_Foward (`float64`): Output predictions. Non-zero only
            for n_train < timestep < num.
        instantA (`float64`): Instantaneous amplitude calculated based on
            estimated state x_hat [Dim: numf x num]
        instantP (`float64`): Instantaneous phase calculated based on estimated
            state x_hat [Dim: numf x num]
    '''

    instantA, instantP = calc_inst_params(x_hat)

    ## PROPAGATE FORWARD USING HARMONIC SUMS
    Propagate_Foward = np.zeros((num))

    tn = 0
    for tn in range(n_train, num, 1):
        Propagate_Foward[tn] = instantA[0]*np.cos((Delta_T_Sampling*tn*freq_basis_array[0]*2*np.pi + instantP[0]))
        Propagate_Foward[tn] += np.sum(instantA[1:]*np.cos((Delta_T_Sampling*tn*freq_basis_array[1:]*2*np.pi + instantP[1:] + phase_correction_noisetraces))) # with correction for noise traces 

    return Propagate_Foward, instantA, instantP
示例#2
0
def makePropForward(freq_basis_array, x_hat, Delta_T_Sampling,
                    phase_correction_noisetraces, num, n_train, numf):
    ''' Extracts learned parameters from Kalman Filtering msmt_record and makes
        predictions for timesteps > n_train.

    Parameters:
    ----------
        freq_basis_array (`float64`): Array containing `numf` number of basis frequencies.
        x_hat (`float64`): Aposteriori KF estimates based on msmt_record.
        Delta_T_Sampling (`float64`): Time interval between measurements.
        phase_correction_noisetraces (`float64`): Applies depending on choice of basis
        num (`int`): Number of points in msmt_record.
        n_train (`int`): Predicted timestep at which algorithm is expected to finish learning.
        numf (`int`): Number of points (spectral basis frequencies) in freq_basis_array.

    Returns:
    -------
        Propagate_Foward (`float64`): Output predictions. Non-zero only
            for n_train < timestep < num.
        instantA (`float64`): Instantaneous amplitude calculated based on
            estimated state x_hat [Dim: numf x num]
        instantP (`float64`): Instantaneous phase calculated based on estimated
            state x_hat [Dim: numf x num]
    '''
    # Instantaneous Amplitude, Phase and Frequency Calculations
    # # not optimised as it doesn't concern the loop
    instantA = np.zeros((numf, num))
    instantP = np.zeros((numf, num))
    ## CALCULATE INSTANTANEOUS PHASE, AMPLITUDE AND FREQUENCY
    k = 1
    while (k < num):
        instantA[:, k], instantP[:, k] = calc_inst_params(x_hat[:, :, k])
        k = k + 1

    ## PROPAGATE FORWARD USING HARMONIC SUMS
    Propagate_Foward = np.zeros((num))
    instantA_Prediction = instantA[:, n_train]
    instantP_Prediction = instantP[:, n_train]

    # Using a harmonic sum for propagating the noise
    tn = 0
    for tn in range(n_train, num, 1):
        Propagate_Foward[tn] = instantA_Prediction[0] * np.cos(
            (Delta_T_Sampling * tn * freq_basis_array[0] * 2 * np.pi +
             instantP_Prediction[0]))
        Propagate_Foward[tn] += np.sum(instantA_Prediction[1:] * np.cos(
            (Delta_T_Sampling * tn * freq_basis_array[1:] * 2 * np.pi +
             instantP_Prediction[1:] + phase_correction_noisetraces))
                                       )  # with correction for noise traces

    return Propagate_Foward, instantA, instantP
示例#3
0
def LKFFB_run(LdExp, y_signal, **kwargs):
    '''
    Return a single LKFFB prediction and spectral density estimate.

    Returns:
    -------
        predictions (`float64`): Predictons from a single run of LKFFB
            [dims: n_testbefore + n_predict x 1].
        x_data[0] (`float64`): Omega axis for LKFFB using freq_basis_array [radians],
            [DIMS: numf x 1].
        x_data[1] (`float64`): Omega axis for True S(w) [radians], [dims: J x 1].
        y_data[0] (`float64`): S(w) estimate based on LKFFB instantaneous
            amplitudes * (1.0/ sum (S(w) True)), [dims: numf x 1].
        y_data[1] (`float64`): True S(w) * (1.0/ sum (S(w) True)), [dims: J x 1].
        true_S_norm[0] (`float64`): sum (S(w) LKFFB), [dims: scalar].
        true_S_norm[1] (`float64`): sum (S(w) True), [dims: scalar].

    Parameters:
    ----------
        LdExp (`class object`) :  A data_tools.load_raw_cluster_data.LoadExperiment instance.
        y_signal (`float64`) : Noisy measurements (input for filtering).
        **kwargs :
            kwargs['opt_sigma'] : Optimally tuned process noise variance for kf.fast_2.
            kwargs['opt_R'] : Optimally tuned measurement noise variance for kf.fast_2.

    Harcoded Fixed Parameters:
    -------------------------
        method (`int`): 'ZeroGain', a type of prediction method defined in kf.fast_2
        freq_basis_array (`float64`): Basis A, a type of fixed basis defined in kf.fast_2
    '''
    oe = 0.0
    rk = 0.0

    # FIXED LKFFB PARAMETER: Prediction Method 'ZeroGain'
    method = 'ZeroGain'

    try:
        quantised = kwargs['quantised']
    except:
        quantised = 'No'

    if len(kwargs) == 2:

        # Optimally tuned Kalman Process noise
        oe = kwargs['opt_sigma']

        # Optimally tuned Kalman Measurement noise
        rk = kwargs['opt_R']

    x0 = LdExp.LKFFB_kalman_params[2]
    p0 = LdExp.LKFFB_kalman_params[3]
    bdelta = LdExp.LKFFB_kalman_params[4]

    # FIXED LKFFB PARAMETER: Choose Basis A
    freq_basis_array = np.arange(0.0, LdExp.Expt.bandwidth, bdelta)

    predictions, x_hat = Kalman.kf_2017(y_signal,
                                        LdExp.Expt.n_train,
                                        LdExp.Expt.n_testbefore,
                                        LdExp.Expt.n_predict,
                                        LdExp.Expt.Delta_T_Sampling,
                                        x0,
                                        p0,
                                        oe,
                                        rk,
                                        freq_basis_array,
                                        phase_correction=0,
                                        prediction_method=method,
                                        skip_msmts=1,
                                        switch_off_save='Yes',
                                        quantised=quantised)

    x_hat_slice = x_hat[:, :, LdExp.Expt.n_train]
    instantA, instantP = calc_inst_params(x_hat_slice)

    x_data, y_data, LdExp.Truth.true_S_norm = LKFFB_amps(
        LdExp, freq_basis_array=freq_basis_array, instantA=instantA)
    # LKFFB and Theory Data (List form: [LKFFB, Theory])
    return x_data, y_data, LdExp.Truth.true_S_norm, predictions