![]() |
|
Binomial distribution in VMS - Printable Version +- The Voynich Ninja (https://www.voynich.ninja) +-- Forum: Voynich Research (https://www.voynich.ninja/forum-27.html) +--- Forum: Analysis of the text (https://www.voynich.ninja/forum-41.html) +--- Thread: Binomial distribution in VMS (/thread-4353.html) |
Binomial distribution in VMS - bi3mw - 17-08-2024 Question: What if the words in the VMS have been shortened or expanded with fill characters (here X) so that they end up corresponding to a binomial distribution (with whatever system)? Here is a line from a comparative text ( regimen sanitatis ): Input example: Capitulum primum De regulis sumptis ex parte elementorum nostro corpori occurrentium ab extra Output example: Ca primum DeXXXXX regul sump exXXXX parteX elemento nost corpo occu abXXXX extra Distribution in the entire, modified text ( regimen sanitatis ): Code: import sys
import numpy as np
from scipy.special import comb
def calculate_binomial_distribution(n, max_length):
"""Berechnet eine Binomialverteilung für Wortlängen."""
k_values = np.arange(1, max_length + 1)
# Berechne die Binomialverteilung für die Formel choose(9, k-1) / 2^9
probabilities = [comb(n, k-1) / (2 ** n) for k in k_values]
# Normiere die Verteilung
probabilities /= np.sum(probabilities)
return probabilities
def adjust_word_lengths(words, target_distribution):
"""Passt die Wortlängen an die Zielverteilung an, indem Wörter gekürzt oder verlängert werden."""
adjusted_words = []
max_word_length = len(target_distribution)
length_bins = np.arange(1, max_word_length + 1)
length_probs = np.array(target_distribution)
for word in words:
current_length = len(word)
target_length = np.random.choice(length_bins, p=length_probs)
# Falls die Zielwortlänge kleiner ist, kürze das Wort
if target_length < current_length:
adjusted_words.append(word[:target_length])
# Falls die Zielwortlänge größer ist, verlängere das Wort mit 'X'
elif target_length > current_length:
adjusted_words.append(word + 'X' * (target_length - current_length))
else:
adjusted_words.append(word) # Wenn die Länge passt, bleibt das Wort unverändert
return adjusted_words
def process_text(file_path):
"""Liest den Text aus der Datei, passt die Wortlängen an und gibt den neuen Text zurück."""
try:
with open(file_path, 'r', encoding='utf-8') as file:
lines = file.readlines()
except FileNotFoundError:
print(f"Error: The file {file_path} was not found.")
sys.exit(1)
except IOError as e:
print(f"Error: An error occurred while reading the file: {e}")
sys.exit(1)
max_word_length = 15 # Maximale Wortlänge festlegen
n = 9 # Anzahl der Würfe für die Binomialverteilung
# Berechne die Binomialverteilung
target_distribution = calculate_binomial_distribution(n, max_word_length)
adjusted_lines = []
for line in lines:
words = line.split()
adjusted_words = adjust_word_lengths(words, target_distribution)
adjusted_lines.append(' '.join(adjusted_words))
return '\n'.join(adjusted_lines)
def main():
if len(sys.argv) != 2:
print("Usage: python adjust_word_length.py <filename>")
sys.exit(1)
file_path = sys.argv[1]
new_text = process_text(file_path)
print("Modified text:")
print(new_text)
if __name__ == "__main__":
main()Quote:ChatGPT RE: Binomial distribution in VMS - Ruby Novacna - 17-08-2024 RE: Binomial distribution in VMS - bi3mw - 17-08-2024 RE: Binomial distribution in VMS - Ruby Novacna - 17-08-2024 RE: Binomial distribution in VMS - bi3mw - 17-08-2024 RE: Binomial distribution in VMS - RobGea - 17-08-2024 RE: Binomial distribution in VMS - RobGea - 17-08-2024 RE: Binomial distribution in VMS - bi3mw - 17-08-2024 RE: Binomial distribution in VMS - bi3mw - 18-08-2024 RE: Binomial distribution in VMS - RobGea - 18-08-2024 |