Skip to content

Instantly share code, notes, and snippets.

View Athospd's full-sized avatar
🏠
Working from home

Athos Petri Damiani Athospd

🏠
Working from home
View GitHub Profile
#!/bin/bash
sudo apt-get update -y
sudo apt-get upgrade -y
sudo apt install -y --no-install-recommends software-properties-common dirmngr
wget -qO- https://cloud.r-project.org/bin/linux/ubuntu/marutter_pubkey.asc | sudo tee -a /etc/apt/trusted.gpg.d/cran_ubuntu_key.asc
sudo add-apt-repository "deb https://cloud.r-project.org/bin/linux/ubuntu $(lsb_release -cs)-cran40/"
sudo apt install -y r-base r-base-core r-recommended r-base-dev
sudo apt install -y libssl1.1
#include <Rcpp.h>
#include <memory>
using namespace Rcpp;
// A simple class for testing ----------------------------
class A{
public:
int value;
A(int x);
};
@Athospd
Athospd / learning_rate_effect
Created April 15, 2023 22:03
Ilustration of the learning rate on a model fit
model_gen <- function(lr) {
lin <- nn_linear(2, 1) #b0 e b1
opt <- torch::optim_adam(lin$parameters, lr = lr)
return(list(lin = lin, opt = opt))
}
model_fit <- function(model) {
model$opt$zero_grad()
pred <- model$lin(x) # b0 + b1*x
@Athospd
Athospd / cartao_corporativo_presidentes_do_brasil.qmd
Last active January 13, 2023 22:31
Gastos dos cartoes corporativos dos presidentes do BR entre 2003 e 2022
---
title: "Cartao Corporativo dos Presidentes do Brasil - 2003 a 2022"
author: "Athos Damiani"
---
```{r}
library(tidyverse)
library(lubridate)
```
@Athospd
Athospd / nuinvest.R
Created April 30, 2022 16:26
scrapper and summary for my nuinvest stock transactions
library(httr)
library(purrr)
library(tidyverse)
# Sys.setenv(EASYNVEST_AUTH_TOKEN = "Bearer eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJuYmYiOjE2NTEyNjU5NjMsImV4cCI6MTY1MTI5NDc2MywiaXNzIjoiaHR0cHM6Ly9hcGkuZWFzeW52ZXN0LmNvbS5ici9hdXRoIiwiYXVkIjpbImh0dHBzOi8vYXBpLmVhc3ludmVzdC5jb20uYnIvYXV0aC9yZXNvdXJjZXMiLCJodHRwczovL3d3dy5lYXN5bnZlc3QuY29tLmJyIl0sImNsaWVudF9pZCI6Ijg3NmRhYjIxOTA0NjQ4ODRiZjliMDkyYWExNDA3NTg1Iiwic3ViIjoiMzIzNzM3NjI4MDMiNsaWVudElkXCI6XCI4NzZkYWIyMTkwNDY0ODg0YmY5YjA5MmFhMTQwNzU4NVwiLFwiTmFtZVwiOlwiUG9ydGFsL0hvbWUgQnJva2VyXCIsXCJJbnRlcm5hbFwiOmZhbHNlfSIsImNpYSI6Ijo6ZmZmZjoxMC42NS43Mi4xNjgiLCJkZXZpY2VfaWQiOiI0ZmZhNjYwNDAzYWZlOGM2OTU2YWI5MzkxZDhjOWJlYSIsInNjb3BlIjpbIm9wZW5pZCIsImh0dHBzOi8vd3d3LmVhc3ludmVzdC5jb20uYnIiLCJvZmZsaW5lX2FjY2VzcyJdLCJhbXIiOlsicGFzc3dvcmQiXX0.WsLEshN75bVckTKOX5HGHRpTVPcvmbahb77Ko6qs_Ho")
notas_de_negociacao <- function(
end_date = lubridate::today() - lubridate::days(1),
start_date = as.Date(end_date) - lubridate::days(89)
) {
---
title: "Kaggle: Guess The Correlation (feat. {torchdatasets})"
date: "2021-01-10"
tags: ["torch", "deep learning", "r", "machine learning"]
categories: ["tutoriais", "r"]
banner: "img/banners/guess-the-correlation.png"
author: ["Athos"]
summary: "Solução para o Kaggle Guess The Correlation com {torch}."
draft: true
editor_options:
animation::saveGIF({
f <- function(t, l = 1) (t>0)*exp(-t*l)
h <- function(t) as.numeric(abs(t) < 1)
g <- function(t, tau = seq(-2,10,l=1000)) mean(f(tau) * h(t-tau))
par(mfrow = c(2,1))
tau <- seq(-2,10,l=1000)
ts <- seq(-2,10,l=100)
gs <- c()
library(torch)
library(mvtnorm)
library(datasauRus)
set.seed(42)
# x <- mvtnorm::rmvnorm(100, c(1,2), sigma = matrix(c(1.2,1,1,1.1), 2))
plot(x)
x <- as.matrix(datasauRus::datasaurus_dozen[datasaurus_dozen$dataset == "dino",c("x", "y")])
x <- torch_tensor(x)
f <- function(x) cos(x*20)
expi <- function(x) cos(x) + sin(x)*1i
par(mfrow = c(1,2))
L <- 40
medias_Re <- c()
fs <- c()
as <- seq(0.01, 1, l = 140)
animation::saveGIF({
for(a in as) {
library(magrittr)
a <- system.file("waves_yesno/1_1_0_1_1_0_1_1.wav", package = "torchaudio")
# mp3 ---------------------------------------------------------------------
a <- system.file("sample_audio_1.mp3", package = "torchaudio")
mp3_bm <- bench::mark(
torchaudio:::av_read_mp3_or_wav(a) %>% torchaudio::transform_to_tensor(),
torchaudio:::tuneR_read_mp3_or_wav(a) %>% torchaudio::transform_to_tensor(),
torchaudio:::av_read_mp3_or_wav(a),