// This is meant to identify noisy packs // storing and reading packs in json format can make certain packs wrong because of numerical precision errors // here we identify some of those packs and clear them from the memory // for each pack, we check if the shapes are overlapping // if shapes overlap then some numerical precision errors must have occured public bool IdentifyRemoveNoisyPack(string packFileName, int packID) { Pack pack = packEvol.ReadPack(packFileName, packID); GameObject[] shapes = packEvol.VisualizePack(pack, loadFromResources: false, keepRenderer: false); bool noisyPack = false; for (int i = 0; i < shapes.Length; i++) { // move shape out of box shapes[i].transform.position = new Vector3(100f, 100f, 100f); // check if the shape collides bool shapeCollide = gtPack.WillShapeCollide(shapes[i], pack.positions[i]); if (shapeCollide) { noisyPack = true; break; } // move shape back in shapes[i].transform.position = pack.positions[i]; } int shapesLength = shapes.Length; for (int i = 0; i < shapes.Length; i++) { UnityEngine.Object.DestroyImmediate(shapes[i]); } return(noisyPack); }
/*** * Fetch a pack * Remove old shapes * Get the new shapes */ public override void AgentReset() { step = 0; stepNum = 0; pack = packEvol.ReadPack(packFileName, packID); GameObject _brain = GameObject.Find("Academy/Brain"); Brain brain = _brain.transform.GetComponent <Brain>(); // Destroying the already present shapes if (shapes != null) { for (int i = 0; i < shapes.Length; i++) { UnityEngine.Object.DestroyImmediate(shapes[i]); } shapes = null; } if (rotBeforeMov) { validPos = new int[1, 1, MOV_RES, MOV_RES, MOV_RES]; } else { validPos = new int[packEvol.r1Value.Count, packEvol.r2Value.Count, MOV_RES, MOV_RES, MOV_RES]; } if (!loadPrecompute) { if (getGT) { gtStepAction = gtPack.GetGtStepAction(ref pack, rotBeforeMov: rotBeforeMov); } if (getSavedAct) { gtStepAction = GetStepAction(); } // Loading the new shapes string[] _null = null; packEvol.GetShapes(ref _null, ref pack.sources, ref shapes, loadFromResources: false, keepRenderer: editorMode); for (int i = 0; i < shapes.Length; i++) { shapes[i].transform.localScale = pack.scales[i]; } // Move shapes in visible pisitions in demoMode // Also removing box colliders for faster processing if (demoMode) { float theta = (2.0f * Mathf.PI) / shapes.Length; for (int i = 0; i < shapes.Length; i++) { BoxCollider[] boxes = shapes[i].GetComponents <BoxCollider>(); foreach (BoxCollider box in boxes) { Destroy(box); } shapes[i].transform.position = new Vector3(2.0f * Mathf.Sin(i * theta), 0f, 2.0f * Mathf.Cos(i * theta)); } } else { // intial estimate added so as to ensure faster computation vox = new List <float> (Mathf.CeilToInt(pack.efficiency * VOX_RES * VOX_RES * VOX_RES)); for (int i = 0; i < shapes.Length; i++) { shapes[i].transform.position = Vector3.zero; boxVoxel(ref vox, i); shapes[i].transform.position = 100 * Vector3.one; } vox.TrimExcess(); // setting up the number of observarions brain.brainParameters.vectorObservationSize = ((VOX_RES * VOX_RES * VOX_RES) > (vox.Count + 1)) ? (VOX_RES * VOX_RES * VOX_RES) + 2 : vox.Count + 3; } } else { shapes = new GameObject[pack.sources.Length]; precompute.loadPrecompute(packFileName, packID, ref gtStepAction, rotBeforeMov); brain.brainParameters.vectorObservationSize = (VOX_RES * VOX_RES * VOX_RES) + 2; if (getSavedAct) { gtStepAction = GetStepAction(); } } }