xrtm-data 0.1.0__tar.gz → 0.2.0__tar.gz
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.
- {xrtm_data-0.1.0/src/xrtm_data.egg-info → xrtm_data-0.2.0}/PKG-INFO +27 -2
- {xrtm_data-0.1.0 → xrtm_data-0.2.0}/README.md +26 -1
- {xrtm_data-0.1.0 → xrtm_data-0.2.0}/pyproject.toml +1 -1
- xrtm_data-0.2.0/src/xrtm/data/__init__.py +56 -0
- xrtm_data-0.2.0/src/xrtm/data/core/__init__.py +26 -0
- xrtm_data-0.2.0/src/xrtm/data/core/interfaces.py +82 -0
- {xrtm_data-0.1.0/src/xrtm/data → xrtm_data-0.2.0/src/xrtm/data/core/schemas}/__init__.py +10 -1
- xrtm_data-0.2.0/src/xrtm/data/core/schemas/forecast.py +249 -0
- xrtm_data-0.2.0/src/xrtm/data/kit/__init__.py +27 -0
- xrtm_data-0.2.0/src/xrtm/data/providers/__init__.py +27 -0
- xrtm_data-0.2.0/src/xrtm/data/providers/local/__init__.py +20 -0
- xrtm_data-0.2.0/src/xrtm/data/providers/local/csv.py +120 -0
- xrtm_data-0.2.0/src/xrtm/data/providers/online/__init__.py +20 -0
- {xrtm_data-0.1.0/src/xrtm/data/providers/data → xrtm_data-0.2.0/src/xrtm/data/providers}/online/polymarket.py +67 -3
- xrtm_data-0.2.0/src/xrtm/data/version.py +28 -0
- {xrtm_data-0.1.0 → xrtm_data-0.2.0/src/xrtm_data.egg-info}/PKG-INFO +27 -2
- xrtm_data-0.2.0/src/xrtm_data.egg-info/SOURCES.txt +22 -0
- xrtm_data-0.2.0/tests/test_local_datasource.py +126 -0
- {xrtm_data-0.1.0 → xrtm_data-0.2.0}/tests/test_schemas.py +10 -15
- xrtm_data-0.1.0/src/xrtm/data/providers/data/__init__.py +0 -4
- xrtm_data-0.1.0/src/xrtm/data/providers/data/base.py +0 -24
- xrtm_data-0.1.0/src/xrtm/data/providers/data/local.py +0 -52
- xrtm_data-0.1.0/src/xrtm/data/providers/data/online/__init__.py +0 -3
- xrtm_data-0.1.0/src/xrtm/data/schemas/__init__.py +0 -3
- xrtm_data-0.1.0/src/xrtm/data/schemas/forecast.py +0 -137
- xrtm_data-0.1.0/src/xrtm_data.egg-info/SOURCES.txt +0 -17
- {xrtm_data-0.1.0 → xrtm_data-0.2.0}/LICENSE +0 -0
- {xrtm_data-0.1.0 → xrtm_data-0.2.0}/setup.cfg +0 -0
- {xrtm_data-0.1.0 → xrtm_data-0.2.0}/src/xrtm_data.egg-info/dependency_links.txt +0 -0
- {xrtm_data-0.1.0 → xrtm_data-0.2.0}/src/xrtm_data.egg-info/requires.txt +0 -0
- {xrtm_data-0.1.0 → xrtm_data-0.2.0}/src/xrtm_data.egg-info/top_level.txt +0 -0
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
Metadata-Version: 2.4
|
|
2
2
|
Name: xrtm-data
|
|
3
|
-
Version: 0.
|
|
3
|
+
Version: 0.2.0
|
|
4
4
|
Summary: The Snapshot Vault for XRTM.
|
|
5
5
|
Author-email: XRTM Team <moy@xrtm.org>
|
|
6
6
|
License: Apache-2.0
|
|
@@ -21,15 +21,27 @@ Dynamic: license-file
|
|
|
21
21
|
|
|
22
22
|
[](https://opensource.org/licenses/Apache-2.0)
|
|
23
23
|
[](https://www.python.org/downloads/)
|
|
24
|
+
[](https://pypi.org/project/xrtm-data/)
|
|
24
25
|
|
|
25
26
|
**The Snapshot Vault for XRTM.**
|
|
26
27
|
|
|
27
28
|
`xrtm-data` provides the rigid schemas and temporal sandboxing infrastructure required for zero-leakage forecasting. It defines the "Ground Truth" data structures that the rest of the ecosystem (Forecast, Eval, Train) relies on.
|
|
28
29
|
|
|
30
|
+
## Part of the XRTM Ecosystem
|
|
31
|
+
|
|
32
|
+
```
|
|
33
|
+
Layer 4: xrtm-train → (imports all)
|
|
34
|
+
Layer 3: xrtm-forecast → (imports eval, data)
|
|
35
|
+
Layer 2: xrtm-eval → (imports data)
|
|
36
|
+
Layer 1: xrtm-data → (zero dependencies) ← YOU ARE HERE
|
|
37
|
+
```
|
|
38
|
+
|
|
39
|
+
`xrtm-data` is the foundation layer with **zero dependencies** on other xrtm packages.
|
|
40
|
+
|
|
29
41
|
## Installation
|
|
30
42
|
|
|
31
43
|
```bash
|
|
32
|
-
|
|
44
|
+
pip install xrtm-data
|
|
33
45
|
```
|
|
34
46
|
|
|
35
47
|
## Core Primitives
|
|
@@ -54,6 +66,19 @@ prediction = ForecastOutput(
|
|
|
54
66
|
### 2. Zero Leakage
|
|
55
67
|
The `MetadataBase` enforces a strict `snapshot_time`. This timestamp represents the "End of History" for the model. Any data point generated after this time is considered "Future Leakage" and is programmatically inaccessible during backtesting.
|
|
56
68
|
|
|
69
|
+
## Project Structure
|
|
70
|
+
|
|
71
|
+
```
|
|
72
|
+
src/xrtm/data/
|
|
73
|
+
├── core/ # Interfaces & Schemas (domain-agnostic)
|
|
74
|
+
│ ├── interfaces.py # DataSource protocol
|
|
75
|
+
│ └── schemas/ # ForecastQuestion, ForecastOutput, etc.
|
|
76
|
+
├── kit/ # Composable utilities (processors)
|
|
77
|
+
└── providers/ # External data source implementations
|
|
78
|
+
├── local/ # LocalDataSource (JSON files)
|
|
79
|
+
└── online/ # PolymarketSource (Gamma API)
|
|
80
|
+
```
|
|
81
|
+
|
|
57
82
|
## Development
|
|
58
83
|
|
|
59
84
|
Prerequisites:
|
|
@@ -2,15 +2,27 @@
|
|
|
2
2
|
|
|
3
3
|
[](https://opensource.org/licenses/Apache-2.0)
|
|
4
4
|
[](https://www.python.org/downloads/)
|
|
5
|
+
[](https://pypi.org/project/xrtm-data/)
|
|
5
6
|
|
|
6
7
|
**The Snapshot Vault for XRTM.**
|
|
7
8
|
|
|
8
9
|
`xrtm-data` provides the rigid schemas and temporal sandboxing infrastructure required for zero-leakage forecasting. It defines the "Ground Truth" data structures that the rest of the ecosystem (Forecast, Eval, Train) relies on.
|
|
9
10
|
|
|
11
|
+
## Part of the XRTM Ecosystem
|
|
12
|
+
|
|
13
|
+
```
|
|
14
|
+
Layer 4: xrtm-train → (imports all)
|
|
15
|
+
Layer 3: xrtm-forecast → (imports eval, data)
|
|
16
|
+
Layer 2: xrtm-eval → (imports data)
|
|
17
|
+
Layer 1: xrtm-data → (zero dependencies) ← YOU ARE HERE
|
|
18
|
+
```
|
|
19
|
+
|
|
20
|
+
`xrtm-data` is the foundation layer with **zero dependencies** on other xrtm packages.
|
|
21
|
+
|
|
10
22
|
## Installation
|
|
11
23
|
|
|
12
24
|
```bash
|
|
13
|
-
|
|
25
|
+
pip install xrtm-data
|
|
14
26
|
```
|
|
15
27
|
|
|
16
28
|
## Core Primitives
|
|
@@ -35,6 +47,19 @@ prediction = ForecastOutput(
|
|
|
35
47
|
### 2. Zero Leakage
|
|
36
48
|
The `MetadataBase` enforces a strict `snapshot_time`. This timestamp represents the "End of History" for the model. Any data point generated after this time is considered "Future Leakage" and is programmatically inaccessible during backtesting.
|
|
37
49
|
|
|
50
|
+
## Project Structure
|
|
51
|
+
|
|
52
|
+
```
|
|
53
|
+
src/xrtm/data/
|
|
54
|
+
├── core/ # Interfaces & Schemas (domain-agnostic)
|
|
55
|
+
│ ├── interfaces.py # DataSource protocol
|
|
56
|
+
│ └── schemas/ # ForecastQuestion, ForecastOutput, etc.
|
|
57
|
+
├── kit/ # Composable utilities (processors)
|
|
58
|
+
└── providers/ # External data source implementations
|
|
59
|
+
├── local/ # LocalDataSource (JSON files)
|
|
60
|
+
└── online/ # PolymarketSource (Gamma API)
|
|
61
|
+
```
|
|
62
|
+
|
|
38
63
|
## Development
|
|
39
64
|
|
|
40
65
|
Prerequisites:
|
|
@@ -0,0 +1,56 @@
|
|
|
1
|
+
# coding=utf-8
|
|
2
|
+
# Copyright 2026 XRTM Team. All rights reserved.
|
|
3
|
+
#
|
|
4
|
+
# Licensed under the Apache License, Version 2.0 (the "License");
|
|
5
|
+
# you may not use this file except in compliance with the License.
|
|
6
|
+
# You may obtain a copy of the License at
|
|
7
|
+
#
|
|
8
|
+
# http://www.apache.org/licenses/LICENSE-2.0
|
|
9
|
+
#
|
|
10
|
+
# Unless required by applicable law or agreed to in writing, software
|
|
11
|
+
# distributed under the License is distributed on an "AS IS" BASIS,
|
|
12
|
+
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
13
|
+
# See the License for the specific language governing permissions and
|
|
14
|
+
# limitations under the License.
|
|
15
|
+
|
|
16
|
+
r"""
|
|
17
|
+
xrtm-data: The Foundation Layer (Layer 1)
|
|
18
|
+
|
|
19
|
+
This package provides the core data schemas and interfaces for the xrtm
|
|
20
|
+
ecosystem. It follows the "Zero Leakage" principle, ensuring all data
|
|
21
|
+
is properly timestamped for temporal isolation.
|
|
22
|
+
|
|
23
|
+
Structure:
|
|
24
|
+
- core/: Domain-agnostic interfaces and schemas
|
|
25
|
+
- kit/: High-level processors and utilities
|
|
26
|
+
- providers/: External data source implementations
|
|
27
|
+
|
|
28
|
+
Example:
|
|
29
|
+
>>> from xrtm.data import ForecastQuestion, DataSource
|
|
30
|
+
>>> from xrtm.data.providers import LocalDataSource
|
|
31
|
+
"""
|
|
32
|
+
|
|
33
|
+
# Core interfaces
|
|
34
|
+
from xrtm.data.core import DataSource
|
|
35
|
+
|
|
36
|
+
# Core schemas (public API)
|
|
37
|
+
from xrtm.data.core.schemas import (
|
|
38
|
+
CausalEdge,
|
|
39
|
+
CausalNode,
|
|
40
|
+
ConfidenceInterval,
|
|
41
|
+
ForecastOutput,
|
|
42
|
+
ForecastQuestion,
|
|
43
|
+
MetadataBase,
|
|
44
|
+
)
|
|
45
|
+
|
|
46
|
+
__all__ = [
|
|
47
|
+
# Interfaces
|
|
48
|
+
"DataSource",
|
|
49
|
+
# Schemas
|
|
50
|
+
"MetadataBase",
|
|
51
|
+
"ForecastQuestion",
|
|
52
|
+
"ForecastOutput",
|
|
53
|
+
"CausalNode",
|
|
54
|
+
"CausalEdge",
|
|
55
|
+
"ConfidenceInterval",
|
|
56
|
+
]
|
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
# coding=utf-8
|
|
2
|
+
# Copyright 2026 XRTM Team. All rights reserved.
|
|
3
|
+
#
|
|
4
|
+
# Licensed under the Apache License, Version 2.0 (the "License");
|
|
5
|
+
# you may not use this file except in compliance with the License.
|
|
6
|
+
# You may obtain a copy of the License at
|
|
7
|
+
#
|
|
8
|
+
# http://www.apache.org/licenses/LICENSE-2.0
|
|
9
|
+
#
|
|
10
|
+
# Unless required by applicable law or agreed to in writing, software
|
|
11
|
+
# distributed under the License is distributed on an "AS IS" BASIS,
|
|
12
|
+
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
13
|
+
# See the License for the specific language governing permissions and
|
|
14
|
+
# limitations under the License.
|
|
15
|
+
|
|
16
|
+
r"""
|
|
17
|
+
Core interfaces and protocols for xrtm-data.
|
|
18
|
+
|
|
19
|
+
This module defines the abstract base classes (protocols) that all data
|
|
20
|
+
providers must implement. The core module is domain-agnostic and MUST NOT
|
|
21
|
+
import from kit/ or providers/.
|
|
22
|
+
"""
|
|
23
|
+
|
|
24
|
+
from xrtm.data.core.interfaces import DataSource
|
|
25
|
+
|
|
26
|
+
__all__ = ["DataSource"]
|
|
@@ -0,0 +1,82 @@
|
|
|
1
|
+
# coding=utf-8
|
|
2
|
+
# Copyright 2026 XRTM Team. All rights reserved.
|
|
3
|
+
#
|
|
4
|
+
# Licensed under the Apache License, Version 2.0 (the "License");
|
|
5
|
+
# you may not use this file except in compliance with the License.
|
|
6
|
+
# You may obtain a copy of the License at
|
|
7
|
+
#
|
|
8
|
+
# http://www.apache.org/licenses/LICENSE-2.0
|
|
9
|
+
#
|
|
10
|
+
# Unless required by applicable law or agreed to in writing, software
|
|
11
|
+
# distributed under the License is distributed on an "AS IS" BASIS,
|
|
12
|
+
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
13
|
+
# See the License for the specific language governing permissions and
|
|
14
|
+
# limitations under the License.
|
|
15
|
+
|
|
16
|
+
r"""
|
|
17
|
+
Abstract interfaces for xrtm-data providers.
|
|
18
|
+
|
|
19
|
+
This module defines the protocols that all data sources must implement.
|
|
20
|
+
These are domain-agnostic abstractions that can be used for any forecasting
|
|
21
|
+
data provider, regardless of the source.
|
|
22
|
+
|
|
23
|
+
Example:
|
|
24
|
+
>>> from xrtm.data.core import DataSource
|
|
25
|
+
>>> class MySource(DataSource):
|
|
26
|
+
... async def fetch_questions(self, query=None, limit=5):
|
|
27
|
+
... return []
|
|
28
|
+
... async def get_question_by_id(self, question_id):
|
|
29
|
+
... return None
|
|
30
|
+
"""
|
|
31
|
+
|
|
32
|
+
import abc
|
|
33
|
+
from typing import List, Optional
|
|
34
|
+
|
|
35
|
+
from xrtm.data.core.schemas.forecast import ForecastQuestion
|
|
36
|
+
|
|
37
|
+
|
|
38
|
+
class DataSource(abc.ABC):
|
|
39
|
+
r"""
|
|
40
|
+
Abstract interface for gathering or streaming forecasting workloads.
|
|
41
|
+
|
|
42
|
+
All data providers (local, online, subgraph) must implement this interface
|
|
43
|
+
to ensure consistent access patterns across the ecosystem.
|
|
44
|
+
|
|
45
|
+
Attributes:
|
|
46
|
+
None. This is a pure protocol.
|
|
47
|
+
|
|
48
|
+
Example:
|
|
49
|
+
>>> class LocalSource(DataSource):
|
|
50
|
+
... async def fetch_questions(self, query=None, limit=5):
|
|
51
|
+
... return [ForecastQuestion(id="1", title="Test")]
|
|
52
|
+
"""
|
|
53
|
+
|
|
54
|
+
@abc.abstractmethod
|
|
55
|
+
async def fetch_questions(self, query: Optional[str] = None, limit: int = 5) -> List[ForecastQuestion]:
|
|
56
|
+
r"""
|
|
57
|
+
Fetch a list of forecast questions from the data source.
|
|
58
|
+
|
|
59
|
+
Args:
|
|
60
|
+
query: Optional search/filter string.
|
|
61
|
+
limit: Maximum number of questions to return.
|
|
62
|
+
|
|
63
|
+
Returns:
|
|
64
|
+
List of ForecastQuestion objects matching the criteria.
|
|
65
|
+
"""
|
|
66
|
+
pass
|
|
67
|
+
|
|
68
|
+
@abc.abstractmethod
|
|
69
|
+
async def get_question_by_id(self, question_id: str) -> Optional[ForecastQuestion]:
|
|
70
|
+
r"""
|
|
71
|
+
Retrieve a single question by its unique identifier.
|
|
72
|
+
|
|
73
|
+
Args:
|
|
74
|
+
question_id: The unique identifier of the question.
|
|
75
|
+
|
|
76
|
+
Returns:
|
|
77
|
+
The ForecastQuestion if found, None otherwise.
|
|
78
|
+
"""
|
|
79
|
+
pass
|
|
80
|
+
|
|
81
|
+
|
|
82
|
+
__all__ = ["DataSource"]
|
|
@@ -13,9 +13,17 @@
|
|
|
13
13
|
# See the License for the specific language governing permissions and
|
|
14
14
|
# limitations under the License.
|
|
15
15
|
|
|
16
|
-
|
|
16
|
+
r"""
|
|
17
|
+
Core data schemas for xrtm-data.
|
|
18
|
+
|
|
19
|
+
This module exports all foundational Pydantic models used across the
|
|
20
|
+
xrtm ecosystem for representing forecasting data structures.
|
|
21
|
+
"""
|
|
22
|
+
|
|
23
|
+
from xrtm.data.core.schemas.forecast import (
|
|
17
24
|
CausalEdge,
|
|
18
25
|
CausalNode,
|
|
26
|
+
ConfidenceInterval,
|
|
19
27
|
ForecastOutput,
|
|
20
28
|
ForecastQuestion,
|
|
21
29
|
MetadataBase,
|
|
@@ -27,4 +35,5 @@ __all__ = [
|
|
|
27
35
|
"ForecastOutput",
|
|
28
36
|
"CausalNode",
|
|
29
37
|
"CausalEdge",
|
|
38
|
+
"ConfidenceInterval",
|
|
30
39
|
]
|
|
@@ -0,0 +1,249 @@
|
|
|
1
|
+
# coding=utf-8
|
|
2
|
+
# Copyright 2026 XRTM Team. All rights reserved.
|
|
3
|
+
#
|
|
4
|
+
# Licensed under the Apache License, Version 2.0 (the "License");
|
|
5
|
+
# you may not use this file except in compliance with the License.
|
|
6
|
+
# You may obtain a copy of the License at
|
|
7
|
+
#
|
|
8
|
+
# http://www.apache.org/licenses/LICENSE-2.0
|
|
9
|
+
#
|
|
10
|
+
# Unless required by applicable law or agreed to in writing, software
|
|
11
|
+
# distributed under the License is distributed on an "AS IS" BASIS,
|
|
12
|
+
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
13
|
+
# See the License for the specific language governing permissions and
|
|
14
|
+
# limitations under the License.
|
|
15
|
+
|
|
16
|
+
r"""
|
|
17
|
+
Core forecast schemas for xrtm-data.
|
|
18
|
+
|
|
19
|
+
This module defines the foundational Pydantic models used across the xrtm
|
|
20
|
+
ecosystem for representing forecast questions, outputs, and causal reasoning
|
|
21
|
+
structures.
|
|
22
|
+
|
|
23
|
+
Example:
|
|
24
|
+
>>> from xrtm.data.core.schemas import ForecastQuestion
|
|
25
|
+
>>> q = ForecastQuestion(id="q1", title="Will it rain tomorrow?")
|
|
26
|
+
"""
|
|
27
|
+
|
|
28
|
+
from datetime import datetime, timezone
|
|
29
|
+
from typing import Any, Dict, List, Optional
|
|
30
|
+
|
|
31
|
+
from pydantic import AliasChoices, BaseModel, ConfigDict, Field
|
|
32
|
+
|
|
33
|
+
|
|
34
|
+
class MetadataBase(BaseModel):
|
|
35
|
+
r"""
|
|
36
|
+
A foundational metadata block used to ensure consistency across schemas.
|
|
37
|
+
|
|
38
|
+
This model captures temporal information critical for the Zero Leakage
|
|
39
|
+
principle, ensuring all data is properly timestamped.
|
|
40
|
+
|
|
41
|
+
Attributes:
|
|
42
|
+
id: Unique identifier for this metadata block.
|
|
43
|
+
created_at: When this metadata was created.
|
|
44
|
+
snapshot_time: The "Time T" at which the world state was frozen.
|
|
45
|
+
tags: List of classification tags.
|
|
46
|
+
subject_type: Type of subject being forecasted.
|
|
47
|
+
source_version: Version of the data source.
|
|
48
|
+
raw_data: Original unprocessed data.
|
|
49
|
+
"""
|
|
50
|
+
|
|
51
|
+
model_config = ConfigDict(extra="allow")
|
|
52
|
+
id: str = Field(
|
|
53
|
+
default_factory=lambda: "meta_" + str(datetime.now(timezone.utc).timestamp()),
|
|
54
|
+
description="Unique identifier for this metadata block",
|
|
55
|
+
)
|
|
56
|
+
created_at: datetime = Field(
|
|
57
|
+
default_factory=lambda: datetime.now(timezone.utc),
|
|
58
|
+
description="When this metadata was created",
|
|
59
|
+
)
|
|
60
|
+
snapshot_time: datetime = Field(
|
|
61
|
+
default_factory=lambda: datetime.now(timezone.utc),
|
|
62
|
+
description="Zero Leakage: The specific 'Time T' at which the world state was frozen.",
|
|
63
|
+
)
|
|
64
|
+
tags: List[str] = Field(default_factory=list, description="Classification tags")
|
|
65
|
+
subject_type: Optional[str] = Field(None, description="Type of subject being forecasted")
|
|
66
|
+
source_version: Optional[str] = Field(None, description="Version of the data source")
|
|
67
|
+
raw_data: Optional[Dict[str, Any]] = Field(None, description="Original unprocessed data")
|
|
68
|
+
|
|
69
|
+
def get(self, key: str, default: Any = None) -> Any:
|
|
70
|
+
r"""Backward compatibility for dict-like access."""
|
|
71
|
+
return getattr(self, key, default)
|
|
72
|
+
|
|
73
|
+
|
|
74
|
+
class ForecastQuestion(BaseModel):
|
|
75
|
+
r"""
|
|
76
|
+
The standardized input format for a forecasting task.
|
|
77
|
+
|
|
78
|
+
This is the primary input schema used throughout the xrtm ecosystem
|
|
79
|
+
to represent a question or hypothesis to be forecasted.
|
|
80
|
+
|
|
81
|
+
Attributes:
|
|
82
|
+
id: Unique identifier for the question.
|
|
83
|
+
title: The main question or statement being forecasted.
|
|
84
|
+
description: Detailed context and background.
|
|
85
|
+
resolution_criteria: Explicit rules for ground truth determination.
|
|
86
|
+
metadata: Associated metadata including temporal information.
|
|
87
|
+
|
|
88
|
+
Example:
|
|
89
|
+
>>> q = ForecastQuestion(
|
|
90
|
+
... id="q1",
|
|
91
|
+
... title="Will Company X announce earnings above expectations?",
|
|
92
|
+
... description="Q4 earnings call scheduled for Jan 15",
|
|
93
|
+
... )
|
|
94
|
+
"""
|
|
95
|
+
|
|
96
|
+
id: str = Field(..., description="Unique identifier for the question")
|
|
97
|
+
title: str = Field(..., description="The main question or statement being forecasted")
|
|
98
|
+
description: Optional[str] = Field(
|
|
99
|
+
None,
|
|
100
|
+
alias="content",
|
|
101
|
+
validation_alias=AliasChoices("description", "content"),
|
|
102
|
+
description="Detailed context and background",
|
|
103
|
+
)
|
|
104
|
+
resolution_criteria: Optional[str] = Field(None, description="Explicit rules for ground truth determination")
|
|
105
|
+
metadata: MetadataBase = Field(default_factory=MetadataBase) # type: ignore[arg-type]
|
|
106
|
+
|
|
107
|
+
@property
|
|
108
|
+
def content(self) -> Optional[str]:
|
|
109
|
+
r"""Backward compatibility alias for description."""
|
|
110
|
+
return self.description
|
|
111
|
+
|
|
112
|
+
|
|
113
|
+
class CausalNode(BaseModel):
|
|
114
|
+
r"""
|
|
115
|
+
Represents a single step in a logical reasoning chain.
|
|
116
|
+
|
|
117
|
+
Attributes:
|
|
118
|
+
event: The assumption or event in the chain.
|
|
119
|
+
probability: Optional probability assigned to this node.
|
|
120
|
+
description: Additional context for this reasoning step.
|
|
121
|
+
node_id: Unique identifier for graph operations.
|
|
122
|
+
"""
|
|
123
|
+
|
|
124
|
+
event: str = Field(..., description="The assumption or event in the chain")
|
|
125
|
+
probability: Optional[float] = Field(None, ge=0, le=1, description="Probability of this event")
|
|
126
|
+
description: Optional[str] = Field(None, description="Additional context")
|
|
127
|
+
node_id: str = Field(
|
|
128
|
+
default_factory=lambda: "node_" + str(datetime.now().timestamp()),
|
|
129
|
+
description="Unique ID for graph operations",
|
|
130
|
+
)
|
|
131
|
+
|
|
132
|
+
|
|
133
|
+
class CausalEdge(BaseModel):
|
|
134
|
+
r"""
|
|
135
|
+
Represents a directed causal dependency between two reasoning nodes.
|
|
136
|
+
|
|
137
|
+
Attributes:
|
|
138
|
+
source: ID of the source node.
|
|
139
|
+
target: ID of the target node.
|
|
140
|
+
weight: Strength of the causal relationship.
|
|
141
|
+
description: Context for this causal link.
|
|
142
|
+
"""
|
|
143
|
+
|
|
144
|
+
source: str = Field(..., description="ID of the source node")
|
|
145
|
+
target: str = Field(..., description="ID of the target node")
|
|
146
|
+
weight: float = Field(default=1.0, ge=0, le=1, description="Strength of causal relationship")
|
|
147
|
+
description: Optional[str] = Field(None, description="Context for this causal link")
|
|
148
|
+
|
|
149
|
+
|
|
150
|
+
class ConfidenceInterval(BaseModel):
|
|
151
|
+
r"""
|
|
152
|
+
Standard range for probabilistic calibration.
|
|
153
|
+
|
|
154
|
+
Attributes:
|
|
155
|
+
low: Lower bound of the interval.
|
|
156
|
+
high: Upper bound of the interval.
|
|
157
|
+
level: Confidence level (default 0.9 for 90%).
|
|
158
|
+
"""
|
|
159
|
+
|
|
160
|
+
low: float = Field(..., description="Lower bound")
|
|
161
|
+
high: float = Field(..., description="Upper bound")
|
|
162
|
+
level: float = Field(0.9, ge=0, le=1, description="Confidence level")
|
|
163
|
+
|
|
164
|
+
|
|
165
|
+
class ForecastOutput(BaseModel):
|
|
166
|
+
r"""
|
|
167
|
+
The structured result of an agent's forecasting reasoning.
|
|
168
|
+
|
|
169
|
+
This model captures not just the final probability, but also the
|
|
170
|
+
complete reasoning chain that led to it, enabling audit and calibration.
|
|
171
|
+
|
|
172
|
+
Attributes:
|
|
173
|
+
question_id: Reference to the input question.
|
|
174
|
+
probability: The assigned probability of the primary outcome.
|
|
175
|
+
uncertainty: Optional measure of forecast uncertainty.
|
|
176
|
+
confidence_interval: Range for calibration.
|
|
177
|
+
reasoning: Narrative reasoning for the forecast.
|
|
178
|
+
logical_trace: Bayesian-style sequence of assumptions.
|
|
179
|
+
logical_edges: Causal dependencies between nodes.
|
|
180
|
+
structural_trace: Order of graph nodes executed.
|
|
181
|
+
calibration_metrics: Performance metrics.
|
|
182
|
+
metadata: Associated temporal and source metadata.
|
|
183
|
+
"""
|
|
184
|
+
|
|
185
|
+
question_id: str = Field(..., description="Reference to the input question")
|
|
186
|
+
probability: float = Field(
|
|
187
|
+
...,
|
|
188
|
+
alias="confidence",
|
|
189
|
+
validation_alias=AliasChoices("probability", "confidence"),
|
|
190
|
+
ge=0,
|
|
191
|
+
le=1,
|
|
192
|
+
description="The assigned probability of the primary outcome",
|
|
193
|
+
)
|
|
194
|
+
uncertainty: Optional[float] = Field(None, ge=0, le=1, description="Measure of forecast uncertainty")
|
|
195
|
+
confidence_interval: Optional[ConfidenceInterval] = None
|
|
196
|
+
reasoning: str = Field(..., description="Narrative reasoning for the forecast")
|
|
197
|
+
logical_trace: List[CausalNode] = Field(
|
|
198
|
+
default_factory=list, description="The Bayesian-style sequence of assumptions"
|
|
199
|
+
)
|
|
200
|
+
logical_edges: List[CausalEdge] = Field(default_factory=list, description="Causal dependencies between nodes")
|
|
201
|
+
structural_trace: List[str] = Field(default_factory=list, description="Order of graph nodes executed")
|
|
202
|
+
calibration_metrics: Dict[str, Any] = Field(default_factory=dict, description="Performance metrics")
|
|
203
|
+
metadata: MetadataBase = Field(default_factory=MetadataBase) # type: ignore[arg-type]
|
|
204
|
+
|
|
205
|
+
@property
|
|
206
|
+
def confidence(self) -> float:
|
|
207
|
+
r"""Backward compatibility alias for probability."""
|
|
208
|
+
return self.probability
|
|
209
|
+
|
|
210
|
+
@confidence.setter
|
|
211
|
+
def confidence(self, value: float) -> None:
|
|
212
|
+
r"""Backward compatibility setter for probability."""
|
|
213
|
+
self.probability = value
|
|
214
|
+
|
|
215
|
+
def to_networkx(self) -> Any:
|
|
216
|
+
r"""
|
|
217
|
+
Convert the logical trace to a NetworkX directed graph.
|
|
218
|
+
|
|
219
|
+
Returns:
|
|
220
|
+
A NetworkX DiGraph representing the reasoning chain.
|
|
221
|
+
|
|
222
|
+
Raises:
|
|
223
|
+
ImportError: If networkx is not installed.
|
|
224
|
+
"""
|
|
225
|
+
try:
|
|
226
|
+
import networkx as nx
|
|
227
|
+
except ImportError:
|
|
228
|
+
raise ImportError("networkx is required for to_networkx(). Install it with 'uv add networkx'.")
|
|
229
|
+
dg = nx.DiGraph()
|
|
230
|
+
for node in self.logical_trace:
|
|
231
|
+
dg.add_node(
|
|
232
|
+
node.node_id,
|
|
233
|
+
event=node.event,
|
|
234
|
+
probability=node.probability,
|
|
235
|
+
description=node.description,
|
|
236
|
+
)
|
|
237
|
+
for edge in self.logical_edges:
|
|
238
|
+
dg.add_edge(edge.source, edge.target, weight=edge.weight, description=edge.description)
|
|
239
|
+
return dg
|
|
240
|
+
|
|
241
|
+
|
|
242
|
+
__all__ = [
|
|
243
|
+
"MetadataBase",
|
|
244
|
+
"ForecastQuestion",
|
|
245
|
+
"CausalNode",
|
|
246
|
+
"CausalEdge",
|
|
247
|
+
"ConfidenceInterval",
|
|
248
|
+
"ForecastOutput",
|
|
249
|
+
]
|
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
# coding=utf-8
|
|
2
|
+
# Copyright 2026 XRTM Team. All rights reserved.
|
|
3
|
+
#
|
|
4
|
+
# Licensed under the Apache License, Version 2.0 (the "License");
|
|
5
|
+
# you may not use this file except in compliance with the License.
|
|
6
|
+
# You may obtain a copy of the License at
|
|
7
|
+
#
|
|
8
|
+
# http://www.apache.org/licenses/LICENSE-2.0
|
|
9
|
+
#
|
|
10
|
+
# Unless required by applicable law or agreed to in writing, software
|
|
11
|
+
# distributed under the License is distributed on an "AS IS" BASIS,
|
|
12
|
+
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
13
|
+
# See the License for the specific language governing permissions and
|
|
14
|
+
# limitations under the License.
|
|
15
|
+
|
|
16
|
+
r"""
|
|
17
|
+
Researcher Kit for xrtm-data.
|
|
18
|
+
|
|
19
|
+
This module provides high-level, composable utilities built on top of
|
|
20
|
+
the core interfaces. Kit components use abstractions from core/ and
|
|
21
|
+
MUST NOT import from providers/.
|
|
22
|
+
|
|
23
|
+
Currently empty - will be populated with data processors (e.g., Beta fitters)
|
|
24
|
+
during the training logic implementation phase.
|
|
25
|
+
"""
|
|
26
|
+
|
|
27
|
+
__all__: list[str] = []
|
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
# coding=utf-8
|
|
2
|
+
# Copyright 2026 XRTM Team. All rights reserved.
|
|
3
|
+
#
|
|
4
|
+
# Licensed under the Apache License, Version 2.0 (the "License");
|
|
5
|
+
# you may not use this file except in compliance with the License.
|
|
6
|
+
# You may obtain a copy of the License at
|
|
7
|
+
#
|
|
8
|
+
# http://www.apache.org/licenses/LICENSE-2.0
|
|
9
|
+
#
|
|
10
|
+
# Unless required by applicable law or agreed to in writing, software
|
|
11
|
+
# distributed under the License is distributed on an "AS IS" BASIS,
|
|
12
|
+
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
13
|
+
# See the License for the specific language governing permissions and
|
|
14
|
+
# limitations under the License.
|
|
15
|
+
|
|
16
|
+
r"""
|
|
17
|
+
Data providers for xrtm-data.
|
|
18
|
+
|
|
19
|
+
This module exports concrete DataSource implementations that fetch data
|
|
20
|
+
from various external sources. Providers implement the core interfaces
|
|
21
|
+
and CAN import from core/ but MUST NOT import from kit/.
|
|
22
|
+
"""
|
|
23
|
+
|
|
24
|
+
from xrtm.data.providers.local import LocalDataSource
|
|
25
|
+
from xrtm.data.providers.online import PolymarketSource
|
|
26
|
+
|
|
27
|
+
__all__ = ["LocalDataSource", "PolymarketSource"]
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
# coding=utf-8
|
|
2
|
+
# Copyright 2026 XRTM Team. All rights reserved.
|
|
3
|
+
#
|
|
4
|
+
# Licensed under the Apache License, Version 2.0 (the "License");
|
|
5
|
+
# you may not use this file except in compliance with the License.
|
|
6
|
+
# You may obtain a copy of the License at
|
|
7
|
+
#
|
|
8
|
+
# http://www.apache.org/licenses/LICENSE-2.0
|
|
9
|
+
#
|
|
10
|
+
# Unless required by applicable law or agreed to in writing, software
|
|
11
|
+
# distributed under the License is distributed on an "AS IS" BASIS,
|
|
12
|
+
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
13
|
+
# See the License for the specific language governing permissions and
|
|
14
|
+
# limitations under the License.
|
|
15
|
+
|
|
16
|
+
r"""Local file-based data providers."""
|
|
17
|
+
|
|
18
|
+
from xrtm.data.providers.local.csv import LocalDataSource
|
|
19
|
+
|
|
20
|
+
__all__ = ["LocalDataSource"]
|