public static void sendMail(String mailMessage) { String to = "*****@*****.**"; String from = "FlotaWeb"; String host = "mail.arabesque.ro"; Properties properties = System.getProperties(); properties.setProperty("mail.smtp.host", host); Session session = Session.getDefaultInstance(properties); try { MimeMessage message = new MimeMessage(session); message.setFrom(new InternetAddress(from)); message.addRecipient(Message.RecipientType.TO, new InternetAddress(to)); message.setSubject("Distributie"); message.setText(mailMessage); Transport.send(message); } catch (MessagingException e) { logger.error(Utils.getStackTrace(e)); } }
public void addProductFromCategory() { SelectSportProduct.click(); Utils.sleep(1); AddToBasket.click(); Utils.sleep(1); }
public void printTopWords(int k, String betaFile) { Arrays.fill(m_parentSstat, 0); Arrays.fill(m_childSstat, 0); System.out.println("print top words"); for (_Doc d : m_trainSet) { if (d instanceof _ParentDoc2) { // print out topic assignment of parent printParentTopicAssignment((_ParentDoc2) d); for (int i = 0; i < number_of_topics; i++) m_parentSstat[i] += m_logSpace ? Math.exp(d.m_topics[i]) : d.m_topics[i]; } else if (d instanceof _ChildDoc2) { // print out topic assignment of child printChildTopicAssignment((_ChildDoc2) d); for (int i = 0; i < number_of_topics; i++) m_childSstat[i] += m_logSpace ? Math.exp(d.m_topics[i]) : d.m_topics[i]; } } Utils.L1Normalization(m_parentSstat); Utils.L1Normalization(m_childSstat); String parentBetaFile = betaFile.replace(".txt", "parent.txt"); String childBetaFile = betaFile.replace(".txt", "child.txt"); printParentTopWords(k, parentBetaFile); printChildTopWords(k, childBetaFile); String parentParameterFile = parentBetaFile.replace("beta", "parameter"); String childParameterFile = childBetaFile.replace("beta", "parameter"); printParameter(parentParameterFile, childParameterFile); }
protected int gradientUpdate(_Query query) { double diff; int i, trainSize = 0; // Step 1: calculate the ranking score for (_QUPair pair : query.m_docList) pair.score(m_weight); m_eval.eval(query); // Step 2: accumulate the lambdas for each URL for (_QUPair pair : query.m_docList) { diff = 0; if (pair.m_worseURLs != null) { for (_QUPair worseURL : pair.m_worseURLs) { // force to moving up diff += Utils.logistic(worseURL.m_score - pair.m_score) * m_eval.delta(pair, worseURL); trainSize++; } } if (pair.m_betterURLs != null) { for (_QUPair betterURL : pair.m_betterURLs) { // force to moving down diff -= Utils.logistic(pair.m_score - betterURL.m_score) * m_eval.delta(betterURL, pair); trainSize++; } } // Step 3: update weight according to this URL if (diff != 0) { for (i = 0; i < pair.m_rankFv.length; i++) m_g[i] -= diff * pair.m_rankFv[i]; } } return trainSize; }
protected void evaluate() { double r; m_obj = 0; m_perf = 0; m_misorder = 0; for (_Query query : m_queries) { // calculate ranking score with latest weight for (_QUPair pair : query.m_docList) pair.score(m_weight); if ((r = m_eval.eval(query)) >= 0) // ranking score should already be calculated m_perf += r; for (_QUPair pair : query.m_docList) { if (pair.m_worseURLs != null) { for (_QUPair worseURL : pair.m_worseURLs) { if ((r = Utils.logistic(pair.m_score - worseURL.m_score)) > 0) m_obj += Math.log(r); if (pair.m_score <= worseURL.m_score) m_misorder++; } } if (pair.m_betterURLs != null) { for (_QUPair betterURL : pair.m_betterURLs) { if ((r = Utils.logistic(betterURL.m_score - pair.m_score)) > 0) m_obj += Math.log(r); if (pair.m_score >= betterURL.m_score) m_misorder++; } } } } m_misorder /= 2; }
/** * Processes requests for both HTTP <code>GET</code> and <code>POST</code> methods. * * @param request servlet request * @param response servlet response * @throws ServletException if a servlet-specific error occurs * @throws IOException if an I/O error occurs */ protected void processRequest(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException { response.setContentType("text/html;charset=UTF-8"); try (PrintWriter out = response.getWriter()) { EmployeeWrapper emp = (EmployeeWrapper) request.getSession().getAttribute("emp"); String deleteButtonFormatingClass = request.getParameter("deleteButtonFormatingClass"); String deleteButtonMethod = request.getParameter("deleteButtonMethod"); String identifier = request.getParameter("identifier"); try { switch (identifier) { case "p": out.print( utils.Utils.loadContacts( emp.getGarage().getGarageId(), deleteButtonFormatingClass, deleteButtonMethod)); break; case "f": out.print( utils.Utils.loadFaxList( emp.getGarage().getGarageId(), deleteButtonFormatingClass, deleteButtonMethod)); break; case "e": out.print( utils.Utils.loadEmailList( emp.getGarage().getGarageId(), deleteButtonFormatingClass, deleteButtonMethod)); break; } } catch (Exception ex) { ex.printStackTrace(); out.print(ex.getMessage()); } } }
private void runServer() { String logFile = properties.getProperty("logFile"); Utils.setLogFile(logFile, Server.class.getName()); int port = Integer.parseInt(properties.getProperty("port")); String ip = properties.getProperty("serverIp"); Logger.getLogger(Server.class.getName()) .log(Level.INFO, "Server started. Listening on: " + port + ", bound to: " + ip); try { serverSocket = new ServerSocket(); serverSocket.bind(new InetSocketAddress(ip, port)); do { Socket socket = serverSocket.accept(); // Important Blocking call Logger.getLogger(Server.class.getName()).log(Level.INFO, "Connected to a client"); ClientHandler tmpClient = new ClientHandler(socket, this); clients.add(tmpClient); tmpClient.start(); } while (keepRunning); } catch (IOException ex) { Logger.getLogger(Server.class.getName()).log(Level.SEVERE, null, ex); } finally { Utils.closeLogger(Server.class.getName()); } }
/** * Processes requests for both HTTP <code>GET</code> and <code>POST</code> methods. * * @param request servlet request * @param response servlet response * @throws ServletException if a servlet-specific error occurs * @throws IOException if an I/O error occurs */ protected void processRequest(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException { HttpSession session = request.getSession(); Connection conn = Utils.getStoredConnection(session); Utilisateur loginedUser = Utils.getLoginedUser(session); int IDP = Integer.parseInt(request.getParameter("IDP")); Photo photo = DBUtils.GetInfoPhoto(conn, IDP); String errorString = (String) session.getAttribute("errorString"); DBUtils.UpdateView(conn, IDP); ArrayList<Photo> ListInCart = null; ArrayList<Photo> ListLike = null; ArrayList<Photo> ListBuy = null; int Sum = 0; ArrayList<Album> ListAlbumUserLogined = new ArrayList<Album>(); if (loginedUser != null) { errorString = null; ListLike = DBUtils.SearchPhotoAime(conn, loginedUser.getIDU()); ListBuy = DBUtils.SearchPhotoAchete(conn, loginedUser.getIDU()); ListInCart = DBUtils.SearchPhoto(conn, loginedUser.getIDU()); ListAlbumUserLogined = DBUtils.LoadListAlbum(conn, loginedUser.getIDU()); if (ListInCart != null) { for (Photo p : ListInCart) { Sum = Sum + p.getPrix(); } } ArrayList<Album> ListAlbum = DBUtils.LoadListAlbum(conn, loginedUser.getIDU()); ArrayList<Photo> ListPhotoOfUser = new ArrayList<Photo>(); if (ListAlbum != null) { for (Album album : ListAlbum) { ListPhotoOfUser.addAll(DBUtils.LoadImage(conn, album.getIDA(), loginedUser.getIDU())); } } if (ListPhotoOfUser != null) { ListBuy.removeAll(ListPhotoOfUser); ListBuy.addAll(ListPhotoOfUser); } } request.setAttribute("photo", photo); request.setAttribute("ListBuy", ListBuy); request.setAttribute("ListLike", ListLike); request.setAttribute("errorString", errorString); request.setAttribute("ListInCart", ListInCart); request.setAttribute("Sum", Sum); request.setAttribute("ListAlbumUserLogined", ListAlbumUserLogined); RequestDispatcher view = request.getRequestDispatcher("viewimage.jsp"); view.forward(request, response); }
/** * Devuelve 0, 2 o 4, segun las probabilidades dadas. Estas probabilidades varín con el * nivel. * * @param p1 probabilidad de 0 en el nivel 1 * @param p2 probabilidad de 2 en el nivel 1 * @return 0, 2 o 4. Al azar */ public static int ponderar(int p1, int p2) { int t = RANDOM.nextInt(100); p1 = Utils.dificultar(p1, true); p2 = Utils.dificultar(p2, true); // p1 *= (1 + (this.nivelActual() - 1) * .15); // p2 *= (1 + (this.nivelActual() - 1) * .15); if (t <= p1) return 0; if (t <= p1 + p2) return 2; return 4; }
private static void recomputeTrainTestSets(TrainAndTestReport r) { // TODO a nicer way? :) if (r instanceof TrainAndTestReportCrisp) { TrainAndTestReportCrisp rep = (TrainAndTestReportCrisp) r; double[] newFittedValues = Arrays.copyOfRange(rep.getFittedValues(), 0, rep.getNumTrainingEntries()); double[] newForecastValsTest = Arrays.copyOfRange( rep.getFittedValues(), rep.getNumTrainingEntries(), rep.getFittedValues().length); rep.setFittedValues(newFittedValues); rep.setForecastValuesTest(newForecastValsTest); double[] newRealTrain = Arrays.copyOfRange(rep.getRealOutputsTrain(), 0, rep.getNumTrainingEntries()); double[] newRealTest = Arrays.copyOfRange( rep.getRealOutputsTrain(), rep.getNumTrainingEntries(), rep.getRealOutputsTrain().length); rep.setRealOutputsTrain(newRealTrain); rep.setRealOutputsTest(newRealTest); rep.setErrorMeasures( ErrorMeasuresUtils.computeAllErrorMeasuresCrisp( Utils.arrayToList(newRealTrain), Utils.arrayToList(newRealTest), Utils.arrayToList(newFittedValues), Utils.arrayToList(newForecastValsTest), 0)); // TODO I hope the 0 is not a problem } else if (r instanceof TrainAndTestReportInterval) { TrainAndTestReportInterval rep = (TrainAndTestReportInterval) r; List<Interval> newFittedValues = new ArrayList<>(rep.getFittedValues().subList(0, rep.getNumTrainingEntries())); List<Interval> newForecastValsTest = new ArrayList<>( rep.getFittedValues() .subList(rep.getNumTrainingEntries(), rep.getFittedValues().size())); rep.setFittedValues(newFittedValues); rep.setForecastValuesTest(newForecastValsTest); List<Interval> realVals = Utils.zipLowerUpperToIntervals(rep.getRealValuesLowers(), rep.getRealValuesUppers()); List<Interval> realValsTrain = new ArrayList<>(realVals.subList(0, rep.getNumTrainingEntries())); List<Interval> realValsTest = new ArrayList<>(realVals.subList(rep.getNumTrainingEntries(), realVals.size())); // TODO somehow add the actual distance and seasonality from params rep.setErrorMeasures( ErrorMeasuresUtils.computeAllErrorMeasuresInterval( realValsTrain, realValsTest, newFittedValues, newForecastValsTest, new WeightedEuclideanDistance(0.5), 0)); } }
@Override public void nextCycle() { super.nextCycle(); final Set<NodeAddress> toRemove = new HashSet<NodeAddress>(); // update member table, send alive messages for (final NodeAddress member : memberTable.keySet()) { final MemebrInfo ni = memberTable.get(member); if (Utils.getTime() - ni.lastMessageTime > lifeTimeThreshold) { toRemove.add(member); continue; } ni.aliveTime--; if (ni.aliveTime == 0) { ni.aliveTime = alivePeriod; sendMessage(new AliveMessage(getMessageTag(), network.getAddress(), member)); } } memberTable.keySet().removeAll(toRemove); removeNeighbors(toRemove); // gossip for (final NodeAddress neighbor : getNeighbors()) { final MemebrInfo ni = memberTable.get(neighbor); ni.gossipTime--; if (ni.gossipTime == 0) { ni.gossipTime = gossipPeriod; final List<NodeAddress> memberList = new ArrayList<NodeAddress>(memberTable.keySet()); memberList.remove(neighbor); Collections.shuffle(memberList, r); final List<NodeAddress> sublist = memberList.subList(0, Math.min(gossipSize, memberList.size())); sendMessage( new PartialMembershipViewMessage<Sizeable>( getMessageTag(), network.getAddress(), neighbor, new LinkedList<NodeAddress>(sublist))); } } // replace fallen neighbors from member view final Set<NodeAddress> neighbors = getNeighbors(); if (neighbors.size() < neighborSize && neighborSize < memberTable.size()) { final TreeMap<NodeAddress, MemebrInfo> addCandidates = new TreeMap<NodeAddress, MemebrInfo>(memberTable); addCandidates.keySet().removeAll(getNeighbors()); final Set<NodeAddress> minVal = Utils.findMinValueKeyGroup(addCandidates); for (final NodeAddress n : minVal) { if (neighbors.size() < neighborSize) { addNeighbor(n); network.send( new ConnectionRequestApprovedMessage<Sizeable>( getMessageTag(), network.getAddress(), n)); } } } }
protected void finalEst() { for (int i = 0; i < this.number_of_topics; i++) { Utils.L1Normalization(m_parentTopicTermProb[i]); Utils.L1Normalization(m_childTopicTermProb[i]); } for (_Doc d : m_trainSet) { estThetaInDoc(d); } discoverSpecificComments(); }
static int[] getPixels(BufferedImage image) throws IOException, InterruptedException { // -----resize image BufferedImage resizedImage = Utils.resizeImage(image, 32, 32); // ImageIO.write(resizeImageJpg, "jpg", new File("cat_32.jpg")); // -----convert to gray resizedImage = Utils.convertToGray(resizedImage); // -----get image pixels int[] pixels = Utils.getPixels(resizedImage); return pixels; }
// log space public double calParentLogLikelihood(_ParentDoc2 pDoc) { double term1 = 0.0; double term2 = 0.0; term1 = Utils.lgamma(number_of_topics * d_alpha) - number_of_topics * Utils.lgamma(d_alpha); for (int k = 0; k < number_of_topics; k++) { term2 += Utils.lgamma(pDoc.m_sstat[k] + d_alpha); } term2 -= Utils.lgamma((double) (number_of_topics * d_alpha + pDoc.getDocLength())); return term1 + term2; }
/** * Check if <code>positionX</code> is between <code>positionA</code> and <code>positionB</code>. * * @param positionX position that we want to check if it's between other positions * @param positionA other position * @param positionB other position * @return <code>true</code> if positionX between other position and all position are on same * line, otherwise <code>false</code> */ public static boolean isPositionBetweenPositionsOnLine( int positionX, int positionA, int positionB) { // if positionX is not between other positions, it can't be between // them. Duh... boolean greaterThanBoth = (positionX > positionA) && (positionX > positionB); boolean lowertThanBoth = (positionX < positionA) && (positionX < positionB); if (greaterThanBoth || lowertThanBoth) { return false; } // all positions must be on same line boolean sameRank = (Utils.getRankFromPosition(positionX) == Utils.getRankFromPosition(positionA)) && (Utils.getRankFromPosition(positionX) == Utils.getRankFromPosition(positionB)); boolean sameFile = (Utils.getFileFromPosition(positionX) == Utils.getFileFromPosition(positionA)) && (Utils.getFileFromPosition(positionX) == Utils.getFileFromPosition(positionB)); if (sameFile || sameRank) { return true; } else { return false; } }
private String getResponse(URL url) throws IOException { HttpURLConnection conn = (HttpURLConnection) url.openConnection(); conn.setRequestMethod(httpMethod.name()); conn.connect(); InputStream is = conn.getInputStream(); return Utils.readInput(is); }
@Override public View getView(final int position, View convertView, ViewGroup parent) { // TODO Auto-generated method stub final Holder holder = new Holder(); View rowView = convertView; rowView = inflater.inflate(R.layout.contactlistitem, null); holder.tv = (TextView) rowView.findViewById(R.id.contactname); holder.img = (ImageView) rowView.findViewById(R.id.contactimage); holder.tv.setText(contactNames.get(position)); holder.img.setImageBitmap(Utils.getFacebookPhoto(context, phoneNumber.get(position))); /*new AsyncTask<String, Void, Bitmap>() { @Override protected Bitmap doInBackground(String... params) { return ; } @Override protected void onPostExecute(Bitmap result) { super.onPostExecute(result); } }.execute(); rowView.setOnClickListener(new OnClickListener() { @Override public void onClick(View v) { } });*/ return rowView; }
private SSLSocket criaSSLSocket(String host) throws Exception { KeyStore ks = Utils.getKeyStore("JKS"); ks.load(new FileInputStream(keystore), byteSenha); KeyManagerFactory kmf = Utils.getKMFactory("SunX509"); kmf.init(ks, byteSenha); SSLContext sslcontext = Utils.criaSSLContext("SSLv3"); sslcontext.init(kmf.getKeyManagers(), null, null); SSLSocketFactory ssf = sslcontext.getSocketFactory(); SSLSocket socket = (SSLSocket) ssf.createSocket(host, HTTPS_PORT); return socket; }
public void train() { double mu; int qid, i, j, pSize; for (int n = 0; n < m_maxIter; n++) { Utils.shuffle(m_order, m_trainingSize); qid = 0; while (qid < m_trainingSize) { pSize = 0; Arrays.fill(m_g, 0.0); for (j = 0; j < m_windowSize; j++) { // collect the gradients in mini-batch pSize += gradientUpdate(m_queries.get(m_order[qid % m_trainingSize])); qid++; } // Step 4: gradient from regularization for (i = 0; i < m_weight.length; i++) m_g[i] = m_g[i] / pSize + m_lambda * m_weight[i]; mu = Math.random() * m_step; for (i = 0; i < m_weight.length; i++) m_weight[i] -= mu * m_g[i]; } m_step *= m_shrinkage; } }
@Override public void run() { Integer second10 = second10Init; Integer second30 = second30Init; while (true) { second10--; second30--; MyRobot.getInstance().getMemory().forgetOldItems(); if (second10 == 0) { second10 = second10Init; CommandDispatcher.getInstance().addCommand(new RobotGetOnOff()); CommandDispatcher.getInstance().addCommand(new RobotCheckSensors()); MyRobot.getInstance().getFaceController().updateFace(); } if (second30 == 0) { second30 = second30Init; // CommandDispatcher.getInstance().addCommand(new CheckInternetConnection()); // CommandDispatcher.getInstance().addCommand(new Alarm()); // CommandDispatcher.getInstance().addCommand(new Test()); } Utils.sleep(second); } }
@Override public void run() { try { while (this.loggedIn()) { DataPacket packet = new DataPacket(Function.CREATE_RANDOM_ORDER); packet.cashier = this; packet = this.communicateWithServer(packet); if (packet == null) continue; this.addOrder(packet.order); int sleepAmount = (Utils.generateRandomNumber(4) + 3) * 1000; try { Thread.sleep(sleepAmount); } catch (InterruptedException e) { } // poll the order manager for any undelivered orders floating about DataPacket undeliveredOrderPacket = new DataPacket(Function.GET_UNDELIVERED_ORDER); DataPacket undeliveredOrderReturnPacket = this.communicateWithServer(undeliveredOrderPacket); if (undeliveredOrderReturnPacket.order != null) this.deliverOrder(undeliveredOrderReturnPacket.order); } } catch (Exception e) { System.out.println("Cashier.run: Error exception " + e.getMessage()); } }
@Override protected void doFinalStuff() throws IOException { int numOfWords = WordsTool.getInstance().getIntegerMap().get(currFileName); double avgWordLength = (double) wordLengthSum / numOfWords; getDoubleMap().put(currFileName, Utils.getDouble(avgWordLength)); super.doFinalStuff(); }
public void actionPerformed(ActionEvent ev) { try { String[] logFiles = new String[] {"log"}; JFileChooser chooser = new JFileChooser(); chooser.setDialogTitle("Opening log file..."); chooser.setMultiSelectionEnabled(false); chooser.addChoosableFileFilter(new SimpleFileFilter(logFiles, "Log files (*.log)")); chooser.setCurrentDirectory(workingDirectory); chooser.showOpenDialog(Utils.getActiveFrame()); File file = chooser.getSelectedFile(); logFilename = file.getAbsolutePath(); System.out.println("Opened " + logFilename + "\n"); File tmpDir = chooser.getCurrentDirectory(); if (tmpDir != null) { workingDirectory = tmpDir; } } catch (Exception e) { System.err.println("Could not Open! \n"); } }
public static ArrayList<TilePiece> initializePieces() { ArrayList<TilePiece> tps = new ArrayList<>(); ArrayList<TilePieceSet> setupPieces = Utils.getTilePieceSetUp(); for (TilePieceSet setPieces : setupPieces) { tps.addAll(setPieces.getTilePieces()); } return tps; }
public LauncherDestructor(String type, String id, War w, WarStatistics statistics) { allListeners = new LinkedList<WarEventListener>(); this.id = id; this.type = Utils.capitalize(type); this.statistics = statistics; this.warName = w.getWarName(); this.w = w; }
// p(w, z)=p(w|z)p(z)~~multinomial-dirichlet public void calLogLikelihood(int iter) { double logLikelihood = 0.0; double parentLogLikelihood = 0.0; double childLogLikelihood = 0.0; for (_Doc d : m_trainSet) { if (d instanceof _ParentDoc2) { parentLogLikelihood += calParentLogLikelihood((_ParentDoc2) d); } else { if (d instanceof _ChildDoc2) { childLogLikelihood += calChildLogLikelihood((_ChildDoc2) d); } } } double term1 = 0.0; double term2 = 0.0; double term3 = 0.0; double term4 = 0.0; for (int k = 0; k < number_of_topics; k++) { for (int n = 0; n < vocabulary_size; n++) { term3 += Utils.lgamma(d_beta + m_parentWordTopicSstat[k][n] + m_childWordTopicSstat[k][n]); } term4 -= Utils.lgamma(vocabulary_size * d_beta + m_parentSstat[k] + m_childSstat[k]); } term1 = number_of_topics * Utils.lgamma(vocabulary_size * d_beta); term2 = -number_of_topics * (vocabulary_size * Utils.lgamma(d_beta)); parentLogLikelihood += term1 + term2 + term3 + term4; term1 = 0.0; term2 = 0.0; term3 = 0.0; term4 = 0.0; for (int k = 0; k < number_of_topics; k++) { for (int n = 0; n < vocabulary_size; n++) { term3 += Utils.lgamma(d_beta + m_parentWordTopicSstat[k][n] + m_childWordTopicSstat[k][n]); } term4 -= Utils.lgamma(vocabulary_size * d_beta + m_parentSstat[k] + m_childSstat[k]); } term1 = number_of_topics * Utils.lgamma(vocabulary_size * d_beta); term2 = -number_of_topics * (vocabulary_size * Utils.lgamma(d_beta)); childLogLikelihood += term1 + term2 + term3 + term4; System.out.format("iter %d, parent log likelihood %.3f\n", iter, parentLogLikelihood); infoWriter.format("iter %d, parent log likelihood %.3f\n", iter, parentLogLikelihood); System.out.format("iter %d, child log likelihood %.3f\n", iter, childLogLikelihood); infoWriter.format("iter %d, child log likelihood %.3f\n", iter, childLogLikelihood); logLikelihood = parentLogLikelihood + childLogLikelihood; System.out.format("iter %d, log likelihood %.3f\n", iter, logLikelihood); infoWriter.format("iter %d, log likelihood %.3f\n", iter, logLikelihood); }
public void actionPerformed(ActionEvent ev) { Color c = ColorPicker.showDialog( Utils.getActiveFrame(), "Choose maximum branches color...", branchesMaxColor, true); if (c != null) branchesMaxColor = c; }
/* * The constructor establishes the RuntimeContract between * the SQL-MR function and Aster Database. During query planning, * the function will constructed on a single node. During * query execution, it will be constructed and run on one or more nodes. */ public ChiSquareTest(RuntimeContract contract) { // Read argument clauses into appropriate member variables. observedArgumentIdx = contract .getInputInfo() .getColumnIndex(contract.useArgumentClause("observed").getSingleValue()); expectedArgumentIdx = contract .getInputInfo() .getColumnIndex(contract.useArgumentClause("expected").getSingleValue()); accumulator = new Accumulator(contract); errorHandler = new ErrorHandler( this.getClass().getName(), Utils.getSingleBooleanFromParameter(contract, "stoponerror", false), Utils.getSingleIntFromParameter(contract, "log", Integer.MAX_VALUE)); // Initialize the service chiSquareTest = new org.apache.commons.math3.stat.inference.ChiSquareTest(); // Verify that the function accepts the given input schema. if (!SqlType.integer().equals(contract.getInputInfo().getColumnType(observedArgumentIdx))) { throw new IllegalUsageException( "\"" + contract.useArgumentClause("observed").getSingleValue() + "\" must be of type 'integer'"); } if (!SqlType.doublePrecision() .equals(contract.getInputInfo().getColumnType(expectedArgumentIdx))) { throw new IllegalUsageException( "\"" + contract.useArgumentClause("expected").getSingleValue() + "\" must be a numeric type"); } // Construct the output schema List<ColumnDefinition> outputColumns = new ArrayList<ColumnDefinition>(); accumulator.constructOutputSchema(contract, outputColumns); outputColumns.add(new ColumnDefinition("pValue", SqlType.getType("double"))); contract.setOutputInfo(new OutputInfo(outputColumns)); // Complete the contract contract.complete(); }
private void receiveEGTable() { int nBytes = (nBits - 1) / 8 + 1; try { for (int j = 0; j < nCols; j++) EGTable[j] = Utils.readBigInteger(nBytes * Wire.labelBitLength, ois); } catch (Exception e) { e.printStackTrace(); System.exit(1); } }
@Override public TrainAndTestReport forecast(Map<String, List<Double>> data, Params parameters) { RandomWalkParams params = (RandomWalkParams) parameters; List<Double> allData = data.get(params.getColName()); List<Double> dataToUse = allData.subList(params.getDataRangeFrom() - 1, params.getDataRangeTo()); TrainAndTestReportCrisp report = new TrainAndTestReportCrisp(Model.RANDOM_WALK); int numTrainingEntries = Math.round( ((float) 100 / 100) * dataToUse .size()); // TODO maybe take a different %age - e.g. to agree with the other // models when avg report.setNumTrainingEntries(numTrainingEntries); List<Double> trainRealOutputs = new ArrayList<>(dataToUse.subList(0, numTrainingEntries)); List<Double> testRealOutputs = new ArrayList<>(dataToUse.subList(numTrainingEntries, dataToUse.size())); List<Double> trainForecastOutputs = new ArrayList<>(); trainForecastOutputs.add(Double.NaN); trainForecastOutputs.addAll(dataToUse.subList(0, numTrainingEntries - 1)); List<Double> testForecastOutputs = new ArrayList<>(dataToUse.subList(numTrainingEntries - 1, dataToUse.size() - 1)); report.setRealOutputsTrain(Utils.listToArray(trainRealOutputs)); report.setRealOutputsTest(Utils.listToArray(testRealOutputs)); report.setPlotCode( "plot.ts(c(" + Utils.arrayToRVectorString(Utils.listToArray(trainForecastOutputs)) + "," + Utils.arrayToRVectorString(Utils.listToArray(testForecastOutputs)) + "))"); report.setFittedValues(Utils.listToArray(trainForecastOutputs)); report.setForecastValuesTest(Utils.listToArray(testForecastOutputs)); ErrorMeasuresCrisp errorMeasures = ErrorMeasuresUtils.computeAllErrorMeasuresCrisp( trainRealOutputs, testRealOutputs, trainForecastOutputs, testForecastOutputs, params.getSeasonality()); report.setErrorMeasures(errorMeasures); return report; }