Lazarus

Announcements => Third party => Topic started by: ebuxbaum on June 06, 2021, 11:10:59 am

Title: Announce: Pascal libraries for maths and statistics
Post by: ebuxbaum on June 06, 2021, 11:10:59 am
Hi,

I have just set up an archive on https://github.com/ebuxbaum/statistics (https://github.com/ebuxbaum/statistics), which contains routines in Object Pascal for general maths, vector and matrix algebra, and statistics (descriptive, decision, multivariate). User interaction is on the command line, so they should work under any OS. Also included is an extensive documentation in LaTeX.

Any comments welcome.

Sincerely

Engelbert
Title: Re: Announce: Pascal libraries for maths and statistics
Post by: Leledumbo on June 06, 2021, 01:42:14 pm
Ah, you have PCA. Thank you.
Title: Re: Announce: Pascal libraries for maths and statistics
Post by: skalogryz on June 13, 2021, 02:38:35 am
GPL3? I don't know...
I thought more permissive licenses like MIT are more popular these days.
Title: Re: Announce: Pascal libraries for maths and statistics
Post by: Alextp on June 13, 2021, 04:36:58 pm
Because of GPL I cannot use these codes,  my app has MPL 2.0 license.
Title: Re: Announce: Pascal libraries for maths and statistics
Post by: schuler on June 17, 2021, 07:02:56 pm
@ebuxbaum,
Given that I'm feeling lazy, instead of looking at the code, I'll just ask you: do you have an example/test with PCA?
Title: Re: Announce: Pascal libraries for maths and statistics
Post by: Paolo on July 19, 2021, 08:57:43 pm
just look at complex.pas, please note that functon Polar is wrong
Code: Pascal  [Select][+][-]
  1.  PROCEDURE Polar(z: ComplexTyp; VAR r, phi: float);
  2.  
  3. BEGIN
  4.   r := ComplexAbs(z);
  5.   IF r <> 0                                                                   // r > 0 should be enough
  6.     THEN IF Abs(Im(z) / r) = 1
  7.            THEN phi := Pi / 2 * (Im(z) / r) / Abs(Im(z) / r)  // why not just Im(z)/Abs(z) or sign(Im(z))
  8.            ELSE phi := ArcTan(Im(z) / Re(z))                      //you can stay here even with Re(z) < 0
  9.     ELSE
  10.       BEGIN
  11.         phi := 0;                                                          
  12.         IF Re(z) < 0                     //if you stay here r=0 so how is it possible that Re(z) < 0 ?
  13.           THEN
  14.             IF Im(z) <> 0                //if you stay here r=0 so how is it possible that Im(z) <> 0 ?
  15.               THEN phi := phi + Pi * Abs(Im(z)) / Im(z)
  16.               ELSE phi := Pi;
  17.       END;
  18. END;
  19.  

using arctan you cannot distinguish among quadrants (plus some redundancy in the code, see the notes)

all the code above can be made by arctan2 function, and in your case in your case you already have ComplexArg function that do the job, not tested anyway.

but as I said you can simply use arctan2

Code: Pascal  [Select][+][-]
  1. {$ifndef FPC_MATH_HAS_ARCTAN2}
  2. function arctan2(y,x : float) : float;
  3.   begin
  4.     if (x=0) then
  5.       begin
  6.         if y=0 then
  7.           arctan2:=0.0
  8.         else if y>0 then
  9.           arctan2:=pi/2
  10.         else if y<0 then  //why such test, here "else" should be sufficent
  11.           arctan2:=-pi/2;
  12.       end
  13.     else
  14.       ArcTan2:=ArcTan(y/x);  
  15.     if x<0.0 then                      
  16.       ArcTan2:=ArcTan2+pi;
  17.     if ArcTan2>pi then
  18.       ArcTan2:=ArcTan2-2*pi;
  19.   end;
  20. {$endif FPC_MATH_HAS_ARCTAN2}
  21.  

where is defined "FPC_MATH_HAS_ARCTAN2" ?
Title: Re: Announce: Pascal libraries for maths and statistics
Post by: winni on July 19, 2021, 09:18:22 pm
Hi!

{$define FPC_MATH_HAS_ARCTAN2}

is defined in the file mathu.inc

What  kind of complicated source is your arctan2?

Mine for a 64 bit CPU is just

Code: Pascal  [Select][+][-]
  1. function arctan2(y,x : float) : float;assembler;
  2.   asm
  3.      fldt y
  4.      fldt x
  5.      fpatan
  6.      fwait
  7.   end;  

Winni
Title: Re: Announce: Pascal libraries for maths and statistics
Post by: Paolo on July 19, 2021, 10:30:47 pm
@winni,
I found it in math.pas, doing ctrl+click in the code I jump there even if ti seems not reachable during debug pressing F7, but it seems active like if FPC_MATH_HAS_ARCTAN2 were not defined ($ifndef...).
I was expecting something like you showed, where is located such function ?

here laz 2.0.10, fpc 3.2.0, win 10.
Title: Re: Announce: Pascal libraries for maths and statistics
Post by: Paolo on July 19, 2021, 10:46:58 pm
ok it is in mathu.inc, but it is disabled ! it has in front {$ifdef FPC_HAS_TYPE_EXTENDED} that seems not true...
Title: Re: Announce: Pascal libraries for maths and statistics
Post by: winni on July 19, 2021, 11:53:17 pm
Hi!

In my case {$ifdef FPC_HAS_TYPE_EXTENDED} is not off.

Otherwise the code would be greyed.
Remember: For 64 bit machines extended is just mapped to Double!!!

Winni

fpc 3.2.0 Lazarus 2.0.12 one Suse Tumbleweed (that is 64 bit)
Title: Re: Announce: Pascal libraries for maths and statistics
Post by: ccrause on July 20, 2021, 08:10:03 am
@Paolo
 the extended type is available on all Intel x86 processors, except on the Windows 64-bit platform.  (https://www.freepascal.org/docs-html/ref/refsu5.html)

Which would explain why FPC_HAS_TYPE_EXTENDED is not defined in your case.
Title: Re: Announce: Pascal libraries for maths and statistics
Post by: Jurassic Pork on July 20, 2021, 10:08:46 am
hello,
and  what about DMath, LMath packages ? do they do the same job ?
Quote
DMath is a mathematical library for Delphi and Free Pascal, written natively in Pascal.

It includes routines for:

Elementary functions
Special functions
Probability distributions
Linear algebra
Optimisation
Polinomials
Numerical integration and differential equations
Fourier transform
Random numbers
Statistics
Linear regression
Multilinear regression and principal component analysis
Nonlinear regression with a library of non-linear regression models
Complex numbers and functions
Fractals and chaos
Expression parsing
Graphical functions
Author: Jean Debord, Laboratoire de Pharmacologie, Faculté de Médecine, Limoges, France

License: LGPL 2.0
Friendly, J.P
Title: Re: Announce: Pascal libraries for maths and statistics
Post by: Paolo on July 20, 2021, 01:39:01 pm
@ccrause, thaks it seems the cause (sigh!  :'()
TinyPortal © 2005-2018