Main function: simulated_annealing()
This is the main function for the phytoclass package.
It takes in the inputs (listed below) and returns the updated pigment to Chl a ratios, the Chl a biomass of each phytoplankton group, error associated with each group, and a graph displaying the Chl a concentration for each group.
It is important that samples are clustered appropriately before using the function (see the Cluster function).
Arguments:
S = Sample matrix – a matrix of pigment samples. Ensure that Chl a is the final column
F = Pigment to Chl a matrix. If left blank default values will be used. Ensure that pigment columns are in the same order as S and column naming conventions match.
user_defined_min_max = If blank default values are used. To create different min_max values, follow the same structure as the phytoclass::min_max file. See the example below.
do_matrix_checks = this should only be set to true when using the default values. This will remove pigment columns that have column sums of 0. Set to FALSE if using customised names for pigments and phytoplankton groups.
niter = number of iterations. Default value is 500.
step = step ratio used. Default value is 0.009.
weight.upper.bound = the upper limit of the weights applied. Default value is 30.
When using the default values, the only argument required is the sample matrix. However, make sure that the pigment names match those in the built-in pigment to Chl matrix Fm.
For the examples that follow the argument niter equals one for processing speed, but should be set much higher to obtain convergence.
Cluster function
Prior to analysis using simulated annealing, pigment samples require clustering.
The Cluster function divides all pigment concentrations by the total Chl a concentration. Following this the data undergoes BoxCox transformation, and the data is hierarchically clustered using the Ward method based on the Manhattan distances between pigment samples. The DynamicTreeCut method of (Langfelder, Zhang, and Horvath 2008) is then used to prune the dendogram into reasonable clusters of specified size(s).
The function returns a list of the clusters and the cluster dendrogram.
An example, using the built-in sample data set Sm:
# list of clusters
Cluster.result$cluster.list
#> [[1]]
#> Per X19but Fuco Neox Pra Viol X19hex
#> 1 0 0.03024000 0.0622500 0.005570000 0.01407000 0.007590000 0.08224000
#> 2 0 0.01084000 0.0286400 0.001110000 0.00351000 0.001440000 0.01497000
#> 3 0 0.01510000 0.1417000 0.004000000 0.00800000 0.002600000 0.02550000
#> 4 0 0.02200000 0.1090000 0.004000000 0.00800000 0.003000000 0.04200000
#> 5 0 0.02052662 0.2714934 0.017692288 0.01994758 0.000000000 0.03011548
#> 6 0 0.02216177 0.1654257 0.012242414 0.01956286 0.000000000 0.02721049
#> 7 0 0.01438545 0.2555594 0.020671983 0.04736366 0.011507712 0.02167651
#> 8 0 0.02662521 0.2205439 0.024444776 0.06623835 0.027029275 0.04015983
#> 9 0 0.05315834 0.2584586 0.016123905 0.04701666 0.011387548 0.08065818
#> 10 0 0.03092146 0.1639481 0.013383240 0.01262176 0.008793182 0.05881285
#> 11 0 0.02725515 0.1966991 0.009916299 0.01832477 0.009112193 0.05488214
#> 12 0 0.01678833 0.1755048 0.008821737 0.02676049 0.006637964 0.02189435
#> 13 0 0.02444961 0.1273596 0.007049435 0.01323978 0.004447137 0.02218985
#> 14 0 0.01567523 0.1052905 0.006144340 0.01372236 0.006294480 0.02208074
#> 15 0 0.03108003 0.0874373 0.011728700 0.02004430 0.005772257 0.04855466
#> Allo Zea Lut ChlcMGDG.18 ChlcMGDG.14 Chl.b Tchla
#> 1 0.001880000 0.002010000 0 0 0 0.08661000 0.4585100
#> 2 0.001440000 0.001910000 0 0 0 0.01473000 0.1457100
#> 3 0.000800000 0.001000000 0 0 0 0.03120000 0.2117000
#> 4 0.003000000 0.003000000 0 0 0 0.03200000 0.2060000
#> 5 0.000000000 0.030828916 0 0 0 0.09243326 0.4812043
#> 6 0.000000000 0.017661542 0 0 0 0.08720595 0.3409079
#> 7 0.009032764 0.018938989 0 0 0 0.14213442 0.4892902
#> 8 0.007170750 0.013507988 0 0 0 0.18532190 0.5711149
#> 9 0.010093841 0.016835362 0 0 0 0.13198111 0.5776707
#> 10 0.011139374 0.012782671 0 0 0 0.05213182 0.3486558
#> 11 0.013767971 0.012392348 0 0 0 0.08734698 0.4556423
#> 12 0.008302439 0.010946550 0 0 0 0.07005955 0.3497736
#> 13 0.005887899 0.010324368 0 0 0 0.03627212 0.2367185
#> 14 0.004908419 0.009914413 0 0 0 0.03735579 0.2117071
#> 15 0.009256850 0.009871839 0 0 0 0.09414383 0.3014690
#> Clust
#> 1 1
#> 2 1
#> 3 1
#> 4 1
#> 5 1
#> 6 1
#> 7 1
#> 8 1
#> 9 1
#> 10 1
#> 11 1
#> 12 1
#> 13 1
#> 14 1
#> 15 1
#>
#> [[2]]
#> Per X19but Fuco Neox Pra Viol X19hex
#> 1 0.0000 0.01560000 0.2172000 0.00640000 0.00920000 0.00000000 0.01740000
#> 2 0.0000 0.01770000 0.2347000 0.00700000 0.01150000 0.00000000 0.01890000
#> 3 0.0000 0.02520000 0.2952000 0.00990000 0.01300000 0.00000000 0.02110000
#> 4 0.0102 0.02220000 0.2275000 0.00760000 0.01070000 0.00000000 0.01900000
#> 5 0.0000 0.04520000 0.4484000 0.00370000 0.00650000 0.00000000 0.13170000
#> 6 0.0000 0.05180000 0.6228000 0.00490000 0.00750000 0.00400000 0.13210000
#> 7 0.0000 0.04906269 0.5266418 0.01733435 0.03446357 0.00000000 0.12044287
#> 8 0.0000 0.02619187 0.6025477 0.03894861 0.04929322 0.03489396 0.10082727
#> 9 0.0000 0.06542364 0.6603459 0.04421571 0.11285620 0.06456028 0.13896777
#> 10 0.0000 0.06040911 0.4494852 0.02786263 0.07757631 0.02525825 0.10999693
#> 11 0.0000 0.07577285 0.3920489 0.01723917 0.05136883 0.02089911 0.12859331
#> 12 0.0000 0.06067605 0.4112795 0.02176825 0.07620416 0.02259290 0.08973832
#> 13 0.0000 0.04388275 0.6257830 0.01237372 0.03347165 0.01349518 0.12822965
#> 14 0.0000 0.03971444 0.4332551 0.01440275 0.02657611 0.01056049 0.09220387
#> Allo Zea Lut ChlcMGDG.18 ChlcMGDG.14 Chl.b Tchla Clust
#> 1 0.00580000 0.00360000 0 0 0 0.0570000 0.6127000 2
#> 2 0.00540000 0.00380000 0 0 0 0.0619000 0.6207000 2
#> 3 0.00140000 0.00760000 0 0 0 0.0578000 0.5302000 2
#> 4 0.00000000 0.00300000 0 0 0 0.0453000 0.4057000 2
#> 5 0.00440000 0.00230000 0 0 0 0.0093000 0.6885000 2
#> 6 0.05970000 0.00350000 0 0 0 0.0121000 1.0849000 2
#> 7 0.02999001 0.03996619 0 0 0 0.1532505 1.0396607 2
#> 8 0.03161029 0.03631312 0 0 0 0.1646133 1.3811642 2
#> 9 0.01600105 0.02867069 0 0 0 0.4172947 1.7413395 2
#> 10 0.01924960 0.02058191 0 0 0 0.2601561 1.0739310 2
#> 11 0.02455042 0.02006658 0 0 0 0.2239172 0.9909010 2
#> 12 0.01671921 0.01921277 0 0 0 0.2368608 0.9520484 2
#> 13 0.01818973 0.01760174 0 0 0 0.1557938 1.2494685 2
#> 14 0.01413191 0.01298448 0 0 0 0.1209073 0.9190665 2
# plot of clusters
plot(Cluster.result$cluster.plot)
Example without clustering
The example here uses the built-in sample matrix Sm.
Results$`condition number`
#> [1] 657.199
Results$RMSE
#> [1] 0.02824877
Results$MAE
#> Per X19but Fuco Neox Pra Viol
#> 6.011970e-03 5.719842e-05 7.020613e-04 2.025538e-02 5.578652e-03 9.209880e-03
#> X19hex Allo Zea Chl.b Tchla
#> 2.071493e-04 7.696124e-04 1.688336e-03 2.923134e-03 4.260736e-03
Results$Error
#> Per X19but Fuco Neox Pra
#> 1257 -4.375017e-04 1.436914e-04 -1.367541e-02 0.002095977 -0.0044146916
#> 1278 -6.341458e-04 2.082765e-04 -1.982210e-02 0.001494711 0.0005021170
#> 1908 -5.213432e-04 1.712280e-04 -1.629612e-02 0.003875528 -0.0033189125
#> 1909 -4.545505e-04 1.492909e-04 -1.420832e-02 0.004027758 -0.0022669636
#> 1914 -1.117572e-04 3.670511e-05 -3.493302e-03 0.007185485 -0.0004990658
#> 1915 -4.311009e-05 1.415892e-05 -1.347533e-03 0.006979788 0.0001086053
#> 5614 0.000000e+00 -7.539801e-05 7.175785e-03 0.005367296 0.0016669597
#> 5647 0.000000e+00 -6.699265e-05 6.375829e-03 0.002216187 0.0023952339
#> 5653 0.000000e+00 -4.109548e-05 3.911143e-03 0.002005720 0.0018169951
#> 6770 0.000000e+00 -6.845036e-05 6.514562e-03 0.005358101 0.0012502294
#> 8425 0.000000e+00 -3.615574e-05 3.441017e-03 0.004764743 -0.0002331778
#> 8426 0.000000e+00 -2.747748e-05 2.615089e-03 0.013445140 -0.0014041314
#> 9538 0.000000e+00 -1.555110e-05 1.480030e-03 0.011252135 -0.0007135439
#> 9568 0.000000e+00 -5.909046e-05 5.623762e-03 0.011991630 0.0096119860
#> 9625 -7.156523e-05 2.350461e-05 -2.236983e-03 0.012001906 0.0041476172
#> 9626 0.000000e+00 -2.853634e-05 2.715862e-03 0.011407619 0.0154806583
#> 9838 -5.254946e-05 1.725914e-05 -1.642589e-03 0.006676976 0.0053680515
#> 9839 0.000000e+00 -4.044992e-05 3.849703e-03 0.006858516 0.0096033048
#> 9845 0.000000e+00 -1.543450e-05 1.468934e-03 0.006297694 0.0061964742
#> 9860 0.000000e+00 -1.059087e-05 1.007955e-03 0.002993529 0.0005632244
#> 9861 0.000000e+00 -1.857334e-05 1.767664e-03 0.004336853 0.0083489344
#> 9904 0.000000e+00 -4.805408e-07 4.573406e-05 0.001983283 -0.0004335829
#> 9913 -4.080994e-05 1.340346e-05 -1.275635e-03 0.004885849 -0.0004095846
#> 9938 0.000000e+00 -5.452353e-05 5.189118e-03 0.014864124 0.0011623559
#> 9980 0.000000e+00 -2.031303e-05 1.933233e-03 0.006259026 -0.0008556170
#> 10081 0.000000e+00 -2.827619e-05 2.691104e-03 0.006505339 0.0106384741
#> 10082 0.000000e+00 -3.510745e-05 3.341249e-03 0.009921212 0.0070419900
#> 10089 0.000000e+00 -4.405819e-05 4.193110e-03 0.008991738 0.0091648056
#> 10121 0.000000e+00 -1.117787e-05 1.063821e-03 0.011208667 -0.0022677772
#> Viol X19hex Allo Zea Chl.b
#> 1257 -1.419110e-03 -9.027724e-04 -5.557261e-04 -5.377101e-03 8.203113e-03
#> 1278 -2.176833e-04 -1.308542e-03 -8.055086e-04 -2.459423e-04 -3.458683e-03
#> 1908 -3.100576e-03 -1.075777e-03 -6.622237e-04 -4.953725e-04 3.524326e-03
#> 1909 -3.320766e-03 -9.379522e-04 -5.773819e-04 -7.398125e-04 2.227136e-03
#> 1914 -3.329905e-03 -2.306079e-04 -1.419569e-04 -4.334308e-05 -8.799421e-04
#> 1915 -3.357041e-03 -8.895646e-05 -5.475956e-05 -6.678027e-04 -1.194183e-03
#> 5614 6.692301e-04 4.737044e-04 2.916016e-04 -3.251167e-03 -2.306327e-03
#> 5647 -5.831693e-04 4.208959e-04 2.590939e-04 7.910798e-05 -3.742790e-03
#> 5653 5.983657e-04 2.581913e-04 1.589367e-04 4.852742e-05 -3.458195e-03
#> 6770 5.871137e-04 4.300542e-04 2.647315e-04 8.082931e-05 -3.452792e-03
#> 8425 -4.125817e-03 2.271563e-04 1.398322e-04 4.269435e-05 6.323017e-04
#> 8426 -5.246586e-03 1.726333e-04 0.000000e+00 3.244667e-05 -2.512429e-04
#> 9538 -6.879749e-03 9.770316e-05 0.000000e+00 1.836345e-05 -7.900722e-05
#> 9568 2.534234e-03 3.712486e-04 2.285322e-04 6.977671e-05 -2.021434e-02
#> 9625 1.336949e-03 -1.476728e-04 -9.090402e-05 -2.775532e-05 -1.178441e-02
#> 9626 4.327619e-03 1.792857e-04 1.103642e-04 -2.565514e-03 -2.912575e-02
#> 9838 1.511350e-03 -1.084343e-04 -6.674969e-05 -1.609497e-03 -1.100001e-02
#> 9839 2.464689e-03 2.541354e-04 1.564399e-04 4.776511e-05 -1.852606e-02
#> 9845 1.789576e-03 9.697062e-05 5.969290e-05 -5.119675e-04 -1.253225e-02
#> 9860 2.416978e-04 6.653942e-05 4.096015e-05 1.250618e-05 -1.968102e-03
#> 9861 2.304167e-03 1.166911e-04 7.183235e-05 -4.910641e-04 -1.548521e-02
#> 9904 -6.124270e-05 3.019102e-06 1.858490e-06 5.674445e-07 1.789799e-05
#> 9913 -7.071037e-06 -8.421016e-05 -5.183785e-05 -1.582742e-05 -1.230509e-03
#> 9938 7.797870e-04 3.425559e-04 2.108696e-04 6.438387e-05 -6.945725e-03
#> 9980 -2.545271e-05 1.276210e-04 7.856058e-05 2.398655e-05 -6.398623e-04
#> 10081 2.932777e-03 1.776513e-04 1.093581e-04 3.338981e-05 -2.038251e-02
#> 10082 2.143520e-03 2.205702e-04 1.357780e-04 4.145649e-05 -1.541395e-02
#> 10089 2.687163e-03 2.768052e-04 1.703949e-04 5.202593e-05 -1.863018e-02
#> 10121 -2.830618e-04 7.022738e-05 4.323037e-05 1.319934e-05 -1.295705e-04
#> Tchla
#> 1257 0.1836063323
#> 1278 0.2661319733
#> 1908 0.2187921029
#> 1909 0.1907612161
#> 1914 0.0469011480
#> 1915 0.0180920125
#> 5614 -0.0963422444
#> 5647 -0.0856020231
#> 5653 -0.0525110834
#> 6770 -0.0874646560
#> 8425 -0.0461991668
#> 8426 -0.0351102453
#> 9538 -0.0198709211
#> 9568 -0.0755047455
#> 9625 0.0300337796
#> 9626 -0.0364632255
#> 9838 0.0220534306
#> 9839 -0.0516861947
#> 9845 -0.0197219370
#> 9860 -0.0135328224
#> 9861 -0.0237326900
#> 9904 -0.0006140265
#> 9913 0.0171267069
#> 9938 -0.0696692033
#> 9980 -0.0259556293
#> 10081 -0.0361308140
#> 10082 -0.0448596846
#> 10089 -0.0562967818
#> 10121 -0.0142828814
Results$`F matrix`
#> Per X19but Fuco Neox Pra Viol X19hex Allo
#> Prasinophytes 0.0000 0.0000 0.0000 0.0457 0.2059 0.0489 0.0000 0.0000
#> Chlorophytes 0.0000 0.0000 0.0000 0.0126 0.0000 0.4155 0.0000 0.0000
#> Cryptophytes 0.0000 0.0000 0.0000 0.0000 0.0000 0.0000 0.0000 0.3671
#> Diatoms-B 0.0000 0.0000 0.7592 0.0000 0.0000 0.0000 0.0000 0.0000
#> Dinoflagellates-A 0.4663 0.0000 0.0000 0.0000 0.0000 0.0000 0.0000 0.0000
#> Haptophytes 0.0000 0.1092 0.1425 0.0000 0.0000 0.0000 0.5119 0.0000
#> Pelagophytes 0.0000 0.4980 1.0255 0.0000 0.0000 0.0000 0.0000 0.0000
#> Syn 0.0000 0.0000 0.0000 0.0000 0.0000 0.0000 0.0000 0.0000
#> Zea Chl.b Tchla
#> Prasinophytes 0.067900 0.8958 1
#> Chlorophytes 0.028900 0.4417 1
#> Cryptophytes 0.000000 0.0000 1
#> Diatoms-B 0.000000 0.0000 1
#> Dinoflagellates-A 0.000000 0.0000 1
#> Haptophytes 0.000000 0.0000 1
#> Pelagophytes 0.000000 0.0000 1
#> Syn 1.202323 0.0000 1
Results$`Class abundances`
#> Prasinophytes Chlorophytes Cryptophytes Diatoms-B Dinoflagellates-A
#> [1,] 0.12074645 0.015580068 0.0089492820 0.04485425 0.0010075936
#> [2,] 0.02795080 0.002780364 0.0074785740 0.02971192 0.0005167257
#> [3,] 0.09042333 0.000000000 0.0264179736 0.40508529 0.0015944291
#> [4,] 0.09545703 0.000000000 0.0232754452 0.40683348 0.0013702356
#> [5,] 0.07155292 0.000000000 0.0045744825 0.36014533 0.0002518340
#> [6,] 0.05335821 0.000000000 0.0001159389 0.25333253 0.0227043626
#> [7,] 0.02937519 0.001161003 0.0015224921 0.12222063 0.0000000000
#> [8,] 0.01369832 0.000000000 0.0094634377 0.41515276 0.0000000000
#> [9,] 0.01726606 0.004145716 0.1475985557 0.63621347 0.0000000000
#> [10,] 0.03061522 0.001982231 0.0066422907 0.07518459 0.0000000000
#> [11,] 0.15574125 0.000000000 0.0742903154 0.52941714 0.0000000000
#> [12,] 0.09665547 0.000000000 0.0000000000 0.28484305 0.0000000000
#> [13,] 0.09363211 0.000000000 0.0000000000 0.15586707 0.0000000000
#> [14,] 0.15696121 0.000000000 0.0206760428 0.25392939 0.0000000000
#> [15,] 0.20047272 0.056760591 0.0916334100 0.79407911 0.0003999825
#> [16,] 0.21648164 0.023560878 0.0178322077 0.20681435 0.0000000000
#> [17,] 0.48244600 0.092869668 0.0461068103 0.76083698 0.0003868454
#> [18,] 0.15547980 0.000000000 0.0243604282 0.18692022 0.0000000000
#> [19,] 0.30108398 0.014266165 0.0501354406 0.43047384 0.0000000000
#> [20,] 0.23784396 0.019902877 0.0649344188 0.32677945 0.0000000000
#> [21,] 0.27948589 0.008919027 0.0431208844 0.37381578 0.0000000000
#> [22,] 0.16721352 0.013101838 0.0494822617 0.73144816 0.0000000000
#> [23,] 0.13671208 0.010179673 0.0399885758 0.50113963 0.0001521378
#> [24,] 0.05013018 0.011451818 0.0262006845 0.12210907 0.0000000000
#> [25,] 0.08822780 0.010545878 0.0355236483 0.18512920 0.0000000000
#> [26,] 0.08773089 0.000000000 0.0209070851 0.17514701 0.0000000000
#> [27,] 0.04358390 0.002363648 0.0145162028 0.09512850 0.0000000000
#> [28,] 0.04247643 0.006073948 0.0118096785 0.08821962 0.0000000000
#> [29,] 0.10120167 0.001995820 0.0244264533 0.03911670 0.0000000000
#> Haptophytes Pelagophytes Syn
#> [1,] 0.23163915 0.035733201 0.000000000
#> [2,] 0.05050987 0.025638311 0.001123433
#> [3,] 0.05429790 0.034881076 0.000000000
#> [4,] 0.05544695 0.038316859 0.000000000
#> [5,] 0.04552364 0.045246150 0.002905640
#> [6,] 0.03853817 0.037650785 0.000000000
#> [7,] 0.04113832 0.016282370 0.000000000
#> [8,] 0.21959043 0.029804457 0.000790597
#> [9,] 0.23454288 0.043625025 0.001508291
#> [10,] 0.06902391 0.022244474 0.000307286
#> [11,] 0.21516755 0.043391122 0.021653360
#> [12,] 0.05466003 0.026572864 0.018472902
#> [13,] 0.05096682 0.031620164 0.008821733
#> [14,] 0.03589015 0.017158552 0.004674831
#> [15,] 0.20888108 0.009648876 0.019288423
#> [16,] 0.07256180 0.033864063 0.000000000
#> [17,] 0.28400360 0.074689583 0.000000000
#> [18,] 0.14171073 0.065381980 0.003817537
#> [19,] 0.20642366 0.071547876 0.000000000
#> [20,] 0.24446020 0.094652291 0.002327784
#> [21,] 0.16693359 0.079773232 0.000000000
#> [22,] 0.25020131 0.033157355 0.004864028
#> [23,] 0.18624166 0.041445890 0.003206848
#> [24,] 0.10014259 0.032455683 0.006165759
#> [25,] 0.10185501 0.029801469 0.004559263
#> [26,] 0.03967877 0.022788118 0.003521716
#> [27,] 0.03948655 0.036313095 0.005326631
#> [28,] 0.03847017 0.019824419 0.004832830
#> [29,] 0.09206533 0.040456258 0.002206732
Example with clustering
Clust1 <- Cluster(Sm, min_cluster_size = 14)$cluster.list[[1]]
#> ..done.
# Remove the cluster column/label
Clust1$Clust <- NULL
set.seed("7683")
Results <- simulated_annealing(Clust1, niter = 1)
Results$`condition number`
#> [1] 775.0989
Results$RMSE
#> [1] 0.02931221
Results$MAE
#> X19but Fuco Neox Pra Viol X19hex
#> 0.0002362059 0.0011316712 0.0219593170 0.0092003730 0.0119773703 0.0005471443
#> Allo Zea Chl.b Tchla
#> 0.0014131269 0.0016726465 0.0071885131 0.0093028209
Results$Error
#> X19but Fuco Neox Pra Viol
#> [1,] -1.523425e-03 -0.0075488424 -0.0015256991 -0.0069232355 -1.430632e-03
#> [2,] -1.022852e-04 -0.0124565197 -0.0009659486 -0.0015130112 -6.418238e-04
#> [3,] 3.540295e-05 0.0043114489 0.0026770207 -0.0009588724 -6.209766e-05
#> [4,] 5.110645e-05 0.0062238545 0.0025589805 -0.0012191255 -1.721382e-04
#> [5,] 7.009945e-06 0.0008536864 0.0101379274 -0.0042890464 -6.367299e-03
#> [6,] 6.977635e-06 0.0008497516 0.0070272037 -0.0041565195 -8.262652e-03
#> [7,] 1.886379e-05 0.0022972738 0.0060376330 0.0033059910 2.927713e-04
#> [8,] 1.132354e-05 0.0013790051 0.0037214791 0.0072366021 1.411981e-03
#> [9,] 3.163756e-05 0.0038528908 0.0020295535 0.0044849217 6.459691e-04
#> [10,] 4.142973e-05 0.0050454031 0.0114474175 -0.0020852577 -7.279872e-04
#> [11,] 1.036135e-05 0.0012618275 0.0026761173 -0.0037145212 -8.431022e-04
#> [12,] 7.173850e-06 0.0008736471 0.0018299967 0.0054676304 1.099524e-03
#> [13,] 2.564600e-05 0.0031232252 0.0062678993 0.0030200950 4.828223e-04
#> [14,] 2.772155e-05 0.0033759906 0.0045343175 0.0044026867 8.458793e-04
#> [15,] 2.151393e-05 0.0026200135 0.0060872331 -0.0064374398 -1.504036e-03
#> X19hex Allo Zea Chl.b Tchla
#> [1,] 0.0004008719 -3.600846e-04 -2.889637e-03 0.020540903 0.14301480
#> [2,] -0.0017396675 -5.941839e-04 -3.551667e-04 0.002734724 0.23599203
#> [3,] 0.0006021335 2.056589e-04 -1.603441e-03 0.002042016 -0.08168153
#> [4,] 0.0008692185 2.968818e-04 1.774578e-04 0.002401422 -0.11791255
#> [5,] 0.0001192252 0.000000e+00 2.434075e-05 0.007029294 -0.01617331
#> [6,] 0.0001186756 0.000000e+00 2.422856e-05 0.010676933 -0.01609877
#> [7,] 0.0003208354 1.095814e-04 6.550106e-05 -0.013782001 -0.04352245
#> [8,] 0.0001925907 6.577942e-05 3.931891e-05 -0.023149024 -0.02612561
#> [9,] 0.0005380916 1.837853e-04 1.098556e-04 -0.013332753 -0.07299403
#> [10,] 0.0007046370 2.406689e-04 1.438571e-04 -0.002926352 -0.09558648
#> [11,] 0.0001762258 6.018998e-05 3.597788e-05 0.008362224 -0.02390565
#> [12,] 0.0001220129 4.167352e-05 2.490988e-05 -0.016689617 -0.01655147
#> [13,] 0.0004361871 1.489798e-04 8.905101e-05 -0.013182292 -0.05917032
#> [14,] 0.0004714881 1.610369e-04 9.625799e-05 -0.015535395 -0.06395903
#> [15,] 0.0003659090 1.249763e-04 7.470318e-05 0.013344474 -0.04963684
Results$`F matrix`
#> X19but Fuco Neox Pra Viol X19hex Allo Zea
#> Prasinophytes 0.0000 0.0000000 0.0833 0.2534 0.0646 0.0000 0.0000 0.0499000
#> Chlorophytes 0.0000 0.0000000 0.0466 0.0000 0.4584 0.0000 0.0000 0.0471000
#> Cryptophytes 0.0000 0.0000000 0.0000 0.0000 0.0000 0.0000 0.4413 0.0000000
#> Diatoms-B 0.0000 0.9187736 0.0000 0.0000 0.0000 0.0000 0.0000 0.0000000
#> Haptophytes 0.1475 0.1066000 0.0000 0.0000 0.0000 0.3851 0.0000 0.0000000
#> Pelagophytes 0.4475 0.7825000 0.0000 0.0000 0.0000 0.0000 0.0000 0.0000000
#> Syn 0.0000 0.0000000 0.0000 0.0000 0.0000 0.0000 0.0000 0.7382825
#> Chl.b Tchla
#> Prasinophytes 0.9012507 1
#> Chlorophytes 0.3239000 1
#> Cryptophytes 0.0000000 1
#> Diatoms-B 0.0000000 1
#> Haptophytes 0.0000000 1
#> Pelagophytes 0.0000000 1
#> Syn 0.0000000 1
Results$`Class abundances`
#> Prasinophytes Chlorophytes Cryptophytes Diatoms-B Haptophytes
#> [1,] 0.09930272 1.068874e-02 0.006363460 0.06429746 0.27785762
#> [2,] 0.02385789 2.064693e-03 0.005599122 0.03158020 0.06264301
#> [3,] 0.02840233 8.947001e-04 0.001373075 0.11469603 0.05598677
#> [4,] 0.02697807 1.575229e-03 0.005217359 0.07350711 0.08665906
#> [5,] 0.09205709 0.000000e+00 0.000000000 0.25995208 0.07545773
#> [6,] 0.08575470 0.000000e+00 0.000000000 0.14413076 0.06821451
#> [7,] 0.15890114 0.000000e+00 0.018515354 0.23575259 0.05077494
#> [8,] 0.21595974 2.205069e-02 0.015248345 0.19419604 0.09837315
#> [9,] 0.14256614 0.000000e+00 0.019418978 0.18174602 0.18034316
#> [10,] 0.04657242 1.042926e-02 0.020788529 0.11766396 0.12665220
#> [11,] 0.08150750 9.065517e-03 0.029698418 0.17623715 0.13580089
#> [12,] 0.08771238 4.341287e-05 0.018150564 0.16240006 0.05482885
#> [13,] 0.04138553 2.356500e-03 0.011744965 0.08899647 0.05086462
#> [14,] 0.04123314 5.625151e-03 0.009695953 0.08184466 0.05023462
#> [15,] 0.08605965 1.143040e-03 0.018875993 0.04985933 0.11388143
#> Pelagophytes Syn
#> [1,] 0.00000000 0.000000000
#> [2,] 0.01747675 0.002488332
#> [3,] 0.01034710 0.000000000
#> [4,] 0.01081244 0.001250720
#> [5,] 0.01954348 0.034193940
#> [6,] 0.02546097 0.017346957
#> [7,] 0.01267124 0.012674905
#> [8,] 0.02399220 0.001294774
#> [9,] 0.04359414 0.010002248
#> [10,] 0.01599641 0.010552990
#> [11,] 0.01342110 0.009911687
#> [12,] 0.01823761 0.008400717
#> [13,] 0.03190633 0.009464102
#> [14,] 0.01439403 0.008679522
#> [15,] 0.02546206 0.006187463
Example using non-default values
#Create Fm (F matrix). Alternatively, a .csv file can be uploaded.
Fu <- data.frame(
Per = c(0, 0, 0, 0, 1, 0, 0, 0),
X19but = c(0, 0, 0, 0, 0, 1, 1, 0),
Fuco = c(0, 0, 0, 1, 0, 1, 1, 0),
Pra = c(1, 0, 0, 0, 0, 0, 0, 0),
X19hex = c(0, 0, 0, 0, 0, 1, 0, 0),
Allo = c(0, 0, 1, 0, 0, 0, 0, 0),
Zea = c(1, 1, 0, 0, 0, 0, 0, 1),
Chl.b = c(1, 1, 0, 0, 0, 0, 0, 0),
Tchla = c(1, 1, 1, 1, 1, 1, 1, 1)
)
rownames(Fu) <- c(
"Prasinophytes", "Chlorophytes", "Cryptophytes"
, "Diatoms-B", "Dinoflagellates-A",
"Haptophytes", "Pelagophytes", "Syn"
)
Min_max <- data.frame(
Class = c(
"Syn", "Chlorophytes", "Chlorophytes", "Prasinophytes", "Prasinophytes",
"Prasinophytes", "Cryptophytes", "Diatoms-B", "Diatoms-B", "Pelagophytes",
"Pelagophytes", "Pelagophytes", "Dinoflagellates-A", "Haptophytes",
"Haptophytes", "Haptophytes", "Haptophytes", "Diatoms-B", "Cryptophytes",
"Prasinophytes", "Chlorophytes", "Syn", "Dinoflagellates-A", "Pelagophytes"
),
Pig_Abbrev = c(
"Zea", "Zea", "Chl.b", "Pra", "Zea", "Chl.b", "Allo", "Chl.c3",
"Fuco", "Chl.c3", "X19but", "Fuco", "Per", "X19but", "X19hex",
"Fuco", "Tchla", "Tchla", "Tchla", "Tchla", "Tchla", "Tchla", "Tchla",
"Tchla"
),
min = as.numeric(c(
0.0800, 0.0063, 0.1666, 0.0642, 0.0151, 0.4993, 0.2118, 0.0189,
0.3315, 0.1471, 0.2457, 0.3092, 0.3421, 0.0819, 0.2107, 0.0090,
1.0000, 1.0000, 1.0000, 1.0000, 1.0000, 1.0000, 1.0000, 1.0000
)),
max = as.numeric(c(
1.2123, 0.0722, 0.9254, 0.4369, 0.1396, 0.9072, 0.5479, 0.1840,
0.9332, 0.2967, 1.0339, 1.2366, 0.8650, 0.2872, 1.3766, 0.4689,
1.0000, 1.0000, 1.0000, 1.0000, 1.0000, 1.0000, 1.0000, 1.0000
))
)
set.seed("7683")
Results <- simulated_annealing(
S = Sm,
F = Fu,
user_defined_min_max = Min_max,
do_matrix_checks = TRUE,
niter = 1,
step = 0.01,
weight.upper.bound = 30
)
Results$`condition number`
#> [1] 1246.385
Results$RMSE
#> [1] 0.02172976
Results$MAE
#> Per X19but Fuco Pra X19hex Allo
#> 4.199727e-03 3.273723e-05 4.756433e-04 3.683680e-03 8.040712e-05 5.794571e-04
#> Zea Chl.b Tchla
#> 3.949947e-03 1.778484e-03 3.083291e-03
Results$Error
#> Per X19but Fuco Pra X19hex
#> 1257 -1.540353e-04 -4.443987e-05 -5.001243e-03 2.387518e-03 -1.892591e-04
#> 1278 -4.407218e-04 -1.271502e-04 -1.430942e-02 2.905187e-03 -5.415031e-04
#> 1908 -2.789685e-04 -8.048366e-05 -9.057595e-03 2.016773e-03 -3.427612e-04
#> 1909 -2.566387e-04 -7.404139e-05 -8.332585e-03 1.971743e-03 -3.153251e-04
#> 1914 -6.912664e-05 -1.994334e-05 -2.244415e-03 4.556748e-04 -8.493406e-05
#> 1915 -3.495682e-05 -1.008520e-05 -1.134983e-03 6.271547e-04 -4.295051e-05
#> 5614 0.000000e+00 3.199972e-05 3.601235e-03 4.125569e-04 1.362794e-04
#> 5647 0.000000e+00 7.954242e-06 8.951668e-04 2.019758e-03 3.387527e-05
#> 5653 0.000000e+00 1.592528e-06 1.792223e-04 1.446277e-03 6.782205e-06
#> 6770 0.000000e+00 2.576880e-05 2.900009e-03 -4.195474e-04 1.097433e-04
#> 8425 0.000000e+00 2.422799e-05 2.726607e-03 -5.535725e-04 1.031814e-04
#> 8426 0.000000e+00 3.898821e-05 4.387716e-03 -8.908209e-04 1.660417e-04
#> 9538 0.000000e+00 3.437586e-05 3.868644e-03 -7.854359e-04 1.463988e-04
#> 9568 0.000000e+00 2.975730e-05 3.348873e-03 6.603140e-03 1.267294e-04
#> 9625 -1.863894e-04 -5.377415e-05 -6.051719e-03 1.505595e-03 -2.290116e-04
#> 9626 -2.192229e-06 -6.324676e-07 -7.117763e-05 1.112948e-02 -2.693533e-06
#> 9838 -1.352676e-04 -3.902530e-05 -4.391890e-03 1.844555e-03 -1.661997e-04
#> 9839 0.000000e+00 1.660517e-05 1.868739e-03 6.898358e-03 7.071758e-05
#> 9845 -3.749984e-05 -1.081887e-05 -1.217551e-03 3.350522e-03 -4.607506e-05
#> 9860 0.000000e+00 1.415749e-05 1.593278e-03 -8.877482e-05 6.029347e-05
#> 9861 -9.153627e-06 -2.640862e-06 -2.972014e-04 5.411871e-03 -1.124682e-05
#> 9904 -2.136934e-05 -6.165148e-06 -6.938230e-04 1.408642e-04 -2.625593e-05
#> 9913 -4.430863e-05 -1.278323e-05 -1.438619e-03 2.920773e-04 -5.444082e-05
#> 9938 0.000000e+00 2.419299e-05 2.722668e-03 -5.527728e-04 1.030323e-04
#> 9980 0.000000e+00 2.553948e-05 2.874202e-03 -5.835380e-04 1.087667e-04
#> 10081 0.000000e+00 8.869575e-06 9.981780e-04 8.070696e-03 3.777346e-05
#> 10082 0.000000e+00 2.948775e-05 3.318538e-03 5.160518e-03 1.255815e-04
#> 10089 0.000000e+00 2.182335e-05 2.455990e-03 6.128883e-03 9.294058e-05
#> 10121 0.000000e+00 4.369520e-05 4.917439e-03 -9.983685e-04 1.860877e-04
#> Allo Zea Chl.b Tchla
#> 1257 -2.400743e-04 -6.818570e-03 2.371929e-05 0.071755809
#> 1278 -6.868943e-04 -4.513605e-04 -7.234509e-03 0.205305833
#> 1908 -4.347911e-04 -1.149024e-03 -4.248508e-03 0.129954705
#> 1909 -3.999885e-04 -1.622101e-03 -3.691928e-03 0.119552557
#> 1914 -1.077385e-04 -7.079531e-05 -1.134723e-03 0.032201955
#> 1915 -5.448253e-05 -1.961634e-03 1.641019e-04 0.016284284
#> 5614 1.728698e-04 -4.950825e-03 3.566148e-03 -0.051669059
#> 5647 4.297063e-05 2.823614e-05 -3.824066e-03 -0.012843491
#> 5653 8.603197e-06 5.653189e-06 -2.789617e-03 -0.002571410
#> 6770 1.392089e-04 -7.300278e-04 1.780952e-03 -0.041608161
#> 8425 1.308851e-04 8.600506e-05 1.378509e-03 -0.039120259
#> 8426 0.000000e+00 1.384012e-04 2.218326e-03 -0.062953169
#> 9538 0.000000e+00 1.220282e-04 1.955896e-03 -0.055505746
#> 9568 1.607557e-04 1.056331e-04 -1.245496e-02 -0.048048281
#> 9625 -2.905002e-04 -1.908887e-04 -3.597588e-03 0.086827618
#> 9626 -3.416735e-06 -7.188582e-03 -1.599866e-02 0.001021228
#> 9838 -2.108236e-04 -4.764176e-03 -4.480252e-04 0.063013059
#> 9839 8.970494e-05 5.894541e-05 -1.319301e-02 -0.026811910
#> 9845 -5.844601e-05 -3.814780e-03 -3.685879e-03 0.017468928
#> 9860 7.648201e-05 -1.089069e-03 1.242080e-03 -0.022859707
#> 9861 -1.426654e-05 -4.000149e-03 -7.419989e-03 0.004264126
#> 9904 -3.330554e-05 -2.188518e-05 -3.507807e-04 0.009954692
#> 9913 -6.905795e-05 -4.537820e-05 -7.273323e-04 0.020640730
#> 9938 1.306961e-04 8.588080e-05 1.376517e-03 -0.039063743
#> 9980 1.379701e-04 9.066061e-05 1.453129e-03 -0.041237884
#> 10081 4.791547e-05 3.148541e-05 -1.556718e-02 -0.014321454
#> 10082 1.592996e-04 1.046763e-04 -9.655891e-03 -0.047613044
#> 10089 1.178947e-04 7.746901e-05 -1.163294e-02 -0.035237552
#> 10121 2.360515e-04 1.551102e-04 2.486142e-03 -0.070553421
Results$`F matrix`
#> Per X19but Fuco Pra X19hex Allo Zea Chl.b Tchla
#> Prasinophytes 0.0000 0.0000 0.0000 0.2279 0.000 0.0000 0.0919 0.8640 1
#> Chlorophytes 0.0000 0.0000 0.0000 0.0000 0.000 0.0000 0.0118 0.2268 1
#> Cryptophytes 0.0000 0.0000 0.0000 0.0000 0.000 0.3321 0.0000 0.0000 1
#> Diatoms-B 0.0000 0.0000 0.8419 0.0000 0.000 0.0000 0.0000 0.0000 1
#> Dinoflagellates-A 0.5176 0.0000 0.0000 0.0000 0.000 0.0000 0.0000 0.0000 1
#> Haptophytes 0.0000 0.1310 0.1053 0.0000 0.894 0.0000 0.0000 0.0000 1
#> Pelagophytes 0.0000 0.6849 0.5205 0.0000 0.000 0.0000 0.0000 0.0000 1
#> Syn 0.0000 0.0000 0.0000 0.0000 0.000 0.0000 0.5054 0.0000 1
Results$`Class abundances`
#> Prasinophytes Chlorophytes Cryptophytes Diatoms-B Dinoflagellates-A
#> [1,] 0.06105833 0.1990376885 0.0070029011 0.05694234 2.482309e-04
#> [2,] 0.01828905 0.0350763698 0.0069735610 0.04052284 2.746169e-04
#> [3,] 0.04003214 0.1832299487 0.0233391511 0.31687606 6.315298e-04
#> [4,] 0.05174144 0.1584216877 0.0214629525 0.33514306 5.949039e-04
#> [5,] 0.05852206 0.0525924650 0.0048017729 0.35050118 1.348690e-04
#> [6,] 0.04628561 0.0289996797 0.0001257441 0.25875623 2.036438e-02
#> [7,] 0.03102206 0.0000000000 0.0019730073 0.13798702 0.000000e+00
#> [8,] 0.01627271 0.0000000000 0.0127580863 0.47748504 0.000000e+00
#> [9,] 0.02028450 0.0000000000 0.1788768956 0.68834971 0.000000e+00
#> [10,] 0.03304855 0.0009664837 0.0081552127 0.09931081 0.000000e+00
#> [11,] 0.14517490 0.0642408514 0.0832722198 0.53387535 0.000000e+00
#> [12,] 0.08117559 0.0451685318 0.0000000000 0.26589364 0.000000e+00
#> [13,] 0.07939196 0.0384453911 0.0000000000 0.15590970 0.000000e+00
#> [14,] 0.16292612 0.0000000000 0.0243302871 0.26087948 0.000000e+00
#> [15,] 0.23598080 0.0000000000 0.1144974301 0.83377275 1.014099e-03
#> [16,] 0.23590672 0.0000000000 0.0216475409 0.23819570 4.798564e-06
#> [17,] 0.53052134 0.0653254799 0.0567307653 0.83706307 9.394163e-04
#> [18,] 0.16187643 0.0000000000 0.0285198402 0.24256379 0.000000e+00
#> [19,] 0.32075065 0.0000000000 0.0603616163 0.49828819 1.553036e-04
#> [20,] 0.21661296 0.1104834137 0.0703885346 0.37615700 0.000000e+00
#> [21,] 0.29258255 0.0000000000 0.0508481651 0.43735952 3.321923e-05
#> [22,] 0.14814749 0.1387954008 0.0560138433 0.71755858 9.554773e-05
#> [23,] 0.11891731 0.1062375285 0.0445581140 0.49948575 1.474983e-04
#> [24,] 0.05295877 0.0077005651 0.0308795322 0.15235979 0.000000e+00
#> [25,] 0.07661799 0.0601020386 0.0381094140 0.19072492 0.000000e+00
#> [26,] 0.09081140 0.0000000000 0.0242271266 0.18713018 0.000000e+00
#> [27,] 0.04316930 0.0000000000 0.0159703163 0.11605087 0.000000e+00
#> [28,] 0.04569986 0.0000000000 0.0136732671 0.10235937 0.000000e+00
#> [29,] 0.07940435 0.0555712748 0.0240573205 0.06305842 0.000000e+00
#> Haptophytes Pelagophytes Syn
#> [1,] 0.10417599 0.03004452 0.000000000
#> [2,] 0.02454977 0.01838375 0.001640034
#> [3,] 0.02474948 0.02384169 0.000000000
#> [4,] 0.02644976 0.02688619 0.000000000
#> [5,] 0.02514533 0.03427030 0.004232025
#> [6,] 0.02194347 0.02922489 0.000000000
#> [7,] 0.02572588 0.01499203 0.000000000
#> [8,] 0.14368310 0.03689270 0.001408358
#> [9,] 0.14705969 0.04714670 0.003182514
#> [10,] 0.04321779 0.02130115 0.000000000
#> [11,] 0.12510901 0.04264135 0.045347038
#> [12,] 0.02981800 0.02091672 0.038231851
#> [13,] 0.02730204 0.02387892 0.015979875
#> [14,] 0.02195285 0.01488997 0.004311483
#> [15,] 0.13347029 0.01970454 0.042724278
#> [16,] 0.04501592 0.03034426 0.000000000
#> [17,] 0.17633325 0.07442616 0.000000000
#> [18,] 0.08546430 0.05722432 0.002022010
#> [19,] 0.12743977 0.06693543 0.000000000
#> [20,] 0.13765510 0.07960397 0.000000000
#> [21,] 0.10124657 0.06997838 0.000000000
#> [22,] 0.14614628 0.03732076 0.005390572
#> [23,] 0.10723226 0.03975156 0.002736478
#> [24,] 0.06098498 0.03021600 0.013556133
#> [25,] 0.05682837 0.02600165 0.007257886
#> [26,] 0.02379894 0.01928751 0.004518430
#> [27,] 0.02258920 0.02823695 0.010701883
#> [28,] 0.02304180 0.01696960 0.009963192
#> [29,] 0.04749637 0.03065805 0.001223182