private XYZDataset createDataSet(HashBasedTable<String, String, Double> data) {

    MatrixSeries series =
        new MatrixSeries(
            "DataTable", roomToCodeMapping.keySet().size(), roomToCodeMapping.keySet().size());

    for (String source : roomToCodeMapping.keySet()) {
      Integer sourceId = roomToCodeMapping.get(source);

      for (String destination : roomToCodeMapping.keySet()) {

        Integer destinationId = roomToCodeMapping.get(destination);
        if (!data.contains(source, destination)) {
          series.update(sourceId, destinationId, -1.0);
        } else {
          double value;
          if (type == MarkovDataDialog.HeatMapType.COMPARISON)
            value = (data.get(source, destination) + 1.0) / 2; // Scale to 0 to 1 for comparison
          else value = data.get(source, destination);
          if (value < 0 || value > 1) {
            System.out.println(
                "***********Problem in value=" + value + "(" + source + "," + destination + ")");
          }
          series.update(sourceId, destinationId, value);
        }
      }
    }

    System.out.println("Room size = " + roomToCodeMapping.keySet().size());
    return new MatrixSeriesCollection(series);
  }
  private static ArrayList<String> printData(HashBasedTable<String, String, Double> tbl1) {

    // lstOut = output data
    // sbl1 = current line
    // rgs1 = list of row ids
    // rgs2 = list of headers

    ArrayList<String> lstOut;
    StringBuilder sbl1;
    String rgs1[];
    String rgs2[];

    lstOut = new ArrayList<String>();
    rgs1 = tbl1.rowKeySet().toArray(new String[tbl1.rowKeySet().size()]);
    rgs2 = new String[rgs1.length];
    for (int i = 0; i < rgs1.length; i++) {
      rgs2[i] = (new File(rgs1[i])).getName();
    }
    lstOut.add("SampleID" + "," + Joiner.on(",").join(rgs2));
    for (String s : tbl1.columnKeySet()) {
      sbl1 = new StringBuilder();
      sbl1.append(s);
      for (int i = 0; i < rgs1.length; i++) {
        sbl1.append("," + tbl1.get(rgs1[i], s));
      }
      lstOut.add(sbl1.toString());
    }
    return lstOut;
  }
 @Test
 public void calculateWeight_WeightsCalculated_WeightsCorrect() {
   for (Integer i : tblWeight.rowKeySet()) {
     for (Integer j : tblWeight.columnKeySet()) {
       assertEquals(tblWeight.get(i, j), spw1.getWeight(spw1.getEdge(i, j)), 0.0000001);
     }
   }
 }
  private void handleIncomingConfirmableCoapRequest(ChannelHandlerContext ctx, MessageEvent me) {
    InetSocketAddress remoteEndpoint = (InetSocketAddress) me.getRemoteAddress();
    CoapMessage coapMessage = (CoapMessage) me.getMessage();

    IncomingReliableMessageExchange newMessageExchange =
        new IncomingReliableMessageExchange(remoteEndpoint, coapMessage.getMessageID());

    IncomingMessageExchange oldMessageExchange =
        ongoingMessageExchanges.get(remoteEndpoint, coapMessage.getMessageID());

    // Check if there is an ongoing
    if (oldMessageExchange != null) {

      if (oldMessageExchange instanceof IncomingReliableMessageExchange) {

        // if the old message exchange is reliable and the empty ACK was already sent send another
        // empty ACK
        if (((IncomingReliableMessageExchange) oldMessageExchange).isAcknowledgementSent())
          writeEmptyAcknowledgement(remoteEndpoint, coapMessage.getMessageID());

      }

      // if the old message was unreliable and the duplicate message is confirmable send empty ACK
      else writeEmptyAcknowledgement(remoteEndpoint, coapMessage.getMessageID());

      // As the message is already being processed there is nothing more to do
      return;
    }

    // try to add new reliable message exchange
    boolean added = false;
    synchronized (monitor) {
      Long time = System.currentTimeMillis() + MIN_EMPTY_ACK_DELAY_MILLIS;

      // Add message exchange to set of ongoing exchanges to detect duplicates
      if (!ongoingMessageExchanges.contains(remoteEndpoint, coapMessage.getMessageID())) {
        ongoingMessageExchanges.put(remoteEndpoint, coapMessage.getMessageID(), newMessageExchange);
        added = true;
      }

      // If the scheduling of the empty ACK does not work then it was already scheduled
      if (!emptyAcknowledgementSchedule.put(time, newMessageExchange)) {
        log.error("Could not schedule empty ACK for message: {}", coapMessage);
        ongoingMessageExchanges.remove(remoteEndpoint, coapMessage.getMessageID());
        added = false;
      }
    }

    // everything is fine, so further process message
    if (added) ctx.sendUpstream(me);
  }
  private void initialize() {

    // ert1 = earth geometry object
    // dThreshold = threshold distance
    // ranDist = distances range
    // ranTime = time range
    // ranDirect = directions range
    // i1 = counter
    // rgdSum = row sums

    double dThreshold;
    EarthGeometry ert1;
    Range<Double> ranDist;
    Range<Double> ranTime;
    Range<Double> ranDirect;
    int i1;
    double rgdSum[];

    // initializing mocked data
    rgdLat = new double[] {45., 46., 47., 48.};
    rgdLon = new double[] {-110., -109., -108., -107.};
    rgdPoints = new double[rgdLat.length * rgdLat.length][2];
    i1 = 0;
    for (int i = 0; i < rgdLat.length; i++) {
      for (int j = 0; j < rgdLat.length; j++) {
        rgdPoints[i1][0] = rgdLat[i];
        rgdPoints[i1][1] = rgdLon[j];
        i1++;
      }
    }

    rgdAbund = new double[2][rgdPoints.length];
    tblWeight = HashBasedTable.create(4, 4);
    dThreshold = 150.;

    ert1 = new EarthGeometry();
    rgdSum = new double[rgdPoints.length];
    for (int i = 0; i < rgdPoints.length; i++) {
      for (int j = 0; j < rgdPoints.length; j++) {
        if (i != j
            && ert1.orthodromicDistanceWGS84(
                    rgdPoints[i][0], rgdPoints[i][1], rgdPoints[j][0], rgdPoints[j][1])
                < dThreshold) {
          tblWeight.put(i, j, 1.);
          rgdSum[i] += 1.;
        } else {
          tblWeight.put(i, j, 0.);
        }
      }
      rgdAbund[0][i] = ((double) i) / 20.;
      rgdAbund[1][i] = (((double) i) % 4.) / 4.;
    }

    for (int i = 0; i < rgdPoints.length; i++) {
      for (int j = 0; j < rgdPoints.length; j++) {
        if (rgdSum[i] > 0) {
          tblWeight.put(i, j, tblWeight.get(i, j) / rgdSum[i]);
        }
      }
    }

    // loading spatial weights object from file
    ranDist = Range.closed(0., dThreshold);
    ranTime = Range.closed(0., 12.);
    ranDirect = Range.closed(0., 360.);
    bio1 =
        new BiomIO(
            "/home/jladau/Desktop/Data/Microbial_Community_Samples/ValidationData.NA.NA.Ladau.biom");

    try {
      spw1 =
          new SpatialWeightsMatrix(
              bio1, ranDist, ranDirect, ranTime, "binary", "latitude-longitude", false);
    } catch (Exception e) {
      e.printStackTrace();
    }
  }
Exemple #6
0
 /**
  * Returns the permitted option occurrence within a message with the given code
  *
  * @param optionNumber the options number
  * @param messageCode the number corresponding to a message code
  * @return the permitted option occurrence within a message with the given code
  */
 public static Occurence getPermittedOccurrence(int optionNumber, int messageCode) {
   Occurence result = OCCURENCE_CONSTRAINTS.get(messageCode, optionNumber);
   return result == null ? NONE : result;
 }
 public void addCrossFeature(int i, int j, String f) {
   if (!crossFactors.contains(i, j)) {
     crossFactors.put(i, j, new Factor());
   }
   crossFactors.get(i, j).add(f);
 }