118 lines
3.6 KiB
Python
118 lines
3.6 KiB
Python
import random
|
|
from typing import List
|
|
|
|
import winkelumrechnungen as wu
|
|
from GHA_triaxial.utils import jacobi_konstante
|
|
from ellipsoid_triaxial import EllipsoidTriaxial
|
|
|
|
ell = EllipsoidTriaxial.init_name("KarneyTest2024")
|
|
file_path = r"Karney_2024_Testset.txt"
|
|
|
|
def line2example(line: str) -> List:
|
|
"""
|
|
Line-String in Liste umwandeln
|
|
:param line: Line-String
|
|
:return: Liste mit Zahlenwerten
|
|
"""
|
|
split = line.split()
|
|
example = [float(value) for value in split[:7]]
|
|
for i, value in enumerate(example):
|
|
if i < 6:
|
|
example[i] = wu.deg2rad(value)
|
|
# example[i] = value
|
|
return example
|
|
|
|
def get_random_examples(num: int, seed: int = None) -> List:
|
|
"""
|
|
Rückgabe zufälliger Beispiele
|
|
beta0, lamb0, alpha0, beta1, lamb1, alpha1, s12
|
|
:param num: Anzahl zufälliger Beispiele
|
|
:param seed: Random-Seed
|
|
:return: Liste mit Beispielen
|
|
"""
|
|
if seed is not None:
|
|
random.seed(seed)
|
|
with open(file_path) as datei:
|
|
lines = datei.readlines()
|
|
examples = []
|
|
for i in range(num):
|
|
example = line2example(lines[random.randint(0, len(lines) - 1)])
|
|
examples.append(example)
|
|
return examples
|
|
|
|
def get_examples(l_i: List) -> List:
|
|
"""
|
|
Rückgabe ausgewählter Beispiele
|
|
beta0, lamb0, alpha0, beta1, lamb1, alpha1, s12
|
|
:param l_i: Liste von Indizes
|
|
:return: Liste mit Beispielen
|
|
"""
|
|
with open(file_path) as datei:
|
|
lines = datei.readlines()
|
|
examples = []
|
|
for i in l_i:
|
|
example = line2example(lines[i])
|
|
examples.append(example)
|
|
return examples
|
|
|
|
|
|
def get_random_examples_gamma(group: str, num: int, seed: int = None, length: str = None) -> List:
|
|
"""
|
|
Zufällige Beispiele aus Karney in Gruppen nach Einteilung anhand der Jacobi-Konstanten
|
|
:param group: Gruppe
|
|
:param num: Anzahl
|
|
:param seed: Random-Seed
|
|
:param length: long oder short, sond egal
|
|
:return: Liste mit Beispielen
|
|
"""
|
|
eps = 1e-20
|
|
long_short = 2
|
|
if seed is not None:
|
|
random.seed(seed)
|
|
with open(file_path) as datei:
|
|
lines = datei.readlines()
|
|
examples = []
|
|
i = 0
|
|
while len(examples) < num and i < len(lines):
|
|
example = line2example(lines[random.randint(0, len(lines) - 1)])
|
|
if example in examples:
|
|
continue
|
|
i += 1
|
|
|
|
beta0, lamb0, alpha0_ell, beta1, lamb1, alpha1_ell, s = example
|
|
gamma = jacobi_konstante(beta0, lamb0, alpha0_ell, ell)
|
|
|
|
if group not in ["a", "b", "c", "d", "e", "de"]:
|
|
break
|
|
elif group == "a" and not 1 >= gamma >= 0.01:
|
|
continue
|
|
elif group == "b" and not 0.01 > gamma > eps:
|
|
continue
|
|
elif group == "c" and not abs(gamma) <= eps:
|
|
continue
|
|
elif group == "d" and not -eps > gamma > -1e-17:
|
|
continue
|
|
elif group == "e" and not -1e-17 >= gamma >= -1:
|
|
continue
|
|
elif group == "de" and not -eps > gamma > -1:
|
|
continue
|
|
|
|
if length == "short":
|
|
if example[6] < long_short:
|
|
examples.append(example)
|
|
elif length == "long":
|
|
if example[6] >= long_short:
|
|
examples.append(example)
|
|
else:
|
|
examples.append(example)
|
|
|
|
return examples
|
|
|
|
|
|
if __name__ == "__main__":
|
|
examples_a = get_random_examples_gamma("a", 10, 42)
|
|
examples_b = get_random_examples_gamma("b", 10, 42)
|
|
examples_c = get_random_examples_gamma("c", 10, 42)
|
|
examples_d = get_random_examples_gamma("d", 10, 42)
|
|
examples_e = get_random_examples_gamma("e", 10, 42)
|
|
pass |