Skip to content

Commit 3f9c83f

Browse files
committed
Fix BuildNoise--Tikhonov results look better
1 parent af50b76 commit 3f9c83f

File tree

4 files changed

+92
-37
lines changed

4 files changed

+92
-37
lines changed

src/Core/Algorithms/Math/BuildNoiseColumnMatrix.cc

Lines changed: 11 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -41,23 +41,21 @@ using namespace SCIRun::Core::Algorithms;
4141
using namespace SCIRun::Core::Algorithms::Math;
4242
using namespace SCIRun::Core::Datatypes;
4343

44-
MusilRNG *musil = new MusilRNG;
45-
4644
BuildNoiseColumnMatrixAlgorithm::BuildNoiseColumnMatrixAlgorithm()
4745
{
4846
addParameter(SignalToNoiseRatio(),10);
4947
}
5048

51-
void BuildNoiseColumnMatrixAlgorithm::run(MatrixHandle output_matrix) const
49+
MatrixHandle BuildNoiseColumnMatrixAlgorithm::run(MatrixHandle input_matrix) const
5250
{
53-
if(matrix_is::sparse(output_matrix))
54-
matrix_convert::to_dense(output_matrix);
55-
51+
static MusilRNG musil;
52+
5653
double mean, power, sigma;
5754
mean=power=sigma=0;
5855
int r, c;
59-
int nr = output_matrix->nrows();
60-
int nc = output_matrix->ncols();
56+
int nr = input_matrix->nrows();
57+
int nc = input_matrix->ncols();
58+
DenseMatrixHandle output(new DenseMatrix(nr, nc));
6159
double curr;
6260

6361
double snr = get(SignalToNoiseRatio()).toDouble();
@@ -66,7 +64,7 @@ void BuildNoiseColumnMatrixAlgorithm::run(MatrixHandle output_matrix) const
6664
for(r = 0; r < nr; r++) {
6765
for(c = 0; c < nc; c++)
6866
{
69-
curr = output_matrix->get(r,c);
67+
curr = input_matrix->get(r, c);
7068
power += (curr - mean)*(curr - mean);
7169
}
7270
}
@@ -78,20 +76,19 @@ void BuildNoiseColumnMatrixAlgorithm::run(MatrixHandle output_matrix) const
7876
{
7977
for(c = 0; c < nc; c++)
8078
{
81-
const double rnd = 2.0 * (*musil)() -1.0;
79+
const double rnd = 2.0 * musil() -1.0;
8280
double perturb = rnd * sigma * sqrt((-2.0 * log(rnd*rnd))/(rnd*rnd));
83-
output_matrix->put(r,c,perturb);
81+
(*output)(r, c) = perturb;
8482
}
8583
}
84+
return output;
8685
}
8786

8887
AlgorithmOutput BuildNoiseColumnMatrixAlgorithm::run_generic(const AlgorithmInput& input) const
8988
{
9089
auto input_matrix = input.get<Matrix>(Variables::InputMatrix);
9190

92-
MatrixHandle output_matrix = input_matrix;
93-
94-
run(output_matrix);
91+
MatrixHandle output_matrix = run(input_matrix);
9592

9693
AlgorithmOutput output;
9794
output[Variables::ResultMatrix] = output_matrix;

src/Core/Algorithms/Math/BuildNoiseColumnMatrix.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -30,8 +30,8 @@
3030
#define ALGORITHMS_MATH_BUILDNOISECOLUMNMATRIX_H 1
3131

3232
#include <Core/Algorithms/Base/AlgorithmBase.h>
33-
#include <Core/Algorithms/Math/share.h>
3433
#include <Core/Datatypes/MatrixFwd.h>
34+
#include <Core/Algorithms/Math/share.h>
3535

3636
namespace SCIRun {
3737
namespace Core {
@@ -46,7 +46,7 @@ namespace SCIRun {
4646
static AlgorithmOutputName ResultMatrix;
4747
static AlgorithmParameterName SignalToNoiseRatio();
4848
BuildNoiseColumnMatrixAlgorithm();
49-
void run(Datatypes::MatrixHandle output_matrix) const;
49+
Datatypes::MatrixHandle run(Datatypes::MatrixHandle input_matrix) const;
5050
AlgorithmOutput run_generic(const AlgorithmInput& input) const;
5151
};
5252
}

src/ExampleNets/developer/tikhonov-noNoise.srn5

Lines changed: 76 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
<networkFile class_id="0" tracking_level="0" version="2">
55
<networkInfo class_id="1" tracking_level="0" version="0">
66
<modules class_id="2" tracking_level="0" version="0">
7-
<count>14</count>
7+
<count>16</count>
88
<item_version>0</item_version>
99
<item class_id="3" tracking_level="0" version="0">
1010
<first>CreateStandardColorMap:14</first>
@@ -426,7 +426,7 @@
426426
<name>SliceIndex</name>
427427
<value>
428428
<which>0</which>
429-
<value>0</value>
429+
<value>8</value>
430430
</value>
431431
</second>
432432
</item>
@@ -554,6 +554,38 @@
554554
</state>
555555
</second>
556556
</item>
557+
<item>
558+
<first>ReportMatrixInfo:14</first>
559+
<second>
560+
<module>
561+
<package_name_>SCIRun</package_name_>
562+
<category_name_>Math</category_name_>
563+
<module_name_>ReportMatrixInfo</module_name_>
564+
</module>
565+
<state>
566+
<stateMap>
567+
<count>0</count>
568+
<item_version>0</item_version>
569+
</stateMap>
570+
</state>
571+
</second>
572+
</item>
573+
<item>
574+
<first>ReportMatrixInfo:15</first>
575+
<second>
576+
<module>
577+
<package_name_>SCIRun</package_name_>
578+
<category_name_>Math</category_name_>
579+
<module_name_>ReportMatrixInfo</module_name_>
580+
</module>
581+
<state>
582+
<stateMap>
583+
<count>0</count>
584+
<item_version>0</item_version>
585+
</stateMap>
586+
</state>
587+
</second>
588+
</item>
557589
<item>
558590
<first>ShowField:12</first>
559591
<second>
@@ -894,7 +926,7 @@
894926
<name>LCurveText</name>
895927
<value>
896928
<which>2</which>
897-
<value>SolveInverseProblemWithTikhonov:0 plot_graph &quot; 2.04155 6.53215 2.04155 6.53083 2.04155 6.52928 2.04155 6.52746 2.04156 6.52534 2.04156 6.52285 2.04157 6.51996 2.04158 6.51658 2.04159 6.51265 2.0416 6.50808 2.04162 6.50279 2.04165 6.49665 2.04169 6.48958 2.04174 6.48142 2.0418 6.47207 2.04188 6.46137 2.04198 6.44917 2.04211 6.43534 2.04226 6.41972 2.04245 6.40216 2.04269 6.38255 2.04296 6.36076 2.04328 6.3367 2.04365 6.31031 2.04406 6.28157 2.04452 6.25048 2.04502 6.21711 2.04555 6.18154 2.0461 6.14393 2.04667 6.10449 2.04725 6.06344 2.04783 6.02107 2.0484 5.97769 2.04895 5.93365 2.04949 5.88929 2.05 5.84496 2.05049 5.80099 2.05094 5.75765 2.05138 5.71516 2.05179 5.67367 2.05218 5.63324 2.05254 5.59386 2.0529 5.55545 2.05324 5.51789 2.05357 5.48101 2.05389 5.44465 2.05421 5.40865 2.05452 5.37287 2.05484 5.33721 2.05515 5.30158 2.05546 5.26597 2.05577 5.23033 2.05607 5.19468 2.05638 5.15901 2.05669 5.1233 2.05699 5.08753 2.0573 5.05165 2.0576 5.01559 2.05791 4.97928 2.05821 4.94262 2.05852 4.90555 2.05883 4.86801 2.05913 4.82997 2.05944 4.79145 2.05974 4.75251 2.06004 4.71324 2.06034 4.67377 2.06063 4.63428 2.06091 4.59494 2.06119 4.55593 2.06145 4.51741 2.06171 4.47953 2.06196 4.44238 2.0622 4.40602 2.06244 4.37046 2.06267 4.33566 2.0629 4.30154 2.06312 4.26801 2.06335 4.23495 2.06357 4.2022 2.06379 4.16964 2.06402 4.1371 2.06425 4.10446 2.06448 4.07159 2.06472 4.03838 2.06496 4.00476 2.06521 3.97068 2.06546 3.93613 2.06571 3.90111 2.06597 3.86567 2.06623 3.82985 2.06649 3.79373 2.06675 3.75738 2.06701 3.72086 2.06727 3.68424 2.06753 3.64756 2.06778 3.61085 2.06804 3.57414 2.06829 3.53741 2.06854 3.50067 2.06878 3.46389 2.06903 3.42705 2.06927 3.39015 2.06951 3.35318 2.06975 3.31614 2.06999 3.27906 2.07023 3.24195 2.07046 3.20488 2.07069 3.16786 2.07092 3.13095 2.07114 3.09415 2.07137 3.05746 2.07159 3.02088 2.0718 2.98436 2.07202 2.94786 2.07224 2.91131 2.07245 2.87466 2.07266 2.83786 2.07288 2.80085 2.07309 2.76359 2.0733 2.72606 2.07351 2.68824 2.07372 2.65011 2.07393 2.61164 2.07413 2.5728 2.07434 2.53354 2.07454 2.49383 2.07474 2.45359 2.07494 2.41279 2.07513 2.37139 2.07533 2.32938 2.07552 2.2868 2.0757 2.24371 2.07588 2.20024 2.07605 2.15655 2.07622 2.11285 2.07638 2.06936 2.07653 2.0263 2.07667 1.98388 2.07681 1.94226 2.07694 1.90151 2.07706 1.86165 2.07718 1.82257 2.0773 1.78413 2.07741 1.74608 2.07752 1.7082 2.07763 1.67023 2.07774 1.63196 2.07785 1.59324 2.07795 1.55396 2.07806 1.5141 2.07817 1.47373 2.07827 1.43295 2.07837 1.39192 2.07847 1.35083 2.07857 1.30984 2.07866 1.26911 2.07875 1.22871 2.07884 1.18865 2.07893 1.14887 2.07901 1.10921 2.07909 1.06946 2.07917 1.02938 2.07925 0.988691 2.07933 0.947137 2.07941 0.904484 2.07949 0.860544 2.07957 0.815181 2.07964 0.768318 2.07971 0.71994 2.07979 0.670095 2.07985 0.618888 2.07992 0.566477 2.07998 0.513075 2.08004 0.458934 2.08009 0.404347 2.08014 0.349627 2.08018 0.295102 2.08022 0.241088 2.08025 0.187869 2.08029 0.135666 2.08032 0.0846159 2.08034 0.0347485 2.08037 -0.0140203 2.08039 -0.0618826 2.08041 -0.109119 2.08043 -0.15607 2.08045 -0.2031 2.08047 -0.250565 2.08048 -0.29879 2.0805 -0.348047 2.08052 -0.398547 2.08053 -0.450436 2.08055 -0.503801 2.08056 -0.558675 2.08057 -0.615045 2.08058 -0.672865 2.08059 -0.73206 2.0806 -0.792539 2.08061 -0.854203 &quot; &quot; 1.04155 6.53215 2.04155 6.53215 2.04155 -0.854203 &quot; 1e-006 0 ;
929+
<value>SolveInverseProblemWithTikhonov:0 plot_graph &quot; -2.51539 4.79125 -2.44639 4.79107 -2.37766 4.79085 -2.30919 4.79061 -2.24103 4.79032 -2.17325 4.78999 -2.10589 4.78961 -2.03902 4.78916 -1.97272 4.78866 -1.90707 4.78808 -1.84216 4.78742 -1.7781 4.78667 -1.71501 4.78583 -1.65298 4.78488 -1.59216 4.78383 -1.53269 4.78268 -1.47469 4.78141 -1.4183 4.78005 -1.36367 4.77858 -1.3109 4.77703 -1.26012 4.7754 -1.21141 4.77372 -1.16486 4.77201 -1.12049 4.77029 -1.07834 4.76857 -1.03836 4.76689 -1.00053 4.76525 -0.964736 4.76368 -0.930869 4.76219 -0.898776 4.76078 -0.86828 4.75946 -0.83918 4.75822 -0.811263 4.75706 -0.784306 4.75597 -0.758086 4.75495 -0.732387 4.75399 -0.707008 4.75308 -0.681765 4.7522 -0.656501 4.75137 -0.631084 4.75056 -0.605409 4.74978 -0.579397 4.74902 -0.552994 4.74827 -0.52617 4.74754 -0.498913 4.74682 -0.471234 4.74612 -0.443159 4.74542 -0.414732 4.74474 -0.386009 4.74407 -0.357057 4.74341 -0.327951 4.74276 -0.298767 4.74213 -0.269576 4.74151 -0.240438 4.74091 -0.211393 4.74033 -0.182459 4.73976 -0.153621 4.73921 -0.124832 4.73868 -0.0960123 4.73816 -0.0670497 4.73765 -0.037806 4.73715 -0.00812452 4.73665 0.0221602 4.73615 0.0532113 4.73565 0.0851785 4.73515 0.118186 4.73463 0.152326 4.7341 0.187646 4.73354 0.22415 4.73297 0.261797 4.73237 0.300503 4.73175 0.340151 4.73109 0.3806 4.73041 0.4217 4.72969 0.463301 4.72894 0.505262 4.72816 0.547463 4.72734 0.589807 4.7265 0.632224 4.72561 0.674669 4.7247 0.717123 4.72375 0.759588 4.72276 0.802083 4.72173 0.844641 4.72066 0.887299 4.71955 0.930095 4.71838 0.973055 4.71716 1.01619 4.71589 1.0595 4.71455 1.10293 4.71315 1.14642 4.71168 1.1899 4.71015 1.23324 4.70855 1.27634 4.70689 1.31908 4.70516 1.36136 4.70338 1.40312 4.70156 1.44432 4.69969 1.48495 4.69777 1.52507 4.69582 1.56476 4.69383 1.60414 4.6918 1.64333 4.68972 1.68248 4.68758 1.72171 4.68537 1.76114 4.68309 1.80083 4.68072 1.84082 4.67825 1.88109 4.67568 1.92161 4.673 1.96233 4.6702 2.00316 4.66728 2.04406 4.66424 2.08497 4.66107 2.12588 4.65777 2.1668 4.65432 2.20776 4.65072 2.24883 4.64695 2.29007 4.64299 2.33154 4.63881 2.3733 4.63439 2.41537 4.6297 2.45775 4.62472 2.50039 4.6194 2.54319 4.61373 2.58605 4.60769 2.62881 4.60126 2.67133 4.59445 2.71347 4.58724 2.7551 4.57963 2.79611 4.57165 2.83646 4.56328 2.87611 4.55453 2.91511 4.54539 2.95352 4.53585 2.99144 4.52585 3.02899 4.51535 3.06629 4.50428 3.10343 4.49254 3.14047 4.48006 3.17741 4.46675 3.21418 4.45251 3.25066 4.4373 3.28669 4.42106 3.32206 4.4038 3.35655 4.38555 3.38996 4.36639 3.42213 4.34643 3.4529 4.32582 3.4822 4.30472 3.51 4.28329 3.53635 4.2617 3.56133 4.24006 3.58508 4.21842 3.60778 4.1968 3.62965 4.17513 3.65088 4.15327 3.67169 4.13107 3.69225 4.10832 3.71269 4.0848 3.73308 4.06031 3.75344 4.03468 3.77373 4.00777 3.79383 3.97951 3.81362 3.94987 3.83293 3.91893 3.8516 3.88682 3.86948 3.85376 3.88644 3.82006 3.90239 3.78607 3.91728 3.75221 3.93109 3.7189 3.94384 3.68653 3.9556 3.65544 3.96647 3.62586 3.97655 3.59787 3.98601 3.5714 3.995 3.54627 4.0037 3.52215 4.01228 3.49863 4.02094 3.47527 4.02983 3.4516 4.0391 3.42717 4.04884 3.40156 4.05912 3.37439 4.06993 3.34536 4.08122 3.3142 4.09288 3.2807 4.10477 3.24474 4.1167 3.20621 4.12851 3.16509 4.14001 3.1214 4.15105 3.07519 4.1615 3.02656 4.17127 2.97564 4.18029 2.92256 4.18853 2.8675 4.196 2.8106 4.2027 2.75205 4.20868 2.692 &quot; &quot; -3.51539 4.30472 3.4822 4.30472 3.4822 2.692 &quot; 0.174263 149 ;
898930
</value>
899931
</value>
900932
</second>
@@ -907,7 +939,7 @@
907939
<name>LambdaCorner</name>
908940
<value>
909941
<which>1</which>
910-
<value>9.99999999999999950e-007</value>
942+
<value>1.74263338600967630e-001</value>
911943
</value>
912944
</second>
913945
</item>
@@ -1073,7 +1105,7 @@
10731105
</item>
10741106
</modules>
10751107
<connections class_id="12" tracking_level="0" version="0">
1076-
<count>16</count>
1108+
<count>18</count>
10771109
<item_version>0</item_version>
10781110
<item class_id="13" tracking_level="0" version="0">
10791111
<moduleId1_>CreateStandardColorMap:14</moduleId1_>
@@ -1111,6 +1143,18 @@
11111143
<id>0</id>
11121144
</port2_>
11131145
</item>
1146+
<item>
1147+
<moduleId1_>EvaluateLinearAlgebraBinary:4</moduleId1_>
1148+
<port1_>
1149+
<name>Result</name>
1150+
<id>0</id>
1151+
</port1_>
1152+
<moduleId2_>ReportMatrixInfo:15</moduleId2_>
1153+
<port2_>
1154+
<name>InputMatrix</name>
1155+
<id>0</id>
1156+
</port2_>
1157+
</item>
11141158
<item>
11151159
<moduleId1_>EvaluateLinearAlgebraBinary:4</moduleId1_>
11161160
<port1_>
@@ -1231,6 +1275,18 @@
12311275
<id>0</id>
12321276
</port2_>
12331277
</item>
1278+
<item>
1279+
<moduleId1_>SolveInverseProblemWithTikhonov:0</moduleId1_>
1280+
<port1_>
1281+
<name>InverseSolution</name>
1282+
<id>0</id>
1283+
</port1_>
1284+
<moduleId2_>ReportMatrixInfo:14</moduleId2_>
1285+
<port2_>
1286+
<name>InputMatrix</name>
1287+
<id>0</id>
1288+
</port2_>
1289+
</item>
12341290
<item>
12351291
<moduleId1_>SolveInverseProblemWithTikhonov:0</moduleId1_>
12361292
<port1_>
@@ -1270,7 +1326,7 @@
12701326
</connections>
12711327
</networkInfo>
12721328
<modulePositions class_id="15" tracking_level="0" version="0">
1273-
<count>14</count>
1329+
<count>16</count>
12741330
<item_version>0</item_version>
12751331
<item class_id="16" tracking_level="0" version="0">
12761332
<first>CreateStandardColorMap:14</first>
@@ -1328,6 +1384,20 @@
13281384
<second>-7.60000000000000000e+002</second>
13291385
</second>
13301386
</item>
1387+
<item>
1388+
<first>ReportMatrixInfo:14</first>
1389+
<second>
1390+
<first>-9.88000000000000000e+002</first>
1391+
<second>0.00000000000000000e+000</second>
1392+
</second>
1393+
</item>
1394+
<item>
1395+
<first>ReportMatrixInfo:15</first>
1396+
<second>
1397+
<first>-7.60000000000000000e+002</first>
1398+
<second>-4.56000000000000000e+002</second>
1399+
</second>
1400+
</item>
13311401
<item>
13321402
<first>ShowField:12</first>
13331403
<second>

src/Modules/Legacy/Math/BuildNoiseColumnMatrix.cc

Lines changed: 3 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -59,19 +59,7 @@ void BuildNoiseColumnMatrix::setStateDefaults()
5959
void BuildNoiseColumnMatrix::execute()
6060
{
6161
auto input_matrix = getRequiredInput(InputMatrix);
62-
//if(inputsChanged() || newStatePresent())
63-
if(needToExecute())
64-
{
65-
algo().set(BuildNoiseColumnMatrixAlgorithm::SignalToNoiseRatio(),get_state()->getValue(BuildNoiseColumnMatrixAlgorithm::SignalToNoiseRatio()).toDouble());
66-
auto output = algo().run_generic(withInputData((InputMatrix,input_matrix)));
67-
sendOutputFromAlgorithm(ResultMatrix, output);
68-
}
69-
62+
algo().set(BuildNoiseColumnMatrixAlgorithm::SignalToNoiseRatio(),get_state()->getValue(BuildNoiseColumnMatrixAlgorithm::SignalToNoiseRatio()).toDouble());
63+
auto output = algo().run_generic(withInputData((InputMatrix,input_matrix)));
64+
sendOutputFromAlgorithm(ResultMatrix, output);
7065
}
71-
72-
73-
74-
75-
76-
77-

0 commit comments

Comments
 (0)