Re: Why GIMP Is Better Than Photoshop

Liste des GroupesRevenir à ol advocacy 
Sujet : Re: Why GIMP Is Better Than Photoshop
De : guhnoo-basher (at) *nospam* linux.advocaca (DFS)
Groupes : comp.os.linux.advocacy
Date : 11. Jan 2025, 17:12:00
Autres entêtes
Organisation : A noiseless patient Spider
Message-ID : <vlu58c$mdjf$3@dont-email.me>
References : 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20
User-Agent : Betterbird (Windows)
On 1/11/2025 1:53 AM, Physfitfreak wrote:

Score of 85 might be a bit too harsh in his case, but I have no doubt that he's around the average IQ but on the dumb side of that average; never on the other side. That, I'm sure.
Get ready Maleki.
========================================================================================
//this code is hereby released to the public domain
#include <stdlib.h>
#include <stdio.h>
#include <math.h>
#include <string.h>
#include <time.h>
/*
  this program computes the descriptive statistics of sets of integers
  1.0 release Dec 2020
  2.0 release Jun 2024
  used the population skewness and Kurtosis formulas from:
https://www.calculatorsoup.com/calculators/statistics/descriptivestatistics.php
  also test the results of this code against that site
  compile:
  $ gcc -Wall prog.c -o prog -lm
  or
  $ gcc -Wall -Wextra -O2 prog.c -o prog -lm
  or
  $ gcc -Wall -Wextra -O2 -fsanitize=undefined prog.c -o prog
  -lm
  usage  : ./prog -option N
            where option is:
            -r generates N random numbers
   -c generates consecutive numbers 1 to N
   -o generates random numbers with outliers
   -f read in dataset from file
   and N is 2+ or the file name
*/
//random ints
int randNbr(int low, int high) {
return (low + rand() / (RAND_MAX / (high - low + 1) + 1));
}
//comparator function used with qsort
int compareint (const void * a, const void * b)
{
   if (*(int*)a > *(int*)b) return 1;
   else if (*(int*)a < *(int*)b) return -1;
   else return 0;
}
int main(int argc, char *argv[])
{
if(argc < 3) {
printf("Missing argument:\n");
printf(" * enter a number greater than 2\n");
printf(" * enter an option -r -c -o or -f\n");
exit(0);
}


//=================================================================================================
//generate datasets
//=================================================================================================

int i = 0, N = 0;
int *nums;
if(strcmp(argv[1],"-f") != 0) {
N = atoi(argv[2]);
nums  = malloc(N * sizeof(int));
}

//random
if(strcmp(argv[1],"-r") == 0) {
srand(time(NULL));
for(i=0;i<N;i++) { nums[i] = randNbr(1,N*3); }

printf("%d Randoms between 1 and %d\n", N, 3*N);
for(i=0;i<N;i++) { printf("%d ", nums[i]); }
qsort(nums,N,sizeof(int),compareint);
printf("\nSorted:\n"); for(i=0;i<N;i++) { printf("%d ", nums[i]); }
}

//random with outliers
if(strcmp(argv[1],"-o") == 0) {
srand(time(NULL));
nums[0] = 1; nums[1] = 3;
for(i=2;i<N-2;i++) { nums[i] = randNbr(100,N*30); }
nums[N-2] = 1000; nums[N-1] = 2000;

printf("%d Randoms with outliers\n", N);
for(i=0;i<N;i++) { printf("%d ", nums[i]); }
qsort(nums,N,sizeof(int),compareint);
printf("\nSorted:\n"); for(i=0;i<N;i++) { printf("%d ", nums[i]); }
}


//consecutive numbers 1 to N
if(strcmp(argv[1],"-c") == 0) {
printf("%d Consecutive\n", N);
for(i=0;i<N;i++) {
nums[i] = i + 1;
printf("%d ", nums[i]);
}
}


//read dataset from file
if(strcmp(argv[1],"-f") == 0) {
nums = malloc(2 * sizeof(int));
FILE* datafile = fopen(argv[2], "r");
while(fscanf(datafile, "%d", &nums[N++]) == 1){
nums = realloc(nums, (N+1) * sizeof(int));
}
fclose (datafile);
N--;
printf("%d from file\n", N);
for(i=0;i<N;i++) { printf("%d ", nums[i]); }
qsort(nums,N,sizeof(int),compareint);
printf("\nSorted:\n"); for(i=0;i<N;i++) { printf("%d ", nums[i]); }
}


//=================================================================================================
//calc descriptive stats
//=================================================================================================
double dmin = nums[0], dmax = nums[N-1];
double sumN=0.0, median=0.0, Q1=0.0, Q2=0.0, Q3=0.0, IQR=0.0;
double diff = 0.0, sqrdiffmean = 0.0, cubediffmean = 0.0, quaddiffmean = 0.0;
double meanabsdev = 0.0, rootmeansqr = 0.0;
char temp[15]="";
for(i=0;i<N;i++) {sumN += nums[i];}
double mean = sumN / (double)N;
for(i = 0; i < N; i++)
{
diff          = nums[i] - mean;
sqrdiffmean  += diff * diff ;  // for variance and sum squares
cubediffmean += diff * diff * diff ;  // for skewness
quaddiffmean += diff * diff * diff * diff ;  // for Kurtosis
meanabsdev   += fabs(diff) ;  // for mean absolute deviation
rootmeansqr  += nums[i] * nums[i] ;  // for root mean square
}

double stddev   = sqrt(sqrdiffmean/N);
double skewness = cubediffmean / (N * pow(stddev,3));
double kurtosis = quaddiffmean / (N * pow(stddev,4));

// median and quartiles
// quartiles divide sorted dataset into four sections
// Q1 = median of values less than Q2
// Q2 = median of the data set
// Q3 = median of values greater than Q2
if(N % 2 == 0) {
Q2 = median = (nums[(N/2)-1] + nums[N/2]) / 2.0;
i = N/2;
if(i % 2 == 0) {
Q1 = (nums[(i/2)-1] + nums[i/2]) / 2.0;
Q3 = (nums[i + ((i-1)/2)] + nums[i+(i/2)]) / 2.0;
}
else {
Q1 = nums[(i-1)/2];
Q3 = nums[i + ((i-1)/2)];
}
}
if(N % 2 != 0) {
Q2 = median = nums[(N-1)/2];
i = (N-1)/2;
if(i % 2 == 0) {
Q1 = (nums[(i/2)-1] + nums[i/2]) / 2.0;
Q3 = (nums[i + (i/2)] + nums[i + (i/2) + 1]) / 2.0;
}
else {
Q1 = nums[(i-1)/2];
Q3 = nums[i + ((i+1)/2)];
}
}

//mode
//1 array to hold count of each value in set
//2 count how many times each number in the set occurs,
//   and track the # of occurrences
//3 extract the values occurring most often
int occur = 0;
char mode[250] = "";
if(strcmp(argv[2],"-c") != 0) { //consecutive #s have no mode
int *modecnt = calloc(dmax + 1, sizeof(int)); //array
for(i = 0; i < N; i++)   { //count occurrences of each value
modecnt[nums[i]]++;
if(modecnt[nums[i]] > occur) {
occur = modecnt[nums[i]];
}
}
if (occur > 1) { //extract modes if any
for(i = 0; i <= dmax; i++) {
if(modecnt[i] == occur) {
sprintf(temp,"%d ",i);
strncat(mode,temp,strlen(temp));
}
}
}
free(modecnt);
}

// outliers
// below Q1−1.5xIQR, or above Q3+1.5xIQR
IQR = Q3 - Q1;
char outliers[200]="";
if (N > 3) {

//range for outliers
double lo = Q1 - (1.5 * IQR);
double hi = Q3 + (1.5 * IQR);

//no outliers
if (dmin >= lo && dmax <= hi) {
strcat(outliers,"none      (using IQR * 1.5 rule)");
}
//at least one outlier
if (dmin < lo || dmax > hi) {
for(i = 0; i < N; i++) {
double val = (double)nums[i];
if(val < lo || val > hi) {
sprintf(temp,"%.0f ",val);
strncat(outliers, temp, strlen(temp));
}
}
strcat(outliers," (using IQR * 1.5 rule)");
}
outliers[strlen(outliers)] = '\0';
}


//=================================================================================================
//output
//=================================================================================================

printf("\n--------------------------------------------------------------\n");
printf("Minimum            : %.0f\n", dmin);
printf("Maximum            : %.0f\n", dmax);
printf("Range              : %.0f\n", dmax - dmin);
printf("Size N             : %d\n"  , N);
printf("Sum  N             : %.0f\n", sumN);
printf("Mean μ             : %.2f\n", mean);
printf("Median             : %.1f\n", median);
if(occur > 1) {
printf("Mode(s)            : %s (%d occurrences ea)\n", mode,occur);}
else {
printf("Mode(s)            : na (no repeating values)\n");}
printf("Std Dev  σ         : %.6f\n", stddev);
printf("Variance σ^2       : %.6f\n", sqrdiffmean/N);
printf("Mid Range          : %.1f\n", (dmax + dmin)/2);
printf("Quartiles");
if(N > 3) {printf("        Q1: %.1f\n", Q1);}
if(N < 4) {printf("        Q1: na\n");}
printf("                 Q2: %.1f      (median)\n", Q2);
if(N > 3) {printf("                 Q3: %.1f\n", Q3);}
if(N < 4) {printf("                 Q3: na\n");}
printf("IQR                : %.1f      (interquartile range)\n", IQR);
if(N > 3) {printf("Outliers           : %s\n", outliers);}
if(N < 4) {printf("Outliers           : na\n");}
printf("Sum Squares SS     : %.6f\n", sqrdiffmean);
printf("MAD                : %.6f    (mean absolute deviation)\n", meanabsdev / N);
printf("Root Mean Sqr      : %.6f\n", sqrt(rootmeansqr / N));
printf("Std Error Mean     : %.6f\n", stddev / sqrt(N));
printf("Skewness  γ1       : %.6f\n", skewness);
printf("Kurtosis  β2       : %.6f\n", kurtosis);
printf("Kurtosis Excess α4 : %.6f\n", kurtosis - 3);
printf("CV                 : %.8f  (coefficient of variation\n", stddev / mean);
printf("RSD                : %.6f%%  (relative std deviation)\n", 100 * (stddev / mean));
printf("--------------------------------------------------------------\n");
printf("Check results up to N=9999 against\n");
printf("https://www.calculatorsoup.com/calculators/statistics/descriptivestatistics.php");
printf("\n\n");
free(nums);

return(0);
}
========================================================================================
OMG that's sweet!  The ONLY part not 100% mine from scratch is the 4-line comparator function.
That's pure pwnage of the programming clowns Mehram Maleki (you) and Larry Pietraskiewicz (Feeb).

His closest "buddy" in here is the brain-dead Relf..
No, though I did like Relf and will miss his odd posts.  I learned a bit about Usenet from him.

Date Sujet#  Auteur
4 Jan 25 * Why GIMP Is Better Than Photoshop32Farley Flud
5 Jan 25 `* Re: Why GIMP Is Better Than Photoshop31DFS
5 Jan 25  `* Re: Why GIMP Is Better Than Photoshop30-hh
5 Jan 25   +* Re: Why GIMP Is Better Than Photoshop4Farley Flud
6 Jan 25   i+* Re: Why GIMP Is Better Than Photoshop2-hh
6 Jan 25   ii`- Re: Why GIMP Is Better Than Photoshop1Farley Flud
6 Jan 25   i`- Re: Why GIMP Is Better Than Photoshop1DFS
6 Jan 25   `* Re: Why GIMP Is Better Than Photoshop25Lawrence D'Oliveiro
6 Jan 25    `* Re: Why GIMP Is Better Than Photoshop24-hh
6 Jan 25     `* Re: Why GIMP Is Better Than Photoshop23Lawrence D'Oliveiro
6 Jan 25      `* Re: Why GIMP Is Better Than Photoshop22-hh
6 Jan 25       `* Re: Why GIMP Is Better Than Photoshop21Lawrence D'Oliveiro
7 Jan 25        `* Re: Why GIMP Is Better Than Photoshop20-hh
7 Jan 25         +- Re: Why GIMP Is Better Than Photoshop1Lawrence D'Oliveiro
7 Jan 25         `* Re: Why GIMP Is Better Than Photoshop18Farley Flud
8 Jan 25          `* Re: Why GIMP Is Better Than Photoshop17Physfitfreak
8 Jan 25           `* Re: Why GIMP Is Better Than Photoshop16Farley Flud
8 Jan 25            `* Re: Why GIMP Is Better Than Photoshop15Physfitfreak
8 Jan 25             +- Re: Why GIMP Is Better Than Photoshop1Physfitfreak
8 Jan 25             `* Re: Why GIMP Is Better Than Photoshop13Farley Flud
8 Jan 25              `* Re: Why GIMP Is Better Than Photoshop12Physfitfreak
8 Jan 25               `* Re: Why GIMP Is Better Than Photoshop11Farley Flud
9 Jan 25                +* Re: Why GIMP Is Better Than Photoshop3Physfitfreak
9 Jan 25                i`* Re: Why GIMP Is Better Than Photoshop2Physfitfreak
9 Jan 25                i `- Re: Why GIMP Is Better Than Photoshop1Physfitfreak
9 Jan 25                `* Re: Why GIMP Is Better Than Photoshop7rbowman
10 Jan 25                 `* Re: Why GIMP Is Better Than Photoshop6Physfitfreak
10 Jan 25                  +- Re: Why GIMP Is Better Than Photoshop1DFS
10 Jan 25                  `* Re: Why GIMP Is Better Than Photoshop4Farley Flud
10 Jan 25                   +- Re: Why GIMP Is Better Than Photoshop1DFS
11 Jan 25                   `* Re: Why GIMP Is Better Than Photoshop2Physfitfreak
11 Jan 25                    `- Re: Why GIMP Is Better Than Photoshop1DFS

Haut de la page

Les messages affichés proviennent d'usenet.

NewsPortal