{"id":13438315,"url":"https://github.com/avinashshenoy97/RusticSOM","last_synced_at":"2025-03-19T18:32:41.825Z","repository":{"id":57665694,"uuid":"123767744","full_name":"avinashshenoy97/RusticSOM","owner":"avinashshenoy97","description":"Rust library for Self Organising Maps (SOM).","archived":false,"fork":false,"pushed_at":"2022-10-15T10:49:14.000Z","size":77,"stargazers_count":34,"open_issues_count":2,"forks_count":6,"subscribers_count":4,"default_branch":"master","last_synced_at":"2025-03-01T23:12:05.627Z","etag":null,"topics":["crates","machine-learning","ml","rust","rust-library","self-organizing-map","som"],"latest_commit_sha":null,"homepage":null,"language":"Rust","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/avinashshenoy97.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null}},"created_at":"2018-03-04T07:44:42.000Z","updated_at":"2024-12-14T04:22:32.000Z","dependencies_parsed_at":"2022-09-14T13:01:43.210Z","dependency_job_id":null,"html_url":"https://github.com/avinashshenoy97/RusticSOM","commit_stats":null,"previous_names":[],"tags_count":0,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/avinashshenoy97%2FRusticSOM","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/avinashshenoy97%2FRusticSOM/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/avinashshenoy97%2FRusticSOM/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/avinashshenoy97%2FRusticSOM/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/avinashshenoy97","download_url":"https://codeload.github.com/avinashshenoy97/RusticSOM/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":244483667,"owners_count":20460162,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["crates","machine-learning","ml","rust","rust-library","self-organizing-map","som"],"created_at":"2024-07-31T03:01:04.481Z","updated_at":"2025-03-19T18:32:41.539Z","avatar_url":"https://github.com/avinashshenoy97.png","language":"Rust","funding_links":[],"categories":["Libraries","库","库 Libraries","Rust","人工智能（Artificial Intelligence）","Clustering"],"sub_categories":["Artificial Intelligence","Machine learning","人工智能","人工智能 Artificial Intelligence","General-Purpose Machine Learning","机器学习（Machine Learning）"],"readme":"# RusticSOM\nRust library for Self Organising Maps (SOM).\n\n![Status](https://img.shields.io/badge/status-active-brightgreen.svg?style=flat)\n[![Open Source Love](https://badges.frapsoft.com/os/v1/open-source.svg?v=103)]()\n[![License](https://img.shields.io/badge/license-mit-brightgreen.svg?style=flat)](https://github.com/aditisrinivas97/rusticsom/blob/master/LICENSE)\n[![](http://meritbadge.herokuapp.com/rusticsom)](https://crates.io/crates/rusticsom)\n[![Build Status](https://travis-ci.org/avinashshenoy97/RusticSOM.svg?branch=master)](https://travis-ci.org/avinashshenoy97/RusticSOM)\n\n## Using this Crate\n\nAdd `rusticsom` as a dependency in `Cargo.toml`\n\n```toml\n[dependencies]\nrusticsom = \"1.1.0\"\n```\n\nInclude the crate \n\n```rust\nuse rusticsom::SOM;\n```\n\n## API\n\nUse `SOM::create` to create an SOM object using the API call below, which creates an SOM with `length x breadth` cells and accepts neurons of length `inputs`.\n\n```rust\npub fn create(length: usize, breadth: usize, inputs: usize, randomize: bool, learning_rate: Option\u003cf32\u003e, sigma: Option\u003cf32\u003e, decay_function: Option\u003cfn(f32, u32, u32) -\u003e f64\u003e, neighbourhood_function: Option\u003cfn((usize, usize), (usize, usize), f32) -\u003e Array2\u003cf64\u003e\u003e) -\u003e SOM { ... }\n```\n\n`randomize` is a flag, which, if true, initializes the weights of each cell to random, small, floating-point values.\n\n`learning_rate`, optional, is the learning_rate of the SOM; by default it will be `0.5`.\n\n`sigma`, optional, is the spread of the neighbourhood function; by default it will be `1.0`.\n\n`decay_function`, optional, is a function pointer that accepts functions that take 3 parameters of types `f32, u32, u32`, and returns an `f64`. This function is used to \"decay\" both the `learning_rate` and `sigma`. By default it is\n\n    new_value = old_value / (1 + current_iteration/total_iterations)\n\n`neighbourhood_function`, optional, is also a function pointer that accepts functions that take 3 parameters, a tuple of type `(usize, usize)` representing the size of the SOM, another tuple of type `(usize, usize)` representing the position of the winner neuron, and an `f32` representing `sigma`; and returns a 2D Array containing weights of the neighbours of the winning neuron, i.e, centered at `winner`. By default, the Gaussian function will be used, which returns a \"Gaussian centered at the winner neuron\".\n\n---\n\n```rust\n    pub fn from_json(serialized: \u0026str,  decay_function: Option\u003cfn(f32, u32, u32) -\u003e f64\u003e, neighbourhood_function: Option\u003cfn((usize, usize), (usize, usize), f32) -\u003e Array2\u003cf64\u003e\u003e) -\u003e serde_json::Result\u003cSOM\u003e { ... }\n```\n\nThis function allows to create a SOM from a previously exported SOM json data using SOM::to_json().\n\n---\n\nUse `SOM_Object.train_random()` to train the SOM with the input dataset, where samples from the input dataset are picked in a random order.\n\n```rust\npub fn train_random(\u0026mut self, data: Array2\u003cf64\u003e, iterations: u32) { ... }\n```\n\nSamples (rows) from the 2D Array `data` are picked randomly and the SOM is trained for `iterations` iterations!\n\n---\n\nUse `SOM_Object.train_batch()` to train the SOM with the input dataset, where samples from the input dataset are picked in a sequential order.\n\n```rust\npub fn train_batch(\u0026mut self, data: Array2\u003cf64\u003e, iterations: u32) { ... }\n```\n\nSamples (rows) from the 2D Array `data` are picked sequentially and the SOM is trained for `iterations` iterations!\n\n---\n\nUse `SOM_Object.winner()` to find the winning neuron for a given sample.\n\n```rust\npub fn winner(\u0026mut self, elem: Array1\u003cf64\u003e) -\u003e (usize, usize) { ... }\n```\n\nThis function must be called **with** an SOM object. \n\nRequires one parameter, a 1D Array of `f64`s representing the input sample. \n\nReturns a tuple `(usize, usize)` representing the x and y coordinates of the winning neuron in the SOM.\n\n---\n\nUse `SOM_Object.winner_dist()` to find the winning neuron for a given sample, and it's distance from this winner neuron.\n\n```rust\npub fn winner_dist(\u0026mut self, elem: Array1\u003cf64\u003e) -\u003e ((usize, usize), f64) { ... }\n```\n\nThis function must be called **with** an SOM object. \n\nRequires one parameter, a 1D Array of `f64`s representing the input sample. \n\nReturns a tuple `(usize, usize)` representing the x and y coordinates of the winning neuron in the SOM.\n\nAlso returns an `f64` representing the distance of the input sample from this winner neuron.\n\n---\n\n```rust\npub fn activation_response(\u0026self) -\u003e ArrayView2\u003cusize\u003e { ... }\n```\n\nThis function returns the activation map of the SOM. The activation map is a 2D Array where each cell at `(i, j)` represents the number of times the `(i, j)` cell of the SOM was picked to be the winner neuron.\n\n---\n\n```rust\npub fn get_size(\u0026self) -\u003e (usize, usize)\n```\n\nThis function returns a tuple representing the size of the SOM. Format is `(length, breadth)`.\n\n---\n\n```rust\npub fn distance_map(self) -\u003e Array2\u003cf64\u003e { ... }\n```\n\nReturns the distance map of the SOM, i.e, the normalized distance of every neuron with every other neuron.\n\n---\n\n```rust\npub fn to_json(\u0026self) -\u003e serde_json::Result\u003cString\u003e { ... }\n```\n\nReturns the internal SOM data as pretty printed json (using serde_json).\n\n---\n## Primary Contributors\n\n|   |   |\n|:-:|:-:|\n| \u003cimg src=\"https://github.com/aditisrinivas97.png\" width=\"75\"\u003e | [Aditi Srinivas](https://github.com/aditisrinivas97) |\n| \u003cimg src=\"https://github.com/avinashshenoy97.png\" width=\"75\"\u003e | [Avinash Shenoy](https://github.com/avinashshenoy97) |\n\n---\n\n---\n\n## Example\n\nWe've tested this crate on the famous iris dataset (present in csv format in the `extras` folder).\n\nThe `t_full_test` function in `/tests/test.rs` was used to produce the required output. The following plots were obtained using matplotlib for Python.\n\nUsing a 5 x 5 SOM, trained for 250 iterations :\n\n![SOM1](https://github.com/avinashshenoy97/RusticSOM/blob/master/extras/5x5_250iter_random.png)\n\n---\n\nUsing a 10 x 10 SOM, trained for 1000 iterations :\n\n![SOM2](https://github.com/avinashshenoy97/RusticSOM/blob/master/extras/10x10_1000iter_random.png)\n\n\n| Symbol | Represents |\n|:-:|:-:|\n|Circle|setosa|\n|Square|versicolor|\n|Diamond|virginica|\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Favinashshenoy97%2FRusticSOM","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Favinashshenoy97%2FRusticSOM","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Favinashshenoy97%2FRusticSOM/lists"}