openenergyid 0.1.8__py2.py3-none-any.whl → 0.1.9__py2.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.

Potentially problematic release.


This version of openenergyid might be problematic. Click here for more details.

openenergyid/__init__.py CHANGED
@@ -1,6 +1,6 @@
1
1
  """Open Energy ID Python SDK."""
2
2
 
3
- __version__ = "0.1.8"
3
+ __version__ = "0.1.9"
4
4
 
5
5
  from .enums import Granularity
6
6
  from .models import TimeSeries
openenergyid/mvlr/main.py CHANGED
@@ -18,6 +18,7 @@ def find_best_mvlr(
18
18
  granularity=granularity,
19
19
  allow_negative_predictions=data.allow_negative_predictions,
20
20
  single_use_exog_prefixes=data.single_use_exog_prefixes,
21
+ exogs__disallow_negative_coefficient=data.get_disallowed_negative_coefficients(),
21
22
  )
22
23
  mvlr.do_analysis()
23
24
  if mvlr.validate(
@@ -51,6 +51,11 @@ class IndependentVariableInput(BaseModel):
51
51
  "Eg. `HDD_16.5` will be Heating Degree Days with a base temperature of 16.5°C, "
52
52
  "`CDD_0` will be Cooling Degree Days with a base temperature of 0°C.",
53
53
  )
54
+ allow_negative_coefficient: bool = Field(
55
+ default=True,
56
+ alias="allowNegativeCoefficient",
57
+ description="Whether the coefficient can be negative.",
58
+ )
54
59
 
55
60
 
56
61
  class MultiVariableRegressionInput(BaseModel):
@@ -123,6 +128,17 @@ class MultiVariableRegressionInput(BaseModel):
123
128
 
124
129
  return frame
125
130
 
131
+ def get_disallowed_negative_coefficients(self) -> List[str]:
132
+ """Get independent variables that are not allowed to have a negative coefficient."""
133
+ result = []
134
+ for iv in self.independent_variables: # pylint: disable=not-an-iterable
135
+ if iv.name == COLUMN_TEMPERATUREEQUIVALENT and iv.variants is not None:
136
+ if not iv.allow_negative_coefficient:
137
+ result.extend(iv.variants)
138
+ elif not iv.allow_negative_coefficient:
139
+ result.append(iv.name)
140
+ return result
141
+
126
142
 
127
143
  ######################
128
144
  # MVLR Result Models #
openenergyid/mvlr/mvlr.py CHANGED
@@ -41,6 +41,7 @@ class MultiVariableLinearRegression:
41
41
  allow_negative_predictions: bool = False,
42
42
  granularity: Granularity = None,
43
43
  single_use_exog_prefixes: list[str] = None,
44
+ exogs__disallow_negative_coefficient: list[str] = None,
44
45
  ):
45
46
  """Parameters
46
47
  ----------
@@ -72,6 +73,8 @@ class MultiVariableLinearRegression:
72
73
  will be used as an independent variable.
73
74
  Once the best fit using a variable with a given prefix is found, the other variables with the same
74
75
  prefix will not be used as independent variables.
76
+ exogs__disallow_negative_coefficient : list of str, default=None
77
+ List of variable names for which the coefficient is not allowed to be negative.
75
78
  """
76
79
  self.data = data.copy()
77
80
  if y not in self.data.columns:
@@ -87,6 +90,7 @@ class MultiVariableLinearRegression:
87
90
  self.allow_negative_predictions = allow_negative_predictions
88
91
  self.granularity = granularity
89
92
  self.single_use_exog_prefixes = single_use_exog_prefixes
93
+ self.exogs__disallow_negative_coefficient = exogs__disallow_negative_coefficient
90
94
  self._fit = None
91
95
  self._list_of_fits = []
92
96
  self.list_of_cverrors = []
@@ -161,6 +165,15 @@ class MultiVariableLinearRegression:
161
165
  ref_fit.model.formula.rhs_termlist + [term],
162
166
  )
163
167
  fit = fm.ols(model_desc, data=self.data).fit()
168
+
169
+ # Check if the coefficient of the variable is allowed to be negative
170
+ if (
171
+ self.exogs__disallow_negative_coefficient is not None
172
+ and x in self.exogs__disallow_negative_coefficient
173
+ and fit.params[x] < 0
174
+ ):
175
+ continue
176
+
164
177
  if fit.bic < best_bic:
165
178
  best_bic = fit.bic
166
179
  best_fit = fit
@@ -174,20 +187,20 @@ class MultiVariableLinearRegression:
174
187
  ref_fit.model.formula.rhs_termlist,
175
188
  ):
176
189
  break
177
- else:
178
- self._list_of_fits.append(best_fit)
179
- all_model_terms_dict.pop(best_x)
180
-
181
- # Check if `best_x` starts with a prefix that should only be used once
182
- # If so, remove all other variables with the same prefix from the list of candidates
183
- if self.single_use_exog_prefixes:
184
- for prefix in self.single_use_exog_prefixes:
185
- if best_x.startswith(prefix):
186
- all_model_terms_dict = {
187
- k: v
188
- for k, v in all_model_terms_dict.items()
189
- if not k.startswith(prefix)
190
- }
190
+
191
+ self._list_of_fits.append(best_fit)
192
+ all_model_terms_dict.pop(best_x)
193
+
194
+ # Check if `best_x` starts with a prefix that should only be used once
195
+ # If so, remove all other variables with the same prefix from the list of candidates
196
+ if self.single_use_exog_prefixes:
197
+ for prefix in self.single_use_exog_prefixes:
198
+ if best_x.startswith(prefix):
199
+ all_model_terms_dict = {
200
+ k: v
201
+ for k, v in all_model_terms_dict.items()
202
+ if not k.startswith(prefix)
203
+ }
191
204
 
192
205
  self._fit = self._list_of_fits[-1]
193
206
 
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.1
2
2
  Name: openenergyid
3
- Version: 0.1.8
3
+ Version: 0.1.9
4
4
  Summary: Open Source Python library for energy analytics and simulations
5
5
  Project-URL: Homepage, https://energyid.eu
6
6
  Project-URL: Repository, https://github.com/EnergieID/OpenEnergyID
@@ -0,0 +1,13 @@
1
+ openenergyid/__init__.py,sha256=_KWarhaNa9a-pxb9L4P7NUtWUi8A2CVl9nD29g21mYs,160
2
+ openenergyid/const.py,sha256=bF-U-r0Qj2GWCYBBxReg8fbv2D0V1JzfPMwSEQ5ZWds,569
3
+ openenergyid/enums.py,sha256=jdw4CB1gkisx0re_SesrTEyh_T-UxYp6uieE7iYlHdA,357
4
+ openenergyid/models.py,sha256=pUJpQCodph0NukiIpFdc9X6Zj6qEGQPSWoztYDwqyuE,2214
5
+ openenergyid/mvlr/__init__.py,sha256=Glrc218oqa8tq_Y2G9LXaSoN4Yba-vsjXUi9r9iPzaY,471
6
+ openenergyid/mvlr/helpers.py,sha256=fsx-gSvBdU31BjncFkRd1RySmSPPYgwflCnmSFzox2Q,961
7
+ openenergyid/mvlr/main.py,sha256=cn7jZ98cHn2eh-0zG9q8Pad0Ft_FuI-u3a-eeHeF8jA,1304
8
+ openenergyid/mvlr/models.py,sha256=SdZYroi3EM4D1U6OnnyfBv6ygzfAQM2UzICg0jaQD6w,8616
9
+ openenergyid/mvlr/mvlr.py,sha256=F7WvWnZQtqUmK1vsguemsn9n8pDDk3tQ1weOlv-bo0c,18626
10
+ openenergyid-0.1.9.dist-info/METADATA,sha256=8BhGlQs47GfSa2XnCp3Hb9vQE_eE0vtSo7RoSAH3Mx8,2431
11
+ openenergyid-0.1.9.dist-info/WHEEL,sha256=ccEkY-EGGllEs7ySpwBlD8G4u70wR77CNej8Q6tzIqA,105
12
+ openenergyid-0.1.9.dist-info/licenses/LICENSE,sha256=NgRdcNHwyXVCXZ8sJwoTp0DCowThJ9LWWl4xhbV1IUY,1074
13
+ openenergyid-0.1.9.dist-info/RECORD,,
@@ -1,13 +0,0 @@
1
- openenergyid/__init__.py,sha256=SddUHMaNL5tWsrK3W-8JyGXmxdYaeyxBhXqd1TsBChc,160
2
- openenergyid/const.py,sha256=bF-U-r0Qj2GWCYBBxReg8fbv2D0V1JzfPMwSEQ5ZWds,569
3
- openenergyid/enums.py,sha256=jdw4CB1gkisx0re_SesrTEyh_T-UxYp6uieE7iYlHdA,357
4
- openenergyid/models.py,sha256=pUJpQCodph0NukiIpFdc9X6Zj6qEGQPSWoztYDwqyuE,2214
5
- openenergyid/mvlr/__init__.py,sha256=Glrc218oqa8tq_Y2G9LXaSoN4Yba-vsjXUi9r9iPzaY,471
6
- openenergyid/mvlr/helpers.py,sha256=fsx-gSvBdU31BjncFkRd1RySmSPPYgwflCnmSFzox2Q,961
7
- openenergyid/mvlr/main.py,sha256=dwkl71u8HnlMAq-cmkwvI7z-XtlmqpvZRFoDc9CN-gg,1210
8
- openenergyid/mvlr/models.py,sha256=ncQ0W0LLCP7IZ4rDgLwIPZRQpK4-xC-qA17BW9tMwio,7878
9
- openenergyid/mvlr/mvlr.py,sha256=UbMuoWdepnGd1_heVtFOnLoBxVUB7WrPRLyOaDELxlI,18030
10
- openenergyid-0.1.8.dist-info/METADATA,sha256=7S_S8PFQ8VtflEhBFwCCxVt46Nkqzyh_UL8T89PWXm4,2431
11
- openenergyid-0.1.8.dist-info/WHEEL,sha256=ccEkY-EGGllEs7ySpwBlD8G4u70wR77CNej8Q6tzIqA,105
12
- openenergyid-0.1.8.dist-info/licenses/LICENSE,sha256=NgRdcNHwyXVCXZ8sJwoTp0DCowThJ9LWWl4xhbV1IUY,1074
13
- openenergyid-0.1.8.dist-info/RECORD,,