-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathSimpleGPVisualizer.cs
More file actions
51 lines (41 loc) · 1.82 KB
/
SimpleGPVisualizer.cs
File metadata and controls
51 lines (41 loc) · 1.82 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
using UnityEngine;
using System.Text;
public class SimpleGPVisualizer : MonoBehaviour
{
public AdvancedSymbolicRegressionGP gpController;
public float updateInterval = 1f;
private float lastUpdate;
private StringBuilder sb;
void Start()
{
sb = new StringBuilder();
}
void Update()
{
if (Time.time - lastUpdate > updateInterval && gpController != null && gpController.bestIndividual != null)
{
DisplayProgress();
lastUpdate = Time.time;
}
}
void DisplayProgress()
{
sb.Clear();
Individual best = gpController.bestIndividual;
// sb.AppendLine("┏━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━┓");
sb.AppendLine(" GENETIC PROGRAMMING PROGRESS ");
// sb.AppendLine("┣━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━┫");
sb.AppendLine($" Expression: {best.root.ToString().PadRight(24)} ");
sb.AppendLine($" MSE: {best.mse:F8} ");
sb.AppendLine($" Fitness: {best.fitness:F6} ");
sb.AppendLine($" Complexity: {best.complexity} ");
// Progress bar
float progress = Mathf.Clamp01(-best.mse / 100f);
int barLength = 30;
int filled = Mathf.RoundToInt(progress * barLength);
string bar = new string('!', filled) + new string('!', barLength - filled);
sb.AppendLine($" Progress: [{bar}] ");
// sb.AppendLine("┗━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━┛");
Debug.Log(sb.ToString());
}
}