it.unimi.dsi.fastutil.ints.Int2IntRBTreeMap Java Examples

The following examples show how to use it.unimi.dsi.fastutil.ints.Int2IntRBTreeMap. 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: AbstractIntegerSym.java    From symja_android_library with GNU General Public License v3.0 6 votes vote down vote up
/** {@inheritDoc} */
@Override
public IAST factorSmallPrimes(int numerator, int root) {
	// SortedMap<Integer, Integer> map = new TreeMap<Integer, Integer>();
	Int2IntMap map = new Int2IntRBTreeMap();
	IInteger b = this;
	boolean isNegative = false;
	if (sign() < 0) {
		b = b.negate();
		isNegative = true;
	}
	if (numerator != 1) {
		b = b.pow(numerator);
	}
	if (b.isLT(F.C8)) {
		return F.NIL;
	}

	BigInteger number = b.toBigNumerator();
	return factorBigInteger(number, isNegative, numerator, root, map);
}
 
Example #2
Source File: MovieService.java    From jstarcraft-example with Apache License 2.0 5 votes vote down vote up
@LockableMethod(strategy = HashLockableStrategy.class)
public void click(@LockableParameter int userIndex, int itemIndex, float score) {
    Int2IntSortedMap qualityFeatures = new Int2IntRBTreeMap();
    qualityFeatures.put(userDimension, userIndex);
    qualityFeatures.put(itemDimension, itemIndex);
    Int2FloatSortedMap quantityFeatures = new Int2FloatRBTreeMap();
    quantityFeatures.put(scoreDimension, score);
    dataModule.associateInstance(qualityFeatures, quantityFeatures, 5F);
}
 
Example #3
Source File: HashInstance.java    From jstarcraft-ai with Apache License 2.0 5 votes vote down vote up
public HashInstance(int qualityOrder, int quantityOrder) {
    this.qualityOrder = qualityOrder;
    this.quantityOrder = quantityOrder;
    this.qualityFeatures = new Int2IntRBTreeMap();
    this.qualityFeatures.defaultReturnValue(DataInstance.defaultInteger);
    this.quantityFeatures = new Int2FloatRBTreeMap();
    this.quantityFeatures.defaultReturnValue(DataInstance.defaultFloat);
    this.qualityMark = defaultInteger;
    this.quantityMark = defaultFloat;
    this.weight = DataInstance.defaultWeight;
}
 
Example #4
Source File: AbstractFractionSym.java    From symja_android_library with GNU General Public License v3.0 5 votes vote down vote up
@Override
public IAST factorSmallPrimes(int numerator, int root) {
	BigInteger b = toBigNumerator();
	boolean isNegative = false;
	if (sign() < 0) {
		b = b.negate();
		isNegative = true;
	}
	if (numerator != 1) {
		b = b.pow(numerator);
	}
	BigInteger d = toBigDenominator();
	if (numerator != 1) {
		d = d.pow(numerator);
	}
	// SortedMap<Integer, Integer> bMap = new TreeMap<Integer, Integer>();
	Int2IntMap bMap = new Int2IntRBTreeMap();
	IAST bAST = AbstractIntegerSym.factorBigInteger(b, isNegative, numerator, root, bMap);
	// SortedMap<Integer, Integer> dMap = new TreeMap<Integer, Integer>();
	Int2IntMap dMap = new Int2IntRBTreeMap();
	IAST dAST = AbstractIntegerSym.factorBigInteger(d, false, numerator, root, dMap);
	if (bAST.isPresent()) {
		if (dAST.isPresent()) {
			return F.Times(bAST, F.Power(dAST, F.CN1));
		}
		return F.Times(bAST, F.Power(denominator(), F.QQ(-numerator, root)));
	} else if (dAST.isPresent()) {
		return F.Times(F.Power(numerator(), F.QQ(numerator, root)), F.Power(dAST, F.CN1));
	}
	return F.NIL;
}
 
Example #5
Source File: BUCMModel.java    From jstarcraft-rns with Apache License 2.0 4 votes vote down vote up
@Override
public void prepare(Configurator configuration, DataModule model, DataSpace space) {
    super.prepare(configuration, model, space);
    // cumulative parameters
    // TODO 考虑重构
    userTopicSums = DenseMatrix.valueOf(userSize, factorSize);
    topicItemSums = DenseMatrix.valueOf(factorSize, itemSize);
    topicItemScoreSums = new float[factorSize][itemSize][scoreSize];

    // initialize count varialbes
    userTopicNumbers = DenseMatrix.valueOf(userSize, factorSize);
    userNumbers = DenseVector.valueOf(userSize);

    topicItemNumbers = DenseMatrix.valueOf(factorSize, itemSize);
    topicNumbers = DenseVector.valueOf(factorSize);

    topicItemScoreNumbers = new int[factorSize][itemSize][scoreSize];

    float initAlpha = configuration.getFloat("recommender.bucm.alpha", 1F / factorSize);
    alpha = DenseVector.valueOf(factorSize);
    alpha.setValues(initAlpha);

    float initBeta = configuration.getFloat("re.bucm.beta", 1F / itemSize);
    beta = DenseVector.valueOf(itemSize);
    beta.setValues(initBeta);

    float initGamma = configuration.getFloat("recommender.bucm.gamma", 1F / factorSize);
    gamma = DenseVector.valueOf(scoreSize);
    gamma.setValues(initGamma);

    // initialize topics
    topicAssignments = new Int2IntRBTreeMap();
    for (MatrixScalar term : scoreMatrix) {
        int userIndex = term.getRow();
        int itemIndex = term.getColumn();
        float score = term.getValue();
        int scoreIndex = scoreIndexes.get(score); // rating level 0 ~
                                                  // numLevels
        int topicIndex = RandomUtility.randomInteger(factorSize); // 0 ~
        // k-1

        // Assign a topic t to pair (u, i)
        topicAssignments.put(userIndex * itemSize + itemIndex, topicIndex);
        // for users
        userTopicNumbers.shiftValue(userIndex, topicIndex, 1F);
        userNumbers.shiftValue(userIndex, 1F);

        // for items
        topicItemNumbers.shiftValue(topicIndex, itemIndex, 1F);
        topicNumbers.shiftValue(topicIndex, 1F);

        // for ratings
        topicItemScoreNumbers[topicIndex][itemIndex][scoreIndex]++;
    }

    probabilities = DenseVector.valueOf(factorSize);
}
 
Example #6
Source File: LDCCModel.java    From jstarcraft-rns with Apache License 2.0 4 votes vote down vote up
@Override
public void prepare(Configurator configuration, DataModule model, DataSpace space) {
    super.prepare(configuration, model, space);
    numberOfStatistics = 0;

    numberOfUserTopics = configuration.getInteger("recommender.pgm.number.users", 10);
    numberOfItemTopics = configuration.getInteger("recommender.pgm.number.items", 10);

    userAlpha = configuration.getFloat("recommender.pgm.user.alpha", 1F / numberOfUserTopics);
    itemAlpha = configuration.getFloat("recommender.pgm.item.alpha", 1F / numberOfItemTopics);
    ratingBeta = configuration.getFloat("recommender.pgm.rating.beta", 1F / actionSize);

    userTopicTimes = DenseMatrix.valueOf(userSize, numberOfUserTopics);
    itemTopicTimes = DenseMatrix.valueOf(itemSize, numberOfItemTopics);
    userScoreTimes = DenseVector.valueOf(userSize);
    itemScoreTimes = DenseVector.valueOf(itemSize);

    rateTopicTimes = new int[numberOfUserTopics][numberOfItemTopics][actionSize];
    topicTimes = DenseMatrix.valueOf(numberOfUserTopics, numberOfItemTopics);
    topicProbabilities = DenseMatrix.valueOf(numberOfUserTopics, numberOfItemTopics);
    userProbabilities = DenseVector.valueOf(numberOfUserTopics);
    itemProbabilities = DenseVector.valueOf(numberOfItemTopics);

    userTopics = new Int2IntRBTreeMap();
    itemTopics = new Int2IntRBTreeMap();

    for (MatrixScalar term : scoreMatrix) {
        int userIndex = term.getRow();
        int itemIndex = term.getColumn();
        float score = term.getValue();
        int scoreIndex = scoreIndexes.get(score);

        int userTopic = RandomUtility.randomInteger(numberOfUserTopics);
        int itemTopic = RandomUtility.randomInteger(numberOfItemTopics);

        userTopicTimes.shiftValue(userIndex, userTopic, 1);
        userScoreTimes.shiftValue(userIndex, 1);

        itemTopicTimes.shiftValue(itemIndex, itemTopic, 1);
        itemScoreTimes.shiftValue(itemIndex, 1);

        rateTopicTimes[userTopic][itemTopic][scoreIndex]++;
        topicTimes.shiftValue(userTopic, itemTopic, 1);

        userTopics.put(userIndex * itemSize + itemIndex, userTopic);
        itemTopics.put(userIndex * itemSize + itemIndex, itemTopic);
    }

    // parameters
    userTopicSums = DenseMatrix.valueOf(userSize, numberOfUserTopics);
    itemTopicSums = DenseMatrix.valueOf(itemSize, numberOfItemTopics);
    rateTopicProbabilities = new float[numberOfUserTopics][numberOfItemTopics][actionSize];
    rateTopicSums = new float[numberOfUserTopics][numberOfItemTopics][actionSize];
}