Skip to content

Instantly share code, notes, and snippets.

View NicolaBernini's full-sized avatar
🎯
Focusing

Nicola Bernini NicolaBernini

🎯
Focusing
View GitHub Profile
@NicolaBernini
NicolaBernini / main.cpp
Last active October 15, 2020 11:50
Boost Asio Deadline Timer - Repeating Async Wait Example
#include <iostream>
#include <boost/system/error_code.hpp>
#include <boost/asio.hpp>
#include <boost/bind.hpp>
#include <boost/date_time/posix_time/posix_time.hpp>
/**
* @brief The Timer Callback Function which reschedule the timer after 1 sec for 5 times
*/
void callback_func(const boost::system::error_code& e, boost::asio::deadline_timer* pt, int* pcont)
@NicolaBernini
NicolaBernini / readme.md
Last active April 23, 2017 09:32
[ML] - The Need for Non Linear Functions in Classification

Overview

An Artificial Neural Network (ANN) with a Multi-Layer Structure can be seen as a Cascade of Linear Combinations of Neurons Transfer Functions

In case of a Binary Classification Task the implicit goal for the ANN is to learn a Function which separates the ANN Input Space in 2 regions: one for each possible label. Let's call this function the Input Space Separation Function.

What if the Neuron Transfer Function would be linear ?

In that case the ANN would only be able to learn a Linear Input Space Separation Function hence

@NicolaBernini
NicolaBernini / loss_function1.ipynb
Created April 10, 2018 06:22
Loss Function - Basics - 2018-04-10
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
#include <stdio.h>
#include <fstream>
#include <stdexcept>
#include <memory>
class URL2File
{
@NicolaBernini
NicolaBernini / readme.md
Last active January 29, 2019 17:37
Solution to the Interval Coverage Detection Problem - Fusion Solution t_20190129_1832_1

Overview

This is a solution to the Interval Coverage Detection Problem, based on the idea of recursively fusing segments

More details in the Medium Article

@NicolaBernini
NicolaBernini / mnist.py
Created January 30, 2019 17:33
MNIST Access
import tensorflow as tf
from matplotlib import pyplot as plt
dataset = tf.keras.datasets.mnist
(x_train, y_train), (x_test, y_test) = dataset.load_data()
# Check it works by plotting a number
plt.imshow(x_train[0])
@NicolaBernini
NicolaBernini / example_hash.py
Last active February 1, 2019 12:31
Implementing Map using an Array and Simple Hashing
# Specs for Naive Hashing
# - Input: String
# - Output: Array id
# - Naive Hashing Function: sum all the string letters and mod for array size to get an id
def hash_str(in_str, in_lin_storage_size):
full_hash_val=0
if(type(in_str) is not str):
raise(ValueError("Arg1 needs to be string"))
for c in in_str:
@NicolaBernini
NicolaBernini / readme.md
Created April 7, 2019 09:23
Solution to get n-th from last element in a linked list

Overview

The problem is a generalization of the one explained in How to find the 3rd element from end in linked list in Java and basically consists of finding the element at position last - n in a Linked List which of course does not provide

  • Random Access Semantic

  • Length Semantic

but just the next() semantic

@NicolaBernini
NicolaBernini / conv.py
Created August 23, 2019 10:51
ConvFilter Kernel
# Defines a WxHxC ConvFilter
# Conventional Internal Representation is C,H,W
class Conv:
# w, h = Kernel Spatial Domain
# in_c = Input Tensor Channels
# out_c = Output Tensor Channels
def __init__(self, w, h, in_c, out_c):
self.w = w
self.h = h
@NicolaBernini
NicolaBernini / main.cpp
Last active August 26, 2019 13:11
Minimal element-wise comparison function in CPP for linear containers
#include <iostream>
#include <vector>
#include <array>
using namespace std;
// Performing element-wise comparison on a containers pair with the same number of elements and returning a vector where for the i-th position
// the -1 means the i-th element in the first is bigger than the i-th in second
// the +1 means the i-th element in the second is bigger than the i-th in the first
// the 0 means the i-th elements in first and second can not be ordered hence it is assumed they are equal (but no explicit use of the equal semantic is done)
template <typename T>