Ejemplo n.º 1
0
JNIEXPORT jobject JNICALL Java_retin_feature_vlat_SparseVlatBuilder_runNativeGenerator
  (JNIEnv *env, jobject thisObject, jobject nativePointerObj, jstring keyObj, jint degre, jstring formatObj){
    RETIN_JAVA_METHOD_BEGIN

    JavaEnv je(env);
    string key = je.createString(keyObj);
    
    FeatureListRef centers = je.getDocumentField<FeatureList> (thisObject,"centers");

    vector<FeatureListRef> tensors; 
    je.getDocumentField<FeatureList> (tensors,thisObject,"tensors");
    
    vector<FloatMatrixRef> Ls; je.getDocumentField<FloatMatrix> (Ls,thisObject,"Ls");
    vector<FloatMatrixRef> Ps; je.getDocumentField<FloatMatrix> (Ps,thisObject,"Ps");
           
    string format = je.createString(formatObj);
    
    
    NativePointerRef instance = je.createDocument<NativePointer>(nativePointerObj);
    NativeDocumentGenerator *ngd = instance->getPointerAs<NativeDocumentGenerator>();
    
    FeatureListRef features = boost::static_pointer_cast<FeatureList>(ngd->computeDocument(key));
    
    SparseVlatBuilder vlat(degre,centers->size(),centers->dim());
    vlat.setCenters(centers->data(),centers->size(),centers->dim());
    for (int d=0;d<degre;d++) {
        FeatureListRef tensor = tensors[d];
        vlat.setMeanTensors(d+1,tensor->data(),tensor->size(),tensor->dim());
    }
    for (int i=0;i<Ls.size();i++) {
        vlat.setEigenDecomposition(i, Ps[i]->data(), Ls[i]->data(), Ps[i]->vectorSize(), Ps[i]->vectorCount());
    }
    
    vlat.setSparsityOn(je.getField<jint>(thisObject,"sparsityOn"));
    vlat.setSparsityStrategy(je.getField<jint>(thisObject,"sparsityStrategy"));
    vlat.setDimSparsity(je.getField<jint>(thisObject,"sparsityDim"));
    vlat.setEnergySparsity(je.getField<jfloat>(thisObject,"sparsityEnergy"));

    vlat.process(features->data(),features->size(),features->dim());

    FeatureRef outputRef = boost::make_shared<Feature>(vlat.getVlatDim(format));
    vlat.getVlat(outputRef->data(),format);

    return je.createObject (outputRef);
    
    RETIN_JAVA_METHOD_END
    return NULL;
}
Ejemplo n.º 2
0
JNIEXPORT jobject JNICALL Java_retin_feature_vlat_StandardPcaVlatBuilder_runNativeGenerator
  (JNIEnv *env, jobject thisObject, jobject nativePointerObj, jstring keyObj, jint degre, jstring formatObj){
    RETIN_JAVA_METHOD_BEGIN

    JavaEnv je(env);
    string key = je.createString(keyObj);
    
    FeatureListRef centers = je.getDocumentField<FeatureList> (thisObject,"centers");

    vector<FeatureListRef> tensors; 
    je.getDocumentField<FeatureList> (tensors,thisObject,"tensors");

    vector<MatrixRef> vectors;
    je.getDocumentField<Matrix> (vectors,thisObject,"vectors");

    vector<MatrixRef> values;
    je.getDocumentField<Matrix> (values,thisObject,"values");

    vector<IntegerRef> dims;
    je.getDocumentField<retin::Integer> (dims,thisObject,"dims");

    jboolean whitening = je.getField<jboolean>(thisObject,"whitening");
            
    string format = je.createString(formatObj);
    
    
    NativePointerRef instance = je.createDocument<NativePointer>(nativePointerObj);
    NativeDocumentGenerator *ngd = instance->getPointerAs<NativeDocumentGenerator>();

    FeatureListRef features = boost::static_pointer_cast<FeatureList>(ngd->computeDocument(key));

    StandardPcaVlatBuilder vlat(centers, tensors, vectors, values, dims, 
            whitening, centers->size(), degre);

    vlat.process(features);
    
    return je.createObject (vlat.getVlat(format));
    
    RETIN_JAVA_METHOD_END
    return NULL;
}