Package etc.aloe.data

Examples of etc.aloe.data.SegmentSet


            segments.add(new Segment(false, null));
        }

        Collections.shuffle(segments);

        SegmentSet segmentSet = new SegmentSet();
        segmentSet.setSegments(segments);
        return segmentSet;
    }
View Full Code Here


        List<SegmentSet> segmentSets = generateTestSegments(10);
        for (SegmentSet segmentSet : segmentSets) {
            UpsampleBalancing instance = new UpsampleBalancing(1, 1);

            SegmentSet result = instance.balance(segmentSet);

            int actualTrue = result.getCountWithTrueLabel(true);
            int actualFalse = result.getCountWithTrueLabel(false);

            //Both are more than they were or the same
            assertTrue(actualTrue >= segmentSet.getCountWithTrueLabel(true));
            assertTrue(actualFalse >= segmentSet.getCountWithTrueLabel(false));
View Full Code Here

    public void run() {

        System.out.println("== Training Final Model ==");

        SegmentSet trainingSegments = segmentSet.onlyLabeled();
        if (getBalancingImpl() != null) {
            trainingSegments = getBalancingImpl().balance(trainingSegments);
        }

        ExampleSet basicExamples = trainingSegments.getBasicExamples();

        //Generate the features
        FeatureGeneration generation = getFeatureGenerationImpl();
        this.featureSpecification = generation.generateFeatures(basicExamples);
View Full Code Here

     */
    @Test
    public void testBalance_withUnlabeled() {
        System.out.println("balance with unlabeled");

        SegmentSet segmentSet = generateTestSegments(20, 110);
        UpsampleBalancing instance = new UpsampleBalancing(1, 1);

        segmentSet.add(new Segment(null, null));
        try {
            SegmentSet result = instance.balance(segmentSet);
            assertTrue(false);
        } catch (IllegalArgumentException e) {
            assertTrue(true);
        }
    }
View Full Code Here

        List<SegmentSet> segmentSets = generateTestSegments(10);
        for (SegmentSet segmentSet : segmentSets) {
            UpsampleBalancing instance = new UpsampleBalancing(2, 1);

            SegmentSet result = instance.balance(segmentSet);

            int actualTrue = result.getCountWithTrueLabel(true);
            int actualFalse = result.getCountWithTrueLabel(false);

            //Both are more than they were or the same
            assertTrue(actualTrue >= segmentSet.getCountWithTrueLabel(true));
            assertTrue(actualFalse >= segmentSet.getCountWithTrueLabel(false));
View Full Code Here

        List<SegmentSet> segmentSets = generateTestSegments(10);
        for (SegmentSet segmentSet : segmentSets) {
            UpsampleBalancing instance = new UpsampleBalancing(1, 2);

            SegmentSet result = instance.balance(segmentSet);

            int actualTrue = result.getCountWithTrueLabel(true);
            int actualFalse = result.getCountWithTrueLabel(false);

            //Both are more than they were or the same
            assertTrue(actualTrue >= segmentSet.getCountWithTrueLabel(true));
            assertTrue(actualFalse >= segmentSet.getCountWithTrueLabel(false));
View Full Code Here

        messages.add(new Message(5, new Date(now + 2 * minute), "Alice", "upon"));
        messages.add(new Message(6, new Date(now + 3 * minute), "Bob", "a"));
        messages.add(new Message(7, new Date(now + 3 * minute + second), "Alice", "time"));

        NullSegmentation instance = new NullSegmentation();
        SegmentSet segments = instance.segment(messages);

        //Expecting the same number of segments as messages
        assertEquals(messages.size(), segments.size());

        for (int i = 0; i < messages.size(); i++) {
            Message message = messages.get(i);
            Segment segment = segments.get(i);

            assertEquals(1, segment.getMessages().size());
            assertEquals(message, segment.getMessages().get(0));
        }
    }
View Full Code Here

                System.out.println("- Starting fold " + (foldIndex + 1));
                //Split the data
                CrossValidationSplit<Segment> split = new CrossValidationSplit<Segment>();

                System.out.println("- Splitting out training set");
                SegmentSet trainingSegments = new SegmentSet();
                trainingSegments.setSegments(split.getTrainingForFold(segmentSet.getSegments(), foldIndex, this.folds));
                if (getBalancingImpl() != null) {
                    trainingSegments = getBalancingImpl().balance(trainingSegments);
                }

                System.out.println("- Extracting basic features from training set");
                ExampleSet basicTrainingExamples = trainingSegments.getBasicExamples();
                trainingSegments = null;

                FeatureGeneration generation = getFeatureGenerationImpl();
                System.out.println("- Generating features");
                FeatureSpecification spec = generation.generateFeatures(basicTrainingExamples);

                FeatureExtraction extraction = getFeatureExtractionImpl();
                System.out.println("- Extracting features from training set");
                ExampleSet trainingSet = extraction.extractFeatures(basicTrainingExamples, spec);
                basicTrainingExamples = null;

                Training training = getTrainingImpl();
                Model model = training.train(trainingSet);
                trainingSet = null;
               
                System.out.println("- Splitting out test set");
                SegmentSet testingSegments = new SegmentSet();
                testingSegments.setSegments(split.getTestingForFold(segmentSet.getSegments(), foldIndex, this.folds));
                if (getBalancingImpl() != null && balanceTestSet) {
                    testingSegments = getBalancingImpl().balance(testingSegments);
                }

                System.out.println("- Extracting basic features from test set");
                ExampleSet basicTestingExamples = testingSegments.getBasicExamples();

                System.out.println("- Extracting features from test set");
                ExampleSet testingSet = extraction.extractFeatures(basicTestingExamples, spec);
                basicTestingExamples = null;
View Full Code Here

     * Test of extractFeatures method, of class FeatureExtractionImpl.
     */
    @Test
    public void testExtractFeatures() {
        System.out.println("extractFeatures");
        SegmentSet segments = new SegmentSet();

        Segment seg0 = new Segment();
        seg0.add(new Message(0, new Date(), "Alice", "it's"));
        seg0.add(new Message(1, new Date(), "Bob", "cow"));
        seg0.add(new Message(2, new Date(), "Alice", "time"));
        seg0.setTrueLabel(Boolean.TRUE);
        segments.add(seg0);

        Segment seg1 = new Segment();
        seg1.add(new Message(3, new Date(), "Bob", "noooooooo"));
        seg1.setTrueLabel(Boolean.FALSE);
        segments.add(seg1);

        Segment seg2 = new Segment();
        seg2.add(new Message(4, new Date(), "Bob", "once"));
        seg2.add(new Message(5, new Date(), "Alice", "upon"));
        seg2.setTrueLabel(Boolean.FALSE);
        segments.add(seg2);

        Segment seg3 = new Segment();
        seg3.add(new Message(6, new Date(), "Bob", "a"));
        seg3.add(new Message(7, new Date(), "Alice", "time"));
        seg3.setTrueLabel(Boolean.TRUE);
        segments.add(seg3);

        Instances basicInstances = segments.getBasicExamples().getInstances();

        String attrName = "newAtt";
        Add addFilter = new Add();
        addFilter.setAttributeName(attrName);
        addFilter.setAttributeType(new SelectedTag(0, Add.TAGS_TYPE));
        try {
            addFilter.setInputFormat(basicInstances);
        } catch (Exception e) {
            assertTrue(e.getMessage(), false);
        }

        RemoveWithValues removeFilter = new RemoveWithValues();
        removeFilter.setAttributeIndex("3"); //the label attribute
        removeFilter.setNominalIndicesArr(new int[]{0}); //false
        try {
            removeFilter.setInputFormat(addFilter.getOutputFormat());
        } catch (Exception e) {
            assertTrue(e.getMessage(), false);
        }

        FeatureSpecification spec = new FeatureSpecification();
        spec.addFilter(addFilter);
        spec.addFilter(removeFilter);

        FeatureExtractionImpl instance = new FeatureExtractionImpl();
        ExampleSet examples = instance.extractFeatures(segments.getBasicExamples(), spec);
        assertNotNull(examples);
        assertNotNull(examples.getInstances());

        Instances instances = examples.getInstances();
        //3 base attrs + 4 basic features + 1 label
View Full Code Here

            messages.add(message);

            //Make a segment for the message
            Segment segment = new Segment();
            segment.add(message);
            SegmentSet segmentSet = new SegmentSet();
            segmentSet.add(segment);

            //First extract features
            FeatureExtraction extraction = getFeatureExtractionImpl();
            extraction.setVerbosity(Loggable.Verbosity.Quiet);

            ExampleSet examples = extraction.extractFeatures(segmentSet.getBasicExamples(), featureSpecification);

            //Predict the labels
            Predictions prediction = this.model.getPredictions(examples);

            //Map back onto messages
View Full Code Here

TOP

Related Classes of etc.aloe.data.SegmentSet

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.