metacountregressor 0.1.91__tar.gz → 0.1.95__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 (28) hide show
  1. {metacountregressor-0.1.91 → metacountregressor-0.1.95}/PKG-INFO +177 -14
  2. {metacountregressor-0.1.91 → metacountregressor-0.1.95}/README.rst +175 -12
  3. metacountregressor-0.1.95/metacountregressor/app_main.py +258 -0
  4. {metacountregressor-0.1.91 → metacountregressor-0.1.95}/metacountregressor/helperprocess.py +267 -5
  5. {metacountregressor-0.1.91 → metacountregressor-0.1.95}/metacountregressor/main.py +241 -98
  6. {metacountregressor-0.1.91 → metacountregressor-0.1.95}/metacountregressor/metaheuristics.py +22 -11
  7. {metacountregressor-0.1.91 → metacountregressor-0.1.95}/metacountregressor/setup.py +3 -2
  8. {metacountregressor-0.1.91 → metacountregressor-0.1.95}/metacountregressor/solution.py +427 -128
  9. {metacountregressor-0.1.91 → metacountregressor-0.1.95}/metacountregressor.egg-info/PKG-INFO +177 -14
  10. {metacountregressor-0.1.91 → metacountregressor-0.1.95}/metacountregressor.egg-info/SOURCES.txt +1 -0
  11. metacountregressor-0.1.95/metacountregressor.egg-info/requires.txt +8 -0
  12. {metacountregressor-0.1.91 → metacountregressor-0.1.95}/setup.py +18 -7
  13. metacountregressor-0.1.91/metacountregressor.egg-info/requires.txt +0 -3
  14. {metacountregressor-0.1.91 → metacountregressor-0.1.95}/LICENSE.txt +0 -0
  15. {metacountregressor-0.1.91 → metacountregressor-0.1.95}/metacountregressor/__init__.py +0 -0
  16. {metacountregressor-0.1.91 → metacountregressor-0.1.95}/metacountregressor/_device_cust.py +0 -0
  17. {metacountregressor-0.1.91 → metacountregressor-0.1.95}/metacountregressor/data_split_helper.py +0 -0
  18. {metacountregressor-0.1.91 → metacountregressor-0.1.95}/metacountregressor/halton.py +0 -0
  19. {metacountregressor-0.1.91 → metacountregressor-0.1.95}/metacountregressor/main_old.py +0 -0
  20. {metacountregressor-0.1.91 → metacountregressor-0.1.95}/metacountregressor/pareto_file.py +0 -0
  21. {metacountregressor-0.1.91 → metacountregressor-0.1.95}/metacountregressor/pareto_logger__plot.py +0 -0
  22. {metacountregressor-0.1.91 → metacountregressor-0.1.95}/metacountregressor/single_objective_finder.py +0 -0
  23. {metacountregressor-0.1.91 → metacountregressor-0.1.95}/metacountregressor/test_generated_paper2.py +0 -0
  24. {metacountregressor-0.1.91 → metacountregressor-0.1.95}/metacountregressor.egg-info/dependency_links.txt +0 -0
  25. {metacountregressor-0.1.91 → metacountregressor-0.1.95}/metacountregressor.egg-info/not-zip-safe +0 -0
  26. {metacountregressor-0.1.91 → metacountregressor-0.1.95}/metacountregressor.egg-info/top_level.txt +0 -0
  27. {metacountregressor-0.1.91 → metacountregressor-0.1.95}/setup.cfg +0 -0
  28. {metacountregressor-0.1.91 → metacountregressor-0.1.95}/tests/test.py +0 -0
@@ -1,17 +1,31 @@
1
- Metadata-Version: 2.1
1
+ Metadata-Version: 2.2
2
2
  Name: metacountregressor
3
- Version: 0.1.91
4
- Summary: Extensions for a Python package for estimation of count models.
3
+ Version: 0.1.95
4
+ Summary: Extensive Testing for Estimation of Data Count Models
5
5
  Home-page: https://github.com/zahern/CountDataEstimation
6
6
  Author: Zeke Ahern
7
- Author-email: zeke.ahern@hdr.qut.edu.au
8
- License: QUT
7
+ Author-email: z.ahern@qut.edu.au
8
+ License: MIT
9
9
  Requires-Python: >=3.10
10
10
  Description-Content-Type: text/markdown
11
11
  License-File: LICENSE.txt
12
12
  Requires-Dist: numpy>=1.13.1
13
13
  Requires-Dist: scipy>=1.0.0
14
14
  Requires-Dist: requests
15
+ Requires-Dist: latextable
16
+ Requires-Dist: pandas
17
+ Requires-Dist: scikit_learn>=1.4.1.post1
18
+ Requires-Dist: statsmodels
19
+ Requires-Dist: psutil
20
+ Dynamic: author
21
+ Dynamic: author-email
22
+ Dynamic: description
23
+ Dynamic: description-content-type
24
+ Dynamic: home-page
25
+ Dynamic: license
26
+ Dynamic: requires-dist
27
+ Dynamic: requires-python
28
+ Dynamic: summary
15
29
 
16
30
  <div style="display: flex; align-items: center;">
17
31
  <img src="https://github.com/zahern/data/raw/main/m.png" alt="My Image" style="width: 100px; margin-right: 20px;">
@@ -23,10 +37,24 @@ Requires-Dist: requests
23
37
 
24
38
  The tutorial provides more extensive examples on how to run the code and perform experiments. Further documentation is currently in development.
25
39
 
26
- ##### Quick Setup
40
+ # For an Application Setup Download the following GUI
41
+ [Download Application](https://github.com/zahern/MetaCount/tree/master/metacountregressor/application_gui/dist/meta_app)
42
+
43
+ The application involves setting up a problem instance to run the models.
44
+
45
+ ### Entire [Git Repository](https://github.com/zahern/MetaCount.git) is available to clone.
46
+ #### Steps
47
+ 1. Clone Project
48
+ 2. Navigate to "metacountregressor/application_gui/dist/meta_app"
49
+ 3. Run meta_app.exe
50
+ 4. Navigate to metacountregressor/app_main.py
51
+ 5. Run app_main.py
52
+
53
+
54
+ ## Setup For Python Package Approach
27
55
  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
56
 
29
- ## Quick install: Requires Python 3.10
57
+ ## Install: Requires Python 3.10
30
58
 
31
59
  Install `metacountregressor` using pip as follows:
32
60
 
@@ -274,6 +302,8 @@ Let's begin by fitting very simple models and use the structure of these models
274
302
 
275
303
 
276
304
  ```python
305
+
306
+ '''Setup Data'''
277
307
  df = pd.read_csv(
278
308
  "https://raw.githubusercontent.com/zahern/data/main/Ex-16-3.csv")
279
309
  X = df
@@ -281,25 +311,158 @@ y = df['FREQ'] # Frequency of crashes
281
311
  X['Offset'] = np.log(df['AADT']) # Explicitley define how to offset the data, no offset otherwise
282
312
  # Drop Y, selected offset term and ID as there are no panels
283
313
  X = df.drop(columns=['FREQ', 'ID', 'AADT'])
284
-
314
+ '''Aguments for Solution'''
285
315
  arguments = {
286
- 'algorithm': 'hs', #alternatively input 'de', or 'sa'
287
- 'is_multi': 1,
316
+ 'is_multi': 1, #is two objectives considered
288
317
  'test_percentage': 0.2, # used in multi-objective optimisation only. Saves 20% of data for testing.
289
318
  'val_percentage:': 0.2, # Saves 20% of data for testing.
290
319
  'test_complexity': 3, # For Very simple Models
291
320
  'obj_1': 'BIC', '_obj_2': 'RMSE_TEST',
292
- 'instance_number': 'name', # used for creeating a named folder where your models are saved into from the directory
321
+ 'instance_number': 'hs_run', # used for creeating a named folder where your models are saved into from the directory
293
322
  'distribution': ['Normal'],
294
- 'Model': [0], # or equivalently ['POS', 'NB']
323
+ 'Model': [0, 1], # or equivalently ['POS', 'NB']
295
324
  'transformations': ['no', 'sqrt', 'archsinh'],
296
325
  '_max_time': 10000
297
- }
326
+ } '''Arguments for the solution algorithm'''
327
+ argument_hs = {
328
+ '_hms': 20, #harmony memory size,
329
+ '_mpai': 1, #adjustement inded
330
+ '_par': 0.3,
331
+ '_hmcr': .5
332
+ }
298
333
  obj_fun = ObjectiveFunction(X, y, **arguments)
299
- results = harmony_search(obj_fun)
334
+ results = harmony_search(obj_fun, None, argument_hs)
300
335
  print(results)
301
336
  ```
302
337
 
338
+ ## Example: Assistance by Differential Evololution and Simulated Annealing
339
+ Similiar to the above example we only need to change the hyperparamaters, the obj_fun can remane the same
340
+
341
+
342
+ ```python
343
+ argument_de = {'_AI': 2,
344
+ '_crossover_perc': .2,
345
+ '_max_iter': 1000,
346
+ '_pop_size': 25
347
+ }
348
+ de_results = differential_evolution(obj_fun, None, **argument_de)
349
+ print(de_results)
350
+
351
+
352
+ args_sa = {'alpha': .99,
353
+ 'STEPS_PER_TEMP': 10,
354
+ 'INTL_ACPT': 0.5,
355
+ '_crossover_perc': .3,
356
+ 'MAX_ITERATIONS': 1000,
357
+ '_num_intl_slns': 25,
358
+ }
359
+
360
+ sa_results = simulated_annealing(obj_fun, None, **args_sa)
361
+ print(sa_results)
362
+ ```
363
+
364
+ ## Comparing to statsmodels
365
+ The following example illustrates how the output compares to well-known packages, including Statsmodels."
366
+
367
+
368
+ ```python
369
+ # Load modules and data
370
+ import statsmodels.api as sm
371
+
372
+ data = sm.datasets.sunspots.load_pandas().data
373
+ #print(data.exog)
374
+ data_exog = data['YEAR']
375
+ data_exog = sm.add_constant(data_exog)
376
+ data_endog = data['SUNACTIVITY']
377
+
378
+ # Instantiate a gamma family model with the default link function.
379
+ import numpy as np
380
+
381
+ gamma_model = sm.NegativeBinomial(data_endog, data_exog)
382
+ gamma_results = gamma_model.fit()
383
+
384
+ print(gamma_results.summary())
385
+
386
+
387
+
388
+
389
+ #NOW LET's COMPARE THIS TO METACOUNTREGRESSOR
390
+
391
+
392
+
393
+
394
+ #Model Decisions,
395
+ manual_fit_spec = {
396
+ 'fixed_terms': ['const','YEAR'],
397
+ 'rdm_terms': [],
398
+ 'rdm_cor_terms': [],
399
+ 'grouped_terms': [],
400
+ 'hetro_in_means': [],
401
+ 'transformations': ['no', 'no'],
402
+ 'dispersion': 1 #Negative Binomial
403
+ }
404
+
405
+
406
+ #Arguments
407
+ arguments = {
408
+ 'algorithm': 'hs',
409
+ 'test_percentage': 0,
410
+ 'test_complexity': 6,
411
+ 'instance_number': 'name',
412
+ 'Manual_Fit': manual_fit_spec
413
+ }
414
+ obj_fun = ObjectiveFunction(data_exog, data_endog, **arguments)
415
+
416
+
417
+
418
+
419
+
420
+
421
+
422
+ ```
423
+
424
+ Optimization terminated successfully.
425
+ Current function value: 4.877748
426
+ Iterations: 22
427
+ Function evaluations: 71
428
+ Gradient evaluations: 70
429
+ NegativeBinomial Regression Results
430
+ ==============================================================================
431
+ Dep. Variable: SUNACTIVITY No. Observations: 309
432
+ Model: NegativeBinomial Df Residuals: 307
433
+ Method: MLE Df Model: 1
434
+ Date: Tue, 13 Aug 2024 Pseudo R-squ.: 0.004087
435
+ Time: 14:13:22 Log-Likelihood: -1507.2
436
+ converged: True LL-Null: -1513.4
437
+ Covariance Type: nonrobust LLR p-value: 0.0004363
438
+ ==============================================================================
439
+ coef std err z P>|z| [0.025 0.975]
440
+ ------------------------------------------------------------------------------
441
+ const 0.2913 1.017 0.287 0.774 -1.701 2.284
442
+ YEAR 0.0019 0.001 3.546 0.000 0.001 0.003
443
+ alpha 0.7339 0.057 12.910 0.000 0.622 0.845
444
+ ==============================================================================
445
+ 0.1.88
446
+ Setup Complete...
447
+ Benchmaking test with Seed 42
448
+ 1
449
+ --------------------------------------------------------------------------------
450
+ Log-Likelihood: -1509.0683662284273
451
+ --------------------------------------------------------------------------------
452
+ bic: 3035.84
453
+ --------------------------------------------------------------------------------
454
+ MSE: 10000000.00
455
+ +--------+--------+-------+----------+----------+------------+
456
+ | Effect | $\tau$ | Coeff | Std. Err | z-values | Prob |z|>Z |
457
+ +========+========+=======+==========+==========+============+
458
+ | const | no | 0.10 | 0.25 | 0.39 | 0.70 |
459
+ +--------+--------+-------+----------+----------+------------+
460
+ | YEAR | no | 0.00 | 0.00 | 20.39 | 0.00*** |
461
+ +--------+--------+-------+----------+----------+------------+
462
+ | nb | | 1.33 | 0.00 | 50.00 | 0.00*** |
463
+ +--------+--------+-------+----------+----------+------------+
464
+
465
+
303
466
  ## Paper
304
467
 
305
468
  The following tutorial is in conjunction with our latest paper. A link the current paper can be found here [MetaCountRegressor](https://www.overleaf.com/read/mszwpwzcxsng#c5eb0c)
@@ -9,21 +9,42 @@ Tutorial also available as a jupyter notebook
9
9
  =============================================
10
10
 
11
11
  `Download Example
12
- Notebook <https://github.com/zahern/CountDataEstimation/blob/main/README.ipynb>`__
12
+ Notebook <https://github.com/zahern/CountDataEstimation/blob/main/Tutorial.ipynb>`__
13
13
 
14
14
  The tutorial provides more extensive examples on how to run the code and
15
15
  perform experiments. Further documentation is currently in development.
16
16
 
17
- Quick Setup
18
- '''''''''''
17
+ For an Application Setup Download the following GUI
18
+ ===================================================
19
+
20
+ `Download
21
+ Application <https://github.com/zahern/MetaCount/tree/master/metacountregressor/application_gui/dist/meta_app>`__
22
+
23
+ The application involves setting up a problem instance to run the
24
+ models.
25
+
26
+ Entire `Git Repository <https://github.com/zahern/MetaCount.git>`__ is available to clone.
27
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
28
+
29
+ Steps
30
+ ^^^^^
31
+
32
+ 1. Clone Project
33
+ 2. Navigate to �metacountregressor/application_gui/dist/meta_app�
34
+ 3. Run meta_app.exe
35
+ 4. Navigate to metacountregressor/app_main.py
36
+ 5. Run app_main.py
37
+
38
+ Setup For Python Package Approach
39
+ ---------------------------------
19
40
 
20
41
  The Below code demonstrates how to set up automatic optimization
21
42
  assisted by the harmony search algorithm. References to the Differential
22
43
  Evolution and Simulated Annealing has been mentioned (change
23
44
  accordingly)
24
45
 
25
- Quick install: Requires Python 3.10
26
- -----------------------------------
46
+ Install: Requires Python 3.10
47
+ -----------------------------
27
48
 
28
49
  Install ``metacountregressor`` using pip as follows:
29
50
 
@@ -376,6 +397,8 @@ factors for our search.
376
397
 
377
398
  .. code:: ipython3
378
399
 
400
+
401
+ '''Setup Data'''
379
402
  df = pd.read_csv(
380
403
  "https://raw.githubusercontent.com/zahern/data/main/Ex-16-3.csv")
381
404
  X = df
@@ -383,24 +406,164 @@ factors for our search.
383
406
  X['Offset'] = np.log(df['AADT']) # Explicitley define how to offset the data, no offset otherwise
384
407
  # Drop Y, selected offset term and ID as there are no panels
385
408
  X = df.drop(columns=['FREQ', 'ID', 'AADT'])
386
-
409
+ '''Aguments for Solution'''
387
410
  arguments = {
388
- 'algorithm': 'hs', #alternatively input 'de', or 'sa'
389
- 'is_multi': 1,
411
+ 'is_multi': 1, #is two objectives considered
390
412
  'test_percentage': 0.2, # used in multi-objective optimisation only. Saves 20% of data for testing.
391
413
  'val_percentage:': 0.2, # Saves 20% of data for testing.
392
414
  'test_complexity': 3, # For Very simple Models
393
415
  'obj_1': 'BIC', '_obj_2': 'RMSE_TEST',
394
- 'instance_number': 'name', # used for creeating a named folder where your models are saved into from the directory
416
+ 'instance_number': 'hs_run', # used for creeating a named folder where your models are saved into from the directory
395
417
  'distribution': ['Normal'],
396
- 'Model': [0], # or equivalently ['POS', 'NB']
418
+ 'Model': [0, 1], # or equivalently ['POS', 'NB']
397
419
  'transformations': ['no', 'sqrt', 'archsinh'],
398
420
  '_max_time': 10000
399
- }
421
+ } '''Arguments for the solution algorithm'''
422
+ argument_hs = {
423
+ '_hms': 20, #harmony memory size,
424
+ '_mpai': 1, #adjustement inded
425
+ '_par': 0.3,
426
+ '_hmcr': .5
427
+ }
400
428
  obj_fun = ObjectiveFunction(X, y, **arguments)
401
- results = harmony_search(obj_fun)
429
+ results = harmony_search(obj_fun, None, argument_hs)
402
430
  print(results)
403
431
 
432
+ Example: Assistance by Differential Evololution and Simulated Annealing
433
+ -----------------------------------------------------------------------
434
+
435
+ Similiar to the above example we only need to change the
436
+ hyperparamaters, the obj_fun can remane the same
437
+
438
+ .. code:: ipython3
439
+
440
+ argument_de = {'_AI': 2,
441
+ '_crossover_perc': .2,
442
+ '_max_iter': 1000,
443
+ '_pop_size': 25
444
+ }
445
+ de_results = differential_evolution(obj_fun, None, **argument_de)
446
+ print(de_results)
447
+
448
+
449
+ args_sa = {'alpha': .99,
450
+ 'STEPS_PER_TEMP': 10,
451
+ 'INTL_ACPT': 0.5,
452
+ '_crossover_perc': .3,
453
+ 'MAX_ITERATIONS': 1000,
454
+ '_num_intl_slns': 25,
455
+ }
456
+
457
+ sa_results = simulated_annealing(obj_fun, None, **args_sa)
458
+ print(sa_results)
459
+
460
+ Comparing to statsmodels
461
+ ------------------------
462
+
463
+ The following example illustrates how the output compares to well-known
464
+ packages, including Statsmodels.�
465
+
466
+ .. code:: ipython3
467
+
468
+ # Load modules and data
469
+ import statsmodels.api as sm
470
+
471
+ data = sm.datasets.sunspots.load_pandas().data
472
+ #print(data.exog)
473
+ data_exog = data['YEAR']
474
+ data_exog = sm.add_constant(data_exog)
475
+ data_endog = data['SUNACTIVITY']
476
+
477
+ # Instantiate a gamma family model with the default link function.
478
+ import numpy as np
479
+
480
+ gamma_model = sm.NegativeBinomial(data_endog, data_exog)
481
+ gamma_results = gamma_model.fit()
482
+
483
+ print(gamma_results.summary())
484
+
485
+
486
+
487
+
488
+ #NOW LET's COMPARE THIS TO METACOUNTREGRESSOR
489
+
490
+
491
+
492
+
493
+ #Model Decisions,
494
+ manual_fit_spec = {
495
+ 'fixed_terms': ['const','YEAR'],
496
+ 'rdm_terms': [],
497
+ 'rdm_cor_terms': [],
498
+ 'grouped_terms': [],
499
+ 'hetro_in_means': [],
500
+ 'transformations': ['no', 'no'],
501
+ 'dispersion': 1 #Negative Binomial
502
+ }
503
+
504
+
505
+ #Arguments
506
+ arguments = {
507
+ 'algorithm': 'hs',
508
+ 'test_percentage': 0,
509
+ 'test_complexity': 6,
510
+ 'instance_number': 'name',
511
+ 'Manual_Fit': manual_fit_spec
512
+ }
513
+ obj_fun = ObjectiveFunction(data_exog, data_endog, **arguments)
514
+
515
+
516
+
517
+
518
+
519
+
520
+
521
+
522
+
523
+ .. parsed-literal::
524
+
525
+ Optimization terminated successfully.
526
+ Current function value: 4.877748
527
+ Iterations: 22
528
+ Function evaluations: 71
529
+ Gradient evaluations: 70
530
+ NegativeBinomial Regression Results
531
+ ==============================================================================
532
+ Dep. Variable: SUNACTIVITY No. Observations: 309
533
+ Model: NegativeBinomial Df Residuals: 307
534
+ Method: MLE Df Model: 1
535
+ Date: Tue, 13 Aug 2024 Pseudo R-squ.: 0.004087
536
+ Time: 14:13:22 Log-Likelihood: -1507.2
537
+ converged: True LL-Null: -1513.4
538
+ Covariance Type: nonrobust LLR p-value: 0.0004363
539
+ ==============================================================================
540
+ coef std err z P>|z| [0.025 0.975]
541
+ ------------------------------------------------------------------------------
542
+ const 0.2913 1.017 0.287 0.774 -1.701 2.284
543
+ YEAR 0.0019 0.001 3.546 0.000 0.001 0.003
544
+ alpha 0.7339 0.057 12.910 0.000 0.622 0.845
545
+ ==============================================================================
546
+ 0.1.88
547
+ Setup Complete...
548
+ Benchmaking test with Seed 42
549
+ 1
550
+ --------------------------------------------------------------------------------
551
+ Log-Likelihood: -1509.0683662284273
552
+ --------------------------------------------------------------------------------
553
+ bic: 3035.84
554
+ --------------------------------------------------------------------------------
555
+ MSE: 10000000.00
556
+ +--------+--------+-------+----------+----------+------------+
557
+ | Effect | $\tau$ | Coeff | Std. Err | z-values | Prob |z|>Z |
558
+ +========+========+=======+==========+==========+============+
559
+ | const | no | 0.10 | 0.25 | 0.39 | 0.70 |
560
+ +--------+--------+-------+----------+----------+------------+
561
+ | YEAR | no | 0.00 | 0.00 | 20.39 | 0.00*** |
562
+ +--------+--------+-------+----------+----------+------------+
563
+ | nb | | 1.33 | 0.00 | 50.00 | 0.00*** |
564
+ +--------+--------+-------+----------+----------+------------+
565
+
566
+
404
567
  Paper
405
568
  -----
406
569