Problem with Adding setSoftEvidence to jSmile

The engine.
Post Reply
HoloDoc
Posts: 5
Joined: Tue Nov 24, 2009 3:50 pm

Problem with Adding setSoftEvidence to jSmile

Post by HoloDoc »

I tried to extend the jSmile wrapper to also include the possibility to set soft evidence.
So in Network.java I added

Code: Select all

public native void setSoftEvidence(String nodeId, double[] evidence);
and in smile_Network the respective Method looks like this:

Code: Select all

JNIEXPORT void JNICALL Java_smile_Network_setSoftEvidence__Ljava_lang_String_2_3D(JNIEnv *env, jobject obj, jstring nodeId, jdoubleArray evidence)
{
    JSMILE_ENTER;
    int nodeHandle = ValidateNodeId(env, obj, nodeId);	
    DSL_node *node = ValidateNodeHandle(env, obj, nodeHandle);

    std::vector<double> vEvidence;
    
    int length = env->GetArrayLength(evidence);
	
    for (int i = 0; i < length; i ++) 
    {
        double d;
        env->GetDoubleArrayRegion(evidence, i, 1, &d);
	     vEvidence.push_back(d);
    }
	
    int res = node->Value()->SetSoftEvidence(vEvidence);
    if (DSL_OKAY != res) 
    {
        ThrowSmileException(env, "SetSoftEvidence", res);
    }
    JSMILE_LEAVE;
}
Is there anything more I should add?

The problem now is, that when I'm calling the new method from my Java programm, "res" is -2, which corresponds to DSL_OUT_OF_RANGE.
I don't think there's a problem with the call from Java itself, the double array should have the right length.
I tried to open the same xdsl with SMILE and add the soft evidence to the same node and that worked, so I think the problem also isn't in the file.

My best bet would be that the code I posted above is wrong or I missed something, which wouldn't be a very big surprise, given I have almost no experience with wrappers or JNI.
So, any help is appreciated.
shooltz[BayesFusion]
Site Admin
Posts: 1457
Joined: Mon Nov 26, 2007 5:51 pm

Re: Problem with Adding setSoftEvidence to jSmile

Post by shooltz[BayesFusion] »

HoloDoc wrote:The problem now is, that when I'm calling the new method from my Java programm, "res" is -2, which corresponds to DSL_OUT_OF_RANGE.
I don't think there's a problem with the call from Java itself, the double array should have the right length.
I tried to open the same xdsl with SMILE and add the soft evidence to the same node and that worked, so I think the problem also isn't in the file.[/quote]

The JNI code posted above looks correct.

The only code path in SetSoftEvidence which returns DSL_OUT_OF_RANGE is executed when node's outcome count is different than size of soft evidence vector.
Post Reply