Exemple #1
0
        public List <string> Classify(string model, string test)
        {
            List <string> ret = new List <string>();

            try
            {
                java.io.ObjectInputStream   ois = new java.io.ObjectInputStream(new java.io.FileInputStream(model));
                weka.classifiers.Classifier cl  = (weka.classifiers.Classifier)ois.readObject();
                ois.close();

                weka.core.Instances insts = new weka.core.Instances(new java.io.FileReader(test));
                insts.setClassIndex(insts.numAttributes() - 1);
                for (int i = 0; i < 1; i++)
                {
                    weka.core.Instance currentInst    = insts.instance(i);
                    double             predictedClass = cl.classifyInstance(currentInst);
                    double[]           distrs         = cl.distributionForInstance(currentInst);
                    //string actual = insts.classAttribute().value((int)currentInst.classValue());
                    //string predicted = insts.classAttribute().value((int)predictedClass);
                    // System.Console.WriteLine("ID: " + (i + 1) + ", " + predicted);
                    for (int j = 0; j < distrs.Length; j++)
                    {
                        string predicted = insts.classAttribute().value(j);
                        string distr     = distrs[j].ToString("#0.000");
                        ret.Add(predicted + "," + distr);
                    }
                }
                return(ret);
            }
            catch
            {
                return(ret);
            }
        }
Exemple #2
0
        public void Test2()
        {
            java.io.ObjectInputStream   ois = new java.io.ObjectInputStream(new java.io.FileInputStream("D:\\android_analysis\\som_model.model"));
            weka.classifiers.Classifier cl  = (weka.classifiers.Classifier)ois.readObject();
            ois.close();

            weka.core.Instances insts = new weka.core.Instances(new java.io.FileReader("D:\\android_analysis\\test1.arff"));
            insts.setClassIndex(insts.numAttributes() - 1);
            for (int i = 0; i < insts.numInstances(); i++)
            {
                weka.core.Instance currentInst    = insts.instance(i);
                double             predictedClass = cl.classifyInstance(currentInst);
                double[]           distrs         = cl.distributionForInstance(currentInst);
                //string actual = insts.classAttribute().value((int)currentInst.classValue());
                //string predicted = insts.classAttribute().value((int)predictedClass);
                // System.Console.WriteLine("ID: " + (i + 1) + ", " + predicted);
            }
        }
Exemple #3
0
        protected object GetStateFromClient(FacesContext facesContext, String viewId, String renderKitId)
        {
            //RenderKit renderKit = RenderKitFactory.getRenderKit (facesContext, renderKitId);
            //ResponseStateManager responseStateManager = renderKit.getResponseStateManager ();
            //responseStateManager.getTreeStructureToRestore (facesContext, viewId); //ignore result. Must call for compatibility with sun implementation.
            //return responseStateManager.getComponentStateToRestore (facesContext);

            java.util.Map map = facesContext.getExternalContext().getRequestParameterMap();
            string        s1  = (string)map.get(VIEWSTATE);

            byte [] buffer = Convert.FromBase64String(s1);
            java.io.ByteArrayInputStream bytearrayinputstream = new java.io.ByteArrayInputStream(vmw.common.TypeUtils.ToSByteArray(buffer));
            java.io.ObjectInputStream    inputStream          = new java.io.ObjectInputStream(bytearrayinputstream);
            //ignore tree structure
            //inputStream.readObject ();
            object state = inputStream.readObject();

            inputStream.close();
            bytearrayinputstream.close();

            return(state);
        }
		protected object GetStateFromClient (FacesContext facesContext, String viewId, String renderKitId) {
			//RenderKit renderKit = RenderKitFactory.getRenderKit (facesContext, renderKitId);
			//ResponseStateManager responseStateManager = renderKit.getResponseStateManager ();
			//responseStateManager.getTreeStructureToRestore (facesContext, viewId); //ignore result. Must call for compatibility with sun implementation.
			//return responseStateManager.getComponentStateToRestore (facesContext);

			java.util.Map map = facesContext.getExternalContext ().getRequestParameterMap ();
			string s1 = (string) map.get (VIEWSTATE);

			byte [] buffer = Convert.FromBase64String (s1);
			java.io.ByteArrayInputStream bytearrayinputstream = new java.io.ByteArrayInputStream (vmw.common.TypeUtils.ToSByteArray (buffer));
			java.io.ObjectInputStream inputStream = new java.io.ObjectInputStream (bytearrayinputstream);
			//ignore tree structure
			//inputStream.readObject ();
			object state = inputStream.readObject ();
			inputStream.close ();
			bytearrayinputstream.close ();

			return state;
		}