Browse Source

Modifications for inversion

master
T-bone 6 years ago
parent
commit
6d0b598f87

+ 3
- 0
examples/CMakeLists.txt View File

@@ -10,6 +10,9 @@ target_link_libraries(  KV0-3loops  "lemmacore" "fdem1d" "merlin")
10 10
 add_executable( ModelAligner ModelAligner.cpp ) 
11 11
 target_link_libraries(  ModelAligner  "lemmacore" "fdem1d" "merlin")
12 12
 
13
+add_executable( KernelAligner KernelAligner.cpp ) 
14
+target_link_libraries(  KernelAligner  "lemmacore" "fdem1d" "merlin")
15
+
13 16
 add_executable( ForwardFID ForwardFID.cpp  )
14 17
 target_link_libraries(  ForwardFID  "lemmacore" "fdem1d" "merlin")
15 18
 

+ 1
- 0
examples/ForwardFID.cpp View File

@@ -36,6 +36,7 @@ int main(int argc, char** argv) {
36 36
         //Forward->SetWindowEdges( VectorXr::LinSpaced(10,0,1) );
37 37
         Forward->SetLogSpacedWindows(10,1000,30);
38 38
         Forward->SetKernel(Kernel);
39
+        Forward->SetNoiseFloor(50); // nV
39 40
         auto FID = Forward->ForwardModel(Model);
40 41
     std::cout << *FID << std::endl;
41 42
 

+ 32
- 0
examples/KernelAligner.cpp View File

@@ -0,0 +1,32 @@
1
+/* This file is part of Lemma, a geophysical modelling and inversion API.
2
+ * More information is available at http://lemmasoftware.org
3
+ */
4
+
5
+/* This Source Code Form is subject to the terms of the Mozilla Public
6
+ * License, v. 2.0. If a copy of the MPL was not distributed with this
7
+ * file, You can obtain one at http://mozilla.org/MPL/2.0/.
8
+ */
9
+
10
+/**
11
+ * @file
12
+ * @date      12/01/2017 10:29:26 PM
13
+ * @version   $Id$
14
+ * @author    Trevor Irons (ti)
15
+ * @email     tirons@egi.utah.edu
16
+ * @copyright Copyright (c) 2017, University of Utah
17
+ * @copyright Copyright (c) 2017, Trevor Irons & Lemma Software, LLC
18
+ */
19
+
20
+#include "Merlin"
21
+
22
+using namespace Lemma;
23
+
24
+int main(int argc, char** argv) {
25
+    if (argc<2) {
26
+        std::cout << "useage\n"
27
+                  << "./KernelAligner  <AkvoData> \n";
28
+        exit(EXIT_SUCCESS);
29
+    }
30
+    auto K0 = KernelV0::NewSP();
31
+    std::cout << *K0 << std::endl;
32
+}

+ 1
- 1
examples/ModelAligner.cpp View File

@@ -34,7 +34,7 @@ int main(int argc, char** argv) {
34 34
 
35 35
     auto Model = LayeredEarthMR::NewSP();
36 36
         Model->AlignWithKernel(Kernel);
37
-        Model->SetT2StarBins(10, 500, 20);
37
+        Model->SetT2StarBins(atoi(argv[2]), atoi(argv[3]), atoi(argv[4]));
38 38
 
39 39
     std::cout << *Model << std::endl;
40 40
 }

+ 8
- 0
include/DataFID.h View File

@@ -129,6 +129,14 @@ namespace Lemma {
129 129
         /** Holds the actual data */
130 130
         MatrixXcr   FIDData;
131 131
 
132
+        /** Estimate of noise for each datum */
133
+        MatrixXr   NoiseEstimate;
134
+
135
+        /** Forward model matrix */
136
+        MatrixXcr   Qt;
137
+
138
+        VectorXr    TrueModel;
139
+
132 140
         VectorXr    WindowCentres;
133 141
 
134 142
         VectorXr    WindowEdges;

+ 12
- 1
include/ForwardFID.h View File

@@ -21,6 +21,7 @@
21 21
 #define  FORWARDFID_INC
22 22
 
23 23
 #pragma once
24
+#include <random>
24 25
 #include "LayeredEarthEM.h"
25 26
 #include "PolygonalWireAntenna.h"
26 27
 #include "EMEarth1D.h"
@@ -132,6 +133,12 @@ namespace Lemma {
132 133
          */
133 134
         void SetKernel( std::shared_ptr< KernelV0 > K0 );
134 135
 
136
+        /**
137
+         *  @param[in] floor is the standard deviation of the noise (zero mean),
138
+         *             defaults to zero
139
+         */
140
+        void SetNoiseFloor( const Real& floor );
141
+
135 142
         // ====================  INQUIRY       =======================
136 143
         /**
137 144
          *  Returns the name of the underlying class, similiar to Python's type
@@ -148,7 +155,7 @@ namespace Lemma {
148 155
         /** Copy is disabled */
149 156
         ForwardFID( const ForwardFID& ) = delete;
150 157
 
151
-        // ====================  DATA MEMBERS  =========================
158
+
152 159
         private:
153 160
 
154 161
         /**
@@ -157,12 +164,16 @@ namespace Lemma {
157 164
          */
158 165
         void CalcQTMatrix( VectorXr T2StarBins );
159 166
 
167
+        // ====================  DATA MEMBERS  =========================
160 168
         /** ASCII string representation of the class name */
161 169
         static constexpr auto CName = "ForwardFID";
162 170
 
163 171
         /** Imaging kernel used in calculation */
164 172
         std::shared_ptr< KernelV0 >   Kernel = nullptr;
165 173
 
174
+        /** Noise floor for additive Gaussian noise */
175
+        Real NoiseFloor = 0.;
176
+
166 177
         /** Time gate windows */
167 178
         VectorXr WindowEdges;
168 179
 

+ 7
- 1
src/DataFID.cpp View File

@@ -25,7 +25,7 @@ namespace Lemma {
25 25
     // ====================  FRIEND METHODS  =====================
26 26
 
27 27
     std::ostream &operator << (std::ostream &stream, const DataFID &ob) {
28
-        stream << ob.Serialize()  << "\n---\n"; // End of doc ---
28
+        stream <<"%YAML 1.2\n---\n" << ob.Serialize()  << "\n"; // End of doc ---
29 29
         return stream;
30 30
     }
31 31
 
@@ -77,6 +77,12 @@ namespace Lemma {
77 77
         // FILL IN CLASS SPECIFICS HERE
78 78
         node["FID_REAL"] = FIDData.real().eval();
79 79
         node["FID_IMAG"] = FIDData.imag().eval();
80
+        //node["Qt_REAL"] = Qt.real().eval();
81
+        //node["Qt_IMAG"] = Qt.imag().eval();
82
+        MatrixXr QTM = Qt.array().abs();
83
+        //node["Qt_MOD"] = QTM;
84
+        //node["TrueModel"] = TrueModel;
85
+        node["NoiseEstimate"] = NoiseEstimate;
80 86
         node["WindowCentres"] = WindowCentres;
81 87
         node["WindowEdges"] =  WindowEdges;
82 88
         node["PulseMoment"] = PulseMoment;

+ 32
- 2
src/ForwardFID.cpp View File

@@ -107,6 +107,17 @@ namespace Lemma {
107 107
 
108 108
     //--------------------------------------------------------------------------------------
109 109
     //       Class:  ForwardFID
110
+    //      Method:  SetNoiseFloor
111
+    //--------------------------------------------------------------------------------------
112
+    void ForwardFID::SetNoiseFloor ( const Real& floor ) {
113
+        assert (floor > 0.);
114
+        NoiseFloor = floor;
115
+        return ;
116
+    }		// -----  end of method ForwardFID::SetNoiseFloor  -----
117
+
118
+
119
+    //--------------------------------------------------------------------------------------
120
+    //       Class:  ForwardFID
110 121
     //      Method:  ForwardModel
111 122
     //--------------------------------------------------------------------------------------
112 123
     std::shared_ptr<DataFID> ForwardFID::ForwardModel ( std::shared_ptr<LayeredEarthMR> Mod ) {
@@ -120,14 +131,33 @@ namespace Lemma {
120 131
         // Forward calculation is just a matrix vector product
121 132
         VectorXcr data = QT*Mod->GetModelVector();
122 133
 
134
+        // rearrange solution back into a matrix
135
+        MatrixXcr B(Eigen::Map<MatrixXcr>(data.data(), nt, nq)); // Complex Data
136
+        MatrixXr N = MatrixXr::Zero(nt, nq);  // Noise
137
+        B.real() = B.array().abs();
138
+        B.imag() *= 0.;
139
+
123 140
         // TODO add noise
141
+        if (NoiseFloor > 1e-5) {
142
+            std::random_device rd;
143
+            std::mt19937 gen(rd());
144
+            std::normal_distribution<> d(0,1e-9*NoiseFloor);
145
+            for (int iq=0; iq<nq; ++iq) {
146
+                for (int it=0; it<nt; ++it) {
147
+                    B(it, iq) += Complex(d(gen), d(gen)) /
148
+                        std::sqrt( WindowEdges(it+1)-WindowEdges(it) );
149
+                    N(it,iq) = (1e-9*NoiseFloor) / std::sqrt(WindowEdges(it+1)-WindowEdges(it));
150
+                }
151
+            }
152
+        }
124 153
 
125
-        // rearrange solution back into a matrix
126
-        MatrixXcr B(Eigen::Map<MatrixXcr>(data.data(), nt, nq));
127 154
         //std::cout << B.imag().transpose() <<std::endl;
128 155
         auto FID = DataFID::NewSP();
129 156
 
130 157
         FID->FIDData = B;
158
+        FID->NoiseEstimate = N;
159
+        FID->Qt = QT;
160
+        FID->TrueModel = Mod->GetModelVector();
131 161
         FID->WindowEdges = WindowEdges;
132 162
         FID->WindowCentres = WindowCentres;
133 163
         FID->PulseMoment = Kernel->GetPulseCurrent()*Kernel->GetPulseDuration();

+ 5
- 2
src/LayeredEarthMR.cpp View File

@@ -24,7 +24,7 @@ namespace Lemma {
24 24
     // ====================  FRIEND METHODS  =====================
25 25
 
26 26
     std::ostream &operator << (std::ostream &stream, const LayeredEarthMR &ob) {
27
-        stream << ob.Serialize()  << "\n---\n"; // End of doc ---
27
+        stream << ob.Serialize()  << "\n"; // End of doc ---
28 28
         return stream;
29 29
     }
30 30
 
@@ -170,7 +170,10 @@ namespace Lemma {
170 170
     //      Method:  GetModelVector
171 171
     //--------------------------------------------------------------------------------------
172 172
     VectorXr LayeredEarthMR::GetModelVector (  ) {
173
-        VectorXr B(Eigen::Map<VectorXr>(ModelMat.data(), ModelMat.cols()*ModelMat.rows()));
173
+        //VectorXr B(Eigen::Map<VectorXr>(ModelMat.data(), ModelMat.cols()*ModelMat.rows()));
174
+        MatrixXr MT = ModelMat.transpose();
175
+        VectorXr B(Eigen::Map<VectorXr>(MT.data(), MT.cols()*MT.rows()));
176
+        //VectorXr B(Eigen::Map<VectorXr>(ModelMat.transpose().data(), ModelMat.cols()*ModelMat.rows()));
174 177
         return B;
175 178
     }		// -----  end of method LayeredEarthMR::GetModelVector  -----
176 179
 

Loading…
Cancel
Save