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
def turbo_bmh(string, pattern): | |
""" | |
Bad character heuristic, good suffix heuristic, turbo-shift heuristic implemented on Python | |
""" | |
def _suffices_preprocessing(suffix): | |
suffix[m - 1] = m | |
g = m - 1 | |
for i in range(m - 2, -1, -1): | |
if i > g and suffix[i + m - f - 1] < i - g: |
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
#!/usr/bin/env python | |
################################################################################ | |
# File name: pso.py # | |
# Description: A module that solves a minimization problem using PSO # | |
#------------------------------------------------------------------------------# | |
# Author: Hussein S. Al-Olimat # | |
# Email: [email protected] # | |
#------------------------------------------------------------------------------# | |
# Date-last-modified: Nov 7, 2016 # |
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
class BoyerMoore: | |
def __init__(self, text, pattern): | |
self.text = text | |
self.pattern = pattern | |
self.m = len(pattern) | |
self.n = len(text) | |
self.skip = [] | |
for i in range(256): self.skip.append(-1) | |
for i in range(self.m): self.skip[ord(pattern[i])] = self.m |
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
import torch | |
def confusion(prediction, truth): | |
""" Returns the confusion matrix for the values in the `prediction` and `truth` | |
tensors, i.e. the amount of positions where the values of `prediction` | |
and `truth` are | |
- 1 and 1 (True Positive) | |
- 1 and 0 (False Positive) | |
- 0 and 0 (True Negative) |
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
% Load training data. | |
imageDir = fullfile('training_data'); | |
labelDir = fullfile('label_data'); | |
% Create an image datastore for the images. | |
imds = imageDatastore(imageDir, 'IncludeSubfolders',true, ... | |
'LabelSource','foldernames'); | |
% Create a pixelLabelDatastore for the ground truth pixel labels. |
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
class last_occurrence(object): | |
"""Last occurrence functor.""" | |
def __init__(self, pattern, alphabet): | |
"""Generate a dictionary with the last occurrence of each alphabet | |
letter inside the pattern. | |
Note: This function uses str.rfind, which already is a pattern | |
matching algorithm. There are more 'basic' ways to generate this | |
dictionary.""" |
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
# Boyer Moore String Search implementation in Python | |
# Ameer Ayoub <[email protected]> | |
# Generate the Bad Character Skip List | |
def generateBadCharShift(term): | |
skipList = {} | |
for i in range(0, len(term)-1): | |
skipList[term[i]] = len(term)-i-1 | |
return skipList |