示例#1
0
  public void ensureIncreasingTime() {
    if (getPositionCount() < 2) return;

    long completeTime = getTime(); // ms
    double completeDistance = getDistance(); // m
    double averageSpeed = completeTime > 0 ? completeDistance / completeTime * 1000 : 1.0; // m/s

    List<P> positions = getPositions();
    P first = positions.get(0);
    if (!first.hasTime()) first.setTime(fromCalendar(Calendar.getInstance(UTC)));

    P previous = first;
    for (int i = 1; i < positions.size(); i++) {
      P next = positions.get(i);
      CompactCalendar time = next.getTime();
      if (time == null || time.equals(previous.getTime())) {
        Double distance = next.calculateDistance(previous);
        Long millis = distance != null ? (long) (distance / averageSpeed * 1000) : null;
        if (millis == null || millis < 1000) millis = 1000L;
        next.setTime(
            fromMillisAndTimeZone(
                previous.getTime().getTimeInMillis() + millis, previous.getTime().getTimeZoneId()));
      }
      previous = next;
    }
  }
示例#2
0
 private void move(int index, int upOrDown) {
   List<P> positions = getPositions();
   P move = positions.get(index);
   P replace = positions.get(index + upOrDown);
   positions.set(index + upOrDown, move);
   positions.set(index, replace);
 }
示例#3
0
 public void sort(Comparator<P> comparator) {
   List<P> positions = getPositions();
   @SuppressWarnings({"SuspiciousToArrayCall", "unchecked"})
   P[] sorted = (P[]) positions.toArray(new BaseNavigationPosition[positions.size()]);
   Arrays.sort(sorted, comparator);
   //noinspection unchecked
   order(asList(sorted));
 }
 /** @return the list of variable varNames. */
 public List<String> getVariableNames() {
   List<Node> variables = getVariables();
   List<String> variableNames = new ArrayList<String>();
   for (Node variable1 : variables) {
     variableNames.add(variable1.getName());
   }
   return variableNames;
 }
  public ICovarianceMatrix getCov() {
    List<DataSet> _dataSets = new ArrayList<DataSet>();

    for (DataSet d : dataSets) {
      _dataSets.add(DataUtils.standardizeData(d));
    }

    return new CovarianceMatrix(DataUtils.concatenateData(dataSets));
  }
示例#6
0
 public int[] getContainedPositions(BoundingBox boundingBox) {
   List<Integer> result = new ArrayList<>();
   List<P> positions = getPositions();
   for (int i = 0; i < positions.size(); i++) {
     P position = positions.get(i);
     if (position.hasCoordinates() && boundingBox.contains(position)) result.add(i);
   }
   return toArray(result);
 }
示例#7
0
  @SuppressWarnings("UnusedDeclaration")
  public TourRoute asTourFormat() {
    if (getFormat() instanceof TourFormat) return (TourRoute) this;

    List<TourPosition> tourPositions = new ArrayList<>();
    for (P position : getPositions()) {
      tourPositions.add(position.asTourPosition());
    }
    return new TourRoute(getName(), tourPositions);
  }
示例#8
0
  @SuppressWarnings("UnusedDeclaration")
  public OvlRoute asOvlFormat() {
    if (getFormat() instanceof OvlFormat) return (OvlRoute) this;

    List<Wgs84Position> ovlPositions = new ArrayList<>();
    for (P position : getPositions()) {
      ovlPositions.add(position.asOvlPosition());
    }
    return new OvlRoute(getCharacteristics(), getName(), ovlPositions);
  }
示例#9
0
  @SuppressWarnings("UnusedDeclaration")
  public MagicMapsPthRoute asMagicMapsPthFormat() {
    if (getFormat() instanceof MagicMapsPthFormat) return (MagicMapsPthRoute) this;

    List<GkPosition> gkPositions = new ArrayList<>();
    for (P position : getPositions()) {
      gkPositions.add(position.asGkPosition());
    }
    return new MagicMapsPthRoute(getCharacteristics(), gkPositions);
  }
示例#10
0
  @SuppressWarnings("UnusedDeclaration")
  public GarminFlightPlanRoute asGarminFlightPlanFormat() {
    if (getFormat() instanceof GarminFlightPlanFormat) return (GarminFlightPlanRoute) this;

    List<GarminFlightPlanPosition> flightPlanPositions = new ArrayList<>();
    for (P position : getPositions()) {
      flightPlanPositions.add(position.asGarminFlightPlanPosition());
    }
    return new GarminFlightPlanRoute(getName(), getDescription(), flightPlanPositions);
  }
示例#11
0
  @SuppressWarnings("UnusedDeclaration")
  public MagicMapsIktRoute asMagicMapsIktFormat() {
    if (getFormat() instanceof MagicMapsIktFormat) return (MagicMapsIktRoute) this;

    List<Wgs84Position> wgs84Positions = new ArrayList<>();
    for (P position : getPositions()) {
      wgs84Positions.add(position.asWgs84Position());
    }
    return new MagicMapsIktRoute(getName(), getDescription(), wgs84Positions);
  }
示例#12
0
  @SuppressWarnings("UnusedDeclaration")
  public ViaMichelinRoute asViaMichelinFormat() {
    if (getFormat() instanceof ViaMichelinFormat) return (ViaMichelinRoute) this;

    List<Wgs84Position> wgs84Positions = new ArrayList<>();
    for (P position : getPositions()) {
      wgs84Positions.add(position.asWgs84Position());
    }
    return new ViaMichelinRoute(getName(), wgs84Positions);
  }
示例#13
0
 public double getElevationDelta(int index) {
   List<P> positions = getPositions();
   NavigationPosition previous = index > 0 ? positions.get(index - 1) : null;
   NavigationPosition current = index < positions.size() ? positions.get(index) : null;
   if (previous != null && current != null) {
     Double elevation = previous.calculateElevation(current);
     if (elevation != null) return elevation;
   }
   return 0;
 }
示例#14
0
  @SuppressWarnings("UnusedDeclaration")
  public NokiaLandmarkExchangeRoute asNokiaLandmarkExchangeFormat() {
    if (getFormat() instanceof NokiaLandmarkExchangeFormat)
      return (NokiaLandmarkExchangeRoute) this;

    List<Wgs84Position> wgs84Positions = new ArrayList<>();
    for (P position : getPositions()) {
      wgs84Positions.add(position.asWgs84Position());
    }
    return new NokiaLandmarkExchangeRoute(getName(), getDescription(), wgs84Positions);
  }
示例#15
0
 /**
  * Removes duplicate adjacent {@link #getPositions() positions} from this route, leaving only
  * distinct neighbours
  */
 public void removeDuplicates() {
   List<P> positions = getPositions();
   P previous = null;
   int index = 0;
   while (index < positions.size()) {
     P next = positions.get(index);
     if (previous != null && (!next.hasCoordinates() || next.calculateDistance(previous) <= 0.0)) {
       positions.remove(index);
     } else index++;
     previous = next;
   }
 }
示例#16
0
 public double getElevationDescend(int startIndex, int endIndex) {
   double result = 0;
   List<P> positions = getPositions();
   NavigationPosition previous = null;
   for (int i = startIndex; i <= endIndex; i++) {
     NavigationPosition next = positions.get(i);
     if (previous != null) {
       Double elevation = previous.calculateElevation(next);
       if (elevation != null && elevation < 0) result += abs(elevation);
     }
     previous = next;
   }
   return result;
 }
示例#17
0
 public double getDistance(int startIndex, int endIndex) {
   double result = 0;
   List<P> positions = getPositions();
   NavigationPosition previous = null;
   for (int i = startIndex; i <= endIndex; i++) {
     NavigationPosition next = positions.get(i);
     if (previous != null) {
       Double distance = previous.calculateDistance(next);
       if (distance != null) result += distance;
     }
     previous = next;
   }
   return result;
 }
示例#18
0
  public void revert() {
    List<P> positions = getPositions();
    List<P> reverted = new ArrayList<>();
    for (P position : positions) {
      reverted.add(0, position);
    }
    order(reverted);

    String routeName = getName();
    if (!routeName.endsWith(REVERSE_ROUTE_NAME_POSTFIX))
      routeName = routeName + REVERSE_ROUTE_NAME_POSTFIX;
    else
      routeName = routeName.substring(0, routeName.length() - REVERSE_ROUTE_NAME_POSTFIX.length());
    setName(routeName);
  }
示例#19
0
  public int getClosestPosition(double longitude, double latitude, double threshold) {
    int closestIndex = -1;
    double closestDistance = MAX_VALUE;

    List<P> positions = getPositions();
    for (int i = 0; i < positions.size(); ++i) {
      P point = positions.get(i);
      Double distance = point.calculateDistance(longitude, latitude);
      if (distance != null && distance < closestDistance && distance < threshold) {
        closestDistance = distance;
        closestIndex = i;
      }
    }
    return closestIndex;
  }
  /*
   * Method to that creates and returns and array list of the initial population of cells.
   * The number of cells in the population is determined by the integer 'population_size'
   */
  private static List<Cell> initiatePopulation(List<Cell> population, int population_size) {
    int[][][] genome = new int[haploid_number][2][2]; // The genome of unlabelled chromosomes

    for (int count_one = 0; count_one < genome.length; count_one++) {
      for (int count_two = 0; count_two < genome[count_one].length; count_two++) {
        for (int count_three = 0;
            count_three < genome[count_one][count_two].length;
            count_three++) {
          genome[count_one][count_two][count_three] = 0; // Set each DNA strand to unlabelled

          // printString("Chromosome " + Integer.toString(count_one+1) + "; Pair " +
          // Integer.toString(count_two+1) + "; Strand " + Integer.toString(count_three+1));
        }
      }
    }

    // POPULATE GENOME WITH 0's

    // Create the starting population of cells, all as generation 1
    for (int counter = 0; counter < population_size; counter++) {
      population.add(
          new Cell(
              counter,
              newest_generation + 1,
              -1,
              true,
              genome)); // Create a new Cell object with the following values.

      id_of_last_created_cell = counter; // Track the id of the lastcreated cell
    } // for
    return population;
  } // initiate_first_population()
  public void insertSimple(int val, Node ptr, int i) {
    // declare two lists to store keys and ptrs
    List<Integer> tempKeys = new ArrayList<Integer>();
    List<Node> tempPtrs = new ArrayList<Node>();

    // store keys and ptrs into list
    for (int j = i; j <= this.getLast(); j++) {
      tempKeys.add(this.getKey(j));
      tempPtrs.add(this.getPtr(j));
    }

    // set keys and ptrs at position i
    this.keys[i] = val;
    this.ptrs[i] = ptr;
    // set parent reference
    this.ptrs[i].setParent(new Reference(this, i, false));

    int end = tempKeys.size();
    // add keys and ptrs to current node from previous lists
    for (int j = i + 1; j <= i + end; j++) {
      this.keys[j] = tempKeys.get(j - i - 1);
      this.ptrs[j] = tempPtrs.get(j - i - 1);
      // set parent reference
      this.ptrs[j].setParent(new Reference(this, j, false));
    }

    // increase lastindex because of insertion
    this.lastindex++;
  }
示例#22
0
 public double[] getDistancesFromStart(int startIndex, int endIndex) {
   double[] result = new double[endIndex - startIndex + 1];
   List<P> positions = getPositions();
   int index = 0;
   double distance = 0.0;
   NavigationPosition previous = positions.size() > 0 ? positions.get(0) : null;
   while (index <= endIndex) {
     NavigationPosition next = positions.get(index);
     if (previous != null) {
       Double delta = previous.calculateDistance(next);
       if (delta != null) distance += delta;
       if (index >= startIndex) result[index - startIndex] = distance;
     }
     index++;
     previous = next;
   }
   return result;
 }
示例#23
0
文件: Octree.java 项目: vlitomsk/fit
  public void allRayIntersections(Vec raypt, Vec rayNormalizedDir, Consumer<Tp> cons) {
    if (!intersectsWithRay(raypt, rayNormalizedDir)) return;

    container.forEach(cons);
    forAllSubtree(
        (i, j, k) -> {
          if (subtree[i][j][k] != null)
            subtree[i][j][k].allRayIntersections(raypt, rayNormalizedDir, cons);
        });
  }
  private List<Chessboard> getPossibleMutations(Chessboard chessboard) {
    List<Chessboard> result = new ArrayList<Chessboard>();

    for (int i = 0; i < chessboard.board.length; ++i) {
      for (int j = i + 1; j < chessboard.board.length; ++j) {
        int rook1Col = chessboard.board[i];
        int rook2Col = chessboard.board[j];

        if (rook1Col > rook2Col) {
          Chessboard newChessboard =
              new Chessboard(Arrays.copyOf(chessboard.board, chessboard.board.length));
          newChessboard.board[j] = rook1Col;
          newChessboard.board[i] = rook2Col;
          result.add(newChessboard);
        }
      }
    }

    return result;
  }
  public IndTestFisherZPercentIndependent(List<DataSet> dataSets, double alpha) {
    this.dataSets = dataSets;
    this.variables = dataSets.get(0).getVariables();

    data = new ArrayList<TetradMatrix>();

    for (DataSet dataSet : dataSets) {
      dataSet = DataUtils.center(dataSet);
      TetradMatrix _data = dataSet.getDoubleData();
      data.add(_data);
    }

    ncov = new ArrayList<TetradMatrix>();
    for (TetradMatrix d : this.data) ncov.add(d.transpose().times(d).scalarMult(1.0 / d.rows()));

    setAlpha(alpha);
    rows = new int[dataSets.get(0).getNumRows()];
    for (int i = 0; i < getRows().length; i++) getRows()[i] = i;

    variablesMap = new HashMap<Node, Integer>();
    for (int i = 0; i < variables.size(); i++) {
      variablesMap.put(variables.get(i), i);
    }

    this.recursivePartialCorrelation = new ArrayList<RecursivePartialCorrelation>();
    for (TetradMatrix covMatrix : ncov) {
      recursivePartialCorrelation.add(new RecursivePartialCorrelation(getVariables(), covMatrix));
    }
  }
示例#26
0
 public int[] getPositionsWithinDistanceToPredecessor(double distance) {
   List<Integer> result = new ArrayList<>();
   List<P> positions = getPositions();
   if (positions.size() <= 2) return new int[0];
   P previous = positions.get(0);
   for (int i = 1; i < positions.size() - 1; i++) {
     P next = positions.get(i);
     if (!next.hasCoordinates() || next.calculateDistance(previous) <= distance) result.add(i);
     else previous = next;
   }
   return toArray(result);
 }
示例#27
0
  public double[] getDistancesFromStart(int[] indices) {
    double[] result = new double[indices.length];
    if (indices.length > 0 && getPositionCount() > 0) {
      Arrays.sort(indices);
      int endIndex = min(indices[indices.length - 1], getPositionCount() - 1);

      int index = 0;
      double distance = 0.0;
      List<P> positions = getPositions();
      NavigationPosition previous = positions.get(0);
      while (index <= endIndex) {
        NavigationPosition next = positions.get(index);
        if (previous != null) {
          Double delta = previous.calculateDistance(next);
          if (delta != null) distance += delta;
          int indexInIndices = binarySearch(indices, index);
          if (indexInIndices >= 0) result[indexInIndices] = distance;
        }
        index++;
        previous = next;
      }
    }
    return result;
  }
示例#28
0
文件: Octree.java 项目: vlitomsk/fit
  public void add(Tp obj, int maxDepth) {
    if (!in(0, 0, 0, 2, obj)) throw new RuntimeException("Object is out of octree");

    if (maxDepth != 0) {
      for (int i = 0; i < 2; ++i)
        for (int j = 0; j < 2; ++j)
          for (int k = 0; k < 2; ++k)
            if (in(i, j, k, 1, obj)) {
              if (subtree[i][j][k] == null)
                subtree[i][j][k] = new Octree(xc[i], xc[i + 1], yc[j], yc[j + 1], zc[k], zc[k + 1]);
              subtree[i][j][k].add(obj, maxDepth - 1);
              return;
            }
    }
    // Gstate.counter++;
    container.add(obj);
    //        System.out.println("gstate counter:" + Gstate.counter);
  }
  private static void runSimulationExecutive(
      int sim_duration,
      int simulation_time_interval,
      List<Cell> cell_population,
      int cell_doubling_rate) {
    int population_size = cell_population.size();
    int next_div_time = cell_doubling_rate;
    int[][][] diploid_genome =
        new int[haploid_number][2]
            [2]; // The genome, chromosome->homologous pair->complementary DNA strands

    // Progress through time at selected intervals for a specified duration
    for (int current_time = 0;
        current_time < sim_duration;
        current_time += simulation_time_interval) {
      Random rand = new Random();
      // Perform division of all cells that can divide as determined by a random number generator
      // and the set division threshhold
      // As new cells are being added to the list, only go through the cells in the population
      // before new cells are added i.e use the previous population size as max number of iterations
      for (int counter = 0; counter < population_size; counter++) {
        if (cell_population.get(counter).getDivisionStatus()) {
          // Random number generator, 0 = divide, 1 = don't divide

          double coin_flip = rand.nextDouble();
          // printString(Double.toString(coin_flip));
          if (coin_flip >= 0.5) {
            // Remove one cell from the current generation and add two to the next
            // by changing the generation of the dividing cell to current_gen + 1 and
            // create a new cell object for the next generation
            cell_population.get(counter).setGen(cell_population.get(counter).getGen() + 1);
            cell_population.add(
                new Cell(
                    id_of_last_created_cell + 1, newest_generation + 1, -1, true, diploid_genome));
            id_of_last_created_cell++;
          }
        } // if the cell can divide
      } // for all items in main population array

      population_size =
          cell_population.size(); // Update the population size after the round of division
      newest_generation++; // Update the value of the most recent generation after the division
      // round
      next_div_time +=
          cell_doubling_rate; // Set the next time of division by adding the doubling rate to the
      // current time

      printString(current_time + " " + population_size);
    } // for
  } // runSimulationExecutive
  public boolean isIndependent(Node x, Node y, List<Node> z) {
    int[] all = new int[z.size() + 2];
    all[0] = variablesMap.get(x);
    all[1] = variablesMap.get(y);
    for (int i = 0; i < z.size(); i++) {
      all[i + 2] = variablesMap.get(z.get(i));
    }

    int sampleSize = data.get(0).rows();
    List<Double> pValues = new ArrayList<Double>();

    for (int m = 0; m < ncov.size(); m++) {
      TetradMatrix _ncov = ncov.get(m).getSelection(all, all);
      TetradMatrix inv = _ncov.inverse();
      double r = -inv.get(0, 1) / sqrt(inv.get(0, 0) * inv.get(1, 1));

      double fisherZ =
          sqrt(sampleSize - z.size() - 3.0) * 0.5 * (Math.log(1.0 + r) - Math.log(1.0 - r));
      double pValue;

      if (Double.isInfinite(fisherZ)) {
        pValue = 0;
      } else {
        pValue = 2.0 * (1.0 - RandomUtil.getInstance().normalCdf(0, 1, abs(fisherZ)));
      }

      pValues.add(pValue);
    }

    double _cutoff = alpha;

    if (fdr) {
      _cutoff = StatUtils.fdrCutoff(alpha, pValues, false);
    }

    Collections.sort(pValues);
    int index = (int) round((1.0 - percent) * pValues.size());
    this.pValue = pValues.get(index);

    //        if (this.pValue == 0) {
    //            System.out.println("Zero pvalue "+ SearchLogUtils.independenceFactMsg(x, y, z,
    // getPValue()));
    //        }

    boolean independent = this.pValue > _cutoff;

    if (verbose) {
      if (independent) {
        TetradLogger.getInstance()
            .log("independencies", SearchLogUtils.independenceFactMsg(x, y, z, getPValue()));
        //            System.out.println(SearchLogUtils.independenceFactMsg(x, y, z, getPValue()));
      } else {
        TetradLogger.getInstance()
            .log("dependencies", SearchLogUtils.dependenceFactMsg(x, y, z, getPValue()));
      }
    }

    return independent;
  }