fit
¶
Neural fitting module.
Functions:
Name | Description |
---|---|
neural_fit |
Neural fitting function with JMP-like capabilities. |
neural_fit_equations |
Convert neural fit result to symbolic equations. |
write_neural_fit_functions |
Write neural fit as a python function. |
Attributes:
Name | Type | Description |
---|---|---|
NeuralFitResult |
Complete result from neural_fit function. |
|
PRNGKey |
TypeAlias
|
The jax.PRNGKey used to generate random weights and biases. |
Params |
Parameters for a single layer in the neural network. |
NeuralFitResult
module-attribute
¶
NeuralFitResult = TypedDict(
"NeuralFitResult",
{
"params": list[Params],
"features": list[str],
"targets": list[str],
"hidden_dims": tuple[int, ...],
"forward_fn": Callable,
"predict_fn": Callable,
"activation_fn": Callable,
"X_norm": Normalization,
"Y_norm": Normalization,
"learning_rate": float,
"num_epochs": int,
"final_loss": float,
},
)
Complete result from neural_fit function.
Attributes:
Name | Type | Description |
---|---|---|
params |
Trained model parameters. |
PRNGKey
module-attribute
¶
The jax.PRNGKey used to generate random weights and biases.
Params
module-attribute
¶
Parameters for a single layer in the neural network.
Attributes:
Name | Type | Description |
---|---|---|
w |
Weights for the layer. |
|
b |
Biases for the layer. |
create_network
¶
create_network(
input_dim: int,
hidden_dims: tuple[int, ...],
output_dim: int,
activation_fn: Callable,
) -> tuple[Callable, Callable]
Create a neural network function.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
input_dim
|
int
|
Number of input features. |
required |
hidden_dims
|
tuple[int, ...]
|
Tuple of hidden layer dimensions. |
required |
output_dim
|
int
|
Number of output dimensions. |
required |
activation_fn
|
Callable
|
Activation function to use. |
required |
Returns:
Type | Description |
---|---|
tuple[Callable, Callable]
|
Tuple of (parameter initialization function, forward function). |
Source code in src/sax/fit.py
neural_fit
¶
neural_fit(
data: DataFrame,
targets: list[str],
features: list[str] | None = None,
hidden_dims: tuple[int, ...] = (10,),
learning_rate: float = 0.003,
num_epochs: int = 1000,
random_seed: int = 42,
*,
activation_fn: Callable = tanh,
loss_fn: Callable = mse,
progress_bar: bool = True,
) -> NeuralFitResult
Neural fitting function with JMP-like capabilities.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
data
|
DataFrame
|
Input data with features and target. |
required |
targets
|
list[str]
|
Names of the target columns. |
required |
features
|
list[str] | None
|
Names of the feature columns. If None, uses all numeric columns except target columns. |
None
|
hidden_dims
|
tuple[int, ...]
|
Hidden layer dimensions, e.g., (10, 5) for two hidden layers. |
(10,)
|
learning_rate
|
float
|
Learning rate for optimization. |
0.003
|
num_epochs
|
int
|
Number of training epochs per tour. |
1000
|
random_seed
|
int
|
Random seed for reproducibility. |
42
|
activation_fn
|
Callable
|
The activation function to use in the network. |
tanh
|
loss_fn
|
Callable
|
The loss function to use for training. |
mse
|
progress_bar
|
bool
|
Whether to show a progress bar during training. |
True
|
Returns:
Type | Description |
---|---|
NeuralFitResult
|
Dictionary containing trained model data |
Raises:
Type | Description |
---|---|
RuntimeError
|
If all training tours fail. |
Source code in src/sax/fit.py
33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 |
|
neural_fit_equations
¶
neural_fit_equations(result: NeuralFitResult) -> dict[str, Equation]
Convert neural fit result to symbolic equations.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
result
|
NeuralFitResult
|
Result from neural_fit function. |
required |
Returns:
Type | Description |
---|---|
dict[str, Equation]
|
Dictionary mapping target names to symbolic equations. |
Source code in src/sax/fit.py
train_network
¶
train_network(
X_norm: Array,
Y_norm: Array,
init_fn: Callable[..., list[Params]],
forward_fn: Callable,
key: PRNGKey,
learning_rate: float = 0.01,
num_epochs: int = 1000,
*,
progress_bar: bool = True,
loss_fn: Callable = mse,
) -> tuple[list, list[float]]
Train the neural network with validation.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
X_norm
|
Array
|
Normalized input features. |
required |
Y_norm
|
Array
|
Normalized target values. |
required |
init_fn
|
Callable[..., list[Params]]
|
Parameter initialization function. |
required |
forward_fn
|
Callable
|
Forward pass function. |
required |
key
|
PRNGKey
|
JAX random key. |
required |
learning_rate
|
float
|
Learning rate for optimizer. |
0.01
|
num_epochs
|
int
|
Number of training epochs. |
1000
|
progress_bar
|
bool
|
Whether to show a progress bar during training. |
True
|
loss_fn
|
Callable
|
Loss function to use for training. |
mse
|
Returns:
Type | Description |
---|---|
tuple[list, list[float]]
|
Tuple of (best parameters, training history). |
Source code in src/sax/fit.py
write_neural_fit_functions
¶
write_neural_fit_functions(
result: NeuralFitResult, *, with_imports: bool = True, path: Path | None = None
) -> None
Write neural fit as a python function.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
result
|
NeuralFitResult
|
Result from neural_fit function. |
required |
with_imports
|
bool
|
Whether to include import statements in the output. |
True
|
path
|
Path | None
|
Path to write the function to. If None, writes to stdout. |
None
|