This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| #Import the optim module from the pytorch package | |
| import torch.optim as optim | |
| #Initialize an optimizer object | |
| learning_rate = 0.001 | |
| optimizer = optim.Adam(net.parameters(), lr=learning_rate) | |
| #Set the parameter gradients to 0 and take a step (as part of a training loop) | |
| for epoch in num_epochs: | |
| train(...) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| class KMP: | |
| def partial(self, pattern): | |
| """ Calculate partial match table: String -> [Int]""" | |
| ret = [0] | |
| for i in range(1, len(pattern)): | |
| j = ret[i - 1] | |
| while j > 0 and pattern[j] != pattern[i]: | |
| j = ret[j - 1] | |
| ret.append(j + 1 if pattern[j] == pattern[i] else j) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| public class Search { | |
| public static <T extends Comparable<T>> int binarySearch(T[] array, T value, int lo, int hi) { | |
| if (lo < hi) { | |
| int mid = (lo / 2) + (hi / 2); | |
| int cmp = array[mid].compareTo(value); | |
| if (cmp < 0) return binarySearch(array, value, lo, mid - 1); | |
| if (cmp > 0) return binarySearch(array, value, mid + 1, hi); | |
| return mid; | |
| } // if |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| angularjsDemo03 |