metacountregressor 0.1.63__tar.gz → 0.1.65__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.
Files changed (52) hide show
  1. metacountregressor-0.1.65/PKG-INFO +274 -0
  2. metacountregressor-0.1.65/README.md +253 -0
  3. {metacountregressor-0.1.63 → metacountregressor-0.1.65}/metacountregressor/__init__.py +0 -3
  4. metacountregressor-0.1.65/metacountregressor/data/1848.csv +1849 -0
  5. metacountregressor-0.1.65/metacountregressor/data/4000.csv +4746 -0
  6. metacountregressor-0.1.65/metacountregressor/data/Copy of 190613_HV Crash Data 2007-2017 Dates.xlsx +0 -0
  7. metacountregressor-0.1.65/metacountregressor/data/Ex-16-3.csv +276 -0
  8. metacountregressor-0.1.65/metacountregressor/data/Ex-16-3variables.csv +276 -0
  9. metacountregressor-0.1.65/metacountregressor/data/Indiana_data.csv +339 -0
  10. metacountregressor-0.1.65/metacountregressor/data/MichiganData.csv +33972 -0
  11. metacountregressor-0.1.65/metacountregressor/data/Stage5A.csv +1849 -0
  12. metacountregressor-0.1.65/metacountregressor/data/Stage5A_1848_All_Initial_Columns.csv +1849 -0
  13. metacountregressor-0.1.65/metacountregressor/data/ThaiAccident.csv +20230 -0
  14. metacountregressor-0.1.65/metacountregressor/data/artificial_1h_mixed_corr_2023_MOOF.csv +1001 -0
  15. metacountregressor-0.1.65/metacountregressor/data/artificial_ZA.csv +20001 -0
  16. metacountregressor-0.1.65/metacountregressor/data/artificial_mixed_corr_2023_MOOF.csv +2001 -0
  17. metacountregressor-0.1.65/metacountregressor/data/artificial_mixed_corr_2023_MOOF_copy.csv +2001 -0
  18. metacountregressor-0.1.65/metacountregressor/data/latex_summary_output.tex +2034 -0
  19. metacountregressor-0.1.65/metacountregressor/data/rqc40516_MotorcycleQUT_engineer_crash.csv +8287 -0
  20. metacountregressor-0.1.65/metacountregressor/data/rural_int.csv +37081 -0
  21. metacountregressor-0.1.65/metacountregressor/data/sum_stats.R +83 -0
  22. metacountregressor-0.1.65/metacountregressor/data/summary_output.txt +302 -0
  23. {metacountregressor-0.1.63 → metacountregressor-0.1.65}/metacountregressor/main.py +0 -3
  24. metacountregressor-0.1.65/metacountregressor/plt_style.txt +52 -0
  25. metacountregressor-0.1.65/metacountregressor/requirements.txt +16 -0
  26. metacountregressor-0.1.65/metacountregressor/requirements_new.txt +145 -0
  27. metacountregressor-0.1.65/metacountregressor/set_data.csv +8440 -0
  28. metacountregressor-0.1.65/pyproject.toml +25 -0
  29. metacountregressor-0.1.63/PKG-INFO +0 -14
  30. metacountregressor-0.1.63/README.rst +0 -357
  31. metacountregressor-0.1.63/metacountregressor/test_motor.py +0 -296
  32. metacountregressor-0.1.63/metacountregressor.egg-info/PKG-INFO +0 -14
  33. metacountregressor-0.1.63/metacountregressor.egg-info/SOURCES.txt +0 -25
  34. metacountregressor-0.1.63/metacountregressor.egg-info/dependency_links.txt +0 -1
  35. metacountregressor-0.1.63/metacountregressor.egg-info/not-zip-safe +0 -1
  36. metacountregressor-0.1.63/metacountregressor.egg-info/requires.txt +0 -2
  37. metacountregressor-0.1.63/metacountregressor.egg-info/top_level.txt +0 -1
  38. metacountregressor-0.1.63/setup.cfg +0 -7
  39. metacountregressor-0.1.63/setup.py +0 -24
  40. metacountregressor-0.1.63/tests/test_dev.py +0 -2
  41. {metacountregressor-0.1.63 → metacountregressor-0.1.65}/LICENSE.txt +0 -0
  42. {metacountregressor-0.1.63 → metacountregressor-0.1.65}/metacountregressor/_device_cust.py +0 -0
  43. {metacountregressor-0.1.63 → metacountregressor-0.1.65}/metacountregressor/halton.py +0 -0
  44. {metacountregressor-0.1.63 → metacountregressor-0.1.65}/metacountregressor/helperprocess.py +0 -0
  45. {metacountregressor-0.1.63 → metacountregressor-0.1.65}/metacountregressor/main_old.py +0 -0
  46. {metacountregressor-0.1.63 → metacountregressor-0.1.65}/metacountregressor/metaheuristics.py +0 -0
  47. {metacountregressor-0.1.63 → metacountregressor-0.1.65}/metacountregressor/pareto_file.py +0 -0
  48. {metacountregressor-0.1.63 → metacountregressor-0.1.65}/metacountregressor/pareto_logger__plot.py +0 -0
  49. {metacountregressor-0.1.63 → metacountregressor-0.1.65}/metacountregressor/setup.py +0 -0
  50. {metacountregressor-0.1.63 → metacountregressor-0.1.65}/metacountregressor/single_objective_finder.py +0 -0
  51. {metacountregressor-0.1.63 → metacountregressor-0.1.65}/metacountregressor/solution.py +0 -0
  52. {metacountregressor-0.1.63 → metacountregressor-0.1.65}/metacountregressor/test_generated_paper2.py +0 -0
@@ -0,0 +1,274 @@
1
+ Metadata-Version: 2.1
2
+ Name: metacountregressor
3
+ Version: 0.1.65
4
+ Summary: A python package for count regression of rare events assisted by metaheuristics
5
+ Author: zahern
6
+ Author-email: zeke.ahern@hdr.qut.edu.au
7
+ Requires-Python: >=3.10,<3.11
8
+ Classifier: Programming Language :: Python :: 3
9
+ Classifier: Programming Language :: Python :: 3.10
10
+ Requires-Dist: latextable (>=1.0.0,<2.0.0)
11
+ Requires-Dist: matplotlib (>=3.7.1,<4.0.0)
12
+ Requires-Dist: numpy (>=1.24.3,<2.0.0)
13
+ Requires-Dist: pandas (>=2.0.2,<3.0.0)
14
+ Requires-Dist: psutil (>=5.9.5,<6.0.0)
15
+ Requires-Dist: scikit-learn (>=1.2.2,<2.0.0)
16
+ Requires-Dist: scipy (>=1.10.1,<2.0.0)
17
+ Requires-Dist: statsmodels (>=0.14.0,<0.15.0)
18
+ Requires-Dist: tabulate (>=0.9.0,<0.10.0)
19
+ Description-Content-Type: text/markdown
20
+
21
+ <div style="display: flex; align-items: center;">
22
+ <img src="https://github.com/zahern/data/raw/main/m.png" alt="My Image" style="width: 200px; margin-right: 20px;">
23
+ <p><span style="font-size: 60px;"><strong>MetaCountRegressor</strong></span></p>
24
+ </div>
25
+
26
+ ##### Quick Setup
27
+ The Below code demonstrates how to set up automatic optimization assisted by the harmony search algorithm. References to the Differential Evolution and Simulated Annealing has been mentioned (change accordingly)
28
+
29
+ ## Quick install: Requires Python 3.10
30
+
31
+ Install `metacountregressor` using pip as follows:
32
+
33
+ ```bash
34
+ pip install metacountregressor
35
+
36
+
37
+ ```python
38
+ import pandas as pd
39
+ import numpy as np
40
+ from metacountregressor.solution import ObjectiveFunction
41
+ from metacountregressor.metaheuristics import (harmony_search,
42
+ differential_evolution,
43
+ simulated_annealing)
44
+ ```
45
+
46
+ #### Basic setup.
47
+ The initial setup involves reading in the data and selecting an optimization algorithm. As the runtime progresses, new solutions will be continually evaluated. Finally, at the end of the runtime, the best solution will be identified and printed out. In the case of multiple objectives all of the best solutions will be printed out that belong to the Pareto frontier.
48
+
49
+
50
+ ```python
51
+ # Read data from CSV file
52
+ df = pd.read_csv(
53
+ "https://raw.githubusercontent.com/zahern/data/main/Ex-16-3.csv")
54
+ X = df
55
+ y = df['FREQ'] # Frequency of crashes
56
+ X['Offset'] = np.log(df['AADT']) # Explicitley define how to offset the data, no offset otherwise
57
+ # Drop Y, selected offset term and ID as there are no panels
58
+ X = df.drop(columns=['FREQ', 'ID', 'AADT'])
59
+
60
+ #some example argument, these are defualt so the following line is just for claritity. See the later agruments section for detials.
61
+ arguments = {'algorithm': 'hs', 'test_percentage': 0.15, 'test_complexity': 6, 'instance_number':1,
62
+ 'val_percentage':0.15, 'obj_1': 'bic', '_obj_2': 'RMSE_TEST', "MAX_TIME": 6}
63
+ # Fit the model with metacountregressor
64
+ obj_fun = ObjectiveFunction(X, y, **arguments)
65
+ #replace with other metaheuristics if desired
66
+ results = harmony_search(obj_fun)
67
+
68
+
69
+ ```
70
+
71
+ ## Arguments to feed into the Objective Function:
72
+ ###
73
+ Note: Please Consider the main arguments to change.
74
+
75
+ - `algorithm`: This parameter has multiple choices for the algorithm, such as 'hs', 'sa', and 'de'. Only one choice should be defined as a string value.
76
+ - `test_percentage`: This parameter represents the percentage of data used for in-sample prediction of the model. The value 0.15 corresponds to 15% of the data.
77
+ - `val_percentage`: This parameter represents the percentage of data used to validate the model. The value 0.15 corresponds to 15% of the data.
78
+ - `test_complexity`: This parameter defines the complexity level for testing. The value 6 tests all complexities. Alternatively, you can provide a list of numbers to consider different complexities. The complexities are further explained later in this document.
79
+ - `instance_number`: This parameter is used to give a name to the outputs.
80
+ - `obj_1`: This parameter has multiple choices for obj_1, such as 'bic', 'aic', and 'hqic'. Only one choice should be defined as a string value.
81
+ - `_obj_2`: This parameter has multiple choices for objective 2, such as 'RMSE_TEST', 'MSE_TEST', and 'MAE_TEST'.
82
+ - `_max_time`: This parameter specifies the maximum number of seconds for the total estimation before stopping.
83
+ - `distribution`: This parameter is a list of distributions to consider. Please select all of the available options and put them into a list of valid options if you want to to consider the distribution type for use when modellign with random parameters. The valid options include: 'Normal', 'LnNormal', 'Triangular', and 'Uniform'.
84
+ - `transformations`: This parameters is a list of transformations to consider. Plesee select all of the available options and put them into a list of valid options if you want to consider the transformation type. The valid options include 'Normal', 'LnNormal', 'Triangular', 'Uniform'.
85
+ - `method_ll`: This is a specificication on the type of solvers are avilable to solve the lower level maximum likilihood objective. The valid options include: 'Normal', 'LnNormal', 'Triangular', and 'Uniform'.
86
+
87
+
88
+
89
+ ### An Example of changing the arguments.
90
+ Modify the arguments according to your preferences using the commented code as a guide.
91
+
92
+
93
+ ```python
94
+ #Solution Arguments
95
+ arguments = {
96
+ 'algorithm': 'hs', #alternatively input 'de', or 'sa'
97
+ 'is_multi': 1,
98
+ 'test_percentage': 0.2, # used in multi-objective optimisation only. Saves 20% of data for testing.
99
+ 'val_percenetage:': 0.2, # Saves 20% of data for testing.
100
+ 'test_complexity': 6, # Complexity level for testing (6 tests all) or a list to consider potential differences in complexity
101
+ 'instance_number': 'name', # used for creeating a named folder where your models are saved into from the directory
102
+ 'distribution': ['Normal', 'LnNormal', 'Triangular', 'Uniform'],
103
+ 'Model': [0,1], # or equivalently ['POS', 'NB']
104
+ 'transformations': ['no', 'sqrt', 'archsinh'],
105
+ 'method_ll': 'BFGS_2',
106
+ '_max_time': 10
107
+ }
108
+ obj_fun = ObjectiveFunction(X, y, **arguments)
109
+ results = harmony_search(obj_fun)
110
+ ```
111
+
112
+ ## Initial Solution Configurement
113
+ Listed below is an example of how to specify an initial solution within the framework. This initial solution will be used to calculate the fitness and considered in the objective-based search. However, as the search progresses, different hypotheses may be proposed, and alternative modeling components may completely replace the initial solution.
114
+
115
+
116
+ ```python
117
+ #Model Decisions, Specify for Intial Optimization
118
+ manual_fit_spec = {
119
+ 'fixed_terms': ['SINGLE', 'LENGTH'],
120
+ 'rdm_terms': ['AADT:normal'],
121
+ 'rdm_cor_terms': ['GRADEBR:uniform', 'CURVES:triangular'],
122
+ 'grouped_terms': [],
123
+ 'hetro_in_means': ['ACCESS:normal', 'MINRAD:normal'],
124
+ 'transformations': ['no', 'no', 'log', 'no', 'no', 'no', 'no'],
125
+ 'dispersion': 1
126
+ }
127
+ #Search Arguments
128
+ arguments = {
129
+ 'algorithm': 'hs',
130
+ 'test_percentage': 0.2,
131
+ 'test_complexity': 6,
132
+ 'instance_number': 'name',
133
+ 'Manual_Fit': manual_fit_spec
134
+ }
135
+ obj_fun = ObjectiveFunction(X, y, **arguments)
136
+ ```
137
+
138
+ simarly to return the results feed the objective function into a metaheuristic solution algorithm. An example of this is provided below:
139
+
140
+
141
+ ```python
142
+ results = harmony_search(obj_fun)
143
+ print(results)
144
+ ```
145
+
146
+ ## Notes:
147
+ ### Capabilities of the software include:
148
+ * Handling of Panel Data
149
+ * Support for Data Transformations
150
+ * Implementation of Models with Correlated and Non-Correlated Random Parameters
151
+ * A variety of mixing distributions for parameter estimations, including normal, lognormal, truncated normal, Lindley, Gamma, triangular, and uniform distributions
152
+ Capability to handle heterogeneity in the means of the random parameters
153
+ * Use of Halton draws for simulated maximum likelihood estimation
154
+ * Support for grouped random parameters with unbalanced groups
155
+ * Post-estimation tools for assessing goodness of fit, making predictions, and conducting out-of-sample validation
156
+ * Multiple parameter optimization routines, such as the BFGS method
157
+ * Comprehensive hypothesis testing using single objectives, such as in-sample BIC and log-likelihood
158
+ * Extensive hypothesis testing using multiple objectives, such as in-sample BIC and out-of-sample MAE (Mean Absolute Error), or in-sample AIC and out-of-sample MSPE (mean-square prediction errorr)
159
+ * Features that allow analysts to pre-specify variables, interactions, and mixing distributions, among others
160
+ * Meta-heuristic Guided Optimization, including techniques like Simulated Annealing, Harmony Search, and Differential Evolution
161
+ * Customization of Hyper-parameters to solve problems tailored to your dataset
162
+ * Out-of-the-box optimization capability using default metaheuristics
163
+
164
+ ### Intreting the output of the model:
165
+ A regression table is produced. The following text elements are explained:
166
+ - Std. Dev.: This column appears for effects that are related to random paramters and displays the assument distributional assumption next to it
167
+ - Chol: This term refers to Cholesky decomposition element, to show the correlation between two random paramaters. The combination of the cholesky element on iyself is equivalent to a normal random parameter.
168
+ - hetro group #: This term represents the heterogeneity group number, which refers all of the contributing factors that share hetrogentiy in the means to each other under the same numbered value.
169
+ - $\tau$: This column, displays the type of transformation that was applied to the specific contributing factor in the data.
170
+
171
+
172
+ ## Arguments:
173
+ #### In reference to the arguments that can be fed into the solution alrogithm, a dictionary system is utilised with relecant names these include
174
+
175
+
176
+ The following list describes the arguments available in this function. By default, all of the capabilities described are enabled unless specified otherwise as an argument. For list arguments, include all desired elements in the list to ensure the corresponding options are considered. Example code will be provided later in this guide.
177
+
178
+ 1. **`complexity_level`**: This argument accepts an integer 1-6 or a list based of integegers between 0 to 5 eg might be a possible configuration [0, 2, 3]. Each integer represents a hierarchy level for estimable models associated with each explanatory variable. Here is a summary of the hierarchy:
179
+ - 0: Null model
180
+ - 1: Simple fixed effects model
181
+ - 2: Random parameters model
182
+ - 3: Random correlated parameters model
183
+ - 4: Grouped random parameters model
184
+ - 5: Heterogeneity in the means random parameter model
185
+
186
+ **Note:** For the grouped random parameters model, groupings need to be defined prior to estimation. This can be achieved by including the following key-value pair in the arguments of the `ObjectiveFunction`: `'group': "Enter Column Grouping in data"`. Replace `"Enter Column Grouping in data"` with the actual column grouping in your dataset.
187
+
188
+ Similarly, for panel data, the panel column needs to be defined using the key-value pair: `'panel': "enter column string covering panels"`. Replace `"enter column string covering panels"` with the appropriate column string that represents the panel information in your dataset.
189
+
190
+ 2. **`distributions`**: This argument accepts a list of strings where each string corresponds to a distribution. Valid options include:
191
+ - "Normal"
192
+ - "Lindley"
193
+ - "Uniform"
194
+ - "LogNormal"
195
+ - "Triangular"
196
+ - "Gamma"
197
+ - "TruncatedNormal"
198
+ - Any of the above, concatenated with ":" (e.g., "Normal:grouped"; requires a grouping term defined in the model)
199
+
200
+ 3. **`Model`**: This argument specifies the model form. It can be a list of integers representing different models to test:
201
+ - 0: Poisson
202
+ - 1: Negative-Binomial
203
+ - 2: Generalized-Poisson
204
+
205
+ 4. **`transformations`**: This argument accepts a list of strings representing available transformations within the framework. Valid options include:
206
+ - "no"
207
+ - "square-root"
208
+ - "logarithmic"
209
+ - "archsinh"
210
+ - "as_factor"
211
+
212
+ 5. **`is_multi`**: This argument accepts an integer indicating whether single or multiple objectives are to be tested (0 for single, 1 for multiple).
213
+
214
+ 6. **`test_percentage`**: This argument is used for multi-objective optimization. Define it as a decimal; for example, 0.2 represents 20% of the data for testing.
215
+
216
+ 7. **`val_percentage`**: This argument saves data for validation. Define it as a decimal; for example, 0.2 represents 20% of the data for validation.
217
+
218
+ 8. **`_max_time`**: This argument is used to add a termination time in the algorithm. It takes values as seconds. Note the time is only dependenant on the time after intial population of solutions are generated.
219
+
220
+ # Example
221
+
222
+
223
+ Let's start by fitting very simple models, use those model sto help and define the objectives, then perform more of an extensive search on the variables that are identified more commonly
224
+
225
+
226
+
227
+ ```python
228
+ df = pd.read_csv(
229
+ "https://raw.githubusercontent.com/zahern/data/main/Ex-16-3.csv")
230
+ X = df
231
+ y = df['FREQ'] # Frequency of crashes
232
+ X['Offset'] = np.log(df['AADT']) # Explicitley define how to offset the data, no offset otherwise
233
+ # Drop Y, selected offset term and ID as there are no panels
234
+ X = df.drop(columns=['FREQ', 'ID', 'AADT'])
235
+
236
+ arguments = {
237
+ 'algorithm': 'hs', #alternatively input 'de', or 'sa'
238
+ 'is_multi': 1,
239
+ 'test_percentage': 0.2, # used in multi-objective optimisation only. Saves 20% of data for testing.
240
+ 'val_percentage:': 0.2, # Saves 20% of data for testing.
241
+ 'test_complexity': 3, # For Very simple Models
242
+ 'obj_1': 'BIC', '_obj_2': 'RMSE_TEST',
243
+ 'instance_number': 'name', # used for creeating a named folder where your models are saved into from the directory
244
+ 'distribution': ['Normal'],
245
+ 'Model': [0], # or equivalently ['POS', 'NB']
246
+ 'transformations': ['no', 'sqrt', 'archsinh'],
247
+ '_max_time': 10000
248
+ }
249
+ obj_fun = ObjectiveFunction(X, y, **arguments)
250
+
251
+ results = harmony_search(obj_fun)
252
+ print(results)
253
+ ```
254
+
255
+ ## Contact
256
+ If you have any questions, ideas to improve MetaCountRegressor, or want to report a bug, just open a new issue in [GitHub repository](https://github.com/zahern/CountDataEstimation).
257
+
258
+ ## Citing MetaCountRegressor
259
+ Please cite MetaCountRegressor as follows:
260
+
261
+ Ahern, Z., Corry P., Paz A. (2023). MetaCountRegressor [Computer software]. [https://pypi.org/project/metacounregressor/](https://pypi.org/project/metacounregressor/)
262
+
263
+ Or using BibTex as follows:
264
+
265
+ ```bibtex
266
+ @misc{Ahern2023,
267
+ author = {Zeke Ahern and Paul Corry and Alexander Paz},
268
+ journal = {PyPi},
269
+ title = {metacountregressor · PyPI},
270
+ url = {https://pypi.org/project/metacountregressor/0.1.47/},
271
+ year = {2023},
272
+ }
273
+
274
+
@@ -0,0 +1,253 @@
1
+ <div style="display: flex; align-items: center;">
2
+ <img src="https://github.com/zahern/data/raw/main/m.png" alt="My Image" style="width: 200px; margin-right: 20px;">
3
+ <p><span style="font-size: 60px;"><strong>MetaCountRegressor</strong></span></p>
4
+ </div>
5
+
6
+ ##### Quick Setup
7
+ The Below code demonstrates how to set up automatic optimization assisted by the harmony search algorithm. References to the Differential Evolution and Simulated Annealing has been mentioned (change accordingly)
8
+
9
+ ## Quick install: Requires Python 3.10
10
+
11
+ Install `metacountregressor` using pip as follows:
12
+
13
+ ```bash
14
+ pip install metacountregressor
15
+
16
+
17
+ ```python
18
+ import pandas as pd
19
+ import numpy as np
20
+ from metacountregressor.solution import ObjectiveFunction
21
+ from metacountregressor.metaheuristics import (harmony_search,
22
+ differential_evolution,
23
+ simulated_annealing)
24
+ ```
25
+
26
+ #### Basic setup.
27
+ The initial setup involves reading in the data and selecting an optimization algorithm. As the runtime progresses, new solutions will be continually evaluated. Finally, at the end of the runtime, the best solution will be identified and printed out. In the case of multiple objectives all of the best solutions will be printed out that belong to the Pareto frontier.
28
+
29
+
30
+ ```python
31
+ # Read data from CSV file
32
+ df = pd.read_csv(
33
+ "https://raw.githubusercontent.com/zahern/data/main/Ex-16-3.csv")
34
+ X = df
35
+ y = df['FREQ'] # Frequency of crashes
36
+ X['Offset'] = np.log(df['AADT']) # Explicitley define how to offset the data, no offset otherwise
37
+ # Drop Y, selected offset term and ID as there are no panels
38
+ X = df.drop(columns=['FREQ', 'ID', 'AADT'])
39
+
40
+ #some example argument, these are defualt so the following line is just for claritity. See the later agruments section for detials.
41
+ arguments = {'algorithm': 'hs', 'test_percentage': 0.15, 'test_complexity': 6, 'instance_number':1,
42
+ 'val_percentage':0.15, 'obj_1': 'bic', '_obj_2': 'RMSE_TEST', "MAX_TIME": 6}
43
+ # Fit the model with metacountregressor
44
+ obj_fun = ObjectiveFunction(X, y, **arguments)
45
+ #replace with other metaheuristics if desired
46
+ results = harmony_search(obj_fun)
47
+
48
+
49
+ ```
50
+
51
+ ## Arguments to feed into the Objective Function:
52
+ ###
53
+ Note: Please Consider the main arguments to change.
54
+
55
+ - `algorithm`: This parameter has multiple choices for the algorithm, such as 'hs', 'sa', and 'de'. Only one choice should be defined as a string value.
56
+ - `test_percentage`: This parameter represents the percentage of data used for in-sample prediction of the model. The value 0.15 corresponds to 15% of the data.
57
+ - `val_percentage`: This parameter represents the percentage of data used to validate the model. The value 0.15 corresponds to 15% of the data.
58
+ - `test_complexity`: This parameter defines the complexity level for testing. The value 6 tests all complexities. Alternatively, you can provide a list of numbers to consider different complexities. The complexities are further explained later in this document.
59
+ - `instance_number`: This parameter is used to give a name to the outputs.
60
+ - `obj_1`: This parameter has multiple choices for obj_1, such as 'bic', 'aic', and 'hqic'. Only one choice should be defined as a string value.
61
+ - `_obj_2`: This parameter has multiple choices for objective 2, such as 'RMSE_TEST', 'MSE_TEST', and 'MAE_TEST'.
62
+ - `_max_time`: This parameter specifies the maximum number of seconds for the total estimation before stopping.
63
+ - `distribution`: This parameter is a list of distributions to consider. Please select all of the available options and put them into a list of valid options if you want to to consider the distribution type for use when modellign with random parameters. The valid options include: 'Normal', 'LnNormal', 'Triangular', and 'Uniform'.
64
+ - `transformations`: This parameters is a list of transformations to consider. Plesee select all of the available options and put them into a list of valid options if you want to consider the transformation type. The valid options include 'Normal', 'LnNormal', 'Triangular', 'Uniform'.
65
+ - `method_ll`: This is a specificication on the type of solvers are avilable to solve the lower level maximum likilihood objective. The valid options include: 'Normal', 'LnNormal', 'Triangular', and 'Uniform'.
66
+
67
+
68
+
69
+ ### An Example of changing the arguments.
70
+ Modify the arguments according to your preferences using the commented code as a guide.
71
+
72
+
73
+ ```python
74
+ #Solution Arguments
75
+ arguments = {
76
+ 'algorithm': 'hs', #alternatively input 'de', or 'sa'
77
+ 'is_multi': 1,
78
+ 'test_percentage': 0.2, # used in multi-objective optimisation only. Saves 20% of data for testing.
79
+ 'val_percenetage:': 0.2, # Saves 20% of data for testing.
80
+ 'test_complexity': 6, # Complexity level for testing (6 tests all) or a list to consider potential differences in complexity
81
+ 'instance_number': 'name', # used for creeating a named folder where your models are saved into from the directory
82
+ 'distribution': ['Normal', 'LnNormal', 'Triangular', 'Uniform'],
83
+ 'Model': [0,1], # or equivalently ['POS', 'NB']
84
+ 'transformations': ['no', 'sqrt', 'archsinh'],
85
+ 'method_ll': 'BFGS_2',
86
+ '_max_time': 10
87
+ }
88
+ obj_fun = ObjectiveFunction(X, y, **arguments)
89
+ results = harmony_search(obj_fun)
90
+ ```
91
+
92
+ ## Initial Solution Configurement
93
+ Listed below is an example of how to specify an initial solution within the framework. This initial solution will be used to calculate the fitness and considered in the objective-based search. However, as the search progresses, different hypotheses may be proposed, and alternative modeling components may completely replace the initial solution.
94
+
95
+
96
+ ```python
97
+ #Model Decisions, Specify for Intial Optimization
98
+ manual_fit_spec = {
99
+ 'fixed_terms': ['SINGLE', 'LENGTH'],
100
+ 'rdm_terms': ['AADT:normal'],
101
+ 'rdm_cor_terms': ['GRADEBR:uniform', 'CURVES:triangular'],
102
+ 'grouped_terms': [],
103
+ 'hetro_in_means': ['ACCESS:normal', 'MINRAD:normal'],
104
+ 'transformations': ['no', 'no', 'log', 'no', 'no', 'no', 'no'],
105
+ 'dispersion': 1
106
+ }
107
+ #Search Arguments
108
+ arguments = {
109
+ 'algorithm': 'hs',
110
+ 'test_percentage': 0.2,
111
+ 'test_complexity': 6,
112
+ 'instance_number': 'name',
113
+ 'Manual_Fit': manual_fit_spec
114
+ }
115
+ obj_fun = ObjectiveFunction(X, y, **arguments)
116
+ ```
117
+
118
+ simarly to return the results feed the objective function into a metaheuristic solution algorithm. An example of this is provided below:
119
+
120
+
121
+ ```python
122
+ results = harmony_search(obj_fun)
123
+ print(results)
124
+ ```
125
+
126
+ ## Notes:
127
+ ### Capabilities of the software include:
128
+ * Handling of Panel Data
129
+ * Support for Data Transformations
130
+ * Implementation of Models with Correlated and Non-Correlated Random Parameters
131
+ * A variety of mixing distributions for parameter estimations, including normal, lognormal, truncated normal, Lindley, Gamma, triangular, and uniform distributions
132
+ Capability to handle heterogeneity in the means of the random parameters
133
+ * Use of Halton draws for simulated maximum likelihood estimation
134
+ * Support for grouped random parameters with unbalanced groups
135
+ * Post-estimation tools for assessing goodness of fit, making predictions, and conducting out-of-sample validation
136
+ * Multiple parameter optimization routines, such as the BFGS method
137
+ * Comprehensive hypothesis testing using single objectives, such as in-sample BIC and log-likelihood
138
+ * Extensive hypothesis testing using multiple objectives, such as in-sample BIC and out-of-sample MAE (Mean Absolute Error), or in-sample AIC and out-of-sample MSPE (mean-square prediction errorr)
139
+ * Features that allow analysts to pre-specify variables, interactions, and mixing distributions, among others
140
+ * Meta-heuristic Guided Optimization, including techniques like Simulated Annealing, Harmony Search, and Differential Evolution
141
+ * Customization of Hyper-parameters to solve problems tailored to your dataset
142
+ * Out-of-the-box optimization capability using default metaheuristics
143
+
144
+ ### Intreting the output of the model:
145
+ A regression table is produced. The following text elements are explained:
146
+ - Std. Dev.: This column appears for effects that are related to random paramters and displays the assument distributional assumption next to it
147
+ - Chol: This term refers to Cholesky decomposition element, to show the correlation between two random paramaters. The combination of the cholesky element on iyself is equivalent to a normal random parameter.
148
+ - hetro group #: This term represents the heterogeneity group number, which refers all of the contributing factors that share hetrogentiy in the means to each other under the same numbered value.
149
+ - $\tau$: This column, displays the type of transformation that was applied to the specific contributing factor in the data.
150
+
151
+
152
+ ## Arguments:
153
+ #### In reference to the arguments that can be fed into the solution alrogithm, a dictionary system is utilised with relecant names these include
154
+
155
+
156
+ The following list describes the arguments available in this function. By default, all of the capabilities described are enabled unless specified otherwise as an argument. For list arguments, include all desired elements in the list to ensure the corresponding options are considered. Example code will be provided later in this guide.
157
+
158
+ 1. **`complexity_level`**: This argument accepts an integer 1-6 or a list based of integegers between 0 to 5 eg might be a possible configuration [0, 2, 3]. Each integer represents a hierarchy level for estimable models associated with each explanatory variable. Here is a summary of the hierarchy:
159
+ - 0: Null model
160
+ - 1: Simple fixed effects model
161
+ - 2: Random parameters model
162
+ - 3: Random correlated parameters model
163
+ - 4: Grouped random parameters model
164
+ - 5: Heterogeneity in the means random parameter model
165
+
166
+ **Note:** For the grouped random parameters model, groupings need to be defined prior to estimation. This can be achieved by including the following key-value pair in the arguments of the `ObjectiveFunction`: `'group': "Enter Column Grouping in data"`. Replace `"Enter Column Grouping in data"` with the actual column grouping in your dataset.
167
+
168
+ Similarly, for panel data, the panel column needs to be defined using the key-value pair: `'panel': "enter column string covering panels"`. Replace `"enter column string covering panels"` with the appropriate column string that represents the panel information in your dataset.
169
+
170
+ 2. **`distributions`**: This argument accepts a list of strings where each string corresponds to a distribution. Valid options include:
171
+ - "Normal"
172
+ - "Lindley"
173
+ - "Uniform"
174
+ - "LogNormal"
175
+ - "Triangular"
176
+ - "Gamma"
177
+ - "TruncatedNormal"
178
+ - Any of the above, concatenated with ":" (e.g., "Normal:grouped"; requires a grouping term defined in the model)
179
+
180
+ 3. **`Model`**: This argument specifies the model form. It can be a list of integers representing different models to test:
181
+ - 0: Poisson
182
+ - 1: Negative-Binomial
183
+ - 2: Generalized-Poisson
184
+
185
+ 4. **`transformations`**: This argument accepts a list of strings representing available transformations within the framework. Valid options include:
186
+ - "no"
187
+ - "square-root"
188
+ - "logarithmic"
189
+ - "archsinh"
190
+ - "as_factor"
191
+
192
+ 5. **`is_multi`**: This argument accepts an integer indicating whether single or multiple objectives are to be tested (0 for single, 1 for multiple).
193
+
194
+ 6. **`test_percentage`**: This argument is used for multi-objective optimization. Define it as a decimal; for example, 0.2 represents 20% of the data for testing.
195
+
196
+ 7. **`val_percentage`**: This argument saves data for validation. Define it as a decimal; for example, 0.2 represents 20% of the data for validation.
197
+
198
+ 8. **`_max_time`**: This argument is used to add a termination time in the algorithm. It takes values as seconds. Note the time is only dependenant on the time after intial population of solutions are generated.
199
+
200
+ # Example
201
+
202
+
203
+ Let's start by fitting very simple models, use those model sto help and define the objectives, then perform more of an extensive search on the variables that are identified more commonly
204
+
205
+
206
+
207
+ ```python
208
+ df = pd.read_csv(
209
+ "https://raw.githubusercontent.com/zahern/data/main/Ex-16-3.csv")
210
+ X = df
211
+ y = df['FREQ'] # Frequency of crashes
212
+ X['Offset'] = np.log(df['AADT']) # Explicitley define how to offset the data, no offset otherwise
213
+ # Drop Y, selected offset term and ID as there are no panels
214
+ X = df.drop(columns=['FREQ', 'ID', 'AADT'])
215
+
216
+ arguments = {
217
+ 'algorithm': 'hs', #alternatively input 'de', or 'sa'
218
+ 'is_multi': 1,
219
+ 'test_percentage': 0.2, # used in multi-objective optimisation only. Saves 20% of data for testing.
220
+ 'val_percentage:': 0.2, # Saves 20% of data for testing.
221
+ 'test_complexity': 3, # For Very simple Models
222
+ 'obj_1': 'BIC', '_obj_2': 'RMSE_TEST',
223
+ 'instance_number': 'name', # used for creeating a named folder where your models are saved into from the directory
224
+ 'distribution': ['Normal'],
225
+ 'Model': [0], # or equivalently ['POS', 'NB']
226
+ 'transformations': ['no', 'sqrt', 'archsinh'],
227
+ '_max_time': 10000
228
+ }
229
+ obj_fun = ObjectiveFunction(X, y, **arguments)
230
+
231
+ results = harmony_search(obj_fun)
232
+ print(results)
233
+ ```
234
+
235
+ ## Contact
236
+ If you have any questions, ideas to improve MetaCountRegressor, or want to report a bug, just open a new issue in [GitHub repository](https://github.com/zahern/CountDataEstimation).
237
+
238
+ ## Citing MetaCountRegressor
239
+ Please cite MetaCountRegressor as follows:
240
+
241
+ Ahern, Z., Corry P., Paz A. (2023). MetaCountRegressor [Computer software]. [https://pypi.org/project/metacounregressor/](https://pypi.org/project/metacounregressor/)
242
+
243
+ Or using BibTex as follows:
244
+
245
+ ```bibtex
246
+ @misc{Ahern2023,
247
+ author = {Zeke Ahern and Paul Corry and Alexander Paz},
248
+ journal = {PyPi},
249
+ title = {metacountregressor · PyPI},
250
+ url = {https://pypi.org/project/metacountregressor/0.1.47/},
251
+ year = {2023},
252
+ }
253
+
@@ -10,10 +10,7 @@ print('loaded standard packages')
10
10
  import numpy as np
11
11
 
12
12
  import pandas as pd
13
-
14
-
15
13
  from .helperprocess import*
16
-
17
14
  print('loaded helper')
18
15
  from .metaheuristics import (differential_evolution,
19
16
  harmony_search,