Skip to content

Commit

Permalink
Added Simulated Annealing to search notebook (#866)
Browse files Browse the repository at this point in the history
* A few helper functions

* Added Simulated Annealing

* Updated README.md
  • Loading branch information
ad71 authored and norvig committed Mar 20, 2018
1 parent b25887b commit 74a3667
Show file tree
Hide file tree
Showing 3 changed files with 747 additions and 2 deletions.
2 changes: 1 addition & 1 deletion README.md
Expand Up @@ -80,7 +80,7 @@ Here is a table of algorithms, the figure, name of the algorithm in the book and
| 3.24 | A\*-Search | `astar_search` | [`search.py`][search] | Done | Included |
| 3.26 | Recursive-Best-First-Search | `recursive_best_first_search` | [`search.py`][search] | Done | |
| 4.2 | Hill-Climbing | `hill_climbing` | [`search.py`][search] | Done | Included |
| 4.5 | Simulated-Annealing | `simulated_annealing` | [`search.py`][search] | Done | |
| 4.5 | Simulated-Annealing | `simulated_annealing` | [`search.py`][search] | Done | Included |
| 4.8 | Genetic-Algorithm | `genetic_algorithm` | [`search.py`][search] | Done | Included |
| 4.11 | And-Or-Graph-Search | `and_or_graph_search` | [`search.py`][search] | Done | |
| 4.21 | Online-DFS-Agent | `online_dfs_agent` | [`search.py`][search] | | |
Expand Down
16 changes: 16 additions & 0 deletions notebook.py
Expand Up @@ -1070,3 +1070,19 @@ def plot_NQueens(solution):
newax.axis('off')
fig.tight_layout()
plt.show()

# Function to plot a heatmap, given a grid
def heatmap(grid, cmap='binary', interpolation='nearest'):
fig = plt.figure(figsize=(7, 7))
ax = fig.add_subplot(111)
ax.set_title('Heatmap')
plt.imshow(grid, cmap=cmap, interpolation=interpolation)
fig.tight_layout()
plt.show()

# Generates a gaussian kernel
def gaussian_kernel(l=5, sig=1.0):
ax = np.arange(-l // 2 + 1., l // 2 + 1.)
xx, yy = np.meshgrid(ax, ax)
kernel = np.exp(-(xx**2 + yy**2) / (2. * sig**2))
return kernel

0 comments on commit 74a3667

Please sign in to comment.