Exemplo n.º 1
0
def search_books(books):
    property = input("Search book by name or author? (Choose one)\n")
    while(property not in ['name', 'author']):
        property = input(
            "You made a wrong selection, you can only search by 'name', or 'author'\n")

    value = input(f"Which {property} would you like to search for: \n")
    search_results = [
        book for book in books if value.lower() in book[property]]
    print()
    if(len(search_results) == 0):
        print("Oops 😞, We couldn't find your book, Please try another search")
    else:
        print('Search Results:')
        display_results(search_results)
print("CG:", best_idx)
results['Conjugate Gradient'] = best

# Parameters: alpha = (0, 0.5], beta = (0, 1)
f_grid = build_grid(np.array([[1E-5, 0.5], [1E-5, 0.999]]), SEARCHES)
counter = 0
best = None
best_idx = None
for i, a in enumerate(f_grid[0]):
    for j, b in enumerate(f_grid[1]):
        tmp = fista(x, ITERATIONS, a, b, early_stop=EARLY_STOP)
        if best is None:
            best = tmp
        else:
            if tmp[0][tmp[1]] <= best[0][best[1]]:
                # take the one with a lower number of convergence iterations
                best = tmp
                best_idx = [a, b]
            counter += 1

print("FISTA:", best_idx)
results['FISTA'] = best

# Parameters: NONE
results['Barzilai Borwein'] = barzilai_borwein(x,
                                               ITERATIONS,
                                               early_stop=EARLY_STOP)

# plot all of the results
display_results(results, str(SIZE))
Exemplo n.º 3
0
def list_books(book_list):
    if len(book_list) == 0:
        print('There are no books in your collection')
    display_results(book_list)