Skip to content

Commit

Permalink
allow specifying the number of training threads in ALS factorizer (mi…
Browse files Browse the repository at this point in the history
…nor change)

git-svn-id: https://svn.apache.org/repos/asf/mahout/trunk@1378518 13f79535-47bb-0310-9956-ffa450edef68
  • Loading branch information
asubmissions committed Aug 29, 2012
1 parent a92140e commit e855005
Showing 1 changed file with 11 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -65,19 +65,28 @@ public class ALSWRFactorizer extends AbstractFactorizer {
/** confidence weighting parameter, only necessary when working with implicit feedback */
private final double alpha;

private final int numTrainingThreads;

private static final double DEFAULT_ALPHA = 40;

private static final Logger log = LoggerFactory.getLogger(ALSWRFactorizer.class);

public ALSWRFactorizer(DataModel dataModel, int numFeatures, double lambda, int numIterations,
boolean usesImplicitFeedback, double alpha) throws TasteException {
boolean usesImplicitFeedback, double alpha, int numTrainingThreads) throws TasteException {
super(dataModel);
this.dataModel = dataModel;
this.numFeatures = numFeatures;
this.lambda = lambda;
this.numIterations = numIterations;
this.usesImplicitFeedback = usesImplicitFeedback;
this.alpha = alpha;
this.numTrainingThreads = numTrainingThreads;
}

public ALSWRFactorizer(DataModel dataModel, int numFeatures, double lambda, int numIterations,
boolean usesImplicitFeedback, double alpha) throws TasteException {
this(dataModel, numFeatures, lambda, numIterations, usesImplicitFeedback, alpha,
Runtime.getRuntime().availableProcessors());
}

public ALSWRFactorizer(DataModel dataModel, int numFeatures, double lambda, int numIterations) throws TasteException {
Expand Down Expand Up @@ -247,7 +256,7 @@ public void run() {
}

protected ExecutorService createQueue() {
return Executors.newFixedThreadPool(Runtime.getRuntime().availableProcessors());
return Executors.newFixedThreadPool(numTrainingThreads);
}

protected static Vector ratingVector(PreferenceArray prefs) {
Expand Down

0 comments on commit e855005

Please sign in to comment.