Skip to content

Commit

Permalink
Impl Mul and MulAssign for stochastic noise
Browse files Browse the repository at this point in the history
  • Loading branch information
ChristopherRabotin committed Jan 14, 2025
1 parent 706ac28 commit c5d3ec8
Show file tree
Hide file tree
Showing 4 changed files with 62 additions and 10 deletions.
22 changes: 13 additions & 9 deletions src/od/noise/gauss_markov.rs
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ use rand::Rng;
use rand_distr::Normal;
use serde_derive::{Deserialize, Serialize};
use std::fmt;
use std::ops::Mul;
use std::ops::{Mul, MulAssign};

use super::Stochastics;

Expand Down Expand Up @@ -153,14 +153,18 @@ impl Mul<f64> for GaussMarkov {
type Output = Self;

/// Scale the Gauss Markov process by a constant, maintaining the same time constant.
fn mul(self, rhs: f64) -> Self::Output {
Self {
tau: self.tau,
process_noise: self.process_noise * rhs,
constant: None,
init_sample: None,
prev_epoch: None,
}
fn mul(mut self, rhs: f64) -> Self::Output {
self.process_noise *= rhs;
self.constant = None;
self.init_sample = None;
self.prev_epoch = None;
self
}
}

impl MulAssign<f64> for GaussMarkov {
fn mul_assign(&mut self, rhs: f64) {
*self = *self * rhs;
}
}

Expand Down
22 changes: 22 additions & 0 deletions src/od/noise/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ use rand_pcg::Pcg64Mcg;
use serde_derive::{Deserialize, Serialize};
use std::error::Error;
use std::fs::File;
use std::ops::{Mul, MulAssign};
use std::path::Path;
use std::sync::Arc;

Expand Down Expand Up @@ -212,6 +213,27 @@ impl StochasticNoise {
}
}

impl Mul<f64> for StochasticNoise {
type Output = Self;

fn mul(mut self, rhs: f64) -> Self::Output {
if let Some(mut wn) = &mut self.white_noise {
wn *= rhs;
}
if let Some(mut gm) = &mut self.bias {
gm *= rhs;
}

self
}
}

impl MulAssign<f64> for StochasticNoise {
fn mul_assign(&mut self, rhs: f64) {
*self = *self * rhs;
}
}

pub struct StochasticState {
pub run: u32,
pub dt_s: f64,
Expand Down
18 changes: 18 additions & 0 deletions src/od/noise/white.rs
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,8 @@
along with this program. If not, see <https://www.gnu.org/licenses/>.
*/

use std::ops::{Mul, MulAssign};

use anise::constants::SPEED_OF_LIGHT_KM_S;
use hifitime::{Duration, Epoch};
use rand::Rng;
Expand Down Expand Up @@ -77,6 +79,22 @@ impl Stochastics for WhiteNoise {
}
}

impl Mul<f64> for WhiteNoise {
type Output = Self;

/// Scale the white noise sigmas by a constant.
fn mul(mut self, rhs: f64) -> Self::Output {
self.sigma *= rhs;
self
}
}

impl MulAssign<f64> for WhiteNoise {
fn mul_assign(&mut self, rhs: f64) {
*self = *self * rhs;
}
}

#[cfg(test)]
mod ut_wn {
use hifitime::{Epoch, TimeUnits};
Expand Down
10 changes: 9 additions & 1 deletion tests/orbit_determination/simulator.rs
Original file line number Diff line number Diff line change
Expand Up @@ -216,7 +216,7 @@ fn continuous_tracking_cov_test(tracking_data: TrackingDataArc) {
fn od_with_modulus_cov_test(
spacecraft: Spacecraft,
tracking_data: TrackingDataArc,
devices: BTreeMap<String, GroundStation>,
mut devices: BTreeMap<String, GroundStation>,
trajectory: Trajectory,
almanac: Arc<Almanac>,
) {
Expand All @@ -227,6 +227,14 @@ fn od_with_modulus_cov_test(
arc.set_moduli(MeasurementType::Range, jpl_dsn_code_length_km);
arc.apply_moduli();

// Increase the noise on the OD process
// Set a bias instead of assuming a modulus.
for (_, device) in &mut devices {
for (_, stochastics) in device.stochastic_noises.as_mut().unwrap().iter_mut() {
*stochastics *= 2.0;
}
}

let uncertainty = SpacecraftUncertainty::builder()
.nominal(spacecraft)
.frame(LocalFrame::RIC)
Expand Down

0 comments on commit c5d3ec8

Please sign in to comment.