Skip to content
GitLab
Menu
Projects
Groups
Snippets
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Sign in
Toggle navigation
Menu
Open sidebar
KiT-RT
KiT-RT
Commits
ddd36751
Commit
ddd36751
authored
Nov 30, 2020
by
Steffen Schotthöfer
Browse files
added option to compute h via dual forumlation
Former-commit-id:
8f0169d9
parent
ba68f7d0
Changes
2
Hide whitespace changes
Inline
Side-by-side
code/include/toolboxes/datagenerator.h
View file @
ddd36751
...
...
@@ -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
code/src/toolboxes/datagenerator.cpp
View file @
ddd36751
...
...
@@ -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"
);
...
...
Write
Preview
Supports
Markdown
0%
Try again
or
attach a new file
.
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment