ARTS 2.5.0 (git: 9ee3ac6c)
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
41void 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
89 "Tessem NN requires ", net.nb_inputs,
90 " values, but input vector has ", nx.nelem(), " element.")
91
93 "Tessem NN generates ", net.nb_outputs,
94 " values, but output vector has ", ny.nelem(), " element.")
95
96 // preprocessing
97 Vector new_x(nx);
98 new_x[0] *= 1e-9;
99 new_x[4] *= 1e3;
100 for (Index i = 0; i < net.nb_inputs; i++)
101 new_x[i] =
102 -1. + (new_x[i] - net.x_min[i]) / (net.x_max[i] - net.x_min[i]) * 2;
103
104 // propagation
105 Vector trans = net.b1;
106 for (Index i = 0; i < net.nb_cache; i++) {
107 for (Index j = 0; j < net.nb_inputs; j++)
108 trans[i] += net.w1(i, j) * new_x[j];
109
110 trans[i] = 2. / (1. + exp(-2. * trans[i])) - 1.;
111 }
112
113 Vector new_y = net.b2;
114 for (Index i = 0; i < net.nb_outputs; i++) {
115 for (Index j = 0; j < net.nb_cache; j++)
116 new_y[i] += net.w2(i, j) * trans[j];
117 }
118
119 // postprocessing
120 for (Index i = 0; i < net.nb_outputs; i++)
121 ny[i] = net.y_min[i] + (new_y[i] + 1.) / 2. * (net.y_max[i] - net.y_min[i]);
122}
A constant view of a Vector.
Definition: matpackI.h:489
Index nelem() const ARTS_NOEXCEPT
Returns the number of elements.
Definition: matpackI.cc:48
void resize(Index r, Index c)
Resize function.
Definition: matpackI.cc:1056
The VectorView class.
Definition: matpackI.h:626
The Vector class.
Definition: matpackI.h:876
void resize(Index n)
Resize function.
Definition: matpackI.cc:408
#define ARTS_USER_ERROR_IF(condition,...)
Definition: debug.h:134
This file contains basic functions to handle ASCII files.
Implementation of Matrix, Vector, and such stuff.
INDEX Index
The type to use for all integer numbers and indices.
Definition: matpack.h:39
This file contains the definition of String, the ARTS string class.
Vector x_max
Definition: tessem.h:42
Matrix w1
Definition: tessem.h:39
Matrix w2
Definition: tessem.h:40
Index nb_outputs
Definition: tessem.h:35
Vector b2
Definition: tessem.h:38
Vector y_max
Definition: tessem.h:44
Index nb_inputs
Definition: tessem.h:34
Index nb_cache
Definition: tessem.h:36
Vector y_min
Definition: tessem.h:43
Vector b1
Definition: tessem.h:37
Vector x_min
Definition: tessem.h:41
void tessem_prop_nn(VectorView &ny, const TessemNN &net, ConstVectorView nx)
Definition: tessem.cc:87
void tessem_read_ascii(std::ifstream &is, TessemNN &net)
Definition: tessem.cc:41
This file contains functions that are adapted from TESSEM code which is used to calculate surface emi...