Skip to content

Instantly share code, notes, and snippets.

#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(...)
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)
@febikamBU
febikamBU / Search.java
Created March 14, 2020 18:02 — forked from mepcotterell/Search.java
Generic Binary Search in Java
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
@febikamBU
febikamBU / angularjsDemo03_.idea_.name
Created October 18, 2019 19:47 — forked from LeeHyungGeun/angularjsDemo03_.idea_.name
Single Page App : Node.js + AngularJS + MongoDB
angularjsDemo03