Skip to content

Commit 88c47a8

Browse files
committed
Network UTA1
1 parent b62e3f0 commit 88c47a8

File tree

187 files changed

+197410
-0
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

187 files changed

+197410
-0
lines changed

AdaptiveParameterController.cs

Lines changed: 100 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,100 @@
1+
using System.Collections.Generic;
2+
using System.Linq;
3+
using UnityEngine;
4+
5+
public class AdaptiveParameterController
6+
{
7+
public float minMutationRate = 0.3f;
8+
public float maxMutationRate = 0.95f;
9+
public float minComplexityWeight = 0.5f;
10+
public float maxComplexityWeight = 5f;
11+
12+
public float MeasureDiversity(List<Individual> population)
13+
{
14+
if (population.Count < 2) return 0f;
15+
16+
float totalDistance = 0f;
17+
int comparisons = 0;
18+
19+
System.Random rng = new System.Random();
20+
int samples = Mathf.Min(50, population.Count / 2);
21+
22+
for (int i = 0; i < samples; i++)
23+
{
24+
int idx1 = rng.Next(population.Count);
25+
int idx2 = rng.Next(population.Count);
26+
27+
if (idx1 != idx2)
28+
{
29+
float distance = TreeDistance(population[idx1].root, population[idx2].root);
30+
totalDistance += distance;
31+
comparisons++;
32+
}
33+
}
34+
35+
return comparisons > 0 ? totalDistance / comparisons : 0f;
36+
}
37+
38+
private float TreeDistance(ExpressionNode tree1, ExpressionNode tree2)
39+
{
40+
if (tree1 == null && tree2 == null) return 0f;
41+
if (tree1 == null || tree2 == null) return 1f;
42+
43+
float distance = tree1.nodeType != tree2.nodeType ? 1f : 0f;
44+
45+
if (tree1.nodeType == NodeType.Constant && tree2.nodeType == NodeType.Constant)
46+
{
47+
distance += Mathf.Abs(tree1.constantValue - tree2.constantValue) / 10f;
48+
}
49+
50+
distance += TreeDistance(tree1.left, tree2.left);
51+
distance += TreeDistance(tree1.right, tree2.right);
52+
53+
return distance;
54+
}
55+
56+
public float MeasureProgress(List<float> recentBestFitness)
57+
{
58+
if (recentBestFitness.Count < 2) return 1f;
59+
60+
float improvement = 0f;
61+
for (int i = 1; i < recentBestFitness.Count; i++)
62+
{
63+
improvement += recentBestFitness[i] - recentBestFitness[i - 1];
64+
}
65+
66+
return improvement / (recentBestFitness.Count - 1);
67+
}
68+
69+
public float AdaptMutationRate(float currentRate, float diversity, float progress)
70+
{
71+
float targetRate = currentRate;
72+
73+
if (diversity < 0.1f && progress < 0.01f)
74+
{
75+
targetRate = Mathf.Min(targetRate * 1.1f, maxMutationRate);
76+
}
77+
else if (diversity > 0.5f && progress > 0.05f)
78+
{
79+
targetRate = Mathf.Max(targetRate * 0.95f, minMutationRate);
80+
}
81+
82+
return targetRate;
83+
}
84+
85+
public float AdaptComplexityWeight(float currentWeight, float avgComplexity, float targetComplexity)
86+
{
87+
float targetWeight = currentWeight;
88+
89+
if (avgComplexity > targetComplexity * 1.5f)
90+
{
91+
targetWeight = Mathf.Min(targetWeight * 1.05f, maxComplexityWeight);
92+
}
93+
else if (avgComplexity < targetComplexity * 0.5f)
94+
{
95+
targetWeight = Mathf.Max(targetWeight * 0.95f, minComplexityWeight);
96+
}
97+
98+
return targetWeight;
99+
}
100+
}

AdaptiveParameterController.cs.meta

Lines changed: 2 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)