Skip to content

Instantly share code, notes, and snippets.

#Monte Carlo Integration
#Example taken from Miranda and Fackler, Chapter 5, page 94
#We want to computer the following integral:
# \int_{-1}^1 \int_{-1}^1 \exp(-x_1) * cos (x_2^2)dx_1 dx_2
#which should be equal to 4.25199
import numpy as np
cimport numpy as np
cimport cython
@cython.boundscheck(False)
@cython.wraparound(False)
def my_cum_sum_memv(double[:, ::1] A,
double[:, ::1] B):
cdef int i, j, lA, lB
cimport cython
cdef class MatOpC:
#no need to declare the matrices anymore, they're declared inside the pxd file
#cdef public double[:, ::1] matA, matB
def __init__(self, A, B):
self.matA = A
self.matB = B
cimport cython
from MatOpC cimport MatOpC
@cython.boundscheck(False)
@cython.wraparound(False)
cdef class wrapclass:
cdef public MatOpC matopobj
def __init__(self, matopobj):
cdef class MatOpC:
cdef public double[:, ::1] matA, matB
cpdef cumsumC(self)
> library(janitor)
> get_dupes
function (dat, ...)
{
names <- as.list(substitute(list(...)))[-1L]
df_name <- deparse(substitute(dat))
var_names <- names
if (is.list(var_names)) {
var_names <- lapply(names, deparse)
}
@b-rodrigues
b-rodrigues / counter.R
Last active April 10, 2017 12:16
Create a "counter" variable that gets incremented by one for each occurence of interest
library(dplyr)
data("iris")
# At the first occurence of, say, Petal.Length = 1 and Petal.Width = 1, counter = 1. If Petal.Length = 1 and Petal.Width = 1 occur
# again, counter gets incremented to 2
iris %>%
group_by(Petal.Length, Petal.Width) %>%
mutate(counter = seq_along(Species))
Date,Poids
2013-10-28,84.1
2013-11-11,85.6
2013-11-24,85.2
2013-12-02,84.4
2013-12-30,83.5
2014-01-10,82.4
2014-02-08,83.5
2015-03-24,83
2015-03-28,82.7
@b-rodrigues
b-rodrigues / tidy_grid_search.R
Created November 15, 2018 09:09
Searching for the optimal hyper-parameters of an ARIMA model in parallel: the tidy gridsearch approach
library(tidyverse)
library(forecast)
library(lubridate)
library(tsibble)
library(brotools)
ihs <- function(x){
log(x + sqrt(x**2 + 1))
}
@b-rodrigues
b-rodrigues / gist:a22d2aa63dff01d88acc2916c003489d
Created January 4, 2019 22:42
1877-12-29_01-00004-alto.xml
<?xml version="1.0" encoding="UTF-8"?>
<alto xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns="http://www.loc.gov/standards/alto/ns-v3#" xmlns:xlink="http://www.w3.org/1999/xlink" xsi:schemaLocation="http://www.loc.gov/standards/alto/ns-v3# https://www.loc.gov/standards/alto/v3/alto-3-1.xsd">
<Description>
<MeasurementUnit>mm10</MeasurementUnit>
<sourceImageInformation>
<fileName>../tif/1877-12-29_01-00004.tif</fileName>
</sourceImageInformation>
<OCRProcessing ID="OCR1">
<ocrProcessingStep>
<processingStepSettings>