@Override public void dotTimesEquals( final Vector other) { // This is a generic implementation to support interoperability. // Sub-classes should make custom ones for performance. this.assertSameDimensionality(other); for (final VectorEntry entry : this) { entry.setValue(entry.getValue() * other.get(entry.getIndex())); } }
private Matrix prepareMatrix(Vector y) { final Matrix Y = DMF.createMatrix(1, y.getDimensionality() + 1); Y.setElement(0, 0, 1); Y.setSubMatrix(0, 1, DMF.copyRowVectors(y)); return Y.transpose(); }
@Override public void assertSameDimensions( Matrix other ) { if (!this.checkSameDimensions(other)) { throw new DimensionalityMismatchException( "Matrices must have same dimensions: " + "(" + this.getNumRows() + "x" + this.getNumColumns() + ") !=" + "(" + other.getNumRows() + "x" + other.getNumColumns() + ")" ); } }
private Matrix repmat(Matrix dL1, int nRows, int nCols) { final Matrix out = DMF.createMatrix(nRows * dL1.getNumRows(), nCols * dL1.getNumColumns()); for (int i = 0; i < nRows; i++) { for (int j = 0; j < nCols; j++) { out.setSubMatrix(i * dL1.getNumRows(), j * dL1.getNumColumns(), dL1); } } return out; }
/** * Creates a new instance of MultivariateGaussian. * * @param dimensionality Dimensionality of the Gaussian to create. */ public MultivariateGaussian( int dimensionality) { this(VectorFactory.getDefault().createVector(dimensionality), MatrixFactory.getDefault().createIdentity(dimensionality, dimensionality)); }
/** * Creates a new instance of MultivariateDiscriminantWithBias. * * @param discriminant internal matrix to premultiply input vectors by. */ public MultivariateDiscriminantWithBias( final Matrix discriminant ) { this( discriminant, VectorFactory.getDefault().createVector(discriminant.getNumRows()) ); }
@Override public boolean checkSameDimensionality( final Vector other ) { return (this.getDimensionality() == other.getDimensionality()); }
@Override public double evaluate( final Vectorizable first, final Vectorizable second) { return first.convertToVector().minus( second.convertToVector()).norm(this.power); }
@Override public void assertDimensionalityEquals( final int otherDimensionality) { if (this.getDimensionality() != otherDimensionality) { throw new DimensionalityMismatchException( this.getDimensionality(), otherDimensionality); } }
public Vector evaluate( final Vectorizable input) { // Apply the transform to the input vector. return input.convertToVector().times(this.transform); }
@Override public void forEachElement( final IndexValueConsumer consumer) { // This is by definition a dense iteration. final int dimensionality = this.getDimensionality(); for (int i = 0; i < dimensionality; i++) { consumer.consume(i, this.get(i)); } }
/** * Creates a new instance of MatrixReader * * * @param reader Java reader stream from which to pull the data */ public MatrixReader( Reader reader ) { this.setInternalReader( new VectorReader( reader ) ); }
@Override public double euclideanDistanceSquared( final InfiniteVector<KeyType> other) { return this.minus(other).norm2Squared(); }
@Override public InfiniteVector<KeyType> plus( final InfiniteVector<KeyType> other) { final InfiniteVector<KeyType> result = this.clone(); result.plusEquals(other); return result; }
@Override public InfiniteVector<KeyType> minus( final InfiniteVector<KeyType> other) { final InfiniteVector<KeyType> result = this.clone(); result.minusEquals(other); return result; }
private Matrix prepareMatrix(Vector y) { final Matrix Y = DMF.createMatrix(1, y.getDimensionality() + 1); Y.setElement(0, 0, 1); Y.setSubMatrix(0, 1, DMF.copyRowVectors(y)); return Y.transpose(); }
/** * Creates a distribution with the given dimensionality. * @param dimensionality * Dimensionality of the distribution. */ public MultivariateStudentTDistribution( int dimensionality ) { this( DEFAULT_DEGREES_OF_FREEDOM, VectorFactory.getDefault().createVector(dimensionality), MatrixFactory.getDefault().createIdentity(dimensionality,dimensionality) ); }
@Override public void assertSameDimensions( Matrix other ) { if (!this.checkSameDimensions(other)) { throw new DimensionalityMismatchException( "Matrices must have same dimensions: " + "(" + this.getNumRows() + "x" + this.getNumColumns() + ") !=" + "(" + other.getNumRows() + "x" + other.getNumColumns() + ")" ); } }
@Override public void dotTimesEquals( final Vector other) { // This is a generic implementation to support interoperability. // Sub-classes should make custom ones for performance. this.assertSameDimensionality(other); for (final VectorEntry entry : this) { entry.setValue(entry.getValue() * other.get(entry.getIndex())); } }
@Override public void dotTimesEquals( final Vector other) { // This is a generic implementation to support interoperability. // Sub-classes should make custom ones for performance. this.assertSameDimensionality(other); for (final VectorEntry entry : this) { entry.setValue(entry.getValue() * other.get(entry.getIndex())); } }