Free cookie consent management tool by TermsFeed Policy Generator

source: trunk/sources/HeuristicLab.Modeling/3.2/alglib/ap.cs @ 2428

Last change on this file since 2428 was 2428, checked in by gkronber, 14 years ago

Implemented #782 (Additional model quality metrics: Pearson product-moment correlation coefficient and Spearman's rank correlation coefficient)

File size: 5.1 KB
Line 
1/*************************************************************************
2AP library
3Copyright (c) 2003-2009 Sergey Bochkanov (ALGLIB project).
4
5>>> LICENSE >>>
6This program is free software; you can redistribute it and/or modify
7it under the terms of the GNU General Public License as published by
8the Free Software Foundation (www.fsf.org); either version 2 of the
9License, or (at your option) any later version.
10
11This program is distributed in the hope that it will be useful,
12but WITHOUT ANY WARRANTY; without even the implied warranty of
13MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
14GNU General Public License for more details.
15
16A copy of the GNU General Public License is available at
17http://www.fsf.org/licensing/licenses
18
19>>> END OF LICENSE >>>
20*************************************************************************/
21namespace AP
22{
23    /********************************************************************
24    Class defining a complex number with double precision.
25    ********************************************************************/
26    public struct Complex
27    {
28        public double x;
29        public double y;
30
31        public Complex(double _x)
32        {
33            x = _x;
34            y = 0;
35        }
36        public Complex(double _x, double _y)
37        {
38            x = _x;
39            y = _y;
40        }
41        public static implicit operator Complex(double _x)
42        {
43            return new Complex(_x);
44        }
45        public static bool operator==(Complex lhs, Complex rhs)
46        {
47            return (lhs.x==rhs.x) & (lhs.y==rhs.y);
48        }
49        public static bool operator!=(Complex lhs, Complex rhs)
50        {
51            return (lhs.x!=rhs.x) | (lhs.y!=rhs.y);
52        }
53        public static Complex operator+(Complex lhs)
54        {
55            return lhs;
56        }
57        public static Complex operator-(Complex lhs)
58        {
59            return new Complex(-lhs.x,-lhs.y);
60        }
61        public static Complex operator+(Complex lhs, Complex rhs)
62        {
63            return new Complex(lhs.x+rhs.x,lhs.y+rhs.y);
64        }
65        public static Complex operator-(Complex lhs, Complex rhs)
66        {
67            return new Complex(lhs.x-rhs.x,lhs.y-rhs.y);
68        }
69        public static Complex operator*(Complex lhs, Complex rhs)
70        {
71            return new Complex(lhs.x*rhs.x-lhs.y*rhs.y, lhs.x*rhs.y+lhs.y*rhs.x);
72        }
73        public static Complex operator/(Complex lhs, Complex rhs)
74        {
75            Complex result;
76            double e;
77            double f;
78            if( System.Math.Abs(rhs.y)<System.Math.Abs(rhs.x) )
79            {
80                e = rhs.y/rhs.x;
81                f = rhs.x+rhs.y*e;
82                result.x = (lhs.x+lhs.y*e)/f;
83                result.y = (lhs.y-lhs.x*e)/f;
84            }
85            else
86            {
87                e = rhs.x/rhs.y;
88                f = rhs.y+rhs.x*e;
89                result.x = (lhs.y+lhs.x*e)/f;
90                result.y = (-lhs.x+lhs.y*e)/f;
91            }
92            return result;
93        }
94    }   
95   
96  /********************************************************************
97  AP math namespace
98  ********************************************************************/
99  public struct rcommstate
100  {
101    public int stage;
102    public int[] ia;
103    public bool[] ba;
104    public double[] ra;
105    public AP.Complex[] ca;
106  };
107
108  /********************************************************************
109    AP math namespace
110    ********************************************************************/
111    public class Math
112    {
113        public static System.Random RndObject = new System.Random(System.DateTime.Now.Millisecond);
114
115        public const double MachineEpsilon = 5E-16;
116        public const double MaxRealNumber = 1E300;
117        public const double MinRealNumber = 1E-300;
118       
119        public static double RandomReal()
120        {
121            double r = 0;
122            lock(RndObject){ r = RndObject.NextDouble(); }
123            return r;
124        }
125        public static int RandomInteger(int N)
126        {
127            int r = 0;
128            lock(RndObject){ r = RndObject.Next(N); }
129            return r;
130        }
131        public static double Sqr(double X)
132        {
133            return X*X;
134        }       
135        public static double AbsComplex(Complex z)
136        {
137            double w;
138            double xabs;
139            double yabs;
140            double v;
141   
142            xabs = System.Math.Abs(z.x);
143            yabs = System.Math.Abs(z.y);
144            w = xabs>yabs ? xabs : yabs;
145            v = xabs<yabs ? xabs : yabs;
146            if( v==0 )
147                return w;
148            else
149            {
150                double t = v/w;
151                return w*System.Math.Sqrt(1+t*t);
152            }
153        }
154        public static Complex Conj(Complex z)
155        {
156            return new Complex(z.x, -z.y);
157        }   
158        public static Complex CSqr(Complex z)
159        {
160            return new Complex(z.x*z.x-z.y*z.y, 2*z.x*z.y);
161        }
162
163    }
164}
Note: See TracBrowser for help on using the repository browser.