double translation = 0;
Color color = Color.orange;
translation += 5;
Polygon2D points = new Polygon2D();
ArrayList<Double> thicks = new ArrayList<Double>(2);
thicks.add(2.5);
thicks.add(2.5);
Vector2D startPoint = new Vector2D(10 + translation, i
* (nodesize + 10) + 10 + nodesize / 2 - 1);
points.add(startPoint);
points.add(new Vector2D(30 + translation, i * (nodesize + 10)
+ 10 + nodesize / 2 - 1));
Polygon2D arrow = this.pfeilMaster.segmentPfeilPol2D(points,
thicks, ArrowMaster.KUGEL_ENDE,
ArrowMaster.EINFACHE_SPITZE_1, new Vector2D(1, 1),
new Vector2D(1, 1));
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);
}
if (currentNeuron.isOutput()) {
Color color = Color.orange;
double translation = 0;
Polygon2D points = new Polygon2D();
ArrayList<Double> thicks = new ArrayList<Double>(2);
translation = this.neurons.size() * (nodesize + 10) + 40;
translation += 5;
thicks.add(2.5);
thicks.add(2.5);
Vector2D startPoint = new Vector2D(10 + translation, i
* (nodesize + 10) + 10 + nodesize / 2 - 1);
points.add(startPoint);
points.add(new Vector2D(30 + translation, i * (nodesize + 10)
+ 10 + nodesize / 2 - 1));
Polygon2D arrow = this.pfeilMaster.segmentPfeilPol2D(points,
thicks, ArrowMaster.KUGEL_ENDE,
ArrowMaster.EINFACHE_SPITZE_1, new Vector2D(1, 1),
new Vector2D(1, 1));
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;
}
// Draw links.
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();
}
}
for (NeuralLink link : currentNeuron.getIncomingLinks()) {
Polygon2D points = new Polygon2D();
ArrayList<Double> thicks = new ArrayList<Double>(2);
Vector2D weightPos = null;
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;
}
thicks.add(4 * weightFactor);
thicks.add(4 * weightFactor);
thicks.add(4 * weightFactor);
Neuron otherNeuron = this.getNeuron(link.getSourceNeuronID());
Font font;
if (Math.abs(weightFactor) > 0.5) {
font = new Font("", Font.BOLD, 12);
} else {
font = new Font("", Font.PLAIN, 10);
}
if (otherNeuron.getId() < currentNeuron.getId()) {
// Regular link from earlier neuron.
points.add(new Vector2D(otherNeuron.getId()
* (nodesize + 10) + 50 + nodesize / 2, otherNeuron
.getId() * (nodesize + 10) + 10 + nodesize));
points.add(new Vector2D(otherNeuron.getId()
* (nodesize + 10) + 50 + nodesize / 2,
currentNeuron.getId() * (nodesize + 10) + 10
+ nodesize / 2));
points.add(new Vector2D(currentNeuron.getId()
* (nodesize + 10) + 40, currentNeuron.getId()
* (nodesize + 10) + 10 + nodesize / 2));
weightPos = new Vector2D(otherNeuron.getId()
* (nodesize + 10) + 53 + nodesize / 2,
currentNeuron.getId() * (nodesize + 10) + 10
+ nodesize / 2 - 3);
} else if (otherNeuron.getId() > currentNeuron.getId()) {
// Reccurent link from later neuron.
points.add(new Vector2D(otherNeuron.getId()
* (nodesize + 10) + 50 + nodesize / 2, otherNeuron
.getId() * (nodesize + 10) + 10 + nodesize));
points.add(new Vector2D(otherNeuron.getId()
* (nodesize + 10) + 50 + nodesize / 2,
currentNeuron.getId() * (nodesize + 10) + 10
+ nodesize / 2));
points.add(new Vector2D(currentNeuron.getId()
* (nodesize + 10) + 60 + nodesize, currentNeuron
.getId() * (nodesize + 10) + 10 + nodesize / 2));
weightPos = new Vector2D(otherNeuron.getId()
* (nodesize + 10) + 53 + nodesize / 2,
currentNeuron.getId() * (nodesize + 10) + 10
+ nodesize / 2 - 3);
} else {
// Reccurent link from same neuron.
double epsilon = 0.05;
double radius = nodesize / 2.0 - 2;
double x = currentNeuron.getId() * (nodesize + 10) + 51 + nodesize / 2.0;
double y = currentNeuron.getId() * (nodesize + 10) + 11 + nodesize / 2.0;
thicks.clear();
for (double d = 0; d < Math.PI * 2; d += epsilon) {
points.add(new Vector2D(x + Math.cos(d) * radius, y + Math.sin(d) * radius));
thicks.add(0 * weightFactor);
}
weightPos = new Vector2D(otherNeuron.getId()
* (nodesize + 10) + 60, currentNeuron.getId()
* (nodesize + 10) + 8);
weightFactor = Double.POSITIVE_INFINITY;
}
double spitzenFactor = 1.0;
if (weightFactor < 0) {
spitzenFactor = -1.0;
}
if (points.size() > 0) {
Polygon2D arrow = ArrowMaster.DOPPELSPITZES_ENDE;
try {
arrow = this.pfeilMaster.segmentPfeilPol2D(points,
thicks, ArrowMaster.DOPPELSPITZES_ENDE,
ArrowMaster.EINFACHE_SPITZE_1, new Vector2D(
spitzenFactor * 1 / weightFactor / 1.7,
1 / weightFactor / 1.7), new Vector2D(
spitzenFactor * 1 / weightFactor / 1.7,
1 / weightFactor / 1.7));
} catch (Exception e) {
GlobalVariables.getPrematureParameters().logStage1(Arrays.deepToString(e.getStackTrace()));
}
if (link.getWeight() > 0) {
g.setColor(Color.black);
} else {
g.setColor(Color.red);
}
g.fillPolygon(arrow.toPol());
}
if (link.getWeight() > 0) {
g.setColor(Color.black);
} else {