/** * Adds the statistics encapsulated in the supplied Evaluation object into this one. Does not * perform any checks for compatibility between the supplied Evaluation object and this one. * * @param evaluation the evaluation object to aggregate */ public void aggregate(Evaluation evaluation) { m_Incorrect += evaluation.incorrect(); m_Correct += evaluation.correct(); m_Unclassified += evaluation.unclassified(); m_MissingClass += evaluation.m_MissingClass; m_WithClass += evaluation.m_WithClass; if (evaluation.m_ConfusionMatrix != null) { double[][] newMatrix = evaluation.confusionMatrix(); if (newMatrix != null) { for (int i = 0; i < m_ConfusionMatrix.length; i++) { for (int j = 0; j < m_ConfusionMatrix[i].length; j++) { m_ConfusionMatrix[i][j] += newMatrix[i][j]; } } } } double[] newClassPriors = evaluation.m_ClassPriors; if (newClassPriors != null) { for (int i = 0; i < this.m_ClassPriors.length; i++) { m_ClassPriors[i] = newClassPriors[i]; } } m_ClassPriorsSum = evaluation.m_ClassPriorsSum; m_TotalCost += evaluation.totalCost(); m_SumErr += evaluation.m_SumErr; m_SumAbsErr += evaluation.m_SumAbsErr; m_SumSqrErr += evaluation.m_SumSqrErr; m_SumClass += evaluation.m_SumClass; m_SumSqrClass += evaluation.m_SumSqrClass; m_SumPredicted += evaluation.m_SumPredicted; m_SumSqrPredicted += evaluation.m_SumSqrPredicted; m_SumClassPredicted += evaluation.m_SumClassPredicted; m_SumPriorAbsErr += evaluation.m_SumPriorAbsErr; m_SumPriorSqrErr += evaluation.m_SumPriorSqrErr; m_SumKBInfo += evaluation.m_SumKBInfo; double[] newMarginCounts = evaluation.m_MarginCounts; if (newMarginCounts != null) { for (int i = 0; i < m_MarginCounts.length; i++) { m_MarginCounts[i] += newMarginCounts[i]; } } m_SumPriorEntropy += evaluation.m_SumPriorEntropy; m_SumSchemeEntropy += evaluation.m_SumSchemeEntropy; m_TotalSizeOfRegions += evaluation.m_TotalSizeOfRegions; m_TotalCoverage += evaluation.m_TotalCoverage; FastVector predsToAdd = evaluation.m_Predictions; if (predsToAdd != null) { if (m_Predictions == null) { m_Predictions = new FastVector(); } for (int i = 0; i < predsToAdd.size(); i++) { m_Predictions.addElement(predsToAdd.elementAt(i)); } } }
public MOVE getMove(EnumMap<GHOST, MOVE> ghostMoves, Tree tree) { long start = System.currentTimeMillis(); LinkedList<Node> nodes = new LinkedList<Node>(); nodes.add(tree.getHeadNode()); int leftValue = Integer.MIN_VALUE; int rightValue = Integer.MIN_VALUE; int upValue = Integer.MIN_VALUE; int downValue = Integer.MIN_VALUE; while (!nodes.isEmpty()) { Node node = nodes.removeFirst(); node.setVisited(true); if (node.getPredecessor() != null) { // regular Node // set gameState and advance move based on current node Game gameState = node.getPredecessor().getGameState().copy(); gameState.advanceGame(node.getMove(), ghostMoves); node.setGameState(gameState); } if (node.getNeighbors() == null) { // end of tree branch int value = Evaluation.evaluateGameState(node.getGameState()); // get head node move type Node nodeType = node.getPredecessor(); while (nodeType.getPredecessor().getMove() != MOVE.NEUTRAL) { nodeType = nodeType.getPredecessor(); } switch (nodeType.getMove()) { case LEFT: if (value > leftValue) leftValue = value; break; case RIGHT: if (value > rightValue) rightValue = value; break; case UP: if (value > upValue) upValue = value; break; case DOWN: if (value > downValue) downValue = value; break; case NEUTRAL: break; } } else { // regular node // add neighbors to be searched ArrayList<Node> neighbors = node.getNeighbors(); for (Node neighbor : neighbors) { if (!neighbor.isVisited()) nodes.add(neighbor); } } } if (Evaluation.LOG_TIME) System.out.println(System.currentTimeMillis() - start); return Evaluation.getBestMove(leftValue, rightValue, upValue, downValue); }
private void jButton1ActionPerformed( java.awt.event.ActionEvent evt) { // GEN-FIRST:event_jButton1ActionPerformed Evaluation obj = new Evaluation(); String input = jTextField1.getText(); float ans = obj.calculate(input); String ans1 = "" + ans; if (ans == 34097) { jLabel2.setText("Invalid Expression "); jLabel2.show(); } else { jLabel2.setText(ans1); jLabel2.show(); } } // GEN-LAST:event_jButton1ActionPerformed
@Override public void onBindViewHolder(ViewHolder holder, int position) { final Evaluation evaluation = mEvaluations.get(position); // TODO: make text thinner/lighter/sharper, like Gmail Context context = holder.mAvatarImageView.getContext(); holder.mAvatarImageView.setImageDrawable(generateAvatar(context, evaluation.getSpeakerName())); // TODO: actually use rows // final String scoreString = // NumberFormat.getPercentInstance().format(evaluation.getScore()); // holder.mScoreTextView.setText(scoreString); }
/** @param args */ public static void main(String[] args) { // TODO Auto-generated method stub /*Trainer1 tra = new Trainer1("weka.classifiers.bayes.NaiveBayes"); tra.bootstrap(); tra.training();*/ Evaluation.runTrainer(args); /*String classifier_Name = args[0]; //args[0]为分类器类名; String unlabeledIns_File = args[1]; // args[1]未标记的大样本集文件名; String labeledIns_File = args[2]; // args[2]标记的小样本集文件名; String testIns_File = args[3]; //arg[3]测试样本集文件名 Tri_trainer tra = new Tri_trainer(classifier_Name,unlabeledIns_File,labeledIns_File,testIns_File); tra.bootstrap(); tra.training(); /*try { Classifier classifier1 = (Classifier)Class.forName("weka.classifiers.trees.J48").newInstance(); Classifier classifier2 = new J48(); Classifier classifier4 = classifier2; Classifier classifier3 = (Classifier)Class.forName("weka.classifiers.trees.J48").newInstance(); //if(classifier1 == null) System.out.println("classifier1 =" + classifier1.hashCode()); System.out.println("classifier2 =" + classifier2.hashCode()); System.out.println("classifier3 =" + classifier3.hashCode()); System.out.println("classifier4 =" + classifier4.hashCode()); } catch(Exception e) { }*/ }
/** * Main method for testing this class. * * @param argv the options */ public static void main(String[] argv) { try { System.out.println(Evaluation.evaluateModel(new Decorate(), argv)); } catch (Exception e) { System.err.println(e.getMessage()); } }
/** * Main method for testing this class * * @param argv options */ public static void main(String[] argv) { try { System.out.println(Evaluation.evaluateModel(new UnivariateLinearRegression(), argv)); } catch (Exception e) { System.out.println(e.getMessage()); e.printStackTrace(); } }
/** * runs the classifier instance with the given options. * * @param classifier the classifier to run * @param options the commandline options */ public static void runClassifier(Classifier classifier, String[] options) { try { System.out.println(Evaluation.evaluateModel(classifier, options)); } catch (Exception e) { if (((e.getMessage() != null) && (e.getMessage().indexOf("General options") == -1)) || (e.getMessage() == null)) { e.printStackTrace(); } else { System.err.println(e.getMessage()); } } }
private void processExamples(String group, List<Example> examples) { Evaluation evaluation = new Evaluation(); if (examples.isEmpty()) return; final String prefix = "iter=0." + group; Execution.putOutput("group", group); LogInfo.begin_track_printAll("Processing %s: %s examples", prefix, examples.size()); LogInfo.begin_track("Dumping metadata"); dumpMetadata(group, examples); LogInfo.end_track(); LogInfo.begin_track("Examples"); for (int e = 0; e < examples.size(); e++) { Example ex = examples.get(e); LogInfo.begin_track_printAll("%s: example %s/%s: %s", prefix, e, examples.size(), ex.id); ex.log(); Execution.putOutput("example", e); StopWatchSet.begin("Parser.parse"); ParserState state = builder.parser.parse(params, ex, false); StopWatchSet.end(); out.printf("########## Example %s ##########\n", ex.id); dumpExample(exampleToLispTree(state)); LogInfo.logs("Current: %s", ex.evaluation.summary()); evaluation.add(ex.evaluation); LogInfo.logs("Cumulative(%s): %s", prefix, evaluation.summary()); LogInfo.end_track(); ex.predDerivations.clear(); // To save memory } LogInfo.end_track(); LogInfo.logs("Stats for %s: %s", prefix, evaluation.summary()); evaluation.logStats(prefix); evaluation.putOutput(prefix); LogInfo.end_track(); }
public static int minmaxJumping(Board board, Color computer, Color player, int deepth) { if (deepth > 0) { int result; Position nextMoveFrom = null; Position nextMoveTo = null; Position nextTake = null; if (computer == BLACK) { result = Integer.MIN_VALUE; } else { result = Integer.MAX_VALUE; } for (Position turnFrom : Position.getAllPositions()) { if (board.getColor(turnFrom) == computer) { // Every brick with the Color is removed board.setColor(turnFrom, NONE); for (Position turnTo : Position.getAllPositions()) { if (turnTo != turnFrom && board.getColor(turnTo) == NONE) { board.setColor(turnTo, computer); // On every possible position, a brick is laid. if (board.isMill(turnTo, computer)) { // If with this position "turnTo" is a mill for (Position takeAway : Position.getAllPositions()) { if (board.getColor(takeAway) == player && !board.isMill(takeAway, player)) { board.setColor(takeAway, NONE); // any opposing stone is taken away int value = minmaxJumping( board, // other player has its turn player, computer, (deepth - 1)); if (computer == BLACK) { if (result < value) { result = value; nextMoveFrom = turnFrom; nextMoveTo = turnTo; nextTake = takeAway; } } if (computer == WHITE) { if (result > value) { result = value; nextMoveFrom = turnFrom; nextMoveTo = turnTo; nextTake = takeAway; } } board.setColor(takeAway, player); } } } else { // no new mill with this move // other player has its turn int value = minmaxJumping(board, player, computer, (deepth - 1)); // Depending on what color is in the series, the minimum or the maximum is stored. if (computer == BLACK) { if (result < value) { result = value; nextMoveFrom = turnFrom; nextMoveTo = turnTo; nextTake = null; } } if (computer == WHITE) { if (result > value) { result = value; nextMoveFrom = turnFrom; nextMoveTo = turnTo; nextTake = null; } } } board.setColor(turnTo, NONE); } } board.setColor(turnFrom, computer); } } // The best turn is stored Play.nextTurnFrom = nextMoveFrom; Play.nextTurnTo = nextMoveTo; Play.nextTake = nextTake; return result; } else { // If the depth is reached, the current field rated return Evaluation.evaluation(board); } }
public boolean same(Evaluation evaluation) { return this.getCorrectColorInCorrectPosition() == evaluation.getCorrectColorInCorrectPosition() && this.getCorrectColorInWrongPosition() == evaluation.getCorrectColorInWrongPosition(); }
public static Evaluation eval(InferState state) { // Print out information about how well we're doing. Evaluation evaluation = new Evaluation(); Candidate trueCandidate = state.getTrueCandidate(); Candidate predCandidate = state.getCandidates().get(0); PredictionContext context = state.getContext(); NgramContext ngramContext = NgramContext.get(context); Statistics statistics = state.getStatistics(); Corpus corpus = statistics.getProjectLangCorpus(context.getPath()); DataSummary summary = statistics.getStatistic(NgramKNCounts.class, corpus).getSummary(); Params params = state.getParams(); boolean oracle = state.isOracle(); int rank = state.getRank(); double entropy = state.getEntropy(); double reciprocalRank = state.getReciprocalRank(); boolean isIdent = state.isIdent(); boolean correct = state.isCorrect(); String path = context.getPath(); String trueTokenStr = trueCandidate.token; String predToken = predCandidate.token; evaluation.add("accuracy", correct); evaluation.add("oracle", oracle); evaluation.add("rank", rank); evaluation.add("reciprocalRank", reciprocalRank); if (oracle) { evaluation.add("entropy", entropy); } if (isIdent) { evaluation.add("identAccuracy", correct); evaluation.add("identOracle", oracle); if (oracle) { evaluation.add("identEntropy", entropy); evaluation.add("identReciprocalRank", reciprocalRank); for (int i = 0; i < Main.clusters; i++) { evaluation.add("identEntropy" + i, -Math.log(trueCandidate.clusterProbs[i])); } } } String contextStr = ngramContext.contextStr(); if (Main.verbose >= 2) { String entropyStr = oracle ? Fmt.D(entropy) : "N/A"; begin_track( "Example %s [%s]: %s (%d candidates, rank %s, entropy %s)", path, correct ? "CORRECT" : "WRONG", contextStr, state.getCandidates().size(), rank, entropyStr); logs("True (prob= %s): [%s]", Fmt.D(trueCandidate.prob), trueTokenStr); logs("Pred (prob= %s): [%s]", Fmt.D(predCandidate.prob), predToken); if (oracle) { KneserNey.logKNIs(true); KneserNey.computeProb(CandidateNgram.get(context, trueCandidate), summary); KneserNey.logKNIs(false); } // begin_track("True"); FeatureVector.logFeatureWeights("True", trueCandidate.features.toMap(), params); // for (int i = 0; i < Main.clusters; i++) { // logs("cluster=%d, score %s, prob %s", i, Fmt.D(trueCandidate.clusterScores[i]), // Fmt.D(trueCandidate.clusterProbs[i])); // FeatureVector.logFeatureWeights("cluster=" + i, // trueCandidate.clusterFeatures.toMap(), // params, Main.clusterDecorators[i]); // } // end_track(); KneserNey.logKNIs(true); KneserNey.computeProb(CandidateNgram.get(context, predCandidate), summary); KneserNey.logKNIs(false); FeatureVector.logFeatureWeights("Pred", predCandidate.features.toMap(), params); // for (Candidate candidate : candidates) { // begin_track("Candidate " + candidate.token); // for (int i = 0; i < Main.clusters; i++) { // logs("cluster=%d, score %s, prob %s", i, Fmt.D(candidate.clusterScores[i]), // Fmt.D(candidate.clusterProbs[i])); // FeatureVector.logFeatureWeights("cluster=" + i, // candidate.clusterFeatures.toMap(), // params, Main.clusterDecorators[i]); // } // end_track(); // } FeatureVector.logFeatureDiff( "True - Pred", trueCandidate.features, predCandidate.features, params); end_track(); } // Longest context that has been seen int context_max_n = ngramContext.getMax_n() - 1; while (context_max_n > 0 && !summary.counts[context_max_n].containsKey(ngramContext.subContext(context_max_n + 1))) context_max_n--; evaluation.add("context_max_n", context_max_n); predOut.println( "path=" + path + "\tident=" + (isIdent ? 1 : 0) + "\tcontext=" + contextStr + "\tcontext_max_n=" + context_max_n + "\ttrue=" + trueTokenStr + "\tpred=" + predToken + "\trank=" + rank + "\tentropy=" + entropy); predOut.flush(); entOut.println( path + "\t" + state.getTrueToken().loc() + "\t" + (isIdent ? 1 : 0) + "\t" + (oracle ? entropy : (state.isOov() ? "oov" : "offBeam")) + "\t" + reciprocalRank); entOut.flush(); return evaluation; }
public double[][] solveThreeStage(String method) // Method: Enter CCR, BCC, SBM { DEA stageOne = new DEA(dmu, input, interOne); double[][] solutionOne = null; try { if (method.equals("CCR") == true && settings[0][0] == true) // Input-Orientation solutionOne = stageOne.solve_Dual_Basic_Input(false); // Solve stage one else if (method.equals("CCR") == true && settings[0][0] == false) // Output-Orientation solutionOne = stageOne.solve_Dual_Basic_Output(false); // Solve stage one else if (method.equals("BCC") == true && settings[0][0] == true) // Input-Orientation solutionOne = stageOne.solve_Dual_Basic_Input(true); // Solve stage one else if (method.equals("BCC") == true && settings[0][0] == false) // Output-Orientation solutionOne = stageOne.solve_Dual_Basic_Output(true); // Solve stage one else if (method.equals("SBM") == true && settings[0][0] == true) // Input-Orientation solutionOne = stageOne.solve_Dual_SBM_Input(); // Solve stage one else if (method.equals("SBM") == true && settings[0][0] == false) // Output-Orientation solutionOne = stageOne.solve_Dual_SBM_Output(); // Solve stage one /*else throw new Exception("Falsche Methodik");*/ solList.add(solutionOne); } catch (IloException ex) { Logger.getLogger(ThreeStageDEA.class.getName()).log(Level.SEVERE, null, ex); } // Calculate Stage 2 DEA stageTwo = null; double[][] effOneFitted = null; if (settings[1][1] == true) // Efficiency of stage 1 is input of stage 2 { double[] effOne = Evaluation.getEfficiency(solutionOne); effOneFitted = fitEfficiency(effOne); stageTwo = new DEA(dmu, effOneFitted, interTwo); } else { if (settings[2][1] == false) // Input is no combination of efficiency and intermediary product { stageTwo = new DEA(dmu, interOne, interTwo); } else { double[][] combInter = combineEffInter(Evaluation.getEfficiency(solutionOne)); stageTwo = new DEA(dmu, combInter, interTwo); } } double[][] solutionTwo = null; try { if (method.equals("CCR") == true && settings[0][1] == true) // Input-Orientation solutionTwo = stageTwo.solve_Dual_Basic_Input(false); // Solve stage two else if (method.equals("CCR") == true && settings[0][1] == false) // Output-Orientation solutionTwo = stageTwo.solve_Dual_Basic_Output(false); // Solve stage two else if (method.equals("BCC") == true && settings[0][1] == true) // Input-Orientation solutionTwo = stageTwo.solve_Dual_Basic_Input(true); // Solve stage two else if (method.equals("BCC") == true && settings[0][1] == false) // Output-Orientation solutionTwo = stageTwo.solve_Dual_Basic_Output(true); // Solve stage two else if (method.equals("SBM") == true && settings[0][1] == true) // Input-Orientation solutionTwo = stageTwo.solve_Dual_SBM_Input(); // Solve stage two else if (method.equals("SBM") == true && settings[0][1] == false) // Output-Orientation solutionTwo = stageTwo.solve_Dual_SBM_Output(); // Solve stage two /*else throw new Exception("Falsche Methodik");*/ solList.add(solutionTwo); } catch (IloException ex) { Logger.getLogger(ThreeStageDEA.class.getName()).log(Level.SEVERE, null, ex); } double[][] solutionOneTwo = createSolution( solutionOne, solutionTwo); // Create a single solution array containing weights and efficiencies. // Calculate Stage 3 DEA stageThree = null; double[][] effTwoFitted = null; if (settings[1][2] == true) // Efficiency of stage 1 is input of stage 2 { double[] effTwo = Evaluation.getEfficiency(solutionTwo); effTwoFitted = fitEfficiency(effTwo); stageThree = new DEA(dmu, effTwoFitted, output); } else { if (settings[2][2] == false) // Input is no combination of efficiency and intermediary product { stageThree = new DEA(dmu, interTwo, output); } else { double[][] combInterTwo = combineEffInter(Evaluation.getEfficiency(solutionTwo)); stageThree = new DEA(dmu, combInterTwo, output); } } double[][] solutionThree = null; try { if (method.equals("CCR") == true && settings[0][2] == true) // Input-Orientation solutionThree = stageThree.solve_Dual_Basic_Input(false); // Solve stage three else if (method.equals("CCR") == true && settings[0][2] == false) // Output-Orientation solutionThree = stageThree.solve_Dual_Basic_Output(false); // Solve stage three else if (method.equals("BCC") == true && settings[0][2] == true) // Input-Orientation solutionThree = stageThree.solve_Dual_Basic_Input(true); // Solve stage three else if (method.equals("BCC") == true && settings[0][2] == false) // Output-Orientation solutionThree = stageThree.solve_Dual_Basic_Output(true); // Solve stage three else if (method.equals("SBM") == true && settings[0][2] == true) // Input-Orientation solutionThree = stageThree.solve_Dual_SBM_Input(); // Solve stage two else if (method.equals("SBM") == true && settings[0][2] == false) // Output-Orientation solutionThree = stageThree.solve_Dual_SBM_Output(); // Solve stage two /*else throw new Exception("Falsche Methodik");*/ solList.add(solutionThree); } catch (IloException ex) { Logger.getLogger(ThreeStageDEA.class.getName()).log(Level.SEVERE, null, ex); } double[][] solutionComplete = createSolution( solutionOneTwo, solutionThree); // Create a single solution array containing weights and efficiencies. return solutionComplete; }
public Evaluation unmarshall(JsonUnmarshallerContext context) throws Exception { Evaluation evaluation = new Evaluation(); int originalDepth = context.getCurrentDepth(); String currentParentElement = context.getCurrentParentElement(); int targetDepth = originalDepth + 1; JsonToken token = context.getCurrentToken(); if (token == null) token = context.nextToken(); if (token == VALUE_NULL) return null; while (true) { if (token == null) break; if (token == FIELD_NAME || token == START_OBJECT) { if (context.testExpression("EvaluationId", targetDepth)) { context.nextToken(); evaluation.setEvaluationId(context.getUnmarshaller(String.class).unmarshall(context)); } if (context.testExpression("MLModelId", targetDepth)) { context.nextToken(); evaluation.setMLModelId(context.getUnmarshaller(String.class).unmarshall(context)); } if (context.testExpression("EvaluationDataSourceId", targetDepth)) { context.nextToken(); evaluation.setEvaluationDataSourceId( context.getUnmarshaller(String.class).unmarshall(context)); } if (context.testExpression("InputDataLocationS3", targetDepth)) { context.nextToken(); evaluation.setInputDataLocationS3( context.getUnmarshaller(String.class).unmarshall(context)); } if (context.testExpression("CreatedByIamUser", targetDepth)) { context.nextToken(); evaluation.setCreatedByIamUser(context.getUnmarshaller(String.class).unmarshall(context)); } if (context.testExpression("CreatedAt", targetDepth)) { context.nextToken(); evaluation.setCreatedAt( context.getUnmarshaller(java.util.Date.class).unmarshall(context)); } if (context.testExpression("LastUpdatedAt", targetDepth)) { context.nextToken(); evaluation.setLastUpdatedAt( context.getUnmarshaller(java.util.Date.class).unmarshall(context)); } if (context.testExpression("Name", targetDepth)) { context.nextToken(); evaluation.setName(context.getUnmarshaller(String.class).unmarshall(context)); } if (context.testExpression("Status", targetDepth)) { context.nextToken(); evaluation.setStatus(context.getUnmarshaller(String.class).unmarshall(context)); } if (context.testExpression("PerformanceMetrics", targetDepth)) { context.nextToken(); evaluation.setPerformanceMetrics( PerformanceMetricsJsonUnmarshaller.getInstance().unmarshall(context)); } if (context.testExpression("Message", targetDepth)) { context.nextToken(); evaluation.setMessage(context.getUnmarshaller(String.class).unmarshall(context)); } if (context.testExpression("ComputeTime", targetDepth)) { context.nextToken(); evaluation.setComputeTime(context.getUnmarshaller(Long.class).unmarshall(context)); } if (context.testExpression("FinishedAt", targetDepth)) { context.nextToken(); evaluation.setFinishedAt( context.getUnmarshaller(java.util.Date.class).unmarshall(context)); } if (context.testExpression("StartedAt", targetDepth)) { context.nextToken(); evaluation.setStartedAt( context.getUnmarshaller(java.util.Date.class).unmarshall(context)); } } else if (token == END_ARRAY || token == END_OBJECT) { if (context.getLastParsedParentElement() == null || context.getLastParsedParentElement().equals(currentParentElement)) { if (context.getCurrentDepth() <= originalDepth) break; } } token = context.nextToken(); } return evaluation; }