metacountregressor 0.1.47__py3-none-any.whl → 0.1.49__py3-none-any.whl

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.
@@ -0,0 +1,236 @@
1
+ Metadata-Version: 2.1
2
+ Name: metacountregressor
3
+ Version: 0.1.49
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="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
+ ##### 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)
27
+
28
+ ## Quick install: Requires Python 3.10
29
+
30
+ Install `metacountregressor` using pip as follows:
31
+
32
+ ```bash
33
+ pip install metacountregressor
34
+
35
+
36
+ ```python
37
+ import pandas as pd
38
+ import numpy as np
39
+ from metacountregressor.solution import ObjectiveFunction
40
+ from metacountregressor.metaheuristics import (harmony_search,
41
+ differential_evolution,
42
+ simulated_annealing)
43
+ ```
44
+
45
+ #### Basic setup.
46
+ 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.
47
+
48
+
49
+ ```python
50
+ # Read data from CSV file
51
+ df = pd.read_csv(
52
+ "https://raw.githubusercontent.com/zahern/data/main/Ex-16-3.csv")
53
+ X = df
54
+ y = df['FREQ'] # Frequency of crashes
55
+ X['Offset'] = np.log(df['AADT']) # Explicitley define how to offset the data, no offset otherwise
56
+ # Drop Y, selected offset term and ID as there are no panels
57
+ X = df.drop(columns=['FREQ', 'ID', 'AADT'])
58
+
59
+ #some example argument, these are defualt so the following line is just for claritity. See the later agruments section for detials.
60
+ arguments = {'algorithm': 'hs', 'test_percentage': 0.15, 'test_complexity': 6, 'instance_number':1,
61
+ 'val_percentage':0.15, 'obj_1': 'bic', '_obj_2': 'RMSE_TEST', "MAX_TIME": 6}
62
+ # Fit the model with metacountregressor
63
+ obj_fun = ObjectiveFunction(X, y, **arguments)
64
+ #replace with other metaheuristics if desired
65
+ results = harmony_search(obj_fun)
66
+
67
+
68
+ ```
69
+
70
+ ## Arguments to feed into the Objective Function:
71
+ ###
72
+ Note: Please Consider the main arguments to change.
73
+
74
+ - `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.
75
+ - `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.
76
+ - `val_percentage`: This parameter represents the percentage of data used to validate the model. The value 0.15 corresponds to 15% of the data.
77
+ - `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.
78
+ - `instance_number`: This parameter is used to give a name to the outputs.
79
+ - `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.
80
+ - `_obj_2`: This parameter has multiple choices for objective 2, such as 'RMSE_TEST', 'MSE_TEST', and 'MAE_TEST'.
81
+ - `MAX_TIME`: This parameter specifies the maximum number of seconds for the total estimation before stopping.
82
+ - `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'.
83
+ - `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'.
84
+
85
+
86
+
87
+ ### An Example of changing the arguments.
88
+ Modify the arguments according to your preferences using the commented code as a guide.
89
+
90
+
91
+ ```python
92
+ #Solution Arguments
93
+ arguments = {
94
+ 'algorithm': 'hs', #alternatively input 'de', or 'sa'
95
+ 'is_multi': 1,
96
+ 'test_percentage': 0.2, # used in multi-objective optimisation only. Saves 20% of data for testing.
97
+ 'val_percenetage:': 0.2, # Saves 20% of data for testing.
98
+ 'test_complexity': 6, # Complexity level for testing (6 tests all) or a list to consider potential differences in complexity
99
+ 'instance_number': 'name', # used for creeating a named folder where your models are saved into from the directory
100
+ 'distribution': ['Normal', 'LnNormal', 'Triangular', 'Uniform'],
101
+ 'Model': [0,1], # or equivalently ['POS', 'NB']
102
+ 'transformations': ['no', 'sqrt', 'archsinh'],
103
+ '_max_time': 10
104
+ }
105
+ obj_fun = ObjectiveFunction(X, y, **arguments)
106
+ results = harmony_search(obj_fun)
107
+ ```
108
+
109
+ ## Initial Solution Configurement
110
+ 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.
111
+
112
+
113
+ ```python
114
+ #Model Decisions, Specify for Intial Optimization
115
+ manual_fit_spec = {
116
+ 'fixed_terms': ['SINGLE', 'LENGTH'],
117
+ 'rdm_terms': ['AADT:normal'],
118
+ 'rdm_cor_terms': ['GRADEBR:uniform', 'CURVES:triangular'],
119
+ 'grouped_terms': [],
120
+ 'hetro_in_means': ['ACCESS:normal', 'MINRAD:normal'],
121
+ 'transformations': ['no', 'no', 'log', 'no', 'no', 'no', 'no'],
122
+ 'dispersion': 1
123
+ }
124
+ #Search Arguments
125
+ arguments = {
126
+ 'algorithm': 'hs',
127
+ 'test_percentage': 0.2,
128
+ 'test_complexity': 6,
129
+ 'instance_number': 'name',
130
+ 'Manual_Fit': manual_fit_spec
131
+ }
132
+ obj_fun = ObjectiveFunction(X, y, **arguments)
133
+ ```
134
+
135
+ simarly to return the results feed the objective function into a metaheuristic solution algorithm. An example of this is provided below:
136
+
137
+
138
+ ```python
139
+ results = harmony_search(obj_fun)
140
+ print(results)
141
+ ```
142
+
143
+ ## Notes:
144
+ ### Capabilities of the software include:
145
+ * Handling of Panel Data
146
+ * Support for Data Transformations
147
+ * Implementation of Models with Correlated and Non-Correlated Random Parameters
148
+ * A variety of mixing distributions for parameter estimations, including normal, lognormal, truncated normal, Lindley, Gamma, triangular, and uniform distributions
149
+ Capability to handle heterogeneity in the means of the random parameters
150
+ * Use of Halton draws for simulated maximum likelihood estimation
151
+ * Support for grouped random parameters with unbalanced groups
152
+ * Post-estimation tools for assessing goodness of fit, making predictions, and conducting out-of-sample validation
153
+ * Multiple parameter optimization routines, such as the BFGS method
154
+ * Comprehensive hypothesis testing using single objectives, such as in-sample BIC and log-likelihood
155
+ * 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)
156
+ * Features that allow analysts to pre-specify variables, interactions, and mixing distributions, among others
157
+ * Meta-heuristic Guided Optimization, including techniques like Simulated Annealing, Harmony Search, and Differential Evolution
158
+ * Customization of Hyper-parameters to solve problems tailored to your dataset
159
+ * Out-of-the-box optimization capability using default metaheuristics
160
+
161
+ ### Intreting the output of the model:
162
+ A regression table is produced. The following text elements are explained:
163
+ - Std. Dev.: This column appears for effects that are related to random paramters and displays the assument distributional assumption next to it
164
+ - 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.
165
+ - 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.
166
+ - $\tau$: This column, displays the type of transformation that was applied to the specific contributing factor in the data.
167
+
168
+
169
+ ## Arguments:
170
+ #### In reference to the arguments that can be fed into the solution alrogithm, a dictionary system is utilised with relecant names these include
171
+
172
+
173
+ 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.
174
+
175
+ 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:
176
+ - 0: Null model
177
+ - 1: Simple fixed effects model
178
+ - 2: Random parameters model
179
+ - 3: Random correlated parameters model
180
+ - 4: Grouped random parameters model
181
+ - 5: Heterogeneity in the means random parameter model
182
+
183
+ **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.
184
+
185
+ 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.
186
+
187
+ 2. **`distributions`**: This argument accepts a list of strings where each string corresponds to a distribution. Valid options include:
188
+ - "Normal"
189
+ - "Lindley"
190
+ - "Uniform"
191
+ - "LogNormal"
192
+ - "Triangular"
193
+ - "Gamma"
194
+ - "TruncatedNormal"
195
+ - Any of the above, concatenated with ":" (e.g., "Normal:grouped"; requires a grouping term defined in the model)
196
+
197
+ 3. **`Model`**: This argument specifies the model form. It can be a list of integers representing different models to test:
198
+ - 0: Poisson
199
+ - 1: Negative-Binomial
200
+ - 2: Generalized-Poisson
201
+
202
+ 4. **`transformations`**: This argument accepts a list of strings representing available transformations within the framework. Valid options include:
203
+ - "no"
204
+ - "square-root"
205
+ - "logarithmic"
206
+ - "archsinh"
207
+ - "as_factor"
208
+
209
+ 5. **`is_multi`**: This argument accepts an integer indicating whether single or multiple objectives are to be tested (0 for single, 1 for multiple).
210
+
211
+ 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.
212
+
213
+ 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.
214
+
215
+ 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.
216
+
217
+ ## Contact
218
+ 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).
219
+
220
+ ## Citing MetaCountRegressor
221
+ Please cite MetaCountRegressor as follows:
222
+
223
+ Ahern, Z., Corry P., Paz A. (2023). MetaCountRegressor [Computer software]. [https://pypi.org/project/metacounregressor/](https://pypi.org/project/metacounregressor/)
224
+
225
+ Or using BibTex as follows:
226
+
227
+ ```bibtex
228
+ @misc{Ahern2023,
229
+ author = {Zeke Ahern and Paul Corry and Alexander Paz},
230
+ journal = {PyPi},
231
+ title = {metacountregressor · PyPI},
232
+ url = {https://pypi.org/project/metacountregressor/0.1.47/},
233
+ year = {2023},
234
+ }
235
+
236
+
@@ -1,8 +1,9 @@
1
1
  metacountregressor/1848.csv,sha256=EMXrgQsLrOwEIYMBIV0XLAnXPpzwiQRWoxg1ueL_k7U,49365
2
2
  metacountregressor/1h_syntth_please.ipynb,sha256=RI7S3TUx-FafrGrYaPtoCOHjbtAtTDpfif6Ka2bRJbs,25000
3
3
  metacountregressor/4000.csv,sha256=lTCmjN50e05DoPFPnAR1M7o-ECt5Su55T20p2BZ2HzY,135986
4
- metacountregressor/__init__.py,sha256=Mt9_rm0pJVqyDYdo_qVIejZt5H6wdfzq_k8tHTIqxh4,208
5
- metacountregressor/_device_cust.py,sha256=Ek-dgesZ5zZ8UeJA4hh3s9Q7Bb2duDwIwfWEaAouDNg,2074
4
+ metacountregressor/__init__.py,sha256=v7LfPyo5S2f0CR4tD0vX5zxm7HuHKFiKgxUnW5Oyk9M,2924
5
+ metacountregressor/_device_cust.py,sha256=2KcXnDUrzwMGMdgC7XEzqwJbMeIF9emY2WzFvJnN2co,2113
6
+ metacountregressor/alog.png,sha256=1G3vajvqzTphv6BxKeEV5t_axUq2zrT0iWy1ZblMYVQ,965927
6
7
  metacountregressor/artificial_1h_mixed_corr_2023_MOOF.csv,sha256=PbgmFs3xaPzjFD7aALDWzaYhEyLKKBC-w_9DfyHV-gc,433769
7
8
  metacountregressor/artificial_mixed_corr_2023_MOOF.csv,sha256=P-211ts-GR_uxlR_TbuuNwa1lTLcEJVMVAwTltFGDFc,7343652
8
9
  metacountregressor/artificial_ZA.csv,sha256=w8GBj586DzDfKOn8hwHDNkLeBz5si0qopht1JjAWaTU,3713176
@@ -38,7 +39,7 @@ metacountregressor/set_data.csv,sha256=68iJkW4O4HVM8GyNlO0drwp8ZMXkccXCUc7jnA8xn
38
39
  metacountregressor/set_data_s.csv,sha256=hELwnv6RjpmXcMheFafwrYbLbyYE21hFKyqJhA8L05o,11111
39
40
  metacountregressor/setup.py,sha256=CpbdBScFhvStc6WByFiAlP7T5wGdWetsLI8X5JRRpP4,268
40
41
  metacountregressor/single_objective_finder.py,sha256=QYXUpxJp7-ul5ZiIKGgYGaH_yFFGUbI7X3yKu5asogE,1960
41
- metacountregressor/solution.py,sha256=wtbIfLOLrNAwMmImWr90inPpuk_eRFk__bg7iLBVeMM,303353
42
+ metacountregressor/solution.py,sha256=_psVXiW-yBi4WqdI3a3aD4tIA2m_jGnC3dmG121JtLo,313756
42
43
  metacountregressor/Stage5A_1848_All_Initial_Columns.csv,sha256=uwsadEyupgIH1w5f8vnlwlo13ryww3VCGYlOnN0dEL0,188769
43
44
  metacountregressor/Stage5A_1848_All_Initial_Columns.xlsx,sha256=5U5Ab1jjGi5qoKp06Bw2tpdPjGaDGoyt5976AAFdEbs,699231
44
45
  metacountregressor/synth_dataset_generator.ipynb,sha256=caBMQJOaeINPZJw5aTsSOXhmenSqrpS7GycINAzUUxs,27153
@@ -48,6 +49,6 @@ metacountregressor/testML.R,sha256=UbTsLFUhoJG9bJnU2rbUKlfcprAkROnhREK41qKzbvQ,2
48
49
  metacountregressor/TestSetFake.csv,sha256=JPYAWYLAw7rgQHdGTz0rltMfapX8QYt3BVSyK_D-Lzg,1640
49
50
  metacountregressor/ThaiAccident.csv,sha256=NIi_uPyo5u-B6Hj0Ln9xuJ8fnvGbWK9GLdTWdpG5uug,418202
50
51
  metacountregressor/tk_app.py,sha256=0UM76hpQ-ha96ma_Z5ryxYQUSdF4PJBCsLuI1EGu6_E,59490
51
- metacountregressor-0.1.47.dist-info/METADATA,sha256=WV4WnzYGY9_Qy5LxbZNdS7DUgrjUtDh4Dh_oUTcBKUs,28479
52
- metacountregressor-0.1.47.dist-info/WHEEL,sha256=Zb28QaM1gQi8f4VCBhsUklF61CTlNYfs9YAZn-TOGFk,88
53
- metacountregressor-0.1.47.dist-info/RECORD,,
52
+ metacountregressor-0.1.49.dist-info/METADATA,sha256=W_TMNtPDympIWynyAhJ7sD6a3FEa1Xjx4NwEHMWutdQ,13060
53
+ metacountregressor-0.1.49.dist-info/WHEEL,sha256=Zb28QaM1gQi8f4VCBhsUklF61CTlNYfs9YAZn-TOGFk,88
54
+ metacountregressor-0.1.49.dist-info/RECORD,,