This file contains 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
# Benchmarking a call to 'Inequality.gini' without weights, | |
# and with a vector of 1s as weights. | |
using BenchmarkTools | |
using Inequality | |
v = rand(1:10000, 300) | |
w = repeat([1], 300) | |
@benchmark gini($v) evals=15 |
This file contains 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
##### Atkinson index ##### | |
""" | |
wtd_atkinson(v, w, ϵ) | |
Computes the weighted Atkinson index given an inequality adversion parameter ϵ. | |
""" | |
function wtd_atkinson(v::Array{<:Real,1}, w::Array{<:Real,1}, ϵ::Real)::Float64 | |
norm_mean!(v) | |
w = w/sum(w) | |
This file contains 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
##### Atkinson index ##### | |
""" | |
atkinson(v, w, ϵ) | |
Computes the weighted Atkinson index given an inequality adversion parameter ϵ. | |
""" | |
function wtd_atkinson(v::Array{<:Real,1}, w::Array{<:Real,1}, ϵ::Real) ::Float64 | |
v = v/Statistics.mean(v) | |
w = w/sum(w) | |
This file contains 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
library(tidyverse) | |
library(magrittr) | |
library(bench) | |
julia_weighted_atkinson_function <- JuliaCall::julia_eval("function weighted_atkinson(v, w, ϵ::Real, skipmissing::Bool) | |
if skipmissing | |
w = w[findall(!ismissing, v)] | |
v = v[findall(!ismissing, v)] | |
end | |
v = v/Statistics.mean(v) |
This file contains 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
weighted_atkinson_jl <- function(x, weights, epsilon, na.rm = FALSE){ | |
JuliaCall::julia_call("weighted_atkinson", x, weights, epsilon, na.rm) | |
} | |
julia_weighted_atkinson_function <- JuliaCall::julia_eval("function weighted_atkinson(v, w, ϵ::Real, skipmissing::Bool) | |
if skipmissing | |
w = w[findall(!ismissing, v)] | |
v = v[findall(!ismissing, v)] |
This file contains 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
#' Weighted quantiles | |
#' | |
#' Wrap over Julia's 'StatsBase.quantile()' function. | |
#' | |
#' @param x A numeric vector for which the quantiles should be computed. | |
#' @param weights A numeric vector with the weights. | |
#' @param probs A numeric vector with the quantiles to compute. | |
#' @param na.rm a logical value indicating whether NA values should be stripped before the computation proceeds. | |
#' | |
#' @return A numeric vector with the weighted quantiles. |
This file contains 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
import re | |
def backward_string_by_word(text: str) -> str: | |
spaces = re.findall(" +", text) | |
words = text.split() | |
if len(words) == 0: |
This file contains 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
library(readr) | |
library(dplyr) | |
library(magrittr) | |
library(purrr) | |
library(ggplot2) | |
all_lissyrtools_scripts <- fs::dir_ls("/media/user/lissyrtools/") | |
invisible(purrr::map(all_lissyrtools_scripts, ~ source(.x))) | |
This file contains 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
# Prepare session | |
library(rlang) | |
library(glue) | |
library(fs) | |
library(dplyr) | |
library(magrittr) | |
library(purrr) | |
library(ggplot2) | |
This file contains 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
#' Compute gini index. | |
#' | |
#' Compute the gini index with (optional) weights. | |
#' | |
#' @param x A numeric vector with the data. | |
#' @param weights A numeric vector with sample weights. | |
#' @return res An atomic vector with the gini index. | |
gini <- function(x, weights = NULL, na.rm = FALSE) { | |