grydra 0.2.0 → 1.0.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/README.md +119 -0
- data/lib/gr/core.rb +1275 -1595
- data/lib/gr/version.rb +1 -1
- metadata +22 -18
checksums.yaml
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
---
|
|
2
2
|
SHA256:
|
|
3
|
-
metadata.gz:
|
|
4
|
-
data.tar.gz:
|
|
3
|
+
metadata.gz: 3ef9ae208812a8c439fb3c1dfdf80e9c2346892588cea921dc046ca4f2726285
|
|
4
|
+
data.tar.gz: 55e68e1aac6d9d10012ac43a3dec300fd9b1b9200f0643e5fc6ecf70335451bc
|
|
5
5
|
SHA512:
|
|
6
|
-
metadata.gz:
|
|
7
|
-
data.tar.gz:
|
|
6
|
+
metadata.gz: 9da256676de6a73003e8b124060f3a2d8606f529fe5db7c201b63c599e2df15f61d066db826f5f5c6c3a67a45954c0bbaa2234c725c06e4a8856f6852bc81e98
|
|
7
|
+
data.tar.gz: 4bbba9fdf9cebae95ecc6d389ccbb9247a353d018c44b0b89a407032356cb9f23c87616ffcbbff72c69da495a487d41e81e9d346555a7e37980616d56ead6197
|
data/README.md
ADDED
|
@@ -0,0 +1,119 @@
|
|
|
1
|
+
# GRYDRA
|
|
2
|
+
|
|
3
|
+
GRYDRA is a Ruby gem designed for building, training, and utilizing neural networks. It provides a flexible framework for creating multi-subnet architectures, implementing various activation functions, optimization techniques, and preprocessing tools, suitable for numerical, categorical (hash), and text-based data tasks.
|
|
4
|
+
|
|
5
|
+
## Features
|
|
6
|
+
|
|
7
|
+
* **Neural Network Architectures:** Build standard feedforward networks, multi-subnet ensembles (`MainNetwork`), and simplified interfaces (`EasyNetwork`).
|
|
8
|
+
* **Multiple Activation Functions:** Includes Tanh, Sigmoid, ReLU, Leaky ReLU, Swish, GELU, and more.
|
|
9
|
+
* **Advanced Optimizers:** Supports the Adam optimizer for efficient training.
|
|
10
|
+
* **Regularization Techniques:** Includes L1, L2 regularization, and Dropout.
|
|
11
|
+
* **Data Preprocessing:** Offers Min-Max and Z-Score normalization. Includes utilities for handling categorical (hash) and text data (vocabulary creation, vectorization, TF-IDF).
|
|
12
|
+
* **Training Features:** Supports mini-batch training, early stopping, learning rate decay, and customizable parameters.
|
|
13
|
+
* **Evaluation Metrics:** Provides MSE, MAE, Accuracy, Precision, Recall, F1-Score, Confusion Matrix, and AUC-ROC.
|
|
14
|
+
* **Cross-Validation:** Includes k-fold cross-validation for robust model evaluation.
|
|
15
|
+
* **Model Persistence:** Save and load trained models and vocabularies using Ruby's `Marshal`.
|
|
16
|
+
* **Analysis Tools:** Gradient analysis and ASCII visualization of network architecture.
|
|
17
|
+
* **Hyperparameter Search:** Basic grid search functionality.
|
|
18
|
+
|
|
19
|
+
## Installation
|
|
20
|
+
|
|
21
|
+
1. Ensure you have Ruby installed.
|
|
22
|
+
2. Save the provided code as a `.rb` file (e.g., `grydra.rb`) or create a Ruby gem.
|
|
23
|
+
3. Require the file or gem in your project: `require 'grydra'` (or the path to your file).
|
|
24
|
+
|
|
25
|
+
## Usage
|
|
26
|
+
|
|
27
|
+
### Basic Example: Training with Numerical Data
|
|
28
|
+
|
|
29
|
+
```ruby
|
|
30
|
+
require 'grydra'
|
|
31
|
+
|
|
32
|
+
# Example data: [height (cm), age (years)] -> [weight (kg)]
|
|
33
|
+
data_input = [[170, 25], [160, 30], [180, 22]]
|
|
34
|
+
data_output = [[65], [60], [75]]
|
|
35
|
+
|
|
36
|
+
# Define subnet structures (hidden layers)
|
|
37
|
+
structures = [[4, 1], [3, 1]]
|
|
38
|
+
|
|
39
|
+
# Create the network using the easy interface
|
|
40
|
+
network = GRYDRA::EasyNetwork.new(print_epochs = true)
|
|
41
|
+
|
|
42
|
+
# Train the network
|
|
43
|
+
network.train_numerical(
|
|
44
|
+
data_input,
|
|
45
|
+
data_output,
|
|
46
|
+
structures,
|
|
47
|
+
learning_rate = 0.05,
|
|
48
|
+
epochs = 15000,
|
|
49
|
+
normalization = :max # Options: :max, :zscore
|
|
50
|
+
)
|
|
51
|
+
|
|
52
|
+
# Make a prediction for a new individual
|
|
53
|
+
new_data = [[172, 26]]
|
|
54
|
+
predictions = network.predict_numerical(new_data, :max) # Use same normalization
|
|
55
|
+
|
|
56
|
+
puts "Predicted weight: #{predictions[0][0].round(2)} kg"
|
|
57
|
+
```
|
|
58
|
+
|
|
59
|
+
### Basic Example: Training with Hash Data
|
|
60
|
+
|
|
61
|
+
```ruby
|
|
62
|
+
require 'grydra'
|
|
63
|
+
|
|
64
|
+
# Example data: Categorical inputs mapped to a numerical label
|
|
65
|
+
data_hash = [
|
|
66
|
+
{ height: 170, is_new: false, label: 0 },
|
|
67
|
+
{ height: 160, is_new: true, label: 1 },
|
|
68
|
+
{ height: 180, is_new: false, label: 0 },
|
|
69
|
+
]
|
|
70
|
+
|
|
71
|
+
input_keys = [:height, :is_new]
|
|
72
|
+
label_key = :label
|
|
73
|
+
structures = [[3, 1]]
|
|
74
|
+
|
|
75
|
+
network = GRYDRA::EasyNetwork.new(print_epochs = true)
|
|
76
|
+
|
|
77
|
+
network.train_hashes(
|
|
78
|
+
data_hash,
|
|
79
|
+
input_keys,
|
|
80
|
+
label_key,
|
|
81
|
+
structures,
|
|
82
|
+
learning_rate = 0.05,
|
|
83
|
+
epochs = 10000,
|
|
84
|
+
normalization = :max
|
|
85
|
+
)
|
|
86
|
+
|
|
87
|
+
# Predict for new data
|
|
88
|
+
new_hashes = [{ height: 175, is_new: true }]
|
|
89
|
+
predictions = network.predict_hashes(new_hashes, input_keys, :max)
|
|
90
|
+
|
|
91
|
+
puts "Prediction: #{predictions[0][0].round(3)}"
|
|
92
|
+
```
|
|
93
|
+
|
|
94
|
+
### Key Classes
|
|
95
|
+
|
|
96
|
+
* `GRYDRA::EasyNetwork`: A high-level interface for easier training and prediction on numerical, hash, and text data.
|
|
97
|
+
* `GRYDRA::MainNetwork`: A class for managing and training multiple sub-networks.
|
|
98
|
+
* `GRYDRA::NeuralNetwork`: Represents a single neural network (used internally by `MainNetwork`).
|
|
99
|
+
* `GRYDRA::Neuron`: Represents a single neuron within a layer.
|
|
100
|
+
* `GRYDRA::DenseLayer`: A standard fully connected layer.
|
|
101
|
+
* `GRYDRA::AdamOptimizer`: An implementation of the Adam optimizer.
|
|
102
|
+
|
|
103
|
+
### Helper Functions
|
|
104
|
+
|
|
105
|
+
* `GRYDRA.save_model(model, name, path, vocabulary)`: Saves a trained model.
|
|
106
|
+
* `GRYDRA.load_model(name, path)`: Loads a saved model.
|
|
107
|
+
* `GRYDRA.save_vocabulary(vocabulary, name, path)`: Saves a vocabulary.
|
|
108
|
+
* `GRYDRA.load_vocabulary(name, path)`: Loads a vocabulary.
|
|
109
|
+
* `GRYDRA.describe_method(class_name, method_name)`: Provides information and examples for specific methods.
|
|
110
|
+
* `GRYDRA.list_methods_available()`: Lists all documented public methods.
|
|
111
|
+
* `GRYDRA.generate_example(num, filename, ext, path)`: Generates example scripts demonstrating usage.
|
|
112
|
+
|
|
113
|
+
## Examples
|
|
114
|
+
|
|
115
|
+
The `GRYDRA.generate_example` method can create various example scripts (numbered 1-12) showcasing different features like advanced training, text processing, classification metrics, and cross-validation. Run `GRYDRA.generate_example(1)` to start.
|
|
116
|
+
|
|
117
|
+
## License
|
|
118
|
+
|
|
119
|
+
[Show licence](LICENCE)
|