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
// | |
// main.cpp | |
// test2 | |
// a slightly less horrible logging class | |
// | |
// Created by Sean Wu on 12/17/18. | |
// Copyright © 2018 Sean Wu. All rights reserved. | |
// | |
/* ###################################################################### |
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
/* standard includes */ | |
#include <stdio.h> | |
#include <iostream> | |
/* hash-table */ | |
#include <unordered_map> | |
#include <string> /* for keys */ | |
class parameters { | |
public: |
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
# continuous time rate | |
R <- 1/5 | |
# mean time to next event in continuous time | |
mean(rexp(n = 1e6,rate = R)) | |
# get a discrete time rate to plug into Euler approximation of continuous time process | |
get_r <- function(R,dt){ | |
log(1 + R*dt) / dt | |
} |
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
# Simulation of NHPP (CTDE style) | |
# based on: https://freakonometrics.hypotheses.org/724 | |
# analytical functions from Mathematica | |
rm(list=ls());gc() | |
# intensity function | |
lambda <- function(x){ | |
100*(sin(x*pi)+1) | |
} |
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
/* the "vals" part of R's rle (run-length encoding) */ | |
Rcpp::IntegerVector rle_vals(const Rcpp::IntegerVector& x){ | |
int n = x.size(); | |
/* y */ | |
Rcpp::IntegerVector head = x[Rcpp::seq(1,n-1)]; | |
Rcpp::IntegerVector tail = x[Rcpp::seq(0,n-2)]; | |
Rcpp::LogicalVector y = head != tail; |
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
smooth_kernels <- function(distances, tol = .Machine$double.eps^0.75){ | |
d_ecdf <- stats::ecdf(distances) | |
d_knots <- stats::knots(d_ecdf) | |
d_pmf <- vapply(d_knots, function(x,tol){ | |
d_ecdf(x+.Machine$double.eps^0.75) - d_ecdf(x-.Machine$double.eps^0.75) | |
}, numeric(1), tol = tol) | |
# might want to check into isotonic regression here to force monotonic increasing fn for smooth CDF |
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
################################################################################ | |
# Definition 4 | |
################################################################################ | |
norm_for_Lp <- function(x,p){ | |
dnorm(x = x,mean = p,sd = 1,log = FALSE) | |
} | |
Lp <- function(p){ | |
integrate(f = norm_for_Lp,lower = -Inf,upper = Inf,p=p)$value |
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
// | |
// main.cpp | |
// main_only_test | |
// | |
// Created by Sean Wu on 7/24/18. | |
// Copyright © 2018 Sean Wu. All rights reserved. | |
// | |
#include <iostream> | |
#include <memory> |
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
/* | |
* still need to figure out how to more the lambda function into the class as a friend or something, | |
* it will be annoying to write lambdas all over the code... | |
*/ | |
#include <iostream> | |
#include <vector> | |
#include <memory> | |
#include <algorithm> |
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
// Example program | |
#include <iostream> | |
#include <string> | |
/* Release event */ | |
template <typename T> | |
class release { | |
public: | |
release(T x); /* constructor */ |