This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
package org.apache.mahout.math; | |
import com.google.common.base.Preconditions; | |
import org.apache.mahout.math.function.DoubleDoubleFunction; | |
import org.apache.mahout.math.set.OpenIntHashSet; | |
import java.util.Iterator; | |
public abstract class VectorBinaryAssign { | |
private static final VectorBinaryAssign operations[] = new VectorBinaryAssign[] { |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
@Test | |
public void testVectorIteration() { | |
Vector vector = new SequentialAccessSparseVector(100); | |
vector.set(0, 1); | |
vector.set(2, 2); | |
vector.set(4, 3); | |
vector.set(6, 4); | |
Iterator<Vector.Element> vectorIterator = vector.iterateNonZero(); | |
Vector.Element element = null; | |
int i = 0; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// Re-weight everything according to the minimum distance to a seed. | |
for (int currSeedIndex : seedSelector) { | |
WeightedVector curr = datapoints.get(currSeedIndex); | |
double newWeight = nextSeed.getWeight() * distanceMeasure.distance(nextSeed, curr); | |
if (newWeight < seedSelector.getWeight(currSeedIndex)) { | |
seedSelector.set(currSeedIndex, newWeight); | |
} | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
library('gmp') | |
primes <- data.frame(1:1000000) | |
names(primes) <- 'nums' | |
primes$isprime <- isprime(primes$nums) | |
pn <- primes[primes$isprime == 2, 'nums'] | |
e <- ecdf(pn) | |
plot(e, xlab='n', ylab='Number of primes less or equal to n') |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
package syntax; | |
import syntax.tree.SyntaxTreeNode; | |
import syntax.tree.arithmetic.*; | |
import syntax.tree.comparison.EqualityNode; | |
import syntax.tree.comparison.IsVoidNode; | |
import syntax.tree.comparison.LessOrEqualThanNode; | |
import syntax.tree.comparison.LessThanNode; | |
import syntax.tree.conditional.CaseNode; | |
import syntax.tree.conditional.ConditionNode; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
public static void trainActual(Iterable<Pair<Text, VectorWritable>> inputIterable, String outBase, | |
Map<String, Integer> clusterNamesToIds) throws IOException { | |
Map<String, Centroid> actualClusters = Maps.newHashMap(); | |
computeActualClusters(inputIterable, actualClusters); | |
OnlineLogisticRegression learningAlgorithm = | |
new OnlineLogisticRegression(NUM_CLASSES, NUM_FEATURES_ACTUAL, new L1()); | |
for (Pair<Text, VectorWritable> pair : inputIterable) { | |
Vector actualCentroid = pair.getSecond().get(); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
@Override | |
public Vector clone() { | |
DelegatingVector r; | |
try { | |
r = (DelegatingVector) super.clone(); | |
} catch (CloneNotSupportedException e) { | |
throw new RuntimeException("Clone not supported for DelegatingVector, shouldn't be possible"); | |
} | |
// delegate points to original without this | |
r.delegate = delegate.clone(); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
ByteArrayOutputStream bs = new ByteArrayOutputStream(2048); | |
LoggerContext lc = (LoggerContext) LoggerFactory.getILoggerFactory(); | |
lc.reset(); | |
lc.setName("context"); | |
lc.start(); | |
PatternLayoutEncoder encoder = new PatternLayoutEncoder(); | |
encoder.setContext(lc); | |
encoder.setPattern("%message\n"); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// Project the vector. | |
Vector vectorValue = value.get().clone(); | |
Vector projectedVector = new DenseVector(3); | |
for (int i = 0; i < 3; ++i) { | |
projectedVector.set(i, vectorValue.dot(basisVectors.get(i))); | |
} | |
projectedVector = projectedVector.normalize(); | |
writer.printf("%f %f %f\n", projectedVector.get(0), projectedVector.get(1), | |
projectedVector.get(2)); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
plot_skm <- function(infile) { | |
print(infile) | |
library(package=ggplot2) | |
skm <- read.table(infile, skip=1) | |
cur_dev <- dev.cur() | |
plot_file <- paste(infile, '-numDataPointSeen.png', sep='') |
NewerOlder