nasa / prog_models

The NASA Prognostic Model Package is a Python framework focused on defining and building models for prognostics (computation of remaining useful life) of engineering systems, and provides a set of prognostics models for select components developed within this framework, suitable for use in prognostics applications for these components.
123 stars 50 forks source link

Tests/calc error #539

Closed aqitya closed 1 year ago

aqitya commented 1 year ago

Moved error checks from each error calculation method to calc_error() to reduce redundancy in code. Furthermore, created tests for calc_error().

Few clarifications of the code below:

Line 1146 of prognostics_model.py follows a format where all three arguments are assumed to be able to take up any one of the acceptable_types: dict, tuple, np.ndarray, list, SimResult, LazySimResult.

check_iterable() ensures that every index of a iterable is either an iterable or Numbers. However, you cannot have both iterables and Numbers exist. Wrote this as a helper function since it may be useful for other functions in prognostics_model.py.

github-actions[bot] commented 1 year ago

Thank you for opening this PR. Each PR into dev requires a code review. For the code review, look at the following:

github-actions[bot] commented 1 year ago
Benchmarking Results From: Test Time (s)
import main 0.12469980000000003
import thrown object 0.49806820000000007
model initialization 0.11861029999999984
set noise 0.6697803
simulate 0.29934819999999984
simulate with saving 0.9163317000000002
simulate with saving, dt 1.0353054
simulate with printing results, dt 1.2595966
Plot results 14.026792900000002
Metrics 0.038930000000000575
Surrogate Model Generation 3.1529358999999992
surrogate sim 1.0093661000000012
surrogate sim, dt 2.9103211999999985
To: Test Time (s)
import main 0.12962779999999996
import thrown object 0.5053261999999998
model initialization 0.11623820000000018
set noise 0.6811134000000001
simulate 0.29633069999999995
simulate with saving 0.9090802999999998
simulate with saving, dt 1.0165810999999998
simulate with printing results, dt 1.2481307
Plot results 13.916891200000002
Metrics 0.038952199999997106
Surrogate Model Generation 3.227964
surrogate sim 0.9920252999999981
surrogate sim, dt 2.8633743000000003
github-actions[bot] commented 1 year ago
Benchmarking Results [Update] From: Test Time (s)
import main 0.13090160000000006
import thrown object 0.5080172999999999
model initialization 0.12312590000000001
set noise 0.6774336000000001
simulate 0.2967261999999997
simulate with saving 0.9436775000000002
simulate with saving, dt 1.0352918
simulate with printing results, dt 1.2527399999999993
Plot results 15.064625199999998
Metrics 0.0359417999999998
Surrogate Model Generation 3.3143895999999984
surrogate sim 1.0997822
surrogate sim, dt 2.992298299999998

To:

Test Time (s)
import main 0.1302002
import thrown object 0.5018836999999998
model initialization 0.12059810000000004
set noise 0.6638683999999999
simulate 0.2963914000000001
simulate with saving 0.933589
simulate with saving, dt 1.0332176000000004
simulate with printing results, dt 1.2495984
Plot results 14.9107681
Metrics 0.03710050000000109
Surrogate Model Generation 3.4154221999999983
surrogate sim 1.0946610999999997
surrogate sim, dt 2.964583000000001
github-actions[bot] commented 1 year ago
Benchmarking Results [Update] From: Test Time (s)
import main 0.12485999999999997
import thrown object 0.5025399000000002
model initialization 0.11747639999999993
set noise 0.6762843999999999
simulate 0.2970367999999999
simulate with saving 0.9067835
simulate with saving, dt 1.0273966999999997
simulate with printing results, dt 1.2504606999999996
Plot results 14.0149308
Metrics 0.040364600000000195
Surrogate Model Generation 3.1643414000000014
surrogate sim 0.9905653000000001
surrogate sim, dt 2.876856499999999

To:

Test Time (s)
import main 0.12494669999999997
import thrown object 0.4989329
model initialization 0.1162323999999999
set noise 0.6765450000000002
simulate 0.2992290999999998
simulate with saving 0.9141124999999999
simulate with saving, dt 1.0271132
simulate with printing results, dt 1.2449735000000004
Plot results 13.965645
Metrics 0.039420499999998526
Surrogate Model Generation 3.245946
surrogate sim 0.9900526999999997
surrogate sim, dt 2.8539744999999996
github-actions[bot] commented 1 year ago
Benchmarking Results [Update] From: Test Time (s)
import main 0.16813259999999985
import thrown object 0.6633701999999999
model initialization 0.19332780000000005
set noise 0.7966855000000002
simulate 0.4187257
simulate with saving 1.3819695999999997
simulate with saving, dt 1.4416580000000003
simulate with printing results, dt 1.7946039000000003
Plot results 23.5316769
Metrics 0.04464259999999598
Surrogate Model Generation 4.690454100000004
surrogate sim 1.8020652000000013
surrogate sim, dt 4.311510800000001

To:

Test Time (s)
import main 0.160474
import thrown object 0.6017737000000001
model initialization 0.1673798999999998
set noise 0.8301324999999999
simulate 0.43930429999999987
simulate with saving 1.3359091999999997
simulate with saving, dt 1.4461750000000002
simulate with printing results, dt 1.7551374000000006
Plot results 22.8494376
Metrics 0.04538960000000003
Surrogate Model Generation 4.7659921999999995
surrogate sim 1.7276331000000056
surrogate sim, dt 4.177431800000001
github-actions[bot] commented 1 year ago
Benchmarking Results [Update] From: Test Time (s)
import main 0.1305322
import thrown object 0.49896509999999994
model initialization 0.1259424
set noise 0.6646617000000001
simulate 0.29727539999999975
simulate with saving 0.9467782999999996
simulate with saving, dt 1.0346376999999998
simulate with printing results, dt 1.2452364999999999
Plot results 15.200561099999998
Metrics 0.037418800000001085
Surrogate Model Generation 3.2762832999999993
surrogate sim 1.116993400000002
surrogate sim, dt 3.0244946000000006

To:

Test Time (s)
import main 0.1311477000000001
import thrown object 0.5120507999999999
model initialization 0.12173239999999996
set noise 0.6451153999999999
simulate 0.29642999999999997
simulate with saving 0.9424513000000001
simulate with saving, dt 1.0300891
simulate with printing results, dt 1.2468392000000001
Plot results 14.7750573
Metrics 0.03653360000000205
Surrogate Model Generation 3.4065179000000008
surrogate sim 1.1108811000000003
surrogate sim, dt 3.004767900000001
github-actions[bot] commented 1 year ago
Benchmarking Results [Update] From: Test Time (s)
import main 0.13475150000000014
import thrown object 0.5146050999999998
model initialization 0.12317120000000004
set noise 0.6687415000000001
simulate 0.2968476
simulate with saving 0.9418646000000002
simulate with saving, dt 1.0322576999999997
simulate with printing results, dt 1.2341566999999998
Plot results 14.708541800000003
Metrics 0.03690629999999828
Surrogate Model Generation 3.233027100000001
surrogate sim 1.1031697999999999
surrogate sim, dt 2.9670895999999978

To:

Test Time (s)
import main 0.12861689999999992
import thrown object 0.4982542000000001
model initialization 0.12049450000000017
set noise 0.6473148000000002
simulate 0.2954597000000003
simulate with saving 0.9269421000000002
simulate with saving, dt 1.0202008
simulate with printing results, dt 1.2301884999999997
Plot results 14.741025399999998
Metrics 0.035857100000001196
Surrogate Model Generation 3.3301704999999977
surrogate sim 1.0999747999999983
surrogate sim, dt 2.968806800000003
github-actions[bot] commented 1 year ago
Benchmarking Results [Update] From: Test Time (s)
import main 0.16774370000000016
import thrown object 0.6060314
model initialization 0.16473280000000012
set noise 0.7654663999999998
simulate 0.42979009999999995
simulate with saving 1.2843844
simulate with saving, dt 1.3942807000000004
simulate with printing results, dt 1.8053545
Plot results 21.982244
Metrics 0.043145299999999054
Surrogate Model Generation 4.500743599999996
surrogate sim 1.7244000999999969
surrogate sim, dt 4.1844924999999975

To:

Test Time (s)
import main 0.16892719999999994
import thrown object 0.593242
model initialization 0.1688052
set noise 0.7848215999999999
simulate 0.3981099000000001
simulate with saving 1.2942738
simulate with saving, dt 1.4421689000000004
simulate with printing results, dt 1.7666657000000008
Plot results 21.8937206
Metrics 0.04224830000000068
Surrogate Model Generation 4.680211400000005
surrogate sim 1.7361035000000058
surrogate sim, dt 4.120238700000002
github-actions[bot] commented 1 year ago
Benchmarking Results [Update] From: Test Time (s)
import main 0.12763709999999995
import thrown object 0.5121156
model initialization 0.1179520999999999
set noise 0.6662909999999997
simulate 0.2944553000000001
simulate with saving 0.9123842999999998
simulate with saving, dt 1.0207845999999998
simulate with printing results, dt 1.2404139999999995
Plot results 13.8653105
Metrics 0.040624299999997504
Surrogate Model Generation 3.103156600000002
surrogate sim 0.9865055000000034
surrogate sim, dt 2.8559516999999985

To:

Test Time (s)
import main 0.12475689999999995
import thrown object 0.5001043000000001
model initialization 0.11561100000000013
set noise 0.6755371000000001
simulate 0.2948892000000001
simulate with saving 0.9047935999999996
simulate with saving, dt 1.0181054
simulate with printing results, dt 1.2413682000000001
Plot results 13.8327731
Metrics 0.039770899999997056
Surrogate Model Generation 3.2008115000000004
surrogate sim 0.9927060999999995
surrogate sim, dt 2.8876676000000003
github-actions[bot] commented 1 year ago
Benchmarking Results [Update] From: Test Time (s)
import main 0.15306719999999996
import thrown object 0.6098178999999999
model initialization 0.14494610000000008
set noise 0.7801155
simulate 0.3304044000000004
simulate with saving 1.0441910999999995
simulate with saving, dt 1.1314428000000003
simulate with printing results, dt 1.4129125
Plot results 16.4649392
Metrics 0.03953849999999903
Surrogate Model Generation 3.6226153999999973
surrogate sim 1.224661000000001
surrogate sim, dt 3.3344159999999974

To:

Test Time (s)
import main 0.1457812999999999
import thrown object 0.5770698000000001
model initialization 0.1304053999999999
set noise 0.6964286
simulate 0.31243319999999963
simulate with saving 1.0301558000000002
simulate with saving, dt 1.0957061000000001
simulate with printing results, dt 1.3354819999999998
Plot results 16.556526599999998
Metrics 0.03844580000000164
Surrogate Model Generation 3.728815000000001
surrogate sim 1.206647799999999
surrogate sim, dt 3.244987899999998
github-actions[bot] commented 1 year ago
Benchmarking Results [Update] From: Test Time (s)
import main 0.14346880000000006
import thrown object 0.5038994000000001
model initialization 0.12251869999999987
set noise 0.6428301000000001
simulate 0.29381150000000034
simulate with saving 0.9244051
simulate with saving, dt 1.0195028999999995
simulate with printing results, dt 1.2404424
Plot results 14.6946263
Metrics 0.03681699999999921
Surrogate Model Generation 3.2268100000000004
surrogate sim 1.1102157000000012
surrogate sim, dt 3.0046777999999996

To:

Test Time (s)
import main 0.13245669999999987
import thrown object 0.5025929
model initialization 0.12019900000000017
set noise 0.6821143999999999
simulate 0.29454160000000007
simulate with saving 0.9323753999999997
simulate with saving, dt 1.0261510999999999
simulate with printing results, dt 1.2343552999999998
Plot results 14.630328400000002
Metrics 0.035172100000000484
Surrogate Model Generation 3.2864044999999997
surrogate sim 1.0967874999999978
surrogate sim, dt 2.928714300000003
codecov-commenter commented 1 year ago

Codecov Report

Merging #539 (be7e1e6) into dev (307d531) will increase coverage by 4.24%. The diff coverage is 100.00%.

@@            Coverage Diff             @@
##              dev     #539      +/-   ##
==========================================
+ Coverage   80.37%   84.61%   +4.24%     
==========================================
  Files          33       34       +1     
  Lines        2507     2509       +2     
==========================================
+ Hits         2015     2123     +108     
+ Misses        492      386     -106     
Impacted Files Coverage Δ
src/prog_models/prognostics_model.py 85.63% <100.00%> (+1.73%) :arrow_up:
src/prog_models/utils/calc_error.py 82.87% <100.00%> (+45.13%) :arrow_up:
src/prog_models/utils/input_validation.py 100.00% <100.00%> (ø)
github-actions[bot] commented 1 year ago
Benchmarking Results [Update] From: Test Time (s)
import main 0.16129119999999997
import thrown object 0.6061078
model initialization 0.16776600000000008
set noise 0.8235624000000001
simulate 0.3982597000000001
simulate with saving 1.3388807000000003
simulate with saving, dt 1.4599804
simulate with printing results, dt 1.8747157000000003
Plot results 22.200248900000002
Metrics 0.052419499999999175
Surrogate Model Generation 2.5128208000000036
surrogate sim 1.772653499999997
surrogate sim, dt 4.2039501

To:

Test Time (s)
import main 0.16728640000000006
import thrown object 0.6017181999999999
model initialization 0.16806070000000028
set noise 0.8025804999999999
simulate 0.4141965000000001
simulate with saving 1.3619308
simulate with saving, dt 1.4065455
simulate with printing results, dt 1.9181515000000005
Plot results 22.779024
Metrics 0.04499369999999914
Surrogate Model Generation 2.501412600000002
surrogate sim 1.8442500000000024
surrogate sim, dt 4.237291800000001
aqitya commented 1 year ago

Please look over the name choice of the function in the 'input_validation.py' file in the utils directory.

I changed the name from 'check_iterable()' to 'all_none_iterable()'.

github-actions[bot] commented 1 year ago
Benchmarking Results [Update] From: Test Time (s)
import main 0.124637
import thrown object 0.4990072000000001
model initialization 0.11750550000000004
set noise 0.6722793000000002
simulate 0.3033315999999999
simulate with saving 0.9199269999999999
simulate with saving, dt 1.0241078000000003
simulate with printing results, dt 1.2460575999999994
Plot results 13.953019100000002
Metrics 0.03989809999999849
Surrogate Model Generation 1.5792748000000003
surrogate sim 0.9902774000000001
surrogate sim, dt 2.897447400000001

To:

Test Time (s)
import main 0.12606399999999995
import thrown object 0.49735209999999985
model initialization 0.11553780000000002
set noise 0.6748145000000001
simulate 0.30213460000000003
simulate with saving 0.9233541999999999
simulate with saving, dt 1.0277995999999998
simulate with printing results, dt 1.2463778999999997
Plot results 13.845831200000001
Metrics 0.03910770000000241
Surrogate Model Generation 1.5693482000000003
surrogate sim 0.988703000000001
surrogate sim, dt 2.894559300000001
github-actions[bot] commented 1 year ago
Benchmarking Results [Update] From: Test Time (s)
import main 0.1286974999999999
import thrown object 0.5008128999999999
model initialization 0.12458189999999991
set noise 0.6602506000000001
simulate 0.30203610000000003
simulate with saving 0.948143
simulate with saving, dt 1.0599153000000001
simulate with printing results, dt 1.2496622000000004
Plot results 15.2658375
Metrics 0.03583910000000046
Surrogate Model Generation 1.6314226000000005
surrogate sim 1.0886700000000005
surrogate sim, dt 2.9796584000000017

To:

Test Time (s)
import main 0.13240580000000013
import thrown object 0.498548
model initialization 0.12049889999999985
set noise 0.6623140999999997
simulate 0.2994652000000002
simulate with saving 0.941573
simulate with saving, dt 1.0337372999999999
simulate with printing results, dt 1.2432615999999994
Plot results 15.290609799999999
Metrics 0.035775099999998616
Surrogate Model Generation 1.6442318
surrogate sim 1.1138629999999985
surrogate sim, dt 2.9739489
github-actions[bot] commented 1 year ago
Benchmarking Results [Update] From: Test Time (s)
import main 0.12760440000000006
import thrown object 0.5053566999999999
model initialization 0.11903010000000003
set noise 0.6695820000000001
simulate 0.3006587999999999
simulate with saving 0.9114089000000001
simulate with saving, dt 1.0176825000000003
simulate with printing results, dt 1.2380569000000001
Plot results 14.4040273
Metrics 0.04020490000000265
Surrogate Model Generation 1.5861187
surrogate sim 0.9978391999999978
surrogate sim, dt 2.9137856000000006

To:

Test Time (s)
import main 0.12515359999999998
import thrown object 0.5137856999999999
model initialization 0.11583009999999994
set noise 0.6703194000000001
simulate 0.3022020000000003
simulate with saving 0.9198008
simulate with saving, dt 1.026849
simulate with printing results, dt 1.2472216999999999
Plot results 14.193616200000001
Metrics 0.0401032999999984
Surrogate Model Generation 1.5847376000000004
surrogate sim 0.9949917999999975
surrogate sim, dt 2.9175188
github-actions[bot] commented 1 year ago
Benchmarking Results [Update] From: Test Time (s)
import main 0.16892570000000018
import thrown object 0.6011451999999999
model initialization 0.17593709999999985
set noise 0.8104769000000003
simulate 0.423632
simulate with saving 1.3174133000000001
simulate with saving, dt 1.4796161999999997
simulate with printing results, dt 1.842364400000001
Plot results 22.539818699999998
Metrics 0.045583100000001764
Surrogate Model Generation 2.424290499999998
surrogate sim 1.7566314999999975
surrogate sim, dt 4.279726199999999

To:

Test Time (s)
import main 0.1684848000000001
import thrown object 0.6112217
model initialization 0.1746531
set noise 0.8792518
simulate 0.42115139999999984
simulate with saving 1.3681888999999998
simulate with saving, dt 1.5100287000000003
simulate with printing results, dt 1.8794305000000007
Plot results 22.5758686
Metrics 0.047668899999997905
Surrogate Model Generation 2.4452415000000016
surrogate sim 1.7512252000000004
surrogate sim, dt 4.309843400000005
github-actions[bot] commented 1 year ago
Benchmarking Results [Update] From: Test Time (s)
import main 0.17729300000000014
import thrown object 0.6780564999999998
model initialization 0.14841080000000018
set noise 0.8779960999999998
simulate 0.35621500000000017
simulate with saving 1.1239276000000005
simulate with saving, dt 1.2311302999999993
simulate with printing results, dt 1.4766807000000002
Plot results 18.172262
Metrics 0.04465890000000172
Surrogate Model Generation 1.932970000000001
surrogate sim 1.2921239
surrogate sim, dt 3.588306799999998

To:

Test Time (s)
import main 0.17689820000000012
import thrown object 0.6544443
model initialization 0.1451387999999998
set noise 0.8544381999999997
simulate 0.35979709999999976
simulate with saving 1.1294741
simulate with saving, dt 1.2373674999999995
simulate with printing results, dt 1.4873899999999995
Plot results 17.686859000000002
Metrics 0.04451249999999973
Surrogate Model Generation 1.9625659000000013
surrogate sim 1.2835750999999966
surrogate sim, dt 3.548009099999998
github-actions[bot] commented 1 year ago
Benchmarking Results [Update] From: Test Time (s)
import main 0.12661219999999995
import thrown object 0.5024157999999999
model initialization 0.1186026
set noise 0.6640110999999997
simulate 0.30074100000000037
simulate with saving 0.9191235999999998
simulate with saving, dt 1.0256168000000003
simulate with printing results, dt 1.2434502000000007
Plot results 13.9226928
Metrics 0.039823200000000725
Surrogate Model Generation 1.574580000000001
surrogate sim 0.9891527000000018
surrogate sim, dt 2.9009715999999983

To:

Test Time (s)
import main 0.12741730000000007
import thrown object 0.4932276
model initialization 0.1156957999999999
set noise 0.6719789999999999
simulate 0.29901430000000007
simulate with saving 0.9215786000000001
simulate with saving, dt 1.0282528000000002
simulate with printing results, dt 1.2540078999999995
Plot results 13.97646
Metrics 0.04025970000000001
Surrogate Model Generation 1.5842832999999992
surrogate sim 0.9973813999999983
surrogate sim, dt 2.9314199999999992
github-actions[bot] commented 1 year ago
Benchmarking Results [Update] From: Test Time (s)
import main 0.15355439999999998
import thrown object 0.6009637999999999
model initialization 0.14268849999999977
set noise 0.7747115
simulate 0.35215580000000024
simulate with saving 1.0729424
simulate with saving, dt 1.1922075999999997
simulate with printing results, dt 1.4346566000000003
Plot results 17.7262311
Metrics 0.043162800000001056
Surrogate Model Generation 1.8744590999999993
surrogate sim 1.261058600000002
surrogate sim, dt 3.4601713000000025

To:

Test Time (s)
import main 0.15597360000000005
import thrown object 0.6084790999999998
model initialization 0.1450806
set noise 0.7764403000000004
simulate 0.3515246000000003
simulate with saving 1.0980618999999998
simulate with saving, dt 1.2023818999999998
simulate with printing results, dt 1.4515674
Plot results 17.6693688
Metrics 0.04315300000000022
Surrogate Model Generation 1.8775934999999997
surrogate sim 1.261284700000001
surrogate sim, dt 3.474193900000003