cern.colt.function.DoubleFunction Java Examples

The following examples show how to use cern.colt.function.DoubleFunction. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: Functions.java    From jAudioGIT with GNU Lesser General Public License v2.1 6 votes vote down vote up
/**
 * Demonstrates usage of this class.
 */
public static void demo1() {
	cern.jet.math.Functions F = cern.jet.math.Functions.functions;
	double a = 0.5; 
	double b = 0.2;
	double v = Math.sin(a) + Math.pow(Math.cos(b),2);
	System.out.println(v);
	DoubleDoubleFunction f = F.chain(F.plus,F.sin,F.chain(F.square,F.cos));
	//DoubleDoubleFunction f = F.chain(plus,sin,F.chain(square,cos));
	System.out.println(f.apply(a,b));
	DoubleDoubleFunction g = new DoubleDoubleFunction() {
		public final double apply(double x, double y) { return Math.sin(x) + Math.pow(Math.cos(y),2); }
	};
	System.out.println(g.apply(a,b));
	DoubleFunction m = F.plus(3);
	DoubleFunction n = F.plus(4);
	System.out.println(m.apply(0));
	System.out.println(n.apply(0));
}
 
Example #2
Source File: Functions.java    From database with GNU General Public License v2.0 6 votes vote down vote up
/**
 * Demonstrates usage of this class.
 */
public static void demo1() {
	cern.jet.math.Functions F = cern.jet.math.Functions.functions;
	double a = 0.5; 
	double b = 0.2;
	double v = Math.sin(a) + Math.pow(Math.cos(b),2);
	System.out.println(v);
	DoubleDoubleFunction f = F.chain(F.plus,F.sin,F.chain(F.square,F.cos));
	//DoubleDoubleFunction f = F.chain(plus,sin,F.chain(square,cos));
	System.out.println(f.apply(a,b));
	DoubleDoubleFunction g = new DoubleDoubleFunction() {
		public final double apply(double x, double y) { return Math.sin(x) + Math.pow(Math.cos(y),2); }
	};
	System.out.println(g.apply(a,b));
	DoubleFunction m = F.plus(3);
	DoubleFunction n = F.plus(4);
	System.out.println(m.apply(0));
	System.out.println(n.apply(0));
}
 
Example #3
Source File: CPLSAFactorizer.java    From RankSys with Mozilla Public License 2.0 5 votes vote down vote up
public ExplicitFactorization(FastUserIndex<U> uIndex, FastItemIndex<I> iIndex,
                             FastFeatureData<I, F, ?> featureData, DoubleFunction initFunction) {
    super(uIndex, iIndex, featureData.numFeatures(), initFunction);
    iIndex.getAllIidx().forEach(iidx -> {
        Set<Integer> itemFidxs = featureData.getIidxFeatures(iidx)
                .map(f -> f.v1)
                .collect(Collectors.toSet());
        featureData.getAllFidx()
                .filter(f -> !itemFidxs.contains(f))
                .forEach(fidx -> this.itemMatrix.setQuick(iidx, fidx, 0.0));
    });
}
 
Example #4
Source File: Functions.java    From database with GNU General Public License v2.0 5 votes vote down vote up
/**
 * Constructs a function that returns <tt>a * b</tt>.
 * <tt>a</tt> is a variable, <tt>b</tt> is fixed.
 */
public static DoubleFunction mult(final double b) {
	return new Mult(b);
	/*
	return new DoubleFunction() {
		public final double apply(double a) { return a * b; }
	};
	*/
}
 
Example #5
Source File: CPLSAFactorizer.java    From RankSys with Mozilla Public License 2.0 5 votes vote down vote up
/**
 * Creates and calculates a factorization.
 *
 * @param data preference data
 * @return a matrix factorization
 */
public Factorization<U, I> factorize(FastPreferenceData<U, I> data) {
    DoubleFunction init = x -> sqrt(1.0 / featureData.numFeatures()) * Math.random();
    Factorization<U, I> factorization = new ExplicitFactorization(data, data, featureData, init);
    factorize(factorization, data);
    return factorization;
}
 
Example #6
Source File: Functions.java    From database with GNU General Public License v2.0 5 votes vote down vote up
/**
 * Constructs a function that returns <tt><tt>Math.log(a) / Math.log(b)</tt></tt>.
 * <tt>a</tt> is a variable, <tt>b</tt> is fixed.
 */
public static DoubleFunction lg(final double b) {
	return new DoubleFunction() {
		private final double logInv = 1 / Math.log(b); // cached for speed
		public final double apply(double a) { return Math.log(a) * logInv; }
	};
}
 
Example #7
Source File: Functions.java    From jAudioGIT with GNU Lesser General Public License v2.1 5 votes vote down vote up
/**
 * Constructs a function that returns <tt><tt>Math.log(a) / Math.log(b)</tt></tt>.
 * <tt>a</tt> is a variable, <tt>b</tt> is fixed.
 */
public static DoubleFunction lg(final double b) {
	return new DoubleFunction() {
		private final double logInv = 1 / Math.log(b); // cached for speed
		public final double apply(double a) { return Math.log(a) * logInv; }
	};
}
 
Example #8
Source File: PLSAFactorizer.java    From RankSys with Mozilla Public License 2.0 5 votes vote down vote up
@Override
public Factorization<U, I> factorize(int K, FastPreferenceData<U, I> data) {
    DoubleFunction init = x -> sqrt(1.0 / K) * Math.random();
    Factorization<U, I> factorization = new Factorization<>(data, data, K, init);
    factorize(factorization, data);
    return factorization;
}
 
Example #9
Source File: ALSFactorizer.java    From RankSys with Mozilla Public License 2.0 5 votes vote down vote up
@Override
public Factorization<U, I> factorize(int K, FastPreferenceData<U, I> data) {
    DoubleFunction init = x -> sqrt(1.0 / K) * Math.random();
    Factorization<U, I> factorization = new Factorization<>(data, data, K, init);
    factorize(factorization, data);
    return factorization;
}
 
Example #10
Source File: Factorization.java    From RankSys with Mozilla Public License 2.0 5 votes vote down vote up
/**
 * Constructor.
 *
 * @param uIndex fast user index
 * @param iIndex fast item index
 * @param K dimension of the latent feature space
 * @param initFunction function to initialize the cells of the matrices
 */
public Factorization(FastUserIndex<U> uIndex, FastItemIndex<I> iIndex, int K, DoubleFunction initFunction) {
    this.userMatrix = new DenseDoubleMatrix2D(uIndex.numUsers(), K);
    this.userMatrix.assign(initFunction);
    this.itemMatrix = new DenseDoubleMatrix2D(iIndex.numItems(), K);
    this.itemMatrix.assign(initFunction);
    this.K = K;
    this.uIndex = uIndex;
    this.iIndex = iIndex;
}
 
Example #11
Source File: Functions.java    From jAudioGIT with GNU Lesser General Public License v2.1 5 votes vote down vote up
/**
 * Constructs a function that returns <tt>a * b</tt>.
 * <tt>a</tt> is a variable, <tt>b</tt> is fixed.
 */
public static DoubleFunction mult(final double b) {
	return new Mult(b);
	/*
	return new DoubleFunction() {
		public final double apply(double a) { return a * b; }
	};
	*/
}
 
Example #12
Source File: Functions.java    From jAudioGIT with GNU Lesser General Public License v2.1 4 votes vote down vote up
/**
 * Constructs a function that returns <tt>a == b ? 1 : 0</tt>.
 * <tt>a</tt> is a variable, <tt>b</tt> is fixed.
 */
public static DoubleFunction equals(final double b) {
	return new DoubleFunction() {
		public final double apply(double a) { return a == b ? 1 : 0; }
	};
}
 
Example #13
Source File: Functions.java    From database with GNU General Public License v2.0 4 votes vote down vote up
/**
 * Constructs a function that returns <tt>Math.pow(a,b)</tt>.
 * <tt>a</tt> is a variable, <tt>b</tt> is fixed.
 */
public static DoubleFunction pow(final double b) {
	return new DoubleFunction() {
		public final double apply(double a) { return Math.pow(a,b); }
	};
}
 
Example #14
Source File: Functions.java    From database with GNU General Public License v2.0 4 votes vote down vote up
/**
 * Constructs a function that returns <tt>a + b</tt>.
 * <tt>a</tt> is a variable, <tt>b</tt> is fixed.
 */
public static DoubleFunction plus(final double b) {
	return new DoubleFunction() {
		public final double apply(double a) { return a + b; }
	};
}
 
Example #15
Source File: Functions.java    From jAudioGIT with GNU Lesser General Public License v2.1 4 votes vote down vote up
/**
 * Constructs a function that returns <tt>(from<=a && a<=to) ? 1 : 0</tt>.
 * <tt>a</tt> is a variable, <tt>from</tt> and <tt>to</tt> are fixed.
 */
public static DoubleFunction between(final double from, final double to) {
	return new DoubleFunction() {
		public final double apply(double a) { return (from<=a && a<=to) ? 1 : 0; }
	};
}
 
Example #16
Source File: Functions.java    From jAudioGIT with GNU Lesser General Public License v2.1 4 votes vote down vote up
/**
 * Constructs a function that returns <tt>a < b ? -1 : a > b ? 1 : 0</tt>.
 * <tt>a</tt> is a variable, <tt>b</tt> is fixed.
 */
public static DoubleFunction compare(final double b) {
	return new DoubleFunction() {
		public final double apply(double a) { return a < b ? -1 : a > b ? 1 : 0; }
	};
}
 
Example #17
Source File: Functions.java    From jAudioGIT with GNU Lesser General Public License v2.1 4 votes vote down vote up
/**
 * Constructs a function that returns the constant <tt>c</tt>.
 */
public static DoubleFunction constant(final double c) {
	return new DoubleFunction() {
		public final double apply(double a) { return c; }
	};
}
 
Example #18
Source File: Functions.java    From jAudioGIT with GNU Lesser General Public License v2.1 4 votes vote down vote up
/**
 * Constructs a function that returns <tt>a > b ? 1 : 0</tt>.
 * <tt>a</tt> is a variable, <tt>b</tt> is fixed.
 */
public static DoubleFunction greater(final double b) {
	return new DoubleFunction() {
		public final double apply(double a) { return a > b ? 1 : 0; }
	};
}
 
Example #19
Source File: Functions.java    From jAudioGIT with GNU Lesser General Public License v2.1 4 votes vote down vote up
/**
 * Constructs a function that returns <tt>Math.IEEEremainder(a,b)</tt>.
 * <tt>a</tt> is a variable, <tt>b</tt> is fixed.
 */
public static DoubleFunction IEEEremainder(final double b) {
	return new DoubleFunction() {
		public final double apply(double a) { return Math.IEEEremainder(a,b); }
	};
}
 
Example #20
Source File: Functions.java    From jAudioGIT with GNU Lesser General Public License v2.1 4 votes vote down vote up
/**
 * Constructs a function that returns <tt>Math.pow(a,b)</tt>.
 * <tt>a</tt> is a variable, <tt>b</tt> is fixed.
 */
public static DoubleFunction pow(final double b) {
	return new DoubleFunction() {
		public final double apply(double a) { return Math.pow(a,b); }
	};
}
 
Example #21
Source File: Functions.java    From jAudioGIT with GNU Lesser General Public License v2.1 4 votes vote down vote up
/**
 * Constructs a function that returns <tt>a < b ? 1 : 0</tt>.
 * <tt>a</tt> is a variable, <tt>b</tt> is fixed.
 */
public static DoubleFunction less(final double b) {
	return new DoubleFunction() {
		public final double apply(double a) { return a < b ? 1 : 0; }
	};
}
 
Example #22
Source File: Functions.java    From jAudioGIT with GNU Lesser General Public License v2.1 4 votes vote down vote up
/**
 * Constructs a function that returns <tt>a + b</tt>.
 * <tt>a</tt> is a variable, <tt>b</tt> is fixed.
 */
public static DoubleFunction plus(final double b) {
	return new DoubleFunction() {
		public final double apply(double a) { return a + b; }
	};
}
 
Example #23
Source File: Functions.java    From jAudioGIT with GNU Lesser General Public License v2.1 4 votes vote down vote up
/**
 * Constructs a function that returns <tt>Math.max(a,b)</tt>.
 * <tt>a</tt> is a variable, <tt>b</tt> is fixed.
 */
public static DoubleFunction max(final double b) {
	return new DoubleFunction() {
		public final double apply(double a) { return Math.max(a,b); }
	};
}
 
Example #24
Source File: Functions.java    From jAudioGIT with GNU Lesser General Public License v2.1 4 votes vote down vote up
/**
 * Constructs a function that returns <tt>Math.min(a,b)</tt>.
 * <tt>a</tt> is a variable, <tt>b</tt> is fixed.
 */
public static DoubleFunction min(final double b) {
	return new DoubleFunction() {
		public final double apply(double a) { return Math.min(a,b); }
	};
}
 
Example #25
Source File: Functions.java    From jAudioGIT with GNU Lesser General Public License v2.1 4 votes vote down vote up
/**
 * Constructs a function that returns <tt>a % b</tt>.
 * <tt>a</tt> is a variable, <tt>b</tt> is fixed.
 */
public static DoubleFunction mod(final double b) {
	return new DoubleFunction() {
		public final double apply(double a) { return a % b; }
	};
}
 
Example #26
Source File: Functions.java    From database with GNU General Public License v2.0 4 votes vote down vote up
/**
 * Constructs a function that returns <tt>a % b</tt>.
 * <tt>a</tt> is a variable, <tt>b</tt> is fixed.
 */
public static DoubleFunction mod(final double b) {
	return new DoubleFunction() {
		public final double apply(double a) { return a % b; }
	};
}
 
Example #27
Source File: Functions.java    From database with GNU General Public License v2.0 4 votes vote down vote up
/**
 * Constructs a function that returns the constant <tt>c</tt>.
 */
public static DoubleFunction constant(final double c) {
	return new DoubleFunction() {
		public final double apply(double a) { return c; }
	};
}
 
Example #28
Source File: Functions.java    From database with GNU General Public License v2.0 4 votes vote down vote up
/**
 * Constructs a function that returns <tt>a < b ? -1 : a > b ? 1 : 0</tt>.
 * <tt>a</tt> is a variable, <tt>b</tt> is fixed.
 */
public static DoubleFunction compare(final double b) {
	return new DoubleFunction() {
		public final double apply(double a) { return a < b ? -1 : a > b ? 1 : 0; }
	};
}
 
Example #29
Source File: Functions.java    From database with GNU General Public License v2.0 4 votes vote down vote up
/**
 * Constructs a function that returns <tt>a == b ? 1 : 0</tt>.
 * <tt>a</tt> is a variable, <tt>b</tt> is fixed.
 */
public static DoubleFunction equals(final double b) {
	return new DoubleFunction() {
		public final double apply(double a) { return a == b ? 1 : 0; }
	};
}
 
Example #30
Source File: Functions.java    From database with GNU General Public License v2.0 4 votes vote down vote up
/**
 * Constructs a function that returns <tt>a > b ? 1 : 0</tt>.
 * <tt>a</tt> is a variable, <tt>b</tt> is fixed.
 */
public static DoubleFunction greater(final double b) {
	return new DoubleFunction() {
		public final double apply(double a) { return a > b ? 1 : 0; }
	};
}