-
Notifications
You must be signed in to change notification settings - Fork 7
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Refactor #61
Refactor #61
Conversation
@bqpd, the renaming of ---------------------------------------------------------------------------
AttributeError Traceback (most recent call last)
/Users/mjburton11/MIT/GPKIT/gpkit-projects/gas_solar_trade/gassolar/environment/wind_fit.py in <module>()
100 print "rms iter=%d" % i
101 np.random.seed(i)
--> 102 cns, rm = fit(X, Y, 4, "SMA")
103 rms.append(rm)
104 if rm > 0.05:
/Users/mjburton11/anaconda/lib/python2.7/site-packages/gpfit/fit.pyc in fit(xdata, ydata, K, ftype)
105 elif ftype == "SMA":
106 # constraint of the form w^alpha >= c1*u1^exp1 + c2*u2^exp2 +....
--> 107 lhs, rhs = w**alpha, monos.sum()
108 print_SMA(A, B, alpha, d, K)
109 elif ftype == "MA":
/Users/mjburton11/MIT/GPKIT/gpkit/gpkit/nomials/array.pyc in sum(self, *args, **kwargs)
199 i = it.multi_index
200 it.iternext()
--> 201 cs.extend(mag(self[i].cs).tolist())
202 exps.extend(self[i].exps)
203 if units:
AttributeError: 'float' object has no attribute 'cs' |
The bottom part of the error message seems to be missing... |
@mjburton11, what's the full error message above? |
Oh I got it. Fixing... |
haha just updated the comment... |
@mjburton11, I think the latest commit fixes the bug |
@bqpd, now getting the following error: ---------------------------------------------------------------------------
ValueError Traceback (most recent call last)
/Users/mjburton11/MIT/GPKIT/gpkit-projects/gas_solar_trade/gassolar/environment/wind_fit.py in <module>()
144 colnames = np.append(colnames, "alpha")
145 colnames = np.insert(colnames, 0, "latitude")
--> 146 df.columns = colnames
147 # df.to_csv("windaltfitdata1.csv")
/Users/mjburton11/anaconda/lib/python2.7/site-packages/pandas/core/generic.pyc in __setattr__(self, name, value)
2159 try:
2160 object.__getattribute__(self, name)
-> 2161 return object.__setattr__(self, name, value)
2162 except AttributeError:
2163 pass
pandas/src/properties.pyx in pandas.lib.AxisProperty.__set__ (pandas/lib.c:42548)()
/Users/mjburton11/anaconda/lib/python2.7/site-packages/pandas/core/generic.pyc in _set_axis(self, axis, labels)
411
412 def _set_axis(self, axis, labels):
--> 413 self._data.set_axis(axis, labels)
414 self._clear_item_cache()
415
/Users/mjburton11/anaconda/lib/python2.7/site-packages/pandas/core/internals.pyc in set_axis(self, axis, new_labels)
2217 if new_len != old_len:
2218 raise ValueError('Length mismatch: Expected axis has %d elements, '
-> 2219 'new values have %d elements' % (old_len, new_len))
2220
2221 self.axes[axis] = new_labels
ValueError: Length mismatch: Expected axis has 8 elements, new values have 14 elements |
Actually I think this is better fixed in gpkit... |
Wait.. this is a pandas error... |
Yeah not sure about that pandas error :p. Worked on mine, got a latex error instead |
@bqpd, ok so when I generate the fit, |
Yeah, the first two terms were zero. :-/ |
Which is what caused the bug. |
Hmmm... that's not what I'm seeing. |
Ok now I'm getting this error: ---------------------------------------------------------------------------
AttributeError Traceback (most recent call last)
/Users/mjburton11/MIT/GPKIT/gpkit-projects/gas_solar_trade/gassolar/environment/wind_fit.py in <module>()
100 print "rms iter=%d" % i
101 np.random.seed(i)
--> 102 cns, rm = fit(X, Y, 4, "SMA")
103 rms.append(rm)
104 if rm > 0.05:
/Users/mjburton11/anaconda/lib/python2.7/site-packages/gpfit/fit.pyc in fit(xdata, ydata, K, ftype)
105 elif ftype == "SMA":
106 # constraint of the form w^alpha >= c1*u1^exp1 + c2*u2^exp2 +....
--> 107 lhs, rhs = w**alpha, monos.sum()
108 print_SMA(A, B, alpha, d, K)
109 elif ftype == "MA":
/Users/mjburton11/MIT/GPKIT/gpkit/gpkit/nomials/array.pyc in sum(self, *args, **kwargs)
199 i = it.multi_index
200 it.iternext()
--> 201 cs.extend(mag(self[i].cs).tolist())
202 exps.extend(self[i].exps)
203 if units:
AttributeError: 'float' object has no attribute 'cs' |
Yup, that's the zeros. |
making a gpkit pull (convexengineering/gpkit#1019) to address the summing issue. Not sure why the fit has zeros, though; did it not before, or was that just abstracted away before? |
So sometimes it did have zeros, but with a different |
Did those functions have a lower rmse, or is a 4th-order fit overkill, or is this some weird local minima thing? |
@mjburton11, now implements proper summing on gpkit master, so you shouldn't see that |
Ok I'm not getting that error anymore. But the printed fit is still different from the returned constraint: In [1]: %run wind_fit.py
Fitting for 54 latitude
rms iter=0
w**0.00298794 = 0.045666 * (u_1)**3.05619 * (u_2)**3.31932
+ 0.00105499 * (u_1)**0.0966488 * (u_2)**27.3915
+ 0.634617 * (u_1)**-0.0265261 * (u_2)**0.0118065
+ 0.362956 * (u_1)**0.0510403 * (u_2)**-0.0161858
RMS Error: 0.013 after iter=0, Altitude 40000
...Pandas error...
In [3]: cns
Out[3]: gpkit.PosynomialInequality(w_fit**0.003 >= 0.363*u_fit_(0,)**0.051*u_fit_(1,)**-0.016 + 0.635*u_fit_(0,)**-0.027*u_fit_(1,)**0.012) |
That looks like a refactor problem, yeah! For some reason it's dropping the two smaller terms. |
Resolved by the latest commit, I think: was a numerical issue with small values of alpha |
@mjburton11, re: |
Now with more refactor... |
@mjburton11, @whoburg, this is ready for review. |
@galbramc, the example seems unable to import gpfit? Or at least it has this pylint error: "Unable to import 'gpfit.fit'" |
@galbramc, fixed it by pip installing gpfit in jenkins |
Hmm, didn't realize I had forgotten to install gpfit |
I've run this through all my stuff and it works fine. I like that the |
:) merge away! (this'll just merge into your PR)
…On Dec 30, 2016 13:39, "Michael Burton" ***@***.***> wrote:
I've run this through all my stuff and it works fine. I like that the
evaluate function can be called from constraint. Much more elegant way to
do that...
—
You are receiving this because you were mentioned.
Reply to this email directly, view it on GitHub
<#61 (comment)>, or mute
the thread
<https://github.com/notifications/unsubscribe-auth/ABagGCjcgP8n81zSs3UYb4USoNbM2sWlks5rNXn-gaJpZM4LTq2I>
.
|
Should I squash/merge? |
Probably regular merge into yours, and we can decide whether to squash from
there?
…On Dec 30, 2016 14:23, "Michael Burton" ***@***.***> wrote:
Should I squash/merge?
—
You are receiving this because you were mentioned.
Reply to this email directly, view it on GitHub
<#61 (comment)>, or mute
the thread
<https://github.com/notifications/unsubscribe-auth/ABagGANmqv7eMqf-6B3SNdEpzMTwxHKGks5rNYRegaJpZM4LTq2I>
.
|
Deleted branch. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks @bqpd, what a huge bunch of improvements! I finally had a chance to review and left a few comments / suggestions. Should we address those with issues / a new PR?
@@ -60,7 +60,7 @@ confidence= | |||
# no Warning level messages displayed, use"--disable=all --enable=classes | |||
# --disable=W" | |||
#disable=import-star-module-level,old-octal-literal,oct-method,print-statement,unpacking-in-except,parameter-unpacking,backtick,old-raise-syntax,old-ne-operator,long-suffix,dict-view-method,dict-iter-method,metaclass-assignment,next-method-called,raising-string,indexing-exception,raw_input-builtin,long-builtin,file-builtin,execfile-builtin,coerce-builtin,cmp-builtin,buffer-builtin,basestring-builtin,apply-builtin,filter-builtin-not-iterating,using-cmp-argument,useless-suppression,range-builtin-not-iterating,suppressed-message,no-absolute-import,old-division,cmp-method,reload-builtin,zip-builtin-not-iterating,intern-builtin,unichr-builtin,reduce-builtin,standarderror-builtin,unicode-builtin,xrange-builtin,coerce-method,delslice-method,getslice-method,setslice-method,input-builtin,round-builtin,hex-method,nonzero-method,map-builtin-not-iterating | |||
disable=locally-disabled | |||
disable=locally-disabled,superfluous-parens,wrong-import-position, fixme, duplicate-code, maybe-no-member |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
In gpkit our pylint.sh
script runs pylint with --disable=fixme
. That seems better than disabling here, so that pylint plugins will show todos.
Also not sure I agree with disabling duplicate-code
, especially while we're working towards refactor! But I know it's a pain until we get the counts to zero, so maybe we should address that by opening an issue re: duplicate-code.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The duplicate code is in the tests directory, which could probably be allowed to have duplicate code...not that this is the right way to do that, either.
|
||
# Naming hint for function names | ||
function-name-hint=[a-z_][a-z0-9_]{2,30}$ | ||
function-rgx=[A-Za-z_][a-z0-9_]{2,30}$ |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
what method needs caps?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I might have done search-and-replace, I was so tired of pylint.
|
||
# Naming hint for class names | ||
class-name-hint=[A-Z_][a-zA-Z0-9]+$ | ||
class-rgx=[t_]?|[A-Z_][a-zA-Z0-9]+$ |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
wouldn't it be better to just update our test classes and modules to follow the expected style?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Definitely!
@@ -3,14 +3,16 @@ | |||
import numpy as np | |||
from numpy import array, arange | |||
from gpfit.lse_implicit import lse_implicit | |||
from .seed import SEED | |||
|
|||
SEED = 33404 |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
just curious, why hard-code this instead of importing?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
With the local import you can't run the test files as scripts!
oh, this got merged to |
I think this mostly replaced smaequality! I'll check what the diff is. |
Made a new issue for these pylint issues: #63 |
@whoburg, these changes were identical to those in |
as part of digging into the gpfit code I cleaned up some logic in
fit.py
...@mjburton11, could you check this still works with your stuff?
@whoburg, ready for review.