HomeDigital EditionSys-Con RadioSearch Java Cd
Advanced Java AWT Book Reviews/Excerpts Client Server Corba Editorials Embedded Java Enterprise Java IDE's Industry Watch Integration Interviews Java Applet Java & Databases Java & Web Services Java Fundamentals Java Native Interface Java Servlets Java Beans J2ME Libraries .NET Object Orientation Observations/IMHO Product Reviews Scalability & Performance Security Server Side Source Code Straight Talking Swing Threads Using Java with others Wireless XML
 

"Digital Neural Network COntrol Using JINI"
Volume: 4 Issue: 5, p. 38

	

Listing 1: JNI prototype implementation.
 
******************************************************* 
/* This is the actual C ZISC function prototype */ 
// void IMPORT Z_Identify(BYTE _far *componentArray, WORD _far NComp, WORD _far *Status,
 WORD _far *Category); 

/* This is a local wrapper for the actual C function. It can be used for debugging purposes
 to 
   verify data type conversions and returned values before they are passed to the third
    party 
   DLL */ 
void J_Z_Identify(BYTE *componentArray, WORD nComp, WORD *statusArray, WORD *categoryArray)
 { 

 Z_Identify(componentArray, nComp, statusArray, categoryArray); 
} 

/* Implementation of the javah generated prototype */ 
JNIEXPORT void JNICALL 
Java_JZISC_JZ_1Identify(JNIEnv *env, jobject obj, jbyteArray componentArray, jint nComp,
 jintArray statusArray, jintArray categoryArray) { 
  // Get all component array elements 
 jbyte *component_array = 
  (*env)->GetByteArrayElements(env, componentArray, NULL); 

 // Get components from status array 
 jint *status_array = 
  (*env)->GetIntArrayElements(env, statusArray, NULL); 

 // Get components from category array 
 jint *category_array = 
  (*env)->GetIntArrayElements(env, categoryArray, NULL); 

  // Call local wrapper for ZISC method 
 J_Z_Identify((BYTE *)component_array, (WORD)nComp, (WORD *)status_array, (WORD   *)category_array); 

  // Release work buffer for component array 
 (*env)->ReleaseByteArrayElements(env, componentArray, component_array, 0); 

  // Update status array with new value 
 (*env)->SetIntArrayRegion(env, statusArray, 0, 1, status_array); 

  // Release work buffer for status array 
 (*env)->ReleaseIntArrayElements(env, statusArray, status_array, 0); 

  // Update category array with new value 
 (*env)->SetIntArrayRegion(env, categoryArray, 0, 1, category_array); 

  // Release work buffer for category array 
 (*env)->ReleaseIntArrayElements(env, categoryArray, category_array, 0); 
} 

Listing 2: Extract information from ANN hardware.
 
******************************************************* 
        // Create instance of JFC dialog 
  NeuralNet panel = new NeuralNet(); 

        // Create instance of Native class 
  JZISC ziscCARD = new JZISC(); 

        // Initialize ANN card 
  int initialized = (int)ziscCARD.JZ_Init(0); 

  if (1 == initialized) 
   System.out.println("cannot open ZISC device (type any key to exit)\n"); 

        // Query number of neurons in PCI board 
  int numberOfNeurons = ziscCARD.JZ_GetMaxNeurons(); 

       System.out.println("The ZISC has " + numberOfNeurons + "neurons\n"); 

        // Get ANN version and type 
  ziscCARD.info= ziscCARD.JZ_GetCardInfo(0); 

  System.out.println("ZISC Info " + ziscCARD.info + "\n"); 
******************************************************* 

Listing 3: ANN learning procedure.
 
******************************************************* 
  /********************** learning *******************************/ 
  /* Symbol 0 is represented by 1 and symbol 1 is represented by a 5 

  /********* input a new set of 2 components (0 0) ***/ 
  ziscCARD.array[0]= (byte)1; 
  ziscCARD.array[1]= (byte)1; 
  System.out.println("Vector (0 0) \n"); 
  ziscCARD.JZ_PutVector(ziscCARD.array, 2);    /* input components */ 
  ziscCARD.JZ_PutCat(1);              /* learn category 0 */ 

  /********* input a new set of 2 components (0 1) ***/ 
  ziscCARD.array[0]= (byte)1; 
  ziscCARD.array[1]= (byte)5; 
  System.out.println("Vector (0 1) \n"); 
  ziscCARD.JZ_PutVector(ziscCARD.array, 2);    /* input components */ 
  ziscCARD.JZ_PutCat(5);              /* learn category 1 */ 

  /********* input a new set of 2 components (1 0) ***/ 
  ziscCARD.array[0]= (byte)5; 
  ziscCARD.array[1]= (byte)1; 
  System.out.println("Vector (1 0) \n"); 
  ziscCARD.JZ_PutVector(ziscCARD.array, 2);    /* input components */ 
  ziscCARD.JZ_PutCat(5);              /* learn category 1 */ 

  /********* input a new set of 2 components (1 1) ***/ 
  ziscCARD.array[0]= (byte)5; 
  ziscCARD.array[1]= (byte)5; 
  System.out.println("Vector (1 1) \n"); 
  ziscCARD.JZ_PutVector(ziscCARD.array, 2);    /* input components */ 
  ziscCARD.JZ_PutCat(1);              /* learn category 0 */ 

Listing 4: Sample output.
 
 ******************************************************* 
Recognize pair (0 1) 

Status content after input vector 

error flag= 0 
deg= 0 
unc= 0 
full= 0 
id= 1 
Sequence of read dist read cat 

======================================== 
CORRECT: dist = 0 Out= 1 

******************************************************* 


 

All Rights Reserved
Copyright ©  2004 SYS-CON Media, Inc.
  E-mail: [email protected]

Java and Java-based marks are trademarks or registered trademarks of Sun Microsystems, Inc. in the United States and other countries. SYS-CON Publications, Inc. is independent of Sun Microsystems, Inc.