示例#1
0
文件: ACOSSO.py 项目: sotorrio1/FOQUS
 def __init__(self, dat=None):
     '''
         ACOSSO interface constructor
     '''
     surrogate.__init__(self, dat)
     self.minInputs = 2
     self.maxInputs = 100
     self.minOutputs = 1
     self.maxOutputs = 1
     self.ex = None
     # Information about the method
     self.methodDescription = \
         "<html>"\
         "<p>ACOSSO:</p>"\
         "<p>The Adaptive COmponent Selection and Shrinkage"\
         " Operator (ACOSSO) surface approximation was developed"\
         " under the Smoothing Spline Analysis of Variance"\
         " (SS-ANOVA) modeling framework. As it is a smoothing type"\
         " method, ACOSSO works best when the underlying function"\
         " is somewhat smooth. For functions which are known to have"\
         " sharp changes or peaks, etc., other methods may be more"\
         " appropriate Since it implicitly performs variable"\
         " selection, ACOSSO can also work well when there are a"\
         " large number of input variables. To facilitate the"\
         " description of ACOSSO, we first review the univariate"\
         " smoothing spline. The ACOSSO procedure also allows for"\
         " categorical inputs.</p>"\
          "</html>"
     # acosso working directory
     self.acossoDir = 'acosso'
     # add options
     self.options.add(
         name="Data Filter",
         default='all',
         dtype=str,
         desc="Filter for sample data, from flowsheet data",
         validValues = ['All', 'None'])
     self.options.add(
         name="Use Flowsheet Data",
         default='Yes',
         dtype=str,
         desc="Use data from FOQUS flowsheet or provide csv files",
         validValues = ['Yes', 'No'])
     self.options.add(
         name="Input Data File",
         default='acosso'+os.path.sep+'xdat.csv',
         dtype=str,
         desc="csv file containing data for model inputs")
     self.options.add(
         name="Output Data File",
         default='acosso'+os.path.sep+'ydat.csv',
         dtype=str,
         desc="csv file containing data for model outputs")
     #self.options.add(
     #    name="RScript path",
     #    default=\
     #        'C:\\Program Files\\R\\R-3.1.2\\bin\\x64\\Rscript.exe',
     #    dtype=str,
     #    desc="Full path the RScript executable")
     self.options.add(
         name="Model File",
         default='acosso_fit.rds',
         dtype=str,
         desc="ACOSSO output R data file")
     self.options.add(
         name="FOQUS Model (for UQ)",
         default="acosso_surrogate_uq.py",
         dtype=str,
         desc=".py file for UQ analysis")
     self.options.add(
         name="FOQUS Model (for Flowsheet)",
         default="acosso_surrogate_fs.py",
         dtype=str,
         desc=".py file flowsheet plugin, saved to user_plugins"\
             " in the working directory")
     self.options.add(
         name="CV",
         default='bic',
         dtype=str,
         validValues = ['5cv', 'gcv', 'bic'],
         desc="Method used to calculate ACOSSO tuning parameter M")
     self.options.add(
         name="Order",
         default=2,
         dtype=int,
         validValues = [1, 2],
         desc="order of interactions to consider")
示例#2
0
    def __init__(self, dat=None):
        '''
            ALAMO interface constructor
        '''
        surrogate.__init__(self, dat)
        self.name = "ALAMO"
        self.ex = None
        #still working on hanging indent for references
        self.methodDescription = \
            ("<html>\n<head>"
             ".hangingindent {\n"
             "    margin-left: 22px ;\n"
             "    text-indent: -22px ;\n"
             "}\n"
             "</head>\n"
             "<b>Automatic Learning of Algebraic Models for Optimization"
             " (ALAMO)</b>"
             "<p class=\"hangingindent\">Cozad, A., N. V. Sahinidis "
             "and D. C. Miller, Learning surrogate models "
             "for simulation‐based optimization, "
             "AIChE Journal, 60, p. 2211–2227, 2014.</p></html>")
        self.alamoDir = 'alamo'
        self.inputCols = [
            ('XFACTOR', float, 1.0),
            ('EXTRAPXMIN', float, 0.0),
            ('EXTRAPXMAX', float, 1.0)]
        self.outputCols = [
            ('MAXTERMS', int, -1),
            ('IGNORE', int, 0),
            ('TOLMEANERROR', float, 0.001),
            ('TOLRELMETRIC', float, 0.0001),
            ('ZMIN', float, 0.0),
            ('ZMAX', float, 1.0),
            ('CUSTOMCON', list, [])]
        self.updateVarCols()
        #include a Section called DATA Settings
        #Check the ALAMOSettings_v2.xlsx with hints and new labels
        self.options.add(
            name="Initial Data Filter",
            section="DATA Settings",
            default='All',
            dtype=str,
            desc="Filter to be applied to the initial data set.",
            hint="Data filters help the user to generate models based"
            "on specific data for each variable.",
            validValues = ['All', 'None'])

        self.options.add(
            name="Validation Data Filter",
            section="DATA Settings",
            default='None',
            dtype=str,
            desc="Data set used to compute model errors at the validation phase.",
            hint="The number of data points in a preexisting validation data set"
            "can be specified by the user",
            validValues = ['All', 'None'])
        #Maxtime
        self.options.add(
            name="MAXTIME",
            section="DATA Settings",
            default=2000,
            desc="Maximum total execution time in seconds.",
            hint="This time includes all steps of the algorithm, including "
                "time to read problem, preprocess data, solve "
                "optimization subproblems, and print results."
            )
        self.options.add(
            name="MINPOINTS",
            section="DATA Settings",
            default=0,
            dtype=int,
            desc="Convergence is assessed only if the simulator is able to compute the "
            "output variables for at least MINPOINTS out the data points requested by ALAMO.",
            hint="A reduced number of MINPOINTS may reduce the computational time to get a model,"
                 "but also reducess the accuracy of the model. MINPOINTS must be a positive integer.")
        self.options.add(
            name="NSAMPLE",
            section="Data Settings",
            default=0,
            dtype=int,
            desc="Number of data points to be generated by sampling before any model is built.",
            hint="These points will be used for model builing along with the NDATA points specified by the user. NSAMPLE must be a nonnegative integer.")
        self.options.add(
            name="MAXSIM",
            section="Data Settings",
            default=5,
            dtype=int,
            desc=" Maximum number of successive simulator failures allowed before quit",
            hint="MAXSIM must be a nonnegative integer")
        #Sampler
        self.samplers={
            "None":0,
            "Random":1,
            "SNOBFIT":2}
        self.options.add(
            name="SAMPLER",
            section="DATA Settings",
            default="None",
            desc="Adaptive sampling method to be used. If adaptive sampling is used, also set MAXITER below.",
            hint="Adaptive sampling method to be used by ALAMO when more data points are needed by the model"
            "If random is used a simulator must be provided by the user. If SNOBFIT is used a simulator must be"
            " by the user and MATLAB must be istalled.",
            validValues = sorted(list(self.samplers.keys()),
                key=lambda k: self.samplers[k]))
        self.options.add(
            name="MAXITER",
            section="DATA Settings",
            default=1,
            desc="Maximum number of ALAMO iterations, 1 = no adaptive sampling, 0 = no limit",
            hint="The maximum number of ALMAO iterations for adaptive sampling, 1 = no adaptive sampling, 0 = no limit")
        self.options.add(
            name="PRESET",
            section="DATA Settings",
            default=-111111,
            desc="Value to be used if the simulation fails.",
            hint="This value must be carefully chosen to be an otherwise not realizable value for the output variables")
        #Add the Section: Model Settings
        self.options.add(
            name="MONOMIALPOWER",
            section="Model Settings",
            default=[1,2,3],
            dtype=list,
            desc="Vector of monomial powers considered in basis "
                "functions. Use an empty vector for none.",
            hint="Exponential terms allowed in the algebraic model as basis functions.")
        self.options.add(
            name="MULTI2POWER",
            section="Model Settings",
            default=[1],
            desc="Vector of powers to be considered for pairwise "
                "combinations in basis functions.   Empty vector "
                "for none.",
            hint="Pairwise combination of powers allowed in the algebraic model.")
        self.options.add(
            name="MULTI3POWER",
            section="Model Settings",
            default=[],
            desc="Vector of three variables combinations of powers to be consiedered as basis functions.",
            hint= "Empty vector for none [].")
        self.options.add(
            name="RATIOPOWER",
            section="Model Settings",
            default=[],
            desc="Vector of ratio combinations of powers to be considered in the basis functions.",
            hint="Ratio combinations of powers are empty as default.")
        self.options.add(
            name="EXPFCNS",
            section="Model Settings",
            default=True,
            desc="Use or not of exponential functions as basis functions in the model.")
        self.options.add(
            name="LOGFCNS",
            section="Model Settings",
            default=True,
            desc="Logarithimic functions are considered as basis "
                "functions if true; otherwise, they are not considered.")
        self.options.add(
            name="SINFCNS",
            section="Model Settings",
            default=False,
            desc="Sine functions are considered as basis functions if "
                "true; otherwise, they are not considered.")
        self.options.add(
            name="COSFCNS",
            section="Model Settings",
            default=False,
            desc="Cosine functions are considered as basis functions if "
                "true; otherwise, they are not considered.")
        self.options.add(
            name="CUSTOMBAS",
            section="Model Settings",
            default = [],
            dtype = list,
            desc = "A list of user-supplied custom basis functions can "
                   "be provided by the user. ",
            hint="The parser is not case sensitive and allows for any "
                "Fortran functional expression in terms of the XLABELS. "
                "In addition, the symbol ^ may be used to denote power "
                "operations instead of **.")
        self.modelers = {
            "BIC":1,
            "Mallow's Cp":2,
            "AICc":3,
            "HQC":4,
            "MSE": 5,
            "Convex Penalty": 6,
            "RIC": 7}
        self.options.add(
            name="MODELER",
            section="Model Settings",
            default="BIC",
            dtype=str,
            desc="Fitness metric to be used for model building.",
            hint="Possible values are Bayesian information criterion, "
                "Mallow's Cp, the corrected Akaike's information "
                "criterion, the Hannan-Quinn information criterion, "
                "mean square error, and a convex penalty consisting of "
                "the sum of square errors and a term penalizing model "
                "size.",
            validValues = sorted(list(self.modelers.keys()),
                key=lambda k: self.modelers[k]))
        self.options.add(
            name="CONVPEN",
            section="Model Settings",
            default=10.0,
            desc="Convex penalty term used if Convex penalty is selected.",
            hint="When MODELER is set to \"Convex Penalty,\" a convex "
                "penalty consisting of the sum of square errors and a "
                "term penalizing model size is used for model building. "
                "In this case, the size of the model is weighted "
                "by CONPEN.")
        self.options.add(
            name="REGULARIZER",
            section="Model Settings",
            default=False,
            desc="Regularization method is used to reduce the number of "
                "potential basis functions before optimization.",
            hint="If true, "
                "regularization with the LASSO is used.")
        self.options.add(
            name="SCALEZ",
            section="Model Settings",
            default=False,
            desc="If used, the variables are scaled prior to the optimization problem is solved.",
            hint="The problem is solved using a mathematical programming solver. Usually, scaling"
            " the variables may help the optimization.")
        #Add the Section: SOLVER Settings
        self.options.add(
            name="GAMS",
            section="Solver Settings",
            default="gams",
            desc="GAMS path is needed. GAMS is the software used to solve the optimization problems.",
            hint="The executable path is expected here or the user must declare GAMS.exe in the environment path.")
        self.options.add(
            name="GAMSSOLVER",
            section="Solver Settings",
            default="BARON",
            desc="Name of preferred GAMS solver for solving ALAMO's mixed-integer quadratic subproblems.",
            hint=" Special features "
                "have been implemented in ALAMO and BARON that "
                "make BARON the preferred selection for this option. "
                "However, any mixed-integer quadratic programming solver "
                "available under GAMS can be used. ")
        self.options.add(
            name="SOLVEMIP",
            section="Solver Settings",
            default=False,
            dtype = bool,
            desc="GAMS will be used to solve ALAMO's MIPs/MIQPs if checked",
            hint="")
        self.funform = {
            "Fortran":1,
            "GAMS":2,
            "BARON":3,
            "C":4}
        self.options.add(
            name="FUNFORM",
            section="Solver Settings",
            default="Fortran",
            desc="Format for printing basis functions and models found by ALAMO. Fortran must be selected to generate FOQUS UQ and flowsheet models.",
            hint="",
            validValues = sorted(list(self.funform.keys()), key=lambda k: self.funform[k]))
        self.options.add(
            name="MIPOPTCA",
            section="Solver Settings",
            default=0.05,
            desc="Absolute convergence tolerance for mixed-integer "
                "optimization problems.",
            hint="This must be a nonnegative "
                "scalar.")
        self.options.add(
            name="MIPOPTCR",
            section="Solver Settings",
            default=0.0001,
            desc="Relative convergence tolerance for mixed-integer "
                "optimization problems.",
            hint="This must be a nonnegative "
                "scalar.")
        self.options.add(
            name="LINEARERROR",
            section="Solver Settings",
            default=False,
            desc="If true, a linear objective is used when solving "
                "the mixed-integer optimization problems.",
            hint="If used the Quadratic objective function is replaced by a linear objective function.")
        self.options.add(
            name="CONREG",
            section="Solver Settings",
            default=False,
            desc="Specify whether a constraint regression is used or not.",
            hint="If CONREG is true, bounds on output variables are "
                "enforced.")
        self.options.add(
            name="CRNCUSTOM",
            section="Solver Settings",
            default=False,
            desc="If true, constraints need to be entered in variables tab.")
        self.options.add(
            name="CRNINITIAL",
            section="Solver Settings",
            default=0,
            dtype=int,
            desc="Number of random bounding points at which constraints "
                "are sampled initially.",
            hint="CRNINITIAL must be a "
                "nonnegative integer.")
        self.options.add(
            name="CRNMAXITER",
            section="Solver Settings",
            default=10,
            dtype=int,
            desc="Maximum allowed constrained regressions iterations.",
            hint="Constraints are enforced on additional points during "
                "each iteration. CRMAXITER must be a positive integer.")
        self.options.add(
            name="CRNVIOL",
            section="Solver Settings",
            default=100,
            dtype=int,
            desc="Number of bounding points added per round per bound "
                "in each iteration.",
            hint="CRNVIOL must be a positive integer.")
        self.options.add(
            name="CRNTRIALS",
            section="Solver Settings",
            default=100,
            dtype=int,
            desc="Number of random trial bounding points per round of "
                "constrained regression.",
            hint="CRNTRIALS must be a positive "
                "integer.")
        self.options.add(
            name="CRTOL",
            section="Solver Settings",
            default=1e-3,
            dtype=int,
            desc="Tolerance within which custom constraints must be satisfied. Real greater than 1e-5 is expected",
            hint="Bound and custom constraints will be satisfied within an absolute tolerance equal to CRTOL")
        #Add the Section: Advanced Settings
        self.options.add(
            name="Input File",
            section="Advanced Settings",
            default="alamo.alm",
            dtype=str,
            desc="File name for ALAMO input file.")
        self.options.add(
            name="FOQUS Model (for UQ)",
            section="Advanced Settings",
            default="alamo_surrogate_uq.py",
            dtype=str,
            desc=".py file for UQ analysis.")
        self.options.add(
            name="FOQUS Model (for Flowsheet)",
            section="Advanced Settings",
            default="alamo_surrogate_fs.py",
            dtype=str,
            desc=".py file flowsheet plugin, saved to user_plugins"\
                " in the working directory.")

        self.inputVarButtons = (
            ('Set XFACTOR from range', self.autoXFact),)
        self.outputVarButtons = (
            ('Set ZMIN and ZMAX from current data filter', self.autoZMin),)
示例#3
0
 def __init__(self, dat=None):
     '''
         BSS-ANOVA interface constructor
     '''
     surrogate.__init__(self, dat)
     self.ex = None
     # Information about the method
     self.methodDescription = \
         ("<html>"
          "<p>BSS-ANOVA:</p>"
          "<p>The Bayesian Smoothing Spline ANOVA (BSS-ANOVA) is"
          " essentially a Bayesian version of ACOSSO.  It is"
          " Gaussian Process (GP) model with a non-conventional"
          " covariance function that borrows its form from SS-ANOVA."
          " It tackles the high dimensionality (of inputs) on two"
          " fronts: (i) variable selection to eliminate"
          " uninformative variables from the model and (ii)"
          " restricting the level of interactions involved among"
          " the variables in the model. This is done through a"
          " fully Bayesian approach which can also allow for"
          " categorical input variables with relative ease."
          " Since it is closely related to ACOSSO, it generally"
          " works well in similar settings as ACOSSO.</p>"
          "</html>")
     # bssanova working directory
     self.bssanovaDir = 'bssanova'
     # add options
     self.options.add(name="Data Filter",
                      default='all',
                      dtype=str,
                      desc="Filter for sample data, from flowsheet data",
                      validValues=['All', 'None'])
     self.options.add(
         name="Use Flowsheet Data",
         default='Yes',
         dtype=str,
         desc="Use data from FOQUS flowsheet or provide csv files",
         validValues=['Yes', 'No'])
     self.options.add(name="Input Data File",
                      default='bssanova' + os.path.sep + 'xdat.csv',
                      dtype=str,
                      desc="csv file containing data for model inputs")
     self.options.add(name="Output Data File",
                      default='bssanova' + os.path.sep + 'ydat.csv',
                      dtype=str,
                      desc="csv file containing data for model outputs")
     #self.options.add(
     #    name="RScript path",
     #    default=\
     #        'C:\\Program Files\\R\\R-3.1.2\\bin\\x64\\Rscript.exe',
     #    dtype=str,
     #    desc="Full path the RScript executable")
     self.options.add(name="Model File",
                      default='bssanova_fit.rds',
                      dtype=str,
                      desc="BSS-ANOVA output R data file")
     self.options.add(name="FOQUS Model (for UQ)",
                      default="bssanova_surrogate_uq.py",
                      dtype=str,
                      desc=".py file for UQ analysis")
     self.options.add(
         name="FOQUS Model (for Flowsheet)",
         default="bssanova_surrogate_fs.py",
         dtype=str,
         desc=".py file flowsheet plugin, saved to user_plugins"\
             " in the working directory")
     self.options.add(name="Burn In",
                      default=0,
                      dtype=int,
                      desc="Number of data point to ignore from begining")
     self.options.add(name="MCMC Iterations",
                      default=1000,
                      dtype=int,
                      desc="Total number of MCMC iterations")
     self.options.add(name="Record Interval",
                      default=1,
                      dtype=int,
                      desc="How often to record a sample")
     self.options.add(
         name="nterms",
         default=25,
         dtype=int,
         desc="number of eigenvalues to use to approximate BSSA-NOVA"\
             "covariance")
     self.options.add(name="order",
                      default=2,
                      dtype=int,
                      validValues=[1, 2],
                      desc="order of interactions to consider covariance")
     self.options.add(
         name="priorprob",
         default=0.5,
         dtype=float,
         desc="prior probability that a given component is"\
             " uninformative")