Using a PMML model with a DefineFunction element

30 views
Skip to first unread message

jcr...@gmail.com

unread,
Jan 10, 2014, 4:53:53 PM1/10/14
to augustu...@googlegroups.com
Hi there,

I'm very excited about using Augustus to run PMML models in Python.  My PMML models use DefineFunction and I'm running into problems.  I've modified the add two numbers example like this:


    <PMML version="4.1" xmlns="http://www.dmg.org/PMML-4_1">
        <Header/>
        <DataDictionary>
            <DataField name="x" dataType="double" optype="continuous"/>
            <DataField name="y" dataType="double" optype="continuous"/>
        </DataDictionary>
        <TransformationDictionary>
            <DefineFunction dataType="float" optype="continuous" name="add">
                <ParameterField optype="continuous" name="first"></ParameterField>
                <ParameterField optype="continuous" name="second"></ParameterField>
                    <Apply function="+" invalidValueTreatment="returnInvalid">
                        <FieldRef field="first"></FieldRef>
                        <FieldRef field="second"></FieldRef>
                    </Apply>
            </DefineFunction>
            <DerivedField name="z" dataType="double" optype="continuous">
                <Apply function="add">
                    <FieldRef field="x"/>
                    <FieldRef field="y"/>
                </Apply>
            </DerivedField>
        </TransformationDictionary>
    </PMML>


And this is my script for running it:

    from resources import add_two_numbers_file
    from augustus.strict import modelLoader

    # Load model
    with open(add_two_numbers_file, 'r') as model_file:
        model_str = model_file.read()
        model = modelLoader.loadXml(model_str)

    # Run model
    print model.calc({'x':[1,2,3],'y':[4,5,6]}).look()


However, I get an error:

    AttributeError: 'DefineFunction' object has no attribute '_setupCalculate'

I'm using the latest trunk and am able to run the unmodified example (without a DefineFunction) without a problem.  Any help would be much appreciated.


Best,

Jason

jpiv...@gmail.com

unread,
Jan 14, 2014, 1:09:11 PM1/14/14
to augustu...@googlegroups.com, jcr...@gmail.com
You are right: this was a bug.  (An API changed and DefineFunction was not brought up-to-date.)  It is now fixed in the [public SVN repository][1]: with Augustus >= r795, you can run your example as originally intended.

By the way, your PMML is coming from an external file, yet you load it into a string and then into a PMML DOM.  You can skip the intermediate step by just passing `loadXML` the file name:

    model = modelLoader.loadXml(add_two_numbers_file)

(This could be relevant for very large PMML files; also note that they can be GZipped.)



Sorry about that and thanks for letting us know,
-- Jim
Reply all
Reply to author
Forward
0 new messages