n2p2 - A neural network potential package
Updater.h
Go to the documentation of this file.
1// n2p2 - A neural network potential package
2// Copyright (C) 2018 Andreas Singraber (University of Vienna)
3//
4// This program is free software: you can redistribute it and/or modify
5// it under the terms of the GNU General Public License as published by
6// the Free Software Foundation, either version 3 of the License, or
7// (at your option) any 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, see <https://www.gnu.org/licenses/>.
16
17#ifndef UPDATER_H
18#define UPDATER_H
19
20#include "Stopwatch.h"
21
22#include <cstddef> // std::size_t
23#include <map> // std::map
24#include <string> // std::string
25#include <vector> // std::vector
26
27namespace nnp
28{
29
32{
33public:
39 virtual void setState(double* state) = 0;
46 virtual void setError(
47 double const* const error,
48 std::size_t const size = 1) = 0;
58 virtual void setJacobian(
59 double const* const jacobian,
60 std::size_t const columns = 1) = 0;
63 virtual void update() = 0;
70 virtual std::string status(std::size_t epoch) const = 0;
75 virtual std::vector<std::string> statusHeader() const = 0;
80 virtual std::vector<std::string> info() const = 0;
85 virtual void setupTiming(
86 std::string const& prefix = "upd");
89 virtual void resetTimingLoop();
94 virtual
95 std::map<std::string, Stopwatch> getTiming() const;
96
97protected:
103 Updater(std::size_t const sizeState);
104
106 bool timing;
110 std::size_t sizeState;
112 std::string prefix;
114 std::map<std::string, Stopwatch> sw;
115};
116
117}
118
119#endif
Base class for different weight update methods.
Definition: Updater.h:32
Updater(std::size_t const sizeState)
Constructor.
Definition: Updater.cpp:22
virtual std::map< std::string, Stopwatch > getTiming() const
Return timings gathered in stopwatch map.
Definition: Updater.cpp:37
std::string prefix
Prefix for timing stopwatches.
Definition: Updater.h:112
virtual void resetTimingLoop()
Start a new timing loop (e.g.
Definition: Updater.cpp:42
virtual std::string status(std::size_t epoch) const =0
Status report.
virtual void setState(double *state)=0
Set pointer to current state.
std::size_t sizeState
Number of neural network connections (weights + biases).
Definition: Updater.h:110
bool timingReset
Internal loop timer reset switch.
Definition: Updater.h:108
virtual std::vector< std::string > statusHeader() const =0
Header for status report file.
virtual void setError(double const *const error, std::size_t const size=1)=0
Set pointer to current error vector.
bool timing
Whether detailed timing is enabled.
Definition: Updater.h:106
virtual std::vector< std::string > info() const =0
Information about this updater.
virtual void setupTiming(std::string const &prefix="upd")
Activate detailed timing.
Definition: Updater.cpp:29
virtual void setJacobian(double const *const jacobian, std::size_t const columns=1)=0
Set pointer to current Jacobi matrix.
virtual void update()=0
Perform single update of state vector.
std::map< std::string, Stopwatch > sw
Stopwatch map for timing.
Definition: Updater.h:114
Definition: Atom.h:29