Package mikera.vectorz

Examples of mikera.vectorz.Vector


        MutableSparseVector scores = MutableSparseVector.create(keySet);
        itemScorer.score(uid, scores);
        params.train(ratings, scores);
        logger.debug("trained parameters for {}: {}", uid, params);

        Vector probabilities = Vector.createLength(params.getLevelCount());
        Long2ObjectMap<IVector> distChannel = null;
        if (reportDistribution) {
            distChannel = predictions.addChannel(RATING_PROBABILITY_CHANNEL);
        }

        for (VectorEntry e: predictions.view(VectorEntry.State.EITHER)) {
            long iid = e.getKey();
            double score = scores.get(iid);
            params.getProbDistribution(score, probabilities);

            int mlIdx = probabilities.maxElementIndex();

            predictions.set(e, quantizer.getIndexValue(mlIdx));
            if (distChannel != null) {
                distChannel.put(e.getKey(), probabilities.immutable());
            }
        }
    }
View Full Code Here


         */
        @SuppressWarnings("ConstantConditions")
        private void train(SparseVector ratings, MutableSparseVector scores) {


            Vector dbeta = Vector.createLength(beta.length());
            double dt1;
            // n is the number of iteration;
            for (int j = 0; j < iterationCount; j++ ) {
                for (VectorEntry rating: ratings) {
                    long iid = rating.getKey();
                    double score = scores.get(iid);
                    int r = quantizer.index(rating.getValue());

                    double probEqualR = getProbEQ(score,r);
                    double probLessR = getProbLE(score,r);
                    double probLessR_1 = getProbLE(score, r-1);

                    dt1 = learningRate / probEqualR * ( probLessR * (1 - probLessR) * derivateOfBeta(r, 0, t1)
                            - probLessR_1 * (1 - probLessR_1) * derivateOfBeta(r-1, 0, t1) - regTerm*t1);

                    double dbetaK;
                    for(int k = 0; k < beta.length(); k++) {
                        dbetaK = learningRate / probEqualR * ( probLessR * (1 - probLessR) *
                                derivateOfBeta(r, k+1, beta.get(k)) - probLessR_1 * (1 - probLessR_1) *
                                derivateOfBeta(r-1, k+1, beta.get(k)) - regTerm*beta.get(k));
                        dbeta.set(k, dbetaK);
                    }
                    t1 = t1 + dt1;
                    beta.add(dbeta);
                }
            }
View Full Code Here

                   equalTo(Math.PI));
    }

    @Test
    public void testBasicVectors() throws Exception {
        Vector uv = Vector.create(new double[]{0.1, 0.2});
        Vector iv = Vector.create(new double[]{0.1, -0.5});
        assertThat(kernel.apply(Math.PI, uv, iv),
                   closeTo(Math.PI + 0.01 - 0.1, 1.0e-5));
    }
View Full Code Here

                   closeTo(Math.PI + 0.01 - 0.1, 1.0e-5));
    }

    @Test
    public void testClamping() throws Exception {
        Vector uv = Vector.create(new double[]{2, 0.2});
        Vector iv = Vector.create(new double[]{2, -0.5});
        assertThat(kernel.apply(3, uv, iv),
                   closeTo(4.9, 1.0e-5));
    }
View Full Code Here

        List<FeatureInfo> featureInfo = new ArrayList<FeatureInfo>(featureCount);

        // Use scratch vectors for each feature for better cache locality
        // Per-feature vectors are strided in the output matrices
        Vector uvec = Vector.createLength(userCount);
        Vector ivec = Vector.createLength(itemCount);

        for (int f = 0; f < featureCount; f++) {
            logger.debug("Training feature {}", f);
            StopWatch timer = new StopWatch();
            timer.start();

            uvec.fill(initialValue);
            ivec.fill(initialValue);

            FeatureInfo.Builder fib = new FeatureInfo.Builder(f);
            trainFeature(f, estimates, uvec, ivec, fib);
            summarizeFeature(uvec, ivec, fib);
            featureInfo.add(fib.build());

            // Update each rating's cached value to accommodate the feature values.
            estimates.update(uvec, ivec);

            // And store the data into the matrix
            userFeatures.setColumn(f, uvec);
            assert Math.abs(userFeatures.getColumnView(f).elementSum() - uvec.elementSum()) < 1.0e-4 : "user column sum matches";
            itemFeatures.setColumn(f, ivec);
            assert Math.abs(itemFeatures.getColumnView(f).elementSum() - ivec.elementSum()) < 1.0e-4 : "item column sum matches";

            timer.stop();
            logger.info("Finished feature {} in {}", f, timer);
        }
View Full Code Here

TOP

Related Classes of mikera.vectorz.Vector

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.