dfm-python 0.5.5__py3-none-any.whl → 0.5.11__py3-none-any.whl

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (48) hide show
  1. dfm_python/__init__.py +24 -11
  2. dfm_python/config/adapter.py +2 -1
  3. dfm_python/config/results.py +1 -55
  4. dfm_python/config/schema.py +232 -183
  5. dfm_python/data/__init__.py +0 -2
  6. dfm_python/data/dataloader.py +3 -3
  7. dfm_python/data/utils.py +15 -12
  8. dfm_python/encoder/vae.py +123 -31
  9. dfm_python/lightning/__init__.py +11 -8
  10. dfm_python/lightning/data_module.py +686 -0
  11. dfm_python/lightning/scaling.py +432 -0
  12. dfm_python/logger/inference_logger.py +1 -1
  13. dfm_python/logger/logger.py +10 -23
  14. dfm_python/logger/train_logger.py +1 -1
  15. dfm_python/models/__init__.py +0 -2
  16. dfm_python/models/base.py +162 -417
  17. dfm_python/models/ddfm.py +1586 -743
  18. dfm_python/models/dfm.py +100 -478
  19. dfm_python/nowcast/__init__.py +37 -0
  20. dfm_python/nowcast/dataview.py +143 -0
  21. dfm_python/nowcast/helpers.py +356 -0
  22. dfm_python/nowcast/nowcast.py +1263 -0
  23. dfm_python/nowcast/splitters.py +441 -0
  24. dfm_python/nowcast/transformers.py +330 -0
  25. dfm_python/nowcast/utils.py +285 -0
  26. dfm_python/ssm/em.py +54 -535
  27. dfm_python/ssm/kalman.py +30 -336
  28. dfm_python/ssm/utils.py +17 -65
  29. dfm_python/trainer/__init__.py +3 -10
  30. dfm_python/trainer/ddfm.py +6 -7
  31. dfm_python/trainer/dfm.py +3 -3
  32. dfm_python/utils/__init__.py +32 -9
  33. dfm_python/utils/data.py +3 -68
  34. dfm_python/utils/helpers.py +1 -1
  35. dfm_python/utils/statespace.py +7 -10
  36. dfm_python/utils/time.py +3 -3
  37. dfm_python-0.5.11.dist-info/METADATA +1299 -0
  38. dfm_python-0.5.11.dist-info/RECORD +49 -0
  39. dfm_python/decoder/__init__.py +0 -0
  40. dfm_python/lightning/ddfm_dm.py +0 -581
  41. dfm_python/lightning/dfm_dm.py +0 -379
  42. dfm_python/lightning/utils.py +0 -496
  43. dfm_python/models/mcmc.py +0 -492
  44. dfm_python/models/utils.py +0 -470
  45. dfm_python-0.5.5.dist-info/METADATA +0 -510
  46. dfm_python-0.5.5.dist-info/RECORD +0 -46
  47. {dfm_python-0.5.5.dist-info → dfm_python-0.5.11.dist-info}/WHEEL +0 -0
  48. {dfm_python-0.5.5.dist-info → dfm_python-0.5.11.dist-info}/licenses/LICENSE +0 -0
dfm_python/__init__.py CHANGED
@@ -6,6 +6,7 @@ This package implements a comprehensive Dynamic Factor Model framework with supp
6
6
  - Tent kernel aggregation for low-to-high frequency mapping
7
7
  - Expectation-Maximization (EM) algorithm for parameter estimation
8
8
  - Kalman filtering and smoothing for factor extraction
9
+ - News decomposition for nowcasting
9
10
  - Deep Dynamic Factor Models (DDFM) with nonlinear encoders (requires PyTorch)
10
11
 
11
12
  The package implements a clock-based approach to mixed-frequency DFMs, where all latent
@@ -22,6 +23,7 @@ Key Features:
22
23
  - Flexible block structure for factor modeling
23
24
  - Robust handling of missing data (internal spline interpolation)
24
25
  - Automatic standardization and data clipping
26
+ - News decomposition for forecast updates
25
27
 
26
28
  Example (Standard Lightning Pattern):
27
29
  >>> from dfm_python import DFM, DFMDataModule, DFMTrainer
@@ -65,7 +67,7 @@ Note: DFMConfig and SeriesConfig are internal implementation details.
65
67
  For detailed documentation, see the README.md file and the tutorial notebooks/scripts.
66
68
  """
67
69
 
68
- __version__ = "0.5.5"
70
+ __version__ = "0.5.11"
69
71
 
70
72
  # ============================================================================
71
73
  # PUBLIC API DEFINITION
@@ -79,14 +81,15 @@ __version__ = "0.5.5"
79
81
  # 2. High-level API: DFM, DDFM, module-level convenience functions
80
82
  # 3. Core utilities: TimeIndex, diagnostics
81
83
  # 4. Models: BaseFactorModel, DDFM (low-level)
82
- # 5. Data & Results: DFMResult
84
+ # 5. Nowcasting: Nowcast, result classes, para_const
85
+ # 6. Data & Results: DFMResult
83
86
  # ============================================================================
84
87
 
85
88
  # Configuration (from config/ subpackage)
86
89
  from .config import (
87
90
  DEFAULT_BLOCK_NAME,
88
- ConfigSource, YamlSource, HydraSource,
89
- make_config_source,
91
+ ConfigSource, YamlSource, DictSource, HydraSource,
92
+ MergedConfigSource, make_config_source,
90
93
  )
91
94
  # Internal imports (for backward compatibility, but not recommended)
92
95
  from .config import DFMConfig, SeriesConfig # Internal use only
@@ -102,13 +105,22 @@ from .utils.time import calculate_rmse
102
105
  # Users can import these directly from dfm_python
103
106
  from .lightning import (
104
107
  DFMDataModule,
105
- DDFMDataModule, # DDFM-specific DataModule
106
108
  DFMDataset, # Dataset class (usually not needed directly)
107
- DDFMDataset, # DDFM Dataset class (usually not needed directly)
108
109
  KalmanFilter, # Module class
109
110
  EMAlgorithm, # Module class
110
111
  )
111
112
 
113
+ # Nowcasting (from nowcast/ subpackage)
114
+ from .nowcast import (
115
+ Nowcast,
116
+ NowcastResult,
117
+ )
118
+ from .nowcast.helpers import (
119
+ para_const,
120
+ NewsDecompResult,
121
+ BacktestResult,
122
+ )
123
+
112
124
  # Model implementations
113
125
  from .models.base import BaseFactorModel
114
126
  from .models.dfm import DFM
@@ -118,16 +130,19 @@ from .models.ddfm import DDFM, DDFMModel
118
130
 
119
131
  __all__ = [
120
132
  # Core classes
121
- 'DFM',
133
+ 'DFM', 'Nowcast',
122
134
  # Model base and implementations
123
135
  'BaseFactorModel',
136
+ # Nowcast result classes
137
+ 'NowcastResult', 'NewsDecompResult', 'BacktestResult',
124
138
  # Constants
125
139
  'DEFAULT_BLOCK_NAME',
126
140
  # Config sources
127
- 'ConfigSource', 'YamlSource', 'HydraSource',
128
- 'make_config_source',
141
+ 'ConfigSource', 'YamlSource', 'DictSource', 'HydraSource',
142
+ 'MergedConfigSource', 'make_config_source',
129
143
  # Low-level API (functional interface - advanced usage)
130
144
  'BaseResult', 'DFMResult', 'DDFMResult', 'calculate_rmse', 'diagnose_series', 'print_series_diagnosis',
145
+ 'para_const', # Internal utility for nowcasting
131
146
  ]
132
147
 
133
148
  # DDFM high-level API (PyTorch is mandatory)
@@ -139,9 +154,7 @@ __all__.extend([
139
154
  # Lightning modules (mandatory dependency)
140
155
  __all__.extend([
141
156
  'DFMDataModule',
142
- 'DDFMDataModule', # DDFM-specific DataModule
143
157
  'DFMDataset', # Dataset class (usually not needed directly)
144
- 'DDFMDataset', # DDFM Dataset class (usually not needed directly)
145
158
  'KalmanFilter', # Module class
146
159
  'EMAlgorithm', # Module class
147
160
  ])
@@ -214,7 +214,8 @@ class YamlSource:
214
214
  frequency=series_data.get('frequency', 'm'),
215
215
  transformation=series_data.get('transformation', 'lin'),
216
216
  blocks=series_data.get('blocks', []),
217
- release_date=release_date
217
+ release_date=release_date,
218
+ scaler=series_data.get('scaler', None) # Optional, for per-series scaling
218
219
  ))
219
220
 
220
221
  # If no series loaded from separate files, try to get from main config
@@ -6,9 +6,8 @@ This module contains dataclasses for storing DFM estimation results and paramete
6
6
  import numpy as np
7
7
  import warnings
8
8
  from dataclasses import dataclass
9
- from typing import Optional, List, Dict, Any, Tuple
9
+ from typing import Optional, List, Dict, Any
10
10
  from abc import ABC
11
- from datetime import datetime
12
11
 
13
12
  from .schema import DFMConfig
14
13
 
@@ -279,59 +278,6 @@ class DDFMResult(BaseResult):
279
278
  use_idiosyncratic: Optional[bool] = None # Whether idio components were used
280
279
 
281
280
 
282
- @dataclass
283
- class NowcastResult:
284
- """Result from a single nowcast calculation.
285
-
286
- This dataclass contains all information from a nowcast operation,
287
- including the nowcast value, metadata about the data view, and
288
- optional diagnostic information.
289
-
290
- Attributes
291
- ----------
292
- target_series : str
293
- Target series ID that was nowcasted.
294
- target_period : datetime
295
- Target period for the nowcast (the period being estimated).
296
- view_date : datetime
297
- View date (when data is available). This determines which
298
- data points are masked/unmasked in the nowcast calculation.
299
- nowcast_value : float
300
- The calculated nowcast value for the target series.
301
- confidence_interval : Tuple[float, float], optional
302
- Confidence interval (lower, upper) for the nowcast, if available.
303
- factors_at_view : np.ndarray, optional
304
- Factor values at the view_date (m,). These are the updated
305
- factor states after applying the data view masking.
306
- dfm_result : BaseResult, optional
307
- Full DFM/DDFM result for this view. Can be used for further
308
- analysis or diagnostics.
309
- data_availability : Dict[str, int], optional
310
- Dictionary with keys 'n_available' and 'n_missing' indicating
311
- how many data points were available vs missing in the data view.
312
-
313
- Examples
314
- --------
315
- >>> from dfm_python import DFM
316
- >>> import numpy as np
317
- >>> model = DFM()
318
- >>> trainer.fit(model, data_module)
319
- >>> # Update state with new data, then predict
320
- >>> X_std = np.random.randn(10, 5) # Standardized data
321
- >>> model.update(X_std)
322
- >>> forecast = model.predict(horizon=1)
323
- >>> print(f"Forecast: {forecast[0, 0]}")
324
- """
325
- target_series: str
326
- target_period: datetime
327
- view_date: datetime
328
- nowcast_value: float
329
- confidence_interval: Optional[Tuple[float, float]] = None # (lower, upper)
330
- factors_at_view: Optional[np.ndarray] = None # Factor values at view_date
331
- dfm_result: Optional[BaseResult] = None # Full DFM/DDFM result for this view
332
- data_availability: Optional[Dict[str, int]] = None # n_available, n_missing
333
-
334
-
335
281
  @dataclass
336
282
  class FitParams:
337
283
  """Parameter overrides for DFM model fitting.