Skip to content

Commit

Permalink
Merge branch 'feature/iteration64' into develop
Browse files Browse the repository at this point in the history
  • Loading branch information
neoneye committed Nov 29, 2023
2 parents c5993f7 + ff8b7b9 commit 076e13d
Show file tree
Hide file tree
Showing 10 changed files with 196 additions and 47 deletions.
2 changes: 1 addition & 1 deletion rust_project/Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Original file line number Diff line number Diff line change
Expand Up @@ -32,4 +32,4 @@ optimize: 0, dontoptimize: 1, optimize/total: 0.0%
AnalyzeProgramModified
timestamps: 88

subcommand_analytics finished, elapsed: 21 ms
subcommand_analytics finished, elapsed: 24 ms
Original file line number Diff line number Diff line change
@@ -1 +1 @@
2023-11-25T18:24:46Z
2023-11-26T21:00:17Z
2 changes: 1 addition & 1 deletion rust_project/loda-rust-cli/Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[package]
name = "loda-rust-cli"
version = "2023.11.25"
version = "2023.11.26"
authors = ["Simon Strandgaard <[email protected]>"]
description = "Command line interface for LODA Rust"
repository = "https://github.com/loda-lang/loda-rust"
Expand Down
1 change: 1 addition & 0 deletions rust_project/loda-rust-cli/src/arc/arc_work_model.rs
Original file line number Diff line number Diff line change
Expand Up @@ -106,6 +106,7 @@ pub struct Input {

// Future experiments to do.
// least_popular_intersection_color
// density of each color, if it's noise the density is low, if it's a solid cluster the density is high.
//
// Resolving these properties is similar to a package manager, a DAG (directed acyclic graph).
// One property may depend on another property that depends on a third property.
Expand Down
58 changes: 58 additions & 0 deletions rust_project/loda-rust-cli/src/arc/measure_density.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,58 @@
use super::{Image, ImagePadding, convolution3x3, ImageHistogram, Histogram};
use anyhow::bail;

pub struct MeasureDensity {
pub density_any_direction: Image,
}

impl MeasureDensity {
pub fn analyze(image: &Image) -> anyhow::Result<Self> {
if image.is_empty() {
bail!("image is empty. Must be 1x1 or larger");
}
let padding: Image = image.padding_with_color(1, 255)?;
let density: Image = convolution3x3(&padding, conv3x3_measure_density_any_direction)?;
let instance = Self {
density_any_direction: density,
};
Ok(instance)
}
}

fn conv3x3_measure_density_any_direction(image: &Image) -> anyhow::Result<u8> {
let histogram: Histogram = image.histogram_all();
let center: u8 = image.get(1, 1).unwrap_or(255);
let count: u32 = histogram.get(center).min(9).max(1) - 1;
Ok(count as u8)
}

#[cfg(test)]
mod tests {
use super::*;
use crate::arc::ImageTryCreate;

#[test]
fn test_10000_density_any_direction() {
// Arrange
let pixels: Vec<u8> = vec![
5, 3, 3, 3,
3, 3, 3, 3,
5, 5, 3, 3,
3, 5, 3, 3,
];
let input: Image = Image::try_create(4, 4, pixels).expect("image");

// Act
let actual: MeasureDensity = MeasureDensity::analyze(&input).expect("image");

// Assert
let expected_pixels: Vec<u8> = vec![
0, 4, 5, 3,
2, 5, 7, 5,
2, 2, 6, 5,
0, 2, 3, 3,
];
let expected: Image = Image::try_create(4, 4, expected_pixels).expect("image");
assert_eq!(actual.density_any_direction, expected);
}
}
2 changes: 2 additions & 0 deletions rust_project/loda-rust-cli/src/arc/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -116,6 +116,7 @@ mod label;
mod landmark_single_pixel;
mod largest_interior_rectangle;
mod linespan;
mod measure_density;
mod ngram;
mod number_to_image;
mod object_with_different_color;
Expand Down Expand Up @@ -265,6 +266,7 @@ pub use label::{ActionLabel, ActionLabelSet, GridLabel, ImageCorner, ImageEdge,
pub use landmark_single_pixel::LandmarkSinglePixel;
pub use largest_interior_rectangle::LargestInteriorRectangle;
pub use linespan::{LineSpan, LineSpanDirection, LineSpanMode};
pub use measure_density::MeasureDensity;
pub use ngram::{ImageNgram, RecordBigram, RecordTrigram};
pub use number_to_image::NumberToImage;
pub use object_with_different_color::ObjectWithDifferentColor;
Expand Down
158 changes: 120 additions & 38 deletions rust_project/loda-rust-cli/src/arc/solve_logisticregression.rs

Large diffs are not rendered by default.

14 changes: 10 additions & 4 deletions rust_project/loda-rust-cli/src/arc/solve_one_color.rs
Original file line number Diff line number Diff line change
@@ -1,13 +1,15 @@
//! Solve tasks that outputs a single color.
//!
//! Solves zero of the hidden ARC tasks.
//!
//! The ARC 1 dataset contains 800 tasks, where 17 of the tasks outputs a single color.
//! 1190e5a7, 1a2e2828, 239be575, 23b5c85d, 27a28665, 3194b014, 445eab21, 44f52bb0, 5582e5ca, 642d658d,
//! 7039b2d7, 8597cfd7, b9b7f026, d631b094, d9fac9be, de1cd16c, e872b94a,
//!
//! This solver is able to solve 16 of the 17 tasks.
//! Where 10 is solved with some confidence.
//! Where 6 of them is solved as a happy accident.
//! Where 1 task is not solved b9b7f026, because it has more than 4 colors to choose from, and chooses the wrong color.
//! This solver is able to solve 14 of the 17 tasks.
//! Where 9 is solved with some confidence.
//! Where 5 of them is solved as a happy accident.
//! Where 3 tasks is not solved 1a2e2828, 27a28665, b9b7f026, because it has more than 4 colors to choose from, and chooses the wrong color.
//!
//! Weakness:
//! When there are 4 or more colors to choose from, then it doesn't do any prediction, and takes the 3 first colors.
Expand Down Expand Up @@ -513,6 +515,10 @@ impl SolveOneColor {
// Assign a low confidence score to these predictions, so they are ranked lower than other high confidence predictions.
// Rule out the noise color, grid color, most dense colors.
debug!("low confidence: task: {} - test_index: {} - available_colors: {:?}", task.id, test_index, the_colors);
// Taking the initial 3 colors doesn't solve any of the hidden ARC tasks.
// Here is a crappy 2nd guess. By reversing the_colors.
the_colors.reverse();
the_colors.truncate(3);
}
}
Ok(the_colors)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1603,7 +1603,7 @@ impl TraverseProgramsAndModels {
let resume_from_last_snapshot = false;

// Solve tasks that outputs a single color.
// Not yet tried on the hidden ARC dataset, so I don't know if this doesn't solves any tasks.
// On the hidden ARC dataset, this doesn't solve any tasks.
let try_solve_one_color = true;

// Solve `splitview` like tasks.
Expand Down

0 comments on commit 076e13d

Please sign in to comment.