Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > de.sci.electronics > #353167

Re: random Statistik

From Carla Schneider <carla_schn@proton.me>
Newsgroups de.sci.electronics
Subject Re: random Statistik
Date 2024-06-10 11:24 +0200
Organization Mausgrau
Message-ID <6666C63C.5953B476@proton.me> (permalink)
References <v41mi1$1ct79$1@solani.org>

Show all headers | View raw


Helmut Schellong wrote:
> 
> Es gab hier Widersprüchliches zu lesen
> zu hohen Ereignis-Anzahlen, die bessere Ergebnisse liefern sollen.
> Es stimmt generell, daß viele Ereignisse zuverlässigere Ergebnisse liefern.
> 
> Nachfolgend wird gewürfelt 1..6 (kryptographisch).
> 1+2+3+4+5+6 = 21 ; 21/6 = 3,5 (Mittelwert)
> 1+6 = 7 ; 7/2 = 3,5 (Reihenrechnung)
> 
> Das Ergebnis wird umso genauer, je mehr Würfel-Ereignisse vorliegen.
> Mit 'genauer' ist gemeint, daß die Differenzen zu vorhergehenden
> Werten fortlaufend geringer werden.
> Das Pendeln um den genauen Mittelwert herum hat fortlaufend eine geringere Frequenz.
> Ein Pendeln bleibt bestehen, weil der Zahlenbereich 1..6 und die Werte sehr klein sind.
> 
> Die erste erwürfelte Zahl kann natürlich eine aus der Menge 1..6 sein.
> 
> ===========================================
> 1 6 6.000 6.000
> 2 3 9.000 4.500
> 3 1 10.000 3.333
> 4 2 12.000 3.000
> 5 5 17.000 3.400
...

Der Sinn diese Tabelle zu posten kann ja wohl nur darin liegen dass ein Leser diese
Tabelle auswertet mit einem Computerprogramm.
Programmieren kostet aber Zeit und die ist nicht umsonst,
also hier mal ein alternativer Zugang mit chatgpt

Erster Versuch:
-----
write a c program that reads lines from stdin and converts the first two space 
separated items in each line to integers and calls a function fuff with these Integers as parameters
-----


Er gibt mir ein Programm das genau das tut:
------
#include <stdio.h>
#include <stdlib.h>

// Function prototype
void fuff(int a, int b);

int main() {
    char line[256];

    // Read lines from stdin
    while (fgets(line, sizeof(line), stdin)) {
        int num1, num2;

        // Extract the first two space-separated integers
        if (sscanf(line, "%d %d", &num1, &num2) == 2) {
            // Call the function fuff with these integers
            fuff(num1, num2);
        } else {
            printf("Invalid input line: %s", line);
        }
    }

    return 0;
}

// Define the function fuff
void fuff(int a, int b) {
    // Example implementation: just print the numbers
    printf("fuff called with: %d and %d\n", a, b);
}

------


Ich wollte das programm jetzt so modifizieren dass er ein Histogramm von num2 macht...
Aber warum nicht chatgpt noch mehr Arbeit uebertragen:

--------
treat num2 as a random variable with the values 1 2 3 4 5 6 and put some 
tests in the orogram that tests if it its distribution
-------

Das hat er dann leider falsch verstanden...
Also habe ich ihm noch geschrieben:
-------
do not generate random numbers but test if  the input numbers are random
-------
Er gibt mir folgendes Programm:
--------
#include <stdio.h>
#include <stdlib.h>

// Function prototype
void fuff(int a, int b);

int main() {
    char line[256];
    int counts[6] = {0}; // Array to count occurrences of 1, 2, 3, 4, 5, 6
    int totalLines = 0;

    // Read lines from stdin
    while (fgets(line, sizeof(line), stdin)) {
        int num1, num2;

        // Extract the first two integers
        if (sscanf(line, "%d %d", &num1, &num2) == 2) {
            // Check if num2 is within the valid range (1-6)
            if (num2 >= 1 && num2 <= 6) {
                // Increment the count for this num2 value
                counts[num2 - 1]++;
                
                // Call the function fuff with these integers
                fuff(num1, num2);

                // Increment the total number of lines processed
                totalLines++;
            } else {
                printf("Invalid num2 value: %d (must be between 1 and 6)\n", num2);
            }
        } else {
            printf("Invalid input line: %s", line);
        }
    }

    // Print the counts for each num2 value
    printf("Distribution of num2 values:\n");
    for (int i = 0; i < 6; i++) {
        printf("%d: %d times\n", i + 1, counts[i]);
    }

    // Calculate the expected count for a uniform distribution
    double expected = totalLines / 6.0;
    double chi_squared = 0.0;

    // Perform the chi-squared test
    for (int i = 0; i < 6; i++) {
        double observed = counts[i];
        chi_squared += (observed - expected) * (observed - expected) / expected;
    }

    printf("Chi-squared statistic: %f\n", chi_squared);

    // Chi-squared critical value for 5 degrees of freedom at 0.05 significance level is 11.070
    if (chi_squared < 11.070) {
        printf("The distribution appears to be uniform.\n");
    } else {
        printf("The distribution does not appear to be uniform.\n");
    }

    return 0;
}

// Define the function fuff
void fuff(int a, int b) {
    // Example implementation: just print the numbers
    printf("fuff called with: %d and %d\n", a, b);
}
--------

Der gesamte Chat ist hier einsehbar:
https://chatgpt.com/share/c513b39e-53eb-49ce-acf5-c7491bf52995

Die Funktion fuff() habe ich aus dem Programm entfernt und das dann auf deine Zahlen losgelassen:


cat inputdat.txt | ./wrfltst
Das ist das Ergebnis:
-------
Distribution of num2 values:
1: 492 times
2: 479 times
3: 486 times
4: 513 times
5: 532 times
6: 498 times
Chi-squared statistic: 3.796000
The distribution appears to be uniform.
-------

Zum Test habe ich jetzt mal die Eingangszahlen verfaelscht, indem jede 6 6 6 Folge
zu einer 6 6 1 Folge gemacht wird:   

Also das Programm veraendert:
-------

    int lnum2 =0;
    int llnum2=0;
    // Read lines from stdin
    while (fgets(line, sizeof(line), stdin)) {
        int num1, num2,xnum2;

        // Extract the first two integers
        if (sscanf(line, "%d %d", &num1, &num2) == 2) {
            // Check if num2 is within the valid range (1-6)
            if (num2 >= 1 && num2 <= 6) {
                // Increment the count for this num2 value
                xnum2=num2;
                if((num2==6) && (lnum2==6) && (llnum2==6)) xnum2=1;
                counts[xnum2 - 1]++;
                llnum2=lnum2;
                lnum2=num2;  
-------

Und heraus kommt:

-------
Distribution of num2 values:
1: 515 times
2: 479 times
3: 486 times
4: 513 times
5: 532 times
6: 475 times
Chi-squared statistic: 5.360000
The distribution appears to be uniform.
--------
D.h. das merkt er nicht dazu sind 3000 Samples zu wenig.

Wenn ich aber alle 6 6 Folgen durch 6 1 ersetze merkt er es:

--------
Distribution of num2 values:
1: 557 times
2: 479 times
3: 486 times
4: 513 times
5: 532 times
6: 433 times
Chi-squared statistic: 19.136000
The distribution does not appear to be uniform.
--------

Back to de.sci.electronics | Previous | NextNext in thread | Find similar


Thread

Re: random Statistik Carla Schneider <carla_schn@proton.me> - 2024-06-10 11:24 +0200
  Re: random Statistik Helmut Schellong <var@schellong.biz> - 2024-06-10 17:05 +0200
    Re: random Statistik Carla Schneider <carla_schn@proton.me> - 2024-06-11 11:48 +0200
      Re: random Statistik Carla Schneider <carla_schn@proton.me> - 2024-06-11 13:00 +0200
        Re: random Statistik Helmut Schellong <var@schellong.biz> - 2024-06-11 15:50 +0200
          Re: random Statistik Carla Schneider <carla_schn@proton.me> - 2024-06-11 16:26 +0200
            Re: random Statistik Helmut Schellong <var@schellong.biz> - 2024-06-11 17:51 +0200
      Re: random Statistik Rolf Bombach <rolfnospambombach@invalid.invalid> - 2024-06-11 14:31 +0200
      Re: random Statistik Helmut Schellong <var@schellong.biz> - 2024-06-11 15:45 +0200
      Re: random Statistik Helmut Schellong <var@schellong.biz> - 2024-06-12 05:04 +0200
        Re: random Statistik Carla Schneider <carla_schn@proton.me> - 2024-06-12 08:43 +0200
          Re: random Statistik Helmut Schellong <var@schellong.biz> - 2024-06-12 16:36 +0200
            Re: random Statistik Helmut Schellong <var@schellong.biz> - 2024-06-12 21:41 +0200
              Re: random Statistik Helmut Schellong <var@schellong.biz> - 2024-06-13 21:01 +0200
                Re: random Statistik Helmut Schellong <var@schellong.biz> - 2024-06-14 10:13 +0200
                Re: random Statistik Carla Schneider <carla_schn@proton.me> - 2024-06-14 12:36 +0200
                Re: random Statistik Helmut Schellong <var@schellong.biz> - 2024-06-15 00:44 +0200
                Re: random Statistik Carla Schneider <carla_schn@proton.me> - 2024-06-15 13:05 +0200
                Re: random Statistik Helmut Schellong <var@schellong.biz> - 2024-06-15 15:10 +0200
                Re: random Statistik Carla Schneider <carla_schn@proton.me> - 2024-06-16 11:17 +0200
                Re: random Statistik Helmut Schellong <var@schellong.biz> - 2024-06-16 22:59 +0200
                Re: random Statistik Carla Schneider <carla_schn@proton.me> - 2024-06-17 12:10 +0200
                Re: random Statistik Helmut Schellong <var@schellong.biz> - 2024-06-17 15:05 +0200
                Re: random Statistik Rolf Bombach <rolfnospambombach@invalid.invalid> - 2024-06-15 20:34 +0200
                Re: random Statistik Helmut Schellong <var@schellong.biz> - 2024-06-15 23:12 +0200
                Re: random Statistik Rolf Bombach <rolfnospambombach@invalid.invalid> - 2024-06-17 15:16 +0200
                Re: random Statistik Helmut Schellong <var@schellong.biz> - 2024-06-17 16:40 +0200
                Re: random Statistik - Windows PowerShell Helmut Schellong <var@schellong.biz> - 2024-06-18 00:17 +0200
            Re: random Statistik Carla Schneider <carla_schn@proton.me> - 2024-06-13 09:43 +0200
              Re: random Statistik Helmut Schellong <var@schellong.biz> - 2024-06-13 12:55 +0200
                Re: random Statistik Carla Schneider <carla_schn@proton.me> - 2024-06-13 14:05 +0200
                Re: random Statistik Helmut Schellong <var@schellong.biz> - 2024-06-13 16:11 +0200
                Re: random Statistik Carla Schneider <carla_schn@proton.me> - 2024-06-13 16:57 +0200
                Re: random Statistik Helmut Schellong <var@schellong.biz> - 2024-06-13 20:47 +0200
                Re: random Statistik Carla Schneider <carla_schn@proton.me> - 2024-06-18 10:59 +0200
                Re: random Statistik Helmut Schellong <var@schellong.biz> - 2024-06-18 17:37 +0200

csiph-web