Browse Source

Modifications for inversion

master
T-bone 7 years ago
parent
commit
6d0b598f87

+ 3
- 0
examples/CMakeLists.txt View File

10
 add_executable( ModelAligner ModelAligner.cpp ) 
10
 add_executable( ModelAligner ModelAligner.cpp ) 
11
 target_link_libraries(  ModelAligner  "lemmacore" "fdem1d" "merlin")
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
 add_executable( ForwardFID ForwardFID.cpp  )
16
 add_executable( ForwardFID ForwardFID.cpp  )
14
 target_link_libraries(  ForwardFID  "lemmacore" "fdem1d" "merlin")
17
 target_link_libraries(  ForwardFID  "lemmacore" "fdem1d" "merlin")
15
 
18
 

+ 1
- 0
examples/ForwardFID.cpp View File

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

+ 32
- 0
examples/KernelAligner.cpp View File

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
 
34
 
35
     auto Model = LayeredEarthMR::NewSP();
35
     auto Model = LayeredEarthMR::NewSP();
36
         Model->AlignWithKernel(Kernel);
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
     std::cout << *Model << std::endl;
39
     std::cout << *Model << std::endl;
40
 }
40
 }

+ 8
- 0
include/DataFID.h View File

129
         /** Holds the actual data */
129
         /** Holds the actual data */
130
         MatrixXcr   FIDData;
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
         VectorXr    WindowCentres;
140
         VectorXr    WindowCentres;
133
 
141
 
134
         VectorXr    WindowEdges;
142
         VectorXr    WindowEdges;

+ 12
- 1
include/ForwardFID.h View File

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

+ 7
- 1
src/DataFID.cpp View File

25
     // ====================  FRIEND METHODS  =====================
25
     // ====================  FRIEND METHODS  =====================
26
 
26
 
27
     std::ostream &operator << (std::ostream &stream, const DataFID &ob) {
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
         return stream;
29
         return stream;
30
     }
30
     }
31
 
31
 
77
         // FILL IN CLASS SPECIFICS HERE
77
         // FILL IN CLASS SPECIFICS HERE
78
         node["FID_REAL"] = FIDData.real().eval();
78
         node["FID_REAL"] = FIDData.real().eval();
79
         node["FID_IMAG"] = FIDData.imag().eval();
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
         node["WindowCentres"] = WindowCentres;
86
         node["WindowCentres"] = WindowCentres;
81
         node["WindowEdges"] =  WindowEdges;
87
         node["WindowEdges"] =  WindowEdges;
82
         node["PulseMoment"] = PulseMoment;
88
         node["PulseMoment"] = PulseMoment;

+ 32
- 2
src/ForwardFID.cpp View File

107
 
107
 
108
     //--------------------------------------------------------------------------------------
108
     //--------------------------------------------------------------------------------------
109
     //       Class:  ForwardFID
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
     //      Method:  ForwardModel
121
     //      Method:  ForwardModel
111
     //--------------------------------------------------------------------------------------
122
     //--------------------------------------------------------------------------------------
112
     std::shared_ptr<DataFID> ForwardFID::ForwardModel ( std::shared_ptr<LayeredEarthMR> Mod ) {
123
     std::shared_ptr<DataFID> ForwardFID::ForwardModel ( std::shared_ptr<LayeredEarthMR> Mod ) {
120
         // Forward calculation is just a matrix vector product
131
         // Forward calculation is just a matrix vector product
121
         VectorXcr data = QT*Mod->GetModelVector();
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
         // TODO add noise
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
         //std::cout << B.imag().transpose() <<std::endl;
154
         //std::cout << B.imag().transpose() <<std::endl;
128
         auto FID = DataFID::NewSP();
155
         auto FID = DataFID::NewSP();
129
 
156
 
130
         FID->FIDData = B;
157
         FID->FIDData = B;
158
+        FID->NoiseEstimate = N;
159
+        FID->Qt = QT;
160
+        FID->TrueModel = Mod->GetModelVector();
131
         FID->WindowEdges = WindowEdges;
161
         FID->WindowEdges = WindowEdges;
132
         FID->WindowCentres = WindowCentres;
162
         FID->WindowCentres = WindowCentres;
133
         FID->PulseMoment = Kernel->GetPulseCurrent()*Kernel->GetPulseDuration();
163
         FID->PulseMoment = Kernel->GetPulseCurrent()*Kernel->GetPulseDuration();

+ 5
- 2
src/LayeredEarthMR.cpp View File

24
     // ====================  FRIEND METHODS  =====================
24
     // ====================  FRIEND METHODS  =====================
25
 
25
 
26
     std::ostream &operator << (std::ostream &stream, const LayeredEarthMR &ob) {
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
         return stream;
28
         return stream;
29
     }
29
     }
30
 
30
 
170
     //      Method:  GetModelVector
170
     //      Method:  GetModelVector
171
     //--------------------------------------------------------------------------------------
171
     //--------------------------------------------------------------------------------------
172
     VectorXr LayeredEarthMR::GetModelVector (  ) {
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
         return B;
177
         return B;
175
     }		// -----  end of method LayeredEarthMR::GetModelVector  -----
178
     }		// -----  end of method LayeredEarthMR::GetModelVector  -----
176
 
179
 

Loading…
Cancel
Save