File size: 4,348 Bytes
108946c
3d26742
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
ca5ca26
3d26742
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
108946c
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
"""Higgs."""

from typing import List

import datasets

import pandas


VERSION = datasets.Version("1.0.0")
_ORIGINAL_FEATURE_NAMES = [
    "is_boson",
    "lepton_pT",
    "lepton_eta",
    "lepton_phi",
    "missing_energy_magnitude",
    "missing_energy_phi",
    "jet1pt",
    "jet1eta",
    "jet1phi",
    "jet1b-tag",
    "jet2pt",
    "jet2eta",
    "jet2phi",
    "jet2b-tag",
    "jet3pt",
    "jet3eta",
    "jet3phi",
    "jet3b-tag",
    "jet4pt",
    "jet4eta",
    "jet4phi",
    "jet4b-tag",
    "m_jj",
    "m_jjj",
    "m_lv",
    "m_jlv",
    "m_bb",
    "m_wbb",
    "m_wwbb"
]

DESCRIPTION = "Higgs dataset from \"Searching for exotic particles in high-energy physics with deep learning\"."
_HOMEPAGE = "https://www.nature.com/articles/ncomms5308/"
_URLS = ("https://www.openml.org/search?type=data&status=active&id=4532")
_CITATION = """
@article{baldi2014searching,
  title={Searching for exotic particles in high-energy physics with deep learning},
  author={Baldi, Pierre and Sadowski, Peter and Whiteson, Daniel},
  journal={Nature communications},
  volume={5},
  number={1},
  pages={4308},
  year={2014},
  publisher={Nature Publishing Group UK London}
}"""

# Dataset info
urls_per_split = {
    "train": "https://gist.githubusercontent.com/msetzu/99114313deb9cc98318d5940fd536b06/raw/7d4cb798cf460aa240b6b92d971009ae6790e3d0/gistfile1.txt",
}
features_types_per_config = {
    "higgs": {
        "lepton_pT": datasets.Value("float64"),
        "lepton_eta": datasets.Value("float64"),
        "lepton_phi": datasets.Value("float64"),
        "missing_energy_magnitude": datasets.Value("float64"),
        "missing_energy_phi": datasets.Value("float64"),
        "jet1pt": datasets.Value("float64"),
        "jet1eta": datasets.Value("float64"),
        "jet1phi": datasets.Value("float64"),
        "jet1b-tag": datasets.Value("float64"),
        "jet2pt": datasets.Value("float64"),
        "jet2eta": datasets.Value("float64"),
        "jet2phi": datasets.Value("float64"),
        "jet2b-tag": datasets.Value("float64"),
        "jet3pt": datasets.Value("float64"),
        "jet3eta": datasets.Value("float64"),
        "jet3phi": datasets.Value("float64"),
        "jet3b-tag": datasets.Value("float64"),
        "jet4pt": datasets.Value("float64"),
        "jet4eta": datasets.Value("float64"),
        "jet4phi": datasets.Value("float64"),
        "jet4b-tag": datasets.Value("float64"),
        "m_jj": datasets.Value("float64"),
        "m_jjj": datasets.Value("float64"),
        "m_lv": datasets.Value("float64"),
        "m_jlv": datasets.Value("float64"),
        "m_bb": datasets.Value("float64"),
        "m_wbb": datasets.Value("float64"),
        "m_wwbb": datasets.Value("float64"),
        "is_boson": datasets.ClassLabel(num_classes=2, names=("no", "yes"))
    }
}
features_per_config = {k: datasets.Features(features_types_per_config[k]) for k in features_types_per_config}


class HiggsConfig(datasets.BuilderConfig):
    def __init__(self, **kwargs):
        super(HiggsConfig, self).__init__(version=VERSION, **kwargs)
        self.features = features_per_config[kwargs["name"]]


class Higgs(datasets.GeneratorBasedBuilder):
    # dataset versions
    DEFAULT_CONFIG = "higgs"
    BUILDER_CONFIGS = [
        HiggsConfig(name="higgs",
                    description="Higgs boson binary classification.")
    ]


    def _info(self):
        info = datasets.DatasetInfo(description=DESCRIPTION, citation=_CITATION, homepage=_HOMEPAGE,
                                    features=features_per_config[self.config.name])

        return info
    
    def _split_generators(self, dl_manager: datasets.DownloadManager) -> List[datasets.SplitGenerator]:
        downloads = dl_manager.download_and_extract(urls_per_split)

        return [
            datasets.SplitGenerator(name=datasets.Split.TRAIN, gen_kwargs={"filepath": downloads["train"]})
        ]
    
    def _generate_examples(self, filepath: str):
        data = pandas.read_csv(filepath)
        data = self.preprocess(data, config=self.config.name)

        for row_id, row in data.iterrows():
            data_row = dict(row)

            yield row_id, data_row


    def preprocess(self, data: pandas.DataFrame, config: str = "higgs") -> pandas.DataFrame:       
        return data[list(features_types_per_config[config].keys())]