Binomial distribution in VMS
#19
If you want to test folios or sections in the VMS yourself, here is the code for plotting:

Code:
import numpy as np import matplotlib.pyplot as plt from scipy.special import comb import argparse import os def calculate_binomial_distribution(n, max_length):     """Berechnet eine Binomialverteilung für Wortlängen."""     k_values = np.arange(1, max_length + 1)     probabilities = [comb(n, k) * (0.5 ** n) for k in k_values]     probabilities /= np.sum(probabilities)  # Normiert die Verteilung     return k_values, probabilities def plot_binomial_distribution(word_lengths, max_length=15, n=10):     """Visualisiert die Binomialverteilung basierend auf den Wortlängen in der Textdatei."""     if len(word_lengths) == 0:         print("Error: Keine Wörter in der Datei gefunden.")         return         # Berechnung der Binomialverteilung     k_values, binomial_probabilities = calculate_binomial_distribution(n, max_length)         # Berechnung der Häufigkeitsverteilung für das Histogramm     counts, bins = np.histogram(word_lengths, bins=np.arange(0.5, max_length + 1.5))     probabilities = counts / np.sum(counts)  # Normalisieren         plt.figure(figsize=(10, 6))         # Histogramm der Wortlängen     bin_centers = (bins[:-1] + bins[1:]) / 2     plt.bar(bin_centers, probabilities, width=0.6, edgecolor='black', alpha=0.6, label='Calculated Distribution')         # Binomialverteilungskurve anpassen     plt.plot(k_values, binomial_probabilities, 'r--', marker='o', label='Theoretical Distribution')         # Achsenbegrenzungen setzen, um die Kurve korrekt darzustellen     plt.xlim(0.5, max_length + 0.5)     plt.xticks(np.arange(1, max_length + 1))         plt.xlabel('Word Length')     plt.ylabel('Probability')     plt.title(f'Binomial Distribution for n={n}')     plt.legend()     plt.grid(True)     plt.show() def process_text_file(file_path):     """Liests eine Textdatei ein und berechnet die Wortlängen."""     if not os.path.isfile(file_path):         print(f"Error: Die Datei {file_path} wurde nicht gefunden.")         return None         try:         with open(file_path, 'r', encoding='utf-8') as file:             text = file.read()     except IOError as e:         print(f"Error: Ein Fehler ist beim Lesen der Datei aufgetreten: {e}")         return None         words = text.split()     word_lengths = [len(word) for word in words]         return word_lengths def main():     parser = argparse.ArgumentParser(description="Visualisiert die Binomialverteilung basierend auf einer Textdatei.")     parser.add_argument('file', type=str, help='Pfad zur Textdatei')     args = parser.parse_args()         # Textdatei verarbeiten     word_lengths = process_text_file(args.file)         if word_lengths is not None:         plot_binomial_distribution(word_lengths, max_length=15, n=10) if __name__ == "__main__":     main()
[+] 2 users say Thank You to bi3mw for this post
Reply


Messages In This Thread
Binomial distribution in VMS - by bi3mw - 17-08-2024, 12:33 AM
RE: Binomial distribution in VMS - by bi3mw - 17-08-2024, 12:28 PM
RE: Binomial distribution in VMS - by bi3mw - 17-08-2024, 12:47 PM
RE: Binomial distribution in VMS - by RobGea - 17-08-2024, 03:35 PM
RE: Binomial distribution in VMS - by RobGea - 17-08-2024, 04:38 PM
RE: Binomial distribution in VMS - by bi3mw - 17-08-2024, 06:38 PM
RE: Binomial distribution in VMS - by nablator - 18-08-2024, 08:18 PM
RE: Binomial distribution in VMS - by bi3mw - 18-08-2024, 01:44 PM
RE: Binomial distribution in VMS - by nablator - 18-08-2024, 05:06 PM
RE: Binomial distribution in VMS - by RobGea - 18-08-2024, 04:14 PM
RE: Binomial distribution in VMS - by bi3mw - 18-08-2024, 04:46 PM
RE: Binomial distribution in VMS - by bi3mw - 18-08-2024, 05:36 PM
RE: Binomial distribution in VMS - by nablator - 18-08-2024, 06:45 PM
RE: Binomial distribution in VMS - by bi3mw - 19-08-2024, 06:08 PM
RE: Binomial distribution in VMS - by nablator - 19-08-2024, 06:43 PM
RE: Binomial distribution in VMS - by bi3mw - 19-08-2024, 07:09 PM
RE: Binomial distribution in VMS - by bi3mw - 19-08-2024, 07:49 PM
RE: Binomial distribution in VMS - by nablator - 19-08-2024, 08:36 PM
RE: Binomial distribution in VMS - by nablator - 19-08-2024, 09:06 PM
RE: Binomial distribution in VMS - by bi3mw - 19-08-2024, 09:12 PM
RE: Binomial distribution in VMS - by nablator - 19-08-2024, 09:40 PM
RE: Binomial distribution in VMS - by bi3mw - 20-08-2024, 03:30 PM
RE: Binomial distribution in VMS - by bi3mw - 21-08-2024, 05:40 PM
RE: Binomial distribution in VMS - by Koen G - 21-08-2024, 07:06 PM
RE: Binomial distribution in VMS - by bi3mw - 21-08-2024, 07:11 PM
RE: Binomial distribution in VMS - by Koen G - 21-08-2024, 07:25 PM
RE: Binomial distribution in VMS - by bi3mw - 21-08-2024, 07:39 PM
RE: Binomial distribution in VMS - by Koen G - 21-08-2024, 08:17 PM
RE: Binomial distribution in VMS - by bi3mw - 22-08-2024, 07:59 PM
RE: Binomial distribution in VMS - by bi3mw - 23-08-2024, 11:24 PM
RE: Binomial distribution in VMS - by bi3mw - 25-08-2024, 12:23 AM
RE: Binomial distribution in VMS - by RobGea - 25-08-2024, 06:11 PM
RE: Binomial distribution in VMS - by bi3mw - 26-08-2024, 10:27 AM
RE: Binomial distribution in VMS - by RobGea - 26-08-2024, 03:38 PM
RE: Binomial distribution in VMS - by bi3mw - 26-08-2024, 05:08 PM
RE: Binomial distribution in VMS - by RobGea - 26-08-2024, 05:54 PM
RE: Binomial distribution in VMS - by bi3mw - 26-08-2024, 06:02 PM
RE: Binomial distribution in VMS - by RobGea - 26-08-2024, 06:08 PM
RE: Binomial distribution in VMS - by bi3mw - 26-08-2024, 08:34 PM
RE: Binomial distribution in VMS - by RobGea - 26-08-2024, 10:45 PM
RE: Binomial distribution in VMS - by bi3mw - 27-08-2024, 03:32 PM
RE: Binomial distribution in VMS - by RobGea - 27-08-2024, 09:41 PM
RE: Binomial distribution in VMS - by ReneZ - 27-08-2024, 10:57 PM
RE: Binomial distribution in VMS - by bi3mw - 28-08-2024, 01:28 PM
RE: Binomial distribution in VMS - by nablator - 28-08-2024, 02:17 PM
RE: Binomial distribution in VMS - by bi3mw - 28-08-2024, 03:03 PM
RE: Binomial distribution in VMS - by RobGea - 28-08-2024, 06:04 PM
RE: Binomial distribution in VMS - by bi3mw - 28-08-2024, 06:25 PM
RE: Binomial distribution in VMS - by RobGea - 28-08-2024, 08:06 PM
RE: Binomial distribution in VMS - by bi3mw - 28-08-2024, 08:19 PM
RE: Binomial distribution in VMS - by RobGea - 28-08-2024, 10:02 PM
RE: Binomial distribution in VMS - by bi3mw - 28-08-2024, 10:44 PM
RE: Binomial distribution in VMS - by RobGea - 28-08-2024, 10:53 PM
RE: Binomial distribution in VMS - by bi3mw - 28-08-2024, 11:02 PM
RE: Binomial distribution in VMS - by RobGea - 28-08-2024, 11:12 PM
RE: Binomial distribution in VMS - by bi3mw - 28-08-2024, 11:52 PM
RE: Binomial distribution in VMS - by RobGea - 29-08-2024, 12:03 AM
RE: Binomial distribution in VMS - by bi3mw - 29-08-2024, 12:18 AM
RE: Binomial distribution in VMS - by bi3mw - 29-08-2024, 10:52 PM
RE: Binomial distribution in VMS - by bi3mw - 30-08-2024, 10:36 PM
RE: Binomial distribution in VMS - by RobGea - 06-09-2024, 08:08 PM
RE: Binomial distribution in VMS - by lelle - 06-09-2024, 09:47 PM
RE: Binomial distribution in VMS - by bi3mw - 07-09-2024, 02:24 AM
RE: Binomial distribution in VMS - by Koen G - 07-09-2024, 09:06 AM
RE: Binomial distribution in VMS - by bi3mw - 07-09-2024, 09:22 AM
RE: Binomial distribution in VMS - by ReneZ - 08-09-2024, 01:53 AM

Forum Jump:


Users browsing this thread: 1 Guest(s)