|
| 1 | +from dataclasses import ( |
| 2 | + dataclass, |
| 3 | + fields, |
| 4 | +) |
| 5 | + |
| 6 | +from beartype.typing import ( |
| 7 | + Dict, |
| 8 | + Union, |
| 9 | +) |
| 10 | +from jaxlib.xla_extension import PjitFunction |
| 11 | +from plum import dispatch |
| 12 | + |
| 13 | +from gpjax.kernels import ( |
| 14 | + RFF, |
| 15 | + ArcCosine, |
| 16 | + GraphKernel, |
| 17 | + Matern12, |
| 18 | + Matern32, |
| 19 | + Matern52, |
| 20 | +) |
| 21 | +from gpjax.objectives import ( |
| 22 | + ELBO, |
| 23 | + CollapsedELBO, |
| 24 | + ConjugateMLL, |
| 25 | + LogPosteriorDensity, |
| 26 | + NonConjugateMLL, |
| 27 | +) |
| 28 | + |
| 29 | +MaternKernels = Union[Matern12, Matern32, Matern52] |
| 30 | +MLLs = Union[ConjugateMLL, NonConjugateMLL, LogPosteriorDensity] |
| 31 | +CitationType = Union[str, Dict[str, str]] |
| 32 | + |
| 33 | + |
| 34 | +@dataclass(repr=False) |
| 35 | +class AbstractCitation: |
| 36 | + citation_key: str = None |
| 37 | + authors: str = None |
| 38 | + title: str = None |
| 39 | + year: str = None |
| 40 | + |
| 41 | + def as_str(self) -> str: |
| 42 | + citation_str = f"@{self.citation_type}{{{self.citation_key}," |
| 43 | + for field in fields(self): |
| 44 | + fn = field.name |
| 45 | + if fn not in ["citation_type", "citation_key", "notes"]: |
| 46 | + citation_str += f"\n{fn} = {{{getattr(self, fn)}}}," |
| 47 | + return citation_str + "\n}" |
| 48 | + |
| 49 | + def __repr__(self) -> str: |
| 50 | + return repr(self.as_str()) |
| 51 | + |
| 52 | + def __str__(self) -> str: |
| 53 | + return self.as_str() |
| 54 | + |
| 55 | + |
| 56 | +class NullCitation(AbstractCitation): |
| 57 | + def __str__(self) -> str: |
| 58 | + return ( |
| 59 | + "No citation available. If you think this is an error, please open a pull" |
| 60 | + " request." |
| 61 | + ) |
| 62 | + |
| 63 | + |
| 64 | +class JittedFnCitation(AbstractCitation): |
| 65 | + def __str__(self) -> str: |
| 66 | + return "Citation not available for jitted objects." |
| 67 | + |
| 68 | + |
| 69 | +@dataclass |
| 70 | +class PhDThesisCitation(AbstractCitation): |
| 71 | + school: str = None |
| 72 | + institution: str = None |
| 73 | + citation_type: str = "phdthesis" |
| 74 | + |
| 75 | + |
| 76 | +@dataclass |
| 77 | +class PaperCitation(AbstractCitation): |
| 78 | + booktitle: str = None |
| 79 | + citation_type: str = "inproceedings" |
| 80 | + |
| 81 | + |
| 82 | +@dataclass |
| 83 | +class BookCitation(AbstractCitation): |
| 84 | + publisher: str = None |
| 85 | + volume: str = None |
| 86 | + citation_type: str = "book" |
| 87 | + |
| 88 | + |
| 89 | +#################### |
| 90 | +# Default citation |
| 91 | +#################### |
| 92 | +@dispatch |
| 93 | +def cite(tree) -> NullCitation: |
| 94 | + return NullCitation() |
| 95 | + |
| 96 | + |
| 97 | +#################### |
| 98 | +# Default citation |
| 99 | +#################### |
| 100 | +@dispatch |
| 101 | +def cite(tree: PjitFunction) -> JittedFnCitation: |
| 102 | + return JittedFnCitation() |
| 103 | + |
| 104 | + |
| 105 | +#################### |
| 106 | +# Kernel citations |
| 107 | +#################### |
| 108 | +@dispatch |
| 109 | +def cite(tree: MaternKernels) -> PhDThesisCitation: |
| 110 | + citation = PhDThesisCitation( |
| 111 | + citation_key="matern1960SpatialV", |
| 112 | + authors="Bertil Matérn", |
| 113 | + title=( |
| 114 | + "Spatial variation : Stochastic models and their application to some" |
| 115 | + " problems in forest surveys and other sampling investigations" |
| 116 | + ), |
| 117 | + year="1960", |
| 118 | + school="Stockholm University", |
| 119 | + institution="Stockholm University", |
| 120 | + ) |
| 121 | + return citation |
| 122 | + |
| 123 | + |
| 124 | +@dispatch |
| 125 | +def cite(tree: ArcCosine) -> PaperCitation: |
| 126 | + return PaperCitation( |
| 127 | + citation_key="cho2009kernel", |
| 128 | + authors="Cho, Youngmin and Saul, Lawrence", |
| 129 | + title="Kernel Methods for Deep Learning", |
| 130 | + year="2009", |
| 131 | + booktitle="Advances in Neural Information Processing Systems", |
| 132 | + ) |
| 133 | + |
| 134 | + |
| 135 | +@dispatch |
| 136 | +def cite(tree: GraphKernel) -> PaperCitation: |
| 137 | + return PaperCitation( |
| 138 | + citation_key="borovitskiy2021matern", |
| 139 | + title="Matérn Gaussian Processes on Graphs", |
| 140 | + authors=( |
| 141 | + "Borovitskiy, Viacheslav and Azangulov, Iskander and Terenin, Alexander and" |
| 142 | + " Mostowsky, Peter and Deisenroth, Marc and Durrande, Nicolas" |
| 143 | + ), |
| 144 | + booktitle="International Conference on Artificial Intelligence and Statistics", |
| 145 | + year="2021", |
| 146 | + ) |
| 147 | + |
| 148 | + |
| 149 | +@dispatch |
| 150 | +def cite(tree: RFF) -> PaperCitation: |
| 151 | + return PaperCitation( |
| 152 | + citation_key="rahimi2007random", |
| 153 | + authors="Rahimi, Ali and Recht, Benjamin", |
| 154 | + title="Random features for large-scale kernel machines", |
| 155 | + year="2007", |
| 156 | + booktitle="Advances in neural information processing systems", |
| 157 | + citation_type="article", |
| 158 | + ) |
| 159 | + |
| 160 | + |
| 161 | +#################### |
| 162 | +# Objective citations |
| 163 | +#################### |
| 164 | +@dispatch |
| 165 | +def cite(tree: MLLs) -> BookCitation: |
| 166 | + return BookCitation( |
| 167 | + citation_key="rasmussen2006gaussian", |
| 168 | + title="Gaussian Processes for Machine Learning", |
| 169 | + authors="Rasmussen, Carl Edward and Williams, Christopher K", |
| 170 | + year="2006", |
| 171 | + publisher="MIT press Cambridge, MA", |
| 172 | + volume="2", |
| 173 | + ) |
| 174 | + |
| 175 | + |
| 176 | +@dispatch |
| 177 | +def cite(tree: CollapsedELBO) -> PaperCitation: |
| 178 | + return PaperCitation( |
| 179 | + citation_key="titsias2009variational", |
| 180 | + title="Variational learning of inducing variables in sparse Gaussian processes", |
| 181 | + authors="Titsias, Michalis", |
| 182 | + year="2009", |
| 183 | + booktitle="International Conference on Artificial Intelligence and Statistics", |
| 184 | + ) |
| 185 | + |
| 186 | + |
| 187 | +@dispatch |
| 188 | +def cite(tree: ELBO) -> PaperCitation: |
| 189 | + return PaperCitation( |
| 190 | + citation_key="hensman2013gaussian", |
| 191 | + title="Gaussian Processes for Big Data", |
| 192 | + authors="Hensman, James and Fusi, Nicolo and Lawrence, Neil D", |
| 193 | + year="2013", |
| 194 | + booktitle="Uncertainty in Artificial Intelligence", |
| 195 | + citation_type="article", |
| 196 | + ) |
0 commit comments