dfm-python 0.1.8__py3-none-any.whl → 0.2.0__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.
dfm_python/__init__.py CHANGED
@@ -27,11 +27,14 @@ Example (High-level API - Recommended):
27
27
  >>> import dfm_python as dfm
28
28
  >>> dfm.load_config('config/default.yaml')
29
29
  >>> dfm.load_data('data/sample_data.csv')
30
- >>> dfm.train()
31
- >>> factors = dfm.result.Z # Direct access to results
30
+ >>> dfm.train(max_iter=1)
31
+ >>> Xf, Zf = dfm.predict(horizon=6)
32
+ >>> dfm.plot(kind='factor', factor_index=0, forecast_horizon=6, save_path='outputs/factor_forecast.png')
33
+ >>> factors = dfm.get_result().Z # Access factors via result
32
34
 
33
35
  Example (Low-level API - For advanced usage):
34
- >>> from dfm_python import load_config, load_data, dfm, DFMConfig, SeriesConfig
36
+ >>> from dfm_python import DFM, DFMConfig, SeriesConfig
37
+ >>> from dfm_python.data_loader import load_data
35
38
  >>> # Option 1: Load from YAML
36
39
  >>> config = load_config('config.yaml')
37
40
  >>> # Option 2: Create directly
@@ -40,41 +43,61 @@ Example (Low-level API - For advanced usage):
40
43
  ... block_names=['Global']
41
44
  ... )
42
45
  >>> X, Time, _ = load_data('data.csv', config) # or use database adapter
43
- >>> result = dfm(X, config)
46
+ >>> model = DFM()
47
+ >>> result = model.fit(X, config)
44
48
  >>> factors = result.Z # Extract estimated factors
45
49
 
46
- For detailed documentation, see the README.md file.
50
+ For detailed documentation, see the README.md file and the tutorial notebooks/scripts.
47
51
  """
48
52
 
49
- __version__ = "0.1.7"
50
-
51
- from .config import DFMConfig, SeriesConfig, BlockConfig
52
- from .data_loader import (
53
- load_config_from_yaml,
54
- load_config_from_spec,
55
- load_data,
56
- transform_data
53
+ __version__ = "0.2.0"
54
+
55
+ from .config import DFMConfig, SeriesConfig, BlockConfig, Params, DEFAULT_GLOBAL_BLOCK_NAME
56
+ from .config import (
57
+ ConfigSource,
58
+ YamlSource,
59
+ DictSource,
60
+ SpecCSVSource,
61
+ HydraSource,
62
+ MergedConfigSource,
63
+ make_config_source,
57
64
  )
58
- from .dfm import DFMResult, dfm, calculate_rmse, diagnose_series, print_series_diagnosis
65
+ from .data_loader import transform_data
66
+ from .dfm import DFMResult, calculate_rmse, diagnose_series, print_series_diagnosis
67
+ from .dfm import DFM as _DFMCore # Core DFM class from dfm.py
59
68
  from .kalman import run_kf, skf, fis, miss_data
60
69
  from .news import update_nowcast, news_dfm, para_const
61
70
 
62
- # Import high-level API
63
- from .dfm_api import DFM, _dfm_instance
71
+ # Import high-level API (extends core DFM with convenience methods)
72
+ from .dfm_api import DFM, _dfm_instance, from_yaml, from_spec, from_spec_df, from_dict
64
73
 
65
74
  # Module-level API: expose singleton instance methods and properties
66
75
  # This allows: import dfm_python as dfm; dfm.load_config(...); dfm.result
67
- def load_config(config):
68
- """Load configuration (module-level convenience function)."""
69
- return _dfm_instance.load_config(config)
70
-
71
- def load_config_from_yaml(yaml_path):
72
- """Load configuration from YAML (module-level convenience function)."""
73
- return _dfm_instance.load_config_from_yaml(yaml_path)
74
-
75
- def load_config_from_spec(spec_path):
76
- """Load configuration from spec CSV (module-level convenience function)."""
77
- return _dfm_instance.load_config_from_spec(spec_path)
76
+ def load_config(
77
+ source=None,
78
+ *,
79
+ yaml=None,
80
+ mapping=None,
81
+ spec=None,
82
+ hydra=None,
83
+ base=None,
84
+ override=None,
85
+ config=None,
86
+ ):
87
+ """Load configuration (module-level convenience function).
88
+
89
+ See DFM.load_config() for parameter documentation.
90
+ """
91
+ return _dfm_instance.load_config(
92
+ source=source,
93
+ yaml=yaml,
94
+ mapping=mapping,
95
+ spec=spec,
96
+ hydra=hydra,
97
+ base=base,
98
+ override=override,
99
+ config=config,
100
+ )
78
101
 
79
102
  def load_data(data_path=None, data=None, **kwargs):
80
103
  """Load data (module-level convenience function)."""
@@ -84,6 +107,14 @@ def train(threshold=None, max_iter=None, **kwargs):
84
107
  """Train the model (module-level convenience function)."""
85
108
  return _dfm_instance.train(threshold=threshold, max_iter=max_iter, **kwargs)
86
109
 
110
+ def predict(horizon=12, **kwargs):
111
+ """Forecast using the trained model (module-level convenience function)."""
112
+ return _dfm_instance.predict(horizon=horizon, **kwargs)
113
+
114
+ def plot(**kwargs):
115
+ """Plot common visualizations (module-level convenience function)."""
116
+ return _dfm_instance.plot(**kwargs)
117
+
87
118
  def reset():
88
119
  """Reset state (module-level convenience function)."""
89
120
  return _dfm_instance.reset()
@@ -132,14 +163,21 @@ def __getattr__(name):
132
163
 
133
164
  __all__ = [
134
165
  # Core classes
135
- 'DFMConfig', 'SeriesConfig', 'BlockConfig', 'DFM',
166
+ 'DFMConfig', 'SeriesConfig', 'BlockConfig', 'Params', 'DFM',
167
+ # Constants
168
+ 'DEFAULT_GLOBAL_BLOCK_NAME',
169
+ # Config sources
170
+ 'ConfigSource', 'YamlSource', 'DictSource', 'SpecCSVSource', 'HydraSource',
171
+ 'MergedConfigSource', 'make_config_source',
136
172
  # High-level API (module-level - recommended)
137
- 'load_config', 'load_config_from_yaml', 'load_config_from_spec',
138
- 'load_data', 'train', 'reset',
173
+ 'load_config',
174
+ 'load_data', 'train', 'predict', 'plot', 'reset',
139
175
  'get_config', 'get_data', 'get_time', 'get_result', 'get_original_data',
176
+ # Convenience constructors (cleaner API)
177
+ 'from_yaml', 'from_spec', 'from_spec_df', 'from_dict',
140
178
  # Low-level API (functional interface - advanced usage)
141
179
  'transform_data',
142
- 'DFMResult', 'dfm', 'calculate_rmse', 'diagnose_series', 'print_series_diagnosis',
180
+ 'DFMResult', 'calculate_rmse', 'diagnose_series', 'print_series_diagnosis',
143
181
  'run_kf', 'skf', 'fis', 'miss_data',
144
182
  'update_nowcast', 'news_dfm', 'para_const',
145
183
  ]