Package etc.aloe.data

Examples of etc.aloe.data.Segment


    }

    private SegmentSet generateTestSegments(int numPositive, int numNegative) {
        List<Segment> segments = new ArrayList<Segment>();
        for (int i = 0; i < numPositive; i++) {
            segments.add(new Segment(true, null));
        }
        for (int i = 0; i < numNegative; i++) {
            segments.add(new Segment(false, null));
        }

        Collections.shuffle(segments);

        SegmentSet segmentSet = new SegmentSet();
View Full Code Here


        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

        //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

    @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
        assertEquals(8, instances.numAttributes());
        //Contains the added attribute in the right place
        assertEquals(attrName, instances.attribute(basicInstances.numAttributes()).name());

        // the middle 2 segments were removed
        assertEquals(2, instances.size());

        //The base attributes are present
        assertNotNull(instances.attribute(ExampleSet.MESSAGE_ATTR_NAME));
        assertNotNull(instances.attribute(ExampleSet.LABEL_ATTR_NAME));
        Attribute idAttr = instances.attribute(ExampleSet.ID_ATTR_NAME);
        assertNotNull(idAttr);

        //Basic features are present
        assertNotNull(instances.attribute(SegmentSet.CPS_ATTR_NAME));

        //The correct segments remain
        assertEquals(seg0.getId(), instances.get(0).value(idAttr), 0);
        assertEquals(seg3.getId(), instances.get(1).value(idAttr), 0);
    }
View Full Code Here

            Message message = new Message(msgIdInc++, time, participant, messageStr);
            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();
View Full Code Here

            messages = sortByParticipant(messages);
        }

        SegmentSet segments = new SegmentSet();

        Segment current = new Segment();
        long lastTime = 0;
        String lastParticipant = null;

        int numLabeled = 0;
        for (Message message : messages) {
            long msgSeconds = message.getTimestamp().getTime() / 1000;
            long diffSeconds = (msgSeconds - lastTime);

            boolean newSegment = false;
            if (lastTime > 0 && diffSeconds > thresholdSeconds) {
                newSegment = true;
            }
            if (byParticipant && lastParticipant != null && !lastParticipant.equals(message.getParticipant())) {
                newSegment = true;
            }

            if (newSegment) {
                if (this.resolution != null) {
                    current.setTrueLabel(this.resolution.resolveLabel(current));
                    if (current.hasTrueLabel()) {
                        numLabeled++;
                    }
                }
                segments.add(current);
                current = new Segment();
            }

            lastTime = msgSeconds;
            lastParticipant = message.getParticipant();
            current.add(message);
        }

        if (current.getMessages().size() > 0) {
            if (this.resolution != null) {
                current.setTrueLabel(this.resolution.resolveLabel(current));
                if (current.hasTrueLabel()) {
                    numLabeled++;
                }
            }
            segments.add(current);
        }
View Full Code Here

        Random random = RandomProvider.getRandom();
        for (int i = 0; i < number; i++) {
            boolean added = false;
            while (!added) {
                int index = random.nextInt(from.size());
                Segment segment = from.get(index);
                if (!selected.contains(segment)) {
                    selected.add(segment);
                    added = true;
                }
            }
View Full Code Here

        System.out.println("Applying no segmentation procedure.");
        SegmentSet segments = new SegmentSet();

        int numLabeled = 0;
        for (Message message : messages.getMessages()) {
            Segment current = new Segment();

            current.add(message);

            if (message.hasTrueLabel()) {
                current.setTrueLabel(message.getTrueLabel());
                numLabeled++;
            }

            segments.add(current);
        }
View Full Code Here

public class LabelMappingImpl implements LabelMapping {

    @Override
    public void map(Predictions predictions, SegmentSet segments) {
        for (int s = 0; s < segments.size(); s++) {
            Segment segment = segments.get(s);
            Boolean predictedLabel = predictions.getPredictedLabel(s);
            Double confidence = predictions.getPredictionConfidence(s);

            segment.setPredictedLabel(predictedLabel);
            segment.setPredictionConfidence(confidence);

            for (Message message : segment.getMessages()) {
                message.setPredictedLabel(predictedLabel);
                message.setPredictionConfidence(confidence);
            }
        }
    }
View Full Code Here

        ArrayList<Segment> selected = new ArrayList<Segment>(from);

        Random random = RandomProvider.getRandom();
        for (int i = selected.size(); i < number; i++) {
            int index = random.nextInt(from.size());
            Segment segment = from.get(index);
            selected.add(segment);
        }

        target.addAll(selected);
    }
View Full Code Here

TOP

Related Classes of etc.aloe.data.Segment

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.