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.
- metacountregressor/__init__.py +102 -5
- metacountregressor/_device_cust.py +2 -1
- metacountregressor/alog.png +0 -0
- metacountregressor/solution.py +333 -106
- metacountregressor-0.1.49.dist-info/METADATA +236 -0
- {metacountregressor-0.1.47.dist-info → metacountregressor-0.1.49.dist-info}/RECORD +7 -6
- metacountregressor-0.1.47.dist-info/METADATA +0 -543
- {metacountregressor-0.1.47.dist-info → metacountregressor-0.1.49.dist-info}/WHEEL +0 -0
metacountregressor/__init__.py
CHANGED
@@ -1,8 +1,105 @@
|
|
1
|
-
|
2
|
-
|
3
|
-
|
1
|
+
import warnings
|
2
|
+
import argparse
|
3
|
+
import csv
|
4
|
+
import faulthandler
|
5
|
+
import sys
|
6
|
+
import timeit
|
7
|
+
from collections import namedtuple
|
8
|
+
print('loaded standard packages')
|
9
|
+
|
10
|
+
import numpy as np
|
11
|
+
|
12
|
+
import pandas as pd
|
13
|
+
|
14
|
+
from helperprocess import*
|
15
|
+
print('loaded helper')
|
16
|
+
from .metaheuristics import (differential_evolution,
|
17
|
+
harmony_search,
|
18
|
+
simulated_annealing)
|
4
19
|
from .solution import ObjectiveFunction
|
5
|
-
from .helperprocess import*
|
6
|
-
from .metaheuristics import*
|
7
20
|
|
8
21
|
|
22
|
+
|
23
|
+
|
24
|
+
|
25
|
+
|
26
|
+
|
27
|
+
|
28
|
+
import pandas as pd
|
29
|
+
df = pd.read_csv("https://raw.githubusercontent.com/zahern/data/main/Ex-16-3.csv")
|
30
|
+
|
31
|
+
|
32
|
+
y = df['FREQ'] #Frequency of crashes
|
33
|
+
X = df.drop(columns=['FREQ', 'ID']) #Drop Y, and ID as there are no panels
|
34
|
+
X = pd.get_dummies(X, columns=['FC'], prefix=['FC'], prefix_sep='_').astype(int)
|
35
|
+
X['Offset'] = np.log(1+X['AADT'] * X['LENGTH'] * 365 / 100000000)
|
36
|
+
#X = interactions(X)
|
37
|
+
#X = pd.get_dummies(X, columns=['FC'], prefix=['FC'], prefix_sep='_')
|
38
|
+
|
39
|
+
|
40
|
+
# Fit the model with metacountregressor
|
41
|
+
|
42
|
+
other_data = 1
|
43
|
+
if other_data:
|
44
|
+
df = pd.read_csv('panel_synth.csv') # read in the data
|
45
|
+
y = df[['Y']].copy() # only consider crashes
|
46
|
+
y.rename(columns={"crashes": "Y"}, inplace=True)
|
47
|
+
panels = df['ind_id']
|
48
|
+
|
49
|
+
X = df.drop(columns=['Y', 'alt'])
|
50
|
+
#Model Decisions, Specify for Intial Optimization
|
51
|
+
manual_fit_spec = {
|
52
|
+
'fixed_terms': ['added_fixed1', 'added_fixed2', 'added_fixed3', 'constant'],
|
53
|
+
'rdm_terms': [],
|
54
|
+
'rdm_cor_terms': ['added_random1:grpd| normal', 'added_random2:grpd| uniform', 'added_random3:grpd| triangular'],
|
55
|
+
'grouped_terms': [],
|
56
|
+
'hetro_in_means': [],
|
57
|
+
'transformations': ['no', 'no', 'no', 'no', 'no', 'no', 'no'],
|
58
|
+
'dispersion': 0
|
59
|
+
}
|
60
|
+
arguments = dict()
|
61
|
+
arguments['group'] = 'group'
|
62
|
+
arguments['panels'] = 'ind_id'
|
63
|
+
arguments['ID'] ='ind_id'
|
64
|
+
else:
|
65
|
+
#Model Decisions, Specify for Intial Optimization
|
66
|
+
manual_fit_spec = {
|
67
|
+
'fixed_terms': ['const', 'FC_2'],
|
68
|
+
'rdm_terms': ['MXGRADE:triangular', 'AVEPRE:normal'],
|
69
|
+
'rdm_cor_terms': [],
|
70
|
+
'grouped_terms': [],
|
71
|
+
'hetro_in_means': ['URB:triangular', 'ACCESS:triangular', 'FC_1:triangular'],
|
72
|
+
'transformations': ['no', 'no', 'no', 'no', 'no', 'no', 'no'],
|
73
|
+
'dispersion': 0
|
74
|
+
}
|
75
|
+
|
76
|
+
|
77
|
+
|
78
|
+
|
79
|
+
#select one of the algorithms
|
80
|
+
alg = [harmony_search, differential_evolution, simulated_annealing]
|
81
|
+
alg = alg[0] #harmony search
|
82
|
+
|
83
|
+
|
84
|
+
|
85
|
+
|
86
|
+
|
87
|
+
#Search Arguments
|
88
|
+
arguments = {
|
89
|
+
'algorithm': 'hs',
|
90
|
+
'test_percentage': 0.2,
|
91
|
+
'test_complexity': 6,
|
92
|
+
'instance_number': 'name',
|
93
|
+
'Manual_Fit': manual_fit_spec
|
94
|
+
}
|
95
|
+
|
96
|
+
arguments['group'] = 'group'
|
97
|
+
arguments['panels'] = 'ind_id'
|
98
|
+
arguments['ID'] ='ind_id'
|
99
|
+
|
100
|
+
|
101
|
+
arguments_hyperparamaters = dict()
|
102
|
+
|
103
|
+
# end default constructor
|
104
|
+
obj_fun = ObjectiveFunction(X, y, **arguments)
|
105
|
+
results = alg(obj_fun, None, **arguments_hyperparamaters)
|
Binary file
|