Skip to content

Commit

Permalink
Merge branch 'feature/iteration63' into develop
Browse files Browse the repository at this point in the history
  • Loading branch information
neoneye committed Nov 26, 2023
2 parents 1a17eb3 + 5dd3243 commit c5993f7
Show file tree
Hide file tree
Showing 15 changed files with 746 additions and 45 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: 20 ms
subcommand_analytics finished, elapsed: 21 ms
Original file line number Diff line number Diff line change
@@ -1 +1 @@
2023-11-23T01:19:08Z
2023-11-25T18:24:46Z
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.23"
version = "2023.11.25"
authors = ["Simon Strandgaard <neoneye@gmail.com>"]
description = "Command line interface for LODA Rust"
repository = "https://github.com/loda-lang/loda-rust"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -820,19 +820,19 @@ impl arc_work_model::Pair {
let output_least_popular_color: Option<u8> = self.output.image_meta.histogram_all.least_popular_color_disallow_ambiguous();

if input_most_popular_color.is_some() && input_most_popular_color == output_most_popular_color {
let label = ActionLabel::InputMostPopularColorIsOutputMostPopularColor;
let label = ActionLabel::PairInputMostPopularColorIsOutputMostPopularColor;
self.action_label_set.insert(label);
}
if input_most_popular_color.is_some() && input_most_popular_color == output_least_popular_color {
let label = ActionLabel::InputMostPopularColorIsOutputLeastPopularColor;
let label = ActionLabel::PairInputMostPopularColorIsOutputLeastPopularColor;
self.action_label_set.insert(label);
}
if input_least_popular_color.is_some() && input_least_popular_color == output_most_popular_color {
let label = ActionLabel::InputLeastPopularColorIsOutputMostPopularColor;
let label = ActionLabel::PairInputLeastPopularColorIsOutputMostPopularColor;
self.action_label_set.insert(label);
}
if input_least_popular_color.is_some() && input_least_popular_color == output_least_popular_color {
let label = ActionLabel::InputLeastPopularColorIsOutputLeastPopularColor;
let label = ActionLabel::PairInputLeastPopularColorIsOutputLeastPopularColor;
self.action_label_set.insert(label);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,18 +27,24 @@ pub enum PredictionType {

SolveSplit,
SolveGenetic,

/// Number of unique colors the output images across all train pairs, is s a single color.
SolveOneColor,
}

impl PredictionType {
#[allow(dead_code)]
fn sort_weight(&self) -> u32 {
match self {
// Split tries out lots of things deterministic, so it's high priority.
Self::SolveSplit => 0,
Self::SolveSplit => 0,

// The SolveOneColor is a very simple solver, so it's high priority.
Self::SolveOneColor => 1,

// The LODA programs that have been manually been coded are somewhat good and deals with many edge cases.
// The mutated LODA programs, may not deal with edge cases, but they are still good, since all train+test pairs gets evaluated.
Self::SolveGenetic => 1,
Self::SolveGenetic => 2,

// Logistic regression is rarely correct, so it's low priority.
// It's best at tasks where `input_size == output_size`.
Expand Down
33 changes: 30 additions & 3 deletions rust_project/loda-rust-cli/src/arc/histogram.rs
Original file line number Diff line number Diff line change
Expand Up @@ -327,7 +327,7 @@ impl Histogram {
self.least_popular().count_allow_ambiguous()
}

/// The pairs ordered by their color value.
/// The pairs ordered by their color value. Ignoring their count.
///
/// The lowest color value comes first.
///
Expand All @@ -342,6 +342,16 @@ impl Histogram {
pairs
}

/// The colors ordered by their color value. Ignoring their count.
///
/// The lowest color value comes first.
///
/// The highest color value comes last.
#[allow(dead_code)]
pub fn color_vec(&self) -> Vec<u8> {
self.pairs_ordered_by_color().iter().map(|pair| pair.1).collect()
}

/// The least frequent occurring comes first.
///
/// The medium frequent occurring comes middle.
Expand Down Expand Up @@ -850,7 +860,24 @@ mod tests {
}

#[test]
fn test_50001_pairs_descending() {
fn test_50001_color_vec() {
// Arrange
let mut h = Histogram::new();
let values: [u8; 8] = [3, 42, 42, 3, 2, 3, 4, 5];
for value in values {
h.increment(value);
}

// Act
let actual: Vec<u8> = h.color_vec();

// Assert
let expected: Vec<u8> = vec![2, 3, 4, 5, 42];
assert_eq!(actual, expected);
}

#[test]
fn test_50002_pairs_descending() {
// Arrange
let mut h = Histogram::new();
let values: [u8; 12] = [3, 1, 1, 42, 7, 42, 7, 3, 2, 3, 4, 5];
Expand All @@ -867,7 +894,7 @@ mod tests {
}

#[test]
fn test_50002_pairs_ascending() {
fn test_50003_pairs_ascending() {
// Arrange
let mut h = Histogram::new();
let values: [u8; 12] = [3, 1, 1, 42, 7, 42, 7, 3, 2, 3, 4, 5];
Expand Down
9 changes: 5 additions & 4 deletions rust_project/loda-rust-cli/src/arc/label.rs
Original file line number Diff line number Diff line change
Expand Up @@ -389,16 +389,16 @@ pub enum ActionLabel {
OutputImageColorsComesFromInputImage,

/// What input colors explains the output colors. The most popular stays the most popular.
InputMostPopularColorIsOutputMostPopularColor,
PairInputMostPopularColorIsOutputMostPopularColor,

/// What input colors explains the output colors. The least popular stays the least popular.
InputLeastPopularColorIsOutputLeastPopularColor,
PairInputLeastPopularColorIsOutputLeastPopularColor,

/// What input colors explains the output colors. The most popular becomes the least popular.
InputMostPopularColorIsOutputLeastPopularColor,
PairInputMostPopularColorIsOutputLeastPopularColor,

/// What input colors explains the output colors. The least popular becomes the most popular.
InputLeastPopularColorIsOutputMostPopularColor,
PairInputLeastPopularColorIsOutputMostPopularColor,

/// The output size is the same as the input size.
/// Each pixel have the same number of identical pixels as in the input.
Expand Down Expand Up @@ -468,6 +468,7 @@ pub enum ActionLabel {
// ObjectsOnlyMoveInDirectionY,
// CropWhenFinishedDrawingInsideSingleColorObjectWithColor { color: u8 },
// OutputImageCropOutSingleColorObject { color: u8 },
// OutputSizeIsHalfOfInputSizeDependingOnInputOrientation,
// OutputSizeIsTheSameAsBoundingBoxOfSingleColorObject { color: u8 },
// OutputSizeIsTheSameAsHoleInSingleColorObject { color: u8 },
// OutputSizeIsTheSameAsInputSmallestSingleColorObjectRectangle,
Expand Down
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 @@ -148,6 +148,7 @@ mod single_color_object;
mod single_color_object_satisfies_label;
mod single_color_object_to_label;
mod solve_logisticregression;
mod solve_one_color;
mod solve_split;
mod split;
mod split_to_label;
Expand Down Expand Up @@ -291,6 +292,7 @@ pub use single_color_object::{SingleColorObject, SingleColorObjectRectangle, Sin
pub use single_color_object_satisfies_label::SingleColorObjectSatisfiesLabel;
pub use single_color_object_to_label::SingleColorObjectToLabel;
pub use solve_logisticregression::SolveLogisticRegression;
pub use solve_one_color::SolveOneColor;
pub use solve_split::{Operation, SolveSplit, SolveSplitFoundSolution};
pub use split::{EvenSplit, Split, SplitCandidate, SplitCandidateContainer};
pub use split_to_label::SplitToLabel;
Expand Down
15 changes: 10 additions & 5 deletions rust_project/loda-rust-cli/src/arc/solve_logisticregression.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,10 @@
//! Performs logistic regression of each input pixel with the corresponding classification for the output pixel.
//!
//! These older commits solves some of the tasks from the hidden ARC dataset, using logistic regression:
//! commit 2023-Nov-25: solves 2 of the hidden ARC tasks. This uses variant=0 and variant=1 and variant=2. Only variant=0 does something useful.
//! Since it uses multiple variants and doesn't solve more tasks than the previous commit, then it is not an improvement.
//! https://github.com/loda-lang/loda-rust/commit/d08069b56c92c54140c27d13f8e6ad0897824d5a
//!
//! commit 2023-Nov-23: solves 2 of the hidden ARC tasks. This uses variant=0 and variant=1 and variant=2. Only variant=0 does something useful.
//! Since it uses multiple variants and doesn't solve more tasks than the previous commit, then it is not an improvement.
//! https://github.com/loda-lang/loda-rust/commit/2e6577cd66af0c00fdd65533d4770a40ed2ccf3c
Expand Down Expand Up @@ -70,6 +74,7 @@
//! However I don't see any improvement of the prediction accuracy.
//!
//! Future experiments:
//! * Use confusion matrix for determining what parameters have impact on the precision. And enable/disable features based on the confusion matrix.
//! * Transform the `train` pairs: rotate90, rotate180, rotate270, flipx, flipy.
//! * Transform the `test` pairs: rotate90, rotate180, rotate270, flipx, flipy.
//! * Provide `weight` to logistic regression, depending on how important each parameter is.
Expand Down Expand Up @@ -388,6 +393,7 @@ impl ProcessTaskContext {
struct ProcessedTaskWithOneTestPair {
test_index: u8,
cropped_image: Image,
#[allow(dead_code)]
inspect_internal_image_vec: Vec<Image>,
}

Expand All @@ -397,12 +403,10 @@ struct ProcessedTask {
}

pub struct SolveLogisticRegression {
#[allow(dead_code)]
tasks: Vec<Task>,
}

impl SolveLogisticRegression {
#[allow(dead_code)]
pub fn new(tasks: Vec<Task>) -> Self {
// println!("loaded {} tasks", tasks.len());
Self {
Expand All @@ -415,6 +419,7 @@ impl SolveLogisticRegression {
/// This can be run with the public ARC dataset contains expected output for the test pairs.
///
/// This cannot be run with the hidden ARC dataset, which doesn't contain expected output for the test pairs.
#[allow(dead_code)]
pub fn run_and_verify(&self) -> anyhow::Result<()> {
let run_and_verify_htmllog = true;
let run_and_verify_ignore_already_solved = false;
Expand Down Expand Up @@ -559,7 +564,7 @@ impl SolveLogisticRegression {
/// This code is intended to run with the hidden ARC dataset, which doesn't contain expected output for the test pairs.
pub fn run_predictions(&self) -> anyhow::Result<TaskNameToPredictionVec> {
let number_of_tasks: u64 = self.tasks.len() as u64;
println!("{} - run start - will process {} tasks with logistic regression", human_readable_utc_timestamp(), number_of_tasks);
println!("{} - run start - will process {} tasks with SolveLogisticRegression", human_readable_utc_timestamp(), number_of_tasks);
let count_solved = AtomicUsize::new(0);
let pb = ProgressBar::new(number_of_tasks as u64);
pb.set_style(ProgressStyle::default_bar()
Expand Down Expand Up @@ -676,10 +681,10 @@ impl SolveLogisticRegression {
}

let mut prediction_vec = Vec::<arcathon_solution_coordinator::Prediction>::new();
for (test_index, ptwotp) in ptwotp_vec.iter().enumerate() {
for ptwotp in &ptwotp_vec {
let grid: arc_json_model::Grid = arc_json_model::Grid::from_image(&ptwotp.cropped_image);
let prediction = arcathon_solution_coordinator::Prediction {
output_id: test_index.min(255) as u8,
output_id: ptwotp.test_index.min(255) as u8,
output: grid,
prediction_type,
};
Expand Down
Loading

0 comments on commit c5993f7

Please sign in to comment.