ARTS  2.4.0(git:4fb77825)
tessem.cc
Go to the documentation of this file.
1 /* Copyright (C) 2016
2  Oliver Lemke <olemke@core-dump.info>
3 
4  This program is free software; you can redistribute it and/or modify it
5  under the terms of the GNU General Public License as published by the
6  Free Software Foundation; either version 2, or (at your option) any
7  later version.
8 
9  This program is distributed in the hope that it will be useful,
10  but WITHOUT ANY WARRANTY; without even the implied warranty of
11  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12  GNU General Public License for more details.
13 
14  You should have received a copy of the GNU General Public License
15  along with this program; if not, write to the Free Software
16  Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307,
17  USA.
18 */
19 
31 #include "tessem.h"
32 #include "file.h"
33 #include "matpackI.h"
34 #include "mystring.h"
35 
41 void tessem_read_ascii(std::ifstream& is, TessemNN& net) {
42  is >> net.nb_inputs >> net.nb_cache >> net.nb_outputs;
43 
44  net.b1.resize(net.nb_cache);
45  for (Index i = 0; i < net.nb_cache; i++) is >> net.b1[i];
46 
47  net.b2.resize(net.nb_outputs);
48  for (Index i = 0; i < net.nb_outputs; i++) is >> net.b2[i];
49 
50  net.w1.resize(net.nb_cache, net.nb_inputs);
51  for (Index i = 0; i < net.nb_cache; i++)
52  for (Index j = 0; j < net.nb_inputs; j++) is >> net.w1(i, j);
53 
54  net.w2.resize(net.nb_outputs, net.nb_cache);
55  for (Index i = 0; i < net.nb_outputs; i++)
56  for (Index j = 0; j < net.nb_cache; j++) is >> net.w2(i, j);
57 
58  net.x_min.resize(net.nb_inputs);
59  for (Index i = 0; i < net.nb_inputs; i++) is >> net.x_min[i];
60 
61  net.x_max.resize(net.nb_inputs);
62  for (Index i = 0; i < net.nb_inputs; i++) is >> net.x_max[i];
63 
64  net.y_min.resize(net.nb_outputs);
65  for (Index i = 0; i < net.nb_outputs; i++) is >> net.y_min[i];
66 
67  net.y_max.resize(net.nb_outputs);
68  for (Index i = 0; i < net.nb_outputs; i++) is >> net.y_max[i];
69 }
70 
88  if (nx.nelem() != net.nb_inputs) {
89  ostringstream os;
90  os << "Tessem NN requires " << net.nb_inputs
91  << " values, but input vector has " << nx.nelem() << " element.";
92  throw std::runtime_error(os.str());
93  }
94 
95  if (ny.nelem() != net.nb_outputs) {
96  ostringstream os;
97  os << "Tessem NN generates " << net.nb_outputs
98  << " values, but output vector has " << ny.nelem() << " element.";
99  throw std::runtime_error(os.str());
100  }
101 
102  // preprocessing
103  Vector new_x(nx);
104  new_x[0] *= 1e-9;
105  new_x[4] *= 1e3;
106  for (Index i = 0; i < net.nb_inputs; i++)
107  new_x[i] =
108  -1. + (new_x[i] - net.x_min[i]) / (net.x_max[i] - net.x_min[i]) * 2;
109 
110  // propagation
111  Vector trans = net.b1;
112  for (Index i = 0; i < net.nb_cache; i++) {
113  for (Index j = 0; j < net.nb_inputs; j++)
114  trans[i] += net.w1(i, j) * new_x[j];
115 
116  trans[i] = 2. / (1. + exp(-2. * trans[i])) - 1.;
117  }
118 
119  Vector new_y = net.b2;
120  for (Index i = 0; i < net.nb_outputs; i++) {
121  for (Index j = 0; j < net.nb_cache; j++)
122  new_y[i] += net.w2(i, j) * trans[j];
123  }
124 
125  // postprocessing
126  for (Index i = 0; i < net.nb_outputs; i++)
127  ny[i] = net.y_min[i] + (new_y[i] + 1.) / 2. * (net.y_max[i] - net.y_min[i]);
128 }
TessemNN::nb_outputs
Index nb_outputs
Definition: tessem.h:35
TessemNN::nb_cache
Index nb_cache
Definition: tessem.h:36
TessemNN::nb_inputs
Index nb_inputs
Definition: tessem.h:34
Vector::resize
void resize(Index n)
Resize function.
Definition: matpackI.cc:404
TessemNN
Definition: tessem.h:33
TessemNN::x_max
Vector x_max
Definition: tessem.h:42
tessem_read_ascii
void tessem_read_ascii(std::ifstream &is, TessemNN &net)
Definition: tessem.cc:41
TessemNN::x_min
Vector x_min
Definition: tessem.h:41
matpackI.h
Implementation of Matrix, Vector, and such stuff.
TessemNN::b2
Vector b2
Definition: tessem.h:38
tessem.h
This file contains functions that are adapted from TESSEM code which is used to calculate surface emi...
TessemNN::y_min
Vector y_min
Definition: tessem.h:43
ConstVectorView::nelem
Index nelem() const
Returns the number of elements.
Definition: matpackI.cc:51
VectorView
The VectorView class.
Definition: matpackI.h:610
TessemNN::y_max
Vector y_max
Definition: tessem.h:44
Matrix::resize
void resize(Index r, Index c)
Resize function.
Definition: matpackI.cc:1056
TessemNN::w1
Matrix w1
Definition: tessem.h:39
tessem_prop_nn
void tessem_prop_nn(VectorView &ny, const TessemNN &net, ConstVectorView nx)
Definition: tessem.cc:87
file.h
This file contains basic functions to handle ASCII files.
Index
INDEX Index
The type to use for all integer numbers and indices.
Definition: matpack.h:39
Vector
The Vector class.
Definition: matpackI.h:860
TessemNN::b1
Vector b1
Definition: tessem.h:37
TessemNN::w2
Matrix w2
Definition: tessem.h:40
ConstVectorView
A constant view of a Vector.
Definition: matpackI.h:476
mystring.h
This file contains the definition of String, the ARTS string class.