Skip to content

Instantly share code, notes, and snippets.

View hristo-vrigazov's full-sized avatar

Hristo Vrigazov hristo-vrigazov

View GitHub Profile
@hristo-vrigazov
hristo-vrigazov / Main.java
Last active December 30, 2020 10:45
Example compare Java
import java.util.ArrayList;
import java.util.List;
import java.util.Random;
public class Main {
public static void main(String[] args) {
List<Long> times = new ArrayList<>();
int numExperiments = 20;
long[] totals = new long[numExperiments];
Random random = new Random();
@hristo-vrigazov
hristo-vrigazov / example_compare.py
Created December 30, 2020 10:37
Python example compare
import numpy as np
from time import time
num_experiments = 20
totals = np.zeros(num_experiments)
for i in range(num_experiments):
start = time()
arr = np.random.randint(0, 1000, size=100000000, dtype=np.int32)
print('Generation took ', time() - start)
start = time()
@hristo-vrigazov
hristo-vrigazov / linspace_external.py
Last active September 1, 2019 07:40
Linspace external
import tensorflow as tf
def tf_repeat(tensor, repeats, axis):
shape = tf.shape(tensor)
axis_range = tf.range(shape.shape[0].value)
ones = tf.ones_like(axis_range)
repeats_tiled = tf.fill(tf.shape(axis_range), repeats)
axis_tiled = tf.fill(tf.shape(axis_range), axis)
mask = tf.equal(axis_range, axis_tiled)
@hristo-vrigazov
hristo-vrigazov / fmi_frogs_ai.py
Created October 7, 2017 12:10
FMI homework with frogs
import sys
signs_map = {
'>': 1,
'<': -1,
'_': 0
}
reverse_signs_map = {
0: '_',
@hristo-vrigazov
hristo-vrigazov / disambiguate.pl
Created January 5, 2017 13:05
Word sense disambiguation using Problog
0.9::attribute_value(brown, brand).
0.9::attribute_value(brown, color).
0.9::attribute_value(tv, noun).
0.9::attribute_value(dress, clothing).
member(X, [Y|T]) :- X = Y; member(X, T).
item_prop(1, brown, brand).
item_prop(1, tv, noun).
@hristo-vrigazov
hristo-vrigazov / chrome_headless.java
Created December 7, 2016 15:17
Starting Chrome in headless mode
package config;
import java.io.File;
import java.io.IOException;
import org.junit.Test;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.chrome.ChromeDriver;
import org.openqa.selenium.chrome.ChromeDriverService;
@hristo-vrigazov
hristo-vrigazov / load_dataset.py
Created December 3, 2016 21:15
Loading dataset for traffic sign classification
# Load pickled data
import pickle
import os.path
import os
import wget
import cv2
import zipfile
import numpy as np
@hristo-vrigazov
hristo-vrigazov / longest_palindromic_substring.py
Last active December 7, 2016 15:17
Longest palindromic substring in quadratic time O(n^2)
def longestPalindrome(self, s):
"""
:type s: str
:rtype: str
"""
best_palindrome_length = 1
best_palindrome = s[0]
n = len(s)
for i in range(2 * n - 1):
@hristo-vrigazov
hristo-vrigazov / basic_thresholding.py
Created November 29, 2016 05:43
Lane detection using simple thresholding
import matplotlib.pyplot as plt
import matplotlib.image as mpimg
import numpy as np
# Read in the image and print out some stats
# Note: in the previous example we were reading a .jpg
# Here we read a .png and convert to 0,255 bytescale
image = (mpimg.imread('test.png')*255).astype('uint8')
print('This image is: ',type(image),
'with dimensions:', image.shape)
@hristo-vrigazov
hristo-vrigazov / hmm.pl
Created November 6, 2016 22:02
Hidden Markov Model in Problog with revealing comments
% Hidden Markov Model example
% The weather can be in state "sun" or "rain" initially
% with 0.5 probabilities for each state
0.5::start(weather, sun);
0.5::start(weather, rain).
% In a given moment in time, if today is sunny - "sun",
% tommorrow will be 0.6 sun or 0.4 rain
0.6::trans(weather, Moment_in_time, sun, sun);