Skip to main content
Version: 0.2.0

Choosing a network size

NeuralFoil comes in eight sizes, all trained on the same data. They differ only in the depth and width of the network, which trades accuracy for speed. The Bora repository includes the weights of all eight, converted from NeuralFoil's weight files.

use bora::{ModelSize, NeuralFoil};

let model = NeuralFoil::new(ModelSize::Large)?;

ModelSize::default() is XLarge, the default of NeuralFoil itself, where its authors place the knee of the speed-accuracy curve (Sharpe and Hansman, 2025).

Accuracy​

The table reproduces the accuracy NeuralFoil's authors measured for each network against XFoil on a held-out test set of 395,665 cases that the networks never saw in training. Bora evaluates the same networks and matches Python NeuralFoil on reference cases, so these figures carry over unchanged.

Network sizes and mean absolute error against XFoil on NeuralFoil's test set. Data from Sharpe and Hansman (2025).

ModelSizeHidden layersWidthCLC_Lln⁡CD\ln C_DCMC_Mxtr/cx_{tr}/c
XXSmall2480.0400.0780.0070.044
XSmall3480.0300.0570.0050.033
Small3640.0270.0500.0050.027
Medium4640.0200.0390.0030.020
Large41280.0160.0300.0030.014
XLarge51280.0130.0240.0020.010
XXLarge52560.0120.0220.0020.009
XXXLarge65120.0120.0200.0020.007

An error in ln⁡CD\ln C_D reads as a relative error in drag: 0.024 means the drag is typically within about 2.4% of XFoil's.

Two cautions from the same source. The test set is deliberately hard, with many post-stall and transition-sensitive cases; on ordinary attached-flow cases the paper reports a mean drag error of 0.37% for the largest network. And all of these are errors against XFoil, not against experiment.

Speed​

Time per call in Bora, in microseconds, measured with cargo bench on an Apple M1 Pro. Run cargo bench to time your own machine.

Time per call in microseconds for each network size (Apple M1 Pro, one thread). The columns are, in order, analyze, analyze_scalars, analyze_with_gradients and analyze_scalars_with_gradients.

ModelSizeAll outputsScalarsAll outputs with gradientsScalars with gradients
XXSmall5.02.3577.0
XSmall6.03.1669.8
Small7.84.49614
Medium9.35.910719
Large231726757
XLarge272232272
XXLarge84731,020247
XXXLarge3563314,4801,130

Cost rises steeply with width, because the work is dominated by products with width-by-width weight matrices: doubling the width of the five-layer network from XLarge to XXLarge triples the time.

Which one​

Start with XLarge. It is within a small margin of the largest network's accuracy at a thirteenth of its cost.

Go smaller when the analysis sits in a tight inner loop and a few percent of drag accuracy is not the limiting error: early design-space exploration, or sectional data inside a low-order wing method. Medium is three times faster than XLarge.

Go larger with care. XXLarge and XXXLarge buy little accuracy against XFoil for a large cost. NeuralFoil's documentation also observes that larger networks follow XFoil's small-scale irregularities more closely, which can make their outputs less smooth for a gradient-based optimizer, while being better able to represent the odd shapes an optimizer passes through (Sharpe, 2023). If an optimization behaves poorly at one size, trying a neighboring size is a cheap experiment.

A model is immutable once loaded, so nothing stops you holding two: a small one for exploration and a larger one to confirm the result.

Names​

Each size has a lower-case name matching NeuralFoil's ("xlarge"), used in weight file names and in the Philote discipline's options. as_str(), Display and FromStr convert between the two, and ModelSize::ALL lists every size from smallest to largest:

let size: bora::ModelSize = "large".parse()?;
assert_eq!(size.to_string(), "large");

for size in bora::ModelSize::ALL {
println!("{size}");
}

Parsing an unknown name returns Error::InvalidArgument.