Esempio n. 1
0
def actionSBFit(formFields):
    global textFormat

    fn = getDataFile(formFields)
    oc = ocUtils("SB")
    global globalOcInstance
    globalOcInstance = oc
    if not textFormat:
        print '<pre>'
    oc.initFromCommandLine(["", fn])
    if not textFormat:
        print '</pre>'
    oc.setDataFile(formFields["datafilename"])
    handleGraphOptions(oc, formFields)
    #functionFlag = formFields.get("functionvalues", "")
    #if functionFlag:
    #oc.setValuesAreFunctions(1)
    if not formFields.has_key("data") or not formFields.has_key("model"):
        actionNone(formFields, "Missing form fields")
        os.remove(fn)
        return
    skipNominalFlag = formFields.get("skipnominal", "")
    if skipNominalFlag:
        oc.setSkipNominal(1)

    maybeSkipResiduals(formFields, oc)
    maybeSkipIVIs(formFields, oc)

    target = formFields["negativeDVforConfusion"] if formFields.has_key(
        "negativeDVforConfusion") else ""

    onlyGfx = formFields.has_key("onlyGfx")
    processSBFit(fn, formFields["model"], target, oc, onlyGfx)
    os.remove(fn)
Esempio n. 2
0
    def computeBestModel(filename):
        oc = ocUtils("VB")
        global globalOcInstance
        globalOcInstance = oc
        oc.initFromCommandLine(["occam", filename])
        oc.setDataFile(filename)
        oc.setAction("search")

        # Hardcoded settings (for now):
        oc.setSortDir("descending")
        oc.setSearchSortDir("descending")  # try to maximize dBIC or dAIC.
        oc.setRefModel("bottom")  # Always uses bottom as reference.

        # Parameters from the web form
        oc.sortName = search["sort by"]
        oc.setSearchLevels(int(search["levels"]))
        oc.setSearchWidth(int(search["width"]))
        oc.setSearchFilter(search["type"])

        [i, d] = search["direction"].split(" ")
        oc.searchDir = d
        oc.setStartModel(i)

        return oc.findBestModel()
Esempio n. 3
0
def actionSearch(formFields):
    global textFormat
    fn = getDataFile(formFields)
    man = "VB"
    oc = ocUtils(man)
    global globalOcInstance
    globalOcInstance = oc
    if not textFormat:
        print '<pre>'
    oc.initFromCommandLine(["", fn])
    if not textFormat:
        print '</pre>'
    oc.setDataFile(formFields["datafilename"])
    # unused error? this should get caught by getDataFile() above
    if not formFields.has_key("data"):
        actionForm(form, "Missing form fields")
        print "missing data"
        return
    #textFormat = formFields.get("format", "")
    if textFormat:
        oc.setReportSeparator(ocUtils.COMMASEP)
    else:
        oc.setReportSeparator(ocUtils.HTMLFORMAT)

    oc.setSortDir(formFields.get("sortdir", ""))
    levels = formFields.get("searchlevels")
    if levels and levels > 0:
        oc.setSearchLevels(levels)
    width = formFields.get("searchwidth")
    if width and width > 0:
        oc.setSearchWidth(width)
    reportSort = formFields.get("sortreportby", "")
    searchSort = formFields.get("sortby", "")
    inverseFlag = formFields.get("inversenotation", "")
    if inverseFlag:
        oc.setUseInverseNotation(1)
    skipNominalFlag = formFields.get("skipnominal", "")
    if skipNominalFlag:
        oc.setSkipNominal(1)
    functionFlag = formFields.get("functionvalues", "")
    if functionFlag:
        oc.setValuesAreFunctions(1)
    oc.setStartModel(formFields.get("model", "default"))
    refModel = formFields.get("refmodel", "default")
    #specificRefModel = ""
    #if refModel == "specific" and formFields.has_key("specificrefmodel"):
    #    refModel = formFields["specificrefmodel"]
    #specificRefModel = refModel
    if refModel == "starting":
        refModel = oc.getStartModel()
    oc.setRefModel(refModel)
    oc.searchDir = formFields.get("searchdir", "default")
    oc.setSearchSortDir(formFields.get("searchsortdir", ""))
    oc.setSearchFilter(formFields.get("searchtype", "all"))
    oc.setAlphaThreshold(formFields.get("alpha-threshold", "0.05"))
    oc.setAction("search")

    ## INTENTIONALLY COMMENTED OUT CODE IN THIS MULTILINE STRING!!!
    ## This code handles the backpropagation-based evaluation,
    ## but it is not currently used (and the HTML forms do not define "evalmode"
    ## so it will crash!!)
    disabledBPCode = """
    if formFields["evalmode"] == "bp":
        reportvars = "Level$I, bp_t, bp_h, ddf, bp_lr, bp_alpha, bp_information"
        oc.setNoIPF(true)
        if reportSort == "information": reportSort = "bp_information"
        elif reportSort == "alpha": reportSort = "bp_alpha"
        if searchSort == "information": searchSort = "bp_information"
        elif searchSort == "alpha": searchSort = "bp_alpha"
        if oc.isDirected():
            reportvars += ", bp_cond_pct_dh"
        reportvars += ", bp_aic, bp_bic"
    """
    if False: pass
    else:
        reportvars = "Level$I"
        if formFields.get("show_h", ""):
            reportvars += ", h"
        reportvars += ", ddf"
        if formFields.get("show_dlr", ""):
            reportvars += ", lr"
        if formFields.get(
                "show_alpha",
                "") or searchSort == "alpha" or reportSort == "alpha":
            reportvars += ", alpha"
        reportvars += ", information"
        if oc.isDirected():
            if formFields.get("show_pct_dh", ""):
                reportvars += ", cond_pct_dh"
        if formFields.get("show_aic",
                          "") or searchSort == "aic" or reportSort == "aic":
            reportvars += ", aic"
        if formFields.get("show_bic",
                          "") or searchSort == "bic" or reportSort == "bic":
            reportvars += ", bic"
    if formFields.get("show_incr_a", ""):
        reportvars += ", incr_alpha, prog_id"


## INTENTIONALLY COMMENTED OUT CODE IN THIS MULTILINE STRING!!!
## This code handles the backpropagation-based evaluation,
## but it is not currently used (and the HTML forms do not define "evalmode"
## so it will crash!!)
    disabledBPCode = """
    if formFields.get("show_bp", "") and formFields["evalmode"] <> "bp":
        reportvars += ", bp_t"
    """

    if oc.isDirected():
        if formFields.get("show_pct", "") or formFields.get(
                "show_pct_cover", ""
        ) or searchSort == "pct_correct_data" or reportSort == "pct_correct_data":
            reportvars += ", pct_correct_data"
            if formFields.get("show_pct_cover", ""):
                reportvars += ", pct_coverage"
            if oc.hasTestData():
                reportvars += ", pct_correct_test"
                if formFields.get("show_pct_miss", ""):
                    reportvars += ", pct_missed_test"
    oc.setReportSortName(reportSort)
    oc.sortName = searchSort
    oc.setReportVariables(reportvars)
    if textFormat:
        oc.doAction(printOptions)
    else:
        print "<hr><p>"
        print '<div class="data">'
        oc.doAction(printOptions)
        print "</div>"
    os.remove(fn)
Esempio n. 4
0
        0]
    sys.exit()

if len(sys.argv) >= 4:
    swidth = sys.argv[2]
    slevels = sys.argv[3]
else:
    swidth = 3
    slevels = 7

if len(sys.argv) >= 5:
    filter = sys.argv[4]
else:
    filter = "loopless"

util = ocUtils("SB")  # create a variable-based manager
t1 = time.time()
util.initFromCommandLine(sys.argv[0:2])  # initialize with the data file

#------------- Main script ---------------
# This script sets various options on a ocUtils object, and then runs the desired action.
# ocUtils is a convenience wrapper around the basic occam3 objects, and it sets appropriate
# defaults if you don't set every option.

# For settings which require model attribute names, the allowed values include:
# h, t, df, ddf, loops [1=loops, 0=no loops]
# information, unexplained, ipf_iterations, lr, alpha, beta, level, aic, bic
# cond_h, cond_dh, cond_pct_dh, cond_df, cond_ddf, p2, p2_alpha, p2_beta
# (Note that the Pearson statistics aren't computed by default because they are expensive.)
# To force a particular attribute to be printed as an integer, append "$I" to the name (e.g., Level$I)
Esempio n. 5
0
File: bp.py Progetto: shrashan/occam
# p2		-- computed by default because they are expensive
# p2_alpha
# p2_alpha
# p2_beta
# p2_beta

# To force a particular attribute to be printed as an integer,
# append "$I" to the name (e.g., Level$I)

#-------------------------------------------------

# create an ocUtils object. This is a convenience wrapper which can
# handle Occam2 files and options
# See the source file for other options which can be set

util = ocUtils()
util.initFromCommandLine(sys.argv)

# set desired options which aren't in the data file, or override them
# here.

# set separator between report fields.
# 1=tab, 2=comma, 3=space fill, 4=HTML
util.setReportSeparator(3)

# set report names, from the list above. If omitted, the list is set
# based on whether the ref model is top or bottom. List is separated
# by commas, and provided as a single text string
# for ref=top, this is a good list:
#util.setReportVars("Level$I, h, ddf, lr, alpha, information")
# for ref=bottom, use something like this:
Esempio n. 6
0
#import pdb
import os, sys
#sys.path.append("/www")
import occam
import time

from ocutils import ocUtils

if len(sys.argv) < 3:
	print 'Incorrect parameters.'
	print 'Usage: %s datafile model' % sys.argv[0]
	sys.exit()


oc = ocUtils("VB")

t1 = time.time()
oc.initFromCommandLine(sys.argv[0:2]) # initialize with the data file

oc.setFitModel(sys.argv[2])
oc.setAction("fit")
oc.setReportSeparator(3)
oc.setSkipNominal(1)
oc.setDDFMethod(1)
#oc.setDefaultFitModel("IV:CD")

t2 = time.time()
oc.doAction(1)
t3 = time.time()
Esempio n. 7
0
# distribution of this software for license terms.

import pdb
import os, sys
sys.path.append("/www")
import occam
import time

from ocutils import ocUtils

if len(sys.argv) < 3:
    print 'Incorrect parameters.'
    print 'Usage: %s datafile model' % sys.argv[0]
    sys.exit()

oc = ocUtils("SB")

t1 = time.time()
oc.initFromCommandLine(sys.argv[0:2])  # initialize with the data file

oc.setFitModel(sys.argv[2])
oc.setAction("SBfit")
oc.setReportSeparator(3)
#oc.setDDFMethod(1)

t2 = time.time()
oc.doAction(0)
t3 = time.time()

print "start:  %8f" % (t2 - t1)
print "fit: %8f" % (t3 - t2)