-
Notifications
You must be signed in to change notification settings - Fork 38
Measurement statistics module #896
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from 11 commits
Commits
Show all changes
46 commits
Select commit
Hold shift + click to select a range
5c8d7b3
add statistics module setup
mgovers e606f4c
minor refactor
mgovers 698bc1f
add calculation parameter tests
mgovers dab85bc
add sym calculation params for symmetric current sensor
mgovers 4f63f86
unit tests for statistics
mgovers d5234f1
extend statistics functionality
mgovers 159dd45
Merge branch 'feature/statistics-module' into feature/current-sensor-…
mgovers deffcfd
change to rdv and add some tests
nitbharambe a2fe613
add decomposed rough
nitbharambe befc6c8
rename rdv 2
nitbharambe 3e20a34
fix polar tests non conversion
nitbharambe 72013ec
add remaining tests
nitbharambe 2581a62
wip tests correction
nitbharambe f7cd9eb
fix remaining
nitbharambe 279e3a9
cleanup
nitbharambe 0012881
structured bindings ref
nitbharambe 30f1787
remove irrelavant todos
nitbharambe b4edcaf
Merge branch 'feature/statistics-module' into feature/current-sensor-…
nitbharambe 909ebcf
add implementation of current sensor
nitbharambe 79db492
add decomposed sym asym conversions
nitbharambe 101d0a3
move subcases
nitbharambe 38d716f
Merge branch 'feature/statistics-module' into feature/current-sensor-…
nitbharambe 9883966
add calc param
nitbharambe 2cb1b9f
Merge branch 'main' into feature/statistics-module
nitbharambe 004d2bf
Merge branch 'feature/statistics-module' into feature/current-sensor-…
nitbharambe ea4fcd8
wip current sensor
nitbharambe decc9e4
finish all tests
nitbharambe ae2b2c5
revert new conversions
nitbharambe a165f46
add correct new conversions
nitbharambe 280729c
rename to randvar
nitbharambe f21f599
address comments
nitbharambe 49caa85
Apply suggestions from code review
nitbharambe 73045b9
use constants
nitbharambe 6e31899
Merge branch 'feature/statistics-module' into feature/current-sensor-…
nitbharambe 4d37735
Update power_grid_model_c/power_grid_model/include/power_grid_model/c…
nitbharambe 5f9ab40
add tests and fixes
nitbharambe 12eb949
shorten tests
nitbharambe 5ee89e4
change shift to loop
nitbharambe 981a65a
Merge branch 'feature/statistics-module' into feature/current-sensor-…
nitbharambe fb6da0f
add equation docs
nitbharambe 2eba909
resolve docstring comments
nitbharambe 273bbcd
change order of initialization
nitbharambe 83838ec
remove todos
nitbharambe 68c9fd3
Merge branch 'feature/statistics-module' into feature/current-sensor-…
Jerry-Jinfeng-Guo 101936d
Merge pull request #903 from PowerGridModel/feature/current-sensor-impl
Jerry-Jinfeng-Guo 0202694
Merge branch 'main' into feature/statistics-module
Jerry-Jinfeng-Guo File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
167 changes: 167 additions & 0 deletions
167
power_grid_model_c/power_grid_model/include/power_grid_model/common/statistics.hpp
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,167 @@ | ||
// SPDX-FileCopyrightText: Contributors to the Power Grid Model project <[email protected]> | ||
// | ||
// SPDX-License-Identifier: MPL-2.0 | ||
|
||
#pragma once | ||
|
||
#include "common.hpp" | ||
#include "three_phase_tensor.hpp" | ||
|
||
/** | ||
* @file statistics.hpp | ||
* @brief This file contains various structures and functions for handling statistical representations of | ||
* randomly distributed variables(RDV) used in the Power Grid Model, like in the State Estimation algorithms to | ||
nitbharambe marked this conversation as resolved.
Show resolved
Hide resolved
|
||
* handle measurements. | ||
* | ||
* The structures provided in this file are used to represent measured values of sensors | ||
* with different types of variances. These structures support both symmetric and asymmetric representations and | ||
* provide conversion operators to transform between these representations. | ||
* | ||
* A Randomly distributed variable in PGM can have following characteristics: | ||
nitbharambe marked this conversation as resolved.
Show resolved
Hide resolved
|
||
* - Uniform: Single Variance for all phases | ||
* - Independent: Unique Variance for each phase | ||
* - Real: The Real value without direction, eg. real axis: RealValue (* 1), imaginary axis: RealValue (* 1i). | ||
* - Complex: A combined complex value in `a + bi` notation. | ||
nitbharambe marked this conversation as resolved.
Show resolved
Hide resolved
|
||
* | ||
* Based on these, we use combine variables in Polar/Decomposed forms: | ||
* - Decomposed: Treat RDV individually as in cartesian co-ordinates with a separate variance for both real and | ||
* complex component. | ||
* - Polar: RDV is in polar co-ordinates, with magnitude and angle. | ||
nitbharambe marked this conversation as resolved.
Show resolved
Hide resolved
|
||
* | ||
*/ | ||
|
||
namespace power_grid_model { | ||
template <symmetry_tag sym_type> struct UniformRealRDV { | ||
using sym = sym_type; | ||
|
||
static constexpr bool symmetric{is_symmetric_v<sym>}; | ||
|
||
RealValue<sym> value{}; | ||
double variance{}; // variance (sigma^2) of the error range, in p.u. | ||
|
||
explicit operator UniformRealRDV<asymmetric_t>() const | ||
requires(is_symmetric_v<sym>) | ||
{ | ||
return {.value = RealValue<asymmetric_t>{std::piecewise_construct, value}, .variance = variance}; | ||
} | ||
explicit operator UniformRealRDV<symmetric_t>() const | ||
requires(is_asymmetric_v<sym>) | ||
{ | ||
return {.value = mean_val(value), .variance = variance / 3.0}; | ||
} | ||
Jerry-Jinfeng-Guo marked this conversation as resolved.
Show resolved
Hide resolved
|
||
}; | ||
|
||
template <symmetry_tag sym_type> struct IndependentRealRDV { | ||
using sym = sym_type; | ||
|
||
static constexpr bool symmetric{is_symmetric_v<sym>}; | ||
|
||
RealValue<sym> value{}; | ||
RealValue<sym> variance{}; // variance (sigma^2) of the error range, in p.u. | ||
|
||
explicit operator UniformRealRDV<symmetric_t>() const { | ||
constexpr auto scale = is_asymmetric_v<sym> ? 3.0 : 1.0; | ||
return {.value = mean_val(value), .variance = mean_val(variance) / scale}; | ||
} | ||
explicit operator UniformRealRDV<asymmetric_t>() const { return {.value = value, .variance = mean_val(variance)}; } | ||
explicit operator IndependentRealRDV<asymmetric_t>() const | ||
requires(is_symmetric_v<sym>) | ||
{ | ||
return {.value = RealValue<asymmetric_t>{std::piecewise_construct, value}, | ||
.variance = RealValue<asymmetric_t>{std::piecewise_construct, variance}}; | ||
} | ||
explicit operator IndependentRealRDV<symmetric_t>() const | ||
requires(is_asymmetric_v<sym>) | ||
{ | ||
return {.value = mean_val(value), .variance = mean_val(variance) / 3.0}; | ||
figueroa1395 marked this conversation as resolved.
Show resolved
Hide resolved
|
||
} | ||
}; | ||
|
||
// Complex measured value of a sensor in p.u. with a uniform variance across all phases and axes of the complex plane | ||
// (rotationally symmetric) | ||
template <symmetry_tag sym_type> struct UniformComplexRDV { | ||
nitbharambe marked this conversation as resolved.
Show resolved
Hide resolved
|
||
using sym = sym_type; | ||
|
||
static constexpr bool symmetric{is_symmetric_v<sym>}; | ||
|
||
ComplexValue<sym> value{}; | ||
double variance{}; // variance (sigma^2) of the error range, in p.u. | ||
}; | ||
|
||
inline UniformComplexRDV<symmetric_t> pos_seq(UniformComplexRDV<asymmetric_t> const& var) { | ||
return {.value = pos_seq(var.value), .variance = var.variance / 3.0}; | ||
} | ||
inline UniformComplexRDV<asymmetric_t> three_phase(UniformComplexRDV<symmetric_t> const& var) { | ||
return {.value = ComplexValue<asymmetric_t>{var.value}, .variance = var.variance}; | ||
} | ||
|
||
// Complex measured value of a sensor in p.u. with separate variances per phase (but rotationally symmetric in the | ||
// complex plane) | ||
template <symmetry_tag sym_type> struct IndependentComplexRDV { | ||
using sym = sym_type; | ||
|
||
static constexpr bool symmetric{is_symmetric_v<sym>}; | ||
|
||
ComplexValue<sym> value{}; | ||
RealValue<sym> variance{}; // variance (sigma^2) of the error range, in p.u. | ||
|
||
explicit operator UniformComplexRDV<sym>() const { | ||
return UniformComplexRDV<sym>{.value = value, .variance = sum_val(variance)}; | ||
} | ||
Jerry-Jinfeng-Guo marked this conversation as resolved.
Show resolved
Hide resolved
|
||
}; | ||
|
||
// Complex measured value of a sensor in p.u. modeled as separate real and imaginary components with independent | ||
// variances (rotationally symmetric) | ||
template <symmetry_tag sym_type> struct DecomposedComplexRDV { | ||
using sym = sym_type; | ||
|
||
static constexpr bool symmetric{is_symmetric_v<sym>}; | ||
|
||
IndependentRealRDV<sym> real_component; | ||
IndependentRealRDV<sym> imag_component; | ||
|
||
ComplexValue<sym> value() const { return {real_component.value, imag_component.value}; } | ||
|
||
explicit operator UniformComplexRDV<sym>() const { | ||
return static_cast<UniformComplexRDV<sym>>(static_cast<IndependentComplexRDV<sym>>(*this)); | ||
} | ||
explicit operator IndependentComplexRDV<sym>() const { | ||
return IndependentComplexRDV<sym>{.value = value(), | ||
.variance = real_component.variance + imag_component.variance}; | ||
} | ||
}; | ||
|
||
// Complex measured value of a sensor in p.u. in polar coordinates (magnitude and angle) | ||
// (rotationally symmetric) | ||
template <symmetry_tag sym_type> struct PolarComplexRDV { | ||
using sym = sym_type; | ||
|
||
static constexpr bool symmetric{is_symmetric_v<sym>}; | ||
|
||
UniformRealRDV<sym> magnitude; | ||
UniformRealRDV<sym> angle; | ||
|
||
ComplexValue<sym> value() const { return magnitude.value * exp(1.0i * angle.value); } | ||
|
||
explicit operator UniformComplexRDV<sym>() const { | ||
return static_cast<UniformComplexRDV<sym>>(static_cast<IndependentComplexRDV<sym>>(*this)); | ||
} | ||
explicit operator IndependentComplexRDV<sym>() const { | ||
return IndependentComplexRDV<sym>{ | ||
.value = value(), .variance = magnitude.variance + magnitude.value * magnitude.value * angle.variance}; | ||
} | ||
explicit operator DecomposedComplexRDV<sym>() const { | ||
auto const cos_theta = cos(angle.value); | ||
auto const sin_theta = sin(angle.value); | ||
auto const real_component = magnitude.value * cos_theta; | ||
auto const imag_component = magnitude.value * sin_theta; | ||
return DecomposedComplexRDV<sym>{ | ||
.real_component = {.value = real_component, | ||
.variance = magnitude.variance * cos_theta * cos_theta + | ||
imag_component * imag_component * angle.variance}, | ||
.imag_component = {.value = imag_component, | ||
.variance = magnitude.variance * sin_theta * sin_theta + | ||
real_component * real_component * angle.variance}}; | ||
} | ||
nitbharambe marked this conversation as resolved.
Show resolved
Hide resolved
|
||
}; | ||
} // namespace power_grid_model |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.