File size: 21,797 Bytes
0a6452f
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
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
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
# API Reference
(Google Gemini Translation)

This document provides a detailed description of all API interfaces, classes, and functions for the emotion and physiological state change prediction model.

## Table of Contents

1. [Model Classes](#model-classes)
2. [Data Processing Classes](#data-processing-classes)
3. [Utility Classes](#utility-classes)
4. [Loss Functions](#loss-functions)
5. [Evaluation Metrics](#evaluation-metrics)
6. [Factory Functions](#factory-functions)
7. [Command-Line Interface](#command-line-interface)

## Model Classes

### `PADPredictor`

A Multi-Layer Perceptron-based predictor for emotion and physiological state changes.

```python
class PADPredictor(nn.Module):
    def __init__(self,
                 input_dim: int = 7,
                 output_dim: int = 3,
                 hidden_dims: list = [512, 256, 128],
                 dropout_rate: float = 0.3,
                 weight_init: str = "xavier_uniform",
                 bias_init: str = "zeros")
```

#### Parameters

- `input_dim` (int): Input dimension, defaults to 7 (User PAD 3D + Vitality 1D + AI Current PAD 3D)
- `output_dim` (int): Output dimension, defaults to 3 (ΔPAD 3D, Pressure is dynamically calculated via formula)
- `hidden_dims` (list): List of hidden layer dimensions, defaults to [512, 256, 128]
- `dropout_rate` (float): Dropout probability, defaults to 0.3
- `weight_init` (str): Weight initialization method, defaults to "xavier_uniform"
- `bias_init` (str): Bias initialization method, defaults to "zeros"

#### Methods

##### `forward(self, x: torch.Tensor) -> torch.Tensor`

Forward pass.

**Parameters:**
- `x` (torch.Tensor): Input tensor with shape (batch_size, input_dim)

**Returns:**
- `torch.Tensor`: Output tensor with shape (batch_size, output_dim)

**Example:**
```python
import torch
from src.models.pad_predictor import PADPredictor

model = PADPredictor()
input_data = torch.randn(4, 7)  # batch_size=4, input_dim=7
output = model(input_data)
print(f"Output shape: {output.shape}")  # torch.Size([4, 3])
```

##### `predict_components(self, x: torch.Tensor) -> Dict[str, torch.Tensor]`

Predicts and decomposes output components.

**Parameters:**
- `x` (torch.Tensor): Input tensor

**Returns:**
- `Dict[str, torch.Tensor]`: Dictionary containing various components
  - `'delta_pad'`: ΔPAD (3D)
  - `'delta_pressure'`: ΔPressure (1D, dynamically calculated)
  - `'confidence'`: Confidence (1D, optional)

**Example:**
```python
components = model.predict_components(input_data)
print(f"ΔPAD shape: {components['delta_pad'].shape}")      # torch.Size([4, 3])
print(f"ΔPressure shape: {components['delta_pressure'].shape}")  # torch.Size([4, 1])
print(f"Confidence shape: {components['confidence'].shape}")     # torch.Size([4, 1])
```

##### `get_model_info(self) -> Dict[str, Any]`

Retrieves model information.

**Returns:**
- `Dict[str, Any]`: Dictionary containing model information

**Example:**
```python
info = model.get_model_info()
print(f"Model type: {info['model_type']}")
print(f"Total parameters: {info['total_parameters']}")
print(f"Trainable parameters: {info['trainable_parameters']}")
```

##### `save_model(self, filepath: str, include_optimizer: bool = False, optimizer: Optional[torch.optim.Optimizer] = None)`

Saves the model to a file.

**Parameters:**
- `filepath` (str): Path to save the model
- `include_optimizer` (bool): Whether to include optimizer state, defaults to False
- `optimizer` (Optional[torch.optim.Optimizer]): Optimizer object

**Example:**
```python
model.save_model("model.pth", include_optimizer=True, optimizer=optimizer)
```

##### `load_model(cls, filepath: str, device: str = 'cpu') -> 'PADPredictor'`

Loads the model from a file.

**Parameters:**
- `filepath` (str): Path to the model file
- `device` (str): Device type, defaults to 'cpu'

**Returns:**
- `PADPredictor`: Loaded model instance

**Example:**
```python
loaded_model = PADPredictor.load_model("model.pth", device='cuda')
```

##### `freeze_layers(self, layer_names: list = None)`

Freezes parameters of specified layers.

**Parameters:**
- `layer_names` (list): List of layer names to freeze; if None, all layers are frozen

**Example:**
```python
# Freeze all layers
model.freeze_layers()

# Freeze specific layers
model.freeze_layers(['network.0.weight', 'network.2.weight'])
```

##### `unfreeze_layers(self, layer_names: list = None)`

Unfreezes parameters of specified layers.

**Parameters:**
- `layer_names` (list): List of layer names to unfreeze; if None, all layers are unfrozen

## Data Processing Classes

### `DataPreprocessor`

Data preprocessor responsible for feature and label scaling.

```python
class DataPreprocessor:
    def __init__(self, 
                 feature_scaler: str = "standard",
                 label_scaler: str = "standard",
                 feature_range: tuple = None,
                 label_range: tuple = None)
```

#### Parameters

- `feature_scaler` (str): Feature scaling method, defaults to "standard"
- `label_scaler` (str): Label scaling method, defaults to "standard"
- `feature_range` (tuple): Feature range for MinMax scaling
- `label_range` (tuple): Label range for MinMax scaling

#### Methods

##### `fit(self, features: np.ndarray, labels: np.ndarray) -> 'DataPreprocessor'`

Fits preprocessor parameters.

**Parameters:**
- `features` (np.ndarray): Training feature data
- `labels` (np.ndarray): Training label data

**Returns:**
- `DataPreprocessor`: Self instance

##### `transform(self, features: np.ndarray, labels: np.ndarray = None) -> tuple`

Transforms data.

**Parameters:**
- `features` (np.ndarray): Input feature data
- `labels` (np.ndarray, optional): Input label data

**Returns:**
- `tuple`: (transformed features, transformed labels)

##### `fit_transform(self, features: np.ndarray, labels: np.ndarray = None) -> tuple`

Fits and transforms data.

##### `inverse_transform(self, features: np.ndarray, labels: np.ndarray = None) -> tuple`

Inverse transforms data.

##### `save(self, filepath: str)`

Saves the preprocessor to a file.

##### `load(cls, filepath: str) -> 'DataPreprocessor'`

Loads the preprocessor from a file.

**Example:**
```python
from src.data.preprocessor import DataPreprocessor

# Create preprocessor
preprocessor = DataPreprocessor(
    feature_scaler="standard",
    label_scaler="standard"
)

# Fit and transform data
processed_features, processed_labels = preprocessor.fit_transform(train_features, train_labels)

# Save preprocessor
preprocessor.save("preprocessor.pkl")

# Load preprocessor
loaded_preprocessor = DataPreprocessor.load("preprocessor.pkl")
```

### `SyntheticDataGenerator`

Synthetic data generator for creating training and test data.

```python
class SyntheticDataGenerator:
    def __init__(self, 
                 num_samples: int = 1000,
                 seed: int = 42,
                 noise_level: float = 0.1,
                 correlation_strength: float = 0.5)
```

#### Parameters

- `num_samples` (int): Number of samples to generate, defaults to 1000
- `seed` (int): Random seed, defaults to 42
- `noise_level` (float): Noise level, defaults to 0.1
- `correlation_strength` (float): Correlation strength, defaults to 0.5

#### Methods

##### `generate_data(self) -> tuple`

Generates synthetic data.

**Returns:**
- `tuple`: (feature data, label data)

##### `save_data(self, features: np.ndarray, labels: np.ndarray, filepath: str, format: str = 'csv')`

Saves data to a file.

**Example:**
```python
from src.data.synthetic_generator import SyntheticDataGenerator

# Create data generator
generator = SyntheticDataGenerator(num_samples=1000, seed=42)

# Generate data
features, labels = generator.generate_data()

# Save data
generator.save_data(features, labels, "synthetic_data.csv", format='csv')
```

### `EmotionDataset`

PyTorch Dataset class for emotion prediction tasks.

```python
class EmotionDataset(Dataset):
    def __init__(self, 
                 features: np.ndarray,
                 labels: np.ndarray,
                 transform: callable = None)
```

#### Parameters

- `features` (np.ndarray): Feature data
- `labels` (np.ndarray): Label data
- `transform` (callable): Data transformation function

## Utility Classes

### `InferenceEngine`

Inference engine providing high-performance model inference.

```python
class InferenceEngine:
    def __init__(self, 
                 model: nn.Module,
                 preprocessor: DataPreprocessor = None,
                 device: str = 'auto')
```

#### Methods

##### `predict(self, input_data: Union[list, np.ndarray]) -> Dict[str, Any]`

Single sample prediction.

**Parameters:**
- `input_data`: Input data, can be a list or NumPy array

**Returns:**
- `Dict[str, Any]`: Dictionary of prediction results

**Example:**
```python
from src.utils.inference_engine import create_inference_engine

# Create inference engine
engine = create_inference_engine(
    model_path="model.pth",
    preprocessor_path="preprocessor.pkl"
)

# Single sample prediction
input_data = [0.5, 0.3, -0.2, 75.0, 0.1, 0.4, -0.1]
result = engine.predict(input_data)
print(f"ΔPAD: {result['delta_pad']}")
print(f"Confidence: {result['confidence']}")
```

##### `predict_batch(self, input_batch: Union[list, np.ndarray]) -> List[Dict[str, Any]]`

Batch prediction.

##### `benchmark(self, num_samples: int = 1000, batch_size: int = 32) -> Dict[str, float]`

Performance benchmarking.

**Returns:**
- `Dict[str, float]`: Performance statistics

**Example:**
```python
# Performance benchmarking
stats = engine.benchmark(num_samples=1000, batch_size=32)
print(f"Throughput: {stats['throughput']:.2f} samples/sec")
print(f"Average latency: {stats['avg_latency']:.2f}ms")
```

### `ModelTrainer`

Model trainer providing full training pipeline management.

```python
class ModelTrainer:
    def __init__(self, 
                 model: nn.Module,
                 preprocessor: DataPreprocessor = None,
                 device: str = 'auto')
```

#### Methods

##### `train(self, train_loader: DataLoader, val_loader: DataLoader, config: Dict[str, Any]) -> Dict[str, Any]`

Trains the model.

**Parameters:**
- `train_loader` (DataLoader): Training data loader
- `val_loader` (DataLoader): Validation data loader
- `config` (Dict[str, Any]): Training configuration

**Returns:**
- `Dict[str, Any]`: Training history

**Example:**
```python
from src.utils.trainer import ModelTrainer

# Create trainer
trainer = ModelTrainer(model, preprocessor)

# Training configuration
config = {
    'epochs': 100,
    'learning_rate': 0.001,
    'weight_decay': 1e-4,
    'patience': 10,
    'save_dir': './models'
}

# Start training
history = trainer.train(train_loader, val_loader, config)
```

##### `evaluate(self, test_loader: DataLoader) -> Dict[str, float]`

Evaluates the model.

## Loss Functions

### `WeightedMSELoss`

Weighted Mean Squared Error loss function.

```python
class WeightedMSELoss(nn.Module):
    def __init__(self, 
                 delta_pad_weight: float = 1.0,
                 delta_pressure_weight: float = 1.0,
                 confidence_weight: float = 0.5,
                 reduction: str = 'mean')
```

#### Parameters

- `delta_pad_weight` (float): Weight for ΔPAD loss, defaults to 1.0
- `delta_pressure_weight` (float): Weight for ΔPressure loss, defaults to 1.0
- `confidence_weight` (float): Weight for confidence loss, defaults to 0.5
- `reduction` (str): Reduction method for the loss, defaults to 'mean'

**Example:**
```python
from src.models.loss_functions import WeightedMSELoss

criterion = WeightedMSELoss(
    delta_pad_weight=1.0,
    delta_pressure_weight=1.0,
    confidence_weight=0.5
)

loss = criterion(predictions, targets)
```

### `ConfidenceLoss`

Confidence loss function.

```python
class ConfidenceLoss(nn.Module):
    def __init__(self, reduction: str = 'mean')
```

## Evaluation Metrics

### `RegressionMetrics`

Regression evaluation metrics calculator.

```python
class RegressionMetrics:
    def __init__(self)
```

#### Methods

##### `calculate_all_metrics(self, y_true: np.ndarray, y_pred: np.ndarray) -> Dict[str, float]`

Calculates all regression metrics.

**Parameters:**
- `y_true` (np.ndarray): True values
- `y_pred` (np.ndarray): Predicted values

**Returns:**
- `Dict[str, float]`: Dictionary containing all metrics

**Example:**
```python
from src.models.metrics import RegressionMetrics

metrics_calculator = RegressionMetrics()
metrics = metrics_calculator.calculate_all_metrics(true_labels, predictions)

print(f"MSE: {metrics['mse']:.4f}")
print(f"MAE: {metrics['mae']:.4f}")
print(f"R²: {metrics['r2']:.4f}")
```

### `PADMetrics`

PAD-specific evaluation metrics.

```python
class PADMetrics:
    def __init__(self)
```

#### Methods

##### `evaluate_predictions(self, predictions: np.ndarray, targets: np.ndarray) -> Dict[str, Any]`

Evaluates PAD prediction results.

## Factory Functions

### `create_pad_predictor(config: Optional[Dict[str, Any]] = None) -> PADPredictor`

Factory function for creating a PAD predictor.

**Parameters:**
- `config` (Dict[str, Any], optional): Configuration dictionary

**Returns:**
- `PADPredictor`: PAD predictor instance

**Example:**
```python
from src.models.pad_predictor import create_pad_predictor

# Use default configuration
model = create_pad_predictor()

# Use custom configuration
config = {
    'dimensions': {
        'input_dim': 7,
        'output_dim': 4 or 3
    },
    'architecture': {
        'hidden_layers': [
            {'size': 256, 'activation': 'ReLU', 'dropout': 0.3},
            {'size': 128, 'activation': 'ReLU', 'dropout': 0.2}
        ]
    }
}
model = create_pad_predictor(config)
```

### `create_inference_engine(model_path: str, preprocessor_path: str = None, device: str = 'auto') -> InferenceEngine`

Factory function for creating an inference engine.

**Parameters:**
- `model_path` (str): Path to the model file
- `preprocessor_path` (str, optional): Path to the preprocessor file
- `device` (str): Device type

**Returns:**
- `InferenceEngine`: Inference engine instance

### `create_training_setup(config: Dict[str, Any]) -> tuple`

Factory function for creating a training setup.

**Parameters:**
- `config` (Dict[str, Any]): Training configuration

**Returns:**
- `tuple`: (model, trainer, data loader)

## Command-Line Interface

### Main CLI Tool

The project provides a unified command-line interface supporting various operations:

```bash
emotion-prediction <command> [options]
```

#### Available Commands

- `train`: Trains the model
- `predict`: Makes predictions
- `evaluate`: Evaluates the model
- `inference`: Inference script
- `benchmark`: Performance benchmarking

#### Train Command

```bash
emotion-prediction train --config CONFIG_FILE [OPTIONS]
```

**Parameters:**
- `--config, -c`: Path to the training configuration file (required)
- `--output-dir, -o`: Output directory (default: ./outputs)
- `--device`: Computing device (auto/cpu/cuda, default: auto)
- `--resume`: Resume training from a checkpoint
- `--epochs`: Override number of training epochs
- `--batch-size`: Override batch size
- `--learning-rate`: Override learning rate
- `--seed`: Random seed (default: 42)
- `--verbose, -v`: Verbose output
- `--log-level`: Log level (DEBUG/INFO/WARNING/ERROR)

**Example:**
```bash
# Basic training
emotion-prediction train --config configs/training_config.yaml

# GPU training
emotion-prediction train --config configs/training_config.yaml --device cuda

# Resume from checkpoint
emotion-prediction train --config configs/training_config.yaml --resume checkpoint.pth
```

#### Predict Command

```bash
emotion-prediction predict --model MODEL_FILE [OPTIONS]
```

**Parameters:**
- `--model, -m`: Path to the model file (required)
- `--preprocessor, -p`: Path to the preprocessor file
- `--interactive, -i`: Interactive mode
- `--quick`: Quick prediction mode (7 numerical values)
- `--batch`: Batch prediction mode (input file)
- `--output, -o`: Output file path
- `--device`: Computing device
- `--verbose, -v`: Verbose output
- `--log-level`: Log level

**Example:**
```bash
# Interactive prediction
emotion-prediction predict --model model.pth --interactive

# Quick prediction
emotion-prediction predict --model model.pth --quick 0.5 0.3 -0.2 75.0 0.1 0.4 -0.1

# Batch prediction
emotion-prediction predict --model model.pth --batch input.csv --output results.csv
```

#### Evaluate Command

```bash
emotion-prediction evaluate --model MODEL_FILE --data DATA_FILE [OPTIONS]
```

**Parameters:**
- `--model, -m`: Path to the model file (required)
- `--data, -d`: Path to the test data file (required)
- `--preprocessor, -p`: Path to the preprocessor file
- `--output, -o`: Path for evaluation results output
- `--report`: Path for generating a detailed report file
- `--metrics`: List of evaluation metrics (default: mse mae r2)
- `--batch-size`: Batch size (default: 32)
- `--device`: Computing device
- `--verbose, -v`: Verbose output
- `--log-level`: Log level

**Example:**
```bash
# Basic evaluation
emotion-prediction evaluate --model model.pth --data test_data.csv

# Generate detailed report
emotion-prediction evaluate --model model.pth --data test_data.csv --report report.html
```

#### Benchmark Command

```bash
emotion-prediction benchmark --model MODEL_FILE [OPTIONS]
```

**Parameters:**
- `--model, -m`: Path to the model file (required)
- `--preprocessor, -p`: Path to the preprocessor file
- `--num-samples`: Number of test samples (default: 1000)
- `--batch-size`: Batch size (default: 32)
- `--device`: Computing device
- `--report`: Path for generating a performance report file
- `--warmup`: Number of warmup iterations (default: 10)
- `--verbose, -v`: Verbose output
- `--log-level`: Log level

**Example:**
```bash
# Standard benchmarking
emotion-prediction benchmark --model model.pth

# Custom test parameters
emotion-prediction benchmark --model model.pth --num-samples 5000 --batch-size 64
```

## Configuration File API

### Model Configuration

Model configuration files use YAML format and support the following parameters:

```yaml
# Model basic information
model_info:
  name: str           # Model name
  type: str           # Model type
  version: str        # Model version

# Input/output dimensions
dimensions:
  input_dim: int      # Input dimension
  output_dim: int     # Output dimension

# Network architecture
architecture:
  hidden_layers:
    - size: int       # Layer size
      activation: str # Activation function
      dropout: float  # Dropout rate
  output_layer:
    activation: str   # Output activation function
  use_batch_norm: bool   # Whether to use batch normalization
  use_layer_norm: bool   # Whether to use layer normalization

# Initialization parameters
initialization:
  weight_init: str    # Weight initialization method
  bias_init: str      # Bias initialization method

# Regularization
regularization:
  weight_decay: float # L2 regularization coefficient
  dropout_config:
    type: str         # Dropout type
    rate: float       # Dropout rate
```

### Training Configuration

Training configuration files support the following parameters:

```yaml
# Training information
training_info:
  experiment_name: str    # Experiment name
  description: str        # Experiment description
  seed: int              # Random seed

# Training hyperparameters
training:
  optimizer:
    type: str            # Optimizer type
    learning_rate: float # Learning rate
    weight_decay: float  # Weight decay
  scheduler:
    type: str            # Scheduler type
  epochs: int            # Number of training epochs
  early_stopping:
    enabled: bool        # Whether to enable early stopping
    patience: int        # Patience value
    min_delta: float     # Minimum improvement
```

## Exception Handling

The project defines the following custom exceptions:

### `ModelLoadError`

Model loading error.

### `DataPreprocessingError`

Data preprocessing error.

### `InferenceError`

Inference process error.

### `ConfigurationError`

Configuration file error.

**Example:**
```python
from src.utils.exceptions import ModelLoadError, InferenceError

try:
    model = PADPredictor.load_model("invalid_model.pth")
except ModelLoadError as e:
    print(f"Model loading failed: {e}")

try:
    result = engine.predict(invalid_input)
except InferenceError as e:
    print(f"Inference failed: {e}")
```

## Logging System

The project uses a structured logging system:

```python
from src.utils.logger import setup_logger
import logging

# Set up logging
setup_logger(level='INFO', log_file='training.log')
logger = logging.getLogger(__name__)

# Use logging
logger.info("Training started")
logger.debug(f"Batch size: {batch_size}")
logger.warning("Potential overfitting detected")
logger.error("Error occurred during training")
```

## Type Hinting

The project fully supports type hinting, with detailed type annotations for all public APIs:

```python
from typing import Dict, List, Optional, Union, Tuple
import numpy as np
import torch

def predict_emotion(
    input_data: Union[List[float], np.ndarray],
    model_path: str,
    preprocessor_path: Optional[str] = None,
    device: str = 'auto'
) -> Dict[str, Any]:
    """
    Predicts emotional changes
    
    Args:
        input_data: Input data, 7-dimensional vector
        model_path: Path to the model file
        preprocessor_path: Path to the preprocessor file
        device: Computing device
        
    Returns:
        A dictionary containing prediction results
        
    Raises:
        InferenceError: Raised when inference fails
    """
    pass
```

---

For more details, please refer to the source code and example files. If you have any questions, please check the [Troubleshooting Guide](TUTORIAL.md#troubleshooting) or submit an Issue.