/** Constructs a function that returns <tt>a / b</tt>. <tt>a</tt> is a variable, <tt>b</tt> is fixed. */ public static DoubleFunction div(double b) { return mult(1 / b); }
@Override public Vector times(double x) { if (x == 0.0) { return like(); } return createOptimizedCopy().assign(Functions.mult(x)); }
@Test public void testAssignUnaryFunction() { test.assign(Functions.mult(-1)); for (int row = 0; row < test.rowSize(); row++) { for (int col = 0; col < test.columnSize(); col++) { assertEquals("value[" + row + "][" + col + ']', -values[row][col], test .getQuick(row, col), EPSILON); } } }
@Test public void testAssignBinaryFunction3() { test.assign(Functions.mult(4)); for (int i = 0; i < values.length; i++) { if (i % 2 == 0) { assertEquals("get [" + i + ']', 0.0, test.get(i), EPSILON); } else { assertEquals("value[" + i + ']', values[i - 1] * 4, test.getQuick(i), EPSILON); } } }
p1.viewPart(5, 3).assign(Functions.mult(4));
/** Constructs a function that returns <tt>a / b</tt>. <tt>a</tt> is a variable, <tt>b</tt> is fixed. */ public static DoubleFunction div(double b) { return mult(1 / b); }
/** Constructs a function that returns <tt>a / b</tt>. <tt>a</tt> is a variable, <tt>b</tt> is fixed. */ public static DoubleFunction div(double b) { return mult(1 / b); }
@Override public Vector times(double x) { if (x == 0.0) { return like(); } return createOptimizedCopy().assign(Functions.mult(x)); }
public TopicModel(Matrix topicTermCounts, Vector topicSums, double eta, double alpha, String[] dictionary, int numThreads, double modelWeight) { this.dictionary = dictionary; this.topicTermCounts = topicTermCounts; this.topicSums = topicSums; this.numTopics = topicSums.size(); this.numTerms = topicTermCounts.numCols(); this.eta = eta; this.alpha = alpha; this.sampler = new Sampler(RandomUtils.getRandom()); this.numThreads = numThreads; if (modelWeight != 1) { topicSums.assign(Functions.mult(modelWeight)); for (int x = 0; x < numTopics; x++) { topicTermCounts.viewRow(x).assign(Functions.mult(modelWeight)); } } initializeThreadPool(); }
public TopicModel(Matrix topicTermCounts, Vector topicSums, double eta, double alpha, String[] dictionary, int numThreads, double modelWeight) { this.dictionary = dictionary; this.topicTermCounts = topicTermCounts; this.topicSums = topicSums; this.numTopics = topicSums.size(); this.numTerms = topicTermCounts.numCols(); this.eta = eta; this.alpha = alpha; this.sampler = new Sampler(RandomUtils.getRandom()); this.numThreads = numThreads; if (modelWeight != 1) { topicSums.assign(Functions.mult(modelWeight)); for (int x = 0; x < numTopics; x++) { topicTermCounts.viewRow(x).assign(Functions.mult(modelWeight)); } } initializeThreadPool(); }
public TopicModel(Matrix topicTermCounts, Vector topicSums, double eta, double alpha, String[] dictionary, int numThreads, double modelWeight) { this.dictionary = dictionary; this.topicTermCounts = topicTermCounts; this.topicSums = topicSums; this.numTopics = topicSums.size(); this.numTerms = topicTermCounts.numCols(); this.eta = eta; this.alpha = alpha; this.sampler = new Sampler(RandomUtils.getRandom()); this.numThreads = numThreads; if (modelWeight != 1) { topicSums.assign(Functions.mult(modelWeight)); for (int x = 0; x < numTopics; x++) { topicTermCounts.viewRow(x).assign(Functions.mult(modelWeight)); } } initializeThreadPool(); }
@Test public void testAssignBinaryFunction3() { test.assign(Functions.mult(4)); for (int i = 0; i < values.length; i++) { if (i % 2 == 0) { assertEquals("get [" + i + ']', 0.0, test.get(i), EPSILON); } else { assertEquals("value[" + i + ']', values[i - 1] * 4, test.getQuick(i), EPSILON); } } }
@Test public void testAssignUnaryFunction() { test.assign(Functions.mult(-1)); for (int row = 0; row < test.rowSize(); row++) { for (int col = 0; col < test.columnSize(); col++) { assertEquals("value[" + row + "][" + col + ']', -values[row][col], test .getQuick(row, col), EPSILON); } } }
public void trainDocTopicModel(Vector original, Vector topics, Matrix docTopicModel) { // first calculate p(topic|term,document) for all terms in original, and all topics, // using p(term|topic) and p(topic|doc) pTopicGivenTerm(original, topics, docTopicModel); normalizeByTopic(docTopicModel); // now multiply, term-by-term, by the document, to get the weighted distribution of // term-topic pairs from this document. for (Element e : original.nonZeroes()) { for (int x = 0; x < numTopics; x++) { Vector docTopicModelRow = docTopicModel.viewRow(x); docTopicModelRow.setQuick(e.index(), docTopicModelRow.getQuick(e.index()) * e.get()); } } // now recalculate \(p(topic|doc)\) by summing contributions from all of pTopicGivenTerm topics.assign(0.0); for (int x = 0; x < numTopics; x++) { topics.set(x, docTopicModel.viewRow(x).norm(1)); } // now renormalize so that \(sum_x(p(x|doc))\) = 1 topics.assign(Functions.mult(1 / topics.norm(1))); }
public void trainDocTopicModel(Vector original, Vector topics, Matrix docTopicModel) { // first calculate p(topic|term,document) for all terms in original, and all topics, // using p(term|topic) and p(topic|doc) pTopicGivenTerm(original, topics, docTopicModel); normalizeByTopic(docTopicModel); // now multiply, term-by-term, by the document, to get the weighted distribution of // term-topic pairs from this document. for (Element e : original.nonZeroes()) { for (int x = 0; x < numTopics; x++) { Vector docTopicModelRow = docTopicModel.viewRow(x); docTopicModelRow.setQuick(e.index(), docTopicModelRow.getQuick(e.index()) * e.get()); } } // now recalculate \(p(topic|doc)\) by summing contributions from all of pTopicGivenTerm topics.assign(0.0); for (int x = 0; x < numTopics; x++) { topics.set(x, docTopicModel.viewRow(x).norm(1)); } // now renormalize so that \(sum_x(p(x|doc))\) = 1 topics.assign(Functions.mult(1 / topics.norm(1))); }
public void trainDocTopicModel(Vector original, Vector topics, Matrix docTopicModel) { // first calculate p(topic|term,document) for all terms in original, and all topics, // using p(term|topic) and p(topic|doc) pTopicGivenTerm(original, topics, docTopicModel); normalizeByTopic(docTopicModel); // now multiply, term-by-term, by the document, to get the weighted distribution of // term-topic pairs from this document. for (Element e : original.nonZeroes()) { for (int x = 0; x < numTopics; x++) { Vector docTopicModelRow = docTopicModel.viewRow(x); docTopicModelRow.setQuick(e.index(), docTopicModelRow.getQuick(e.index()) * e.get()); } } // now recalculate \(p(topic|doc)\) by summing contributions from all of pTopicGivenTerm topics.assign(0.0); for (int x = 0; x < numTopics; x++) { topics.set(x, docTopicModel.viewRow(x).norm(1)); } // now renormalize so that \(sum_x(p(x|doc))\) = 1 topics.assign(Functions.mult(1 / topics.norm(1))); }