This file contains 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
""" | |
Helper to convert GPX files to CSV files for analysis. | |
Created by Trevor Phillips | |
""" | |
import os | |
import json | |
try: |
This file contains 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
private func sampleNormalDist(withMean mean: Double, std: Double) -> Double { | |
precondition(std > 0) | |
let first = Double(rng.nextUniform()) | |
let second = Double(rng.nextUniform()) | |
let zScore = sqrt(-2 * log(first)) * cos(2 * Double.pi * second) | |
return zScore * std + mean | |
} |
This file contains 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
func addNoise(to trueLocation: CLLocation) -> CLLocation { | |
let distanceWiggle = sampleNormalDist(withMean: 0, std: 0.952) | |
let xContribution = rng.nextUniform() | |
let xoff = distanceWiggle * Double(xContribution) | |
let yoff = distanceWiggle * sqrt(1 - pow(Double(xContribution), 2)) | |
let newCoord = trueLocation.coordinate.offsetBy(xMeters: xoff, yMeters: yoff) | |
let newHacc = sampleNormalDist(withMean: 7.179, std: 1.682) | |
let newVacc = sampleNormalDist(withMean: 3.643, std: 0.300) | |
let timeWiggle = sampleNormalDist(withMean: 1.00, std: 0.131) |
This file contains 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
struct Scenario { | |
/// A sequence of CLLocations representing the "true path" of the GPS track | |
let truePath: [CLLocation] | |
/// A sequence of CLLocations based on the true path, but with noise added to various parameters | |
let noisyPath: [CLLocation] | |
/// A number between 0.0-1.0 representing the minimum allowable percentage difference between |
This file contains 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
enum PathType: String, CaseIterable { | |
case outAndBack, loop | |
} | |
enum Distance: Double, CaseIterable { | |
case short = 1000 // in meters | |
case medium = 5000 | |
case long = 15000 | |
} |
This file contains 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 Foundation | |
import CoreLocation | |
extension CLLocation { | |
// Alias for `horizontalAccuracy` (more readable) | |
var uncertainty: Double { | |
return horizontalAccuracy | |
} | |
} |
This file contains 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
func checkScenario(_ scenario: Scenario) { | |
let filter = KalmanFilter() | |
// Add up the distance between each location in the true path | |
let trueDist = unfilteredDistance(scenario.truePath) | |
// Add up the distance between each location in the noisy path | |
let unfilteredDist = unfilteredDistance(scenario.noisyPath) | |
This file contains 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
#include <stdio.h> | |
#include <stdlib.h> | |
#include <stdint.h> | |
#ifdef _MSC_VER | |
#include <intrin.h> /* for rdtscp and clflush */ | |
#pragma optimize("gt",on) | |
#else | |
#include <x86intrin.h> /* for rdtscp and clflush */ | |
#endif |