0
# Optimization Results
1
2
Container for maximum likelihood and maximum a posteriori estimation results. The CmdStanMLE class provides access to optimized parameter values and optimization iterations when available.
3
4
## Capabilities
5
6
### Parameter Access
7
8
Access optimized parameter estimates in multiple formats.
9
10
```python { .api }
11
def optimized_params_np(self):
12
"""
13
Get optimized parameters as NumPy array.
14
15
Returns:
16
np.ndarray: Final parameter estimates
17
"""
18
19
def optimized_params_pd(self):
20
"""
21
Get optimized parameters as pandas DataFrame.
22
23
Returns:
24
pd.DataFrame: Parameters with names as index
25
"""
26
27
def optimized_params_dict(self):
28
"""
29
Get optimized parameters as dictionary.
30
31
Returns:
32
dict: Mapping from parameter names to values
33
"""
34
35
def optimized_iterations_np(self):
36
"""
37
Get optimization iterations as NumPy array.
38
39
Returns:
40
np.ndarray or None: Iteration history if save_iterations=True
41
"""
42
43
def optimized_iterations_pd(self):
44
"""
45
Get optimization iterations as pandas DataFrame.
46
47
Returns:
48
pd.DataFrame or None: Iteration history if save_iterations=True
49
"""
50
```
51
52
### Variable Access
53
54
Access individual Stan variables with automatic type handling.
55
56
```python { .api }
57
def stan_variable(self, var, inc_iter=False):
58
"""
59
Get value for specific Stan variable.
60
61
Parameters:
62
- var (str): Variable name
63
- inc_iter (bool): Include optimization iterations if available
64
65
Returns:
66
float or np.ndarray: Variable value with original Stan dimensions
67
"""
68
69
def stan_variables(self, inc_iter=False):
70
"""
71
Get all Stan variables as dictionary.
72
73
Parameters:
74
- inc_iter (bool): Include optimization iterations if available
75
76
Returns:
77
dict: Mapping from variable names to values
78
"""
79
```
80
81
### File Operations
82
83
```python { .api }
84
def save_csvfiles(self, dir=None):
85
"""
86
Save CSV output files to directory.
87
88
Parameters:
89
- dir (str or PathLike, optional): Target directory
90
91
Returns:
92
None
93
"""
94
```
95
96
## Properties
97
98
```python { .api }
99
# Results information
100
mle.column_names # Tuple[str, ...]: Parameter names
101
mle.metadata # InferenceMetadata: Run configuration and timing
102
```
103
104
## Usage Examples
105
106
```python
107
# Run optimization
108
mle = model.optimize(data=data, algorithm="lbfgs", iter=1000)
109
110
# Access results in different formats
111
params_dict = mle.optimized_params_dict()
112
print(f"MLE estimate for theta: {params_dict['theta']}")
113
114
# Get specific variables
115
theta_mle = mle.stan_variable("theta")
116
sigma_mle = mle.stan_variable("sigma")
117
118
# Save results
119
mle.save_csvfiles(dir="./mle_results")
120
```