Repository navigation
Module_Examples
The Examples/ folder at the repository root contains standalone runnable sample projects. These projects reference the main library Vorcyc.Mathematics (targets/dotNET10_Portable) and demonstrate how to use each module's API in real-world scenarios; they are not included in the NuGet package and must be built and run from source.
| Project | Path | Primary Modules | Description |
|---|---|---|---|
| Audio WAV + MFCC | Examples/Audio_example/ |
SignalProcessing, DeepLearning, NAudio | NAudio read/write WAV, MFCC analysis, training and inference |
| Core / linear algebra / statistics | Examples/Core_example/ |
ComputingContext, LinearAlgebra, Statistics | MatrixFp32 multiply, Span statistics, VectorSpan, scope resolution |
| Machine learning | Examples/MachineLearning_example/ |
MachineLearning | 0.9 classification/regression pipelines, trees/forests, ensemble learning, CV/grid search |
| Image colorization | Examples/Colorization_example/ |
DeepLearning, LinearAlgebra | ColorNet / ChromaGAN black-and-white image colorization |
| Signal processing | Examples/SignalProcessing_example/ |
SignalProcessing | Signal synthesis, FFT, filtering, MFCC, effects, parallel features |
| Deep learning | Examples/DeepLearning_example/ |
DeepLearning | XOR/batch training/CNN+MLP/audio classification, serialization, MlpRegressor curve fitting |
| Calculus | Examples/Calculus_example/ |
Calculus | Integration, derivatives, ODE, root finding, series |
📒Contents
- 🔖 Directory Layout Convention
- 🔖 Audio_example — NAudio Audio Pipeline
- 🔖 Core_example — Core and ComputingContext
- 🔖 MachineLearning_example — Tabular Learning
- 🔖 Colorization_example — Image Colorization
- 🔖 SignalProcessing_example — Signal Processing
- 🔖 DeepLearning_example — Deep Learning
- 🔖 Calculus_example — Calculus
Examples/
└── <example_name>_example/
├── <example_name>_example.csproj # References dotNET10_Portable
├── Program.cs # CLI entry point
├── models/ # Exported .vmdl (optional, copied to output on build)
└── … # Model definitions, serialization, image I/O, etc.
When adding a new example:
- Create a standalone
.csprojunderExamples/withTargetFrameworkmatching the main library (net10.0). - Add the project to the
/Examples/folder inVorcyc.Mathematics.slnx. - Append a row to the table on this page and add a corresponding section.
End-to-end demo: NAudio read/write WAV → Vorcyc Signal → MFCC → BatchSequential training/inference. Closer to real projects than the audio command in DeepLearning_example (.wav files on disk rather than in-memory synthesized waves).
| Package | Version | Purpose |
|---|---|---|
NAudio |
2.2.1 |
AudioFileReader / WaveFileWriter read/write channel WAV |
Vorcyc.Mathematics |
Project reference | Signal, MFCC, AudioTrainingSamples, ModelSerializer
|
# Full pipeline: generate demo WAV → train → analyze → infer
dotnet run --project Examples/Audio_example
dotnet run --project Examples/Audio_example -- prepare
dotnet run --project Examples/Audio_example -- analyze data/class_low/tone_220hz.wav
dotnet run --project Examples/Audio_example -- analyze my.wav --csv mfcc.csv
dotnet run --project Examples/Audio_example -- train --epochs 3000
dotnet run --project Examples/Audio_example -- predict data/class_high/tone_1200hz.wav
dotnet run --project Examples/Audio_example -- helpData directory (default under output directory bin/.../net10.0/data/):
data/
├── class_low/ # Label low: low-frequency demo tones (replace with your own WAV files)
└── class_high/ # Label high: high-frequency demo tones
models/
└── pitch_mfcc.vmdl # BatchSequential weights saved after train
Examples/Audio_example/
├── Program.cs
├── PitchClassifierConfig.cs
├── Io/
│ └── WavBridge.cs # NAudio ↔ Signal (with resampling)
└── Pipeline/
├── DemoDataFactory.cs # Generate 16-bit PCM demo WAV
├── LabeledWavDataset.cs # Load labeled dataset by folder
├── MfccFileAnalyzer.cs # analyze: RMS / FFT / MFCC
└── PitchClassifierTrainer.cs # train / predict + ModelSerializer
Audio_example |
DeepLearning_example -- audio |
|
|---|---|---|
| Input | Disk WAV (NAudio) | In-memory GenerateWave
|
| External dependencies | NAudio | None |
| Model persistence |
.vmdl save/load |
None |
| Best for | File I/O + deployed inference | Quick API wiring validation |
Demonstrates ComputingContext, MatrixFp32.Multiply, Span statistics extensions, and VectorSpan hot-path APIs. No extra NuGet packages; runs cross-platform. Complements the Module_ComputingContext manual.
dotnet run --project Examples/Core_example
dotnet run --project Examples/Core_example -- matrix
dotnet run --project Examples/Core_example -- statistics
dotnet run --project Examples/Core_example -- vector
dotnet run --project Examples/Core_example -- context
dotnet run --project Examples/Core_example -- helpExamples/Core_example/
├── Program.cs
├── MatrixDemo.cs # MatrixFp32.Multiply + ComputingScope
├── StatisticsDemo.cs # Sum / Average / StandardDeviation
├── VectorDemo.cs # Dot / Norm / Axpy
└── ComputingContextDemo.cs # Explicit parameters vs Scope priority
Demonstrates typical 0.9 machine learning module workflows: synthetic three-cluster 2D data, DataSplit partitioning, training and evaluation with multiple IClassifier<double> implementations, ClassificationPipeline, grid search and K-fold cross-validation, plus regression pipeline examples. No extra NuGet dependencies; runs cross-platform.
# Overview (default): classification + regression
dotnet run --project Examples/MachineLearning_example
# Classification only
dotnet run --project Examples/MachineLearning_example -- classify
# Regression: KnnRegressor, RegressionPipeline batch prediction, ridge regression, K-fold CV
dotnet run --project Examples/MachineLearning_example -- regression
dotnet run --project Examples/MachineLearning_example -- helpExamples/MachineLearning_example/
├── Program.cs # classify / regression CLI
├── BlobDataset.cs # Three-cluster synthetic classification data
└── RegressionDataset.cs # Synthetic regression data
For batch inference performance comparison, see `benchmarks/basic_benchmark/MachineLearning_batch_benchmark.cs` (uncomment in `Program.cs` to run).
Full API documentation and copy-paste snippets: Machine Learning Module — 0.9 classifier walkthrough.
Colorizes grayscale or color photos, ported from the NeuralColor / Colorization approach in Vorcyc.AwesomeAI, rewritten with the 0.9 DeepLearning Modules API (Convolution2DLayer, BatchNormLayer, ReLUActivation, etc.) and custom model containers; image I/O uses Emgu.CV.
| Scenario | CLI --scenario
|
Network | Best for |
|---|---|---|---|
| Realistic |
realistic (default) |
ColorNet | Landscapes, architecture, natural scenes |
| People | people |
ChromaGAN | Portraits, group photos |
Both networks use dual-branch or encode-fusion structures that cannot be described by a single BatchSequential, so the sample project implements ColorNetModel / ChromaGanModel; weights are saved via sample-specific serializers as VMDL v3 variants (ModelKind = 4 / 5, see VmdlTensorArchive).
| File | Format | Description |
|---|---|---|
*.HModel |
Half-precision binary (legacy) | Original ColorfulSoft weights |
*.vmdl |
VMDL v3 (float64 tensors) | Exported new format used for inference |
Default paths (overridable on the command line):
- ColorNet:
models/Colornet.vmdl, legacy modelmodel_zoo/vision/colorization/Colornet.HModel - ChromaGAN:
models/ChromaGAN.vmdl, legacy modelmodel_zoo/vision/colorization/ChromaGAN.HModel
In addition to the main library, the sample project references:
| Package | Version | Purpose |
|---|---|---|
Emgu.CV |
4.9.0.5494 | Read images, resize, color spaces |
Emgu.CV.runtime.windows |
4.9.0.5494 | Windows native OpenCV runtime |
Runtime must be Windows (Emgu runtime package). On Linux/macOS, replace with the corresponding Emgu runtime or rewrite image I/O.
If you only have .HModel, export to .vmdl first:
cd Examples/Colorization_example
# ColorNet
dotnet run -- export colornet <Colornet.HModel path> models/Colornet.vmdl
# ChromaGAN
dotnet run -- export chromagan <ChromaGAN.HModel path> models/ChromaGAN.vmdlExport flow: half-precision decode (Legacy/HalfHelper) → populate ColorNetModel / ChromaGanModel Parameter → ColorNetSerializer / ChromaGanSerializer write VMDL.
If the target .vmdl does not exist when running colorize and the corresponding .HModel exists at the default path, the program auto-exports before inference.
# Realistic colorization (ColorNet)
dotnet run --project Examples/Colorization_example -- colorize photo.jpg result.jpg --scenario realistic
# People colorization (ChromaGAN)
dotnet run --project Examples/Colorization_example -- colorize photo.jpg result.jpg --scenario people
# Specify model file
dotnet run --project Examples/Colorization_example -- colorize photo.jpg out.jpg --scenario people --model models/ChromaGAN.vmdlCommand summary
| Command | Description |
|---|---|
export <colornet|chromagan> [hmodel] [vmdl] |
Legacy weights → VMDL |
colorize <image> [output] [--scenario realistic|people] [--model path] |
Colorize and save JPEG |
Examples/Colorization_example/
├── Program.cs # export / colorize CLI
├── ColorizationEnhancer.cs # Unified entry (Scenario + model loading)
├── Models/
│ ├── ColorNetModel.cs # ColorNet forward (Modules API)
│ ├── ChromaGanModel.cs # ChromaGAN forward
│ ├── SpatialLinearLayer.cs # GFN / global2 spatial fully connected
│ └── ModelWeightUtils.cs # Weight copy helpers
├── Legacy/
│ ├── HalfHelper.cs # half → float
│ ├── HModelReader.cs # ColorNet HModel
│ └── HModelChromaGanReader.cs
├── Serialization/
│ ├── VmdlTensorArchive.cs # Shared VMDL tensor read/write
│ ├── ColorNetSerializer.cs # ModelKind = 4
│ └── ChromaGanSerializer.cs # ModelKind = 5
└── Vision/
├── ColorNetIo.cs # Emgu preprocessing / LAB compositing
└── ChromaGanIo.cs
Programmatic usage example
using Colorization_example;
using Emgu.CV;
using var enhancer = new ColorizationEnhancer(
ColorizationEnhancer.Scenario.RealisticView,
@"models/Colornet.vmdl");
using var input = new Mat(@"photo.jpg");
using var output = enhancer.Colorize(input);
CvInvoke.Imwrite(@"result.jpg", output);| Capability | Main library ModelSerializer v3 |
This sample |
|---|---|---|
| Supported containers |
Sequential, BatchSequential, CnnMlp, BatchParallelConcat
|
Custom ColorNetModel / ChromaGanModel
|
| Layer API | Modules.* |
Same + legacy Layers.JoinLayer / Fusion / Upsample2D
|
| Serialization | Architecture LayerDescriptor + weights |
Fixed topology; read/write named tensors in order |
Full training stack documentation: Deep Learning Module. This sample demonstrates inference and legacy weight migration only; to train similar networks, implement Forward / Backward on top of main library containers or extend ModelSerializer.
Demonstrates 0.9 Signal main API: waveform synthesis, TransformToFrequencyDomain, Butterworth low-pass, MfccExtractor (HTK preset), and TremoloEffect. No extra NuGet packages; runs cross-platform.
dotnet run --project Examples/SignalProcessing_example
dotnet run --project Examples/SignalProcessing_example -- synth
dotnet run --project Examples/SignalProcessing_example -- fft
dotnet run --project Examples/SignalProcessing_example -- filter
dotnet run --project Examples/SignalProcessing_example -- mfcc --csv mfcc.csv
dotnet run --project Examples/SignalProcessing_example -- effect
dotnet run --project Examples/SignalProcessing_example -- context
dotnet run --project Examples/SignalProcessing_example -- helpExamples/SignalProcessing_example/
├── Program.cs
├── SynthDemo.cs
├── FftDemo.cs
├── FilterDemo.cs
├── MfccDemo.cs
├── EffectDemo.cs
└── ContextDemo.cs # GetRms, ParallelComputeFrom(MFCC)
FftDemo and ContextDemo demonstrate ComputingContext / ComputingScope (FFT, RMS, parallel MFCC).
Demonstrates the differentiable training stack: Sequential / BatchSequential + Trainer (XOR, batch XOR, CNN+MLP, MFCC audio classification), computingContext parameters, ModelSerializer v3 round-trip, and MlpRegressor (DeepLearning.Training) curve fitting (y=x^2).
dotnet run --project Examples/DeepLearning_example
dotnet run --project Examples/DeepLearning_example -- xor
dotnet run --project Examples/DeepLearning_example -- classify
dotnet run --project Examples/DeepLearning_example -- batch
dotnet run --project Examples/DeepLearning_example -- cnn
dotnet run --project Examples/DeepLearning_example -- audio
dotnet run --project Examples/DeepLearning_example -- serialize
dotnet run --project Examples/DeepLearning_example -- curvefit
dotnet run --project Examples/DeepLearning_example -- help| Command | Highlights |
|---|---|
batch |
FitBatched + ComputingContext.Parallel
|
cnn |
CnnMlpModel + FitCnnMlp (4×4 left/right patterns) |
audio |
AudioTrainingSamples.FeatureMeanClassification + FitBatchSequential
|
Examples/DeepLearning_example/
├── Program.cs
├── XorDemo.cs
├── ClassifyDemo.cs
├── BatchTrainDemo.cs
├── CnnMlpDemo.cs
├── AudioClassifyDemo.cs
├── SerializeDemo.cs
└── CurveFitDemo.cs
Demonstrates numerical integration (trapezoidal / Romberg / Gauss-Legendre), derivatives and gradients, RK4 ODE solving, Newton/Brent root finding, and Taylor / Fourier series.
dotnet run --project Examples/Calculus_example
dotnet run --project Examples/Calculus_example -- integrate
dotnet run --project Examples/Calculus_example -- derivative
dotnet run --project Examples/Calculus_example -- ode
dotnet run --project Examples/Calculus_example -- root
dotnet run --project Examples/Calculus_example -- series
dotnet run --project Examples/Calculus_example -- helpExamples/Calculus_example/
├── Program.cs
├── IntegrationDemo.cs
├── DerivativeDemo.cs
├── OdeDemo.cs
├── RootFindingDemo.cs
└── SeriesDemo.cs
-
- 🔖 ArrayExtension class
- 🔖 BaseConverter class
- 🔖 BitMathExtension class
- 🔖 Combinatorics class
- 🔖 ConstantsFp32 class
- 🔖 NumberMapper class
- 🔖 PinnableArray<T> class
- 🔖 SimpleRNG_Fp32 and SimpleRNG_Fp64 classes
- 🔖 TrigonometryHelper class
- 🔖 VMath class
- 🔖 Pinned buffers (Buffers)
- 🔖 IPinnedBuffer<T> interface
- 🔖 POHBuffer<T> class
- 🔖 NativeBuffer<T> class
-
- 🔖 0.9 classifier walkthrough
- 🔖 KNN<T> class
- 🔖 MultipleLinearRegression<T> class
- 🔖 SimpleLinearRegression<T> class
- 🔖 SupportVectorMachine<TSelf> class
- 🔖 DBSCAN<T> class
- 🔖 ExpectationMaximization<T> class
- 🔖 GMM<T> class
- 🔖 HierarchicalClustering<T> class
- 🔖 KMeansClusterer<T> class
- 🔖 VectorQuantization<T> class
- 🔖 FactorAnalysis<T> class
- 🔖 PCA<TSelf> class
- 🔖 TSNE<T> class
- 🔖 Distance metric classes
-
📒 Examples
-
📒 GPU 策略说明
- 🔖 为何放弃主包 GPU
- 🔖 当前性能路径
- 🔖 若仍需要更强算力
-
📒 计算上下文模块
-
📒 核心模块
-
📒 深度学习模块
-
📒 线性代数模块
-
📒 机器学习模块
- 🔖 0.9 分类器完整示例
- 🔖 KNN<T> 类
- 🔖 MultipleLinearRegression<T> 类
- 🔖 SimpleLinearRegression<T> 类
- 🔖 SupportVectorMachine<TSelf> 类
- 🔖 DBSCAN<T> 类
- 🔖 ExpectationMaximization<T> 类
- 🔖 GMM<T> 类
- 🔖 HierarchicalClustering<T> 类
- 🔖 KMeansClusterer<T> 类
- 🔖 VectorQuantization<T> 类
- 🔖 FactorAnalysis<T> 类
- 🔖 PCA<TSelf> 类
- 🔖 TSNE<T> 类
- 🔖 距离度量类
-
📒 信号处理模块
-
📒 数值模块
-
📒 统计模块
- 🔖 基础统计函数
- 🔖 高级统计函数
- 🔖 稳健统计 / RunningMoments
- 🔖 其它统计函数
- 🔖 分布相关函数
- 🔖 时间序列分析
- 🔖 IComparable 扩展
- 🔖 ExtremeValueFinder
- 🔖 INumber 扩展
-
📒 FFTW 扩展
-
📒 示例