Argmax 1.0.0

dotnet add package Argmax --version 1.0.0
                    
NuGet\Install-Package Argmax -Version 1.0.0
                    
This command is intended to be used within the Package Manager Console in Visual Studio, as it uses the NuGet module's version of Install-Package.
<PackageReference Include="Argmax" Version="1.0.0" />
                    
For projects that support PackageReference, copy this XML node into the project file to reference the package.
<PackageVersion Include="Argmax" Version="1.0.0" />
                    
Directory.Packages.props
<PackageReference Include="Argmax" />
                    
Project file
For projects that support Central Package Management (CPM), copy this XML node into the solution Directory.Packages.props file to version the package.
paket add Argmax --version 1.0.0
                    
#r "nuget: Argmax, 1.0.0"
                    
#r directive can be used in F# Interactive and Polyglot Notebooks. Copy this into the interactive tool or source code of the script to reference the package.
#:package Argmax@1.0.0
                    
#:package directive can be used in C# file-based apps starting in .NET 10 preview 4. Copy this into a .cs file before any lines of code to reference the package.
#addin nuget:?package=Argmax&version=1.0.0
                    
Install as a Cake Addin
#tool nuget:?package=Argmax&version=1.0.0
                    
Install as a Cake Tool

Argmax

Gradient-free population-based optimization for .NET — Genetic Algorithm, CMA-ES with BIPOP restart, and Differential Evolution with jDE self-adaptation.

CI NuGet

Install

dotnet add package Argmax

Quick Start

Optimize a two-variable Rosenbrock function (minimum at x=1, y=1) using CMA-ES:

using Argmax;
using Argmax.CmaEs;

var ranges = new[]
{
    new ParameterRange("x", null, -5.0, 5.0, 0.01),
    new ParameterRange("y", null, -5.0, 5.0, 0.01),
};

var optimizer = new CmaEsOptimizer(ranges, new CmaEsSettings());

// Optimizer.Run maximizes fitness, so negate the Rosenbrock value
var best = Optimizer.Run(optimizer, candidate =>
{
    var x = candidate.Get("x");
    var y = candidate.Get("y");
    return -(100.0 * (y - x * x) * (y - x * x) + (1.0 - x) * (1.0 - x));
});

Console.WriteLine($"Best: x={best.Get("x"):F3}, y={best.Get("y"):F3}");
// Best: x=1.000, y=1.000

Optimizer.Run handles the generate-evaluate-evolve loop. Swap CmaEsOptimizer for GeneticAlgorithmOptimizer or DifferentialEvolutionOptimizer with no other changes.

Manual Loop

For full control — progress reporting, early stopping, custom logging:

using Argmax;
using Argmax.GeneticAlgorithm;

var ranges = new[]
{
    new ParameterRange("learningRate", "model", 0.001, 0.1,  0.001),
    new ParameterRange("maxDepth",     "model", 3.0,   12.0, 1.0),
    new ParameterRange("dropout",      "model", 0.0,   0.5,  0.05),
};

var optimizer = new GeneticAlgorithmOptimizer(ranges, new GeneticAlgorithmSettings
{
    PopulationSize = 60,
    Generations    = 30,
});

var population = optimizer.GenerateInitialPopulation();

while (!optimizer.IsComplete)
{
    var evaluated = population
        .Select(p => new EvaluatedCandidate(p, EvaluateModel(p)))
        .ToList();

    population = optimizer.Evolve(evaluated);
}

static double EvaluateModel(ParameterSet p)
{
    // run your backtest, ML training, simulation, or benchmark here
    return 0.0;
}

The loop is identical regardless of which optimizer you use. The interface is:

public interface IPopulationOptimizer
{
    int ActualSeed { get; }                                                          // for reproducibility
    IReadOnlyList<ParameterSet> GenerateInitialPopulation();
    IReadOnlyList<ParameterSet> Evolve(IReadOnlyList<EvaluatedCandidate> evaluated);
    bool IsComplete { get; }
}

Two-Phase Refinement

For large search spaces, run a broad phase first, then narrow around the best results:

using Argmax;
using Argmax.DifferentialEvolution;

var ranges = new[]
{
    new ParameterRange("x", null, -10.0, 10.0, 0.1),
    new ParameterRange("y", null, -10.0, 10.0, 0.1),
};

// Phase 1 — broad exploration
var phase1 = new DifferentialEvolutionOptimizer(ranges, new DeSettings { MaxGenerations = 50 });
var best1 = Optimizer.Run(phase1, Evaluate);

// Narrow around top results (keep top 10 candidates, narrow by 20%)
var topResults = new[] { best1 };   // collect more via manual loop if needed
var narrowedRanges = RefinementNarrower.Narrow(ranges, topResults, narrowingPercent: 20);

// Phase 2 — fine-grained search in the narrowed space
var phase2 = new DifferentialEvolutionOptimizer(narrowedRanges, new DeSettings { MaxGenerations = 50 });
var best2 = Optimizer.Run(phase2, Evaluate);

static double Evaluate(ParameterSet p) => -(p.Get("x") * p.Get("x") + p.Get("y") * p.Get("y"));

Progress Reporting

var progress = new Progress<OptimizationProgress>(p =>
    Console.WriteLine($"Gen {p.Generation}: best={p.BestFitness:F4}, pop={p.PopulationSize}"));

var best = Optimizer.Run(optimizer, Evaluate, progress: progress);

Algorithm Comparison

Genetic Algorithm CMA-ES Differential Evolution
Landscape type Separable, discrete Ill-conditioned, correlated Noisy, mixed
Termination Fixed generations Self-terminating Fixed generations
Parameter tuning Moderate Minimal (auto pop-size) None with jDE
Per-gen cost Low Medium (eigendecomp) Low
Restart strategy None BIPOP (built-in) None
Discrete params Native Via quantization Native

Algorithm Selection Guide

GA (GeneticAlgorithmOptimizer) — Choose when your search space has many discrete or mixed parameters, you want SBX crossover and elitism, or you need a fixed generation budget.

CMA-ES (CmaEsOptimizer) — Choose when parameters are correlated (tight coupling between two or more parameters), the landscape is ill-conditioned or rotated, you want self-termination rather than a fixed budget, or you need BIPOP restart for multi-modal problems. This is the only CMA-ES + BIPOP implementation on NuGet.

DE (DifferentialEvolutionOptimizer) — Choose when evaluations are noisy, the space is high-dimensional (tens of parameters), or you want zero tuning. jDE self-adaptation handles F and CR automatically — no manual configuration required.

Thread Safety

IPopulationOptimizer implementations are not thread-safe. Do not share a single optimizer instance across threads.

For independent parallel runs (e.g., different random seeds), create a separate optimizer per thread:

using Argmax;
using Argmax.CmaEs;

var seeds = new[] { 1, 2, 3, 4 };

var tasks = seeds.Select(seed => Task.Run(() =>
{
    var optimizer = new CmaEsOptimizer(ranges, new CmaEsSettings(), seed: seed);
    return Optimizer.Run(optimizer, Evaluate);
})).ToArray();

var results = await Task.WhenAll(tasks);
var best = results.MaxBy(p => Evaluate(p));

For parallel evaluation within a single run (evaluate multiple candidates concurrently), use PLINQ in your evaluation function — the optimizer itself is called sequentially:

var evaluated = population
    .AsParallel()
    .Select(p => new EvaluatedCandidate(p, Evaluate(p)))
    .ToList();

Supported Frameworks

  • netstandard2.0 — .NET Framework 4.6.1+, Mono, Unity, Xamarin
  • net9.0 — .NET 9+

License

Apache-2.0 — see LICENSE for details.

Product Compatible and additional computed target framework versions.
.NET net5.0 was computed.  net5.0-windows was computed.  net6.0 was computed.  net6.0-android was computed.  net6.0-ios was computed.  net6.0-maccatalyst was computed.  net6.0-macos was computed.  net6.0-tvos was computed.  net6.0-windows was computed.  net7.0 was computed.  net7.0-android was computed.  net7.0-ios was computed.  net7.0-maccatalyst was computed.  net7.0-macos was computed.  net7.0-tvos was computed.  net7.0-windows was computed.  net8.0 was computed.  net8.0-android was computed.  net8.0-browser was computed.  net8.0-ios was computed.  net8.0-maccatalyst was computed.  net8.0-macos was computed.  net8.0-tvos was computed.  net8.0-windows was computed.  net9.0 is compatible.  net9.0-android was computed.  net9.0-browser was computed.  net9.0-ios was computed.  net9.0-maccatalyst was computed.  net9.0-macos was computed.  net9.0-tvos was computed.  net9.0-windows was computed.  net10.0 was computed.  net10.0-android was computed.  net10.0-browser was computed.  net10.0-ios was computed.  net10.0-maccatalyst was computed.  net10.0-macos was computed.  net10.0-tvos was computed.  net10.0-windows was computed. 
.NET Core netcoreapp2.0 was computed.  netcoreapp2.1 was computed.  netcoreapp2.2 was computed.  netcoreapp3.0 was computed.  netcoreapp3.1 was computed. 
.NET Standard netstandard2.0 is compatible.  netstandard2.1 was computed. 
.NET Framework net461 was computed.  net462 was computed.  net463 was computed.  net47 was computed.  net471 was computed.  net472 was computed.  net48 was computed.  net481 was computed. 
MonoAndroid monoandroid was computed. 
MonoMac monomac was computed. 
MonoTouch monotouch was computed. 
Tizen tizen40 was computed.  tizen60 was computed. 
Xamarin.iOS xamarinios was computed. 
Xamarin.Mac xamarinmac was computed. 
Xamarin.TVOS xamarintvos was computed. 
Xamarin.WatchOS xamarinwatchos was computed. 
Compatible target framework(s)
Included target framework(s) (in package)
Learn more about Target Frameworks and .NET Standard.
  • .NETStandard 2.0

    • No dependencies.
  • net9.0

    • No dependencies.

NuGet packages

This package is not used by any NuGet packages.

GitHub repositories

This package is not used by any popular GitHub repositories.

Version Downloads Last Updated
1.0.0 146 3/29/2026
0.1.0-beta.1 62 3/29/2026