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
feat(StoNEZD): Implement StoNEZD by classes #14
Conversation
Thanks for your new pr and suggestions. After the refactoring work, we could schedule a meeting to discuss the next step work. Regarding this pr, I am thinking about whether we should integrate the CNLSZ to CNLS class similar to the CNLSDDF class. The user can free to choose whether they need the Z variables (or undesirable variables). In some R packages, they usually include the z variables in the main routine. What do you think? |
@ds2010 , great idea. |
OK, Good. Sorry, forgot to say the StoNEZD class. It also could be integrated into StoNED. |
@ds2010 , The merge has been done.
Rather than:
Since the arguments are much more complicated, calling functions with keyword arguments can help precisely using models. CNLS prodimport pandas as pd
import numpy as np
# import the package pystoned
from pystoned import CNLS
# import Finnish electricity distribution firms data
url = 'https://raw.githubusercontent.com/ds2010/pyStoNED-Tutorials/master/Data/firms.csv'
df = pd.read_csv(url, error_bad_lines=False)
# output
y = df['Energy']
# inputs
x1 = df['OPEX']
x1 = np.asmatrix(x1).T
x2 = df['CAPEX']
x2 = np.asmatrix(x2).T
x = np.concatenate((x1, x2), axis=1)
# define and solve the CNLS model
cet = "addi"
fun = "prod"
rts = "vrs"
model = CNLS.CNLS(y, x, cet=cet, fun=fun, rts=rts)
model.optimize(False)
model.display_residual() CNLS costimport pandas as pd
import numpy as np
# import the package pystoned
from pystoned import CNLS
# import Finnish electricity distribution firms data
url = 'https://raw.githubusercontent.com/ds2010/pyStoNED-Tutorials/master/Data/firms.csv'
df = pd.read_csv(url, error_bad_lines=False)
df.head(5)
# output
y = df['TOTEX']
# inputs
x1 = df['Energy']
x1 = np.asmatrix(x1).T
x2 = df['Length']
x2 = np.asmatrix(x2).T
x3 = df['Customers']
x3 = np.asmatrix(x3).T
x = np.concatenate((x1, x2, x3), axis=1)
# define and solve the CNLS model
cet = "mult"
fun = "cost"
rts = "crs"
model = CNLS.CNLS(y, x, cet=cet, fun=fun, rts=rts)
model.optimize()
model.display_residual() StoNEZD
|
@JulianaTa Yes. Good suggestion. One more comment:
|
Here is some information about the comment. For a further information, here is a part of architecture of the current pyStoNED:
The first stage is the main module Sharing a same for modules and classes is common in python. |
OK I see. Thanks! |
This pr provides a tiny refactor of CNLSZ and an implementation of StoNEZD.
First, thanks for the major refactoring of CNLSZ class, this pr used inheritance to reduce the duplicated codes for consistency of our package.
Second, the StoNEZD model has been implemented. It is now simple to implement this kind o advanced model since we have so many basic models as complements.
The testing codes are provided below:
CNLSZ
StoNEDZ
The models based on CNLS/StoNED are now available!
The models have not been refactored are below: