Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
SWIFTsim
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Deploy
Releases
Model registry
Monitor
Incidents
Analyze
Value stream analytics
Contributor analytics
Repository analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
SWIFT
SWIFTsim
Commits
eee112e2
Commit
eee112e2
authored
6 years ago
by
Folkert Nobels
Browse files
Options
Downloads
Patches
Plain Diff
Format the testRandom code
parent
7862afa2
No related branches found
No related tags found
1 merge request
!742
Fix the random number generator
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
tests/testRandom.c
+17
-10
17 additions, 10 deletions
tests/testRandom.c
with
17 additions
and
10 deletions
tests/testRandom.c
+
17
−
10
View file @
eee112e2
/*******************************************************************************
* This file is part of SWIFT.
* Copyright (C) 2019 Matthieu Schaller (schaller@strw.leidenuniv.nl)
* 2019 Folkert Nobels (nobels@strw.leidenuniv.nl)
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU Lesser General Public License as published
...
...
@@ -75,8 +76,8 @@ int main(int argc, char* argv[]) {
const
double
r
=
random_unit_interval
(
id
,
ti_current
,
random_number_star_formation
);
const
double
r_2ndid
=
random_unit_interval
(
idoffset
,
ti_current
,
random_number_star_formation
);
const
double
r_2ndid
=
random_unit_interval
(
idoffset
,
ti_current
,
random_number_star_formation
);
total
+=
r
;
total2
+=
r
*
r
;
...
...
@@ -96,25 +97,31 @@ int main(int argc, char* argv[]) {
const
double
var
=
total2
/
(
double
)
count
-
mean
*
mean
;
/* Pearson correlation calculation for different times */
const
double
mean_xy
=
sum_previous_current
/
(
(
double
)
count
-
1
.
f
);
const
double
correlation
=
(
mean_xy
-
mean
*
mean
)
/
var
;
const
double
mean_xy
=
sum_previous_current
/
((
double
)
count
-
1
.
f
);
const
double
correlation
=
(
mean_xy
-
mean
*
mean
)
/
var
;
/* Pearson correlation for different IDs */
const
double
meanID
=
totalID
/
(
double
)
count
;
const
double
varID
=
total2ID
/
(
double
)
count
-
meanID
*
meanID
;
const
double
meanID_xy
=
pearsonIDs
/
(
double
)
count
;
const
double
correlationID
=
(
meanID_xy
-
mean
*
meanID
)
/
pow
(
var
*
varID
,
.
5
f
);
const
double
correlationID
=
(
meanID_xy
-
mean
*
meanID
)
/
pow
(
var
*
varID
,
.
5
f
);
/* Verify that the mean and variance match the expected values for a uniform
* distribution */
if
((
fabs
(
mean
-
0
.
5
)
/
0
.
5
>
2e-4
)
||
(
fabs
(
var
-
1
.
/
12
.)
/
(
1
.
/
12
.)
>
1e-3
)
||
(
fabs
(
correlation
)
>
3e-4
)
||
(
fabs
(
correlationID
)
>
3e-4
)
)
{
(
fabs
(
correlation
)
>
3e-4
)
||
(
fabs
(
correlationID
)
>
3e-4
))
{
message
(
"Test failed!"
);
message
(
"Result: count=%d mean=%f var=%f, correlation=%f ID correlation=%f"
,
count
,
mean
,
var
,
correlation
,
correlationID
);
message
(
"Expected: count=%d mean=%f var=%f, correlation=%f ID correlation=%f"
,
count
,
0
.
5
f
,
1
.
/
12
.,
0
.,
0
.);
message
(
"Result: count=%d mean=%f var=%f, correlation=%f ID "
"correlation=%f"
,
count
,
mean
,
var
,
correlation
,
correlationID
);
message
(
"Expected: count=%d mean=%f var=%f, correlation=%f ID "
"correlation=%f"
,
count
,
0
.
5
f
,
1
.
/
12
.,
0
.,
0
.);
return
1
;
}
}
...
...
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment