plotting scratchpad
This commit is contained in:
parent
32b8a1fe1a
commit
8547347ac6
12
examples/15_plotting-scratchpad/notes.md
Normal file
12
examples/15_plotting-scratchpad/notes.md
Normal file
|
@ -0,0 +1,12 @@
|
||||||
|
options:
|
||||||
|
- use gnuplot
|
||||||
|
- requires aggregation
|
||||||
|
- do aggregation in its own gnuplot language
|
||||||
|
- use something like awk
|
||||||
|
- use some other language, like python or R, specifically to do the aggregation
|
||||||
|
- do the aggregation in C
|
||||||
|
- use ggplot
|
||||||
|
- requires setting up bins correctly
|
||||||
|
- also can't pipe to an r script directly, sadly enough.
|
||||||
|
- use python for plotting?
|
||||||
|
- just present the confidence intervals in C?
|
0
examples/15_plotting-scratchpad/r/.Rhistory
Normal file
0
examples/15_plotting-scratchpad/r/.Rhistory
Normal file
7
examples/15_plotting-scratchpad/r/plot.R
Normal file
7
examples/15_plotting-scratchpad/r/plot.R
Normal file
|
@ -0,0 +1,7 @@
|
||||||
|
library(ggplot2)
|
||||||
|
|
||||||
|
data <- read.csv("samples.txt", header = FALSE)
|
||||||
|
data <- as.data.frame(data)
|
||||||
|
|
||||||
|
ggplot(data = data, aes(x = V1)) +
|
||||||
|
geom_freqpoly()
|
1000000
examples/15_plotting-scratchpad/r/samples.txt
Normal file
1000000
examples/15_plotting-scratchpad/r/samples.txt
Normal file
File diff suppressed because it is too large
Load Diff
BIN
examples/15_plotting-scratchpad/src/example
Executable file
BIN
examples/15_plotting-scratchpad/src/example
Executable file
Binary file not shown.
50
examples/15_plotting-scratchpad/src/example.c
Normal file
50
examples/15_plotting-scratchpad/src/example.c
Normal file
|
@ -0,0 +1,50 @@
|
||||||
|
#include "../../squiggle.h"
|
||||||
|
#include <stdint.h>
|
||||||
|
#include <stdio.h>
|
||||||
|
#include <stdlib.h>
|
||||||
|
|
||||||
|
// Estimate functions
|
||||||
|
double sample_0(uint64_t* seed)
|
||||||
|
{
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
double sample_1(uint64_t* seed)
|
||||||
|
{
|
||||||
|
return 1;
|
||||||
|
}
|
||||||
|
|
||||||
|
double sample_few(uint64_t* seed)
|
||||||
|
{
|
||||||
|
return sample_to(1, 3, seed);
|
||||||
|
}
|
||||||
|
|
||||||
|
double sample_many(uint64_t* seed)
|
||||||
|
{
|
||||||
|
return sample_to(2, 10, seed);
|
||||||
|
}
|
||||||
|
|
||||||
|
int main()
|
||||||
|
{
|
||||||
|
// set randomness seed
|
||||||
|
uint64_t* seed = malloc(sizeof(uint64_t));
|
||||||
|
*seed = 1000; // xorshift can't start with 0
|
||||||
|
|
||||||
|
double p_a = 0.8;
|
||||||
|
double p_b = 0.5;
|
||||||
|
double p_c = p_a * p_b;
|
||||||
|
|
||||||
|
int n_dists = 4;
|
||||||
|
double weights[] = { 1 - p_c, p_c / 2, p_c / 4, p_c / 4 };
|
||||||
|
double (*samplers[])(uint64_t*) = { sample_0, sample_1, sample_few, sample_many };
|
||||||
|
|
||||||
|
int n_samples = 1000000;
|
||||||
|
double* result_many = (double*)malloc(n_samples * sizeof(double));
|
||||||
|
for (int i = 0; i < n_samples; i++) {
|
||||||
|
result_many[i] = sample_mixture(samplers, weights, n_dists, seed);
|
||||||
|
printf("%f\n", result_many[i]);
|
||||||
|
}
|
||||||
|
// printf("Mean: %f\n", array_mean(result_many, n_samples));
|
||||||
|
|
||||||
|
free(seed);
|
||||||
|
}
|
53
examples/15_plotting-scratchpad/src/makefile
Normal file
53
examples/15_plotting-scratchpad/src/makefile
Normal file
|
@ -0,0 +1,53 @@
|
||||||
|
# Interface:
|
||||||
|
# make
|
||||||
|
# make build
|
||||||
|
# make format
|
||||||
|
# make run
|
||||||
|
|
||||||
|
# Compiler
|
||||||
|
CC=gcc
|
||||||
|
# CC=tcc # <= faster compilation
|
||||||
|
|
||||||
|
# Main file
|
||||||
|
SRC=example.c ../../squiggle.c
|
||||||
|
OUTPUT=example
|
||||||
|
|
||||||
|
## Dependencies
|
||||||
|
MATH=-lm
|
||||||
|
|
||||||
|
## Flags
|
||||||
|
DEBUG= #'-g'
|
||||||
|
STANDARD=-std=c99
|
||||||
|
WARNINGS=-Wall
|
||||||
|
OPTIMIZED=-O3 #-Ofast
|
||||||
|
# OPENMP=-fopenmp
|
||||||
|
|
||||||
|
## Formatter
|
||||||
|
STYLE_BLUEPRINT=webkit
|
||||||
|
FORMATTER=clang-format -i -style=$(STYLE_BLUEPRINT)
|
||||||
|
|
||||||
|
## make build
|
||||||
|
build: $(SRC)
|
||||||
|
$(CC) $(OPTIMIZED) $(DEBUG) $(SRC) $(MATH) -o $(OUTPUT)
|
||||||
|
|
||||||
|
format: $(SRC)
|
||||||
|
$(FORMATTER) $(SRC)
|
||||||
|
|
||||||
|
run: $(SRC) $(OUTPUT)
|
||||||
|
./$(OUTPUT) && echo
|
||||||
|
|
||||||
|
time-linux:
|
||||||
|
@echo "Requires /bin/time, found on GNU/Linux systems" && echo
|
||||||
|
|
||||||
|
@echo "Running 100x and taking avg time $(OUTPUT)"
|
||||||
|
@t=$$(/usr/bin/time -f "%e" -p bash -c 'for i in {1..100}; do ./$(OUTPUT); done' 2>&1 >/dev/null | grep real | awk '{print $$2}' ); echo "scale=2; 1000 * $$t / 100" | bc | sed "s|^|Time using 1 thread: |" | sed 's|$$|ms|' && echo
|
||||||
|
|
||||||
|
## Profiling
|
||||||
|
|
||||||
|
profile-linux:
|
||||||
|
echo "Requires perf, which depends on the kernel version, and might be in linux-tools package or similar"
|
||||||
|
echo "Must be run as sudo"
|
||||||
|
$(CC) $(SRC) $(MATH) -o $(OUTPUT)
|
||||||
|
sudo perf record ./$(OUTPUT)
|
||||||
|
sudo perf report
|
||||||
|
rm perf.data
|
Loading…
Reference in New Issue
Block a user