diff --git a/README.md b/README.md index 809819a..abd8571 100644 --- a/README.md +++ b/README.md @@ -57,6 +57,8 @@ Project or files: │   └── unixsocket ├── __log │   └── log4rs +├── __machinelearning +│   └── rusty-machine ├── __misc │   ├── better_panic │   ├── fancy-regex @@ -145,7 +147,7 @@ Project or files: ├── vec.rs └── while.rs -117 directories, 26 files +119 directories, 26 files ``` diff --git a/__machinelearning/rusty-machine/Cargo.lock b/__machinelearning/rusty-machine/Cargo.lock new file mode 100644 index 0000000..ea20b3a --- /dev/null +++ b/__machinelearning/rusty-machine/Cargo.lock @@ -0,0 +1,172 @@ +# This file is automatically @generated by Cargo. +# It is not intended for manual editing. +[[package]] +name = "autocfg" +version = "1.0.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "cdb031dd78e28731d87d56cc8ffef4a8f36ca26c38fe2de700543e627f8a464a" + +[[package]] +name = "fuchsia-cprng" +version = "0.1.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "a06f77d526c1a601b7c4cdd98f54b5eaabffc14d5f2f0296febdc7f357c6d3ba" + +[[package]] +name = "libc" +version = "0.2.80" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "4d58d1b70b004888f764dfbf6a26a3b0342a1632d33968e4a179d8011c760614" + +[[package]] +name = "matrixmultiply" +version = "0.1.15" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "dcad67dcec2d58ff56f6292582377e6921afdf3bfbd533e26fb8900ae575e002" +dependencies = [ + "rawpointer", +] + +[[package]] +name = "num" +version = "0.1.42" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "4703ad64153382334aa8db57c637364c322d3372e097840c72000dabdcf6156e" +dependencies = [ + "num-integer", + "num-iter", + "num-traits", +] + +[[package]] +name = "num-integer" +version = "0.1.44" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "d2cc698a63b549a70bc047073d2949cce27cd1c7b0a4a862d08a8031bc2801db" +dependencies = [ + "autocfg", + "num-traits", +] + +[[package]] +name = "num-iter" +version = "0.1.42" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "b2021c8337a54d21aca0d59a92577a029af9431cb59b909b03252b9c164fad59" +dependencies = [ + "autocfg", + "num-integer", + "num-traits", +] + +[[package]] +name = "num-traits" +version = "0.2.14" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "9a64b1ec5cda2586e284722486d802acf1f7dbdc623e2bfc57e65ca1cd099290" +dependencies = [ + "autocfg", +] + +[[package]] +name = "rand" +version = "0.3.23" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "64ac302d8f83c0c1974bf758f6b041c6c8ada916fbb44a609158ca8b064cc76c" +dependencies = [ + "libc", + "rand 0.4.6", +] + +[[package]] +name = "rand" +version = "0.4.6" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "552840b97013b1a26992c11eac34bdd778e464601a4c2054b5f0bff7c6761293" +dependencies = [ + "fuchsia-cprng", + "libc", + "rand_core 0.3.1", + "rdrand", + "winapi", +] + +[[package]] +name = "rand_core" +version = "0.3.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "7a6fdeb83b075e8266dcc8762c22776f6877a63111121f5f8c7411e5be7eed4b" +dependencies = [ + "rand_core 0.4.2", +] + +[[package]] +name = "rand_core" +version = "0.4.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "9c33a3c44ca05fa6f1807d8e6743f3824e8509beca625669633be0acbdf509dc" + +[[package]] +name = "rawpointer" +version = "0.1.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "ebac11a9d2e11f2af219b8b8d833b76b1ea0e054aa0e8d8e9e4cbde353bdf019" + +[[package]] +name = "rdrand" +version = "0.4.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "678054eb77286b51581ba43620cc911abf02758c91f93f479767aed0f90458b2" +dependencies = [ + "rand_core 0.3.1", +] + +[[package]] +name = "rulinalg" +version = "0.3.7" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "5670ce3717deb2d4436bdb29f07c549b56595f1fd8af1ca4682f1c1b1ac57f86" +dependencies = [ + "matrixmultiply", + "num", +] + +[[package]] +name = "rusty-machine" +version = "0.1.0" +dependencies = [ + "rusty-machine 0.5.4", +] + +[[package]] +name = "rusty-machine" +version = "0.5.4" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "dee5358236bbd0835aeee9a8b04c8b9b0aaea243a1a1a71253957b4606fb9171" +dependencies = [ + "num", + "rand 0.3.23", + "rulinalg", +] + +[[package]] +name = "winapi" +version = "0.3.9" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "5c839a674fcd7a98952e593242ea400abe93992746761e38641405d28b00f419" +dependencies = [ + "winapi-i686-pc-windows-gnu", + "winapi-x86_64-pc-windows-gnu", +] + +[[package]] +name = "winapi-i686-pc-windows-gnu" +version = "0.4.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "ac3b87c63620426dd9b991e5ce0329eff545bccbbb34f3be09ff6fb6ab51b7b6" + +[[package]] +name = "winapi-x86_64-pc-windows-gnu" +version = "0.4.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "712e227841d057c1ee1cd2fb22fa7e5a5461ae8e48fa2ca79ec42cfc1931183f" diff --git a/__machinelearning/rusty-machine/Cargo.toml b/__machinelearning/rusty-machine/Cargo.toml new file mode 100644 index 0000000..c7029bc --- /dev/null +++ b/__machinelearning/rusty-machine/Cargo.toml @@ -0,0 +1,11 @@ +[package] +name = "rusty-machine" +version = "0.1.0" +authors = ["Hatter Jiang "] +edition = "2018" + +# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html + +[dependencies] +rusty-machine = "0.5.4" + diff --git a/__machinelearning/rusty-machine/README.md b/__machinelearning/rusty-machine/README.md new file mode 100644 index 0000000..0773ba9 --- /dev/null +++ b/__machinelearning/rusty-machine/README.md @@ -0,0 +1,5 @@ + + +Rusty-Machine 机器学习库 +https://mp.weixin.qq.com/s/fWNMnp846Yqy4AGENB1JWw + diff --git a/__machinelearning/rusty-machine/src/main.rs b/__machinelearning/rusty-machine/src/main.rs new file mode 100644 index 0000000..84743b2 --- /dev/null +++ b/__machinelearning/rusty-machine/src/main.rs @@ -0,0 +1,37 @@ +use rusty_machine::linalg::{Matrix, Vector}; +use rusty_machine::learning::gp::{GaussianProcess, ConstMean}; +use rusty_machine::learning::toolkit::kernel::SquaredExp; +use rusty_machine::learning::SupModel; + +fn main() { + // 首先获取一些数据。 + + // 一些示例训练数据。 + let inputs = Matrix::new(3,3,vec![1.,1.,1.,2.,2.,2.,3.,3.,3.]); + let targets = Vector::new(vec![0.,1.,0.]); + + // 一些示例测试数据。 + let test_inputs = Matrix::new(2,3, vec![1.5,1.5,1.5,2.5,2.5,2.5]); + + // 现在设置好我们的模组 + // 这几乎是rusty-machine 中最复杂的模组了! + + // 设置平方指数核函数,长度参数 2,宽度参数 1。 + let ker = SquaredExp::new(2., 1.); + + // 零函数 + let zero_mean = ConstMean::default(); + + // 用核函数,平均值, 噪声0.5来构建一个高斯过程。 + let mut gp = GaussianProcess::new(ker, zero_mean, 0.5); + + // 现在我们可以训练并且用这个模组进行预测了。 + + // 训练模组! + gp.train(&inputs, &targets).unwrap(); + + // 使用测试数据来测试预测。 + let outputs = gp.predict(&test_inputs).unwrap(); + + println!("{:?}", outputs); +} \ No newline at end of file