5 #include <boost/bind.hpp>
6 #include <boost/date_time/posix_time/posix_time.hpp>
7 #include <boost/program_options.hpp>
10 #include "NetCDFTools.h"
15 using namespace gplib;
17 string version =
"$Id: mtunn.cpp 1838 2010-03-04 16:19:34Z mmoorkamp $";
24 boost::bind(multiplies<double> (), _1, factor));
29 double themax = *max_element(Component.
GetData().begin(),
30 Component.
GetData().end(), gplib::absLess<double, double>());
31 double factor = 1. / themax;
33 Component.
GetData().begin(), boost::bind(multiplies<double> (), _1,
38 void GetNNSetup(
const size_t filterlength,
const size_t hiddenlayers,
43 SigmoidalNeuron::bipolar);
44 for (
size_t i = 0; i < hiddenlayers; ++i)
46 NNLayers.push_back(typeVector);
48 typeVector.assign(1, SigmoidalNeuron::identity);
49 NNLayers.push_back(typeVector);
52 namespace po = boost::program_options;
54 int main(
int argc,
char *argv[])
56 cout <<
"This is mtunn: Perform neural network filtering on MT time-series"
59 <<
" The program will ask for reference and input filename, further settings are read from 'mtuadaptive.conf' "
62 <<
" Output will be 1 Phoenix format file with ending '.clean' where all channels are overwritten"
65 <<
" Network weights are stored in a file with ending '.weights.nc' and network topology in '.dot"
67 cout <<
" This is Version: " <<
version << endl << endl;
69 int filterlength = 0, shift = 0, hiddenlayers;
72 po::options_description desc(
"General options");
73 desc.add_options()(
"help",
"produce help message")(
"filterlength",
74 po::value<int>(&filterlength)->default_value(10),
75 "The length of the adaptive filter")(
"shift",
76 po::value<int>(&shift)->default_value(0),
77 "The shift in samples between the time series")(
"mu",
78 po::value<double>(&mu)->default_value(1.0),
79 "Stepsize for LMS adaptive filter")(
"alpha", po::value<
80 double>(&alpha)->default_value(1.0),
"")(
"hiddenlayers", po::value<int>(
81 &hiddenlayers)->default_value(1),
82 "The number of hiddenlayers for the neural network");
85 po::store(po::parse_command_line(argc, argv, desc), vm);
90 std::cout << desc <<
"\n";
95 string tsfilename, noisefilename;
99 noisefilename = argv[1];
100 tsfilename = argv[2];
104 cout <<
"Reference Data: ";
105 cin >> noisefilename;
106 cout <<
"Input Time Series Filename: ";
110 ReferenceData.
GetData(noisefilename);
113 cout <<
"Input Start time: " << InputData.
GetData().
GetTime().front()
115 cout <<
"Reference Start time: "
120 cerr <<
"Time series not synchronized !" << endl;
127 cout <<
"Removing " << lengthdiff
128 <<
" datapoints from Reference time-series." << endl;
134 cout <<
"Removing " << lengthdiff
135 <<
" datapoints from Input time-series." << endl;
139 cout <<
"Input End time: " << InputData.
GetData().
GetTime().back() << endl;
140 cout <<
"Reference End time: " << ReferenceData.
GetData().
GetTime().back()
144 double NNmaxinit = 1.0;
145 const int ntimeseries = 4;
146 GetNNSetup(filterlength, hiddenlayers, ntimeseries, NNLayers, NNmaxinit);
147 NeuralNetwork NN(filterlength, ntimeseries, mu, NNLayers, NNmaxinit,
true);
170 ofstream weightfile((noisefilename +
"weights").c_str());
172 cout <<
" First iteration: " << endl << endl;
176 cout << endl << endl <<
" Second iteration: " << endl << endl;
189 ReferenceData.
WriteBack(noisefilename +
".clean");
std::vector< double > & GetData()
Access for data vector, for ease of use and efficiency we return a reference.
void AddReferenceChannel(TimeSeriesComponent &Channel)
Add a reference channel to the filter, some AdaptiveFilter objects require only one reference...
Apply an adaptive filter to a time-series.
TimeSeries & GetData()
return a reference to the actual object stored in the pointer
TimeSeriesComponent & GetEx()
virtual void PrintWeights(std::ostream &output)
Print the weights of the network to the specified output stream.
void ShowProgress(const bool what)
Do we want visual feedback of the progess on the screen, if yes draw a simple progress indicator in t...
void SetAlpha(const double a)
Set the momentum multiplier.
int main(int argc, char *argv[])
void Restore(const TimeSeriesComponent &Input, TimeSeriesComponent &Output, const double factor)
void erase(const int startindex, const int endindex)
Erase data between startindex and endindex.
void AddInputChannel(TimeSeriesComponent &Channel)
Add an input channel to the filter.
std::vector< ttypeVector > ttypeArray
TimeSeriesComponent & GetHy()
void SetWeightSaveIntervall(const int intervall)
Set the distance between iterations at which the weights are saved.
TimeSeriesComponent is the base storage class for all types of time series data.
std::vector< SigmoidalNeuron::tneurontype > ttypeVector
void GetNNSetup(const size_t filterlength, const size_t hiddenlayers, const size_t ntimeseries, NeuralNetwork::ttypeArray &NNLayers, double &NNmaxinit)
void FilterData()
Filter the input channels with the current settings.
void SetShift(const int theshift)
Set the shift between the input time series and the reference time series.
void WriteBack(std::string filename_base)
Write in the format it was originally read in.
TimeSeriesData stores a pointer to the different components of magnetotelluric data and provides func...
double Normalize(TimeSeriesComponent &Component)
size_t Size()
Return the size of the time series, throws if one of the components has a different size...
const std::vector< boost::shared_ptr< TimeSeriesComponent > > & GetOutChannels()
Return the vector of output channels.
TimeSeriesComponent & GetEy()
TimeSeriesComponent & GetHx()
Access function for Hx, returns reference for efficiency.