This file contains 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
# This gist aims to test BloomFilter with k-slices | |
# Assume we have a giant set of English words, | |
# user enters any string to know if the string is an English word | |
# It is important not to use HashMap or HashSet because of memory contraints | |
# | |
# Steps to follow before using: | |
# 1. Download English words from this repo: https://github.com/dwyl/english-words/blob/master/words_alpha.txt | |
# 2. Open command line and install murmur hash: | |
# pip3 install mmh3 | |
# 3. Run sbf.py from command line: |
This file contains 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 numpy as np | |
import matplotlib.pyplot as plt | |
import time | |
# Class 1: | |
mean_1 = [-2, 1] | |
cov1 = [[1, 0.8], [0.8, 2]] | |
# Class 2: |
This file contains 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 numpy as np | |
import matplotlib.pyplot as plt | |
import time | |
import math | |
class GradientDescent: | |
def __init__(self, x, y, a): | |
self.x = x |
This file contains 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
from math import e | |
# Compute k (optimal number of hash functions) | |
# n - the number of elements | |
# m - the bloom filter size | |
def compute_k(n, m): | |
ln2 = 0.69314718056 | |
k = ln2 * m / n | |
return round(k) |
This file contains 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
/** | |
* Imports here | |
*/ | |
class ShakeActivity : AppCompatActivity(), ShakeDetector.ShakeListener { | |
override fun onCreate(savedInstanceState: Bundle?) { | |
super.onCreate(savedInstanceState) | |
setContentView(R.layout.activity_shake) |
This file contains 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 numpy as np | |
import random | |
import matplotlib.pyplot as plt | |
def clustering(x1, x2): | |
# randomly initialize centroids | |
c1 = [random.randint(10, 40), random.randint(10, 40)] | |
c2 = [random.randint(50, 100), random.randint(50, 100)] | |
m = len(x1) |
This file contains 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 numpy as np | |
def sigmoid(z): | |
return 1 / (1 + np.exp(-z)) | |
def sigmoid_derivative(z): | |
return z * (1 - z) |
This file contains 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 numpy as np | |
import math | |
def sigmoid(x): | |
return 1 / (1 + math.exp(-x)) | |
def hypothesis(weights, x): | |
h = np.dot(weights, x) |
This file contains 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 numpy as np | |
def hypothesis(weights, x): | |
return np.dot(weights, x) | |
def cost_derivative(weights, x, y, feature_x): | |
s = 0 | |
m = len(x[0]) |
This file contains 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 MessageUI(val flags: Int = 0) : AnkoComponent<ViewGroup> { | |
override fun createView(ui: AnkoContext<ViewGroup>): View = with(ui) { | |
linearLayout { | |
layoutParams = LinearLayout.LayoutParams(matchParent, wrapContent) | |
if (flags && 8 >= 1) { | |
textView { | |
layoutParams = LinearLayout.LayoutParams(matchParent, dip(56)) | |
text = "Contact message" | |
} |
NewerOlder