Skip to content

Instantly share code, notes, and snippets.

@jjallaire
jjallaire / .gitignore
Last active November 2, 2023 14:19 — forked from wch/retirement-logo.png
Retirement simulation Quarto Shiny app
env/
__pycache__/
*-app.py
*_files/
*.html
@jjallaire
jjallaire / multiplicative_lstm.R
Created October 26, 2018 13:15
Custom Multiplicative LSTM Layer for R Keras
library(keras)
library(reticulate)
layer_multiplicative_lstm <-function(
object, units, activation = "tanh", recurrent_activation = "hard_sigmoid", use_bias = TRUE,
return_sequences = FALSE, return_state = FALSE, go_backwards = FALSE, stateful = FALSE, unroll = FALSE,
kernel_initializer = "glorot_uniform", recurrent_initializer = "orthogonal", bias_initializer = "zeros",
unit_forget_bias = TRUE, kernel_regularizer = NULL, recurrent_regularizer = NULL, bias_regularizer = NULL,
from keras.models import Model
from keras import layers
from keras import Input
text_vocabulary_size = 10000
question_vocabulary_size = 10000
answer_vocabulary_size = 500
text_input = Input(shape=(None,), dtype='int32', name='text')
embedded_text = layers.Embedding(
'''Train MNIST with tfrecords yielded from a TF Dataset
In order to run this example you should first run 'mnist_to_tfrecord.py'
which will download MNIST data and serialize it into 3 tfrecords files
(train.tfrecords, validation.tfrecords, and test.tfrecords).
This example demonstrates the use of TF Datasets wrapped by a generator
function. The example currently only works with a fork of keras that accepts
`workers=0` as an argument to fit_generator, etc. Passing `workers=0` results
in the generator function being run on the main thread (without this various
@jjallaire
jjallaire / reveal.Rmd
Created March 24, 2016 14:14
reveal.js with custom css
---
title: "Untitled"
output:
revealjs::revealjs_presentation:
css: styles.css
---
## R Markdown
This is an R Markdown presentation. Markdown is a simple formatting syntax for authoring HTML, PDF,
@jjallaire
jjallaire / reveal-dygraph.Rmd
Created January 20, 2016 13:07
dygraphs with reveal.js
---
title: "Untitled"
output: revealjs::revealjs_presentation
---
## R Markdown
This is an R Markdown presentation. Markdown is a simple formatting syntax for authoring HTML, PDF, and MS Word documents. For more details on using R Markdown see <http://rmarkdown.rstudio.com>.
When you click the **Knit** button a document will be generated that includes both content as well as the output of any embedded R code chunks within the document.
@jjallaire
jjallaire / gist:008622dabd5730cf74cf
Created March 26, 2015 21:58
UTF8 CharacterVector
#include <Rcpp.h>
using namespace Rcpp;
// [[Rcpp::export]]
CharacterVector asUTF8(CharacterVector x) {
const void *vmax = vmaxget();
CharacterVector xUTF8(x.length());
for (int i = 0; i<x.length(); i++) {
const char* utf8 = Rf_translateCharUTF8(x[i]);
xUTF8[i] = Rf_mkCharCE(utf8, CE_UTF8);
@jjallaire
jjallaire / gist:bfc84ce7dd566a0a7231
Created February 17, 2015 22:15
custom finalizer
#include <Rcpp.h>
using namespace Rcpp;
void finalizeInt(int* ptr) {
// do nothing
}
typedef XPtr<int,PreserveStorage,finalizeInt> XPtrInt;
// [[Rcpp::export]]
@jjallaire
jjallaire / gist:ded5279b9c552ece9917
Created February 4, 2015 17:22
boost function and boost bind
#include <Rcpp.h>
using namespace Rcpp;
// [[Rcpp::depends(BH)]]
#include <boost/bind.hpp>
#include <boost/function.hpp>
typedef boost::function<int(int,int)> Combiner;
int add(int x, int y) {
@jjallaire
jjallaire / uniform.cpp
Created December 28, 2014 20:46
Rcpp modules with sourceCpp
#include <Rcpp.h>
using namespace Rcpp;
using namespace Rcpp;
class Uniform {
public:
Uniform(double min_, double max_) : min(min_), max(max_) {}
NumericVector draw(int n) const {
RNGScope scope;
return runif( n, min, max );