cds1011-ls2/rule_based_values.py
2025-11-29 14:33:03 +01:00

86 lines
2.0 KiB
Python

# generate points and x, y coordinates based on this rules
# 1. points possible: 0 to 10
# 2. possible points for x, y range
# 2a. 10 (0,0) (1.5, 1.5)
# 2.b 9 (1.5,0) (1.5, 1.5)
# 2.c 8 (0,0) (1.5, 1.5)
# 2.d 7 (0,0) (1.5, 1.5)
# 2.e 6 (0,0) (1.5, 1.5)
# 2.f 5 (0,0) (1.5, 1.5)
# 2.g 4 (0,0) (1.5, 1.5)
# 2.h 3 (0,0) (1.5, 1.5)
# 2.i 2 (0,0) (1.5, 1.5)
# 2.j 1 (0,0) (1.5, 1.5)
# 2.j 0 (0,0) (1.5, 1.5)
import pandas as pd
import numpy as np
import csv
FEATURES = ["points", "x", "y"]
# Area circle
A10 = 1.5 ** 2 * np.pi
A9 = 2.5 ** 2 * np.pi
A8 = 3.5 ** 2 * np.pi
A7 = 4.5 ** 2 * np.pi
A6 = 5.5 ** 2 * np.pi
A5 = 6.5 ** 2 * np.pi
A4 = 7.5 ** 2 * np.pi
A3 = 8.5 ** 2 * np.pi
A2 = 9.5 ** 2 * np.pi
A1 = 10.5 ** 2 * np.pi
'''print(A10)
print(A9)
print(A8)
print(A7)
print(A6)
print(A5)
print(A4)
print(A3)
print(A2)
print(A1)
print("")'''
possible_values = np.linspace(-10, 10, 41) # frin -10 to 10 with step 0.5
xy = [(np.random.choice(possible_values), np.random.choice(possible_values)) for _ in range(1000)]
dataset = []
for i in xy:
A = (i[0]**2 + i[1]**2) * np.pi
#print(A)
if A <= A10:
dataset.append([10, i[0], i[1]])
elif A > A10 and A <= A9:
dataset.append([9, i[0], i[1]])
elif A > A9 and A <= A8:
dataset.append([8, i[0], i[1]])
elif A > A8 and A <= A7:
dataset.append([7, i[0], i[1]])
elif A > A7 and A <= A6:
dataset.append([6, i[0], i[1]])
elif A > A6 and A <= A5:
dataset.append([5, i[0], i[1]])
elif A > A5 and A <= A4:
dataset.append([4, i[0], i[1]])
elif A > A4 and A <= A3:
dataset.append([3, i[0], i[1]])
elif A > A3 and A <= A2:
dataset.append([2, i[0], i[1]])
elif A > A2 and A <= A1:
dataset.append([1, i[0], i[1]])
elif A > A1:
dataset.append([0, i[0], i[1]])
#print(dataset)
with open('data/synthetic_data.csv', 'w', newline='') as csvfile:
fieldnames = ['points', 'x', 'y']
writer = csv.writer(csvfile)
writer.writerows(dataset)