Commit ddd36751 authored by Steffen Schotthöfer's avatar Steffen Schotthöfer
Browse files

added option to compute h via dual forumlation


Former-commit-id: 8f0169d9
parent ba68f7d0
......@@ -14,6 +14,7 @@ class SphericalHarmonics;
class QuadratureBase;
class Config;
class NewtonOptimizer;
class EntropyBase;
class nnDataGenerator
{
......@@ -56,6 +57,7 @@ class nnDataGenerator
VectorVector _moments; /*! @brief: Moment Vector pre-computed at each quadrature point: dim= _nq x _nTotalEntries */
NewtonOptimizer* _optimizer; /*! @brief: Class to solve minimal entropy problem */
EntropyBase* _entropy; /*! @brief: Class to handle entropy functional evaluations */
// Helper functions
/*! @brief : computes the global index of the moment corresponding to basis function (l,k)
......@@ -66,8 +68,11 @@ class nnDataGenerator
void ComputeMoments(); /*! @brief : Pre-Compute Moments at all quadrature points. */
// Main methods
void sampleSolutionU(); /*! @brief : Samples solution vectors u */
void computeEntropyH(); /*! @brief : Compute the entropy functional at (u,alpha) */
void sampleSolutionU(); /*! @brief : Samples solution vectors u */
void computeEntropyH_dual(); /*! @brief : Compute the entropy functional at (u,alpha) in dual formulation */
void computeEntropyH_primal(); /*! @brief: Compute the entropy functional at (u,alpha) in primal formulation */
// IO routines
void printTrainingData(); /*! @brief : Print computed training data to csv file and screen */
};
#endif // DATAGENERATOR_H
......@@ -6,6 +6,7 @@
#include "toolboxes/datagenerator.h"
#include "common/config.h"
#include "entropies/entropybase.h"
#include "optimizers/newtonoptimizer.h"
#include "quadratures/quadraturebase.h"
#include "solvers/sphericalharmonics.h"
......@@ -37,6 +38,9 @@ nnDataGenerator::nnDataGenerator( Config* settings ) {
// Optimizer
_optimizer = new NewtonOptimizer( _settings );
// Entropy
_entropy = EntropyBase::Create( _settings );
// Initialize Training Data
_uSol = VectorVector( _setSize, Vector( _nTotalEntries, 0.0 ) );
_alpha = VectorVector( _setSize, Vector( _nTotalEntries, 0.0 ) );
......@@ -54,7 +58,7 @@ void nnDataGenerator::computeTrainingData() {
_optimizer->SolveMultiCell( _alpha, _uSol, _moments );
// --- compute entropy functional ---
computeEntropyH();
computeEntropyH_primal();
// --- Print everything ----
printTrainingData();
......@@ -85,12 +89,25 @@ void nnDataGenerator::sampleSolutionU() {
}
}
void nnDataGenerator::computeEntropyH() {
void nnDataGenerator::computeEntropyH_dual() {
for( unsigned idx_set = 0; idx_set < _setSize; idx_set++ ) {
_hEntropy[idx_set] = _optimizer->ComputeObjFunc( _alpha[idx_set], _uSol[idx_set], _moments );
}
}
void nnDataGenerator::computeEntropyH_primal() {
double result = 0.0;
for( unsigned idx_set = 0; idx_set < _setSize; idx_set++ ) {
result = 0.0;
// Integrate (eta(eta'_*(alpha*m))
for( unsigned idx_quad = 0; idx_quad < _nq; idx_quad++ ) {
result += _entropy->Entropy( _entropy->EntropyPrimeDual( dot( _alpha[idx_set], _moments[idx_quad] ) ) ) * _weights[idx_quad];
}
_hEntropy[idx_set] = result;
}
}
void nnDataGenerator::printTrainingData() {
auto log = spdlog::get( "event" );
auto logCSV = spdlog::get( "tabular" );
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment