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
# Word Count using Spark | |
# https://spark.apache.org/examples.html | |
text_file = sc.textFile("./sample.txt") //local file | |
counts = text_file.flatMap(lambda line: line.split(" ")) \ | |
.map(lambda word: (word, 1)) \ | |
.reduceByKey(lambda a, b: a + b) | |
counts.saveAsTextFile("./count_output") |
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
# Compute value of PI using Monte Carlo Approach | |
# Source: http://spark.apache.org/examples.html | |
NUM_SAMPLES = 1000000 | |
def inside(p): | |
x, y = random.random(), random.random() | |
return x*x + y*y < 1 | |
# filter: http://spark.apache.org/docs/latest/api/python/pyspark.html | |
count = sc.parallelize(range(0, NUM_SAMPLES),10) \ |
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
function [J, grad] = cofiCostFunc(params, Y, R, num_users, num_movies, ... | |
num_features, lambda) | |
% Unfold the U and W matrices from params | |
X = reshape(params(1:num_movies*num_features), num_movies, num_features); | |
Theta = reshape(params(num_movies*num_features+1:end), ... | |
num_users, num_features); | |
% You need to return the following values correctly | |
J = 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
function [mu sigma2] = estimateGaussian(X) | |
% To estimate parameters of Gaussian distribution using data | |
% Useful variables | |
[m, n] = size(X); | |
% You should return these values correctly | |
mu = zeros(n, 1); | |
sigma2 = zeros(n, 1); |
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
# Training Module of LSTM 2 layer stack | |
max_review_length = 600 | |
X_train = sequence.pad_sequences(X_train, maxlen=max_review_length) | |
X_test = sequence.pad_sequences(X_test, maxlen=max_review_length) | |
# To train the Model | |
def trainModel(model): | |
history = model.fit(numpy.array(X_train), numpy.array(y_train), \ |
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
# Speech Recognition Thread identifies the command from defined synonyms and inserting to stt Queue | |
def stopStream(stream_reader): | |
if stream_reader: | |
stream_reader.stop_stream() | |
stream_reader = None | |
def received_frames(frames, speech, stt): | |
speech.push_data(frames, finish_processing=False) |
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 os | |
import cv2 | |
from queue import Queue | |
from threading import Thread, Event | |
from audio import audio_helper | |
from speech_library.speech_manager import SpeechManager | |
from speech_library.speech_proxy import SPEECH_CONFIG |
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
# To detect wink from stream of eye images and print the sequence of Event trigger | |
while(runLoop): | |
for i in range (1000): | |
# read the image | |
image = cv2.imread("eyeImages_day/eye"+str(i) + ".jpg", 1) | |
# Convert to gray scale as histogram works well on 256 values. | |
gray = cv2.cvtColor(image, cv2.COLOR_BGR2GRAY) |
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
# Code to fit the inverse sigmoid curve to tail end of signal | |
def sigmoid(x, L ,x0, k, b): | |
y = L / (1 + np.exp(k*(x-x0)))+b | |
return (y) | |
def isCurveSigmoid(pixelCounts, count): | |
try: | |
xIndex = len(pixelCounts) |
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
# yaw and pitch are important for mouse control | |
poseArrowX = orientation[0] #* arrowLength | |
poseArrowY = orientation[1] #* arrowLength | |
# Taking 2nd and 3rd row for 2D Projection | |
############################# LEFT EYE ################################### | |
cv2.arrowedLine(frame, leftEye_Center, | |
(int((xCenter_left + arrowLength * (cosR * cosY + sinY * sinP * sinR))), | |
int((yCenter_left + arrowLength * cosP * sinR))), (255, 0, 0), 4) | |