Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Contribute to GitLab
Sign in / Register
Toggle navigation
T
Thick-Common
Project
Project
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
潘栩锋
Thick-Common
Commits
39a52e19
Commit
39a52e19
authored
Aug 20, 2019
by
潘栩锋
🚴
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
1.添加 Misc.MyMath.Correl 支持double
parent
e35bd63d
Show whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
59 additions
and
1 deletion
+59
-1
MyMath.cs
Project.FLY.Misc/MISC/MyMath.cs
+59
-1
No files found.
Project.FLY.Misc/MISC/MyMath.cs
View file @
39a52e19
...
...
@@ -269,6 +269,64 @@ namespace Misc
return
0
;
}
/// <summary>
/// 求相关性
/// </summary>
/// <param name="x"></param>
/// <param name="y"></param>
public
static
double
Correl
(
IEnumerable
<
double
>
x
,
IEnumerable
<
double
>
y
)
{
return
Correl
(
x
,
0
,
y
,
0
,
x
.
Count
());
}
/// <summary>
/// 求相关性
/// </summary>
/// <param name="x"></param>
/// <param name="y"></param>
/// <returns></returns>
public
static
double
Correl
(
IEnumerable
<
double
>
x
,
int
x_offset
,
IEnumerable
<
double
>
y
,
int
y_offset
,
int
len
)
{
double
sum_x
=
0
;
double
sum_y
=
0
;
double
sum_x2
=
0
;
double
sum_y2
=
0
;
double
sum_xy
=
0
;
int
cnt
=
0
;
////避免溢出
//int max_x = Max(x, x_offset, x_offset + len - 1);
//if (max_x > 30000)
//{
//}
for
(
int
i
=
0
;
i
<
len
;
i
++)
{
int
x_i
=
i
+
x_offset
;
int
y_i
=
i
+
y_offset
;
double
xv
=
x
.
ElementAt
(
x_i
);
double
yv
=
y
.
ElementAt
(
y_i
);
if
((!
double
.
IsNaN
(
xv
))
&&
(!
double
.
IsNaN
(
yv
)))
{
sum_x
+=
xv
;
sum_y
+=
yv
;
sum_x2
+=
xv
*
xv
;
sum_y2
+=
yv
*
yv
;
sum_xy
+=
xv
*
yv
;
cnt
++;
}
}
if
(
cnt
>
0
)
{
double
s1
=
cnt
*
sum_xy
-
sum_x
*
sum_y
;
double
s2
=
Math
.
Sqrt
(
cnt
*
sum_x2
-
sum_x
*
sum_x
);
double
s3
=
Math
.
Sqrt
(
cnt
*
sum_y2
-
sum_y
*
sum_y
);
double
s4
=
s1
/
s2
/
s3
;
return
s4
;
}
else
return
0
;
}
/// <summary>
/// 求相关性
/// </summary>
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment