List of usage examples for java.lang Float isNaN
public static boolean isNaN(float v)
From source file:services.SimulationService.java
public void moveObject(SWGObject object, Point3D newPosition, Quaternion newOrientation, int movementCounter, float speed, CellObject cell) { if (Float.isNaN(newPosition.x) || Float.isNaN(newPosition.y) || Float.isNaN(newPosition.z)) return;//from www .j a v a 2 s . co m if (object instanceof CreatureObject) { CreatureObject cre = (CreatureObject) object; if (cre.getPosture() == Posture.Dead || cre.getPosture() == Posture.Incapacitated) return; } if (cell == null) { Point3D oldPos; synchronized (object.getMutex()) { oldPos = object.getPosition(); if (object.getContainer() == null) move(object, oldPos.x, oldPos.z, newPosition.x, newPosition.z); object.setPosition(newPosition); object.setOrientation(newOrientation); object.setMovementCounter(movementCounter + 1); } if (object.getContainer() != null && newPosition != oldPos) { object.getContainer()._remove(object); add(object, newPosition.x, newPosition.z); } if (object.getPlanet().getName().equals("talus") && object.getTemplate().contains("stormtrooper")) { // float xx = object.getWorldPosition().x - newPosition.x; // float zz = object.getWorldPosition().z - newPosition.z; // float diff = (float) Math.sqrt(xx*xx+zz*zz); // System.out.println(" ((CreatureObject)object).getSpeedMultiplierBase());: " + ((CreatureObject)object).getSpeedMultiplierBase()); // System.out.println(" ((CreatureObject)object).getSpeedMultiplierMod());: " + ((CreatureObject)object).getSpeedMultiplierMod()); // } UpdateTransformMessage utm = new UpdateTransformMessage(object.getObjectID(), (short) (newPosition.x * 4 + 0.5), (short) (newPosition.y * 4 + 0.5), (short) (newPosition.z * 4 + 0.5), movementCounter + 1, getSpecialDirection(newOrientation), speed); List<SWGObject> newAwareObjects = get(object.getPlanet(), newPosition.x, newPosition.z, 512); ArrayList<SWGObject> oldAwareObjects = new ArrayList<SWGObject>(object.getAwareObjects()); @SuppressWarnings("unchecked") Collection<SWGObject> updateAwareObjects = CollectionUtils.intersection(oldAwareObjects, newAwareObjects); object.notifyObservers(utm, false); for (int i = 0; i < oldAwareObjects.size(); i++) { SWGObject obj = oldAwareObjects.get(i); if (!updateAwareObjects.contains(obj) && obj != object && obj.getWorldPosition().getDistance2D(newPosition) > 200 && obj.isInQuadtree() /*&& obj.getParentId() == 0*/) { if (obj.getAttachment("bigSpawnRange") != null && obj.getWorldPosition().getDistance2D(newPosition) < 512) continue; object.makeUnaware(obj); if (obj.getClient() != null) obj.makeUnaware(object); } else if (obj != object && obj.getWorldPosition().getDistance2D(newPosition) > 200 && obj.isInQuadtree() && obj.getAttachment("bigSpawnRange") == null) { object.makeUnaware(obj); if (obj.getClient() != null) obj.makeUnaware(object); } } for (int i = 0; i < newAwareObjects.size(); i++) { SWGObject obj = newAwareObjects.get(i); //System.out.println(obj.getTemplate()); if (!updateAwareObjects.contains(obj) && obj != object && !object.getAwareObjects().contains(obj) && obj.getContainer() != object && obj.isInQuadtree()) { if (obj.getAttachment("bigSpawnRange") == null && obj.getWorldPosition().getDistance2D(newPosition) > 200) continue; object.makeAware(obj); if (obj.getClient() != null) obj.makeAware(object); } } checkForCollidables(object); MoveEvent event = new MoveEvent(); event.object = object; object.getEventBus().publish(event); } else { newPosition.setCell(cell); Point3D oldPos = object.getPosition(); object.setPosition(newPosition); object.setOrientation(newOrientation); object.setMovementCounter(movementCounter + 1); UpdateTransformWithParentMessage utm = new UpdateTransformWithParentMessage(object.getObjectID(), cell.getObjectID(), (short) (newPosition.x * 8 + 0.5), (short) (newPosition.y * 8 + 0.5), (short) (newPosition.z * 8 + 0.5), movementCounter + 1, getSpecialDirection(newOrientation), speed); if (object.getContainer() != cell) { remove(object, oldPos.x, oldPos.z); if (object.getContainer() != null) object.getContainer()._remove(object); cell._add(object); } object.notifyObservers(utm, false); checkForCollidables(object); } }
From source file:org.eclipse.january.dataset.Stats.java
/** * @param a dataset/* w w w. ja v a2 s . c o m*/ * @param axis * @param ignoreInvalids see {@link Dataset#max(int, boolean...)} * @return cumulative product of items along axis in dataset * @since 2.0 */ public static Dataset cumulativeProduct(final Dataset a, int axis, final boolean... ignoreInvalids) { axis = a.checkAxis(axis); int dtype = a.getDType(); int[] oshape = a.getShape(); int alen = oshape[axis]; oshape[axis] = 1; final boolean ignoreNaNs; final boolean ignoreInfs; if (a.hasFloatingPointElements()) { ignoreNaNs = ignoreInvalids != null && ignoreInvalids.length > 0 ? ignoreInvalids[0] : false; ignoreInfs = ignoreInvalids != null && ignoreInvalids.length > 1 ? ignoreInvalids[1] : ignoreNaNs; } else { ignoreNaNs = false; ignoreInfs = false; } Dataset result = DatasetFactory.zeros(a); PositionIterator pi = result.getPositionIterator(axis); int[] pos = pi.getPos(); while (pi.hasNext()) { if (a.isComplex()) { double rv = 1, iv = 0; switch (dtype) { case Dataset.COMPLEX64: ComplexFloatDataset af = (ComplexFloatDataset) a; ComplexFloatDataset rf = (ComplexFloatDataset) result; for (int j = 0; j < alen; j++) { if (!Double.isNaN(rv) || !Double.isNaN(iv)) { pos[axis] = j; final float r1 = af.getReal(pos); final float i1 = af.getImag(pos); if (ignoreNaNs && (Float.isNaN(r1) || Float.isNaN(i1))) { continue; } if (ignoreInfs && (Float.isInfinite(r1) || Float.isInfinite(i1))) { continue; } final double tv = r1 * rv - i1 * iv; iv = r1 * iv + i1 * rv; rv = tv; } rf.set((float) rv, (float) iv, pos); } break; case Dataset.COMPLEX128: ComplexDoubleDataset ad = (ComplexDoubleDataset) a; ComplexDoubleDataset rd = (ComplexDoubleDataset) result; for (int j = 0; j < alen; j++) { if (!Double.isNaN(rv) || !Double.isNaN(iv)) { pos[axis] = j; final double r1 = ad.getReal(pos); final double i1 = ad.getImag(pos); if (ignoreNaNs && (Double.isNaN(r1) || Double.isNaN(i1))) { continue; } if (ignoreInfs && (Double.isInfinite(r1) || Double.isInfinite(i1))) { continue; } final double tv = r1 * rv - i1 * iv; iv = r1 * iv + i1 * rv; rv = tv; } rd.set(rv, iv, pos); } break; } } else { final int is; final long[] lresults; final double[] dresults; switch (dtype) { case Dataset.BOOL: case Dataset.INT8: case Dataset.INT16: case Dataset.INT32: case Dataset.INT64: long lresult = 1; for (int j = 0; j < alen; j++) { pos[axis] = j; lresult *= a.getInt(pos); result.set(lresult, pos); } break; case Dataset.ARRAYINT8: is = a.getElementsPerItem(); lresults = new long[is]; for (int k = 0; k < is; k++) { lresults[k] = 1; } for (int j = 0; j < alen; j++) { pos[axis] = j; final byte[] va = (byte[]) a.getObject(pos); for (int k = 0; k < is; k++) { lresults[k] *= va[k]; } result.set(lresults, pos); } break; case Dataset.ARRAYINT16: is = a.getElementsPerItem(); lresults = new long[is]; for (int k = 0; k < is; k++) { lresults[k] = 1; } for (int j = 0; j < alen; j++) { pos[axis] = j; final short[] va = (short[]) a.getObject(pos); for (int k = 0; k < is; k++) { lresults[k] *= va[k]; } result.set(lresults, pos); } break; case Dataset.ARRAYINT32: is = a.getElementsPerItem(); lresults = new long[is]; for (int k = 0; k < is; k++) { lresults[k] = 1; } for (int j = 0; j < alen; j++) { pos[axis] = j; final int[] va = (int[]) a.getObject(pos); for (int k = 0; k < is; k++) { lresults[k] *= va[k]; } result.set(lresults, pos); } break; case Dataset.ARRAYINT64: is = a.getElementsPerItem(); lresults = new long[is]; for (int k = 0; k < is; k++) { lresults[k] = 1; } for (int j = 0; j < alen; j++) { pos[axis] = j; final long[] va = (long[]) a.getObject(pos); for (int k = 0; k < is; k++) { lresults[k] *= va[k]; } result.set(lresults, pos); } break; case Dataset.FLOAT32: case Dataset.FLOAT64: double dresult = 1.; for (int j = 0; j < alen; j++) { if (!Double.isNaN(dresult)) { pos[axis] = j; final double x = a.getDouble(pos); if (ignoreNaNs && Double.isNaN(x)) { continue; } if (ignoreInfs && Double.isInfinite(x)) { continue; } dresult *= x; } result.set(dresult, pos); } break; case Dataset.ARRAYFLOAT32: case Dataset.ARRAYFLOAT64: is = a.getElementsPerItem(); CompoundDataset da = (CompoundDataset) a; double[] dvalues = new double[is]; dresults = new double[is]; for (int k = 0; k < is; k++) { dresults[k] = 1.; } for (int j = 0; j < alen; j++) { pos[axis] = j; da.getDoubleArray(dvalues, pos); boolean okay = true; for (int k = 0; k < is; k++) { final double val = dvalues[k]; if (ignoreNaNs && Double.isNaN(val)) { okay = false; break; } if (ignoreInfs && Double.isInfinite(val)) { okay = false; break; } } if (okay) { for (int k = 0; k < is; k++) { dresults[k] *= dvalues[k]; } } result.set(dresults, pos); } break; } } } return result; }
From source file:model.experiments.stickyprices.StickyPricesCSVPrinter.java
private static void oneHundredLearningCompetitive(File file) throws IOException { CSVWriter writer = new CSVWriter(new FileWriter(file)); writer.writeNext(new String[] { "production", "price" }); //this will take a looong time //run the test 5 times! for (long i = 0; i < 100; i++) { //create the run MacroII macroII = new MacroII(i); TripolistScenario scenario = new TripolistScenario(macroII); macroII.setScenario(scenario);/*from ww w. j a va 2 s .c o m*/ scenario.setAdditionalCompetitors(4); //set the demand scenario.setAskPricingStrategy(InventoryBufferSalesControl.class); scenario.setControlType( MonopolistScenario.MonopolistScenarioIntegratedControlEnum.MARGINAL_PLANT_CONTROL); //start it and have one step macroII.start(); macroII.schedule.step(macroII); //now set the right parameters for (Firm firm : scenario.getCompetitors()) { final SalesDepartment salesDepartment = firm.getSalesDepartment(UndifferentiatedGoodType.GENERIC); //learning assert salesDepartment.getPredictorStrategy() instanceof RecursiveSalePredictor; } //run the model for (int j = 0; j < 5000; j++) { macroII.schedule.step(macroII); MarginalMaximizerPIDTuning.printProgressBar(5000, j, 100); } //average over the last 500 steps SummaryStatistics prices = new SummaryStatistics(); SummaryStatistics quantities = new SummaryStatistics(); for (int j = 0; j < 500; j++) { macroII.schedule.step(macroII); assert !Float.isNaN(macroII.getMarket(UndifferentiatedGoodType.GENERIC).getTodayAveragePrice()); prices.addValue(macroII.getMarket(UndifferentiatedGoodType.GENERIC).getTodayAveragePrice()); quantities.addValue(macroII.getMarket(UndifferentiatedGoodType.GENERIC).getTodayVolume()); } String[] resultString = new String[2]; resultString[0] = String.valueOf(quantities.getMean()); resultString[1] = String.valueOf(prices.getMean()); System.out.println(Arrays.toString(resultString)); writer.writeNext(resultString); writer.flush(); } writer.close(); }
From source file:com.actelion.research.table.view.JVisualization.java
private void updateColorIndices() { if (mMarkerColor.getColorColumn() == cColumnUnassigned) { for (int i = 0; i < mDataPoints; i++) mPoint[i].colorIndex = VisualizationColor.cDefaultDataColorIndex; } else if (CompoundTableHitlistHandler.isHitlistColumn(mMarkerColor.getColorColumn())) { int hitlistIndex = CompoundTableHitlistHandler.getHitlistFromColumn(mMarkerColor.getColorColumn()); int flagNo = mTableModel.getHitlistHandler().getHitlistFlagNo(hitlistIndex); for (int i = 0; i < mDataPoints; i++) mPoint[i].colorIndex = (byte) (mPoint[i].record.isFlagSet(flagNo) ? VisualizationColor.cSpecialColorCount : VisualizationColor.cSpecialColorCount + 1); } else if (mTableModel.isDescriptorColumn(mMarkerColor.getColorColumn())) { setSimilarityColors(-1);/*from w w w . j ava 2s . c o m*/ } else if (mMarkerColor.getColorListMode() == VisualizationColor.cColorListModeCategories) { for (int i = 0; i < mDataPoints; i++) mPoint[i].colorIndex = (byte) (VisualizationColor.cSpecialColorCount + mTableModel.getCategoryIndex(mMarkerColor.getColorColumn(), mPoint[i].record)); } else if (mTableModel.isColumnTypeDouble(mMarkerColor.getColorColumn())) { float min = Float.isNaN(mMarkerColor.getColorMin()) ? mTableModel.getMinimumValue(mMarkerColor.getColorColumn()) : (mTableModel.isLogarithmicViewMode(mMarkerColor.getColorColumn())) ? (float) Math.log10(mMarkerColor.getColorMin()) : mMarkerColor.getColorMin(); float max = Float.isNaN(mMarkerColor.getColorMax()) ? mTableModel.getMaximumValue(mMarkerColor.getColorColumn()) : (mTableModel.isLogarithmicViewMode(mMarkerColor.getColorColumn())) ? (float) Math.log10(mMarkerColor.getColorMax()) : mMarkerColor.getColorMax(); // 1. colorMin is explicitly set; max is real max, but lower than min // or 2. colorMax is explicitly set; min is real min, but larger than max // first case is OK, second needs adaption below to be handled as indented if (min >= max) if (!Float.isNaN(mMarkerColor.getColorMax())) min = Float.MIN_VALUE; for (int i = 0; i < mDataPoints; i++) { float value = mPoint[i].record.getDouble(mMarkerColor.getColorColumn()); if (Float.isNaN(value)) mPoint[i].colorIndex = VisualizationColor.cMissingDataColorIndex; else if (value <= min) mPoint[i].colorIndex = (byte) VisualizationColor.cSpecialColorCount; else if (value >= max) mPoint[i].colorIndex = (byte) (mMarkerColor.getColorList().length - 1); else mPoint[i].colorIndex = (byte) (0.5 + VisualizationColor.cSpecialColorCount + (float) (mMarkerColor.getColorList().length - VisualizationColor.cSpecialColorCount - 1) * (value - min) / (max - min)); } } invalidateOffImage(true); }
From source file:au.org.ala.layers.intersect.Grid.java
public void printMinMax() { float min = Float.MAX_VALUE; float max = -1 * Float.MAX_VALUE; float[] data = this.getGrid(); int numMissing = 0; for (float d : data) { if (Float.isNaN(d)) { numMissing++;/*w ww . j a v a 2 s .c o m*/ } if (d < min) { min = d; } if (d > max) { max = d; } } if (min != this.minval || max != this.maxval) { logger.error(this.filename + " ERR header(" + this.minval + " " + this.maxval + ") actual(" + min + " " + max + ") number missing(" + numMissing + " of " + data.length + ")"); } else { logger.error(this.filename + " OK header(" + this.minval + " " + this.maxval + ") number missing(" + numMissing + " of " + data.length + ")"); } }
From source file:com.taobao.weex.ui.component.WXComponent.java
/** * This is an experimental feature for elevation of material design. *//*ww w .j av a2 s . c o m*/ private void updateElevation() { float elevation = getDomObject().getAttrs().getElevation(getInstance().getViewPortWidth()); if (!Float.isNaN(elevation)) { ViewCompat.setElevation(getHostView(), elevation); } }
From source file:org.eclipse.dataset.Stats.java
/** * @param a// w w w .j a va 2 s. c o m * @param ignoreNaNs if true, skip NaNs * @param axis * @return cumulative sum of items along axis in dataset */ public static Dataset cumulativeSum(final Dataset a, boolean ignoreNaNs, int axis) { axis = a.checkAxis(axis); int dtype = a.getDtype(); int[] oshape = a.getShape(); int alen = oshape[axis]; oshape[axis] = 1; Dataset result = DatasetFactory.zeros(a); PositionIterator pi = result.getPositionIterator(axis); int[] pos = pi.getPos(); while (pi.hasNext()) { if (a.isComplex()) { double rv = 0, iv = 0; switch (dtype) { case Dataset.COMPLEX64: ComplexFloatDataset af = (ComplexFloatDataset) a; if (ignoreNaNs) { for (int j = 0; j < alen; j++) { pos[axis] = j; final float x = af.getReal(pos); final float y = af.getImag(pos); if (Float.isNaN(x) || Float.isNaN(y)) continue; rv += x; iv += y; af.set((float) rv, (float) iv, pos); } } else { for (int j = 0; j < alen; j++) { pos[axis] = j; rv += af.getReal(pos); iv += af.getImag(pos); af.set((float) rv, (float) iv, pos); } } break; case Dataset.COMPLEX128: ComplexDoubleDataset ad = (ComplexDoubleDataset) a; if (ignoreNaNs) { for (int j = 0; j < alen; j++) { pos[axis] = j; final double x = ad.getReal(pos); final double y = ad.getImag(pos); if (Double.isNaN(x) || Double.isNaN(y)) continue; rv += x; iv += y; ad.set(rv, iv, pos); } } else { for (int j = 0; j < alen; j++) { pos[axis] = j; rv += ad.getReal(pos); iv += ad.getImag(pos); ad.set(rv, iv, pos); } } break; } result.set(new Complex(rv, iv), pos); } else { final int is; final long[] lresults; final double[] dresults; switch (dtype) { case Dataset.BOOL: case Dataset.INT8: case Dataset.INT16: case Dataset.INT32: case Dataset.INT64: long lresult = 0; for (int j = 0; j < alen; j++) { pos[axis] = j; lresult += a.getInt(pos); result.set(lresult, pos); } break; case Dataset.ARRAYINT8: is = a.getElementsPerItem(); lresults = new long[is]; for (int j = 0; j < alen; j++) { pos[axis] = j; final byte[] va = (byte[]) a.getObject(pos); for (int k = 0; k < is; k++) { lresults[k] += va[k]; } result.set(lresults, pos); } break; case Dataset.ARRAYINT16: is = a.getElementsPerItem(); lresults = new long[is]; for (int j = 0; j < alen; j++) { pos[axis] = j; final short[] va = (short[]) a.getObject(pos); for (int k = 0; k < is; k++) { lresults[k] += va[k]; } result.set(lresults, pos); } break; case Dataset.ARRAYINT32: is = a.getElementsPerItem(); lresults = new long[is]; for (int j = 0; j < alen; j++) { pos[axis] = j; final int[] va = (int[]) a.getObject(pos); for (int k = 0; k < is; k++) { lresults[k] += va[k]; } result.set(lresults, pos); } break; case Dataset.ARRAYINT64: is = a.getElementsPerItem(); lresults = new long[is]; for (int j = 0; j < alen; j++) { pos[axis] = j; final long[] va = (long[]) a.getObject(pos); for (int k = 0; k < is; k++) { lresults[k] += va[k]; } result.set(lresults, pos); } break; case Dataset.FLOAT32: case Dataset.FLOAT64: double dresult = 0.; if (ignoreNaNs) { for (int j = 0; j < alen; j++) { pos[axis] = j; final double x = a.getDouble(pos); if (Double.isNaN(x)) continue; dresult += x; result.set(dresult, pos); } } else { for (int j = 0; j < alen; j++) { pos[axis] = j; dresult += a.getDouble(pos); result.set(dresult, pos); } } break; case Dataset.ARRAYFLOAT32: is = a.getElementsPerItem(); dresults = new double[is]; if (ignoreNaNs) { for (int j = 0; j < alen; j++) { pos[axis] = j; final float[] va = (float[]) a.getObject(pos); boolean skip = false; for (int k = 0; k < is; k++) { if (Float.isNaN(va[k])) { skip = true; break; } } if (!skip) for (int k = 0; k < is; k++) { dresults[k] += va[k]; } result.set(dresults, pos); } } else { for (int j = 0; j < alen; j++) { pos[axis] = j; final float[] va = (float[]) a.getObject(pos); for (int k = 0; k < is; k++) { dresults[k] += va[k]; } result.set(dresults, pos); } } break; case Dataset.ARRAYFLOAT64: is = a.getElementsPerItem(); dresults = new double[is]; if (ignoreNaNs) { for (int j = 0; j < alen; j++) { pos[axis] = j; final double[] va = (double[]) a.getObject(pos); boolean skip = false; for (int k = 0; k < is; k++) { if (Double.isNaN(va[k])) { skip = true; break; } } if (!skip) for (int k = 0; k < is; k++) { dresults[k] += va[k]; } result.set(dresults, pos); } } else { for (int j = 0; j < alen; j++) { pos[axis] = j; final double[] va = (double[]) a.getObject(pos); for (int k = 0; k < is; k++) { dresults[k] += va[k]; } result.set(dresults, pos); } } break; } } } return result; }
From source file:org.eclipse.january.dataset.Stats.java
/** * @param a dataset/*from w ww .j a va 2 s .co m*/ * @param axis * @param ignoreInvalids see {@link Dataset#max(int, boolean...)} * @return cumulative sum of items along axis in dataset * @since 2.0 */ public static Dataset cumulativeSum(final Dataset a, int axis, final boolean... ignoreInvalids) { axis = a.checkAxis(axis); int dtype = a.getDType(); int[] oshape = a.getShape(); int alen = oshape[axis]; oshape[axis] = 1; final boolean ignoreNaNs; final boolean ignoreInfs; if (a.hasFloatingPointElements()) { ignoreNaNs = ignoreInvalids != null && ignoreInvalids.length > 0 ? ignoreInvalids[0] : false; ignoreInfs = ignoreInvalids != null && ignoreInvalids.length > 1 ? ignoreInvalids[1] : ignoreNaNs; } else { ignoreNaNs = false; ignoreInfs = false; } Dataset result = DatasetFactory.zeros(a); PositionIterator pi = result.getPositionIterator(axis); int[] pos = pi.getPos(); while (pi.hasNext()) { if (a.isComplex()) { double rv = 0, iv = 0; switch (dtype) { case Dataset.COMPLEX64: ComplexFloatDataset af = (ComplexFloatDataset) a; ComplexFloatDataset rf = (ComplexFloatDataset) result; for (int j = 0; j < alen; j++) { if (!Double.isNaN(rv) || !Double.isNaN(iv)) { pos[axis] = j; final float r1 = af.getReal(pos); final float i1 = af.getImag(pos); if (ignoreNaNs && (Float.isNaN(r1) || Float.isNaN(i1))) { continue; } if (ignoreInfs && (Float.isInfinite(r1) || Float.isInfinite(i1))) { continue; } rv += r1; iv += i1; } rf.set((float) rv, (float) iv, pos); } break; case Dataset.COMPLEX128: ComplexDoubleDataset ad = (ComplexDoubleDataset) a; ComplexDoubleDataset rd = (ComplexDoubleDataset) result; for (int j = 0; j < alen; j++) { if (!Double.isNaN(rv) || !Double.isNaN(iv)) { pos[axis] = j; final double r1 = ad.getReal(pos); final double i1 = ad.getImag(pos); if (ignoreNaNs && (Double.isNaN(r1) || Double.isNaN(i1))) { continue; } if (ignoreInfs && (Double.isInfinite(r1) || Double.isInfinite(i1))) { continue; } rv += r1; iv += i1; } rd.set(rv, iv, pos); } break; } } else { final int is; final long[] lresults; final double[] dresults; switch (dtype) { case Dataset.BOOL: case Dataset.INT8: case Dataset.INT16: case Dataset.INT32: case Dataset.INT64: long lresult = 0; for (int j = 0; j < alen; j++) { pos[axis] = j; lresult += a.getInt(pos); result.set(lresult, pos); } break; case Dataset.ARRAYINT8: is = a.getElementsPerItem(); lresults = new long[is]; for (int j = 0; j < alen; j++) { pos[axis] = j; final byte[] va = (byte[]) a.getObject(pos); for (int k = 0; k < is; k++) { lresults[k] += va[k]; } result.set(lresults, pos); } break; case Dataset.ARRAYINT16: is = a.getElementsPerItem(); lresults = new long[is]; for (int j = 0; j < alen; j++) { pos[axis] = j; final short[] va = (short[]) a.getObject(pos); for (int k = 0; k < is; k++) { lresults[k] += va[k]; } result.set(lresults, pos); } break; case Dataset.ARRAYINT32: is = a.getElementsPerItem(); lresults = new long[is]; for (int j = 0; j < alen; j++) { pos[axis] = j; final int[] va = (int[]) a.getObject(pos); for (int k = 0; k < is; k++) { lresults[k] += va[k]; } result.set(lresults, pos); } break; case Dataset.ARRAYINT64: is = a.getElementsPerItem(); lresults = new long[is]; for (int j = 0; j < alen; j++) { pos[axis] = j; final long[] va = (long[]) a.getObject(pos); for (int k = 0; k < is; k++) { lresults[k] += va[k]; } result.set(lresults, pos); } break; case Dataset.FLOAT32: case Dataset.FLOAT64: double dresult = 0.; for (int j = 0; j < alen; j++) { if (!Double.isNaN(dresult)) { pos[axis] = j; final double x = a.getDouble(pos); if (ignoreNaNs && Double.isNaN(x)) { continue; } if (ignoreInfs && Double.isInfinite(x)) { continue; } dresult += x; } result.set(dresult, pos); } break; case Dataset.ARRAYFLOAT32: case Dataset.ARRAYFLOAT64: is = a.getElementsPerItem(); CompoundDataset da = (CompoundDataset) a; double[] dvalues = new double[is]; dresults = new double[is]; for (int j = 0; j < alen; j++) { pos[axis] = j; da.getDoubleArray(dvalues, pos); boolean okay = true; for (int k = 0; k < is; k++) { final double val = dvalues[k]; if (ignoreNaNs && Double.isNaN(val)) { okay = false; break; } if (ignoreInfs && Double.isInfinite(val)) { okay = false; break; } } if (okay) { for (int k = 0; k < is; k++) { dresults[k] += dvalues[k]; } } result.set(dresults, pos); } break; } } } return result; }
From source file:com.actelion.research.table.view.JVisualization.java
/** * @param rowID if != -1 then update this row only *//*from ww w . j av a2s. co m*/ private void setSimilarityColors(int rowID) { if (mActivePoint == null) { for (int i = 0; i < mDataPoints; i++) mPoint[i].colorIndex = VisualizationColor.cDefaultDataColorIndex; } else { float min = Float.isNaN(mMarkerColor.getColorMin()) ? 0.0f : mMarkerColor.getColorMin(); float max = Float.isNaN(mMarkerColor.getColorMax()) ? 1.0f : mMarkerColor.getColorMax(); if (min >= max) { min = 0.0f; max = 1.0f; } int column = mMarkerColor.getColorColumn(); float[] flexophoreSimilarity = null; if (rowID == -1 && DescriptorConstants.DESCRIPTOR_Flexophore.shortName .equals(mTableModel.getColumnSpecialType(column))) { // if we have the slow 3DPPMM2 then use a progress dialog and multi-threading Object descriptor = mActivePoint.record.getData(column); if (descriptor != null) { Component c = this; while (!(c instanceof Frame)) c = c.getParent(); String idcode = new String( (byte[]) mActivePoint.record.getData(mTableModel.getParentColumn(column))); flexophoreSimilarity = createSimilarityListSMP(idcode, descriptor, column); if (flexophoreSimilarity == null) { // cancelled mMarkerColor.setColor(cColumnUnassigned); return; } } } for (int i = 0; i < mDataPoints; i++) { if (rowID == -1 || mActivePoint.record.getID() == rowID) { float similarity = (flexophoreSimilarity != null) ? flexophoreSimilarity[i] : mTableModel.getDescriptorSimilarity(mActivePoint.record, mPoint[i].record, column); if (Float.isNaN(similarity)) mPoint[i].colorIndex = VisualizationColor.cMissingDataColorIndex; else if (similarity <= min) mPoint[i].colorIndex = (byte) VisualizationColor.cSpecialColorCount; else if (similarity >= max) mPoint[i].colorIndex = (byte) (mMarkerColor.getColorList().length - 1); else mPoint[i].colorIndex = (byte) (0.5 + VisualizationColor.cSpecialColorCount + (float) (mMarkerColor.getColorList().length - VisualizationColor.cSpecialColorCount - 1) * (similarity - min) / (max - min)); } } } }
From source file:com.yahoo.egads.models.tsmm.TestOlympicModel2.java
@Test public void predict() throws Exception { OlympicModel2 model = new OlympicModel2(config); TimeSeries ts = new TimeSeries(); ts.append(1475452800, 10);// w ww.j a v a 2s . c om ts.append(1475453100, 25); ts.append(1476057600, 20); ts.append(1476057900, 45); ts.append(1476662400, 30); ts.append(1476662700, 55); ts.append(1477267200, 40); ts.append(1477267500, 65); model.train(ts.data); ts.append(1477872000, Float.NaN); ts.append(1477872300, Float.NaN); model.predict(ts.data); assertEquals(1477872000, ts.data.get(8).time); assertEquals(25, ts.data.get(8).value, 0.0001); assertEquals(1477872300, ts.data.get(9).time); assertEquals(47.5, ts.data.get(9).value, 0.0001); assertEquals(10, ts.data.size()); // new series ts = new TimeSeries(); ts.append(1477872000, Float.NaN); ts.append(1477872300, Float.NaN); model.predict(ts.data); assertEquals(1477872000, ts.data.get(0).time); assertEquals(25, ts.data.get(0).value, 0.0001); assertEquals(1477872300, ts.data.get(1).time); assertEquals(47.5, ts.data.get(1).value, 0.0001); assertEquals(2, ts.data.size()); // missing later point ts = new TimeSeries(); ts.append(1477872000, Float.NaN); model.predict(ts.data); assertEquals(1477872000, ts.data.get(0).time); assertEquals(25, ts.data.get(0).value, 0.0001); assertEquals(1, ts.data.size()); // missing first point ts = new TimeSeries(); ts.append(1477872300, Float.NaN); model.predict(ts.data); assertEquals(1477872300, ts.data.get(0).time); assertEquals(47.5, ts.data.get(0).value, 0.0001); assertEquals(1, ts.data.size()); // higher resolution sequence than model ts = new TimeSeries(); ts.append(1477872000, Float.NaN); ts.append(1477872060, Float.NaN); ts.append(1477872120, Float.NaN); ts.append(1477872180, Float.NaN); ts.append(1477872240, Float.NaN); ts.append(1477872300, Float.NaN); ts.append(1477872360, Float.NaN); model.predict(ts.data); assertEquals(1477872000, ts.data.get(0).time); assertEquals(25.0, ts.data.get(0).value, 0.0001); assertEquals(1477872060, ts.data.get(1).time); assertTrue(Float.isNaN(ts.data.get(1).value)); assertEquals(1477872120, ts.data.get(2).time); assertTrue(Float.isNaN(ts.data.get(2).value)); assertEquals(1477872180, ts.data.get(3).time); assertTrue(Float.isNaN(ts.data.get(3).value)); assertEquals(1477872240, ts.data.get(4).time); assertTrue(Float.isNaN(ts.data.get(4).value)); assertEquals(1477872300, ts.data.get(5).time); assertEquals(47.5, ts.data.get(5).value, 0.0001); assertEquals(1477872360, ts.data.get(6).time); assertTrue(Float.isNaN(ts.data.get(6).value)); assertEquals(7, ts.data.size()); }