Skip to content

Instantly share code, notes, and snippets.

View Ddedalus's full-sized avatar

Hubert Bereś Ddedalus

View GitHub Profile
@Ddedalus
Ddedalus / progres_bar.py
Created January 15, 2018 21:56
Terminal progress indicator "x out of y"
def progress_bar(current, total, what):
print('\r', current, "out of", total, what, end="", flush=True)
@Ddedalus
Ddedalus / decisionTreeLearning.py
Created February 1, 2018 17:48
Decision-tree-learning algorithm pseudocode
def decisionTreeLearning(examples, attributes, parent_examples):
if len(examples) == 0:
return pluralityValue(parent_examples)
# return most probable answer as there is no training data left
elif len(attributes) == 0:
return pluralityValue(examples)
elif (all examples classify the same):
return their classification
A = max(attributes, key(a)=importance(a, examples)
@Ddedalus
Ddedalus / zapsmall.Rmd
Created May 5, 2018 18:41
Avoid scientific view of numbers relatively close to zero
zapsmall(matrix)
@Ddedalus
Ddedalus / matplot.Rmd
Created May 5, 2018 18:56
Plot multiple series of data on the same plot
matplot(x, y_matrix_of_columns)
@Ddedalus
Ddedalus / graphWithDensity.Rmd
Last active May 7, 2018 17:13
Random graph with given density
graphWithDensity <- function(no_vertices, dens){
erdos.renyi.game(no_vertices, as.integer(no_vertices * dens), type="gnm",
directed = T) # Create a graph with given number of vertices and edges
}
g3 <- graphWithDensity(15, 2)
plot(g3)
@Ddedalus
Ddedalus / qqmath.Rmd
Created May 7, 2018 22:48
Fit discrete distribution and qq plot in R
library(fitdistrplus)
library(lattice)
in_geom_fit <- fitdist(in_deg, "geom")
summary(in_geom_fit)
plot(in_geom_fit)
quantiles <- seq(0, 1, 0.05)
qqmath(~in_deg, distribution=function(p){ qgeom(p, prob = in_geom_fit$estimate)}, main="Q-Q plot against geometric distribution", xlab = "geometirc from estimate")
@Ddedalus
Ddedalus / density.Rmd
Created May 7, 2018 22:59
Get density function out of data in R
{plot(density(in_deg), col=2) # where in_deg is a list of degrees - one obs. per verticle
lines(density(out_deg), col=3)}
@Ddedalus
Ddedalus / mutual.multiple.loop.Rmd
Created May 7, 2018 23:51
Check various patologies in a graph R
which_mutual(g5) %>% table
which_multiple(g5) %>% table
which_loop(g5) %>% table
@Ddedalus
Ddedalus / AssignAddin.R
Created May 10, 2018 15:40
A simple Addin template for R
AssignAddin <- function() {
rstudioapi::insertText(" <- ")
}
@Ddedalus
Ddedalus / corrtest.Rmd
Created May 12, 2018 15:33
Check correlation between in/out degrees
```{r}
plot(degree(g5, mode = "in"), degree(n5, mode = "out"), type = "p")
cor.test(degree(g5, mode = "in"), degree(g5, mode = "out"))
```