Upload folder using huggingface_hub
Browse files- README.md +75 -0
- config.json +38 -0
- model.onnx +3 -0
- model.onnx.data +0 -0
- pytorch_model.bin +3 -0
- weights.json +64 -0
README.md
ADDED
|
@@ -0,0 +1,75 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
---
|
| 2 |
+
license: mit
|
| 3 |
+
tags:
|
| 4 |
+
- regression
|
| 5 |
+
- pytorch
|
| 6 |
+
- function-approximation
|
| 7 |
+
- single-hidden-layer
|
| 8 |
+
---
|
| 9 |
+
|
| 10 |
+
# ANN Approximation of y = x² — random_600_hidden6_mae_sigmoid
|
| 11 |
+
|
| 12 |
+
A single-hidden-layer feedforward neural network trained to approximate
|
| 13 |
+
**y = x²** on the interval **[-1, 1]**.
|
| 14 |
+
|
| 15 |
+
## Model Details
|
| 16 |
+
|
| 17 |
+
- **Architecture**: `Linear(1 → 6) → Sigmoid → Linear(6 → 1)`
|
| 18 |
+
- **Hidden units**: 6
|
| 19 |
+
- **Activation function**: sigmoid
|
| 20 |
+
- **Loss function used in training**: mae
|
| 21 |
+
- **Training dataset**: random sampling, 600 points, 80/20 train/val split
|
| 22 |
+
- **Optimizer**: Adam, lr=0.01, full-batch gradient descent
|
| 23 |
+
|
| 24 |
+
## Performance (validation set)
|
| 25 |
+
|
| 26 |
+
| Metric | Value |
|
| 27 |
+
|---|---|
|
| 28 |
+
| MSE | 0.000006 |
|
| 29 |
+
| RMSE | 0.002442 |
|
| 30 |
+
| MAE | 0.001800 |
|
| 31 |
+
| MAPE | 49.7565% |
|
| 32 |
+
| R² | 0.9999 |
|
| 33 |
+
|
| 34 |
+
This model was selected as the best-performing configuration out of a
|
| 35 |
+
1350-run grid search sweeping dataset (10 variants), hidden-layer width
|
| 36 |
+
(2–10), loss function (MSE/MAE/Huber), and activation function
|
| 37 |
+
(ReLU/Tanh/Sigmoid/Leaky ReLU/ELU).
|
| 38 |
+
|
| 39 |
+
## Usage
|
| 40 |
+
|
| 41 |
+
```python
|
| 42 |
+
import torch
|
| 43 |
+
import torch.nn as nn
|
| 44 |
+
|
| 45 |
+
class SingleHiddenLayerANN(nn.Module):
|
| 46 |
+
def __init__(self, hidden_units=6, activation="sigmoid"):
|
| 47 |
+
super().__init__()
|
| 48 |
+
self.hidden = nn.Linear(1, hidden_units)
|
| 49 |
+
self.output = nn.Linear(hidden_units, 1)
|
| 50 |
+
activations = {"relu": nn.ReLU(), "tanh": nn.Tanh(), "sigmoid": nn.Sigmoid(),
|
| 51 |
+
"leaky_relu": nn.LeakyReLU(0.01), "elu": nn.ELU()}
|
| 52 |
+
self.activation = activations[activation]
|
| 53 |
+
|
| 54 |
+
def forward(self, x):
|
| 55 |
+
return self.output(self.activation(self.hidden(x)))
|
| 56 |
+
|
| 57 |
+
model = SingleHiddenLayerANN()
|
| 58 |
+
model.load_state_dict(torch.load("pytorch_model.bin", map_location="cpu"))
|
| 59 |
+
model.eval()
|
| 60 |
+
|
| 61 |
+
x = torch.tensor([[0.5]])
|
| 62 |
+
y_pred = model(x)
|
| 63 |
+
print(y_pred) # should be close to 0.25 (0.5^2)
|
| 64 |
+
```
|
| 65 |
+
|
| 66 |
+
## Visualizing this model
|
| 67 |
+
|
| 68 |
+
The `model.onnx` file in this repo can be opened directly at
|
| 69 |
+
[netron.app](https://netron.app) (drag-and-drop, no install) to see the
|
| 70 |
+
network graph, layer shapes, and weights interactively.
|
| 71 |
+
|
| 72 |
+
## Source
|
| 73 |
+
|
| 74 |
+
Full training pipeline, all 1350 experiment results, and analysis tools:
|
| 75 |
+
see the linked GitHub repository.
|
config.json
ADDED
|
@@ -0,0 +1,38 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
{
|
| 2 |
+
"run_id": "random_600_hidden6_mae_sigmoid",
|
| 3 |
+
"sampling": "random",
|
| 4 |
+
"n_samples": 600,
|
| 5 |
+
"hidden_units": 6,
|
| 6 |
+
"loss": "mae",
|
| 7 |
+
"activation": "sigmoid",
|
| 8 |
+
"master_seed": 42,
|
| 9 |
+
"hyperparams": {
|
| 10 |
+
"optimizer": "adam",
|
| 11 |
+
"learning_rate": 0.01,
|
| 12 |
+
"epochs": 2000,
|
| 13 |
+
"batch_size": "full",
|
| 14 |
+
"checkpoint_every": 200,
|
| 15 |
+
"activation": "sigmoid"
|
| 16 |
+
},
|
| 17 |
+
"device": "cuda",
|
| 18 |
+
"resumed_from_checkpoint": false,
|
| 19 |
+
"training_seconds": 5.401285171508789,
|
| 20 |
+
"completed_at": "2026-07-21T19:35:45Z",
|
| 21 |
+
"software_versions": {
|
| 22 |
+
"python": "3.11.15",
|
| 23 |
+
"platform": "Windows-10-10.0.26200-SP0",
|
| 24 |
+
"torch": "2.11.0+cu128",
|
| 25 |
+
"numpy": "2.4.6",
|
| 26 |
+
"cuda_available": "True",
|
| 27 |
+
"cuda_version": "12.8",
|
| 28 |
+
"gpu_name": "NVIDIA GeForce RTX 4050 Laptop GPU"
|
| 29 |
+
},
|
| 30 |
+
"model_summary": "SingleHiddenLayerANN(hidden_units=6, activation=sigmoid)\n Linear(1 -> 6)\n Sigmoid()\n Linear(6 -> 1)\n Total trainable parameters: 19",
|
| 31 |
+
"metrics": {
|
| 32 |
+
"mse": 5.962054646594423e-06,
|
| 33 |
+
"rmse": 0.0024417318949046,
|
| 34 |
+
"mae": 0.0017995336077233,
|
| 35 |
+
"mape": 49.756466100269705,
|
| 36 |
+
"r2": 0.99993212811375
|
| 37 |
+
}
|
| 38 |
+
}
|
model.onnx
ADDED
|
@@ -0,0 +1,3 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
version https://git-lfs.github.com/spec/v1
|
| 2 |
+
oid sha256:fd4080b284b4e49bc2fdf1365a18422de871675f15e3fcdee1e9056e7c5c5203
|
| 3 |
+
size 4479
|
model.onnx.data
ADDED
|
File without changes
|
pytorch_model.bin
ADDED
|
@@ -0,0 +1,3 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
version https://git-lfs.github.com/spec/v1
|
| 2 |
+
oid sha256:6c7c55fd01e773c331d9b1eef6b7563bf252fcf48f8e92967f4a9d9a32935c16
|
| 3 |
+
size 2585
|
weights.json
ADDED
|
@@ -0,0 +1,64 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
{
|
| 2 |
+
"architecture": {
|
| 3 |
+
"hidden_units": 6,
|
| 4 |
+
"activation": "sigmoid",
|
| 5 |
+
"layers": [
|
| 6 |
+
"Linear(1 -> h)",
|
| 7 |
+
"sigmoid()",
|
| 8 |
+
"Linear(h -> 1)"
|
| 9 |
+
]
|
| 10 |
+
},
|
| 11 |
+
"hidden_layer": {
|
| 12 |
+
"weight": [
|
| 13 |
+
[
|
| 14 |
+
2.7088844776153564
|
| 15 |
+
],
|
| 16 |
+
[
|
| 17 |
+
2.8541743755340576
|
| 18 |
+
],
|
| 19 |
+
[
|
| 20 |
+
0.0023373549338430166
|
| 21 |
+
],
|
| 22 |
+
[
|
| 23 |
+
1.5461868047714233
|
| 24 |
+
],
|
| 25 |
+
[
|
| 26 |
+
0.0023936263751238585
|
| 27 |
+
],
|
| 28 |
+
[
|
| 29 |
+
-2.2972044944763184
|
| 30 |
+
]
|
| 31 |
+
],
|
| 32 |
+
"bias": [
|
| 33 |
+
-2.926323890686035,
|
| 34 |
+
3.071049690246582,
|
| 35 |
+
0.8033617734909058,
|
| 36 |
+
-0.7763761878013611,
|
| 37 |
+
0.7987249493598938,
|
| 38 |
+
-2.333636999130249
|
| 39 |
+
]
|
| 40 |
+
},
|
| 41 |
+
"output_layer": {
|
| 42 |
+
"weight": [
|
| 43 |
+
[
|
| 44 |
+
2.6142003536224365,
|
| 45 |
+
-1.274052619934082,
|
| 46 |
+
0.48730725049972534,
|
| 47 |
+
0.3808853030204773,
|
| 48 |
+
0.6062461137771606,
|
| 49 |
+
1.6951392889022827
|
| 50 |
+
]
|
| 51 |
+
],
|
| 52 |
+
"bias": [
|
| 53 |
+
0.062105655670166016
|
| 54 |
+
]
|
| 55 |
+
},
|
| 56 |
+
"run_id": "random_600_hidden6_mae_sigmoid",
|
| 57 |
+
"metrics": {
|
| 58 |
+
"mse": 5.962054646594423e-06,
|
| 59 |
+
"rmse": 0.0024417318949046,
|
| 60 |
+
"mae": 0.0017995336077233,
|
| 61 |
+
"mape": 49.756466100269705,
|
| 62 |
+
"r2": 0.99993212811375
|
| 63 |
+
}
|
| 64 |
+
}
|