/** * Copies the values from the given Collection. It does this by iterating * through collection and initializing by iterating through them * in the order specified by the collection. Thus, this should probably * not be used with collections that do not have a very well determined * iteration order, like a HashSet (as such, LinkedHashSet may be a better * option to preserve insertion order). * * @param values * Values to create a vector from. Cannot be null and cannot contain * null values. * @return * A vector of dimensionality equal to the size of the given * collection and whose values are initialized to the values in the * collection in order of iteration. */ public VectorType copyValues( final Collection<? extends Number> values) { final VectorType v = this.createVector(values.size()); int index = 0; for (final Number value : values) { v.set(index, value.doubleValue()); index++; } return v; }
/** * Copies the values from the given Collection. It does this by iterating * through collection and initializing by iterating through them * in the order specified by the collection. Thus, this should probably * not be used with collections that do not have a very well determined * iteration order, like a HashSet (as such, LinkedHashSet may be a better * option to preserve insertion order). * * @param values * Values to create a vector from. Cannot be null and cannot contain * null values. * @return * A vector of dimensionality equal to the size of the given * collection and whose values are initialized to the values in the * collection in order of iteration. */ public VectorType copyValues( final Collection<? extends Number> values) { final VectorType v = this.createVector(values.size()); int index = 0; for (final Number value : values) { v.set(index, value.doubleValue()); index++; } return v; }
/** * Copies the values from the given Collection. It does this by iterating * through collection and initializing by iterating through them * in the order specified by the collection. Thus, this should probably * not be used with collections that do not have a very well determined * iteration order, like a HashSet (as such, LinkedHashSet may be a better * option to preserve insertion order). * * @param values * Values to create a vector from. Cannot be null and cannot contain * null values. * @return * A vector of dimensionality equal to the size of the given * collection and whose values are initialized to the values in the * collection in order of iteration. */ public VectorType copyValues( final Collection<? extends Number> values) { final VectorType v = this.createVector(values.size()); int index = 0; for (final Number value : values) { v.set(index, value.doubleValue()); index++; } return v; }
/** * Creates a vector from the given map of indices to values. * * @param dimensionality * The dimensionality of the vector. Cannot be negative. * @param map * The map of indices to values to fill in the vector. All indices * must be 0-based and between 0 (inclusive) and dimensionality * (exclusive). Cannot be null. * @return * A new vector with elements initialized to the ones in the map. */ public VectorType copyMap( final int dimensionality, final Map<Integer, ? extends Number> map) { ArgumentChecker.assertIsNotNull("map", map); final VectorType result = this.createVectorCapacity(dimensionality, map.size()); for (final Map.Entry<Integer, ? extends Number> entry : map.entrySet()) { result.set(entry.getKey(), entry.getValue().doubleValue()); } return result; }
/** * Creates a vector from the given map of indices to values. * * @param dimensionality * The dimensionality of the vector. Cannot be negative. * @param map * The map of indices to values to fill in the vector. All indices * must be 0-based and between 0 (inclusive) and dimensionality * (exclusive). Cannot be null. * @return * A new vector with elements initialized to the ones in the map. */ public VectorType copyMap( final int dimensionality, final Map<Integer, ? extends Number> map) { ArgumentChecker.assertIsNotNull("map", map); final VectorType result = this.createVectorCapacity(dimensionality, map.size()); for (final Map.Entry<Integer, ? extends Number> entry : map.entrySet()) { result.set(entry.getKey(), entry.getValue().doubleValue()); } return result; }
/** * Creates a vector from the given map of indices to values. * * @param dimensionality * The dimensionality of the vector. Cannot be negative. * @param map * The map of indices to values to fill in the vector. All indices * must be 0-based and between 0 (inclusive) and dimensionality * (exclusive). Cannot be null. * @return * A new vector with elements initialized to the ones in the map. */ public VectorType copyMap( final int dimensionality, final Map<Integer, ? extends Number> map) { ArgumentChecker.assertIsNotNull("map", map); final VectorType result = this.createVectorCapacity(dimensionality, map.size()); for (final Map.Entry<Integer, ? extends Number> entry : map.entrySet()) { result.set(entry.getKey(), entry.getValue().doubleValue()); } return result; }
this.inputsTransposed.get(entry.getIndex()).set(i, entry.getValue());
this.inputsTransposed.get(entry.getIndex()).set(i, entry.getValue());
this.inputsTransposed.get(entry.getIndex()).set(i, entry.getValue());
@Override public Vector sample( final Random random) { // Create the result vector. final int K = this.getParameters().getDimensionality(); final Vector y = VectorFactory.getDenseDefault().createVector(K); double sum = 0.0; for (int i = 0; i < K; i++) { final double yi = GammaDistribution.sampleStandard( this.parameters.get(i), random); y.set(i, yi); sum += yi; } if (sum != 0.0) { y.scaleEquals(1.0 / sum); } return y; }
@Override public Vector sample( final Random random) { // Create the result vector. final int K = this.getParameters().getDimensionality(); final Vector y = VectorFactory.getDenseDefault().createVector(K); double sum = 0.0; for (int i = 0; i < K; i++) { final double yi = GammaDistribution.sampleStandard( this.parameters.get(i), random); y.set(i, yi); sum += yi; } if (sum != 0.0) { y.scaleEquals(1.0 / sum); } return y; }
@Override public Vector sample( final Random random) { // Create the result vector. final int K = this.getParameters().getDimensionality(); final Vector y = VectorFactory.getDenseDefault().createVector(K); double sum = 0.0; for (int i = 0; i < K; i++) { final double yi = GammaDistribution.sampleStandard( this.parameters.get(i), random); y.set(i, yi); sum += yi; } if (sum != 0.0) { y.scaleEquals(1.0 / sum); } return y; }
y.set(i, yin); sum += yin;
y.set(i, yin); sum += yin;
y.set(i, yin); sum += yin;
final double actual = example.getOutput(); final double error = actual - prediction; errors.set(i, error); (oldWeight * sumOfSquares + derivative.dot(errors)) / (sumOfSquares + this.weightRegularization); weights.set(j, newWeight); for (int i = 0; i < this.dataSize; i++) factorTimesInput.set(i, this.dataList.get(i).getInput().dot(factorRow));
final double actual = example.getOutput(); final double error = actual - prediction; errors.set(i, error); (oldWeight * sumOfSquares + derivative.dot(errors)) / (sumOfSquares + this.weightRegularization); weights.set(j, newWeight); for (int i = 0; i < this.dataSize; i++) factorTimesInput.set(i, this.dataList.get(i).getInput().dot(factorRow));
final double actual = example.getOutput(); final double error = actual - prediction; errors.set(i, error); (oldWeight * sumOfSquares + derivative.dot(errors)) / (sumOfSquares + this.weightRegularization); weights.set(j, newWeight); for (int i = 0; i < this.dataSize; i++) factorTimesInput.set(i, this.dataList.get(i).getInput().dot(factorRow));