Beispiel #1
0
def compute_preconditioned_basis_matrix_condition_number(
        basis_matrix_func, samples):
    basis_matrix = basis_matrix_func(samples)
    basis_matrix = basis_matrix * np.sqrt(
        christoffel_weights(basis_matrix))[:, np.newaxis]
    cond = np.linalg.cond(basis_matrix)
    return cond
def candidate_based_christoffel_leja_rule_1d(
        recursion_coeffs,
        generate_candidate_samples,
        num_candidate_samples,
        level,
        initial_points=None,
        growth_rule=leja_growth_rule,
        samples_filename=None,
        return_weights_for_all_levels=True):

    num_vars = 1
    num_leja_samples = growth_rule(level)

    leja_sequence = get_candidate_based_christoffel_leja_sequence_1d(
        num_leja_samples, recursion_coeffs, generate_candidate_samples,
        num_candidate_samples, initial_points, samples_filename)

    from pyapprox.polynomial_sampling import christoffel_weights

    generate_basis_matrix = lambda x: evaluate_orthonormal_polynomial_deriv_1d(
        x[0, :], num_leja_samples, recursion_coeffs, deriv_order=0)

    weight_function = lambda x: christoffel_weights(generate_basis_matrix(x))
    ordered_weights_1d = get_leja_sequence_quadrature_weights(
        leja_sequence, growth_rule, generate_basis_matrix, weight_function,
        level, return_weights_for_all_levels)

    return leja_sequence[0, :], ordered_weights_1d
Beispiel #3
0
def candidate_based_leja_rule(recursion_coeffs,
                              generate_candidate_samples,
                              num_candidate_samples,
                              level,
                              initial_points=None,
                              growth_rule=leja_growth_rule,
                              samples_filename=None,
                              return_weights_for_all_levels=True):
    from pyapprox.orthonormal_polynomials_1d import \
        evaluate_orthonormal_polynomial_1d
    from pyapprox.polynomial_sampling import get_lu_leja_samples,\
        christoffel_preconditioner, christoffel_weights
    num_leja_samples = growth_rule(level)
    generate_basis_matrix = lambda x: evaluate_orthonormal_polynomial_1d(
        x[0, :], num_leja_samples, recursion_coeffs)
    if samples_filename is None or not os.path.exists(samples_filename):
        leja_sequence, __ = get_lu_leja_samples(
            generate_basis_matrix,
            generate_candidate_samples,
            num_candidate_samples,
            num_leja_samples,
            preconditioning_function=christoffel_preconditioner,
            initial_samples=initial_points)
        if samples_filename is not None:
            np.savez(samples_filename, samples=leja_sequence)
    else:
        leja_sequence = np.load(samples_filename)['samples']
        assert leja_sequence.shape[1] >= growth_rule(level)
        leja_sequence = leja_sequence[:, :growth_rule(level)]

    weight_function = lambda x: christoffel_weights(generate_basis_matrix(x))
    ordered_weights_1d = get_leja_sequence_quadrature_weights(
        leja_sequence, growth_rule, generate_basis_matrix, weight_function,
        level, return_weights_for_all_levels)

    return leja_sequence[0, :], ordered_weights_1d
Beispiel #4
0
 def weight_function(x): return christoffel_weights(
     generate_basis_matrix(x))
 ordered_weights_1d = get_leja_sequence_quadrature_weights(
 def precond_func(matrix, samples): return christoffel_weights(matrix)
 canonical_samples, data_structures = get_fekete_samples(
 def precond_func(matrix, samples): return christoffel_weights(matrix)
 initial_samples, data_structures = get_lu_leja_samples(