Skip to content

Commit

Permalink
use fixed rng generator in stochastic_edf instead of std::default_ran…
Browse files Browse the repository at this point in the history
…dom_engine (which is implementation defined), fixed test data files
  • Loading branch information
AlePalu committed Dec 5, 2023
1 parent 609eeb3 commit d999940
Show file tree
Hide file tree
Showing 12 changed files with 136 additions and 130 deletions.
4 changes: 4 additions & 0 deletions .github/workflows/test-macos-clang.yml
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,11 @@ jobs:
run: |
brew install eigen
- name: run_tests
id: test_result
run: |
cd test/
chmod +x run_tests.sh
./run_tests.sh --compiler clang
- name: check tests passed
if: steps.test_result.outputs.result != 0
run: exit 1
2 changes: 1 addition & 1 deletion fdaPDE/models/regression/stochastic_edf.h
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ class StochasticEDF {
std::size_t n = model_.Psi().cols(); // number of basis functions
if (!init_) {
// compute sample from Rademacher distribution
std::default_random_engine rng(seed_);
std::mt19937 rng(seed_);
std::bernoulli_distribution Be(0.5); // bernulli distribution with parameter p = 0.5
Us_.resize(model_.n_obs(), r_); // preallocate memory for matrix Us
// fill matrix
Expand Down
26 changes: 13 additions & 13 deletions test/data/models/gcv/2D_test2/edfs.mtx
Original file line number Diff line number Diff line change
@@ -1,15 +1,15 @@
%%MatrixMarket matrix coordinate real general
13 1 13
1 1 4.32044645746894332e+02
2 1 4.25557826358423029e+02
3 1 4.14916335726335660e+02
4 1 3.98298698170906448e+02
5 1 3.74073263813082065e+02
6 1 3.41675245320309500e+02
7 1 3.02334595579629763e+02
8 1 2.59007047290856917e+02
9 1 2.15441688634389209e+02
10 1 1.74958341150108026e+02
11 1 1.39626444941978491e+02
12 1 1.10159798620504887e+02
13 1 8.63108234557470126e+01
1 1 4.32021039198922892e+02
2 1 4.25522929567800020e+02
3 1 4.14873042530062378e+02
4 1 3.98266076895162541e+02
5 1 3.74103735893420662e+02
6 1 3.41866879972166089e+02
7 1 3.02816167075625515e+02
8 1 2.59884360468809632e+02
9 1 2.16730493986841623e+02
10 1 1.76556030915588451e+02
11 1 1.41348626077408881e+02
12 1 1.11811153816370691e+02
13 1 8.77443855394085830e+01
26 changes: 13 additions & 13 deletions test/data/models/gcv/2D_test2/gcvs.mtx
Original file line number Diff line number Diff line change
@@ -1,15 +1,15 @@
%%MatrixMarket matrix coordinate real general
13 1 13
1 1 3.99521157143593042e-02
2 1 3.96780663311930085e-02
3 1 3.93209291270814262e-02
4 1 3.89846453373592222e-02
5 1 3.89528044130071568e-02
6 1 3.97027865252773185e-02
7 1 4.17477399380632164e-02
8 1 4.54051262198951963e-02
9 1 5.07834703175452859e-02
10 1 5.80290315658153685e-02
11 1 6.74495508972190322e-02
12 1 7.93012680610599152e-02
13 1 9.35351645449739588e-02
1 1 3.97423159913252999e-02
2 1 3.94993404954733368e-02
3 1 3.91907250420472225e-02
4 1 3.89251495840626099e-02
5 1 3.89882994691757440e-02
6 1 3.98564341380043818e-02
7 1 4.20392292293938763e-02
8 1 4.58460709519122808e-02
9 1 5.13688202359919507e-02
10 1 5.87323371480102940e-02
11 1 6.82270821048180098e-02
12 1 8.00988833219871688e-02
13 1 9.42958632289764148e-02
50 changes: 25 additions & 25 deletions test/data/models/gcv/2D_test4/edfs.mtx
Original file line number Diff line number Diff line change
@@ -1,27 +1,27 @@
%%MatrixMarket matrix coordinate real general
25 1 25
1 1 1.06270977581565006e+02
2 1 9.12781878154271595e+01
3 1 7.68216314734006431e+01
4 1 6.36368232668402314e+01
5 1 5.20874830058305562e+01
6 1 4.22619783483174274e+01
7 1 3.40612617815139203e+01
8 1 2.72926608538180062e+01
9 1 2.17650509877889817e+01
10 1 1.73309390327612363e+01
11 1 1.38629820650085431e+01
12 1 1.12197970258596094e+01
13 1 9.24700647123681385e+00
14 1 7.79750626571524652e+00
15 1 6.74085317219083091e+00
16 1 5.96326507965191510e+00
17 1 5.37181793542495178e+00
18 1 4.90124887162198419e+00
19 1 4.51242586263820300e+00
20 1 4.18377055475370874e+00
21 1 3.90382259859446323e+00
22 1 3.66432454265614727e+00
23 1 3.45479036967105779e+00
24 1 3.26508343895101216e+00
25 1 3.09306489406572727e+00
1 1 1.04855259314200708e+02
2 1 8.95540782044290040e+01
3 1 7.49884417381362027e+01
4 1 6.18903640466741791e+01
5 1 5.05737190513991024e+01
6 1 4.10566008341611663e+01
7 1 3.31779272887793795e+01
8 1 2.67036175067818355e+01
9 1 2.14184258657010069e+01
10 1 1.71648532642079026e+01
11 1 1.38201488131988715e+01
12 1 1.12581217392264801e+01
13 1 9.34146374941871649e+00
14 1 7.93490872945333958e+00
15 1 6.91306922133931057e+00
16 1 6.16300326230962536e+00
17 1 5.59089823851671230e+00
18 1 5.12988637242883794e+00
19 1 4.73967556553652791e+00
20 1 4.39970218929568269e+00
21 1 4.10215062353023807e+00
22 1 3.84321306684485853e+00
23 1 3.61537871833021995e+00
24 1 3.40955480223371676e+00
25 1 3.22380241693635439e+00
50 changes: 25 additions & 25 deletions test/data/models/gcv/2D_test4/gcvs.mtx
Original file line number Diff line number Diff line change
@@ -1,27 +1,27 @@
%%MatrixMarket matrix coordinate real general
25 1 25
1 1 1.99333254551576555e+00
2 1 1.93395161631425827e+00
3 1 1.87444001831781870e+00
4 1 1.81641749586584922e+00
5 1 1.76080583934040402e+00
6 1 1.70824617637648535e+00
7 1 1.65956189596789194e+00
8 1 1.61611778889017765e+00
9 1 1.57942695924555609e+00
10 1 1.55034942751862159e+00
11 1 1.52854900341808309e+00
12 1 1.51297617852348565e+00
13 1 1.50284702259311587e+00
14 1 1.49773839485892979e+00
15 1 1.49676218401194006e+00
16 1 1.49833515718130461e+00
17 1 1.50109452267282428e+00
18 1 1.50472406751965981e+00
19 1 1.51052309120612627e+00
20 1 1.52348951559282542e+00
21 1 1.55788900569283362e+00
22 1 1.64774989708737629e+00
23 1 1.85824856735570876e+00
24 1 2.27531843854887139e+00
25 1 2.94263623382949380e+00
1 1 1.90891775494798566e+00
2 1 1.85293951608389640e+00
3 1 1.80354439273861744e+00
4 1 1.75873403988546917e+00
5 1 1.71681723470431780e+00
6 1 1.67670119072799984e+00
7 1 1.63835701302016101e+00
8 1 1.60295016301302895e+00
9 1 1.57211543386299368e+00
10 1 1.54700361242298379e+00
11 1 1.52771602383640026e+00
12 1 1.51370224152849064e+00
13 1 1.50460376634155546e+00
14 1 1.50026351715042305e+00
15 1 1.49990566091079658e+00
16 1 1.50196851701618339e+00
17 1 1.50507348178885625e+00
18 1 1.50887518859554581e+00
19 1 1.51465517164148333e+00
20 1 1.52744128249058697e+00
21 1 1.56159374640848725e+00
22 1 1.65127857550186530e+00
23 1 1.86181587497195600e+00
24 1 2.27924300647016276e+00
25 1 2.94722404627099976e+00
26 changes: 13 additions & 13 deletions test/data/models/gcv/2D_test6/edfs.mtx
Original file line number Diff line number Diff line change
@@ -1,15 +1,15 @@
%%MatrixMarket matrix coordinate real general
13 1 13
1 1 3.92639873661275544e+02
2 1 3.67005359358505871e+02
3 1 3.34396032847368758e+02
4 1 2.96854390242241266e+02
5 1 2.57293503677055696e+02
6 1 2.18346310459933164e+02
7 1 1.81810724142492148e+02
8 1 1.48761124842487476e+02
9 1 1.19818784211309762e+02
10 1 9.52531545500184080e+01
11 1 7.49790711890389048e+01
12 1 5.86159568240670694e+01
13 1 4.56216944905244262e+01
1 1 3.92337678199337461e+02
2 1 3.66560507495375191e+02
3 1 3.33793464517921848e+02
4 1 2.96112905460031016e+02
5 1 2.56471217803766365e+02
6 1 2.17527029467346324e+02
7 1 1.81074206819362047e+02
8 1 1.48155022286378340e+02
9 1 1.19352391905695598e+02
10 1 9.49153515931277667e+01
11 1 7.47610573867771677e+01
12 1 5.85196371270228326e+01
13 1 4.56516384107361262e+01
26 changes: 13 additions & 13 deletions test/data/models/gcv/2D_test6/gcvs.mtx
Original file line number Diff line number Diff line change
@@ -1,15 +1,15 @@
%%MatrixMarket matrix coordinate real general
13 1 13
1 1 4.40443133834047207e-01
2 1 4.13489805727039306e-01
3 1 3.82417619045291590e-01
4 1 3.50200699824506412e-01
5 1 3.19596782632299292e-01
6 1 2.92530938416051711e-01
7 1 2.70185278671796480e-01
8 1 2.53390007936006190e-01
9 1 2.42920844592872109e-01
10 1 2.39511010690212689e-01
11 1 2.43901092351600401e-01
12 1 2.57448427762076604e-01
13 1 2.83771409947806474e-01
1 1 4.34989771446547102e-01
2 1 4.08562526277372162e-01
3 1 3.78130843875191303e-01
4 1 3.46625446400602333e-01
5 1 3.16754793649113409e-01
6 1 2.90389957201114046e-01
7 1 2.68656271478976194e-01
8 1 2.52342208518361089e-01
9 1 2.42216879946678537e-01
10 1 2.39043679693174110e-01
11 1 2.43610801114107656e-01
12 1 2.57318778061728315e-01
13 1 2.83814397606675706e-01
26 changes: 13 additions & 13 deletions test/data/models/gcv/2D_test8/edfs.mtx
Original file line number Diff line number Diff line change
@@ -1,15 +1,15 @@
%%MatrixMarket matrix coordinate real general
13 1 13
1 1 6.83104768409759799e+00
2 1 6.71236355717686095e+00
3 1 6.52356943727560967e+00
4 1 6.24116565057531059e+00
5 1 5.85041225600076498e+00
6 1 5.35405101997265742e+00
7 1 4.77255903512690693e+00
8 1 4.13699679744609394e+00
9 1 3.48458909961546315e+00
10 1 2.86043979087440103e+00
11 1 2.31368160554780911e+00
12 1 1.88068175893077805e+00
13 1 1.56994837816481492e+00
1 1 6.83293513386279194e+00
2 1 6.71569036485425475e+00
3 1 6.52933864335703884e+00
4 1 6.25081032121975699e+00
5 1 5.86546542637629642e+00
6 1 5.37524138213206548e+00
7 1 4.79910443157617550e+00
8 1 4.16775160061379690e+00
9 1 3.52079168294696654e+00
10 1 2.90669213421517547e+00
11 1 2.37515519489696469e+00
12 1 1.95945455924774681e+00
13 1 1.66423550973962930e+00
26 changes: 13 additions & 13 deletions test/data/models/gcv/2D_test8/gcvs.mtx
Original file line number Diff line number Diff line change
@@ -1,15 +1,15 @@
%%MatrixMarket matrix coordinate real general
13 1 13
1 1 2.56960716321667775e+01
2 1 2.49212379291962769e+01
3 1 2.37278907064885978e+01
4 1 2.20506431657932183e+01
5 1 1.99866647378768612e+01
6 1 1.78620876450079429e+01
7 1 1.61266862014873773e+01
8 1 1.51260832893288590e+01
9 1 1.49640061955584951e+01
10 1 1.55220163816125858e+01
11 1 1.65359284471161168e+01
12 1 1.76814853738732261e+01
13 1 1.86935898436080734e+01
1 1 2.62799647644697352e+01
2 1 2.55078746397448164e+01
3 1 2.43131525790858554e+01
4 1 2.26220341098014401e+01
5 1 2.05205552362241725e+01
6 1 1.83310463660431964e+01
7 1 1.65180458967136339e+01
8 1 1.54563689156867579e+01
9 1 1.52770395767984528e+01
10 1 1.58747803459192252e+01
11 1 1.69784421943835788e+01
12 1 1.82384502948204386e+01
13 1 1.93600877443842023e+01
2 changes: 2 additions & 0 deletions test/run_tests.sh
Original file line number Diff line number Diff line change
Expand Up @@ -81,6 +81,8 @@ if [ "$MEMCHECK" = true ]; then
valgrind --leak-check=full --track-origins=yes ./fdapde_test
else
./fdapde_test
TEST_OUTPUT=$? ## get exit code
fi

rm fdapde_test
exit $TEST_OUTPUT
2 changes: 1 addition & 1 deletion test/src/gcv_srpde_newton_test.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -173,7 +173,7 @@ TEST(gcv_srpde_newton_test, laplacian_nonparametric_samplingatnodes_newton_fd_st
DVector<double> pt = SVector<1>(6.25e-06);
opt.optimize(GCV, pt);
auto best_lambda = opt.optimum();
DVector<double> expected_lambda = SVector<1>(0.0000071167457322);
DVector<double> expected_lambda = SVector<1>(0.0000075627208132);
// check optimal lambda
EXPECT_TRUE( almost_equal(best_lambda[0], expected_lambda[0]) );
}

0 comments on commit d999940

Please sign in to comment.