Skip to content

Commit

Permalink
Merge branch 'release/0.2.1'
Browse files Browse the repository at this point in the history
  • Loading branch information
mlange-42 committed Apr 22, 2020
2 parents 21da965 + a6bf55a commit 51fe8cd
Show file tree
Hide file tree
Showing 23 changed files with 365 additions and 57 deletions.
114 changes: 113 additions & 1 deletion Cargo.lock

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

3 changes: 2 additions & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[package]
name = "kohonen"
version = "0.2.0"
version = "0.2.1"
authors = ["m-lange <martin_lange_@gmx.net>"]
edition = "2018"

Expand All @@ -12,6 +12,7 @@ rand = "0.5.5"
easy_graph = { git = "https://github.com/mlange-42/easy_graph.git" }
serde = { version = "1.0", features = ["derive"] }
serde_json = "1.0"
dont_disappear = "3.0.1"

# TODO put CLI in feature
structopt = "0.3"
Expand Down
4 changes: 2 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -12,12 +12,12 @@ _Warning:_ This project is in a very experimental state.

### Installation

* Download the [latest binaries](https://github.com/mlange-42/kohonen/releases/latest).
* Download the [latest binaries](https://github.com/mlange-42/kohonen/releases).
* Unzip somewhere with write privileges (only required for running examples in place).

### Usage

* Try the examples in sub-directory `cmd_examples`.
* Try the examples in sub-directory [`/cmd_examples`](https://github.com/mlange-42/chrono-photo/tree/master/cmd_examples).
* To view the full list of options, run `kohonen --help`

## Library / crate
Expand Down
18 changes: 18 additions & 0 deletions cmd_examples/countries-test.koo
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
--file example_data\countries.csv
--size 16 12
--epochs 2500
--layers "child_mort_2010 birth_p_1000 log_GNI LifeExpectancy PopGrowth PopUrbanized PopGrowthUrb AdultLiteracy PrimSchool Income_low_40 Income_high_20" "continent"
--preserve Country code
--labels Country
--label-length 10
--categ false true
--norm gauss none
--weights 1 0.5
--alpha 0.2 0.01 lin
--radius 6 0.8 lin
--decay 0.2 0.001 exp
--neigh gauss
--no-data -
--fps 1
--output example_data\_countries
--wait
3 changes: 2 additions & 1 deletion cmd_examples/countries.bat
Original file line number Diff line number Diff line change
Expand Up @@ -15,4 +15,5 @@
--neigh gauss ^
--no-data - ^
--fps 1 ^
--output ..\example_data\_countries
--output ..\example_data\_countries ^
--wait
18 changes: 18 additions & 0 deletions cmd_examples/countries.koo
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
--file ../example_data/countries.csv
--size 16 12
--epochs 2500
--layers "child_mort_2010 birth_p_1000 log_GNI LifeExpectancy PopGrowth PopUrbanized PopGrowthUrb AdultLiteracy PrimSchool Income_low_40 Income_high_20" "continent"
--preserve Country code
--labels Country
--label-length 10
--categ false true
--norm gauss none
--weights 1 0.5
--alpha 0.2 0.01 lin
--radius 6 0.8 lin
--decay 0.2 0.001 exp
--neigh gauss
--no-data -
--fps 1
--output ../example_data/_countries
--wait
3 changes: 2 additions & 1 deletion cmd_examples/iris.bat
Original file line number Diff line number Diff line change
Expand Up @@ -11,4 +11,5 @@
--radius 8 0.7 lin ^
--decay 0.2 0.001 exp ^
--neigh gauss ^
--output ..\example_data\_iris
--output ..\example_data\_iris ^
--wait
3 changes: 2 additions & 1 deletion cmd_examples/us-congress-votes.bat
Original file line number Diff line number Diff line change
Expand Up @@ -14,4 +14,5 @@
--neigh gauss ^
--no-data - ^
--fps 1 ^
--output ..\example_data\_us-congress-votes
--output ..\example_data\_us-congress-votes ^
--wait
3 changes: 2 additions & 1 deletion cmd_examples/winequality-red.bat
Original file line number Diff line number Diff line change
Expand Up @@ -13,4 +13,5 @@
--neigh gauss ^
--no-data - ^
--fps 1 ^
--output ..\example_data\_winequality-red
--output ..\example_data\_winequality-red ^
--wait
3 changes: 2 additions & 1 deletion cmd_examples/winequality-white.bat
Original file line number Diff line number Diff line change
Expand Up @@ -13,4 +13,5 @@
--neigh gauss ^
--no-data - ^
--fps 1 ^
--output ..\example_data\_winequality-white
--output ..\example_data\_winequality-white ^
--wait
5 changes: 5 additions & 0 deletions example_data/_countries-norm.csv
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
param;child_mort_2010;birth_p_1000;log_GNI;LifeExpectancy;PopGrowth;PopUrbanized;PopGrowthUrb;AdultLiteracy;PrimSchool;Income_low_40;Income_high_20;continent:AF;continent:AS;continent:EU;continent:MA;continent:NA;continent:OC;continent:SA
a_norm;0.010497384535940586;0.04664640119834835;0.7617458331554051;0.050738491994078906;0.4025927797455095;0.02202841192555459;0.27936954333706365;0.02613710043645987;0.044937319841335456;0.1166912636296901;0.0650040357561435;1;1;1;1;1;1;1
b_norm;0.03589896590547123;-0.5420287734364373;-2.240412693353556;-2.9989827840138976;-0.11708526628770033;-0.721230681139496;-0.15636322154024562;-1.6364318645492235;-3.5722927953512924;-1.4445933395471173;-2.588558418893565;0;0;0;0;0;0;0
a_denorm;95.26182417879751;21.437881043552142;1.3127738367240773;19.708902663419682;2.483899489285746;45.395918842425765;3.5794882579361365;38.259790998279705;22.253218561560786;8.569621828532219;15.383660235364548;1;1;1;1;1;1;1
b_denorm;-3.419800978287647;11.619948367112817;2.9411551672990717;59.10665977940128;0.29082803313490446;32.74092946767601;0.559700315476376;62.609541120578456;79.49501234084124;12.379618615935232;39.82150321565106;0;0;0;0;0;0;0
2 changes: 1 addition & 1 deletion examples/countries.rs
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ fn main() {
.with_fps_skip(1.0)
.build();

let mut view_x = LayerView::new(win_x, &[0], &proc.data().names_ref_vec(), None);
let mut view_x = LayerView::new(win_x, &[0], &proc.data().columns_ref_vec(), None);

while view_x.is_open() {
som.epoch(proc.data(), None);
Expand Down
4 changes: 2 additions & 2 deletions examples/iris.rs
Original file line number Diff line number Diff line change
Expand Up @@ -37,8 +37,8 @@ fn main() {
.with_fps_skip(5.0)
.build();

let mut view_x = LayerView::new(win_x, &[0], &proc.data().names_ref_vec(), None);
let mut view_y = LayerView::new(win_y, &[1], &proc.data().names_ref_vec(), None);
let mut view_x = LayerView::new(win_x, &[0], &proc.data().columns_ref_vec(), None);
let mut view_y = LayerView::new(win_y, &[1], &proc.data().columns_ref_vec(), None);

while view_x.is_open() || view_y.is_open() {
som.epoch(proc.data(), None);
Expand Down
9 changes: 5 additions & 4 deletions src/calc/metric.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,9 @@ pub trait Metric: Sync {
fn distance(&self, from: &[f64], to: &[f64]) -> f64;
}*/

use crate::{EnumFromString, ParseEnumError};
use crate::ParseEnumError;
use serde::{Deserialize, Serialize};
use std::str::FromStr;

#[derive(Debug, Clone, Serialize, Deserialize)]
pub enum Metric {
Expand Down Expand Up @@ -64,12 +65,12 @@ impl Metric {
}
}
}

impl EnumFromString for Metric {
impl FromStr for Metric {
type Err = ParseEnumError;
/// Parse a string to a `Metric`.
///
/// Accepts `"euclidean" | "tanimoto"`.
fn from_string(str: &str) -> Result<Metric, ParseEnumError> {
fn from_str(str: &str) -> Result<Self, Self::Err> {
match str {
"euclidean" => Ok(Metric::Euclidean),
"tanimoto" => Ok(Metric::Tanimoto),
Expand Down
32 changes: 28 additions & 4 deletions src/calc/neighborhood.rs
Original file line number Diff line number Diff line change
@@ -1,19 +1,22 @@
//! Neighborhoods (i.e. kernels), for effect on nearby SOM-units.

use crate::{EnumFromString, ParseEnumError};
use crate::ParseEnumError;
use serde::{Deserialize, Serialize};
use std::str::FromStr;

/// Neighborhoods: 4 or 8 neighbors.
#[derive(Debug, Clone)]
pub enum Neighbors {
Neighbors4,
Neighbors8,
}
impl EnumFromString for Neighbors {
impl FromStr for Neighbors {
type Err = ParseEnumError;

/// Parse a string to a `Neighbors`.
///
/// Accepts `"4" | "n4" | "N4" | "Neighbors4" | "8" | "n8" | "N8" | "Neighbors8"`.
fn from_string(str: &str) -> Result<Neighbors, ParseEnumError> {
fn from_str(str: &str) -> Result<Neighbors, ParseEnumError> {
match str {
"4" | "n4" | "N4" | "Neighbors4" => Ok(Neighbors::Neighbors4),
"8" | "n8" | "N8" | "Neighbors8" => Ok(Neighbors::Neighbors8),
Expand Down Expand Up @@ -83,6 +86,27 @@ impl Neighborhood {
}
}
}
impl FromStr for Neighborhood {
type Err = ParseEnumError;

/// Parse a string to a `Neighborhood`.
///
/// Accepts `gauss | triangular | epanechnikov | quartic | triweight`.
fn from_str(str: &str) -> Result<Self, Self::Err> {
match str {
"gauss" => Ok(Neighborhood::Gauss),
"triangular" => Ok(Neighborhood::Triangular),
"epanechnikov" => Ok(Neighborhood::Epanechnikov),
"quartic" => Ok(Neighborhood::Quartic),
"triweight" => Ok(Neighborhood::Triweight),
_ => Err(ParseEnumError(format!(
"Not a neighborhood: {}. Must be one of (gauss|<todo>)",
str
))),
}
}
}
/*
impl EnumFromString for Neighborhood {
/// Parse a string to a `Neighborhood`.
///
Expand All @@ -100,7 +124,7 @@ impl EnumFromString for Neighborhood {
))),
}
}
}
}*/

#[cfg(test)]
mod test {
Expand Down
Loading

0 comments on commit 51fe8cd

Please sign in to comment.