/** * * @param func * @param x0 * @param f0 * @param h * @param oneSided * @return */ public static INDArray denseDifference(Function<INDArray,INDArray> func, INDArray x0,INDArray f0, INDArray h,INDArray oneSided) { INDArray hVecs = Nd4j.diag(h.reshape(1,h.length())); INDArray dx,df,x; INDArray jTransposed = Nd4j.create(x0.length(),f0.length()); for(int i = 0; i < h.length(); i++) { INDArray hVecI = hVecs.slice(i); x = (x0.add(hVecI)); dx = x.slice(i).sub(x0.slice(i)); df = func.apply(x).sub(f0); INDArray div = df.div(dx); jTransposed.putSlice(i,div); } if(f0.length() == 1) jTransposed = jTransposed.ravel(); return jTransposed; }
/** * Convert a file to a row vector * * @param f the image to convert * @return the flattened image * @throws IOException */ @Override public INDArray asRowVector(File f) throws IOException { return asMatrix(f).ravel(); }
/** * Convert a file to a row vector * * @param f the image to convert * @return the flattened image * @throws IOException */ @Override public INDArray asRowVector(File f) throws IOException { return asMatrix(f).ravel(); }
/** * Returns {@code asMatrix(image, false).ravel()}. */ public INDArray asRowVector(BufferedImage image) throws IOException { return asMatrix(image, false).ravel(); }
/** * Returns {@code asMatrix(image, flipChannels).ravel()}. */ public INDArray asRowVector(BufferedImage image, boolean flipChannels) throws IOException { return asMatrix(image, flipChannels).ravel(); }
/** * Returns {@code asMatrix(image).ravel()}. * @see #asMatrix(Object) */ public INDArray asRowVector(Object image) throws IOException { return asMatrix(image).ravel(); }
/** * Changes the input stream in to an * bgr based raveled(flattened) vector * @param is the input stream to convert * @return the raveled bgr values for this input stream */ public INDArray toRaveledTensor(InputStream is) { return toBgr(is).ravel(); }
/** * Changes the input stream in to an * bgr based raveled(flattened) vector * @param is the input stream to convert * @return the raveled bgr values for this input stream */ public INDArray toRaveledTensor(InputStream is) { return toBgr(is).ravel(); }
public INDArray asRowVector(Mat image) throws IOException { return asMatrix(image).ravel(); }
public INDArray asRowVector(Mat image) throws IOException { return asMatrix(image).ravel(); }
@Override public INDArray asRowVector(InputStream is) throws IOException { return asMatrix(is).ravel(); }
@Override public INDArray asRowVector(InputStream is) throws IOException { return asMatrix(is).ravel(); }
public INDArray asRowVector(Bitmap image) throws IOException { return asMatrix(image).ravel(); }
/** * Changes the input stream in to an * bgr based raveled(flattened) vector * @param file the input stream to convert * @return the raveled bgr values for this input stream */ public INDArray toRaveledTensor(File file) { try { BufferedInputStream bis = new BufferedInputStream(new FileInputStream(file)); INDArray ret = toRaveledTensor(bis); bis.close(); return ret.ravel(); } catch (IOException e) { throw new RuntimeException(e); } }
/** * Changes the input stream in to an * bgr based raveled(flattened) vector * @param file the input stream to convert * @return the raveled bgr values for this input stream */ public INDArray toRaveledTensor(File file) { try { BufferedInputStream bis = new BufferedInputStream(new FileInputStream(file)); INDArray ret = toRaveledTensor(bis); bis.close(); return ret.ravel(); } catch (IOException e) { throw new RuntimeException(e); } } /**
/** * Convert an image in to a raveled tensor of * the bgr values of the image * @param image the image to parse * @return the raveled tensor of bgr values */ public INDArray toRaveledTensor(BufferedImage image) { try { image = scalingIfNeed(image, false); return toINDArrayBGR(image).ravel(); } catch (Exception e) { throw new RuntimeException("Unable to load image", e); } }
/** * Convert an image in to a raveled tensor of * the bgr values of the image * @param image the image to parse * @return the raveled tensor of bgr values */ public INDArray toRaveledTensor(BufferedImage image) { try { image = scalingIfNeed(image, false); return toINDArrayBGR(image).ravel(); } catch (Exception e) { throw new RuntimeException("Unable to load image", e); } }
public double varManual(INDArray x, double mean) { INDArray xSubMean = x.sub(mean); INDArray squared = xSubMean.muli(xSubMean); double accum = Nd4j.getExecutioner().execAndReturn(new Sum(squared)).getFinalResult().doubleValue(); return accum / x.ravel().length(); }
/** * Convert an image in to a row vector * @param image the image to convert * @return the row vector based on a rastered * representation of the image */ public INDArray asRowVector(BufferedImage image) { if (centerCropIfNeeded) { image = centerCropIfNeeded(image); } image = scalingIfNeed(image, true); if (channels == 3) { return toINDArrayBGR(image).ravel(); } int[][] ret = toIntArrayArray(image); return NDArrayUtil.toNDArray(ArrayUtil.flatten(ret)); }
/** * Convert an image in to a row vector * @param image the image to convert * @return the row vector based on a rastered * representation of the image */ public INDArray asRowVector(BufferedImage image) { if (centerCropIfNeeded) { image = centerCropIfNeeded(image); } image = scalingIfNeed(image, true); if(channels == 3) { return toINDArrayBGR(image).ravel(); } int[][] ret = toIntArrayArray(image); return NDArrayUtil.toNDArray(ArrayUtil.flatten(ret)); }