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
use std::collections::HashMap; | |
//use std::sync::Mutex; | |
use std::sync::Arc; | |
use std::thread; | |
pub fn frequency(input: &[&str], worker_count: usize) -> HashMap<char, usize> { | |
let input_len = input.len(); | |
let lines_per_thread = ((input_len as f64) / (worker_count as f64)).ceil() as usize; | |
let mut thread_handles = vec![]; |
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 LeftRotate(i, r, bitSize) { | |
if (i.isNegative()){ | |
//take twos complement representation | |
i=bigInt(1).shiftLeft(32).subtract(i.abs()).and(bigInt("00000000ffffffff",16)); | |
var mask=bigInt(1).shiftLeft(bitSize).subtract(1); | |
var x=i.shiftLeft(r).or(i.shiftRight(bitSize-r)).and(mask); | |
var x_arr=x.toArray(2) | |
var neg=false | |
if (x_arr['value'][0]==1){ | |
//convert back |
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 p = predictOneVsAll(all_theta, X) | |
%PREDICT Predict the label for a trained one-vs-all classifier. The labels | |
%are in the range 1..K, where K = size(all_theta, 1). | |
% p = PREDICTONEVSALL(all_theta, X) will return a vector of predictions | |
% for each example in the matrix X. Note that X contains the examples in | |
% rows. all_theta is a matrix where the i-th row is a trained logistic | |
% regression theta vector for the i-th class. You should set p to a vector | |
% of values from 1..K (e.g., p = [1; 3; 1; 2] predicts classes 1, 3, 1, 2 | |
% for 4 examples) |
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 [all_theta] = oneVsAll(X, y, num_labels, lambda) | |
%ONEVSALL trains multiple logistic regression classifiers and returns all | |
%the classifiers in a matrix all_theta, where the i-th row of all_theta | |
%corresponds to the classifier for label i | |
% [all_theta] = ONEVSALL(X, y, num_labels, lambda) trains num_labels | |
% logisitc regression classifiers and returns each of these classifiers | |
% in a matrix all_theta, where the i-th row of all_theta corresponds | |
% to the classifier for label i | |
% Some useful variables |
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] = costFunctionReg(theta, X, y, lambda) | |
%COSTFUNCTIONREG Compute cost and gradient for logistic regression with regularization | |
% J = COSTFUNCTIONREG(theta, X, y, lambda) computes the cost of using | |
% theta as the parameter for regularized logistic regression and the | |
% gradient of the cost w.r.t. to the parameters. | |
% Initialize some useful values | |
m = length(y); % number of training examples | |
% You need to return the following variables correctly |