Beispiel #1
0
def lnprior(Y_array, *args):
    """
    Log-Prior function for mapping

    Parameters
    ----------

    Returns
    -------
    """

    # Unpack args
    Obs_ij, Obsnoise_ij, Kernel_il, regularization, n_regparam, flip, verbose, n_type, n_slice  = args
    n_band = len(Obs_ij[0])

    # Parameter conversion
    if (n_regparam > 0):
        X_albd_kj, X_area_lk = reparameterize.transform_Y2X(Y_array[:-1*n_regparam], n_type, n_band, n_slice )
    else:
        X_albd_kj, X_area_lk = reparameterize.transform_Y2X(Y_array, n_type, n_band, n_slice )

    # Flat prior for albedo
    Y_albd_kj = Y_array[0:n_type*n_band].reshape([n_type, n_band])
    ln_prior_albd = prior.get_ln_prior_albd( Y_albd_kj )

    # flat prior for area fraction
    Y_area_lk = Y_array[n_type*n_band:n_type*n_band+n_slice*(n_type-1)].reshape([n_slice, n_type-1])
    ln_prior_area = prior.get_ln_prior_area_new( Y_area_lk, X_area_lk[:,:-1] )

    # flat ordering prior for labeling degeneracy
    ln_prior_order = prior.get_ln_prior_ordering(X_albd_kj, X_area_lk)

    # regularization
    if regularization is not None:
        if ( regularization == 'Tikhonov' ):
            # ---Tikhonov Regularization
            regparam = Y_array[-1*n_regparam]
            regterm_area = prior.regularize_area_tikhonov( X_area_lk, regparam )
        elif ( regularization == 'GP' ):
            # ---Gaussian Process
            regparam = ( Y_array[-1*n_regparam], Y_array[-1*n_regparam+1], Y_array[-1*n_regparam+2] )
            regterm_area = prior.regularize_area_GP( X_area_lk, regparam )
        elif ( regularization == 'GP2' ):
            # ---Gaussian Process without constraint
            regparam = ( Y_array[-1*n_regparam], Y_array[-1*n_regparam+1] )
            regterm_area = prior.regularize_area_GP2( X_area_lk, regparam )
    # ---Others
    else :
        regterm_area = 0.

    answer = ln_prior_albd + ln_prior_area + ln_prior_order + regterm_area

    # Check for nans
    if np.isnan(answer):
        answer = -np.inf

    if flip :
        return -1. * answer
    else :
         return answer
def lnprob(Y_array, *args):
    """
    Misfit-function to be minimized
    """

    Obs_ij, Obsnoise_ij, Kernel_il, n_regparam, flip, verbose  = args
    n_band = len(Obs_ij[0])

    # parameter conversion
    if ( n_regparam > 0 ):
        X_albd_kj, X_area_lk = transform_Y2X(Y_array[:-1*n_regparam], N_TYPE, n_band, N_SLICE)
    else:
        X_albd_kj, X_area_lk = transform_Y2X(Y_array, N_TYPE, n_band, N_SLICE)

    # making matrix...
    Model_ij = np.dot(Kernel_il, np.dot(X_area_lk, X_albd_kj))
    Diff_ij = ( Obs_ij - Model_ij ) / Obsnoise_ij
    Chi2_i  = np.diag(np.dot( Diff_ij, Diff_ij.T ))
    chi2    = np.sum( Chi2_i )

    # flat prior for albedo
    Y_albd_kj = Y_array[0:N_TYPE*n_band].reshape([N_TYPE, n_band])
    ln_prior_albd = prior.get_ln_prior_albd( Y_albd_kj )

    # flat prior for area fraction
    Y_area_lk = Y_array[N_TYPE*n_band:N_TYPE*n_band+N_SLICE*(N_TYPE-1)].reshape([N_SLICE, N_TYPE-1])
    ln_prior_area =  prior.get_ln_prior_area_new( Y_area_lk, X_area_lk[:,:-1] )

    # regularization
    # ---Tikhonov Regularization
    if 'REGULARIZATION' in globals():
        if ( REGULARIZATION == 'Tikhonov' ):
            regparam = Y_array[-1*N_REGPARAM]
            regterm_area = prior.regularize_area_tikhonov( X_area_lk, regparam ) 
    # ---Gaussian Process
        elif ( REGULARIZATION == 'GP' ):
            regparam = ( Y_array[-1*N_REGPARAM], Y_array[-1*N_REGPARAM+1], Y_array[-1*N_REGPARAM+2] )
            regterm_area = prior.regularize_area_GP( X_area_lk, regparam ) 
    # ---Gaussian Process without constraint
        elif ( REGULARIZATION == 'GP2' ):
            regparam = ( Y_array[-1*N_REGPARAM], Y_array[-1*N_REGPARAM+1] )
            regterm_area = prior.regularize_area_GP2( X_area_lk, regparam ) 
    # ---Others
    else :
        regterm_area = 0.

    # verbose
    if verbose :
        print 'chi2', chi2 - ln_prior_albd - ln_prior_area, chi2, ln_prior_albd, ln_prior_area
        print 'chi2/d.o.f.', chi2 / (len(Y_array)*1.-1.), len(Y_array)

    answer = - chi2 + ln_prior_albd + ln_prior_area + regterm_area
    if flip :
        return -1. * answer
    else :
         return answer
Beispiel #3
0
def lnprob(Y_array, *args):
    """
    Log-probability function for mapping

    Parameters
    ----------

    Returns
    -------
    """

    # Unpack args
    Obs_ij, Obsnoise_ij, Kernel_il, regularization, n_regparam, flip, verbose, n_type, n_slice  = args
    n_band = len(Obs_ij[0])

    # Parameter conversion
    if (n_regparam > 0):
        X_albd_kj, X_area_lk = reparameterize.transform_Y2X(Y_array[:-1*n_regparam], n_type, n_band, n_slice )
    else:
        X_albd_kj, X_area_lk = reparameterize.transform_Y2X(Y_array, n_type, n_band, n_slice )

    # Model
    Model_ij = np.dot(Kernel_il, np.dot(X_area_lk, X_albd_kj))

    # Chi-squared statistic
    Diff_ij = ( Obs_ij - Model_ij ) / Obsnoise_ij
    Chi2_i  = np.diag(np.dot( Diff_ij, Diff_ij.T ))
    chi2    = np.sum(Chi2_i)

    # Flat prior for albedo
    Y_albd_kj = Y_array[0:n_type*n_band].reshape([n_type, n_band])
    ln_prior_albd = prior.get_ln_prior_albd( Y_albd_kj )

    # flat prior for area fraction
    Y_area_lk = Y_array[n_type*n_band:n_type*n_band+n_slice*(n_type-1)].reshape([n_slice, n_type-1])
    ln_prior_area = prior.get_ln_prior_area_new( Y_area_lk, X_area_lk[:,:-1] )

    # flat ordering prior for labeling degeneracy
    ln_prior_order = prior.get_ln_prior_ordering(X_albd_kj, X_area_lk)

    # regularization
    if regularization is not None:
        if ( regularization == 'Tikhonov' ):
            # ---Tikhonov Regularization
            regparam = Y_array[-1*n_regparam]
            regterm_area = prior.regularize_area_tikhonov( X_area_lk, regparam )
        elif ( regularization == 'GP' ):
            # ---Gaussian Process
            regparam = ( Y_array[-1*n_regparam], Y_array[-1*n_regparam+1], Y_array[-1*n_regparam+2] )
            regterm_area = prior.regularize_area_GP( X_area_lk, regparam )
        elif ( regularization == 'GP2' ):
            # ---Gaussian Process without constraint
            regparam = ( Y_array[-1*n_regparam], Y_array[-1*n_regparam+1] )
            regterm_area = prior.regularize_area_GP2( X_area_lk, regparam )
    # ---Others
    else :
        regterm_area = 0.

    # verbose
    if verbose :
        print 'chi2', chi2 - ln_prior_albd - ln_prior_area, chi2, ln_prior_albd, ln_prior_area
        print 'chi2/d.o.f.', chi2 / (len(Y_array)*1.-1.), len(Y_array)

    answer = - chi2 + ln_prior_albd + ln_prior_area + ln_prior_order + regterm_area

    # Check for nans
    if np.isnan(answer):
        answer = -np.inf

    if flip :
        return -1. * answer
    else :
         return answer, Model_ij
def lnprob(Y_array, *args):
    """
    Misfit-function to be minimized
    """

    # Unpack args
    Obs_ij, Obsnoise_ij, Kernel_il, N_REGPARAM, flip, verbose = args
    n_slice = len(Obs_ij)
    n_band = len(Obs_ij[0])

    # Parameter conversion
    if (N_REGPARAM > 0):
        X_albd_kj, X_area_lk = reparameterize.transform_Y2X(
            Y_array[:-1 * N_REGPARAM], N_TYPE, n_band, n_slice)
    else:
        X_albd_kj, X_area_lk = reparameterize.transform_Y2X(
            Y_array, N_TYPE, n_band, n_slice)

    # Model
    Model_ij = np.dot(Kernel_il, np.dot(X_area_lk, X_albd_kj))

    # Chi-squared statistic
    Diff_ij = (Obs_ij - Model_ij) / Obsnoise_ij
    Chi2_i = np.diag(np.dot(Diff_ij, Diff_ij.T))
    chi2 = np.sum(Chi2_i)

    # Flat prior for albedo
    Y_albd_kj = Y_array[0:N_TYPE * n_band].reshape([N_TYPE, n_band])
    ln_prior_albd = prior.get_ln_prior_albd(Y_albd_kj)

    # flat prior for area fraction
    Y_area_lk = Y_array[N_TYPE * n_band:N_TYPE * n_band + n_slice *
                        (N_TYPE - 1)].reshape([n_slice, N_TYPE - 1])
    ln_prior_area = prior.get_ln_prior_area_new(Y_area_lk, X_area_lk[:, :-1])

    # flat ordering prior for labeling degeneracy
    ln_prior_order = prior.get_ln_prior_ordering(X_albd_kj, X_area_lk)

    # regularization
    # ---Tikhonov Regularization
    if REGULARIZATION is not None:
        if (REGULARIZATION == 'Tikhonov'):
            regparam = Y_array[-1 * N_REGPARAM]
            regterm_area = prior.regularize_area_tikhonov(X_area_lk, regparam)
    # ---Gaussian Process
        elif (REGULARIZATION == 'GP'):
            regparam = (Y_array[-1 * N_REGPARAM], Y_array[-1 * N_REGPARAM + 1],
                        Y_array[-1 * N_REGPARAM + 2])
            regterm_area = prior.regularize_area_GP(X_area_lk, regparam)
    # ---Gaussian Process without constraint
        elif (REGULARIZATION == 'GP2'):
            regparam = (Y_array[-1 * N_REGPARAM], Y_array[-1 * N_REGPARAM + 1])
            regterm_area = prior.regularize_area_GP2(X_area_lk, regparam)
    # ---Others
    else:
        regterm_area = 0.

    # verbose
    if verbose:
        print 'chi2', chi2 - ln_prior_albd - ln_prior_area, chi2, ln_prior_albd, ln_prior_area
        print 'chi2/d.o.f.', chi2 / (len(Y_array) * 1. - 1.), len(Y_array)

    answer = -chi2 + ln_prior_albd + ln_prior_area + ln_prior_order + regterm_area

    # Check for nans
    if np.isnan(answer):
        answer = -np.inf

    if flip:
        return -1. * answer
    else:
        return answer, Model_ij
Beispiel #5
0
def lnprob_atmosphere(Y_array, *args):
    """
    Log-probability function for mapping

    Parameters
    ----------

    Returns
    -------
    """

    # Unpack args
    Obs_ij, Obsnoise_ij, Kernel_il, regularization, n_regparam, flip, verbose, n_type, n_slice, use_grey, use_global = args
    n_band = len(Obs_ij[0])

    # Parameter conversion
    if (n_regparam > 0):
        X_albd_kj, X_area_lk = reparameterize.transform_Y2X_atmosphere(
            Y_array[:-1 * n_regparam],
            n_type,
            n_band,
            n_slice,
            use_grey=use_grey,
            use_global=use_global)
    else:
        X_albd_kj, X_area_lk = reparameterize.transform_Y2X_atmosphere(
            Y_array,
            n_type,
            n_band,
            n_slice,
            use_grey=use_grey,
            use_global=use_global)

    # Model
    Model_ij = np.dot(Kernel_il, np.dot(X_area_lk, X_albd_kj))

    # Chi-squared statistic
    Diff_ij = (Obs_ij - Model_ij) / Obsnoise_ij
    Chi2_i = np.diag(np.dot(Diff_ij, Diff_ij.T))
    chi2 = np.sum(Chi2_i)

    # Flat prior for albedo
    Y_albd_kj = Y_array[0:n_type * n_band].reshape([n_type, n_band])
    ln_prior_albd = prior.get_ln_prior_albd(Y_albd_kj)

    # Extract Y_area_lk from Y_array
    if use_grey and use_global:
        Y_area_lk = Y_array[(n_type - 1) * n_band:(n_type - 1) * n_band +
                            n_slice * (n_type - 2)].reshape(
                                [n_slice, n_type - 2])
    elif use_grey and not use_global:
        Y_area_lk = Y_array[(n_type - 1) * n_band:(n_type - 1) * n_band +
                            n_slice * (n_type - 1)].reshape(
                                [n_slice, n_type - 1])
    elif use_global and not use_grey:
        Y_area_lk = Y_array[n_type * n_band:n_type * n_band + n_slice *
                            (n_type - 2)].reshape([n_slice, n_type - 2])
    else:
        Y_area_lk = Y_array[n_type * n_band:(n_type) * n_band + n_slice *
                            (n_type - 1)].reshape([n_slice, n_type - 1])

    # flat prior for area fraction
    ln_prior_area = prior.get_ln_prior_area_new(Y_area_lk, X_area_lk[:, :-1])

    # flat ordering prior for labeling degeneracy
    ln_prior_order = prior.get_ln_prior_ordering(X_albd_kj, X_area_lk)

    # atmosphere prior
    #ln_prior_atmosphere = prior.get_ln_prior_atmosphere(X_albd_kj, X_area_lk, use_grey, use_global, max_dev = max_dev)

    # regularization
    if regularization is not None:
        if (regularization == 'Tikhonov'):
            # ---Tikhonov Regularization
            regparam = Y_array[-1 * n_regparam]
            regterm_area = prior.regularize_area_tikhonov(X_area_lk, regparam)
        elif (regularization == 'GP'):
            # ---Gaussian Process
            regparam = (Y_array[-1 * n_regparam], Y_array[-1 * n_regparam + 1],
                        Y_array[-1 * n_regparam + 2])
            regterm_area = prior.regularize_area_GP(X_area_lk, regparam)
        elif (regularization == 'GP2'):
            # ---Gaussian Process without constraint
            regparam = (Y_array[-1 * n_regparam], Y_array[-1 * n_regparam + 1])
            regterm_area = prior.regularize_area_GP2(X_area_lk, regparam)
    # ---Others
    else:
        regterm_area = 0.

    # verbose
    if verbose:
        print 'chi2', chi2 - ln_prior_albd - ln_prior_area, chi2, ln_prior_albd, ln_prior_area
        print 'chi2/d.o.f.', chi2 / (len(Y_array) * 1. - 1.), len(Y_array)

    answer = - chi2 \
             + ln_prior_albd \
             + ln_prior_area \
             + ln_prior_order \
             + regterm_area

    # Check for nans
    if np.isnan(answer):
        answer = -np.inf

    if flip:
        return -1. * answer
    else:
        return answer, Model_ij
Beispiel #6
0
def lnprior(Y_array, *args):
    """
    Log-Prior function for mapping

    Parameters
    ----------

    Returns
    -------
    """

    # Unpack args
    Obs_ij, Obsnoise_ij, Kernel_il, regularization, n_regparam, flip, verbose, n_type, n_slice = args
    n_band = len(Obs_ij[0])

    # Parameter conversion
    if (n_regparam > 0):
        X_albd_kj, X_area_lk = reparameterize.transform_Y2X(
            Y_array[:-1 * n_regparam], n_type, n_band, n_slice)
    else:
        X_albd_kj, X_area_lk = reparameterize.transform_Y2X(
            Y_array, n_type, n_band, n_slice)

    # Flat prior for albedo
    Y_albd_kj = Y_array[0:n_type * n_band].reshape([n_type, n_band])
    ln_prior_albd = prior.get_ln_prior_albd(Y_albd_kj)

    # flat prior for area fraction
    Y_area_lk = Y_array[n_type * n_band:n_type * n_band + n_slice *
                        (n_type - 1)].reshape([n_slice, n_type - 1])
    ln_prior_area = prior.get_ln_prior_area_new(Y_area_lk, X_area_lk[:, :-1])

    # flat ordering prior for labeling degeneracy
    ln_prior_order = prior.get_ln_prior_ordering(X_albd_kj, X_area_lk)

    # regularization
    if regularization is not None:
        if (regularization == 'Tikhonov'):
            # ---Tikhonov Regularization
            regparam = Y_array[-1 * n_regparam]
            regterm_area = prior.regularize_area_tikhonov(X_area_lk, regparam)
        elif (regularization == 'GP'):
            # ---Gaussian Process
            regparam = (Y_array[-1 * n_regparam], Y_array[-1 * n_regparam + 1],
                        Y_array[-1 * n_regparam + 2])
            regterm_area = prior.regularize_area_GP(X_area_lk, regparam)
        elif (regularization == 'GP2'):
            # ---Gaussian Process without constraint
            regparam = (Y_array[-1 * n_regparam], Y_array[-1 * n_regparam + 1])
            regterm_area = prior.regularize_area_GP2(X_area_lk, regparam)
    # ---Others
    else:
        regterm_area = 0.

    answer = ln_prior_albd + ln_prior_area + ln_prior_order + regterm_area

    # Check for nans
    if np.isnan(answer):
        answer = -np.inf

    if flip:
        return -1. * answer
    else:
        return answer
def lnprob(Y_array, *args):
    """
    Misfit-function to be minimized
    """

    Obs_ij, Obsnoise_ij, Kernel_il, N_REGPARAM, n_type, flip, verbose  = args
    #n_slice = len(Obs_ij)
    n_slice = len(Kernel_il[0])
    n_band = len(Obs_ij[0])
 
    # parameter conversion
    if (N_REGPARAM > 0):
        X_albd_kj, X_area_lk = reparameterize.transform_Y2X(Y_array[:-1*N_REGPARAM], n_type, n_band, n_slice )
    else:
        X_albd_kj, X_area_lk = reparameterize.transform_Y2X(Y_array, n_type, n_band, n_slice )

    # making matrix...
    Model_ij = np.dot(Kernel_il, np.dot(X_area_lk, X_albd_kj))
    Diff_ij = ( Obs_ij - Model_ij ) / Obsnoise_ij
    Chi2_i  = np.diag(np.dot( Diff_ij, Diff_ij.T ))
    chi2    = np.sum(Chi2_i)

    # flat prior for albedo
    Y_albd_kj = Y_array[0:n_type*n_band].reshape([n_type, n_band])
    ln_prior_albd = prior.get_ln_prior_albd( Y_albd_kj )

    # flat prior for area fraction
    if (N_REGPARAM > 0):
        Y_area_lk = Y_array[n_type*n_band:-1*N_REGPARAM].reshape([n_slice, n_type-1])
    else:
        Y_area_lk = Y_array[n_type*n_band:].reshape([n_slice, n_type-1])
    ln_prior_area = prior.get_ln_prior_area_new( Y_area_lk, X_area_lk[:,:-1] )

    # regularization
    # ---Tikhonov Regularization
    if REGULARIZATION is not None:
        if ( REGULARIZATION == 'Tikhonov' ):
            regparam = Y_array[-1*N_REGPARAM]
            regterm_area = prior.regularize_area_tikhonov( X_area_lk, regparam )
    # ---Gaussian Process
        elif ( REGULARIZATION == 'GP' ):
            regparam = ( Y_array[-1*N_REGPARAM], Y_array[-1*N_REGPARAM+1], Y_array[-1*N_REGPARAM+2] )
            regterm_area = prior.regularize_area_GP( X_area_lk, regparam )
    # ---Gaussian Process without constraint
        elif ( REGULARIZATION == 'GP2' ):
            regparam = ( Y_array[-1*N_REGPARAM], Y_array[-1*N_REGPARAM+1] )
            regterm_area = prior.regularize_area_GP2( X_area_lk, regparam )
    # ---Gaussian Process
        elif ( REGULARIZATION == 'GP3' ):
            regparam = ( Y_array[-1*N_REGPARAM], Y_array[-1*N_REGPARAM+1] )
            regterm_area = prior.regularize_area_GP3( X_area_lk, regparam )
    # ---Gaussian Process
        elif ( REGULARIZATION == 'GP4' ):
            regparam = ( SIGMA_Y, -10., np.pi/180.*120. )
#            regparam = ( 0.01, -10., np.pi/180.*120. )
#            regparam = ( 0.0001, -10., np.pi/180.*60. )
            regterm_area = prior.regularize_area_GP( X_area_lk, regparam )
    # ---Others
    else :
        regterm_area = 0.

    # verbose
    if verbose :
        print 'chi2', chi2 - ln_prior_albd - ln_prior_area, chi2, ln_prior_albd, ln_prior_area
        print 'chi2/d.o.f.', chi2 / (len(Y_array)*1.-1.), len(Y_array)

    answer = - chi2 + ln_prior_albd + ln_prior_area + regterm_area
    if flip :
        return -1. * answer
    else :
         return answer
def lnprob(Y_array, *args):
    """
    Misfit-function to be minimized
    """

    # Unpack args
    Obs_ij, Obsnoise_ij, Kernel_il, N_REGPARAM, flip, verbose  = args
    n_slice = len(Obs_ij)
    n_band = len(Obs_ij[0])

    # Parameter conversion
    if (N_REGPARAM > 0):
        X_albd_kj, X_area_lk = reparameterize.transform_Y2X(Y_array[:-1*N_REGPARAM], N_TYPE, n_band, n_slice )
    else:
        X_albd_kj, X_area_lk = reparameterize.transform_Y2X(Y_array, N_TYPE, n_band, n_slice )

    # Model
    Model_ij = np.dot(Kernel_il, np.dot(X_area_lk, X_albd_kj))

    # Chi-squared statistic
    Diff_ij = ( Obs_ij - Model_ij ) / Obsnoise_ij
    Chi2_i  = np.diag(np.dot( Diff_ij, Diff_ij.T ))
    chi2    = np.sum(Chi2_i)

    # Flat prior for albedo
    Y_albd_kj = Y_array[0:N_TYPE*n_band].reshape([N_TYPE, n_band])
    ln_prior_albd = prior.get_ln_prior_albd( Y_albd_kj )

    # flat prior for area fraction
    Y_area_lk = Y_array[N_TYPE*n_band:N_TYPE*n_band+n_slice*(N_TYPE-1)].reshape([n_slice, N_TYPE-1])
    ln_prior_area = prior.get_ln_prior_area_new( Y_area_lk, X_area_lk[:,:-1] )

    # flat ordering prior for labeling degeneracy
    ln_prior_order = prior.get_ln_prior_ordering(X_albd_kj, X_area_lk)

    # regularization
    # ---Tikhonov Regularization
    if REGULARIZATION is not None:
        if ( REGULARIZATION == 'Tikhonov' ):
            regparam = Y_array[-1*N_REGPARAM]
            regterm_area = prior.regularize_area_tikhonov( X_area_lk, regparam )
    # ---Gaussian Process
        elif ( REGULARIZATION == 'GP' ):
            regparam = ( Y_array[-1*N_REGPARAM], Y_array[-1*N_REGPARAM+1], Y_array[-1*N_REGPARAM+2] )
            regterm_area = prior.regularize_area_GP( X_area_lk, regparam )
    # ---Gaussian Process without constraint
        elif ( REGULARIZATION == 'GP2' ):
            regparam = ( Y_array[-1*N_REGPARAM], Y_array[-1*N_REGPARAM+1] )
            regterm_area = prior.regularize_area_GP2( X_area_lk, regparam )
    # ---Others
    else :
        regterm_area = 0.

    # verbose
    if verbose :
        print 'chi2', chi2 - ln_prior_albd - ln_prior_area, chi2, ln_prior_albd, ln_prior_area
        print 'chi2/d.o.f.', chi2 / (len(Y_array)*1.-1.), len(Y_array)

    answer = - chi2 + ln_prior_albd + ln_prior_area + ln_prior_order + regterm_area

    # Check for nans
    if np.isnan(answer):
        answer = -np.inf

    if flip :
        return -1. * answer
    else :
         return answer, Model_ij