This file contains hidden or 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
## Empty list -- just use the empty environment for this. | |
nil <- function() { | |
emptyenv() | |
} | |
## Test if a list is the empty list: | |
is_empty <- function(lis) { | |
identical(lis, nil()) | |
} |
This file contains hidden or 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 sys | |
import numpy as np | |
import networkx as nx | |
import matplotlib.pyplot as plt | |
def plot(data,filename,degreetype): | |
""" Plot Distribution """ | |
plt.plot(range(len(data)),data,'bo') | |
plt.yscale('log') | |
plt.xscale('log') |
This file contains hidden or 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
tanimoto <- function(x, similarity=F) { | |
res<-sapply(x, function(x1){ | |
sapply(x, function(x2) {i=length(which(x1 & x2)) / length(which(x1 | x2)); ifelse(is.na(i), 0, i)}) | |
}) | |
if(similarity==T) return(res) | |
else return(1-res) | |
} | |
x <- data.frame(Samp1=c(0,0,0,1,1,1,0,0,1), Samp2=c(1,1,1,1,1,1,0,0,1), Samp3=c(1,0,0,1,0,0,0,0,0), Samp4=c(1,1,1,1,1,1,1,1,1)) | |
tanimoto(x) |
This file contains hidden or 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
printname c.entry file line_no | |
- do_arith R-4.0.3\src\main\arithmetic.c 411 | |
! do_logic R-4.0.3\src\main\logic.c 40 | |
!= do_relop R-4.0.3\src\main\relop.c 51 | |
$ do_subset3 R-4.0.3\src\main\subset.c 1206 | |
$<- do_subassign3 R-4.0.3\src\main\subassign.c 2081 | |
%% do_arith R-4.0.3\src\main\arithmetic.c 411 | |
%*% do_matprod R-4.0.3\src\main\array.c 1228 | |
%/% do_arith R-4.0.3\src\main\arithmetic.c 411 | |
& do_logic R-4.0.3\src\main\logic.c 40 |
This file contains hidden or 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(INLA) | |
m = 50 | |
points = matrix(runif(m*2), m, 2) | |
mesh = inla.mesh.2d(loc=points,cutoff=0.05,offset=c(0.1, 0.4),max.edge=c(0.05, 0.5) ) | |
bnd = inla.nonconvex.hull(points, convex=0.12) | |
mesh = inla.mesh.2d(boundary=bnd,cutoff=0.05,offset = c(1, 0.5),max.edge=c(0.1, 0.5) ) | |
A = inla.spde.make.A(mesh, loc=points) | |
sigma0 = 1 ## Field std.dev. for theta=0 | |
size = min(c(diff(range(mesh$loc[,1])), diff(range(mesh$loc[,2])))) | |
range0 = size/5 ## A fifth of the approximate domain width. |
This file contains hidden or 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
abstract Person | |
type Adult <: Person | |
age::Int | |
height::Float64 | |
position::Int | |
end | |
type Child <: Person | |
age::Int |
This file contains hidden or 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
# Find all CRAN package with FORTRAN code | |
packages <- c() | |
base_url <- 'https://api.github.com/search/repositories?q=user:cran%20language:fortran' | |
for(page in 1:100){ | |
url <- paste0(base_url, "&page=", page) | |
cat("Reading", url, "\n") | |
repos <- jsonlite::fromJSON(url) | |
if(!length(repos$items)) | |
break | |
packages <- c(packages, repos$items$name) |
This file contains hidden or 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
# function needed for visualization purposes | |
sigmoid = function(params, x) { | |
params[1] / (1 + exp(-params[2] * (x - params[3]))) | |
} | |
x = 1:53 | |
y = c(0,0,0,0,0,0,0,0,0,0,0,0,0,0.1,0.18,0.18,0.18,0.33,0.33,0.33,0.33,0.41, | |
0.41,0.41,0.41,0.41,0.41,0.5,0.5,0.5,0.5,0.68,0.58,0.58,0.68,0.83,0.83,0.83, | |
0.74,0.74,0.74,0.83,0.83,0.9,0.9,0.9,1,1,1,1,1,1,1) |
This file contains hidden or 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
#Load library mass and set seed | |
library(MASS) | |
set.seed(100) | |
# We are going to use 3 random variables | |
m <- 3 | |
# Number of samples to be drawn | |
n <- 2000 |
This file contains hidden or 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(ggraph) | |
library(gganimate) | |
library(igraph) | |
# Data from http://konect.uni-koblenz.de/networks/sociopatterns-infectious | |
infect <- read.table('out.sociopatterns-infectious', skip = 2, sep = ' ', stringsAsFactors = FALSE) | |
infect$V3 <- NULL | |
names(infect) <- c('from', 'to', 'time') | |
infect$timebins <- as.numeric(cut(infect$time, breaks = 100)) | |
# We want that nice fading effect so we need to add extra data for the trailing |