From 8fbecdfba937e2a6b070093b12200a113e8fa316 Mon Sep 17 00:00:00 2001 From: HowToSD Date: Fri, 14 Mar 2025 03:15:16 -0700 Subject: [PATCH] Added iris classification example workflow as well as data type conversion nodes. --- __init__.py | 27 ++++ docs/model_training.md | 8 + docs/reference/node_reference.md | 12 ++ docs/reference/pt_predict_regression_model.md | 5 + docs/reference/pt_to_bfloat16.md | 17 ++ docs/reference/pt_to_float16.md | 17 ++ docs/reference/pt_to_float32.md | 17 ++ docs/reference/pt_to_float64.md | 17 ++ docs/reference/pt_to_int16.md | 17 ++ docs/reference/pt_to_int32.md | 17 ++ docs/reference/pt_to_int64.md | 17 ++ docs/reference/pt_to_int8.md | 17 ++ docs/reference/pt_to_uint8.md | 17 ++ examples/datasets/iris/Index | 5 + examples/datasets/iris/bezdekIris.data | 151 +++++++++++++++++ .../datasets/iris/bezdekIris_with_header.data | 152 ++++++++++++++++++ examples/datasets/iris/iris.data | 151 +++++++++++++++++ examples/datasets/iris/iris.names | 69 ++++++++ examples/datasets/iris/iris_train.csv | 121 ++++++++++++++ examples/datasets/iris/iris_val.csv | 31 ++++ examples/datasets/iris/readme.md | 18 +++ examples/datasets/iris/train_val_split.py | 45 ++++++ .../iris_classification_train_eval.json | 1 + modules/pytorch_wrapper/pt_to_bfloat16.py | 39 +++++ modules/pytorch_wrapper/pt_to_float16.py | 39 +++++ modules/pytorch_wrapper/pt_to_float32.py | 39 +++++ modules/pytorch_wrapper/pt_to_float64.py | 39 +++++ modules/pytorch_wrapper/pt_to_int16.py | 39 +++++ modules/pytorch_wrapper/pt_to_int32.py | 39 +++++ modules/pytorch_wrapper/pt_to_int64.py | 39 +++++ modules/pytorch_wrapper/pt_to_int8.py | 39 +++++ modules/pytorch_wrapper/pt_to_uint8.py | 39 +++++ pyproject.toml | 2 +- tests/pytorch_wrapper/pt_to_bfloat16_test.py | 41 +++++ tests/pytorch_wrapper/pt_to_float16_test.py | 41 +++++ tests/pytorch_wrapper/pt_to_float32_test.py | 41 +++++ tests/pytorch_wrapper/pt_to_float64_test.py | 41 +++++ tests/pytorch_wrapper/pt_to_int16_test.py | 41 +++++ tests/pytorch_wrapper/pt_to_int32_test.py | 41 +++++ tests/pytorch_wrapper/pt_to_int64_test.py | 41 +++++ tests/pytorch_wrapper/pt_to_int8_test.py | 41 +++++ tests/pytorch_wrapper/pt_to_uint8.py | 41 +++++ 42 files changed, 1670 insertions(+), 1 deletion(-) create mode 100644 docs/reference/pt_to_bfloat16.md create mode 100644 docs/reference/pt_to_float16.md create mode 100644 docs/reference/pt_to_float32.md create mode 100644 docs/reference/pt_to_float64.md create mode 100644 docs/reference/pt_to_int16.md create mode 100644 docs/reference/pt_to_int32.md create mode 100644 docs/reference/pt_to_int64.md create mode 100644 docs/reference/pt_to_int8.md create mode 100644 docs/reference/pt_to_uint8.md create mode 100755 examples/datasets/iris/Index create mode 100755 examples/datasets/iris/bezdekIris.data create mode 100755 examples/datasets/iris/bezdekIris_with_header.data create mode 100755 examples/datasets/iris/iris.data create mode 100755 examples/datasets/iris/iris.names create mode 100644 examples/datasets/iris/iris_train.csv create mode 100644 examples/datasets/iris/iris_val.csv create mode 100644 examples/datasets/iris/readme.md create mode 100644 examples/datasets/iris/train_val_split.py create mode 100644 examples/workflows/iris_classification_train_eval.json create mode 100644 modules/pytorch_wrapper/pt_to_bfloat16.py create mode 100644 modules/pytorch_wrapper/pt_to_float16.py create mode 100644 modules/pytorch_wrapper/pt_to_float32.py create mode 100644 modules/pytorch_wrapper/pt_to_float64.py create mode 100644 modules/pytorch_wrapper/pt_to_int16.py create mode 100644 modules/pytorch_wrapper/pt_to_int32.py create mode 100644 modules/pytorch_wrapper/pt_to_int64.py create mode 100644 modules/pytorch_wrapper/pt_to_int8.py create mode 100644 modules/pytorch_wrapper/pt_to_uint8.py create mode 100644 tests/pytorch_wrapper/pt_to_bfloat16_test.py create mode 100644 tests/pytorch_wrapper/pt_to_float16_test.py create mode 100644 tests/pytorch_wrapper/pt_to_float32_test.py create mode 100644 tests/pytorch_wrapper/pt_to_float64_test.py create mode 100644 tests/pytorch_wrapper/pt_to_int16_test.py create mode 100644 tests/pytorch_wrapper/pt_to_int32_test.py create mode 100644 tests/pytorch_wrapper/pt_to_int64_test.py create mode 100644 tests/pytorch_wrapper/pt_to_int8_test.py create mode 100644 tests/pytorch_wrapper/pt_to_uint8.py diff --git a/__init__.py b/__init__.py index 8958226..5bbc107 100644 --- a/__init__.py +++ b/__init__.py @@ -89,11 +89,20 @@ from .modules.pytorch_wrapper.pt_sub import PtSub from .modules.pytorch_wrapper.pt_sum import PtSum from .modules.pytorch_wrapper.pt_tan import PtTan from .modules.pytorch_wrapper.pt_tanh import PtTanh +from .modules.pytorch_wrapper.pt_to_bfloat16 import PtToBfloat16 +from .modules.pytorch_wrapper.pt_to_float16 import PtToFloat16 +from .modules.pytorch_wrapper.pt_to_float32 import PtToFloat32 +from .modules.pytorch_wrapper.pt_to_float64 import PtToFloat64 from .modules.pytorch_wrapper.pt_to_image import PtToImage from .modules.pytorch_wrapper.pt_to_image_transpose import PtToImageTranspose +from .modules.pytorch_wrapper.pt_to_int16 import PtToInt16 +from .modules.pytorch_wrapper.pt_to_int32 import PtToInt32 +from .modules.pytorch_wrapper.pt_to_int64 import PtToInt64 +from .modules.pytorch_wrapper.pt_to_int8 import PtToInt8 from .modules.pytorch_wrapper.pt_to_latent import PtToLatent from .modules.pytorch_wrapper.pt_to_numpy import PtToNumpy from .modules.pytorch_wrapper.pt_to_rgb_tensors import PtToRgbTensors +from .modules.pytorch_wrapper.pt_to_uint8 import PtToUint8 from .modules.pytorch_wrapper.pt_train_classification_model import PtTrainClassificationModel from .modules.pytorch_wrapper.pt_train_classification_model_lr import PtTrainClassificationModelLr from .modules.pytorch_wrapper.pt_train_regression_model import PtTrainRegressionModel @@ -216,11 +225,20 @@ NODE_CLASS_MAPPINGS: Dict[str, Type[T]] = { "PtSum": PtSum, "PtTan": PtTan, "PtTanh": PtTanh, + "PtToBfloat16": PtToBfloat16, + "PtToFloat16": PtToFloat16, + "PtToFloat32": PtToFloat32, + "PtToFloat64": PtToFloat64, "PtToImage": PtToImage, "PtToImageTranspose": PtToImageTranspose, + "PtToInt16": PtToInt16, + "PtToInt32": PtToInt32, + "PtToInt64": PtToInt64, + "PtToInt8": PtToInt8, "PtToLatent": PtToLatent, "PtToNumpy": PtToNumpy, "PtToRgbTensors": PtToRgbTensors, + "PtToUint8": PtToUint8, "PtTrainClassificationModel": PtTrainClassificationModel, "PtTrainClassificationModelLr": PtTrainClassificationModelLr, "PtTrainRegressionModel": PtTrainRegressionModel, @@ -343,11 +361,20 @@ NODE_DISPLAY_NAME_MAPPINGS: Dict[str, str] = { "PtSum": "Pt Sum", "PtTan": "Pt Tan", "PtTanh": "Pt Tanh", + "PtToBfloat16": "Pt To Bfloat16", + "PtToFloat16": "Pt To Float16", + "PtToFloat32": "Pt To Float32", + "PtToFloat64": "Pt To Float64", "PtToImage": "Pt To Image", "PtToImageTranspose": "Pt To Image Transpose", + "PtToInt16": "Pt To Int16", + "PtToInt32": "Pt To Int32", + "PtToInt64": "Pt To Int64", + "PtToInt8": "Pt To Int8", "PtToLatent": "Pt To Latent", "PtToNumpy": "Pt To Numpy", "PtToRgbTensors": "Pt To Rgb Tensors", + "PtToUint8": "Pt To Uint8", "PtTrainClassificationModel": "Pt Train Classification Model", "PtTrainClassificationModelLr": "Pt Train Classification Model Lr", "PtTrainRegressionModel": "Pt Train Regression Model", diff --git a/docs/model_training.md b/docs/model_training.md index 82b9e10..c31ef37 100644 --- a/docs/model_training.md +++ b/docs/model_training.md @@ -88,3 +88,11 @@ This workflow illustrates: If you run training, you will notice that the loss remains in the 20s–30s instead of approaching 0, as you might expect. Do you know why this happens? + +# Using MLP for Small Dataset Classification + +MLP can be used for small dataset classification. +Below is an example workflow for classifying the classic Iris dataset: +`examples/workflows/iris_classification_train_eval.json`. + +According to [the UCI repository](https://archive.ics.uci.edu/dataset/53/iris), the neural network baseline accuracy for this dataset ranges from 92.105% to 100%. Using this workflow, you can expect around 96% accuracy, occasionally reaching 100%, which aligns with the baseline. diff --git a/docs/reference/node_reference.md b/docs/reference/node_reference.md index 040818c..d5ad1d2 100644 --- a/docs/reference/node_reference.md +++ b/docs/reference/node_reference.md @@ -36,6 +36,18 @@ | [Pt Le](pt_le.md) | Tests whether elements in the first PyTorch tensor are less than or equal to the corresponding elements in the second tensor. | | [Pt Lt](pt_lt.md) | Tests whether elements in the first PyTorch tensor are less than the corresponding elements in the second tensor. | | [Pt Ne](pt_ne.md) | Tests whether two PyTorch tensors are not equal element-wise. | +## PyTorch wrapper - Data type conversion +| Node | Description | +| --- | --- | +| [Pt To Bfloat](pt_to_bfloat16.md) | Converts the input tensor's data type to bfloat16. | +| [Pt To Float](pt_to_float16.md) | Converts the input tensor's data type to float16. | +| [Pt To Float](pt_to_float32.md) | Converts the input tensor's data type to float32. | +| [Pt To Float](pt_to_float64.md) | Converts the input tensor's data type to float64. | +| [Pt To Int](pt_to_int16.md) | Converts the input tensor's data type to int16. | +| [Pt To Int](pt_to_int32.md) | Converts the input tensor's data type to int32. | +| [Pt To Int](pt_to_int64.md) | Converts the input tensor's data type to int64. | +| [Pt To Int](pt_to_int8.md) | Converts the input tensor's data type to int8. | +| [Pt To Uint](pt_to_uint8.md) | Converts the input tensor's data type to uint8. | ## PyTorch wrapper - Image processing | Node | Description | | --- | --- | diff --git a/docs/reference/pt_predict_regression_model.md b/docs/reference/pt_predict_regression_model.md index 1cb4e86..837c0cb 100644 --- a/docs/reference/pt_predict_regression_model.md +++ b/docs/reference/pt_predict_regression_model.md @@ -8,6 +8,11 @@ Performs inference on input data. | inputs | Tensor | | use_gpu | Boolean | +## Output +| Data type | +|---| +| Tensor | +
Category: PyTorch wrapper - Training diff --git a/docs/reference/pt_to_bfloat16.md b/docs/reference/pt_to_bfloat16.md new file mode 100644 index 0000000..d1d6413 --- /dev/null +++ b/docs/reference/pt_to_bfloat16.md @@ -0,0 +1,17 @@ +# Pt To Bfloat +Converts the input tensor's data type to bfloat16. + +## Input +| Name | Data type | +|---|---| +| tens_a | Tensor | + +## Output +| Data type | +|---| +| Tensor | + +
+Category: PyTorch wrapper - Data type conversion + +ComfyUI Data Analysis Node Reference. © 2025 Hide Inada (HowToSD.com). All rights reserved. diff --git a/docs/reference/pt_to_float16.md b/docs/reference/pt_to_float16.md new file mode 100644 index 0000000..315da17 --- /dev/null +++ b/docs/reference/pt_to_float16.md @@ -0,0 +1,17 @@ +# Pt To Float +Converts the input tensor's data type to float16. + +## Input +| Name | Data type | +|---|---| +| tens_a | Tensor | + +## Output +| Data type | +|---| +| Tensor | + +
+Category: PyTorch wrapper - Data type conversion + +ComfyUI Data Analysis Node Reference. © 2025 Hide Inada (HowToSD.com). All rights reserved. diff --git a/docs/reference/pt_to_float32.md b/docs/reference/pt_to_float32.md new file mode 100644 index 0000000..775bd63 --- /dev/null +++ b/docs/reference/pt_to_float32.md @@ -0,0 +1,17 @@ +# Pt To Float +Converts the input tensor's data type to float32. + +## Input +| Name | Data type | +|---|---| +| tens_a | Tensor | + +## Output +| Data type | +|---| +| Tensor | + +
+Category: PyTorch wrapper - Data type conversion + +ComfyUI Data Analysis Node Reference. © 2025 Hide Inada (HowToSD.com). All rights reserved. diff --git a/docs/reference/pt_to_float64.md b/docs/reference/pt_to_float64.md new file mode 100644 index 0000000..bb15e56 --- /dev/null +++ b/docs/reference/pt_to_float64.md @@ -0,0 +1,17 @@ +# Pt To Float +Converts the input tensor's data type to float64. + +## Input +| Name | Data type | +|---|---| +| tens_a | Tensor | + +## Output +| Data type | +|---| +| Tensor | + +
+Category: PyTorch wrapper - Data type conversion + +ComfyUI Data Analysis Node Reference. © 2025 Hide Inada (HowToSD.com). All rights reserved. diff --git a/docs/reference/pt_to_int16.md b/docs/reference/pt_to_int16.md new file mode 100644 index 0000000..b0a4b3e --- /dev/null +++ b/docs/reference/pt_to_int16.md @@ -0,0 +1,17 @@ +# Pt To Int +Converts the input tensor's data type to int16. + +## Input +| Name | Data type | +|---|---| +| tens_a | Tensor | + +## Output +| Data type | +|---| +| Tensor | + +
+Category: PyTorch wrapper - Data type conversion + +ComfyUI Data Analysis Node Reference. © 2025 Hide Inada (HowToSD.com). All rights reserved. diff --git a/docs/reference/pt_to_int32.md b/docs/reference/pt_to_int32.md new file mode 100644 index 0000000..8c9321e --- /dev/null +++ b/docs/reference/pt_to_int32.md @@ -0,0 +1,17 @@ +# Pt To Int +Converts the input tensor's data type to int32. + +## Input +| Name | Data type | +|---|---| +| tens_a | Tensor | + +## Output +| Data type | +|---| +| Tensor | + +
+Category: PyTorch wrapper - Data type conversion + +ComfyUI Data Analysis Node Reference. © 2025 Hide Inada (HowToSD.com). All rights reserved. diff --git a/docs/reference/pt_to_int64.md b/docs/reference/pt_to_int64.md new file mode 100644 index 0000000..f72a206 --- /dev/null +++ b/docs/reference/pt_to_int64.md @@ -0,0 +1,17 @@ +# Pt To Int +Converts the input tensor's data type to int64. + +## Input +| Name | Data type | +|---|---| +| tens_a | Tensor | + +## Output +| Data type | +|---| +| Tensor | + +
+Category: PyTorch wrapper - Data type conversion + +ComfyUI Data Analysis Node Reference. © 2025 Hide Inada (HowToSD.com). All rights reserved. diff --git a/docs/reference/pt_to_int8.md b/docs/reference/pt_to_int8.md new file mode 100644 index 0000000..b8c490a --- /dev/null +++ b/docs/reference/pt_to_int8.md @@ -0,0 +1,17 @@ +# Pt To Int +Converts the input tensor's data type to int8. + +## Input +| Name | Data type | +|---|---| +| tens_a | Tensor | + +## Output +| Data type | +|---| +| Tensor | + +
+Category: PyTorch wrapper - Data type conversion + +ComfyUI Data Analysis Node Reference. © 2025 Hide Inada (HowToSD.com). All rights reserved. diff --git a/docs/reference/pt_to_uint8.md b/docs/reference/pt_to_uint8.md new file mode 100644 index 0000000..c5a74f3 --- /dev/null +++ b/docs/reference/pt_to_uint8.md @@ -0,0 +1,17 @@ +# Pt To Uint +Converts the input tensor's data type to uint8. + +## Input +| Name | Data type | +|---|---| +| tens_a | Tensor | + +## Output +| Data type | +|---| +| Tensor | + +
+Category: PyTorch wrapper - Data type conversion + +ComfyUI Data Analysis Node Reference. © 2025 Hide Inada (HowToSD.com). All rights reserved. diff --git a/examples/datasets/iris/Index b/examples/datasets/iris/Index new file mode 100755 index 0000000..8c246ed --- /dev/null +++ b/examples/datasets/iris/Index @@ -0,0 +1,5 @@ +Index of iris + +02 Dec 1996 105 Index +08 Mar 1993 4551 iris.data +30 May 1989 2604 iris.names diff --git a/examples/datasets/iris/bezdekIris.data b/examples/datasets/iris/bezdekIris.data new file mode 100755 index 0000000..d4ee8db --- /dev/null +++ b/examples/datasets/iris/bezdekIris.data @@ -0,0 +1,151 @@ +5.1,3.5,1.4,0.2,Iris-setosa +4.9,3.0,1.4,0.2,Iris-setosa +4.7,3.2,1.3,0.2,Iris-setosa +4.6,3.1,1.5,0.2,Iris-setosa +5.0,3.6,1.4,0.2,Iris-setosa +5.4,3.9,1.7,0.4,Iris-setosa +4.6,3.4,1.4,0.3,Iris-setosa +5.0,3.4,1.5,0.2,Iris-setosa +4.4,2.9,1.4,0.2,Iris-setosa +4.9,3.1,1.5,0.1,Iris-setosa +5.4,3.7,1.5,0.2,Iris-setosa +4.8,3.4,1.6,0.2,Iris-setosa +4.8,3.0,1.4,0.1,Iris-setosa +4.3,3.0,1.1,0.1,Iris-setosa +5.8,4.0,1.2,0.2,Iris-setosa +5.7,4.4,1.5,0.4,Iris-setosa +5.4,3.9,1.3,0.4,Iris-setosa +5.1,3.5,1.4,0.3,Iris-setosa +5.7,3.8,1.7,0.3,Iris-setosa +5.1,3.8,1.5,0.3,Iris-setosa +5.4,3.4,1.7,0.2,Iris-setosa +5.1,3.7,1.5,0.4,Iris-setosa +4.6,3.6,1.0,0.2,Iris-setosa +5.1,3.3,1.7,0.5,Iris-setosa +4.8,3.4,1.9,0.2,Iris-setosa +5.0,3.0,1.6,0.2,Iris-setosa +5.0,3.4,1.6,0.4,Iris-setosa +5.2,3.5,1.5,0.2,Iris-setosa +5.2,3.4,1.4,0.2,Iris-setosa +4.7,3.2,1.6,0.2,Iris-setosa +4.8,3.1,1.6,0.2,Iris-setosa +5.4,3.4,1.5,0.4,Iris-setosa +5.2,4.1,1.5,0.1,Iris-setosa +5.5,4.2,1.4,0.2,Iris-setosa +4.9,3.1,1.5,0.2,Iris-setosa +5.0,3.2,1.2,0.2,Iris-setosa +5.5,3.5,1.3,0.2,Iris-setosa +4.9,3.6,1.4,0.1,Iris-setosa +4.4,3.0,1.3,0.2,Iris-setosa +5.1,3.4,1.5,0.2,Iris-setosa +5.0,3.5,1.3,0.3,Iris-setosa +4.5,2.3,1.3,0.3,Iris-setosa +4.4,3.2,1.3,0.2,Iris-setosa +5.0,3.5,1.6,0.6,Iris-setosa +5.1,3.8,1.9,0.4,Iris-setosa +4.8,3.0,1.4,0.3,Iris-setosa +5.1,3.8,1.6,0.2,Iris-setosa +4.6,3.2,1.4,0.2,Iris-setosa +5.3,3.7,1.5,0.2,Iris-setosa +5.0,3.3,1.4,0.2,Iris-setosa +7.0,3.2,4.7,1.4,Iris-versicolor +6.4,3.2,4.5,1.5,Iris-versicolor +6.9,3.1,4.9,1.5,Iris-versicolor +5.5,2.3,4.0,1.3,Iris-versicolor +6.5,2.8,4.6,1.5,Iris-versicolor +5.7,2.8,4.5,1.3,Iris-versicolor +6.3,3.3,4.7,1.6,Iris-versicolor +4.9,2.4,3.3,1.0,Iris-versicolor +6.6,2.9,4.6,1.3,Iris-versicolor +5.2,2.7,3.9,1.4,Iris-versicolor +5.0,2.0,3.5,1.0,Iris-versicolor +5.9,3.0,4.2,1.5,Iris-versicolor +6.0,2.2,4.0,1.0,Iris-versicolor +6.1,2.9,4.7,1.4,Iris-versicolor +5.6,2.9,3.6,1.3,Iris-versicolor +6.7,3.1,4.4,1.4,Iris-versicolor +5.6,3.0,4.5,1.5,Iris-versicolor +5.8,2.7,4.1,1.0,Iris-versicolor +6.2,2.2,4.5,1.5,Iris-versicolor +5.6,2.5,3.9,1.1,Iris-versicolor +5.9,3.2,4.8,1.8,Iris-versicolor +6.1,2.8,4.0,1.3,Iris-versicolor +6.3,2.5,4.9,1.5,Iris-versicolor +6.1,2.8,4.7,1.2,Iris-versicolor +6.4,2.9,4.3,1.3,Iris-versicolor +6.6,3.0,4.4,1.4,Iris-versicolor +6.8,2.8,4.8,1.4,Iris-versicolor +6.7,3.0,5.0,1.7,Iris-versicolor +6.0,2.9,4.5,1.5,Iris-versicolor +5.7,2.6,3.5,1.0,Iris-versicolor +5.5,2.4,3.8,1.1,Iris-versicolor +5.5,2.4,3.7,1.0,Iris-versicolor +5.8,2.7,3.9,1.2,Iris-versicolor +6.0,2.7,5.1,1.6,Iris-versicolor +5.4,3.0,4.5,1.5,Iris-versicolor +6.0,3.4,4.5,1.6,Iris-versicolor +6.7,3.1,4.7,1.5,Iris-versicolor +6.3,2.3,4.4,1.3,Iris-versicolor +5.6,3.0,4.1,1.3,Iris-versicolor +5.5,2.5,4.0,1.3,Iris-versicolor +5.5,2.6,4.4,1.2,Iris-versicolor +6.1,3.0,4.6,1.4,Iris-versicolor +5.8,2.6,4.0,1.2,Iris-versicolor +5.0,2.3,3.3,1.0,Iris-versicolor +5.6,2.7,4.2,1.3,Iris-versicolor +5.7,3.0,4.2,1.2,Iris-versicolor +5.7,2.9,4.2,1.3,Iris-versicolor +6.2,2.9,4.3,1.3,Iris-versicolor +5.1,2.5,3.0,1.1,Iris-versicolor +5.7,2.8,4.1,1.3,Iris-versicolor +6.3,3.3,6.0,2.5,Iris-virginica +5.8,2.7,5.1,1.9,Iris-virginica +7.1,3.0,5.9,2.1,Iris-virginica +6.3,2.9,5.6,1.8,Iris-virginica +6.5,3.0,5.8,2.2,Iris-virginica +7.6,3.0,6.6,2.1,Iris-virginica +4.9,2.5,4.5,1.7,Iris-virginica +7.3,2.9,6.3,1.8,Iris-virginica +6.7,2.5,5.8,1.8,Iris-virginica +7.2,3.6,6.1,2.5,Iris-virginica +6.5,3.2,5.1,2.0,Iris-virginica +6.4,2.7,5.3,1.9,Iris-virginica +6.8,3.0,5.5,2.1,Iris-virginica +5.7,2.5,5.0,2.0,Iris-virginica +5.8,2.8,5.1,2.4,Iris-virginica +6.4,3.2,5.3,2.3,Iris-virginica +6.5,3.0,5.5,1.8,Iris-virginica +7.7,3.8,6.7,2.2,Iris-virginica +7.7,2.6,6.9,2.3,Iris-virginica +6.0,2.2,5.0,1.5,Iris-virginica +6.9,3.2,5.7,2.3,Iris-virginica +5.6,2.8,4.9,2.0,Iris-virginica +7.7,2.8,6.7,2.0,Iris-virginica +6.3,2.7,4.9,1.8,Iris-virginica +6.7,3.3,5.7,2.1,Iris-virginica +7.2,3.2,6.0,1.8,Iris-virginica +6.2,2.8,4.8,1.8,Iris-virginica +6.1,3.0,4.9,1.8,Iris-virginica +6.4,2.8,5.6,2.1,Iris-virginica +7.2,3.0,5.8,1.6,Iris-virginica +7.4,2.8,6.1,1.9,Iris-virginica +7.9,3.8,6.4,2.0,Iris-virginica +6.4,2.8,5.6,2.2,Iris-virginica +6.3,2.8,5.1,1.5,Iris-virginica +6.1,2.6,5.6,1.4,Iris-virginica +7.7,3.0,6.1,2.3,Iris-virginica +6.3,3.4,5.6,2.4,Iris-virginica +6.4,3.1,5.5,1.8,Iris-virginica +6.0,3.0,4.8,1.8,Iris-virginica +6.9,3.1,5.4,2.1,Iris-virginica +6.7,3.1,5.6,2.4,Iris-virginica +6.9,3.1,5.1,2.3,Iris-virginica +5.8,2.7,5.1,1.9,Iris-virginica +6.8,3.2,5.9,2.3,Iris-virginica +6.7,3.3,5.7,2.5,Iris-virginica +6.7,3.0,5.2,2.3,Iris-virginica +6.3,2.5,5.0,1.9,Iris-virginica +6.5,3.0,5.2,2.0,Iris-virginica +6.2,3.4,5.4,2.3,Iris-virginica +5.9,3.0,5.1,1.8,Iris-virginica + diff --git a/examples/datasets/iris/bezdekIris_with_header.data b/examples/datasets/iris/bezdekIris_with_header.data new file mode 100755 index 0000000..e3c1b5a --- /dev/null +++ b/examples/datasets/iris/bezdekIris_with_header.data @@ -0,0 +1,152 @@ +sepal length,sepal width,petal length,petal width,class +5.1,3.5,1.4,0.2,Iris-setosa +4.9,3.0,1.4,0.2,Iris-setosa +4.7,3.2,1.3,0.2,Iris-setosa +4.6,3.1,1.5,0.2,Iris-setosa +5.0,3.6,1.4,0.2,Iris-setosa +5.4,3.9,1.7,0.4,Iris-setosa +4.6,3.4,1.4,0.3,Iris-setosa +5.0,3.4,1.5,0.2,Iris-setosa +4.4,2.9,1.4,0.2,Iris-setosa +4.9,3.1,1.5,0.1,Iris-setosa +5.4,3.7,1.5,0.2,Iris-setosa +4.8,3.4,1.6,0.2,Iris-setosa +4.8,3.0,1.4,0.1,Iris-setosa +4.3,3.0,1.1,0.1,Iris-setosa +5.8,4.0,1.2,0.2,Iris-setosa +5.7,4.4,1.5,0.4,Iris-setosa +5.4,3.9,1.3,0.4,Iris-setosa +5.1,3.5,1.4,0.3,Iris-setosa +5.7,3.8,1.7,0.3,Iris-setosa +5.1,3.8,1.5,0.3,Iris-setosa +5.4,3.4,1.7,0.2,Iris-setosa +5.1,3.7,1.5,0.4,Iris-setosa +4.6,3.6,1.0,0.2,Iris-setosa +5.1,3.3,1.7,0.5,Iris-setosa +4.8,3.4,1.9,0.2,Iris-setosa +5.0,3.0,1.6,0.2,Iris-setosa +5.0,3.4,1.6,0.4,Iris-setosa +5.2,3.5,1.5,0.2,Iris-setosa +5.2,3.4,1.4,0.2,Iris-setosa +4.7,3.2,1.6,0.2,Iris-setosa +4.8,3.1,1.6,0.2,Iris-setosa +5.4,3.4,1.5,0.4,Iris-setosa +5.2,4.1,1.5,0.1,Iris-setosa +5.5,4.2,1.4,0.2,Iris-setosa +4.9,3.1,1.5,0.2,Iris-setosa +5.0,3.2,1.2,0.2,Iris-setosa +5.5,3.5,1.3,0.2,Iris-setosa +4.9,3.6,1.4,0.1,Iris-setosa +4.4,3.0,1.3,0.2,Iris-setosa +5.1,3.4,1.5,0.2,Iris-setosa +5.0,3.5,1.3,0.3,Iris-setosa +4.5,2.3,1.3,0.3,Iris-setosa +4.4,3.2,1.3,0.2,Iris-setosa +5.0,3.5,1.6,0.6,Iris-setosa +5.1,3.8,1.9,0.4,Iris-setosa +4.8,3.0,1.4,0.3,Iris-setosa +5.1,3.8,1.6,0.2,Iris-setosa +4.6,3.2,1.4,0.2,Iris-setosa +5.3,3.7,1.5,0.2,Iris-setosa +5.0,3.3,1.4,0.2,Iris-setosa +7.0,3.2,4.7,1.4,Iris-versicolor +6.4,3.2,4.5,1.5,Iris-versicolor +6.9,3.1,4.9,1.5,Iris-versicolor +5.5,2.3,4.0,1.3,Iris-versicolor +6.5,2.8,4.6,1.5,Iris-versicolor +5.7,2.8,4.5,1.3,Iris-versicolor +6.3,3.3,4.7,1.6,Iris-versicolor +4.9,2.4,3.3,1.0,Iris-versicolor +6.6,2.9,4.6,1.3,Iris-versicolor +5.2,2.7,3.9,1.4,Iris-versicolor +5.0,2.0,3.5,1.0,Iris-versicolor +5.9,3.0,4.2,1.5,Iris-versicolor +6.0,2.2,4.0,1.0,Iris-versicolor +6.1,2.9,4.7,1.4,Iris-versicolor +5.6,2.9,3.6,1.3,Iris-versicolor +6.7,3.1,4.4,1.4,Iris-versicolor +5.6,3.0,4.5,1.5,Iris-versicolor +5.8,2.7,4.1,1.0,Iris-versicolor +6.2,2.2,4.5,1.5,Iris-versicolor +5.6,2.5,3.9,1.1,Iris-versicolor +5.9,3.2,4.8,1.8,Iris-versicolor +6.1,2.8,4.0,1.3,Iris-versicolor +6.3,2.5,4.9,1.5,Iris-versicolor +6.1,2.8,4.7,1.2,Iris-versicolor +6.4,2.9,4.3,1.3,Iris-versicolor +6.6,3.0,4.4,1.4,Iris-versicolor +6.8,2.8,4.8,1.4,Iris-versicolor +6.7,3.0,5.0,1.7,Iris-versicolor +6.0,2.9,4.5,1.5,Iris-versicolor +5.7,2.6,3.5,1.0,Iris-versicolor +5.5,2.4,3.8,1.1,Iris-versicolor +5.5,2.4,3.7,1.0,Iris-versicolor +5.8,2.7,3.9,1.2,Iris-versicolor +6.0,2.7,5.1,1.6,Iris-versicolor +5.4,3.0,4.5,1.5,Iris-versicolor +6.0,3.4,4.5,1.6,Iris-versicolor +6.7,3.1,4.7,1.5,Iris-versicolor +6.3,2.3,4.4,1.3,Iris-versicolor +5.6,3.0,4.1,1.3,Iris-versicolor +5.5,2.5,4.0,1.3,Iris-versicolor +5.5,2.6,4.4,1.2,Iris-versicolor +6.1,3.0,4.6,1.4,Iris-versicolor +5.8,2.6,4.0,1.2,Iris-versicolor +5.0,2.3,3.3,1.0,Iris-versicolor +5.6,2.7,4.2,1.3,Iris-versicolor +5.7,3.0,4.2,1.2,Iris-versicolor +5.7,2.9,4.2,1.3,Iris-versicolor +6.2,2.9,4.3,1.3,Iris-versicolor +5.1,2.5,3.0,1.1,Iris-versicolor +5.7,2.8,4.1,1.3,Iris-versicolor +6.3,3.3,6.0,2.5,Iris-virginica +5.8,2.7,5.1,1.9,Iris-virginica +7.1,3.0,5.9,2.1,Iris-virginica +6.3,2.9,5.6,1.8,Iris-virginica +6.5,3.0,5.8,2.2,Iris-virginica +7.6,3.0,6.6,2.1,Iris-virginica +4.9,2.5,4.5,1.7,Iris-virginica +7.3,2.9,6.3,1.8,Iris-virginica +6.7,2.5,5.8,1.8,Iris-virginica +7.2,3.6,6.1,2.5,Iris-virginica +6.5,3.2,5.1,2.0,Iris-virginica +6.4,2.7,5.3,1.9,Iris-virginica +6.8,3.0,5.5,2.1,Iris-virginica +5.7,2.5,5.0,2.0,Iris-virginica +5.8,2.8,5.1,2.4,Iris-virginica +6.4,3.2,5.3,2.3,Iris-virginica +6.5,3.0,5.5,1.8,Iris-virginica +7.7,3.8,6.7,2.2,Iris-virginica +7.7,2.6,6.9,2.3,Iris-virginica +6.0,2.2,5.0,1.5,Iris-virginica +6.9,3.2,5.7,2.3,Iris-virginica +5.6,2.8,4.9,2.0,Iris-virginica +7.7,2.8,6.7,2.0,Iris-virginica +6.3,2.7,4.9,1.8,Iris-virginica +6.7,3.3,5.7,2.1,Iris-virginica +7.2,3.2,6.0,1.8,Iris-virginica +6.2,2.8,4.8,1.8,Iris-virginica +6.1,3.0,4.9,1.8,Iris-virginica +6.4,2.8,5.6,2.1,Iris-virginica +7.2,3.0,5.8,1.6,Iris-virginica +7.4,2.8,6.1,1.9,Iris-virginica +7.9,3.8,6.4,2.0,Iris-virginica +6.4,2.8,5.6,2.2,Iris-virginica +6.3,2.8,5.1,1.5,Iris-virginica +6.1,2.6,5.6,1.4,Iris-virginica +7.7,3.0,6.1,2.3,Iris-virginica +6.3,3.4,5.6,2.4,Iris-virginica +6.4,3.1,5.5,1.8,Iris-virginica +6.0,3.0,4.8,1.8,Iris-virginica +6.9,3.1,5.4,2.1,Iris-virginica +6.7,3.1,5.6,2.4,Iris-virginica +6.9,3.1,5.1,2.3,Iris-virginica +5.8,2.7,5.1,1.9,Iris-virginica +6.8,3.2,5.9,2.3,Iris-virginica +6.7,3.3,5.7,2.5,Iris-virginica +6.7,3.0,5.2,2.3,Iris-virginica +6.3,2.5,5.0,1.9,Iris-virginica +6.5,3.0,5.2,2.0,Iris-virginica +6.2,3.4,5.4,2.3,Iris-virginica +5.9,3.0,5.1,1.8,Iris-virginica + diff --git a/examples/datasets/iris/iris.data b/examples/datasets/iris/iris.data new file mode 100755 index 0000000..5c4316c --- /dev/null +++ b/examples/datasets/iris/iris.data @@ -0,0 +1,151 @@ +5.1,3.5,1.4,0.2,Iris-setosa +4.9,3.0,1.4,0.2,Iris-setosa +4.7,3.2,1.3,0.2,Iris-setosa +4.6,3.1,1.5,0.2,Iris-setosa +5.0,3.6,1.4,0.2,Iris-setosa +5.4,3.9,1.7,0.4,Iris-setosa +4.6,3.4,1.4,0.3,Iris-setosa +5.0,3.4,1.5,0.2,Iris-setosa +4.4,2.9,1.4,0.2,Iris-setosa +4.9,3.1,1.5,0.1,Iris-setosa +5.4,3.7,1.5,0.2,Iris-setosa +4.8,3.4,1.6,0.2,Iris-setosa +4.8,3.0,1.4,0.1,Iris-setosa +4.3,3.0,1.1,0.1,Iris-setosa +5.8,4.0,1.2,0.2,Iris-setosa +5.7,4.4,1.5,0.4,Iris-setosa +5.4,3.9,1.3,0.4,Iris-setosa +5.1,3.5,1.4,0.3,Iris-setosa +5.7,3.8,1.7,0.3,Iris-setosa +5.1,3.8,1.5,0.3,Iris-setosa +5.4,3.4,1.7,0.2,Iris-setosa +5.1,3.7,1.5,0.4,Iris-setosa +4.6,3.6,1.0,0.2,Iris-setosa +5.1,3.3,1.7,0.5,Iris-setosa +4.8,3.4,1.9,0.2,Iris-setosa +5.0,3.0,1.6,0.2,Iris-setosa +5.0,3.4,1.6,0.4,Iris-setosa +5.2,3.5,1.5,0.2,Iris-setosa +5.2,3.4,1.4,0.2,Iris-setosa +4.7,3.2,1.6,0.2,Iris-setosa +4.8,3.1,1.6,0.2,Iris-setosa +5.4,3.4,1.5,0.4,Iris-setosa +5.2,4.1,1.5,0.1,Iris-setosa +5.5,4.2,1.4,0.2,Iris-setosa +4.9,3.1,1.5,0.1,Iris-setosa +5.0,3.2,1.2,0.2,Iris-setosa +5.5,3.5,1.3,0.2,Iris-setosa +4.9,3.1,1.5,0.1,Iris-setosa +4.4,3.0,1.3,0.2,Iris-setosa +5.1,3.4,1.5,0.2,Iris-setosa +5.0,3.5,1.3,0.3,Iris-setosa +4.5,2.3,1.3,0.3,Iris-setosa +4.4,3.2,1.3,0.2,Iris-setosa +5.0,3.5,1.6,0.6,Iris-setosa +5.1,3.8,1.9,0.4,Iris-setosa +4.8,3.0,1.4,0.3,Iris-setosa +5.1,3.8,1.6,0.2,Iris-setosa +4.6,3.2,1.4,0.2,Iris-setosa +5.3,3.7,1.5,0.2,Iris-setosa +5.0,3.3,1.4,0.2,Iris-setosa +7.0,3.2,4.7,1.4,Iris-versicolor +6.4,3.2,4.5,1.5,Iris-versicolor +6.9,3.1,4.9,1.5,Iris-versicolor +5.5,2.3,4.0,1.3,Iris-versicolor +6.5,2.8,4.6,1.5,Iris-versicolor +5.7,2.8,4.5,1.3,Iris-versicolor +6.3,3.3,4.7,1.6,Iris-versicolor +4.9,2.4,3.3,1.0,Iris-versicolor +6.6,2.9,4.6,1.3,Iris-versicolor +5.2,2.7,3.9,1.4,Iris-versicolor +5.0,2.0,3.5,1.0,Iris-versicolor +5.9,3.0,4.2,1.5,Iris-versicolor +6.0,2.2,4.0,1.0,Iris-versicolor +6.1,2.9,4.7,1.4,Iris-versicolor +5.6,2.9,3.6,1.3,Iris-versicolor +6.7,3.1,4.4,1.4,Iris-versicolor +5.6,3.0,4.5,1.5,Iris-versicolor +5.8,2.7,4.1,1.0,Iris-versicolor +6.2,2.2,4.5,1.5,Iris-versicolor +5.6,2.5,3.9,1.1,Iris-versicolor +5.9,3.2,4.8,1.8,Iris-versicolor +6.1,2.8,4.0,1.3,Iris-versicolor +6.3,2.5,4.9,1.5,Iris-versicolor +6.1,2.8,4.7,1.2,Iris-versicolor +6.4,2.9,4.3,1.3,Iris-versicolor +6.6,3.0,4.4,1.4,Iris-versicolor +6.8,2.8,4.8,1.4,Iris-versicolor +6.7,3.0,5.0,1.7,Iris-versicolor +6.0,2.9,4.5,1.5,Iris-versicolor +5.7,2.6,3.5,1.0,Iris-versicolor +5.5,2.4,3.8,1.1,Iris-versicolor +5.5,2.4,3.7,1.0,Iris-versicolor +5.8,2.7,3.9,1.2,Iris-versicolor +6.0,2.7,5.1,1.6,Iris-versicolor +5.4,3.0,4.5,1.5,Iris-versicolor +6.0,3.4,4.5,1.6,Iris-versicolor +6.7,3.1,4.7,1.5,Iris-versicolor +6.3,2.3,4.4,1.3,Iris-versicolor +5.6,3.0,4.1,1.3,Iris-versicolor +5.5,2.5,4.0,1.3,Iris-versicolor +5.5,2.6,4.4,1.2,Iris-versicolor +6.1,3.0,4.6,1.4,Iris-versicolor +5.8,2.6,4.0,1.2,Iris-versicolor +5.0,2.3,3.3,1.0,Iris-versicolor +5.6,2.7,4.2,1.3,Iris-versicolor +5.7,3.0,4.2,1.2,Iris-versicolor +5.7,2.9,4.2,1.3,Iris-versicolor +6.2,2.9,4.3,1.3,Iris-versicolor +5.1,2.5,3.0,1.1,Iris-versicolor +5.7,2.8,4.1,1.3,Iris-versicolor +6.3,3.3,6.0,2.5,Iris-virginica +5.8,2.7,5.1,1.9,Iris-virginica +7.1,3.0,5.9,2.1,Iris-virginica +6.3,2.9,5.6,1.8,Iris-virginica +6.5,3.0,5.8,2.2,Iris-virginica +7.6,3.0,6.6,2.1,Iris-virginica +4.9,2.5,4.5,1.7,Iris-virginica +7.3,2.9,6.3,1.8,Iris-virginica +6.7,2.5,5.8,1.8,Iris-virginica +7.2,3.6,6.1,2.5,Iris-virginica +6.5,3.2,5.1,2.0,Iris-virginica +6.4,2.7,5.3,1.9,Iris-virginica +6.8,3.0,5.5,2.1,Iris-virginica +5.7,2.5,5.0,2.0,Iris-virginica +5.8,2.8,5.1,2.4,Iris-virginica +6.4,3.2,5.3,2.3,Iris-virginica +6.5,3.0,5.5,1.8,Iris-virginica +7.7,3.8,6.7,2.2,Iris-virginica +7.7,2.6,6.9,2.3,Iris-virginica +6.0,2.2,5.0,1.5,Iris-virginica +6.9,3.2,5.7,2.3,Iris-virginica +5.6,2.8,4.9,2.0,Iris-virginica +7.7,2.8,6.7,2.0,Iris-virginica +6.3,2.7,4.9,1.8,Iris-virginica +6.7,3.3,5.7,2.1,Iris-virginica +7.2,3.2,6.0,1.8,Iris-virginica +6.2,2.8,4.8,1.8,Iris-virginica +6.1,3.0,4.9,1.8,Iris-virginica +6.4,2.8,5.6,2.1,Iris-virginica +7.2,3.0,5.8,1.6,Iris-virginica +7.4,2.8,6.1,1.9,Iris-virginica +7.9,3.8,6.4,2.0,Iris-virginica +6.4,2.8,5.6,2.2,Iris-virginica +6.3,2.8,5.1,1.5,Iris-virginica +6.1,2.6,5.6,1.4,Iris-virginica +7.7,3.0,6.1,2.3,Iris-virginica +6.3,3.4,5.6,2.4,Iris-virginica +6.4,3.1,5.5,1.8,Iris-virginica +6.0,3.0,4.8,1.8,Iris-virginica +6.9,3.1,5.4,2.1,Iris-virginica +6.7,3.1,5.6,2.4,Iris-virginica +6.9,3.1,5.1,2.3,Iris-virginica +5.8,2.7,5.1,1.9,Iris-virginica +6.8,3.2,5.9,2.3,Iris-virginica +6.7,3.3,5.7,2.5,Iris-virginica +6.7,3.0,5.2,2.3,Iris-virginica +6.3,2.5,5.0,1.9,Iris-virginica +6.5,3.0,5.2,2.0,Iris-virginica +6.2,3.4,5.4,2.3,Iris-virginica +5.9,3.0,5.1,1.8,Iris-virginica + diff --git a/examples/datasets/iris/iris.names b/examples/datasets/iris/iris.names new file mode 100755 index 0000000..062b486 --- /dev/null +++ b/examples/datasets/iris/iris.names @@ -0,0 +1,69 @@ +1. Title: Iris Plants Database + Updated Sept 21 by C.Blake - Added discrepency information + +2. Sources: + (a) Creator: R.A. Fisher + (b) Donor: Michael Marshall (MARSHALL%PLU@io.arc.nasa.gov) + (c) Date: July, 1988 + +3. Past Usage: + - Publications: too many to mention!!! Here are a few. + 1. Fisher,R.A. "The use of multiple measurements in taxonomic problems" + Annual Eugenics, 7, Part II, 179-188 (1936); also in "Contributions + to Mathematical Statistics" (John Wiley, NY, 1950). + 2. Duda,R.O., & Hart,P.E. (1973) Pattern Classification and Scene Analysis. + (Q327.D83) John Wiley & Sons. ISBN 0-471-22361-1. See page 218. + 3. Dasarathy, B.V. (1980) "Nosing Around the Neighborhood: A New System + Structure and Classification Rule for Recognition in Partially Exposed + Environments". IEEE Transactions on Pattern Analysis and Machine + Intelligence, Vol. PAMI-2, No. 1, 67-71. + -- Results: + -- very low misclassification rates (0% for the setosa class) + 4. Gates, G.W. (1972) "The Reduced Nearest Neighbor Rule". IEEE + Transactions on Information Theory, May 1972, 431-433. + -- Results: + -- very low misclassification rates again + 5. See also: 1988 MLC Proceedings, 54-64. Cheeseman et al's AUTOCLASS II + conceptual clustering system finds 3 classes in the data. + +4. Relevant Information: + --- This is perhaps the best known database to be found in the pattern + recognition literature. Fisher's paper is a classic in the field + and is referenced frequently to this day. (See Duda & Hart, for + example.) The data set contains 3 classes of 50 instances each, + where each class refers to a type of iris plant. One class is + linearly separable from the other 2; the latter are NOT linearly + separable from each other. + --- Predicted attribute: class of iris plant. + --- This is an exceedingly simple domain. + --- This data differs from the data presented in Fishers article + (identified by Steve Chadwick, spchadwick@espeedaz.net ) + The 35th sample should be: 4.9,3.1,1.5,0.2,"Iris-setosa" + where the error is in the fourth feature. + The 38th sample: 4.9,3.6,1.4,0.1,"Iris-setosa" + where the errors are in the second and third features. + +5. Number of Instances: 150 (50 in each of three classes) + +6. Number of Attributes: 4 numeric, predictive attributes and the class + +7. Attribute Information: + 1. sepal length in cm + 2. sepal width in cm + 3. petal length in cm + 4. petal width in cm + 5. class: + -- Iris Setosa + -- Iris Versicolour + -- Iris Virginica + +8. Missing Attribute Values: None + +Summary Statistics: + Min Max Mean SD Class Correlation + sepal length: 4.3 7.9 5.84 0.83 0.7826 + sepal width: 2.0 4.4 3.05 0.43 -0.4194 + petal length: 1.0 6.9 3.76 1.76 0.9490 (high!) + petal width: 0.1 2.5 1.20 0.76 0.9565 (high!) + +9. Class Distribution: 33.3% for each of 3 classes. diff --git a/examples/datasets/iris/iris_train.csv b/examples/datasets/iris/iris_train.csv new file mode 100644 index 0000000..0c0610a --- /dev/null +++ b/examples/datasets/iris/iris_train.csv @@ -0,0 +1,121 @@ +,sepal length,sepal width,petal length,petal width,class +0,4.9,3.0,1.4,0.2,Iris-setosa +1,4.7,3.2,1.3,0.2,Iris-setosa +2,4.6,3.1,1.5,0.2,Iris-setosa +3,5.0,3.6,1.4,0.2,Iris-setosa +4,4.6,3.4,1.4,0.3,Iris-setosa +5,5.0,3.4,1.5,0.2,Iris-setosa +6,4.4,2.9,1.4,0.2,Iris-setosa +7,4.9,3.1,1.5,0.1,Iris-setosa +8,4.8,3.4,1.6,0.2,Iris-setosa +9,4.8,3.0,1.4,0.1,Iris-setosa +10,4.3,3.0,1.1,0.1,Iris-setosa +11,5.8,4.0,1.2,0.2,Iris-setosa +12,5.4,3.9,1.3,0.4,Iris-setosa +13,5.1,3.5,1.4,0.3,Iris-setosa +14,5.7,3.8,1.7,0.3,Iris-setosa +15,5.1,3.8,1.5,0.3,Iris-setosa +16,5.1,3.7,1.5,0.4,Iris-setosa +17,4.6,3.6,1.0,0.2,Iris-setosa +18,5.1,3.3,1.7,0.5,Iris-setosa +19,4.8,3.4,1.9,0.2,Iris-setosa +20,5.0,3.4,1.6,0.4,Iris-setosa +21,5.2,3.5,1.5,0.2,Iris-setosa +22,5.2,3.4,1.4,0.2,Iris-setosa +23,4.7,3.2,1.6,0.2,Iris-setosa +24,5.4,3.4,1.5,0.4,Iris-setosa +25,5.2,4.1,1.5,0.1,Iris-setosa +26,5.5,4.2,1.4,0.2,Iris-setosa +27,4.9,3.1,1.5,0.2,Iris-setosa +28,5.5,3.5,1.3,0.2,Iris-setosa +29,4.9,3.6,1.4,0.1,Iris-setosa +30,4.4,3.0,1.3,0.2,Iris-setosa +31,5.1,3.4,1.5,0.2,Iris-setosa +32,4.5,2.3,1.3,0.3,Iris-setosa +33,4.4,3.2,1.3,0.2,Iris-setosa +34,5.0,3.5,1.6,0.6,Iris-setosa +35,5.1,3.8,1.9,0.4,Iris-setosa +36,5.1,3.8,1.6,0.2,Iris-setosa +37,4.6,3.2,1.4,0.2,Iris-setosa +38,5.3,3.7,1.5,0.2,Iris-setosa +39,5.0,3.3,1.4,0.2,Iris-setosa +40,6.4,3.2,4.5,1.5,Iris-versicolor +41,6.9,3.1,4.9,1.5,Iris-versicolor +42,5.5,2.3,4.0,1.3,Iris-versicolor +43,6.5,2.8,4.6,1.5,Iris-versicolor +44,6.3,3.3,4.7,1.6,Iris-versicolor +45,4.9,2.4,3.3,1.0,Iris-versicolor +46,6.6,2.9,4.6,1.3,Iris-versicolor +47,5.2,2.7,3.9,1.4,Iris-versicolor +48,5.9,3.0,4.2,1.5,Iris-versicolor +49,6.0,2.2,4.0,1.0,Iris-versicolor +50,6.1,2.9,4.7,1.4,Iris-versicolor +51,5.6,2.9,3.6,1.3,Iris-versicolor +52,5.6,3.0,4.5,1.5,Iris-versicolor +53,5.8,2.7,4.1,1.0,Iris-versicolor +54,6.2,2.2,4.5,1.5,Iris-versicolor +55,5.6,2.5,3.9,1.1,Iris-versicolor +56,6.1,2.8,4.0,1.3,Iris-versicolor +57,6.3,2.5,4.9,1.5,Iris-versicolor +58,6.1,2.8,4.7,1.2,Iris-versicolor +59,6.4,2.9,4.3,1.3,Iris-versicolor +60,6.8,2.8,4.8,1.4,Iris-versicolor +61,6.7,3.0,5.0,1.7,Iris-versicolor +62,6.0,2.9,4.5,1.5,Iris-versicolor +63,5.7,2.6,3.5,1.0,Iris-versicolor +64,5.5,2.4,3.7,1.0,Iris-versicolor +65,5.8,2.7,3.9,1.2,Iris-versicolor +66,6.0,2.7,5.1,1.6,Iris-versicolor +67,5.4,3.0,4.5,1.5,Iris-versicolor +68,6.7,3.1,4.7,1.5,Iris-versicolor +69,6.3,2.3,4.4,1.3,Iris-versicolor +70,5.6,3.0,4.1,1.3,Iris-versicolor +71,5.5,2.5,4.0,1.3,Iris-versicolor +72,6.1,3.0,4.6,1.4,Iris-versicolor +73,5.8,2.6,4.0,1.2,Iris-versicolor +74,5.0,2.3,3.3,1.0,Iris-versicolor +75,5.6,2.7,4.2,1.3,Iris-versicolor +76,5.7,2.9,4.2,1.3,Iris-versicolor +77,6.2,2.9,4.3,1.3,Iris-versicolor +78,5.1,2.5,3.0,1.1,Iris-versicolor +79,5.7,2.8,4.1,1.3,Iris-versicolor +80,5.8,2.7,5.1,1.9,Iris-virginica +81,7.1,3.0,5.9,2.1,Iris-virginica +82,6.3,2.9,5.6,1.8,Iris-virginica +83,6.5,3.0,5.8,2.2,Iris-virginica +84,4.9,2.5,4.5,1.7,Iris-virginica +85,7.3,2.9,6.3,1.8,Iris-virginica +86,6.7,2.5,5.8,1.8,Iris-virginica +87,7.2,3.6,6.1,2.5,Iris-virginica +88,6.4,2.7,5.3,1.9,Iris-virginica +89,6.8,3.0,5.5,2.1,Iris-virginica +90,5.7,2.5,5.0,2.0,Iris-virginica +91,5.8,2.8,5.1,2.4,Iris-virginica +92,6.5,3.0,5.5,1.8,Iris-virginica +93,7.7,3.8,6.7,2.2,Iris-virginica +94,7.7,2.6,6.9,2.3,Iris-virginica +95,6.0,2.2,5.0,1.5,Iris-virginica +96,5.6,2.8,4.9,2.0,Iris-virginica +97,7.7,2.8,6.7,2.0,Iris-virginica +98,6.3,2.7,4.9,1.8,Iris-virginica +99,6.7,3.3,5.7,2.1,Iris-virginica +100,6.2,2.8,4.8,1.8,Iris-virginica +101,6.1,3.0,4.9,1.8,Iris-virginica +102,6.4,2.8,5.6,2.1,Iris-virginica +103,7.2,3.0,5.8,1.6,Iris-virginica +104,7.9,3.8,6.4,2.0,Iris-virginica +105,6.4,2.8,5.6,2.2,Iris-virginica +106,6.3,2.8,5.1,1.5,Iris-virginica +107,6.1,2.6,5.6,1.4,Iris-virginica +108,6.3,3.4,5.6,2.4,Iris-virginica +109,6.4,3.1,5.5,1.8,Iris-virginica +110,6.0,3.0,4.8,1.8,Iris-virginica +111,6.9,3.1,5.4,2.1,Iris-virginica +112,6.9,3.1,5.1,2.3,Iris-virginica +113,5.8,2.7,5.1,1.9,Iris-virginica +114,6.8,3.2,5.9,2.3,Iris-virginica +115,6.7,3.3,5.7,2.5,Iris-virginica +116,6.3,2.5,5.0,1.9,Iris-virginica +117,6.5,3.0,5.2,2.0,Iris-virginica +118,6.2,3.4,5.4,2.3,Iris-virginica +119,5.9,3.0,5.1,1.8,Iris-virginica diff --git a/examples/datasets/iris/iris_val.csv b/examples/datasets/iris/iris_val.csv new file mode 100644 index 0000000..d5d729b --- /dev/null +++ b/examples/datasets/iris/iris_val.csv @@ -0,0 +1,31 @@ +,sepal length,sepal width,petal length,petal width,class +0,5.1,3.5,1.4,0.2,Iris-setosa +1,5.4,3.9,1.7,0.4,Iris-setosa +2,5.4,3.7,1.5,0.2,Iris-setosa +3,5.7,4.4,1.5,0.4,Iris-setosa +4,5.4,3.4,1.7,0.2,Iris-setosa +5,5.0,3.0,1.6,0.2,Iris-setosa +6,4.8,3.1,1.6,0.2,Iris-setosa +7,5.0,3.2,1.2,0.2,Iris-setosa +8,5.0,3.5,1.3,0.3,Iris-setosa +9,4.8,3.0,1.4,0.3,Iris-setosa +10,7.0,3.2,4.7,1.4,Iris-versicolor +11,5.7,2.8,4.5,1.3,Iris-versicolor +12,5.0,2.0,3.5,1.0,Iris-versicolor +13,6.7,3.1,4.4,1.4,Iris-versicolor +14,5.9,3.2,4.8,1.8,Iris-versicolor +15,6.6,3.0,4.4,1.4,Iris-versicolor +16,5.5,2.4,3.8,1.1,Iris-versicolor +17,6.0,3.4,4.5,1.6,Iris-versicolor +18,5.5,2.6,4.4,1.2,Iris-versicolor +19,5.7,3.0,4.2,1.2,Iris-versicolor +20,6.3,3.3,6.0,2.5,Iris-virginica +21,7.6,3.0,6.6,2.1,Iris-virginica +22,6.5,3.2,5.1,2.0,Iris-virginica +23,6.4,3.2,5.3,2.3,Iris-virginica +24,6.9,3.2,5.7,2.3,Iris-virginica +25,7.2,3.2,6.0,1.8,Iris-virginica +26,7.4,2.8,6.1,1.9,Iris-virginica +27,7.7,3.0,6.1,2.3,Iris-virginica +28,6.7,3.1,5.6,2.4,Iris-virginica +29,6.7,3.0,5.2,2.3,Iris-virginica diff --git a/examples/datasets/iris/readme.md b/examples/datasets/iris/readme.md new file mode 100644 index 0000000..1dba2c6 --- /dev/null +++ b/examples/datasets/iris/readme.md @@ -0,0 +1,18 @@ +# Iris Data License +Iris data downloaded from [UCI Machine Learning Repository](https://archive.ics.uci.edu/dataset/53/iris), originally from **R.A. Fisher**. + +This dataset is licensed under a [Creative Commons Attribution 4.0 International (CC BY 4.0) license](https://creativecommons.org/licenses/by/4.0/legalcode). + +bedzekIris.data contains data what was identiefed as correct. Please see this article: https://lucykuncheva.co.uk/papers/jbjkrklknptfs99.pdf + +``` +diff bezdekIris.data iris.data +35c35 +< 4.9,3.1,1.5,0.2,Iris-setosa +--- +> 4.9,3.1,1.5,0.1,Iris-setosa +38c38 +< 4.9,3.6,1.4,0.1,Iris-setosa +--- +> 4.9,3.1,1.5,0.1,Iris-setosa +``` \ No newline at end of file diff --git a/examples/datasets/iris/train_val_split.py b/examples/datasets/iris/train_val_split.py new file mode 100644 index 0000000..eba356e --- /dev/null +++ b/examples/datasets/iris/train_val_split.py @@ -0,0 +1,45 @@ +""" +Train val split by HowToSD +""" +import os +import sys +import pandas as pd + +def main(): + target_file_path = os.path.join(os.path.dirname(__file__), "bezdekIris_with_header.data") + + df = pd.read_csv(target_file_path) + + # Split to 3 dfs + df1 = df.query('`class`=="Iris-setosa"') + df2 = df.query('`class`=="Iris-versicolor"') + df3 = df.query('`class`=="Iris-virginica"') + assert len(df1) == 50 + assert len(df2) == 50 + assert len(df3) == 50 + + train_indices = [] + val_indices = [] + + # Train/validation split indices (20% validation) + val_indices = list(range(0, 50, 5)) # [0, 5, 10, 15, 20, 25, 30, 35, 40, 45] + train_indices = list(set(range(50)) - set(val_indices)) + + # Apply train/val split + df1_train, df1_val = df1.iloc[train_indices], df1.iloc[val_indices] + df2_train, df2_val = df2.iloc[train_indices], df2.iloc[val_indices] + df3_train, df3_val = df3.iloc[train_indices], df3.iloc[val_indices] + + # Concatenate all train and val datasets + df_train = pd.concat([df1_train, df2_train, df3_train], ignore_index=True) + df_val = pd.concat([df1_val, df2_val, df3_val], ignore_index=True) + + # Check dataset sizes + assert len(df_train) == 120 + assert len(df_val) == 30 + + df_train.to_csv(os.path.join(os.path.dirname(__file__), "iris_train.csv")) + df_val.to_csv(os.path.join(os.path.dirname(__file__), "iris_val.csv")) + +if __name__ == "__main__": + main() \ No newline at end of file diff --git a/examples/workflows/iris_classification_train_eval.json b/examples/workflows/iris_classification_train_eval.json new file mode 100644 index 0000000..0b22073 --- /dev/null +++ b/examples/workflows/iris_classification_train_eval.json @@ -0,0 +1 @@ +{"last_node_id":76,"last_link_id":112,"nodes":[{"id":70,"type":"PandasShowDataFrame","pos":[522.3012084960938,4590.89990234375],"size":[497.2306213378906,448.692138671875],"flags":{},"order":7,"mode":0,"inputs":[{"name":"dataframe","type":"DATAFRAME","link":104}],"outputs":[{"name":"STRING","type":"STRING","links":null,"shape":6}],"properties":{"Node name for S&R":"PandasShowDataFrame"},"widgets_values":[" sepal length sepal width petal length petal width class\n0 5.1 3.5 1.4 0.2 Iris-setosa\n1 5.4 3.9 1.7 0.4 Iris-setosa\n2 5.4 3.7 1.5 0.2 Iris-setosa\n3 5.7 4.4 1.5 0.4 Iris-setosa\n4 5.4 3.4 1.7 0.2 Iris-setosa\n5 5.0 3.0 1.6 0.2 Iris-setosa\n6 4.8 3.1 1.6 0.2 Iris-setosa\n7 5.0 3.2 1.2 0.2 Iris-setosa\n8 5.0 3.5 1.3 0.3 Iris-setosa\n9 4.8 3.0 1.4 0.3 Iris-setosa\n10 7.0 3.2 4.7 1.4 Iris-versicolor\n11 5.7 2.8 4.5 1.3 Iris-versicolor\n12 5.0 2.0 3.5 1.0 Iris-versicolor\n13 6.7 3.1 4.4 1.4 Iris-versicolor\n14 5.9 3.2 4.8 1.8 Iris-versicolor\n15 6.6 3.0 4.4 1.4 Iris-versicolor\n16 5.5 2.4 3.8 1.1 Iris-versicolor\n17 6.0 3.4 4.5 1.6 Iris-versicolor\n18 5.5 2.6 4.4 1.2 Iris-versicolor\n19 5.7 3.0 4.2 1.2 Iris-versicolor\n20 6.3 3.3 6.0 2.5 Iris-virginica\n21 7.6 3.0 6.6 2.1 Iris-virginica\n22 6.5 3.2 5.1 2.0 Iris-virginica\n23 6.4 3.2 5.3 2.3 Iris-virginica\n24 6.9 3.2 5.7 2.3 Iris-virginica\n25 7.2 3.2 6.0 1.8 Iris-virginica\n26 7.4 2.8 6.1 1.9 Iris-virginica\n27 7.7 3.0 6.1 2.3 Iris-virginica\n28 6.7 3.1 5.6 2.4 Iris-virginica\n29 6.7 3.0 5.2 2.3 Iris-virginica"]},{"id":68,"type":"PandasReplaceAdvanced","pos":[1072.482666015625,4348.2099609375],"size":[261.212158203125,119.18181610107422],"flags":{},"order":6,"mode":0,"inputs":[{"name":"dataframe","type":"DATAFRAME","link":102}],"outputs":[{"name":"DATAFRAME","type":"DATAFRAME","links":[103],"slot_index":0}],"properties":{"Node name for S&R":"PandasReplaceAdvanced"},"widgets_values":["{\"Iris-setosa\":0,\n\"Iris-versicolor\":1,\n\"Iris-virginica\":2}"]},{"id":44,"type":"CDAShowFloat","pos":[3463.3115234375,4348.2099609375],"size":[315,76],"flags":{},"order":18,"mode":0,"inputs":[{"name":"float_scalar","type":"FLOAT","link":53,"widget":{"name":"float_scalar"}}],"outputs":[{"name":"STRING","type":"STRING","links":null,"shape":6}],"title":"Accuracy","properties":{"Node name for S&R":"CDAShowFloat"},"widgets_values":[0,"0.9666666666666667"]},{"id":72,"type":"CDAShowFloat","pos":[3463.3115234375,4476.33642578125],"size":[315,76],"flags":{},"order":19,"mode":0,"inputs":[{"name":"float_scalar","type":"FLOAT","link":108,"widget":{"name":"float_scalar"}}],"outputs":[{"name":"STRING","type":"STRING","links":null,"shape":6}],"title":"Precision","properties":{"Node name for S&R":"CDAShowFloat"},"widgets_values":[0,"0.9696969696969697"]},{"id":73,"type":"CDAShowFloat","pos":[3463.3115234375,4601.6923828125],"size":[315,76],"flags":{},"order":20,"mode":0,"inputs":[{"name":"float_scalar","type":"FLOAT","link":110,"widget":{"name":"float_scalar"}}],"outputs":[{"name":"STRING","type":"STRING","links":null,"shape":6}],"title":"Recall","properties":{"Node name for S&R":"CDAShowFloat"},"widgets_values":[0,"0.9666666666666667"]},{"id":74,"type":"CDAShowFloat","pos":[3463.3115234375,4735.68310546875],"size":[315,76],"flags":{},"order":21,"mode":0,"inputs":[{"name":"float_scalar","type":"FLOAT","link":111,"widget":{"name":"float_scalar"}}],"outputs":[{"name":"STRING","type":"STRING","links":null,"shape":6}],"title":"F1","properties":{"Node name for S&R":"CDAShowFloat"},"widgets_values":[0,"0.9665831244778612"]},{"id":76,"type":"CDAShowInt","pos":[3463.3115234375,4872.4619140625],"size":[315,76],"flags":{},"order":22,"mode":0,"inputs":[{"name":"int_scalar","type":"INT","link":112,"widget":{"name":"int_scalar"}}],"outputs":[{"name":"STRING","type":"STRING","links":null,"shape":6}],"title":"Num samples","properties":{"Node name for S&R":"CDAShowInt"},"widgets_values":[0,"30"]},{"id":16,"type":"PandasShowDataFrame","pos":[1072.482666015625,3408.90966796875],"size":[481.2576599121094,230.6519775390625],"flags":{},"order":8,"mode":0,"inputs":[{"name":"dataframe","type":"DATAFRAME","link":77}],"outputs":[{"name":"STRING","type":"STRING","links":null,"shape":6}],"properties":{"Node name for S&R":"PandasShowDataFrame"},"widgets_values":[" sepal length sepal width petal length petal width class\n0 4.9 3.0 1.4 0.2 0\n1 4.7 3.2 1.3 0.2 0\n2 4.6 3.1 1.5 0.2 0\n3 5.0 3.6 1.4 0.2 0\n4 4.6 3.4 1.4 0.3 0\n.. ... ... ... ... ...\n115 6.7 3.3 5.7 2.5 2\n116 6.3 2.5 5.0 1.9 2\n117 6.5 3.0 5.2 2.0 2\n118 6.2 3.4 5.4 2.3 2\n119 5.9 3.0 5.1 1.8 2\n\n[120 rows x 5 columns]"]},{"id":11,"type":"PandasShowDataFrame","pos":[522.3012084960938,3408.90966796875],"size":[514.46728515625,237.3878936767578],"flags":{},"order":4,"mode":0,"inputs":[{"name":"dataframe","type":"DATAFRAME","link":88}],"outputs":[{"name":"STRING","type":"STRING","links":null,"shape":6}],"properties":{"Node name for S&R":"PandasShowDataFrame"},"widgets_values":[" sepal length sepal width petal length petal width class\n0 4.9 3.0 1.4 0.2 Iris-setosa\n1 4.7 3.2 1.3 0.2 Iris-setosa\n2 4.6 3.1 1.5 0.2 Iris-setosa\n3 5.0 3.6 1.4 0.2 Iris-setosa\n4 4.6 3.4 1.4 0.3 Iris-setosa\n.. ... ... ... ... ...\n115 6.7 3.3 5.7 2.5 Iris-virginica\n116 6.3 2.5 5.0 1.9 Iris-virginica\n117 6.5 3.0 5.2 2.0 Iris-virginica\n118 6.2 3.4 5.4 2.3 Iris-virginica\n119 5.9 3.0 5.1 1.8 Iris-virginica\n\n[120 rows x 5 columns]"]},{"id":63,"type":"PtDataLoaderFromTensors","pos":[2156.013916015625,4348.2099609375],"size":[340.20001220703125,102],"flags":{},"order":12,"mode":0,"inputs":[{"name":"x","type":"TENSOR","link":106},{"name":"y","type":"TENSOR","link":107}],"outputs":[{"name":"PTDATALOADER","type":"PTDATALOADER","links":[75],"slot_index":0}],"properties":{"Node name for S&R":"PtDataLoaderFromTensors"},"widgets_values":[5,false]},{"id":29,"type":"PtnLinearModel","pos":[2156.013916015625,3441.72314453125],"size":[315,106],"flags":{},"order":0,"mode":0,"inputs":[],"outputs":[{"name":"PTMODEL","type":"PTMODEL","links":[29,51],"slot_index":0}],"properties":{"Node name for S&R":"PtnLinearModel"},"widgets_values":["[4,512,3]","[True,True]",2]},{"id":42,"type":"PtoAdam","pos":[2156.013916015625,3696.825927734375],"size":[315,106],"flags":{},"order":3,"mode":0,"inputs":[{"name":"model","type":"PTMODEL","link":51}],"outputs":[{"name":"PTOPTIMIZER","type":"PTOPTIMIZER","links":[52],"slot_index":0}],"properties":{"Node name for S&R":"PtoAdam"},"widgets_values":[0.001,0.9,0.999]},{"id":32,"type":"PtSaveModel","pos":[3463.3115234375,3173.329833984375],"size":[315,58],"flags":{},"order":14,"mode":0,"inputs":[{"name":"model","type":"PTMODEL","link":32}],"outputs":[{"name":"model full path","type":"STRING","links":[49],"slot_index":0}],"properties":{"Node name for S&R":"PtSaveModel"},"widgets_values":["iris.pkl"]},{"id":33,"type":"PtShowText","pos":[3463.3115234375,3343.487548828125],"size":[631.916259765625,81.7053451538086],"flags":{},"order":16,"mode":0,"inputs":[{"name":"tens","type":"TENSOR","link":33}],"outputs":[{"name":"STRING","type":"STRING","links":null,"shape":6}],"properties":{"Node name for S&R":"PtShowText"},"widgets_values":["tensor([0.9147, 0.6376, 0.4849, ..., 0.0641, 0.0745, 0.0556])"]},{"id":65,"type":"PandasLoadCSVWithIndex","pos":[522.3012084960938,3173.329833984375],"size":[327.5999755859375,82],"flags":{},"order":1,"mode":0,"inputs":[],"outputs":[{"name":"DATAFRAME","type":"DATAFRAME","links":[88,89],"slot_index":0}],"properties":{"Node name for S&R":"PandasLoadCSVWithIndex"},"widgets_values":["custom_nodes/pt-wrapper/examples/datasets/iris/iris_train.csv",0]},{"id":69,"type":"PandasFeatureSplitToPt","pos":[1702.9251708984375,4348.2099609375],"size":[327.5999755859375,150],"flags":{},"order":10,"mode":0,"inputs":[{"name":"dataframe","type":"DATAFRAME","link":103}],"outputs":[{"name":"feature","type":"TENSOR","links":[106],"slot_index":0},{"name":"label","type":"TENSOR","links":[107],"slot_index":1}],"properties":{"Node name for S&R":"PandasFeatureSplitToPt"},"widgets_values":[-1,true,"float32","int64"]},{"id":64,"type":"PandasReplaceAdvanced","pos":[1072.482666015625,3173.329833984375],"size":[261.212158203125,119.18181610107422],"flags":{},"order":5,"mode":0,"inputs":[{"name":"dataframe","type":"DATAFRAME","link":89}],"outputs":[{"name":"DATAFRAME","type":"DATAFRAME","links":[77,90],"slot_index":0}],"properties":{"Node name for S&R":"PandasReplaceAdvanced"},"widgets_values":["{\"Iris-setosa\":0,\n\"Iris-versicolor\":1,\n\"Iris-virginica\":2}"]},{"id":66,"type":"PandasFeatureSplitToPt","pos":[1702.9251708984375,3173.329833984375],"size":[327.5999755859375,150],"flags":{},"order":9,"mode":0,"inputs":[{"name":"dataframe","type":"DATAFRAME","link":90}],"outputs":[{"name":"feature","type":"TENSOR","links":[91],"slot_index":0},{"name":"label","type":"TENSOR","links":[92],"slot_index":1}],"properties":{"Node name for S&R":"PandasFeatureSplitToPt"},"widgets_values":[-1,true,"float32","int64"]},{"id":28,"type":"PtDataLoaderFromTensors","pos":[2156.013916015625,3173.329833984375],"size":[340.20001220703125,102],"flags":{},"order":11,"mode":0,"inputs":[{"name":"x","type":"TENSOR","link":91},{"name":"y","type":"TENSOR","link":92}],"outputs":[{"name":"PTDATALOADER","type":"PTDATALOADER","links":[30],"slot_index":0}],"properties":{"Node name for S&R":"PtDataLoaderFromTensors"},"widgets_values":[10,true]},{"id":43,"type":"PtEvaluateClassificationModel","pos":[2724.5361328125,4348.2099609375],"size":[403.1999816894531,138],"flags":{},"order":15,"mode":0,"inputs":[{"name":"model","type":"PTMODEL","link":54},{"name":"data_loader","type":"PTDATALOADER","link":75}],"outputs":[{"name":"accuracy","type":"FLOAT","links":[53],"slot_index":0},{"name":"precision","type":"FLOAT","links":[108],"slot_index":1},{"name":"recall","type":"FLOAT","links":[110],"slot_index":2},{"name":"f1","type":"FLOAT","links":[111],"slot_index":3},{"name":"num_samples","type":"INT","links":[112],"slot_index":4}],"properties":{"Node name for S&R":"PtEvaluateClassificationModel"},"widgets_values":[true]},{"id":30,"type":"PtTrainClassificationModel","pos":[2724.5361328125,3173.329833984375],"size":[365.4000244140625,214],"flags":{},"order":13,"mode":0,"inputs":[{"name":"model","type":"PTMODEL","link":29},{"name":"train_loader","type":"PTDATALOADER","link":30},{"name":"optimizer","type":"PTOPTIMIZER","link":52},{"name":"val_loader","type":"PTDATALOADER","link":null,"shape":7}],"outputs":[{"name":"Model","type":"PTMODEL","links":[32,54],"slot_index":0},{"name":"train loss","type":"TENSOR","links":[33],"slot_index":1},{"name":"val loss","type":"TENSOR","links":null}],"properties":{"Node name for S&R":"PtTrainClassificationModel"},"widgets_values":[200,true,false,10,false]},{"id":41,"type":"PandasShowText","pos":[4206.8994140625,3173.329833984375],"size":[523.6947021484375,76],"flags":{},"order":17,"mode":0,"inputs":[{"name":"text","type":"STRING","link":49,"widget":{"name":"text"}}],"outputs":[{"name":"STRING","type":"STRING","links":null,"shape":6}],"properties":{"Node name for S&R":"PandasShowText"},"widgets_values":["","/home/dockeruser/comfy/ComfyUI/custom_nodes/pt-wrapper/models/iris.pkl"]},{"id":67,"type":"PandasLoadCSVWithIndex","pos":[522.3012084960938,4348.2099609375],"size":[327.5999755859375,82],"flags":{},"order":2,"mode":0,"inputs":[],"outputs":[{"name":"DATAFRAME","type":"DATAFRAME","links":[102,104],"slot_index":0}],"properties":{"Node name for S&R":"PandasLoadCSVWithIndex"},"widgets_values":["custom_nodes/pt-wrapper/examples/datasets/iris/iris_val.csv",0]}],"links":[[29,29,0,30,0,"PTMODEL"],[30,28,0,30,1,"PTDATALOADER"],[32,30,0,32,0,"PTMODEL"],[33,30,1,33,0,"TENSOR"],[49,32,0,41,0,"STRING"],[51,29,0,42,0,"PTMODEL"],[52,42,0,30,2,"PTOPTIMIZER"],[53,43,0,44,0,"FLOAT"],[54,30,0,43,0,"PTMODEL"],[75,63,0,43,1,"PTDATALOADER"],[77,64,0,16,0,"DATAFRAME"],[88,65,0,11,0,"DATAFRAME"],[89,65,0,64,0,"DATAFRAME"],[90,64,0,66,0,"DATAFRAME"],[91,66,0,28,0,"TENSOR"],[92,66,1,28,1,"TENSOR"],[102,67,0,68,0,"DATAFRAME"],[103,68,0,69,0,"DATAFRAME"],[104,67,0,70,0,"DATAFRAME"],[106,69,0,63,0,"TENSOR"],[107,69,1,63,1,"TENSOR"],[108,43,1,72,0,"FLOAT"],[110,43,2,73,0,"FLOAT"],[111,43,3,74,0,"FLOAT"],[112,43,4,76,0,"INT"]],"groups":[],"config":{},"extra":{"ds":{"scale":0.2547179056219536,"offset":[-1778.4133821565692,-2306.537758548792]},"node_versions":{"data-analysis":"e490b620286600930c8c9d3a6986f73d5320463f","pt-wrapper":"4fbfd28f609278974f0f2e7cbb8b7bdc4fafef3d"},"ue_links":[]},"version":0.4} \ No newline at end of file diff --git a/modules/pytorch_wrapper/pt_to_bfloat16.py b/modules/pytorch_wrapper/pt_to_bfloat16.py new file mode 100644 index 0000000..4a97cc1 --- /dev/null +++ b/modules/pytorch_wrapper/pt_to_bfloat16.py @@ -0,0 +1,39 @@ +from typing import Any, Dict +import torch + +class PtToBfloat16: + """ + Converts the input tensor's data type to bfloat16. + + category: PyTorch wrapper - Data type conversion + """ + + @classmethod + def INPUT_TYPES(cls) -> Dict[str, Any]: + """ + Defines the required input types. + + Returns: + Dict[str, Any]: A dictionary of required input types. + """ + return { + "required": { + "tens_a": ("TENSOR", {}) + } + } + + RETURN_TYPES: tuple = ("TENSOR",) + FUNCTION: str = "f" + CATEGORY: str = "Data Analysis" + + def f(self, tens_a: torch.Tensor) -> tuple: + """ + Converts the input tensor's data type to bfloat16. + + Args: + tens_a (torch.Tensor): A PyTorch tensor of numerical type. + + Returns: + tuple: A tuple containing the resultant tensor after the operation. + """ + return (tens_a.to(torch.bfloat16),) diff --git a/modules/pytorch_wrapper/pt_to_float16.py b/modules/pytorch_wrapper/pt_to_float16.py new file mode 100644 index 0000000..f062651 --- /dev/null +++ b/modules/pytorch_wrapper/pt_to_float16.py @@ -0,0 +1,39 @@ +from typing import Any, Dict +import torch + +class PtToFloat16: + """ + Converts the input tensor's data type to float16. + + category: PyTorch wrapper - Data type conversion + """ + + @classmethod + def INPUT_TYPES(cls) -> Dict[str, Any]: + """ + Defines the required input types. + + Returns: + Dict[str, Any]: A dictionary of required input types. + """ + return { + "required": { + "tens_a": ("TENSOR", {}) + } + } + + RETURN_TYPES: tuple = ("TENSOR",) + FUNCTION: str = "f" + CATEGORY: str = "Data Analysis" + + def f(self, tens_a: torch.Tensor) -> tuple: + """ + Converts the input tensor's data type to float16. + + Args: + tens_a (torch.Tensor): A PyTorch tensor of numerical type. + + Returns: + tuple: A tuple containing the resultant tensor after the operation. + """ + return (tens_a.to(torch.float16),) diff --git a/modules/pytorch_wrapper/pt_to_float32.py b/modules/pytorch_wrapper/pt_to_float32.py new file mode 100644 index 0000000..f26ecc0 --- /dev/null +++ b/modules/pytorch_wrapper/pt_to_float32.py @@ -0,0 +1,39 @@ +from typing import Any, Dict +import torch + +class PtToFloat32: + """ + Converts the input tensor's data type to float32. + + category: PyTorch wrapper - Data type conversion + """ + + @classmethod + def INPUT_TYPES(cls) -> Dict[str, Any]: + """ + Defines the required input types. + + Returns: + Dict[str, Any]: A dictionary of required input types. + """ + return { + "required": { + "tens_a": ("TENSOR", {}) + } + } + + RETURN_TYPES: tuple = ("TENSOR",) + FUNCTION: str = "f" + CATEGORY: str = "Data Analysis" + + def f(self, tens_a: torch.Tensor) -> tuple: + """ + Converts the input tensor's data type to float32. + + Args: + tens_a (torch.Tensor): A PyTorch tensor of numerical type. + + Returns: + tuple: A tuple containing the resultant tensor after the operation. + """ + return (tens_a.to(torch.float32),) diff --git a/modules/pytorch_wrapper/pt_to_float64.py b/modules/pytorch_wrapper/pt_to_float64.py new file mode 100644 index 0000000..8a906fa --- /dev/null +++ b/modules/pytorch_wrapper/pt_to_float64.py @@ -0,0 +1,39 @@ +from typing import Any, Dict +import torch + +class PtToFloat64: + """ + Converts the input tensor's data type to float64. + + category: PyTorch wrapper - Data type conversion + """ + + @classmethod + def INPUT_TYPES(cls) -> Dict[str, Any]: + """ + Defines the required input types. + + Returns: + Dict[str, Any]: A dictionary of required input types. + """ + return { + "required": { + "tens_a": ("TENSOR", {}) + } + } + + RETURN_TYPES: tuple = ("TENSOR",) + FUNCTION: str = "f" + CATEGORY: str = "Data Analysis" + + def f(self, tens_a: torch.Tensor) -> tuple: + """ + Converts the input tensor's data type to float64. + + Args: + tens_a (torch.Tensor): A PyTorch tensor of numerical type. + + Returns: + tuple: A tuple containing the resultant tensor after the operation. + """ + return (tens_a.to(torch.float64),) diff --git a/modules/pytorch_wrapper/pt_to_int16.py b/modules/pytorch_wrapper/pt_to_int16.py new file mode 100644 index 0000000..440a0b3 --- /dev/null +++ b/modules/pytorch_wrapper/pt_to_int16.py @@ -0,0 +1,39 @@ +from typing import Any, Dict +import torch + +class PtToInt16: + """ + Converts the input tensor's data type to int16. + + category: PyTorch wrapper - Data type conversion + """ + + @classmethod + def INPUT_TYPES(cls) -> Dict[str, Any]: + """ + Defines the required input types. + + Returns: + Dict[str, Any]: A dictionary of required input types. + """ + return { + "required": { + "tens_a": ("TENSOR", {}) + } + } + + RETURN_TYPES: tuple = ("TENSOR",) + FUNCTION: str = "f" + CATEGORY: str = "Data Analysis" + + def f(self, tens_a: torch.Tensor) -> tuple: + """ + Converts the input tensor's data type to int16. + + Args: + tens_a (torch.Tensor): A PyTorch tensor of numerical type. + + Returns: + tuple: A tuple containing the resultant tensor after the operation. + """ + return (tens_a.to(torch.int16),) diff --git a/modules/pytorch_wrapper/pt_to_int32.py b/modules/pytorch_wrapper/pt_to_int32.py new file mode 100644 index 0000000..ec75884 --- /dev/null +++ b/modules/pytorch_wrapper/pt_to_int32.py @@ -0,0 +1,39 @@ +from typing import Any, Dict +import torch + +class PtToInt32: + """ + Converts the input tensor's data type to int32. + + category: PyTorch wrapper - Data type conversion + """ + + @classmethod + def INPUT_TYPES(cls) -> Dict[str, Any]: + """ + Defines the required input types. + + Returns: + Dict[str, Any]: A dictionary of required input types. + """ + return { + "required": { + "tens_a": ("TENSOR", {}) + } + } + + RETURN_TYPES: tuple = ("TENSOR",) + FUNCTION: str = "f" + CATEGORY: str = "Data Analysis" + + def f(self, tens_a: torch.Tensor) -> tuple: + """ + Converts the input tensor's data type to int32. + + Args: + tens_a (torch.Tensor): A PyTorch tensor of numerical type. + + Returns: + tuple: A tuple containing the resultant tensor after the operation. + """ + return (tens_a.to(torch.int32),) diff --git a/modules/pytorch_wrapper/pt_to_int64.py b/modules/pytorch_wrapper/pt_to_int64.py new file mode 100644 index 0000000..31dcdb3 --- /dev/null +++ b/modules/pytorch_wrapper/pt_to_int64.py @@ -0,0 +1,39 @@ +from typing import Any, Dict +import torch + +class PtToInt64: + """ + Converts the input tensor's data type to int64. + + category: PyTorch wrapper - Data type conversion + """ + + @classmethod + def INPUT_TYPES(cls) -> Dict[str, Any]: + """ + Defines the required input types. + + Returns: + Dict[str, Any]: A dictionary of required input types. + """ + return { + "required": { + "tens_a": ("TENSOR", {}) + } + } + + RETURN_TYPES: tuple = ("TENSOR",) + FUNCTION: str = "f" + CATEGORY: str = "Data Analysis" + + def f(self, tens_a: torch.Tensor) -> tuple: + """ + Converts the input tensor's data type to int64. + + Args: + tens_a (torch.Tensor): A PyTorch tensor of numerical type. + + Returns: + tuple: A tuple containing the resultant tensor after the operation. + """ + return (tens_a.to(torch.int64),) diff --git a/modules/pytorch_wrapper/pt_to_int8.py b/modules/pytorch_wrapper/pt_to_int8.py new file mode 100644 index 0000000..4bccaab --- /dev/null +++ b/modules/pytorch_wrapper/pt_to_int8.py @@ -0,0 +1,39 @@ +from typing import Any, Dict +import torch + +class PtToInt8: + """ + Converts the input tensor's data type to int8. + + category: PyTorch wrapper - Data type conversion + """ + + @classmethod + def INPUT_TYPES(cls) -> Dict[str, Any]: + """ + Defines the required input types. + + Returns: + Dict[str, Any]: A dictionary of required input types. + """ + return { + "required": { + "tens_a": ("TENSOR", {}) + } + } + + RETURN_TYPES: tuple = ("TENSOR",) + FUNCTION: str = "f" + CATEGORY: str = "Data Analysis" + + def f(self, tens_a: torch.Tensor) -> tuple: + """ + Converts the input tensor's data type to int8. + + Args: + tens_a (torch.Tensor): A PyTorch tensor of numerical type. + + Returns: + tuple: A tuple containing the resultant tensor after the operation. + """ + return (tens_a.to(torch.int8),) diff --git a/modules/pytorch_wrapper/pt_to_uint8.py b/modules/pytorch_wrapper/pt_to_uint8.py new file mode 100644 index 0000000..e9a7b25 --- /dev/null +++ b/modules/pytorch_wrapper/pt_to_uint8.py @@ -0,0 +1,39 @@ +from typing import Any, Dict +import torch + +class PtToUint8: + """ + Converts the input tensor's data type to uint8. + + category: PyTorch wrapper - Data type conversion + """ + + @classmethod + def INPUT_TYPES(cls) -> Dict[str, Any]: + """ + Defines the required input types. + + Returns: + Dict[str, Any]: A dictionary of required input types. + """ + return { + "required": { + "tens_a": ("TENSOR", {}) + } + } + + RETURN_TYPES: tuple = ("TENSOR",) + FUNCTION: str = "f" + CATEGORY: str = "Data Analysis" + + def f(self, tens_a: torch.Tensor) -> tuple: + """ + Converts the input tensor's data type to uint8. + + Args: + tens_a (torch.Tensor): A PyTorch tensor of numerical type. + + Returns: + tuple: A tuple containing the resultant tensor after the operation. + """ + return (tens_a.to(torch.uint8),) diff --git a/pyproject.toml b/pyproject.toml index 30b3568..28c52fc 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -1,7 +1,7 @@ [project] name = "pt-wrapper" description = "PyTorch extension for ComfyUI featuring extensive PyTorch wrapper nodes for seamless tensor operations and PyTorch model training." -version = "3.0.8" +version = "3.0.9" license = {file = "LICENSE"} [project.urls] diff --git a/tests/pytorch_wrapper/pt_to_bfloat16_test.py b/tests/pytorch_wrapper/pt_to_bfloat16_test.py new file mode 100644 index 0000000..490d58f --- /dev/null +++ b/tests/pytorch_wrapper/pt_to_bfloat16_test.py @@ -0,0 +1,41 @@ +import os +import sys +import unittest +import torch + +PROJECT_ROOT = os.path.realpath(os.path.join(os.path.dirname(__file__), "..", "..")) +MODULE_ROOT = os.path.join(PROJECT_ROOT, "modules") +sys.path.append(MODULE_ROOT) + +from pytorch_wrapper.pt_to_bfloat16 import PtToBfloat16 + + +class TestPtToFloat16(unittest.TestCase): + def setUp(self): + """Set up test instance.""" + self.node = PtToBfloat16() + + # Test cases: (Tensor A, expected result, expected dtype) + self.test_cases = [ + (torch.tensor([1.0, 2.0, 3.0], dtype=torch.float16), torch.tensor([1.0, 2.0, 3.0], dtype=torch.bfloat16), torch.bfloat16), + ] + + def test_1(self): + """Test tensor element-wise square root using torch.sqrt().""" + for tens_a, expected_value, expected_dtype in self.test_cases: + with self.subTest(tens_a=tens_a): + result, = self.node.f(tens_a) + + # Ensure return value is a tensor + self.assertTrue(isinstance(result, torch.Tensor), "Output is not a tensor") + + # Ensure data type + self.assertEqual(result.dtype, expected_dtype, + f"Expected dtype {expected_dtype}, got {result.dtype}") + + # Ensure result matches expected values + self.assertTrue(torch.allclose(result, expected_value, atol=1e-6), f"Expected {expected_value}, got {result}") + + +if __name__ == "__main__": + unittest.main() diff --git a/tests/pytorch_wrapper/pt_to_float16_test.py b/tests/pytorch_wrapper/pt_to_float16_test.py new file mode 100644 index 0000000..a617b07 --- /dev/null +++ b/tests/pytorch_wrapper/pt_to_float16_test.py @@ -0,0 +1,41 @@ +import os +import sys +import unittest +import torch + +PROJECT_ROOT = os.path.realpath(os.path.join(os.path.dirname(__file__), "..", "..")) +MODULE_ROOT = os.path.join(PROJECT_ROOT, "modules") +sys.path.append(MODULE_ROOT) + +from pytorch_wrapper.pt_to_float16 import PtToFloat16 + + +class TestPtToFloat16(unittest.TestCase): + def setUp(self): + """Set up test instance.""" + self.node = PtToFloat16() + + # Test cases: (Tensor A, expected result, expected dtype) + self.test_cases = [ + (torch.tensor([1.0, 2.0, 3.0], dtype=torch.float32), torch.tensor([1.0, 2.0, 3.0], dtype=torch.float16), torch.float16), + ] + + def test_1(self): + """Test tensor element-wise square root using torch.sqrt().""" + for tens_a, expected_value, expected_dtype in self.test_cases: + with self.subTest(tens_a=tens_a): + result, = self.node.f(tens_a) + + # Ensure return value is a tensor + self.assertTrue(isinstance(result, torch.Tensor), "Output is not a tensor") + + # Ensure data type + self.assertEqual(result.dtype, expected_dtype, + f"Expected dtype {expected_dtype}, got {result.dtype}") + + # Ensure result matches expected values + self.assertTrue(torch.allclose(result, expected_value, atol=1e-6), f"Expected {expected_value}, got {result}") + + +if __name__ == "__main__": + unittest.main() diff --git a/tests/pytorch_wrapper/pt_to_float32_test.py b/tests/pytorch_wrapper/pt_to_float32_test.py new file mode 100644 index 0000000..dfbb139 --- /dev/null +++ b/tests/pytorch_wrapper/pt_to_float32_test.py @@ -0,0 +1,41 @@ +import os +import sys +import unittest +import torch + +PROJECT_ROOT = os.path.realpath(os.path.join(os.path.dirname(__file__), "..", "..")) +MODULE_ROOT = os.path.join(PROJECT_ROOT, "modules") +sys.path.append(MODULE_ROOT) + +from pytorch_wrapper.pt_to_float32 import PtToFloat32 + + +class TestPtToFloat32(unittest.TestCase): + def setUp(self): + """Set up test instance.""" + self.node = PtToFloat32() + + # Test cases: (Tensor A, expected result, expected dtype) + self.test_cases = [ + (torch.tensor([1.0, 2.0, 3.0], dtype=torch.float16), torch.tensor([1.0, 2.0, 3.0], dtype=torch.float32), torch.float32), + ] + + def test_1(self): + """Test tensor element-wise square root using torch.sqrt().""" + for tens_a, expected_value, expected_dtype in self.test_cases: + with self.subTest(tens_a=tens_a): + result, = self.node.f(tens_a) + + # Ensure return value is a tensor + self.assertTrue(isinstance(result, torch.Tensor), "Output is not a tensor") + + # Ensure data type + self.assertEqual(result.dtype, expected_dtype, + f"Expected dtype {expected_dtype}, got {result.dtype}") + + # Ensure result matches expected values + self.assertTrue(torch.allclose(result, expected_value, atol=1e-6), f"Expected {expected_value}, got {result}") + + +if __name__ == "__main__": + unittest.main() diff --git a/tests/pytorch_wrapper/pt_to_float64_test.py b/tests/pytorch_wrapper/pt_to_float64_test.py new file mode 100644 index 0000000..43c123f --- /dev/null +++ b/tests/pytorch_wrapper/pt_to_float64_test.py @@ -0,0 +1,41 @@ +import os +import sys +import unittest +import torch + +PROJECT_ROOT = os.path.realpath(os.path.join(os.path.dirname(__file__), "..", "..")) +MODULE_ROOT = os.path.join(PROJECT_ROOT, "modules") +sys.path.append(MODULE_ROOT) + +from pytorch_wrapper.pt_to_float64 import PtToFloat64 + + +class TestPtToFloat64(unittest.TestCase): + def setUp(self): + """Set up test instance.""" + self.node = PtToFloat64() + + # Test cases: (Tensor A, expected result, expected dtype) + self.test_cases = [ + (torch.tensor([1.0, 2.0, 3.0], dtype=torch.float16), torch.tensor([1.0, 2.0, 3.0], dtype=torch.float64), torch.float64), + ] + + def test_1(self): + """Test tensor element-wise square root using torch.sqrt().""" + for tens_a, expected_value, expected_dtype in self.test_cases: + with self.subTest(tens_a=tens_a): + result, = self.node.f(tens_a) + + # Ensure return value is a tensor + self.assertTrue(isinstance(result, torch.Tensor), "Output is not a tensor") + + # Ensure data type + self.assertEqual(result.dtype, expected_dtype, + f"Expected dtype {expected_dtype}, got {result.dtype}") + + # Ensure result matches expected values + self.assertTrue(torch.allclose(result, expected_value, atol=1e-6), f"Expected {expected_value}, got {result}") + + +if __name__ == "__main__": + unittest.main() diff --git a/tests/pytorch_wrapper/pt_to_int16_test.py b/tests/pytorch_wrapper/pt_to_int16_test.py new file mode 100644 index 0000000..100b85a --- /dev/null +++ b/tests/pytorch_wrapper/pt_to_int16_test.py @@ -0,0 +1,41 @@ +import os +import sys +import unittest +import torch + +PROJECT_ROOT = os.path.realpath(os.path.join(os.path.dirname(__file__), "..", "..")) +MODULE_ROOT = os.path.join(PROJECT_ROOT, "modules") +sys.path.append(MODULE_ROOT) + +from pytorch_wrapper.pt_to_int16 import PtToInt16 + + +class TestPtToInt16(unittest.TestCase): + def setUp(self): + """Set up test instance.""" + self.node = PtToInt16() + + # Test cases: (Tensor A, expected result, expected dtype) + self.test_cases = [ + (torch.tensor([1.0, 2.0, 3.0], dtype=torch.float32), torch.tensor([1, 2, 3], dtype=torch.int16), torch.int16), + ] + + def test_1(self): + """Test tensor element-wise square root using torch.sqrt().""" + for tens_a, expected_value, expected_dtype in self.test_cases: + with self.subTest(tens_a=tens_a): + result, = self.node.f(tens_a) + + # Ensure return value is a tensor + self.assertTrue(isinstance(result, torch.Tensor), "Output is not a tensor") + + # Ensure data type + self.assertEqual(result.dtype, expected_dtype, + f"Expected dtype {expected_dtype}, got {result.dtype}") + + # Ensure result matches expected values + self.assertTrue(torch.allclose(result, expected_value, atol=1e-6), f"Expected {expected_value}, got {result}") + + +if __name__ == "__main__": + unittest.main() diff --git a/tests/pytorch_wrapper/pt_to_int32_test.py b/tests/pytorch_wrapper/pt_to_int32_test.py new file mode 100644 index 0000000..2f8a573 --- /dev/null +++ b/tests/pytorch_wrapper/pt_to_int32_test.py @@ -0,0 +1,41 @@ +import os +import sys +import unittest +import torch + +PROJECT_ROOT = os.path.realpath(os.path.join(os.path.dirname(__file__), "..", "..")) +MODULE_ROOT = os.path.join(PROJECT_ROOT, "modules") +sys.path.append(MODULE_ROOT) + +from pytorch_wrapper.pt_to_int32 import PtToInt32 + + +class TestPtToInt32(unittest.TestCase): + def setUp(self): + """Set up test instance.""" + self.node = PtToInt32() + + # Test cases: (Tensor A, expected result, expected dtype) + self.test_cases = [ + (torch.tensor([1.0, 2.0, 3.0], dtype=torch.float32), torch.tensor([1, 2, 3], dtype=torch.int32), torch.int32), + ] + + def test_1(self): + """Test tensor element-wise square root using torch.sqrt().""" + for tens_a, expected_value, expected_dtype in self.test_cases: + with self.subTest(tens_a=tens_a): + result, = self.node.f(tens_a) + + # Ensure return value is a tensor + self.assertTrue(isinstance(result, torch.Tensor), "Output is not a tensor") + + # Ensure data type + self.assertEqual(result.dtype, expected_dtype, + f"Expected dtype {expected_dtype}, got {result.dtype}") + + # Ensure result matches expected values + self.assertTrue(torch.allclose(result, expected_value, atol=1e-6), f"Expected {expected_value}, got {result}") + + +if __name__ == "__main__": + unittest.main() diff --git a/tests/pytorch_wrapper/pt_to_int64_test.py b/tests/pytorch_wrapper/pt_to_int64_test.py new file mode 100644 index 0000000..bcf9610 --- /dev/null +++ b/tests/pytorch_wrapper/pt_to_int64_test.py @@ -0,0 +1,41 @@ +import os +import sys +import unittest +import torch + +PROJECT_ROOT = os.path.realpath(os.path.join(os.path.dirname(__file__), "..", "..")) +MODULE_ROOT = os.path.join(PROJECT_ROOT, "modules") +sys.path.append(MODULE_ROOT) + +from pytorch_wrapper.pt_to_int64 import PtToInt64 + + +class TestPtToInt64(unittest.TestCase): + def setUp(self): + """Set up test instance.""" + self.node = PtToInt64() + + # Test cases: (Tensor A, expected result, expected dtype) + self.test_cases = [ + (torch.tensor([1.0, 2.0, 3.0], dtype=torch.float32), torch.tensor([1, 2, 3], dtype=torch.int64), torch.int64), + ] + + def test_1(self): + """Test tensor element-wise square root using torch.sqrt().""" + for tens_a, expected_value, expected_dtype in self.test_cases: + with self.subTest(tens_a=tens_a): + result, = self.node.f(tens_a) + + # Ensure return value is a tensor + self.assertTrue(isinstance(result, torch.Tensor), "Output is not a tensor") + + # Ensure data type + self.assertEqual(result.dtype, expected_dtype, + f"Expected dtype {expected_dtype}, got {result.dtype}") + + # Ensure result matches expected values + self.assertTrue(torch.allclose(result, expected_value, atol=1e-6), f"Expected {expected_value}, got {result}") + + +if __name__ == "__main__": + unittest.main() diff --git a/tests/pytorch_wrapper/pt_to_int8_test.py b/tests/pytorch_wrapper/pt_to_int8_test.py new file mode 100644 index 0000000..193eea9 --- /dev/null +++ b/tests/pytorch_wrapper/pt_to_int8_test.py @@ -0,0 +1,41 @@ +import os +import sys +import unittest +import torch + +PROJECT_ROOT = os.path.realpath(os.path.join(os.path.dirname(__file__), "..", "..")) +MODULE_ROOT = os.path.join(PROJECT_ROOT, "modules") +sys.path.append(MODULE_ROOT) + +from pytorch_wrapper.pt_to_int8 import PtToInt8 + + +class TestPtToInt8(unittest.TestCase): + def setUp(self): + """Set up test instance.""" + self.node = PtToInt8() + + # Test cases: (Tensor A, expected result, expected dtype) + self.test_cases = [ + (torch.tensor([1.0, 2.0, 3.0], dtype=torch.float32), torch.tensor([1, 2, 3], dtype=torch.int8), torch.int8), + ] + + def test_1(self): + """Test tensor element-wise square root using torch.sqrt().""" + for tens_a, expected_value, expected_dtype in self.test_cases: + with self.subTest(tens_a=tens_a): + result, = self.node.f(tens_a) + + # Ensure return value is a tensor + self.assertTrue(isinstance(result, torch.Tensor), "Output is not a tensor") + + # Ensure data type + self.assertEqual(result.dtype, expected_dtype, + f"Expected dtype {expected_dtype}, got {result.dtype}") + + # Ensure result matches expected values + self.assertTrue(torch.allclose(result, expected_value, atol=1e-6), f"Expected {expected_value}, got {result}") + + +if __name__ == "__main__": + unittest.main() diff --git a/tests/pytorch_wrapper/pt_to_uint8.py b/tests/pytorch_wrapper/pt_to_uint8.py new file mode 100644 index 0000000..5ccdcb7 --- /dev/null +++ b/tests/pytorch_wrapper/pt_to_uint8.py @@ -0,0 +1,41 @@ +import os +import sys +import unittest +import torch + +PROJECT_ROOT = os.path.realpath(os.path.join(os.path.dirname(__file__), "..", "..")) +MODULE_ROOT = os.path.join(PROJECT_ROOT, "modules") +sys.path.append(MODULE_ROOT) + +from pytorch_wrapper.pt_to_uint8 import PtToUint8 + + +class TestPtToUint8(unittest.TestCase): + def setUp(self): + """Set up test instance.""" + self.node = PtToUint8() + + # Test cases: (Tensor A, expected result, expected dtype) + self.test_cases = [ + (torch.tensor([1.0, 2.0, 3.0], dtype=torch.float32), torch.tensor([1, 2, 3], dtype=torch.uint8), torch.uint8), + ] + + def test_1(self): + """Test tensor element-wise square root using torch.sqrt().""" + for tens_a, expected_value, expected_dtype in self.test_cases: + with self.subTest(tens_a=tens_a): + result, = self.node.f(tens_a) + + # Ensure return value is a tensor + self.assertTrue(isinstance(result, torch.Tensor), "Output is not a tensor") + + # Ensure data type + self.assertEqual(result.dtype, expected_dtype, + f"Expected dtype {expected_dtype}, got {result.dtype}") + + # Ensure result matches expected values + self.assertTrue(torch.allclose(result, expected_value, atol=1e-6), f"Expected {expected_value}, got {result}") + + +if __name__ == "__main__": + unittest.main()