Package eas.startSetup.marbBuilder.zeichenModi

Examples of eas.startSetup.marbBuilder.zeichenModi.ArrowMaster


            g = g2;
        }
       
        Polygon2D pfeilSpitze = new Polygon2D(ArrowMaster.EINFACHE_SPITZE_1);
        pfeilSpitze.scale(pfeilSpitze.getBoundingBox().middle(), new Vector2D(0.139 / 1.5, 0.139 / 1.5));
        ArrowMaster pfeilMaster = new ArrowMaster(getParCollection());
        double leftBorder = -2;
        double rightBorder = (this.network.getNeuronCount() - 1) * this.distanceBetweenNeurons.x + 2;
       
        for (int i = 0; i < this.network.getNeuronCount(); i++) {
            Polygon2D polTarget = this.getAgentShapeInEnvironment(i);
            Neuron currentNeuron = this.network.getNeuron(i);
            double dicke = polTarget.getBoundingBox().getWidth() / 30;
            double inputOutputArrowLength = dicke * 6;
           
            // Draw input / output.
            if (currentNeuron.isInput()) {
                Color color = Color.orange;

                Polygon2D points = new Polygon2D();
                ArrayList<Double> thicks = new ArrayList<Double>(2);

                thicks.add(dicke);
                thicks.add(dicke);
                Vector2D startPoint = new Vector2D(leftBorder, polTarget.getBoundingBox().middle().y);
                points.add(startPoint);
                points.add(new Vector2D(leftBorder + inputOutputArrowLength, polTarget.getBoundingBox().middle().y));

                Polygon2D arrow = pfeilMaster.segmentPfeilPol2D(points,
                        thicks, ArrowMaster.KUGEL_ENDE,
                        ArrowMaster.EINFACHE_SPITZE_1, new Vector2D(1, 1),
                        new Vector2D(1, 1));
               
                arrow = this.getPolygonInVisualization(arrow);
               
                g.setColor(color);
                g.fillPolygon(arrow.toPol());
                g.setColor(Color.black);
                g.drawPolygon(arrow.toPol());
                g.drawString(StaticMethods.round(currentNeuron.getInput(), 2)
                        + "", (float) startPoint.x, (float) startPoint.y - 5);

                Vector2D textPos = new Vector2D(startPoint.x, startPoint.y - 0.2);
                textPos = this.getPointInVisualization(textPos);
                g.setColor(Color.blue);
                g.setFont(new Font("", Font.PLAIN, 10));
                g.drawString(
                        "[" + Math.round(currentNeuron.getInput() * 10000.0) / 10000.0 + "]",
                        (int) textPos.x,
                        (int) textPos.y);
            }

            if (currentNeuron.isOutput()) {
                Color color = Color.orange;
                Polygon2D points = new Polygon2D();
                ArrayList<Double> thicks = new ArrayList<Double>(2);
                thicks.add(dicke);
                thicks.add(dicke);
               
                Vector2D startPoint = new Vector2D(rightBorder - inputOutputArrowLength, polTarget.getBoundingBox().middle().y);
                points.add(startPoint);
                points.add(new Vector2D(rightBorder, polTarget.getBoundingBox().middle().y));

                Polygon2D arrow = pfeilMaster.segmentPfeilPol2D(points,
                        thicks, ArrowMaster.KUGEL_ENDE,
                        ArrowMaster.EINFACHE_SPITZE_1, new Vector2D(1, 1),
                        new Vector2D(1, 1));
               
                arrow = this.getPolygonInVisualization(arrow);

                g.setColor(color);
                g.fillPolygon(arrow.toPol());
                g.setColor(Color.black);
                g.drawPolygon(arrow.toPol());
                g.drawString(StaticMethods.round(currentNeuron.getOutput(), 2)
                        + "", (float) startPoint.x, (float) startPoint.y - 8);

                color = Color.orange;
               
                Vector2D textPos = new Vector2D(startPoint.x, startPoint.y - 0.2);
                textPos = this.getPointInVisualization(textPos);
                g.setColor(Color.blue);
                g.setFont(new Font("", Font.PLAIN, 10));
                g.drawString(
                        "[" + Math.round(currentNeuron.getOutput() * 10000.0) / 10000.0 + "]",
                        (int) textPos.x,
                        (int) textPos.y);
            }
           
            double maxWeight = Double.NEGATIVE_INFINITY;
            double minWeight = Double.POSITIVE_INFINITY;
            for (NeuralLink link : currentNeuron.getIncomingLinks()) {
                if (link.getWeight() > maxWeight) {
                    maxWeight = link.getWeight();
                }
                if (link.getWeight() < minWeight) {
                    minWeight = link.getWeight();
                }
            }

            // Paint links.
            for (NeuralLink link : this.network.getNeuron(i).getIncomingLinks()) {
                Polygon2D polSource = this.getAgentShapeInEnvironment(link.getSourceNeuronID());

                double xSource = polSource.getBoundingBox().middle().x;
                double ySource = 0;
                double xTarget = 0;
                double yTarget = polTarget.getBoundingBox().middle().y;
                Vector2D weightPosSelf = null;

                if (i > link.getSourceNeuronID()) {
                    ySource = polSource.getBoundingBox().lowerRightCorner().y;
                    xTarget = polTarget.getBoundingBox().upperLeftCorner().x - pfeilSpitze.getBoundingBox().getWidth();
                } else if (i < link.getSourceNeuronID()) {
                    ySource = polSource.getBoundingBox().upperLeftCorner().y;
                    xTarget = polTarget.getBoundingBox().lowerRightCorner().x + pfeilSpitze.getBoundingBox().getWidth();
                } else { // ==
                    weightPosSelf = new Vector2D(polSource.centerPoint().x - 1, polSource.centerPoint().y - 1.075);
                }
               
                Polygon2D punkte = new Polygon2D();
                punkte.add(new Vector2D(xSource, ySource));
                punkte.add(new Vector2D(xSource, yTarget));
                punkte.add(new Vector2D(xTarget, yTarget));
                LinkedList<Double> dicken = new LinkedList<Double>();
               
                double weightFactor;

                if (Math.abs(maxWeight) > Math.abs(minWeight)) {
                    minWeight = -maxWeight;
                } else {
                    maxWeight = -minWeight;
                }

                if (link.getWeight() >= 0) {
                    weightFactor = link.getWeight() / maxWeight;
                } else {
                    weightFactor = link.getWeight() / minWeight;
                }
                if (weightFactor > 0 && weightFactor < 0.26) {
                    weightFactor = 0.26;
                }
                if (weightFactor <= 0 && weightFactor > -0.26) {
                    weightFactor = -0.26;
                }

                if (Double.isNaN(weightFactor)) {
                    weightFactor = 0.1;
                }

                double actualDicke = dicke * weightFactor;
                dicken.add(actualDicke);
                dicken.add(actualDicke);
                dicken.add(actualDicke);

                // Arrow.
                Polygon2D pol = pfeilMaster.segmentPfeilPol2D(
                        punkte,
                        dicken,
                        ArrowMaster.EINFACHER_ABSCHLUSS,
                        ArrowMaster.EINFACHE_SPITZE_1,
                        new Vector2D(1, 1),
View Full Code Here


    }

    public BufferedImage erzeugeDarstellung(ParCollection params) {
        final int width = 500;
        final int height = 500;
        ArrowMaster master = new ArrowMaster(params);
       
        BufferedImage img;
        DarstModEA dar = new DarstModEA(0, 0, width, height);
        DargestellterGraph darGraph = dar.erzeuge(this, null);
        List<Object> drawList = master.graph(darGraph);
        img = Geometry2D.erzBuffImgAusObjekten(drawList);
       
        return img;
    }
View Full Code Here

        double maxY = Double.MIN_VALUE;
        double minY = Double.MAX_VALUE;
        double schrittX;
        double schrittY;
        double dicke = 2;
        ArrowMaster master = new ArrowMaster(params);
        LinkedList<Object> zeichenObjekte = new LinkedList<Object>();
        AusgMerkm[] merkmale = new AusgMerkm[2];
        merkmale[0] = new AusgMerkm(Color.black, Color.black, true, true);
        merkmale[1] = new AusgMerkm(Color.white, Color.white, false, false);
        Polygon2D rahmen = new Polygon2D();
        Polygon2D balkenOben = new Polygon2D();
        Polygon2D balkenUnten = new Polygon2D();
        Polygon2D durchschnitt;
        double strichweiteX = 25;
        int glAbst = 50; // TODO: Gleitender Durchschnitt.
       
        if (werte == null || werte.size() == 0) {
            return null;
        }
       
        // Maxima suchen:
        for (ArrayList<Double> liste : werte) {
            if (maxX < 0) {
                maxX = liste.size();
            }
            if (maxX != liste.size()) {
                throw new RuntimeException("Listen haben ungleiche Länge.");
            }
            for (double d : liste) {
                if (d > maxY) {
                    maxY = d;
                }
                if (d < minY) {
                    minY = d;
                }
            }
        }

        // Falls Fitnesswerte alle auf einer Konstanten liegen:
        if (Math.abs(maxY - minY) < 0.0000001) {
            maxY = minY + 0.0000001;
        }
       
        rahmen.add(new Vector2D(0, 0));
        rahmen.add(new Vector2D(0, hoehe));
        rahmen.add(new Vector2D(breite, hoehe));
        rahmen.add(new Vector2D(breite, 0));
        balkenOben.add(new Vector2D(0, -1));
        balkenOben.add(new Vector2D(breite, -1));
        balkenOben.add(new Vector2D(breite, -60));
        balkenOben.add(new Vector2D(0, -60));
        balkenUnten.add(new Vector2D(0, hoehe + 1));
        balkenUnten.add(new Vector2D(breite, hoehe + 1));
        balkenUnten.add(new Vector2D(breite, hoehe + 60));
        balkenUnten.add(new Vector2D(0, hoehe + 60));
       
        schrittX = breite / maxX;
        schrittY = hoehe / (maxY - minY);
       
        // Nulllinie:
        ArrayList<Double> dicken = new ArrayList<Double>(
                (int) Math.round(maxX) + 1);
       
        zeichenObjekte.add(
                new AusgMerkm(Color.black, Color.black, true, true));
        Polygon2D nulllinie = new Polygon2D();
        nulllinie.add(new Vector2D(0, hoehe - (0 - minY) * schrittY));
        nulllinie.add(new Vector2D(breite, hoehe - (0 - minY) * schrittY));
        Polygon nullPol = master.segmentPfeilPol(
                nulllinie,
                null,
                ArrowMaster.EINFACHER_ABSCHLUSS,
                ArrowMaster.EINFACHER_ABSCHLUSS,
                new Vector2D(1, 1),
                new Vector2D(1, 1),
                1,
                Vector2D.NULL_VECTOR);
       
        // Einzelne Werte.
        zeichenObjekte.add(
                new AusgMerkm(Color.LIGHT_GRAY, Color.LIGHT_GRAY, true, true));
        for (ArrayList<Double> liste : werte) {
            Polygon2D pol = new Polygon2D();
            dicken = new ArrayList<Double>(liste.size() + 1);
//            Pol2DMitAusgMerkm[] gestrichelt;
            double x = 0;
           
            for (double d : liste) {
                pol.add(new Vector2D(x, hoehe - (d - minY) * schrittY));
                x += schrittX;
            }
//            pol = pol.normalisiere();
            for (int i = 0; i < pol.nPoints(); i++) {
                dicken.add(dicke);
            }
           
//            gestrichelt = master.gestrichelterPfeil(
//                    pol,
//                    dicken,
//                    PfeilMaster.EINFACHER_ABSCHLUSS,
//                    PfeilMaster.EINFACHER_ABSCHLUSS,
//                    new Vektor2D(1, 1),
//                    new Vektor2D(1, 1),
//                    merkmale,
//                    10000,
//                    params);
           
            pol = master.segmentPfeilPol2D(
                    pol,
                    dicken,
                    ArrowMaster.EINFACHER_ABSCHLUSS,
                    ArrowMaster.EINFACHER_ABSCHLUSS,
                    new Vector2D(1, 1),
                    new Vector2D(1, 1));
            zeichenObjekte.add(pol.toPol());
           
//            for (Pol2DMitAusgMerkm pa : gestrichelt) {
//                if (pa != null) {
//                    zeichenObjekte.add(pa.getAusg());
//                    zeichenObjekte.add(pa.getPol().toPol());
//                }
//            }
        }

        // Durchschnittslinie:
        double maxDurch = Double.MIN_VALUE;
        double maxGleit = Double.MIN_VALUE;
       
        zeichenObjekte.add(
                new AusgMerkm(
                        Color.black,
                        new Color(185, 0, 0),
                        true,
                        true));
        durchschnitt = new Polygon2D();
        dicken = new ArrayList<Double>(
                (int) Math.round(maxX) + 1);
        double x = 0;
       
        for (int i = 0; i < maxX; i++) {
            double durchWert = 0;
           
            for (ArrayList<Double> liste : werte) {
                durchWert += liste.get(i);
            }
           
            durchWert /= werte.size();

            if (maxDurch < durchWert) {
                maxDurch = durchWert;
            }
           
            durchschnitt.add(new Vector2D(x, hoehe - (durchWert - minY) * schrittY));
            x += schrittX;
        }

//        durchschnitt = durchschnitt.normalisiere();
        for (int i = 0; i < durchschnitt.nPoints(); i++) {
            dicken.add(dicke * 2);
        }
       
        Polygon durchPol = master.segmentPfeilPol(
                durchschnitt,
                dicken,
                ArrowMaster.EINFACHER_ABSCHLUSS,
                ArrowMaster.EINFACHER_ABSCHLUSS,
                new Vector2D(1, 1),
                new Vector2D(1, 1),
                1,
                Vector2D.NULL_VECTOR);

        zeichenObjekte.add(durchPol);

        // Gleitender Durchschnitt.
        ArrayList<Double> durch = new ArrayList<Double>(werte.get(0).size());
        ArrayList<Double> dickenGleit = new ArrayList<Double>(durch.size());
       
        for (int i = 0; i < maxX; i++) { // Durchschnitt.
            double durchWert = 0;
           
            for (ArrayList<Double> liste : werte) {
                durchWert += liste.get(i);
            }
           
            durch.add(durchWert / werte.size());
        }
       
        ArrayList<Double> gleit = MiscMath.glDurchSchn(durch, glAbst);
       
        // Maximum suchen.
        for (double d : gleit) {
            if (d > maxGleit) {
                maxGleit = d;
            }
        }
       
        Polygon2D gleitPol = new Polygon2D();
        x = schrittX * glAbst;
       
        for (double glWert : gleit) {
            gleitPol.add(new Vector2D(x, hoehe - (glWert - minY) * schrittY));
            dickenGleit.add(dicke * 4);
            x += schrittX;
        }
       
        Polygon gleitP = master.segmentPfeilPol(
                gleitPol,
                dickenGleit,
                ArrowMaster.EINFACHER_ABSCHLUSS,
                ArrowMaster.EINFACHER_ABSCHLUSS,
                new Vector2D(1, 1),
                new Vector2D(1, 1),
                1,
                Vector2D.NULL_VECTOR);
       
        zeichenObjekte.add(
                new AusgMerkm(Color.white, Color.black, true, true));
        zeichenObjekte.add(gleitP);

        // Umrisse und Linien:
        zeichenObjekte.add(
                new AusgMerkm(Color.white, Color.white, true, true));
        zeichenObjekte.add(balkenOben.toPol());
        zeichenObjekte.add(balkenUnten.toPol());
        zeichenObjekte.add(
                new AusgMerkm(Color.black, Color.white, true, false));
        zeichenObjekte.add(rahmen.toPol());
        zeichenObjekte.add(nullPol);

        // Beschriftungen:
        if (beschriftungen != null) {
            Polygon2D strichPol2D;
            Polygon strichPol;
            zeichenObjekte.add(new AusgMerkm(
                    Color.black,
                    Color.black,
                    true,
                    true,
                    "",
                    0,
                    20));
           
            for (double d = 0; d < maxX; d += strichweiteX) {
                strichPol2D = new Polygon2D();
                dicken = new ArrayList<Double>(2);
                strichPol2D.add(new Vector2D(d * schrittX, hoehe - 5));
                strichPol2D.add(new Vector2D(d * schrittX, hoehe + 5));
                dicken.add(dicke);
                dicken.add(dicke);
               
                strichPol = master.segmentPfeilPol(
                        strichPol2D,
                        dicken,
                        ArrowMaster.EINFACHER_ABSCHLUSS,
                        ArrowMaster.EINFACHER_ABSCHLUSS,
                        new Vector2D(1, 1),
View Full Code Here

TOP

Related Classes of eas.startSetup.marbBuilder.zeichenModi.ArrowMaster

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.