function_dataloader
Bases: dataloader
A dataloader class for handling mathematical functions and equations.
This class extends the base dataloader
class to provide functionality for loading equations,
processing variables, and generating datasets based on mathematical formulas.
Attributes:
Name | Type | Description |
---|---|---|
name |
str
|
The name of the dataloader instance. |
function_list |
list
|
A list of string representations of mathematical functions or equations. |
equation_index |
int
|
The index of the currently selected equation. |
Methods:
Name | Description |
---|---|
__init__ |
Initializes the function dataloader. |
load_equation |
Loads and processes an equation from the |
load_all_equations |
Loads and processes all equations in the |
generate_data |
Generates synthetic data based on a given formula and variable ranges. |
load |
Loads training and testing datasets for a specified equation. |
Source code in tinybig/data/function_dataloader.py
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 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 |
|
__init__(name='function_dataloader', function_list=[], equation_index=0, train_batch_size=64, test_batch_size=64)
Initializes the function dataloader with a list of equations and configurations.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
name
|
The name of the dataloader instance. |
'function_dataloader'
|
|
function_list
|
list
|
A list of string representations of mathematical functions or equations. |
[]
|
equation_index
|
int
|
The index of the currently selected equation. |
0
|
train_batch_size
|
The batch size for training data. |
64
|
|
test_batch_size
|
The batch size for testing data. |
64
|
Returns:
Type | Description |
---|---|
None
|
|
Source code in tinybig/data/function_dataloader.py
generate_data(formula, variables, num=2000, value_range=(0, 1), normalize_X=False, normalize_y=False, *args, **kwargs)
staticmethod
Generates synthetic data based on a formula and variable ranges.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
formula
|
str
|
The mathematical formula to generate data for. |
required |
variables
|
dict
|
A dictionary of variable names and their respective ranges. |
required |
num
|
int
|
The number of data samples to generate. |
2000
|
value_range
|
list
|
The default range for variables if not specified in |
(0, 1)
|
normalize_X
|
bool
|
Whether to normalize the input features. |
False
|
normalize_y
|
bool
|
Whether to normalize the output values. |
False
|
Returns:
Type | Description |
---|---|
tuple
|
A tuple containing input features |
Raises:
Type | Description |
---|---|
AssertionError
|
If variable ranges are not properly specified. |
Source code in tinybig/data/function_dataloader.py
load(equation_index=None, cache_dir='./data/', num=2000, train_percentage=0.5, random_state=1234, shuffle=False, *args, **kwargs)
Loads training and testing datasets for a specified equation.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
equation_index
|
int
|
The index of the equation to load. If None, the default |
None
|
cache_dir
|
The directory for caching data. |
'./data/'
|
|
num
|
The number of data samples to generate. |
2000
|
|
train_percentage
|
The percentage of data to use for training. |
0.5
|
|
random_state
|
The random seed for reproducibility. |
1234
|
|
shuffle
|
Whether to shuffle the data before splitting. |
False
|
Returns:
Type | Description |
---|---|
dict
|
A dictionary containing training and testing data loaders, and the equation string. |
Raises:
Type | Description |
---|---|
ValueError
|
If the |
Source code in tinybig/data/function_dataloader.py
load_all_equations()
Loads and processes all equations in the function_list
.
Returns:
Type | Description |
---|---|
dict
|
A dictionary where each key is an equation index, and the value is a tuple containing the processed equation dictionary and the original string representation. |
Source code in tinybig/data/function_dataloader.py
load_equation(index=0)
Loads and processes a specific equation from the function list.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
index
|
int
|
The index of the equation to load. If None, the default |
0
|
Returns:
Type | Description |
---|---|
tuple
|
A tuple containing the processed equation dictionary and the original string representation. |
Raises:
Type | Description |
---|---|
AssertionError
|
If the index is out of range of the |