gamsapi 52.5.0__cp312-cp312-win_amd64.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.
- gams/__init__.py +27 -0
- gams/_version.py +1 -0
- gams/connect/__init__.py +28 -0
- gams/connect/agents/__init__.py +24 -0
- gams/connect/agents/_excel/__init__.py +32 -0
- gams/connect/agents/_excel/excelagent.py +312 -0
- gams/connect/agents/_excel/workbook.py +155 -0
- gams/connect/agents/_sqlconnectors/__init__.py +42 -0
- gams/connect/agents/_sqlconnectors/_accesshandler.py +211 -0
- gams/connect/agents/_sqlconnectors/_databasehandler.py +250 -0
- gams/connect/agents/_sqlconnectors/_mysqlhandler.py +168 -0
- gams/connect/agents/_sqlconnectors/_postgreshandler.py +131 -0
- gams/connect/agents/_sqlconnectors/_pyodbchandler.py +112 -0
- gams/connect/agents/_sqlconnectors/_sqlalchemyhandler.py +74 -0
- gams/connect/agents/_sqlconnectors/_sqlitehandler.py +262 -0
- gams/connect/agents/_sqlconnectors/_sqlserverhandler.py +179 -0
- gams/connect/agents/concatenate.py +440 -0
- gams/connect/agents/connectagent.py +743 -0
- gams/connect/agents/csvreader.py +675 -0
- gams/connect/agents/csvwriter.py +151 -0
- gams/connect/agents/domainwriter.py +143 -0
- gams/connect/agents/excelreader.py +756 -0
- gams/connect/agents/excelwriter.py +467 -0
- gams/connect/agents/filter.py +223 -0
- gams/connect/agents/gamsreader.py +112 -0
- gams/connect/agents/gamswriter.py +239 -0
- gams/connect/agents/gdxreader.py +109 -0
- gams/connect/agents/gdxwriter.py +146 -0
- gams/connect/agents/labelmanipulator.py +303 -0
- gams/connect/agents/projection.py +539 -0
- gams/connect/agents/pythoncode.py +71 -0
- gams/connect/agents/rawcsvreader.py +248 -0
- gams/connect/agents/rawexcelreader.py +312 -0
- gams/connect/agents/schema/CSVReader.yaml +92 -0
- gams/connect/agents/schema/CSVWriter.yaml +44 -0
- gams/connect/agents/schema/Concatenate.yaml +52 -0
- gams/connect/agents/schema/DomainWriter.yaml +25 -0
- gams/connect/agents/schema/ExcelReader.yaml +121 -0
- gams/connect/agents/schema/ExcelWriter.yaml +78 -0
- gams/connect/agents/schema/Filter.yaml +74 -0
- gams/connect/agents/schema/GAMSReader.yaml +20 -0
- gams/connect/agents/schema/GAMSWriter.yaml +47 -0
- gams/connect/agents/schema/GDXReader.yaml +23 -0
- gams/connect/agents/schema/GDXWriter.yaml +32 -0
- gams/connect/agents/schema/LabelManipulator.yaml +99 -0
- gams/connect/agents/schema/Projection.yaml +24 -0
- gams/connect/agents/schema/PythonCode.yaml +6 -0
- gams/connect/agents/schema/RawCSVReader.yaml +34 -0
- gams/connect/agents/schema/RawExcelReader.yaml +42 -0
- gams/connect/agents/schema/SQLReader.yaml +75 -0
- gams/connect/agents/schema/SQLWriter.yaml +103 -0
- gams/connect/agents/sqlreader.py +301 -0
- gams/connect/agents/sqlwriter.py +276 -0
- gams/connect/connectdatabase.py +275 -0
- gams/connect/connectvalidator.py +93 -0
- gams/connect/errors.py +34 -0
- gams/control/__init__.py +136 -0
- gams/control/database.py +2231 -0
- gams/control/execution.py +1900 -0
- gams/control/options.py +2792 -0
- gams/control/workspace.py +1198 -0
- gams/core/__init__.py +24 -0
- gams/core/cfg/__init__.py +26 -0
- gams/core/cfg/_cfgmcc.cp312-win_amd64.pyd +0 -0
- gams/core/cfg/cfgmcc.py +519 -0
- gams/core/dct/__init__.py +26 -0
- gams/core/dct/_dctmcc.cp312-win_amd64.pyd +0 -0
- gams/core/dct/dctmcc.py +574 -0
- gams/core/embedded/__init__.py +26 -0
- gams/core/embedded/gamsemb.py +1024 -0
- gams/core/emp/__init__.py +24 -0
- gams/core/emp/emplexer.py +89 -0
- gams/core/emp/empyacc.py +281 -0
- gams/core/gdx/__init__.py +26 -0
- gams/core/gdx/_gdxcc.cp312-win_amd64.pyd +0 -0
- gams/core/gdx/gdxcc.py +866 -0
- gams/core/gev/__init__.py +26 -0
- gams/core/gev/_gevmcc.cp312-win_amd64.pyd +0 -0
- gams/core/gev/gevmcc.py +855 -0
- gams/core/gmd/__init__.py +26 -0
- gams/core/gmd/_gmdcc.cp312-win_amd64.pyd +0 -0
- gams/core/gmd/gmdcc.py +917 -0
- gams/core/gmo/__init__.py +26 -0
- gams/core/gmo/_gmomcc.cp312-win_amd64.pyd +0 -0
- gams/core/gmo/gmomcc.py +2046 -0
- gams/core/idx/__init__.py +26 -0
- gams/core/idx/_idxcc.cp312-win_amd64.pyd +0 -0
- gams/core/idx/idxcc.py +510 -0
- gams/core/numpy/__init__.py +29 -0
- gams/core/numpy/_gams2numpy.cp312-win_amd64.pyd +0 -0
- gams/core/numpy/gams2numpy.py +1048 -0
- gams/core/opt/__init__.py +26 -0
- gams/core/opt/_optcc.cp312-win_amd64.pyd +0 -0
- gams/core/opt/optcc.py +840 -0
- gams/engine/__init__.py +204 -0
- gams/engine/api/__init__.py +13 -0
- gams/engine/api/auth_api.py +7653 -0
- gams/engine/api/cleanup_api.py +751 -0
- gams/engine/api/default_api.py +887 -0
- gams/engine/api/hypercube_api.py +2629 -0
- gams/engine/api/jobs_api.py +5229 -0
- gams/engine/api/licenses_api.py +2220 -0
- gams/engine/api/namespaces_api.py +7783 -0
- gams/engine/api/usage_api.py +5627 -0
- gams/engine/api/users_api.py +5931 -0
- gams/engine/api_client.py +804 -0
- gams/engine/api_response.py +21 -0
- gams/engine/configuration.py +601 -0
- gams/engine/exceptions.py +216 -0
- gams/engine/models/__init__.py +86 -0
- gams/engine/models/bad_input.py +89 -0
- gams/engine/models/cleanable_job_result.py +104 -0
- gams/engine/models/cleanable_job_result_page.py +113 -0
- gams/engine/models/engine_license.py +107 -0
- gams/engine/models/files_not_found.py +93 -0
- gams/engine/models/forwarded_token_response.py +112 -0
- gams/engine/models/generic_key_value_pair.py +89 -0
- gams/engine/models/hypercube.py +160 -0
- gams/engine/models/hypercube_page.py +111 -0
- gams/engine/models/hypercube_summary.py +91 -0
- gams/engine/models/hypercube_token.py +97 -0
- gams/engine/models/identity_provider.py +107 -0
- gams/engine/models/identity_provider_ldap.py +121 -0
- gams/engine/models/identity_provider_oauth2.py +146 -0
- gams/engine/models/identity_provider_oauth2_scope.py +89 -0
- gams/engine/models/identity_provider_oauth2_with_secret.py +152 -0
- gams/engine/models/identity_provider_oidc.py +133 -0
- gams/engine/models/identity_provider_oidc_with_secret.py +143 -0
- gams/engine/models/inex.py +91 -0
- gams/engine/models/invitation.py +136 -0
- gams/engine/models/invitation_quota.py +106 -0
- gams/engine/models/invitation_token.py +87 -0
- gams/engine/models/job.py +165 -0
- gams/engine/models/job_no_text_entry.py +138 -0
- gams/engine/models/job_no_text_entry_page.py +111 -0
- gams/engine/models/license.py +91 -0
- gams/engine/models/log_piece.py +96 -0
- gams/engine/models/message.py +87 -0
- gams/engine/models/message_and_token.py +99 -0
- gams/engine/models/message_with_webhook_id.py +89 -0
- gams/engine/models/model_auth_token.py +87 -0
- gams/engine/models/model_configuration.py +125 -0
- gams/engine/models/model_default_instance.py +99 -0
- gams/engine/models/model_default_user_instance.py +98 -0
- gams/engine/models/model_hypercube_job.py +106 -0
- gams/engine/models/model_hypercube_usage.py +130 -0
- gams/engine/models/model_instance_info.py +116 -0
- gams/engine/models/model_instance_info_full.py +123 -0
- gams/engine/models/model_instance_pool_info.py +112 -0
- gams/engine/models/model_job_labels.py +179 -0
- gams/engine/models/model_job_usage.py +133 -0
- gams/engine/models/model_pool_usage.py +124 -0
- gams/engine/models/model_usage.py +115 -0
- gams/engine/models/model_user.py +96 -0
- gams/engine/models/model_userinstance_info.py +119 -0
- gams/engine/models/model_userinstancepool_info.py +95 -0
- gams/engine/models/model_version.py +91 -0
- gams/engine/models/models.py +120 -0
- gams/engine/models/namespace.py +104 -0
- gams/engine/models/namespace_quota.py +96 -0
- gams/engine/models/namespace_with_permission.py +96 -0
- gams/engine/models/not_found.py +91 -0
- gams/engine/models/password_policy.py +97 -0
- gams/engine/models/perm_and_username.py +89 -0
- gams/engine/models/quota.py +117 -0
- gams/engine/models/quota_exceeded.py +97 -0
- gams/engine/models/status_code_meaning.py +89 -0
- gams/engine/models/stream_entry.py +89 -0
- gams/engine/models/system_wide_license.py +92 -0
- gams/engine/models/text_entries.py +87 -0
- gams/engine/models/text_entry.py +101 -0
- gams/engine/models/time_span.py +95 -0
- gams/engine/models/time_span_pool_worker.py +99 -0
- gams/engine/models/token_forward_error.py +87 -0
- gams/engine/models/user.py +127 -0
- gams/engine/models/user_group_member.py +96 -0
- gams/engine/models/user_groups.py +108 -0
- gams/engine/models/vapid_info.py +87 -0
- gams/engine/models/webhook.py +138 -0
- gams/engine/models/webhook_parameterized_event.py +99 -0
- gams/engine/py.typed +0 -0
- gams/engine/rest.py +258 -0
- gams/magic/__init__.py +32 -0
- gams/magic/gams_magic.py +142 -0
- gams/magic/interactive.py +402 -0
- gams/tools/__init__.py +30 -0
- gams/tools/errors.py +34 -0
- gams/tools/toolcollection/__init__.py +24 -0
- gams/tools/toolcollection/alg/__init__.py +24 -0
- gams/tools/toolcollection/alg/rank.py +51 -0
- gams/tools/toolcollection/data/__init__.py +24 -0
- gams/tools/toolcollection/data/csvread.py +444 -0
- gams/tools/toolcollection/data/csvwrite.py +311 -0
- gams/tools/toolcollection/data/exceldump.py +47 -0
- gams/tools/toolcollection/data/sqlitewrite.py +276 -0
- gams/tools/toolcollection/gdxservice/__init__.py +24 -0
- gams/tools/toolcollection/gdxservice/gdxencoding.py +104 -0
- gams/tools/toolcollection/gdxservice/gdxrename.py +94 -0
- gams/tools/toolcollection/linalg/__init__.py +24 -0
- gams/tools/toolcollection/linalg/cholesky.py +57 -0
- gams/tools/toolcollection/linalg/eigenvalue.py +56 -0
- gams/tools/toolcollection/linalg/eigenvector.py +58 -0
- gams/tools/toolcollection/linalg/invert.py +55 -0
- gams/tools/toolcollection/linalg/ols.py +138 -0
- gams/tools/toolcollection/tooltemplate.py +321 -0
- gams/tools/toolcollection/win32/__init__.py +24 -0
- gams/tools/toolcollection/win32/excelmerge.py +93 -0
- gams/tools/toolcollection/win32/exceltalk.py +76 -0
- gams/tools/toolcollection/win32/msappavail.py +49 -0
- gams/tools/toolcollection/win32/shellexecute.py +54 -0
- gams/tools/tools.py +116 -0
- gams/transfer/__init__.py +35 -0
- gams/transfer/_abcs/__init__.py +37 -0
- gams/transfer/_abcs/container_abcs.py +433 -0
- gams/transfer/_internals/__init__.py +63 -0
- gams/transfer/_internals/algorithms.py +436 -0
- gams/transfer/_internals/casepreservingdict.py +124 -0
- gams/transfer/_internals/constants.py +270 -0
- gams/transfer/_internals/domainviolation.py +103 -0
- gams/transfer/_internals/specialvalues.py +172 -0
- gams/transfer/containers/__init__.py +26 -0
- gams/transfer/containers/_container.py +1794 -0
- gams/transfer/containers/_io/__init__.py +28 -0
- gams/transfer/containers/_io/containers.py +164 -0
- gams/transfer/containers/_io/gdx.py +1029 -0
- gams/transfer/containers/_io/gmd.py +872 -0
- gams/transfer/containers/_mixins/__init__.py +26 -0
- gams/transfer/containers/_mixins/ccc.py +1274 -0
- gams/transfer/syms/__init__.py +33 -0
- gams/transfer/syms/_methods/__init__.py +24 -0
- gams/transfer/syms/_methods/tables.py +120 -0
- gams/transfer/syms/_methods/toDict.py +115 -0
- gams/transfer/syms/_methods/toList.py +83 -0
- gams/transfer/syms/_methods/toValue.py +60 -0
- gams/transfer/syms/_mixins/__init__.py +32 -0
- gams/transfer/syms/_mixins/equals.py +626 -0
- gams/transfer/syms/_mixins/generateRecords.py +499 -0
- gams/transfer/syms/_mixins/pivot.py +313 -0
- gams/transfer/syms/_mixins/pve.py +627 -0
- gams/transfer/syms/_mixins/sa.py +27 -0
- gams/transfer/syms/_mixins/sapve.py +27 -0
- gams/transfer/syms/_mixins/saua.py +27 -0
- gams/transfer/syms/_mixins/sauapve.py +199 -0
- gams/transfer/syms/_mixins/spve.py +1528 -0
- gams/transfer/syms/_mixins/ve.py +936 -0
- gams/transfer/syms/container_syms/__init__.py +31 -0
- gams/transfer/syms/container_syms/_alias.py +984 -0
- gams/transfer/syms/container_syms/_equation.py +333 -0
- gams/transfer/syms/container_syms/_parameter.py +973 -0
- gams/transfer/syms/container_syms/_set.py +604 -0
- gams/transfer/syms/container_syms/_universe_alias.py +461 -0
- gams/transfer/syms/container_syms/_variable.py +321 -0
- gamsapi-52.5.0.dist-info/METADATA +150 -0
- gamsapi-52.5.0.dist-info/RECORD +257 -0
- gamsapi-52.5.0.dist-info/WHEEL +5 -0
- gamsapi-52.5.0.dist-info/licenses/LICENSE +22 -0
- gamsapi-52.5.0.dist-info/top_level.txt +1 -0
|
@@ -0,0 +1,499 @@
|
|
|
1
|
+
#
|
|
2
|
+
# GAMS - General Algebraic Modeling System Python API
|
|
3
|
+
#
|
|
4
|
+
# Copyright (c) 2017-2026 GAMS Development Corp. <support@gams.com>
|
|
5
|
+
# Copyright (c) 2017-2026 GAMS Software GmbH <support@gams.com>
|
|
6
|
+
#
|
|
7
|
+
# Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
8
|
+
# of this software and associated documentation files (the "Software"), to deal
|
|
9
|
+
# in the Software without restriction, including without limitation the rights
|
|
10
|
+
# to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
11
|
+
# copies of the Software, and to permit persons to whom the Software is
|
|
12
|
+
# furnished to do so, subject to the following conditions:
|
|
13
|
+
#
|
|
14
|
+
# The above copyright notice and this permission notice shall be included in all
|
|
15
|
+
# copies or substantial portions of the Software.
|
|
16
|
+
#
|
|
17
|
+
# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
18
|
+
# IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
19
|
+
# FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
20
|
+
# AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
21
|
+
# LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
22
|
+
# OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
23
|
+
# SOFTWARE.
|
|
24
|
+
#
|
|
25
|
+
|
|
26
|
+
import numpy as np
|
|
27
|
+
import pandas as pd
|
|
28
|
+
from pandas.api.types import CategoricalDtype
|
|
29
|
+
from gams.transfer._internals import cartesian_product, choice_no_replace
|
|
30
|
+
from typing import Optional, Union, Callable
|
|
31
|
+
|
|
32
|
+
|
|
33
|
+
class GenerateRecordsBase:
|
|
34
|
+
def generateRecords(self, density=None, seed=None):
|
|
35
|
+
#
|
|
36
|
+
# ARG: density
|
|
37
|
+
if not isinstance(density, (int, float, list, type(None))):
|
|
38
|
+
raise TypeError(
|
|
39
|
+
"Argument 'density' must be type int, float, list or NoneType"
|
|
40
|
+
)
|
|
41
|
+
|
|
42
|
+
if density is None:
|
|
43
|
+
density = 1.0
|
|
44
|
+
|
|
45
|
+
if isinstance(density, list):
|
|
46
|
+
if len(density) != self.dimension:
|
|
47
|
+
raise ValueError(
|
|
48
|
+
f"Argument 'density' must be of length <symbol>.dimension ({len(density)} != {self.dimension})"
|
|
49
|
+
)
|
|
50
|
+
|
|
51
|
+
for dense in density:
|
|
52
|
+
if not isinstance(dense, (int, float)):
|
|
53
|
+
raise TypeError(
|
|
54
|
+
"Argument 'density' must contain only type int or float"
|
|
55
|
+
)
|
|
56
|
+
|
|
57
|
+
if not (dense >= 0 and dense <= 1):
|
|
58
|
+
raise ValueError(
|
|
59
|
+
"Argument 'density' must contain values on the interval [0,1]."
|
|
60
|
+
)
|
|
61
|
+
|
|
62
|
+
# check if domain is "regular"
|
|
63
|
+
if self.domain_type != "regular":
|
|
64
|
+
raise Exception(
|
|
65
|
+
"Cannot generate records unless the symbol has domain "
|
|
66
|
+
"objects for all dimensions (i.e., <symbol>.domain_type == 'regular')"
|
|
67
|
+
)
|
|
68
|
+
|
|
69
|
+
# check all domain objects have records
|
|
70
|
+
for symobj in self.domain:
|
|
71
|
+
if symobj.records is None:
|
|
72
|
+
raise Exception(
|
|
73
|
+
f"Symbol `{symobj.name}` was used as a domain, but it does not have records "
|
|
74
|
+
"-- cannot generate records unless all domain objects have records."
|
|
75
|
+
)
|
|
76
|
+
|
|
77
|
+
# if empty
|
|
78
|
+
is_empty = False
|
|
79
|
+
if isinstance(density, (int, float)):
|
|
80
|
+
if density == 0:
|
|
81
|
+
is_empty = True
|
|
82
|
+
elif isinstance(density, list):
|
|
83
|
+
if any(d == 0 for d in density):
|
|
84
|
+
is_empty = True
|
|
85
|
+
|
|
86
|
+
return density, is_empty
|
|
87
|
+
|
|
88
|
+
def _set_empty(self):
|
|
89
|
+
self.records = pd.DataFrame(
|
|
90
|
+
columns=[list(range(self.dimension + len(self._attributes)))]
|
|
91
|
+
)
|
|
92
|
+
|
|
93
|
+
# set column names
|
|
94
|
+
self.domain_labels = self.domain_names
|
|
95
|
+
|
|
96
|
+
for x, symobj in enumerate(self.domain):
|
|
97
|
+
self.records.isetitem(
|
|
98
|
+
x, self.records.iloc[:, x].astype(CategoricalDtype([], ordered=True))
|
|
99
|
+
)
|
|
100
|
+
|
|
101
|
+
|
|
102
|
+
class GenerateRecordsSetMixin(GenerateRecordsBase):
|
|
103
|
+
def generateRecords(
|
|
104
|
+
self,
|
|
105
|
+
density: Optional[Union[int, float, list]] = None,
|
|
106
|
+
seed: Optional[int] = None,
|
|
107
|
+
) -> None:
|
|
108
|
+
"""
|
|
109
|
+
Convenience method to set standard pandas.DataFrame formatted records given domain set information. Will generate records with the Cartesian product of all domain sets
|
|
110
|
+
|
|
111
|
+
Parameters
|
|
112
|
+
----------
|
|
113
|
+
density : int | float | list, optional
|
|
114
|
+
Takes any value on the interval [0,1]. If density is <1 then randomly selected records will be removed. `density` will accept a `list` of length `dimension` -- allows users to specify a density per symbol dimension, by default None
|
|
115
|
+
seed : int, optional
|
|
116
|
+
Random number state can be set with `seed` argument, by default None
|
|
117
|
+
"""
|
|
118
|
+
# check & set
|
|
119
|
+
density, is_empty = super().generateRecords(density, seed)
|
|
120
|
+
|
|
121
|
+
if is_empty:
|
|
122
|
+
super()._set_empty()
|
|
123
|
+
|
|
124
|
+
# if not empty
|
|
125
|
+
else:
|
|
126
|
+
if isinstance(density, (int, float)):
|
|
127
|
+
dtypes = []
|
|
128
|
+
for n, symobj in enumerate(self.domain):
|
|
129
|
+
cats = symobj.getUELs(ignore_unused=True)
|
|
130
|
+
dtypes.append(CategoricalDtype(cats, ordered=True))
|
|
131
|
+
|
|
132
|
+
codes = [np.arange(len(dtype.categories)) for dtype in dtypes]
|
|
133
|
+
arr = cartesian_product(*tuple(codes))
|
|
134
|
+
r, c = arr.shape
|
|
135
|
+
idx = choice_no_replace(r, density * r, seed=seed)
|
|
136
|
+
|
|
137
|
+
# set records
|
|
138
|
+
self.records = pd.DataFrame(arr[idx, ...])
|
|
139
|
+
|
|
140
|
+
# create categoricals from_codes
|
|
141
|
+
for x, symobj in enumerate(self.domain):
|
|
142
|
+
self.records.isetitem(
|
|
143
|
+
x,
|
|
144
|
+
pd.Categorical.from_codes(
|
|
145
|
+
codes=self.records.iloc[:, x], dtype=dtypes[x]
|
|
146
|
+
),
|
|
147
|
+
)
|
|
148
|
+
|
|
149
|
+
# add element_text column
|
|
150
|
+
self.records.insert(len(self.records.columns), "element_text", "")
|
|
151
|
+
|
|
152
|
+
# set column names
|
|
153
|
+
self.domain_labels = self.domain_names
|
|
154
|
+
|
|
155
|
+
# remove unused categories
|
|
156
|
+
self.removeUELs()
|
|
157
|
+
|
|
158
|
+
elif isinstance(density, list):
|
|
159
|
+
codes = []
|
|
160
|
+
dtypes = []
|
|
161
|
+
for n, (symobj, dense) in enumerate(zip(self.domain, density)):
|
|
162
|
+
cats = symobj.getUELs(ignore_unused=True)
|
|
163
|
+
dtypes.append(CategoricalDtype(cats, ordered=True))
|
|
164
|
+
|
|
165
|
+
codes.append(
|
|
166
|
+
choice_no_replace(len(cats), dense * len(cats), seed=seed)
|
|
167
|
+
)
|
|
168
|
+
|
|
169
|
+
# set records
|
|
170
|
+
self.records = pd.DataFrame(cartesian_product(*tuple(codes)))
|
|
171
|
+
|
|
172
|
+
# create categoricals from_codes
|
|
173
|
+
for x, symobj in enumerate(self.domain):
|
|
174
|
+
self.records.isetitem(
|
|
175
|
+
x,
|
|
176
|
+
pd.Categorical.from_codes(
|
|
177
|
+
codes=self.records.iloc[:, x], dtype=dtypes[x]
|
|
178
|
+
),
|
|
179
|
+
)
|
|
180
|
+
|
|
181
|
+
# add element_text column
|
|
182
|
+
self.records.insert(len(self.records.columns), "element_text", "")
|
|
183
|
+
|
|
184
|
+
# set column names
|
|
185
|
+
self.domain_labels = self.domain_names
|
|
186
|
+
|
|
187
|
+
# remove unused categories
|
|
188
|
+
self.removeUELs()
|
|
189
|
+
|
|
190
|
+
else:
|
|
191
|
+
raise TypeError(
|
|
192
|
+
f"Encountered unsupported 'density' type: {type(density)} "
|
|
193
|
+
)
|
|
194
|
+
|
|
195
|
+
|
|
196
|
+
class GenerateRecordsParameterMixin(GenerateRecordsBase):
|
|
197
|
+
def generateRecords(
|
|
198
|
+
self,
|
|
199
|
+
density: Optional[Union[int, float, list]] = None,
|
|
200
|
+
func: Optional[Callable] = None,
|
|
201
|
+
seed: Optional[int] = None,
|
|
202
|
+
) -> None:
|
|
203
|
+
"""
|
|
204
|
+
Convenience method to set standard pandas.DataFrame formatted records given domain set information. Will generate records with the Cartesian product of all domain sets.
|
|
205
|
+
|
|
206
|
+
Parameters
|
|
207
|
+
----------
|
|
208
|
+
density : int | float | list, optional
|
|
209
|
+
Takes any value on the interval [0,1]. If density is <1 then randomly selected records will be removed. `density` will accept a `list` of length `dimension` -- allows users to specify a density per symbol dimension, by default None
|
|
210
|
+
func : Callable, optional
|
|
211
|
+
Functions to generate the records, by default None; numpy.random.uniform(0,1)
|
|
212
|
+
seed : int, optional
|
|
213
|
+
Random number state can be set with `seed` argument, by default None
|
|
214
|
+
"""
|
|
215
|
+
# check & set
|
|
216
|
+
density, is_empty = super().generateRecords(density, seed)
|
|
217
|
+
|
|
218
|
+
#
|
|
219
|
+
# ARG: func
|
|
220
|
+
if not (callable(func) or func is None):
|
|
221
|
+
raise TypeError("Argument 'func' must be a callable or None")
|
|
222
|
+
|
|
223
|
+
# if empty
|
|
224
|
+
if is_empty:
|
|
225
|
+
super()._set_empty()
|
|
226
|
+
|
|
227
|
+
# if not empty
|
|
228
|
+
else:
|
|
229
|
+
if isinstance(density, (int, float)):
|
|
230
|
+
dtypes = []
|
|
231
|
+
for n, symobj in enumerate(self.domain):
|
|
232
|
+
cats = symobj.getUELs(ignore_unused=True)
|
|
233
|
+
dtypes.append(CategoricalDtype(cats, ordered=True))
|
|
234
|
+
|
|
235
|
+
codes = [np.arange(len(dtype.categories)) for dtype in dtypes]
|
|
236
|
+
arr = cartesian_product(*tuple(codes))
|
|
237
|
+
r, c = arr.shape
|
|
238
|
+
idx = choice_no_replace(r, density * r, seed=seed)
|
|
239
|
+
|
|
240
|
+
# set records
|
|
241
|
+
self.records = pd.DataFrame(arr[idx, ...])
|
|
242
|
+
|
|
243
|
+
# create categoricals from_codes
|
|
244
|
+
for x, symobj in enumerate(self.domain):
|
|
245
|
+
self.records.isetitem(
|
|
246
|
+
x,
|
|
247
|
+
pd.Categorical.from_codes(
|
|
248
|
+
codes=self.records.iloc[:, x], dtype=dtypes[x]
|
|
249
|
+
),
|
|
250
|
+
)
|
|
251
|
+
|
|
252
|
+
# add value column
|
|
253
|
+
try:
|
|
254
|
+
if func is None:
|
|
255
|
+
rng = np.random.default_rng(seed)
|
|
256
|
+
self.records["value"] = rng.uniform(
|
|
257
|
+
low=0.0, high=1.0, size=(len(self.records),)
|
|
258
|
+
)
|
|
259
|
+
else:
|
|
260
|
+
self.records["value"] = func(
|
|
261
|
+
seed=seed, size=(len(self.records),)
|
|
262
|
+
)
|
|
263
|
+
cols = list(self.records.columns)
|
|
264
|
+
self.records.isetitem(
|
|
265
|
+
cols.index("value"), self.records["value"].astype(float)
|
|
266
|
+
)
|
|
267
|
+
|
|
268
|
+
# set column names
|
|
269
|
+
self.domain_labels = self.domain_names
|
|
270
|
+
|
|
271
|
+
except Exception as err:
|
|
272
|
+
raise err
|
|
273
|
+
|
|
274
|
+
# remove unused categories
|
|
275
|
+
self.removeUELs()
|
|
276
|
+
|
|
277
|
+
elif isinstance(density, list):
|
|
278
|
+
codes = []
|
|
279
|
+
dtypes = []
|
|
280
|
+
for n, (symobj, dense) in enumerate(zip(self.domain, density)):
|
|
281
|
+
cats = symobj.getUELs(ignore_unused=True)
|
|
282
|
+
dtypes.append(CategoricalDtype(cats, ordered=True))
|
|
283
|
+
|
|
284
|
+
codes.append(
|
|
285
|
+
choice_no_replace(len(cats), dense * len(cats), seed=seed)
|
|
286
|
+
)
|
|
287
|
+
|
|
288
|
+
# set records
|
|
289
|
+
self.records = pd.DataFrame(cartesian_product(*tuple(codes)))
|
|
290
|
+
|
|
291
|
+
# create categoricals from_codes
|
|
292
|
+
for x, symobj in enumerate(self.domain):
|
|
293
|
+
self.records.isetitem(
|
|
294
|
+
x,
|
|
295
|
+
pd.Categorical.from_codes(
|
|
296
|
+
codes=self.records.iloc[:, x], dtype=dtypes[x]
|
|
297
|
+
),
|
|
298
|
+
)
|
|
299
|
+
|
|
300
|
+
# add value column
|
|
301
|
+
try:
|
|
302
|
+
if func is None:
|
|
303
|
+
rng = np.random.default_rng(seed)
|
|
304
|
+
self.records["value"] = rng.uniform(
|
|
305
|
+
low=0.0, high=1.0, size=(len(self.records),)
|
|
306
|
+
)
|
|
307
|
+
else:
|
|
308
|
+
self.records["value"] = func(
|
|
309
|
+
seed=seed, size=(len(self.records),)
|
|
310
|
+
)
|
|
311
|
+
cols = list(self.records.columns)
|
|
312
|
+
self.records.isetitem(
|
|
313
|
+
cols.index("value"), self.records["value"].astype(float)
|
|
314
|
+
)
|
|
315
|
+
|
|
316
|
+
# set column names
|
|
317
|
+
self.domain_labels = self.domain_names
|
|
318
|
+
except Exception as err:
|
|
319
|
+
raise err
|
|
320
|
+
|
|
321
|
+
else:
|
|
322
|
+
raise TypeError(
|
|
323
|
+
f"Encountered unsupported 'density' type: {type(density)} "
|
|
324
|
+
)
|
|
325
|
+
|
|
326
|
+
# remove unused categories
|
|
327
|
+
self.removeUELs()
|
|
328
|
+
|
|
329
|
+
|
|
330
|
+
class GenerateRecordsVariableMixin(GenerateRecordsBase):
|
|
331
|
+
def generateRecords(
|
|
332
|
+
self,
|
|
333
|
+
density: Optional[Union[int, float, list]] = None,
|
|
334
|
+
func: Optional[Callable] = None,
|
|
335
|
+
seed: Optional[int] = None,
|
|
336
|
+
) -> None:
|
|
337
|
+
"""
|
|
338
|
+
Convenience method to set standard pandas.DataFrame formatted records given domain set information. Will generate records with the Cartesian product of all domain sets.
|
|
339
|
+
|
|
340
|
+
Parameters
|
|
341
|
+
----------
|
|
342
|
+
density : int | float | list, optional
|
|
343
|
+
Takes any value on the interval [0,1]. If density is <1 then randomly selected records will be removed. `density` will accept a `list` of length `dimension` -- allows users to specify a density per symbol dimension, by default None
|
|
344
|
+
func : Callable, optional
|
|
345
|
+
Functions to generate the records, by default None; numpy.random.uniform(0,1)
|
|
346
|
+
seed : int, optional
|
|
347
|
+
Random number state can be set with `seed` argument, by default None
|
|
348
|
+
"""
|
|
349
|
+
# check & set
|
|
350
|
+
density, is_empty = super().generateRecords(density, seed)
|
|
351
|
+
|
|
352
|
+
#
|
|
353
|
+
# ARG: func
|
|
354
|
+
if not isinstance(func, (dict, type(None))):
|
|
355
|
+
raise TypeError("Argument 'func' must be a dict or NoneType")
|
|
356
|
+
|
|
357
|
+
if isinstance(func, dict):
|
|
358
|
+
# check all keys in func dict
|
|
359
|
+
if any(i not in self._attributes for i in func.keys()):
|
|
360
|
+
raise Exception(
|
|
361
|
+
f"Unrecognized equation attribute detected in `func`. "
|
|
362
|
+
f"Attributes must be {self._attributes}, user passed "
|
|
363
|
+
f"dict keys: {list(func.keys())}."
|
|
364
|
+
)
|
|
365
|
+
|
|
366
|
+
# check that all func equation attributes are callable
|
|
367
|
+
for i in func.keys():
|
|
368
|
+
if not callable(func[i]):
|
|
369
|
+
raise TypeError(
|
|
370
|
+
f"Object supplied to `func` argument (`{i}`) must be callable -- received {type(func[i])}"
|
|
371
|
+
)
|
|
372
|
+
|
|
373
|
+
# if empty
|
|
374
|
+
if is_empty:
|
|
375
|
+
super()._set_empty()
|
|
376
|
+
|
|
377
|
+
# if not empty
|
|
378
|
+
else:
|
|
379
|
+
if isinstance(density, (int, float)):
|
|
380
|
+
dtypes = []
|
|
381
|
+
for n, symobj in enumerate(self.domain):
|
|
382
|
+
cats = symobj.getUELs(ignore_unused=True)
|
|
383
|
+
dtypes.append(CategoricalDtype(cats, ordered=True))
|
|
384
|
+
|
|
385
|
+
codes = [np.arange(len(dtype.categories)) for dtype in dtypes]
|
|
386
|
+
arr = cartesian_product(*tuple(codes))
|
|
387
|
+
r, c = arr.shape
|
|
388
|
+
idx = choice_no_replace(r, density * r, seed=seed)
|
|
389
|
+
|
|
390
|
+
# set records
|
|
391
|
+
self.records = pd.DataFrame(arr[idx, ...])
|
|
392
|
+
|
|
393
|
+
# create categoricals from_codes
|
|
394
|
+
for x, symobj in enumerate(self.domain):
|
|
395
|
+
self.records.isetitem(
|
|
396
|
+
x,
|
|
397
|
+
pd.Categorical.from_codes(
|
|
398
|
+
codes=self.records.iloc[:, x], dtype=dtypes[x]
|
|
399
|
+
),
|
|
400
|
+
)
|
|
401
|
+
|
|
402
|
+
# add attribute columns
|
|
403
|
+
try:
|
|
404
|
+
if func is None:
|
|
405
|
+
rng = np.random.default_rng(seed)
|
|
406
|
+
self.records["level"] = rng.uniform(
|
|
407
|
+
low=0.0, high=1.0, size=(len(self.records),)
|
|
408
|
+
)
|
|
409
|
+
|
|
410
|
+
for i in self._attributes:
|
|
411
|
+
if i != "level":
|
|
412
|
+
self.records[i] = self.default_records[i]
|
|
413
|
+
|
|
414
|
+
else:
|
|
415
|
+
for i in self._attributes:
|
|
416
|
+
if i in func.keys():
|
|
417
|
+
self.records[i] = func[i](
|
|
418
|
+
seed=seed, size=(len(self.records),)
|
|
419
|
+
)
|
|
420
|
+
cols = list(self.records.columns)
|
|
421
|
+
self.records.isetitem(
|
|
422
|
+
cols.index(i), self.records[i].astype(float)
|
|
423
|
+
)
|
|
424
|
+
else:
|
|
425
|
+
self.records[i] = self.default_records[i]
|
|
426
|
+
|
|
427
|
+
# set column names
|
|
428
|
+
self.domain_labels = self.domain_names
|
|
429
|
+
|
|
430
|
+
except Exception as err:
|
|
431
|
+
raise err
|
|
432
|
+
|
|
433
|
+
# remove unused categories
|
|
434
|
+
self.removeUELs()
|
|
435
|
+
|
|
436
|
+
elif isinstance(density, list):
|
|
437
|
+
codes = []
|
|
438
|
+
dtypes = []
|
|
439
|
+
for n, (symobj, dense) in enumerate(zip(self.domain, density)):
|
|
440
|
+
cats = symobj.getUELs(ignore_unused=True)
|
|
441
|
+
dtypes.append(CategoricalDtype(cats, ordered=True))
|
|
442
|
+
|
|
443
|
+
codes.append(
|
|
444
|
+
choice_no_replace(len(cats), dense * len(cats), seed=seed)
|
|
445
|
+
)
|
|
446
|
+
|
|
447
|
+
# set records
|
|
448
|
+
self.records = pd.DataFrame(cartesian_product(*tuple(codes)))
|
|
449
|
+
|
|
450
|
+
# create categoricals from_codes
|
|
451
|
+
for x, symobj in enumerate(self.domain):
|
|
452
|
+
self.records.isetitem(
|
|
453
|
+
x,
|
|
454
|
+
pd.Categorical.from_codes(
|
|
455
|
+
codes=self.records.iloc[:, x], dtype=dtypes[x]
|
|
456
|
+
),
|
|
457
|
+
)
|
|
458
|
+
|
|
459
|
+
# add attribute columns
|
|
460
|
+
try:
|
|
461
|
+
if func is None:
|
|
462
|
+
rng = np.random.default_rng(seed)
|
|
463
|
+
self.records["level"] = rng.uniform(
|
|
464
|
+
low=0.0, high=1.0, size=(len(self.records),)
|
|
465
|
+
)
|
|
466
|
+
|
|
467
|
+
for i in self._attributes:
|
|
468
|
+
if i != "level":
|
|
469
|
+
self.records[i] = self.default_records[i]
|
|
470
|
+
|
|
471
|
+
else:
|
|
472
|
+
for i in self._attributes:
|
|
473
|
+
if i in func.keys():
|
|
474
|
+
self.records[i] = func[i](
|
|
475
|
+
seed=seed, size=(len(self.records),)
|
|
476
|
+
)
|
|
477
|
+
cols = list(self.records.columns)
|
|
478
|
+
self.records.isetitem(
|
|
479
|
+
cols.index(i), self.records[i].astype(float)
|
|
480
|
+
)
|
|
481
|
+
else:
|
|
482
|
+
self.records[i] = self.default_records[i]
|
|
483
|
+
|
|
484
|
+
# set column names
|
|
485
|
+
self.domain_labels = self.domain_names
|
|
486
|
+
|
|
487
|
+
except Exception as err:
|
|
488
|
+
raise err
|
|
489
|
+
|
|
490
|
+
# remove unused categories
|
|
491
|
+
self.removeUELs()
|
|
492
|
+
|
|
493
|
+
else:
|
|
494
|
+
raise TypeError(
|
|
495
|
+
f"Encountered unsupported 'density' type: {type(density)} "
|
|
496
|
+
)
|
|
497
|
+
|
|
498
|
+
|
|
499
|
+
class GenerateRecordsEquationMixin(GenerateRecordsVariableMixin): ...
|