Skip to content

Instantly share code, notes, and snippets.

View PabRod's full-sized avatar

Pablo Rodríguez-Sánchez PabRod

View GitHub Profile
@PabRod
PabRod / deco.R
Created July 28, 2021 10:22
Decorators in R
deco <- function(f) {
wrapper <- function(...) {
# <code prior to execution>
res <- f(...)
# <code after execution>
return(res)
}
@PabRod
PabRod / q-learning.py
Created July 24, 2019 14:02
Simple example of q-learning
# This gist reproduces the algorithm available at:
# http://mnemstudio.org/path-finding-q-learning-tutorial.htm
import numpy as np
import random
## Initialize q-table
Nstates = 6
Nactions = 6
Q = np.zeros((Nstates, Nactions))
# Your init script
#
# Atom will evaluate this file each time a new window is opened. It is run
# after packages are loaded/activated and after the previous editor state
# has been restored.
#
# An example hack to log to the console when each text editor is saved.
#
# atom.workspace.observeTextEditors (editor) ->
# editor.onDidSave ->
@PabRod
PabRod / encryptWithChaos.m
Last active January 25, 2018 17:58
An easy version of the method for using chaos to encrypt an audio message described in Strogatz's Nonlinear dynamics and chaos, 1994
%% Encrypt with chaos
% An easy version of the method for using chaos to encrypt an audio message
% described in Strogatz's Nonlinear dynamics and chaos, 1994
%
% More information at: <http://mappingignorance.org/2016/05/09/the-sound-of-chaos/>
%% Load the original sound
load handel;
sampling_freq = Fs;
@PabRod
PabRod / hearChaos.m
Last active August 12, 2020 13:01
A script for solving a Lorenz-like initial value problem and export the time series of each coordinate as a sound file
%% Hearing chaos
% How chaos sounds? In this script we will create a chaotic time series and
% translate it to a sound signal
%
% More information at: <http://mappingignorance.org/2016/05/09/the-sound-of-chaos/>
%% Harvest chaos from the Lorenz equation
% The Lorenz equation is the classical example of deterministic dynamical
% system giving rise to chaos. The equation reads:
%
@PabRod
PabRod / chirp.m
Created April 19, 2016 14:25 — forked from Enchufa2/chirp.m
Simulation of the chirp echo created in the staircases of Mesoamerican pyramids
clap = audioread('clap.wav');
fs = 96e3; % sampling frequency
N = 40; % steps
ssize = 0.15; % step size
delay = ssize * 2 / 340;
samples = round(delay * fs);
stairs = zeros(samples * N + length(clap) + N, N);
for i = 1:N
samples = samples + 1;
indexes = (i-1)*samples+1 : length(clap)+(i-1)*samples;