com.jstarcraft.ai.data.DataSpace Java Examples

The following examples show how to use com.jstarcraft.ai.data.DataSpace. 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: AutoRecModel.java    From jstarcraft-rns with Apache License 2.0 6 votes vote down vote up
@Override
public void prepare(Configurator configuration, DataModule model, DataSpace space) {
    super.prepare(configuration, model, space);
    inputDimension = getInputDimension();
    hiddenDimension = configuration.getInteger("recommender.hidden.dimension");
    hiddenActivation = configuration.getString("recommender.hidden.activation");
    outputActivation = configuration.getString("recommender.output.activation");
    learnRatio = configuration.getFloat("recommender.iterator.learnrate");
    momentum = configuration.getFloat("recommender.iterator.momentum");
    weightRegularization = configuration.getFloat("recommender.weight.regularization");

    // transform the sparse matrix to INDArray
    int[] matrixShape = new int[] { itemSize, userSize };
    inputData = new Nd4jMatrix(Nd4j.zeros(matrixShape));
    maskData = new Nd4jMatrix(Nd4j.zeros(matrixShape));
    outputData = new Nd4jMatrix(Nd4j.zeros(matrixShape));
    for (MatrixScalar term : scoreMatrix) {
        if (term.getValue() > 0D) {
            inputData.setValue(term.getColumn(), term.getRow(), term.getValue());
            maskData.setValue(term.getColumn(), term.getRow(), 1F);
        }
    }
}
 
Example #2
Source File: FFMModel.java    From jstarcraft-rns with Apache License 2.0 6 votes vote down vote up
@Override
public void prepare(Configurator configuration, DataModule model, DataSpace space) {
    super.prepare(configuration, model, space);

    // Matrix for p * (factor * filed)
    // TODO 此处应该还是稀疏
    featureFactors = DenseMatrix.valueOf(featureSize, factorSize * marker.getQualityOrder());
    featureFactors.iterateElement(MathCalculator.SERIAL, (scalar) -> {
        scalar.setValue(distribution.sample().floatValue());
    });

    // init the map for feature of filed
    featureOrders = new int[featureSize];
    int count = 0;
    for (int orderIndex = 0, orderSize = dimensionSizes.length; orderIndex < orderSize; orderIndex++) {
        int size = dimensionSizes[orderIndex];
        for (int index = 0; index < size; index++) {
            featureOrders[count + index] = orderIndex;
        }
        count += size;
    }
}
 
Example #3
Source File: FMALSModel.java    From jstarcraft-rns with Apache License 2.0 6 votes vote down vote up
@Override
public void prepare(Configurator configuration, DataModule model, DataSpace space) {
    super.prepare(configuration, model, space);
    // init Q
    // TODO 此处为rateFactors
    actionFactors = DenseMatrix.valueOf(actionSize, factorSize);

    // construct training appender matrix
    HashMatrix table = new HashMatrix(true, actionSize, featureSize, new Long2FloatRBTreeMap());
    int index = 0;
    int order = marker.getQualityOrder();
    for (DataInstance sample : model) {
        int count = 0;
        for (int orderIndex = 0; orderIndex < order; orderIndex++) {
            table.setValue(index, count + sample.getQualityFeature(orderIndex), 1F);
            count += dimensionSizes[orderIndex];
        }
        index++;
    }
    // TODO 考虑重构(.此处似乎就是FactorizationMachineRecommender.getFeatureVector);
    featureMatrix = SparseMatrix.valueOf(actionSize, featureSize, table);
}
 
Example #4
Source File: IRRGModel.java    From jstarcraft-rns with Apache License 2.0 6 votes vote down vote up
@Override
public void prepare(Configurator configuration, DataModule model, DataSpace space) {
    super.prepare(configuration, model, space);
    for (MatrixScalar term : scoreMatrix) {
        int userIndex = term.getRow();
        int itemIndex = term.getColumn();
        dataTable.put(userIndex, itemIndex, term.getValue());
    }

    correlationRegularization = configuration.getFloat("recommender.alpha");
    userFactors.iterateElement(MathCalculator.SERIAL, (scalar) -> {
        scalar.setValue(RandomUtility.randomFloat(0.8F));
    });
    itemFactors.iterateElement(MathCalculator.SERIAL, (scalar) -> {
        scalar.setValue(RandomUtility.randomFloat(0.8F));
    });

    computeAssociationRuleByItem();
    sortAssociationRuleByItem();
    computeAssociationRuleByGroup();
    sortAssociationRuleByGroup();
    complementAssociationRule();
    complementMatrix = SparseMatrix.valueOf(itemSize, itemSize, itemCorrsAR_added);
}
 
Example #5
Source File: ProbabilisticGraphicalModel.java    From jstarcraft-rns with Apache License 2.0 6 votes vote down vote up
/**
 * setup init member method
 *
 * @throws ModelException if error occurs during setting up
 */
@Override
public void prepare(Configurator configuration, DataModule model, DataSpace space) {
    super.prepare(configuration, model, space);
    factorSize = configuration.getInteger("recommender.topic.number", 10);
    burnIn = configuration.getInteger("recommender.pgm.burnin", 100);
    sampleSize = configuration.getInteger("recommender.pgm.samplelag", 100);

    // TODO 此处会与scoreIndexes一起重构,本质为连续特征离散化.
    FloatSet scores = new FloatRBTreeSet();
    for (MatrixScalar term : scoreMatrix) {
        scores.add(term.getValue());
    }
    scores.remove(0F);
    scoreIndexes = new Float2IntLinkedOpenHashMap();
    int index = 0;
    for (float score : scores) {
        scoreIndexes.put(score, index++);
    }
    scoreSize = scoreIndexes.size();
}
 
Example #6
Source File: BPMFModel.java    From jstarcraft-rns with Apache License 2.0 6 votes vote down vote up
@Override
public void prepare(Configurator configuration, DataModule model, DataSpace space) {
    super.prepare(configuration, model, space);
    userMean = configuration.getFloat("recommender.recommender.user.mu", 0F);
    userBeta = configuration.getFloat("recommender.recommender.user.beta", 1F);
    userWishart = configuration.getFloat("recommender.recommender.user.wishart.scale", 1F);

    itemMean = configuration.getFloat("recommender.recommender.item.mu", 0F);
    itemBeta = configuration.getFloat("recommender.recommender.item.beta", 1F);
    itemWishart = configuration.getFloat("recommender.recommender.item.wishart.scale", 1F);

    rateSigma = configuration.getFloat("recommender.recommender.rating.sigma", 2F);

    gibbsIterations = configuration.getInteger("recommender.recommender.iterations.gibbs", 1);

    userMatrixes = new DenseMatrix[epocheSize - 1];
    itemMatrixes = new DenseMatrix[epocheSize - 1];

    normalDistribution = new QuantityProbability(JDKRandomGenerator.class, factorSize, NormalDistribution.class, 0D, 1D);
    userGammaDistributions = new QuantityProbability[factorSize];
    itemGammaDistributions = new QuantityProbability[factorSize];
    for (int index = 0; index < factorSize; index++) {
        userGammaDistributions[index] = new QuantityProbability(JDKRandomGenerator.class, index, GammaDistribution.class, (userSize + factorSize - (index + 1D)) / 2D, 2D);
        itemGammaDistributions[index] = new QuantityProbability(JDKRandomGenerator.class, index, GammaDistribution.class, (itemSize + factorSize - (index + 1D)) / 2D, 2D);
    }
}
 
Example #7
Source File: FISMAUCModel.java    From jstarcraft-rns with Apache License 2.0 6 votes vote down vote up
@Override
public void prepare(Configurator configuration, DataModule model, DataSpace space) {
    super.prepare(configuration, model, space);
    // 注意:FISM使用itemFactors来组成userFactors
    userFactors = DenseMatrix.valueOf(itemSize, factorSize);
    userFactors.iterateElement(MathCalculator.SERIAL, (scalar) -> {
        scalar.setValue(distribution.sample().floatValue());
    });
    itemFactors = DenseMatrix.valueOf(itemSize, factorSize);
    itemFactors.iterateElement(MathCalculator.SERIAL, (scalar) -> {
        scalar.setValue(distribution.sample().floatValue());
    });
    // TODO
    itemBiases = DenseVector.valueOf(itemSize);
    itemBiases.iterateElement(MathCalculator.SERIAL, (scalar) -> {
        scalar.setValue(distribution.sample().floatValue());
    });
    rho = configuration.getFloat("recommender.fismauc.rho");// 3-15
    alpha = configuration.getFloat("recommender.fismauc.alpha", 0.5F);
    beta = configuration.getFloat("recommender.fismauc.beta", 0.6F);
    gamma = configuration.getFloat("recommender.fismauc.gamma", 0.1F);
    biasRegularization = configuration.getFloat("recommender.iteration.learnrate", 0.0001F);
    // cacheSpec = conf.get("guava.cache.spec",
    // "maximumSize=200,expireAfterAccess=2m");
}
 
Example #8
Source File: WARPMFModel.java    From jstarcraft-rns with Apache License 2.0 6 votes vote down vote up
@Override
public void prepare(Configurator configuration, DataModule model, DataSpace space) {
    super.prepare(configuration, model, space);

    lossType = configuration.getInteger("losstype", 3);
    epsilon = configuration.getFloat("epsilon");
    orderLosses = new float[itemSize - 1];
    float orderLoss = 0F;
    for (int orderIndex = 1; orderIndex < itemSize; orderIndex++) {
        orderLoss += 1D / orderIndex;
        orderLosses[orderIndex - 1] = orderLoss;
    }
    for (int rankIndex = 1; rankIndex < itemSize; rankIndex++) {
        orderLosses[rankIndex - 1] /= orderLoss;
    }
}
 
Example #9
Source File: RankSGDModel.java    From jstarcraft-rns with Apache License 2.0 6 votes vote down vote up
@Override
public void prepare(Configurator configuration, DataModule model, DataSpace space) {
    super.prepare(configuration, model, space);
    // compute item sampling probability
    DefaultScalar sum = DefaultScalar.getInstance();
    sum.setValue(0F);
    itemProbabilities = DenseVector.valueOf(itemSize);
    itemProbabilities.iterateElement(MathCalculator.SERIAL, (scalar) -> {
        int index = scalar.getIndex();
        float userSize = scoreMatrix.getColumnScope(index);
        // sample items based on popularity
        float value = (userSize + 0F) / actionSize;
        sum.shiftValue(value);
        scalar.setValue(sum.getValue());
    });
}
 
Example #10
Source File: TrustMFModel.java    From jstarcraft-rns with Apache License 2.0 6 votes vote down vote up
@Override
public void prepare(Configurator configuration, DataModule model, DataSpace space) {
    super.prepare(configuration, model, space);
    mode = configuration.getString("recommender.social.model", "T");
    // algoName = "TrustMF (" + model + ")";
    switch (mode) {
    case "Tr":
        prepareByTruster();
        break;
    case "Te":
        prepareByTrustee();
        break;
    case "T":
    default:
        prepareByTruster();
        prepareByTrustee();
    }
}
 
Example #11
Source File: SocialModel.java    From jstarcraft-rns with Apache License 2.0 6 votes vote down vote up
@Override
public void prepare(Configurator configuration, DataModule model, DataSpace space) {
    super.prepare(configuration, model, space);

    socialRegularization = configuration.getFloat("recommender.social.regularization", 0.01f);
    // social path for the socialMatrix
    // TODO 此处是不是应该使用context.getSimilarity().getSimilarityMatrix();代替?
    DataModule socialModel = space.getModule("social");
    // TODO 此处需要重构,trusterDimension与trusteeDimension要配置
    coefficientField = configuration.getString("data.model.fields.coefficient");
    trusterDimension = socialModel.getQualityInner(userField) + 0;
    trusteeDimension = socialModel.getQualityInner(userField) + 1;
    coefficientDimension = socialModel.getQuantityInner(coefficientField);
    HashMatrix matrix = new HashMatrix(true, userSize, userSize, new Long2FloatRBTreeMap());
    for (DataInstance instance : socialModel) {
        matrix.setValue(instance.getQualityFeature(trusterDimension), instance.getQualityFeature(trusteeDimension), instance.getQuantityFeature(coefficientDimension));
    }
    socialMatrix = SparseMatrix.valueOf(userSize, userSize, matrix);
}
 
Example #12
Source File: LambdaFMDynamicModel.java    From jstarcraft-rns with Apache License 2.0 6 votes vote down vote up
@Override
public void prepare(Configurator configuration, DataModule model, DataSpace space) {
    super.prepare(configuration, model, space);
    dynamicRho = configuration.getFloat("recommender.item.distribution.parameter");
    numberOfOrders = configuration.getInteger("recommender.number.orders", 10);

    DefaultScalar sum = DefaultScalar.getInstance();
    sum.setValue(0F);
    orderProbabilities = DenseVector.valueOf(numberOfOrders);
    orderProbabilities.iterateElement(MathCalculator.SERIAL, (scalar) -> {
        int index = scalar.getIndex();
        float value = (float) (Math.exp(-(index + 1) / (numberOfOrders * dynamicRho)));
        sum.shiftValue(value);
        scalar.setValue(sum.getValue());
    });
    negatives = new ArrayInstance[numberOfOrders];
    orderIndexes = new Integer[numberOfOrders];
    for (int index = 0; index < numberOfOrders; index++) {
        negatives[index] = new ArrayInstance(model.getQualityOrder(), model.getQuantityOrder());
        orderIndexes[index] = index;
    }
}
 
Example #13
Source File: CDAEModel.java    From jstarcraft-rns with Apache License 2.0 6 votes vote down vote up
@Override
public void prepare(Configurator configuration, DataModule model, DataSpace space) {
    super.prepare(configuration, model, space);
    inputDimension = getInputDimension();
    hiddenDimension = configuration.getInteger("recommender.hidden.dimension");
    hiddenActivation = configuration.getString("recommender.hidden.activation");
    outputActivation = configuration.getString("recommender.output.activation");
    learnRatio = configuration.getFloat("recommender.iterator.learnrate");
    momentum = configuration.getFloat("recommender.iterator.momentum");
    weightRegularization = configuration.getFloat("recommender.weight.regularization");
    binarie = configuration.getFloat("recommender.binarize.threshold");
    // transform the sparse matrix to INDArray
    // the sparse training matrix has been binarized

    INDArray array = Nd4j.create(userSize, itemSize);
    inputData = new Nd4jMatrix(array);

    array = Nd4j.create(userSize, itemSize);
    labelData = new Nd4jMatrix(array);
    for (MatrixScalar term : scoreMatrix) {
        labelData.setValue(term.getRow(), term.getColumn(), 1F);
    }

    array = Nd4j.create(userSize, itemSize);
    outputData = new Nd4jMatrix(array);
}
 
Example #14
Source File: RandomSeparator.java    From jstarcraft-rns with Apache License 2.0 6 votes vote down vote up
public RandomSeparator(DataSpace space, DataModule dataModule, String matchField, float random) {
    this.dataModule = dataModule;
    ReferenceModule[] modules;
    if (matchField == null) {
        modules = new ReferenceModule[] { new ReferenceModule(dataModule) };
    } else {
        int matchDimension = dataModule.getQualityInner(matchField);
        DataSplitter splitter = new QualityFeatureDataSplitter(matchDimension);
        int size = space.getQualityAttribute(matchField).getSize();
        modules = splitter.split(dataModule, size);
    }
    this.trainReference = new IntegerArray();
    this.testReference = new IntegerArray();
    for (ReferenceModule module : modules) {
        IntegerArray reference = module.getReference();
        for (int cursor = 0, length = reference.getSize(); cursor < length; cursor++) {
            if (RandomUtility.randomFloat(1F) < random) {
                this.trainReference.associateData(reference.getData(cursor));
            } else {
                this.testReference.associateData(reference.getData(cursor));
            }
        }
    }
}
 
Example #15
Source File: ListwiseMFModel.java    From jstarcraft-rns with Apache License 2.0 5 votes vote down vote up
@Override
public void prepare(Configurator configuration, DataModule model, DataSpace space) {
    super.prepare(configuration, model, space);
    userExponentials = DenseVector.valueOf(userSize);
    for (MatrixScalar matrixentry : scoreMatrix) {
        int userIndex = matrixentry.getRow();
        float score = matrixentry.getValue();
        userExponentials.shiftValue(userIndex, (float) Math.exp(score));
    }
}
 
Example #16
Source File: AutoRecModel.java    From jstarcraft-rns with Apache License 2.0 5 votes vote down vote up
@Override
public void prepare(Configurator configuration, DataModule model, DataSpace space) {
    super.prepare(configuration, model, space);
    // transform the sparse matrix to INDArray
    int[] matrixShape = new int[] { itemSize, userSize };
    inputData = Nd4j.zeros(matrixShape);
    maskData = Nd4j.zeros(matrixShape);
    for (MatrixScalar term : scoreMatrix) {
        if (term.getValue() > 0D) {
            inputData.putScalar(term.getColumn(), term.getRow(), term.getValue());
            maskData.putScalar(term.getColumn(), term.getRow(), 1D);
        }
    }
}
 
Example #17
Source File: LambdaFMWeightModel.java    From jstarcraft-rns with Apache License 2.0 5 votes vote down vote up
@Override
public void prepare(Configurator configuration, DataModule model, DataSpace space) {
    super.prepare(configuration, model, space);
    epsilon = configuration.getFloat("epsilon");
    orderLosses = new float[itemSize - 1];
    float orderLoss = 0F;
    for (int orderIndex = 1; orderIndex < itemSize; orderIndex++) {
        orderLoss += 1F / orderIndex;
        orderLosses[orderIndex - 1] = orderLoss;
    }
    for (int rankIndex = 1; rankIndex < itemSize; rankIndex++) {
        orderLosses[rankIndex - 1] /= orderLoss;
    }
}
 
Example #18
Source File: ASVDPlusPlusModel.java    From jstarcraft-rns with Apache License 2.0 5 votes vote down vote up
@Override
public void prepare(Configurator configuration, DataModule model, DataSpace space) {
    super.prepare(configuration, model, space);
    positiveFactors = DenseMatrix.valueOf(itemSize, factorSize);
    positiveFactors.iterateElement(MathCalculator.SERIAL, (scalar) -> {
        scalar.setValue(distribution.sample().floatValue());
    });
    negativeFactors = DenseMatrix.valueOf(itemSize, factorSize);
    negativeFactors.iterateElement(MathCalculator.SERIAL, (scalar) -> {
        scalar.setValue(distribution.sample().floatValue());
    });
}
 
Example #19
Source File: EALSModel.java    From jstarcraft-rns with Apache License 2.0 5 votes vote down vote up
@Override
public void prepare(Configurator configuration, DataModule model, DataSpace space) {
    super.prepare(configuration, model, space);
    weightCoefficient = configuration.getFloat("recommender.wrmf.weight.coefficient", 4.0f);
    ratio = configuration.getFloat("recommender.eals.ratio", 0.4f);
    overallWeight = configuration.getFloat("recommender.eals.overall", 128.0f);
    type = configuration.getInteger("recommender.eals.wrmf.judge", 1);

    confidences = new float[itemSize];

    // get ci
    if (type == 0 || type == 2) {
        float sumPopularity = 0F;
        for (int itemIndex = 0; itemIndex < itemSize; itemIndex++) {
            float alphaPopularity = (float) Math.pow(scoreMatrix.getColumnScope(itemIndex) * 1.0 / actionSize, ratio);
            confidences[itemIndex] = overallWeight * alphaPopularity;
            sumPopularity += alphaPopularity;
        }
        for (int itemIndex = 0; itemIndex < itemSize; itemIndex++) {
            confidences[itemIndex] = confidences[itemIndex] / sumPopularity;
        }
    } else {
        for (int itemIndex = 0; itemIndex < itemSize; itemIndex++) {
            confidences[itemIndex] = 1;
        }
    }

    weights = SparseMatrix.copyOf(scoreMatrix, false);
    weights.iterateElement(MathCalculator.SERIAL, (scalar) -> {
        if (type == 1 || type == 2) {
            scalar.setValue(1F + weightCoefficient * scalar.getValue());
        } else {
            scalar.setValue(1F);
        }
    });
}
 
Example #20
Source File: EpocheModel.java    From jstarcraft-rns with Apache License 2.0 5 votes vote down vote up
@Override
public void prepare(Configurator configuration, DataModule model, DataSpace space) {
    super.prepare(configuration, model, space);
    // 参数部分
    epocheSize = configuration.getInteger("recommender.iterator.maximum", 100);
    isConverged = configuration.getBoolean("recommender.recommender.earlystop", false);
}
 
Example #21
Source File: RankALSModel.java    From jstarcraft-rns with Apache License 2.0 5 votes vote down vote up
@Override
public void prepare(Configurator configuration, DataModule model, DataSpace space) {
    super.prepare(configuration, model, space);
    weight = configuration.getBoolean("recommender.rankals.support.weight", true);
    weightVector = DenseVector.valueOf(itemSize);
    sumSupport = 0;
    for (int itemIndex = 0; itemIndex < itemSize; itemIndex++) {
        float supportValue = weight ? scoreMatrix.getColumnScope(itemIndex) : 1F;
        weightVector.setValue(itemIndex, supportValue);
        sumSupport += supportValue;
    }

    userList = new LinkedList<>();
    for (int userIndex = 0; userIndex < userSize; userIndex++) {
        if (scoreMatrix.getRowVector(userIndex).getElementSize() > 0) {
            userList.add(userIndex);
        }
    }
    userList = new ArrayList<>(userList);

    itemList = new LinkedList<>();
    for (int itemIndex = 0; itemIndex < itemSize; itemIndex++) {
        if (scoreMatrix.getColumnVector(itemIndex).getElementSize() > 0) {
            itemList.add(itemIndex);
        }
    }
    itemList = new ArrayList<>(itemList);
}
 
Example #22
Source File: NeuralNetworkModel.java    From jstarcraft-rns with Apache License 2.0 5 votes vote down vote up
@Override
public void prepare(Configurator configuration, DataModule model, DataSpace space) {
    super.prepare(configuration, model, space);
    inputDimension = getInputDimension();
    hiddenDimension = configuration.getInteger("recommender.hidden.dimension");
    hiddenActivation = configuration.getString("recommender.hidden.activation");
    outputActivation = configuration.getString("recommender.output.activation");
    learnRatio = configuration.getFloat("recommender.iterator.learnrate");
    momentum = configuration.getFloat("recommender.iterator.momentum");
    weightRegularization = configuration.getFloat("recommender.weight.regularization");
}
 
Example #23
Source File: FISMRMSEModel.java    From jstarcraft-rns with Apache License 2.0 5 votes vote down vote up
@Override
public void prepare(Configurator configuration, DataModule model, DataSpace space) {
    super.prepare(configuration, model, space);
    // 注意:FISM使用itemFactors来组成userFactors
    userFactors = DenseMatrix.valueOf(itemSize, factorSize);
    userFactors.iterateElement(MathCalculator.SERIAL, (scalar) -> {
        scalar.setValue(distribution.sample().floatValue());
    });
    itemFactors = DenseMatrix.valueOf(itemSize, factorSize);
    itemFactors.iterateElement(MathCalculator.SERIAL, (scalar) -> {
        scalar.setValue(distribution.sample().floatValue());
    });
    userBiases = DenseVector.valueOf(userSize);
    userBiases.iterateElement(MathCalculator.SERIAL, (scalar) -> {
        scalar.setValue(distribution.sample().floatValue());
    });
    itemBiases = DenseVector.valueOf(itemSize);
    itemBiases.iterateElement(MathCalculator.SERIAL, (scalar) -> {
        scalar.setValue(distribution.sample().floatValue());
    });

    numNeighbors = scoreMatrix.getElementSize();
    rho = configuration.getFloat("recommender.fismrmse.rho");// 3-15
    alpha = configuration.getFloat("recommender.fismrmse.alpha", 0.5F);
    beta = configuration.getFloat("recommender.fismrmse.beta", 0.6F);
    itemRegularization = configuration.getFloat("recommender.fismrmse.gamma", 0.1F);
    userRegularization = configuration.getFloat("recommender.fismrmse.gamma", 0.1F);
    learnRatio = configuration.getFloat("recommender.fismrmse.lrate", 0.0001F);
}
 
Example #24
Source File: WRMFModel.java    From jstarcraft-rns with Apache License 2.0 5 votes vote down vote up
@Override
public void prepare(Configurator configuration, DataModule model, DataSpace space) {
    super.prepare(configuration, model, space);
    weightCoefficient = configuration.getFloat("recommender.wrmf.weight.coefficient", 4.0f);

    confindenceMatrix = SparseMatrix.copyOf(scoreMatrix, false);
    confindenceMatrix.iterateElement(MathCalculator.SERIAL, (scalar) -> {
        scalar.setValue((float) Math.log(1F + Math.pow(10, weightCoefficient) * scalar.getValue()));
    });
    preferenceMatrix = SparseMatrix.copyOf(scoreMatrix, false);
    preferenceMatrix.setValues(1F);
}
 
Example #25
Source File: MovieModelConfigurer.java    From jstarcraft-example with Apache License 2.0 5 votes vote down vote up
private Model getModel(Class<? extends Model> clazz, DataSpace dataSpace, DataModule dataModule) throws Exception {
    Model model = ReflectionUtility.getInstance(clazz);
    EnvironmentContext context = EnvironmentFactory.getContext();
    Future<?> task = context.doTask(() -> {
        model.prepare(configuration, dataModule, dataSpace);
        model.practice();
    });
    task.get();
    return model;
}
 
Example #26
Source File: MatrixFactorizationModel.java    From jstarcraft-rns with Apache License 2.0 5 votes vote down vote up
@Override
public void prepare(Configurator configuration, DataModule model, DataSpace space) {
    super.prepare(configuration, model, space);

    userRegularization = configuration.getFloat("recommender.user.regularization", 0.01f);
    itemRegularization = configuration.getFloat("recommender.item.regularization", 0.01f);

    factorSize = configuration.getInteger("recommender.factor.number", 10);

    isLearned = configuration.getBoolean("recommender.learnrate.bolddriver", false);
    learnDecay = configuration.getFloat("recommender.learnrate.decay", 1.0f);
    learnRatio = configuration.getFloat("recommender.iterator.learnrate", 0.01f);
    learnLimit = configuration.getFloat("recommender.iterator.learnrate.maximum", 1000.0f);

    // TODO 此处需要重构
    initMean = configuration.getFloat("recommender.init.mean", 0F);
    initStd = configuration.getFloat("recommender.init.std", 0.1F);

    distribution = new QuantityProbability(JDKRandomGenerator.class, 0, NormalDistribution.class, initMean, initStd);
    userFactors = DenseMatrix.valueOf(userSize, factorSize);
    userFactors.iterateElement(MathCalculator.SERIAL, (scalar) -> {
        scalar.setValue(distribution.sample().floatValue());
    });
    itemFactors = DenseMatrix.valueOf(itemSize, factorSize);
    itemFactors.iterateElement(MathCalculator.SERIAL, (scalar) -> {
        scalar.setValue(distribution.sample().floatValue());
    });
}
 
Example #27
Source File: DeepCrossModel.java    From jstarcraft-rns with Apache License 2.0 5 votes vote down vote up
@Override
public void prepare(Configurator configuration, DataModule model, DataSpace space) {
    super.prepare(configuration, model, space);
    learnRatio = configuration.getFloat("recommender.iterator.learnrate");
    momentum = configuration.getFloat("recommender.iterator.momentum");
    weightRegularization = configuration.getFloat("recommender.weight.regularization");
    this.marker = model;

    // TODO 此处需要重构,外部索引与内部索引的映射转换
    dimensionSizes = new int[marker.getQualityOrder()];
    for (int orderIndex = 0, orderSize = marker.getQualityOrder(); orderIndex < orderSize; orderIndex++) {
        Entry<Integer, KeyValue<String, Boolean>> term = marker.getOuterKeyValue(orderIndex);
        dimensionSizes[marker.getQualityInner(term.getValue().getKey())] = space.getQualityAttribute(term.getValue().getKey()).getSize();
    }
}
 
Example #28
Source File: YongfengZhangAttributeHandler.java    From jstarcraft-rns with Apache License 2.0 5 votes vote down vote up
YongfengZhangAttributeHandler(DataSpace space) {
    this.space = space;
    this.userAttribute = space.getQualityAttribute("user");
    this.itemAttribute = space.getQualityAttribute("item");
    this.wordAttribute = space.getQualityAttribute("word");
    this.scoreAttribute = space.getQuantityAttribute("score");
    this.sentimentAttribute = space.getQuantityAttribute("sentiment");
}
 
Example #29
Source File: AoBPRModel.java    From jstarcraft-rns with Apache License 2.0 5 votes vote down vote up
@Override
public void prepare(Configurator configuration, DataModule model, DataSpace space) {
    super.prepare(configuration, model, space);
    // set for this alg
    lambdaItem = (int) (configuration.getFloat("recommender.item.distribution.parameter") * itemSize);
    // lamda_Item=500;
    loopNumber = (int) (itemSize * Math.log(itemSize));

    factorVariances = new float[factorSize];
    factorRanks = new int[factorSize][itemSize];
}
 
Example #30
Source File: GBPRModel.java    From jstarcraft-rns with Apache License 2.0 5 votes vote down vote up
@Override
public void prepare(Configurator configuration, DataModule model, DataSpace space) {
    super.prepare(configuration, model, space);
    itemBiases = DenseVector.valueOf(itemSize);
    itemBiases.iterateElement(MathCalculator.SERIAL, (scalar) -> {
        scalar.setValue(RandomUtility.randomFloat(1F));
    });

    rho = configuration.getFloat("recommender.gpbr.rho", 1.5f);
    gLen = configuration.getInteger("recommender.gpbr.gsize", 2);
}