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
interface Array<T> { | |
mapAsync<U>(callbackfn: (value: T, index: number, array: T[]) => Promise<U>, thisArg?: any): Promise<U[]>; | |
} | |
Array.prototype.mapAsync = function<U>(callbackfn: (value: any, index: number, array: any[]) => Promise<U>, thisArg?: any): Promise<U[]> { | |
var promises = this.map((value: any, index: number, array: any[]) => callbackfn(value, index, array)); | |
return Promise.all(promises); | |
} |
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
var testArray = [[1,2,[3]],4]; | |
function flat(array) { | |
var result = []; | |
for(var i=0; i < array.length; i++) { | |
if(array[i] instanceof Array) { | |
result.push(...flat(array[i])); | |
} else { | |
result.push(array[i]); | |
} |
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
const buildCnn = function (data) { | |
return new Promise(function (resolve, reject) { | |
// Linear (sequential) stack of layers | |
const model = tf.sequential(); | |
// Define input layer | |
model.add(tf.layers.inputLayer({ | |
inputShape: [7, 1], | |
})); |
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
let array = [ | |
{ name: "Test Name 1", gender: "M", age: "28"}, | |
{ name: "Test Name 2", gender: "F", age: "29"}, | |
{ name: "Test Name 3", gender: "M", age: "35"}, | |
{ name: "Test Name 4", gender: "F", age: "38"} | |
]; | |
Array.prototype.groupBy = function(prop) { | |
return this.reduce((groups, item) => { | |
const val = item[prop]; |
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 string UsingTemplateFromEmbedded<T>(string path, T model) | |
{ | |
// Generate the template name | |
string templateName = GetTemplateName(path); | |
string template = memoryCache.Get<string>(templateName); | |
if(string.IsNullOrEmpty(template)) | |
{ | |
// Locking this resource is necessary since there are parallel requests to this methnod |
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
function [J grad] = nnCostFunction(nn_params, ... | |
input_layer_size, ... | |
hidden_layer_size, ... | |
num_labels, ... | |
X, y, lambda) | |
%NNCOSTFUNCTION Implements the neural network cost function for a two layer | |
%neural network which performs classification | |
% [J grad] = NNCOSTFUNCTON(nn_params, hidden_layer_size, num_labels, ... | |
% X, y, lambda) computes the cost and gradient of the neural network. The | |
% parameters for the neural network are "unrolled" into the vector |
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
function p = predict(Theta1, Theta2, X) | |
... | |
h1 = sigmoid([ones(m, 1) X] * Theta1'); | |
h2 = sigmoid([ones(m, 1) h1] * Theta2'); | |
[value, p] = max(h2, [], 2); | |
... |
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
... | |
options = optimset('MaxIter', 100); | |
... | |
% Now, costFunction is a function that takes in only one argument (the | |
% neural network parameters) | |
[nn_params, cost] = fmincg(costFunction, initial_nn_params, options); | |
% Obtain Theta1 and Theta2 back from nn_params | |
Theta1 = reshape(nn_params(1:hidden_layer_size * (input_layer_size + 1)), ... | |
hidden_layer_size, (input_layer_size + 1)); |
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
... | |
% Feedforward the neural network and return the cost in the variable J | |
summary = 0; | |
for j = 1:m | |
y_label = y(j,:); | |
a_one = X(j,:); | |
a_one = [1 a_one]; | |
z_one = a_one * Theta1'; |
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
function image_out = processSkinImage(filename) | |
Step 1... | |
% Read the image | |
original = imread(filename); | |
... | |
Step 2... | |
% Resize the image to 50x50 | |
image_resized = imresize(original, scale); | |
[M N Z] = size(image_resized); |
NewerOlder