Skip to content

Conversation

@fderuiter
Copy link
Owner

This PR refactors several modules in math_explorer to adhere to DRY and SOLID principles.

  1. Clinical Trials: Removed unwrap() in simple_randomization (deprecated wrapper), replacing it with expect for better safety/documentation.
  2. ODE / Epidemiology: Created impl_vector_ops! macro in ode.rs and applied it to SIRState and SEIRState in compartmental.rs, removing repetitive manual implementation of arithmetic traits.
  3. AI / Climate:
    • Defined ActivationFunction trait in ai/activations.rs.
    • Implemented ReLU, LeakyReLU, Sigmoid, Tanh.
    • Refactored Predictor, Encoder, Decoder, and Autoencoder to be generic over A: ActivationFunction<f32>.
    • Added type aliases (Autoencoder, Encoder, etc.) defaulting to LeakyReLU to ensure backward compatibility with existing code (e.g., Cera).
    • Removed hardcoded leaky_relu usage in models.

All tests passed.


PR created automatically by Jules for task 17486821741747226782 started by @fderuiter

- Clinical Trials: Replace unwrap with expect in design.rs
- ODE/Epidemiology: Add impl_vector_ops macro to reduce boilerplate
- AI/Climate: Introduce ActivationFunction trait and generics for models
- Clean up duplicated logic and enforce type safety

Co-authored-by: fderuiter <127706008+fderuiter@users.noreply.github.com>
@google-labs-jules
Copy link
Contributor

👋 Jules, reporting for duty! I'm here to lend a hand with this pull request.

When you start a review, I'll add a 👀 emoji to each comment to let you know I've read it. I'll focus on feedback directed at me and will do my best to stay out of conversations between you and other bots or reviewers to keep the noise down.

I'll push a commit with your requested changes shortly after. Please note there might be a delay between these steps, but rest assured I'm on the job!

For more direct control, you can switch me to Reactive Mode. When this mode is on, I will only act on comments where you specifically mention me with @jules. You can find this option in the Pull Request section of your global Jules UI settings. You can always switch back!

New to Jules? Learn more at jules.google/docs.


For security, I will only act on instructions from the user who triggered this task.

@fderuiter
Copy link
Owner Author

Run cargo fmt -- --check
Diff in /home/runner/work/math/math/math_explorer/src/climate/autoencoder.rs:104:
}

impl<A: ActivationFunction> DecoderGeneric {

  • pub fn new_with_activation(
  •    latent_channels: usize,
    
  •    out_channels: usize,
    
  •    activation: A,
    
  • ) -> Self {
  • pub fn new_with_activation(latent_channels: usize, out_channels: usize, activation: A) -> Self {
    let layers = vec![
    ConvLayer::new(latent_channels, 64),
    ConvLayer::new(64, 64),
    Diff in /home/runner/work/math/math/math_explorer/src/climate/autoencoder.rs:149:
    }

impl<A: ActivationFunction + Clone> AutoencoderGeneric {

  • pub fn new_with_activation(
  •    in_channels: usize,
    
  •    latent_channels: usize,
    
  •    activation: A,
    
  • ) -> Self {
  •    let encoder = EncoderGeneric::new_with_activation(in_channels, latent_channels, activation.clone());
    
  • pub fn new_with_activation(in_channels: usize, latent_channels: usize, activation: A) -> Self {
  •    let encoder =
    
  •        EncoderGeneric::new_with_activation(in_channels, latent_channels, activation.clone());
       let decoder = DecoderGeneric::new_with_activation(latent_channels, in_channels, activation);
       Self { encoder, decoder }
    
    }
    Diff in /home/runner/work/math/math/math_explorer/src/climate/autoencoder.rs:191:
    assert_eq!(reconstruction.nrows(), n_samples);
    assert_eq!(reconstruction.ncols(), in_channels);
    }

}

Error: Process completed with exit code 1.

@google-labs-jules
Copy link
Contributor

Run cargo fmt -- --check
Diff in /home/runner/work/math/math/math_explorer/src/climate/autoencoder.rs:104:
}

impl<A: ActivationFunction> DecoderGeneric {

  • pub fn new_with_activation(
  •    latent_channels: usize,
    
  •    out_channels: usize,
    
  •    activation: A,
    
  • ) -> Self {
  • pub fn new_with_activation(latent_channels: usize, out_channels: usize, activation: A) -> Self {
    let layers = vec![
    ConvLayer::new(latent_channels, 64),
    ConvLayer::new(64, 64),
    Diff in /home/runner/work/math/math/math_explorer/src/climate/autoencoder.rs:149:
    }

impl<A: ActivationFunction + Clone> AutoencoderGeneric {

  • pub fn new_with_activation(
  •    in_channels: usize,
    
  •    latent_channels: usize,
    
  •    activation: A,
    
  • ) -> Self {
  •    let encoder = EncoderGeneric::new_with_activation(in_channels, latent_channels, activation.clone());
    
  • pub fn new_with_activation(in_channels: usize, latent_channels: usize, activation: A) -> Self {
  •    let encoder =
    
  •        EncoderGeneric::new_with_activation(in_channels, latent_channels, activation.clone());
       let decoder = DecoderGeneric::new_with_activation(latent_channels, in_channels, activation);
       Self { encoder, decoder }
    
    }
    Diff in /home/runner/work/math/math/math_explorer/src/climate/autoencoder.rs:191:
    assert_eq!(reconstruction.nrows(), n_samples);
    assert_eq!(reconstruction.ncols(), in_channels);
    }

}

Error: Process completed with exit code 1.

I have run cargo fmt to fix the formatting issues.

- Clinical Trials: Replace unwrap with expect in design.rs
- ODE/Epidemiology: Add impl_vector_ops macro to reduce boilerplate
- AI/Climate: Introduce ActivationFunction trait and generics for models
- Clean up duplicated logic and enforce type safety

Co-authored-by: fderuiter <127706008+fderuiter@users.noreply.github.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants