zuma/w3/create_bayes_nasty.py
2021-03-17 20:09:43 +01:00

27 lines
650 B
Python

#!/usr/bin/python3
# -*- coding:utf-8 -*-
import csv
import math
import random
import sys
def create_bayes_nasty_data(filename):
with open(filename, 'w') as f:
writer = csv.writer(
f, delimiter=('\t' if filename.endswith('.tsv') else ','))
for i in range(100):
x = random.uniform(-1.0, 1.0)
y = random.uniform(-1.0, 1.0)
p = abs(x-y) / abs(x+y)
# for i in range(2):
# p = -2 * p**3 + 3 * p**2
v = 1 if random.random() > p else 0
writer.writerow([v, x, y])
if __name__ == '__main__':
create_bayes_nasty_data(sys.argv[1])