Skip to content

Instantly share code, notes, and snippets.

@sudo-ben
sudo-ben / naive_bayes.rs
Last active August 27, 2019 12:31
Naive bayes classifier Rust
/// Author Ben McDonald. Adapted from python scikit-learn
///
/// Naive bayes is a machine learning classifier. It uses bayes formula to classify data
/// based on how well data fits into normal distributions modeled from training data
use rulinalg::matrix::BaseMatrix;
use rulinalg::matrix::BaseMatrixMut;
use rulinalg::matrix::{Axes, Matrix};
use std::collections::HashMap;
use std::error::Error;
use std::f64::consts::PI;
from time import time
_MAX_AREA_FLUCTUATION = 0.6 #percent
_STONG_FRAME_COUNT = 20
_OBJECT_TIMEOUT = 3 #seconds
class TrackedObject(object):
"""
A class to track objects detected in a frame. The class logs frame
locations an object is detected and calculates an area the object is
'''
This program is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANy WARRANTy; without even the implied warranty of
MERCHANTABILITy or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
you should have received a copy of the GNU General Public License
@sudo-ben
sudo-ben / detectDataURL.js
Last active June 16, 2016 07:28 — forked from bgrins/detectDataURL.js
Detect if a string is a data URL. Doesn't try to parse it or determine validity, just a quick check if a string appears to be a data URL. See http://jsfiddle.net/bgrins/aZWTB/ for a demo.
function isDataURL(s) {
var commaIndex = s.indexOf(',');
if (commaIndex === -1) {
return false;
} else {
try {
window.atob(s.slice(commaIndex + 1));
return true;