//[SerializeField] private int m_playerSizeNumber = 1; public override List <SampleContainer> GenerateSamples(int width, int height, int obstacleLength, int playerLength) { m_data.Clear(); int dataLength = obstacleLength + playerLength; int playerWidth = playerLength / width;//(int)(Mathf.Sqrt((width) + 0.01f)); int playerHeight = playerWidth; //Debug.Log("playerWidth: " + playerWidth); for (int i = 0; i < m_absolutePixelNumber; i++) { float[] inputRight = new float[dataLength]; float[] inputLeft = new float[dataLength]; for (int w = 0; w < (playerWidth * (1)); w++) { for (int h = 0; h < playerHeight; h++) { // on the right half, go left inputRight[obstacleLength + w + i + h * width] = 1; //Debug.Log("0: " + obstacleLength + " + " + w + " + " + i + "(" + h + " * " + width + ") = " + (obstacleLength + w + i + h * width)); // on the left half, go right //Debug.Log("1: " + (obstacleLength + playerLength - (w + i + h * width) - 1));// "o " + obstacleLength + " + pL " + playerLength + " - (w " + w + " + h " + h + " * wi " + width + ") - 1 = " + (obstacleLength + playerLength - (w + h * width) - 1)); inputLeft[obstacleLength + playerLength - (w + i + h * width) - 1] = 1; } } float[] desiredOutput = new float[m_screenshotManager.GetOutputNumber()]; desiredOutput[1] = 1; SampleContainer container = new SampleContainer(inputRight, desiredOutput, null, width, height); m_data.Add(container); desiredOutput = new float[m_screenshotManager.GetOutputNumber()]; desiredOutput[0] = 1; SampleContainer container2 = new SampleContainer(inputLeft, desiredOutput, null, width, height); m_data.Add(container2); } return(m_data); }
public void ApplyData() { m_samplesGatheredNoStay.Clear(); m_cacheSampleSource = null; m_cacheSampleThis = null; m_screenshotScriptThis.ApplyData(); }
public void UpdateVisualizationSample(SampleContainer sample) { if (!m_visualize) { return; } }
public SampleContainer GenerateSampleSource(bool save) { float[] desiredOutput = GenerateDesiredOutput(); bool isOkay = CheckIsOkayDesiredOutput(desiredOutput); if (!isOkay) { return(new SampleContainer(false)); } float[] input = GenerateInputSource(); isOkay = CheckIsOkayInput(input); if (!isOkay) { return(new SampleContainer(false)); } SampleContainer sampleContainer = new SampleContainer(input, desiredOutput, CheckFilterDesiredOutput(desiredOutput), m_screenshotScriptThis.GetCaptureWidth(), m_screenshotScriptThis.GetCaptureHeight()); if (save) { SaveSample(sampleContainer); } m_cacheSampleSource = sampleContainer; return(sampleContainer); }
private void SavePlayerSample() { if (!m_savePlayerSamples || m_movementManager.GetControllerType() != PlayerMovementManager.ControllerType.Player) { return; } float[] desiredOutput = PlayerMovementManager.Instance().GenerateInputData(); bool isOkay = m_sampleManager.CheckIsOkayDesiredOutput(desiredOutput); if (!isOkay) { return; } float[] input = m_sampleManager.GetScreenshotScript().GetScreenshotDataComputed(0, 0, 0, TakeScreenshot.CaptureType.Separate, m_sampleManager.GetCurveWidthSource(), m_sampleManager.GetCurveHeightSource()); isOkay = m_sampleManager.CheckIsOkayInput(input); if (!isOkay) { return; } SampleContainer sampleContainer = new SampleContainer(input, desiredOutput, m_sampleManager.CheckFilterDesiredOutput(desiredOutput), m_sampleManager.GetScreenshotScript().GetCaptureWidth(), m_sampleManager.GetScreenshotScript().GetCaptureHeight()); m_samples.Add(sampleContainer); }
float[] GetInputForNetwork() { SampleContainer sample = m_networkContainer.m_sampleManager.GenerateSampleThis(); //m_networkContainer.m_visualization.UpdateVisualizationSample(sample); float[] input = sample.m_input; return(input); }
public void Test() { SampleContainer <SampleObject> container = new SampleContainer <SampleObject>(); SpecificObject o = new SpecificObject(); //create an object container.List.Add(o); //add it to the list o.Parent = container; //set its parent }
public SampleContainer GenerateSampleOffline() { //if(m_usePreDefinedSamples && m_useGatheredSamples) //{ // Debug.Log("Warning: m_usePreDefinedSamples && m_useGatheredSamples not implented yet! Using only m_usePreDefinedSamples instead!"); //} /*else*/ if (m_minSamplesNoStay > 0 && m_samplesGatheredNoStay.Count < m_minSamplesNoStay) { return(new SampleContainer(false)); } if (GetRandom(0f, 1f) < m_sampleDistributionPre) { SampleContainer sampleContainer = null; float total = 0; foreach (SampleGeneration bundle in m_sampleBundles) { total += bundle.GetDistribution(); } float counter = 0; float random = GetRandom(0f, total); foreach (SampleGeneration bundle in m_sampleBundles) { counter += bundle.GetDistribution(); if (random <= counter) { sampleContainer = bundle.GetRandomSample(); break; } } return(sampleContainer); } else { SampleContainer sampleContainer = new SampleContainer(false); bool isStay = GetRandom(0f, 1f) < m_sampleDistributionStay; if (isStay && m_samplesGatheredStay.Count > 0) { int index = GetRandom(0, m_samplesGatheredStay.Count); sampleContainer = m_samplesGatheredStay[index]; } else if (m_samplesGatheredNoStay.Count > 0) { int index = GetRandom(0, m_samplesGatheredNoStay.Count); sampleContainer = m_samplesGatheredNoStay[index]; } return(sampleContainer); } //return new SampleContainer(false); }
public SampleContainer GenerateSampleThis() { float[] input = GenerateInputThis(); float[] desiredOutput = null; SampleContainer sampleContainer = new SampleContainer(input, desiredOutput, null, m_screenshotScriptThis.GetCaptureWidth(), m_screenshotScriptThis.GetCaptureHeight()); m_cacheSampleThis = sampleContainer; return(sampleContainer); }
public void OutSimulationTest() { // Arrange int ret = 0; var mockSample = MockRepository.GenerateMock <ISample>(); var container = new SampleContainer(mockSample); mockSample.Stub(s => s.MethodWithOutParameter(out ret)).OutRef(100); // Act container.MethodWithOutParameter(out ret); // Assert ret.Should().Be(100); }
public void TrainNetworkOffline() { SampleContainer sampleSource = m_sampleManager.GenerateSampleOffline(); if (!sampleSource.m_isOkay) { return; } bool update = m_network.AddTrainingData(sampleSource.m_input, sampleSource.m_desiredOutput, GetLearnRate(m_trainingUnitsCompleted)); if (update) { UpdateTraningCount(); } }
private void FilterSamples() { if (m_samplesPredefined == null || m_samplesPredefined.Count == 0) { return; } for (int i = m_samplesPredefined.Count - 1; i >= 0; i--) { SampleContainer sample = m_samplesPredefined[i]; if (!CheckIsOkayDesiredOutput(sample.m_desiredOutput) || !CheckIsOkayInput(sample.m_input)) { m_samplesPredefined.RemoveAt(i); } } }
public void Decode_SampleContainer_ShouldRecursiveEncodeCorrect() { var input = new SampleContainer() { Sample1 = new ObjectSample() { X = 1.3 }, Sample2 = new ObjectSample() { X = 11 } }; const string expected = "1~33:1.3~2~33:11"; var encoded = ObjectParser.Encode(input); Assert.AreEqual(expected, encoded); }
public void Decode_SampleContainer_ShouldRecursiveDecodeCorrect() { var expected = new SampleContainer() { Sample1 = new ObjectSample() { X = 1.3 }, Sample2 = new ObjectSample() { X = 11 } }; const string input = "1~33:1.3~2~33:11"; var decoded = ObjectParser.Decode <SampleContainer>(input); decoded.Should().BeEquivalentTo(expected); }
private void SaveSample(SampleContainer sampleContainer) { bool isStay = IsStay(sampleContainer.m_desiredOutput); if (!isStay) { while (m_maxSamplesNoStay >= 0 && m_samplesGatheredNoStay.Count > m_maxSamplesNoStay) { m_samplesGatheredNoStay.RemoveAt(GetRandom(0, m_samplesGatheredNoStay.Count)); } m_samplesGatheredNoStay.Add(sampleContainer); } else if (m_maxSamplesStay > 0 || m_maxSamplesStayPercent > 0) { int maxSamplesStay = m_maxSamplesStay;// (int)(m_maxSamplesNoStay * m_sampleStayDistribution); while (maxSamplesStay >= 0 && m_samplesGatheredStay.Count > maxSamplesStay) { m_samplesGatheredStay.RemoveAt(GetRandom(0, m_samplesGatheredStay.Count)); } m_samplesGatheredStay.Add(sampleContainer); } }
public override List <SampleContainer> GenerateSamples(int width, int height, int obstacleLength, int playerLength) { m_data.Clear(); int dataLength = obstacleLength + playerLength; for (int w = 0; w < width; w++) { float[] input = new float[dataLength]; float[] desiredOutput = new float[m_screenshotManager.GetOutputNumber()]; // on the right half, go left desiredOutput[0] = w >= width / 2 ? 1 : 0; // on the left half, go right desiredOutput[1] = w < width / 2 ? 1 : 0; int playerIndex = w + obstacleLength; input[playerIndex] = 1; SampleContainer container = new SampleContainer(input, desiredOutput, null, width, height); m_data.Add(container); } return(m_data); }
public override List <SampleContainer> GenerateSamples(int width, int height, int obstacleLength, int playerLength) { m_data.Clear(); int dataLength = obstacleLength + playerLength; int playerWidth = playerLength / width; int playerHeight = playerWidth; int minIndexPlayerY = 0; int maxIndexPlayerY = playerHeight; for (int playerPositionX = 0; playerPositionX < (width - playerWidth + 1); playerPositionX++) { bool playerIsRightHalf = playerPositionX >= width / 2; float playerPositionXCenter = (playerPositionX + playerPositionX + playerWidth - 1) * 0.5f; int minIndexX = Mathf.Max(0, playerPositionX - (int)((playerIsRightHalf ? m_considerRangeXCenter : m_considerRangeXEdge) * width)); int maxIndexX = Mathf.Min(playerPositionX + (int)((playerIsRightHalf ? m_considerRangeXEdge : m_considerRangeXCenter) * width), width - 1); int minIndexY = 0; int maxIndexY = Mathf.Min((int)(m_considerRangeY * height), height - 1); float[] inputLeft = new float[dataLength]; float[] inputRight = new float[dataLength]; // set values for obstacles for (int y = minIndexY; y <= maxIndexY; y++) { for (int x = minIndexX; x <= maxIndexX; x++) { if (m_singlePictures) { inputLeft = new float[dataLength]; inputRight = new float[dataLength]; } for (int yPlayer = minIndexPlayerY; yPlayer < maxIndexPlayerY; yPlayer++) { for (int xPlayer = playerPositionX; xPlayer < Mathf.Min(width, playerPositionX + playerWidth); xPlayer++) { int index2 = obstacleLength + xPlayer + yPlayer * width; inputLeft[index2] = 1; inputRight[index2] = 1; } } //Debug.Log(x + " - " + playerPositionXCenter + " / " + width + " = " + (Mathf.Abs(x - playerPositionXCenter) / width) + ", eval = " + distFactorX); float distFactorY = m_rangeCurveY.Evaluate((float)Mathf.Abs(y - (x == playerPositionX ? (maxIndexPlayerY - 1) : 0)) / height); int index = x + y * width; if (playerIsRightHalf && x < playerPositionXCenter) { float distFactor = m_rangeCurveXCenter.Evaluate(Mathf.Abs(x - playerPositionXCenter) / width); inputLeft[index] = distFactor * distFactorY; // player right half, left side } else if (playerIsRightHalf) { float distFactor = m_rangeCurveXEdge.Evaluate(Mathf.Abs(x - playerPositionXCenter) / width); inputRight[index] = distFactor * distFactorY; // player right half, right side } if (!playerIsRightHalf && x > playerPositionXCenter) { float distFactor = m_rangeCurveXCenter.Evaluate(Mathf.Abs(x - playerPositionXCenter) / width); inputLeft[index] = distFactor * distFactorY; // player left half, right side } else if (!playerIsRightHalf) { float distFactor = m_rangeCurveXEdge.Evaluate(Mathf.Abs(x - playerPositionXCenter) / width); inputRight[index] = distFactor * distFactorY;// player left half, left side } if (m_singlePictures) { bool isLeftSide = x < playerPositionXCenter; bool isRightSide = x > playerPositionXCenter; bool isAhead = x == playerPositionXCenter; float[] desiredOutput = new float[m_screenshotManager.GetOutputNumber()]; if (isRightSide) { if (!playerIsRightHalf && m_stayInsteadOfDodge) { desiredOutput[2] = 1; } else { desiredOutput[0] = 1; } } if (isLeftSide) { if (playerIsRightHalf && m_stayInsteadOfDodge) { desiredOutput[2] = 1; } else { desiredOutput[1] = 1; } } if (isAhead) { if (playerIsRightHalf) { desiredOutput[0] = 1; } else { desiredOutput[1] = 1; } } if (inputLeft[index] > 0) { SampleContainer container = new SampleContainer(inputLeft, desiredOutput, null, width, height); m_data.Add(container); } if (inputRight[index] > 0) { SampleContainer container = new SampleContainer(inputRight, desiredOutput, null, width, height); m_data.Add(container); } //SampleContainer containerRight = new SampleContainer(inputRight, desiredOutputRight, null, width, height); //m_data.Add(containerRight); } // player is on the right half } } if (!m_singlePictures) { float[] desiredOutputLeft = new float[m_screenshotManager.GetOutputNumber()]; float[] desiredOutputRight = new float[m_screenshotManager.GetOutputNumber()]; if (playerIsRightHalf) { desiredOutputRight[0] = 1; desiredOutputLeft[m_stayInsteadOfDodge ? 2 : 1] = 1; } else { desiredOutputRight[1] = 1; desiredOutputLeft[m_stayInsteadOfDodge ? 2 : 0] = 1; } SampleContainer containerLeft = new SampleContainer(inputLeft, desiredOutputLeft, null, width, height); m_data.Add(containerLeft); SampleContainer containerRight = new SampleContainer(inputRight, desiredOutputRight, null, width, height); m_data.Add(containerRight); } //// set values for obstacles //for (int h = minIndexY; h <= maxIndexY; h++) //{ // for (int w = minIndexX; w <= maxIndexX; w++) // { // float[] input = new float[dataLength]; // //input[playerPositionX + obstacleLength] = 1; // for (int y = minPlayerY; y < maxPlayerY; y++) // { // for (int x = playerPositionX; x < Mathf.Min(width, playerPositionX + playerWidth); x++) // { // int index2 = obstacleLength + x + y * width; // input[index2] = 1; // } // } // float distFactorX = m_rangeCurveX.Evaluate(Mathf.Abs(w - playerPositionXCenter) / width); // float distFactorY = m_rangeCurveY.Evaluate(Mathf.Abs(h - maxIndexY) / height); // int index = w + h * w; // input[index] = distFactorX * distFactorY; // float[] desiredOutput = new float[m_screenshotManager.GetOutputNumber()]; // // player is on the right half // if (playerIsRightHalf) // { // // current w is to the right, go left // if(w < playerPositionXCenter) // desiredOutput[0] = 1; // else // desiredOutput[1] = 1; // } // // player is on the left half // else // { // // current w is to the left, go right // if (w > playerPositionXCenter) // desiredOutput[1] = 1; // else // desiredOutput[0] = 1; // } // SampleContainer container = new SampleContainer(input, desiredOutput, null, width, height); // m_data.Add(container); // } //} } return(m_data); }
private void LateUpdate() { m_cacheSampleSource = null; m_cacheSampleThis = null; }
private SmartCollection<SampleContainer> GetSampleLabel(ref MsSqlPersistence dbConnection, ref SqlCommand dbCommand, int arlNumber) { SmartCollection<SampleContainer> returnList = new SmartCollection<SampleContainer>(); try { returnList = new SmartCollection<SampleContainer>(); dbCommand.CommandType = CommandType.StoredProcedure; dbCommand.CommandText = "uspGetSampleLabel"; dbCommand.Parameters.Clear(); dbCommand.Parameters.Add("@ARLNumber", System.Data.SqlDbType.Int).Value = arlNumber; DataTable returnDT = dbConnection.ExecuteQuery(dbCommand); foreach (DataRow row in returnDT.Rows) { SampleContainer container = new SampleContainer(); container.SampleContainerId = Convert.ToInt32(row["SampleContainerID"]); container.Label = row["Label"].ToString(); container.ARLNumber = Convert.ToInt32(row["ARLNumber"]); container.ReceivedDate = row["ReceivedDate"].ToString(); container.StorageLocationCode = row["StorageLocationCode"].ToString(); returnList.Add(container); } } catch { throw; } return returnList; }
void Render() { SampleContainer sample = m_samples[m_currentSampleIndex]; int renderWidth = sample.m_width; int renderHeight = sample.m_height + 1; float pixelSize = m_screenshotManager.GetBackgroundHeight() * m_screenshotManager.GetCaptureWidth() / m_screenshotManager.GetCaptureHeight() / renderWidth; int height = (int)(m_screenshotManager.GetPlayerHeight() / pixelSize); if (m_screenshotManager.GetPlayerHeight() != pixelSize) { height += 1; } int playerLength = renderWidth * height; //m_rect = new Rect(0, 0, renderWidth, renderHeight); //m_renderTexture = new RenderTexture(renderWidth, renderHeight, 24); //m_screenshotTexture = m_image.texture as Texture2D;// new Texture2D(renderWidth, renderHeight, TextureFormat.RGB24, false); Destroy(m_image.texture); Destroy(m_screenshotTexture); m_screenshotTexture = new Texture2D(renderWidth, renderHeight, TextureFormat.RGB24, false); m_screenshotTexture.filterMode = FilterMode.Point; // input for (int h = 0; h < sample.m_height; h++) { for (int w = 0; w < sample.m_width; w++) { int index = w + h * sample.m_width; float obstacleInput = Mathf.Clamp01(sample.m_input[index]); int playerIndex = index + sample.m_width * sample.m_height; float playerInput = playerIndex >= sample.m_input.Length ? 0f : Mathf.Clamp01(sample.m_input[playerIndex]); if (index < playerLength && playerInput > 0) { m_screenshotTexture.SetPixel(w, h, new Color(0, playerInput, 0)); } else if (obstacleInput > 0) { m_screenshotTexture.SetPixel(w, h, new Color(obstacleInput, 0, 0)); } else { m_screenshotTexture.SetPixel(w, h, new Color(0, 0, 0)); } } } // desired output for (int i = 0; i < sample.m_desiredOutput.Length; i++) { int startIndex = (int)((float)sample.m_width * i / (sample.m_desiredOutput.Length)); int endIndex = (int)Mathf.Min(startIndex + (float)sample.m_width / sample.m_desiredOutput.Length, sample.m_width - 1); for (int j = startIndex; j <= endIndex; j++) { Color c = new Color(); if (i == 0) { c.g = sample.m_desiredOutput[0]; } if (i == 1) { c.r = sample.m_desiredOutput[2]; } if (i == 2) { c.b = sample.m_desiredOutput[1]; } m_screenshotTexture.SetPixel(j, renderHeight - 1, c);// new Color(sample.m_desiredOutput[0] * 255, sample.m_desiredOutput[1] * 255, sample.m_desiredOutput[2] * 255)); } } // apply m_screenshotTexture.Apply(); m_image.texture = m_screenshotTexture; }