Skip to content

Instantly share code, notes, and snippets.

View gognjanovski's full-sized avatar
🏠
Working from home

Gavril Ognjanovski gognjanovski

🏠
Working from home
View GitHub Profile
@gognjanovski
gognjanovski / arrayMapAsync.ts
Created March 24, 2021 12:12
Asynchronous Map function extension for the Array interface
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);
}
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]);
}
@gognjanovski
gognjanovski / buildCnn
Created February 18, 2019 16:04
Building CNN (Convolutional Neural Network) with Tensorflow.JS
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],
}));
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];
...
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
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
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);
...
...
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));
@gognjanovski
gognjanovski / nnCostFunction_Feedforward.m
Last active December 14, 2018 09:25
Feedforward Neural Network Cost Function
...
% 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';
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);