-
Notifications
You must be signed in to change notification settings - Fork 224
Code to optimize the choice of new moon #7053
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
base: main
Are you sure you want to change the base?
Conversation
type Output = f64; | ||
fn cost(&self, param: &f64) -> Result<f64, Error> { | ||
let candidate = self.center_moment + *param; | ||
Ok(self.new_moon_moments.iter().map(|(i, x)| (candidate - *x) - self.mean_synodic_length * (self.new_moon_number - i) as f64).map(|v| v * v).sum::<f64>()) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
this uses mean absolute error for the new moon dates. but the date of the new moon is not the only thing our algorithm approximates.
the cost should be the count of months where the simple approximation doesn't match the GB/T calculations for >2100 (and potentially the ground truth for <1900, weighted appropriately)
let jan1900 = fixed_from_gregorian(1900, 1, 1); | ||
let jan2000 = fixed_from_gregorian(2000, 1, 1); | ||
let jan2100 = fixed_from_gregorian(2100, 1, 1); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
this is the one range where the approximation isn't used, so why optimise over that?
let cost_fn = NewMoons { | ||
new_moon_moments, | ||
mean_synodic_length: MEAN_SYNODIC_MONTH_LENGTH_F64, | ||
center_moment: Moment::try_from_rata_die(fixed_from_gregorian(2000, 1, 6)).unwrap(), |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
issue: our LocalMoment
is milliseconds-i64. optimising a Moment
, which is day-f64, is not equivalent
const MEAN_SYNODIC_MONTH_LENGTH: Milliseconds = day_fraction_to_ms!(295305888531 / 10000000000i64); | ||
|
||
#[cfg(test)] | ||
const MEAN_SYNODIC_MONTH_LENGTH_F64: f64 = 29.5305888531; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
issue: this is not an exact version of MEAN_SYNODIC_MONTH_LENGTH
18:14 which actually happened if you want to do this, we should optimise the choice of actual new moon, instead of inventing one |
Trying to pick the best value for the new moon. Output of this test:
which equates to about 14:18 UTC on Jan 6, 2000, as compared to 18:14 on that day as we currently have.
CC @robertbastian